Forums > Jitter

Error in my shader for per pixel point light?

May 22, 2012 | 2:42 am

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.

– Pasted Max Patch, click to expand. –
Attachments:
  1. dalespot.jxs

May 22, 2012 | 9:49 am

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.

[attachment=194423,3914] [attachment=194423,3915]

Attachments:
  1. Capture2.PNG

May 22, 2012 | 11:49 am

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.


May 22, 2012 | 1:15 pm

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! :)


May 23, 2012 | 10:45 am

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)

[attachment=194543,3922] [attachment=194543,3923]

Attachments:
  1. step7.png

Viewing 5 posts - 1 through 5 (of 5 total)