private ShaderEffectProtoPixel LookupMaterial(FusMaterial m) { if (_matMap.TryGetValue(m, out var sfx)) { return(sfx); } var vals = new MaterialValues(); if (m.HasNormalMap) { vals.NormalMap = m.NormalMap.Texture ?? null; vals.NormalMapIntensity = m.HasNormalMap ? m.NormalMap.Intensity : 0; } if (m.HasAlbedo) { vals.AlbedoColor = m.Albedo.Color; vals.AlbedoMix = m.Albedo.Mix; vals.AlbedoTexture = m.Albedo.Texture ?? null; } if (m.HasEmissive) { vals.EmissiveColor = m.Emissive.Color; vals.EmissiveMix = m.Emissive.Mix; vals.EmissiveTexture = m.Emissive.Texture ?? null; } if (m.HasSpecular) { vals.SpecularColor = m.Specular.Color; vals.SpecularMix = m.Specular.Mix; vals.SpecularTexture = m.Specular.Texture ?? null; vals.SpecularIntensity = m.Specular.Intensity; vals.SpecularShininess = m.Specular.Shininess; } sfx = ShaderCodeBuilder.MakeShaderEffectFromShaderEffectPropsProto( new ShaderEffectProps { MatProbs = { HasAlbedo = m.HasAlbedo, HasAlbedoTexture = m.HasAlbedo && m.Albedo.Texture != null, HasSpecular = m.HasSpecular, HasSpecularTexture = m.HasSpecular && m.Specular.Texture != null, HasEmissive = m.HasEmissive, HasEmissiveTexture = m.HasEmissive && m.Emissive.Texture != null, HasNormalMap = m.HasNormalMap }, MatType = MaterialType.Standard, MatValues = vals }); sfx.Name = m.Name ?? ""; _matMap.Add(m, sfx); return(sfx); }
public void ConvMaterial(FusMaterial matComp) { if (_currentNode.Components == null) { _currentNode.Components = new List <SceneComponent>(); } var effect = LookupMaterial(matComp); _currentNode.Components.Add(effect); }
public void ConvShaderEffect(ShaderEffect fx) { // TODO: FusMaterialPBR not yet implemented, needs to be done when blender export to principle BRDF shader is implemented properly var mat = new FusMaterial(); if (fx.ParamDecl.ContainsKey(UniformNameDeclarations.AlbedoColor)) { mat.Albedo = new MatChannelContainer(); } if (fx.ParamDecl.ContainsKey(UniformNameDeclarations.SpecularColor)) { mat.Specular = new SpecularChannelContainer(); } if (fx.ParamDecl.ContainsKey(UniformNameDeclarations.NormalMap)) { mat.NormalMap = new NormapMapChannelContainer(); } if (fx.ParamDecl.ContainsKey(UniformNameDeclarations.EmissiveColor)) { mat.Emissive = new MatChannelContainer(); } foreach (var decl in fx.ParamDecl) { switch (decl.Key) { case UniformNameDeclarations.AlbedoColor: mat.Albedo.Color = (float4)decl.Value; break; case UniformNameDeclarations.AlbedoTexture: mat.Albedo.Texture = (string)decl.Value; break; case UniformNameDeclarations.AlbedoMix: mat.Albedo.Mix = (float)decl.Value; break; case UniformNameDeclarations.EmissiveColor: mat.Emissive.Color = (float4)decl.Value; break; case UniformNameDeclarations.EmissiveTexture: mat.Emissive.Texture = (string)decl.Value; break; case UniformNameDeclarations.EmissiveMix: mat.Emissive.Mix = (float)decl.Value; break; case UniformNameDeclarations.SpecularColor: mat.Specular.Color = (float4)decl.Value; break; case UniformNameDeclarations.SpecularTexture: mat.Specular.Texture = (string)decl.Value; break; case UniformNameDeclarations.SpecularMix: mat.Specular.Mix = (float)decl.Value; break; case UniformNameDeclarations.SpecularShininess: mat.Specular.Shininess = (float)decl.Value; break; case UniformNameDeclarations.SpecularIntensity: mat.Specular.Intensity = (float)decl.Value; break; case UniformNameDeclarations.NormalMap: mat.NormalMap.Texture = (string)decl.Value; break; case UniformNameDeclarations.NormalMapIntensity: mat.NormalMap.Intensity = (float)decl.Value; break; } } _currentNode.AddComponent(mat); }