-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
Inline grayscaling in materials #11308
Comments
That is implemented with postprocessing. See this example, and set saturation to 0. |
@looeee is right. Such features should be implemented with post processing. |
Of course it can be implemented in postprocessing. But would be much more efficient to have the option to do it inline. Tone-mapping could also be done in postprocessing, yet you still made it available inline. |
For reference, adding inline color-correction -- and possibly LUTs -- was mentioned in #11076 (comment). Perhaps we could call it color-remapping. |
Sry, i've missed this in the mentioned discussion. |
color-remapping sounds like a good term for it. |
Another thing that can easily be done with: for example something like: myMaterial = new MeshPhongMaterial( params );
myMaterial.shaderIncludes = {
fog_fragment: THREE.ShaderChunks.fog_fragment +
"\n" +
"gl_FragColor.xyz = mix( gl_FragColor.xyz, dot( gl_FragColor.xyz , 1.) , uMyGrayScaleUniform );"
uv_pars_fragment: THREE.ShaderChunks.uv_pars_fragment +
"\n" +
"uniform float uMyGrayScaleUniform;"
}
myMaterial.shaderUniforms = {
uMyGrayScaleUniform: { value: 0 }
} The idea being - you should be able to decorate any material and modify the glsl to your liking. Current materials have not been built with that in mind. For example, this works, but While it gives flexibility, you need to know glsl and go through three's shader library. If it were further abstracted, that you have meaningful hooks, it would be much easier to work with. Anyway it doesn't have to be this ugly. You'd do something like this, or a factory or something: class MeshPhongMaterialGS extends MeshPhongMaterial {
constructor(){
super(...args)
this.shaderUniforms = {
uGrayscale: { value: 0 }
}
this.shaderIncludes = {
uv_pars_fragment: "...",
fog_fragment: "..."
}
}
set grayscale ( v ) { this.shaderUniforms.uGrayscale = v }
get grayscale () { return this.shaderUniforms.uGrayscale }
} The main benefit is - now you're relying on the community to patch the library and add a feature to cover what so far may be a single use case ( can already be done with post processing ). Even if that happens, you might find the grays too washed out, or too having too much contrast, and you can't even use it. With this api, you could go here and grab any algorithm, and apply it yourself. Even if you don't know glsl, you might find an npm module that does just this, because someone else solved the problem without altering the library but using it instead. |
Duplicate of #19457. |
Description of the problem
It would be great to have the option to render in grayscale. It could be implemented as a new tonemapping type and set in renderer.tonemapping.
The text was updated successfully, but these errors were encountered: