Variance Shadow Mapping for the Sun

Posted By: Slin

Variance Shadow Mapping for the Sun - 01/04/08 02:39

I played around with shadowmapping for a cuple of weeks now and had an other breakthrough yesterday. That resulted in support for the sun with a quite high shadowresolution near to the player.

This is how it works:
I render three depthmaps from three views at the position of the sun. They are all facing the camera but have different arc values. Now when calculating the shadows I always use the depthmap with the highest resolution possible.

This is WIP and needs a lot of more work but I already like to show it of.
Things I know about:
-The shadows are one frame behind the camera.
-There is a lot of aliasing on the shadows.
-When shadows are overlapping there are sometimes non shadowed parts which should be shadowed.

The depthmapresolution used here is 512*512.

I would like to get some feedback on how it works on your computer and what you think about it

Thanks,
Slin

A screenshot and the download:

Download (3.15mb)

You can move the sun around with q and e. You have to press 0 before you can move around and you can open the debugpanel through pressing F11.
Posted By: Nems

Re: Variance Shadow Mapping for the Sun - 01/04/08 03:25

Sorry slin, couldnt review it on my pc, the demo shows up no probs but no shadows which I presume is higher shader requirements than my system has (1.1 I think).
Posted By: DavidLancaster

Re: Variance Shadow Mapping for the Sun - 01/04/08 03:25

Looks pretty cool!

Wish I could play the demo, when I first ran the exe got and error about missing 'd3dx9_30.dll' so I copied it into the directory when I ran again got a crash...I have no idea what it could be.
Posted By: Nems

Re: Variance Shadow Mapping for the Sun - 01/04/08 03:34

@ DavidLancaster, that happened to me too but then I used the other exe to get a view in, does that mean I used the wrong one?
Posted By: Ready

Re: Variance Shadow Mapping for the Sun - 01/04/08 07:17

It just crashes for me and says something non specific (VSM_main.exe encountered a problem and must be closed bla bla bla)
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/04/08 08:39

