Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Simplify effect nodes. #28778

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/nodes/display/AfterImageNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,13 @@ class AfterImageNode extends TempNode {
const textureNode = this.textureNode;
const textureNodeOld = this.textureNodeOld;

if ( textureNode.isTextureNode !== true ) {

console.error( 'AfterImageNode requires a TextureNode.' );

return vec4();

}

//

const uvNode = textureNode.uvNode || uv();

textureNodeOld.uvNode = uvNode;

const sampleTexture = ( uv ) => textureNode.cache().context( { getUV: () => uv, forceUVContext: true } );
const sampleTexture = ( uv ) => textureNode.uv( uv );

const when_gt = tslFn( ( [ x_immutable, y_immutable ] ) => {

Expand Down Expand Up @@ -154,7 +146,7 @@ class AfterImageNode extends TempNode {

}

export const afterImage = ( node, damp ) => nodeObject( new AfterImageNode( nodeObject( node ), damp ) );
export const afterImage = ( node, damp ) => nodeObject( new AfterImageNode( nodeObject( node ).toTexture(), damp ) );
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved

addNodeElement( 'afterImage', afterImage );

Expand Down
13 changes: 1 addition & 12 deletions src/nodes/display/AnamorphicNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TempNode from '../core/TempNode.js';
import { nodeObject, addNodeElement, tslFn, float, vec2, vec3, vec4 } from '../shadernode/ShaderNode.js';
import { nodeObject, addNodeElement, tslFn, float, vec2, vec3 } from '../shadernode/ShaderNode.js';
import { loop } from '../utils/LoopNode.js';
import { uniform } from '../core/UniformNode.js';
import { NodeUpdateType } from '../core/constants.js';
Expand Down Expand Up @@ -86,17 +86,6 @@ class AnamorphicNode extends TempNode {
setup( builder ) {

const textureNode = this.textureNode;

if ( textureNode.isTextureNode !== true ) {

console.error( 'AnamorphNode requires a TextureNode.' );

return vec4();

}

//

const uvNode = textureNode.uvNode || uv();

const sampleTexture = ( uv ) => textureNode.uv( uv );
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/display/DepthOfFieldNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class DepthOfFieldNode extends TempNode {

}

export const dof = ( node, viewZNode, focus = 1, aperture = 0.025, maxblur = 1 ) => nodeObject( new DepthOfFieldNode( nodeObject( node ), nodeObject( viewZNode ), nodeObject( focus ), nodeObject( aperture ), nodeObject( maxblur ) ) );
export const dof = ( node, viewZNode, focus = 1, aperture = 0.025, maxblur = 1 ) => nodeObject( new DepthOfFieldNode( nodeObject( node ).toTexture(), nodeObject( viewZNode ), nodeObject( focus ), nodeObject( aperture ), nodeObject( maxblur ) ) );

addNodeElement( 'dof', dof );

Expand Down
74 changes: 10 additions & 64 deletions src/nodes/display/DotScreenNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,39 @@ import { nodeObject, addNodeElement, tslFn, vec2, vec3, vec4 } from '../shaderno
import { uniform } from '../core/UniformNode.js';
import { NodeUpdateType } from '../core/constants.js';
import { uv } from '../accessors/UVNode.js';
import { texturePass } from './PassNode.js';
import { sin, cos } from '../math/MathNode.js';
import { add } from '../math/OperatorNode.js';
import QuadMesh from '../../renderers/common/QuadMesh.js';

import { Vector2 } from '../../math/Vector2.js';
import { RenderTarget } from '../../core/RenderTarget.js';

const quadMesh = new QuadMesh();

class DotScreenNode extends TempNode {

constructor( colorNode, center = new Vector2( 0.5, 0.5 ), angle = 1.57, scale = 1 ) {
constructor( inputNode, center = new Vector2( 0.5, 0.5 ), angle = 1.57, scale = 1 ) {

super( 'vec4' );

this.colorNode = colorNode;
this.inputNode = inputNode;
this.center = uniform( center );
this.angle = uniform( angle );
this.scale = uniform( scale );

this._renderTarget = new RenderTarget();
this._renderTarget.texture.name = 'dotScreen';

this._size = uniform( new Vector2() );

this._textureNode = texturePass( this, this._renderTarget.texture );

this.updateBeforeType = NodeUpdateType.RENDER;

}

getTextureNode() {

return this._textureNode;

}

setSize( width, height ) {

this._size.value.set( width, height );
this._renderTarget.setSize( width, height );

}

updateBefore( frame ) {

const { renderer } = frame;
updateBefore() {

const colorNode = this.colorNode;
const map = colorNode.value;
const map = this.inputNode.value;

this._renderTarget.texture.type = map.type;

const currentRenderTarget = renderer.getRenderTarget();
const currentTexture = colorNode.value;

quadMesh.material = this._material;

this.setSize( map.image.width, map.image.height );

// render

renderer.setRenderTarget( this._renderTarget );

quadMesh.render( renderer );

// restore

renderer.setRenderTarget( currentRenderTarget );
colorNode.value = currentTexture;
this._size.value.set( map.image.width, map.image.height );

}

setup( builder ) {
setup() {

const colorNode = this.colorNode;
const inputNode = this.inputNode;

const pattern = tslFn( () => {

Expand All @@ -95,27 +51,17 @@ class DotScreenNode extends TempNode {

const dotScreen = tslFn( () => {

const color = colorNode;
const color = inputNode;

const average = add( color.r, color.g, color.b ).div( 3 );

return vec4( vec3( average.mul( 10 ).sub( 5 ).add( pattern() ) ), color.a );

} );

//

const material = this._material || ( this._material = builder.createNodeMaterial() );
material.fragmentNode = dotScreen();

//

const properties = builder.getNodeProperties( this );
properties.textureNode = colorNode;

//
const outputNode = dotScreen();

return this._textureNode;
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved
return outputNode;

}

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/display/GaussianBlurNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class GaussianBlurNode extends TempNode {

}

export const gaussianBlur = ( node, directionNode, sigma ) => nodeObject( new GaussianBlurNode( nodeObject( node ), directionNode, sigma ) );
export const gaussianBlur = ( node, directionNode, sigma ) => nodeObject( new GaussianBlurNode( nodeObject( node ).toTexture(), directionNode, sigma ) );

addNodeElement( 'gaussianBlur', gaussianBlur );

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/display/RGBShiftNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RGBShiftNode extends TempNode {

const uvNode = textureNode.uvNode || uv();

const sampleTexture = ( uv ) => this.textureNode.uv( uv );
const sampleTexture = ( uv ) => textureNode.uv( uv );

const rgbShift = tslFn( () => {

Expand Down
4 changes: 2 additions & 2 deletions src/nodes/display/SobelOperatorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SobelOperatorNode extends TempNode {

const uvNode = textureNode.uvNode || uv();

const sampleTexture = ( uv ) => this.textureNode.cache().context( { getUV: () => uv, forceUVContext: true } );
const sampleTexture = ( uv ) => textureNode.uv( uv );

const sobel = tslFn( () => {

Expand Down Expand Up @@ -114,7 +114,7 @@ class SobelOperatorNode extends TempNode {

}

export const sobel = ( node ) => nodeObject( new SobelOperatorNode( nodeObject( node ) ) );
export const sobel = ( node ) => nodeObject( new SobelOperatorNode( nodeObject( node ).toTexture() ) );

addNodeElement( 'sobel', sobel );

Expand Down