Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// Grayscale post-processing effect
// AJ Weeks 2017
Texture2D gTexture;
float gIntensity;
SamplerState samPoint
{
Filter = MIN_MAG_MIP_POINT;
AddressU = Mirror;
AddressV = Mirror;
};
RasterizerState BackfaceCull
{
CullMode = NONE;
};
BlendState DisableBlending
{
BlendEnable[0] = FALSE;
};
DepthStencilState EnableDepth
{
DepthEnable = TRUE;
DepthWriteMask = ALL;
};
//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;
output.Position = float4(input.Position, 1.0);
output.TexCoord = input.TexCoord;
return output;
}
//PIXEL SHADER
//------------
float4 PS(PS_INPUT input): SV_Target
{
float4 sam = gTexture.Sample(samPoint, input.TexCoord);
float mean = 0.21 * sam.r + 0.72 * sam.g + 0.07 * sam.b;
return float4(lerp(sam.rgb, float3(mean, mean, mean), gIntensity), 1.0f);
}
//TECHNIQUE
//---------
technique11 Grayscale
{
pass P0
{
SetRasterizerState(BackfaceCull);
SetDepthStencilState(EnableDepth, 0);
SetBlendState(DisableBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment