- m.depthwrite = false;
- m.depthdisable = false;
- m.tex[0] = R_GetTexture(surf->currenttexture->texture);
- if (surf->flags & SURF_DRAWFULLBRIGHT || currentrenderentity->effects & EF_FULLBRIGHT)
- {
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
- if (R_Mesh_Draw_GetBuffer(&m, true))
- {
- base[0] = base[1] = base[2] = 1.0f * m.colorscale;
- memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3]));
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- VectorCopy(base, outc);
- outc[3] = alpha;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- if (fogenabled)
- {
- VectorSubtract(outv, r_origin, diff);
- f = 1 - exp(fogdensity/DotProduct(diff, diff));
- VectorScale(outc, f, outc);
- }
- }
- R_Mesh_Render();
- }
- }
- }
- else
- {
- size3 = ((surf->extents[0]>>4)+1)*((surf->extents[1]>>4)+1)*3;
- base[0] = base[1] = base[2] = (r_ambient.value * (1.0f / 64.0f) + ((surf->flags & SURF_LIGHTMAP) ? 0 : 0.5f));
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
- if (R_Mesh_Draw_GetBuffer(&m, true))
- {
- cl = m.colorscale;
- memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3]));
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- VectorCopy(base, outc);
- outc[3] = alpha;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- if (surf->dlightframe == r_framecount)
- RSurf_LightSeparate(surf->dlightbits, m.numverts, m.vertex, m.color);
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color;i < m.numverts;i++, v++, outv += 4, outc += 4)
- {
- if (surf->flags & SURF_LIGHTMAP)
- if (surf->styles[0] != 255)
- {
- lm = surf->samples + v->lightmapoffset;
- scale = d_lightstylevalue[surf->styles[0]] * (1.0f / 32768.0f);
- VectorMA(outc, scale, lm, outc);
- if (surf->styles[1] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[surf->styles[1]] * (1.0f / 32768.0f);
- VectorMA(outc, scale, lm, outc);
- if (surf->styles[2] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[surf->styles[2]] * (1.0f / 32768.0f);
- VectorMA(outc, scale, lm, outc);
- if (surf->styles[3] != 255)
- {
- lm += size3;
- scale = d_lightstylevalue[surf->styles[3]] * (1.0f / 32768.0f);
- VectorMA(outc, scale, lm, outc);
- }
- }
- }
- }
- if (fogenabled)
- {
- VectorSubtract(outv, r_origin, diff);
- f = cl * (1 - exp(fogdensity/DotProduct(diff, diff)));
- VectorScale(outc, f, outc);
- }
- else
- VectorScale(outc, cl, outc);
- }
- R_Mesh_Render();
- }
- }
- }
-}
-
-static void RSurfShader_Water_Pass_Fog(msurface_t *surf)
-{
- int i;
- surfvertex_t *v;
- float *outv, *outc, *outst, diff[3];
- float base[3], f;
- surfmesh_t *mesh;
- rmeshbufferinfo_t m;
- float alpha = currentrenderentity->alpha * (surf->flags & SURF_DRAWNOALPHA ? 1 : r_wateralpha.value);
- memset(&m, 0, sizeof(m));
- m.transparent = currentrenderentity->effects & EF_ADDITIVE || surf->currenttexture->fogtexture != NULL || alpha < 1;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- m.depthwrite = false;
- m.depthdisable = false;
- m.tex[0] = R_GetTexture(surf->currenttexture->fogtexture);
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)