public static TextureMapper Load(Utility utility)
        {
            var tm = new TextureMapper();

            CGFXDebug.LoadStart(tm, utility);

            tm.TypeId = utility.ReadU32();
            if (tm.TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"TextureMapper: Expected type 0x80000000, got {tm.TypeId}");
            }

            tm.DynamicAllocator = utility.ReadU32();

            // Texture Reference
            tm.TextureReference = utility.LoadDICTObj <TextureReference>();

            // Sampler
            utility.LoadIndirect(() =>
            {
                tm.TextureSampler = TextureSampler.Load(tm, utility);
            });

            tm.Commands       = utility.ReadUInts(14);
            tm.CommandsLength = utility.ReadU32();  // Seems to be length of the aforementioned "Commands"?

            // I think this is a fair sanity check??
            if (tm.CommandsLength != (14 * 4))
            {
                throw new InvalidOperationException("CommandsLength mismatch");
            }

            return(tm);
        }
Example #2
0
        public static TextureSampler Load(TextureMapper parent, Utility utility)
        {
            var s = new TextureSampler();

            CGFXDebug.LoadStart(s, utility);

            // This has a TypeId here...
            s.TypeId = utility.ReadU32();
            if (s.TypeId != 0x80000000)
            {
                throw new InvalidOperationException($"TextureSampler: Expected type 0x80000000, got {s.TypeId}");
            }

            // Just reading the offset but we'll resolve this later
            var ownerModelOffset = utility.ReadOffset();

            s.Parent = parent;

            s.MinFilter = (TextureMinFilter)utility.ReadU32();

            s.BorderColor = ColorFloat.Read(utility);
            s.LODBias     = utility.ReadFloat();

            return(s);
        }
        public override void Load(Utility utility)
        {
            base.Load(utility);

            MaterialFlags = utility.ReadU32();

            TextureCoordinatesConfig = (TextCoordConfig)utility.ReadU32();
            TranslucencyKind         = (TranslucencyKind)utility.ReadU32();

            MaterialColor     = MaterialColorContainer.Load(utility);
            Rasterization     = RasterizationContainer.Load(utility);
            FragmentOperation = FragmentOperationContainer.Load(utility);

            // Texture coordinates
            UsedTextureCoordinates = utility.ReadU32();     // ???
            TextureCoords          = new TextureCoord[3];

            for (var i = 0; i < TextureCoords.Length; i++)
            {
                var textureCoord = new TextureCoord
                {
                    SourceCoordIndex     = utility.ReadI32(),
                    MappingType          = (TextureCoord.TextureMappingType)utility.ReadU32(),
                    ReferenceCameraIndex = utility.ReadI32(),
                    TransformType        = (TextureCoord.TextureTransformType)utility.ReadU32(),
                    Scale       = Vector2.Read(utility),
                    Rotation    = utility.ReadFloat(),
                    Translation = Vector2.Read(utility),
                    Flags       = utility.ReadU32(),
                    Transform   = Matrix.Read(utility),
                };

                TextureCoords[i] = textureCoord;
            }

            // Texture mappers
            TextureMappers = new TextureMapper[4];
            for (var i = 0; i < TextureMappers.Length; i++)
            {
                utility.LoadIndirect(() =>
                {
                    if (i < 3)
                    {
                        TextureMappers[i] = TextureMapper.Load(utility);
                    }
                    else
                    {
                        // FIXME -- "Procedural texture mapper" ???
                        // Not implemented at all in Ohana3DS
                        // According to SPICA, this is what the fourth slot points to, however
                        throw new NotImplementedException("Procedural texture mapper not implemented");
                    }
                });
            }


            ShaderReference = utility.LoadDICTObj <ShaderReference>();

            utility.LoadIndirect(() =>
            {
                FragmentShader = FragmentShader.Load(utility);
            });

            ShaderProgramDescIndex = utility.ReadI32();

            // NOT SUPPORTED
            ShaderParametersCount = utility.ReadU32();
            ShaderParametersPointerTableOffset = utility.ReadOffset();
            if (ShaderParametersCount != 0 || ShaderParametersPointerTableOffset != 0)
            {
                throw new NotImplementedException($"ModelMaterial Load: Shader Parameters UNSUPPORTED");
            }


            LightSetIndex = utility.ReadI32(); // Reference??
            FogIndex      = utility.ReadI32(); // Reference??

            // NOTE -- See SPICA GfxMaterial.cs for computations involving these hash functions.
            // I ASSUME if I never change any values in the material these never need recomputed.
            // Let's try to get by without needing this support right now...
            MaterialFlagsHash      = utility.ReadU32();
            ShaderParamsHash       = utility.ReadU32();
            TextureCoordsHash      = utility.ReadU32();
            TextureSamplersHash    = utility.ReadU32();
            TextureMappersHash     = utility.ReadU32();
            MaterialColorsHash     = utility.ReadU32();
            RasterizationHash      = utility.ReadU32();
            FragLightHash          = utility.ReadU32();
            FragLightLUTHash       = utility.ReadU32();
            FragLightLUTSampHash   = utility.ReadU32();
            TextureEnvironmentHash = utility.ReadU32();
            AlphaTestHash          = utility.ReadU32();
            FragOpHash             = utility.ReadU32();
            UniqueId = utility.ReadU32();
        }