I have a World with a 3D model of a head in it and that World rotates, like such:
protected override void Update(GameTime gameTime)
{
//other stuff
angle += 0.00005f;
//more other stuff
}
protected override void Draw(GameTime gameTime)
{
//other stuff
Matrix rotation = Matrix.CreateRotationY(3 * angle);
effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));
// other stuff
}
And then in my Effects file I create a spotlight:
float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
float4 lightDirection = { 1, 1, 1, 0 };
float theta = 10.0f;
float phi = 30.0f;
float4 color;
float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));
float angle = acos(dot(input.lightDir, normalize(lightDirection)));
if(angle > radians(phi))
color = AmbientColor * AmbientIntensity;
else if(angle < radians(theta))
color = lambert;
else
color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
return color;
}
And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.
Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.
Edit: my vertexshader:
VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff
float4 lightPoint = {-3, -2, -2, 0};
output.lightDir = normalize(input.Position3D) - lightPoint;
output.lambertLightDir = float4(30, 30, 20, 0);
return output;
}
edit2: I am using xna