From: divverent Date: Tue, 9 Jun 2009 10:06:49 +0000 (+0000) Subject: make tcgen environment work exactly like in Q3A (the previous code didn't just use... X-Git-Tag: xonotic-v0.1.0preview~1610 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6d62a4ab568c28eb6111824bea906b05d13991ab;p=xonotic%2Fdarkplaces.git make tcgen environment work exactly like in Q3A (the previous code didn't just use pixels from the spheremap, it even left the bounds of it), but let it transform the reflected ray to worldspace so it can even be used on models git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9012 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_rmain.c b/gl_rmain.c index 72bfa4bb..9f485fe7 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -5517,12 +5517,28 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta float *out_tc = rsurface.array_generatedtexcoordtexture2f + 2 * surface->num_firstvertex; for (j = 0;j < surface->num_vertices;j++, vertex += 3, normal += 3, out_tc += 2) { - float l, d, eyedir[3]; - VectorSubtract(rsurface.modelorg, vertex, eyedir); - l = 0.5f / VectorLength(eyedir); - d = DotProduct(normal, eyedir)*2; - out_tc[0] = 0.5f + (normal[1]*d - eyedir[1])*l; - out_tc[1] = 0.5f - (normal[2]*d - eyedir[2])*l; + // identical to Q3A's method, but executed in worldspace so + // carried models can be shiny too + + float viewer[3], d, reflected[3], worldreflected[3]; + + VectorSubtract(rsurface.modelorg, vertex, viewer); + // VectorNormalize(viewer); + + d = DotProduct(normal, viewer); + + reflected[0] = normal[0]*2*d - viewer[0]; + reflected[1] = normal[1]*2*d - viewer[1]; + reflected[2] = normal[2]*2*d - viewer[2]; + // note: this is proportinal to viewer, so we can normalize later + + Matrix4x4_Transform3x3(&rsurface.matrix, reflected, worldreflected); + VectorNormalize(worldreflected); + + // note: this sphere map only uses world x and z! + // so positive and negative y will LOOK THE SAME. + out_tc[0] = 0.5 + 0.5 * worldreflected[1]; + out_tc[1] = 0.5 - 0.5 * worldreflected[2]; } } rsurface.texcoordtexture2f = rsurface.array_generatedtexcoordtexture2f;