Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active August 15, 2026 04:45
Show Gist options
  • Select an option

  • Save amirrajan/6894f307efe04227a019f155812c0ad9 to your computer and use it in GitHub Desktop.

Select an option

Save amirrajan/6894f307efe04227a019f155812c0ad9 to your computer and use it in GitHub Desktop.
gray scale shader
Texture2D tex_scene : register(t0, space2);
SamplerState sam_scene : register(s0, space2);
struct Input {
float4 tex_color : COLOR0;
float2 tex_coord : TEXCOORD0;
};
struct Output {
float4 frag_color : SV_Target;
};
Output main(Input input) {
Output output;
float4 color = tex_scene.Sample(sam_scene, input.tex_coord) * input.tex_color;
// https://en.wikipedia.org/wiki/Grayscale
float4 luma = dot(color.rgb, float3(0.2126, 0.7152, 0.0722));
output.frag_color = float4(luma.r, luma.g, luma.b, color.a);
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment