Getting the unlit to work from the pipeline, and found the isLinear for texture bug!

This commit is contained in:
samcake 2016-05-06 18:36:55 -07:00
parent 8bad58749c
commit a8347cac6e
5 changed files with 43 additions and 10 deletions

View file

@ -72,6 +72,10 @@ void FBXReader::consolidateFBXMaterials() {
// foreach (const QString& materialID, materials) {
for (QHash<QString, FBXMaterial>::iterator it = _fbxMaterials.begin(); it != _fbxMaterials.end(); it++) {
FBXMaterial& material = (*it);
// Maya is the exporting the shading model and we aretrying to use it
bool isMaterialLambert = (material.shadingModel.toLower() == "lambert");
// the pure material associated with this part
bool detectDifferentUVs = false;
FBXTexture diffuseTexture;
@ -171,6 +175,13 @@ void FBXReader::consolidateFBXMaterials() {
emissiveTexture = getTexture(emissiveTextureID);
detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
material.emissiveTexture = emissiveTexture;
if (isMaterialLambert) {
// If the emissiveTextureID comes from the Texture bound to Emissive when material is lambert, we know it s exported from maya
// And the EMissiveColor is forced to 0.5 by Maya which is bad
// So we need to force it to 1.0
material.emissiveColor = vec3(1.0);
}
}
FBXTexture occlusionTexture;
@ -198,7 +209,7 @@ void FBXReader::consolidateFBXMaterials() {
material._material = std::make_shared<model::Material>();
// Emissive color is the mix of emissiveColor with emissiveFactor
auto emissive = material.emissiveColor * material.emissiveFactor;
auto emissive = material.emissiveColor * (isMaterialLambert ? 1.0f : material.emissiveFactor); // In lambert there is not emissiveFactor
material._material->setEmissive(emissive);
// Final diffuse color is the mix of diffuseColor with diffuseFactor
@ -213,9 +224,17 @@ void FBXReader::consolidateFBXMaterials() {
float metallic = std::max(material.specularColor.x, std::max(material.specularColor.y, material.specularColor.z));
material._material->setMetallic(metallic);
if (material.shadingModel == "lambert") {
if (isMaterialLambert) {
if (!material._material->getKey().isAlbedo()) {
// switch emissive to material albedo as we tag the material to unlit
material._material->setUnlit(true);
material._material->setEmissive(diffuse);
material._material->setAlbedo(emissive);
if (!material.emissiveTexture.isNull()) {
material.albedoTexture = material.emissiveTexture;
}
std::cout << emissive;
}
}

View file

@ -104,7 +104,7 @@ const QImage& image, bool isLinear, bool doCompress) {
if (image.hasAlphaChannel()) {
gpu::Semantic gpuSemantic;
gpu::Semantic mipSemantic;
if (isLinear) {
if (!isLinear) {
mipSemantic = gpu::SBGRA;
if (doCompress) {
gpuSemantic = gpu::COMPRESSED_SRGBA;
@ -124,7 +124,7 @@ const QImage& image, bool isLinear, bool doCompress) {
} else {
gpu::Semantic gpuSemantic;
gpu::Semantic mipSemantic;
if (isLinear) {
if (!isLinear) {
mipSemantic = gpu::SRGB;
if (doCompress) {
gpuSemantic = gpu::COMPRESSED_SRGB;

View file

@ -144,6 +144,11 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
auto materialKey = _drawMaterial->getKey();
auto textureMaps = _drawMaterial->getTextureMaps();
int numUnlit = 0;
if (materialKey.isUnlit()) {
numUnlit++;
}
// Albedo
if (materialKey.isAlbedoMap()) {
auto albedoMap = textureMaps[model::MaterialKey::ALBEDO_MAP];

View file

@ -15,7 +15,8 @@
<@include DeferredBufferWrite.slh@>
<@include model/Material.slh@>
uniform sampler2D albedoMap;
<@include MaterialTextures.slh@>
<$declareMaterialTextures(ALBEDO, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
in vec2 _texCoord0;
in vec3 _normal;
@ -23,14 +24,21 @@ in vec3 _color;
in float _alpha;
void main(void) {
vec4 texel = texture(albedoMap, _texCoord0);
Material mat = getMaterial();
//vec3 fragColor = getMaterialEmissive(mat) * texel.rgb * _color;
vec3 fragColor = vec3(1.0, 0.5, 0.0);
int matKey = getMaterialKey(mat);
<$fetchMaterialTextures(matKey, _texCoord0, albedoTex, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL, _SCRIBE_NULL)$>
float opacity = 1.0;
<$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>;
<$discardTransparent(opacity)$>;
vec3 albedo = getMaterialAlbedo(mat);
<$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>;
albedo *= _color;
packDeferredFragmentUnlit(
normalize(_normal),
1.0,
fragColor);
opacity,
albedo);
}

View file

@ -33,6 +33,7 @@ Column {
"Roughness",
"Metallic",
"Emissive",
"Shaded/Lightmapped/Unlit",
"Occlusion",
"Lightmap",
"Lighting",