diff options
author | RunitaiLinden <davep@lindenlab.com> | 2023-06-27 18:49:36 -0500 |
---|---|---|
committer | RunitaiLinden <davep@lindenlab.com> | 2023-06-27 18:49:36 -0500 |
commit | 8d17467f7f70aa28d7ad012426ca59dc760bc43f (patch) | |
tree | 7450535fd9aadb0ad0d585be9c55ff93dc87846d | |
parent | 298109864503d9c1e00d41dd1556f9dfea988e14 (diff) |
SL-19884 Fix for garbled rigged meshes in model import preview window.
-rw-r--r-- | indra/newview/app_settings/shaders/class1/objects/previewV.glsl | 24 | ||||
-rw-r--r-- | indra/newview/llmodelpreview.cpp | 115 | ||||
-rw-r--r-- | indra/newview/llviewershadermgr.cpp | 12 |
3 files changed, 86 insertions, 65 deletions
diff --git a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl index b474a5803f..f51b0f4d9e 100644 --- a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl @@ -25,7 +25,6 @@ uniform mat3 normal_matrix; uniform mat4 texture_matrix0; -uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; in vec3 position; @@ -54,14 +53,27 @@ float calcDirectionalLight(vec3 n, vec3 l) //==================================================================================================== +#ifdef HAS_SKIN +mat4 getObjectSkinnedTransform(); +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +#endif + void main() { - //transform vertex - vec4 pos = (modelview_matrix * vec4(position.xyz, 1.0)); - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec3 norm; +#ifdef HAS_SKIN + mat4 mat = getObjectSkinnedTransform(); + mat = modelview_matrix * mat; + vec4 pos = mat * vec4(position.xyz, 1.0); + gl_Position = projection_matrix * pos; + norm = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); +#else + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + norm = normalize(normal_matrix * normal); +#endif + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - - vec3 norm = normalize(normal_matrix * normal); vec4 col = vec4(0,0,0,1); diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp index c98e0e1bbe..6ceffd452e 100644 --- a/indra/newview/llmodelpreview.cpp +++ b/indra/newview/llmodelpreview.cpp @@ -2751,6 +2751,16 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights) base_iter++; + bool skinned = include_skin_weights && !mdl->mSkinWeights.empty(); + + LLMatrix4a mat_normal; + if (skinned) + { + glh::matrix4f m((F32*)mdl->mSkinInfo.mBindShapeMatrix.getF32ptr()); + m = m.inverse().transpose(); + mat_normal.loadu(m.m); + } + S32 num_faces = mdl->getNumVolumeFaces(); for (S32 i = 0; i < num_faces; ++i) { @@ -2765,7 +2775,7 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights) LLVertexBuffer* vb = NULL; - bool skinned = include_skin_weights && !mdl->mSkinWeights.empty(); + U32 mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0; @@ -2803,6 +2813,15 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights) LLVector4a::memcpyNonAliased16((F32*)vertex_strider.get(), (F32*)vf.mPositions, num_vertices * 4 * sizeof(F32)); + if (skinned) + { + for (U32 i = 0; i < num_vertices; ++i) + { + LLVector4a* v = (LLVector4a*)vertex_strider.get(); + mdl->mSkinInfo.mBindShapeMatrix.affineTransform(*v, *v); + vertex_strider++; + } + } if (vf.mTexCoords) { vb->getTexCoord0Strider(tc_strider); @@ -2813,7 +2832,25 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights) if (vf.mNormals) { vb->getNormalStrider(normal_strider); - LLVector4a::memcpyNonAliased16((F32*)normal_strider.get(), (F32*)vf.mNormals, num_vertices * 4 * sizeof(F32)); + + if (skinned) + { + F32* normals = (F32*)normal_strider.get(); + LLVector4a* src = vf.mNormals; + LLVector4a* end = src + num_vertices; + + while (src < end) + { + LLVector4a normal; + mat_normal.rotate(*src++, normal); + normal.store4a(normals); + normals += 4; + } + } + else + { + LLVector4a::memcpyNonAliased16((F32*)normal_strider.get(), (F32*)vf.mNormals, num_vertices * 4 * sizeof(F32)); + } } if (skinned) @@ -3276,7 +3313,7 @@ BOOL LLModelPreview::render() refresh(); } - gObjectPreviewProgram.bind(); + gObjectPreviewProgram.bind(skin_weight); gGL.loadIdentity(); gPipeline.enableLightsPreview(); @@ -3351,11 +3388,11 @@ BOOL LLModelPreview::render() } gGL.pushMatrix(); + LLMatrix4 mat = instance.mTransform; gGL.multMatrix((GLfloat*)mat.mMatrix); - - + U32 num_models = mVertexBuffer[mPreviewLOD][model].size(); for (U32 i = 0; i < num_models; ++i) { @@ -3685,65 +3722,41 @@ BOOL LLModelPreview::render() { LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i]; - const LLVolumeFace& face = model->getVolumeFace(i); - - LLStrider<LLVector3> position; - buffer->getVertexStrider(position); - - LLStrider<LLVector4> weight; - buffer->getWeight4Strider(weight); + model->mSkinInfo.updateHash(); + LLRenderPass::uploadMatrixPalette(mPreviewAvatar, &model->mSkinInfo); - //quick 'n dirty software vertex skinning - - //build matrix palette - - LLMatrix4a mat[LL_MAX_JOINTS_PER_MESH_OBJECT]; - LLSkinningUtil::initSkinningMatrixPalette(mat, joint_count, - skin, getPreviewAvatar()); + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - const LLMatrix4a& bind_shape_matrix = skin->mBindShapeMatrix; - U32 max_joints = LLSkinningUtil::getMaxJointCount(); - for (U32 j = 0; j < buffer->getNumVerts(); ++j) + if (textures) { - LLMatrix4a final_mat; - F32 *wptr = weight[j].mV; - LLSkinningUtil::getPerVertexSkinMatrix(wptr, mat, true, final_mat, max_joints); - - //VECTORIZE THIS - LLVector4a& v = face.mPositions[j]; + int materialCnt = instance.mModel->mMaterialList.size(); + if (i < materialCnt) + { + const std::string& binding = instance.mModel->mMaterialList[i]; + const LLImportMaterial& material = instance.mMaterial[binding]; - LLVector4a t; - LLVector4a dst; - bind_shape_matrix.affineTransform(v, t); - final_mat.affineTransform(t, dst); + gGL.diffuseColor4fv(material.mDiffuseColor.mV); - position[j][0] = dst[0]; - position[j][1] = dst[1]; - position[j][2] = dst[2]; + // Find the tex for this material, bind it, and add it to our set + // + LLViewerFetchedTexture* tex = bindMaterialDiffuseTexture(material); + if (tex) + { + mTextureSet.insert(tex); + } + } } - - llassert(model->mMaterialList.size() > i); - const std::string& binding = instance.mModel->mMaterialList[i]; - const LLImportMaterial& material = instance.mMaterial[binding]; - - buffer->unmapBuffer(); - - buffer->setBuffer(); - gGL.diffuseColor4fv(material.mDiffuseColor.mV); - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - - // Find the tex for this material, bind it, and add it to our set - // - LLViewerFetchedTexture* tex = bindMaterialDiffuseTexture(material); - if (tex) + else { - mTextureSet.insert(tex); + gGL.diffuseColor4fv(PREVIEW_BASE_COL.mV); } + buffer->setBuffer(); buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0); if (edges) { + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.diffuseColor4fv(PREVIEW_EDGE_COL.mV); glLineWidth(PREVIEW_EDGE_WIDTH); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 5eae1dfb18..4559d71d6d 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -92,6 +92,7 @@ LLGLSLShader gCopyDepthProgram; //object shaders LLGLSLShader gObjectPreviewProgram; +LLGLSLShader gSkinnedObjectPreviewProgram; LLGLSLShader gPhysicsPreviewProgram; LLGLSLShader gObjectFullbrightAlphaMaskProgram; LLGLSLShader gSkinnedObjectFullbrightAlphaMaskProgram; @@ -251,7 +252,6 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gWaterProgram); mShaderList.push_back(&gWaterEdgeProgram); mShaderList.push_back(&gAvatarEyeballProgram); - mShaderList.push_back(&gObjectPreviewProgram); mShaderList.push_back(&gImpostorProgram); mShaderList.push_back(&gObjectBumpProgram); mShaderList.push_back(&gSkinnedObjectBumpProgram); @@ -2876,20 +2876,16 @@ BOOL LLViewerShaderMgr::loadShadersObject() if (success) { - gObjectPreviewProgram.mName = "Simple Shader"; - gObjectPreviewProgram.mFeatures.calculatesLighting = false; - gObjectPreviewProgram.mFeatures.calculatesAtmospherics = false; - gObjectPreviewProgram.mFeatures.hasGamma = false; - gObjectPreviewProgram.mFeatures.hasAtmospherics = false; - gObjectPreviewProgram.mFeatures.hasLighting = false; - gObjectPreviewProgram.mFeatures.mIndexedTextureChannels = 0; + gObjectPreviewProgram.mName = "Object Preview Shader"; gObjectPreviewProgram.mFeatures.disableTextureIndex = true; gObjectPreviewProgram.mShaderFiles.clear(); gObjectPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewV.glsl", GL_VERTEX_SHADER)); gObjectPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewF.glsl", GL_FRAGMENT_SHADER)); gObjectPreviewProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT]; + success = make_rigged_variant(gObjectPreviewProgram, gSkinnedObjectPreviewProgram); success = gObjectPreviewProgram.createShader(NULL, NULL); gObjectPreviewProgram.mFeatures.hasLighting = true; + gSkinnedObjectPreviewProgram.mFeatures.hasLighting = true; } if (success) |