public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            storeDataHandler.Complete();
            int count = Mathf.Min(maximumProbe, reflectProbes.Length);

            reflectionEnabled = (count > 0);
            if (!reflectionEnabled)
            {
                return;
            }

            CommandBuffer      buffer        = data.buffer;
            ComputeShader      cullingShader = data.resources.shaders.reflectionCullingShader;
            ref CBDRSharedData cbdr          = ref lightingEvents.cbdr;
Exemplo n.º 2
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            RenderTargetIdentifier source, dest;

            PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest);
            data.buffer.BlitSRT(source, dest, ShaderIDs._DepthBufferTexture, lightingMaterial, 0);
            data.buffer.BlitSRT(source, dest, ShaderIDs._DepthBufferTexture, lightingMaterial, 1);
            //Calculate CBDR
            DirLight(cam, ref data);
            PointLight(cam, ref data);
            //Calculate Lighting
            data.buffer.BlitSRTWithDepth(cam.targets.renderTargetIdentifier, ShaderIDs._DepthBufferTexture, lightingMaterial, 2);
            LightFilter.Clear();
        }
Exemplo n.º 3
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            Graphics.SetRenderTarget(cam.depthTexture.colorBuffer, cam.renderTarget.depthBuffer);
            GL.Clear(true, true, Color.black);
            Shader.SetGlobalTexture(_CameraDepthTexture, cam.depthTexture);
            int childCount = transformParent.childCount;

            gbufferMaterial.SetPass(0);
            for (int i = 0; i < childCount; ++i)
            {
                Transform  tr     = transformParent.GetChild(i);
                MeshFilter filter = tr.GetComponent <MeshFilter>();
                Graphics.DrawMeshNow(filter.sharedMesh, tr.localToWorldMatrix);
            }
        }
Exemplo n.º 4
0
 public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data, CommandBuffer 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();
 }
        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
            };

            SceneController.DrawCluster(ref options, ref cam.targets, ref data, cam.cam);

            //   buffer.Blit(cam.targets.gbufferIdentifier[2], BuiltinRenderTextureType.CameraTarget);
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            handle.Complete();
            SkyboxPreviewMatrix last = IPerCameraData.GetProperty(camera, () => new SkyboxPreviewMatrix());

            buffer.SetGlobalMatrix(_InvSkyVP, job.invViewProj);
            buffer.SetGlobalMatrix(_LastSkyVP, last.lastViewProj);
            targetIdentifiers[0] = camera.targets.renderTargetIdentifier;
            targetIdentifiers[1] = ShaderIDs._CameraMotionVectorsTexture;
            buffer.SetRenderTarget(colors: targetIdentifiers, depth: ShaderIDs._DepthBufferTexture);
            buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0);
            last.lastViewProj = job.viewProj;
        }
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            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];
                block.SetVector(ShaderIDs._LightColor, light.color);
                block.SetVector(ShaderIDs._LightPos, new Vector4(light.position.x, light.position.y, light.position.z, light.range));
                block.SetFloat(ShaderIDs._LightIntensity, light.intensity);
                buffer.DrawProceduralIndirect(Matrix4x4.identity, pointLightMaterial, 0, MeshTopology.Triangles, sphereIndirectBuffer, 0, block);
            }
            //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, block, ref cubeBuffer, ref data.baseBuffer, cullShader, i, cubeDepthMaterial);
                    buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier);
                    block.Clear();
                    block.SetVector(ShaderIDs._LightColor, light.color);
                    block.SetVector(ShaderIDs._LightPos, positions[i]);
                    block.SetFloat(ShaderIDs._LightIntensity, light.intensity);
                    block.SetTexture(ShaderIDs._CubeShadowMap, light.shadowmapTexture);
                    buffer.DrawProceduralIndirect(Matrix4x4.identity, pointLightMaterial, 1, MeshTopology.Triangles, sphereIndirectBuffer, 0, block);
                }
                positions.Dispose();
            }
            //Shadow Point Light
            indicesArray.Dispose();
        }
