-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
Auto shader output definitions for MRT #27808
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
base: dev
Are you sure you want to change the base?
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
@vanruesc This issue has been fixed, you need to pull the code again. Solution:
... All checks have passed ... |
I've fixed this now by including the render target in the material properties to detect if the current render target differs from the one that was previously associated with the material. The I've adjusted |
Description
This PR aims to make Multiple Render Targets (MRT) easier to use by implementing automatic shader output definitions for built-in materials and
ShaderMaterial
.Context
For MRT workflows it's up to the user to define what data should be written to the respective textures. The MRT example promotes the use of
RawShaderMaterial
to achieve this. However, MRT is most useful for rendering out additional pixel data during the main render pass. In most situations the main scene will consist of meshes that use built-in materials likeMeshStandardMaterial
, but those materials are currently difficult to use with MRT.Improving compatibility
It's possible to use
onBeforeCompile
on every object in a scene to modify built-in materials, but this has some downsides:onBeforeCompile
hook, so care must be taken to preserve it.onBeforeCompile
hooks multiple times.onBeforeCompile
hooks.If it wasn't necessary to define shader outputs, we could avoid using
onBeforeCompile
altogether and modify theShaderChunk
library instead (example). But at the moment there's no way aroundonBeforeCompile
.Meeting halfway
With the changes in this PR, three can define shader outputs automatically based on the current render target. To avoid breakage, this is only done for built-in materials and for
ShaderMaterial
if the shader doesn't already define shader outputs. This implementation also uses the names of the MRT textures to define macros of the formout_${name}
for convenience which allows for conditional MRT code like the following:I've considered using the texture names as-is but opted for a prefix approach to reduce the risk of name conflicts.
Open issue
This PR is in draft mode because the material/program doesn't get updated after switching the render target. I've tried modifying WebGLPrograms.getProgramCacheKey to account for the render target, but that didn't work out. Setting material.needsUpdate to true also didn't trigger a program update.