Skip to content

Commit

Permalink
NodeMaterial: Fixes (WebGL) (mrdoob#23064)
Browse files Browse the repository at this point in the history
* fix keyword example

* fix NodeMaterial ColorSpace: mrdoob#22998

* variable params.length to ARCTAN: mrdoob#22930

* NodeMaterial: fix CLEARCOAT

* possible fix to: mrdoob#23054

* fix NodeMaterial: toon example: mrdoob#22989
  • Loading branch information
sunag authored Dec 22, 2021
1 parent 2095a6c commit f5a3397
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions examples/jsm/nodes/materials/nodes/StandardNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class StandardNode extends Node {
if ( useClearcoat ) {

builder.define( 'CLEARCOAT' );
builder.define( 'USE_CLEARCOAT' );

}

Expand Down
12 changes: 12 additions & 0 deletions examples/jsm/nodes/math/MathNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class MathNode extends TempNode {

switch ( this.method ) {

// variable

case MathNode.ARCTAN:

return this.b ? 2 : 1;

// 3

case MathNode.MIX:
case MathNode.CLAMP:
case MathNode.REFRACT:
Expand All @@ -26,6 +34,8 @@ class MathNode extends TempNode {

return 3;

// 2

case MathNode.MIN:
case MathNode.MAX:
case MathNode.MOD:
Expand All @@ -38,6 +48,8 @@ class MathNode extends TempNode {

return 2;

// 1

default:

return 1;
Expand Down
5 changes: 1 addition & 4 deletions examples/jsm/nodes/misc/TextureCubeUVNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ class TextureCubeUVNode extends TempNode {
const bilinearCubeUV = new FunctionCallNode( TextureCubeUVNode.Nodes.bilinearCubeUV, [ texture, uv, mipInt ] );

this.colorSpaceTL = this.colorSpaceTL || new ColorSpaceNode( new ExpressionNode( '', 'v4' ) );
this.colorSpaceTL.fromDecoding( builder.getTextureEncodingFromMap( this.value.value ) );
this.colorSpaceTL.input.parse( bilinearCubeUV.build( builder ) + '.tl' );

this.colorSpaceTR = this.colorSpaceTR || new ColorSpaceNode( new ExpressionNode( '', 'v4' ) );
this.colorSpaceTR.fromDecoding( builder.getTextureEncodingFromMap( this.value.value ) );
this.colorSpaceTR.input.parse( bilinearCubeUV.build( builder ) + '.tr' );

this.colorSpaceBL = this.colorSpaceBL || new ColorSpaceNode( new ExpressionNode( '', 'v4' ) );
this.colorSpaceBL.fromDecoding( builder.getTextureEncodingFromMap( this.value.value ) );
this.colorSpaceBL.input.parse( bilinearCubeUV.build( builder ) + '.bl' );

this.colorSpaceBR = this.colorSpaceBR || new ColorSpaceNode( new ExpressionNode( '', 'v4' ) );
this.colorSpaceBR.fromDecoding( builder.getTextureEncodingFromMap( this.value.value ) );
this.colorSpaceBR.input.parse( bilinearCubeUV.build( builder ) + '.br' );

// add a custom context for fix incompatibility with the core
Expand Down Expand Up @@ -230,6 +226,7 @@ TextureCubeUVNode.Nodes = ( function () {
return TextureCubeUVData( tl, tr, br, bl, f );
}`, [ TextureCubeUVData, getFace, getUV, cubeUV_maxMipLevel, cubeUV_minMipLevel, cubeUV_maxTileSize, cubeUV_minTileSize ] );

bilinearCubeUV.useKeywords = false;

// These defines must match with PMREMGenerator
Expand Down
14 changes: 7 additions & 7 deletions examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ ${this.shader[ getShaderStageProperty( shaderStage ) ]}
this.parseInclude( 'fragment', 'lights_physical_fragment' );

const colorSlot = this.getSlot( 'fragment', 'COLOR' );
const normalSlot = this.getSlot( 'fragment', 'NORMAL' );
const opacityNode = this.getSlot( 'fragment', 'OPACITY' );
const normalSlot = this.getSlot( 'fragment', 'NORMAL' );
const emissiveNode = this.getSlot( 'fragment', 'EMISSIVE' );
const roughnessNode = this.getSlot( 'fragment', 'ROUGHNESS' );
const metalnessNode = this.getSlot( 'fragment', 'METALNESS' );
Expand All @@ -397,22 +397,22 @@ ${this.shader[ getShaderStageProperty( shaderStage ) ]}

}

if ( normalSlot !== undefined ) {
if ( opacityNode !== undefined ) {

this.addCodeAfterInclude(
'fragment',
'normal_fragment_begin',
`${normalSlot.code}\n\tnormal = ${normalSlot.result};`
'alphatest_fragment',
`${opacityNode.code}\n\tdiffuseColor.a = ${opacityNode.result};`
);

}

if ( opacityNode !== undefined ) {
if ( normalSlot !== undefined ) {

this.addCodeAfterInclude(
'fragment',
'alphamap_fragment',
`${opacityNode.code}\n\tdiffuseColor.a = ${opacityNode.result};`
'normal_fragment_begin',
`${normalSlot.code}\n\tnormal = ${normalSlot.result};`
);

}
Expand Down
Binary file modified examples/screenshots/webgl_materials_envmaps_hdr_nodes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_materials_envmaps_pmrem_nodes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions examples/webgl_materials_nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@

mtl.ao = val ? new Nodes.FloatNode() : undefined;

mtl.needsUpdate = true;
mtl.dispose();

} );

Expand Down Expand Up @@ -2458,8 +2458,8 @@

var keywordsexample = new Nodes.FunctionNode( [
// use "uv" reserved keyword
'vec4 keywordsexample( sampler2D texture ) {',
' return texture2D( texture, myUV ) + vec4( position * myAlpha, 0.0 );',
'vec4 keywordsexample( sampler2D tex ) {',
' return texture2D( tex, myUV ) + vec4( position * myAlpha, 0.0 );',
'}'
].join( '\n' ) );

Expand Down

0 comments on commit f5a3397

Please sign in to comment.