diff options
author | SmileTheory <SmileTheory@gmail.com> | 2013-11-12 19:21:51 -0800 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2014-06-17 17:43:36 +0100 |
commit | 38af27b32b1302fd5ddd83d992fc8ec73209b3ad (patch) | |
tree | 0af9a9e571ffd1120d4603bd8d09f092875786e3 /src/renderergl2/tr_surface.c | |
parent | 1efea34f7dc0afa21c1ddaa62705c8f4e6b76d9e (diff) |
OpenGL2: Calculate bitangent in shader, and store normal/tangent as normalized byte arrays.
Diffstat (limited to 'src/renderergl2/tr_surface.c')
-rw-r--r-- | src/renderergl2/tr_surface.c | 99 |
1 files changed, 66 insertions, 33 deletions
diff --git a/src/renderergl2/tr_surface.c b/src/renderergl2/tr_surface.c index eff3a257..6853bdc7 100644 --- a/src/renderergl2/tr_surface.c +++ b/src/renderergl2/tr_surface.c @@ -125,10 +125,25 @@ void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, float color[4], // constant normal all the way around VectorSubtract( vec3_origin, backEnd.viewParms.or.axis[0], normal ); - VectorCopy(normal, tess.normal[ndx]); - VectorCopy(normal, tess.normal[ndx+1]); - VectorCopy(normal, tess.normal[ndx+2]); - VectorCopy(normal, tess.normal[ndx+3]); + tess.normal[ndx][0] = (uint8_t)(normal[0] * 127.5f + 128.0f); + tess.normal[ndx][1] = (uint8_t)(normal[1] * 127.5f + 128.0f); + tess.normal[ndx][2] = (uint8_t)(normal[2] * 127.5f + 128.0f); + tess.normal[ndx][3] = 0; + + tess.normal[ndx+1][0] = (uint8_t)(normal[0] * 127.5f + 128.0f); + tess.normal[ndx+1][1] = (uint8_t)(normal[1] * 127.5f + 128.0f); + tess.normal[ndx+1][2] = (uint8_t)(normal[2] * 127.5f + 128.0f); + tess.normal[ndx+1][3] = 0; + + tess.normal[ndx+2][0] = (uint8_t)(normal[0] * 127.5f + 128.0f); + tess.normal[ndx+2][1] = (uint8_t)(normal[1] * 127.5f + 128.0f); + tess.normal[ndx+2][2] = (uint8_t)(normal[2] * 127.5f + 128.0f); + tess.normal[ndx+2][3] = 0; + + tess.normal[ndx+3][0] = (uint8_t)(normal[0] * 127.5f + 128.0f); + tess.normal[ndx+3][1] = (uint8_t)(normal[1] * 127.5f + 128.0f); + tess.normal[ndx+3][2] = (uint8_t)(normal[2] * 127.5f + 128.0f); + tess.normal[ndx+3][3] = 0; // standard square texture coordinates VectorSet2(tess.texCoords[ndx ][0], s1, t1); @@ -317,9 +332,10 @@ static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIn int i; glIndex_t *inIndex; srfVert_t *dv; - float *xyz, *normal, *texCoords, *lightCoords, *lightdir; + float *xyz, *texCoords, *lightCoords, *lightdir; + uint8_t *normal; #ifdef USE_VERT_TANGENT_SPACE - float *tangent, *bitangent; + uint8_t *tangent; #endif glIndex_t *outIndex; float *color; @@ -348,7 +364,12 @@ static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIn dv = verts; normal = tess.normal[ tess.numVertexes ]; for ( i = 0 ; i < numVerts ; i++, dv++, normal+=4 ) - VectorCopy(dv->normal, normal); + { + normal[0] = (uint8_t)(dv->normal[0] * 127.5f + 128.0f); + normal[1] = (uint8_t)(dv->normal[1] * 127.5f + 128.0f); + normal[2] = (uint8_t)(dv->normal[2] * 127.5f + 128.0f); + normal[3] = 0; + } } #ifdef USE_VERT_TANGENT_SPACE @@ -357,15 +378,12 @@ static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIn dv = verts; tangent = tess.tangent[ tess.numVertexes ]; for ( i = 0 ; i < numVerts ; i++, dv++, tangent+=4 ) - VectorCopy(dv->tangent, tangent); - } - - if ( tess.shader->vertexAttribs & ATTR_BITANGENT ) - { - dv = verts; - bitangent = tess.bitangent[ tess.numVertexes ]; - for ( i = 0 ; i < numVerts ; i++, dv++, bitangent+=4 ) - VectorCopy(dv->bitangent, bitangent); + { + tangent[0] = (uint8_t)(dv->tangent[0] * 127.5f + 128.0f); + tangent[1] = (uint8_t)(dv->tangent[1] * 127.5f + 128.0f); + tangent[2] = (uint8_t)(dv->tangent[2] * 127.5f + 128.0f); + tangent[3] = (uint8_t)(dv->tangent[3] * 127.5f + 128.0f); + } } #endif @@ -1128,7 +1146,8 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp) VectorArrayNormalize((vec4_t *)tess.normal[tess.numVertexes], numVerts); } #endif - float *outXyz, *outNormal; + float *outXyz; + uint8_t *outNormal; mdvVertex_t *newVerts; int vertNum; @@ -1145,8 +1164,16 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp) for (vertNum=0 ; vertNum < surf->numVerts ; vertNum++) { + vec3_t normal; + VectorCopy(newVerts->xyz, outXyz); - VectorCopy(newVerts->normal, outNormal); + VectorCopy(newVerts->normal, normal); + + outNormal[0] = (uint8_t)(normal[0] * 127.5f + 128.0f); + outNormal[1] = (uint8_t)(normal[1] * 127.5f + 128.0f); + outNormal[2] = (uint8_t)(normal[2] * 127.5f + 128.0f); + outNormal[3] = 0; + newVerts++; outXyz += 4; outNormal += 4; @@ -1164,15 +1191,22 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp) for (vertNum=0 ; vertNum < surf->numVerts ; vertNum++) { - VectorLerp(backlerp, newVerts->xyz, oldVerts->xyz, outXyz); - VectorLerp(backlerp, newVerts->normal, oldVerts->normal, outNormal); - //VectorNormalize(outNormal); + vec3_t normal; + + VectorLerp(newVerts->xyz, oldVerts->xyz, backlerp, outXyz); + VectorLerp(newVerts->normal, oldVerts->normal, backlerp, normal); + VectorNormalize(normal); + + outNormal[0] = (uint8_t)(normal[0] * 127.5f + 128.0f); + outNormal[1] = (uint8_t)(normal[1] * 127.5f + 128.0f); + outNormal[2] = (uint8_t)(normal[2] * 127.5f + 128.0f); + outNormal[3] = 0; + newVerts++; oldVerts++; outXyz += 4; outNormal += 4; } - VectorArrayNormalize((vec4_t *)tess.normal[tess.numVertexes], surf->numVerts); } } @@ -1293,9 +1327,9 @@ static void RB_SurfaceGrid( srfBspSurface_t *srf ) { int i, j; float *xyz; float *texCoords, *lightCoords; - float *normal; + uint8_t *normal; #ifdef USE_VERT_TANGENT_SPACE - float *tangent, *bitangent; + uint8_t *tangent; #endif float *color, *lightdir; srfVert_t *dv; @@ -1383,7 +1417,6 @@ static void RB_SurfaceGrid( srfBspSurface_t *srf ) { normal = tess.normal[numVertexes]; #ifdef USE_VERT_TANGENT_SPACE tangent = tess.tangent[numVertexes]; - bitangent = tess.bitangent[numVertexes]; #endif texCoords = tess.texCoords[numVertexes][0]; lightCoords = tess.texCoords[numVertexes][1]; @@ -1404,22 +1437,22 @@ static void RB_SurfaceGrid( srfBspSurface_t *srf ) { if ( tess.shader->vertexAttribs & ATTR_NORMAL ) { - VectorCopy(dv->normal, normal); + normal[0] = (uint8_t)(dv->normal[0] * 127.5f + 128.0f); + normal[1] = (uint8_t)(dv->normal[1] * 127.5f + 128.0f); + normal[2] = (uint8_t)(dv->normal[2] * 127.5f + 128.0f); + normal[3] = 0; normal += 4; } #ifdef USE_VERT_TANGENT_SPACE if ( tess.shader->vertexAttribs & ATTR_TANGENT ) { - VectorCopy(dv->tangent, tangent); + tangent[0] = (uint8_t)(dv->tangent[0] * 127.5f + 128.0f); + tangent[1] = (uint8_t)(dv->tangent[1] * 127.5f + 128.0f); + tangent[2] = (uint8_t)(dv->tangent[2] * 127.5f + 128.0f); + tangent[3] = (uint8_t)(dv->tangent[3] * 127.5f + 128.0f); tangent += 4; } - - if ( tess.shader->vertexAttribs & ATTR_BITANGENT ) - { - VectorCopy(dv->bitangent, bitangent); - bitangent += 4; - } #endif if ( tess.shader->vertexAttribs & ATTR_TEXCOORD ) { |