예제 #1
0
        public void Prepare(PipelineResources.CameraRenderingPath renderingPath)
        {
            RequireEventAttribute requireEvt = GetType().GetCustomAttribute <RequireEventAttribute>(true);

            this.renderingPath = renderingPath;
            if (requireEvt != null)
            {
                if (dependingEvents == null)
                {
                    dependingEvents = new List <PipelineEvent>(requireEvt.events.Length);
                }
                foreach (var t in requireEvt.events)
                {
                    PipelineEvent targetevt = RenderPipeline.GetEvent(renderingPath, t);
                    if (targetevt != null)
                    {
                        if (targetevt.dependedEvents == null)
                        {
                            targetevt.dependedEvents = new List <PipelineEvent>();
                        }
                        targetevt.dependedEvents.Add(this);
                        dependingEvents.Add(targetevt);
                    }
                }
            }
        }
        protected override void Init(PipelineResources resources)
        {
            proper            = RenderPipeline.GetEvent <PropertySetEvent>();
            probeBuffer       = new ComputeBuffer(maximumProbe, sizeof(ReflectionData));
            lightingEvents    = RenderPipeline.GetEvent <LightingEvent>();
            reflectionIndices = new ComputeBuffer(CBDRSharedData.XRES * CBDRSharedData.YRES * CBDRSharedData.ZRES * (maximumProbe + 1), sizeof(int));
            string old    = "_ReflectionCubeMap";
            string newStr = new string(' ', old.Length + 1);

            reflectionCubemapIDs = new NativeList <int>(maximumProbe, maximumProbe, Allocator.Persistent);
            fixed(char *ctr = old)
            {
                fixed(char *newCtr = newStr)
                {
                    for (int i = 0; i < old.Length; ++i)
                    {
                        newCtr[i] = ctr[i];
                    }
                    for (int i = 0; i < reflectionCubemapIDs.Length; ++i)
                    {
                        newCtr[old.Length]      = (char)(i + 48);
                        reflectionCubemapIDs[i] = Shader.PropertyToID(newStr);
                    }
                }
            }

            reflectionMat = new Material(resources.shaders.reflectionShader);
            ssrEvents.Init(resources);
        }
 /*
  * private static int SSR_ProjectionMatrix_ID = Shader.PropertyToID("_SSR_ProjectionMatrix");
  * private static int SSR_InverseProjectionMatrix_ID = Shader.PropertyToID("_SSR_InverseProjectionMatrix");
  * private static int SSR_WorldToCameraMatrix_ID = Shader.PropertyToID("_SSR_WorldToCameraMatrix");
  * private static int SSR_CameraToWorldMatrix_ID = Shader.PropertyToID("_SSR_CameraToWorldMatrix");
  * private static int SSR_ProjectToPixelMatrix_ID = Shader.PropertyToID("_SSR_ProjectToPixelMatrix");
  */
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public void Init(PipelineResources res)
 {
     StochasticScreenSpaceReflectionMaterial = new Material(res.shaders.ssrShader);
     ssrDatas         = new ComputeBuffer(1, sizeof(SSRData), ComputeBufferType.Constant);
     rand             = new Random((uint)System.Guid.NewGuid().GetHashCode());
     propertySetEvent = RenderPipeline.GetEvent <PropertySetEvent>();
 }
        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();
        }
예제 #5
0
        public RenderPipeline(PipelineResources resources)
        {
            resources.SetRenderingPath();
            var allEvents = resources.allEvents;

            GraphicsUtility.UpdatePlatform();
            MLight.ClearLightDict();
            this.resources     = resources;
            current            = this;
            data.buffer        = new CommandBuffer();
            data.frustumPlanes = new Vector4[6];

            for (int i = 0; i < allEvents.Length; ++i)
            {
                PipelineEvent[] events = allEvents[i];
                if (events == null)
                {
                    continue;
                }
                foreach (var j in events)
                {
                    j.Prepare((PipelineResources.CameraRenderingPath)i);
                }
                foreach (var j in events)
                {
                    j.InitEvent(resources);
                }
            }
        }
