示例#1
0
        private void OnEnable()
        {
            if (!decalDatas.isCreated)
            {
                decalDatas = new NativeList <DecalData>(10, Unity.Collections.Allocator.Persistent);
            }
            index = decalDatas.Length;
            float4x4 worldToLocal = transform.worldToLocalMatrix;
            float4x4 localToWorld = transform.localToWorldMatrix;

            decalDatas.Add(
                new DecalData
            {
                localToWorld        = float3x4(localToWorld.c0.xyz, localToWorld.c1.xyz, localToWorld.c2.xyz, localToWorld.c3.xyz),
                worldToLocal        = float3x4(worldToLocal.c0.xyz, worldToLocal.c1.xyz, worldToLocal.c2.xyz, worldToLocal.c3.xyz),
                albedoScaleOffset   = albedoScaleOffset,
                normalScaleOffset   = normalScaleOffset,
                specularScaleOffset = specularScaleOffset,
                importance          = importance,
                comp              = MUnsafeUtility.GetManagedPtr(this),
                texIndex          = int3(albedoIndex, normalIndex, specularIndex),
                avaliableDistance = avaliableDistance,
                opacity           = float3(albedoOpacity, normalOpacity, specularOpacity),
                layer             = (uint)layer
            });
        }
        private void OnEnable()
        {
            if (!allVolumes.isCreated)
            {
                allVolumes = new NativeList <FogVolumeContainer>(30, Allocator.Persistent);
            }

            FogVolumeContainer currentcon;

            currentcon.light = MUnsafeUtility.GetManagedPtr(this);
            float3x3 localToWorld = new float3x3
            {
                c0 = transform.right,
                c1 = transform.up,
                c2 = transform.forward
            };
            float4x4  worldToLocal = transform.worldToLocalMatrix;
            FogVolume volume       = new FogVolume
            {
                extent        = transform.localScale * 0.5f,
                localToWorld  = localToWorld,
                position      = transform.position,
                worldToLocal  = float3x4(worldToLocal.c0.xyz, worldToLocal.c1.xyz, worldToLocal.c2.xyz, worldToLocal.c3.xyz),
                targetVolume  = this.volume,
                color         = float3(fogColor.r, fogColor.g, fogColor.b),
                emissionColor = float3(emissionColor.r, emissionColor.g, emissionColor.b)
            };

            currentcon.volume = volume;
            allVolumes.Add(currentcon);
            index = allVolumes.Length - 1;
        }
示例#3
0
        public RenderPipeline(PipelineResources resources)
        {
            eventsGuideBook = new NativeDictionary <UIntPtr, int, PtrEqual>(resources.availiableEvents.Length, Allocator.Persistent, new PtrEqual());
            resources.SetRenderingPath();
            var allEvents = resources.allEvents;

            GraphicsUtility.UpdatePlatform();
            MLight.ClearLightDict();
            this.resources = resources;
            current        = this;
            data.buffer    = new CommandBuffer();
            for (int i = 0; i < resources.availiableEvents.Length; ++i)
            {
                resources.availiableEvents[i].InitDependEventsList();
            }
            for (int i = 0; i < resources.availiableEvents.Length; ++i)
            {
                eventsGuideBook.Add(new UIntPtr(MUnsafeUtility.GetManagedPtr(resources.availiableEvents[i].GetType())), i);
                resources.availiableEvents[i].Prepare();
            }
            for (int i = 0; i < resources.availiableEvents.Length; ++i)
            {
                resources.availiableEvents[i].InitEvent(resources);
            }
            waitReleaseRT = new NativeList <int>(20, Allocator.Persistent);
        }
示例#4
0
        public void Execute()
        {
            List <MLight> allSpotLight  = MLight.avaliableSpotShadowIndices;
            List <MLight> allPointLight = MLight.avaliableCubemapIndices;
            UIntPtr *     allPtr        = stackalloc UIntPtr[max(spotExists ? allSpotLight.Count : 0, pointExists ? allPointLight.Count : 0)];
            int           ptrCount      = 0;

            if (spotExists)
            {
                for (int i = 0; i < allSpotLight.Count; ++i)
                {
                    ref Cone c   = ref allSpotLightPosition[i];
                    float3   dir = c.vertex - cameraPos;
                    if (!MathLib.ConeIntersect(allSpotLightPosition[i], MathLib.GetPlane(dir, cameraPos + dir * shadowDistance)))
                    {
                        allPtr[ptrCount] = new UIntPtr(MUnsafeUtility.GetManagedPtr(allSpotLight[i]));
                        ptrCount++;
                    }
                }
                for (int i = 0; i < ptrCount; ++i)
                {
                    MLight ml = MUnsafeUtility.GetObject <MLight>(allPtr[i].ToPointer());
                    ml.RemoveLightFromAtlas(false);
                    ml.updateShadowCache = true;
                }
            }
示例#5
0
 public static void AddRunnableObject(int id, IPipelineRunnable func)
 {
     if (!iRunnableObjects.isCreated)
     {
         iRunnableObjects = new NativeDictionary <int, ulong, IntEqual>(10, Allocator.Persistent, new IntEqual());
     }
     iRunnableObjects.Add(id, (ulong)MUnsafeUtility.GetManagedPtr(func));
 }
 private void OnEnable()
 {
     if (!allCamera.isCreated)
     {
         allCamera = new NativeDictionary <int, UIntPtr>(17, Unity.Collections.Allocator.Persistent, (i, j) => i == j);
     }
     allCamera.Add(gameObject.GetInstanceID(), new UIntPtr(MUnsafeUtility.GetManagedPtr(this)));
 }
示例#7
0
 private void OnEnable()
 {
     if (!allProbe.isCreated)
     {
         allProbe = new NativeList <UIntPtr>(10, Allocator.Persistent);
     }
     index = allProbe.Length;
     allProbe.Add(new UIntPtr(MUnsafeUtility.GetManagedPtr(this)));
 }
示例#8
0
 public void AddToDict()
 {
     InitializeDict();
     cameraSearchDict[gameObject.GetInstanceID()] = (ulong)MUnsafeUtility.GetManagedPtr(this);
     if (!frustumArray.isCreated)
     {
         frustumArray = new NativeList <float4>(6, 6, Allocator.Persistent);
     }
 }
 private void OnEnable()
 {
     if (!allCamera.isCreated)
     {
         allCamera = new NativeDictionary <int, UIntPtr, IntEqual>(17, Allocator.Persistent, new IntEqual());
     }
     allCamera.Add(gameObject.GetInstanceID(), new UIntPtr(MUnsafeUtility.GetManagedPtr(this)));
     GetComponent <Camera>().layerCullDistances = layerCullDistance;
 }
示例#10
0
        public static PipelineEvent GetEvent(Type type)
        {
            int value;

            if (eventsGuideBook.Get(new UIntPtr(MUnsafeUtility.GetManagedPtr(type)), out value))
            {
                return(current.resources.availiableEvents[value]);
            }
            return(null);
        }
示例#11
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);
            }
        }
示例#12
0
        public static void RemoveProperty <T>(PipelineCamera camera)
        {
            int            index = camera.allDatas[(ulong)MUnsafeUtility.GetManagedPtr(typeof(T))];
            IPerCameraData data  = MUnsafeUtility.GetHookedObject(index) as IPerCameraData;

            if (data != null)
            {
                data.DisposeProperty();
            }
            MUnsafeUtility.RemoveHookedObject(index);
        }
示例#13
0
        public static T GetEvent <T>() where T : PipelineEvent
        {
            Type type = typeof(T);
            int  value;

            if (eventsGuideBook.Get(new UIntPtr(MUnsafeUtility.GetManagedPtr(type)), out value))
            {
                return(current.resources.availiableEvents[value] as T);
            }
            return(null);
        }
示例#14
0
 public void AddToDict()
 {
     if (!cameraSearchDict.isCreated)
     {
         cameraSearchDict = new NativeDictionary <int, ulong, IntEqual>(20, Allocator.Persistent, new IntEqual());
     }
     cameraSearchDict[gameObject.GetInstanceID()] = (ulong)MUnsafeUtility.GetManagedPtr(this);
     if (!frustumArray.isCreated)
     {
         frustumArray = new NativeList <float4>(6, 6, Allocator.Persistent);
     }
 }
