default_rect.effect 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. uniform float4x4 ViewProj;
  2. uniform texture_rect image;
  3. sampler_state def_sampler {
  4. Filter = Linear;
  5. AddressU = Clamp;
  6. AddressV = Clamp;
  7. };
  8. struct VertInOut {
  9. float4 pos : POSITION;
  10. float2 uv : TEXCOORD0;
  11. };
  12. VertInOut VSDefault(VertInOut vert_in)
  13. {
  14. VertInOut vert_out;
  15. vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
  16. vert_out.uv = vert_in.uv;
  17. return vert_out;
  18. }
  19. float4 PSDrawBare(VertInOut vert_in) : TARGET
  20. {
  21. return image.Sample(def_sampler, vert_in.uv);
  22. }
  23. float4 PSDrawOpaque(VertInOut vert_in) : TARGET
  24. {
  25. return float4(image.Sample(def_sampler, vert_in.uv).rgb, 1.0);
  26. }
  27. float srgb_nonlinear_to_linear_channel(float u)
  28. {
  29. return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4);
  30. }
  31. float3 srgb_nonlinear_to_linear(float3 v)
  32. {
  33. return float3(srgb_nonlinear_to_linear_channel(v.r), srgb_nonlinear_to_linear_channel(v.g), srgb_nonlinear_to_linear_channel(v.b));
  34. }
  35. float4 PSDrawSrgbDecompress(VertInOut vert_in) : TARGET
  36. {
  37. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  38. rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
  39. return rgba;
  40. }
  41. technique Draw
  42. {
  43. pass
  44. {
  45. vertex_shader = VSDefault(vert_in);
  46. pixel_shader = PSDrawBare(vert_in);
  47. }
  48. }
  49. technique DrawOpaque
  50. {
  51. pass
  52. {
  53. vertex_shader = VSDefault(vert_in);
  54. pixel_shader = PSDrawOpaque(vert_in);
  55. }
  56. }
  57. technique DrawSrgbDecompress
  58. {
  59. pass
  60. {
  61. vertex_shader = VSDefault(vert_in);
  62. pixel_shader = PSDrawSrgbDecompress(vert_in);
  63. }
  64. }