Created
June 15, 2018 06:31
-
-
Save Andersama/133d87cb1584d4b5d0ba4d367468dd2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uniform float4x4 ViewProj; | |
//this pulls in the texture from render target 1 | |
uniform texture2d image; | |
//assuming the pattern followed~ | |
uniform texture2d image_2; | |
uniform texture2d image_3; | |
uniform float2 elapsed_time; | |
uniform float2 uv_offset; | |
uniform float2 uv_scale; | |
uniform float2 uv_pixel_interval; | |
uniform float shadow_x; | |
uniform float shadow_y; | |
uniform float blur_size; | |
uniform float4 shadow_color; | |
sampler_state textureSampler { | |
Filter = Linear; | |
AddressU = Border; | |
AddressV = Border; | |
BorderColor = 00000000; | |
}; | |
struct VertData { | |
float4 pos : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
VertData mainTransform(VertData v_in) | |
{ | |
VertData vert_out; | |
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj); | |
vert_out.uv = v_in.uv * uv_scale + uv_offset; | |
return vert_out; | |
} | |
struct PS_OUTPUT | |
{ | |
float4 color: SV_Target0; | |
float4 original: SV_Target1; | |
float4 shadow: SV_TARGET2; | |
}; | |
PS_OUTPUT drop_shadow_init(VertData v_in) | |
{ | |
PS_OUTPUT output; | |
float4 c = image.Sample(textureSampler, v_in.uv); | |
output.original = c; | |
output.color = c; | |
output.shadow = float4(shadow_color.rgb, c.a); | |
return output; | |
} | |
PS_OUTPUT drop_shadow_blur_x(VertData v_in) | |
{ | |
PS_OUTPUT output; | |
int shadow_blur_samples = (shadow_blur_size * 2) + 1; | |
float2 shadow_uv = float2(v_in.uv.x - uv_pixel_interval.x * shadow_offset_x, | |
v_in.uv.y - uv_pixel_interval.y * shadow_offset_y); | |
float sampled_shadow_alpha = 0; | |
for (int blur_i = -shadow_blur_size; blur_i <= shadow_blur_size; blur_i++){ | |
float2 blur_uv = shadow_uv + float2(0, uv_pixel_interval.y * blur_i); | |
sampled_shadow_alpha += image.Sample(textureSampler, blur_uv).a; | |
} | |
sampled_shadow_alpha /= shadow_blur_samples; | |
output.color = float4(shadow_color.rgb, shadow_color.a * sampled_shadow_alpha); | |
output.original = image_2; | |
output.shadow = output.color; | |
} | |
PS_OUTPUT drop_shadow_blur_y(VertData v_in) | |
{ | |
PS_OUTPUT output; | |
int shadow_blur_samples = (shadow_blur_size * 2) + 1; | |
float2 shadow_uv = float2(v_in.uv.x - uv_pixel_interval.x * shadow_offset_x, | |
v_in.uv.y - uv_pixel_interval.y * shadow_offset_y); | |
float4 sampled_shadow = float4(0,0,0,0); | |
for (int blur_i = -shadow_blur_size; blur_i <= shadow_blur_size; blur_i++){ | |
float2 blur_uv = shadow_uv + float2(uv_pixel_interval.x * blur_i, 0); | |
sampled_shadow += image_3.Sample(textureSampler, blur_uv); | |
} | |
sampled_shadow /= shadow_blur_samples; | |
float4 original_color = image_2.Sample(textureSampler, v_in.uv); | |
output.shadow = sampled_shadow; | |
output.color = sampled_shadow * (1-original_color.a) + original_color * (is_alpha_premultiplied * 1 + !is_alpha_premultiplied * original_color.a); | |
output.original_color = original_color; | |
} | |
technique Draw | |
{ | |
pass p0 | |
{ | |
vertex_shader = mainTransform(v_in); | |
pixel_shader = drop_shadow_init(v_in); | |
} | |
pass p2 | |
{ | |
vertex_shader = mainTransform(v_in); | |
pixel_shader = drop_shadow_blur_x(v_in); | |
} | |
pass p3 | |
{ | |
vertex_shader = mainTransform(v_in); | |
pixel_shader = drop_shadow_blur_y(v_in); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment