Skip to content

Instantly share code, notes, and snippets.

@yanorei32
Last active February 3, 2022 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanorei32/c9d3d138edf69c98fe2afb4003b73e0c to your computer and use it in GitHub Desktop.
Save yanorei32/c9d3d138edf69c98fe2afb4003b73e0c to your computer and use it in GitHub Desktop.
uniform int shadow_blur_unit_dist;
uniform float shadow_blur_gain;
uniform float4 shadow_color;
float4 mainImage(VertData v_in) : TARGET {
float invsqrt2 = 0.70710678118654;
float2x2 rotateClockwise45 = {
invsqrt2, -invsqrt2,
invsqrt2, invsqrt2,
};
float sampled_shadow_alpha = 0;
float2 offset = float2(0, shadow_blur_unit_dist);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
offset = mul(rotateClockwise45, offset);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
offset = mul(rotateClockwise45, offset);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
offset = mul(rotateClockwise45, offset);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
offset = mul(rotateClockwise45, offset);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
offset = mul(rotateClockwise45, offset);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
offset = mul(rotateClockwise45, offset);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
offset = mul(rotateClockwise45, offset);
sampled_shadow_alpha += image.Sample(textureSampler, v_in.uv + offset * uv_pixel_interval).a;
sampled_shadow_alpha /= 8;
sampled_shadow_alpha *= shadow_blur_gain;
float4 final_shadow_color = float4(shadow_color.rgb, sampled_shadow_alpha);
float4 color = image.Sample(textureSampler, v_in.uv);
return final_shadow_color * (1-color.a) + color;
}
@yanorei32
Copy link
Author

yanorei32 commented Jan 28, 2022

GPU Util
Disable 6%
drop_shadow.shader (shadow_blur_size: 50) 69% (+63%)
fake_blur.shader 6% (+<1%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment