return o; } half4 GaussianBlur(v2f i){ // Gaussian weights for the six samples around the current pixel: // -3 -2 -1 +1 +2 +3 float w[6] = { 0.006f, 0.061f, 0.242f, 0.242f, 0.061f, 0.006f }; float o[6] = { -1.0f, -0.6667f, -0.3333f, 0.3333f, 0.6667f, 1.0f };
// Fetch color and linear depth for current pixel: float4 colorM = tex2D(_MainTex, i.uv); float depthM = DecodeFloatRG(tex2D (_CameraDepthNormalsTexture, i.uv).zw);
// Accumulate center sample, multiplying it with its gaussian weight: float4 colorBlurred = colorM; colorBlurred.rgb *= 0.382f; // Calculate the step that we will use to fetch the surrounding pixels, // where "step" is: // step = sssStrength * gaussianWidth * pixelSize * dir // The closer the pixel, the stronger the effect needs to be, hence // the factor 1.0 / depthM. float2 finalStep = colorM.a * step / depthM * 0.0125f; for (int j = 0; j < 6; ++ j) { // Fetch color and depth for current sample: float2 offset = i.uv + o[j] * finalStep; float3 color = tex2D(_MainTex, offset).rgb; float depth = DecodeFloatRG(tex2D (_CameraDepthNormalsTexture, offset).zw);
// If the difference in depth is huge, we lerp color back to "colorM": float s = min(correction * abs(depthM - depth), 1); color = lerp(color, colorM.rgb, s);
protectedvoidCreateMaterials() { if (sssssMaterial == null) { sssssMaterial = new Material(sssssShader); sssssMaterial.hideFlags = HideFlags.DontSave; } }
protectedvoidStart() { // Disable if we don't support image effects if (!SystemInfo.supportsImageEffects) { enabled = false; Debug.Log("PostProcess SSSSS: Image Effects not supported"); return; } if (!SystemInfo.SupportsRenderTextureFormat (RenderTextureFormat.Depth)) { enabled = false; Debug.Log("PostProcess SSSSS: Depth Texture not supported"); return; }
CreateMaterials(); // Disable if the shader can't run on the users graphics card if (!sssssShader || !sssssMaterial.shader.isSupported) { enabled = false; Debug.Log("PostProcess SSSSS: shader or material not found"); return; } }