+ 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) * ispacing[0]);
+ numsteps = bound(1, numsteps, 1024);
+ w = 1.0f / numsteps;
+ VectorScale(stepdelta, w, stepdelta);
+ VectorMA(clipstart, 0.5f, stepdelta, 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]) - 0.5f;
+ texlerp[1][1] = ((steppos[1] - mins[1]) * ispacing[1]) - 0.5f;
+ texlerp[1][2] = ((steppos[2] - mins[2]) * ispacing[2]) - 0.5f;
+ 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)
+ {
+ // it is within bounds... do the real work now
+ // 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 (pixelband = 0;pixelband < pixelbands;pixelband++)
+ {
+ for (corner = 0;corner < 8;corner++)
+ {
+ // calculate address for pixel
+ w = pixelweight[corner];
+ pixel = pixels + 4 * pixelindex[corner] + pixelband * pixelsperband * 4;
+ highpixel = highpixels + 4 * pixelindex[corner] + pixelband * pixelsperband * 4;
+ // add to the high precision pixel color
+ highpixel[0] += (splatcolor[pixelband*4+0]*w);
+ highpixel[1] += (splatcolor[pixelband*4+1]*w);
+ highpixel[2] += (splatcolor[pixelband*4+2]*w);
+ highpixel[3] += (splatcolor[pixelband*4+3]*w);
+ // flag the low precision pixel as needing to be updated
+ pixel[3] = 255;
+ // advance to next band of coefficients
+ //pixel += pixelsperband*4;
+ //highpixel += pixelsperband*4;
+ }
+ }
+ }
+ VectorAdd(steppos, stepdelta, steppos);