   distance field shadow maps
  I´m developing a project for which i need very very hard shadows, like stencil-volumes hard, but using shadowmaps. I´ve been toying around with the idea of generating 2d distance fields from shadowmaps and using them to perform the shadow test. Right now, this is my method: 4 averaged custom bilinear filtering taps on 4 different shadow test results to generate a pseudo-distance field. The output looks a lot like 3x3 bilinear filtered pcf. Then i alpha test it (>=0.5?) to obtain the final shadow.The image shows a 512x512 shadowmap. The results are ok for my needs, although since it is not a true distance field, small "wavy" artifacts can be seen on the edges of the shadow (highlighted in red). It naturally  eliminates all self-occlusion artifacts due to the alpha-testing, though. But of course, the shadow jitters when moving, because of the low shadowmap resolution, but that can´t be helped. Here´s where i need a bit of help to get it 100% right: Does anyone know a good way (...or any way :( ) of generating a true distance field from a relatively low res bilinearly filtered input, so that the wavy artifacts disappear? Has anyone tried this before and managed to get it working properly?I was thinking of a method that involved using a variation of marching squares  on the shadow map instead of bilinear filtering, then computing distance to the resulting segments. But it will look too "segmented" and probably be very slow too. Bilinearly filtering the shadow test twice might give good results too, but it is also an ugly hack. Some ideas?   
  Intersting stuff!Quote:Original post by ArKano22Bilinearly filtering the shadow test twice might give good results too, but it is also an ugly hack. Some ideas?How about cubic filtering? There is an approach decribed in GPU Gems 2 (available free here) which implements cubic filtering in terms of linear filtering. I recall reading on the NVidia forums that it runs at about half the speed.   ;Quote:Original post by PolyVoxHow about cubic filtering? There is an approach decribed in GPU Gems 2 (available free here) which implements cubic filtering in terms of linear filtering. I recall reading on the NVidia forums that it runs at about half the speed.Wow, there´s some nice filtering going on there. I´m going to try it because the ouput seems much more usable that my current one. thank you!!   ;  damn... I had an idea like this after reading how valve does decals in team fortress. Every good idea I have is taken :PLooks good, I'll be interested to follow your progress.   ;  Don´t worry, it is not a really good idea :P. The problem is that valve generates the distance field from a high-res image. Here, i´m stuck with a low-res shadow map. If i compute a distance filed as usual, the jaggies show up in the reconstruction too.I´ve tried with a different distance field computation method where i store an average distance instead of the minimum distance, but it has problems with capturing fine details... the shadow looks like a blob, all round edges. I´ve also tried bicubic filtering but the results were similar to x1 bilinear filter. At the end, the x4 bilinear filter method i was using before gave the best results, so i´ll stick to it. I´ll post the glsl code later if anyone is interested.   ;  They use this technique for baked shadow maps in the Unreal engine. In that instance, they can generate a huge shadowmap to get a really nice distance field before downsizing (and storing in a DXT texture IIRC). This graphicrants blog post talks a little bit about it: http://graphicrants.blogspot.com/2009/11/udk.htmlT   ;Quote:Original post by TessellatorThey use this technique for baked shadow maps in the Unreal engine. In that instance, they can generate a huge shadowmap to get a really nice distance field before downsizing (and storing in a DXT texture IIRC). This graphicrants blog post talks a little bit about it: http://graphicrants.blogspot.com/2009/11/udk.htmlTThat´s the best use-case possible for this. If you can precompute the field from a high-res source, the results are almost flawless :). Did´t know about its use in the unreal engine, thanks for the link!   ;I finally managed to remove all artifacts using the mean-distance field mentioned before. The image shows a 256x256 shadowmap, with and without distance field.It has the same "antialiasing" proposed in valve´s decal paper, which softens the edge a bit. Speed wise is slower (like x3 slower) than standard shadowmapping, but it pays off with quality.Time to choose a name for this... dfsm sounds good enough :). Code in the next post.   ;  Hey, the results looks amazing.I've implemented valves algorithm too (for gui icons ;-) ). When I understand your approach, you will not perform valves algorithm directly on the shadowmap, right ? (this would be like blurring a shadowmap which results in shadow artifacts). You need to process the already projected shadow to get 0/1 values (like the UDK lightmaps). In your case this would be the screen or an upscaled buffer containing the screen projected shadow. It's like screenspace shadow blurring. You can archive similar results as the valve algorithm by just blurring the image (I've to look up the link,sry), it might be simpler or faster then generating a distance field (blur is separable).;  Got the link which was posted by Hodgman in this thread.   