Skip to content

Commit

Permalink
WebGPURenderer: Fix faceDirection in WebGLBackend if used `BackSi…
Browse files Browse the repository at this point in the history
…de` (#28064)

* Fix faceDirection in WebGLBackend if used BackSide

* Added frontFaceCW
  • Loading branch information
sunag committed Apr 3, 2024
1 parent cf5db53 commit a84ff89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 13 additions & 0 deletions examples/jsm/nodes/display/FrontFacingNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Node, { addNodeClass } from '../core/Node.js';
import { nodeImmutable, float } from '../shadernode/ShaderNode.js';
import { BackSide, WebGLCoordinateSystem } from 'three';

class FrontFacingNode extends Node {

Expand All @@ -13,6 +14,18 @@ class FrontFacingNode extends Node {

generate( builder ) {

const { renderer, material } = builder;

if ( renderer.coordinateSystem === WebGLCoordinateSystem ) {

if ( material.side === BackSide ) {

return 'false';

}

}

return builder.getFrontFacing();

}
Expand Down
7 changes: 4 additions & 3 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ class WebGLBackend extends Backend {

draw( renderObject, info ) {

const { pipeline, material, context } = renderObject;
const { object, pipeline, material, context } = renderObject;
const { programGPU } = this.get( pipeline );

const { gl, state } = this;
Expand All @@ -579,7 +579,9 @@ class WebGLBackend extends Backend {

this._bindUniforms( renderObject.getBindings() );

state.setMaterial( material );
const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );

state.setMaterial( material, frontFaceCW );

gl.useProgram( programGPU );

Expand Down Expand Up @@ -611,7 +613,6 @@ class WebGLBackend extends Backend {

const index = renderObject.getIndex();

const object = renderObject.object;
const geometry = renderObject.geometry;
const drawRange = geometry.drawRange;
const firstVertex = drawRange.start;
Expand Down

0 comments on commit a84ff89

Please sign in to comment.