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 DrawClusterOccDoubleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts, ref RenderTargets rendTargets)
        {
            CommandBuffer buffer           = options.command;
            ComputeShader gpuFrustumShader = options.cullingShader;

            PipelineFunctions.UpdateOcclusionBuffer(
                baseBuffer, gpuFrustumShader,
                buffer,
                hizOpts.hizData,
                options.frustumPlanes,
                options.isOrtho);
            //绘制第一次剔除结果
            PipelineFunctions.DrawLastFrameCullResult(baseBuffer, buffer, options.proceduralMaterial);
            //更新Vector,Depth Mip Map
            hizOpts.hizData.lastFrameCameraUp = hizOpts.currentCameraUpVec;
            PipelineFunctions.ClearOcclusionData(baseBuffer, buffer, gpuFrustumShader);
            //TODO 绘制其他物体

            //TODO
            buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0);
            hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer);
            //使用新数据进行二次剔除
            PipelineFunctions.OcclusionRecheck(baseBuffer, gpuFrustumShader, buffer, hizOpts.hizData);
            //绘制二次剔除结果
            buffer.SetRenderTarget(rendTargets.gbufferIdentifier, rendTargets.depthIdentifier);
            PipelineFunctions.DrawRecheckCullResult(baseBuffer, options.proceduralMaterial, buffer);
            buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0);
            hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer);
        }
Ejemplo n.º 3
0
        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);
            }
        }
        private void Awake()
        {
            if (initialized)
            {
                Debug.LogError("Should Be Singleton!");
                Destroy(gameObject);
                return;
            }
            initialized      = true;
            nullValue        = current;
            current          = this;
            baseBuffer       = new PipelineBaseBuffer();
            clusterResources = Resources.Load <ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;

            allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i.name, i.clusterCount));
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterResources, mapResources, clusterCount);
            SceneStreaming.pointerContainer = new NativeList <ulong>(clusterCount, Allocator.Persistent);
            SceneStreaming.commandQueue     = new LoadingCommandQueue();
        }
        private void PointLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            VoxelLightCommonData(buffer, cam.cam);
            lightingHandle.Complete();
            foreach (var i in addMLightCommandList)
            {
                MLight.AddMLight(i);
            }
            addMLightCommandList.Clear();
            int count = Mathf.Min(cubemapVPMatrices.Length, CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT);

            cbdr.pointshadowCount = count;
            if (LightFilter.pointLightCount > 0)
            {
                if (count > 0)
                {
                    var cullShader = data.resources.shaders.gpuFrustumCulling;
                    buffer.SetGlobalTexture(ShaderIDs._CubeShadowMapArray, cbdr.cubeArrayMap);
                    NativeArray <VisibleLight> allLights     = data.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);
                        if (light.useShadowCache)
                        {
                            light.UpdateShadowCacheType(true);
                            if (light.updateShadowCache)
                            {
                                light.updateShadowCache = false;
                                SceneController.DrawPointLight(light, shadowLayer, ref pointLightPtr[lightIndex.x], cubeDepthMaterial, buffer, cullShader, i, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap, cam.inverseRender);
                                int offset = i * 6;
                                for (int a = 0; a < 6; ++a)
                                {
                                    buffer.CopyTexture(cbdr.cubeArrayMap, offset + a, light.shadowMap, a);
                                }
                            }
                            else
                            {
                                PipelineFunctions.CopyToCubeMap(cbdr.cubeArrayMap, light.shadowMap, buffer, i);
                            }
                        }
                        else
                        {
                            SceneController.DrawPointLight(light, shadowLayer, ref pointLightPtr[lightIndex.x], cubeDepthMaterial, buffer, cullShader, i, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap, cam.inverseRender);
                        }

                        //TODO
                        //Multi frame shadowmap
                    }
                }
                SetPointLightBuffer(pointLightArray, LightFilter.pointLightCount);
                buffer.EnableShaderKeyword("POINTLIGHT");
                cbdr.lightFlag |= 1;
            }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        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);
        }
 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();
 }
        private void Awake()
        {
            if (singleton)
            {
                Debug.LogError("Render Pipeline should be Singleton!");
                DestroyImmediate(gameObject);
                return;
            }
            data.buffer = new CommandBuffer();
            DontDestroyOnLoad(this);
            singleton            = this;
            data.arrayCollection = new RenderArray(true);
            clusterResources     = Resources.Load <ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;

            allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i.name, i.clusterCount));
            }
            PipelineFunctions.InitBaseBuffer(ref data.baseBuffer, clusterResources, mapResources, clusterCount);
            allEvents = new List <PipelineEvent>(GetComponentsInChildren <PipelineEvent>());
            foreach (var i in allEvents)
            {
                i.InitEvent(resources);
            }
            SceneStreaming.pointerContainer = new NativeList <ulong>(clusterCount, Allocator.Persistent);
            SceneStreaming.commandQueue     = new LoadingCommandQueue();
        }
 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);
         renderContext.Submit();
     }
     foreach (var i in afterRenderFrame)
     {
         i.func(i.obj);
     }
     afterRenderFrame.Clear();
 }
