private IMaterialAsset TransformMaterial(Material material, string id, ReaderContext context) { var materialAsset = new MaterialAsset(id); materialAsset.AlphaCutoff = material.AlphaCutoff; materialAsset.Alpha = GetAlphaMode(material.Alpha); materialAsset.DoubleSided = material.DoubleSided; materialAsset.Unlit = material.Unlit; var shaderParameters = material.Channels.Select(_ => TransformShaderParameter(_, context)).SelectMany(_ => _) .ToDictionary(_ => _.Key, _ => _); var metallicRoughness = 0; var specularGlossiness = 0; foreach (var shaderParameter in shaderParameters) { switch (shaderParameter.Key) { case ShaderParameterKey.BaseColorFactor: case ShaderParameterKey.BaseColorTexture: case ShaderParameterKey.MetallicFactor: case ShaderParameterKey.MetallicRoughnessTexture: ++metallicRoughness; break; case ShaderParameterKey.DiffuseFactor: case ShaderParameterKey.DiffuseTexture: case ShaderParameterKey.SpecularFactor: case ShaderParameterKey.GlossinessFactor: case ShaderParameterKey.SpecularGlossinessTexture: ++specularGlossiness; break; } } if (metallicRoughness > 0 && specularGlossiness == 0) { var shader = new MetallicRoughnessShader(); materialAsset.Shader = shader; } else if (metallicRoughness == 0 && specularGlossiness >= 0) { var shader = new SpecularGlossinessShader(); materialAsset.Shader = shader; } else { var shader = new ShaderAsset(); materialAsset.Shader = shader; } foreach (var shaderParameter in shaderParameters) { materialAsset.Shader.Set(shaderParameter.Value); } return(materialAsset); }
private void SetupMetallicRoughnessShader(Material material, MetallicRoughnessShader shader, WriterContext context) { material = material.WithPBRMetallicRoughness(); SetupDefaultShader(material, shader, context); TrySetupTexture(material, "BaseColor", shader.BaseColorTexture, context); material.WithChannelParameter("BaseColor", shader.BaseColorFactor); TrySetupTexture(material, "MetallicRoughness", shader.MetallicRoughnessTexture, context); material.WithChannelParameter("MetallicRoughness", new Vector4(shader.MetallicFactor, shader.RoughnessFactor, 0, 0)); }