void Update()
    {
        // Spin the cube. Proves that the batch is reading the matrices just fine
        var transforms = _brg.GetBatchMatrices(_batch);

        transforms[0] = Matrix4x4.Rotate(Quaternion.Euler(Mathf.Sin(Time.time) * 180, Mathf.Sin(Time.time) * 180, Mathf.Cos(Time.time) * 180));

        // I thought this would set the color in the shader but it isn't working for me
        var instVals = _brg.GetBatchVectorArray(_batch, "_Color");

        instVals[0] = new Vector4(0, 1, 0, 1);
    }
Example #2
0
        private void RenderMeshes()
        {
            using (var chunks = _spriteWithMesh.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                var sharedSpriteMaterialType = GetArchetypeChunkSharedComponentType <SharedSpriteMaterialComponent>();
                var chunkSpriteMeshType      = GetArchetypeChunkComponentType <ChunkSpriteMeshComponent>(true);
                for (int chunkIdx = 0; chunkIdx < chunks.Length; chunkIdx++)
                {
                    var chunk           = chunks[chunkIdx];
                    var chunkSpriteMesh = chunk.GetChunkComponentData(chunkSpriteMeshType);
                    int chunkMeshId     = chunkSpriteMesh.ChunkMeshId;
                    var meshData        = _meshById[chunkMeshId];

                    if (meshData.MaterialVersion != LastSystemVersion)
                    {
                        continue;
                    }

                    int renderIndex = _meshIds.IndexOf(chunkMeshId);
                    if (renderIndex >= 0)
                    {
                        _renderGroup.RemoveBatch(renderIndex);
                        _meshIds.RemoveAtSwapBack(renderIndex);
                    }

                    var sharedSprite = chunk.GetSharedComponentData(sharedSpriteMaterialType, EntityManager);
                    renderIndex = _renderGroup.AddBatch(
                        meshData.Mesh,
                        subMeshIndex: 0,
                        sharedSprite.Material,
                        sharedSprite.Layer,
                        ShadowCastingMode.Off,
                        receiveShadows: false,
                        invertCulling: false,
                        meshData.Mesh.bounds,
                        instanceCount: 1,
                        customProps: null,
                        associatedSceneObject: null
                        );
                    Debug.Assert(renderIndex == _meshIds.Count);
                    _meshIds.Add(chunkMeshId);
                    var mvp = _renderGroup.GetBatchMatrices(renderIndex);
                    mvp[0] = float4x4.identity;
                }
            }
        }
Example #3
0
    private JobHandle CullingCallback(BatchRendererGroup rendererGroup, BatchCullingContext cullingContext)
    {
        var inputDependency = _jobDependency;

        for (var i = 0; i < cullingContext.batchVisibility.Length; ++i)
        {
            var job = new CullingJob
            {
                CullingContext = cullingContext,
                Matrices       = rendererGroup.GetBatchMatrices(i),
                BatchIndex     = i
            }.Schedule(inputDependency);

            // Jobの依存関係を更新
            _jobDependency = JobHandle.CombineDependencies(job, _jobDependency);
        }

        return(_jobDependency);
    }
Example #4
0
    private void Update()
    {
        jobDependency.Complete();

        var jobHandlers = new NativeList <JobHandle>(batchIndexes.Count, Allocator.Temp);

        foreach (var batchIndex in batchIndexes)
        {
            jobHandlers.Add(new UpdateMatrixJob
            {
                Matrices = batchRendererGroup.GetBatchMatrices(batchIndex),
                Time     = Time.time,
                Split    = split
            }.Schedule(split * split * split, 16));
        }

        jobDependency = JobHandle.CombineDependencies(jobHandlers);
        jobHandlers.Dispose();
    }