コード例 #1
0
 protected override void OnUpdate()
 {
     for (int index = 0; index < terrainDataGroup.sectors.Length; index++)
     {
         var sector    = terrainDataGroup.sectors[index];
         var heightmap = chunkAssets.GetHeightmapTex(sector);
         var normalmap = chunkAssets.GetNormalmapTex(sector);
         var splatmap  = chunkAssets.GetSplatmapTex(sector);
         var baseColor = chunkAssets.GetBaseColorTex(sector);
         materialBlock.SetTexture(_HeightMap0, heightmap);
         materialBlock.SetTexture(_NormalMap0, normalmap);
         materialBlock.SetTexture(_LayerMaskMap, splatmap);
         materialBlock.SetTexture(_BaseColor0, baseColor);
         materialBlock.SetVector(_Sector, new Vector4(sector.value.x, sector.value.y, 0, 0));
         materialBlock.SetFloat(_HeightAmplitude0, WorldChunkConstants.TerrainHeightScale);
         RenderHelpers.CopyMatrices(terrainDataGroup.transforms, index, 1, RenderHelpers.matricesArray);
         Graphics.DrawMeshInstanced(gridMesh, 0, material, RenderHelpers.matricesArray, 1, materialBlock, /*castShadows*/ ShadowCastingMode.On, /*receiveShadows*/ true);
     }
 }
コード例 #2
0
        protected override void OnUpdate()
        {
            EntityManager.GetAllUniqueSharedComponentDatas(cacheduniqueRendererTypes);
            var forEachFilter = renderGroup.CreateForEachFilter(cacheduniqueRendererTypes);

            for (int i = 0; i != cacheduniqueRendererTypes.Count; i++)
            {
                var renderer   = cacheduniqueRendererTypes[i];
                var transforms = renderGroup.GetComponentDataArray <Transform>(forEachFilter, i);

                if (renderer.mesh == null)
                {
                    continue;
                }

                for (int temp = 0; temp < transforms.Length; ++temp)
                {
                    RenderHelpers.CopyMatrices(transforms, temp, 1, RenderHelpers.matricesArray);

                    var materials = new Material[] { renderer.material0, renderer.material1, renderer.material2 };
                    for (int subpart = 0; subpart < renderer.materialCount; ++subpart)
                    {
                        Graphics.DrawMeshInstanced(renderer.mesh, subpart, materials[subpart], RenderHelpers.matricesArray, 1, null, /*castShadows*/ ShadowCastingMode.On, /*receiveShadows*/ true);
                    }
                }

                /*
                 * int beginIndex = 0;
                 * while (beginIndex < transforms.Length)
                 * {
                 *  //int length = math.min(RenderHelpers.matricesArray.Length, transforms.Length - beginIndex);
                 *  //RenderHelpers.CopyMatrices(transforms, beginIndex, length, RenderHelpers.matricesArray);
                 *  //Graphics.DrawMeshInstanced(renderer.mesh, 0, renderer.material, RenderHelpers.matricesArray, length, null, /*castShadows* /ShadowCastingMode.On, /*receiveShadows* /true);
                 *
                 *  beginIndex += length;
                 * }
                 */
            }

            cacheduniqueRendererTypes.Clear();
            forEachFilter.Dispose();
        }