jPCT-AE - a 3d engine for Android > Support

Moving spot light

<< < (2/2)

Thomas.:
Yes, position is wrong, only light direction should by in camera space... change "lightPos[2]" to "lightPositions[8]". And loops is not good to use in the mobile shaders. Better way is to use "if(lightCount >= 0) { ... if(lightCount >= 1){...}}" or generate the specific shader.

iblis:
"lightPositions[8]"? Should I use Light class and set position of lights like this?

--- Code: ---this.carBody.object3d.getTransformedCenter(position);
light.setPosition(position);

--- End code ---
Does the Light class set "lightPositions[8]"?
This a result.

The light rotates with the camera ;/ But it should rotate with the car. Moreover the car moves right, but the light moves left. I think it works the same earlier.
Vertex Shader:


--- Code: ---uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform vec3 lightPositions[8];


uniform vec3 lightDir[2];

attribute vec4 position;
attribute vec3 normal;

varying vec3 eyeMV;
varying vec3 normalMV;
//I want to use 2 lights, but one is easier to test
varying vec3 lightPosMV[2];
varying vec3 lightDirMV[2];

void main(void)
{
normalMV = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz;

vec3 vertex = (modelViewMatrix * position).xyz;
eyeMV = -vertex;


lightDirMV[0] = normalize(lightDir[0]);
lightPosMV[0] = normalize(lightPositions[0] - vertex);

gl_Position = modelViewProjectionMatrix * position;
}
--- End code ---

Thomas.:
Axises of light direction is probably inverted. Try this:


--- Code: ---dirBuf[i].y *= -1;
dirBuf[i].z *= -1;
--- End code ---

iblis:
The direction is correct :) JPCT coordinates != OpenGL coordinates :)
But sth is wrong with position.

--- Code: ---car.carBody.object3d.getTransformedCenter(position);
light.setPosition(position);

--- End code ---
The position of the red box is 0, 0, 0.

The car (bigger red box) moved  to 0, 0, -20. The light changed x and z coordinates.

Navigation

[0] Message Index

[*] Previous page

Go to full version