1
0

sharpness.effect 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Based on libretro shader https://github.com/libretro/common-shaders/blob/master/test/lab/misc/sharpness.cg
  2. // Converted to obs effect file by Nibbles
  3. uniform float4x4 ViewProj;
  4. uniform texture2d image;
  5. uniform float4x4 color_matrix;
  6. uniform float3 color_range_min = {0.0, 0.0, 0.0};
  7. uniform float3 color_range_max = {1.0, 1.0, 1.0};
  8. uniform texture2d target;
  9. uniform float4 color = {1.0, 1.0, 1.0, 1.0};
  10. uniform float sharpness;
  11. uniform float texture_width;
  12. uniform float texture_height;
  13. sampler_state def_sampler {
  14. Filter = Linear;
  15. AddressU = Clamp;
  16. AddressV = Clamp;
  17. };
  18. struct VertInOut {
  19. float4 pos : POSITION;
  20. float2 uv : TEXCOORD0;
  21. };
  22. struct VertOut {
  23. float4 pos : POSITION;
  24. float4 col : COLOR;
  25. float2 uv : TEXCOORD0;
  26. float4 t1 : TEXCOORD1;
  27. float4 t2 : TEXCOORD2;
  28. float4 t3 : TEXCOORD3;
  29. };
  30. VertOut VSDefault(VertInOut vert_in)
  31. {
  32. VertOut vert_out;
  33. vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
  34. vert_out.uv = vert_in.uv;
  35. vert_out.col = color;
  36. float2 ps = float2(1.0/texture_width, 1.0/texture_height);
  37. float dx = ps.x;
  38. float dy = ps.y;
  39. vert_out.t1 = vert_in.uv.xxxy + float4( -dx, 0, dx, -dy); // A B C
  40. vert_out.t2 = vert_in.uv.xxxy + float4( -dx, 0, dx, 0); // D E F
  41. vert_out.t3 = vert_in.uv.xxxy + float4( -dx, 0, dx, dy); // G H I
  42. return vert_out;
  43. }
  44. float4 PSDrawBare(VertOut vert_in) : TARGET
  45. {
  46. float4 E = image.Sample(def_sampler, vert_in.uv);
  47. float4 colorx = 8*E;
  48. float4 B = image.Sample(def_sampler, vert_in.t1.yw);
  49. float4 D = image.Sample(def_sampler, vert_in.t2.xw);
  50. float4 F = image.Sample(def_sampler, vert_in.t2.zw);
  51. float4 H = image.Sample(def_sampler, vert_in.t3.yw);
  52. colorx -= image.Sample(def_sampler, vert_in.t1.xw);
  53. colorx -= B;
  54. colorx -= image.Sample(def_sampler, vert_in.t1.zw);
  55. colorx -= D;
  56. colorx -= F;
  57. colorx -= image.Sample(def_sampler, vert_in.t3.xw);
  58. colorx -= H;
  59. colorx -= image.Sample(def_sampler, vert_in.t3.zw);
  60. colorx = ((E!=F && E!=D) || (E!=B && E!=H)) ? saturate(E + colorx*sharpness) : E;
  61. return colorx;
  62. }
  63. float4 PSDrawMatrix(VertOut vert_in) : TARGET
  64. {
  65. float4 E = image.Sample(def_sampler, vert_in.uv);
  66. float4 colorx = 8*E;
  67. float4 B = image.Sample(def_sampler, vert_in.t1.yw);
  68. float4 D = image.Sample(def_sampler, vert_in.t2.xw);
  69. float4 F = image.Sample(def_sampler, vert_in.t2.zw);
  70. float4 H = image.Sample(def_sampler, vert_in.t3.yw);
  71. colorx -= image.Sample(def_sampler, vert_in.t1.xw);
  72. colorx -= B;
  73. colorx -= image.Sample(def_sampler, vert_in.t1.zw);
  74. colorx -= D;
  75. colorx -= F;
  76. colorx -= image.Sample(def_sampler, vert_in.t3.xw);
  77. colorx -= H;
  78. colorx -= image.Sample(def_sampler, vert_in.t3.zw);
  79. colorx = ((E!=F && E!=D) || (E!=B && E!=H)) ? saturate(E + colorx*sharpness) : E;
  80. float4 yuv = colorx;
  81. yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
  82. return saturate(mul(float4(yuv.xyz, 1.0), color_matrix));
  83. }
  84. technique Draw
  85. {
  86. pass
  87. {
  88. vertex_shader = VSDefault(vert_in);
  89. pixel_shader = PSDrawBare(vert_in);
  90. }
  91. }
  92. technique DrawMatrix
  93. {
  94. pass
  95. {
  96. vertex_shader = VSDefault(vert_in);
  97. pixel_shader = PSDrawMatrix(vert_in);
  98. }
  99. }