• Advertisement

Archived

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

Render to texture - reaching every pixel

This topic is 5490 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, I want to use a texture as render target and I need to reach every pixel of that texture exactly once. This is because I''m doing some numerical computations in the pixel shader in HLSL and the result is rendered into a texture. Therefore I use a quad (2 triangles) that is rendered exactly to the texture size. I''m looking for a more precise way, because the 3D triangles (quad) have to be mapped to the 2D texture and this not stable if the texture size changes. Is there a simpler way to implement that? I thought of some 2D pixel function drawing a filled box or something. If that is possible, can I use pixel shaders here, too? By the way I''m using DirectX 9.0 Thanks

Share this post


Link to post
Share on other sites
Advertisement
Meanwhile I got the texture shader running, but I don''t know how to set texture as input parameters. Is that possible?

Share this post


Link to post
Share on other sites
I was able to render to a texture using D3DXFillTexture but when I try to access every pixel inside the texture I get strange results, like the following code gives funny blue and yellow verticals stripes.... My texture is 32*32 (I hardcoded it in the example) Another thing, I call this block of code after loading a real 32*32 texture, so basically it should write over a red texture. I should get an entire blue texture with that :


  
m_pMeshTextures[0]->LockRect(0,&rect,NULL,0);
DWORD *pImage = (DWORD*)rect.pBits;

DWORD dwPitchShift = rect.Pitch / 4;

for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 32; j++)
{
pImage[j] = D3DCOLOR_XRGB(0, 0, 255);
}
pImage += dwPitchShift;
}

m_pMeshTextures[0]->UnlockRect(0);


Is there another way to access the pixel with or without locking the texture.

Frankski

Share this post


Link to post
Share on other sites
hmm. I can''t see anything wrong in your code and this is the only way I know to access textures.

I haven''t tried to access textures with D3DXFillTexture() but within D3DXFillTextureTX() in pixel shaders.
But it didn''t work because there seems to be no methode to set texture parameters to D3DXFillTextureTX() in the constant table.

I tried to bind the texture to the first texture unit with Device->SetTexture(0,...) but everything remains black.

Do you know something about that?

Share this post


Link to post
Share on other sites
I came up with 2 potential solutions to date. The first : use a pixel shader on that texture. I am relatively new to pixel or vertex shaders but after seing some vertex shaders example in the dx9 sdk I think I will go this way and create a pixel shader. I just have to learn it.

The other way I came up to was to use a secondary array to make my calculation on and then fetch the data to the appropriate texel in my texture. What I want is to make so sort of animated cloud effect (a bit like old plasma effect) and render that to a texture. Since it seems next to impossible/unsafe to play with texel/screen pixel directly with Dx3d, I thought I could make my calculations in that array (which would have the same size as my texture)then use D3DXFillTexture with a function that copy each element of my array to the corresponding texel in my texture.

Frankski

Share this post


Link to post
Share on other sites
I''m currenly using pixel shaders and vertex shaders to fill my textures, but I thought using texture shaders as they are much more elegant in code design.

Please tell me your ideas how to use pixel shaders to fill textures. I do it by setting a render target to that texture and then render to triangles in space exactly to the size of the texture. Texture shaders would be much better.

Share this post


Link to post
Share on other sites

  • Advertisement