void FilterCubemapCommon(CommandBuffer cmd, Texture source, RenderTexture target, int mipCount, Matrix4x4[] worldToViewMatrices) { // Solid angle associated with a texel of the cubemap. float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI); m_GgxConvolveMaterial.SetTexture("_MainTex", source); m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData); m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1); m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP); for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip) { string sampleName = String.Format("Filter Cubemap Mip {0}", mip); cmd.BeginSample(sampleName); for (int face = 0; face < 6; ++face) { Vector4 faceSize = new Vector4(source.width >> mip, source.height >> mip, 1.0f / (source.width >> mip), 1.0f / (source.height >> mip)); Matrix4x4 transform = SkyManager.ComputePixelCoordToWorldSpaceViewDirectionMatrix(0.5f * Mathf.PI, faceSize, worldToViewMatrices[face], true); MaterialPropertyBlock props = new MaterialPropertyBlock(); props.SetFloat("_Level", mip); props.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, transform); Utilities.SetRenderTarget(cmd, target, ClearFlag.ClearNone, mip, (CubemapFace)face); Utilities.DrawFullScreen(cmd, m_GgxConvolveMaterial, props); } cmd.EndSample(sampleName); } }
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque) { // TODO: Currently we can't render opaque object forward when deferred is enabled // miss option if (!debugParameters.ShouldUseForwardRenderingOnly() && renderOpaque) { return; } using (new Utilities.ProfilingSample("Forward Pass", renderContext)) { Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT); if (m_LightLoop != null) { m_LightLoop.RenderForward(camera, renderContext, renderOpaque); } if (renderOpaque) { RenderOpaqueRenderList(cullResults, camera, renderContext, "Forward", Utilities.kRendererConfigurationBakedLighting); } else { RenderTransparentRenderList(cullResults, camera, renderContext, "Forward", Utilities.kRendererConfigurationBakedLighting); } } }
void FilterCubemapCommon(ScriptableRenderContext context, Texture source, RenderTexture target, int mipCount, Mesh[] cubemapFaceMesh) { // Solid angle associated with a texel of the cubemap. float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI); m_GgxConvolveMaterial.SetTexture("_MainTex", source); m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData); m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1); m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP); for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip) { MaterialPropertyBlock props = new MaterialPropertyBlock(); props.SetFloat("_Level", mip); for (int face = 0; face < 6; ++face) { Utilities.SetRenderTarget(context, target, ClearFlag.ClearNone, mip, (CubemapFace)face); var cmd = new CommandBuffer { name = "" }; cmd.DrawMesh(cubemapFaceMesh[face], Matrix4x4.identity, m_GgxConvolveMaterial, 0, 0, props); context.ExecuteCommandBuffer(cmd); cmd.Dispose(); } } }
void FilterCubemapCommon(CommandBuffer cmd, Texture source, RenderTexture target, int mipCount, Mesh[] cubemapFaceMesh) { // Solid angle associated with a texel of the cubemap. float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI); m_GgxConvolveMaterial.SetTexture("_MainTex", source); m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData); m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1); m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP); for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip) { string sampleName = String.Format("Filter Cubemap Mip {0}", mip); cmd.BeginSample(sampleName); MaterialPropertyBlock props = new MaterialPropertyBlock(); props.SetFloat("_Level", mip); for (int face = 0; face < 6; ++face) { Utilities.SetRenderTarget(cmd, target, ClearFlag.ClearNone, mip, (CubemapFace)face); cmd.DrawMesh(cubemapFaceMesh[face], Matrix4x4.identity, m_GgxConvolveMaterial, 0, 0, props); } cmd.EndSample(sampleName); } }
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque) { // TODO: Currently we can't render opaque object forward when deferred is enabled // miss option if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly() && renderOpaque) { return; } using (new Utilities.ProfilingSample("Forward Pass", renderContext)) { Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT); if (m_LightLoop != null) { m_LightLoop.RenderForward(camera, renderContext, renderOpaque); } bool debugLighting = globalDebugSettings.lightingDebugSettings.lightingDebugMode != LightingDebugMode.None; string forwardPassName = debugLighting ? "ForwardDebugLighting" : "Forward"; if (renderOpaque) { RenderOpaqueRenderList(cullResults, camera, renderContext, forwardPassName, Utilities.kRendererConfigurationBakedLighting); } else { RenderTransparentRenderList(cullResults, camera, renderContext, forwardPassName, Utilities.kRendererConfigurationBakedLighting); } } }
public override void SetRenderTargets(BuiltinSkyParameters builtinParams) { if (builtinParams.depthBuffer == BuiltinSkyParameters.nullRT) { Utilities.SetRenderTarget(builtinParams.renderContext, builtinParams.colorBuffer); } else { Utilities.SetRenderTarget(builtinParams.renderContext, builtinParams.colorBuffer, builtinParams.depthBuffer); } }
private void BlitCubemap(CommandBuffer cmd, Cubemap source, RenderTexture dest) { MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock(); for (int i = 0; i < 6; ++i) { Utilities.SetRenderTarget(cmd, dest, ClearFlag.ClearNone, 0, (CubemapFace)i); propertyBlock.SetTexture("_MainTex", source); propertyBlock.SetFloat("_faceIndex", (float)i); cmd.DrawProcedural(Matrix4x4.identity, m_BlitCubemapMaterial, 0, MeshTopology.Triangles, 3, 1, propertyBlock); } }
// Render material that are forward opaque only (like eye), this include unlit material void RenderForwardOnlyOpaque(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext) { using (new Utilities.ProfilingSample("Forward Only Pass", renderContext)) { Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT); if (m_LightLoop != null) { m_LightLoop.RenderForward(camera, renderContext, true); } RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnlyOpaque", Utilities.kRendererConfigurationBakedLighting); } }
private void RenderSkyToCubemap(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, RenderTexture target) { for (int i = 0; i < 6; ++i) { builtinParams.invViewProjMatrix = m_faceCameraInvViewProjectionMatrix[i]; builtinParams.screenSize = m_CubemapScreenSize; builtinParams.skyMesh = m_CubemapFaceMesh[i]; builtinParams.colorBuffer = target; builtinParams.depthBuffer = BuiltinSkyParameters.nullRT; Utilities.SetRenderTarget(builtinParams.renderContext, target, ClearFlag.ClearNone, 0, (CubemapFace)i); m_Renderer.RenderSky(builtinParams, skyParameters, true); } }
// This pass is use in case of forward opaque and deferred rendering. We need to render forward objects before tile lighting pass void RenderForwardOnlyOpaqueDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext) { // If we are forward only we don't need to render ForwardOnlyOpaqueDepthOnly object // But in case we request a prepass we render it if (debugParameters.ShouldUseForwardRenderingOnly() && !debugParameters.useDepthPrepass) { return; } using (new Utilities.ProfilingSample("Forward opaque depth", renderContext)) { Utilities.SetRenderTarget(renderContext, m_CameraDepthStencilBufferRT); RenderOpaqueRenderList(cull, camera, renderContext, "ForwardOnlyOpaqueDepthOnly"); } }
void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext renderContext) { if (debugParameters.ShouldUseForwardRenderingOnly()) { return; } using (new Utilities.ProfilingSample("GBuffer Pass", renderContext)) { // setup GBuffer for rendering Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT); // render opaque objects into GBuffer RenderOpaqueRenderList(cull, camera, renderContext, "GBuffer", Utilities.kRendererConfigurationBakedLighting); } }
void RenderDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext) { // If we are forward only we will do a depth prepass // TODO: Depth prepass should be enabled based on light loop settings. LightLoop define if they need a depth prepass + forward only... if (!debugParameters.useDepthPrepass) { return; } using (new Utilities.ProfilingSample("Depth Prepass", renderContext)) { // TODO: Must do opaque then alpha masked for performance! // TODO: front to back for opaque and by materal for opaque tested when we split in two Utilities.SetRenderTarget(renderContext, m_CameraDepthStencilBufferRT); RenderOpaqueRenderList(cull, camera, renderContext, "DepthOnly"); } }
private void BlitCubemap(ScriptableRenderContext renderContext, Cubemap source, RenderTexture dest) { MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock(); for (int i = 0; i < 6; ++i) { Utilities.SetRenderTarget(renderContext, dest, ClearFlag.ClearNone, 0, (CubemapFace)i); var cmd = new CommandBuffer { name = "" }; propertyBlock.SetTexture("_MainTex", source); propertyBlock.SetFloat("_faceIndex", (float)i); cmd.DrawProcedural(Matrix4x4.identity, m_BlitCubemapMaterial, 0, MeshTopology.Triangles, 3, 1, propertyBlock); renderContext.ExecuteCommandBuffer(cmd); cmd.Dispose(); } }
private void RenderSkyToCubemap(BuiltinSkyParameters builtinParams, SkySettings skySettings, RenderTexture target) { for (int i = 0; i < 6; ++i) { builtinParams.pixelCoordToViewDirMatrix = m_facePixelCoordToViewDirMatrices[i]; builtinParams.invViewProjMatrix = m_faceCameraInvViewProjectionMatrix[i]; builtinParams.colorBuffer = target; builtinParams.depthBuffer = BuiltinSkyParameters.nullRT; Utilities.SetRenderTarget(builtinParams.commandBuffer, target, ClearFlag.ClearNone, 0, (CubemapFace)i); m_Renderer.RenderSky(builtinParams, skySettings, true); } // Generate mipmap for our cubemap Debug.Assert(target.autoGenerateMips == false); builtinParams.commandBuffer.GenerateMips(target); }
void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext renderContext) { if (m_Owner.renderingSettings.ShouldUseForwardRenderingOnly()) { return; } using (new Utilities.ProfilingSample("GBuffer Pass", renderContext)) { bool debugLighting = globalDebugSettings.lightingDebugSettings.lightingDebugMode != LightingDebugMode.None; // setup GBuffer for rendering Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT); // render opaque objects into GBuffer RenderOpaqueRenderList(cull, camera, renderContext, debugLighting ? "GBufferDebugLighting" : "GBuffer", Utilities.kRendererConfigurationBakedLighting); } }
void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext) { using (new Utilities.ProfilingSample("DebugView Material Mode Pass", renderContext)) // Render Opaque forward { Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, Utilities.kClearAll, Color.black); Shader.SetGlobalInt("_DebugViewMaterial", (int)debugParameters.debugViewMaterial); RenderOpaqueRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial", Utilities.kRendererConfigurationBakedLighting); } // Render GBuffer opaque if (!debugParameters.ShouldUseForwardRenderingOnly()) { Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewMaterialGBuffer); m_DebugViewMaterialGBuffer.SetFloat("_DebugViewMaterial", (float)debugParameters.debugViewMaterial); // m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer); // TODO: Bind depth textures var cmd = new CommandBuffer { name = "GBuffer Debug Pass" }; cmd.Blit(null, m_CameraColorBufferRT, m_DebugViewMaterialGBuffer, 0); renderContext.ExecuteCommandBuffer(cmd); cmd.Dispose(); } // Render forward transparent { RenderTransparentRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial", Utilities.kRendererConfigurationBakedLighting); } // Last blit { var cmd = new CommandBuffer { name = "Blit DebugView Material Debug" }; cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget); renderContext.ExecuteCommandBuffer(cmd); cmd.Dispose(); } }
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderContext) { using (new Utilities.ProfilingSample("InitAndClearBuffer", renderContext)) { // We clear only the depth buffer, no need to clear the various color buffer as we overwrite them. // Clear depth/stencil and init buffers using (new Utilities.ProfilingSample("InitGBuffers and clear Depth/Stencil", renderContext)) { var cmd = new CommandBuffer(); cmd.name = ""; // Init buffer // With scriptable render loop we must allocate ourself depth and color buffer (We must be independent of backbuffer for now, hope to fix that later). // Also we manage ourself the HDR format, here allocating fp16 directly. // With scriptable render loop we can allocate temporary RT in a command buffer, they will not be release with ExecuteCommandBuffer // These temporary surface are release automatically at the end of the scriptable render pipeline if not release explicitly int w = camera.pixelWidth; int h = camera.pixelHeight; cmd.GetTemporaryRT(m_CameraColorBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV cmd.GetTemporaryRT(m_CameraSubsurfaceBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear, 1, true); // Enable UAV cmd.GetTemporaryRT(m_CameraFilteringBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear, 1, true); // Enable UAV cmd.GetTemporaryRT(m_CameraDepthStencilBuffer, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth); cmd.GetTemporaryRT(m_CameraStencilBuffer, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth); if (!m_Owner.debugParameters.ShouldUseForwardRenderingOnly()) { m_gbufferManager.InitGBuffers(w, h, cmd); } renderContext.ExecuteCommandBuffer(cmd); cmd.Dispose(); Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.ClearDepth); } // Clear the diffuse SSS lighting target using (new Utilities.ProfilingSample("Clear SSS diffuse target", renderContext)) { Utilities.SetRenderTarget(renderContext, m_CameraSubsurfaceBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.ClearColor, Color.black); } // Clear the SSS filtering target using (new Utilities.ProfilingSample("Clear SSS filtering target", renderContext)) { Utilities.SetRenderTarget(renderContext, m_CameraFilteringBuffer, m_CameraDepthStencilBufferRT, ClearFlag.ClearColor, Color.black); } // TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later. // Clear the HDR target using (new Utilities.ProfilingSample("Clear HDR target", renderContext)) { Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.ClearColor, Color.black); } // Clear GBuffers if (!debugParameters.ShouldUseForwardRenderingOnly()) { using (new Utilities.ProfilingSample("Clear GBuffer", renderContext)) { Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT, ClearFlag.ClearColor, Color.black); } } // END TEMP } }
public override void SetRenderTargets(BuiltinSkyParameters builtinParams) { // We do not bind the depth buffer as a depth-stencil target since it is // bound as a color texture which is then sampled from within the shader. Utilities.SetRenderTarget(builtinParams.renderContext, builtinParams.colorBuffer); }