Jump to content


D3D10 Shadow Mapping


123 replies to this topic

#61 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 20 February 2009 - 10:33 AM

Mmm, do you think that it's the same problem?
BTW no problem, i will add the small value and will let you know.

Thank you again for all your help.
Mabye i i would gave up without you!

#62 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 20 February 2009 - 02:28 PM

It looks like completely ok with the small adding (and a change in condition)

Posted Image

#63 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 20 February 2009 - 10:53 PM

XVincentX said:

It looks like completely ok with the small adding (and a change in condition)

I'd wager that with that addition of an epsilon it would work with >= too.

Quote

Thank you again for all your help.

You're welcome :) I'm glad I was of some help :) Even if it did take far too long to figure out the issues :lol:

#64 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 25 February 2009 - 09:12 PM

Hello. I'm still here with 2-3 questions.

A) I just tested that, pointing the spotlight ON the shadowed zone gave by the point light: as i expected, the shader draws still black.
So i tried to replace this code

return (PointLight + SpotLight) * BaseColor * ShadowValue * CubeValue;

with

return (PointLight + SpotLight) * BaseColor * (ShadowValue || CubeValue);

Hoping that the OR on the ints would leave lighted at least the points lighted by a light source.

B) Can you suggest me a good way to avoid black shadow and simply give less light (i already did it but i want to make it in another way, if possible)?

Thank you.

#65 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 25 February 2009 - 10:00 PM

A) Naturally you will get black. You are multiplying with a conditional held in an int. The value will be either 1 or 0. As you are, i'm sure, aware 0x = 0 and 1x = x.

B) You could try

(ambientColour + (PointLight * CubeValue) + (SpotLight * ShadowValue)) * SampledTextureColour;

PointLight * CubeValue means that you will light, with the point light, any section that isn't in shadow. If in shadow then it will add nothing to the ambient colour. The same goes for the SpotLight * ShadowValue. However it will allow you to have a difference between things lit by the point light but in the shadow of the spot light or lit by the spot light and in the shadow of the point, or in shadow of both or in shadow of neither. This gives you far more control.

Essentially when doing multipass rendering, ala Doom3, this is what you would be doing. You would do an ambient pass. And then do a pass for each light where you add the contribution from that light (or not if in shadow). You would then multiply the whole thing by the texture colour.

Of course once you have done that you can then add specular highlights on top of that whole lot. But that might just be complicating matters further ;)

I'd strongly recommend doing some reading on how the lighting pipeline works.

This page is a good start: http://msdn.microsof...178(VS.85).aspx

Its also worth looking into the physics of lighting itself, the RGB colour model and additive colours. Once you understand HOW light contributes to a surface you will have a much better understanding of how direct lighting works :)

A quick flick found this: http://www.rgbworld.com/color.html

#66 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 26 February 2009 - 11:07 AM

I tried your "equation" and, while the Point Shadow it's black but lighted when spotlight goes on it, the Spotlight simply "does not draw", as you can see here

Posted Image

Mabye the point light on the lamp lights also the wall and reduces shadow?

Thanks for the links and yes, i really have to read something more about lights, i'm completely on 0 (just lambert and phong)

#67 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 26 February 2009 - 11:57 AM

Are you sure the spot light just isn't very bright? I can see what appears to be the spot light to the right of the car on the ground its just really not particularly bright. The fact that it casts a shadow on the wall behind the car that fades nicely into the light from the point light seems to indicate its working to me ...

#68 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 26 February 2009 - 12:00 PM

Also worth noting that yellow isn't the easiest of colours to see ... set the spot light to full white (ie 255, 255, 255) and see what happens then.

#69 imerso

    Senior Member

  • Members
  • PipPipPipPip
  • 428 posts
  • LocationBrasil

Posted 26 February 2009 - 02:59 PM

These screenshots are starting to look nice. :-)

As a suggestion, sometimes when debugging thinks like this, it may help if you change objects and positions from time to time, you may find a bug just doing this and looking the new results.

Good luck!

#70 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 26 February 2009 - 03:28 PM

Thank you, but the 80% of work was made by Goz's suggestions.
There is still a lot to do.
A) Make a decent scene with good illumination
B) Make a camera system (the one i'm using is owful, if you can suggest me one "Maya Like" it would be great)
C) Use some more advanced shadow mapping alghoritm.

P.S.
I made sense of strange post hours...i'm not from USA or Canada, so when you see 5.00 AM here are 10 o clock...but do you REALLY post at that time???

#71 imerso

    Senior Member

  • Members
  • PipPipPipPip
  • 428 posts
  • LocationBrasil

Posted 26 February 2009 - 06:21 PM

Not sure if you were talking to me about post hours, but I usually wake up in random hours (like 4:00AM), then I come to this PC and start reading forums or programming. Well, sometimes I just don't sleep. :-)

#72 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 28 February 2009 - 12:10 PM

Here is modified light color
Posted Image

The less "darkness" of shadow is due to point light contribution?

#73 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 28 February 2009 - 03:23 PM

XVincentX said:

The less "darkness" of shadow is due to point light contribution?

Behind the car? Cos yes if thats what you mean. If you turn on a torch and it casts a shadow if you then place a light behind the object casting the shadow then the shadow will get washed out by the new light ...

#74 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 01 March 2009 - 10:07 AM

Mmm...i can't get any kind of antialiasing in the scene, mabye becouse shadow map is big enough to avoid it?
I tried to reduce it to 100x100 or 200x200, and the antialiasing comes out. So the PSM and TSM are used to reduce antialiasing of little textures (in front of backbuffer size)?

#75 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 01 March 2009 - 07:10 PM

position the camera right next to the wall the shadow is cast upon and im pretty sure you'll see the aliasing.

Of course its worth noting that unless you are right up against the wall its nto actually worth, in many case, wasting time doing anti-aliasing.

If itg looks good as is then its not worth wasting time making it look a tiny percent better. Only bother when its needed and save your GPU time for where its really needed.

#76 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 01 March 2009 - 08:34 PM

I ask you help once again.
I checked on nvidia developer site, and i found A LOT of other shadow map implementation:
Parallel-Split Shadow Maps
Variance Shadow Maps
Percentage-Closer Filtering
Perspective Shadow Maps
Trapezoidal Shadow Maps

What could be the "must" to learn about it?

#77 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 01 March 2009 - 10:43 PM

XVincentX said:

I ask you help once again.
I checked on nvidia developer site, and i found A LOT of other shadow map implementation:
Parallel-Split Shadow Maps
Variance Shadow Maps
Percentage-Closer Filtering
Perspective Shadow Maps
Trapezoidal Shadow Maps

What could be the "must" to learn about it?

Learn any one of them inside out. Once you've learnt it you'll find it easier to get your head round the others. Each method has its advantage and its disadvantages. The learning process teaches yyou when to use one over another :) It take a while, though ... good luck!

#78 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 02 March 2009 - 02:47 PM

I hope i will be able to find you here to help me!!

#79 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 02 March 2009 - 11:52 PM

I was giving a look to Variance Shadow Mapping and the alghoritm looks like very easy.

I just wanted to try without the usual gaussian blur.
So i modified my code in pixel shader:

    
		int ShadowValue = (step((LightToVecDist/FarClip),SpotShadow.x) && Atten != 0);
		
		float lit = (float2)0.0f;
		float E_x2 = SpotShadow.y;
		float Ex_2 = SpotShadow.x * SpotShadow.x;
		float variance = E_x2 - Ex_2;
		float mD = SpotShadow.x - (LightToVecDist/FarClip);
		float mD_2 = mD * mD;
		float p = variance / (variance + mD_2);
		lit = max( p, ShadowValue );
		
    
		LightToVec = In.WPos - LightInfo.xyz;
		LightToVecDist = length(LightToVec);
		float CubeShadow = Cubemap.Sample(SamplText,(LightToVec/LightToVecDist));	
		int CubeValue =  step((LightToVecDist / FarClip),CubeShadow);
		
		float4 SpotLight = (Atten * dot( In.Nor, LightToVecDirection ));
		return ((PointLight * CubeValue) + (SpotLight * lit) + 0.1f) * BaseColor;


And obiously modified the depth pass
	return float2(depth,pow(depth,2)); 

But it does not work: the shadow remains perfectly the same.

BTW, a concept is not really clear to me.
Why have i to store depth^2 in the second channel and retrive it?
Can't i compute it directly in Pixel shader retriving original depth?

Anyway, reading original paper, i have to scale light intensity by lit value. But how? Dividing?

Thank you.

#80 XVincentX

    Valued Member

  • Members
  • PipPipPip
  • 115 posts

Posted 03 March 2009 - 09:56 PM

As i expected, Ex_2 and E_x2 are the same: my troubles it's confirmed.
Posted Image
It's something due to limited 32bit precision?

I do not think it, becouse the code
		float E_x2 = SpotShadow.y;
		float Ex_2 = SpotShadow.x * SpotShadow.x;
Are the SAME thing!!!!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users