sharpness.effect 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 texture2d target;
  6. uniform float sharpness;
  7. uniform float texture_width;
  8. uniform float texture_height;
  9. sampler_state def_sampler {
  10. Filter = Linear;
  11. AddressU = Clamp;
  12. AddressV = Clamp;
  13. };
  14. struct VertInOut {
  15. float4 pos : POSITION;
  16. float2 uv : TEXCOORD0;
  17. };
  18. struct VertOut {
  19. float4 pos : POSITION;
  20. float2 uv : TEXCOORD0;
  21. float4 t1 : TEXCOORD1;
  22. float4 t2 : TEXCOORD2;
  23. float4 t3 : TEXCOORD3;
  24. };
  25. VertOut VSDefault(VertInOut vert_in)
  26. {
  27. VertOut vert_out;
  28. vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
  29. vert_out.uv = vert_in.uv;
  30. float2 ps = float2(1.0/texture_width, 1.0/texture_height);
  31. float dx = ps.x;
  32. float dy = ps.y;
  33. vert_out.t1 = vert_in.uv.xxxy + float4( -dx, 0, dx, -dy); // A B C
  34. vert_out.t2 = vert_in.uv.xxxy + float4( -dx, 0, dx, 0); // D E F
  35. vert_out.t3 = vert_in.uv.xxxy + float4( -dx, 0, dx, dy); // G H I
  36. return vert_out;
  37. }
  38. float4 PSDrawBare(VertOut vert_in) : TARGET
  39. {
  40. float4 E = image.Sample(def_sampler, vert_in.uv);
  41. float4 color = 8*E;
  42. float4 B = image.Sample(def_sampler, vert_in.t1.yw);
  43. float4 D = image.Sample(def_sampler, vert_in.t2.xw);
  44. float4 F = image.Sample(def_sampler, vert_in.t2.zw);
  45. float4 H = image.Sample(def_sampler, vert_in.t3.yw);
  46. color -= image.Sample(def_sampler, vert_in.t1.xw);
  47. color -= B;
  48. color -= image.Sample(def_sampler, vert_in.t1.zw);
  49. color -= D;
  50. color -= F;
  51. color -= image.Sample(def_sampler, vert_in.t3.xw);
  52. color -= H;
  53. color -= image.Sample(def_sampler, vert_in.t3.zw);
  54. color = ((E!=F && E!=D) || (E!=B && E!=H)) ? saturate(E + color*sharpness) : E;
  55. return color;
  56. }
  57. technique Draw
  58. {
  59. pass
  60. {
  61. vertex_shader = VSDefault(vert_in);
  62. pixel_shader = PSDrawBare(vert_in);
  63. }
  64. }