예제 #6
0
 protected override void Init(PipelineResources resources)
 {
     proper = RenderPipeline.GetEvent <PropertySetEvent>();
     if (useTBDR)
     {
         minMaxBoundMat = new Material(resources.shaders.minMaxDepthBounding);
     }
     needCheckedShadows = new NativeList <ShadowAvaliable>(20, Allocator.Persistent);
     cbdr = new CBDRSharedData(resources);
     for (int i = 0; i < cascadeShadowMapVP.Length; ++i)
     {
         cascadeShadowMapVP[i] = Matrix4x4.identity;
     }
     cubeDepthMaterial = new Material(resources.shaders.cubeDepthShader);
     spotBuffer        = new RenderSpotShadowCommand();
     spotBuffer.Init(resources.shaders.spotLightDepthShader);
     whiteTex = new Texture2DArray(1, 1, 1, TextureFormat.ARGB32, false, false);
     whiteTex.SetPixels(new Color[] { Color.white }, 0);
     if (iesTextures.Length > 0)
     {
         ComputeShader texCopyShader = resources.shaders.texCopyShader;
         iesAtlas = new RenderTexture(new RenderTextureDescriptor
         {
             colorFormat       = RenderTextureFormat.R8,
             dimension         = TextureDimension.Tex2DArray,
             width             = 256,
             height            = 1,
             volumeDepth       = iesTextures.Length,
             enableRandomWrite = true,
             msaaSamples       = 1
         });
         ((RenderTexture)iesAtlas).Create();
         UpdateIESTexture(texCopyShader);
     }
 }
예제 #7
0
 protected override void Init(PipelineResources resources)
 {
     //   debugMat = new Material(debug);
     downSampleDepthMat = new Material(resources.shaders.depthDownSample);
     GTAOMaterial       = new Material(resources.shaders.gtaoShader);
     propertySetEvent   = RenderPipeline.GetEvent <PropertySetEvent>();
 }
예제 #8
0
        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();
            }
        }
 protected override void OnDisable()
 {
     RenderPipeline.ExecuteBufferAtFrameEnding((buffer) =>
     {
         buffer.DisableShaderKeyword("ENABLE_REFLECTION");
     });
 }
예제 #10
0
 //   public Shader debug;
 //   private Material debugMat;
 /* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* *//* */
 protected override void Init(PipelineResources resources)
 {
     //    debugMat = new Material(debug);
     GTAOMaterial     = new Material(resources.shaders.gtaoShader);
     propertySetEvent = RenderPipeline.GetEvent <PropertySetEvent>();
     dataBuffer       = new ComputeBuffer(1, sizeof(AOData), ComputeBufferType.Constant);
     proper           = RenderPipeline.GetEvent <PropertySetEvent>();
 }
예제 #11
0
 public void Init(PipelineResources res)
 {
     getDataFunc = (c) => new SSRCameraData(new Vector2Int(c.cam.pixelWidth, c.cam.pixelHeight), 2);
     StochasticScreenSpaceReflectionMaterial = new Material(res.shaders.ssrShader);
     ssrDatas         = new ComputeBuffer(1, sizeof(SSRData), ComputeBufferType.Constant);
     rand             = new Random((uint)System.Guid.NewGuid().GetHashCode());
     propertySetEvent = RenderPipeline.GetEvent <PropertySetEvent>();
 }
예제 #12
0
 public void Init(PipelineResources res)
 {
     cbdrShader  = res.shaders.cbdrShader;
     proper      = RenderPipeline.GetEvent <PropertySetEvent>();
     lightingEvt = RenderPipeline.GetEvent <LightingEvent>();
     decalBuffer = new ComputeBuffer(INITCOUNT, sizeof(DecalStrct));
     sortJob.sortedDecalDatas = new NativeList <DecalStrct>(INITCOUNT, Allocator.Persistent);
     minMaxBoundMat           = new Material(res.shaders.minMaxDepthBounding);
 }
예제 #13
0
 protected override void OnDisable()
 {
     RenderPipeline.ExecuteBufferAtFrameEnding((buffer) =>
     {
         buffer.DisableShaderKeyword("ENABLE_SUN");
         buffer.DisableShaderKeyword("SPOTLIGHT");
         buffer.DisableShaderKeyword("POINTLIGHT");
     });
 }
예제 #14
0
 private void Awake()
 {
     cam              = GetComponent <Camera>();
     cam.enabled      = false;
     cam.orthographic = true;
     cam.aspect       = 1;
     renderingCommand = new NativeList <CameraState>(10, Allocator.Persistent);
     idfs             = new RenderTargetIdentifier[3];
     RenderPipeline.AddRunnableObject(GetInstanceID(), this);
 }
예제 #15
0
 public void DebugTry()
 {
     if (!SceneController.gpurpEnabled)
     {
         Debug.Log("Cluster Rendering not enabled!");
         return;
     }
     BakeMap(0);
     RenderPipeline.ExecuteBufferAtFrameEnding(cbuffer);
 }
예제 #16
0
 protected override void Init(PipelineResources resources)
 {
     cbdr            = new CBDRSharedData(resources);
     volumetricEvent = RenderPipeline.GetEvent <VolumetricLightEvent>(renderingPath);
     for (int i = 0; i < cascadeShadowMapVP.Length; ++i)
     {
         cascadeShadowMapVP[i] = Matrix4x4.identity;
     }
     cubeDepthMaterial = new Material(resources.shaders.cubeDepthShader);
     spotBuffer        = new RenderSpotShadowCommand();
     spotBuffer.Init(resources.shaders.spotLightDepthShader);
 }
        private void BakeCubemap()
        {
            PerspCam persp = new PerspCam();

            persp.aspect        = 1;
            persp.farClipPlane  = considerRange;
            persp.nearClipPlane = 0.1f;
            persp.fov           = 90f;
            NativeList <float4x4> worldToCameras = new NativeList <float4x4>(6, 6, Allocator.TempJob);
            NativeList <float4x4> projection     = new NativeList <float4x4>(6, 6, Allocator.TempJob);

            GetMatrix(worldToCameras.unsafePtr, ref persp, transform.position);
            persp.UpdateProjectionMatrix();
            for (int i = 0; i < 6; ++i)
            {
                projection[i] = persp.projectionMatrix;
            }
            RenderTexture rt = new RenderTexture(new RenderTextureDescriptor
            {
                autoGenerateMips  = false,
                bindMS            = false,
                colorFormat       = RenderTextureFormat.ARGBHalf,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2DArray,
                enableRandomWrite = false,
                height            = 128,
                width             = 128,
                volumeDepth       = 6,
                msaaSamples       = 1,
                useMipMap         = true
            });

            rt.filterMode = FilterMode.Trilinear;
            rt.Create();
            RenderTexture tempRT = new RenderTexture(new RenderTextureDescriptor
            {
                autoGenerateMips  = false,
                bindMS            = false,
                colorFormat       = RenderTextureFormat.ARGBHalf,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2D,
                enableRandomWrite = false,
                height            = 128,
                width             = 128,
                volumeDepth       = 1,
                msaaSamples       = 1
            });

            cbuffer.Clear();
            cbuffer.SetGlobalTexture("_Cubemap", rt);
            cbuffer.GenerateMips(rt);
            RenderPipeline.AddRenderingMissionInEditor(worldToCameras, projection, targetCamera, rt, tempRT, cbuffer);
        }
