testgpurender_effects_CRT.frag.hlsl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This shader is adapted from the Lightweight CRT Effect at:
  2. // https://godotshaders.com/shader/lightweight-crt-effect/
  3. cbuffer Context : register(b0, space3) {
  4. float2 resolution;
  5. };
  6. Texture2D u_texture : register(t0, space2);
  7. SamplerState u_sampler : register(s0, space2);
  8. struct PSInput {
  9. float4 v_color : COLOR0;
  10. float2 v_uv : TEXCOORD0;
  11. };
  12. struct PSOutput {
  13. float4 o_color : SV_Target;
  14. };
  15. static const float PI = 3.14159265f;
  16. // These could be turned into uniforms if you wanted to tweak them
  17. static const float scan_line_amount = 0.5; // Range 0-1
  18. static const float warp_amount = 0.05; // Range 0-1
  19. static const float vignette_amount = 0.5; // Range 0-1
  20. static const float vignette_intensity = 0.3; // Range 0-1
  21. static const float grille_amount = 0.05; // Range 0-1
  22. static const float brightness_boost = 1.2; // Range 1-2
  23. PSOutput main(PSInput input) {
  24. PSOutput output;
  25. float2 uv = input.v_uv;
  26. float2 delta = uv - 0.5;
  27. float warp_factor = dot(delta, delta) * warp_amount;
  28. uv += delta * warp_factor;
  29. float scanline = sin(uv.y * resolution.y * PI) * 0.5 + 0.5;
  30. scanline = lerp(1.0, scanline, scan_line_amount * 0.5);
  31. float grille = fmod(uv.x * resolution.x, 3.0) < 1.5 ? 0.95 : 1.05;
  32. grille = lerp(1.0, grille, grille_amount * 0.5);
  33. float4 color = u_texture.Sample(u_sampler, input.v_uv) * input.v_color;
  34. color.rgb *= scanline * grille;
  35. float2 v_uv = uv * (1.0 - uv.xy);
  36. float vignette = v_uv.x * v_uv.y * 15.0;
  37. vignette = lerp(1.0, vignette, vignette_amount * 0.7);
  38. color.rgb *= vignette * brightness_boost;
  39. output.o_color = color;
  40. return output;
  41. }