//> parts of SSS shader
{
//> diffuse
float nDotl = dot(i.normalWS, lightDir);
float3 diffuse = saturate(nDotl);
//> specular
float3 refl = reflect(lightDir, normalWS);
float rDotv = saturate(dot(refl, -viewDir));
float3 specular = pow(rDotv, 100);
specular *= specularIntensity.rgb;
//> SSS
float3 h = normalize(lightDir + normalWS * _Distortion);
float vDoth = pow(saturate(dot(viewDir, -h)), _SSSPower + 0.000001) * _SSSScale;
float3 backLight = _Attenuation * (vDoth + _Ambient) * thickness * _SSSColor.rgb;
}
//> parts of Rim light shader
{
float3 normalWS = normalize(i.normalWS);
float3 viewDirWS = normalize(i.viewDirWS);
float nDotv = dot(normalWS, viewDirWS);
float rim = saturate(nDotv);
rim = pow(1 - rim, _RimPower);
float holo = pow(frac(normalWS.y * 3 - _Time.y), 15);
float alpha = (holo + rim) * abs(sin(_Time.y));
return half4(_RimColor.rgb, alpha);
}
//> Parts of Icicle shader
{
//> ice offset
float2 appendXZ = (o.normalWS.xz * _IcicleMaskTile) + 0.5;
float4 offsetMask = tex2Dlod(_IceOffset, float4(appendXZ, 0, 0));
//> yMask and vertex Offset
float yMask = saturate(o.normalWS.y * -1 * _IceSlider);
float yMaskTop = saturate(o.normalWS.y * 3) * remap(_IceSlider, float2(0, 1), float2(0, 0.02));
float3 vertexOffset = v.normalOS * (yMask * offsetMask.rgb * _IceLength + yMaskTop);
o.yMask = saturate(yMask * 8);
//> Set
o.positionCS = TransformObjectToHClip(v.positionOS + vertexOffset);
float3 positionWS = TransformObjectToWorld(v.positionOS + vertexOffset);
o.viewDir = GetWorldSpaceViewDir(positionWS);
}
//> Parts of Ramp shader
{
float3 lightDir = normalize(_MainLightPosition.xyz);
float3 viewDir = normalize(i.viewDir);
float nDotl = saturate(dot(normalWS, lightDir));
float nDotv = saturate(dot(normalWS, viewDir));
half4 ramp = SAMPLE_TEXTURE2D(_RampTex, sampler_RampTex, float2(nDotl, nDotv));
}
//> Parts of Water Lake shader
{
//> Water Color
float depthFade = Depthfade(i.positionNDC.xy, i.scrPos, _DepthDistance);
float4 waterColor = lerp(_ShallowColor, _DeepColor, depthFade);
//> Distortion
float2 uvD = Movement(i.uv, _DistortionSpeed, _DistortionScale);
float noiseD = GradientNoise(uvD, 20);
float3 normalTS = NormalFromHeight_Tangent(noiseD, i.positionWS, i.tbn);
float3 distortion = normalTS * _DistortionStrength + float3(i.positionNDC.xy, 0);
distortion = SampleSceneColor(distortion);
//> Foam
float foamCutoff = Depthfade(i.positionNDC.xy, i.scrPos, _FoamAmount) * _FoamCutoff;
float2 uvF = Movement(i.uv, _FoamSpeed, _FoamScale);
float4 noiseF = GradientNoise(uvF, 1);
float4 foamTerm = step(foamCutoff, noiseF) * _FoamColor.a;
float4 foam = lerp(waterColor, _FoamColor, foamTerm);
//> Shadow
float4 shadowcoord = TransformWorldToShadowCoord(i.positionWS);
Light mainLight = GetMainLight(shadowcoord);
float3 attenuation = mainLight.color * mainLight.distanceAttenuation * mainLight.shadowAttenuation;
attenuation = attenuation * 0.6 + 0.4;
//> Reflect
float2 uv = float2(i.scrPos.xy / i.scrPos.w);
uv = uv * _ReflectionTilingOffset.xy + _ReflectionTilingOffset.zw;
float4 refl = SAMPLE_TEXTURE2D(_ReflectionTex, sampler_ReflectionTex, uv);
}
//> Parts of Outline Post Processing shader
{
float cameraOutlineDepthTexture = tex2D(_CustomOutlineDepthTexture,i.uv).r;
float4 cameraColorTexture = tex2D(_CameraOpaqueTexture,i.uv);
float4 cameraColorObstructTexture = tex2D(_CustomColorObstructTexture,i.uv);
float cameraDepthObstructTexture = tex2D(_CustomDepthObstructTexture,i.uv).r;
float3 cameraWorldNormalTexture = sampleWorldNormal(i.uv);
float3 worldPos = ComputeWorldSpacePosition(i.uv, cameraOutlineDepthTexture, UNITY_MATRIX_I_VP);//World Pos texture
float3 V = GetWorldSpaceNormalizeViewDir(worldPos);
float2 screenSpaceUV = i.uv;
float fresnel = saturate(dot(V,cameraWorldNormalTexture));
}
//> RenderFeature
public class ScreenSpaceOutlines: ScriptableRendererFeature
{
class DrawOpaqueDepthPass : ScriptableRenderPass
{
readonly int srcDepthID;
readonly int dstDepthID;
readonly List<ShaderTagId> shaderTagIdList;
RTHandle srcDepthRT;
RTHandle dstDepthRT;
RendererListParams rendererListParams;
RendererList rendererList;
DrawingSettings depthDrawingSettings;
FilteringSettings depthFilteringSettings;
public DrawOpaqueDepthPass (LayerMask outlineMask)
{
srcDepthID = Shader.PropertyToID("_DrawOutlineDepth");
dstDepthID = Shader.PropertyToID("_CustomOutlineDepthTexture");
shaderTagIdList = new List<ShaderTagId>
{
new ShaderTagId("UniversalForward"),
new ShaderTagId("UniversalForwardOnly"),
new ShaderTagId("LightweightForward"),
new ShaderTagId("SRPDefaultUnlit")
};
depthFilteringSettings = new FilteringSettings(RenderQueueRange.opaque, outlineMask);
}
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
{
cmd.GetTemporaryRT(srcDepthID, Screen.width, Screen.height, 32, FilterMode.Point, RenderTextureFormat.Depth);
srcDepthRT = RTHandles.Alloc(new RenderTargetIdentifier(srcDepthID));
RenderTextureDescriptor destDepthDescriptor = cameraTextureDescriptor;
destDepthDescriptor.depthBufferBits = 32;
destDepthDescriptor.colorFormat = RenderTextureFormat.RFloat;
cmd.GetTemporaryRT(dstDepthID, destDepthDescriptor);
dstDepthRT = RTHandles.Alloc(new RenderTargetIdentifier(dstDepthID));
ConfigureTarget(srcDepthRT);
ConfigureClear(ClearFlag.All, Camera.main.backgroundColor);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, new ProfilingSampler("Draw_CustomOutlineDepthTexture")))
{
depthDrawingSettings = CreateDrawingSettings(shaderTagIdList, ref renderingData, SortingCriteria.CommonTransparent);// renderingData.cameraData.defaultOpaqueSortFlags);
rendererListParams = new RendererListParams(renderingData.cullResults, depthDrawingSettings, depthFilteringSettings);
rendererList = context.CreateRendererList(ref rendererListParams);
cmd.DrawRendererList(rendererList);
cmd.Blit(srcDepthRT.nameID, dstDepthRT.nameID);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
public override void OnCameraCleanup(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(srcDepthID);
cmd.ReleaseTemporaryRT(dstDepthID);
dstDepthRT.Release();
srcDepthRT.Release();
}
}
// ...
// ...
// ScriptableRenderPass and Setting of ScriptableRendererFeature
}