Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: INVERSEPROJECTION  (Read 2116 times)
AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« on: January 12, 2009, 10:06:34 PM »

After googling this it seems a lot of engines have the semantic. I can't find one in the wiki for TV3D and just trying the semantic and crossing my fingers hasn't worked either. Does this exist? An if not, what is the workaround?

Thanks.
Logged

-...-

George
Community Member
*
Posts: 11


« Reply #1 on: January 12, 2009, 11:39:21 PM »

Hey Arius,

try doing TVCamera.GetProjectionMatrix() and inverting that
via MathLibrary.TVMatrixInverse.

That should do the trick.

Cheers,
George

P.S.: Besides, there's no VIEWPROJECTIONINVERSE either. As Camera.GetMatrix()
returns the inverse view matrix it's not a problem though, if I'm not mistaken
you can invert the projection matrix and multiply first with your inverse
projection to 'un-project' and then with your inverse view matrix to 'un-view' Wink
« Last Edit: January 12, 2009, 11:45:50 PM by George » Logged
AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #2 on: January 13, 2009, 12:05:39 AM »

Hey Arius,

try doing TVCamera.GetProjectionMatrix() and inverting that
via MathLibrary.TVMatrixInverse.

That should do the trick.

Cheers,
George

P.S.: Besides, there's no VIEWPROJECTIONINVERSE either. As Camera.GetMatrix()
returns the inverse view matrix it's not a problem though, if I'm not mistaken
you can invert the projection matrix and multiply first with your inverse
projection to 'un-project' and then with your inverse view matrix to 'un-view' Wink

Hmm, not sure what you mean by the P.S.. My mind isn't readily able to compute matrix math so I can get a bit confused. If I try to inverse the projection matrix, the result is blank pixels... if I output as such:

Code:
float4 P     = mul(float4(1, 1, 1, 1), InvProj);
return P;

Whereas doing the same thing with PROJECTION produces yellow pixels. So I'm not convinced that's working. I do recall when doing planar reflection that there was something funny about the TVMatrixInverse function - you sure it works as it should?
Logged

-...-

George
Community Member
*
Posts: 11


« Reply #3 on: January 13, 2009, 12:49:34 PM »

Well, what are you trying to achieve? If I'm not totally
out of the loop you would f.ex. transform a model position
from object to clip space with

WorldPosition = ObjectPosition * matWorld
ViewPosition = WorldPosition * matView
ScreenPosition = ViewPosition * matProjection

When you store the result of that, and then use the inverted
projection matrix to do

ViewPosition = ScreenPosition * matProjectionInverse

you have a test case.

Might be I'm wrong, but I'm pretty sure that the inverse of
Camera.GetProjectionMatrix is what you need...

Cheers,
G.
Logged
AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #4 on: January 13, 2009, 01:00:09 PM »

I dunno, right now I am doing this kind of thing:

Code:
//Vertex Program.
OUT.ScreenUV    = OUT.Position.xy/OUT.Position.w;
OUT.Depth       = OUT.Position.zw;

//Fragment Program.
float2 sUV      = 0.5 * ((IN.ScreenUV) + float2(0.5f, 0.5f));
sUV.y           = 1 - sUV.y;

float partDepth = IN.Depth.x;
partDepth      /= IN.Depth.y;

float sDepth    = tex2D(DeepSample, sUV).r;

float4 dvSample = mul(float4(IN.ScreenUV, sDepth, 1), Projection);
float4 dpSample = mul(float4(IN.ScreenUV, partDepth, 1), Projection);

Now, outputting dvSample or dpSample yields a coloured pixel. As seen here, output of dvSample( http://i43.tinypic.com/35kqy52.jpg ). To my limited knowledge of such things, that appears correct. If I use the following code:

Code:
float bah;
cTV_3DMATRIX miP;
m_Math->TVMatrixInverse(&miP, &bah, &m_Cam->GetProjectionMatrix());
shadeSoft->SetEffectParamMatrix("invProj", &miP);

//Fragment.
float4 dvSample = mul(float4(IN.ScreenUV, sDepth, 1), invProj);
float4 dpSample = mul(float4(IN.ScreenUV, partDepth, 1), invProj);

I get no pixel output, as such( http://i42.tinypic.com/2qva5fo.jpg ).

The Microsoft example says:

Code:
        float4 depthViewSample = mul( float4( input.ScreenTex, depthSample, 1 ), g_mInvProj );
        float4 depthViewParticle = mul( float4( input.ScreenTex, particleDepth, 1 ), g_mInvProj );

So I am guessing I must use the inverse.
Logged

-...-

Enzi
Community Member
*
Posts: 67


« Reply #5 on: January 17, 2009, 10:04:53 PM »

I don't know what you are doing in the second code part. At least it makes no sense for me when I look at the first part.

Just in case you don't know it.

ViewProj = mul(View, Projection);

View = mul(ViewProj, InvProj);

I don't know what the shader code from Microsoft wants to do so a little more info would be nice.

From reading it, and it's just a wild guess because of the tex2d(deep), do you want to get the worldspace of the 2d point?

Just in case:
Code:
float4 worldPosition;
worldPosition.x=In.TexCoord.x*2.0f-1.0f;
worldPosition.y=-(In.TexCoord.y*2.0f-1.0f);   
worldPosition.z= (SceneDepth);
worldPosition.w=1.0f;
   
worldPosition=mul(worldPosition,invViewProj);
worldPosition/=worldPosition.w;
   
float3 ViewSpacePosition = mul(worldPosition,View);

edit:

And from further reading it, I really think that you need to offset the uv as you did in the first shader code and then multiply it with the inversed ViewProjection. The matrix in the MS code can't just be the projection. It wouldn't make sense.
« Last Edit: January 17, 2009, 10:08:12 PM by Enzi » Logged
AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #6 on: January 17, 2009, 10:32:14 PM »

Thanks Enzi, though, I went a different way and ended up not using MS's code. I did this instead: http://pastebin.com/f253ff332
Logged

-...-

Enzi
Community Member
*
Posts: 67


« Reply #7 on: January 18, 2009, 08:13:57 AM »

Nice approach with the delta calculation. But the division seems rather random. Wink
Logged
Pages: [1]
  Print  
 
Jump to:  

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