From 21f53f1bbd1d48f9a58579861470e84bd741f9f9 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 21 Sep 2015 16:57:55 -0700 Subject: [PATCH] debugging the lighting issue on the craps table --- libraries/render-utils/src/Model.cpp | 23 +++++++++++++---------- libraries/render-utils/src/Model.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index c87be06dba..cae4167567 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -190,6 +190,7 @@ void Model::RenderPipelineLib::initLocations(gpu::ShaderPointer& program, Model: locations.emissiveParams = program->getUniforms().findLocation("emissiveParams"); locations.glowIntensity = program->getUniforms().findLocation("glowIntensity"); locations.normalFittingMapUnit = program->getTextures().findLocation("normalFittingMap"); + locations.normalTextureUnit = program->getTextures().findLocation("normalMap"); locations.specularTextureUnit = program->getTextures().findLocation("specularMap"); locations.emissiveTextureUnit = program->getTextures().findLocation("emissiveMap"); locations.materialBufferUnit = program->getBuffers().findLocation("materialBuffer"); @@ -1496,10 +1497,14 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape const FBXGeometry& geometry = _geometry->getFBXGeometry(); const std::vector>& networkMeshes = _geometry->getMeshes(); - auto drawMaterial = _geometry->getShapeMaterial(shapeID); - if (!drawMaterial) { + auto networkMaterial = _geometry->getShapeMaterial(shapeID); + if (!networkMaterial) { return; }; + auto material = networkMaterial->_material; + if (!material) { + return; + } // TODO: Not yet // auto drawMesh = _geometry->getShapeMesh(shapeID); @@ -1516,12 +1521,12 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape const FBXMesh& mesh = geometry.meshes.at(meshIndex); const MeshState& state = _meshStates.at(meshIndex); - auto drawMaterialKey = drawMaterial->_material->getKey(); + auto drawMaterialKey = material->getKey(); bool translucentMesh = drawMaterialKey.isTransparent() || drawMaterialKey.isTransparentMap(); - bool hasTangents = !mesh.tangents.isEmpty(); - bool hasSpecular = !drawMaterial->specularTextureName.isEmpty(); //mesh.hasSpecularTexture(); - bool hasLightmap = !drawMaterial->emissiveTextureName.isEmpty(); //mesh.hasEmissiveTexture(); + bool hasTangents = drawMaterialKey.isNormalMap() && !mesh.tangents.isEmpty(); + bool hasSpecular = drawMaterialKey.isGlossMap(); // !drawMaterial->specularTextureName.isEmpty(); //mesh.hasSpecularTexture(); + bool hasLightmap = drawMaterialKey.isLightmapMap(); // !drawMaterial->emissiveTextureName.isEmpty(); //mesh.hasEmissiveTexture(); bool isSkinned = state.clusterMatrices.size() > 1; bool wireframe = isWireframe(); @@ -1624,8 +1629,6 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape const FBXMeshPart& part = mesh.parts.at(partIndex); - //model::MaterialPointer material = part._material; - auto material = drawMaterial->_material; #ifdef WANT_DEBUG if (material == nullptr) { @@ -1633,7 +1636,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape } #endif - if (material != nullptr) { + { // apply material properties if (mode != RenderArgs::SHADOW_RENDER_MODE) { @@ -1667,7 +1670,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape } // Normal map - if (materialKey.isNormalMap()) { + if ((locations->normalTextureUnit >= 0) && hasTangents) { auto normalMap = textureMaps[model::MaterialKey::NORMAL_MAP]; if (normalMap && normalMap->isDefined()) { batch.setResourceTexture(NORMAL_MAP_SLOT, normalMap->getTextureView()); diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index eaa7089d12..acc419a81f 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -339,6 +339,7 @@ private: int tangent; int alphaThreshold; int texcoordMatrices; + int normalTextureUnit; int specularTextureUnit; int emissiveTextureUnit; int emissiveParams;