Esempio n. 1
0
    public InstancedSkinningDrawer(TextureAnimatorSystem.DataPerUnitType data, Mesh meshToDraw)
    {
        this.data     = data;
        this.mesh     = meshToDraw;
        this.material = new Material(data.Material);

        argsBuffer      = new ComputeBuffer(1, indirectArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
        indirectArgs[0] = mesh.GetIndexCount(0);
        indirectArgs[1] = (uint)0;
        argsBuffer.SetData(indirectArgs);

        objectRotationsBuffer    = new ComputeBuffer(PreallocatedBufferSize, 16);
        objectPositionsBuffer    = new ComputeBuffer(PreallocatedBufferSize, 16);
        textureCoordinatesBuffer = new ComputeBuffer(PreallocatedBufferSize, 12);

        TextureCoordinates = new NativeList <float3>(PreallocatedBufferSize, Allocator.Persistent);
        ObjectPositions    = new NativeList <float4>(PreallocatedBufferSize, Allocator.Persistent);
        ObjectRotations    = new NativeList <quaternion>(PreallocatedBufferSize, Allocator.Persistent);

        material.SetBuffer("textureCoordinatesBuffer", textureCoordinatesBuffer);
        material.SetBuffer("objectPositionsBuffer", objectPositionsBuffer);
        material.SetBuffer("objectRotationsBuffer", objectRotationsBuffer);
        material.SetTexture("_AnimationTexture0", data.BakedData.Texture0);
        material.SetTexture("_AnimationTexture1", data.BakedData.Texture1);
        material.SetTexture("_AnimationTexture2", data.BakedData.Texture2);
    }
Esempio n. 2
0
    public unsafe InstancedSkinningDrawer(TextureAnimatorSystem.DataPerUnitType data, Mesh meshToDraw)
    {
        this.data     = data;
        this.mesh     = meshToDraw;
        this.material = new Material(data.Material);

        argsBuffer      = new ComputeBuffer(1, indirectArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
        indirectArgs[0] = mesh.GetIndexCount(0);
        indirectArgs[1] = (uint)0;
        argsBuffer.SetData(indirectArgs);

        objectRotationsBuffer    = new ComputeBuffer(PreallocatedBufferSize, 16);
        objectPositionsBuffer    = new ComputeBuffer(PreallocatedBufferSize, 16);
        textureCoordinatesBuffer = new ComputeBuffer(PreallocatedBufferSize, 12);

#if !USE_SAFE_JOBS
        TextureCoordinates = new NativeArray <float3>(PreallocatedBufferSize, Allocator.Persistent);
        ObjectPositions    = new NativeArray <float4>(PreallocatedBufferSize, Allocator.Persistent);
        ObjectRotations    = new NativeArray <float4>(PreallocatedBufferSize, Allocator.Persistent);
#else
        TextureCoordinates = new NativeList <float3>(PreallocatedBufferSize, Allocator.Persistent);
        ObjectPositions    = new NativeList <float4>(PreallocatedBufferSize, Allocator.Persistent);
        ObjectRotations    = new NativeList <quaternion>(PreallocatedBufferSize, Allocator.Persistent);
#endif

#if !USE_SAFE_JOBS
        BufferPointers = new NativeArray <IntPtr>(3, Allocator.Persistent);

        BufferPointers[0] = ObjectPositions.GetUnsafeBufferPointerWithoutChecks();
        BufferPointers[1] = ObjectRotations.GetUnsafeBufferPointerWithoutChecks();
        BufferPointers[2] = TextureCoordinates.GetUnsafeBufferPointerWithoutChecks();
        BufferCounter     = new IntHolder(Allocator.Persistent);
#endif

        material.SetBuffer("textureCoordinatesBuffer", textureCoordinatesBuffer);
        material.SetBuffer("objectPositionsBuffer", objectPositionsBuffer);
        material.SetBuffer("objectRotationsBuffer", objectRotationsBuffer);
        material.SetTexture("_AnimationTexture0", data.BakedData.Texture0);
        material.SetTexture("_AnimationTexture1", data.BakedData.Texture1);
        material.SetTexture("_AnimationTexture2", data.BakedData.Texture2);
    }