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

Use multiple render target in preset materials #22920

Closed
ligaofeng0901 opened this issue Nov 30, 2021 · 1 comment · Fixed by #22931
Closed

Use multiple render target in preset materials #22920

ligaofeng0901 opened this issue Nov 30, 2021 · 1 comment · Fixed by #22931

Comments

@ligaofeng0901
Copy link
Contributor

Is your feature request related to a problem? Please describe.

When I try to use multiple render target, the preset materials doesn't work. Then I try to replace something in onBeforeCompile, like layout(location = 1) out highp vec4 pc_fragColor1;, The shader fail to complie and the error message is 'pc_fragColor' : must explicitly specify all locations when using multiple fragment outputs. The main reason is the code in https://github.com/mrdoob/three.js/blob/dev/src/renderers/webgl/WebGLProgram.js#L725 add the extra code into shader source, and there is no way to modify it.

Describe the solution you'd like

For now, I directly modify some code in three.js, and it is a bad idea.

Describe alternatives you've considered

  1. modify the code in WebGLProgram.js#L725, maybe like this
    ( parameters.glslVersion === GLSL3 ) ? '' : 'layout(location = 0) out highp vec4 pc_fragColor;', I don't know if this will cause a compatible issue, and if not, why not?
  2. the onBeforeCompile method can get the shader source but not the final shader source. And I wonder if it's possible to have a api to modify the final shader source. Maybe there has some ways, I just don't know.

Additional context

emm...

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 30, 2021

Then I try to replace something in onBeforeCompile, like layout(location = 1) out highp vec4 pc_fragColor1;

I'm afraid that does not work since you don't have access to this particular part of the shader program. It's kind of a foundation for all built-in materials (and ShaderMaterial) which is not supposed to be changed by the user.

If you need full controls over the entire shader source, you have to build your material based on RawShaderMaterial.

modify the code in WebGLProgram.js#L725, maybe like this
( parameters.glslVersion === GLSL3 ) ? '' : 'layout(location = 0) out highp vec4 pc_fragColor;', I don't know if this will cause a compatible issue, and if not, why not?

This was already suggested here: #16390 (comment)

I think we could give this a try. Would you like to file a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants