Skip to content

Instantly share code, notes, and snippets.

@ajweeks
Last active August 21, 2017 14:52
Show Gist options
  • Save ajweeks/cb00bd2ce0b3fb2d5dc70d95d8924f03 to your computer and use it in GitHub Desktop.
Save ajweeks/cb00bd2ce0b3fb2d5dc70d95d8924f03 to your computer and use it in GitHub Desktop.
// 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