- // it is within bounds... do the real work now
- // calculate first order spherical harmonics values (average, slopeX, slopeY, slopeZ)
- if (settings.directionalshading)
- {
- VectorSubtract(clipstart, cliptrace.endpos, clipdiff);
- VectorNormalize(clipdiff);
- splatcolor[ 0] = shotcolor[0] * clipdiff[2];
- splatcolor[ 1] = shotcolor[0] * clipdiff[1];
- splatcolor[ 2] = shotcolor[0] * clipdiff[0];
- splatcolor[ 3] = shotcolor[0];
- splatcolor[ 4] = shotcolor[1] * clipdiff[2];
- splatcolor[ 5] = shotcolor[1] * clipdiff[1];
- splatcolor[ 6] = shotcolor[1] * clipdiff[0];
- splatcolor[ 7] = shotcolor[1];
- splatcolor[ 8] = shotcolor[2] * clipdiff[2];
- splatcolor[ 9] = shotcolor[2] * clipdiff[1];
- splatcolor[10] = shotcolor[2] * clipdiff[0];
- splatcolor[11] = shotcolor[2];
- w = VectorLength(shotcolor);
- splatcolor[12] = clipdiff[2] * w;
- splatcolor[13] = clipdiff[1] * w;
- splatcolor[14] = clipdiff[0] * w;
- splatcolor[15] = 1.0f;
- }
- else
- {
- splatcolor[ 0] = shotcolor[2];
- splatcolor[ 1] = shotcolor[1];
- splatcolor[ 2] = shotcolor[0];
- splatcolor[ 3] = 1.0f;
- }
- // calculate the lerp factors
- texlerp[1][0] -= tex[0];
- texlerp[1][1] -= tex[1];
- texlerp[1][2] -= tex[2];
- texlerp[0][0] = 1.0f - texlerp[1][0];
- texlerp[0][1] = 1.0f - texlerp[1][1];
- texlerp[0][2] = 1.0f - texlerp[1][2];
- // calculate individual pixel indexes and weights
- pixelindex[0] = (((tex[2] )*resolution[1]+tex[1] )*resolution[0]+tex[0] );pixelweight[0] = (texlerp[0][0]*texlerp[0][1]*texlerp[0][2]);
- pixelindex[1] = (((tex[2] )*resolution[1]+tex[1] )*resolution[0]+tex[0]+1);pixelweight[1] = (texlerp[1][0]*texlerp[0][1]*texlerp[0][2]);
- pixelindex[2] = (((tex[2] )*resolution[1]+tex[1]+1)*resolution[0]+tex[0] );pixelweight[2] = (texlerp[0][0]*texlerp[1][1]*texlerp[0][2]);
- pixelindex[3] = (((tex[2] )*resolution[1]+tex[1]+1)*resolution[0]+tex[0]+1);pixelweight[3] = (texlerp[1][0]*texlerp[1][1]*texlerp[0][2]);
- pixelindex[4] = (((tex[2]+1)*resolution[1]+tex[1] )*resolution[0]+tex[0] );pixelweight[4] = (texlerp[0][0]*texlerp[0][1]*texlerp[1][2]);
- pixelindex[5] = (((tex[2]+1)*resolution[1]+tex[1] )*resolution[0]+tex[0]+1);pixelweight[5] = (texlerp[1][0]*texlerp[0][1]*texlerp[1][2]);
- pixelindex[6] = (((tex[2]+1)*resolution[1]+tex[1]+1)*resolution[0]+tex[0] );pixelweight[6] = (texlerp[0][0]*texlerp[1][1]*texlerp[1][2]);
- pixelindex[7] = (((tex[2]+1)*resolution[1]+tex[1]+1)*resolution[0]+tex[0]+1);pixelweight[7] = (texlerp[1][0]*texlerp[1][1]*texlerp[1][2]);
- // update the 8 pixels...
- for (corner = 0;corner < 8;corner++)
+ VectorSubtract(clipstart, cliptrace.endpos, clipdiff);
+ VectorNormalize(clipdiff);
+ // store bentnormal in case the shader has a use for it
+ splatcolor[ 4] = clipdiff[0] * w;
+ splatcolor[ 5] = clipdiff[1] * w;
+ splatcolor[ 6] = clipdiff[2] * w;
+ splatcolor[ 7] = w;
+ // accumulate directional contributions (+X, +Y, +Z, -X, -Y, -Z)
+ splatcolor[ 8] = shotcolor[0] * max(0.0f, clipdiff[0]);
+ splatcolor[ 9] = shotcolor[0] * max(0.0f, clipdiff[1]);
+ splatcolor[10] = shotcolor[0] * max(0.0f, clipdiff[2]);
+ splatcolor[11] = 0.0f;
+ splatcolor[12] = shotcolor[1] * max(0.0f, clipdiff[0]);
+ splatcolor[13] = shotcolor[1] * max(0.0f, clipdiff[1]);
+ splatcolor[14] = shotcolor[1] * max(0.0f, clipdiff[2]);
+ splatcolor[15] = 0.0f;
+ splatcolor[16] = shotcolor[2] * max(0.0f, clipdiff[0]);
+ splatcolor[17] = shotcolor[2] * max(0.0f, clipdiff[1]);
+ splatcolor[18] = shotcolor[2] * max(0.0f, clipdiff[2]);
+ splatcolor[19] = 0.0f;
+ splatcolor[20] = shotcolor[0] * max(0.0f, -clipdiff[0]);
+ splatcolor[21] = shotcolor[0] * max(0.0f, -clipdiff[1]);
+ splatcolor[22] = shotcolor[0] * max(0.0f, -clipdiff[2]);
+ splatcolor[23] = 0.0f;
+ splatcolor[24] = shotcolor[1] * max(0.0f, -clipdiff[0]);
+ splatcolor[25] = shotcolor[1] * max(0.0f, -clipdiff[1]);
+ splatcolor[26] = shotcolor[1] * max(0.0f, -clipdiff[2]);
+ splatcolor[27] = 0.0f;
+ splatcolor[28] = shotcolor[2] * max(0.0f, -clipdiff[0]);
+ splatcolor[29] = shotcolor[2] * max(0.0f, -clipdiff[1]);
+ splatcolor[30] = shotcolor[2] * max(0.0f, -clipdiff[2]);
+ splatcolor[31] = 0.0f;
+ }
+ // calculate the number of steps we need to traverse this distance
+ VectorSubtract(cliptrace.endpos, clipstart, stepdelta);
+ numsteps = (int)(VectorLength(stepdelta) / settings.airstepsize);
+ numsteps = bound(1, numsteps, settings.airstepmax);
+ w = 1.0f / numsteps;
+ VectorScale(stepdelta, w, stepdelta);
+ VectorMA(clipstart, 0.5f, stepdelta, steppos);
+ if (settings.airstepmax == 1)
+ VectorCopy(cliptrace.endpos, steppos);
+ for (step = 0;step < numsteps;step++)
+ {
+ r_refdef.stats.bouncegrid_splats++;
+ // figure out which texture pixel this is in
+ texlerp[1][0] = ((steppos[0] - mins[0]) * ispacing[0]);
+ texlerp[1][1] = ((steppos[1] - mins[1]) * ispacing[1]);
+ texlerp[1][2] = ((steppos[2] - mins[2]) * ispacing[2]);
+ tex[0] = (int)floor(texlerp[1][0]);
+ tex[1] = (int)floor(texlerp[1][1]);
+ tex[2] = (int)floor(texlerp[1][2]);
+ if (tex[0] >= 1 && tex[1] >= 1 && tex[2] >= 1 && tex[0] < resolution[0] - 2 && tex[1] < resolution[1] - 2 && tex[2] < resolution[2] - 2)