Exemplo n.º 9
0
        private void PointLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            shadowCullHandle.Complete();
            CommandBuffer buffer = data.buffer;

            VoxelLightCommonData(buffer, cam.cam);
            lightingHandle.Complete();
            foreach (var i in addMLightCommandList)
            {
                MLight.AddMLight(i);
            }
            foreach (var i in needCheckedShadows)
            {
                MLight mlt = MUnsafeUtility.GetObject <MLight>(i.mlight.ToPointer());
                mlt.CheckShadowSetting(i.isAvaliable);
            }
            addMLightCommandList.Clear();
            int count = Mathf.Min(cubemapVPMatrices.Length, CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT);

            cbdr.pointshadowCount = count;
            //Calculate PointLight Shadow
            if (LightFilter.pointLightCount > 0)
            {
                if (count > 0)
                {
                    var cullShader = data.resources.shaders.gpuFrustumCulling;
                    buffer.SetGlobalTexture(ShaderIDs._CubeShadowMapArray, cbdr.cubeArrayMap);
                    NativeArray <VisibleLight> allLights     = proper.cullResults.visibleLights;
                    PointLightStruct *         pointLightPtr = pointLightArray.Ptr();

                    for (int i = 0; i < count; ++i)
                    {
                        ref CubemapViewProjMatrix vpMatrices = ref cubemapVPMatrices[i];
                        int2   lightIndex = vpMatrices.index;
                        Light  lt         = allLights[lightIndex.y].light;
                        MLight light      = MUnsafeUtility.GetObject <MLight>(vpMatrices.mLightPtr);
                        light.CheckShadowCamera();
                        ref PointLightStruct ptLitStr = ref pointLightPtr[lightIndex.x];
                        if (!light.useShadowCache || light.updateShadowCache)
                        {
                            light.updateShadowCache = false;
                            SceneController.DrawPointLight(light, localLightShadowLayer, ref ptLitStr, cubeDepthMaterial, buffer, cullShader, i, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap, cam.inverseRender, proper.overrideOpaqueMaterial);
                        }
                        ptLitStr.shadowIndex = light.ShadowIndex;
                        //TODO
                        //Multi frame shadowmap
                    }
                }
        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);
            PipelineFunctions.ReleaseRenderTarget(sharedData.temporalRT);
        }
Exemplo n.º 11
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            handle.Complete();
            lastViewProjection        = calculateJob.lastVP;
            inverseLastViewProjection = calculateJob.lastInverseVP;
            CommandBuffer buffer = data.buffer;

            buffer.SetKeyword("RENDERING_TEXTURE", cam.cam.targetTexture != null);
            buffer.SetGlobalMatrix(ShaderIDs._LastVp, lastViewProjection);
            buffer.SetGlobalMatrix(ShaderIDs._NonJitterVP, calculateJob.nonJitterVP);
            buffer.SetGlobalMatrix(ShaderIDs._NonJitterTextureVP, calculateJob.nonJitterTextureVP);
            buffer.SetGlobalMatrix(ShaderIDs._InvNonJitterVP, calculateJob.nonJitterInverseVP);
            buffer.SetGlobalMatrix(ShaderIDs._InvVP, inverseVP);
            buffer.SetGlobalVector(ShaderIDs._RandomSeed, calculateJob.randNumber);
            lastData.lastVP = calculateJob.nonJitterVP;
        }
 public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
 {
     //Press Space To Start Tracing
     if (pressSpace)
     {
         pressSpace = false;
         Matrix4x4 invvp = GL.GetGPUProjectionMatrix(cam.cam.projectionMatrix, true) * cam.cam.worldToCameraMatrix;
         invvp = invvp.inverse;
         traceMat.SetMatrix(ShaderIDs._InvVP, invvp);
         traceMat.SetTexture(ShaderIDs._EnvMap, environmentMap);
         Graphics.SetRenderTarget(cam.renderTarget);
         GL.Clear(true, true, Color.black);
         traceMat.SetPass(0);
         Graphics.DrawMeshNow(GraphicsUtility.mesh, Matrix4x4.identity);
     }
 }
Exemplo n.º 13
0
        public void PreRenderFrame(ref PipelineCommandData data)
        {
            if (IrradianceVolumeController.current == null)
            {
                return;
            }
            NativeList <LoadedIrradiance> allVolume = IrradianceVolumeController.current.loadedIrradiance;

            cullingResult = new NativeList <int>(allVolume.Length, Allocator.Temp);
            handle        = new IrradianceVolumeCulling
            {
                cameraFrustum = (float4 *)UnsafeUtility.AddressOf(ref data.frustumPlanes[0]),
                irradiance    = allVolume.unsafePtr,
                result        = cullingResult
            }.Schedule(allVolume.Length, 32);
        }
