Error in my shader for per pixel point light?
Working from a tutorial to create a per-pixel point light shader, I am unable to see why my shader misbehaves. I should see a cone pointing right which is shaded with white/grey and a little red. The bad behavior is that I see only the tiny tip of the code in red and everything else is black.
Below is patcher. Attached is shader.
Repro:
1. Save attached shader to a directory
2. Create patcher from code below and save into same directory.
3. Click toggle to turn on metro
4. Click read dale_spot.jxs message box
Result:
Most of cone is invisible. Only a tiny bit of red is on the tip of the cone. This red is coming from the global ambient.
Expected:
The whole cone mostly white/grey with a little red in it.
Note:
You can click the dispose messagebox to kill the shader and see the plain code, and then read the shader back in to see the same errant behavior.
Hi,
As far as I can see your shader works as you expect. (on win7 x64, max6).
But I am a GLSL beginner aswel.
Do you want to add your point light to the standard lighting in max?
This would not work (methinks) as you cannot use the fixed functions together with a shader.
Img1: Your patch with your shader.
Img2: The same with different colors for global_ambient and light_diffuse.
Wow. I agree with you. It does work. I tried it on a 2nd PC w/ a different graphics card and got the same good results as you. I will try and simplify/isolate until I get the problematic function on my card. Thank you!
There are limited ways to use fixed functions with a shader. In this case, I am just using the GL light (via the jit.gl.light) to store lighting params which I then use in the shader. The normal GL lighting engine/renderer isn't use.
Ha, great to hear you found the culprit. At least machine wise.
I did not know for sure you could use the max gl.objects for easy parameter storing. Thanks for pointing out! :)
I found a workaround. Step 5 (attached) is an example of the errant behavior. On graphic card/drivers which experience this kind of problem with a shader applied to a 3D object, try setting these attributes on that 3D object:
lighting_enable=1
auto_material=0
Setting these attributes appear to cause no harm if you don't have the problem. While also fixing the errant behavior if you do have the problem.
It results in correct lighting like in step 7 (Attached)