예제 #18
0
        public void Init(PipelineResources res)
        {
            cbdrShader       = res.shaders.cbdrShader;
            copyMat          = new Material(res.shaders.copyShader);
            proper           = RenderPipeline.GetEvent <PropertySetEvent>();
            lightingEvt      = RenderPipeline.GetEvent <LightingEvent>();
            decalBuffer      = new ComputeBuffer(INITCOUNT, sizeof(DecalStrct));
            decalIndexBuffer = new ComputeBuffer(CBDRSharedData.XRES * CBDRSharedData.YRES * CBDRSharedData.ZRES * (CBDRSharedData.MAXLIGHTPERCLUSTER + 1), sizeof(int));
            if (decalAlbedoAtlasNames.Length > 0)
            {
                decalAlbedoAtlas = new RenderTexture(new RenderTextureDescriptor
                {
                    width       = atlasWidth,
                    height      = atlasHeight,
                    volumeDepth = decalAlbedoAtlasNames.Length,
                    dimension   = TextureDimension.Tex2DArray,
                    msaaSamples = 1,
                    colorFormat = RenderTextureFormat.ARGB32
                });
            }
            if (decalNormalAtlasNames.Length > 0)
            {
                decalNormalAtlas = new RenderTexture(new RenderTextureDescriptor
                {
                    width       = atlasWidth,
                    height      = atlasHeight,
                    volumeDepth = decalAlbedoAtlasNames.Length,
                    dimension   = TextureDimension.Tex2DArray,
                    msaaSamples = 1,
                    colorFormat = RenderTextureFormat.RGHalf
                });
            }
            for (int i = 0; i < decalAlbedoAtlasNames.Length; ++i)
            {
                Graphics.SetRenderTarget(decalAlbedoAtlas.colorBuffer, decalAlbedoAtlas.depthBuffer, 0, CubemapFace.Unknown, i);
                Texture tex = Resources.Load <Texture>(decalAlbedoAtlasNames[i]);
                copyMat.SetTexture(ShaderIDs._MainTex, tex);
                copyMat.SetPass(0);
                Graphics.DrawMeshNow(GraphicsUtility.mesh, Matrix4x4.identity);
                Resources.UnloadAsset(tex);
            }
            for (int i = 0; i < decalNormalAtlasNames.Length; ++i)
            {
                Graphics.SetRenderTarget(decalNormalAtlas.colorBuffer, decalNormalAtlas.depthBuffer, 0, CubemapFace.Unknown, i);
                Texture tex = Resources.Load <Texture>(decalNormalAtlasNames[i]);
                copyMat.SetTexture(ShaderIDs._MainTex, tex);
                copyMat.SetPass(1);
                Graphics.DrawMeshNow(GraphicsUtility.mesh, Matrix4x4.identity);
                Resources.UnloadAsset(tex);
            }

            Object.DestroyImmediate(copyMat);
        }
예제 #19
0
 public void QueueJob()
 {
     jobHandle = (new MoveTransform
     {
         offset = offset
     }).Schedule(transformArray);
     jobHandle.Complete();
     Shader.SetGlobalVector(ShaderIDs._SceneOffset, new float4(offset.xyz, lengthsq(offset.xyz) > 0.01f ? 1 : 0));
     mainCamera.transform.position += (Vector3)offset;
     SceneController.TransformMapPosition(0);
     RenderPipeline.AddCommandAfterFrame(this, (o) => Shader.SetGlobalVector(ShaderIDs._SceneOffset, Vector4.zero));
 }