It needs Shadermodel 2.0.
You probably need the d3dx_35.dll (http://www.dll-files.com/dllindex/dll-files.shtml?d3dx9_35) to run it, because it needs a simple plugin which uses the directx SDK... But I am not sure about it-_-
Thanks for testing
Posted By: Loopix

Re: Variance Shadow Mapping for the Sun - 01/04/08 09:41

That looks promissing...althoug I can't run it. It crashes on my GTS 8800 with no specific error messages.

Slin, please keep on working on it! Once it is more stable...would you be willing to release the full source (for further public improovement!)?
If yes...I suggest to make a sponsor call and you could decide to release the full source after you 've got a certain amount of money (100-200$?). If you prefere to sell the stuff and become real rich...that's fine too

Is there any chance to get rid off the SetLightMatrices.dll...set the matrices somehow in c-script and still being able to use this shadow method in A7??
Posted By: Rasterbar

Re: Variance Shadow Mapping for the Sun - 01/04/08 09:51

I have the the same Crash.

Quote:

It just crashes for me and says something non specific (VSM_main.exe encountered a problem and must be closed bla bla bla)



Posted By: William

Re: Variance Shadow Mapping for the Sun - 01/04/08 09:51

I tried it out, and put the dll in the folder with the demo, but still no luck. Looks quite interesting though.
Posted By: TSG_Christof

Re: Variance Shadow Mapping for the Sun - 01/04/08 09:54

Geforce 7950 GX2 (Shader Model 3.0) Graka and it is Crash.
Posted By: Pappenheimer

Re: Variance Shadow Mapping for the Sun - 01/04/08 10:16

Same here! Probably a missing file.
Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/04/08 10:19

I've got a crash here too when running the .exe. Even when putting the correct dlls in the map
When I tried to run the compiled version, it works but no shadows appeared.
Looks very promising though

Thanks in progress

Frazzle
Posted By: adoado

Re: Variance Shadow Mapping for the Sun - 01/04/08 12:08

I got it working on my machine: 7600GT with 60fps. It looks awesome, shadows are still sharp but very promising!

Also, this SetLightMatrices DLL - did you make this? I am guessing it generates the view matrix or something similar for the light, is there any chance you will release how to use it and if we can use it

Looks very awesome!

Thanks,
Adoado
Posted By: Mythran

Re: Variance Shadow Mapping for the Sun - 01/04/08 16:50

Crashed with me too. Maybe a bad compilation?
Have you tested it Slin? I have shader 3.0 too...
Posted By: Slin

Variance Shadow Mapping for the Sun - 01/05/08 00:53

Quote:


Is there any chance to get rid off the SetLightMatrices.dll...
set the matrices somehow in c-script and still being able to use this shadow method in A7??




It is all written in Lite-C and I wasnīt able to get the functionality of the dll in Lite-C...

I am going to release the full code when everything works fine.
I thought about selling it but a sponsor call is probably a good idea


Quote:


It looks awesome, shadows are still sharp but very promising!




I know how to blur them more but had some wierd problems when trying that yesterday,
but I will look into it more deeply very soon.

Quote:


Also, this SetLightMatrices DLL - did you make this?
I am guessing it generates the view matrix or something similar for the light,
is there any chance you will release how to use it and if we can use it




I created that DLL. I need it to pass more than one custom matrix to shaders.
It is actually very simple but I plan to expand it to help me with some other stuff as well
You can use it for everything you want to.
You have to use it like that:
-Put the dll in your plugindir.
-Place these lines on top of your scripts:
Code:

dllfunction SetCustomMatrix(char *Name, float *Matrix); //passes a custom matrix to a shader
dllfunction SetCustomVector(char *Name, float *Vector); //passes a custom matrix to a shader


-Call the function you want to use in the event of the material you want to pass the matrix to:
Code:

SetCustomMatrix("MatName", ArrayWith16Values);
SetCustomVector("VecName", ArrayWith4Values);


-You can than acces the Vector and the Matrix in the Shader like this:
Code:

float4x4 MatName;
float4 VecName;



This is the sourcecode of the dll:
Code:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <math.h.>

// engine specific header file
#define DLL_USE // always define before including adll.h
#include "adll.h"
#include <d3dx9.h>

// DLL main entry point - normally this needs not to be changed
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
// make sure the library is linked
engine_bind();
return TRUE;
}

LPD3DXEFFECT *A7_eff;

DLLFUNC void SetCustomMatrix(char *Name, float *Matrix)
{
D3DXMATRIX matCustom = (D3DXMATRIX)Matrix;

A7_eff = (LPD3DXEFFECT*)ev->render_d3dxeffect;
if(A7_eff)
{
LPD3DXEFFECT(A7_eff)->SetMatrix(Name,&matCustom);
}
}

DLLFUNC void SetCustomVector(char *Name, float *Vector)
{
D3DXVECTOR4 vecCustom = (D3DXVECTOR4)Vector;

A7_eff = (LPD3DXEFFECT*)ev->render_d3dxeffect;
if(A7_eff)
{
LPD3DXEFFECT(A7_eff)->SetVector(Name,&vecCustom);
}
}



The problem for the errors is that this dll doesnīt get loaded on many computers (it works fine on my computer...)... -_-

Here is a short clip of the shadows until I solve the problem with the dll:
http://www.youtube.com/watch?v=JL8NIaTpGTo

Thanks for all those comments
Posted By: mpdeveloper_B

Re: Variance Shadow Mapping for the Sun - 01/05/08 01:26

i'd pay about $10-$20 but that's entirely up to you.
Posted By: Lutz_G

Re: Variance Shadow Mapping for the Sun - 01/05/08 10:22

20-50USD.
Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/05/08 10:34

@Slin :

But I wonder why we get a crash due too the dll since it doens't get loaded anywhere in the code yet ??
Btw, that isn't an easy dll

Thanks in progress

Frazzle
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/05/08 12:58

Quote:


But I wonder why we get a crash due too the dll since it doens't get loaded anywhere in the code yet ??




I use the functions of the dll. That causes the crash. 3DGS just does not load the dll on most systems but it does on some (it works perfectly on my computer-_-).
Posted By: Excessus

Re: Variance Shadow Mapping for the Sun - 01/05/08 13:15

Quote:

I use the functions of the dll. That causes the crash. 3DGS just does not load the dll on most systems but it does on some (it works perfectly on my computer-_-).




Did you create the plugin with VC++? Maybe those users have to install the vcredist.exe? Or you have to distribute the libraries another way.
Posted By: adoado

Re: Variance Shadow Mapping for the Sun - 01/05/08 15:39

Its wierd, it worked on my machine. I could list my specs but I doubt very very much this is a hardware issue

Not sure why people are having trouble with it...
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/05/08 16:43

Quote:


Did you create the plugin with VC++? Maybe those users have to install the vcredist.exe? Or you have to distribute the libraries another way.




I compiled the dll with VC++ 2008 Express... It doesnīt seem to help to install the vcredist.exe for vc++ 2005. But I didnīt find newer?
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/05/08 20:23

Here is a new screenshot of the shadows with softer edges than before:

Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/05/08 22:01

Looks better and better Slin but the aliasing effect is still quite noticeble present
But I hope you get a new demo soon which is capable of running on most of our machines ^^

Cheers

Frazzle
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/05/08 22:05

Thank you frazzle
I have to play around with the parameters a bit more or maybe use a fourth depthmap...

I just got the problem fixed that the shadows were one frame to late. Here is a new clip: http://www.youtube.com/watch?v=CtBjXkKmYUw
Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/05/08 22:14

Looks quite good Slin
Btw, will adding more depth maps not cause higher aliasing effects ??

Thanks in progress

Frazzle
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/06/08 01:19

Quote:


Btw, will adding more depth maps not cause higher aliasing effects ??




Nope, that has nothing to do with each other It just allows me smoother steps between the different qualities.

I compiled the dll with an other compiler and it seems to work now
You can download the new Version here:
http://files.filefront.com/VSM+Sun+V2/;9386545;/fileinfo.html
I just swapped to an bigger depthmap resolution (1024*1024*32) which makes it look a bit better but is quite slow and needs a good graphicscard. But there is quite a bit of space for optimisations
Turn around with the mouse and move with WASD or the arrow keys. Move the sun around with q and e.
I hope that it works this time

And yeah I know there is still a lot to do... But I hope that I am on a good track

