shade29450

I wisth to fill in floating point values in a texture, I have tried to outline the idea below. I have however not really understood the way you can access texture data, the texture is of the format D3DFMT_A32B32G32R32F, kinda miss glTexImage2D


D3DLOCKED_RECT LockedRect;
md_pTexture->LockRect(0,&LockedRect,NULL,0);
FLOAT *pbits = (FLOAT *) LockedRect.pBits;
for(int x = 0; x < md_nWidth; x++)
{
for(int y = 0; y < md_nHeight; y++)
{
pbits[x+y*LockedRect.Pitch+0] = 1.0f;
pbits[x+y*LockedRect.Pitch+1] = 0.0f;
pbits[x+y*LockedRect.Pitch+2] = 0.0f;
pbits[x+y*LockedRect.Pitch+3] = 0.0f;
}
}
md_pTexture->UnlockRect(0);


Re: Game Technologies: Graphics manual texture access

BLANC Guillaume

Your code looks good to me, isn't it working

Anyway, I would have rather use the gpu to initialize pixel values so that you would not have to worry about formats:

- Use the Device->Clear function once the texture has been set as the current render target

- Render a quad other the texture and use a pixel shader that ouput the pixel color you want

- Use D3DXFillTextureTX that enable using a shader to procedurally fill out the texture

All those methods will allow you to set pixels color without worrying of the pixel format. 

 






Re: Game Technologies: Graphics manual texture access

shade


The code does like "ok" but It doesnot give correct results...

So if you have a working example I would very much appreciate it.
I would like to fill the floating point texture with data from system memory, kinda like under OpenGL glTexImage2D.

I have an array of D3DXVECTOR4s and would like to fill the vectors into a my floating point texture.

1) ->Clear is not valid for operations as this.
2) A screen sized quad and pixel shader is not helping either.

Could you demonstrate how to use D3DXFillTextureTX I know of the functions but havent found an example...




Re: Game Technologies: Graphics manual texture access

BLANC Guillaume

>> The code does like "ok" but It doesnot give correct results...

What are the results, could you explain or send a screenshot Maybe it could help.

Have you try to work with a simpler RGBA d3dformat to debug your code You can have a look to this nexe entry which explains how to do what you're expecting to do. It's working exactly the same way OpenGL is working : mapping pixels to main memory, and that's it. I've double checked my code doing this, and there's really nothing more complicated you could have miss. Maybe you could just test Dx function call returns to be sure everything's ok.
Also, maybe the problem is not in filling the texture, but rather the way you're using it later on, can it


>> I have an array of D3DXVECTOR4s and would like to fill the vectors into a my floating point texture.

I don't know how a floating format is stored in memory, that's why I recommend you to use a shader which abstracts that point. I understand it can not be used in your case, but it still can help understanding how pixels are stored (using Pix maybe).

>> Could you demonstrate how to use D3DXFillTextureTX I know of the functions but havent found an example...

I don't have any example either.






Re: Game Technologies: Graphics manual texture access

shade

Sure OpenGL and DirectX are interfacing the same hardware but the interface of glTexImage2D and D3DXFillTextureTX or using LockRect are very different.

I will try with ordinary non fp - RGB format and check back, if I solve the puzzle.






Re: Game Technologies: Graphics manual texture access

BLANC Guillaume

The only difference I can see between the two APi is that OpenGL is reading from a memory buffer of pixels and DirectX returns a memory buffer (using LockRect function) that must be filled by the application. Even if OpenGL version seems safier, it's still doing the same thing because it's application responsability to correctly fill the pixel buffer with valid data including a valid pitch, a valid format conversion, and so on...

Tell me if you get problems working with a RGB format, I'll prepare a sample code.





Re: Game Technologies: Graphics manual texture access

shade

I am DirectX man all the way ;-) Still i just find the resource management at times is cumbersome.

Anyways I am able to access a ordinary rgba/rgb texture but I am not able to do the same trick with a floating point texture. Below is a very simple example of an ordinary rgba texture which works, but the same procedure will not work for a floating point texture.

I need a floating point texture for a path tracer I have implemented which performs the HDR correction using a few shaders but with an ordinary rgba texture I am not able to store radiance values which are beyond 255 .

For a floating point example see below

hr = md_pd3dDevice->CreateTexture(md_nWidth,md_nHeight,
   1,D3DUSAGE_DYNAMIC,D3DFMT_A8R8G8B8,
    D3DPOOL_DEFAULT,&md_pTexture,NULL);
if(FAILED(hr))
{
    hr = E_FAIL;
    return hr;
}

D3DLOCKED_RECT LockedRect;
hr = md_pTexture->LockRect(0,&LockedRect,NULL,0);
if(FAILED(hr))
{
   hr = E_FAIL;
   return hr;
}
DWORD *pbits = (DWORD *) LockedRect.pBits;
for(int y = 0; y < md_nHeight; y++)
{
    DWORD dwOffset = y*md_nWidth;
    for(int x = 0; x < md_nWidth; x++)
    {
        DWORD b = 255;
        DWORD g = 0;
        DWORD r = 0;
        DWORD a = 0;
        pbits[dwOffset+x] = ( ( a<<24L ) + ( r<<16L ) + ( g<<8L )+( b ) );
    }
}
hr = md_pTexture->UnlockRect(0);
if(FAILED(hr))
{
   hr = E_FAIL;
   return hr;
}


    floating point texture (D3DFMT_A32B32G32R32F)
    D3DXVECTOR4 *pbits = (D3DXVECTOR4 *) LockedRect.pBits;
    for(int y = 0; y < md_nHeight; y++)
    {
        DWORD dwOffset = y*md_nWidth;
        for(int x = 0; x < md_nWidth; x++)
        {
            pbits[dwOffset+x] = D3DXVECTOR4(0.0f,1.0f,0.0f,1.0f);
        }
    }