I'm currently working on creating static light that remains constant regardless of camera movement, and I need to retrieve the actual position of the light within the fragment shader.
Here is my current setup:
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(60, canvas.width() / canvas.height(), 1, 10000);
camera.position.z = 2000;
camera.lookAt(0, 0, 0);
var light = new THREE.SpotLight(0xFFFFFF, 1);
light.position.set(0.5, 0.5, 0.1).normalize();
camera.add(light);
....
var lambertShader = THREE.ShaderLib['lambert'];
uniformsVolume = THREE.UniformsUtils.clone(lambertShader.uniforms);
....
materialVolumeRendering = new THREE.ShaderMaterial({
uniforms: uniformsVolume,
vertexColors: THREE.VertexColors,
vertexShader: vertVolumeRendering,
fragmentShader: fragVolumeRendering,
vertexColors: THREE.VertexColors,
lights :true
});
....
scene.add(camera);
In the fragment shader, I set a uniform variable:
uniform vec3 spotLightPosition;
and calculate the light for each voxel:
float dProd = max(0.0, dot(getGradient(posInCube), normalize(lightPos - posInCube)));
voxelColored.rgb = voxelColored.rgb * dProd + voxelColored.rgb * 0.2;
The issue I'm facing is that the light behavior is not as expected. I want the light to remain static even when moving the object (essentially the camera). Currently, the light source moves along with the camera instead of being fixed in the scene.
Any suggestions or ideas would be greatly appreciated.
Thank you. Tomáš