[WIP] Cool pick

I am trying to experiment between different shadow mapping approaches:
I really only need global illumination in my game, and it has to be vast. My idea is to use

this code is on git hub github.com/treeform/panda3d-CSM

Cascading Shadow map:

On pictures above i used single high resolution camera

added some shadowing

Here i use 3 low resolution cameras to just shadow the place i am at, and father, and global shadow.

Hmm it looks like “tex2Dproj” works bad.

I get much better result with the fall back mechanism:

  float4 proj = l_shadowcoord / l_shadowcoord.w;
  float mapval = tex2D(k_Ldepthmap,proj.xy);
  float shade = (mapval > proj.z);

Looking at it more i think tex2Dproj expects the shadow texture to be some how reversed.

The only difference between tex2DProj and tex2D is that tex2DProj should do the perspective divide (by w) for you, while tex2D does not. If tex2DProj doesn’t work correctly, that sounds like a driver bug, or your w coordinate is not right.

well am just using the standard shadow code and tex2DProj is significantly worse then the other method.

New pics:

You can see different shadows are cased by different shadow cameras huge cam, med cam and then close up cam.

A better algorithm needs to be made to get around that push bias thing - its killing me.

I found the push bias thing to be totally unnecessary.
My golden rules for shadows:

  • Disable color write for the shadowcam render. This gives at least a 300% performance increase. You can try to disable shaders for the shadowcam render too, if they don’t do any deformation.
  • The shadowcam render MUST be backwards culled. Only the backsides of surfaces must cast shadows, this completely entirely removes the artifacts, as the backfaces of objects are dark anyways (if you cut off the dot product at 0, which should be done anyways)
  • This won’t fix it for objects which are infinitely thin, use glPolygonOffset for those. E.g, something like:

Or, in 1.7.0, you can write:


(you can also specify this in the egg file, with the “depth-offset” scalar)

After this, the self-shadowing artifacts / moire patterns should be gone entirely and makes you able to set the push bias to 0 (get that ugly code out of your shader! :slight_smile: )

PS. The shadow system found in latest CVS Panda does all these things for you.

That does produce much better stuff - but there is still problem with paterns on the back faces - its not very noticeable but the artefacts is still there.

I haven’t seen this suggested before. Sounds like a great idea!

treeform, that’s because you only have shadows, not shading. The back faces of objects are always shadowed anyways, so making polygons facing away from the light black solves the artifacts - normal dot product shading does this.

that is true, but the backface is not 100% black, what if i have ambient lighting and stuff. That causes problems. I want to solve that with shadows only.

That’s why you should first calculate the shadow values for each individual light, darken the backsides, and after that apply the ambient lighting.

Yeah that worked great. Now i just need to move it all into screen space :slight_smile: