Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef BANDED_OUTLINE_INCLUDED
- #define BANDED_OUTLINE_INCLUDED
- float3 posterize(float3 inColor, float steps)
- {
- steps = max(1.0, steps);
- return floor(inColor * steps) / steps;
- }
- void BandedOutline_float(float2 screenUV, float4 blitSourceAndDepth, float3 normalsWorld,
- out float4 blitComposite)
- {
- float3 sceneColor = blitSourceAndDepth.rgb;
- float sceneDepth = blitSourceAndDepth.w; // Scene eye depth in meters
- #ifdef SHADERGRAPH_PREVIEW
- blitComposite = float4(sceneColor, 1.0);
- #else
- float2 texel = _ScreenParams.zw - 1.0;
- #define EYE_DEPTH(off) LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(screenUV + texel * (off)), _ZBufferParams)
- float dTL = EYE_DEPTH(float2(-1.0, 1.0));
- float dT = EYE_DEPTH(float2( 0.0, 1.0));
- float dTR = EYE_DEPTH(float2( 1.0, 1.0));
- float dL = EYE_DEPTH(float2(-1.0, 0.0));
- float dR = EYE_DEPTH(float2( 1.0, 0.0));
- float dBL = EYE_DEPTH(float2(-1.0, -1.0));
- float dB = EYE_DEPTH(float2( 0.0, -1.0));
- float dBR = EYE_DEPTH(float2( 1.0, -1.0));
- #undef EYE_DEPTH
- float gx = (dTR + 2.0 * dR + dBR) - (dTL + 2.0 * dL + dBL);
- float gy = (dTL + 2.0 * dT + dTR) - (dBL + 2.0 * dB + dBR);
- float gradient = sqrt(gx * gx + gy * gy) / max(sceneDepth, 1e-4);
- const float edgeStart = 0.05;
- const float edgeFull = 0.25;
- float edge = smoothstep(edgeStart, edgeFull, gradient);
- float3 post = lerp(posterize(sceneColor, 32.), sceneColor, 0.45);
- blitComposite = float4(lerp(post, float3(0.0, 0.0, 0.0), edge * 0.8), 1.0);
- #endif
- }
- #endif // BANDED_OUTLINE_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment