diff --git a/Assets/_Content/Shaders/Postprocess/Include/EnkiBillalFullscreen.hlsl b/Assets/_Content/Shaders/Postprocess/Include/EnkiBillalFullscreen.hlsl index 14983707..8abeae75 100644 --- a/Assets/_Content/Shaders/Postprocess/Include/EnkiBillalFullscreen.hlsl +++ b/Assets/_Content/Shaders/Postprocess/Include/EnkiBillalFullscreen.hlsl @@ -173,7 +173,7 @@ float ComputeOutline(float2 UV, float2 Thickness, float3 NormalWS, float3 ViewDi { // DEPTH OUTLINE - float2 o = Thickness * (1 - DepthAtten); + float2 o = Thickness * lerp(1, .5, DepthAtten); float d0 = SampleSceneDepthMeter(UV); float d1 = SampleSceneDepthMeter(UV + float2(-o.x,0)); @@ -219,15 +219,13 @@ void EnkiBillalFullscreen_float { // INPUTS - float3 sceneColor = SampleSceneColor(UV); - float rawDepth = SampleSceneDepth(UV); #if UNITY_REVERSED_Z - bool isSky = rawDepth <= 0.00001; - rawDepth = isSky ? 0.0 : rawDepth; + bool isSky = rawDepth <= .00001; + rawDepth = isSky ? 0 : rawDepth; #else - bool isSky = rawDepth >= 0.99999; - rawDepth = isSky ? 1.0 : rawDepth; + bool isSky = rawDepth >= .99999; + rawDepth = isSky ? 1 : rawDepth; #endif float depthMeters = isSky ? _ProjectionParams.z @@ -239,76 +237,99 @@ void EnkiBillalFullscreen_float #endif float3 positionWS = ComputeWorldSpacePosition(UV, depthForReconstruct, UNITY_MATRIX_I_VP); + float3 normalWS = normalize(SampleSceneNormals(UV)); + float3 viewDir = normalize(_WorldSpaceCameraPos.xyz - positionWS); + float time = _Time.y; + + // NOISES float noiseAtten = pow(smoothstep(1, 10, depthMeters), 2); - float np1 = PerlinNoise3D(positionWS + floor(_Time.y * 8) * 3.7, 15) * 2 - 1; - float2 uv1 = UV + np1 * lerp(.001, .002, noiseAtten); + float np0 = PerlinNoise3D(positionWS, 80); + float np1 = PerlinNoise3D(positionWS , 1.7) * 2 - 1; + float np2 = PerlinNoise3D(positionWS + floor(time * 3.) * 2.6, 0.8) * 2 - 1; + float np3 = PerlinNoise3D(positionWS + floor(time * 5.) * 6.1, 0.1) * 2 - 1; + float np4 = PerlinNoise3D(positionWS + floor(time * 9.) * 9.2, .03) * 2 - 1; - float3 normalWS = normalize(SampleSceneNormals(UV)); - float3 viewDir = normalize(_WorldSpaceCameraPos.xyz - positionWS); + // UVs - float np2 = FBMNoise3D(positionWS + np1 * .05, .5, 1, 2, .5) * 2 - 1; - float2 uv2 = uv1 + np2 * .0; + float2 uv0 = UV; + float2 uv1 = uv0 + np1 * lerp(.001, .002, noiseAtten); + float2 uv2 = uv1 + (np1 * .3 + np2 * .7) * lerp(.003, .006, noiseAtten); + float2 uv3 = uv2 + (np2 * .3 + np3 * .7) * lerp(.015, .029, noiseAtten); + float2 uv4 = uv3 + (np3 * .3 + np4 * .7) * lerp(.019, .032, noiseAtten); - float3 sceneColor2 = SampleSceneColor(uv2); + // SCENE COLOR - float np3 = PerlinNoise3D(positionWS + floor(_Time.y * 5) * 6.1, 1.5); - float2 uv3 = uv2 + np3 * lerp(.005, .008, noiseAtten); + float3 sceneColor = SampleSceneColor(uv0 + (np0 * 2 - 1) * noiseAtten * .003); + float greyscale = (sceneColor.r + sceneColor.g + sceneColor.b) / 3.; + + // DISTORTION + + float distortAtten = pow(smoothstep(5, 20, depthMeters), 2); + float nDistort = FBMNoise3D(positionWS * float3(1, 2, 1) - time * .1 - np0 * .5, 1.5, 1, 2, .5) * 2 - 1; + float2 uvDistort = uv0 + nDistort * .03; + float3 sceneColor2 = SampleSceneColor(uvDistort); + float3 cDistort = saturate(sceneColor2 - sceneColor) * distortAtten; // OUTLINE + float3 outlineColor = float3(.001, .002, .0015); float outlineAtten = smoothstep(3, 30, depthMeters); - float outline = 0; - float n0 = PerlinNoise3D(positionWS, 80); + float outlineWeight = 0; + + float2 uvs[4]; + uvs[0] = uv1; + uvs[1] = uv2; + uvs[2] = uv3; + uvs[3] = uv4; [Unroll] - for (float i = 0; i < 2; i++) + for (float i = 0; i < 4; i++) { float t = floor(cos((_Time.y + positionWS) * (4 + i * 3) * .8) * .1); t = 0; - float n1 = PerlinNoise3D(positionWS + i * 3.3 + n0, 1.7 + 1 * .2 + t); - - float2 thickness = lerp(0, 15 + i * 2, pow(n1, 2)); + float2 thickness = 8 - i * .9; + thickness = thickness * lerp(.05, 1, np2 * .5 + .5); thickness = thickness * _ScreenParams.y / 1080 / _ScreenParams.xy; - float2 uv = uv3; - if (i == 1) - uv = uv1; - - outline += ComputeOutline(uv, thickness, normalWS, viewDir, outlineAtten) * (i * .5 + 1); + float2 uv = uvs[i]; + float w = 1 - i * .3; + + outline += ComputeOutline(uv, thickness, normalWS, viewDir, outlineAtten) * w; + outlineWeight += w; } - outline /= 2.5; + outline /= outlineWeight; // COLOR (WIP) + float3 c = sceneColor; - float3 greyscale = smoothstep(.1, .5, (sceneColor2.r + sceneColor2.g + sceneColor2.b) / 3.); //c = lerp(sceneColor, sceneColor2, smoothstep(1, .9, (sceneColor2.r + sceneColor2.g + sceneColor2.b) / 3)); //c = (sceneColor2.r + sceneColor2.g + sceneColor2.b) / 3.; - c = lerp(c, sceneColor2, (greyscale + smoothstep(5, 35, depthMeters) * .8) * .5); + //c = lerp(c, sceneColor2, (greyscale + smoothstep(5, 35, depthMeters) * .8) * .5); //c += sceneColor2 * greyscale * .5; - c = lerp(c, float3(.001, .002, .0015), outline); + c = lerp(c, outlineColor, outline); + c += cDistort * .5; //c = ((c + 1) * (sceneColor2 + 0)); - //c = sceneColor2; //c = smoothstep(-.1, 0, np2); //c = greyscale; /*float3 pWS = positionWS; //scaledPositionOS; - //float n0 = PerlinNoise3D(pWS, 2); - float distort = WorldDistort(pWS + n0 * .2, normalWS, 1, .1); - float3 p = pWS + n0 * 2 + distort * smoothstep(.5, .7, n0) * .06; + //float np0 = PerlinNoise3D(pWS, 2); + float distort = WorldDistort(pWS + np0 * .2, normalWS, 1, .1); + float3 p = pWS + np0 * 2 + distort * smoothstep(.5, .7, np0) * .06; float grad = 0; float cell = 0; VoronoiNoise3D_float(p, 2, 1, 1, grad, cell); float3 v = cell * .8; // * (grad + distort * .1); - v += smoothstep(.05, .02, grad) * smoothstep(.4, .7, n0) * 2; + v += smoothstep(.05, .02, grad) * smoothstep(.4, .7, np0) * 2; c *= lerp(.9, 1, v); // DIRT @@ -323,7 +344,7 @@ void EnkiBillalFullscreen_float // SHADOW - float sceneLuminance = dot(sceneColor, float3(.299, .587, .114)); + /*float sceneLuminance = dot(sceneColor, float3(.299, .587, .114)); float hatchAtten = smoothstep(15, 1, depthMeters); @@ -331,7 +352,7 @@ void EnkiBillalFullscreen_float float hatchWidth = lerp(.025, .18, hatchMask) * hatchAtten; - float hatchLayerMask = smoothstep(.35, .75, np3 + n0); + float hatchLayerMask = smoothstep(.35, .75, np3 + np0); float hatch0 = BipyramidHatch(positionWS, normalWS, .35, 28, hatchWidth); float hatch1 = BipyramidHatch(positionWS + 13.7, normalWS, 1.75, 21, hatchWidth * .85); @@ -344,12 +365,14 @@ void EnkiBillalFullscreen_float float hatches = saturate(hatchesA + hatchesB * hatchLayerMask * .55); - c = lerp(c, float3(0, 0, 0), hatches * hatchMask * .3); + c = lerp(c, float3(0, 0, 0), hatches * hatchMask * .3);*/ // OUTPUT Output = c; - //Output = sceneColor; + //Output = nDistort * .5 + .5; + //Output = np2; + //Output = sceneColor2; //Output = hatchMask; //Output = dot(normalWS, viewDir); }