Exemplo n.º 14
0
 public void PreRender(ref PipelineCommandData data, PropertySetEvent proper)
 {
     if (!AreaVolumeProbe.allAreaLight.isCreated)
     {
         return;
     }
     areaCullResult = new NativeArray <AreaLight>(AreaVolumeProbe.allAreaLight.Length, Allocator.Temp);
     job            = new VolJob
     {
         count   = 0,
         light   = areaCullResult.Ptr(),
         allArea = AreaVolumeProbe.allAreaLight.unsafePtr,
         planes  = (float4 *)proper.frustumPlanes.Ptr()
     };
     jobHandle = job.ScheduleRefBurst(AreaVolumeProbe.allAreaLight.Length, 32);
 }
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (!enabledPost)
            {
                data.buffer.Blit(cam.targets.renderTargetIdentifier, cam.cameraTarget);
                return;
            }
#if UNITY_EDITOR
            if (!enableInEditor && RenderPipeline.renderingEditor)
            {
                data.buffer.Blit(cam.targets.renderTargetIdentifier, cam.cameraTarget);
                return;
            }
#endif
            postContext.camera              = cam.cam;
            postContext.command             = data.buffer;
            postContext.sourceFormat        = RenderTextureFormat.ARGBHalf;
            postContext.autoExposureTexture = RuntimeUtilities.whiteTexture;
            postContext.bloomBufferNameID   = -1;
            RenderTargetIdentifier source, dest;
            postContext.source      = cam.targets.renderTargetIdentifier;
            postContext.destination = cam.targets.backupIdentifier;
            postContext.logHistogram.Generate(postContext);
            foreach (var i in allPostEffects)
            {
                PostProcessEffectSettings setting;
                if (allSettings.TryGetValue(i.type, out setting))
                {
                    if (i.needBlit && setting.active)
                    {
                        PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest);
                        postContext.source      = source;
                        postContext.destination = dest;
                    }
                    i.renderer.SetSettings(setting);
                    i.renderer.Render(postContext);
                }
            }
            ;
            cyberColor.FrameUpdate(data.buffer);
            data.buffer.BlitSRT(cam.targets.renderTargetIdentifier, cam.cameraTarget, postContext.uberSheet.material, 0, postContext.uberSheet.properties);
            if (postContext.bloomBufferNameID > -1)
            {
                data.buffer.ReleaseTemporaryRT(postContext.bloomBufferNameID);
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            handle.Complete();
            kernelBuffer.SetData(kernel);
            kernel.Dispose();

            buffer.SetGlobalFloat(ShaderIDs._SSSScale, SubsurfaceScaler);
            buffer.SetGlobalBuffer(ShaderIDs._Kernel, kernelBuffer);
            RenderTargetIdentifier source, dest;

            PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest);
            buffer.BlitSRT(source, dest, ShaderIDs._DepthBufferTexture, mat, 0);
            PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest);
            buffer.BlitSRT(source, dest, ShaderIDs._DepthBufferTexture, mat, 1);
        }
Exemplo n.º 19
0
        private void DirLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (SunLight.current == null || !SunLight.current.enabled)
            {
                return;
            }
            cbdr.lightFlag |= 0b100;
            if (SunLight.current.enableShadow)
            {
                cbdr.lightFlag |= 0b010;
            }
            CommandBuffer buffer = data.buffer;

            if (SunLight.current.enableShadow)
            {
                RenderClusterOptions opts = new RenderClusterOptions
                {
                    frustumPlanes = shadowFrustumVP,
                    command       = buffer,
                    cullingShader = data.resources.shaders.gpuFrustumCulling,
                };
                buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(SunLight.current.firstLevelDistance,
                                                                                     SunLight.current.secondLevelDistance,
                                                                                     SunLight.current.thirdLevelDistance,
                                                                                     SunLight.current.farestDistance));//Only Mask
                buffer.SetGlobalVector(ShaderIDs._SoftParam, SunLight.current.cascadeSoftValue / SunLight.current.resolution);
                float *cascadeShadowmap = stackalloc float[4];
                cascadeShadowmap[0] = 0;
                float maxCascadeLevel = SunLight.CASCADELEVELCOUNT - 1;
                for (int i = 1; i < 4; ++i)
                {
                    cascadeShadowmap[i] = min(maxCascadeLevel, i);
                }
                buffer.SetGlobalVector(ShaderIDs._CascadeShadowWeight, *(float4 *)cascadeShadowmap);
                sunCullResultHandle.Complete();
                SceneController.DrawDirectionalShadow(cam, ref data, ref opts, clipDistances, sunShadowCams, cascadeShadowMapVP, proper.overrideOpaqueMaterial);
                buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP);
                buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.current.shadowmapTexture);
                cbdr.dirLightShadowmap = SunLight.current.shadowmapTexture;
                staticFit.frustumCorners.Dispose();
            }

            buffer.SetGlobalVector(ShaderIDs._DirLightFinalColor, SunLight.current.light.color * SunLight.current.light.intensity);
            buffer.SetGlobalVector(ShaderIDs._DirLightPos, -SunLight.current.transform.forward);
        }
