Hi there
i’m new at custom shader
i use glsl format, and i want to add light into my planets. There is a few documentation about adding light into custom shader. i wonder how do i add light into my custom shader?
Here is my code :
Mercury.js
import * as THREE from "three";
//Import Shaders
import vertexShader from "../shaders/venus/vertex.glsl";
import fragmentShader from "../shaders/venus/fragment.glsl";
//Object Using shader material
export const venus = new THREE.Mesh(
new THREE.SphereGeometry(35, 40, 40),
new THREE.ShaderMaterial({
vertexShader,
fragmentShader,
uniforms: {
Texture: {
value: new THREE.TextureLoader().load("../../assets/Texture/venus.jpg"),
},
},
})
);
vertex.glsl
varying vec2 vertexUV;
varying vec3 vertexNormal;
void main() {
vertexUV = uv;
vertexNormal = normalize(normalMatrix * normal);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
fragment.glsl
uniform sampler2D Texture;
varying vec2 vertexUV;
varying vec3 vertexNormal;
void main() {
float intentsity = 1.05 - dot(vertexNormal, vec3(0.0, 0.0, 1.0));
vec3 atmosphere = vec3(0.7, 0.7, 0.7) * pow(intentsity, 1.5);
gl_FragColor = vec4(atmosphere + texture2D(Texture, vertexUV).xyz, 1.0);
}