default_rect.effect 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 PSDrawSrgbDecompressPremultiplied(VertInOut vert_in) : TARGET
  36. {
  37. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  38. rgba.rgb = max(float3(0.0, 0.0, 0.0), rgba.rgb / rgba.a);
  39. rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
  40. return rgba;
  41. }
  42. technique Draw
  43. {
  44. pass
  45. {
  46. vertex_shader = VSDefault(vert_in);
  47. pixel_shader = PSDrawBare(vert_in);
  48. }
  49. }
  50. technique DrawOpaque
  51. {
  52. pass
  53. {
  54. vertex_shader = VSDefault(vert_in);
  55. pixel_shader = PSDrawOpaque(vert_in);
  56. }
  57. }
  58. technique DrawSrgbDecompressPremultiplied
  59. {
  60. pass
  61. {
  62. vertex_shader = VSDefault(vert_in);
  63. pixel_shader = PSDrawSrgbDecompressPremultiplied(vert_in);
  64. }
  65. }