public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { SortingSettings sortSettings = new SortingSettings(cam.cam); sortSettings.criteria = SortingCriteria.CommonTransparent; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("Transparent"), sortSettings) { enableDynamicBatching = false, enableInstancing = false, perObjectData = UnityEngine.Rendering.PerObjectData.None }; FilteringSettings filter = new FilteringSettings { excludeMotionVectorObjects = false, layerMask = cam.cam.cullingMask, renderQueueRange = RenderQueueRange.transparent, renderingLayerMask = (uint)cam.cam.cullingMask, sortingLayerRange = SortingLayerRange.all }; data.buffer.CopyTexture(cam.targets.renderTargetIdentifier, 0, 0, cam.targets.backupIdentifier, 0, 0); data.buffer.SetGlobalTexture(ShaderIDs._GrabTexture, cam.targets.backupIdentifier); transparentOutput[0] = cam.targets.renderTargetIdentifier; transparentOutput[1] = ShaderIDs._CameraDepthTexture; data.buffer.SetRenderTarget(colors: transparentOutput, depth: ShaderIDs._DepthBufferTexture); data.ExecuteCommandBuffer(); data.context.DrawRenderers(proper.cullResults, ref drawSettings, ref filter); }
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { bool *propertyCheckedFlags = stackalloc bool[] { false, false, false }; foreach (var cam in cameras) { PipelineCamera pipelineCam = cam.GetComponent <PipelineCamera>(); if (!pipelineCam) { pipelineCam = Camera.main.GetComponent <PipelineCamera>(); if (!pipelineCam) { continue; } } Render(pipelineCam, BuiltinRenderTextureType.CameraTarget, ref renderContext, cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); renderContext.Submit(); } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { if (SunLight.current == null) { return; } if (data.baseBuffer.clusterCount <= 0) { return; } CommandBuffer buffer = data.buffer; int pass; if (SunLight.current.enableShadow) { PipelineFunctions.UpdateShadowMapState(ref SunLight.shadMap, ref SunLight.current.settings, buffer); PipelineFunctions.DrawShadow(cam.cam, data.resources.gpuFrustumCulling, buffer, ref data.baseBuffer, ref SunLight.current.settings, ref SunLight.shadMap, cascadeShadowMapVP, shadowFrustumVP); PipelineFunctions.UpdateShadowMaskState(buffer, ref SunLight.shadMap, cascadeShadowMapVP); pass = 0; } else { pass = 1; } buffer.SetGlobalVector(ShaderIDs._LightFinalColor, SunLight.shadMap.light.color * SunLight.shadMap.light.intensity); buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); buffer.SetGlobalVector(ShaderIDs._LightPos, -SunLight.shadMap.shadCam.forward); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, shadMaskMaterial, 0, pass); data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; skyboxIdentifier[0] = camera.targets.renderTargetIdentifier; skyboxIdentifier[1] = camera.targets.motionVectorTexture; buffer.SetRenderTarget(skyboxIdentifier, camera.targets.depthIdentifier); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0); data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { // Material proceduralMaterial = data.baseBuffer.combinedMaterial; CommandBuffer buffer = data.buffer; buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier); buffer.ClearRenderTarget(true, true, Color.black); PipelineBaseBuffer baseBuffer; if (!SceneController.current.GetBaseBufferAndCheck(out baseBuffer)) { return; } HizOcclusionData hizData = IPerCameraData.GetProperty <HizOcclusionData>(cam, getOcclusionData); RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.arrayCollection.frustumPlanes, proceduralMaterial = proceduralMaterial, isOrtho = cam.cam.orthographic, cullingShader = data.resources.gpuFrustumCulling }; HizOptions hizOptions; switch (occCullingMod) { case OcclusionCullingMode.None: SceneController.current.DrawCluster(ref options); break; case OcclusionCullingMode.SingleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat }; SceneController.current.DrawClusterOccSingleCheck(ref options, ref hizOptions); break; case OcclusionCullingMode.DoubleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat }; SceneController.current.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets); break; } data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier); buffer.ClearRenderTarget(true, true, Color.black); PipelineBaseBuffer baseBuffer; bool isClusterEnabled = SceneController.GetBaseBuffer(out baseBuffer); HizOcclusionData hizData = IPerCameraData.GetProperty <HizOcclusionData>(cam, () => new HizOcclusionData()); RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.arrayCollection.frustumPlanes, isOrtho = cam.cam.orthographic, cullingShader = data.resources.gpuFrustumCulling, terrainCompute = data.resources.terrainCompute, isClusterEnabled = isClusterEnabled, isTerrainEnabled = true }; HizOptions hizOptions; switch (occCullingMod) { case OcclusionCullingMode.None: SceneController.current.DrawCluster(ref options, ref cam.targets); break; case OcclusionCullingMode.SingleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat, currentDepthTex = cam.targets.depthTexture }; SceneController.current.DrawClusterOccSingleCheck(ref options, ref hizOptions, ref cam.targets); break; case OcclusionCullingMode.DoubleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat, currentDepthTex = cam.targets.depthTexture }; SceneController.current.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets); break; } data.ExecuteCommandBuffer(); }
private static void RenderScene(ref PipelineCommandData data, Camera cam) { data.ExecuteCommandBuffer(); FilteringSettings renderSettings = new FilteringSettings(); renderSettings.renderQueueRange = RenderQueueRange.opaque; renderSettings.layerMask = cam.cullingMask; renderSettings.renderingLayerMask = (uint)cam.cullingMask; data.defaultDrawSettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam)); data.defaultDrawSettings.perObjectData = UnityEngine.Rendering.PerObjectData.MotionVectors; data.context.DrawRenderers(data.cullResults, ref data.defaultDrawSettings, ref renderSettings); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { if (data.baseBuffer.clusterCount <= 0) { return; } CommandBuffer buffer = data.buffer; cullJobHandler.Complete(); UnsafeUtility.ReleaseGCObject(gcHandler); pointLightMaterial.SetBuffer(ShaderIDs.verticesBuffer, sphereBuffer); //Un Shadow Point light buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); for (int c = 0; c < unShadowCount; c++) { var i = cullJob.indices[cullJob.length - c]; MPointLight light = MPointLight.allPointLights[i]; buffer.SetGlobalVector(ShaderIDs._LightColor, light.color); buffer.SetGlobalVector(ShaderIDs._LightPos, new Vector4(light.position.x, light.position.y, light.position.z, light.range)); buffer.SetGlobalFloat(ShaderIDs._LightIntensity, light.intensity); buffer.DrawProceduralIndirect(Matrix4x4.identity, pointLightMaterial, 0, MeshTopology.Triangles, sphereIndirectBuffer, 0); } //TODO if (shadowCount > 0) { NativeArray <Vector4> positions = new NativeArray <Vector4>(shadowCount, Allocator.Temp, NativeArrayOptions.UninitializedMemory); for (int i = 0; i < shadowCount; i++) { MPointLight light = MPointLight.allPointLights[cullJob.indices[i]]; positions[i] = new Vector4(light.position.x, light.position.y, light.position.z, light.range); } CubeFunction.UpdateLength(ref cubeBuffer, shadowCount); var cullShader = data.resources.pointLightFrustumCulling; CubeFunction.SetBuffer(ref cubeBuffer, ref data.baseBuffer, cullShader, buffer); CubeFunction.PrepareDispatch(ref cubeBuffer, buffer, cullShader, positions); for (int i = 0; i < shadowCount; i++) { MPointLight light = MPointLight.allPointLights[cullJob.indices[i]]; CubeFunction.DrawShadow(light, buffer, ref cubeBuffer, ref data.baseBuffer, cullShader, i, cubeDepthMaterial); buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); buffer.SetGlobalVector(ShaderIDs._LightColor, light.color); buffer.SetGlobalVector(ShaderIDs._LightPos, positions[i]); buffer.SetGlobalFloat(ShaderIDs._LightIntensity, light.intensity); buffer.SetGlobalTexture(ShaderIDs._CubeShadowMap, light.shadowmapTexture); buffer.DrawProceduralIndirect(Matrix4x4.identity, pointLightMaterial, 1, MeshTopology.Triangles, sphereIndirectBuffer, 0); } positions.Dispose(); } //Shadow Point Light indicesArray.Dispose(); data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; handle.Complete(); SkyboxPreviewMatrix last = IPerCameraData.GetProperty(camera, () => new SkyboxPreviewMatrix()); buffer.SetGlobalMatrix(_LastSkyVP, last.lastViewProj); targetIdentifiers[0] = camera.targets.renderTargetIdentifier; targetIdentifiers[1] = ShaderIDs._CameraMotionVectorsTexture; buffer.SetRenderTarget(colors: targetIdentifiers, depth: ShaderIDs._DepthBufferTexture); data.ExecuteCommandBuffer(); data.context.DrawSkybox(camera.cam); last.lastViewProj = job.viewProj; }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; sharedData.autoExposureTexture = RuntimeUtilities.whiteTexture; sharedData.screenSize = new Vector2Int(cam.cam.pixelWidth, cam.cam.pixelHeight); sharedData.uberMaterial.SetTexture(PostProcessing.ShaderIDs.AutoExposureTex, sharedData.autoExposureTexture); renderAction(ref data); if (sharedData.keywordsTransformed) { sharedData.keywordsTransformed = false; sharedData.uberMaterial.shaderKeywords = sharedData.shaderKeywords.ToArray(); } PostFunctions.RunPostProcess(ref cam.targets, buffer, ref data, uberAction); data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { data.buffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); data.buffer.ClearRenderTarget(true, true, Color.black); data.ExecuteCommandBuffer(); //Execute the commandbuffer, buffer will be automatically cleared after executed FilterRenderersSettings filterSettings = new FilterRenderersSettings(true); filterSettings.excludeMotionVectorObjects = false; filterSettings.layerMask = cam.cam.cullingMask; filterSettings.renderQueueRange = RenderQueueRange.opaque; DrawRendererSettings drawSettings = new DrawRendererSettings(cam.cam, new ShaderPassName("Unlit")); drawSettings.flags = DrawRendererFlags.EnableDynamicBatching; drawSettings.rendererConfiguration = RendererConfiguration.None; drawSettings.sorting.flags = SortFlags.CommonOpaque; data.context.DrawRenderers(data.cullResults.visibleRenderers, ref drawSettings, filterSettings); }
private void Render(PipelineCamera pipelineCam, RenderTargetIdentifier dest, ref ScriptableRenderContext context, Camera cam) { CameraRenderingPath path = pipelineCam.renderingPath; pipelineCam.cam = cam; pipelineCam.EnableThis(); if (!CullResults.GetCullingParameters(cam, out data.cullParams)) { return; } context.SetupCameraProperties(cam); //Set Global Data data.defaultDrawSettings = new DrawRendererSettings(cam, new ShaderPassName("")); data.context = context; data.cullResults = CullResults.Cull(ref data.cullParams, context); PipelineFunctions.InitRenderTarget(ref pipelineCam.targets, cam, data.buffer); data.resources = resources; PipelineFunctions.GetViewProjectMatrix(cam, out data.vp, out data.inverseVP); for (int i = 0; i < data.frustumPlanes.Length; ++i) { Plane p = data.cullParams.GetCullingPlane(i); //GPU Driven RP's frustum plane is inverse from SRP's frustum plane data.frustumPlanes[i] = new Vector4(-p.normal.x, -p.normal.y, -p.normal.z, -p.distance); } DrawEvent evt; if (allDrawEvents.TryGetValue(path, out evt)) { //Pre Calculate Events foreach (var i in evt.preRenderEvents) { i.PreRenderFrame(pipelineCam, ref data); } //Run job system together JobHandle.ScheduleBatchedJobs(); //Start Prepare Render Targets //Frame Update Events foreach (var i in evt.drawEvents) { i.FrameUpdate(pipelineCam, ref data); } } data.buffer.Blit(pipelineCam.targets.renderTargetIdentifier, dest); data.ExecuteCommandBuffer(); }
private static void RenderScene(ref PipelineCommandData data, Camera cam) { data.ExecuteCommandBuffer(); FilteringSettings renderSettings = new FilteringSettings(); renderSettings.renderQueueRange = RenderQueueRange.opaque; renderSettings.layerMask = cam.cullingMask; renderSettings.renderingLayerMask = (uint)cam.cullingMask; DrawingSettings dsettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam)) { enableDynamicBatching = true, enableInstancing = false, perObjectData = UnityEngine.Rendering.PerObjectData.MotionVectors }; data.context.DrawRenderers(data.cullResults, ref dsettings, ref renderSettings); }
private static void RenderScene(ref PipelineCommandData data, Camera cam) { data.ExecuteCommandBuffer(); FilterRenderersSettings renderSettings = new FilterRenderersSettings(true) { renderQueueRange = RenderQueueRange.opaque, layerMask = cam.cullingMask }; data.defaultDrawSettings.SetShaderPassName(0, new ShaderPassName("GBuffer")); data.defaultDrawSettings.sorting = new DrawRendererSortSettings { flags = SortFlags.CommonOpaque, sortMode = DrawRendererSortMode.Perspective, cameraPosition = cam.transform.position }; data.defaultDrawSettings.rendererConfiguration = RendererConfiguration.PerObjectMotionVectors; data.context.DrawRenderers(data.cullResults.visibleRenderers, ref data.defaultDrawSettings, renderSettings); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); cullJobHandler.Complete(); UnsafeUtility.ReleaseGCObject(gcHandler); //Use Result Indices foreach (int i in cullJob.resultIndices) { ReflectionCube cube = ReflectionCube.allCubes[i]; block.SetTexture(_ReflectionProbe, cube.reflectionCube); buffer.DrawMesh(GraphicsUtility.cubeMesh, cube.localToWorld, reflectMaterial, 0, 0, block); } //TODO cullJob.resultIndices.Dispose(); data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; HistoryTexture texComponent = IPerCameraData.GetProperty <HistoryTexture>(cam, (c) => new HistoryTexture(c.cam)); texComponent.UpdateProperty(cam); SetHistory(cam.cam, buffer, ref texComponent.historyTex, cam.targets.renderTargetIdentifier); historyTex = texComponent.historyTex; //TAA Start const float kMotionAmplification_Blending = 100f * 60f; const float kMotionAmplification_Bounding = 100f * 30f; buffer.SetGlobalFloat(ShaderIDs._Sharpness, sharpness); buffer.SetGlobalVector(ShaderIDs._TemporalClipBounding, new Vector4(stationaryAABBScale, motionAABBScale, kMotionAmplification_Bounding, 0f)); buffer.SetGlobalVector(ShaderIDs._FinalBlendParameters, new Vector4(stationaryBlending, motionBlending, kMotionAmplification_Blending, 0f)); buffer.SetGlobalTexture(ShaderIDs._HistoryTex, historyTex); PostFunctions.RunPostProcess(ref cam.targets, buffer, ref data, taaFunction); data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { SortingSettings sortSettings = new SortingSettings(cam.cam); sortSettings.criteria = SortingCriteria.CommonTransparent; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("Transparent"), sortSettings) { enableDynamicBatching = false, enableInstancing = false, perObjectData = UnityEngine.Rendering.PerObjectData.None }; FilteringSettings filter = new FilteringSettings { excludeMotionVectorObjects = false, layerMask = cam.cam.cullingMask, renderQueueRange = RenderQueueRange.transparent, renderingLayerMask = (uint)cam.cam.cullingMask, sortingLayerRange = SortingLayerRange.all }; int blurTex = blur.Render(data.buffer, new Vector2Int(cam.cam.pixelWidth, cam.cam.pixelHeight), cam.targets.renderTargetIdentifier); data.buffer.SetGlobalTexture(ShaderIDs._GrabTexture, blurTex); transparentOutput[0] = cam.targets.renderTargetIdentifier; transparentOutput[1] = ShaderIDs._CameraDepthTexture; data.buffer.SetRenderTarget(colors: transparentOutput, depth: ShaderIDs._DepthBufferTexture); cullJob.Complete(); var lst = CustomDrawRequest.allEvents; foreach (var i in customCullResults) { lst[i].DrawTransparent(data.buffer); } data.ExecuteCommandBuffer(); data.context.DrawRenderers(proper.cullResults, ref drawSettings, ref filter); CommandBuffer bf = cam.GetCommand <TransEvent>(); data.context.ExecuteCommandBuffer(bf); bf.Clear(); data.buffer.ReleaseTemporaryRT(blurTex); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { if (SunLight.current == null) { return; } PipelineBaseBuffer baseBuffer; if (!SceneController.current.GetBaseBufferAndCheck(out baseBuffer)) { return; } CommandBuffer buffer = data.buffer; int pass; if (SunLight.current.enableShadow) { RenderClusterOptions opts = new RenderClusterOptions { frustumPlanes = shadowFrustumVP, command = buffer, cullingShader = data.resources.gpuFrustumCulling, isOrtho = true, proceduralMaterial = null }; PipelineFunctions.UpdateShadowMapState(ref SunLight.shadMap, ref SunLight.current.settings, buffer); SceneController.current.DrawDirectionalShadow(cam.cam, ref opts, ref SunLight.current.settings, ref SunLight.shadMap, cascadeShadowMapVP); PipelineFunctions.UpdateShadowMaskState(buffer, ref SunLight.shadMap, cascadeShadowMapVP); pass = 0; } else { pass = 1; } buffer.SetGlobalVector(ShaderIDs._LightFinalColor, SunLight.shadMap.light.color * SunLight.shadMap.light.intensity); buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); buffer.SetGlobalVector(ShaderIDs._LightPos, -SunLight.shadMap.shadCam.forward); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, shadMaskMaterial, 0, pass); data.ExecuteCommandBuffer(); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { SortingSettings sortSettings = new SortingSettings(cam.cam); sortSettings.criteria = SortingCriteria.CommonTransparent; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("Transparent"), sortSettings) { enableDynamicBatching = false, enableInstancing = false, perObjectData = UnityEngine.Rendering.PerObjectData.None }; FilteringSettings filter = new FilteringSettings { excludeMotionVectorObjects = false, layerMask = cam.cam.cullingMask, renderQueueRange = RenderQueueRange.transparent, renderingLayerMask = (uint)cam.cam.cullingMask, sortingLayerRange = SortingLayerRange.all }; data.ExecuteCommandBuffer(); data.context.DrawRenderers(data.cullResults, ref drawSettings, ref filter); }
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { foreach (var i in beforeRenderFrame) { i.func(i.obj); } beforeRenderFrame.Clear(); SceneController.SetState(); foreach (var cam in cameras) { PipelineCamera pipelineCam = cam.GetComponent <PipelineCamera>(); if (!pipelineCam) { pipelineCam = Camera.main.GetComponent <PipelineCamera>(); if (!pipelineCam) { continue; } } Render(pipelineCam, BuiltinRenderTextureType.CameraTarget, ref renderContext, cam); PipelineFunctions.ReleaseRenderTarget(data.buffer, ref pipelineCam.targets); data.ExecuteCommandBuffer(); } foreach (var i in bufferAfterFrame) { renderContext.ExecuteCommandBuffer(i); i.Clear(); } bufferAfterFrame.Clear(); foreach (var i in afterRenderFrame) { i.func(i.obj); } afterRenderFrame.Clear(); renderContext.Submit(); }
public void PipelineUpdate(ref PipelineCommandData data) { if (renderingCommand.Length <= 0) { return; } CommandBuffer buffer = data.buffer; for (int i = 0; i < renderingCommand.Length; ++i) { ref CameraState orthoCam = ref renderingCommand[i]; ScriptableCullingParameters cullParam; bool rendering = orthoCam.cullingMask != 0; if (rendering) { transform.position = orthoCam.position; transform.rotation = orthoCam.rotation; cam.orthographicSize = orthoCam.size; cam.nearClipPlane = orthoCam.nearClipPlane; cam.farClipPlane = orthoCam.farClipPlane; cam.cullingMask = orthoCam.cullingMask; rendering = cam.TryGetCullingParameters(out cullParam); if (rendering) { data.context.SetupCameraProperties(cam); cullParam.cullingMask = (uint)orthoCam.cullingMask; cullParam.cullingOptions = CullingOptions.ForceEvenIfCameraIsNotActive; CullingResults result = data.context.Cull(ref cullParam); FilteringSettings filter = new FilteringSettings { layerMask = orthoCam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(1000, 5000) }; SortingSettings sort = new SortingSettings(cam) { criteria = SortingCriteria.RenderQueue }; DrawingSettings drawS = new DrawingSettings(new ShaderTagId("TerrainDecal"), sort) { perObjectData = UnityEngine.Rendering.PerObjectData.None }; DrawingSettings drawH = new DrawingSettings(new ShaderTagId("TerrainDisplacement"), sort) { perObjectData = UnityEngine.Rendering.PerObjectData.None }; ComputeShader copyShader = data.resources.shaders.texCopyShader; buffer.SetGlobalVector(ShaderIDs._MaskScaleOffset, float4(orthoCam.maskScaleOffset, (float)(1.0 / MTerrain.current.terrainData.displacementScale))); buffer.SetGlobalInt(ShaderIDs._OffsetIndex, orthoCam.heightIndex); var terrainData = MTerrain.current.terrainData; buffer.SetGlobalVector(ShaderIDs._HeightScaleOffset, (float4)double4(terrainData.heightScale, terrainData.heightOffset, 1, 1)); buffer.GetTemporaryRT(RenderTargets.gbufferIndex[0], MTerrain.COLOR_RESOLUTION, MTerrain.COLOR_RESOLUTION, 16, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, true); buffer.GetTemporaryRT(RenderTargets.gbufferIndex[2], MTerrain.COLOR_RESOLUTION, MTerrain.COLOR_RESOLUTION, 0, FilterMode.Point, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear, 1, true); buffer.GetTemporaryRT(RenderTargets.gbufferIndex[1], MTerrain.COLOR_RESOLUTION, MTerrain.COLOR_RESOLUTION, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, true); idfs[0] = RenderTargets.gbufferIndex[0]; idfs[1] = RenderTargets.gbufferIndex[2]; idfs[2] = RenderTargets.gbufferIndex[1]; buffer.SetComputeIntParam(copyShader, ShaderIDs._Count, orthoCam.depthSlice); buffer.SetComputeTextureParam(copyShader, 7, ShaderIDs._VirtualMainTex, orthoCam.albedoRT); buffer.SetComputeTextureParam(copyShader, 7, ShaderIDs._VirtualBumpMap, orthoCam.normalRT); buffer.SetComputeTextureParam(copyShader, 7, ShaderIDs._VirtualSMO, orthoCam.smoRT); buffer.SetComputeTextureParam(copyShader, 7, RenderTargets.gbufferIndex[0], RenderTargets.gbufferIndex[0]); buffer.SetComputeTextureParam(copyShader, 7, RenderTargets.gbufferIndex[1], RenderTargets.gbufferIndex[1]); buffer.SetComputeTextureParam(copyShader, 7, RenderTargets.gbufferIndex[2], RenderTargets.gbufferIndex[2]); const int disp = MTerrain.COLOR_RESOLUTION / 8; buffer.DispatchCompute(copyShader, 7, disp, disp, 1); buffer.SetRenderTarget(colors: idfs, depth: idfs[0]); buffer.ClearRenderTarget(true, false, new Color(0, 0, 0, 0)); data.ExecuteCommandBuffer(); data.context.DrawRenderers(result, ref drawS, ref filter); buffer.SetComputeTextureParam(copyShader, 6, ShaderIDs._VirtualMainTex, orthoCam.albedoRT); buffer.SetComputeTextureParam(copyShader, 6, ShaderIDs._VirtualBumpMap, orthoCam.normalRT); buffer.SetComputeTextureParam(copyShader, 6, ShaderIDs._VirtualSMO, orthoCam.smoRT); buffer.SetComputeTextureParam(copyShader, 6, RenderTargets.gbufferIndex[0], RenderTargets.gbufferIndex[0]); buffer.SetComputeTextureParam(copyShader, 6, RenderTargets.gbufferIndex[1], RenderTargets.gbufferIndex[1]); buffer.SetComputeTextureParam(copyShader, 6, RenderTargets.gbufferIndex[2], RenderTargets.gbufferIndex[2]); buffer.DispatchCompute(copyShader, 6, disp, disp, 1); buffer.ReleaseTemporaryRT(RenderTargets.gbufferIndex[1]); buffer.ReleaseTemporaryRT(RenderTargets.gbufferIndex[2]); buffer.ReleaseTemporaryRT(RenderTargets.gbufferIndex[0]); buffer.SetRenderTarget(color: heightTempTex.colorBuffer, depth: heightTempTex.depthBuffer, 0); buffer.ClearRenderTarget(true, true, Color.black); data.ExecuteCommandBuffer(); data.context.DrawRenderers(result, ref drawH, ref filter); buffer.GenerateMips(heightTempTex); buffer.CopyTexture(heightTempTex, 0, 2, orthoCam.heightRT, orthoCam.depthSlice, 0); } } if (!rendering) { buffer.SetRenderTarget(orthoCam.heightRT, mipLevel: 0, cubemapFace: CubemapFace.Unknown, depthSlice: orthoCam.depthSlice); buffer.ClearRenderTarget(false, true, Color.black); } MTerrain.current.GenerateMips(orthoCam.depthSlice, buffer); data.ExecuteCommandBuffer(); data.context.Submit(); }
protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { bool *propertyCheckedFlags = stackalloc bool[] { false, false, false }; GraphicsSettings.useScriptableRenderPipelineBatching = resources.useSRPBatcher; foreach (var i in beforeRenderFrame) { i.func(i.obj); } beforeRenderFrame.Clear(); SceneController.SetState(); #if UNITY_EDITOR foreach (var pair in bakeList) { PipelineCamera pipelineCam = pair.pipelineCamera; for (int i = 0; i < pair.worldToCamera.Length; ++i) { pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i]; pipelineCam.cam.projectionMatrix = pair.projection[i]; Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags); data.buffer.Blit(pipelineCam.targets.renderTargetIdentifier, pair.tempTex); PipelineFunctions.ReleaseRenderTarget(data.buffer, ref pipelineCam.targets); data.buffer.CopyTexture(pair.tempTex, 0, 0, pair.texArray, i, 0); data.ExecuteCommandBuffer(); renderContext.Submit(); } pair.worldToCamera.Dispose(); pair.projection.Dispose(); renderContext.ExecuteCommandBuffer(pair.buffer); pair.buffer.Clear(); renderContext.Submit(); } bakeList.Clear(); #endif if (!PipelineCamera.allCamera.isCreated) { return; } foreach (var cam in cameras) { PipelineCamera pipelineCam; UIntPtr pipelineCamPtr; if (!PipelineCamera.allCamera.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr)) { #if UNITY_EDITOR renderingEditor = true; if (!PipelineCamera.allCamera.Get(Camera.main.gameObject.GetInstanceID(), out pipelineCamPtr)) { continue; } #else continue; #endif } else { renderingEditor = false; } pipelineCam = MUnsafeUtility.GetObject <PipelineCamera>(pipelineCamPtr.ToPointer()); Render(pipelineCam, ref renderContext, cam, propertyCheckedFlags); PipelineFunctions.ReleaseRenderTarget(data.buffer, ref pipelineCam.targets); data.ExecuteCommandBuffer(); renderContext.Submit(); } foreach (var i in afterRenderFrame) { i.func(i.obj); } afterRenderFrame.Clear(); if (bufferAfterFrame.Count > 0) { foreach (var i in bufferAfterFrame) { i(data.buffer); } data.ExecuteCommandBuffer(); bufferAfterFrame.Clear(); renderContext.Submit(); } }
protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { bool *propertyCheckedFlags = stackalloc bool[resources.allEvents.Length]; UnsafeUtility.MemClear(propertyCheckedFlags, resources.allEvents.Length); GraphicsSettings.useScriptableRenderPipelineBatching = resources.useSRPBatcher; SceneController.SetState(); #if UNITY_EDITOR int tempID = Shader.PropertyToID("_TempRT"); foreach (var pair in bakeList) { PipelineCamera pipelineCam = pair.pipelineCamera; for (int i = 0; i < pair.worldToCamera.Length; ++i) { pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i]; pipelineCam.cam.projectionMatrix = pair.projection[i]; pipelineCam.cameraTarget = tempID; data.buffer.GetTemporaryRT(tempID, pair.texArray.width, pair.texArray.height, pair.texArray.depth, FilterMode.Point, pair.texArray.format, RenderTextureReadWrite.Linear); Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags); data.buffer.CopyTexture(tempID, 0, 0, pair.texArray, i, 0); data.buffer.ReleaseTemporaryRT(tempID); data.ExecuteCommandBuffer(); renderContext.Submit(); } pair.worldToCamera.Dispose(); pair.projection.Dispose(); renderContext.ExecuteCommandBuffer(pair.buffer); pair.buffer.Clear(); renderContext.Submit(); } bakeList.Clear(); #endif if (PipelineCamera.allCamera.isCreated) { foreach (var cam in cameras) { PipelineCamera pipelineCam; UIntPtr pipelineCamPtr; if (!PipelineCamera.allCamera.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr)) { #if UNITY_EDITOR renderingEditor = true; var pos = cam.transform.eulerAngles; pos.z = 0; cam.transform.eulerAngles = pos; if (!PipelineCamera.allCamera.Get(Camera.main.gameObject.GetInstanceID(), out pipelineCamPtr)) { continue; } #else continue; #endif } else { renderingEditor = false; } pipelineCam = MUnsafeUtility.GetObject <PipelineCamera>(pipelineCamPtr.ToPointer()); Render(pipelineCam, ref renderContext, cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); renderContext.Submit(); } if (bufferAfterFrame.Count > 0) { foreach (var i in bufferAfterFrame) { i(data.buffer); } data.ExecuteCommandBuffer(); bufferAfterFrame.Clear(); renderContext.Submit(); } } else { if (bufferAfterFrame.Count > 0) { foreach (var i in bufferAfterFrame) { i(data.buffer); } Graphics.ExecuteCommandBuffer(data.buffer); bufferAfterFrame.Clear(); } } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = proper.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; FilteringSettings alphaTestFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2450, 2499) }; FilteringSettings opaqueFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2000, 2449) }; DrawingSettings depthAlphaTestDrawSettings = new DrawingSettings(new ShaderTagId("Depth"), new SortingSettings(cam.cam) { criteria = SortingCriteria.OptimizeStateChanges } ) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = true, enableInstancing = false }; DrawingSettings depthOpaqueDrawSettings = new DrawingSettings(new ShaderTagId("Depth"), new SortingSettings(cam.cam) { criteria = SortingCriteria.None }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = true, enableInstancing = false, overrideMaterial = proper.overrideOpaqueMaterial, overrideMaterialPassIndex = 1 }; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam.cam) { criteria = SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges }) { perObjectData = UnityEngine.Rendering.PerObjectData.Lightmaps, enableDynamicBatching = true, enableInstancing = false }; //Draw Depth Prepass data.buffer.SetRenderTarget(ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(true, false, Color.black); cullHandle.Complete(); var lst = CustomDrawRequest.allEvents; foreach (var i in gbufferCullResults) { lst[i].DrawDepthPrepass(buffer); } HizOcclusionData hizOccData = null; PipelineFunctions.UpdateFrustumMinMaxPoint(buffer, proper.frustumMinPoint, proper.frustumMaxPoint); if (useHiZ && SceneController.gpurpEnabled) { #if UNITY_EDITOR if (Application.isPlaying) { #endif hizOccData = IPerCameraData.GetProperty(cam, (c) => new HizOcclusionData(c.cam.pixelWidth)); hizOccData.UpdateWidth(cam.cam.pixelWidth); SceneController.CullCluster_LastFrameDepthHiZ(ref options, hizOccData, cam); buffer.DrawProceduralIndirect(Matrix4x4.identity, clusterMat, 2, MeshTopology.Triangles, SceneController.baseBuffer.instanceCountBuffer, 0); #if UNITY_EDITOR } #endif } RenderStateBlock depthBlock = new RenderStateBlock { depthState = new DepthState(true, CompareFunction.Less), mask = RenderStateMask.Depth }; SceneController.RenderScene(ref data, ref opaqueFilter, ref depthOpaqueDrawSettings, ref proper.cullResults, ref depthBlock); data.context.DrawRenderers(proper.cullResults, ref depthAlphaTestDrawSettings, ref alphaTestFilter); decalEvt.FrameUpdate(cam, ref data); //Draw GBuffer data.buffer.SetRenderTarget(colors: cam.targets.gbufferIdentifier, depth: ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(false, true, Color.black); foreach (var i in gbufferCullResults) { lst[i].DrawGBuffer(buffer); } if (useHiZ && SceneController.gpurpEnabled) { #if UNITY_EDITOR if (Application.isPlaying) { #endif buffer.SetGlobalBuffer(ShaderIDs._MaterialBuffer, data.resources.clusterResources.vmManager.materialBuffer); buffer.SetGlobalBuffer(ShaderIDs._TriangleMaterialBuffer, SceneController.baseBuffer.triangleMaterialBuffer); buffer.SetGlobalTexture(ShaderIDs._GPURPMainTex, data.resources.clusterResources.rgbaPool.rt); buffer.SetGlobalTexture(ShaderIDs._GPURPEmissionMap, data.resources.clusterResources.emissionPool.rt); buffer.SetGlobalTexture(ShaderIDs._GPURPBumpMap, data.resources.clusterResources.normalPool.rt); buffer.SetGlobalTexture(ShaderIDs._GPURPHeightMap, data.resources.clusterResources.heightPool.rt); buffer.DrawProceduralIndirect(Matrix4x4.identity, clusterMat, 0, MeshTopology.Triangles, SceneController.baseBuffer.instanceCountBuffer, 0); #if UNITY_EDITOR } #endif } SceneController.RenderScene(ref data, ref opaqueFilter, ref drawSettings, ref proper.cullResults); if (MTerrain.current) { MTerrain.current.DrawTerrain(buffer, 0, proper.frustumPlanes); } //Draw AlphaTest /* SortingSettings st = drawSettings.sortingSettings; * st.criteria = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges; * drawSettings.sortingSettings = st;*/ SceneController.RenderScene(ref data, ref alphaTestFilter, ref drawSettings, ref proper.cullResults); //Draw Recheck HIZ Occlusion if (useHiZ && SceneController.gpurpEnabled) { #if UNITY_EDITOR if (Application.isPlaying) #endif SceneController.DrawCluster_RecheckHiz(ref options, ref hizDepth, hizOccData, clusterMat, linearMat, cam); } //Draw Depth data.buffer.Blit(ShaderIDs._DepthBufferTexture, ShaderIDs._CameraDepthTexture); if (needUpdateGeometryBuffer) { needUpdateGeometryBuffer = false; data.ExecuteCommandBuffer(); data.context.ExecuteCommandBuffer(m_afterGeometryBuffer); m_afterGeometryBuffer.Clear(); } }
public static void RenderScene(ref PipelineCommandData data, ref FilteringSettings filterSettings, ref DrawingSettings drawSettings, ref CullingResults cullResults, ref RenderStateBlock stateBlock) { data.ExecuteCommandBuffer(); data.context.DrawRenderers(cullResults, ref drawSettings, ref filterSettings, ref stateBlock); }
public void PipelineUpdate(ref PipelineCommandData data) { if (renderingCommand.Length <= 0) { return; } CommandBuffer buffer = data.buffer; for (int i = 0; i < renderingCommand.Length; ++i) { ref CameraState orthoCam = ref renderingCommand[i]; transform.position = orthoCam.position; transform.rotation = orthoCam.rotation; cam.orthographicSize = orthoCam.size; cam.nearClipPlane = orthoCam.nearClipPlane; cam.farClipPlane = orthoCam.farClipPlane; #region CAMERA_RENDERING ScriptableCullingParameters cullParam; data.context.SetupCameraProperties(cam); if (!cam.TryGetCullingParameters(out cullParam)) { continue; } cullParam.cullingMask = (uint)orthoCam.cullingMask; cullParam.cullingOptions = CullingOptions.ForceEvenIfCameraIsNotActive; CullingResults result = data.context.Cull(ref cullParam); FilteringSettings filter = new FilteringSettings { layerMask = orthoCam.cullingMask, renderingLayerMask = uint.MaxValue, renderQueueRange = new RenderQueueRange(1000, 5000) }; SortingSettings sort = new SortingSettings(cam) { criteria = SortingCriteria.RenderQueue }; DrawingSettings drawS = new DrawingSettings(new ShaderTagId("TerrainDecal"), sort) { perObjectData = UnityEngine.Rendering.PerObjectData.None }; buffer.GetTemporaryRT(RenderTargets.gbufferIndex[0], orthoCam.resolution, orthoCam.resolution, 16, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, false); buffer.GetTemporaryRT(RenderTargets.gbufferIndex[2], orthoCam.resolution, orthoCam.resolution, 0, FilterMode.Point, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear, 1, false); buffer.GetTemporaryRT(RenderTargets.gbufferIndex[1], orthoCam.resolution, orthoCam.resolution, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, false); idfs[0] = RenderTargets.gbufferIndex[0]; idfs[1] = RenderTargets.gbufferIndex[2]; idfs[2] = RenderTargets.gbufferIndex[1]; buffer.SetRenderTarget(colors: idfs, depth: idfs[0]); buffer.ClearRenderTarget(true, true, new Color(0, 0, 0, 0)); data.ExecuteCommandBuffer(); data.context.DrawRenderers(result, ref drawS, ref filter); ComputeShader copyShader = data.resources.shaders.texCopyShader; buffer.SetComputeTextureParam(copyShader, 6, ShaderIDs._VirtualMainTex, orthoCam.albedoRT); buffer.SetComputeTextureParam(copyShader, 6, ShaderIDs._VirtualBumpMap, orthoCam.normalRT); buffer.SetComputeTextureParam(copyShader, 6, ShaderIDs._VirtualSMO, orthoCam.smoRT); buffer.SetComputeTextureParam(copyShader, 6, RenderTargets.gbufferIndex[0], RenderTargets.gbufferIndex[0]); buffer.SetComputeTextureParam(copyShader, 6, RenderTargets.gbufferIndex[1], RenderTargets.gbufferIndex[1]); buffer.SetComputeTextureParam(copyShader, 6, RenderTargets.gbufferIndex[2], RenderTargets.gbufferIndex[2]); buffer.SetComputeIntParam(copyShader, ShaderIDs._Count, orthoCam.depthSlice); int disp = orthoCam.resolution / 8; buffer.DispatchCompute(copyShader, 6, disp, disp, 1); buffer.ReleaseTemporaryRT(RenderTargets.gbufferIndex[0]); buffer.ReleaseTemporaryRT(RenderTargets.gbufferIndex[1]); buffer.ReleaseTemporaryRT(RenderTargets.gbufferIndex[2]); data.ExecuteCommandBuffer(); #endregion }
protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { currentFrameCamera.Clear(); PipelineCamera.InitializeDict(); foreach (var cam in cameras) { CameraSetting csg; ulong pipelineCamPtr; if (!PipelineCamera.CameraSearchDict.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr)) { if (!cam.TryGetComponent(out csg.pipeCam)) { #if UNITY_EDITOR if (cam.cameraType == CameraType.SceneView) { csg.isRenderingEditor = true; var pos = cam.transform.eulerAngles; pos.z = 0; cam.transform.eulerAngles = pos; if (!Camera.main || !(csg.pipeCam = Camera.main.GetComponent <PipelineCamera>())) { continue; } } else if (cam.cameraType == CameraType.Game) { csg.isRenderingEditor = false; csg.pipeCam = cam.gameObject.AddComponent <PipelineCamera>(); } else { continue; } #else csg.isRenderingEditor = false; csg.pipeCam = cam.gameObject.AddComponent <PipelineCamera>(); #endif } else { csg.isRenderingEditor = false; csg.pipeCam.AddToDict(); } } else { csg.isRenderingEditor = false; csg.pipeCam = MUnsafeUtility.GetObject <PipelineCamera>((void *)pipelineCamPtr); } csg.cam = cam; csg.pipeCam.cam = cam; csg.pipeCam.BeforeFrameRendering(); currentFrameCamera.Add(csg); } bool *propertyCheckedFlags = stackalloc bool[resources.allEvents.Length]; bool needSubmit = false; CustomDrawRequest.Initialize(); UnsafeUtility.MemClear(propertyCheckedFlags, resources.allEvents.Length); SceneController.SetState(); data.context = renderContext; data.resources = resources; if (motionVectorMatricesBuffer == null || !motionVectorMatricesBuffer.IsValid()) { motionVectorMatricesBuffer = new ComputeBuffer(MotionVectorDrawer.Capacity, sizeof(float3x4)); } else if (motionVectorMatricesBuffer.count < MotionVectorDrawer.Capacity) { motionVectorMatricesBuffer.Dispose(); motionVectorMatricesBuffer = new ComputeBuffer(MotionVectorDrawer.Capacity, sizeof(float3x4)); } MotionVectorDrawer.ExecuteBeforeFrame(motionVectorMatricesBuffer); data.buffer.SetGlobalBuffer(ShaderIDs._LastFrameModel, motionVectorMatricesBuffer); #if UNITY_EDITOR int tempID = Shader.PropertyToID("_TempRT"); foreach (var pair in bakeList) { PipelineCamera pipelineCam = pair.pipelineCamera; for (int i = 0; i < pair.worldToCamera.Length; ++i) { pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i]; pipelineCam.cam.projectionMatrix = pair.projection[i]; pipelineCam.cameraTarget = tempID; data.buffer.GetTemporaryRT(tempID, pair.texArray.width, pair.texArray.height, pair.texArray.depth, FilterMode.Point, pair.texArray.format, RenderTextureReadWrite.Linear); Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags); data.buffer.CopyTexture(tempID, 0, 0, pair.texArray, i, 0); data.buffer.ReleaseTemporaryRT(tempID); data.ExecuteCommandBuffer(); renderContext.Submit(); needSubmit = false; } pair.worldToCamera.Dispose(); pair.projection.Dispose(); renderContext.ExecuteCommandBuffer(pair.buffer); pair.buffer.Clear(); renderContext.Submit(); needSubmit = false; } bakeList.Clear(); #endif foreach (var cam in preFrameRenderCamera) { Render(cam, ref renderContext, cam.cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); renderContext.Submit(); needSubmit = false; } preFrameRenderCamera.Clear(); if (CustomDrawRequest.allEvents.Count > 0 || JobProcessEvent.allEvents.Count > 0) { foreach (var i in CustomDrawRequest.allEvents) { i.PrepareJob(resources); } foreach (var i in JobProcessEvent.allEvents) { i.PrepareJob(); } JobHandle.ScheduleBatchedJobs(); foreach (var i in CustomDrawRequest.allEvents) { i.FinishJob(); } foreach (var i in JobProcessEvent.allEvents) { i.FinishJob(); } } if (Application.isPlaying && resources.clusterResources) { resources.clusterResources.UpdateData(data.buffer, resources); } resources.loadingThread.Update(); if (useBeforeFrameBuffer) { renderContext.ExecuteCommandBuffer(m_beforeFrameBuffer); m_beforeFrameBuffer.Clear(); needSubmit = true; useBeforeFrameBuffer = false; } if (iRunnableObjects.isCreated) { foreach (var i in iRunnableObjects) { IPipelineRunnable func = MUnsafeUtility.GetObject <IPipelineRunnable>((void *)i.value); func.PipelineUpdate(ref data); } } if (cameras.Length > 0) { data.buffer.SetGlobalVector(ShaderIDs._SceneOffset, new float4(sceneOffset, 1)); } foreach (var cam in currentFrameCamera) { renderingEditor = cam.isRenderingEditor; Render(cam.pipeCam, ref renderContext, cam.cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); #if UNITY_EDITOR if (renderingEditor) { renderContext.DrawGizmos(cam.cam, GizmoSubset.PostImageEffects); ScriptableRenderContext.EmitWorldGeometryForSceneView(cam.cam); } #endif renderContext.Submit(); needSubmit = false; } if (useAfterFrameBuffer) { renderContext.ExecuteCommandBuffer(m_afterFrameBuffer); m_afterFrameBuffer.Clear(); needSubmit = true; useAfterFrameBuffer = false; } if (needSubmit) { renderContext.Submit(); } MotionVectorDrawer.ExecuteAfterFrame(); sceneOffset = 0; foreach (var cam in currentFrameCamera) { cam.pipeCam.cam = cam.cam; cam.pipeCam.AfterFrameRendering(); } }
protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { bool *propertyCheckedFlags = stackalloc bool[resources.allEvents.Length]; bool needSubmit = false; UnsafeUtility.MemClear(propertyCheckedFlags, resources.allEvents.Length); GraphicsSettings.useScriptableRenderPipelineBatching = resources.useSRPBatcher; SceneController.SetState(); data.context = renderContext; data.resources = resources; #if UNITY_EDITOR int tempID = Shader.PropertyToID("_TempRT"); foreach (var pair in bakeList) { PipelineCamera pipelineCam = pair.pipelineCamera; for (int i = 0; i < pair.worldToCamera.Length; ++i) { pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i]; pipelineCam.cam.projectionMatrix = pair.projection[i]; pipelineCam.cameraTarget = tempID; data.buffer.GetTemporaryRT(tempID, pair.texArray.width, pair.texArray.height, pair.texArray.depth, FilterMode.Point, pair.texArray.format, RenderTextureReadWrite.Linear); Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags); data.buffer.CopyTexture(tempID, 0, 0, pair.texArray, i, 0); data.buffer.ReleaseTemporaryRT(tempID); data.ExecuteCommandBuffer(); renderContext.Submit(); needSubmit = false; } pair.worldToCamera.Dispose(); pair.projection.Dispose(); renderContext.ExecuteCommandBuffer(pair.buffer); pair.buffer.Clear(); renderContext.Submit(); needSubmit = false; } bakeList.Clear(); #endif foreach (var cam in preFrameRenderCamera) { Render(cam, ref renderContext, cam.cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); renderContext.Submit(); needSubmit = false; } preFrameRenderCamera.Clear(); if (CustomDrawRequest.AllEvents.Count > 0 || JobProcessEvent.allEvents.Count > 0) { foreach (var i in CustomDrawRequest.AllEvents) { i.PrepareJob(resources); } foreach (var i in JobProcessEvent.allEvents) { i.PrepareJob(); } JobHandle.ScheduleBatchedJobs(); foreach (var i in CustomDrawRequest.AllEvents) { i.FinishJob(); } foreach (var i in JobProcessEvent.allEvents) { i.FinishJob(); } } if (useBeforeFrameBuffer) { renderContext.ExecuteCommandBuffer(m_beforeFrameBuffer); m_beforeFrameBuffer.Clear(); needSubmit = true; useBeforeFrameBuffer = false; } if (PipelineCamera.allCamera.isCreated) { foreach (var cam in cameras) { PipelineCamera pipelineCam; UIntPtr pipelineCamPtr; if (!PipelineCamera.allCamera.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr)) { #if UNITY_EDITOR renderingEditor = true; var pos = cam.transform.eulerAngles; pos.z = 0; cam.transform.eulerAngles = pos; if (!PipelineCamera.allCamera.Get(Camera.main.gameObject.GetInstanceID(), out pipelineCamPtr)) { continue; } #else continue; #endif } else { renderingEditor = false; } pipelineCam = MUnsafeUtility.GetObject <PipelineCamera>(pipelineCamPtr.ToPointer()); Render(pipelineCam, ref renderContext, cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); #if UNITY_EDITOR if (renderingEditor) { renderContext.DrawGizmos(cam, GizmoSubset.PostImageEffects); } #endif renderContext.Submit(); needSubmit = false; } } if (useAfterFrameBuffer) { renderContext.ExecuteCommandBuffer(m_afterFrameBuffer); m_afterFrameBuffer.Clear(); needSubmit = true; useAfterFrameBuffer = false; } if (needSubmit) { renderContext.Submit(); } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { DirLight(cam, ref data); PointLight(cam, ref data); data.ExecuteCommandBuffer(); }
protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { bool *propertyCheckedFlags = stackalloc bool[resources.allEvents.Length]; bool needSubmit = false; CustomDrawRequest.Initialize(); UnsafeUtility.MemClear(propertyCheckedFlags, resources.allEvents.Length); GraphicsSettings.useScriptableRenderPipelineBatching = resources.useSRPBatcher; SceneController.SetState(); data.context = renderContext; data.resources = resources; if (motionVectorMatricesBuffer == null || !motionVectorMatricesBuffer.IsValid()) { motionVectorMatricesBuffer = new ComputeBuffer(MotionVectorDrawer.Capacity, sizeof(float3x4)); } else if (motionVectorMatricesBuffer.count < MotionVectorDrawer.Capacity) { motionVectorMatricesBuffer.Dispose(); motionVectorMatricesBuffer = new ComputeBuffer(MotionVectorDrawer.Capacity, sizeof(float3x4)); } MotionVectorDrawer.ExecuteBeforeFrame(motionVectorMatricesBuffer); data.buffer.SetGlobalBuffer(ShaderIDs._LastFrameModel, motionVectorMatricesBuffer); #if UNITY_EDITOR int tempID = Shader.PropertyToID("_TempRT"); foreach (var pair in bakeList) { PipelineCamera pipelineCam = pair.pipelineCamera; for (int i = 0; i < pair.worldToCamera.Length; ++i) { pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i]; pipelineCam.cam.projectionMatrix = pair.projection[i]; pipelineCam.cameraTarget = tempID; data.buffer.GetTemporaryRT(tempID, pair.texArray.width, pair.texArray.height, pair.texArray.depth, FilterMode.Point, pair.texArray.format, RenderTextureReadWrite.Linear); Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags); data.buffer.CopyTexture(tempID, 0, 0, pair.texArray, i, 0); data.buffer.ReleaseTemporaryRT(tempID); data.ExecuteCommandBuffer(); renderContext.Submit(); needSubmit = false; } pair.worldToCamera.Dispose(); pair.projection.Dispose(); renderContext.ExecuteCommandBuffer(pair.buffer); pair.buffer.Clear(); renderContext.Submit(); needSubmit = false; } bakeList.Clear(); #endif foreach (var cam in preFrameRenderCamera) { Render(cam, ref renderContext, cam.cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); renderContext.Submit(); needSubmit = false; } preFrameRenderCamera.Clear(); if (CustomDrawRequest.allEvents.Count > 0 || JobProcessEvent.allEvents.Count > 0) { foreach (var i in CustomDrawRequest.allEvents) { i.PrepareJob(resources); } foreach (var i in JobProcessEvent.allEvents) { i.PrepareJob(); } JobHandle.ScheduleBatchedJobs(); foreach (var i in CustomDrawRequest.allEvents) { i.FinishJob(); } } if (useBeforeFrameBuffer) { renderContext.ExecuteCommandBuffer(m_beforeFrameBuffer); m_beforeFrameBuffer.Clear(); needSubmit = true; useBeforeFrameBuffer = false; } foreach (var cam in cameras) { PipelineCamera pipelineCam = cam.GetComponent <PipelineCamera>(); if (!pipelineCam) { #if UNITY_EDITOR if (cam.cameraType == CameraType.SceneView) { renderingEditor = true; var pos = cam.transform.eulerAngles; pos.z = 0; cam.transform.eulerAngles = pos; if (!Camera.main || !(pipelineCam = Camera.main.GetComponent <PipelineCamera>())) { continue; } } else if (cam.cameraType == CameraType.Game) { renderingEditor = false; pipelineCam = cam.gameObject.AddComponent <PipelineCamera>(); } else { continue; } #else renderingEditor = false; pipelineCam = cam.gameObject.AddComponent <PipelineCamera>(); #endif } else { renderingEditor = false; } Render(pipelineCam, ref renderContext, cam, propertyCheckedFlags); data.ExecuteCommandBuffer(); #if UNITY_EDITOR if (renderingEditor) { renderContext.DrawGizmos(cam, GizmoSubset.PostImageEffects); } #endif renderContext.Submit(); needSubmit = false; } if (useAfterFrameBuffer) { renderContext.ExecuteCommandBuffer(m_afterFrameBuffer); m_afterFrameBuffer.Clear(); needSubmit = true; useAfterFrameBuffer = false; } if (needSubmit) { renderContext.Submit(); } MotionVectorDrawer.ExecuteAfterFrame(); foreach (var i in JobProcessEvent.allEvents) { i.FinishJob(); } }