Tweak tangents.

This commit is contained in:
Shyotl
2017-03-17 00:54:48 -05:00
parent f4a713a500
commit 1ccd8cfd89

View File

@@ -1326,6 +1326,13 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
const LLTextureEntry *tep = mVObjp->getTE(f); const LLTextureEntry *tep = mVObjp->getTE(f);
const U8 bump_code = tep ? tep->getBumpmap() : 0; const U8 bump_code = tep ? tep->getBumpmap() : 0;
if ( bump_code && rebuild_tcoord && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TANGENT) )
{
LLMaterial* mat = tep->getMaterialParams().get();
if( !mat || mat->getNormalID().isNull() )
rebuild_tangent = true;
}
BOOL is_static = mDrawablep->isStatic(); BOOL is_static = mDrawablep->isStatic();
BOOL is_global = is_static; BOOL is_global = is_static;
@@ -1592,6 +1599,9 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
LLVector4a bump_t_primary_light_ray(0.f, 0.f, 0.f); LLVector4a bump_t_primary_light_ray(0.f, 0.f, 0.f);
LLQuaternion bump_quat; LLQuaternion bump_quat;
if (!LLPipeline::sRenderDeferred)
{
if (mDrawablep->isActive()) if (mDrawablep->isActive())
{ {
bump_quat = LLQuaternion(LLMatrix4(mDrawablep->getRenderMatrix().getF32ptr())); bump_quat = LLQuaternion(LLMatrix4(mDrawablep->getRenderMatrix().getF32ptr()));
@@ -1601,25 +1611,25 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
{ {
mVObjp->getVolume()->genTangents(f); mVObjp->getVolume()->genTangents(f);
F32 offset_multiple; F32 offset_multiple;
switch( bump_code ) switch (bump_code)
{ {
case BE_NO_BUMP: case BE_NO_BUMP:
offset_multiple = 0.f; offset_multiple = 0.f;
break; break;
case BE_BRIGHTNESS: case BE_BRIGHTNESS:
case BE_DARKNESS: case BE_DARKNESS:
if( mTexture[LLRender::DIFFUSE_MAP].notNull() && mTexture[LLRender::DIFFUSE_MAP]->hasGLTexture()) if (mTexture[LLRender::DIFFUSE_MAP].notNull() && mTexture[LLRender::DIFFUSE_MAP]->hasGLTexture())
{ {
// Offset by approximately one texel // Offset by approximately one texel
S32 cur_discard = mTexture[LLRender::DIFFUSE_MAP]->getDiscardLevel(); S32 cur_discard = mTexture[LLRender::DIFFUSE_MAP]->getDiscardLevel();
S32 max_size = llmax( mTexture[LLRender::DIFFUSE_MAP]->getWidth(), mTexture[LLRender::DIFFUSE_MAP]->getHeight() ); S32 max_size = llmax(mTexture[LLRender::DIFFUSE_MAP]->getWidth(), mTexture[LLRender::DIFFUSE_MAP]->getHeight());
max_size <<= cur_discard; max_size <<= cur_discard;
const F32 ARTIFICIAL_OFFSET = 2.f; const F32 ARTIFICIAL_OFFSET = 2.f;
offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size; offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size;
} }
else else
{ {
offset_multiple = 1.f/256; offset_multiple = 1.f / 256;
} }
break; break;
@@ -1630,9 +1640,9 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
F32 s_scale = 1.f; F32 s_scale = 1.f;
F32 t_scale = 1.f; F32 t_scale = 1.f;
if( tep ) if (tep)
{ {
tep->getScale( &s_scale, &t_scale ); tep->getScale(&s_scale, &t_scale);
} }
// Use the nudged south when coming from above sun angle, such // Use the nudged south when coming from above sun angle, such
// that emboss mapping always shows up on the upward faces of cubes when // that emboss mapping always shows up on the upward faces of cubes when
@@ -1644,6 +1654,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
bump_s_primary_light_ray.load3((offset_multiple * s_scale * primary_light_ray).mV); bump_s_primary_light_ray.load3((offset_multiple * s_scale * primary_light_ray).mV);
bump_t_primary_light_ray.load3((offset_multiple * t_scale * primary_light_ray).mV); bump_t_primary_light_ray.load3((offset_multiple * t_scale * primary_light_ray).mV);
} }
}
U8 texgen = getTextureEntry()->getTexGen(); U8 texgen = getTextureEntry()->getTexGen();
if (rebuild_tcoord && texgen != LLTextureEntry::TEX_GEN_DEFAULT) if (rebuild_tcoord && texgen != LLTextureEntry::TEX_GEN_DEFAULT)
@@ -1913,7 +1924,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
mVertexBuffer->flush(); mVertexBuffer->flush();
} }
if (!mat && do_bump) if ( !LLPipeline::sRenderDeferred && do_bump )
{ {
mVertexBuffer->getTexCoord1Strider(tex_coords1, mGeomIndex, mGeomCount, map_range); mVertexBuffer->getTexCoord1Strider(tex_coords1, mGeomIndex, mGeomCount, map_range);
@@ -2090,11 +2101,21 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
LLVector4a* src = vf.mTangents; LLVector4a* src = vf.mTangents;
LLVector4a* end = vf.mTangents+num_vertices; LLVector4a* end = vf.mTangents+num_vertices;
LLVector4a* src2 = vf.mNormals;
LLVector4a* end2 = vf.mNormals+num_vertices;
LLMaterial* mat = tep->getMaterialParams().get();
F32 rot = RAD_TO_DEG * ( (mat && mat->getNormalID().notNull()) ? mat->getNormalRotation() : r);
bool rotate_tangent = src2 && !is_approx_equal(rot, 360.f) && !is_approx_zero(rot);
while (src < end) while (src < end)
{ {
LLVector4a tangent_out; LLVector4a tangent_out = *src;
mat_normal.rotate(*src, tangent_out); if (rotate_tangent && src2 < end2)
{
gGL.genRot(rot, *src2++).rotate(tangent_out, tangent_out);
}
mat_normal.rotate(tangent_out, tangent_out);
tangent_out.normalize3fast(); tangent_out.normalize3fast();
tangent_out.copyComponent<3>(*src); tangent_out.copyComponent<3>(*src);
tangent_out.store4a(tangents); tangent_out.store4a(tangents);