Edit: If it doesnīt work try updating your DirecX version (http://www.microsoft.com/downloads/detai...;DisplayLang=en).
Posted By: ello

Re: Variance Shadow Mapping for the Sun - 01/06/08 01:48

hi, ich hab folgendes problem hier:


beim umschauen taucht die schattenmap mal hier und mal da auf. und wie im bild zu erkennen ist, ist der schatten zerschippelt und die position scheint nicht zu stimmen. gpu: gforce 6800 ultra
Posted By: Joozey

Re: Variance Shadow Mapping for the Sun - 01/06/08 02:19

With your first demo I got a crash with no specific details for the cause. This demo does not crash anymore, but there are some severe errors.

ATI Mobility Radeon X1600
Updated to DX 9.2xxwhatever
Also installed the DLL somehwere in this thread


Posted By: chaotic_dragon

Re: Variance Shadow Mapping for the Sun - 01/06/08 09:26

Very nice work Slin i am truely impressed keep up the good work.

- Dragon -
Posted By: Rasterbar

Re: Variance Shadow Mapping for the Sun - 01/06/08 10:03

Hi, the new version don't crash, but this is what i see:

in the distance on the terrain there are shadow fields.
Graka: geforce 7600 gt
Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/06/08 11:05

The demo works great with a constant of 60 fps
But the reason I thought more depth maps would cause more aliasing is because you use conditional requests (if-else branching) to call them. Thus an import remark is that conditionals in pixel shaders can cause aliasing and since you're planning to use 4 depth maps, the amount of conditionals requests will rise and so will the aliasing effect

Cheers

Frazzle
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/06/08 15:31

Okay, I didnīt know that frazzle

For those with just one big black shadow: I think that your graficscard doesnīt support 1024*1024 pixels rendertargets.
At the moment I am trying to figure out the reason for the missing transparency...
ellos problem is a bit strange -_-

But anyways, here is a new screenshot:

Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/06/08 15:33

Quote:


Okay, I didnīt know that frazzle





Well now you know it
Nice screen btw

Cheers

Frazzle
Posted By: Scorpion

Re: Variance Shadow Mapping for the Sun - 01/06/08 18:24

hey slin that looks cool now. I love your work with shadowmapping. But I am too lazy to get in there

PS: if you are ready with that you have to start with that..."so-farer-away-the shadow-the-more-bluring-thing"
Posted By: fogman

Re: Variance Shadow Mapping for the Sun - 01/06/08 20:29

The latest version works for me, but Iīve got the same problems as Rasterbar.
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/06/08 20:46

Okay here is an other demo. It should work for most of you but with the costs of a lower quality. This demo uses a depthmapsresolution of 512*512 and 16bit floatingpoint format. The version before used 1024*1024 and 32bit floatingpoint...
The lower depth causes some artifacts in the variance part but I already have an idea on how to reduce them
I included a firstperson camera and I added some animated boxes Lutz_G gave me for that reason .
And as he proposed I now fade the shadows out in the distance.
Here is the downloadlink:
http://files.filefront.com/VSM+Sun+V3/;9391415;/fileinfo.html

This is what this version looks like:

Posted By: fogman

Re: Variance Shadow Mapping for the Sun - 01/06/08 21:15

Quote:

And as he proposed I now fade the shadows out in the distance



Would be nice to give us a way to tweak this variable.
Apart from the artifacts it runs well at 75 fps.
Posted By: Joozey

Re: Variance Shadow Mapping for the Sun - 01/07/08 13:06

Lol, doomstyle


At least no odd black squares anymore just low fps and blocky shadows ^^.
Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/07/08 20:06

As for the fps, I still get a constant of 60 which is a great point but it would be even better if those annoying artifacts would be totaly
gone The shadows are great, no doubt about that but I still reckon that with out the use of conditionals, you would get a scene with better visual content thus without aliasing effects
I found an article which covers anti-aliasing through centroids, can be handy.

Cheers

Frazzle
Posted By: ello

Re: Variance Shadow Mapping for the Sun - 01/08/08 18:57

yea, good improvement so far. here is a little shot of some artifacts on the rotating cubes for which there may be a solution...



maybe you can try one of those ideas or even combine both. what about rendering the depth path with inverted CullMode.. i always fail when the question is which one. i guess its CCW so you see draw the backsides for the depth calculation

and you could offset the vertexpositions a bit:
In.position.xyz += (In.normal.xyz,matWorldViewProj)*factor;

maybe you already tried that? if not, it could be worth a shot
Posted By: Slin

Re: Variance Shadow Mapping for the Sun - 01/15/08 15:34

Thanks you two for the hints
I will be quite slow with updates on these in the next time. Because of the compatibility problems with a higher shadowquality, I plan to realise the shadows completely with a dll. But my nearly not existing knowledge about c++ and directx will slow this down a lot But this is a good possibility to learn it, although it is probably not the easiest goal . This means that I will have to read a lot of tutorials which slows me down a lot^^. But I am progressing It would also allow the shadows to be used with each 3dgs version which uses dx 9 (6.30.1 and above) and with each edition (standart/extra/comm/pro).

Would you be interested in me uploading this Project with the scripting? But I wonīt write any instructions and it is not THAT easy to use at the moment and far not perfect.
Just let me know if you are interested in me uploading it or not

Slin
Posted By: ello

Re: Variance Shadow Mapping for the Sun - 01/15/08 15:50

me off course. i guess others as well
Posted By: frazzle

Re: Variance Shadow Mapping for the Sun - 01/15/08 19:45

Who wouldn't

Cheers

Frazzle
Posted By: 3run

Re: Variance Shadow Mapping for the Sun - 07/10/09 18:47

People please reupload it!!! smile
© 2024 lite-C Forums