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

Added singleMaterials option in NormalPass #202

Closed
wants to merge 1 commit into from
Closed

Conversation

giulioz
Copy link
Member

@giulioz giulioz commented May 26, 2020

Adds an alternative way for rendering the NormalPass using different material instances instead of a single override.
This fixes broken AO with Instancing.

@vanruesc
Copy link
Member

Hi,

thanks for contributing!

The limitations of three's override material system not only affect instanced meshes but also skinned meshes. I understand that a hack is better than nothing, but the problem should be solved at the root and not in postprocessing. If you need the workaround right now, you'll have to use a customized version of the NormalPass in your projects.

Apart from the fact that traversing the scene each frame is bad, this workaround doesn't fully solve the problem: the individual override materials don't use the values of the original materials such as normal maps and displacement maps. A complete workaround would be rather complex on top of being slow. See https://github.com/gkjohnson/threejs-sandbox/tree/master/shader-replacement for a more complete implementation attempt.

The best solution would be Multiple Render Targets in combination with extensible built-in materials, but three doesn't support that yet.

@giulioz
Copy link
Member Author

giulioz commented May 28, 2020

Thanks for your response.

I saw that in typical scenes (~10-30 elements) it's not too slow, since it's O(2N), but I understand that in some cases it may slow down the render loop too much.

I know that this is really an hack, but I think that, at least, this problem and a possible solution should be noted in the docs. For example, I didn't found any reference about how to do AO with instancing online.

Thanks again for your work.

vanruesc added a commit that referenced this pull request Jun 5, 2020
Includes a workaround for instanced and skinned meshes. Addresses #202.
@vanruesc
Copy link
Member

vanruesc commented Jun 5, 2020

I tried to implement a more efficient solution with layers but ran into weird material caching issues and massive FPS drops due to unexpected shader recompilations. So I think we have no other choice but to replace materials every frame. The scrapped version can be found here.

A workaround for override materials with instanced and skinned meshes has been added in postprocessing@6.14.0. Check this to find out how it can be used.

@vanruesc vanruesc closed this Jun 5, 2020
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.

None yet

2 participants