예제 #1
0
        private void ExportSpecularGlossiness(AssetContext asset, SpecularGlossinessShaderArguments arguments)
        {
            using (var writer = asset.DestinationFolder.CreateXml(asset.UrhoAssetName))
            {
                if (writer == null)
                {
                    return;
                }
                writer.WriteStartDocument();
                writer.WriteWhitespace(Environment.NewLine);
                writer.WriteStartElement("material");
                writer.WriteWhitespace(Environment.NewLine);

                if (arguments.Diffuse != null)
                {
                    // Albedo
                    if (arguments.PBRSpecular != null)
                    {
                        // Albedo, MetallicGloss
                        if (arguments.Bump != null)
                        {
                            // Albedo, MetallicGloss, Normal
                            if (arguments.Emission)
                            {
                                // Albedo, MetallicGloss, Normal, Emission
                                if (arguments.Transparent)
                                {
                                    WriteTechnique(writer,
                                                   "Techniques/PBR/PBRMetallicRoughDiffNormalSpecEmissiveAlpha.xml");
                                }
                                else
                                {
                                    WriteTechnique(writer, "Techniques/PBR/PBRMetallicRoughDiffNormalSpecEmissive.xml");
                                }
                                WriteTexture(arguments.Emission, writer, "emissive");
                            }
                            else
                            {
                                // Albedo, MetallicGloss, Normal, No Emission
                                if (arguments.Transparent)
                                {
                                    WriteTechnique(writer, "Techniques/PBR/PBRMetallicRoughDiffNormalSpecAlpha.xml");
                                }
                                else
                                {
                                    WriteTechnique(writer, "Techniques/PBR/PBRMetallicRoughDiffNormalSpec.xml");
                                }
                            }

                            WriteTexture(arguments.Bump, writer, "normal");
                        }
                        else
                        {
                            // Albedo, MetallicGloss, No Normal
                            if (arguments.Transparent)
                            {
                                WriteTechnique(writer, "Techniques/PBR/PBRMetallicRoughDiffSpecAlpha.xml");
                            }
                            else
                            {
                                WriteTechnique(writer, "Techniques/PBR/PBRMetallicRoughDiffSpec.xml");
                            }
                        }

                        if (_assets.TryGetTexturePath(arguments.PBRSpecular, out var baseAssetName))
                        {
                            var textureReferences = new TextureReferences(TextureSemantic.PBRSpecularGlossiness, 1.0f,
                                                                          arguments.SmoothnessTextureChannel == SmoothnessTextureChannel.AlbedoAlpha
                                    ? arguments.Diffuse
                                    : arguments.PBRSpecular, arguments.SmoothnessTextureChannel);
                            var textureOutputName =
                                TextureExporter.GetTextureOutputName(baseAssetName, textureReferences);
                            WriteTexture(textureOutputName, writer, "specular");
                        }
                    }
                    else
                    {
                        // Albedo, No MetallicGloss
                        if (arguments.Bump != null)
                        {
                            // Albedo, No MetallicGloss, Normal
                            if (arguments.Emission != null)
                            {
                                // Albedo, No MetallicGloss, Normal, Emission
                                if (arguments.Transparent)
                                {
                                    WriteTechnique(writer, "Techniques/PBR/PBRDiffNormalEmissiveAlpha.xml");
                                }
                                else
                                {
                                    WriteTechnique(writer, "Techniques/PBR/PBRDiffNormalEmissive.xml");
                                }
                                WriteTexture(arguments.Emission, writer, "emissive");
                            }
                            else
                            {
                                // Albedo, No MetallicGloss, Normal, No Emission
                                if (arguments.Transparent)
                                {
                                    WriteTechnique(writer, "Techniques/PBR/PBRDiffNormalAlpha.xml");
                                }
                                else
                                {
                                    WriteTechnique(writer, "Techniques/PBR/PBRDiffNormal.xml");
                                }
                            }

                            WriteTexture(arguments.Bump, writer, "normal");
                        }
                        else
                        {
                            // Albedo, No MetallicGloss, No Normal
                            if (arguments.Transparent)
                            {
                                WriteTechnique(writer, "Techniques/PBR/PBRDiffAlpha.xml");
                            }
                            else
                            {
                                WriteTechnique(writer, "Techniques/PBR/PBRDiff.xml");
                            }
                        }
                    }

                    if (_assets.TryGetTexturePath(arguments.Diffuse, out var diffuseName))
                    {
                        var textureReferences = new TextureReferences(TextureSemantic.PBRDiffuse, 1.0f,
                                                                      arguments.PBRSpecular, arguments.SmoothnessTextureChannel);
                        var textureOutputName = TextureExporter.GetTextureOutputName(diffuseName, textureReferences);
                        WriteTexture(textureOutputName, writer, "diffuse");
                    }
                }
                else
                {
                    // No albedo
                    if (arguments.Transparent)
                    {
                        WriteTechnique(writer, "Techniques/PBR/PBRNoTextureAlpha.xml");
                    }
                    else
                    {
                        WriteTechnique(writer, "Techniques/PBR/PBRNoTexture.xml");
                    }
                }

                WriteParameter(writer, "MatDiffColor", BaseNodeExporter.Format(arguments.DiffuseColor));
                if (arguments.HasEmission)
                {
                    WriteParameter(writer, "MatEmissiveColor", BaseNodeExporter.FormatRGB(arguments.EmissiveColor));
                }
                WriteParameter(writer, "MatEnvMapColor", BaseNodeExporter.FormatRGB(Color.white));
                WriteParameter(writer, "MatSpecColor", BaseNodeExporter.Format(Vector4.zero));
                if (arguments.PBRSpecular != null)
                {
                    WriteParameter(writer, "Roughness", BaseNodeExporter.Format(0));
                    WriteParameter(writer, "Metallic", BaseNodeExporter.Format(0));
                }
                else
                {
                    ////TODO: Evaluate correct parameters:
                    WriteParameter(writer, "Roughness", BaseNodeExporter.Format(0.0f));
                    WriteParameter(writer, "Metallic", BaseNodeExporter.Format(0.0f));
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
예제 #2
0
        private void ExportLegacy(AssetContext asset, LegacyShaderArguments arguments)
        {
            using (var writer = asset.DestinationFolder.CreateXml(asset.UrhoAssetName))
            {
                if (writer == null)
                {
                    return;
                }
                writer.WriteStartDocument();
                writer.WriteWhitespace(Environment.NewLine);

                var flags = new LegacyTechniqueFlags();
                flags.hasAlpha    = arguments.Transparent;
                flags.hasDiffuse  = arguments.Diffuse != null;
                flags.hasEmissive = arguments.Emission != null;
                flags.hasNormal   = arguments.Bump != null;
                flags.hasSpecular = arguments.Specular != null;
                writer.WriteStartElement("material");
                writer.WriteWhitespace(Environment.NewLine);
                {
                    var bestTechnique         = Techniques[0];
                    var bestTechniqueDistance = bestTechnique.Material - flags;
                    foreach (var technique in Techniques)
                    {
                        if (technique.Material.Fits(flags))
                        {
                            var d = technique.Material - flags;
                            if (d < bestTechniqueDistance)
                            {
                                bestTechnique         = technique;
                                bestTechniqueDistance = d;
                            }
                        }
                    }

                    WriteTechnique(writer, "Techniques/" + bestTechnique.Name);
                }
                if (arguments.Diffuse != null)
                {
                    WriteTexture(arguments.Diffuse, writer, "diffuse");
                }
                if (arguments.Specular != null)
                {
                    WriteTexture(arguments.Specular, writer, "specular");
                }
                if (arguments.Bump != null)
                {
                    WriteTexture(arguments.Bump, writer, "normal");
                }
                if (arguments.Emission != null)
                {
                    WriteTexture(arguments.Bump, writer, "emissive");
                }
                WriteParameter(writer, "MatDiffColor", BaseNodeExporter.Format(arguments.DiffColor));
                if (arguments.HasEmission)
                {
                    WriteParameter(writer, "MatEmissiveColor", BaseNodeExporter.FormatRGB(arguments.EmissiveColor));
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }