sharpness.effect 2.0 KB

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