Game Development Community

Need lighting help

by Will O-Reagan · in Torque X 2D · 06/30/2010 (5:21 pm) · 9 replies

I'm trying to have some objects get lit within a scene. A few problems I have is

1. "all objects seem to be very Dependant on the position of the camera". This was solved by modifying some source, so that the camera always appeared to be to the right of the object. This helped tremendously, but its still a little odd when you are actually to the left of the object, and the object appears pretty dark.

2. The "point" light, seems to direct light in 270 degrees, and I'd like it to do a 360 degree light.

Otherwise, the bugs seem to be few and far between and lighting seems like alot of fun. Just those issues irk us a bit.


Thanks

About the author

I have a degree in dramatic art, and literature, from UC Santa Barbara. I've worked for a few studios, also at Animax Ent in 2008, and some smaller studios. Currently studying Computer Science at CSU Channel Islands.


#1
07/01/2010 (9:50 am)
Ok, I figured out this was probably an issue with my normal maps.
#2
07/03/2010 (1:10 am)
Ok, I'm back to thinking its an issue with the engine, just too much about the lighting doesn't make sense... heres a screenshot of a work in progress, that seems to be having issues with the light scheme.

www.modernintrigues.com/bugreporting/lightingbug.png
The stats for that light is Point Light: Constant Attenuation: .5, Linear Attentuation.5, then (0,0,0), (.5,.4,.4), (.75,.75,.75)
#3
07/03/2010 (10:18 am)
I'm thinking this issue is resolved on my end a bit, basically I just cut out my specular lighting, and things seem hunky dory, but I'm a bit confused why this isn't an option on the T2DLightComponent.
#4
08/04/2010 (6:13 pm)
spec lighting is controlled in the material itself.
spec lighting calculation is wrong in the simipleshader file.
object rotation isn't calculated at all on the normal maps in the simipleshader file either.

if you want torque to work as advertised (as always) you have to rewrite parts of it properly yourself. that's just the way it goes.

The lighting calc issues haven't been adressed since before v2 so don't hold ur breath.

best of luck.
#5
08/05/2010 (1:04 am)
In the LightingEffect2D.fx PixelLightingPS function this will orient the
normals to whatever rotation the object is at

after the line float3 normal add
float specular = 0.0;

// after the line normal.xyz = normalMap.xyz * 2.0 - 1.0; add
normal = mul(normal, _worldMatrix);
normal = normalize(normal);

For specular lighting, in the same PixelLightingPS function change in the for loop
if(doSpecular)
     lightDirection += lightVector * attenuation;

// change to this
if (doSpecular)
{
     float3 halfVector = normalize(lightVector + float3(0.0, 0.0, 1.0));
     float3 reflectVec = normalize(reflect(-lightVector, normal));
     specular = pow(saturate(dot(reflectVec, halfVector)), _specularPower) * specularScalar;
}
// add the specular to this line
lightColor += ((_lightDiffuse[i] * lightAmount) + _lightAmbient[i] + specular) * attenuation;

After the line color.a *= _opacity;

delete the doSpecular if statement and everything in it, you can also delete the float lightDirection = 0.0 line

Also in the PixelLightingSpecularTechnique change
PixelShader  = compile ps_2_0 PixelLightingPS(3, false, true);

// to this
PixelShader  = compile ps_2_0 PixelLightingPS(2, false, true);

and in PixelLightingSpecularNormalMapTechnique change
PixelShader  = compile ps_2_0 PixelLightingPS(3, false, true);

// to this
PixelShader  = compile ps_2_0 PixelLightingPS(1, false, true);





#6
08/06/2010 (7:29 am)
Hmm, well with or without doing specular lighting, these changes you propose don't seem to be an improvement over my solution of just cutting the specular lighting. Not sure whats happening, any chance you can send me your .fx file and I can try it again?

-Will
#7
08/06/2010 (7:09 pm)
@ Will

Yes, I can send you the .fx file I currently use, but it requires other changes from the associated classes in the engine, which I can send you as well.

In addition to the specular lighting, the changes I've made allow lighting to be correct on rotated and flipped objects, and for Point Lights placed in behind objects to not light everything in the layers in front of them. All these use version 3.1.5.
#8
08/08/2010 (3:34 pm)
Ok, I'm certainly interested. Can you get me something at regan.bill@gmail.com? I have some other lighting things I need to look at as well. I actually have a light testing demo as well, were getting pretty good results over here at Project Gert, Modern Intrigues (see my latest blog). But were still open to improve the situation, there are flaws in the lighting as good as its getting, still flaws.
#9
08/08/2010 (4:45 pm)
@ Will

Changes sent, if you have any questions or issues with them, just let me know.

-Alex