예제 #20
0
        protected override void Init(PipelineResources resources)
        {
            lightingData = RenderPipeline.GetEvent <LightingEvent>();
            randomBuffer = new ComputeBuffer(downSampledSize.x * downSampledSize.y * downSampledSize.z, sizeof(uint));
            NativeArray <uint> randomArray = new NativeArray <uint>(randomBuffer.count, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            uint *randPtr = randomArray.Ptr();

            for (int i = 0; i < randomArray.Length; ++i)
            {
                randPtr[i] = (uint)-System.Guid.NewGuid().GetHashCode();
            }
            randomBuffer.SetData(randomArray);
            randomArray.Dispose();
        }
 private void OnDestroy()
 {
     if (singleton != this)
     {
         return;
     }
     singleton = null;
     foreach (var i in allEvents)
     {
         i.DisposeEvent();
     }
     allEvents = null;
     data.arrayCollection.Dispose();
 }
예제 #22
0
        private IEnumerator FinishLoading()
        {
            coeff.SetData(bytes);
            yield return(null);

            RenderPipeline.ExecuteBufferAtFrameEnding(cubeToCoeff);
            yield return(null);

            yield return(null);

            coeffTextures.Add(currentTexture);
            loadedIrradiance.Add(currentIrr);
            isLoading = false;
        }
 protected override void Init(PipelineResources resources)
 {
     linearMat       = new Material(resources.shaders.linearDepthShader);
     linearDrawerMat = new Material(resources.shaders.linearDrawerShader);
     motionVecMat    = new Material(resources.shaders.motionVectorShader);
     if (useHiZ)
     {
         hizDepth.InitHiZ(resources, new Vector2(Screen.width, Screen.height));
         clusterMat = new Material(resources.shaders.clusterRenderShader);
     }
     ao            = RenderPipeline.GetEvent <AOEvents>();
     reflection    = RenderPipeline.GetEvent <ReflectionEvent>();
     proper        = RenderPipeline.GetEvent <PropertySetEvent>();
     downSampleMat = new Material(resources.shaders.depthDownSample);
 }
예제 #24
0
 private void OnDestroy()
 {
     if (singleton != this)
     {
         return;
     }
     singleton = null;
     DisposeScene();
     foreach (var i in allEvents)
     {
         i.DisposeEvent();
     }
     allEvents = null;
     data.buffer.Dispose();
 }
 private void Awake()
 {
     if (singleton)
     {
         Debug.LogError("Render Pipeline should be Singleton!");
         Destroy(this);
         return;
     }
     data.arrayCollection = RenderArray.GetRenderArray();
     singleton            = this;
     allEvents            = new List <PipelineEvent>(eventParent.GetComponentsInChildren <PipelineEvent>());
     foreach (var i in allEvents)
     {
         i.InitEvent(resources);
     }
 }
예제 #26
0
 protected override void Init(PipelineResources resources)
 {
     proper = RenderPipeline.GetEvent <PropertySetEvent>();
     if (useEmissionGeometry)
     {
         geometry.Init();
     }
     if (useNoiseEvents)
     {
         noiseEvents.Init(resources);
     }
     lightingData       = RenderPipeline.GetEvent <LightingEvent>();
     reflectData        = RenderPipeline.GetEvent <ReflectionEvent>();
     lightingMat        = new Material(resources.shaders.volumetricShader);
     cameraNormalBuffer = new ComputeBuffer(3, sizeof(float3));
 }
 private void OnDestroy()
 {
     if (current != this)
     {
         return;
     }
     current = null;
     foreach (var i in allEvents)
     {
         i.DisposeEvent();
     }
     allEvents = null;
     data.buffer.Dispose();
     sceneController.OnDestroy();
     PipelineSharedData.DisposeAll();
 }
예제 #28
0
 private void OnEnable()
 {
     heightTempTex                  = new RenderTexture(MTerrain.HEIGHT_RESOLUTION * 4, MTerrain.HEIGHT_RESOLUTION * 4, 16, MTerrain.HEIGHT_FORMAT, 3);
     heightTempTex.useMipMap        = true;
     heightTempTex.autoGenerateMips = false;
     heightTempTex.filterMode       = FilterMode.Point;
     heightTempTex.antiAliasing     = 1;
     heightTempTex.Create();
     cam              = GetComponent <Camera>();
     cam.enabled      = false;
     cam.orthographic = true;
     cam.aspect       = 1;
     renderingCommand = new NativeList <CameraState>(10, Allocator.Persistent);
     idfs             = new RenderTargetIdentifier[3];
     RenderPipeline.AddRunnableObject(GetInstanceID(), this);
 }
예제 #29
0
        public void Prepare()
        {
            RequireEventAttribute requireEvt = GetType().GetCustomAttribute <RequireEventAttribute>(true);

            if (requireEvt != null)
            {
                foreach (var t in requireEvt.events)
                {
                    PipelineEvent targetevt = RenderPipeline.GetEvent(t);
                    if (targetevt != null)
                    {
                        targetevt.dependedEvents.Add(new UIntPtr(MUnsafeUtility.GetManagedPtr(this)));
                        dependingEvents.Add(new UIntPtr(MUnsafeUtility.GetManagedPtr(targetevt)));
                    }
                }
            }
        }
 private void OnDestroy()
 {
     if (singleton != this)
     {
         return;
     }
     singleton = null;
     PipelineFunctions.Dispose(ref data.baseBuffer);
     foreach (var i in allEvents)
     {
         i.DisposeEvent();
     }
     allEvents = null;
     data.buffer.Dispose();
     SceneStreaming.pointerContainer.Dispose();
     SceneStreaming.commandQueue = null;
 }