public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination) { Debug.Assert(m_Material != null); AdditionalCompositorData layerData = null; camera.camera.gameObject.TryGetComponent <AdditionalCompositorData>(out layerData); if (layerData == null || layerData.layerFilters == null) { HDUtils.BlitCameraTexture(cmd, source, destination); return; } int index = layerData.layerFilters.FindIndex(x => x.filterType == CompositionFilter.FilterType.ALPHA_MASK); if (index < 0) { HDUtils.BlitCameraTexture(cmd, source, destination); return; } var filter = layerData.layerFilters[index]; m_Material.SetTexture(ShaderIDs.k_InputTexture, source); m_Material.SetTexture(ShaderIDs.k_AlphaTexture, filter.alphaMask); HDUtils.DrawFullScreen(cmd, m_Material, destination); }
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination) { Debug.Assert(m_Material != null); AdditionalCompositorData layerData = null; camera.camera.gameObject.TryGetComponent <AdditionalCompositorData>(out layerData); if (activate.value == false || layerData == null || layerData.layerFilters == null) { HDUtils.BlitCameraTexture(cmd, source, destination); return; } int index = layerData.layerFilters.FindIndex(x => x.filterType == CompositionFilter.FilterType.CHROMA_KEYING); if (index < 0) { HDUtils.BlitCameraTexture(cmd, source, destination); return; } var filter = layerData.layerFilters[index]; Vector4 keyParams; keyParams.x = filter.keyThreshold; keyParams.y = filter.keyTolerance; keyParams.z = filter.spillRemoval; keyParams.w = 1.0f; m_Material.SetVector(ShaderIDs.k_KeyColor, filter.maskColor); m_Material.SetVector(ShaderIDs.k_KeyParams, keyParams); m_Material.SetTexture(ShaderIDs.k_InputTexture, source); HDUtils.DrawFullScreen(cmd, m_Material, destination); }
protected override void Execute(CustomPassContext ctx) { // Executed every frame for all the camera inside the pass volume AdditionalCompositorData layerData = null; ctx.hdCamera.camera.gameObject.TryGetComponent <AdditionalCompositorData>(out layerData); if (layerData == null || layerData.clearColorTexture == null) { return; } else { float cameraAspectRatio = (float)ctx.hdCamera.actualWidth / ctx.hdCamera.actualHeight; float imageAspectRatio = (float)layerData.clearColorTexture.width / layerData.clearColorTexture.height; var scaleBiasRt = new Vector4(1.0f, 1.0f, 0.0f, 0.0f); if (layerData.imageFitMode == BackgroundFitMode.FitHorizontally) { scaleBiasRt.y = cameraAspectRatio / imageAspectRatio; scaleBiasRt.w = (1 - scaleBiasRt.y) / 2.0f; } else if (layerData.imageFitMode == BackgroundFitMode.FitVertically) { scaleBiasRt.x = imageAspectRatio / cameraAspectRatio; scaleBiasRt.z = (1 - scaleBiasRt.x) / 2.0f; } //else stretch (nothing to do) // The texture might not cover the entire screen (letter boxing), so in this case clear first to the background color (and stencil) if (scaleBiasRt.x < 1.0f || scaleBiasRt.y < 1.0f) { m_FullscreenPassMaterial.SetVector(ShaderIDs.k_BlitScaleBiasRt, new Vector4(1.0f, 1.0f, 0.0f, 0.0f)); m_FullscreenPassMaterial.SetVector(ShaderIDs.k_BlitScaleBias, new Vector4(1.0f, 1.0f, 0.0f, 0.0f)); ctx.cmd.DrawProcedural(Matrix4x4.identity, m_FullscreenPassMaterial, (int)PassType.ClearColorAndStencil, MeshTopology.Quads, 4, 1); } m_FullscreenPassMaterial.SetTexture(ShaderIDs.k_BlitTexture, layerData.clearColorTexture); m_FullscreenPassMaterial.SetVector(ShaderIDs.k_BlitScaleBiasRt, scaleBiasRt); m_FullscreenPassMaterial.SetVector(ShaderIDs.k_BlitScaleBias, new Vector4(1.0f, 1.0f, 0.0f, 0.0f)); m_FullscreenPassMaterial.SetInt(ShaderIDs.k_ClearAlpha, layerData.clearAlpha ? 1 : 0); // draw a quad (not Triangle), to support letter boxing and stretching ctx.cmd.DrawProcedural(Matrix4x4.identity, m_FullscreenPassMaterial, (int)PassType.DrawTextureAndClearStencil, MeshTopology.Quads, 4, 1); } }