Skip to content

Commit 79c0c49

Browse files
committed
fix renderTarget issue
1 parent 0d26ee3 commit 79c0c49

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

examples/webgpu_postprocessing_pixel.html

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3434
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
3535

36-
import { pass, normalPass, uniform, pixelation } from 'three/tsl';
36+
import { pass, normalPass, uniform, pixelation, pixelationPass } from 'three/tsl';
3737

3838
let camera, scene, renderer, composer, crystalMesh, clock;
3939
let gui, params;
@@ -68,8 +68,8 @@
6868
function addBox( boxSideLength, x, z, rotation ) {
6969

7070
const mesh = new THREE.Mesh( new THREE.BoxGeometry( boxSideLength, boxSideLength, boxSideLength ), boxMaterial );
71-
mesh.castShadow = true;
72-
mesh.receiveShadow = true;
71+
mesh.castShadow = false;
72+
mesh.receiveShadow = false;
7373
mesh.rotation.y = rotation;
7474
mesh.position.y = boxSideLength / 2;
7575
mesh.position.set( x, boxSideLength / 2 + .0001, z );
@@ -101,8 +101,8 @@
101101
specular: 0xffffff
102102
} )
103103
);
104-
crystalMesh.receiveShadow = true;
105-
crystalMesh.castShadow = true;
104+
crystalMesh.receiveShadow = false;
105+
crystalMesh.castShadow = false;
106106
scene.add( crystalMesh );
107107

108108
// lights
@@ -111,7 +111,7 @@
111111

112112
const directionalLight = new THREE.DirectionalLight( 0xfffecd, 1.5 );
113113
directionalLight.position.set( 100, 100, 100 );
114-
directionalLight.castShadow = true;
114+
directionalLight.castShadow = false;
115115
directionalLight.shadow.mapSize.set( 2048, 2048 );
116116
scene.add( directionalLight );
117117

@@ -120,30 +120,26 @@
120120
const target = spotLight.target;
121121
scene.add( target );
122122
target.position.set( 0, 0, 0 );
123-
spotLight.castShadow = true;
123+
spotLight.castShadow = false;
124124
scene.add( spotLight );
125125

126-
renderer = new THREE.WebGPURenderer();
126+
renderer = new THREE.WebGPURenderer({ antialias: false });
127127
renderer.shadowMap.enabled = true;
128128
//renderer.setPixelRatio( window.devicePixelRatio );
129129
renderer.setSize( window.innerWidth, window.innerHeight );
130130
renderer.setAnimationLoop( animate );
131131
document.body.appendChild( renderer.domElement );
132132

133133
const effectController = {
134-
pixelSize: 14,
134+
pixelSize: uniform(14),
135135
normalEdgeStrength: uniform(0.3),
136136
depthEdgeStrength: uniform(0.4)
137137
}
138138

139139
composer = new THREE.PostProcessing( renderer );
140140

141-
const scenePass = normalPass( scene, camera );
142-
const scenePassColor = scenePass.getTextureNode();
143-
const scenePassDepth = scenePass.getTextureDepthNode();
144-
const scenePassNormal = scenePass.getTextureNormalNode();
145-
const pixelationPass = scenePassColor.pixelation( scenePassDepth, scenePassNormal, 4, effectController.normalEdgeStrength, effectController.depthEdgeStrength);
146-
composer.outputNode = pixelationPass;
141+
const scenePass = pixelationPass( scene, camera, effectController.pixelSize, effectController.normalEdgeStrength, effectController.depthEdgeStrength );
142+
composer.outputNode = scenePass;
147143
window.addEventListener( 'resize', onWindowResize );
148144

149145
const controls = new OrbitControls( camera, renderer.domElement );
@@ -152,7 +148,7 @@
152148
// gui
153149

154150
gui = new GUI();
155-
gui.add( pixelationPass.pixelSizeNode, 'value', 0, 14, 1).name( 'Pixel Size' );
151+
gui.add( effectController.pixelSize, 'value', 0, 14, 1).name( 'Pixel Size' );
156152
gui.add( effectController.normalEdgeStrength, 'value', 0, 2, 0.05 ).name( 'Normal Edge Strength' );
157153
gui.add( effectController.depthEdgeStrength, 'value', 0, 1, 0.05 ).name( 'Depth Edge Strength' );
158154

src/nodes/display/PixelationNode.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { uniform } from '../core/UniformNode.js';
66
import { dot, clamp, smoothstep, sign, step, floor } from '../math/MathNode.js';
77
import { float, If } from '../shadernode/ShaderNode.js';
88
import { Vector4 } from '../../math/Vector4.js';
9-
import { temp } from '../Nodes.js';
109
import { property } from '../core/PropertyNode.js';
1110

1211
class PixelationNode extends TempNode {
@@ -32,9 +31,8 @@ class PixelationNode extends TempNode {
3231
updateBefore() {
3332

3433
const map = this.textureNode.value;
35-
const width = map.image.width / this.pixelSizeNode.value;
36-
const height = map.image.height / this.pixelSizeNode.value;
37-
34+
const width = map.image.width;
35+
const height = map.image.height;
3836
this._resolution.value.set( width, height, 1 / width, 1 / height );
3937

4038
}
@@ -141,7 +139,7 @@ class PixelationNode extends TempNode {
141139

142140
}
143141

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 ) );
142+
export const pixelation = ( node, depthNode, normalNode, pixelSize = 14, normalEdgeStrength = 0.3, depthEdgeStrength = 0.4 ) => nodeObject( new PixelationNode( nodeObject( node ).toTexture(), nodeObject( depthNode ).toTexture(), nodeObject( normalNode ).toTexture(), nodeObject(pixelSize), nodeObject(normalEdgeStrength), nodeObject(depthEdgeStrength) ) );
145143

146144
addNodeElement( 'pixelation', pixelation );
147145

src/nodes/display/PixelationPassNode.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { nodeObject } from '../shadernode/ShaderNode.js';
22
import { addNodeClass } from '../core/Node.js';
33
import { NodeUpdateType } from '../core/constants.js';
44
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';
85
import { Vector2 } from '../../math/Vector2.js';
96
import { MeshNormalNodeMaterial } from '../Nodes.js';
107

@@ -36,15 +33,14 @@ class PixelationPassNode extends PassNode {
3633
const size = renderer.getSize( _size );
3734
const pixelSize = this.pixelSize.value ? this.pixelSize.value : this.pixelSize;
3835

39-
this.setSize( pixelSize >= 1 ? size.width / pixelSize : size.width, pixelSize >= 1 ? size.height / pixelSize : size.height );
36+
this.setSize( pixelSize >= 1 ? (size.width / pixelSize) | 0 : size.width, pixelSize >= 1 ? (size.height / pixelSize) | 0 : size.height );
4037

4138
const currentRenderTarget = renderer.getRenderTarget();
4239

4340
this._cameraNear.value = camera.near;
4441
this._cameraFar.value = camera.far;
4542

4643
renderer.setRenderTarget( this.renderTarget );
47-
console.log(this.renderTarget)
4844

4945
renderer.render( scene, camera );
5046

@@ -61,14 +57,12 @@ class PixelationPassNode extends PassNode {
6157
setSize( width, height ) {
6258

6359
super.setSize( width, height );
64-
this.normalRenderTarget.setSize( width * this._pixelRatio, height * this._pixelRatio );
6560

6661
}
6762

6863
setup() {
6964

70-
const pass = super.getTextureDepthNode();
71-
console.log( this.normalEdgeStrength )
65+
const pass = super.getTextureNode();
7266
return pass.pixelation( this._depthTextureNode, this._normalTextureNode, this.pixelSize, this.normalEdgeStrength, this.depthEdgeStrength );
7367

7468
}

0 commit comments

Comments
 (0)