Exemplo n.º 20
0
 public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
 {
     HistoryTexture.GetHistoryTexture getHis = new HistoryTexture.GetHistoryTexture
     {
         cam = cam.cam
     };
     texComponent = IPerCameraData.GetProperty <HistoryTexture, HistoryTexture.GetHistoryTexture>(cam, getHis);
     PreviousDepthData.GetPreviousDepthData getDepthData = new PreviousDepthData.GetPreviousDepthData
     {
         currentSize = new Vector2Int(cam.cam.pixelWidth, cam.cam.pixelHeight)
     };
     prevDepthData = IPerCameraData.GetProperty <PreviousDepthData, PreviousDepthData.GetPreviousDepthData>(cam, getDepthData);
     prevDepthData.targetObject = this;
     data.buffer.SetGlobalVector(ShaderIDs._LastJitter, texComponent.jitter);
     cam.cam.ResetProjectionMatrix();
     ConfigureJitteredProjectionMatrix(cam.cam, ref texComponent.jitter);
     data.buffer.SetGlobalVector(ShaderIDs._Jitter, texComponent.jitter);
 }
Exemplo n.º 21
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data, CommandBuffer buffer)
        {
            HistoryTexture texComponent = IPerCameraData.GetProperty <HistoryTexture>(cam, GetHistoryTex);

            texComponent.UpdateProperty(cam);
            SetHistory(cam.cam, buffer, ref texComponent.historyTex, cam.targets.renderTarget);
            historyTex = texComponent.historyTex;
            //TAA Start
            const float kMotionAmplification_Blending = 100f * 60f;
            const float kMotionAmplification_Bounding = 100f * 30f;

            block.SetVector(ShaderIDs._Jitter, jitter);
            block.SetFloat(ShaderIDs._Sharpness, sharpness);
            block.SetVector(ShaderIDs._TemporalClipBounding, new Vector4(stationaryAABBScale, motionAABBScale, kMotionAmplification_Bounding, 0f));
            block.SetVector(ShaderIDs._FinalBlendParameters, new Vector4(stationaryBlending, motionBlending, kMotionAmplification_Blending, 0f));
            block.SetTexture(ShaderIDs._HistoryTex, historyTex);
            PostFunctions.RunPostProcess(ref cam.targets, buffer, ref data, taaFunction);
        }
 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);
 }
Exemplo n.º 23
0
        private void DirLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (SunLight.current == null || !SunLight.current.enabled)
            {
                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
                };
                buffer.SetGlobalVector(ShaderIDs._NormalBiases, SunLight.current.normalBias);   //Only Depth
                buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(SunLight.current.firstLevelDistance,
                                                                                     SunLight.current.secondLevelDistance,
                                                                                     SunLight.current.thirdLevelDistance,
                                                                                     SunLight.current.farestDistance));//Only Mask
                buffer.SetGlobalVector(ShaderIDs._SoftParam, SunLight.current.cascadeSoftValue / SunLight.current.resolution);
                SceneController.DrawDirectionalShadow(cam.cam, ref data, ref opts, SunLight.current, cascadeShadowMapVP);
                buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP);
                buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.current.shadowmapTexture);
                cbdr.dirLightShadowmap = SunLight.current.shadowmapTexture;
                pass = 0;
            }
            else
            {
                pass = 1;
            }
            buffer.SetGlobalVector(ShaderIDs._DirLightFinalColor, SunLight.current.light.color * SunLight.current.light.intensity);
            buffer.SetGlobalVector(ShaderIDs._DirLightPos, -(Vector3)SunLight.current.shadCam.forward);
            buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier);
            buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, shadMaskMaterial, 0, pass);
        }
