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

MeshPhysicalMaterial: Fix shader error for clear coat/anisotropy when normal map is missing. #26334

Merged
merged 2 commits into from
Jun 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;

#else

mat3 tbn = getTangentFrame( - vViewPosition, normal, vNormalMapUv );
mat3 tbn = getTangentFrame( - vViewPosition, normal,
#if defined( USE_NORMALMAP )
vNormalMapUv
#elif defined( USE_CLEARCOAT_NORMALMAP )
vClearcoatNormalMapUv
#else
vUv
#endif
);

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default /* glsl */`
#ifdef USE_UV
#if defined( USE_UV ) || defined( USE_ANISOTROPY )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this line is required, then USE_UV is not properly defined.

It's also possible to set USE_UV in javascript instead of checking for USE_ANISOTROPY while defining the variable.

Right. Why didn't you do that?

Copy link
Contributor Author

@repalash repalash Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure what the plan was for USE_UV after #25740 and a hotfix was required.
Do you recommend setting parameters.vertexUvs when anisotropy is present or creating the define either in WebGLProgram or WebGLRenderer.
Also, there is vAnisotropyMapUv that could be considered or defined cleanly when no normal map is present.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@repalash This is not your fault. Thank you for your contribution.

I think USE_UV should be properly defined. Where it is best to define it at this point I would leave to @Mugen87 and yourself.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there is vAnisotropyMapUv that could be considered or defined cleanly when no normal map is present.

I would favor this approach (if feasible) since anisotropy would work similar to clear coat then.


varying vec2 vUv;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default /* glsl */`
#ifdef USE_UV
#if defined( USE_UV ) || defined( USE_ANISOTROPY )

varying vec2 vUv;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default /* glsl */`
#ifdef USE_UV
#if defined( USE_UV ) || defined( USE_ANISOTROPY )

vUv = vec3( uv, 1 ).xy;

Expand Down