/* ========================= RB_CalcDeformNormals Wiggle the normals for wavy environment mapping ========================= */ void RB_CalcDeformNormals( deformStage_t *ds ) { int i; float scale; float *xyz = ( float * ) tess.xyz; float *normal = ( float * ) tess.normal; for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { scale = 0.98f; scale = R_NoiseGet4f( xyz[0] * scale, xyz[1] * scale, xyz[2] * scale, backEnd.refdef.floatTime * ds->deformationWave.frequency ); normal[ 0 ] += ds->deformationWave.amplitude * scale; scale = 0.98f; scale = R_NoiseGet4f( 100 + xyz[0] * scale, xyz[1] * scale, xyz[2] * scale, backEnd.refdef.floatTime * ds->deformationWave.frequency ); normal[ 1 ] += ds->deformationWave.amplitude * scale; scale = 0.98f; scale = R_NoiseGet4f( 200 + xyz[0] * scale, xyz[1] * scale, xyz[2] * scale, backEnd.refdef.floatTime * ds->deformationWave.frequency ); normal[ 2 ] += ds->deformationWave.amplitude * scale; VectorNormalizeFast( normal ); } }
// Wiggle the normals for wavy environment mapping void RB_CalcDeformNormals( deformStage_t *ds ) { int i; float scale; vector3 *xyz = &tess.xyz[0], *normal = &tess.normal[0]; for ( i = 0; i < tess.numVertexes; i++, xyz++, normal++ ) { scale = 0.98f; scale = R_NoiseGet4f( 000 + xyz->x * scale, xyz->y * scale, xyz->z * scale, tess.shaderTime * ds->deformationWave.frequency ); normal->x += ds->deformationWave.amplitude * scale; scale = 0.98f; scale = R_NoiseGet4f( 100 + xyz->x * scale, xyz->y * scale, xyz->z * scale, tess.shaderTime * ds->deformationWave.frequency ); normal->y += ds->deformationWave.amplitude * scale; scale = 0.98f; scale = R_NoiseGet4f( 200 + xyz->z * scale, xyz->y * scale, xyz->z * scale, tess.shaderTime * ds->deformationWave.frequency ); normal->z += ds->deformationWave.amplitude * scale; VectorNormalizeFast( normal ); } }
/* ** EvalWaveForm ** ** Evaluates a given waveForm_t, referencing backEnd.refdef.time directly */ static float EvalWaveForm( const waveForm_t *wf ) { float *table; if ( wf->func == GF_NOISE ) { return ( wf->base + R_NoiseGet4f( 0, 0, 0, ( backEnd.refdef.floatTime + wf->phase ) * wf->frequency ) * wf->amplitude ); } else if (wf->func == GF_RAND) { if( GetNoiseTime( backEnd.refdef.time + wf->phase ) <= wf->frequency ) { return (wf->base + wf->amplitude); } else { return wf->base; } } table = TableForFunc( wf->func ); return WAVEVALUE( table, wf->base, wf->amplitude, wf->phase, wf->frequency ); }
/* =============== R_Init =============== */ void R_Init( void ) { int err; int i; byte *ptr; ri.Printf( PRINT_ALL, "----- R_Init -----\n" ); // clear all our internal state Com_Memset( &tr, 0, sizeof( tr ) ); Com_Memset( &backEnd, 0, sizeof( backEnd ) ); Com_Memset( &tess, 0, sizeof( tess ) ); #ifdef ELITEFORCE if(sizeof(glconfig_t) != 5192) { ri.Error( ERR_FATAL, "Mod ABI incompatible: sizeof(glconfig_t) == %u != 5192", (unsigned int) sizeof(glconfig_t)); } #else if(sizeof(glconfig_t) != 11332) ri.Error( ERR_FATAL, "Mod ABI incompatible: sizeof(glconfig_t) == %u != 11332", (unsigned int) sizeof(glconfig_t)); #endif // Swap_Init(); if ( (intptr_t)tess.xyz & 15 ) { ri.Printf( PRINT_WARNING, "tess.xyz not 16 byte aligned\n" ); } Com_Memset( tess.constantColor255, 255, sizeof( tess.constantColor255 ) ); R_NoiseInit(); // // init function tables // for ( i = 0; i < FUNCTABLE_SIZE; i++ ) { tr.sinTable[i] = sin( DEG2RAD( i * 360.0f / ( ( float ) ( FUNCTABLE_SIZE - 1 ) ) ) ); tr.squareTable[i] = ( i < FUNCTABLE_SIZE/2 ) ? 1.0f : -1.0f; tr.sawToothTable[i] = (float)i / FUNCTABLE_SIZE; tr.inverseSawToothTable[i] = 1.0f - tr.sawToothTable[i]; tr.noiseTable[i] = R_NoiseGet4f(0, 0, 0, i); if ( i < FUNCTABLE_SIZE / 2 ) { if ( i < FUNCTABLE_SIZE / 4 ) { tr.triangleTable[i] = ( float ) i / ( FUNCTABLE_SIZE / 4 ); } else { tr.triangleTable[i] = 1.0f - tr.triangleTable[i-FUNCTABLE_SIZE / 4]; } } else { tr.triangleTable[i] = -tr.triangleTable[i-FUNCTABLE_SIZE/2]; } } R_InitFogTable(); R_Register(); max_polys = r_maxpolys->integer; if (max_polys < MAX_POLYS) max_polys = MAX_POLYS; max_polyverts = r_maxpolyverts->integer; if (max_polyverts < MAX_POLYVERTS) max_polyverts = MAX_POLYVERTS; ptr = ri.Hunk_Alloc( sizeof( *backEndData ) + sizeof(srfPoly_t) * max_polys + sizeof(polyVert_t) * max_polyverts, h_low); backEndData = (backEndData_t *) ptr; backEndData->polys = (srfPoly_t *) ((char *) ptr + sizeof( *backEndData )); backEndData->polyVerts = (polyVert_t *) ((char *) ptr + sizeof( *backEndData ) + sizeof(srfPoly_t) * max_polys); R_InitNextFrame(); InitOpenGL(); R_InitImages(); R_InitShaders(); R_InitSkins(); R_ModelInit(); R_InitFreeType(); err = qglGetError(); if ( err != GL_NO_ERROR ) ri.Printf (PRINT_ALL, "glGetError() = 0x%x\n", err); // print info GfxInfo_f(); ri.Printf( PRINT_ALL, "----- finished R_Init -----\n" ); }
/* =============== R_Init =============== */ void R_Init( void ) { static qboolean firstTime = qtrue; int err; int i; byte *ptr; ri.Printf(PRINT_DEVELOPER, "----- R_Init -----\n"); // clear all our internal state Com_Memset( &tr, 0, sizeof( tr ) ); Com_Memset( &backEnd, 0, sizeof( backEnd ) ); Com_Memset( &tess, 0, sizeof( tess ) ); // Swap_Init(); if ( refHeadless ) { // dummy shader tr.defaultShader = ri.Hunk_Alloc( sizeof( shader_t ), h_low ); tr.defaultShader->defaultShader = qtrue; Q_strncpyz(tr.defaultShader->name, "<default>", MAX_QPATH); // dedicated server only uses model data R_ModelInit(); return; } if ( (intptr_t)tess.xyz & 15 ) { ri.Printf( PRINT_WARNING, "tess.xyz not 16 byte aligned\n" ); } Com_Memset( tess.constantColor255, 255, sizeof( tess.constantColor255 ) ); R_NoiseInit(); // // init function tables // for ( i = 0; i < FUNCTABLE_SIZE; i++ ) { tr.sinTable[i] = sin( DEG2RAD( i * 360.0f / ( ( float ) ( FUNCTABLE_SIZE - 1 ) ) ) ); tr.squareTable[i] = ( i < FUNCTABLE_SIZE/2 ) ? 1.0f : -1.0f; tr.sawToothTable[i] = (float)i / FUNCTABLE_SIZE; tr.inverseSawToothTable[i] = 1.0f - tr.sawToothTable[i]; tr.noiseTable[i] = R_NoiseGet4f(0, 0, 0, i); if ( i < FUNCTABLE_SIZE / 2 ) { if ( i < FUNCTABLE_SIZE / 4 ) { tr.triangleTable[i] = ( float ) i / ( FUNCTABLE_SIZE / 4 ); } else { tr.triangleTable[i] = 1.0f - tr.triangleTable[i-FUNCTABLE_SIZE / 4]; } } else { tr.triangleTable[i] = -tr.triangleTable[i-FUNCTABLE_SIZE/2]; } } R_InitFogTable(); R_Register(); max_polys = r_maxpolys->integer; if (max_polys < MAX_POLYS) max_polys = MAX_POLYS; max_polyverts = r_maxpolyverts->integer; if (max_polyverts < MAX_POLYVERTS) max_polyverts = MAX_POLYVERTS; max_polybuffers = r_maxpolybuffers->integer; if (max_polybuffers < MAX_POLYBUFFERS) max_polybuffers = MAX_POLYBUFFERS; ptr = ri.Hunk_Alloc( sizeof( *backEndData ) + sizeof(srfPoly_t) * max_polys + sizeof(polyVert_t) * max_polyverts + sizeof(srfPolyBuffer_t) * max_polybuffers, h_low); backEndData = (backEndData_t *) ptr; backEndData->polys = (srfPoly_t *) ((char *) ptr + sizeof( *backEndData )); backEndData->polyVerts = (polyVert_t *) ((char *) ptr + sizeof( *backEndData ) + sizeof(srfPoly_t) * max_polys); backEndData->polybuffers = (srfPolyBuffer_t *) ((char *) ptr + sizeof( *backEndData ) + sizeof(srfPoly_t) * max_polys + sizeof(polyVert_t) * max_polyverts); R_InitNextFrame(); InitOpenGL(); R_InitImages(); R_InitShaders(); R_InitSkins(); R_ModelInit(); R_InitFreeType(); err = qglGetError(); if ( err != GL_NO_ERROR ) ri.Printf (PRINT_ALL, "glGetError() = 0x%x\n", err); if (firstTime) { firstTime = qfalse; // print info GfxInfo_f(); } ri.Printf(PRINT_DEVELOPER, "----- finished R_Init -----\n"); }