public override void OnPreRenderEvent()
    {
        Matrix4x4 vp = projMatrix * viewMatrix;

        PipelineFunctions.GetCullingPlanes(ref vp, frustumCullingPlanes);
        PipelineFunctions.SetBaseBuffer(ref baseBuffer, gpuFrustumShader, frustumCullingPlanes);
        PipelineFunctions.DispatchCulling(ref baseBuffer, gpuFrustumShader, renderObjects, drawingCommands);
        PipelineFunctions.SetShaderBuffer(geometryBuffer, ref baseBuffer);
        PipelineFunctions.RenderProceduralCommand(drawingCommands, geometryBuffer);
    }
    protected override void OnEnable()
    {
        base.OnEnable();
        int count = 0;

        foreach (var i in renderObjects)
        {
            count += i.objPositions.Length;
        }
        PipelineFunctions.Initialize(ref baseBuffer, renderObjects, count);
        System.GC.Collect();
    }
Exemple #3
0
    public static void Initialize()
    {
        if (isInitialized)
        {
            return;
        }
        isInitialized                = true;
        gpuFrustumShader             = Resources.Load <ComputeShader>("GpuFrustumCulling");
        shadMask.shadowmaskMaterial  = new Material(Shader.Find("Hidden/ShadowMask"));
        shadMask.afterLightingBuffer = new CommandBuffer();
        TextAsset pointText = Resources.Load <TextAsset>("MapPoints");
        TextAsset infoText  = Resources.Load <TextAsset>("MapInfos");

        byte[]      pointBytes  = pointText.bytes;
        byte[]      infoBytes   = infoText.bytes;
        Point *     points      = null;
        ObjectInfo *infos       = null;
        int         pointLength = 0;
        int         infoLength  = 0;

        fixed(void *ptr = &pointBytes[0])
        {
            points      = (Point *)ptr;
            pointLength = pointBytes.Length / Point.SIZE;
        }

        fixed(void *ptr = &infoBytes[0])
        {
            infos      = (ObjectInfo *)ptr;
            infoLength = infoBytes.Length / ObjectInfo.SIZE;
        }

        NativeArray <Point>      allPoints = new NativeArray <Point>(pointLength, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
        NativeArray <ObjectInfo> allInfos  = new NativeArray <ObjectInfo>(infoLength, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
        void *destination = allPoints.GetUnsafePtr();

        UnsafeUtility.MemCpy(destination, points, pointBytes.Length);
        destination = allInfos.GetUnsafePtr();
        UnsafeUtility.MemCpy(destination, infos, infoBytes.Length);
        PipelineFunctions.Initialize(ref baseBuffer, allPoints, allInfos);
        for (int i = 0; i < cascadeShadowMapVP.Length; ++i)
        {
            cascadeShadowMapVP[i] = Matrix4x4.identity;
        }
        Resources.UnloadAsset(pointText);
        Resources.UnloadAsset(infoText);
        allInfos.Dispose();
        allPoints.Dispose();
    }
 protected override void OnDisable()
 {
     base.OnDisable();
     PipelineFunctions.Dispose(ref baseBuffer, renderObjects);
     System.GC.Collect();
 }
Exemple #5
0
 private void OnDestroy()
 {
     PipelineFunctions.Dispose(ref baseBuffer);
     shadMask.afterLightingBuffer.Dispose();
     Destroy(shadMask.shadowmaskMaterial);
 }
Exemple #6
0
 protected void OnDisable()
 {
     currentCam.RemoveCommandBuffer(CameraEvent.AfterLighting, shadMask.afterLightingBuffer);
     currentCam.RemoveCommandBuffer(CameraEvent.AfterGBuffer, baseBuffer.geometryCommand);
     PipelineFunctions.Dispose(ref baseBuffer);
 }