Chroma smear shaders?

I’m trying to set-up a VHS shader into my shader chain was wondering what my choices for chroma smear are?

I know there’s VHS in the vhs folder.

Also as a final note, @hunterk are you still working on that (red smear?) shader?

Hmm, I guess so. I never really did anything with it (like put it in the repo or whatever), but I think I might have posted the code somewhere, didn’t I?

1 Like

No, I’m pretty sure all you ever did was post some screens of it. (Happy to be corrected though, lol)

I tend to download any code you post, and I don’t have the red smear. (I don’t enjoy digging through the forums for code, lol.)

Ah, it must be sitting on my office computer, then, so I won’t have access to it until I go back to my office.

EDIT: had to go to the office for something today, so here you go:

#version 450

layout(push_constant) uniform Push
{
	vec4 SourceSize;
	vec4 OriginalSize;
	vec4 OutputSize;
	uint FrameCount;
   float smearsize;
   float overdrive_r;
} params;

#pragma parameter smearsize "Chroma Bleed" 0.5 0.0 1.0 0.05
#pragma parameter overdrive_r "Red Overdrive" 0.5 0.0 1.0 0.05

layout(std140, set = 0, binding = 0) uniform UBO
{
	mat4 MVP;
} global;

/////////////////////////////////  MIT LICENSE  ////////////////////////////////

//  Copyright (C) 2014 TroggleMonkey
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to
//  deal in the Software without restriction, including without limitation the
//  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
//  sell copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//  
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
//  IN THE SOFTWARE.


///////////////////////////////  VERTEX INCLUDES  ///////////////////////////////

#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 tex_uv;
layout(location = 1) out vec2 blur_dxdy;

void main()
{
   gl_Position = global.MVP * Position;
   tex_uv = TexCoord;

	//  Get the uv sample distance between output pixels.  Blurs are not generic
    //  Gaussian resizers, and correct blurs require:
    //  1.) OutputSize.xy == SourceSize.xy * 2^m, where m is an integer <= 0.
    //  2.) mipmap_inputN = "true" for this pass in .cgp preset if m != 0
    //  3.) filter_linearN = "true" except for 1x scale nearest neighbor blurs
    //  Gaussian resizers would upsize using the distance between input texels
    //  (not output pixels), but we avoid this and consistently blur at the
    //  destination size.  Otherwise, combining statically calculated weights
    //  with bilinear sample exploitation would result in terrible artifacts.   
    const vec2 dxdy_scale = params.SourceSize.xy * params.OutputSize.zw;
	const vec2 dxdy = dxdy_scale * params.SourceSize.zw;
    //  This blur is horizontal-only, so zero out the vertical offset:
	blur_dxdy = vec2(dxdy.x, 0.0);
}

///////////////////////////////  FRAGMENT SHADER  //////////////////////////////

#pragma stage fragment
layout(location = 0) in vec2 tex_uv;
layout(location = 1) in vec2 blur_dxdy;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define input_texture Source

mat3x3 RGB_to_YIQ = mat3x3(
         0.299,0.587,0.114, 
		 0.595716,-0.274453,-0.321263,
		 0.211456,-0.522591, 0.311135);
mat3x3 YIQ_to_RGB = mat3x3(
         1.0,0.9563,0.6210, 
		 1.0,-0.2721,-0.6474,
		 1.0,-1.1070, 1.7046);
       
//  Modified from TroggleMonkey's original to only smear to the right
float get_fast_gaussian_weight_sum_inv(const float sigma)
{
    //  We can use the Gaussian integral to calculate the asymptotic weight for
    //  the center pixel.  Since the unnormalized center pixel weight is 1.0,
    //  the normalized weight is the same as the weight sum inverse.  Given a
    //  large enough blur (9+), the asymptotic weight sum is close and faster:
    //      center_weight = 0.5 *
    //          (erf(0.5/(sigma*sqrt(2.0))) - erf(-0.5/(sigma*sqrt(2.0))))
    //      erf(-x) == -erf(x), so we get 0.5 * (2.0 * erf(blah blah)):
    //  However, we can get even faster results with curve-fitting.  These are
    //  also closer than the asymptotic results, because they were constructed
    //  from 64 blurs sizes from [3, 131) and 255 equally-spaced sigmas from
    //  (0, blurN_std_dev), so the results for smaller sigmas are biased toward
    //  smaller blurs.  The max error is 0.0031793913.
    //  Relative FPS: 134.3 with erf, 135.8 with curve-fitting.
    //static const float temp = 0.5/sqrt(2.0);
    //return erf(temp/sigma);
    return min(exp(exp(0.348348412457428/
        (sigma - 0.0860587260734721))), 0.399334576340352/sigma);
}
       
const float blur43_std_dev = 10.1852050781;

vec3 blur43fast(const sampler2D tex, const vec2 tex_uv,
    const vec2 dxdy, const float sigma)
{
    //  Requires:   Same as tex2Dblur11()
    //  Returns:    A 1D 43x Gaussian blurred texture lookup using 22 linear
    //              taps.  It may be mipmapped depending on settings and dxdy.
    //  First get the texel weights and normalization factor as above.
    const float denom_inv = 0.5/(sigma*sigma);
    const float w0 = 1.0;
    const float w1 = exp(-1.0 * denom_inv);
    const float w2 = exp(-4.0 * denom_inv);
    const float w3 = exp(-9.0 * denom_inv);
    const float w4 = exp(-16.0 * denom_inv);
    const float w5 = exp(-25.0 * denom_inv);
    const float w6 = exp(-36.0 * denom_inv);
    const float w7 = exp(-49.0 * denom_inv);
    const float w8 = exp(-64.0 * denom_inv);
    const float w9 = exp(-81.0 * denom_inv);
    const float w10 = exp(-100.0 * denom_inv);
    const float w11 = exp(-121.0 * denom_inv);
    const float w12 = exp(-144.0 * denom_inv);
    const float w13 = exp(-169.0 * denom_inv);
    const float w14 = exp(-196.0 * denom_inv);
    const float w15 = exp(-225.0 * denom_inv);
    const float w16 = exp(-256.0 * denom_inv);
    const float w17 = exp(-289.0 * denom_inv);
    const float w18 = exp(-324.0 * denom_inv);
    const float w19 = exp(-361.0 * denom_inv);
    const float w20 = exp(-400.0 * denom_inv);
    const float w21 = exp(-441.0 * denom_inv);
    //const float weight_sum_inv = 1.0 /
    //    (w0 + 2.0 * (w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9 + w10 + w11 +
    //        w12 + w13 + w14 + w15 + w16 + w17 + w18 + w19 + w20 + w21));
    const float weight_sum_inv = get_fast_gaussian_weight_sum_inv(sigma);
    //  Calculate combined weights and linear sample ratios between texel pairs.
    //  The center texel (with weight w0) is used twice, so halve its weight.
    const float w0_1 = w0 * 0.5 + w1;
    const float w2_3 = w2 + w3;
    const float w4_5 = w4 + w5;
    const float w6_7 = w6 + w7;
    const float w8_9 = w8 + w9;
    const float w10_11 = w10 + w11;
    const float w12_13 = w12 + w13;
    const float w14_15 = w14 + w15;
    const float w16_17 = w16 + w17;
    const float w18_19 = w18 + w19;
    const float w20_21 = w20 + w21;
    const float w0_1_ratio = w1/w0_1;
    const float w2_3_ratio = w3/w2_3;
    const float w4_5_ratio = w5/w4_5;
    const float w6_7_ratio = w7/w6_7;
    const float w8_9_ratio = w9/w8_9;
    const float w10_11_ratio = w11/w10_11;
    const float w12_13_ratio = w13/w12_13;
    const float w14_15_ratio = w15/w14_15;
    const float w16_17_ratio = w17/w16_17;
    const float w18_19_ratio = w19/w18_19;
    const float w20_21_ratio = w21/w20_21;
    //  Statically normalize weights, sum weighted samples, and return:
    vec3 sum = vec3(0.0,0.0,0.0);
    sum += w20_21 * texture(tex, tex_uv - (20.0 + w20_21_ratio) * dxdy).rgb;
    sum += w18_19 * texture(tex, tex_uv - (18.0 + w18_19_ratio) * dxdy).rgb;
    sum += w16_17 * texture(tex, tex_uv - (16.0 + w16_17_ratio) * dxdy).rgb;
    sum += w14_15 * texture(tex, tex_uv - (14.0 + w14_15_ratio) * dxdy).rgb;
    sum += w12_13 * texture(tex, tex_uv - (12.0 + w12_13_ratio) * dxdy).rgb;
    sum += w10_11 * texture(tex, tex_uv - (10.0 + w10_11_ratio) * dxdy).rgb;
    sum += w8_9 * texture(tex, tex_uv - (8.0 + w8_9_ratio) * dxdy).rgb;
    sum += w6_7 * texture(tex, tex_uv - (6.0 + w6_7_ratio) * dxdy).rgb;
    sum += w4_5 * texture(tex, tex_uv - (4.0 + w4_5_ratio) * dxdy).rgb;
    sum += w2_3 * texture(tex, tex_uv - (2.0 + w2_3_ratio) * dxdy).rgb;
    sum += w0_1 * texture(tex, tex_uv - w0_1_ratio * dxdy).rgb;
    // leave a couple with low offsets to sort of halo the objects
    sum += w0_1 * texture(tex, tex_uv + w0_1_ratio * dxdy).rgb;
    sum += w2_3 * texture(tex, tex_uv + (2.0 + w2_3_ratio) * dxdy).rgb;
    sum += w4_5 * texture(tex, tex_uv + (4.0 + w4_5_ratio) * dxdy).rgb;
    sum += w6_7 * texture(tex, tex_uv - (6.0 + w6_7_ratio) * dxdy).rgb;
    sum += w8_9 * texture(tex, tex_uv - (8.0 + w8_9_ratio) * dxdy).rgb;
    sum += w10_11 * texture(tex, tex_uv - (10.0 + w10_11_ratio) * dxdy).rgb;
    sum += w12_13 * texture(tex, tex_uv - (12.0 + w12_13_ratio) * dxdy).rgb;
    sum += w14_15 * texture(tex, tex_uv - (14.0 + w14_15_ratio) * dxdy).rgb;
    sum += w16_17 * texture(tex, tex_uv - (16.0 + w16_17_ratio) * dxdy).rgb;
    sum += w18_19 * texture(tex, tex_uv - (18.0 + w18_19_ratio) * dxdy).rgb;
    sum += w20_21 * texture(tex, tex_uv - (20.0 + w20_21_ratio) * dxdy).rgb;
    return sum * weight_sum_inv;
}

