Example #1
0
        public void SetShaderParameter(string name, ShaderParamType type, object value)
        {
            ShaderParam param = new ShaderParam();

            param.Name      = name;
            param.DataValue = value;
            param.Type      = type;

            if (!ShaderParams.ContainsKey(name))
            {
                ShaderParams.Add(name, param);
            }
            else
            {
                ShaderParams[name] = param;
            }
        }
Example #2
0
        public void Reload(Material material)
        {
            ShaderArchive = "";
            ShaderModel   = "";
            ShaderParams.Clear();
            ShaderOptions.Clear();
            Samplers.Clear();
            TextureMaps.Clear();

            UpdateRenderState();

            if (material.ShaderAssign != null)
            {
                ShaderArchive = material.ShaderAssign.ShaderArchiveName;
                ShaderModel   = material.ShaderAssign.ShadingModelName;
            }

            foreach (var param in material.ShaderParams)
            {
                ShaderParams.Add(param.Key, param.Value);
            }
            foreach (var option in material.ShaderAssign.ShaderOptions)
            {
                ShaderOptions.Add(option.Key, option.Value);
            }

            // if (ShaderParams.ContainsKey("gsys_i_color_ratio0"))
            //   ShaderParams["gsys_i_color_ratio0"].DataValue = 0.1f;

            for (int i = 0; i < material.TextureRefs.Count; i++)
            {
                string  name        = material.TextureRefs[i].Name;
                Sampler sampler     = material.Samplers[i];
                var     texSampler  = material.Samplers[i].TexSampler;
                string  samplerName = sampler.Name;
                string  fragSampler = "";

                //Force frag shader sampler to be used
                if (material.ShaderAssign.SamplerAssigns.ContainsValue(samplerName))
                {
                    material.ShaderAssign.SamplerAssigns.TryGetKey(samplerName, out fragSampler);
                }

                Samplers.Add(fragSampler);

                this.TextureMaps.Add(new TextureMap()
                {
                    Name      = name,
                    Sampler   = samplerName,
                    MagFilter = GXConverter.ConvertMagFilter(texSampler.MagFilter),
                    MinFilter = GXConverter.ConvertMinFilter(
                        texSampler.MipFilter,
                        texSampler.MinFilter),
                    Type    = GetTextureType(fragSampler),
                    WrapU   = GXConverter.ConvertWrapMode(texSampler.ClampX),
                    WrapV   = GXConverter.ConvertWrapMode(texSampler.ClampY),
                    LODBias = texSampler.LodBias,
                    MaxLOD  = texSampler.MaxLod,
                    MinLOD  = texSampler.MinLod,
                });
            }
        }