Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Generating "Screen Aligned Projective Texture"

This topic is 5985 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

Hi, there. I have some difficulty in generating texture called "Screen Aligned Projective Texture"(I''ve seen that name in the article titled "GPU Toon Rendering" in nvidia homepage. "Screen Aligned Projective Texture" is the texture that the RGB value of texel in it represents normalized vector links some point in near clip plane to camera position. I excerpted some words about it from "GPU Toon Rendering". "For each pixel on the screen, envision a view vector. The center of the screen holds a vector pointing straight out of the screen <0, 0, -1>. (If we assume a 90 degree field of view with a square aspect ratio)The upper left corner would hold a vector pointing toward the upper left <-sqrt(3),-sqrt(3), -sqrt(3)>, and so on. In between the vectors would be smoothly interpolated. We can create a texture that holds these vectors in RGB form. We will use this texture to hold our modified view vector. " So I made some function to generate "Screen Aligned Projective Texture"(This function is used as callback function of D3DXFillTexture() ). float aspect; //screen width / screen height float fovy; void FillViewVectorMap(D3DXVECTOR4* pOut,//RGBA of texel(output) D3DXVECTOR2* pTexCoord, //(u,v) of texel(input) D3DXVECTOR2* pTexelSize, //no use LPVOID pData){ //no use float w, h; D3DXVECTOR3 v; h = tanf(fovy * 0.5f) * 2; w = h * aspect; v.x = w * (0.5f - pTexCoord->x); v.y = h * (pTexCoord->y - 0.5f); v.z = -1; v /= D3DXVec3Length(&v); //nomalization pOut->x = v3.x * 0.5f + 0.5f; //some scaling and bias. pOut->y = v3.y * 0.5f + 0.5f; //because coordinates of vector pOut->z = v3.z * 0.5f + 0.5f; //is in [-1.1] but color value is pOut->w = 1.0f; //in [0,1]. } But, above function doesn''t work correctly. If you know where''s wrong, please let me know. Thanks.

Share this post

Link to post
Share on other sites

D3DXVECTOR4* pOut,//RGBA of texel(output)

D3DXVECTOR4 is 16 bytes large, 4*32 bits, an ARGB value is only 1*32 bits

im not sure if this is the answer to your problems, but i guess you should store it as with the DOT3-bump textures, where each component of the vector is a signed byte, a normalized vector can then be translated as:
signed char cx = vec->x*255.f;

hope this helps

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!