Hello, webgl expert. Hope you are doing well.
I have some issues in my WebGL site, and I can’t find good solution.
For now, I’m using shader for floating image plane, and I would like to add light reflecting effect to the plane.
But there are no light in this plane.
this.material = new THREE.ShaderMaterial({
extensions: {
derivatives: “#extension GL_OES_standard_derivatives : enable”,
},
side: THREE.DoubleSide,
uniforms: {
time: { type: “f”, value: 0 },
distanceFromCenter: { type: “f”, value: 0 },
texture1: { type: “t”, value: null },
resolution: { type: “v4”, value: new THREE.Vector4() },
uvRate1: {
value: new THREE.Vector2(1, 1),
},
bendY: { type: “f”, value: 0 },
bendZ: { type: “f”, value: 0 },
},
// wireframe: true,
// lights: true,
transparent: true,
vertexShader: vertex,
fragmentShader: fragment,
});
uniform float time;
uniform float progress;
uniform float distanceFromCenter;
uniform sampler2D texture1;
uniform vec4 resolution;
varying vec2 vUv;
varying vec3 vPosition;
float PI = 3.141592653589793238;
void main() {
vec4 t = texture2D(texture1, vUv);
float bw = (t.r + t.b + t.g) / 3.;
vec4 another = vec4(bw, bw, bw, 1.);
gl_FragColor = mix(another, t, distanceFromCenter);
gl_FragColor.a = clamp(distanceFromCenter, 0.2, 1.);
// gl_FragColor = vec4(0.,1.,0.0,1.)
}
//vertex.glsl
uniform float time;
uniform vec2 pixels;
uniform float distanceFromCenter;
uniform float bendY;
uniform float bendZ;
varying vec2 vUv;
varying vec3 vPosition;
float PI = 3.141592653589793238;
void main() {
vUv = (uv - vec2(0.5)) * (1.2 - 0.2 * distanceFromCenter * (2. - distanceFromCenter)) + vec2(0.5);
vec3 pos = position;
pos.y += sin(PI * uv.x) * bendY;
pos.z += sin(PI * uv.x) * bendZ;
pos.y += sin(time * 0.3) * 0.02;
vUv.y -= sin(time * 0.3) * 0.02;
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
}
This is the video link: forum.mp4 - Google Drive
Thanks for reading.