Created
June 14, 2020 18:55
-
-
Save bdunderscore/e0ba3ab764633d68a3a897c953aee7c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Texture2D _MainTex; | |
SamplerState sampler_point_clamp_MainTex; | |
SamplerState sampler_bilinear_clamp_MainTex; | |
float4 _MainTex_TexelSize; | |
fixed4 scrollcal_sample_plan(struct scrollcal_context ctx, struct scrollcal_render_plan plan) { | |
fixed4 bg = _MainTex.SampleLevel(sampler_bilinear_clamp_MainTex, plan.background_uv, ctx.mip); | |
fixed4 overlay = fixed4(0,0,0,0); | |
fixed4 text = fixed4(0,0,0,0); | |
fixed overlay_alpha = 1; | |
fixed4 text_color = fixed4(0,0,0,0); | |
if (plan.text_uv.x >= 0) { | |
text = _MainTex.SampleLevel(sampler_bilinear_clamp_MainTex, plan.text_uv, ctx.mip); | |
text_color = _MainTex.SampleLevel(sampler_point_clamp_MainTex, plan.palette_uv, 0); | |
} | |
if (plan.overlay_uv.x >= 0) { | |
overlay = _MainTex.SampleLevel(sampler_bilinear_clamp_MainTex, plan.overlay_uv, ctx.mip); | |
if (plan.overlay_alpha_uv.x >= 0.0) { | |
overlay_alpha = saturate(LinearToGammaSpace(_MainTex.SampleLevel(sampler_bilinear_clamp_MainTex, plan.overlay_alpha_uv, ctx.mip)).r); | |
} | |
} | |
float text_alpha = saturate(LinearToGammaSpace(dot(text, plan.colormask))); | |
overlay_alpha *= plan.overlay_alpha_mul; | |
if (plan.overlay_above_text) { | |
return lerp(lerp(bg, text_color, text_alpha), overlay, overlay_alpha); | |
} else { | |
return lerp(lerp(bg, overlay, overlay_alpha), text_color, text_alpha); | |
} | |
} | |
fixed4 scrollcal_albedo(struct scrollcal_context ctx) { | |
float2 uv_px = ctx.viewport_size.xy; | |
float2 dx_uv = ddx(uv_px); | |
float2 dy_uv = ddy(uv_px); | |
float del_sq_v = max(dot(dx_uv, dx_uv), dot(dy_uv, dy_uv)); | |
ctx.mip = 0.5 * log2(del_sq_v); | |
float cutoff_header_sides = ctx.borders.x + ctx.other_tex_params.z; | |
struct scrollcal_render_plan plan; | |
if (uv_px.y <= ctx.borders.x) { | |
plan = scrollcal_plan_header(ctx, uv_px); | |
} else if (ctx.viewport_size.w - uv_px.y <= ctx.borders.y) { | |
plan = scrollcal_plan_footer(ctx, uv_px); | |
} else if (ctx.borders.z >= uv_px.x) { | |
plan = scrollcal_plan_side(ctx, uv_px, 0); | |
} else if (uv_px.x >= ctx.viewport_size.z - ctx.borders.w) { | |
plan = scrollcal_plan_side(ctx, uv_px - float2(ctx.viewport_size.z - ctx.borders.w, 0), 1); | |
} else { | |
plan = scrollcal_plan_main(ctx, uv_px); | |
} | |
return scrollcal_sample_plan(ctx, plan); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment