I am trying to make a buffer to store object index then read it from CPU to implement mouse picking algorithm, but I don't know how to write to UAV buffer from a pixel shader. I coped tutorial 4 and modified it,when I add the first line in PS function the code doesn't compile.
Can anyone tell me what is the problem.
Thank you in advance.
//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
}
// dynamic
RWTexture2D<uint> DynamicBuffer : register(u0);
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR0;
uint id : ID;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VS( float4 Pos : POSITION, float4 Color : COLOR )
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.Pos = mul( Pos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Color = Color;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( VS_OUTPUT input ) : SV_Target
{
DynamicBuffer[uint2(input.Pos.xy)] = float(input.id); // error
return input.Color;
}