Is it possible in D3D11 to tell to which the object on scene given pixel belongs? Could you give me some links ?
Ray picking and postprocessing
It's basically impossible to do this from the pixel level*, so ray tracing will be needed.
*I doubt if anyone actually does this, but you could have a frame that has each object render with a unique color ID (they must be unshaded, of course), which you could then use to identify the object.
It's basically impossible to do this from the pixel level*, so ray tracing will be needed.
*I doubt if anyone actually does this, but you could have a frame that has each object render with a unique color ID (they must be unshaded, of course), which you could then use to identify the object.
Well it's more "ray casting" since you just want to know what your mouse is pointing at, and don't need to trace the ray's path through the scene according to some physical situation. That might bring up some better google hits.
I have problem. Now i try to save 2 texture to file. One should be normal texture and second instead color have position. In first i create 2 ID3D11RenderTargetView and init them the same texture.
ID3D11RenderTargetView* renderTargetView[2];
...
ID3D11Texture2D* BackBuffer;
SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView[0] );
d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView[1] );
Next I set render targets
d3d11DevCon->OMSetRenderTargets( 2, renderTargetView, depthStencilView );
After drawing I try save render target. In both cases I get blue picture (color of clearing render target)
ID3D11Resource * res;
ID3D11Texture2D * tex;
renderTargetView[0]->GetResource(&res);//for renderTargetView[1] the same result
res->QueryInterface(&tex);
D3DX11SaveTextureToFile(
d3d11DevCon, tex, D3DX11_IFF_PNG, L"name.png");
This is my shader
cbuffer cbPerObject
{
float4x4 WVP;
};
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float3 normal : NORMAL;
};
struct PS_OUTPUT
{
float4 Color: SV_Target0;
float4 Color2: SV_Target1;
};
VS_OUTPUT VS(float4 inPos : POSITION, float3 inNormal : NORMAL)
{
VS_OUTPUT output;
output.Pos = mul(inPos, WVP);
output.normal = inNormal;
return output;
}
PS_OUTPUT PS(VS_OUTPUT input) : SV_TARGET
{
PS_OUTPUT psOut;
psOut.Color=float4(input.normal[0],input.normal[1],input.normal[2],1.0f);
psOut.Color2=input.Pos;
return psOut;
//return float4(input.normal[0],input.normal[1],input.normal[2],1.0f);
//return float4(1.0f,0.0f,0.0f,1.0f);
}
It's basically impossible to do this from the pixel level*, so ray tracing will be needed.
If each object gets own ID you could use stencil buffer or extra RT to save object's ID for each pixel.