Advertisement
Krythic

BloomStencilShader

Aug 26th, 2020
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. struct Vertex
  2. {
  3.     float4 pos : POSITION;
  4.     float2 tex : TEXTURE;
  5.     float3 norm : NORMAL;
  6. };
  7.  
  8. struct PixelShaderArgs
  9. {
  10.     float4 pos : SV_POSITION;
  11.     float2 col : TEXTURE;
  12.     float3 norm : NORMAL;
  13. };
  14.  
  15. struct BloomShaderData
  16. {
  17.     float Threshold;
  18.     float Intensity;
  19.     float Padding1;
  20.     float Padding2;
  21. };
  22.  
  23. Texture2D ShaderTexture : register(t0);
  24. SamplerState Sampler : register(s0);
  25. float4x4 localMatrix : register(b0);
  26.  
  27. cbuffer BloomShaderDataBuffer : register(b1)
  28. {
  29.     BloomShaderData BloomData;
  30. };
  31.  
  32. PixelShaderArgs VertexShaderMain(Vertex vertex)
  33. {
  34.     PixelShaderArgs output;
  35.     output.pos = vertex.pos;
  36.     output.col = vertex.tex;
  37.     return output;
  38. }
  39.  
  40. float4 PixelShaderMain(PixelShaderArgs pixelShaderArgs) : SV_Target
  41. {
  42.     float4 diffuse = ShaderTexture.Sample(Sampler, pixelShaderArgs.col);
  43.     float luminosity = (diffuse.r * 0.2126) + (diffuse.g * 0.7152) + (diffuse.b * 0.0722);
  44.     if (luminosity > BloomData.Threshold)
  45.     {
  46.         return diffuse;
  47.     }
  48.     else
  49.     {
  50.         return float4(0, 0, 0, 0);
  51.     }
  52. }
  53.  
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement