Obtaining Light Info for Custom Shaders
by Sean H. · in Torque Game Engine Advanced · 12/28/2007 (8:05 am) · 1 replies
I'm having problems using a custom shader with tgea's integrated lighting system. I'm attempting to use the VC_LIGHT_POS1(C23) and PC_DIFF_COLOR(C2) registers for obtaining light info.
I have a custom shader I wrote which initially used a hard-coded light position in world space and a hard-coded light color. It's my first shader and I'm very proud of it. :) This shader worked fine in the engine and in showtool with constants for the light position and color. However, when I tried to change the shader to use the info passed in C23 and C2 registers, I always get incorrect results in the engine. When I attempt to use VC_LIGHT_POS1 in the vertex shader, i get a black object because this value's not being intialized properly. When I attempt to use PC_DIFF_COLOR in the pixel shader for the light's color, I get an object that's all gray with no texture or lighting.
The funny thing is that this same shader works fine in showtool. Using this shader in showtool, I get an object which is correctly lit. Changing the lighting color correctly dynamically changes the color of the object. It seems as if when I use showtool, C23 and C2 registers are properly initialized, but during a running mission, the sgLightObject isn't registering it's dynamic light info. Of course I'm using the default "greenlight" from features.mis. I know it's always possible for there to be errors with the shader code. I always check the console for errors when I run the engine. I've hit a point where I get no errors, but it's still not working.
I've tried playing around with some of the light parameters in the light's datablock. my reasoning was that it may be using a particular directional lighting method and thus not have a light position. but no matter what I change the parameters to, it still doesn't work. I may be missing some key info here.
I also tried setting the "dynamicLightingMaterial" parameter of the material to an identical material defined right before it. I basically just made a duplicate material to handle the dynamic lighting. This didn't work either. Again, no console errors, and no lighting. In fact, using the "dynamicLightingMaterial" parameter breaks the shader in showtool.
I'm at a loss. I don't know if I need to modify the light, or the material settings. The only thing I really need is the light's position, the shader can take care of the rest. Has anyone else experienced problems using VC_LIGHT_POS1(C23) in a custom shader?
I have a custom shader I wrote which initially used a hard-coded light position in world space and a hard-coded light color. It's my first shader and I'm very proud of it. :) This shader worked fine in the engine and in showtool with constants for the light position and color. However, when I tried to change the shader to use the info passed in C23 and C2 registers, I always get incorrect results in the engine. When I attempt to use VC_LIGHT_POS1 in the vertex shader, i get a black object because this value's not being intialized properly. When I attempt to use PC_DIFF_COLOR in the pixel shader for the light's color, I get an object that's all gray with no texture or lighting.
The funny thing is that this same shader works fine in showtool. Using this shader in showtool, I get an object which is correctly lit. Changing the lighting color correctly dynamically changes the color of the object. It seems as if when I use showtool, C23 and C2 registers are properly initialized, but during a running mission, the sgLightObject isn't registering it's dynamic light info. Of course I'm using the default "greenlight" from features.mis. I know it's always possible for there to be errors with the shader code. I always check the console for errors when I run the engine. I've hit a point where I get no errors, but it's still not working.
I've tried playing around with some of the light parameters in the light's datablock. my reasoning was that it may be using a particular directional lighting method and thus not have a light position. but no matter what I change the parameters to, it still doesn't work. I may be missing some key info here.
I also tried setting the "dynamicLightingMaterial" parameter of the material to an identical material defined right before it. I basically just made a duplicate material to handle the dynamic lighting. This didn't work either. Again, no console errors, and no lighting. In fact, using the "dynamicLightingMaterial" parameter breaks the shader in showtool.
I'm at a loss. I don't know if I need to modify the light, or the material settings. The only thing I really need is the light's position, the shader can take care of the rest. Has anyone else experienced problems using VC_LIGHT_POS1(C23) in a custom shader?
Torque 3D Owner Ilusis