DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Programming & Development > Graphics Theory & Programming
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 03-18-2009, 06:10 AM   #101
JarkkoL
Valued Member
 
Join Date: Mar 2008
Location: Finland
Posts: 263
Default Re: D3D10 Shadow Mapping

For the weights, just use the Gaussian distribution function I posted link earlier in this thread. I use variance 0.75 myself, which seems to work ok. Also, normalize the weights so that they add up to 1.
___________________________________________
Spin-X Engine / Community / My Blog
JarkkoL is offline   Reply With Quote
Old 03-18-2009, 08:48 AM   #102
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

Ok i made also gaussian blur with this results:

I computed Gaussian distribution using the formula found on wikipedia.

Code:
float GaussianWidth(float Sigma, float Displace) { return (1/(sqrt(2*D3DX_PI) * Sigma)) * (pow(exp(1.0f),-(Displace*Displace)/(2 * Sigma * Sigma))); }

What do you mean "normalize" weights?

With Sigma = 1 and 9 samples (from -4 to 4), and 128x128 texture





What do you think about it? Should i blur more? Changing what? Samples number? Sigma?

Last edited by XVincentX : 03-18-2009 at 09:03 AM.
XVincentX is offline   Reply With Quote
Old 03-18-2009, 09:22 AM   #103
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

I do not know why, but saving image using PIX (like last one) is different than saving images using STAMP:



Looks like miss anisotropic filtering (that is enabled)

Last edited by XVincentX : 03-18-2009 at 09:42 AM.
XVincentX is offline   Reply With Quote
Old 03-18-2009, 10:19 AM   #104
Goz
Senior Member
 
Join Date: Sep 2004
Posts: 572
Default Re: D3D10 Shadow Mapping

For future reference if you hit "alt-printscreen" it will grab the current window's contents to the clipboard. Probably the best way to do screenshots and get it representitive of what you are seeing, IMO.

Your screenshots look, to me, like anisotropic filtering is turned OFF.

Well your blur could definitely do with looking a tad better. For a 9x9 blur you should get MUCH better results than that ...
Goz is offline   Reply With Quote
Old 03-18-2009, 10:40 AM   #105
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

Quote:
Originally Posted by Goz
For future reference if you hit "alt-printscreen" it will grab the current window's contents to the clipboard. Probably the best way to do screenshots and get it representitive of what you are seeing, IMO.

Your screenshots look, to me, like anisotropic filtering is turned OFF.

But it's enabled, as you can see from screenshot grabbed from Pix...i will check better this, anyway.

Quote:
Originally Posted by Goz
Well your blur could definitely do with looking a tad better. For a 9x9 blur you should get MUCH better results than that ...

I thought same thing but for now i do not have got ideas...mabye gaussian parameters?
XVincentX is offline   Reply With Quote
Old 03-18-2009, 11:21 AM   #106
JarkkoL
Valued Member
 
Join Date: Mar 2008
Location: Finland
Posts: 263
Default Re: D3D10 Shadow Mapping

Quote:
Originally Posted by XVincentX
What do you mean "normalize" weights?
When you sum the weights, make sure they equal to 1.
___________________________________________
Spin-X Engine / Community / My Blog
JarkkoL is offline   Reply With Quote
Old 03-18-2009, 01:03 PM   #107
Goz
Senior Member
 
Join Date: Sep 2004
Posts: 572
Default Re: D3D10 Shadow Mapping

could you post up the code for your 2 passes as well?
Goz is offline   Reply With Quote
Old 03-19-2009, 02:12 PM   #108
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

Sure.
Gaussian coefficients are computed using this forumula
Code:
float GaussianWidth(float Sigma, float Displace) { return (1/(sqrt(2*D3DX_PI) * Sigma)) * (pow(exp(1.0f),-(Displace*Displace)/(2 * Sigma * Sigma))); }

Due to packing HLSL rules, coefficient are grouped in float4, in this way

Code:
cbuffer cTwiceFrame { float4 SampleOffsets[SAMPLE_COUNT/2]; float4 SampleWeights[SAMPLE_COUNT/4]; };

SAMPLE_COUNT = 8 (the nineth sample is taken directly in Pixel Shader).

Data is filled in this way

Code:
cTwiceFrame.SampleWeights[0].x = GaussianWidth(1.0f,-4.0f); cTwiceFrame.SampleWeights[0].y = GaussianWidth(1.0f,-3.0f); cTwiceFrame.SampleWeights[0].z = GaussianWidth(1.0f,-2.0f); cTwiceFrame.SampleWeights[0].w = GaussianWidth(1.0f,-1.0f); cTwiceFrame.SampleWeights[1].x = GaussianWidth(1.0f, 1.0f); cTwiceFrame.SampleWeights[1].y = GaussianWidth(1.0f, 2.0f); cTwiceFrame.SampleWeights[1].z = GaussianWidth(1.0f, 3.0f); cTwiceFrame.SampleWeights[1].w = GaussianWidth(1.0f, 4.0f);

While texture displacement:

Code:
cTwiceFrame.SampleOffsets[0] = D3DXVECTOR4(0,(-4.0f * 1/SMX),0,(-3.0f * 1/SMX)); cTwiceFrame.SampleOffsets[1] = D3DXVECTOR4(0,(-2.0f * 1/SMX),0,(-1.0f * 1/SMX)); cTwiceFrame.SampleOffsets[2] = D3DXVECTOR4(0,( 1.0f * 1/SMX),0,( 2.0f * 1/SMX)); cTwiceFrame.SampleOffsets[4] = D3DXVECTOR4(0,( 3.0f * 1/SMX),0,( 4.0f * 1/SMX));

And make Pixel Shader. So reuse the same target and make same pixel shader with these

Code:
cTwiceFrame.SampleOffsets[0] = D3DXVECTOR4((-4.0f * 1/SMX),0,(-3.0f * 1/SMX),0); cTwiceFrame.SampleOffsets[1] = D3DXVECTOR4((-2.0f * 1/SMX),0,(-1.0f * 1/SMX),0); cTwiceFrame.SampleOffsets[2] = D3DXVECTOR4(( 1.0f * 1/SMX),0,( 2.0f * 1/SMX),0); cTwiceFrame.SampleOffsets[4] = D3DXVECTOR4(( 3.0f * 1/SMX),0,( 4.0f * 1/SMX),0);

Finally, the pixel shader:
Code:
float4 Blur(VSB_OUTPUT Inp) : SV_TARGET { float4 c = 0; float4 SampleOnZero = SpotText.Sample(SamplText,Inp.Tex); for (int i = 0; i < SAMPLE_COUNT / 4; i++) { int i2 = i * 2; c += SpotText.Sample( SamplText, Inp.Tex + SampleOffsets[i2].xy ) * SampleWeights[i].x; c += SpotText.Sample( SamplText, Inp.Tex + SampleOffsets[i2].zw ) * SampleWeights[i].y; c += SpotText.Sample( SamplText, Inp.Tex + SampleOffsets[i2 + 1].xy ) * SampleWeights[i].z; c += SpotText.Sample( SamplText, Inp.Tex + SampleOffsets[i2 + 1].zw ) * SampleWeights[i].w; } return c + (SampleOnZero*0.39); //0.39 is GaussianWidth with 1.0f,0.0f. }
XVincentX is offline   Reply With Quote
Old 03-22-2009, 12:12 PM   #109
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

So?
XVincentX is offline   Reply With Quote
Old 03-22-2009, 03:51 PM   #110
Goz
Senior Member
 
Join Date: Sep 2004
Posts: 572
Default Re: D3D10 Shadow Mapping

Try:

Code:
float GaussianWidth(float Sigma, float Displace) { return (1/(sqrt(2*D3DX_PI) * Sigma)) * exp( -(Displace*Displace)/(2 * Sigma * Sigma))); }

exp( 1.0 ) IS 1.0

What you are saying is raise 1 to the power you should be rasing e too ...

Last edited by Goz : 03-22-2009 at 03:55 PM.
Goz is offline   Reply With Quote
Old 03-22-2009, 04:16 PM   #111
Reedbeta
DevMaster Staff
 
Join Date: Oct 2004
Location: Seattle, WA
Posts: 3,790
Default Re: D3D10 Shadow Mapping

Quote:
Originally Posted by Goz
exp( 1.0 ) IS 1.0

Actually exp(0) = 1.0, and exp(1.0) = e.
___________________________________________
Currently working at Sucker Punch
reedbeta.com - OpenGL demos and other projects
Luabridge - a lightweight, dependency-free C++/Lua binding library.
CD Lite - an unobtrusive, minimal CD player application for Windows.
Reedbeta is offline   Reply With Quote
Old 03-22-2009, 04:19 PM   #112
Goz
Senior Member
 
Join Date: Sep 2004
Posts: 572
Default Re: D3D10 Shadow Mapping

Quote:
Originally Posted by Reedbeta
Actually exp(0) = 1.0, and exp(1.0) = e.

goddammit reedbeta would you stop correcting my completely retarded ramblings hehehe
Goz is offline   Reply With Quote
Old 03-22-2009, 04:25 PM   #113
Goz
Senior Member
 
Join Date: Sep 2004
Posts: 572
Default Re: D3D10 Shadow Mapping

Still not convinced by thaty GaussianWidth function though.

You know btw that value for "-x" is the same as for "x"? ie you don't need to run it for every value.

Can you post up the values returned by GaussianWidth?
Goz is offline   Reply With Quote
Old 03-23-2009, 12:08 PM   #114
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

Quote:
Originally Posted by Reedbeta
Actually exp(0) = 1.0, and exp(1.0) = e.

I just used it to avoid writing costans by my own.
Gaussian values coming soon.
XVincentX is offline   Reply With Quote
Old 03-23-2009, 02:02 PM   #115
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

Values for you

Code:
GaussianWidth(1.0f,-4.0f); 0.00013383027 GaussianWidth(1.0f,-3.0f); 0.0044318493 GaussianWidth(1.0f,-2.0f); 0.053990975 GaussianWidth(1.0f,-1.0f); 0.24197073

Your function version return quite same values, except for last 2 numbers.

Last edited by XVincentX : 03-23-2009 at 02:06 PM.
XVincentX is offline   Reply With Quote
Old 03-23-2009, 03:04 PM   #116
Goz
Senior Member
 
Join Date: Sep 2004
Posts: 572
Default Re: D3D10 Shadow Mapping

Quote:
Originally Posted by XVincentX
Values for you

Code:
GaussianWidth(1.0f,-4.0f); 0.00013383027 GaussianWidth(1.0f,-3.0f); 0.0044318493 GaussianWidth(1.0f,-2.0f); 0.053990975 GaussianWidth(1.0f,-1.0f); 0.24197073

Your function version return quite same values, except for last 2 numbers.

It should return identical values ...

I can't see anything wrong in your code .. the only thing that strikes me as being a potential problem (and I'm grasping at straws here) is your value for "SMX" ...
Goz is offline   Reply With Quote
Old 03-23-2009, 03:05 PM   #117
JarkkoL
Valued Member
 
Join Date: Mar 2008
Location: Finland
Posts: 263
Default Re: D3D10 Shadow Mapping

The variance value you are using is way too small. The Gaussian weight values are way too small for more distant samples thus they barely contribute to the value. Use the value 0.75 that I originally said for x=[-1, 1].
___________________________________________
Spin-X Engine / Community / My Blog
JarkkoL is offline   Reply With Quote
Old 03-23-2009, 03:13 PM   #118
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

I just tried, but i did not find any noticeable improvement.




I was also forced to mul by 2 all spotlight becouse it was too dark
XVincentX is offline   Reply With Quote
Old 03-23-2009, 03:15 PM   #119
JarkkoL
Valued Member
 
Join Date: Mar 2008
Location: Finland
Posts: 263
Default Re: D3D10 Shadow Mapping

So what are the new values?
___________________________________________
Spin-X Engine / Community / My Blog
JarkkoL is offline   Reply With Quote
Old 03-23-2009, 04:21 PM   #120
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

Sorry i forgot to paste them
4.6268983e-008
5.8531972e-005
0.0096201422
0.20542553
XVincentX is offline   Reply With Quote
Old 03-23-2009, 04:40 PM   #121
JarkkoL
Valued Member
 
Join Date: Mar 2008
Location: Finland
Posts: 263
Default Re: D3D10 Shadow Mapping

How about trying to do what I have been saying for quite some time here? Spoon feeding follows:
Code:
float weights[9]; float weight_sum=0.0f; for(int i=0; i<9; ++i) { float weight=GaussianWeight(0.75f, float(i-4)/4.0f); weight_sum+=weight; weights[i]=weight; } for(unsigned i=0; i<9; ++i) weight[i]/=weight_sum;
___________________________________________
Spin-X Engine / Community / My Blog
JarkkoL is offline   Reply With Quote
Old 03-23-2009, 05:10 PM   #122
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

I'm sorry you should understand me.
When you work so much and too many time on the same project, sometimes happens to me to have fog and clouds on my head and forget all suggestion. I will try also this other.
Thank you still for the help.
XVincentX is offline   Reply With Quote
Old 03-23-2009, 05:35 PM   #123
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

With normalization the darkening is vanished, and i can see a better blur (even if little).

Anisotropic filtering, 128x128 variance shadow map (Gauss 0.75). The ligher is due to 2*light i used before

No anisotropic, 128x128 variance shadow map (Gauss 0.75).

Lit factor. Looks like perfect.


Shadow Map.
XVincentX is offline   Reply With Quote
Old 03-26-2009, 03:47 PM   #124
XVincentX
Valued Member
 
Join Date: Jul 2008
Location: Italy
Posts: 114
Default Re: D3D10 Shadow Mapping

Thank you all for your help.
XVincentX is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 01:59 AM.


Powered by vBulletin
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.