Sign in to follow this  

screen space texcoord from vertex position [HLSL]

This topic is 4308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i was trying to see how accurate this can be done using tex2Dproj. first, i looked at two sources: ShaderTech link Deferred Shading demo I tried the sample code from the second source, but couldnt get it work though. What happened was that i could get screen space texcoords with a slight distortion, about 2-3 pixels being offsetted along the x axis. What I did was to render a quad with screen space coords. And then a second pass tries to uses tex2Dproj to lookup the earlier texture to see the lookup was done correctly or not. I use a modified DX texture tool to read back the pixel values (like Image Debugger) to check if the 2nd pass was performing the lookup accurately. Unfortunately, it didnt. :(
D3DXMATRIXA16 matPostProjRescale;
D3DXMATRIXA16 translation, scaling;
D3DXMatrixIdentity(&matPostProjRescale);
D3DXMatrixIdentity(&translation);
D3DXMatrixIdentity(&scaling);
D3DXMatrixTranslation(&translation, 1.0f + 1.0f / 512.0f, -1.0f - 1.0f / 512.0f, 0.0f);
D3DXMatrixScaling(&scaling, 0.5f, -0.5f, 1.0f);
D3DXMatrixMultiply(&matPostProjRescale,&translation,&scaling);
anyone tried this way of getting screen space texcoords before? if u do, do you get extremely accurate results or also have slight distortions... then again, I might as well get an X1K card and use VPOS instead. And I hope ATI supports VPOS... phew! Edwin

Share this post


Link to post
Share on other sites
Quote:
Original post by edwinnie
anyone tried this way of getting screen space texcoords before?
I've not tried the way you're talking about, but I'd personally choose to implement the viewport matrix in a shader and pass the values across to the pixel shader.


(from this page)


The regular output of a vertex shader should be in projection space, and the above matrix can remap it to screenspace. You just need to output a float2 from the vertex shader as a TEXCOORD[n] that you can read into the pixel shader.

Quote:
Original post by edwinnie
I might as well get an X1K card and use VPOS instead. And I hope ATI supports VPOS...
Unlike when ATI cheated their way around vertex texturing, I don't see any way that they can't support VPOS [smile]

hth
Jack

Share this post


Link to post
Share on other sites
After you have applied this matrix there is a final step to get screen coordinates. X,Y and Z need to be divided by W. If you are sure that W is always 1 you don’t need to do this.

Share this post


Link to post
Share on other sites
ok i believe the method from the website and yours are essentially the same. But i believe the problem could lie with ATI 24bit precision as i realized that during readback, I have trailing errors with accumulate... sigh

thx again!
Edwin

Share this post


Link to post
Share on other sites

This topic is 4308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this