screen space texcoord from vertex position [HLSL]

Started by
2 comments, last by edwinnie 18 years, 1 month ago
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
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
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

This topic is closed to new replies.

Advertisement