Ejemplo n.º 12
0
 public static void Dispose()
 {
     singletonReady = false;
     PipelineFunctions.Dispose(baseBuffer);
     pointerContainer.Dispose();
     commandQueue = null;
     commonData.avaiableProperties.Dispose();
     commonData.avaiableTexs.Dispose();
     commonData.avaiableLightmap.Dispose();
     commonData.texCopyBuffer.Dispose();
     commonData.lightmapCopyBuffer.Dispose();
     commonData.propertyBuffer.Dispose();
     commonData.texDict.Clear();
     commonData.lightmapDict.Clear();
     commonData.terrainDrawStreaming.Dispose();
     UnityEngine.Object.DestroyImmediate(commonData.terrainMaterial);
     UnityEngine.Object.DestroyImmediate(commonData.terrainMaterial);
     UnityEngine.Object.DestroyImmediate(commonData.lightmapArray);
     UnityEngine.Object.DestroyImmediate(commonData.texArray);
     addList.Dispose();
     foreach (var i in commonData.allTempBuffers.Values)
     {
         i.Dispose();
     }
 }
        public static void Awake(PipelineResources resources, int resolution, int texArrayCapacity, int propertyCapacity, string mapResources)
        {
            SceneController.resolution = resolution;
            singletonReady = true;
            SceneController.resources = resources;
            addList = new NativeList<ulong>(10, Allocator.Persistent);
            baseBuffer = new PipelineBaseBuffer();
            clusterResources = Resources.Load<ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;
            allScenes = new List<SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i));
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterResources, mapResources, clusterCount);
            pointerContainer = new NativeList<ulong>(clusterCount, Allocator.Persistent);
            commandQueue = new LoadingCommandQueue();
            RenderTextureDescriptor desc = new RenderTextureDescriptor
            {
                autoGenerateMips = false,
                bindMS = false,
                colorFormat = RenderTextureFormat.ARGB32,
                depthBufferBits = 0,
                dimension = TextureDimension.Tex2DArray,
                enableRandomWrite = false,
                height = resolution,
                width = resolution,
                memoryless = RenderTextureMemoryless.None,
                msaaSamples = 1,
                vrUsage = VRTextureUsage.None,
                volumeDepth = texArrayCapacity,
                shadowSamplingMode = ShadowSamplingMode.None,
                sRGB = false,
                useMipMap = false
            };
            commonData = new SceneCommonData
            {
                texDict = new Dictionary<string, SceneCommonData.TextureIdentifier>(),
                avaiableProperties = new NativeList<int>(propertyCapacity, Allocator.Persistent),
                avaiableTexs = new NativeList<int>(texArrayCapacity, Allocator.Persistent),
                texCopyBuffer = new ComputeBuffer(resolution * resolution, sizeof(int)),
                propertyBuffer = new ComputeBuffer(propertyCapacity, sizeof(PropertyValue)),
                copyTextureMat = new Material(resources.shaders.copyShader),
                texArray = new RenderTexture(desc),
                clusterMaterial = new Material(resources.shaders.clusterRenderShader),
                terrainMaterial = new Material(resources.shaders.terrainShader),
                terrainDrawStreaming = new TerrainDrawStreaming(100, 16, resources.shaders.terrainCompute)
            };

            for (int i = 0; i < propertyCapacity; ++i)
            {
                commonData.avaiableProperties.Add(i);
            }
            for (int i = 0; i < texArrayCapacity; ++i)
            {
                commonData.avaiableTexs.Add(i);
            }
        }
        public void Render(CameraRenderingPath path, PipelineCamera pipelineCam, RenderTexture dest)
        {
            //Set Global Data
            Camera cam = pipelineCam.cam;

            data.resources = resources;
            PipelineFunctions.GetViewProjectMatrix(cam, out data.vp, out data.inverseVP);
            ref RenderArray arr = ref data.arrayCollection;
        public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (SunLight.current && SunLight.current.enabled && SunLight.current.gameObject.activeSelf)
            {
                data.buffer.EnableShaderKeyword("ENABLE_SUN");
                data.buffer.SetKeyword("ENABLE_SUNSHADOW", SunLight.current.enableShadow);
            }
            else
            {
                data.buffer.DisableShaderKeyword("ENABLE_SUN");
            }
            var visLights = data.cullResults.visibleLights;

            LightFilter.allVisibleLight = visLights.Ptr();
            allLights.Clear();
            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;
            Transform camTrans = cam.cam.transform;

            lightingHandle = (new LightFilter {
                camPos = cam.cam.transform.position,
                lightDist = localLightDistance
            }).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);
                sunShadowCams = MUnsafeUtility.Malloc <OrthoCam>(SunLight.CASCADELEVELCOUNT * sizeof(OrthoCam), Allocator.Temp);
                Matrix4x4 proj = cam.cam.projectionMatrix;
                cam.cam.projectionMatrix = cam.cam.nonJitteredProjectionMatrix;
                PipelineFunctions.GetfrustumCorners(clipDistances, SunLight.CASCADELEVELCOUNT + 1, cam.cam, staticFit.frustumCorners.Ptr());
                cam.cam.projectionMatrix = proj;
                csmStruct = new CascadeShadowmap
                {
                    cascadeShadowmapVPs = (float4x4 *)cascadeShadowMapVP.Ptr(),
                    results             = sunShadowCams,
                    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);
            }
        }
        public override void DrawCluster(ref RenderClusterOptions options)
        {
            PipelineFunctions.SetBaseBuffer(baseBuffer, options.cullingShader, options.frustumPlanes, options.command);
            PipelineFunctions.RunCullDispatching(baseBuffer, options.cullingShader, options.isOrtho, options.command);
            PipelineFunctions.RenderProceduralCommand(baseBuffer, options.proceduralMaterial, options.command);
            //TODO 绘制其他物体

            //TODO
            options.command.DispatchCompute(options.cullingShader, 1, 1, 1, 1);
        }
