public UniformDefinition(string name, ActiveUniformType type, List <string> aliases, UniformValueContent value) { Name = name; Type = type; Aliases = new List <string>(aliases); Value = value; }
public MaterialContent CreateMaterial(ContentProcessorContext context, Dictionary <string, object> parameters) { MaterialContent content = new MaterialContent() { Name = _name }; int i = 0; foreach (PassTemplate template in _passes) { MaterialContent.Pass pass = new MaterialContent.Pass(string.IsNullOrEmpty(template.Name) ? string.Format("{0}_Pass_{1}", _name, i) : template.Name); pass.VertexShaderSources.AddRange(template.VertexShaders.Select(s => new ExternalReferenceContent <ShaderSourceContent>(s))); pass.FragmentShaderSources.AddRange(template.FragmentShaders.Select(s => new ExternalReferenceContent <ShaderSourceContent>(s))); foreach (UniformDefinition def in template.Variables) { UniformValueContent value = null; object o; if (!parameters.TryGetValue(def.Name, out o)) { foreach (string name in def.Aliases) { if (parameters.TryGetValue(name, out o)) { break; } } } if (o != null) { value = GetAsUniformValueContent(def.Type, def.Name, o, context); } if (value == null) // no match, or not able to convert to uniform type { value = def.Value; } pass.Parameters[def.Name] = value; } foreach (UniformDefinition def in template.Constants) { pass.Parameters[def.Name] = def.Value; } pass.ComparisonParameters = template.ComparisonParameters; i++; content.Passes.Add(pass); } return(content); }
public UniformDefinition(string name, ActiveUniformType type, UniformValueContent value) : this(name, type, new List <string>(), value) { }
private void GetMaterialParameters(Material material, Dictionary <string, object> parameters, ContentProcessorContext context) { foreach (Assimp.TextureType type in (Assimp.TextureType[])Enum.GetValues(typeof(Assimp.TextureType))) { if (type == Assimp.TextureType.None || type == Assimp.TextureType.Unknown || material.GetTextureCount(type) == 0) { continue; } TextureSlot tex = material.GetTexture(type, 0); // we dont handle multiple textures of a given type so just get the first one. string parameterName = ""; if (tex.TextureType == Assimp.TextureType.Normals) { parameterName = "NormalMap"; } else { parameterName = string.Format("{0}Map", tex.TextureType.ToString()); } SamplerContent sampler = new SamplerContent(); string path = File.Exists(tex.FilePath) ? tex.FilePath : Path.GetFileName(tex.FilePath); sampler.Texture = new ExternalReferenceContent <TextureContent>(context.ContentManager.ProcessorContext.GetFilenamePath(path), context.ContentManager) { ImporterData = new Dictionary <string, object>() { { "GenerateMipmaps", GenerateMipmaps }, { "PremultiplyAlpha", PremultiplyAlpha }, { "OutputType", OutputType } } }; sampler.WrapS = ConvertWrapMode(tex.WrapModeU); sampler.WrapT = ConvertWrapMode(tex.WrapModeV); parameters[parameterName] = new UniformValueContent(Minotaur.Graphics.UniformValueType.Sampler, new[] { sampler }); } if (material.HasBlendMode) { parameters["BlendMode"] = material.BlendMode; } if (material.HasBumpScaling) { parameters["BumpScaling"] = material.BumpScaling; } if (material.HasColorAmbient) { parameters["AmbientColor"] = ConvertColor(material.ColorAmbient); } if (material.HasColorDiffuse) { parameters["DiffuseColor"] = ConvertColor(material.ColorDiffuse); } if (material.HasColorEmissive) { parameters["EmissiveColor"] = ConvertColor(material.ColorEmissive); } if (material.HasColorReflective) { parameters["ReflectiveColor"] = ConvertColor(material.ColorReflective); } if (material.HasColorSpecular) { parameters["SpecularColor"] = ConvertColor(material.ColorSpecular); } if (material.HasColorTransparent) { parameters["TransparentColor"] = ConvertColor(material.ColorTransparent); } if (material.HasOpacity) { parameters["Opacity"] = material.Opacity; } if (material.HasReflectivity) { parameters["Reflectivity"] = material.Reflectivity; } if (material.HasShadingMode) { parameters["ShadingMode"] = material.ShadingMode; } if (material.HasShininess) { parameters["Shininess"] = material.Shininess; } if (material.HasShininessStrength) { parameters["ShininessStrength"] = material.ShininessStrength; } if (material.HasTwoSided) { parameters["TwoSided"] = material.IsTwoSided; } if (material.HasWireFrame) { parameters["WireFrame"] = material.IsWireFrameEnabled; } }