I am trying to create visualization of Earth Moon System (Or maybe full solar system in the future) and I found this amazing shader that dynamically applies day and night textures to Earth parts based on lightning.
There is one issue with that solution. I can’t see any way to apply other maps like bump map or specular map.
They were really nice before applying the shader and I really want them back.
When researching the topic I’ve seen that you can create other maps that are dynamically modified.
I am looking for a way to modify these shaders to apply other static maps while keeping dynamic main map
Vertex Shader
varying vec2 vUv;
varying vec3 vNormal;
varying vec3 vSunDir;
uniform vec3 sunDirection;
void main() {
vUv = uv;
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
vNormal = normalMatrix * normal;
vSunDir = mat3(viewMatrix) * sunDirection;
gl_Position = projectionMatrix * mvPosition;
}
Fragment Shader
uniform sampler2D dayTexture;
uniform sampler2D nightTexture;
varying vec2 vUv;
varying vec3 vNormal;
varying vec3 vSunDir;
void main(void) {
vec3 dayColor = texture2D(dayTexture, vUv).rgb;
vec3 nightColor = texture2D(nightTexture, vUv).rgb;
float cosineAngleSunToNormal = dot(normalize(vNormal), normalize(vSunDir));
cosineAngleSunToNormal = clamp(cosineAngleSunToNormal * 5.0, -1.0, 1.0);
float mixAmount = cosineAngleSunToNormal * 0.5 + 0.5;
vec3 color = mix(nightColor, dayColor, mixAmount);
gl_FragColor = vec4(color, 1.0);
}
Material Setup
const earthmaterial = new THREE.ShaderMaterial({
uniforms: {
sunDirection: {
value: new THREE.Vector3(1, 0, 0)
},
dayTexture: {
value: earthtexture
},
nightTexture: {
value: earthnighttexture,
}
},
vertexShader: dayNightShader.vertex,
fragmentShader: dayNightShader.fragment,
})