示例#15
0
 public NativeDictionary(int capacity, Allocator alloc, Func <K, K, bool> equals)
 {
     capacity       = Mathf.Max(capacity, 1);
     equalsFunc     = MUnsafeUtility.GetManagedPtr(equals);
     isCreated      = true;
     data           = (DictData *)MUnsafeUtility.Malloc(sizeof(DictData), alloc);
     data->capacity = capacity;
     data->length   = 0;
     data->alloc    = alloc;
     data->start    = MUnsafeUtility.Malloc(8 * capacity, alloc);
     UnsafeUtility.MemClear(data->start, 8 * capacity);
 }
 private void Awake()
 {
     if (!decalDatas.isCreated)
     {
         decalDatas = new NativeList <DecalData>(10, Unity.Collections.Allocator.Persistent);
     }
     decalDatas.Add(
         new DecalData
     {
         position = transform.position,
         rotation = transform.localToWorldMatrix,
         comp     = MUnsafeUtility.GetManagedPtr(this)
     });
     Init();
 }
示例#17
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)));
                    }
                }
            }
        }
示例#18
0
        public static T GetProperty <T, R>(PipelineCamera camera, R runnable) where T : IPerCameraData where R : struct, IGetCameraData
        {
            int            index;
            IPerCameraData data;

            if (!camera.allDatas.isCreated)
            {
                camera.allDatas = new NativeDictionary <ulong, int, PipelineCamera.PtrEqual>(20, Unity.Collections.Allocator.Persistent, new PipelineCamera.PtrEqual());
            }
            if (!camera.allDatas.Get((ulong)MUnsafeUtility.GetManagedPtr(typeof(T)), out index))
            {
                data  = runnable.Run();
                index = MUnsafeUtility.HookObject(data);
                camera.allDatas.Add((ulong)MUnsafeUtility.GetManagedPtr(typeof(T)), index);
            }
            return(MUnsafeUtility.GetHookedObject(index) as T);
        }
示例#19
0
 private void OnEnable()
 {
     if (!decalDatas.isCreated)
     {
         decalDatas = new NativeList <DecalData>(10, Unity.Collections.Allocator.Persistent);
     }
     index = decalDatas.Length;
     decalDatas.Add(
         new DecalData
     {
         position     = transform.position,
         rotation     = transform.localToWorldMatrix,
         worldToLocal = transform.worldToLocalMatrix,
         index        = texIndex,
         comp         = MUnsafeUtility.GetManagedPtr(this)
     });
 }
示例#20
0
        public void UpdateLight()
        {
            Bounds bound = GetFrustumBounds();

            allAreaLight[index] = new AreaLightComponent
            {
                area = new AreaLight
                {
                    mat   = GetProjectionMatrix(true),
                    color = float3(color.r, color.g, color.b) * intensity
                },
                localToWorld = transform.localToWorldMatrix,
                center       = bound.center,
                extent       = bound.extents,
                componentPtr = MUnsafeUtility.GetManagedPtr(this)
            };
        }
示例#21
0
        private void OnEnable()
        {
            if (!allVoxelData.isCreated)
            {
                allVoxelData = new NativeList <VoxelCubeData>(10, Unity.Collections.Allocator.Persistent);
            }
            index = allVoxelData.Length;
            float3 minV, maxV;

            GetMinMax(out minV, out maxV);
            allVoxelData.Add(new VoxelCubeData
            {
                localToWorldMatrix = transform.localToWorldMatrix,
                worldToLocalMatrix = transform.worldToLocalMatrix,
                ptr      = MUnsafeUtility.GetManagedPtr(this),
                minPoint = minV,
                maxPoint = maxV
            });
            OnEnableFunc();
        }
示例#22
0
        private void Awake()
        {
            if (!decalDatas.isCreated)
            {
                decalDatas = new NativeList <DecalComponent>(10, Unity.Collections.Allocator.Persistent);
            }
            float4x4 localToWorld = transform.localToWorldMatrix;

            decalDatas.Add(new DecalComponent
            {
                comp = MUnsafeUtility.GetManagedPtr(this),
                data = new DecalData
                {
                    endUV    = endUV,
                    position = transform.position,
                    rotation = float3x3(localToWorld.c0.xyz, localToWorld.c1.xyz, localToWorld.c2.xyz),
                    startUV  = startUV
                }
            });
        }