vec3 blur43fast(const sampler2D tex, const vec2 tex_uv,
    const vec2 dxdy)
{
    return blur43fast(tex, tex_uv, dxdy, blur43_std_dev);
}
		 
#define saturate(c) clamp(c, 0.0, 1.0)
void main()
{
   // sample image, convert to YIQ
   FragColor.rgb = texture(Source, tex_uv).rgb * RGB_to_YIQ;
   // blurry sample
	vec3 color = blur43fast(Source, tex_uv, blur_dxdy);
   // isolate areas that are very red from ones that just have red in them
   float redsmear = max(saturate(color.r - color.g),  saturate(color.r - color.b));
   // put our blurry screen into YIQ
   vec3 yiq_color = color * RGB_to_YIQ;
   // smear chroma components but leave luma sharp
   FragColor.gb = mix(FragColor.gb, yiq_color.gb, params.smearsize);

   FragColor = (vec4(FragColor.rgb * YIQ_to_RGB, 1.0));
   // overdrive our reds
   FragColor.r = mix(FragColor.r, FragColor.r + redsmear, params.overdrive_r);
}

And here’s the preset:

shaders = 1

shader0 = chroma-smear.slang
scale_type0 = source
scale0 = 1.0
wrap_mode0 = mirrored_repeat
1 Like