Point Light Shadows?

I was trying for the last hour or so to make point (omni) lights cast shadows.

The best thing I came up with is a point-spot combo, it’s not that bad, but not quite the thing.
It looks a bit better ‘live’ (if you look very, very closely you can actually spot the shadows on the screenshot):

code+model+textures if anyone is interested:

Is there any other/better way to do it (apart from ‘write a custom shader’)?

Is there any hope that omni lights could cast shadows via the shader generator some day?

I’ve worked on it a few times. There have been a few issues with cube maps and depth buffers in Panda, so it hasn’t progressed very fast. I haven’t gotten a chance to get back to it yet, but I should have some time sometime soon. Feel free to poke me for updates in a few weeks.

If it won’t be too much additional work, maybe a method to smooth (blur) the shadows could also be implemented?

What kind of algorithm did you have in mind?

Honestly? I don’t know. I see everyone talking about PSSM shadows these days, but I’m not sure.

Here are some examples of smooth shadows I found:
[Soft Shadows)
[Paraboloid Shadow Map + PCF Smooth)

Demomaster has one too, but you need to edit the program a bit to not crash on 1.8.

The shader is located in “demomaster-0.8/share/shaders/softshadow.sha”.


void vshader(float4 vtx_position : POSITION,
             float2 vtx_texcoord0: TEXCOORD0,
             float3 vtx_normal: NORMAL,

             uniform float4x4 trans_model_to_clip_of_light,
             uniform float4x4 mat_modelproj,
             uniform float4 mspos_light,

             out float4 l_position : POSITION,
             out float2 l_texcoord0 : TEXCOORD0,
             out float4 l_shadowcoord : TEXCOORD1,
             out float  l_smooth : TEXCOORD2,
             out float4 l_lightclip : TEXCOORD3
  l_position = mul(mat_modelproj, vtx_position);
  l_texcoord0 = vtx_texcoord0;
  l_smooth = saturate(dot(vtx_normal, normalize(mspos_light - vtx_position)));
  //float4 pushed = vtx_position + float4(vtx_normal, 0);
  float4 pushed = vtx_position + float4(vtx_normal*0.2, 0);
  l_lightclip = mul(trans_model_to_clip_of_light, pushed);
  l_shadowcoord = l_lightclip * float4(0.5,0.5,0.5,1.0) + l_lightclip.w * float4(0.5,0.5,0.5,0.0);

void fshader(in float2 l_texcoord0 : TEXCOORD0,
             in float4 l_shadowcoord : TEXCOORD1,
             in float  l_smooth : TEXCOORD2,
             in float4 l_lightclip : TEXCOORD3,
             uniform float4 attr_color: COLOR,
             uniform sampler2D tex_0 : TEXUNIT0,
             uniform sampler2D k_depthmap : TEXUNIT1,
             uniform float4 k_props,
             uniform float4 k_texDisable,
             out float4 o_color:COLOR)
  float3 circleoffs = float3(l_lightclip.xy / l_lightclip.w, 0);
  float falloff = saturate(1.0 - dot(circleoffs, circleoffs));
  //float4 baseColor = saturate(tex2D(tex_0, l_texcoord0) + k_texDisable.x);
  float4 baseColor;
  float4 proj = l_shadowcoord / l_shadowcoord.w;
  float shade = 1 - saturate((proj.z - tex2D(k_depthmap, proj.xy)) * k_props.y);
  //o_color = baseColor * (shade * falloff * l_smooth + k_props.x);
  if (k_texDisable.x > 0)
      o_color = attr_color * (shade * falloff * l_smooth + k_props.x);
  else {
      baseColor = tex2D(tex_0, l_texcoord0);
      o_color = baseColor * (shade * falloff * l_smooth + k_props.x);

(demomaster also seems to have a PSSM shader).

Anything else I found was for PSSM:
[PSSM Shadows)
panda3d.org/forums/viewtopic … c&start=30 (3rd post from bottom)

Some articles:
http.developer.nvidia.com/GPUGem … _ch10.html

That’s all I know.

So shadows for point lights would use cube maps and use ~6x more gpu power as spotlights?
Not very good news for me.

Soft shadows would be a great addition to Panda3D. Just saying.

Any new news?

No, I haven’t been able to do a lot of work on Panda in the last few weeks, as I’ve been fighting off a disease.

Get well soon.


Is any of this on some TO DO list or just forgotten?

I can submit the idea to the bugtracker if it helps :wink:

I’ve been focusing on fixing important bugs for 1.8.1. A bug report would help, thanks.