Exemplo n.º 24
0
        public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
        {
            var visLights = data.cullResults.visibleLights;

            LightFilter.allVisibleLight = visLights.Ptr();
            allLights.Clear();
            cbdr.UpdateFroxel(volumetricEvent && volumetricEvent.Enabled);
            foreach (var i in visLights)
            {
                allLights.Add(i.light);
            }
            addMLightCommandList.Clear();
            LightFilter.allMLightCommandList = addMLightCommandList;
            pointLightArray               = new NativeArray <PointLightStruct>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            spotLightArray                = new NativeArray <SpotLight>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            cubemapVPMatrices             = new NativeList <CubemapViewProjMatrix>(CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT, Allocator.Temp);
            spotLightMatrices             = new NativeList <SpotLightMatrix>(CBDRSharedData.MAXIMUMSPOTLIGHTCOUNT, Allocator.Temp);
            LightFilter.allLights         = allLights;
            LightFilter.pointLightArray   = pointLightArray;
            LightFilter.spotLightArray    = spotLightArray;
            LightFilter.cubemapVPMatrices = cubemapVPMatrices;
            LightFilter.spotLightMatrices = spotLightMatrices;
            lightingHandle                = (new LightFilter()).Schedule(allLights.Count, 1);
            if (SunLight.current != null && SunLight.current.enabled && SunLight.current.enableShadow)
            {
                clipDistances        = (float *)UnsafeUtility.Malloc(SunLight.CASCADECLIPSIZE * sizeof(float), 16, Allocator.Temp);
                staticFit            = DirectionalShadowStaticFit(cam.cam, SunLight.current, clipDistances);
                cascadeWorldToCamera = (float4x4 *)UnsafeUtility.Malloc(SunLight.CASCADELEVELCOUNT * sizeof(float4x4), 16, Allocator.Temp);
                cascadeProjection    = (float4x4 *)UnsafeUtility.Malloc(SunLight.CASCADELEVELCOUNT * sizeof(float4x4), 16, Allocator.Temp);
                PipelineFunctions.GetfrustumCorners(clipDistances, SunLight.CASCADELEVELCOUNT + 1, cam.cam, staticFit.frustumCorners.Ptr());
                csmStruct = new CascadeShadowmap
                {
                    cascadeShadowmapVPs  = (float4x4 *)cascadeShadowMapVP.Ptr(),
                    cascadeProjection    = cascadeProjection,
                    cascadeWorldToCamera = cascadeWorldToCamera,
                    orthoCam             = (OrthoCam *)UnsafeUtility.AddressOf(ref SunLight.current.shadCam),
                    farClipPlane         = SunLight.current.farestZ,
                    frustumCorners       = staticFit.frustumCorners.Ptr(),
                    resolution           = staticFit.resolution,
                    isD3D = GraphicsUtility.platformIsD3D
                };
                csmHandle = csmStruct.ScheduleRefBurst(SunLight.CASCADELEVELCOUNT, 1);
            }
        }
