public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerDataList) { LightweightRP lw = RenderPipelineManager.currentPipeline as LightweightRP; if (lw == null) { return; } PipelineCapabilities capabilities = LightweightRP.GetPipelineCapabilities(); int prevVariantCount = compilerDataList.Count; for (int i = 0; i < compilerDataList.Count; ++i) { if (StripUnused(capabilities, shader, snippetData, compilerDataList[i])) { compilerDataList.RemoveAt(i); --i; } } #if LOG_VARIANTS m_TotalVariantsInputCount += prevVariantCount; m_TotalVariantsOutputCount += compilerDataList.Count; LogVariants(shader, snippetData, prevVariantCount, compilerDataList.Count); #endif }
void CopyDepthSubPass(ref ScriptableRenderContext context, ref CameraData cameraData) { CommandBuffer cmd = CommandBufferPool.Get("Depth Copy"); RenderTargetIdentifier depthSurface = GetSurface(depthAttachmentHandle); RenderTargetIdentifier copyDepthSurface = GetSurface(RenderTargetHandles.DepthTexture); RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref cameraData); descriptor.colorFormat = RenderTextureFormat.Depth; descriptor.depthBufferBits = k_DepthStencilBufferBits; descriptor.msaaSamples = 1; descriptor.bindMS = false; cmd.GetTemporaryRT(RenderTargetHandles.DepthTexture, descriptor, FilterMode.Point); if (cameraData.msaaSamples > 1) { cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); if (cameraData.msaaSamples == 4) { cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); } else { cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); } cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial); } else { cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get("Depth Copy"); RenderTargetIdentifier depthSurface = source.Identifier(); RenderTargetIdentifier copyDepthSurface = destination.Identifier(); RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref renderingData.cameraData); descriptor.colorFormat = RenderTextureFormat.Depth; descriptor.depthBufferBits = 32; //TODO: fix this ; descriptor.msaaSamples = 1; descriptor.bindMS = false; cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point); if (renderingData.cameraData.msaaSamples > 1) { cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); if (renderingData.cameraData.msaaSamples == 4) { cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); } else { cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); } cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial); } else { cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4); LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
public void CollectShadows(Camera camera, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context) { CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows"); SetShadowCollectPassKeywords(cmd); // Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that // doesn't like null sources when trying to determine a stereo-ized blit. So for proper // stereo functionality, we use the screen-space shadow map as the source (until we have // a better solution). // An alternative would be DrawProcedural, but that would require further changes in the shader. cmd.SetRenderTarget(m_ScreenSpaceShadowmapTexture); cmd.ClearRenderTarget(true, true, Color.white); cmd.Blit(m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowsMaterial); LightweightPipeline.StartStereoRendering(camera, ref context, frameRenderingConfiguration); context.ExecuteCommandBuffer(cmd); LightweightPipeline.StopStereoRendering(camera, ref context, frameRenderingConfiguration); CommandBufferPool.Release(cmd); }
void SetupMainLightConstants(CommandBuffer cmd, ref LightData lightData) { Vector4 lightPos, lightColor, lightDistanceAttenuation, lightSpotDir, lightSpotAttenuation; List <VisibleLight> lights = lightData.visibleLights; InitializeLightConstants(lightData.visibleLights, lightData.mainLightIndex, out lightPos, out lightColor, out lightDistanceAttenuation, out lightSpotDir, out lightSpotAttenuation); if (lightData.mainLightIndex >= 0) { VisibleLight mainLight = lights[lightData.mainLightIndex]; Light mainLightRef = mainLight.light; if (LightweightPipeline.IsSupportedCookieType(mainLight.lightType) && mainLightRef.cookie != null) { Matrix4x4 lightCookieMatrix; LightweightPipeline.GetLightCookieMatrix(mainLight, out lightCookieMatrix); cmd.SetGlobalTexture(LightConstantBuffer._MainLightCookie, mainLightRef.cookie); cmd.SetGlobalMatrix(LightConstantBuffer._WorldToLight, lightCookieMatrix); } } cmd.SetGlobalVector(LightConstantBuffer._MainLightPosition, new Vector4(lightPos.x, lightPos.y, lightPos.z, lightDistanceAttenuation.w)); cmd.SetGlobalVector(LightConstantBuffer._MainLightColor, lightColor); }
void FinalBlitPass(ref ScriptableRenderContext context, ref CameraData cameraData) { Material material = cameraData.isStereoEnabled ? null : m_BlitMaterial; RenderTargetIdentifier sourceRT = GetSurface(colorAttachmentHandle); CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass"); cmd.SetGlobalTexture("_BlitTex", sourceRT); if (!cameraData.isDefaultViewport) { SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.All, Color.black); cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); cmd.SetViewport(cameraData.camera.pixelRect); LightweightPipeline.DrawFullScreen(cmd, material); } else { cmd.Blit(GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, material); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }