Game Development Community

Is the point light specular error?

by 3Dgame · in Torque Game Engine Advanced · 12/10/2007 (12:01 am) · 5 replies

I add a object with a specular material to the scene.
It was rendered ok in the sun light.
But when I add a point light near it,I can't see a correct specular rendered.
I found the shader generated to see how it work.

OUT.outLightVec.xyz = -inLightVec;

It use the Vertex Const VC_LIGHT_DIR1 to define the light Direction,and use this to generate specular.
But this is a point light,not a direction light.
So I think this is a error.

And the direction is always (0 0 1).

How can I make the point light work OK?

#1
12/11/2007 (5:34 pm)
Can anyone help me?
#2
12/12/2007 (10:11 am)
The difference between omni and directional light is that they both have color and direction, but omni also have a position.

In the vertex shader if:
uniform float3 inLightPos : register(VC_LIGHT_POS1)
uniform float3 inLightDir : register(VC_LIGHT_DIR1)
......
OUT.hpos = mul(modelview, IN.position);

then need to convert it:
float3 render = normalize(inLightPos - OUT.hpos);
distance = length(inLightPos - OUT.hpos);


In the fragment shader use them.

float N = normalize(normal);
NdotL = max(dot(N,normalize(inLightDir)),0.0);
if (NdotL) {here use to create the attenuation;}
#3
12/14/2007 (12:32 am)
But the problem is that the shaderGen of TGEA don't support the specular for the omni light!
#4
12/14/2007 (3:48 am)
Yupp, there were no omni lights when it was implemented most likely.
#5
12/14/2007 (10:22 am)
Then use to modify outLightVec to point the omni's direction (disable sun's specular and use it for the omni).