Hello everyone!
I’m kinda stuck with SkyMaterial shader modification.
I want to implement day/night cycle as a night background image use simple texture with .png as source.
Here is the part of the shader code (pic1)
vec4 texture = texture2D(nightSky, uv);
vec4 color = clamp(vec4(retColor.rgb, alpha), 0.0, 1.0);
vec4 nightSkyColor;
if (uv.y < 0.5) {
nightSkyColor = clamp(texture, 0.0, 1.0);
}
float luminance = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
// float darkness = 1.0 - luminance;
nightSkyColor *= luminance;
color += nightSkyColor;
And here is the invertsion:
vec4 texture = texture2D(nightSky, uv);
vec4 color = clamp(vec4(retColor.rgb, alpha), 0.0, 1.0);
vec4 nightSkyColor;
if (uv.y < 0.5) {
nightSkyColor = clamp(texture, 0.0, 1.0);
}
float luminance = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
float darkness = 1.0 - luminance;
nightSkyColor *= darkness;
color += nightSkyColor;
The question is on the surface what’s wrong? I wanna get nice transition between bright sky and starry sky.
Maybe color value (normalization???) issue?
PS:
Unfortunatelly I cant provide sandbox link cuz its local sandbox (from contribution Guide).
But here is the code im using to set the texture:
const skyMat = new BABYLON.SkyMaterial('sky', scene);
const nightTexture = new BABYLON.Texture('https://i.postimg.cc/z8gwvY9n/skysphere-transparent2.png?dl=1');
nightTexture.coordinatesMode = BABYLON.Texture.SPHERICAL_MODE;
nightTexture.hasAlpha = true;
skyMat.setNightSkyTexture(nightTexture);
skyMat.sideOrientation = 0;
skyMat.inclination = .49;
skyMat.alphaMode = 1;
sphere.material = skyMat;
// Move the sphere upward 1/2 its height
sphere.position.y = 1;
sphere.useVertexColors = sphere.hasVertexAlpha = false;