sharpness.effect 1.8 KB

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