-
-/*
- if (mod_generatelightmaps_maxsamples <= mod_generatelightmaps_numsamples)
- {
- lightmapsample_t *oldsamples = mod_generatelightmaps_samples;
- mod_generatelightmaps_maxsamples = max(65536, mod_generatelightmaps_maxsamples * 2);
-
-
- }
- sample = &mod_generatelightmaps_samples[mod_generatelightmaps_numsamples++];
- memset(sample, 0, sizeof(*sample));
- sample->pos[0] = pos[0];
- sample->pos[1] = pos[1];
- sample->pos[2] = pos[2];
- sample->normal[0] = normal[0];
- sample->normal[1] = normal[1];
- sample->normal[2] = normal[2];
- sample->vertex_color = vertex_color;
- sample->lm_bgr = lm_bgr;
- sample->lm_dir = lm_dir;
- */
+ int i;
+ for (i = 0;i < 4*3;i++)
+ sh1[i] = 0.0f;
+ R_SampleRTLights(pos, sh1);
+}
+
+static void Mod_GenerateLightmaps_LightmapSample(const float *pos, const float *normal, unsigned char *lm_bgr, unsigned char *lm_dir)
+{
+ float sh1[4*3];
+ float color[3];
+ float dir[3];
+ Mod_GenerateLightmaps_SamplePoint(pos, sh1);
+ VectorSet(dir, VectorLength(sh1 + 3), VectorLength(sh1 + 6), VectorLength(sh1 + 9));
+ VectorNormalize(dir);
+ VectorScale(sh1, 127.5f, color);
+ VectorSet(dir, (dir[0]+1.0f)*127.5f, (dir[1]+1.0f)*127.5f, (dir[2]+1.0f)*127.5f);
+ lm_bgr[0] = (unsigned char)bound(0.0f, color[2], 255.0f);
+ lm_bgr[1] = (unsigned char)bound(0.0f, color[1], 255.0f);
+ lm_bgr[2] = (unsigned char)bound(0.0f, color[0], 255.0f);
+ lm_bgr[3] = 255;
+ lm_dir[0] = (unsigned char)dir[0];
+ lm_dir[1] = (unsigned char)dir[1];
+ lm_dir[2] = (unsigned char)dir[2];
+ lm_dir[3] = 255;
+}
+
+static void Mod_GenerateLightmaps_VertexSample(const float *pos, const float *normal, float *vertex_color)
+{
+ float sh1[4*3];
+ Mod_GenerateLightmaps_SamplePoint(pos, sh1);
+ VectorCopy(sh1, vertex_color);
+}
+
+static void Mod_GenerateLightmaps_GridSample(const float *pos, q3dlightgrid_t *s)
+{
+ float sh1[4*3];
+ float ambient[3];
+ float diffuse[3];
+ float dir[3];
+ Mod_GenerateLightmaps_SamplePoint(pos, sh1);
+ // calculate the direction we'll use to reduce the sh1 to a directional light source
+ VectorSet(dir, VectorLength(sh1 + 3), VectorLength(sh1 + 6), VectorLength(sh1 + 9));
+ VectorNormalize(dir);
+ // scale the ambient from 0-2 to 0-255
+ VectorScale(sh1, 127.5f, ambient);
+ // extract the diffuse color along the chosen direction and scale it
+ diffuse[0] = (dir[0]*sh1[3] + dir[1]*sh1[6] + dir[2]*sh1[ 9] + sh1[0]) * 127.5f;
+ diffuse[1] = (dir[0]*sh1[4] + dir[1]*sh1[7] + dir[2]*sh1[10] + sh1[1]) * 127.5f;
+ diffuse[2] = (dir[0]*sh1[5] + dir[1]*sh1[8] + dir[2]*sh1[11] + sh1[2]) * 127.5f;
+ // encode to the grid format
+ s->ambientrgb[0] = (unsigned char)bound(0.0f, ambient[0], 255.0f);
+ s->ambientrgb[1] = (unsigned char)bound(0.0f, ambient[1], 255.0f);
+ s->ambientrgb[2] = (unsigned char)bound(0.0f, ambient[2], 255.0f);
+ s->diffusergb[0] = (unsigned char)bound(0.0f, diffuse[0], 255.0f);
+ s->diffusergb[1] = (unsigned char)bound(0.0f, diffuse[1], 255.0f);
+ s->diffusergb[2] = (unsigned char)bound(0.0f, diffuse[2], 255.0f);
+ if (dir[2] >= 0.99f) {s->diffuseyaw = 0;s->diffusepitch = 0;}
+ else if (dir[2] <= -0.99f) {s->diffuseyaw = 0;s->diffusepitch = 128;}
+ else {s->diffuseyaw = (unsigned char)(acos(dir[2]) * (127.5f/M_PI));s->diffusepitch = (unsigned char)(atan2(dir[1], dir[0]) * (127.5f/M_PI));}