Guest User

Banded Outline for NIGHTFALL GMTK 2026 Game

a guest
Jul 28th, 2026
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | Gaming | 0 0
  1. #ifndef BANDED_OUTLINE_INCLUDED
  2. #define BANDED_OUTLINE_INCLUDED
  3.  
  4. float3 posterize(float3 inColor, float steps)
  5. {
  6.     steps = max(1.0, steps);
  7.     return floor(inColor * steps) / steps;
  8. }
  9.  
  10. void BandedOutline_float(float2 screenUV, float4 blitSourceAndDepth, float3 normalsWorld,
  11.     out float4 blitComposite)
  12. {
  13.     float3 sceneColor = blitSourceAndDepth.rgb;
  14.     float  sceneDepth = blitSourceAndDepth.w; // Scene eye depth in meters
  15.  
  16. #ifdef SHADERGRAPH_PREVIEW
  17.     blitComposite = float4(sceneColor, 1.0);
  18. #else
  19.     float2 texel = _ScreenParams.zw - 1.0;
  20.  
  21.     #define EYE_DEPTH(off) LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(screenUV + texel * (off)), _ZBufferParams)
  22.     float dTL = EYE_DEPTH(float2(-1.0,  1.0));
  23.     float dT  = EYE_DEPTH(float2( 0.0,  1.0));
  24.     float dTR = EYE_DEPTH(float2( 1.0,  1.0));
  25.     float dL  = EYE_DEPTH(float2(-1.0,  0.0));
  26.     float dR  = EYE_DEPTH(float2( 1.0,  0.0));
  27.     float dBL = EYE_DEPTH(float2(-1.0, -1.0));
  28.     float dB  = EYE_DEPTH(float2( 0.0, -1.0));
  29.     float dBR = EYE_DEPTH(float2( 1.0, -1.0));
  30.     #undef EYE_DEPTH
  31.  
  32.     float gx = (dTR + 2.0 * dR + dBR) - (dTL + 2.0 * dL + dBL);
  33.     float gy = (dTL + 2.0 * dT + dTR) - (dBL + 2.0 * dB + dBR);
  34.  
  35.     float gradient = sqrt(gx * gx + gy * gy) / max(sceneDepth, 1e-4);
  36.  
  37.     const float edgeStart = 0.05;
  38.     const float edgeFull  = 0.25;
  39.     float edge = smoothstep(edgeStart, edgeFull, gradient);
  40.  
  41.     float3 post = lerp(posterize(sceneColor, 32.), sceneColor, 0.45);
  42.    
  43.     blitComposite = float4(lerp(post, float3(0.0, 0.0, 0.0), edge * 0.8), 1.0);
  44. #endif
  45. }
  46.  
  47. #endif // BANDED_OUTLINE_INCLUDED
  48.  
Advertisement
Add Comment
Please, Sign In to add comment