-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
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
Auto shader output definitions for MRT #27808
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.
|
@@ -82,7 +40,7 @@ | |||
return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); | |||
} | |||
|
|||
layout(location = 0) out vec4 pc_FragColor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw: does anyone know what "pc" stands for? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My best guess would be something in the direction of "program compatibility", since pc_fragColor
is related to GLSL1 compatibility in WebGLProgram
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that could be it 👍
I just found it weird that I couldn't find anything when I tried looking it up.
@vanruesc This issue has been fixed, you need to pull the code again. Solution:
... All checks have passed ... |
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. Settingmaterial.needsUpdate
totrue
also didn't trigger a program update.It would be great if someone could help with this, provided there's interest in this PR.