summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-01-06 12:12:02 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-01-07 09:28:14 +0000
commita0d90233bd2520236b920483db253dafb1e14e8f (patch)
tree3631da6d7464b96b26ae87e3f554a97dba3b3bf2 /tools
parentba2c6593ae21326565bf40723148ee29eff22802 (diff)
qgltf: Output a KHR_materials_common block
Unless disabled by a command-line switch. The spec is insufficient to support normal maps, the "normalmap" value is our own extension to the extension for now. Also, the common technique name is always PHONG. The correct material can be chosen based on the presence and type of the value list entries. Task-number: QTBUG-49384 Change-Id: I4f2e5848ad8019c44e9392416501655ab1163d7c Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/qgltf/qgltf.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/tools/qgltf/qgltf.cpp b/tools/qgltf/qgltf.cpp
index 9a6e73cab..7d40029d9 100644
--- a/tools/qgltf/qgltf.cpp
+++ b/tools/qgltf/qgltf.cpp
@@ -229,6 +229,7 @@ struct Options {
ETC1
};
TextureCompression texComp;
+ bool commonMat;
bool showLog;
} opts;
@@ -1190,7 +1191,7 @@ bool Exporter::nodeIsUseful(const Importer::Node *n) const
void Exporter::copyExternalTextures(const QString &inputFilename)
{
- // External textures needs copying only when output dir was specified.
+ // External textures need copying only when output dir was specified.
if (!opts.outDir.isEmpty()) {
foreach (const QString &textureFilename, m_importer->externalTextures()) {
QString dst = opts.outDir + textureFilename;
@@ -1265,6 +1266,7 @@ private:
QString semantic;
uint type;
};
+ QString commonTechniqueName;
QString vertShader;
QString fragShader;
QVector<Param> attributes;
@@ -1551,6 +1553,7 @@ void GltfExporter::initShaderInfo()
ProgramInfo p;
p = ProgramInfo();
+ p.commonTechniqueName = "PHONG"; // diffuse RGBA, specular RGBA
p.vertShader = "color.vert";
p.fragShader = "color.frag";
p.attributes << ProgramInfo::Param("position", "vertexPosition", "POSITION", GLT_FLOAT_VEC3);
@@ -1567,6 +1570,7 @@ void GltfExporter::initShaderInfo()
m_progs << p;
p = ProgramInfo();
+ p.commonTechniqueName = "PHONG"; // diffuse texture, specular RGBA
p.vertShader = "diffusemap.vert";
p.fragShader = "diffusemap.frag";
p.attributes << ProgramInfo::Param("position", "vertexPosition", "POSITION", GLT_FLOAT_VEC3);
@@ -1584,6 +1588,7 @@ void GltfExporter::initShaderInfo()
m_progs << p;
p = ProgramInfo();
+ p.commonTechniqueName = "PHONG"; // diffuse texture, specular texture
p.vertShader = "diffusemap.vert";
p.fragShader = "diffusespecularmap.frag";
p.attributes << ProgramInfo::Param("position", "vertexPosition", "POSITION", GLT_FLOAT_VEC3);
@@ -1601,6 +1606,7 @@ void GltfExporter::initShaderInfo()
m_progs << p;
p = ProgramInfo();
+ p.commonTechniqueName = "PHONG"; // diffuse texture, specular RGBA, normalmap texture
p.vertShader = "normaldiffusemap.vert";
p.fragShader = "normaldiffusemap.frag";
p.attributes << ProgramInfo::Param("position", "vertexPosition", "POSITION", GLT_FLOAT_VEC3);
@@ -1620,6 +1626,7 @@ void GltfExporter::initShaderInfo()
m_progs << p;
p = ProgramInfo();
+ p.commonTechniqueName = "PHONG"; // diffuse texture, specular texture, normalmap texture
p.vertShader = "normaldiffusemap.vert";
p.fragShader = "normaldiffusespecularmap.frag";
p.attributes << ProgramInfo::Param("position", "vertexPosition", "POSITION", GLT_FLOAT_VEC3);
@@ -1830,6 +1837,25 @@ void GltfExporter::exportMaterials(QJsonObject &materials, QHash<QString, QStrin
material["techniqueGL2"] = techniqueInfo.gl2Name;
}
+ if (opts.commonMat) {
+ // The built-in shaders we output are of little use in practice.
+ // Ideally we want Qt3D's own standard materials in order to have our
+ // models participate in lighting for example. To achieve this, output
+ // a KHR_materials_common block which Qt3D's loader will recognize and
+ // prefer over the shader-based techniques.
+ if (!prog->commonTechniqueName.isEmpty()) {
+ QJsonObject commonMat;
+ commonMat["technique"] = prog->commonTechniqueName;
+ // Set the values as-is. "normalmap" is our own extension, not in the spec.
+ commonMat["values"] = vals;
+ if (!opaque)
+ commonMat["transparent"] = true;
+ QJsonObject extensions;
+ extensions["KHR_materials_common"] = commonMat;
+ material["extensions"] = extensions;
+ }
+ }
+
materials[matInfo.name] = material;
}
}
@@ -2442,6 +2468,8 @@ int main(int argc, char **argv)
cmdLine.addOption(coreOpt);
QCommandLineOption etc1Opt(QStringLiteral("1"), QStringLiteral("Generate ETC1 compressed textures by invoking etc1tool (PNG only)"));
cmdLine.addOption(etc1Opt);
+ QCommandLineOption noCommonMatOpt(QStringLiteral("T"), QStringLiteral("Do not generate KHR_materials_common block"));
+ cmdLine.addOption(noCommonMatOpt);
QCommandLineOption silentOpt(QStringLiteral("s"), QStringLiteral("Silence debug output"));
cmdLine.addOption(silentOpt);
cmdLine.process(app);
@@ -2461,6 +2489,7 @@ int main(int argc, char **argv)
}
opts.genCore = cmdLine.isSet(coreOpt);
opts.texComp = cmdLine.isSet(etc1Opt) ? Options::ETC1 : Options::NoTextureCompression;
+ opts.commonMat = !cmdLine.isSet(noCommonMatOpt);
opts.showLog = !cmdLine.isSet(silentOpt);
if (!opts.outDir.isEmpty()) {
if (!opts.outDir.endsWith('/'))