add support for front/back/double to MeshNormalMaterial #10330

Merged
merged 2 commits into from Dec 11, 2016

Projects

None yet

3 participants

@bhouston
Contributor

Add support for MeshNormalMaterial to render properly if it is double sided. I also expanded the material_channels example to allow for specifying front/back/double sided to test this functionality.

@WestLangley
Collaborator

I am not seeing any difference in rendering with this PR. I must be missing something... I am testing with a sphere sector...

Part of the problem -- and it has nothing to do with the PR -- is that the normals are rendered in camera space. So as you move the camera, the colors change.

I wonder why it was implemented that way? It would seem to me that the normals should be rendered in world space so the colors would be view-independent. On the other hand, this does show what is passed to the shader...

+ if( standardMaterial.side !== side ) {
+
+ standardMaterial.side = side;
+ standardMaterial.needsUpdate = true;
@WestLangley
WestLangley Dec 11, 2016 Collaborator

Is the needsUpdate flag required here?

@bhouston
bhouston Dec 11, 2016 Contributor

yes, because gl_FrontFacing is only checked if the define DOUBLE_SIDED is set and defines only change their state when one recompiles the shaders.

@WestLangley
WestLangley Dec 11, 2016 Collaborator

Oh, yes. It's the defines that are the culprit. I think we implemented it that way to avoid an if-statement in the shader.

@bhouston
Contributor

gl_FrontFacing is only used when double sided. The trick is to look at the material_channels example with double sided and then tilt the head so you can see inside of the neck and the front of the face at the same time - this PR changes that case.

@bhouston
Contributor

It is standard for normals rendered to the normal buffer be in camera space. This is actually required for a ton of algorithms. We should not change it.

@mrdoob mrdoob merged commit d8c3636 into mrdoob:dev Dec 11, 2016
@mrdoob
Owner
mrdoob commented Dec 11, 2016

Thanks!

@WestLangley
Collaborator

We should not change it.

Good point.

tilt the head so you can see inside of the neck

I see. So with this PR, the interior of the neck is blue when double-sided -- as it should be.

But the interior of the neck is green when back-sided. It should also be blue, no? -- at least when the camera is oriented so the (flipped) surface normal points toward the viewer.


Aha... It appears the vertex shader is missing a bunch of chunks related to the normal calculation...

@bhouston
Contributor

@WestLangley I am not sure the BackSide behavior is correct i'n this material_channel example. I actually suspect it may be wrong. But it was like this originally so it isn't something I just introduced but it may be something we should fix.

@WestLangley
Collaborator

@bhouston Yes, more changes are required to the shader to properly support sidedness in MeshNormalMaterial. I'll work on it.

Might as well support displacement, bump, and normal maps, too. I think that could be very illustrative.

What do you think?

@bhouston
Contributor
@Jozain Jozain deleted the bhouston:normalDoubleSided branch Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment