old fixes including for rgb_gen_topcolor in shaders

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3098 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2009-01-15 04:56:44 +00:00
parent 7f90f66bfc
commit 9fc7a20e9c
2 changed files with 98 additions and 59 deletions

View file

@ -347,7 +347,7 @@ int R_LoadTexture(char *name, int width, int height, void *data, void *palette,
#define R_LoadTexture8(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?D3D_LoadTexture(skinname, width, height, data, usemips, alpha):GL_LoadTexture(skinname, width, height, data, usemips, alpha)) #define R_LoadTexture8(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?D3D_LoadTexture(skinname, width, height, data, usemips, alpha):GL_LoadTexture(skinname, width, height, data, usemips, alpha))
#define R_LoadTexture32(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?D3D_LoadTexture32(skinname, width, height, data, usemips, alpha):GL_LoadTexture32(skinname, width, height, data, usemips, alpha)) #define R_LoadTexture32(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?D3D_LoadTexture32(skinname, width, height, data, usemips, alpha):GL_LoadTexture32(skinname, width, height, data, usemips, alpha))
#define R_LoadTextureFB(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?D3D_LoadTextureFB(skinname, width, height, data, usemips, alpha):GL_LoadTextureFB(skinname, width, height, data, usemips, alpha)) #define R_LoadTextureFB(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?D3D_LoadTextureFB(skinname, width, height, data, usemips, alpha):GL_LoadTextureFB(skinname, width, height, data, usemips, alpha))
#define R_LoadTexture8Bump(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?/*D3D_LoadTexture8Bump(skinname, width, height, data, usemips, alpha)*/NULL:GL_LoadTexture8Bump(skinname, width, height, data, usemips, alpha)) #define R_LoadTexture8Bump(skinname,width,height,data,usemips,alpha) ((qrenderer == QR_DIRECT3D)?D3D_LoadTexture8Bump(skinname, width, height, data, usemips, alpha):GL_LoadTexture8Bump(skinname, width, height, data, usemips, alpha))
#define R_FindTexture(name) ((qrenderer == QR_DIRECT3D)?D3D_FindTexture(name):GL_FindTexture(name)) #define R_FindTexture(name) ((qrenderer == QR_DIRECT3D)?D3D_FindTexture(name):GL_FindTexture(name))
#define R_LoadCompressed(name) ((qrenderer == QR_DIRECT3D)?D3D_LoadCompressed(name):GL_LoadCompressed(name)) #define R_LoadCompressed(name) ((qrenderer == QR_DIRECT3D)?D3D_LoadCompressed(name):GL_LoadCompressed(name))

View file

@ -1265,16 +1265,22 @@ void R_ModifyTextureCoords ( shaderpass_t *pass, int unit )
float *tcArray, *buffer; float *tcArray, *buffer;
tcmod_t *tcmod; tcmod_t *tcmod;
r_texNums[unit] = R_ShaderpassTex ( pass ); r_texNums[unit] = R_ShaderpassTex(pass);
// we're smart enough not to copy data and simply switch the pointer // we're smart enough not to copy data and simply switch the pointer
if ( !pass->numtcmods ) { if (!pass->numtcmods)
if ( pass->tcgen == TC_GEN_BASE ) { {
qglTexCoordPointer( 2, GL_FLOAT, 0, coordsArray ); if (pass->tcgen == TC_GEN_BASE)
} else if ( pass->tcgen == TC_GEN_LIGHTMAP ) { {
qglTexCoordPointer( 2, GL_FLOAT, 0, lightmapCoordsArray ); qglTexCoordPointer(2, GL_FLOAT, 0, coordsArray);
} else { }
qglTexCoordPointer( 2, GL_FLOAT, 0, R_VertexTCBase (pass->tcgen, unit)); else if (pass->tcgen == TC_GEN_LIGHTMAP)
{
qglTexCoordPointer(2, GL_FLOAT, 0, lightmapCoordsArray);
}
else
{
qglTexCoordPointer(2, GL_FLOAT, 0, R_VertexTCBase(pass->tcgen, unit));
} }
return; return;
} }
@ -1290,10 +1296,11 @@ void R_ModifyTextureCoords ( shaderpass_t *pass, int unit )
{ {
case SHADER_TCMOD_ROTATE: case SHADER_TCMOD_ROTATE:
cost = tcmod->args[0] * r_localShaderTime; cost = tcmod->args[0] * r_localShaderTime;
sint = R_FastSin( cost ); sint = R_FastSin(cost);
cost = R_FastSin( cost + 0.25 ); cost = R_FastSin(cost + 0.25);
for ( j = 0; j < numVerts; j++, tcArray += 2 ) { for (j = 0; j < numVerts; j++, tcArray += 2)
{
t1 = cost * (tcArray[0] - 0.5f) - sint * (tcArray[1] - 0.5f) + 0.5f; t1 = cost * (tcArray[0] - 0.5f) - sint * (tcArray[1] - 0.5f) + 0.5f;
t2 = cost * (tcArray[1] - 0.5f) + sint * (tcArray[0] - 0.5f) + 0.5f; t2 = cost * (tcArray[1] - 0.5f) + sint * (tcArray[0] - 0.5f) + 0.5f;
tcArray[0] = t1; tcArray[0] = t1;
@ -1305,7 +1312,8 @@ void R_ModifyTextureCoords ( shaderpass_t *pass, int unit )
t1 = tcmod->args[0]; t1 = tcmod->args[0];
t2 = tcmod->args[1]; t2 = tcmod->args[1];
for ( j = 0; j < numVerts; j++, tcArray += 2 ) { for (j = 0; j < numVerts; j++, tcArray += 2)
{
tcArray[0] = tcArray[0] * t1; tcArray[0] = tcArray[0] * t1;
tcArray[1] = tcArray[1] * t2; tcArray[1] = tcArray[1] * t2;
} }
@ -1315,20 +1323,22 @@ void R_ModifyTextureCoords ( shaderpass_t *pass, int unit )
t1 = tcmod->args[2] + r_localShaderTime * tcmod->args[3]; t1 = tcmod->args[2] + r_localShaderTime * tcmod->args[3];
t2 = tcmod->args[1]; t2 = tcmod->args[1];
for ( j = 0; j < numVerts; j++, tcArray += 2 ) { for (j = 0; j < numVerts; j++, tcArray += 2)
{
tcArray[0] = tcArray[0] + R_FastSin (tcArray[0]*t2+t1) * t2; tcArray[0] = tcArray[0] + R_FastSin (tcArray[0]*t2+t1) * t2;
tcArray[1] = tcArray[1] + R_FastSin (tcArray[1]*t2+t1) * t2; tcArray[1] = tcArray[1] + R_FastSin (tcArray[1]*t2+t1) * t2;
} }
break; break;
case SHADER_TCMOD_STRETCH: case SHADER_TCMOD_STRETCH:
table = R_TableForFunc ( tcmod->args[0] ); table = R_TableForFunc(tcmod->args[0]);
t2 = tcmod->args[3] + r_localShaderTime * tcmod->args[4]; t2 = tcmod->args[3] + r_localShaderTime * tcmod->args[4];
t1 = FTABLE_EVALUATE ( table, t2 ) * tcmod->args[2] + tcmod->args[1]; t1 = FTABLE_EVALUATE(table, t2) * tcmod->args[2] + tcmod->args[1];
t1 = t1 ? 1.0f / t1 : 1.0f; t1 = t1 ? 1.0f / t1 : 1.0f;
t2 = 0.5f - 0.5f * t1; t2 = 0.5f - 0.5f * t1;
for ( j = 0; j < numVerts; j++, tcArray += 2 ) { for (j = 0; j < numVerts; j++, tcArray += 2)
{
tcArray[0] = tcArray[0] * t1 + t2; tcArray[0] = tcArray[0] * t1 + t2;
tcArray[1] = tcArray[1] * t1 + t2; tcArray[1] = tcArray[1] * t1 + t2;
} }
@ -1338,14 +1348,16 @@ void R_ModifyTextureCoords ( shaderpass_t *pass, int unit )
t1 = tcmod->args[0] * r_localShaderTime; t1 = tcmod->args[0] * r_localShaderTime;
t2 = tcmod->args[1] * r_localShaderTime; t2 = tcmod->args[1] * r_localShaderTime;
for ( j = 0; j < numVerts; j++, tcArray += 2 ) { for (j = 0; j < numVerts; j++, tcArray += 2)
{
tcArray[0] = tcArray[0] + t1; tcArray[0] = tcArray[0] + t1;
tcArray[1] = tcArray[1] + t2; tcArray[1] = tcArray[1] + t2;
} }
break; break;
case SHADER_TCMOD_TRANSFORM: case SHADER_TCMOD_TRANSFORM:
for ( j = 0; j < numVerts; j++, tcArray += 2 ) { for (j = 0; j < numVerts; j++, tcArray += 2)
{
t1 = tcArray[0]; t1 = tcArray[0];
t2 = tcArray[1]; t2 = tcArray[1];
tcArray[0] = t1 * tcmod->args[0] + t2 * tcmod->args[2] + tcmod->args[4]; tcArray[0] = t1 * tcmod->args[0] + t2 * tcmod->args[2] + tcmod->args[4];
@ -1386,9 +1398,12 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
rgbgenfunc = &pass->rgbgen_func; rgbgenfunc = &pass->rgbgen_func;
alphagenfunc = &pass->alphagen_func; alphagenfunc = &pass->alphagen_func;
if ( noArray ) { if (noArray)
{
numColors = 1; numColors = 1;
} else { }
else
{
numColors = numVerts; numColors = numVerts;
} }
@ -1397,6 +1412,7 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
switch (pass->rgbgen) switch (pass->rgbgen)
{ {
default:
case RGB_GEN_IDENTITY: case RGB_GEN_IDENTITY:
memset ( bArray, 255, sizeof(byte_vec4_t)*numColors ); memset ( bArray, 255, sizeof(byte_vec4_t)*numColors );
break; break;
@ -1414,10 +1430,10 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
break; break;
case RGB_GEN_WAVE: case RGB_GEN_WAVE:
table = R_TableForFunc ( rgbgenfunc->type ); table = R_TableForFunc(rgbgenfunc->type);
c = rgbgenfunc->args[2] + r_localShaderTime * rgbgenfunc->args[3]; c = rgbgenfunc->args[2] + r_localShaderTime * rgbgenfunc->args[3];
c = FTABLE_EVALUATE ( table, c ) * rgbgenfunc->args[1] + rgbgenfunc->args[0]; c = FTABLE_EVALUATE(table, c) * rgbgenfunc->args[1] + rgbgenfunc->args[0];
clamp ( c, 0.0f, 1.0f ); clamp(c, 0.0f, 1.0f);
memset ( bArray, FloatToByte (c), sizeof(byte_vec4_t)*numColors ); memset ( bArray, FloatToByte (c), sizeof(byte_vec4_t)*numColors );
break; break;
@ -1427,7 +1443,7 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
((qbyte*)&b)[1] = currententity->shaderRGBAf[1]; ((qbyte*)&b)[1] = currententity->shaderRGBAf[1];
((qbyte*)&b)[2] = currententity->shaderRGBAf[2]; ((qbyte*)&b)[2] = currententity->shaderRGBAf[2];
((qbyte*)&b)[3] = currententity->shaderRGBAf[3]; ((qbyte*)&b)[3] = currententity->shaderRGBAf[3];
for ( i = 0; i < numColors; i++, bArray += 4 ) for (i = 0; i < numColors; i++, bArray += 4)
{ {
*(int *)bArray = b; *(int *)bArray = b;
} }
@ -1438,7 +1454,7 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
((qbyte*)&b)[1] = 255-currententity->shaderRGBAf[1]; ((qbyte*)&b)[1] = 255-currententity->shaderRGBAf[1];
((qbyte*)&b)[2] = 255-currententity->shaderRGBAf[2]; ((qbyte*)&b)[2] = 255-currententity->shaderRGBAf[2];
((qbyte*)&b)[3] = 255-currententity->shaderRGBAf[3]; ((qbyte*)&b)[3] = 255-currententity->shaderRGBAf[3];
for ( i = 0; i < numColors; i++, bArray += 4 ) for (i = 0; i < numColors; i++, bArray += 4)
{ {
*(int *)bArray = b; *(int *)bArray = b;
} }
@ -1446,14 +1462,18 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
case RGB_GEN_VERTEX: case RGB_GEN_VERTEX:
case RGB_GEN_EXACT_VERTEX: case RGB_GEN_EXACT_VERTEX:
memcpy ( bArray, vArray, sizeof(byte_vec4_t)*numColors ); memcpy (bArray, vArray, sizeof(byte_vec4_t)*numColors);
break; break;
case RGB_GEN_TOPCOLOR: //multiply vertex by topcolor (for player models) case RGB_GEN_TOPCOLOR: //multiply vertex by topcolor (for player models)
{ {
int rc, gc, bc; int rc, gc, bc;
R_FetchTopColour(&rc, &gc, &bc); R_FetchTopColour(&rc, &gc, &bc);
for ( i = 0; i < numColors; i++, bArray += 4, vArray += 4 ) {
R_LightArrays((byte_vec4_t*)vArray, numColors, normalsArray);
for (i = 0; i < numColors; i++, bArray += 4, vArray += 4)
{
bArray[0] = (vArray[0]*rc)>>8; bArray[0] = (vArray[0]*rc)>>8;
bArray[1] = (vArray[1]*gc)>>8; bArray[1] = (vArray[1]*gc)>>8;
bArray[2] = (vArray[2]*bc)>>8; bArray[2] = (vArray[2]*bc)>>8;
@ -1465,7 +1485,11 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
{ {
int rc, gc, bc; int rc, gc, bc;
R_FetchBottomColour(&rc, &gc, &bc); R_FetchBottomColour(&rc, &gc, &bc);
for ( i = 0; i < numColors; i++, bArray += 4, vArray += 4 ) {
R_LightArrays((byte_vec4_t*)vArray, numColors, normalsArray);
for (i = 0; i < numColors; i++, bArray += 4, vArray += 4)
{
bArray[0] = (vArray[0]*rc)>>8; bArray[0] = (vArray[0]*rc)>>8;
bArray[1] = (vArray[1]*gc)>>8; bArray[1] = (vArray[1]*gc)>>8;
bArray[2] = (vArray[2]*bc)>>8; bArray[2] = (vArray[2]*bc)>>8;
@ -1475,7 +1499,8 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
case RGB_GEN_ONE_MINUS_VERTEX: case RGB_GEN_ONE_MINUS_VERTEX:
for ( i = 0; i < numColors; i++, bArray += 4, vArray += 4 ) { for (i = 0; i < numColors; i++, bArray += 4, vArray += 4)
{
bArray[0] = 255 - vArray[0]; bArray[0] = 255 - vArray[0];
bArray[1] = 255 - vArray[1]; bArray[1] = 255 - vArray[1];
bArray[2] = 255 - vArray[2]; bArray[2] = 255 - vArray[2];
@ -1483,18 +1508,15 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
break; break;
case RGB_GEN_LIGHTING_DIFFUSE: case RGB_GEN_LIGHTING_DIFFUSE:
if ( !currententity ) if (!currententity)
{ {
memset ( bArray, 255, sizeof(byte_vec4_t)*numColors ); memset (bArray, 255, sizeof(byte_vec4_t)*numColors);
} }
else else
{ {
R_LightArrays((byte_vec4_t*)bArray, numColors, normalsArray); R_LightArrays((byte_vec4_t*)bArray, numColors, normalsArray);
} }
break; break;
default:
break;
} }
bArray = colorArray[0]; bArray = colorArray[0];
@ -1502,8 +1524,10 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
switch (pass->alphagen) switch (pass->alphagen)
{ {
default:
case ALPHA_GEN_IDENTITY: case ALPHA_GEN_IDENTITY:
for ( i = 0; i < numColors; i++, bArray += 4 ) { for (i = 0; i < numColors; i++, bArray += 4)
{
bArray[3] = 255; bArray[3] = 255;
} }
break; break;
@ -1511,7 +1535,8 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
case ALPHA_GEN_CONST: case ALPHA_GEN_CONST:
b = FloatToByte ( alphagenfunc->args[0] ); b = FloatToByte ( alphagenfunc->args[0] );
for ( i = 0; i < numColors; i++, bArray += 4 ) { for (i = 0; i < numColors; i++, bArray += 4)
{
bArray[3] = b; bArray[3] = b;
} }
break; break;
@ -1522,25 +1547,28 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
a = FTABLE_EVALUATE ( table, a ) * alphagenfunc->args[1] + alphagenfunc->args[0]; a = FTABLE_EVALUATE ( table, a ) * alphagenfunc->args[1] + alphagenfunc->args[0];
b = FloatToByte ( bound (0.0f, a, 1.0f) ); b = FloatToByte ( bound (0.0f, a, 1.0f) );
for ( i = 0; i < numColors; i++, bArray += 4 ) { for (i = 0; i < numColors; i++, bArray += 4)
{
bArray[3] = b; bArray[3] = b;
} }
break; break;
case ALPHA_GEN_PORTAL: case ALPHA_GEN_PORTAL:
VectorAdd ( vertexArray[0], currententity->origin, v ); VectorAdd(vertexArray[0], currententity->origin, v);
VectorSubtract ( r_origin, v, t ); VectorSubtract(r_origin, v, t);
a = VectorLength ( t ) * (1.0 / 255.0); a = VectorLength ( t ) * (1.0 / 255.0);
clamp ( a, 0.0f, 1.0f ); clamp ( a, 0.0f, 1.0f );
b = FloatToByte ( a ); b = FloatToByte ( a );
for ( i = 0; i < numColors; i++, bArray += 4 ) { for (i = 0; i < numColors; i++, bArray += 4)
{
bArray[3] = b; bArray[3] = b;
} }
break; break;
case ALPHA_GEN_VERTEX: case ALPHA_GEN_VERTEX:
for ( i = 0; i < numColors; i++, bArray += 4, vArray += 4 ) { for (i = 0; i < numColors; i++, bArray += 4, vArray += 4)
{
bArray[3] = vArray[3]; bArray[3] = vArray[3];
} }
break; break;
@ -1561,20 +1589,24 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
{ {
mat3_t axis; mat3_t axis;
AngleVectors(currententity->angles, axis[0], axis[1], axis[2]); AngleVectors(currententity->angles, axis[0], axis[1], axis[2]);
VectorSubtract ( r_origin, currententity->origin, t ); VectorSubtract(r_origin, currententity->origin, t);
if ( !Matrix3_Compare (axis, axisDefault) ) { if (!Matrix3_Compare(axis, axisDefault))
Matrix3_Multiply_Vec3 ( axis, t, v ); {
} else { Matrix3_Multiply_Vec3(axis, t, v );
VectorCopy ( t, v ); }
} else
{
VectorCopy(t, v);
}
for ( i = 0; i < numColors; i++, bArray += 4 ) { for (i = 0; i < numColors; i++, bArray += 4)
VectorSubtract ( v, vertexArray[i], t ); {
a = DotProduct( t, normalsArray[i] ) * Q_rsqrt ( DotProduct(t,t) ); VectorSubtract(v, vertexArray[i], t);
a = a * a * a * a * a; a = DotProduct(t, normalsArray[i] ) * Q_rsqrt(DotProduct(t,t));
bArray[3] = FloatToByte ( bound (0.0f, a, 1.0f) ); a = a * a * a * a * a;
} bArray[3] = FloatToByte(bound (0.0f, a, 1.0f));
}
} }
break; break;
@ -1617,26 +1649,33 @@ void R_ModifyColor ( meshbuffer_t *mb, shaderpass_t *pass )
c = DotProduct ( diff, fog_vpn ); c = DotProduct ( diff, fog_vpn );
a = (1.0f - bound ( 0, c, 1.0f )) * (1.0 / 255.0); a = (1.0f - bound ( 0, c, 1.0f )) * (1.0 / 255.0);
} else { }
else
{
vdist = PlaneDiff ( diff, fogplane ); vdist = PlaneDiff ( diff, fogplane );
if ( vdist < 0 ) { if ( vdist < 0 )
{
VectorSubtract ( diff, r_origin, diff ); VectorSubtract ( diff, r_origin, diff );
c = vdist / ( vdist - dist ); c = vdist / ( vdist - dist );
c *= DotProduct ( diff, fog_vpn ); c *= DotProduct ( diff, fog_vpn );
a = (1.0f - bound ( 0, c, 1.0f )) * (1.0 / 255.0); a = (1.0f - bound ( 0, c, 1.0f )) * (1.0 / 255.0);
} else { }
else
{
a = 1.0 / 255.0; a = 1.0 / 255.0;
} }
} }
if ( pass->blendmode == GL_ADD || if (pass->blendmode == GL_ADD ||
((pass->blendsrc == GL_ZERO) && (pass->blenddst == GL_ONE_MINUS_SRC_COLOR)) ) { ((pass->blendsrc == GL_ZERO) && (pass->blenddst == GL_ONE_MINUS_SRC_COLOR)) ) {
bArray[0] = FloatToByte ( (float)bArray[0]*a ); bArray[0] = FloatToByte ( (float)bArray[0]*a );
bArray[1] = FloatToByte ( (float)bArray[1]*a ); bArray[1] = FloatToByte ( (float)bArray[1]*a );
bArray[2] = FloatToByte ( (float)bArray[2]*a ); bArray[2] = FloatToByte ( (float)bArray[2]*a );
} else { }
else
{
bArray[3] = FloatToByte ( (float)bArray[3]*a ); bArray[3] = FloatToByte ( (float)bArray[3]*a );
} }
} }