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.
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
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.
The whole cone mostly white/grey with a little red in it.
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.
----------begin_max5_patcher---------- 628.3ocyWtsaaCBFG+ZWo9Nf70YQ13X6jck2ywTkE1l5PDF7.RSZq1693Pbi aaRSUSHqJRlv2A3O+3ffmu8lfvJ9VrLD7SvuAAAOqsDXsYrDLXHHrCsslhj1 .C6vRIpEGNYmSEdqx5ngH64x8NXq6HLJVYSCNX8dNSwPcXaJ+RPPzwIvWqFx HdvLowFKuZ0ORV7RvtHUO1icxOLDb239PRdx5IFNMZvdORUujvZKE3ZkKs3Y YZ+f3EolhTnsx7oQf6r472auwTpKlb9.RfQMfFDEWpAkZ5psRuxp7KMqRhFg p3n4W.VwvazZ88nZEQMskNkRZWp.EFkC54Dl5v.K9h.rYY9AXv4NfAsEvHeB L4RTCV.JtmPwudoFnv.l81tTjDd.RB+.RpEZYGRIHaCmblbcGPyy8OWaEjFM a0KCKbE0bl9+BtBoC8wm.QfEQ5OE6l.tNXN8Zf4jYVLmjOyyXdCg0v2.TXoW oVbxwoVEh09040Ln6.RWw7qv1cAlYVsYPFn.KPRbYMmxEfH6uXPg8DzxVJuB QKQcUDLSosa85SJm6KHmLlwI4YdDxJPEvBUeBprSCJmFNCZk6tbiOOm7OcXk fCRi74UZROAqNCD4NjK6RrmUwaaomZMyoGrviOXMWDZ+X83aRdYzLLl1mhPO GnvhRLCUQssazaFvtnCoD16dgfsGMNdCFj70h5AQtawMXT21nOmhvPJBmMJn 7WGzRRSC15+kYM8KKLpr4PxbxWTVwe+jU5mgVYWcYYdz0o0E7+fvx+lJL3mQ Womkr1s6D02+.VH20xNEoOMZEWXpmMwUmvb0csr9cnOPFRIUaw1p5O+CgZ6o NC -----------end_max5_patcher-----------
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:
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)