| We hope you enjoy your visit. You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you are already a member please log in to your account to access all of our features: |
| how to render depth map and compare pixel depth DX8? | |
|---|---|
| Tweet Topic Started: Nov 4 2010, 08:50 AM (576 Views) | |
| 3da | Nov 4 2010, 08:50 AM Post #1 |
|
Advanced Member
![]() ![]() ![]() ![]() ![]()
|
Hello, what i need is know how to render depth map using PSS, then how compare depth of shadow map(depth map) and object texture depth. i tried to find solution via web, found this codes, but i am little confused of imput. ps_1_1 // Mask to copy red component to all components. def c0, 1.0, 0.0, 0.0, 0.0 def c1, 1.0, 1.0, 1.0, 1.0 // dummy non shadow color def c3, 0.5, 0.5, 0.5, 0.5 // helper for comparing depth //------------------------------------------- // t0 contains the shadow map texture coordinates. // c0 is color mask, c1 is non shadow color (usually 0, 0, 0, 0) // and c2 is shadow color (0, 0, 0, 0.5). The alpha component // is the important part here because we use alpha blending to // darken areas where the shadow is. // v0 holds the depth of the current pixel from the light source. // t1 holds the half of the depth value for comparing above 0.5 // for skipping everthing above our visible depth. //------------------------------------------- // Sample shadow map texture coordinates tex t0 texcoord t1 // Copy red color to all channels (need that for comparing) dp3 r0, t0, c0 // Compare depth value (c0) with shadow map depth (v0) // Use -0.5 bias for cnd formula (comparing to +0.5) // This is the only way to compare values in ps_1_1. sub r0.a, r0.a, v0_bias //cnd r0, r0.a, c1, c2 cnd r1, r0.a, c1, c2 // Compare depth, everything above the farplane should be unshadowed sub r0.a, c1.a, t1//_bias //mov r0.a, t0_bias cnd r0, r0.a, r1, c1 //mov r0, t1 //mov_x2 r0, t0 // Just return that What i need to pass to oT1? How pass depth from light to v0? Thx in advance for any help... |
![]() |
|
| Dr. Best | Nov 4 2010, 05:35 PM Post #2 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Out for shadow mapping, aye? That is difficult to do with Ultimate 3D. You will need specific shaders for every combination of light sources and model transformation types. It certainly would be easier to use the built in stencil shadows. Implementing soft shadow mapping in Direct3D 8.1 is close to impossible anyway and hard shadow mapping looks bad, because the shadows are pixelated. If you want to do it anyway, I can give you some hints, but it is really quite complicated. |
![]() |
|
| 3da | Nov 7 2010, 01:39 PM Post #3 |
|
Advanced Member
![]() ![]() ![]() ![]() ![]()
|
first thx for reply.. wanted to implement 1directional light hard shadowmap shadows with self cast i cannot use stencil shadows cause i need texture alpha blended shadows (trees etc.) i am using ortho camera (directional light) with pss (depth map) caster/reciever using projection mapping shader to map depth map but then comes the depth comparison problem to correctly self cast and remove shadow from objects closer to light camera. i need mainly those hints: 1) how to render correct depth map (directional light camera view) 2) how to set correct values for z-bias 3) finally how to effiently compare values lightdepth - caster/reciever texture depth thx in advance for any hint |
![]() |
|
| Dr. Best | Nov 7 2010, 02:47 PM Post #4 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
There is a complicated way and a rather simple way. The complicated way is to use a copy of each shadow caster and to render it with a special vertex shader that renders depth values. The easy way is really quite simple. It uses fog to do the job: 1) Make sure that none of your shadow casters uses an emissive material color. 2) Create an additional shadow map camera in a special room and make it render to a texture. 3) Make sure that all shadow casters are visible in that special room. 4) Make sure that all light sources and ambient lighting do not effect this room. 5) Set up white fog, while you render to the shadow map. Use the near clipping plane of the camera as start distance and the far clipping plane as end distance. What is important is that all shadow casters are absolutely black, if there is no fog. This is why all lights and emissive lighting need to be disabled. If that is given it should work reliable. Experiment with different values. Your shadow map will have just eight bit depth, so you will probably need a relatively large value. 0.02 might be a good point to start experimenting. The best choice is the one, which yields the fewest artifacts. Though you probably won't get rid of all artifacts. The key is the cmp shader instruction. Here's how what you need to do in more detail: 1) Sample the value from the shadow map. To do this you need to use the method from the projection shader. 2) Get the depth of the pixel. You need to compute this depth in the vertex shader. Then you can pass it to the pixel shader through a texture coordinate register and retrieve it through the texcrd instruction. 3) Add the bias to the shadow map value using add. 4) Subtract the depth of the pixel from the biased shadow map value using sub. 5) Use cmp to compare the resulting difference to 0.0. If the difference is positive, the pixel is lit, so you pass the lighting color for src1. Otherwise it is in the shadow, so you pass a constant holding 0.0 for src2. A useful optimization would be to subtract the bias from the pixel depth in the vertex shader. This way you can get rid of one add instruction in the pixel shader. |
![]() |
|
| 3da | Nov 7 2010, 03:08 PM Post #5 |
|
Advanced Member
![]() ![]() ![]() ![]() ![]()
|
thx a lot !!! |
![]() |
|
| 3da | Nov 8 2010, 11:01 PM Post #6 |
|
Advanced Member
![]() ![]() ![]() ![]() ![]()
|
tried a bit but got 2 more qs if possible ![]() 1st: can i compute pixel depth just using v0.w transformed to light proj space or do i have to trace vo to light camera distance? 2nd:texcrd clamps to [-8, 8]. so _d8 pixel depth.rgb data? |
![]() |
|
| Dr. Best | Nov 8 2010, 11:43 PM Post #7 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
1st: Transform the vertex position into the projection space of the shadow map camera. The z-coordinate of the result is the depth value you need. 2nd: That's worth a try. It makes things a bit more complicated, but might increase the precision a little. On the other hand the precision of the texture coordinate probably won't be much of a problem. The 8-bit depth of the shadow map is more problematic. |
![]() |
|
| 3da | Nov 9 2010, 12:49 AM Post #8 |
|
Advanced Member
![]() ![]() ![]() ![]() ![]()
|
thx |
![]() |
|
| 3da | Nov 10 2010, 01:25 PM Post #9 |
|
Advanced Member
![]() ![]() ![]() ![]() ![]()
|
i tried hard but it still doesnt work, ill post code, prolly i do something wrong...thx i advance for any clue got shadow camera with fog 255,255,255, dir light to 0, ambient 0, material of objects 0,0,0,255 in vs 1.1 i got(i post only code for shadow mapping) m4x4 r1, v0, c50 // to world space m4x4 r2, r1, c4 // to view space m4x4 r1, r2, c54 // to projection space mov oT3, r1.z // pass pixel depth as tex coord, dunno if its clamped to [0,1] ps 1.4: // sample shadowmap texld r3, r5 // Light proj space pixel depth from vertex shader texcrd r5.rgb, t3 // rgb value is clamped to what range?? //mov_sat r5.rgb, r5 add_sat r3.rgb, r3, c4.x // add bias for correction sub r3.rgb, r3, r5 cmp r3.rgb, r3, c1, c2 result r3 should be b/w lightmap? |
![]() |
|
| Dr. Best | Nov 10 2010, 06:32 PM Post #10 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Could you post the *.ufx file as well and/or comment on the contents of the constant registers? In the vertex shader you need transformations of the shadow map camera and getting those is not trivial. Especially the projection space matrix is a little hard to get, but I can link you to the formulas. It can be found on this page and this image gives the relevant matrix. For debugging purposes I recommend that you use the sampled shadow map texture coordinate and the computed depth value as pixel color (i.e. move them to r0). This way you can actually see what happens in your shader. You can also pass the shadow map depth to r0.r and the other depth to r0.g. Then you can take screenshots and compare the values with an image processing software. |
![]() |
|
| 3da | Nov 11 2010, 02:06 PM Post #11 |
|
Advanced Member
![]() ![]() ![]() ![]() ![]()
|
u use pass shadow camera tranform matrix scripts from softer shadows demo, think its correct cause got no problems with correct shadow camera projection onto objects. but strange thing is that when i mov pixel depth (texcrd r1.rgb, t3(passed r1.z from v0 transformed to light proj view) to r0 reciever object gets full white. ill rather try hard to check all parts with your clues, dont wanna bother.. ill post if break through thx finally got cast/selfcast shadows problem was that i forgot sub near clip from vertex projected z and divide by far ![]() although shadows arent detailed as stencil and suffer from some 8bit z bias issues , they work clear with boned geometry and alpha transparency. Edited by 3da, Nov 18 2010, 11:53 AM.
|
![]() |
|
| « Previous Topic · Questions about Ultimate 3D · Next Topic » |





![]](http://z1.ifrm.com/static/1/pip_r.png)




9:12 PM Jul 11