//=============================================================================
//// Shader uses position and texture
//=============================================================================
SamplerState samPoint
{
Filter = MIN_MAG_MIP_POINT;
AddressU = Mirror;
AddressV = Mirror;
};
Texture2D gTexture;
float3 blackPoint = float3(0, 0, 0); // input: location of complete black (range: 0.0 - 1.0)
float3 whitePoint = float3(0.9f, 0.9f, 0.9f); // input: location of complete white (range: 0.0 - 1.0)
float3 gamma = float3(2.5f, 2.5f, 2.5f); // input: midtones adjustment (range: 1.0 - 3.0)
// Create Depth Stencil State (ENABLE DEPTH WRITING)
DepthStencilState EnableDepthStencilWriting
{
DepthEnable = TRUE;
DepthWriteMask = ALL;
DepthFunc = LESS;
};
BlendState NoBlending
{
BlendEnable[0] = FALSE;
};
// Create Rasterizer State (Backface culling)
RasterizerState gRS_BackfaceCulling
{
CullMode = BACK;
};
//IN/OUT STRUCTS
//--------------
struct VS_INPUT
{
float3 Position : POSITION;
float2 TexCoord : TEXCOORD0;
};
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 TexCoord : TEXCOORD1;
};
//VERTEX SHADER
//-------------
PS_INPUT VS(VS_INPUT input)
{
PS_INPUT output = (PS_INPUT) 0;
// Set the Position
output.Position = float4(input.Position, 1.0f);
// Set the TexCoord
output.TexCoord = input.TexCoord;
return output;
}
//PIXEL SHADER
//------------
float4 PS(PS_INPUT input) : SV_Target
{
// Step 1: sample the texture
float4 color = gTexture.Sample(samPoint, input.TexCoord);
// Step 2: apply Levels adjustment
color.rgb = (color.rgb - blackPoint) / (whitePoint - blackPoint); // Remap colors based on black and white points
color.rgb = pow(color.rgb, 1.0 / gamma); // Adjust midtones based on gamma
// Clamp values to [0, 1] range in case they are out of bounds after Levels adjustment
color.rgb = clamp(color.rgb, 0.0, 1.0);
// Step 3: return the color
return color;
}
//TECHNIQUE
//---------
technique11 LevelsAdjustment
{
pass P0
{
// Set states...
SetDepthStencilState(EnableDepthStencilWriting, 1);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); // added
SetRasterizerState(gRS_BackfaceCulling);
SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PS()));
}
}