Ejemplo n.º 17
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (!enabledPost || !cam.postProfile)
            {
                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
            NativeDictionary <ulong, ulong, PtrEqual> allSettings = new NativeDictionary <ulong, ulong, PtrEqual>(allPostEffects.Count, Unity.Collections.Allocator.Temp, new PtrEqual());
            foreach (var i in cam.postProfile.settings)
            {
                allSettings.Add((ulong)MUnsafeUtility.GetManagedPtr(i.GetType()), (ulong)MUnsafeUtility.GetManagedPtr(i));
            }
            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);
            cyberGlitch.Render(data.buffer, ref cam.targets);
            foreach (var i in allPostEffects)
            {
                ulong settingsPtr;
                if (allSettings.Get((ulong)MUnsafeUtility.GetManagedPtr(i.type), out settingsPtr))
                {
                    PostProcessEffectSettings setting = MUnsafeUtility.GetObject <PostProcessEffectSettings>((void *)settingsPtr);
                    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);
                }
            }
            ;
            allSettings.Dispose();
            //   data.buffer.Blit(ShaderIDs._CameraMotionVectorsTexture, cam.cameraTarget);
            //     data.buffer.BlitSRT(cam.cameraTarget, debugMat, 0);
            data.buffer.BlitSRT(cam.targets.renderTargetIdentifier, cam.cameraTarget, postContext.uberSheet.material, 0, postContext.uberSheet.properties);
            if (postContext.bloomBufferNameID > -1)
            {
                data.buffer.ReleaseTemporaryRT(postContext.bloomBufferNameID);
            }
        }
Ejemplo n.º 18
0
 public static void DrawCluster(ref RenderClusterOptions options, ref RenderTargets targets, ref PipelineCommandData data, Camera cam)
 {
     if (gpurpEnabled)
     {
         options.command.SetGlobalBuffer(ShaderIDs._PropertiesBuffer, commonData.propertyBuffer);
         options.command.SetGlobalTexture(ShaderIDs._MainTex, commonData.texArray);
         PipelineFunctions.SetBaseBuffer(baseBuffer, options.cullingShader, options.frustumPlanes, options.command);
         PipelineFunctions.RunCullDispatching(baseBuffer, options.cullingShader, options.isOrtho, options.command);
         PipelineFunctions.RenderProceduralCommand(baseBuffer, commonData.clusterMaterial, options.command);
     }
     RenderScene(ref data, cam);
 }
Ejemplo n.º 19
0
        private void PointLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            pointLightMaterial.SetBuffer(ShaderIDs.verticesBuffer, sphereBuffer);
            VoxelLightCommonData(buffer, cam.cam);
            ClearDispatch(buffer);
            lightingHandle.Complete();
            foreach (var i in addMLightCommandList)
            {
                MLight.AddMLight(i);
            }
            addMLightCommandList.Clear();
            cbdr.pointshadowCount = cubemapVPMatrices.Length;
            if (LightFilter.pointLightCount > 0)
            {
                if (cubemapVPMatrices.Length > 0)
                {
                    var cullShader = data.resources.gpuFrustumCulling;
                    buffer.SetGlobalTexture(ShaderIDs._CubeShadowMapArray, cbdr.cubeArrayMap);
                    RenderClusterOptions opts = new RenderClusterOptions
                    {
                        cullingShader = cullShader,
                        command       = buffer,
                        frustumPlanes = null,
                        isOrtho       = false
                    };
                    List <VisibleLight> allLights     = data.cullResults.visibleLights;
                    PointLightStruct *  pointLightPtr = pointLightArray.Ptr();
                    for (int i = 0; i < cubemapVPMatrices.Length; ++i)
                    {
                        ref CubemapViewProjMatrix vpMatrices = ref cubemapVPMatrices[i];
                        int2   lightIndex = vpMatrices.index;
                        Light  lt         = allLights[lightIndex.y].light;
                        MLight light      = MUnsafeUtility.GetObject <MLight>(vpMatrices.mLightPtr);
                        if (light.updateShadowmap)
                        {
                            light.UpdateShadowCacheType(true);
                            SceneController.DrawPointLight(light, ref pointLightPtr[lightIndex.x], cubeDepthMaterial, ref opts, i, light.shadowMap, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap);
                        }
                        else
                        {
                            PipelineFunctions.CopyToCubeMap(cbdr.cubeArrayMap, light.shadowMap, buffer, i);
                        }

                        //TODO
                        //Multi frame shadowmap
                    }
                }
                SetPointLightBuffer(pointLightArray, LightFilter.pointLightCount, buffer);
                buffer.EnableShaderKeyword("POINTLIGHT");
                cbdr.lightFlag |= 1;
            }
 private void OnDestroy()
 {
     if (current != this)
     {
         return;
     }
     current     = nullValue;
     initialized = false;
     PipelineFunctions.Dispose(baseBuffer);
     SceneStreaming.pointerContainer.Dispose();
     SceneStreaming.commandQueue = null;
 }
Ejemplo n.º 21
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.isD3D       = GraphicsUtility.platformIsD3D;
            calculateJob.nonJitterP  = cam.cam.nonJitteredProjectionMatrix;
            calculateJob.worldToView = cam.cam.worldToCameraMatrix;
            calculateJob.lastVP      = lastData.lastVP;
            calculateJob.rand        = (Random *)UnsafeUtility.AddressOf(ref rand);
            calculateJob.p           = cam.cam.projectionMatrix;
            calculateJob.VP          = (float4x4 *)UnsafeUtility.AddressOf(ref VP);
            calculateJob.inverseVP   = (float4x4 *)UnsafeUtility.AddressOf(ref inverseVP);
            Transform camTrans = cam.cam.transform;

            perspCam.forward       = camTrans.forward;
            perspCam.up            = camTrans.up;
            perspCam.right         = camTrans.right;
            perspCam.position      = camTrans.position;
            perspCam.nearClipPlane = cam.cam.nearClipPlane;
            perspCam.farClipPlane  = cam.cam.farClipPlane;
            perspCam.aspect        = cam.cam.aspect;
            perspCam.fov           = cam.cam.fieldOfView;
            float3 *corners = stackalloc float3[8];

            PipelineFunctions.GetFrustumCorner(ref perspCam, corners);
            frustumMinPoint = corners[0];
            frustumMaxPoint = corners[0];
            for (int i = 1; i < 8; ++i)
            {
                frustumMinPoint = min(frustumMinPoint, corners[i]);
                frustumMaxPoint = max(frustumMaxPoint, corners[i]);
            }
            handle = calculateJob.ScheduleRefBurst();
        }
        public static void Dispose()
        {
            singletonReady = false;
            PipelineFunctions.Dispose(baseBuffer);

            addList.Dispose();
            var values = allTempBuffers.Values;

            foreach (var i in values)
            {
                i.Dispose();
            }
        }
