Shadow Mapping on Linux & ATI

Shadow Mapping does not seem to work properly in Panda v1.4.2, using Linux with ATI graphics.

Sample-Programs–Shadows fails with “Video driver cannot create an offscreen buffer.” (as do a few other samples).
But the workaround suggested by treeform in
depth texture (shadows) problems for x600 on both w&l does get the demo to run, although the shadows are not right. The teapot casts a shadow, but the panda does not. Also teapot does not cast shadows on itself.


{{Click a pic to see it 800x600}}

Same problem with ynjh_jo’s code at
Regular hardware shadow mapping (no filtering).
Again, the teapot casts a shadow but not the room nor the actors inside.

Problem seems to be with tex2Dproj() in the fragment shader.

According to some comments on the Web, tex2Dproj() does not work properly in ATI drivers. Alternatively, it could be that “texture was not configured for depth compare texturing”, says the Cg doco.

In shadow.sha of the Sample-Programs–Shadows, I replaced

float shade = tex2Dproj(k_Ldepthmap,l_shadowcoord);

by

float shade=tex2D(k_Ldepthmap, l_shadowcoord.xy/l_shadowcoord.w).x;
shade=step((l_shadowcoord.z/l_shadowcoord.w), shade);

Shadows are now much better – but is this how they are meant to look?

Panda v1.4.2
Ubuntu 7.04 (Feisty Fawn)
ATI Radeon X1950 Pro (yes, I know, I’ll get nVidia next time)

Are other ATI+Linux people getting this sort of thing?

Dude! You are my hero!

You fixed my shadows too! I had the exact same problem as you have. Only i thought it was more or less normal for a while :slight_smile:

I had:
Panda v1.4.2
Ubuntu 7.04 (Feisty Fawn)
ATI Radeon X600 Mobility (i been happy with this card ATi soon to come out with oss drivers)

I haven’t run this demo, but yeah, that’s what unfiltered depth shadows look like. Enabling texture filtering will partly smooth out the jaggies, and using a higher resolution shadow buffer will reduce the size of the jaggies.

Adding ambient lighting into the shader will allow shadowed parts of models to get some lighting applied to not appear pitch black (as will using multiple light sources, but this requires an additional render pass and shadow buffer for each light source).

Arkaein, do you know turn my unfiltered depth shadows to filtered?

It’s really odd why it didn’t work at all. Here on my nVidia card I get perfect filtered shadows, without having to modify anything.

pro you are using “tex2Dproj” while are using Ffeuuell’s method. Maybe there is some alteration we can do Ffeuuell to enable better smoothing?

Seems to be specific to ATI cards, not nVidia. I’ve no idea whether problem is with card, or Linux driver, or how Panda talks to them.

“perfect filtered shadows” does that mean you do not have jagged edges on shadows? Can you show us a picture?

Cg documentation implies that nVidia’s tex2Dproj() might smooth the edge with greys instead of jumping black-white, but it is not clear. They give details for all the easy functions, but become suddenly vague about all the different texture map functions. That’s why I asked whether my pics looked right.

Yes, that’s correct, as you can see, if you take a very close look :

it’s the blue-highlighted part.

I don’t know about ATI cards, but here my nV does the what-they-call-freePCF, both tex2d and tex2dproj. And from your shot, you don’t seem to have them for free.

The jaggy edges is not avoidable since the shader doesn’t do any filtering. If you really want heavyweight soft filter, try nVIDIA’s PCSS shader. I guess you can use FXcomposer2 to convert it to Cg.

or, if you want sharp edges near the camera’s frustum, try TrapezoidalShadowMapping, it’s brilliant !! :slight_smile:

I’m not sure. The place where I’ve done projected shadows is in OpenGL, and in that case the difference was made in the texture itself by using linear filtering. However this was for non-shader based shadowing, when I did different shader based shadowing it didn’t work out like this and I got the aliasing.

I guess the first thing I would do is try modifying the filtering type of the depth texture using this info:

panda3d.org/manual/index.php/Texture_Filter_Types

Other than that you can Google for Percentage Closer Filtering (PCF), which is the type of filtering done to smooth the edges. Modern graphics hardware can do this automatically with no performance loss. To do it in a shader you basically compare the projected depth texture coordinate of the pixel being rendered, which is a fractional coordinate, and you compare it to the surrounding integer projected depth texture coordinate, and if some are shadowed and some aren’t you apply weighted shadowing based on the distance from the shadowed and unshadowed texels. However I didn’t figure out how to enable this automatically in my shader without performing the extra texture lookups manually (and with a performance penalty).

I don’t think it’s possible, Arkaein, since P3D reserves the usage of min/mag texture filter to mark the texture as depth map, to allow hardware-depth-comparison to be done.