Skip to content

Commit 0d26ee3

Browse files
committed
playing with render targets
1 parent 6f87fc3 commit 0d26ee3

File tree

4 files changed

+97
-6
lines changed

4 files changed

+97
-6
lines changed

src/nodes/Nodes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export { default as FilmNode, film } from './display/FilmNode.js';
135135
export { default as Lut3DNode, lut3D } from './display/Lut3DNode.js';
136136
export { default as RenderOutputNode, renderOutput } from './display/RenderOutputNode.js';
137137
export { default as PixelationNode, pixelation } from './display/PixelationNode.js';
138+
export { default as PixelationPassNode, pixelationPass } from './display/PixelationPassNode.js'
138139

139140
export { default as PassNode, pass, texturePass, depthPass, normalPass } from './display/PassNode.js';
140141

src/nodes/display/PassNode.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import MeshNormalNodeMaterial from '../materials/MeshNormalNodeMaterial.js';
1515

1616
const _size = new Vector2();
1717

18-
class PassTextureNode extends TextureNode {
18+
export class PassTextureNode extends TextureNode {
1919

2020
constructor( passNode, texture ) {
2121

@@ -70,11 +70,11 @@ class PassNode extends TempNode {
7070

7171
if ( this.scope === PassNode.NORMAL ) {
7272

73-
const target = new RenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType } );
74-
renderTarget.texture.name = 'PostProcessingNormal';
75-
this.normalRenderTarget = target;
73+
const normalTarget = new RenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType } );
74+
normalTarget.texture.name = 'PostProcessingNormal';
75+
this.normalRenderTarget = normalTarget;
7676

77-
this._normalTextureNode = nodeObject( new PassTextureNode( this, target.texture ) );
77+
this._normalTextureNode = nodeObject( new PassTextureNode( this, normalTarget.texture ) );
7878

7979
}
8080

src/nodes/display/PixelationNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class PixelationNode extends TempNode {
141141

142142
}
143143

144-
export const pixelation = ( node, depthNode, normalNode, pixelSize, normalEdgeStrength = 0.3, depthEdgeStrength = 0.4 ) => nodeObject( new PixelationNode( nodeObject( node ).toTexture(), nodeObject( depthNode ).toTexture(), nodeObject( normalNode ).toTexture(), nodeObject( pixelSize ), normalEdgeStrength, depthEdgeStrength ) );
144+
export const pixelation = ( node, depthNode, normalNode, pixelSize = 4, normalEdgeStrength = 0.3, depthEdgeStrength = 0.4 ) => nodeObject( new PixelationNode( nodeObject( node ).toTexture(), nodeObject( depthNode ).toTexture(), nodeObject( normalNode ).toTexture(), pixelSize, normalEdgeStrength, depthEdgeStrength ) );
145145

146146
addNodeElement( 'pixelation', pixelation );
147147

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { nodeObject } from '../shadernode/ShaderNode.js';
2+
import { addNodeClass } from '../core/Node.js';
3+
import { NodeUpdateType } from '../core/constants.js';
4+
import PassNode from './PassNode.js';
5+
import { RenderTarget } from '../../core/RenderTarget.js';
6+
import { HalfFloatType/*, FloatType*/ } from '../../constants.js';
7+
import { PassTextureNode } from './PassNode.js';
8+
import { Vector2 } from '../../math/Vector2.js';
9+
import { MeshNormalNodeMaterial } from '../Nodes.js';
10+
11+
const _size = new Vector2();
12+
13+
class PixelationPassNode extends PassNode {
14+
15+
constructor( scene, camera, pixelSize, normalEdgeStrength, depthEdgeStrength ) {
16+
17+
super( 'normal', scene, camera );
18+
19+
this.pixelSize = pixelSize;
20+
this.normalEdgeStrength = normalEdgeStrength;
21+
this.depthEdgeStrength = depthEdgeStrength;
22+
23+
this.updateBeforeType = NodeUpdateType.FRAME;
24+
25+
this.isPixelationPassNode = true;
26+
27+
}
28+
29+
updateBefore( frame ) {
30+
31+
const { renderer } = frame;
32+
const { scene, camera } = this;
33+
34+
this._pixelRatio = renderer.getPixelRatio();
35+
36+
const size = renderer.getSize( _size );
37+
const pixelSize = this.pixelSize.value ? this.pixelSize.value : this.pixelSize;
38+
39+
this.setSize( pixelSize >= 1 ? size.width / pixelSize : size.width, pixelSize >= 1 ? size.height / pixelSize : size.height );
40+
41+
const currentRenderTarget = renderer.getRenderTarget();
42+
43+
this._cameraNear.value = camera.near;
44+
this._cameraFar.value = camera.far;
45+
46+
renderer.setRenderTarget( this.renderTarget );
47+
console.log(this.renderTarget)
48+
49+
renderer.render( scene, camera );
50+
51+
renderer.setRenderTarget( this.normalRenderTarget );
52+
const oldMaterial = scene.overrideMaterial;
53+
scene.overrideMaterial = new MeshNormalNodeMaterial();
54+
renderer.render( scene, camera );
55+
scene.overrideMaterial = oldMaterial;
56+
57+
renderer.setRenderTarget( currentRenderTarget );
58+
59+
}
60+
61+
setSize( width, height ) {
62+
63+
super.setSize( width, height );
64+
this.normalRenderTarget.setSize( width * this._pixelRatio, height * this._pixelRatio );
65+
66+
}
67+
68+
setup() {
69+
70+
const pass = super.getTextureDepthNode();
71+
console.log( this.normalEdgeStrength )
72+
return pass.pixelation( this._depthTextureNode, this._normalTextureNode, this.pixelSize, this.normalEdgeStrength, this.depthEdgeStrength );
73+
74+
}
75+
76+
dispose() {
77+
78+
super.dispose();
79+
this.normalRenderTarget.dispose();
80+
81+
82+
}
83+
84+
}
85+
86+
export default PixelationPassNode;
87+
88+
export const pixelationPass = ( scene, camera, pixelSize, normalEdgeStrength, depthEdgeStrength ) => nodeObject( new PixelationPassNode( scene, camera, pixelSize, normalEdgeStrength, depthEdgeStrength ) );
89+
90+
addNodeClass( 'PixelationPassNode', PixelationPassNode );

0 commit comments

Comments
 (0)