///<inheritdoc/> public void Render(PostProcessPassContext ctx, CameraSensorBase sensor, PostProcessData data, CubemapFace cubemapFace = CubemapFace.Unknown) { if (PostProcessSystem == null) { return; } var lateQueue = PostProcessSystem.IsLatePostprocess(sensor, typeof(TData)); if (!IsActive) { PostProcessSystem.Skip(ctx.cmd, ctx.cameraColorBuffer, sensor, true, lateQueue); return; } if (!(data is TData tData)) { Debug.LogWarning($"Attempting to render postprocess with invalid data type (required {typeof(TData).Name}, got {data.GetType().Name})"); PostProcessSystem.Skip(ctx.cmd, ctx.cameraColorBuffer, sensor, true, lateQueue); return; } PostProcessSystem.GetRTHandles(ctx.cmd, ctx.cameraColorBuffer, sensor, false, lateQueue, out var source, out var target, cubemapFace); Render(ctx, source, target, tData); PostProcessSystem.RecycleSourceRT(source, ctx.cameraColorBuffer, false); if (cubemapFace != CubemapFace.Unknown) { PostProcessSystem.TryPerformFinalCubemapPass(ctx.cmd, sensor, target, ctx.cameraColorBuffer, cubemapFace); } }
protected override void Render(PostProcessPassContext ctx, RTHandle source, RTHandle destination, Rain data) { var cmd = ctx.cmd; if (Mathf.Approximately(EnvironmentEffectsManager.Rain, 0f)) { HDUtils.BlitCameraTexture(cmd, source, destination); return; } if (EnvironmentEffectsManager.Rain < .35) { cmd.EnableShaderKeyword("LOW"); cmd.DisableShaderKeyword("MED"); cmd.DisableShaderKeyword("HGH"); } else if (EnvironmentEffectsManager.Rain >= .35 && EnvironmentEffectsManager.Rain < .7) { cmd.EnableShaderKeyword("MED"); cmd.DisableShaderKeyword("LOW"); cmd.DisableShaderKeyword("HGH"); } else { cmd.EnableShaderKeyword("HGH"); cmd.DisableShaderKeyword("LOW"); cmd.DisableShaderKeyword("MED"); } cmd.SetGlobalFloat("_Intensity", EnvironmentEffectsManager.Rain); cmd.SetGlobalTexture("_InputTexture", source); cmd.SetGlobalFloat("_Size", data.size); HDUtils.DrawFullScreen(cmd, material, destination); }
protected override void Render(PostProcessPassContext ctx, RTHandle source, RTHandle destination, GreyScale data) { if (Mathf.Approximately(data.intensity, 0f)) { HDUtils.BlitCameraTexture(ctx.cmd, source, destination); return; } ctx.cmd.SetGlobalFloat("_Intensity", data.intensity); ctx.cmd.SetGlobalTexture("_InputTexture", source); HDUtils.DrawFullScreen(ctx.cmd, material, destination); }
protected sealed override void Execute(CustomPassContext customPassContext) { if (PostProcessSystem == null) { return; } var ctx = new PostProcessPassContext(customPassContext); var sensor = ctx.hdCamera.camera.GetComponent <CameraSensorBase>(); if (sensor == null || sensor.Postprocessing == null || sensor.Postprocessing.Count == 0) { return; } // Late postprocessing queue is always called directly, never executed through volume if (PostProcessSystem.IsLatePostprocess(sensor, typeof(TData))) { return; } if (!IsActive) { PostProcessSystem.Skip(ctx.cmd, ctx.cameraColorBuffer, sensor, true, false); return; } TData data = null; foreach (var sensorData in sensor.Postprocessing) { if (sensorData is TData matchingData) { data = matchingData; break; } } if (data == null) { return; } PostProcessSystem.GetRTHandles(ctx.cmd, ctx.cameraColorBuffer, sensor, true, false, out var source, out var target); Render(ctx, source, target, data); PostProcessSystem.RecycleSourceRT(source, ctx.cameraColorBuffer, true); }
protected override void Render(PostProcessPassContext ctx, RTHandle source, RTHandle destination, VideoArtifacts data) { var cmd = ctx.cmd; if (Mathf.Approximately(data.intensity, 0f)) { HDUtils.BlitCameraTexture(cmd, source, destination); return; } // Update the time parameters. var time = Time.time; var delta = time - prevTime; prevTime = time; // Block parameters var block = data.intensity; var block3 = block * block * block; // Shuffle block parameters every 1/30 seconds. blockTime += delta * 60; if (blockTime > 1) { if (Random.value < 0.09f) { blockSeed1 += 251; } if (Random.value < 0.29f) { blockSeed2 += 373; } if (Random.value < 0.25f) { blockStride = Random.Range(1, 32); } blockTime = 0; } // Invoke the shader. cmd.SetGlobalInt(ShaderIDs.Seed, (int)(time * 10000)); cmd.SetGlobalFloat(ShaderIDs.BlockStrength, block3); cmd.SetGlobalInt(ShaderIDs.BlockStride, blockStride); cmd.SetGlobalInt(ShaderIDs.BlockSeed1, blockSeed1); cmd.SetGlobalInt(ShaderIDs.BlockSeed2, blockSeed2); cmd.SetGlobalTexture(ShaderIDs.InputTexture, source); cmd.SetGlobalInt(ShaderIDs.BlockSize, data.blockSize); HDUtils.DrawFullScreen(cmd, material, destination); }
/// <summary> /// <para>Renders all post-distortion postprocessing effects declared for given sensor.</para> /// </summary> /// <param name="ctx">Context used for this pass execution.</param> /// <param name="sensor">Sensor that should have postprocessing effects rendered.</param> public void RenderLateForSensor(PostProcessPassContext ctx, CameraSensorBase sensor) { if (sensor.LatePostprocessing == null || sensor.LatePostprocessing.Count == 0) { return; } foreach (var data in sensor.LatePostprocessing) { foreach (var kvp in postProcessingPasses) { if (data.GetType() == kvp.Key) { RenderPostProcess(ctx, sensor, kvp.Value, data); } } } }
/// <summary> /// <para>Renders all pre-distortion postprocessing effects declared for given sensor.</para> /// <para> /// This should only be used on cameras with custom render method. Cameras using HDRP passes will render all /// effects automatically. /// </para> /// </summary> /// <param name="ctx">Context used for this pass execution.</param> /// <param name="sensor">Sensor that should have postprocessing effects rendered.</param> /// <param name="cubemapFace">Specifies target face if cubemap is used.</param> public void RenderForSensor(PostProcessPassContext ctx, CameraSensorBase sensor, CubemapFace cubemapFace = CubemapFace.Unknown) { if (sensor.Postprocessing == null || sensor.Postprocessing.Count == 0) { return; } foreach (var data in sensor.Postprocessing) { foreach (var kvp in postProcessingPasses) { if (data.GetType() == kvp.Key) { RenderPostProcess(ctx, sensor, kvp.Value, data, cubemapFace); } } } }
/// <summary> /// <para>Called when this postprocessing pass is supposed to be rendered.</para> /// <para>All rendering code for this pass should be executed here.</para> /// </summary> /// <param name="ctx">Context used for this pass execution.</param> /// <param name="source"><see cref="RTHandle"/> that should be used as a source (can be sampled).</param> /// <param name="destination"><see cref="RTHandle"/> that should be used as a target (can't be sampled).</param> /// <param name="data">Data container for postprocessing parameters.</param> protected abstract void Render(PostProcessPassContext ctx, RTHandle source, RTHandle destination, TData data);
protected override void Render(PostProcessPassContext ctx, RTHandle source, RTHandle destination, SunFlare data) { var cmd = ctx.cmd; var camera = ctx.hdCamera; var cam = camera.camera; var sunForward = sunTransform.forward; var sunWorldPos = cam.transform.position - sunForward * 1000f; var sunViewPos = cam.WorldToViewportPoint(sunWorldPos); var intensity = Mathf.Clamp01(Vector3.Dot(cam.transform.forward, -sunForward)); var sunVisible = sunViewPos.z > 0 && sunViewPos.x >= -0.1f && sunViewPos.x < 1.1f && sunViewPos.y >= -0.1f && sunViewPos.y < 1.1f; if (!sunVisible) { if (Physics.Raycast(cam.transform.position, -sunForward, 1000f, LayerMask)) { intensity = 0f; } } if (intensity > 0f) { var depthTexRes = ctx.cameraDepthBuffer.referenceSize; var actualCameraSize = new Vector2Int(camera.actualWidth, camera.actualHeight); var occlTexRes = new Vector2Int(OcclusionRes, OcclusionRes); var scaleRatio = new Vector2((float)actualCameraSize.x / depthTexRes.x, (float)actualCameraSize.y / depthTexRes.y); var aspectRatio = (float)actualCameraSize.y / actualCameraSize.x; var scaledSun = new Vector4(sunViewPos.x * scaleRatio.x, sunViewPos.y * scaleRatio.y, 0.1f * aspectRatio * scaleRatio.x, 0.1f * scaleRatio.y); cmd.SetComputeVectorParam(computeShader, DepthTextureRes, new Vector4(depthTexRes.x, depthTexRes.y, 1f / depthTexRes.x, 1f / depthTexRes.y)); cmd.SetComputeVectorParam(computeShader, OcclusionTextureRes, new Vector4(occlTexRes.x, occlTexRes.y, 1f / occlTexRes.x, 1f / occlTexRes.y)); cmd.SetComputeVectorParam(computeShader, SunViewPos, scaledSun); var kernel = textureOcclusionKernel; cmd.SetComputeTextureParam(computeShader, kernel, DepthTexture, ctx.cameraDepthBuffer); cmd.SetComputeTextureParam(computeShader, kernel, OcclusionTextureOut, occlusionTextureA); cmd.DispatchCompute(computeShader, kernel, OcclusionRes / 8, OcclusionRes / 8, 1); kernel = blurTextureOcclusionKernel; cmd.SetComputeTextureParam(computeShader, kernel, OcclusionTextureIn, occlusionTextureA); cmd.SetComputeTextureParam(computeShader, kernel, OcclusionTextureOut, occlusionTextureB); cmd.DispatchCompute(computeShader, kernel, OcclusionRes / 8, OcclusionRes / 8, 1); kernel = reduceTextureOcclusionKernel; cmd.SetComputeTextureParam(computeShader, kernel, OcclusionTextureIn, occlusionTextureB); cmd.SetComputeTextureParam(computeShader, kernel, OcclusionTextureOut, occlusionTextureA); cmd.DispatchCompute(computeShader, kernel, 1, 1, 1); kernel = angleOcclusionKernel; cmd.SetComputeTextureParam(computeShader, kernel, OcclusionTextureIn, occlusionTextureB); cmd.SetComputeBufferParam(computeShader, kernel, AngleOcclusion, angleOcclusion); cmd.DispatchCompute(computeShader, kernel, AngleSamples / 64, 1, 1); cmd.SetGlobalVector(SunViewPos, sunViewPos); cmd.SetGlobalVector(SunSettings, new Vector4(data.sunIntensity, data.haloIntensity, data.ghostingIntensity, intensity)); cmd.SetGlobalTexture(InputTexture, source); cmd.SetGlobalTexture(OcclusionTextureIn, occlusionTextureA); cmd.SetGlobalTexture(OcclusionTextureOut, occlusionTextureB); cmd.SetGlobalBuffer(AngleOcclusion, angleOcclusion); HDUtils.DrawFullScreen(cmd, material, destination); } else { HDUtils.BlitCameraTexture(cmd, source, destination); } }
private static void RenderPostProcess <T>(PostProcessPassContext ctx, CameraSensorBase sensor, CustomPass pass, T data, CubemapFace cubemapFace = CubemapFace.Unknown) where T : PostProcessData { var postProcessPass = pass as IPostProcessRenderer; postProcessPass?.Render(ctx, sensor, data, cubemapFace); }