Skip to main content
edited body
Source Link

I use a uint texture to store material ID's.

The shader output struct I use for this is and the ID constant:

uint matID;

struct GBufferPixelShaderOutputPixelShaderOutput
{   
float4 Color : SV_Target0;     
 uint RenderMaterialID : SV_Target2;SV_Target0;   
};

Write to the output targets:

GBufferPixelShaderOutputPixelShaderOutput PShader(PixelShaderInput input)
{
 GBufferPixelShaderOutputPixelShaderOutput output = (GBufferPixelShaderOutputPixelShaderOutput) 0;
float4 Color =  colorMap.Sample(colorSampler, input.TexCoord); 

 output.RenderMaterialID = matID;
output.Color = Color;

 return output;
}

Then just read back the ID texture at a later stage in your render pipeline

Texture2D<uint> RenderMaterialIDs;
uint MatID = RenderMaterialIDs.Load(uint3(globalIdx.x, globalIdx.y, 0));

I use a uint texture to store material ID's.

The shader output struct I use for this is and the ID constant:

uint matID;

struct GBufferPixelShaderOutput
{   
float4 Color : SV_Target0;     
uint RenderMaterialID : SV_Target2;   
};

Write to the output targets:

GBufferPixelShaderOutput PShader(PixelShaderInput input)
{
 GBufferPixelShaderOutput output = (GBufferPixelShaderOutput) 0;
float4 Color =  colorMap.Sample(colorSampler, input.TexCoord); 

output.RenderMaterialID = matID;
output.Color = Color;

 return output;
}

Then just read back the ID texture at a later stage in your render pipeline

Texture2D<uint> RenderMaterialIDs;
uint MatID = RenderMaterialIDs.Load(uint3(globalIdx.x, globalIdx.y, 0));

I use a uint texture to store material ID's.

The shader output struct I use for this is and the ID constant:

uint matID;

struct PixelShaderOutput
{          
 uint RenderMaterialID : SV_Target0;   
};

Write to the output targets:

PixelShaderOutput PShader(PixelShaderInput input)
{
 PixelShaderOutput output = (PixelShaderOutput) 0;   
 output.RenderMaterialID = matID;  

 return output;
}

Then just read back the ID texture at a later stage in your render pipeline

Texture2D<uint> RenderMaterialIDs;
uint MatID = RenderMaterialIDs.Load(uint3(globalIdx.x, globalIdx.y, 0));
Source Link

I use a uint texture to store material ID's.

The shader output struct I use for this is and the ID constant:

uint matID;

struct GBufferPixelShaderOutput
{   
float4 Color : SV_Target0;     
uint RenderMaterialID : SV_Target2;   
};

Write to the output targets:

GBufferPixelShaderOutput PShader(PixelShaderInput input)
{
 GBufferPixelShaderOutput output = (GBufferPixelShaderOutput) 0;
float4 Color =  colorMap.Sample(colorSampler, input.TexCoord); 

output.RenderMaterialID = matID;
output.Color = Color;

 return output;
}

Then just read back the ID texture at a later stage in your render pipeline

Texture2D<uint> RenderMaterialIDs;
uint MatID = RenderMaterialIDs.Load(uint3(globalIdx.x, globalIdx.y, 0));