Exemplo n.º 1
0
        public override void ApplyBatchKeyMaterial(bool innerLayer)
        {
            DecrementTextureUsage();

            var modifiedBatchKey = BatchKey;

            if (sideEntity.NativeObject == null)
            {
                modifiedBatchKey.sourceMaterial =
                    MaterialGeneration_Geometry.GetMaterial(ShapeDescriptor.Empty,
                                                            transferMode: 0,
                                                            isOpaqueSurface: true,
                                                            MaterialGeneration_Geometry.SurfaceTypes.Normal,
                                                            incrementUsageCounter: false);
            }
            else if (innerLayer)
            {
                switch (dataSource)
                {
                case LevelEntity_Side.DataSources.Primary:
#if USE_TEXTURE_ARRAYS
                    modifiedBatchKey.sourceShapeDescriptor = sideEntity.NativeObject.Primary.Texture;
#endif
                    modifiedBatchKey.sourceMaterial =
                        MaterialGeneration_Geometry.GetMaterial(sideEntity.NativeObject.Primary.Texture,
                                                                sideEntity.NativeObject.PrimaryTransferMode,
                                                                sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                                                                MaterialGeneration_Geometry.SurfaceTypes.Normal,
                                                                incrementUsageCounter: true);

#if USE_TEXTURE_ARRAYS
                    lastTextureIndex = MaterialGeneration_Geometry.GetTextureArrayIndex(
                        sideEntity.NativeObject.Primary.Texture,
                        sideEntity.NativeObject.PrimaryTransferMode,
                        sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                        MaterialGeneration_Geometry.SurfaceTypes.Normal);
#endif

                    break;

                case LevelEntity_Side.DataSources.Secondary:
#if USE_TEXTURE_ARRAYS
                    modifiedBatchKey.sourceShapeDescriptor = sideEntity.NativeObject.Secondary.Texture;
#endif
                    modifiedBatchKey.sourceMaterial =
                        MaterialGeneration_Geometry.GetMaterial(sideEntity.NativeObject.Secondary.Texture,
                                                                sideEntity.NativeObject.SecondaryTransferMode,
                                                                sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                                                                MaterialGeneration_Geometry.SurfaceTypes.Normal,
                                                                incrementUsageCounter: true);

#if USE_TEXTURE_ARRAYS
                    lastTextureIndex = MaterialGeneration_Geometry.GetTextureArrayIndex(
                        sideEntity.NativeObject.Secondary.Texture,
                        sideEntity.NativeObject.SecondaryTransferMode,
                        sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                        MaterialGeneration_Geometry.SurfaceTypes.Normal);
#endif

                    break;

                case LevelEntity_Side.DataSources.Transparent:

#if USE_TEXTURE_ARRAYS
                    modifiedBatchKey.sourceShapeDescriptor = sideEntity.NativeObject.Transparent.Texture;
#endif
                    modifiedBatchKey.sourceMaterial =
                        MaterialGeneration_Geometry.GetMaterial(sideEntity.NativeObject.Transparent.Texture,
                                                                sideEntity.NativeObject.TransparentTransferMode,
                                                                sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                                                                MaterialGeneration_Geometry.SurfaceTypes.Normal,
                                                                incrementUsageCounter: true);

#if USE_TEXTURE_ARRAYS
                    lastTextureIndex = MaterialGeneration_Geometry.GetTextureArrayIndex(
                        sideEntity.NativeObject.Transparent.Texture,
                        sideEntity.NativeObject.TransparentTransferMode,
                        sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                        MaterialGeneration_Geometry.SurfaceTypes.Normal);
#endif

                    break;

                default:
                    throw new NotImplementedException($"DataSource '{dataSource}' is not implemented.");
                }
            }
            else
            {
#if USE_TEXTURE_ARRAYS
                modifiedBatchKey.layeredTransparentSideShapeDescriptor = sideEntity.NativeObject.Transparent.Texture;
#endif
                modifiedBatchKey.layeredTransparentSideSourceMaterial =
                    MaterialGeneration_Geometry.GetMaterial(sideEntity.NativeObject.Transparent.Texture,
                                                            sideEntity.NativeObject.TransparentTransferMode,
                                                            sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                                                            MaterialGeneration_Geometry.SurfaceTypes.LayeredTransparentOuter,
                                                            incrementUsageCounter: true);

#if USE_TEXTURE_ARRAYS
                lastLayeredTransparentSideTextureIndex = MaterialGeneration_Geometry.GetTextureArrayIndex(
                    sideEntity.NativeObject.Transparent.Texture,
                    sideEntity.NativeObject.TransparentTransferMode,
                    sideEntity.NativeObject.SurfaceShouldBeOpaque(dataSource, sideEntity.ParentLevel.Level),
                    MaterialGeneration_Geometry.SurfaceTypes.LayeredTransparentOuter);
#endif
            }

            if (innerLayer)
            {
                var UVs = SurfaceMesh.uv.Select(uv => new Vector4(uv.x, uv.y, lastLightIndex, lastTextureIndex)).ToArray();
                SurfaceMesh.SetUVs(0, UVs);
            }
            else
            {
                var UVs = SurfaceMesh.uv.Select(uv => new Vector4(uv.x, uv.y, lastLayeredTransparentSideLightIndex, lastLayeredTransparentSideTextureIndex)).ToArray();
                SurfaceMesh.SetUVs(1, UVs);
            }

            BatchKey = modifiedBatchKey;
        }
Exemplo n.º 2
0
        public override void ApplyBatchKeyMaterial(bool innerLayer = true)
        {
            DecrementTextureUsage();

            var modifiedBatchKey = BatchKey;

            switch (dataSource)
            {
            case LevelEntity_Polygon.DataSources.Floor:
#if USE_TEXTURE_ARRAYS
                modifiedBatchKey.sourceShapeDescriptor = polygonEntity.NativeObject.FloorTexture;
#endif
                modifiedBatchKey.sourceMaterial =
                    MaterialGeneration_Geometry.GetMaterial(
                        polygonEntity.NativeObject.FloorTexture,
                        polygonEntity.NativeObject.FloorTransferMode,
                        isOpaqueSurface: true,
                        MaterialGeneration_Geometry.SurfaceTypes.Normal,
                        incrementUsageCounter: true);

#if USE_TEXTURE_ARRAYS
                lastTextureIndex = MaterialGeneration_Geometry.GetTextureArrayIndex(
                    polygonEntity.NativeObject.FloorTexture,
                    polygonEntity.NativeObject.FloorTransferMode,
                    isOpaqueSurface: true,
                    MaterialGeneration_Geometry.SurfaceTypes.Normal);
#endif

                break;

            case LevelEntity_Polygon.DataSources.Ceiling:
#if USE_TEXTURE_ARRAYS
                modifiedBatchKey.sourceShapeDescriptor = polygonEntity.NativeObject.CeilingTexture;
#endif
                modifiedBatchKey.sourceMaterial =
                    MaterialGeneration_Geometry.GetMaterial(
                        polygonEntity.NativeObject.CeilingTexture,
                        polygonEntity.NativeObject.CeilingTransferMode,
                        isOpaqueSurface: true,
                        MaterialGeneration_Geometry.SurfaceTypes.Normal,
                        incrementUsageCounter: true);

#if USE_TEXTURE_ARRAYS
                lastTextureIndex = MaterialGeneration_Geometry.GetTextureArrayIndex(
                    polygonEntity.NativeObject.CeilingTexture,
                    polygonEntity.NativeObject.CeilingTransferMode,
                    isOpaqueSurface: true,
                    MaterialGeneration_Geometry.SurfaceTypes.Normal);
#endif

                break;

            case LevelEntity_Polygon.DataSources.Media:
                var mediaShapeDescriptor = new ShapeDescriptor((ushort)polygonEntity.NativeObject.FloorTexture);

                switch (BatchKey.sourceMedia.NativeObject.Type)
                {
                case MediaType.Water:
                    mediaShapeDescriptor.Collection = 17;
                    mediaShapeDescriptor.Bitmap     = 19;
                    break;

                case MediaType.Lava:
                    mediaShapeDescriptor.Collection = 18;
                    mediaShapeDescriptor.Bitmap     = 12;
                    break;

                case MediaType.Goo:
                    mediaShapeDescriptor.Collection = 21;
                    mediaShapeDescriptor.Bitmap     = 5;
                    break;

                case MediaType.Sewage:
                    mediaShapeDescriptor.Collection = 19;
                    mediaShapeDescriptor.Bitmap     = 13;
                    break;

                case MediaType.Jjaro:
                    mediaShapeDescriptor.Collection = 20;
                    mediaShapeDescriptor.Bitmap     = 13;
                    break;
                }

#if USE_TEXTURE_ARRAYS
                modifiedBatchKey.sourceShapeDescriptor = mediaShapeDescriptor;
#endif
                modifiedBatchKey.sourceMaterial =
                    MaterialGeneration_Geometry.GetMaterial(
                        mediaShapeDescriptor,
                        (short)TransferModes.Normal,
                        isOpaqueSurface: true,
                        MaterialGeneration_Geometry.SurfaceTypes.Media,
                        incrementUsageCounter: false);

#if USE_TEXTURE_ARRAYS
                lastTextureIndex = MaterialGeneration_Geometry.GetTextureArrayIndex(
                    mediaShapeDescriptor,
                    (short)TransferModes.Normal,
                    isOpaqueSurface: true,
                    MaterialGeneration_Geometry.SurfaceTypes.Media);
#endif

                break;

            default:
                throw new NotImplementedException($"DataSource '{dataSource}' is not implemented.");
            }

            var UVs = SurfaceMesh.uv.Select(uv => new Vector4(uv.x, uv.y, lastLightIndex, lastTextureIndex)).ToArray();
            SurfaceMesh.SetUVs(0, UVs);

            BatchKey = modifiedBatchKey;
        }