I'm a beginner pixel shader writer and I'm running into some trouble. I want to take a 256x256, 16-bit input (DXGI_FORMAT_R16_UINT) image, and pass it through a 256x256 look-up texture (DXGI_FORMAT_R8_UNORM) to convert it to a 256x256 8-bit output.
Unfortunately, I seem to be running into a lot of trouble and the output seems to always clamp to black or white.
Also, I'm not sure which DXGI formats I should be using, and also, which data type correlates with each format.
// Global Variables
Texture2D<uint> imgTexture : register( t0 );
Texture2D lutTexture : register( t1 );
SamplerState SampleType : register( s0 );
// Structures
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
};
// Pixel Shader
float4 PS( PS_INPUT input) : SV_Target
{
uint pixelValue = imgTexture[input.Tex];
uint2 index = { pixelValue / 256, pixelValue % 256 };
// uint row = pixelValue / 256;
// uint col = pixelValue % 256;
float4 output = lutTexture[index];
output.g = output.r;
output.b = output.r;
output.a = 1.0f;
return output;
}
Should I be normalizing the pixelValue before trying to turn it into a 2D index?
Should I be normalizing the index before using it?
Should I be sampling instead?
Am I even on the right path here?
I would appreciate ANY help, thanks!