-
Notifications
You must be signed in to change notification settings - Fork 6
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
Working with sRGBEncoding
#1
Comments
Thanks! The examples in this repo use I have added an example (https://stevinz.github.io/three-wboit/EffectComposer.html) that uses this |
That is interesting. Initial thoughts is that the textures on the trees aren't sRGB encoded, or that lighting is enabled on the tree material? I have updated the EffectComposer.html example (source - live link) to use sRGB encoded textures. I am having trouble trying to recreate the issue. I would be willing to spend more time looking into it if you could provide a minimal example demonstrating the problem. (codepen, jsfiddle, etc.) |
Thanks for the response! I just found out something weird... The screenshot I produced is on one of my dual monitor setups. I switched it to the other monitor, and everything looked correct. What could be the cause of this? Things look great on this monitor. Link to the monitor that creates weird looking leaves. |
Hmm, tricky. Monitors have encoding settings as well. I know on mine when I open the monitor settings with the physical buttons on the side / rear of the monitors, under 'Color Settings' I can select 'sRGB', 'P3', 'Warm', 'Cool', etc. Could be a hardware setting? These settings are external of the computer / OS / graphics card... |
Weird... I can't seem to find color settings by pressing the buttons. I do see an "input color format" of "YCbCr", does that have to do with the issue? |
Hard to say, even with different monitor settings the difference you posted the first time looks pretty extreme. Ignoring the monitor issue for a moment... When you're using wboit + gamma correction do you have renderer.outputEncoding set to Linear or sRGB? Now that the sRGB encoding is happening in the Effect Composer the renderer should be set to Linear, otherwise it's possible the encoding is happening twice in some cases. |
I just checked and I do have it on const material = new ShaderMaterial({
vertexColors: true,
fragmentShader,
vertexShader,
uniforms: {
...UniformsUtils.clone(ShaderLib.basic.uniforms),
// map: this.uniforms.atlas,
uSunlightIntensity: this.uniforms.sunlightIntensity,
uAOTable: this.uniforms.ao,
uMinBrightness: this.uniforms.minBrightness,
uFogNear: this.uniforms.fogNear,
uFogFar: this.uniforms.fogFar,
uFogColor: this.uniforms.fogColor,
uTime: this.uniforms.time,
...uniforms,
},
}) as CustomShaderMaterial;
WboitUtils.patch(material); export const DEFAULT_CHUNK_SHADERS = {
vertex: ShaderLib.basic.vertexShader
.replace(
"#include <common>",
`
attribute int light;
varying float vAO;
varying vec4 vLight;
varying vec4 vWorldPosition;
uniform vec4 uAOTable;
uniform float uTime;
vec4 unpackLight(int l) {
float r = float((l >> 8) & 0xF) / 15.0;
float g = float((l >> 4) & 0xF) / 15.0;
float b = float(l & 0xF) / 15.0;
float s = float((l >> 12) & 0xF) / 15.0;
return vec4(r, g, b, s);
}
#include <common>
`
)
.replace(
"#include <color_vertex>",
`
#include <color_vertex>
int ao = light >> 16;
vAO = ((ao == 0) ? uAOTable.x :
(ao == 1) ? uAOTable.y :
(ao == 2) ? uAOTable.z : uAOTable.w) / 255.0;
vLight = unpackLight(light & ((1 << 16) - 1));
`
)
.replace(
"#include <worldpos_vertex>",
`
vec4 worldPosition = vec4( transformed, 1.0 );
#ifdef USE_INSTANCING
worldPosition = instanceMatrix * worldPosition;
#endif
worldPosition = modelMatrix * worldPosition;
vWorldPosition = worldPosition;
`
),
fragment: ShaderLib.basic.fragmentShader
.replace(
"#include <common>",
`
uniform vec3 uFogColor;
uniform float uFogNear;
uniform float uFogFar;
uniform float uSunlightIntensity;
uniform float uMinBrightness;
uniform float uTime;
varying float vAO;
varying vec4 vLight;
varying vec4 vWorldPosition;
#include <common>
`
)
.replace(
"#include <envmap_fragment>",
`
#include <envmap_fragment>
// Intensity of light is wavelength ** 2
float s = min(vLight.a * vLight.a * uSunlightIntensity * (1.0 - uMinBrightness) + uMinBrightness, 1.0);
float scale = 2.0;
outgoingLight.rgb *= vec3(s + pow(vLight.r, scale), s + pow(vLight.g, scale), s + pow(vLight.b, scale));
outgoingLight *= vAO;
`
)
.replace(
"#include <fog_fragment>",
`
vec3 fogOrigin = cameraPosition;
float depth = sqrt(pow(vWorldPosition.x - fogOrigin.x, 2.0) + pow(vWorldPosition.z - fogOrigin.z, 2.0));
float fogFactor = smoothstep(uFogNear, uFogFar, depth);
gl_FragColor.rgb = mix(gl_FragColor.rgb, uFogColor, fogFactor);
`
),
}; For all the textures used in the project, I made sure that they had This is the link to the shader source, and this (and this) is to the material code. |
I don't think the shader code matters. I just tried using a |
It could be, is the Now that you're using an import { RenderPass } from 'three/addons/postprocessing/RenderPass.js'; // replace
// composer.addPass( new WboitPass( renderer, scene, camera ) );
// with
composer.addPass( new RenderPass( scene, camera ) ); |
After running |
This is interesting... The problem still occurs on transparent objects. |
Hmm, another thought. Are you doing any passes in
Does that make a difference? |
Seems like this problem happens to other people too. This is @donmccurdy's solution: link. I will try to dig deeper into |
I'm not sure that is the same issue, your colors seem off differently than the colors in that post. Do you have a link to a specific texture that you are having this issue with? It would be nice to have a minimal example... It shouldn't be necessary, or desired, but someone also suggested to try setting
I would be curious if that made a difference. You could try changing the encoding on the main render target in
|
Okay, I think I've solved it. The blending methods used in I have updated the library and the build on npm. To use: import { sRGBShader } from 'three-wboit'; // replace
// composer.addPass( new ShaderPass( GammaCorrectionShader ) );
// with
composer.addPass( new ShaderPass( sRGBShader ) ); |
Thanks for your help so far! I just tried out the Here's the source code for my example: Let me see if I can setup a minimized example somewhere so it's easier to reproduce the problem. |
Very interesting.. It could be an issue with At then in your fragment shader ( Add the uniforms:
And at the very end, add the wboit code:
And then in
|
Hmm, well I just tested it with Does the darkness / blackness go away if you set opacity to a lower value, like 0.5? |
Let me try. I'm creating a tiny project and am trying to reproduce the problem. Thanks for your help man 💯 |
For my actual project, setting opacity to 0.5 doesn't change. I'm starting to wonder whether or not it's the TextureAtlas class's fault 🤔 |
Ok here's the project: link On the left is using the same texture generated from the texture atlas, but without doing |
Okay, thanks I'll take a look |
Okay, so using the original However, I think that's because in your file |
The background has to be black, not white. Try adding at top of
|
Hmmm.. I see on your machine the one on the right is also slightly brighter. Could it be that my monitor gets affected more by the Wboit pass? I found out that if I turn the material to double side, it would become even brighter, but when I turn the opacity down a bit it isn't as bright. |
It is strange. But, the one on the right is brighter because the renderer's write buffer has partially transparent pixels from the WboitPass and the background color is mixing with the renderers output. That's why setting the background to black should fix the issue. It's possible your monitor is then taking the resulting pixels and applying more correction on them. Even though visually the two objects should look the same on a black background. The one on the left has an alpha value of 1.0, where the one on the right varies, but in that picture has an alpha value of 0.5. In which case for two pixels to look the same with different alpha values the RGB values must be greater, and then in turn get affected more by any correction your monitor is doing after. The point of the sRGBShader I added was to convert the alpha value to 1. I am going back to it and working on some more tests... |
Alright, how does (https://stevinz.github.io/three-wboit/vox/VoxTest.html) look on your machine? Try adjusting the opacity slider as well. |
Wait it looks exactly the same on both sides! How is this done? |
Well, the blending methods used in wboit create alpha values that are different then standard blending. They seemed to be causing a problem on your monitor (and I'm guessing others would have the same issue). So before doing gamma correction in the I have temporarily put the source on the repo (https://github.com/stevinz/three-wboit/tree/master/example/vox) |
This is not related to the issue, but I wanted to mention it while I was thinking about it. Since you're working with sRGB encoded textures, and then doing some manual rebuilding into a texture atlas and working with
After setting |
Got it. Thanks so much for the help! |
Hi, great work! How could I get this to work with
THREE.sRGBEncoding
forrenderer.outputEncoding
?The text was updated successfully, but these errors were encountered: