Exemplo n.º 1
0
            public ShaderStage(FileReader reader)
            {
                Type = (ShaderType)reader.ReadUInt32();

                uint numParams = reader.ReadUInt32();

                Uniforms = new UniformParam[numParams];
                for (int i = 0; i < numParams; i++)
                {
                    Uniforms[i] = new UniformParam(reader);
                }

                uint numSamplers = reader.ReadUInt32();

                Samplers = new SamplerParam[numSamplers];
                for (int i = 0; i < numSamplers; i++)
                {
                    Samplers[i] = new SamplerParam(reader);
                }

                foreach (var uniform in Uniforms)
                {
                    UniformData.Add(uniform.Name, uniform.Data);
                }
            }
Exemplo n.º 2
0
        public static BSMATMaterialFile Import(string text)
        {
            var conv  = new Newtonsoft.Json.Converters.StringEnumConverter();
            var bsmat = JsonConvert.DeserializeObject <BSMATMaterialFile>(text, conv);

            foreach (var stage in bsmat.ShaderStages)
            {
                List <UniformParam> uniformList = new List <UniformParam>();
                foreach (var uniform in stage.UniformData)
                {
                    var uniformParam = new UniformParam();
                    uniformList.Add(uniformParam);

                    uniformParam.Name = uniform.Key;

                    //Basic type define via the start of uniform name.
                    //All params have starting characters (f float, i int, v vec, etc)
                    uniformParam.DataType = ParamType.Float;
                    if (uniform.Key.StartsWith("i"))
                    {
                        uniformParam.DataType = ParamType.Int;
                    }

                    //Turn the data into normal array objects
                    if (uniformParam.DataType == ParamType.Float)
                    {
                        uniformParam.Data = ((Newtonsoft.Json.Linq.JArray)uniform.Value).ToObject <float[]>();
                    }
                    if (uniformParam.DataType == ParamType.Int)
                    {
                        uniformParam.Data = ((Newtonsoft.Json.Linq.JArray)uniform.Value).ToObject <int[]>();
                    }
                }
                stage.Uniforms = uniformList.ToArray();
            }
            return(bsmat);
        }