我需要创建静态光(相机移动不变),并且我需要在片段着色器中获取光的实际位置。
我现在在做什么:
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);
比在片段着色器中我设置统一变量:
uniform vec3 spotLightPosition;
并计算体素的光:
float dProd = max(0.0, dot(getGradient(posInCube), normalize(lightPos
- posInCube)));
voxelColored.rgb = voxelColored.rgb * dProd + voxelColored.rgb * 0.2;
问题是,它不能正常工作。我的想法是,我将随着物体移动(实际上是用相机)。光仍然会从同一侧发光(在场景中是静态的)。这时光线不是静止的,工作很奇怪。
任何的想法?请问有人...
坦克很多。托马斯