public ShaderContent Build() { ShaderContent content = new ShaderContent(); dynamic units = _compilerEngine.units; foreach (dynamic unit in units) { foreach (dynamic shader in unit.shaders) content.Add(new ShaderEntry(shader)); } return content; }
static MaterialContent GetMaterialFromMaterial(SurfaceMaterial material, ShaderContent vertexShaderStage, ShaderContent fragmentShaderStage, IContentImporter importer, string filename) { var shaderTuple = new Tuple <ShaderContent, ShaderContent>(vertexShaderStage, fragmentShaderStage); if (_materialsCache.ContainsKey(material) && _materialsCache[material].ContainsKey(shaderTuple)) { return(_materialsCache[material][shaderTuple]); } if (!_materialsCache.ContainsKey(material)) { _materialsCache[material] = new Dictionary <Tuple <ShaderContent, ShaderContent>, MaterialContent>(); } var material2 = new MaterialContent(); material2.VertexShader = vertexShaderStage; material2.FragmentShader = fragmentShaderStage; material2.Alpha = 1; material2.DiffuseColor = new Vector3(0.5f, 0.5f, 0.5f); material2.Name = material.Name; Property diffuseProp; Property emissiveProp; Property textureProp; if (material is SurfaceLambert) { var lambert = material as SurfaceLambert; diffuseProp = GetMaterialColorProperty(lambert, "Diffuse", lambert.Diffuse); emissiveProp = GetMaterialColorProperty(lambert, "Emissive", lambert.Emissive); textureProp = FindTextureProperty(lambert, "Diffuse", lambert.Diffuse); } else { diffuseProp = GetMaterialColorProperty(material, "Diffuse"); emissiveProp = GetMaterialColorProperty(material, "Emissive"); textureProp = FindTextureProperty(material, "Diffuse"); } if (diffuseProp != null) { material2.DiffuseColor = GetPropertyValue(diffuseProp); } if (emissiveProp != null) { material2.EmissiveColor = GetPropertyValue(emissiveProp); } if (textureProp != null) { var tex = GetMaterialTexture(textureProp, importer, filename); if (tex != null) { material2.Texture = tex; } } if (material is SurfacePhong) { var phong = material as SurfacePhong; var specularProp = GetMaterialColorProperty(phong, "Specular", phong.Specular); if (specularProp != null) { material2.SpecularColor = GetPropertyValue(specularProp); var props = phong.FindProperties( p => p.Name.ToLower() == "shininessexponent" || p.Name.ToLower() == "shininess"); double shininess = 0; foreach (var prop in props) { if (prop.PropertyDataType == typeof(double)) { shininess = prop.Get <double>(); if (shininess > 0) { break; } } } material2.SpecularPower = (float)shininess; } } if (material is SurfaceLambert) { var transparencyFactor = (material as SurfaceLambert).TransparencyFactor; if (transparencyFactor != null) { material2.Alpha = (float)(1 - transparencyFactor.Get()); } } _materialsCache[material][shaderTuple] = material2; return(material2); }