private void RenderScreenSpaceReflection(CommandBuffer SSGi_Buffer, PipelineCamera cam, ref RenderTargets targets) { Camera RenderCamera = cam.cam; SSGIData data = IPerCameraData.GetProperty(cam, (cc) => new SSGIData(int2(cc.cam.pixelWidth, cc.cam.pixelHeight))); data.UpdateResolution(int2(cam.cam.pixelWidth, cam.cam.pixelHeight)); //////Set HierarchicalDepthRT////// SSGi_Buffer.CopyTexture(ShaderIDs._CameraDepthTexture, 0, 0, data.SSGi_HierarchicalDepth_RT, 0, 0); for (int i = 1; i < HiZ_MaxLevel; ++i) { SSGi_Buffer.SetGlobalInt(SSGi_HiZ_PrevDepthLevel_ID, i - 1); SSGi_Buffer.SetRenderTarget(data.SSGi_HierarchicalDepth_BackUp_RT, i); SSGi_Buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, SSGi_Material, 0, RenderPass_HiZ_Depth); SSGi_Buffer.CopyTexture(data.SSGi_HierarchicalDepth_BackUp_RT, 0, i, data.SSGi_HierarchicalDepth_RT, 0, i); } SSGi_Buffer.SetGlobalTexture(SSGi_HierarchicalDepth_ID, data.SSGi_HierarchicalDepth_RT); SSGi_Buffer.GetTemporaryRT(SSGi_SceneColor_ID, RenderCamera.pixelWidth, RenderCamera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf); SSGi_Buffer.CopyTexture(targets.renderTargetIdentifier, 0, 0, SSGi_SceneColor_ID, 0, 0); //////RayCasting////// SSGi_Buffer.GetTemporaryRT(SSGi_Trace_ID, RenderCamera.pixelWidth, RenderCamera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf); SSGi_Buffer.BlitSRT(SSGi_Trace_ID, SSGi_Material, RenderPass_HiZ3D_MultiSpp); SSGi_Buffer.Blit(SSGi_Trace_ID, targets.renderTargetIdentifier); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { AOHistoryData historyData = IPerCameraData.GetProperty(cam, (c) => new AOHistoryData(c.cam.pixelWidth, c.cam.pixelHeight), this); UpdateVariable_SSAO(historyData, cam, ref data); RenderSSAO(historyData, cam, ref data); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { storeDataHandler.Complete(); reflectionCount = Mathf.Min(maximumProbe, storeRef.count); CommandBuffer buffer = data.buffer; ComputeShader cullingShader = data.resources.shaders.reflectionCullingShader; ref CBDRSharedData cbdr = ref lightingEvents.cbdr;
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; texComponent.UpdateProperty(cam); SetHistory(cam.cam, buffer, ref texComponent.historyTex, cam.targets.renderTargetIdentifier); RenderTexture 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); buffer.SetGlobalTexture(ShaderIDs._LastFrameDepthTexture, prevDepthData.SSR_PrevDepth_RT); buffer.SetGlobalTexture(ShaderIDs._LastFrameMotionVectors, texComponent.historyMV); buffer.SetGlobalMatrix(ShaderIDs._InvLastVp, proper.inverseLastViewProjection); RenderTargetIdentifier source, dest; PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest); buffer.BlitSRT(source, dest, ShaderIDs._DepthBufferTexture, taaMat, 0); buffer.CopyTexture(dest, historyTex); buffer.CopyTexture(ShaderIDs._CameraMotionVectorsTexture, texComponent.historyMV); prevDepthData.UpdateCameraSize(new Vector2Int(cam.cam.pixelWidth, cam.cam.pixelHeight)); buffer.CopyTexture(ShaderIDs._CameraDepthTexture, 0, 0, prevDepthData.SSR_PrevDepth_RT, 0, 0); }
private void Render(PipelineCamera pipelineCam, ref ScriptableRenderContext context, Camera cam, bool *pipelineChecked) { PipelineResources.CameraRenderingPath path = pipelineCam.renderingPath; currentPath = path; pipelineCam.cam = cam; pipelineCam.EnableThis(resources); if (!cam.TryGetCullingParameters(out data.cullParams)) { return; } context.SetupCameraProperties(cam); //Set Global Data data.context = context; data.cullParams.reflectionProbeSortingCriteria = ReflectionProbeSortingCriteria.ImportanceThenSize; data.cullResults = context.Cull(ref data.cullParams); 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); } var allEvents = resources.allEvents; var collect = allEvents[(int)path]; #if UNITY_EDITOR //Need only check for Unity Editor's bug! if (!pipelineChecked[(int)path]) { pipelineChecked[(int)path] = true; foreach (var e in collect) { if (!e.CheckProperty()) { e.CheckInit(resources); } } } #endif data.buffer.SetInvertCulling(pipelineCam.inverseRender); foreach (var e in collect) { if (e.Enabled) { e.PreRenderFrame(pipelineCam, ref data); } } JobHandle.ScheduleBatchedJobs(); foreach (var e in collect) { if (e.Enabled) { e.FrameUpdate(pipelineCam, ref data); } } data.buffer.SetInvertCulling(false); }
private void RenderSSAO(AOHistoryData historyData, PipelineCamera cam, ref PipelineCommandData data, int2 renderResolution, int2 originResolution) { CommandBuffer buffer = data.buffer; buffer.GetTemporaryRT(_GTAO_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear); buffer.GetTemporaryRT(_BentNormal_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); AO_BentNormal_ID[0] = _GTAO_Texture_ID; AO_BentNormal_ID[1] = _BentNormal_Texture_ID; //Resolve GTAO buffer.BlitMRT(AO_BentNormal_ID, _GTAO_Texture_ID, GTAOMaterial, 0); //Spatial filter //------//XBlur buffer.GetTemporaryRT(_GTAO_Spatial_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf); buffer.BlitSRT(_GTAO_Spatial_Texture_ID, GTAOMaterial, 1); //------//YBlur buffer.CopyTexture(_GTAO_Spatial_Texture_ID, AO_BentNormal_ID[0]); buffer.BlitSRT(_GTAO_Spatial_Texture_ID, GTAOMaterial, 2); buffer.GetTemporaryRT(_UpSampleRT, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf); buffer.BlitSRT(_UpSampleRT, GTAOMaterial, 4); //Temporal filter buffer.SetGlobalTexture(_PrevRT_ID, historyData.prev_Texture); buffer.GetTemporaryRT(_CurrRT_ID, originResolution.x, originResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf); buffer.BlitSRT(_CurrRT_ID, GTAOMaterial, 3); buffer.CopyTexture(_CurrRT_ID, historyData.prev_Texture); buffer.ReleaseTemporaryRT(_GTAO_Spatial_Texture_ID); buffer.ReleaseTemporaryRT(_CurrRT_ID); buffer.ReleaseTemporaryRT(_UpSampleRT); buffer.ReleaseTemporaryRT(_GTAO_Texture_ID); buffer.ReleaseTemporaryRT(_BentNormal_Texture_ID); buffer.SetGlobalTexture(ShaderIDs._AOROTexture, historyData.prev_Texture); // buffer.Blit(historyData.prev_Texture, BuiltinRenderTextureType.CameraTarget, debugMat, 0); }
public void Render(ref PipelineCommandData data, PipelineCamera cam, PropertySetEvent proper) { SSRCameraData cameraData = IPerCameraData.GetProperty(cam, getDataFunc); SSR_UpdateVariable(cameraData, cam.cam, ref data, proper); RenderScreenSpaceReflection(data.buffer, cameraData, cam); }
public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data) { float4x4 proj = GL.GetGPUProjectionMatrix(camera.cam.nonJitteredProjectionMatrix, false); float4x4 viewProj; if (camera.cam.orthographic) { OrthoCam cam = new OrthoCam { forward = camera.cam.transform.forward, up = camera.cam.transform.up, right = camera.cam.transform.right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } else { PerspCam cam = new PerspCam { forward = camera.cam.transform.forward, up = camera.cam.transform.up, right = camera.cam.transform.right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } CommandBuffer buffer = data.buffer; buffer.SetGlobalMatrix(_InvSkyVP, inverse(viewProj)); buffer.SetRenderTarget(color: camera.targets.renderTargetIdentifier, depth: ShaderIDs._DepthBufferTexture); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0); }
public void UpdateProperty(PipelineCamera camera) { int camWidth = camera.cam.pixelWidth; int camHeight = camera.cam.pixelHeight; Resize(historyTex, camWidth, camHeight); }
public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data, CommandBuffer buffer) { skyboxIdentifier[0] = camera.targets.renderTargetIdentifier; skyboxIdentifier[1] = camera.targets.motionVectorTexture; buffer.SetRenderTarget(camera.targets.renderTargetIdentifier, camera.targets.depthIdentifier); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { postContext.camera = cam.cam; postContext.command = data.buffer; postContext.sourceFormat = RenderTextureFormat.ARGBHalf; var settings = profile.settings; postContext.autoExposureTexture = RuntimeUtilities.whiteTexture; postContext.bloomBufferNameID = -1; data.buffer.SetGlobalTexture(UnityEngine.Rendering.PostProcessing.ShaderIDs.AutoExposureTex, postContext.autoExposureTexture); int source, dest; PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest); foreach (var i in settings) { PostProcessEffectRenderer renderer; if (allEvents.TryGetValue(i.GetType(), out renderer)) { postContext.source = source; postContext.destination = dest; renderer.SetSettings(i); renderer.Render(postContext); } } ; data.buffer.BlitSRT(source, dest, postContext.uberSheet.material, 0, postContext.uberSheet.properties); }
public void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { if (!Decal.decalDatas.isCreated) { return; } CommandBuffer buffer = data.buffer; handle.Complete(); DecalStrct *resulPtr = decalCullResults.Ptr(); if (cullJob.count > decalBuffer.count) { int oldCount = decalBuffer.count; decalBuffer.Dispose(); decalBuffer = new ComputeBuffer((int)max(oldCount * 1.5f, cullJob.count), sizeof(DecalStrct)); } decalBuffer.SetData(decalCullResults, 0, 0, cullJob.count); buffer.SetComputeTextureParam(cbdrShader, CBDRSharedData.DecalCull, ShaderIDs._XYPlaneTexture, lightingEvt.cbdr.xyPlaneTexture); buffer.SetComputeTextureParam(cbdrShader, CBDRSharedData.DecalCull, ShaderIDs._ZPlaneTexture, lightingEvt.cbdr.zPlaneTexture); buffer.SetComputeBufferParam(cbdrShader, CBDRSharedData.DecalCull, ShaderIDs._AllDecals, decalBuffer); buffer.SetComputeBufferParam(cbdrShader, CBDRSharedData.DecalCull, ShaderIDs._DecalIndexBuffer, decalIndexBuffer); buffer.SetComputeIntParam(cbdrShader, ShaderIDs._DecalCount, cullJob.count); buffer.DispatchCompute(cbdrShader, CBDRSharedData.DecalCull, 1, 1, CBDRSharedData.ZRES); buffer.SetGlobalTexture(ShaderIDs._DecalAtlas, decalAlbedoAtlas); buffer.SetGlobalTexture(ShaderIDs._DecalNormalAtlas, decalNormalAtlas); buffer.SetGlobalBuffer(ShaderIDs._DecalIndexBuffer, decalIndexBuffer); buffer.SetGlobalBuffer(ShaderIDs._AllDecals, decalBuffer); decalCullResults.Dispose(); decalCompareResults.Dispose(); }
public void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data) { if (!Decal.decalDatas.isCreated) { return; } decalCullResults = new NativeArray <DecalStrct>(Decal.allDecalCount, Allocator.Temp); decalCompareResults = new NativeArray <DecalIndexCompare>(Decal.allDecalCount, Allocator.Temp); float2 albedoSize; float2 normalSize; cullJob = new DecalCullJob { count = 0, decalDatas = decalCullResults.Ptr(), frustumPlanes = (float4 *)proper.frustumPlanes.Ptr(), availiableDistanceSqr = lightingEvt.cbdrDistance * lightingEvt.cbdrDistance, camPos = cam.cam.transform.position, indexCompares = decalCompareResults.Ptr(), allDatas = Decal.decalDatas.unsafePtr, albedoAtlasSize = atlasWidth, normalAtlasSize = atlasHeight, }; handle = cullJob.ScheduleRefBurst(Decal.allDecalCount, 32); handle = new DecalSortJob { compares = decalCompareResults.Ptr(), count = cullJob.count.Ptr(), decalDatas = decalCullResults.Ptr(), }.Schedule(handle); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (current != this) { return; } current = null; data.buffer.Dispose(); var allEvents = resources.allEvents; foreach (var i in allEvents) { if (i != null) { foreach (var j in i) { j.DisposeEvent(); } } } foreach (var i in PipelineCamera.allCamera) { PipelineCamera cam = MUnsafeUtility.GetObject <PipelineCamera>(i.ToPointer()); var values = cam.allDatas.Values; foreach (var j in values) { j.DisposeProperty(); } cam.allDatas.Clear(); } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { ScriptableCullingParameters cullParams; if (!cam.cam.TryGetCullingParameters(out cullParams)) { return; } cullParams.cullingOptions = cam.cam.useOcclusionCulling ? CullingOptions.OcclusionCull: CullingOptions.None; CullingResults cullReslt = data.context.Cull(ref cullParams); data.buffer.GetTemporaryRT(ShaderIDs._DepthBufferTexture, cam.cam.pixelWidth, cam.cam.pixelHeight, 32, FilterMode.Bilinear, RenderTextureFormat.Depth, RenderTextureReadWrite.Linear); data.buffer.SetRenderTarget(ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(true, false, Color.black); FilteringSettings filterSettings = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = RenderQueueRange.opaque }; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId(passName), new SortingSettings(cam.cam) { criteria = SortingCriteria.CommonOpaque }) { perObjectData = UnityEngine.Rendering.PerObjectData.None }; SceneController.RenderScene(ref data, ref filterSettings, ref drawSettings, ref cullReslt); data.buffer.Blit(ShaderIDs._DepthBufferTexture, cam.cameraTarget); data.buffer.ReleaseTemporaryRT(ShaderIDs._DepthBufferTexture); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { ScriptableCullingParameters cullParams; if (!cam.cam.TryGetCullingParameters(out cullParams)) { return; } cullParams.cullingOptions = cam.cam.useOcclusionCulling ? CullingOptions.OcclusionCull: CullingOptions.None; CullingResults cullReslt = data.context.Cull(ref cullParams); data.buffer.SetRenderTarget(cam.cameraTarget); data.buffer.ClearRenderTarget(true, true, new Color(float.MaxValue, float.MaxValue, float.MaxValue, float.MaxValue)); FilteringSettings filterSettings = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = RenderQueueRange.opaque }; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam.cam) { criteria = SortingCriteria.CommonOpaque }) { perObjectData = UnityEngine.Rendering.PerObjectData.Lightmaps }; SceneController.RenderScene(ref data, ref filterSettings, ref drawSettings, ref cullReslt); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { postContext.camera = cam.cam; postContext.command = data.buffer; postContext.bloomBufferNameID = -1; postContext.sourceFormat = RenderTextureFormat.ARGBHalf; var settings = profile.settings; postContext.autoExposureTexture = RuntimeUtilities.whiteTexture; postContext.bloomBufferNameID = -1; RenderTargetIdentifier source, dest; PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest); postContext.source = source; postContext.destination = dest; postContext.logHistogram.Generate(postContext); foreach (var i in settings) { PostProcessEffectRenderer renderer; if (allEvents.TryGetValue(i.GetType(), out renderer)) { renderer.SetSettings(i); renderer.Render(postContext); } } ; data.buffer.BlitSRT(source, dest, postContext.uberSheet.material, 0, postContext.uberSheet.properties); if (postContext.bloomBufferNameID > -1) { data.buffer.ReleaseTemporaryRT(postContext.bloomBufferNameID); } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; if (enableOcclusionCulling) { if (SceneController.gpurpEnabled) { buffer.SetRenderTarget(hizDepth.backupMip); buffer.ClearRenderTarget(true, true, Color.white); if (OccluderDrawer.current) { OccluderDrawer.current.Drawer(buffer, linearDrawerMat, data.frustumPlanes); } } SceneController.DrawClusterOccDoubleCheck(ref options, ref cam.targets, ref data, ref hizDepth, linearMat, cam.cam); } else { SceneController.DrawCluster(ref options, ref cam.targets, ref data, cam.cam); } }
public void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data) { if (!Decal.decalDatas.isCreated) { return; } decalCullResults = new NativeArray <DecalStrct>(Decal.allDecalCount, Allocator.Temp); decalCompareResults = new NativeArray <DecalIndexCompare>(Decal.allDecalCount, Allocator.Temp); cullJob = new DecalCullJob { count = 0, decalDatas = decalCullResults.Ptr(), frustumPlanes = (float4 *)proper.frustumPlanes.Ptr(), availiableDistanceSqr = lightingEvt.cbdrDistance * lightingEvt.cbdrDistance, camPos = cam.cam.transform.position, allDatas = Decal.decalDatas.unsafePtr, camMinPos = cam.frustumMinPoint, camMaxPos = cam.frustumMaxPoint }; cullJob.indexCompares = decalCompareResults.Ptr(); handle = cullJob.ScheduleRefBurst(Decal.allDecalCount, max(1, Decal.allDecalCount / 4)); sortJob.compares = decalCompareResults.Ptr(); sortJob.count = cullJob.count.Ptr(); sortJob.decalDatas = decalCullResults.Ptr(); handle = sortJob.Schedule(handle); }
private void DirLight(PipelineCamera cam, ref PipelineCommandData data) { PipelineBaseBuffer baseBuffer; if (SunLight.current == null || !SunLight.current.enabled || !SceneController.GetBaseBuffer(out baseBuffer)) { return; } cbdr.lightFlag |= 0b100; if (SunLight.current.enableShadow) { cbdr.lightFlag |= 0b010; } CommandBuffer buffer = data.buffer; int pass; if (SunLight.current.enableShadow) { RenderClusterOptions opts = new RenderClusterOptions { frustumPlanes = shadowFrustumVP, command = buffer, cullingShader = data.resources.gpuFrustumCulling, isOrtho = true }; ref ShadowmapSettings settings = ref SunLight.current.settings; buffer.SetGlobalVector(ShaderIDs._NormalBiases, settings.normalBias); //Only Depth buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(settings.firstLevelDistance, settings.secondLevelDistance, settings.thirdLevelDistance, settings.farestDistance)); //Only Mask buffer.SetGlobalVector(ShaderIDs._SoftParam, settings.cascadeSoftValue / settings.resolution); SceneController.current.DrawDirectionalShadow(cam.cam, ref opts, ref SunLight.current.settings, ref SunLight.shadMap, cascadeShadowMapVP); buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP); buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.shadMap.shadowmapTexture); cbdr.dirLightShadowmap = SunLight.shadMap.shadowmapTexture; pass = 0; }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; LastVPData lastData = IPerCameraData.GetProperty <LastVPData>(cam, getLastVP); //Calculate Last VP for motion vector and Temporal AA Matrix4x4 nonJitterVP = GL.GetGPUProjectionMatrix(cam.cam.nonJitteredProjectionMatrix, false) * cam.cam.worldToCameraMatrix; ref Matrix4x4 lastVp = ref lastData.lastVP;
private void InitBake() { GameObject obj = new GameObject("BakeCam", typeof(Camera), typeof(PipelineCamera)); bakeCamera = obj.GetComponent <PipelineCamera>(); bakeCamera.cam = obj.GetComponent <Camera>(); bakeCamera.cam.enabled = false; bakeCamera.renderingPath = PipelineResources.CameraRenderingPath.Unlit; bakeCamera.inverseRender = true; readBackAction = ReadBack; finalData = new NativeList <float3x3>(resolution.x * resolution.y * resolution.z + 1024, Allocator.Persistent); cameraTarget = new RenderTexture(new RenderTextureDescriptor { msaaSamples = 1, width = 1024, height = 1024, depthBufferBits = 32, colorFormat = RenderTextureFormat.RFloat, dimension = TextureDimension.Cube, volumeDepth = 1 }); buffer = new CommandBuffer(); occlusionBuffer = new ComputeBuffer(1024 * 1024, sizeof(float3x3)); finalBuffer = new ComputeBuffer(1024, sizeof(float3x3)); }
protected override void Dispose(bool disposing) { eventsGuideBook.Dispose(); waitReleaseRT.Dispose(); base.Dispose(disposing); if (current == this) { current = null; } data.buffer.Dispose(); var allEvents = resources.allEvents; for (int i = 0; i < resources.availiableEvents.Length; ++i) { resources.availiableEvents[i].DisposeEvent(); } for (int i = 0; i < resources.availiableEvents.Length; ++i) { resources.availiableEvents[i].DisposeDependEventsList(); } if (PipelineCamera.allCamera.isCreated) { foreach (var i in PipelineCamera.allCamera) { PipelineCamera cam = MUnsafeUtility.GetObject <PipelineCamera>(i.value.ToPointer()); var values = cam.allDatas.Values; foreach (var j in values) { j.DisposeProperty(); } cam.allDatas.Clear(); } } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { if (SunLight.current == null) { return; } CommandBuffer buffer = data.buffer; int pass; lightBlock.Clear(); if (SunLight.current.enableShadow) { PipelineFunctions.UpdateShadowMapState(ref SunLight.shadMap, lightBlock, 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(lightBlock, ref SunLight.shadMap, cascadeShadowMapVP); pass = 0; } else { pass = 1; } lightBlock.SetVector(ShaderIDs._LightFinalColor, SunLight.shadMap.light.color * SunLight.shadMap.light.intensity); buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); lightBlock.SetVector(ShaderIDs._LightPos, -SunLight.shadMap.shadCam.forward); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, shadMaskMaterial, 0, pass, lightBlock); }
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); HizOcclusionData hizData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData()); RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; if (enableOcclusionCulling) { HizOptions hizOptions; hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat, currentDepthTex = cam.targets.depthIdentifier }; SceneController.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets, ref data, cam.cam); } else { SceneController.DrawCluster(ref options, ref cam.targets, ref data, cam.cam); } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (current == this) { current = null; } iRunnableObjects.Dispose(); CustomDrawRequest.Dispose(); if (m_afterFrameBuffer != null) { m_afterFrameBuffer.Dispose(); m_afterFrameBuffer = null; } if (m_beforeFrameBuffer != null) { m_beforeFrameBuffer.Dispose(); m_beforeFrameBuffer = null; } try { eventsGuideBook.Dispose(); waitReleaseRT.Dispose(); } catch { } SceneController.Dispose(resources); resources.loadingThread.Dispose(); data.buffer.Dispose(); var allEvents = resources.allEvents; for (int i = 0; i < resources.availiableEvents.Length; ++i) { resources.availiableEvents[i].DisposeEvent(); } for (int i = 0; i < resources.availiableEvents.Length; ++i) { resources.availiableEvents[i].DisposeDependEventsList(); } foreach (var camPtr in PipelineCamera.CameraSearchDict) { PipelineCamera cam = MUnsafeUtility.GetObject <PipelineCamera>((void *)camPtr.value); if (cam.allDatas.isCreated) { foreach (var i in cam.allDatas) { IPerCameraData data = ((IPerCameraData)MUnsafeUtility.GetHookedObject(i.value)); data.DisposeProperty(); MUnsafeUtility.RemoveHookedObject(i.value); } cam.allDatas.Dispose(); } } if (motionVectorMatricesBuffer != null) { motionVectorMatricesBuffer.Dispose(); } MotionVectorDrawer.Dispose(); }
private void RenderSSAO(AOHistoryData historyData, PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; int2 renderResolution = int2(cam.cam.pixelWidth, cam.cam.pixelHeight); buffer.GetTemporaryRT(_GTAO_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear); buffer.GetTemporaryRT(_BentNormal_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); AO_BentNormal_ID[0] = _GTAO_Texture_ID; AO_BentNormal_ID[1] = _BentNormal_Texture_ID; //Resolve GTAO buffer.BlitMRT(AO_BentNormal_ID, cam.targets.renderTargetIdentifier, GTAOMaterial, 0); //Spatial filter //------//XBlur buffer.GetTemporaryRT(_GTAO_Spatial_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf); buffer.BlitSRTWithDepth(_GTAO_Spatial_Texture_ID, cam.targets.depthBuffer, GTAOMaterial, 1); //------//YBlur buffer.CopyTexture(_GTAO_Spatial_Texture_ID, AO_BentNormal_ID[0]); buffer.BlitSRTWithDepth(_GTAO_Spatial_Texture_ID, cam.targets.depthBuffer, GTAOMaterial, 2); //Temporal filter buffer.SetGlobalTexture(_PrevRT_ID, historyData.prev_Texture); buffer.GetTemporaryRT(_CurrRT_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf); buffer.BlitSRTWithDepth(_CurrRT_ID, cam.targets.depthBuffer, GTAOMaterial, 3); buffer.CopyTexture(_CurrRT_ID, historyData.prev_Texture); buffer.ReleaseTemporaryRT(_GTAO_Spatial_Texture_ID); buffer.ReleaseTemporaryRT(_CurrRT_ID); buffer.ReleaseTemporaryRT(_Combien_AO_RT_ID); buffer.ReleaseTemporaryRT(_GTAO_Texture_ID); buffer.ReleaseTemporaryRT(_BentNormal_Texture_ID); buffer.SetGlobalTexture(ShaderIDs._AOROTexture, historyData.prev_Texture); }
public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data) { reflectProbes = proper.cullResults.visibleReflectionProbes; reflectionData = new NativeArray <ReflectionData>(reflectProbes.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory); storeRef = new StoreReflectionData { data = reflectionData.Ptr(), allProbes = reflectProbes.Ptr(), count = reflectProbes.Length, camPos = cam.cam.transform.position, dist = availiableDistance, localToWorldMat = MUnsafeUtility.Malloc <Matrix4x4>(sizeof(Matrix4x4) * reflectProbes.Length, Allocator.Temp) }; storeDataHandler = storeRef.ScheduleRefBurst(); if (ssrEvents.enabled && !RenderPipeline.renderingEditor) { ssrEvents.PreRender(cam); } if (!preintDefaultRT) { preintDefaultRT = new RenderTexture(512, 512, 0, RenderTextureFormat.RG16, RenderTextureReadWrite.Linear); preintDefaultRT.filterMode = FilterMode.Bilinear; preintDefaultRT.Create(); data.buffer.BlitSRT(preintDefaultRT, preintMat, 0); } }
public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; buffer.SetRenderTarget(color: camera.targets.renderTargetIdentifier, depth: camera.targets.depthBuffer); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0); }
public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data) { if (!cam.cam.TryGetCullingParameters(out cullParams)) { return; } data.buffer.SetInvertCulling(cam.inverseRender); cullParams.reflectionProbeSortingCriteria = ReflectionProbeSortingCriteria.ImportanceThenSize; cullParams.cullingOptions = CullingOptions.NeedsLighting | CullingOptions.NeedsReflectionProbes; if (cam.cam.useOcclusionCulling) { cullParams.cullingOptions |= CullingOptions.OcclusionCull; } cullResults = data.context.Cull(ref cullParams); for (int i = 0; i < frustumPlanes.Length; ++i) { Plane p = cullParams.GetCullingPlane(i); //GPU Driven RP's frustum plane is inverse from SRP's frustum plane frustumPlanes[i] = new Vector4(-p.normal.x, -p.normal.y, -p.normal.z, -p.distance); } PipelineFunctions.InitRenderTarget(ref cam.targets, cam.cam, data.buffer); lastData = IPerCameraData.GetProperty(cam, getLastVP); calculateJob = new CalculateMatrixJob { isD3D = GraphicsUtility.platformIsD3D, nonJitterP = cam.cam.nonJitteredProjectionMatrix, worldToView = cam.cam.worldToCameraMatrix, lastVP = lastData.lastVP, rand = (Random *)UnsafeUtility.AddressOf(ref rand), p = cam.cam.projectionMatrix, VP = (float4x4 *)UnsafeUtility.AddressOf(ref VP), inverseVP = (float4x4 *)UnsafeUtility.AddressOf(ref inverseVP) }; handle = calculateJob.ScheduleRefBurst(); }