SHOW:
|
|
- or go back to the newest paste.
| 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 | ||
| 4 | uniform float4x4 ViewProj; | |
| 5 | uniform texture2d image; | |
| 6 | uniform float4x4 color_matrix; | |
| 7 | uniform float3 color_range_min = {0.0, 0.0, 0.0};
| |
| 8 | uniform float3 color_range_max = {1.0, 1.0, 1.0};
| |
| 9 | ||
| 10 | uniform texture2d target; | |
| 11 | uniform float4 color = {1.0, 1.0, 1.0, 1.0};
| |
| 12 | ||
| 13 | uniform float sharpness; | |
| 14 | uniform float texture_width; | |
| 15 | uniform float texture_height; | |
| 16 | ||
| 17 | sampler_state def_sampler {
| |
| 18 | Filter = Linear; | |
| 19 | AddressU = Clamp; | |
| 20 | AddressV = Clamp; | |
| 21 | }; | |
| 22 | ||
| 23 | struct VertInOut {
| |
| 24 | float4 pos : POSITION; | |
| 25 | float2 uv : TEXCOORD0; | |
| 26 | }; | |
| 27 | ||
| 28 | struct VertOut {
| |
| 29 | float4 pos : POSITION; | |
| 30 | float4 col : COLOR; | |
| 31 | float2 uv : TEXCOORD0; | |
| 32 | }; | |
| 33 | ||
| 34 | VertOut VSDefault(VertInOut vert_in) | |
| 35 | {
| |
| 36 | VertOut vert_out; | |
| 37 | vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj); | |
| 38 | vert_out.uv = vert_in.uv; | |
| 39 | vert_out.col = color; | |
| 40 | ||
| 41 | return vert_out; | |
| 42 | } | |
| 43 | ||
| 44 | float4 PSDrawMatrix(VertOut vert_in) : TARGET | |
| 45 | {
| |
| 46 | float numBlurPixelsPerSide = 4.0; | |
| 47 | float2 blurMultiplyVec = float2(1.0, 0.0); | |
| 48 | float2 blurMultiplyVec2 = float2(0.0, 1.0); | |
| 49 | float sigma = 4.0; | |
| 50 | float pi = 3.14159265; | |
| 51 | float blurSize = sharpness / 25; | |
| 52 | ||
| 53 | float3 incrementalGaussian = float3(1.0 / (sqrt(2.0 * pi) * sigma), exp(-0.5 / (sigma * sigma)), exp(-0.5 / (sigma * sigma)) * exp(-0.5 / (sigma * sigma))); | |
| 54 | ||
| 55 | float4 avgValue = vec4(0.0, 0.0, 0.0, 0.0); | |
| 56 | float coefficientSum = 0.0; | |
| 57 | ||
| 58 | avgValue += image.Sample(def_sampler, vert_in.uv) * incrementalGaussian.x; | |
| 59 | coefficientSum += incrementalGaussian.x; | |
| 60 | incrementalGaussian.xy *= incrementalGaussian.yz; | |
| 61 | ||
| 62 | for (float i = 1.0f; i <= numBlurPixelsPerSide; i++) | |
| 63 | {
| |
| 64 | avgValue += image.Sample(def_sampler, vert_in.uv - i * blurSize * blurMultiplyVec) * incrementalGaussian.x; | |
| 65 | avgValue += image.Sample(def_sampler, vert_in.uv + i * blurSize * blurMultiplyVec) * incrementalGaussian.x; | |
| 66 | avgValue += image.Sample(def_sampler, vert_in.uv - i * blurSize * blurMultiplyVec2) * incrementalGaussian.x; | |
| 67 | avgValue += image.Sample(def_sampler, vert_in.uv + i * blurSize * blurMultiplyVec2) * incrementalGaussian.x; | |
| 68 | ||
| 69 | coefficientSum += 4 * incrementalGaussian.x; | |
| 70 | incrementalGaussian.xy *= incrementalGaussian.yz; | |
| 71 | } | |
| 72 | ||
| 73 | return avgValue / coefficientSum; | |
| 74 | } | |
| 75 | ||
| 76 | technique Draw | |
| 77 | {
| |
| 78 | pass | |
| 79 | {
| |
| 80 | vertex_shader = VSDefault(vert_in); | |
| 81 | pixel_shader = PSDrawMatrix(vert_in); | |
| 82 | } | |
| 83 | } | |
| 84 | ||
| 85 | technique DrawMatrix | |
| 86 | {
| |
| 87 | pass | |
| 88 | {
| |
| 89 | vertex_shader = VSDefault(vert_in); | |
| 90 | pixel_shader = PSDrawMatrix(vert_in); | |
| 91 | } | |
| 92 | } |