示例#23
0
        private void OnEnable()
        {
            if (!allAreaLight.isCreated)
            {
                allAreaLight = new NativeList <AreaLightComponent>(20, Allocator.Persistent);
            }
            index = allAreaLight.Length;
            Bounds bound = GetFrustumBounds();

            allAreaLight.Add(new AreaLightComponent
            {
                area = new AreaLight
                {
                    mat   = GetProjectionMatrix(true),
                    color = float3(color.r, color.g, color.b) * intensity
                },
                localToWorld = transform.localToWorldMatrix,
                center       = bound.center,
                extent       = bound.extents,
                componentPtr = MUnsafeUtility.GetManagedPtr(this)
            });
        }
        private static NativeArray <UIntPtr> GetAllPath()
        {
            NativeList <UIntPtr> pool     = new NativeList <UIntPtr>(10, Allocator.Temp);
            NativeList <int>     typePool = new NativeList <int>(10, Allocator.Temp);

            FieldInfo[] allInfos = typeof(AllEvents).GetFields();
            foreach (var i in allInfos)
            {
                RenderingPathAttribute but = i.GetCustomAttribute(typeof(RenderingPathAttribute)) as RenderingPathAttribute;
                if (but != null && i.FieldType == typeof(Type[]))
                {
                    pool.Add(new UIntPtr(MUnsafeUtility.GetManagedPtr(i)));
                    typePool.Add((int)but.path);
                }
            }
            NativeArray <UIntPtr> final = new NativeArray <UIntPtr>(pool.Length, Allocator.Temp, NativeArrayOptions.ClearMemory);

            for (int i = 0; i < pool.Length; ++i)
            {
                final[typePool[i]] = pool[i];
            }
            return(final);
        }
示例#25
0
        private void OnEnable()
        {
            if (!decalDatas.isCreated)
            {
                decalDatas = new NativeList <DecalData>(10, Unity.Collections.Allocator.Persistent);
            }
            index = decalDatas.Length;
            float4x4 localToWorld = transform.localToWorldMatrix;
            float4x4 worldToLocal = transform.worldToLocalMatrix;

            decalDatas.Add(
                new DecalData
            {
                position          = transform.position,
                rotation          = float3x4(localToWorld.c0.xyz, localToWorld.c1.xyz, localToWorld.c2.xyz, localToWorld.c3.xyz),
                worldToLocal      = float3x4(worldToLocal.c0.xyz, worldToLocal.c1.xyz, worldToLocal.c2.xyz, worldToLocal.c3.xyz),
                albedoScaleOffset = albedoScaleOffset,
                normalScaleOffset = normalScaleOffset,
                importance        = importance,
                comp     = MUnsafeUtility.GetManagedPtr(this),
                texIndex = int2(albedoIndex, normalIndex)
            });
        }
示例#26
0
        private void OnEnable()
        {
            if (!allVolumes.isCreated)
            {
                allVolumes = new NativeList <FogVolumeContainer>(30, Allocator.Persistent);
            }

            FogVolumeContainer currentcon;

            currentcon.light = MUnsafeUtility.GetManagedPtr(this);
            float3x3 localToWorld = new float3x3
            {
                c0 = transform.right,
                c1 = transform.up,
                c2 = transform.forward
            };
            float4x4 worldToLocal = inverse(new float4x4
            {
                c0 = float4(localToWorld.c0, 0),
                c1 = float4(localToWorld.c1, 0),
                c2 = float4(localToWorld.c2, 0),
                c3 = float4(transform.position, 1)
            });
            FogVolume volume = new FogVolume
            {
                extent       = transform.localScale * 0.5f,
                localToWorld = localToWorld,
                position     = transform.position,
                worldToLocal = worldToLocal,
                targetVolume = this.volume
            };

            currentcon.volume = volume;
            allVolumes.Add(currentcon);
            container = allVolumes.unsafePtr + allVolumes.Length - 1;
        }