Several ways about ESM

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
mengzhu
Posts: 28
Joined: Fri Jul 17, 2009 7:00 am

Several ways about ESM

Post by mengzhu »

After some hard searching on net(so hard),I found a entire tutorial http://thecansin.com/tag/exponential-shadow-maps/
(though it's mainly about deferred shading & on XNA),and though the author has written a very detailed tut,1st,I can't see ESM's effect(not the .fx file,just the effect...) from his example,I used his techniques in my codes,I can't find many superiority like VSM than the normal SMs...the author just encode depth to a form of exponential
Last edited by mengzhu on Wed Jun 29, 2011 6:47 pm, edited 6 times in total.
mengzhu
Posts: 28
Joined: Fri Jul 17, 2009 7:00 am

Post by mengzhu »

and,I found another guy's pixel shader codes on ESM http://www.truevision3d.com/forums/anno ... 293.0.html
you can see ,he 's done a PSSM+ESM and wrote
...
float shadow = saturate(exp(max(ESM_MIN, ESM_K * (occluder - receiver))));
...
his calculation is not much like that xna lessons author 's ,I wonder how he save the depth?

The final edit,I suddenly hate all SM,such as esm evsm ,i think many guys have already written things maybe named as PSEVSM ...
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

It`s been a while since I tried ESM, so I may mislead you somehow and for some weird reason I cannot find my test app, may be in my old pc, but here are some things I still recall (still would be nice if someone else shares his/her opinion):

For ESM you do:

1) Store exponential depth. IIRC I`ve seen different ways doing so like a 0-1 depth, Z/W (clip spaced) and then storing its exponential or linearly with the viewPos.xyz/viewPos.w

2) Apply some logarithmic filtering on the shadowmap

3) Get the shadow value (with the occluder-receiver code)
I can't see ESM's effect
What exactly do you expect to see? It`s nothing but some gradient looking SM. The way it`s easily recognised is that the shadows it generates usually look darker with distance increase, but it basically depends on what you do.
I can't find many superiority like VSM than the normal SMs
What do you mean? It`s not looking as nice as VSM or what?! See, all SM techniques have their pros and cons, one have better performance, but more artifacts etc. Usually you decide and use one and that`s it.
the author just encode depth to a form of exponential,then I ask, it does the prefiltering?
No, he needs to filter his shadowmap, or it will look bad (well, nonfiltered).
The final edit,I suddenly hate all SM,such as esm evsm ,i think many guys have already written things maybe named as PSEVSM ...
As a last note I hate them too, but if I need to use some SM, I will get over it and use it. See, the SMs don`t care whether you love them or not, right?! :D
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
mengzhu
Posts: 28
Joined: Fri Jul 17, 2009 7:00 am

Post by mengzhu »

I really thank you from my heart, yesterday I thought no one would answer my mumbling :D ; I won't beg you for the source now~,it 's not polite because you need to open your old PC;

But I still wonder how to save the depth for the example above?If you and other masters have time ,then give a reply or share a example :D :
...
#define ESM_K 50.0f // Range [0, 80]
#define ESM_MIN -0.5f // Range [0, -oo]
#define ESM_DIFFUSE_SCALE 1.79f // Range [1, 10]
....
float occluder = tex2D(depthMap, uv)[splitIndex]; // this is sure for PSSM
float shadow = saturate(exp(max(ESM_MIN, ESM_K * (occluder - receiver))));
return 1.0f - (ESM_DIFFUSE_SCALE * (1.0f - shadow)) ;
...

his way is likely from this famous man 's short blog http://pixelstoomany.wordpress.com/2008 ... mple-code/
that ESM theory use a limit calculation to make a approximation of PCF ,as a eternal newbie I feel it's a trick indeed,e.g. : exp( k(Oi-R) ) is lim to 0 ...
And I suddenly hate the author mentioned in 2nd floor :D ,I can't find his vertex shader on net,and when I save the depth as normal SMs do,I still can see a shadow~~~(just the color is not so black like normal SM's and of course can be scaled by ESM_DIFFUSE_SCALE ) :lol: , I feel funny,this let me remember the time I first touch VSM,that VSM source was wrong copied by a guy (he hasn't copied ddx() ddy() but just a Chebyshev inequality)

People say ESM is not that difficult to implement ,but most of them hide the codes~ :D Though I also find some guy's codes in their SVN trunk, their code is hard or need long time to analyse,and I got a EVSM source but written in DX11(my baby HD4850 not support),though dx11 is not the key problem,I will have to spend long time on reading its codes if I really want to know the secret.
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

I won't beg you for the source now~,it 's not polite because you need to open your old PC;
No, it`s ok, as it`s quite dirty and nothing special and I definitely didn`t invented sth new. Problem is that my old pc`s in my basement and is missing a PSU (donated to a friend), so it`s my lazyness and lack of time more than anything else.