Ejemplo n.º 23
0
        public void Render(CommandBuffer buffer, ref RenderTargets targets)
        {
            if (!enabled)
            {
                return;
            }
            buffer.SetGlobalConstantBuffer(constantBuffer, _CyberData, 0, sizeof(CyberSetData));
            SetValue();
            RenderTargetIdentifier source, dest;

            PipelineFunctions.RunPostProcess(ref targets, out source, out dest);
            buffer.Blit(source, dest, glitchMat);
        }
 private void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     if (RenderPipeline.singleton)
     {
         PipelineFunctions.InitRenderTarget(ref targets, cam, temporaryTextures);
         RenderPipeline.singleton.Render(renderingPath, this, destination);
         PipelineFunctions.ReleaseRenderTarget(temporaryTextures);
     }
     else
     {
         Graphics.Blit(source, destination);
     }
 }
        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);

            /*HizOcclusionData hizOccData;
             * hizOccData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData());
             * data.buffer.Blit(hizOccData.historyDepth, cam.cameraTarget);*/
            //data.buffer.Blit(ShaderIDs._CameraMotionVectorsTexture, cam.cameraTarget);
            data.buffer.BlitSRT(cam.targets.renderTargetIdentifier, cam.cameraTarget, 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)
 {
     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);
 }
Ejemplo n.º 27
0
        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);
            }
            PipelineEvent[] events = null;
            switch (pipelineCam.renderingPath)
            {
            case CameraRenderingPath.GPUDeferred:
                events = gpurpEvents;
                break;
            }
            currentRenderingPath = pipelineCam.renderingPath;
            foreach (var e in events)
            {
                if (e.enabled && e.preEnable)
                {
                    e.PreRenderFrame(pipelineCam, ref data);
                }
            }
            JobHandle.ScheduleBatchedJobs();
            foreach (var e in events)
            {
                if (e.enabled && e.postEnable)
                {
                    e.FrameUpdate(pipelineCam, ref data);
                }
            }
            data.buffer.Blit(pipelineCam.targets.renderTargetIdentifier, dest);
        }
Ejemplo n.º 28
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();
        }
Ejemplo n.º 29
0
 public static void DrawCluster(ref RenderClusterOptions options, ref RenderTargets targets, ref PipelineCommandData data, Camera cam)
 {
     data.buffer.SetRenderTarget(targets.gbufferIdentifier, targets.depthBuffer);
     data.buffer.ClearRenderTarget(true, true, Color.black);
     if (gpurpEnabled)
     {
         options.command.SetGlobalBuffer(ShaderIDs._PropertiesBuffer, commonData.propertyBuffer);
         options.command.SetGlobalTexture(ShaderIDs._MainTex, commonData.texArray);
         options.command.SetGlobalTexture(ShaderIDs._LightMap, commonData.lightmapArray);
         PipelineFunctions.SetBaseBuffer(baseBuffer, options.cullingShader, options.frustumPlanes, options.command);
         PipelineFunctions.RunCullDispatching(baseBuffer, options.cullingShader, options.command);
         PipelineFunctions.RenderProceduralCommand(baseBuffer, commonData.clusterMaterial, options.command);
     }
     RenderScene(ref data, cam);
 }
Ejemplo n.º 30
0
        public static void Dispose(PipelineResources res)
        {
            singletonReady = false;
            PipelineFunctions.Dispose(baseBuffer);
            if (Application.isPlaying && res.clusterResources)
            {
                res.clusterResources.Dispose();
            }
            addList.Dispose();
            var values = allTempBuffers.Values;

            foreach (var i in values)
            {
                i.Dispose();
            }
        }