im trying to implement ID value on geometry
so i use MRT, first render target is color texture and second render target is R32_UINT format and store unsigned int value
this is how my pixel shader works.
color for first render target and id for second one
struct PS_OUT
{
float4 color : SV_TARGET0;
uint id : SV_TARGET1;
};
....
...
..
.
output.color = tex[0].Sample(splr, tc * tilingFactor) * color;
output.id = 100;
return output;
and there is issue that is accessing id value from texture
i made same 2DTexture with second rendertarget and based on mouse position i coppied one pixel from texture that is second rendertarget (x,y is mouse position)
D3D11_TEXTURE2D_DESC textureDesc;
textureDesc.Width = 1;
textureDesc.Height = 1;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = (DXGI_FORMAT_R32_UINT);
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
textureDesc.Usage = D3D11_USAGE_STAGING;
textureDesc.BindFlags = 0;
textureDesc.MiscFlags = 0;
gfx.GetDevice()->CreateTexture2D(&textureDesc, nullptr, &pTexTemp);
D3D11_BOX srcBox;
srcBox.left = x;
srcBox.right = x + 1;
srcBox.bottom = y + 1;
srcBox.top = y;
srcBox.front = 0;
srcBox.back = 1;
gfx.GetContext()->CopySubresourceRegion(pTexTemp.Get(), 0, 0, 0, 0, pTexSource.Get(), 0, &srcBox);
D3D11_MAPPED_SUBRESOURCE msr = {};
gfx.GetContext()->Map(pTexTemp.Get(), 0, D3D11_MAP::D3D11_MAP_READ, 0, &msr);
if (x >= 0 && x <= m_width && y >= 0 && y <= m_height)
{
uint32_t* data = reinterpret_cast<uint32_t*>(msr.pData);
}
gfx.GetContext()->Unmap(pTexTemp.Get(), 0);
and through map,unmap i accessed a value and cast it unsigned int *
but i got the weird value. for test i assigned 100 at the rendertarget
i got the 4294967295 which is max value on unsigned int when i drag mouse to empty space i get 0 . (becauce there is nothing)
how can i read unsigned int value from texture? is there any problem in my code?
p.s i tried CopyResource method not copy one pixel data but result was same