Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Projection of a shadow on mesh and landscape  (Read 1422 times)
petrus
Community Member
*
Posts: 90


« on: January 21, 2008, 04:05:55 AM »

I have a very strange problem.
Both my landscape and mesh, shadow mapping shaders are kinda the same.
The problem is, as you can see on the images. The shadows/ depth map is projected accurately over the landscape but seem to be a bit off on meshes. Actually using the landscape shader on a mesh also gives the same problem.
I don't know what I'm doing wrong, I know it worked when I started working on shadow mapping last year, but now... the projection coordinates are messed up.
I added two pictures, note how the shadows fall accurately on the landscape but are projected wrong on meshes...
I really think it's because of the projection matrix used to render the depth map... but why is it only affecting the mesh objects, and not the landscape?


What can I be doing wrong?
Here is a screen shot of it working last year. But I don't find the problem.

O and as soon as I find the solution check the showcase forms again... I found a way to soften the shadows more efficiently. Wink And also created my own, faster, bilinear filter, Faster than PCF3x3 and looks better too.
Logged
BlindSide
Customers
Community Member
*****
Posts: 758


WWW
« Reply #1 on: January 22, 2008, 04:36:27 PM »

Are you using any sort of biasing to deal with shadow acne? I use a small mul offset, but it could have different results on a mesh vs. large landscape. I've seen other's use a small subtraction/addition.
Logged

Blind's Dev Blog - www.smithbower.com/devblog/

Irc.Desolation.Org :: #TV3DLicensed :: Moderated IRC channel for all your TV3D needs :: Non-Licensed users welcome.
petrus
Community Member
*
Posts: 90


« Reply #2 on: January 23, 2008, 03:16:56 AM »

Nope cant get the tweaking right Cry  Embarrassed
This is what I'm doing (converted to vb)
Code:
Dim LightViewProj As TV_3DMATRIX
math.TVMatrixInverse LightViewProj, 0, lightRS.GetCamera.GetMatrix
math.TVMatrixMultiply LightViewProj, LightViewProj, lightRS.GetCamera.GetProjectionMatrix
colorShader.SetEffectParamMatrix "lightCameraViewP", LightViewProj

And then in my shader I'm calculating the projection coordinates like so:
Vertex shader:
Code:
OUT.ShadowMapSamplingPos = mul(IN.position, lightCameraViewP);
OUT.depth = OUT.ShadowMapSamplingPos.z *BIAS;
And then in my pixel shader:
Code:
float2 ProjectedTexCoords;
 ProjectedTexCoords[0] = IN.ShadowMapSamplingPos.x/IN.ShadowMapSamplingPos.w/2.0f + 0.5f;
 ProjectedTexCoords[1] = -IN.ShadowMapSamplingPos.y/IN.ShadowMapSamplingPos.w/2.0f + 0.5f;
 float depth = tex2D(DepthMapSampler, ProjectedTexCoords).r;
This is a clean method, but its driving me crazy Undecided
-------------------------------------------------------------------------------------------
Wow wait a minute- I just found out that some of my semantics are not properly being updated. I think that my vertex shader POSITION semantic might not contain the correct values, a object at vector 0,0,0 will cast a correct shadow, the further away from the origin the more I see an offset.
Also trying to send material data to the shader using semantics also isn't working.
Why wouldn't TV send the semantic data? The matrices are being updated?
« Last Edit: January 24, 2008, 09:09:27 AM by petrus » Logged
BlindSide
Customers
Community Member
*****
Posts: 758


WWW
« Reply #3 on: January 25, 2008, 03:56:47 AM »

Semantics SHOULD be being updated, but I think shaders were broken a bit in the last release. IE something is messed up with tangents.. all my lighting shaders are broken, until I plug an old dll back in.

Try manually updating for now, see if that makes a difference.
Logged

Blind's Dev Blog - www.smithbower.com/devblog/

Irc.Desolation.Org :: #TV3DLicensed :: Moderated IRC channel for all your TV3D needs :: Non-Licensed users welcome.
sybixsus
Customers
Community Member
*****
Posts: 1048


WWW
« Reply #4 on: January 25, 2008, 12:35:26 PM »

Have you got a lighting mode set for the mesh which you're applying the shader to? I know some semantics don't get sent without a lighting mode, but I wouldn't expect that to include the semantics you're talking about here. Still might be worth a try though.
Logged
SylvainTV
Administrator
Community Member
*****
Posts: 4431


WWW
« Reply #5 on: January 27, 2008, 07:36:33 PM »

Hmm if it works with an object with an identity matrix (0,0,0 position for example), maybe your shader projection doesn't use the WORLD matrix ?
Don't forget to transform your POSITION from vertex shader by the world matrix to get the position in world space, then you can project it in light space etc.
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
petrus
Community Member
*
Posts: 90


« Reply #6 on: January 29, 2008, 03:10:53 AM »

As always no problem with this engine, just my own stupidity Tongue
Thanks Sylvain, I forgot to transform the vectors, I was working with object-space. I have to transform from object-space, to world-space, to light-space.

And somehow I must have deactivated the lighting mode and materials, while doing debugging on this - I fixed the problem now. Everything is working beautifully.  Cheesy

Actually, as I now learned, transforming the vectors are very important.
It will probably be a good idea to transform the POSITION, NORMAL, and maybe TANGENTs(don't know about that one)? Undecided
I suppose most lighting shaders (not transforming anything), will look OK on the origin (position 0,0,0) but as they move away things will start too look wrong.
Thanks everyone... Wink
Logged
BlindSide
Customers
Community Member
*****
Posts: 758


WWW
« Reply #7 on: January 30, 2008, 03:36:00 PM »

You only need to transform the POSITION vector - tangent and normal don't need to be transformed (they are always local).
Logged

Blind's Dev Blog - www.smithbower.com/devblog/

Irc.Desolation.Org :: #TV3DLicensed :: Moderated IRC channel for all your TV3D needs :: Non-Licensed users welcome.
SylvainTV
Administrator
Community Member
*****
Posts: 4431


WWW
« Reply #8 on: January 31, 2008, 05:13:05 PM »

Well depends how the shader works.
If you have the lights in local space of the model, no need to transform them, else you have to transform the tangent/binormal by the rotation matrix of the mesh ( 3x3 part of world matrix, if there is no weird scale)
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
petrus
Community Member
*
Posts: 90


« Reply #9 on: February 01, 2008, 12:47:11 AM »

Mmhhh... I didn't know that.
But it makes perfect sense.
I actually recall Zaknafein stating that (in shader FAQ)
Quote
A little tip for those into shading...
If you use the vertex normals with the NORMAL semantic, be sure to transform them using the WORLDIT/WORLDINVERSETRANSPOSE float4x4 matrix before working with them, or else all the matrix transformations on your mesh will not affect the normals!
And also this lovely link
http://www.gignews.com/realtime020100.htm
Thanks for all your help. Wink
Logged
Shadowsong
Customers
Community Member
*****
Posts: 131


« Reply #10 on: May 08, 2008, 12:11:42 AM »

Would you release the source or the shader?  Cheesy
Logged
petrus
Community Member
*
Posts: 90


« Reply #11 on: May 12, 2008, 02:50:23 AM »

Whell I am planning to release the source with the shader. Actually I just have to rip most of it out of my game engine and create a new smaller project -  Roll Eyes lot of work.
But before I go and make myself too much work... is C++ OK? Or do I have to go and recode the whole thing in VB for the community Undecided
And then I have to create a view new textures and simple models, just to illustrate the effect. Shouldn't take too long.
And the next thing is- I need some place to upload to, I don't have ftp server.
Does anybody know where I can host the source from - a good safe place... or is the wiki OK. We need truevisionfilez back or the projects site.
Logged
Happy
Customers
Community Member
*****
Posts: 76


« Reply #12 on: May 12, 2008, 05:25:57 AM »

Hi petrus,  Smiley

Quote
But before I go and make myself too much work... is C++ OK? Or do I have to go and recode the whole thing in VB for the community

I'm quite for sure some here wouldn't mind converting the source for vb.net, as it was generiously done before on many base occasions for other projects.

Quote
Does anybody know where I can host the source from - a good safe place... or is the wiki OK. We need truevisionfilez back or the projects site.

This probably not the best site, but it's something that looks very promising, heres the link thanks goes to Ghost. http://tv3dsamples.blogspot.com/

We look forward to seeing more great progress on you're project. Thankyou.
Logged
ZaPPZion
Community Member
*
Posts: 299


« Reply #13 on: May 12, 2008, 05:28:27 AM »

the tvprojects page is already up and running again: http://projects.truevision3d.com
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks