Fix merge issues from genBBoxes optimizations fighting with genBBoxes optimizations and missing statics

meow-7.2.2
Graham Linden 2013-08-19 12:56:04 -07:00
parent 3f186aab77
commit 62011c2871
6 changed files with 119 additions and 147 deletions

View File

@ -136,6 +136,82 @@ BOOL LLLineSegmentBoxIntersect(const F32* start, const F32* end, const F32* cent
return true;
}
// Finds tangent vec based on three vertices with texture coordinates.
// Fills in dummy values if the triangle has degenerate texture coordinates.
void calc_tangent_from_triangle(
LLVector4a& normal,
LLVector4a& tangent_out,
const LLVector4a& v1,
const LLVector2& w1,
const LLVector4a& v2,
const LLVector2& w2,
const LLVector4a& v3,
const LLVector2& w3)
{
const F32* v1ptr = v1.getF32ptr();
const F32* v2ptr = v2.getF32ptr();
const F32* v3ptr = v3.getF32ptr();
float x1 = v2ptr[0] - v1ptr[0];
float x2 = v3ptr[0] - v1ptr[0];
float y1 = v2ptr[1] - v1ptr[1];
float y2 = v3ptr[1] - v1ptr[1];
float z1 = v2ptr[2] - v1ptr[2];
float z2 = v3ptr[2] - v1ptr[2];
float s1 = w2.mV[0] - w1.mV[0];
float s2 = w3.mV[0] - w1.mV[0];
float t1 = w2.mV[1] - w1.mV[1];
float t2 = w3.mV[1] - w1.mV[1];
F32 rd = s1*t2-s2*t1;
float r = ((rd*rd) > FLT_EPSILON) ? 1.0F / rd : 1024.f; //some made up large ratio for division by zero
llassert(llfinite(r));
llassert(!llisnan(r));
LLVector4a sdir(
(t2 * x1 - t1 * x2) * r,
(t2 * y1 - t1 * y2) * r,
(t2 * z1 - t1 * z2) * r);
LLVector4a tdir(
(s1 * x2 - s2 * x1) * r,
(s1 * y2 - s2 * y1) * r,
(s1 * z2 - s2 * z1) * r);
LLVector4a n = normal;
LLVector4a t = sdir;
LLVector4a ncrosst;
ncrosst.setCross3(n,t);
// Gram-Schmidt orthogonalize
n.mul(n.dot3(t).getF32());
LLVector4a tsubn;
tsubn.setSub(t,n);
if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO)
{
tsubn.normalize3fast_checked();
// Calculate handedness
F32 handedness = ncrosst.dot3(tdir).getF32() < 0.f ? -1.f : 1.f;
tsubn.getF32ptr()[3] = handedness;
tangent_out = tsubn;
}
else
{
// degenerate, make up a value
//
tangent_out.set(0,0,1,1);
}
}
// intersect test between triangle vert0, vert1, vert2 and a ray from orig in direction dir.
@ -5908,10 +5984,10 @@ void LLVolumeFace::cacheOptimize()
wght = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
}
LLVector4a* binorm = NULL;
LLVector4a* tangent = NULL;
if (mTangents)
{
binorm = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
tangent = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
}
//allocate mapping of old indices to new indices
@ -7277,83 +7353,6 @@ void calc_binormal_from_triangle(LLVector4a& binormal,
}
}
// Finds binormal based on three vertices with texture coordinates.
// Fills in dummy values if the triangle has degenerate texture coordinates.
void calc_tangent_from_triangle(
LLVector4a& normal,
LLVector4a& tangent_out,
const LLVector4a& v1,
const LLVector2& w1,
const LLVector4a& v2,
const LLVector2& w2,
const LLVector4a& v3,
const LLVector2& w3)
{
const F32* v1ptr = v1.getF32ptr();
const F32* v2ptr = v2.getF32ptr();
const F32* v3ptr = v3.getF32ptr();
float x1 = v2ptr[0] - v1ptr[0];
float x2 = v3ptr[0] - v1ptr[0];
float y1 = v2ptr[1] - v1ptr[1];
float y2 = v3ptr[1] - v1ptr[1];
float z1 = v2ptr[2] - v1ptr[2];
float z2 = v3ptr[2] - v1ptr[2];
float s1 = w2.mV[0] - w1.mV[0];
float s2 = w3.mV[0] - w1.mV[0];
float t1 = w2.mV[1] - w1.mV[1];
float t2 = w3.mV[1] - w1.mV[1];
F32 rd = s1*t2-s2*t1;
float r = ((rd*rd) > FLT_EPSILON) ? 1.0F / rd : 1024.f; //some made up large ratio for division by zero
llassert(llfinite(r));
llassert(!llisnan(r));
LLVector4a sdir(
(t2 * x1 - t1 * x2) * r,
(t2 * y1 - t1 * y2) * r,
(t2 * z1 - t1 * z2) * r);
LLVector4a tdir(
(s1 * x2 - s2 * x1) * r,
(s1 * y2 - s2 * y1) * r,
(s1 * z2 - s2 * z1) * r);
LLVector4a n = normal;
LLVector4a t = sdir;
LLVector4a ncrosst;
ncrosst.setCross3(n,t);
// Gram-Schmidt orthogonalize
n.mul(n.dot3(t).getF32());
LLVector4a tsubn;
tsubn.setSub(t,n);
if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO)
{
tsubn.normalize3fast_checked();
// Calculate handedness
F32 handedness = ncrosst.dot3(tdir).getF32() < 0.f ? -1.f : 1.f;
tsubn.getF32ptr()[3] = handedness;
tangent_out = tsubn;
}
else
{
// degenerate, make up a value
//
tangent_out.set(0,0,1,1);
}
}
//adapted from Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”. Terathon Software 3D Graphics Library, 2001. http://www.terathon.com/code/tangent.html
void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal,
const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent)

View File

@ -768,7 +768,7 @@ bool less_than_max_mag(const LLVector4a& vec)
}
BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
const LLMatrix4& mat_vert_in, const LLMatrix3& mat_normal_in, BOOL global_volume)
const LLMatrix4& mat_vert_in, BOOL global_volume)
{
//get bounding box
if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION | LLDrawable::REBUILD_RIGGED))
@ -777,10 +777,6 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
LLMatrix4a mat_vert;
mat_vert.loadu(mat_vert_in);
LLMatrix4a mat_normal;
mat_normal.loadu(mat_normal_in);
//VECTORIZE THIS
LLVector4a min,max;
if (f >= volume.getNumVolumeFaces())
@ -797,95 +793,69 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
llassert(less_than_max_mag(max));
//min, max are in volume space, convert to drawable render space
LLVector4a center;
LLVector4a t;
t.setAdd(min, max);
t.mul(0.5f);
mat_vert.affineTransform(t, center);
LLVector4a size;
size.setSub(max, min);
size.mul(0.5f);
llassert(less_than_max_mag(min));
llassert(less_than_max_mag(max));
//get 8 corners of bounding box
LLVector4Logical mask[6];
if (!global_volume)
for (U32 i = 0; i < 6; ++i)
{
//VECTORIZE THIS
LLVector4a scale;
scale.load3(mDrawablep->getVObj()->getScale().mV);
size.mul(scale);
mask[i].clear();
}
mat_normal.mMatrix[0].normalize3fast();
mat_normal.mMatrix[1].normalize3fast();
mat_normal.mMatrix[2].normalize3fast();
mask[0].setElement<2>(); //001
mask[1].setElement<1>(); //010
mask[2].setElement<1>(); //011
mask[2].setElement<2>();
mask[3].setElement<0>(); //100
mask[4].setElement<0>(); //101
mask[4].setElement<2>();
mask[5].setElement<0>(); //110
mask[5].setElement<1>();
LLVector4a v[4];
LLVector4a v[8];
//get 4 corners of bounding box
mat_normal.rotate(size,v[0]);
v[6] = min;
v[7] = max;
//VECTORIZE THIS
LLVector4a scale;
for (U32 i = 0; i < 6; ++i)
{
v[i].setSelectWithMask(mask[i], min, max);
}
scale.set(-1.f, -1.f, 1.f);
scale.mul(size);
mat_normal.rotate(scale, v[1]);
LLVector4a tv[8];
scale.set(1.f, -1.f, -1.f);
scale.mul(size);
mat_normal.rotate(scale, v[2]);
scale.set(-1.f, 1.f, -1.f);
scale.mul(size);
mat_normal.rotate(scale, v[3]);
//transform bounding box into drawable space
for (U32 i = 0; i < 8; ++i)
{
mat_vert.affineTransform(v[i], tv[i]);
}
//find bounding box
LLVector4a& newMin = mExtents[0];
LLVector4a& newMax = mExtents[1];
newMin = newMax = center;
newMin = newMax = tv[0];
llassert(less_than_max_mag(center));
for (U32 i = 0; i < 4; i++)
for (U32 i = 1; i < 8; ++i)
{
LLVector4a delta;
delta.setAbs(v[i]);
LLVector4a min;
min.setSub(center, delta);
LLVector4a max;
max.setAdd(center, delta);
newMin.setMin(newMin,min);
newMax.setMax(newMax,max);
llassert(less_than_max_mag(newMin));
llassert(less_than_max_mag(newMax));
newMin.setMin(newMin, tv[i]);
newMax.setMax(newMax, tv[i]);
}
if (!mDrawablep->isActive())
{
{ // Shift position for region
LLVector4a offset;
offset.load3(mDrawablep->getRegion()->getOriginAgent().mV);
newMin.add(offset);
newMax.add(offset);
llassert(less_than_max_mag(newMin));
llassert(less_than_max_mag(newMax));
}
LLVector4a t;
t.setAdd(newMin, newMax);
t.mul(0.5f);
llassert(less_than_max_mag(t));
//VECTORIZE THIS
mCenterLocal.set(t.getF32ptr());
llassert(less_than_max_mag(newMin));
llassert(less_than_max_mag(newMax));
t.setSub(newMax,newMin);
mBoundingSphereRadius = t.getLength3().getF32()*0.5f;

View File

@ -194,8 +194,7 @@ public:
void setSize(S32 numVertices, S32 num_indices = 0, bool align = false);
BOOL genVolumeBBoxes(const LLVolume &volume, S32 f,
const LLMatrix4& mat, BOOL global_volume = FALSE);
BOOL genVolumeBBoxes(const LLVolume &volume, S32 f,const LLMatrix4& mat, BOOL global_volume = FALSE);
void init(LLDrawable* drawablep, LLViewerObject* objp);
void destroy();

View File

@ -1458,7 +1458,7 @@ BOOL LLVOVolume::genBBoxes(BOOL force_global)
continue;
}
res &= face->genVolumeBBoxes(*volume, i,
mRelativeXform, mRelativeXformInvTrans,
mRelativeXform, /*mRelativeXformInvTrans,*/
(mVolumeImpl && mVolumeImpl->isVolumeGlobal()) || force_global);
if (rebuild)

View File

@ -169,6 +169,7 @@ S32 LLPipeline::RenderGlowIterations;
F32 LLPipeline::RenderGlowWidth;
F32 LLPipeline::RenderGlowStrength;
BOOL LLPipeline::RenderDepthOfField;
BOOL LLPipeline::RenderDepthOfFieldInEditMode;
F32 LLPipeline::CameraFocusTransitionTime;
F32 LLPipeline::CameraFNumber;
F32 LLPipeline::CameraFocalLength;
@ -379,6 +380,7 @@ BOOL LLPipeline::sWaterReflections = FALSE;
BOOL LLPipeline::sRenderGlow = FALSE;
BOOL LLPipeline::sReflectionRender = FALSE;
BOOL LLPipeline::sImpostorRender = FALSE;
BOOL LLPipeline::sImpostorRenderAlphaDepthPass = FALSE;
BOOL LLPipeline::sUnderWaterRender = FALSE;
BOOL LLPipeline::sTextureBindTest = FALSE;
BOOL LLPipeline::sRenderFrameTest = FALSE;

View File

@ -295,7 +295,8 @@ public:
void unbindDeferredShader(LLGLSLShader& shader);
void renderDeferredLighting();
void renderDeferredLightingToRT(LLRenderTarget* target);
void generateWaterReflection(LLCamera& camera);
void generateSunShadow(LLCamera& camera);
void generateHighlight(LLCamera& camera);
@ -594,6 +595,7 @@ public:
static BOOL sPickAvatar;
static BOOL sReflectionRender;
static BOOL sImpostorRender;
static BOOL sImpostorRenderAlphaDepthPass;
static BOOL sUnderWaterRender;
static BOOL sRenderGlow;
static BOOL sTextureBindTest;