Skip to content

Conversation

@Oletus
Copy link
Contributor

@Oletus Oletus commented Oct 29, 2019

Clearcoat normals need to use temporary variable names that are different from regular normals so that there's no name conflict. This also moves sampling of the normal map outside of the normal perturbation helper function so that there isn't as much duplicate code.

Clearcoat normals need to use temporary variable names that are different from regular normals so that there's no name conflict. This also moves sampling of the normal map outside of the normal perturbation helper function so that there isn't as much duplicate code.
In case a material has both regular and clearcoat normal maps and is using vertex tangents, we can compute the tangent space matrix made out of the three basis vectors once and use it for both regular and clearcoat normals.
@Oletus
Copy link
Contributor Author

Oletus commented Oct 29, 2019

@Mugen87 @mrdoob Please review this bug fix!

@Oletus
Copy link
Contributor Author

Oletus commented Oct 29, 2019

Not sure what's up with the CI, looks like it maybe timed out due to some unrelated condition?

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 29, 2019

Current (https://threejs.org/examples/webgl_materials_physical_clearcoat):

image

PR:

image

It seems the actual normalMap is now visible.

Prior to this PR clearcoat used "normalMap" in case per-vertex tangents were enabled, and "clearcoatNormalMap" in case per-vertex tangents were disabled. Now we're correctly always using "clearcoatNormalMap".
@Oletus
Copy link
Contributor Author

Oletus commented Oct 29, 2019

Looks like the previous code also had another bug - in case per-vertex tangents were being used, clearcoat would use the regular normal map. I used that as a reference so I accidentally broke the case that was previously working correctly. Added a commit to always use the right normal map now.

@WestLangley
Copy link
Collaborator

It seems the actual normalMap is now visible.

@Mugen87 No, that is a bug in the PR.

@WestLangley
Copy link
Collaborator

@Oletus said

Clearcoat normals need to use temporary variable names that are different from regular normals so that there's no name conflict.

Can you please point to the bug you were referring to -- and presumably fixed?

//

I spent about an hour studying your PR and I agree your refactoring is an improvement. Thanks!

@mrdoob mrdoob added this to the r111 milestone Oct 30, 2019
@Oletus
Copy link
Contributor Author

Oletus commented Oct 30, 2019

I didn't file a separate bug report for the bugs.

Bug 1: there's a shader name conflict when vertexTangents are enabled on a material with clearcoat. You can reproduce this by using BufferGeometryUtils.computeTangents and enabling vertexTangents in the clearcoat example.

Bug 2: clearcoat shader code under the USE_TANGENT define was also referring to regular normal map instead of the clearcoat normal map , this line in the old code:

vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;`

@WestLangley
Copy link
Collaborator

@Oletus This looks good to me. Thank you.

It is not your fault, but IMO, the shader code with the chunks is very fragile. Logical errors and edge cases are easy to overlook. I found the bug you introduced prior to you mentioning it (bug 2), but I did not notice the redeclaration bug you fixed (bug 1) until I asked.

I think it would be beneficial if @arobertson0 would review these changes, too.

@arobertson0
Copy link
Contributor

I think it would be beneficial if @arobertson0 would review these changes, too.

On it =)

@arobertson0
Copy link
Contributor

The examples are running correctly, and the code is clear and seemingly correct =)

I'm noticing that the contents of clearcoat_normal_fragment_maps and normal_fragment_maps are very similar.
Would it be worthwhile to abstract the logic as a function? It would probably land in normal_fragment_begin, right where vTBN is being defined.

@WestLangley
Copy link
Collaborator

The examples are running correctly

The examples worked before...

The related examples don't use tangents. Testing requires a lot of effort, and numerous use cases.

@Oletus
Copy link
Contributor Author

Oletus commented Oct 30, 2019

Should we add something to examples to have at least a basic test for this? It would be easy enough to add variations of geometry that use computed per-vertex tangents to the webgl_materials_physical_clearcoat example.

@WestLangley
Copy link
Collaborator

Should we add something to examples

That is up to @mrdoob.

For the record, there are 8 cases:

  • with/without normal map
  • with/without clearcoat normal map
  • with/without tangents

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 5, 2019

I don't think the mentioned examples should block this PR from being merged. They can also be added at a later point, too.

@mrdoob
Copy link
Owner

mrdoob commented Nov 5, 2019

Looks good to me. We can improve things as we go.

@mrdoob mrdoob merged commit 7e0aafa into mrdoob:dev Nov 5, 2019
@mrdoob
Copy link
Owner

mrdoob commented Nov 5, 2019

Thanks!

@WestLangley
Copy link
Collaborator

/ping @sunag FYI. :-)

@Oletus Oletus deleted the simplify-normal-shader branch November 6, 2019 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants