Skip to content

Commit

Permalink
Modify the opengl version of the blur shader to match the d3d11 version
Browse files Browse the repository at this point in the history
  • Loading branch information
y2kcyborg committed May 29, 2024
1 parent ac0c00a commit daab437
Showing 1 changed file with 76 additions and 11 deletions.
87 changes: 76 additions & 11 deletions data/shaders/gaussian_1d_texture.effect
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,33 @@ struct VertData {
float2 uv : TEXCOORD0;
};

float4 PremulToStraight(float4 col)
{
col.rgb = saturate(col.rgb / max(col.a, 0.0001f));
return col;
}

float4 StraightToPremul(float4 col)
{
col.rgb *= col.a;
return col;
}

VertData mainTransform(VertData v_in)
{
v_in.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
return v_in;
}

float4 mainImage(VertData v_in) : TARGET
float4 SampleBlur(float2 uv)
{
// DO THE BLUR
// 1. Sample incoming pixel, multiply by weight[0]
// float4 test = kernel_texture.Sample(tableSampler, float2(v_in.uv[0], 0.0));
// float4 test = kernel_texture.Sample(tableSampler, float2(uv[0], 0.0));
// float max_radius = kernel_texture.Sample(tableSampler, float2(1.0, 0.0))[1];
// return float4(test.g/max_radius, test.g/max_radius, test.g/max_radius, 1.0);
float weight = kernel_texture.Sample(tableSampler, float2(0.0f, 0.0f))[0];
float4 col = image.Sample(textureSampler, v_in.uv) * weight;
float4 col = image.Sample(textureSampler, uv) * weight;
float total_weight = weight;

// 2. March out from incoming pixel, multiply by corresponding weight.
Expand All @@ -55,18 +67,71 @@ float4 mainImage(VertData v_in) : TARGET
weight = kernel_values[0];
float offset = kernel_values[1];
total_weight += 2.0f*weight;
col += image.Sample(textureSampler, v_in.uv + (offset * texel_step)) * weight;
col += image.Sample(textureSampler, v_in.uv - (offset * texel_step)) * weight;
col += image.Sample(textureSampler, uv + (offset * texel_step)) * weight;
col += image.Sample(textureSampler, uv - (offset * texel_step)) * weight;
}
col /= total_weight;
return col;
}

technique Draw
float4 mainStraightToPremul(VertData v_in) : TARGET
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = mainImage(v_in);
}
return StraightToPremul(image.Sample(textureSampler, v_in.uv));
}

float4 mainPremulToStraight(VertData v_in) : TARGET
{
return PremulToStraight(image.Sample(textureSampler, v_in.uv));
}

float4 mainBlur(VertData v_in) : TARGET
{
// Input image is premultiplied
float4 col = SampleBlur(v_in.uv);
// Output is still premultiplied
return col;
}

float4 mainBlurPremulToStraight(VertData v_in) : TARGET
{
// Input image is premultiplied
float4 col = SampleBlur(v_in.uv);
// Output is straight alpha
return PremulToStraight(col);
}

technique DrawStraightToPremul
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = mainStraightToPremul(v_in);
}
}

technique DrawPremulToStraight
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = mainPremulToStraight(v_in);
}
}

technique DrawBlur
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = mainBlur(v_in);
}
}

technique DrawBlurPremulToStraight
{
pass
{
vertex_shader = mainTransform(v_in);
pixel_shader = mainBlurPremulToStraight(v_in);
}
}

0 comments on commit daab437

Please sign in to comment.