Exemplo n.º 25
0
        private void DirLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (SunLight.current == null || !SunLight.current.enabled)
            {
                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.shaders.gpuFrustumCulling,
                };
                buffer.SetGlobalVector(ShaderIDs._NormalBiases, SunLight.current.normalBias);   //Only Depth
                buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(SunLight.current.firstLevelDistance,
                                                                                     SunLight.current.secondLevelDistance,
                                                                                     SunLight.current.thirdLevelDistance,
                                                                                     SunLight.current.farestDistance));//Only Mask
                buffer.SetGlobalVector(ShaderIDs._SoftParam, SunLight.current.cascadeSoftValue / SunLight.current.resolution);
                csmHandle.Complete();
                SceneController.DrawDirectionalShadow(cam, ref staticFit, ref data, ref opts, clipDistances, cascadeWorldToCamera, cascadeProjection);
                buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP);
                buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.current.shadowmapTexture);
                cbdr.dirLightShadowmap = SunLight.current.shadowmapTexture;
                staticFit.frustumCorners.Dispose();
                pass = 0;
            }
            else
            {
                pass = 1;
            }
            buffer.SetGlobalVector(ShaderIDs._DirLightFinalColor, SunLight.current.light.color * SunLight.current.light.intensity);
            buffer.SetGlobalVector(ShaderIDs._DirLightPos, -(Vector3)SunLight.current.shadCam.forward);
        }
 public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
 {
     reflectProbes  = proper.cullResults.visibleReflectionProbes;
     reflectionData = new NativeArray <ReflectionData>(Mathf.Min(maximumProbe, reflectProbes.Length), Allocator.Temp, NativeArrayOptions.UninitializedMemory);
     storeRef       = new StoreReflectionData
     {
         data         = reflectionData.Ptr(),
         allProbes    = reflectProbes.Ptr(),
         count        = 0,
         camPos       = cam.cam.transform.position,
         dist         = availiableDistance,
         maximumProbe = maximumProbe
     };
     storeDataHandler = storeRef.ScheduleRefBurst(reflectProbes.Length, 32);
     if (ssrEvents.enabled && !RenderPipeline.renderingEditor)
     {
         ssrEvents.PreRender(cam);
     }
 }
 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);
     }
 }
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
#if UNITY_EDITOR
            if (!enableInEditor && RenderPipeline.renderingEditor)
            {
                data.buffer.Blit(cam.targets.renderTargetIdentifier, BuiltinRenderTextureType.CameraTarget);
                return;
            }
#endif
            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;
            postContext.source      = cam.targets.renderTargetIdentifier;
            postContext.destination = cam.targets.backupIdentifier;
            postContext.logHistogram.Generate(postContext);
            foreach (var i in settings)
            {
                PostEffect ef;
                if (allEvents.TryGetValue(i.GetType(), out ef))
                {
                    if (ef.needBlit && i.active)
                    {
                        PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest);
                        postContext.source      = source;
                        postContext.destination = dest;
                    }
                    ef.renderer.SetSettings(i);
                    ef.renderer.Render(postContext);
                }
            }
            ;
            // data.buffer.Blit(cam.targets.renderTargetIdentifier, BuiltinRenderTextureType.CameraTarget);
            data.buffer.BlitSRT(cam.targets.renderTargetIdentifier, BuiltinRenderTextureType.CameraTarget, postContext.uberSheet.material, 0, postContext.uberSheet.properties);
            if (postContext.bloomBufferNameID > -1)
            {
                data.buffer.ReleaseTemporaryRT(postContext.bloomBufferNameID);
            }
        }
Exemplo n.º 29
0
        public void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            handle.Complete();
            buffer.GetTemporaryRT(ShaderIDs._BackupAlbedoMap, cam.cam.pixelWidth, cam.cam.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, false);
            buffer.GetTemporaryRT(ShaderIDs._BackupNormalMap, cam.cam.pixelWidth, cam.cam.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear, 1, false);
            buffer.CopyTexture(cam.targets.gbufferIndex[2], 0, 0, ShaderIDs._BackupNormalMap, 0, 0);
            buffer.CopyTexture(cam.targets.gbufferIndex[0], 0, 0, ShaderIDs._BackupAlbedoMap, 0, 0);
            decalTargets[0] = cam.targets.gbufferIndex[0];
            decalTargets[1] = cam.targets.gbufferIndex[2];
            buffer.SetRenderTarget(colors: decalTargets, depth: ShaderIDs._DepthBufferTexture);
            DecalData *resulPtr = decalCullResults.Ptr();

            for (int i = 0; i < cullJob.count; ++i)
            {
                ref DecalData decal = ref resulPtr[i];
                DecalBase     dec   = MUnsafeUtility.GetObject <DecalBase>(decal.comp);
                dec.DrawDecal(buffer);
            }
 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();
     customRendererCulledResult = new NativeList <int>(CustomDrawRequest.AllEvents.Count, Unity.Collections.Allocator.Temp);
     cdrCullHandle = new CustomRendererCullJob
     {
         cullResult    = customRendererCulledResult,
         frustumPlanes = (float4 *)frustumPlanes.Ptr()
     }.Schedule(CustomDrawRequest.AllEvents.Count, 8);
 }