But, I googled it a bit and I found a topic I used some code from:
http://forum.quest3d.com/index.php?topic=66112.0

Note that it was when I was experimenting with a deferred pipeline, so it may be a bit different.
If you and other masters have time
Haha! I`m really flattered, but I`m a forever-noob-type just like you, the only difference is that I`ve already tried this thingy. But I admit there are many graphics masters and excellent programmers in the shadows around us. :D
People say ESM is not that difficult to implement ,but most of them hide the codes
I don`t quite believe this to be true, probably you`re just not searching enough. I remember I found many articles about it, and even there was one comparing performance and quality in PCF, VSM, ESM...

I believe you`ve taken some parallel split ESM or sth alike that`s making the things harder to get. Basically the code in the link I posted is the "heart" of ESM. :)
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
mengzhu
Posts: 28
Joined: Fri Jul 17, 2009 7:00 am

Post by mengzhu »

Glad to talk with you,you are a warm-hearted man indeed.
The page you give to me http://forum.quest3d.com/index.php?topic=66112.0 is a "famous ESM web page" I think,I did found it before,and another guy(seems like a master :D ) said dont use that code because it is "wrong wrong wrong",he just did a little change,if you are interested in it you may take a look at his page
http://nolimitsdesigns.com/tag/exponential-shadow-map/
Now,,I think I'll be quiet now,I ’ve said too much words and made you spend too much time on this :D
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Re: Several ways about ESM

Post by omaremad »

I am a big fan of this technique, and currently using it in irrlicht, however i dont understand which part isnt working for you, post code and some screenshots and i will be glad to help out, its a simple and very effcient technique compared to other shadow mapping schemes.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
mengzhu
Posts: 28
Joined: Fri Jul 17, 2009 7:00 am

Re: Several ways about ESM

Post by mengzhu »

omaremad wrote:I am a big fan of this technique, and currently using it in irrlicht, however i dont understand which part isnt working for you, post code and some screenshots and i will be glad to help out, its a simple and very effcient technique compared to other shadow mapping schemes.
Thank you for your warm helping. Maybe you've seen,I 've tried the way mentioned in 2nd floor and see a shadow,but don't know if I'm right.Since every body says ESM is simple to implement,but why even ShaderX6 and above link 's codes are still buggy?so would you share your codes?It's seems no need to hide it :D ;However,then I can compare every versions and know things in those ESM white papers clearer ,and after some days,maybe other "eternal newbie"s would thank you too~ Allah bless you
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Several ways about ESM

Post by devsh »

I'm not a fan of z warping techniques.. I am a firm believer in linear depth for shadow maps. cause its fine if you have exponential depth with a camera, so you get appropriate precision on near objects... but the frusta of the light and camera are independent so z quality has to be consistent unless you have a magical way of making the map exponential around any given target depth.
mengzhu
Posts: 28
Joined: Fri Jul 17, 2009 7:00 am

Re: Several ways about ESM

Post by mengzhu »

Hello again, masters,now I think I understand that XNA lessons author's esm codes and run out a good shadow.At first ,I did something wrong with translating something from deferred shading codes(the magic thing is,I can still get a shadow by that wrong way :D ,I 've said ,this situation is like the time I met a wrong vsm example).
Post Reply