X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=r_shadow.c;h=50de89788c7513570ea2222a6efcc91cd5fd72e0;hp=72307efb4c0d5761c813a1b3681480fdb24bd736;hb=70ce88b345e2575cae2b5580a4dcfaf7315938ba;hpb=8975282c766a46aa0da84f14a0ba278f62c9c8df diff --git a/r_shadow.c b/r_shadow.c index 72307efb..50de8978 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -22,6 +22,10 @@ int maxshadowelements; int *shadowelements; int maxtrianglefacinglight; qbyte *trianglefacinglight; +int *trianglefacinglightlist; + +int maxshadowvertices; +float *shadowvertices; rtexturepool_t *r_shadow_texturepool; rtexture_t *r_shadow_normalscubetexture; @@ -61,8 +65,11 @@ void r_shadow_start(void) r_shadow_mempool = Mem_AllocPool("R_Shadow"); maxshadowelements = 0; shadowelements = NULL; + maxshadowvertices = 0; + shadowvertices = NULL; maxtrianglefacinglight = 0; trianglefacinglight = NULL; + trianglefacinglightlist = NULL; r_shadow_normalscubetexture = NULL; r_shadow_attenuation2dtexture = NULL; r_shadow_attenuation3dtexture = NULL; @@ -87,8 +94,11 @@ void r_shadow_shutdown(void) R_FreeTexturePool(&r_shadow_texturepool); maxshadowelements = 0; shadowelements = NULL; + maxshadowvertices = 0; + shadowvertices = NULL; maxtrianglefacinglight = 0; trianglefacinglight = NULL; + trianglefacinglightlist = NULL; Mem_FreePool(&r_shadow_mempool); } @@ -132,9 +142,9 @@ void R_Shadow_ProjectVertices(float *verts, int numverts, const float *relativel } } -void R_Shadow_MakeTriangleShadowFlags(const int *elements, const float *vertex, int numtris, qbyte *trianglefacinglight, const float *relativelightorigin, float lightradius) +int R_Shadow_MakeTriangleShadowFlags(const int *elements, const float *vertex, int numtris, qbyte *facing, int *list, const float *relativelightorigin) { - int i; + int i, tris = 0; const float *v0, *v1, *v2; for (i = 0;i < numtris;i++, elements += 3) { @@ -150,13 +160,18 @@ void R_Shadow_MakeTriangleShadowFlags(const int *elements, const float *vertex, // fast version // subtracts v1 from v0 and v2, combined into a crossproduct, // combined with a dotproduct of the light location relative to the - // first point of the triangle (any point works, since the triangle + // first point of the triangle (any point works, since any triangle // is obviously flat), and finally a comparison to determine if the // light is infront of the triangle (the goal of this statement) - trianglefacinglight[i] = - (relativelightorigin[0] - v0[0]) * ((v0[1] - v1[1]) * (v2[2] - v1[2]) - (v0[2] - v1[2]) * (v2[1] - v1[1])) + if((relativelightorigin[0] - v0[0]) * ((v0[1] - v1[1]) * (v2[2] - v1[2]) - (v0[2] - v1[2]) * (v2[1] - v1[1])) + (relativelightorigin[1] - v0[1]) * ((v0[2] - v1[2]) * (v2[0] - v1[0]) - (v0[0] - v1[0]) * (v2[2] - v1[2])) - + (relativelightorigin[2] - v0[2]) * ((v0[0] - v1[0]) * (v2[1] - v1[1]) - (v0[1] - v1[1]) * (v2[0] - v1[0])) > 0; + + (relativelightorigin[2] - v0[2]) * ((v0[0] - v1[0]) * (v2[1] - v1[1]) - (v0[1] - v1[1]) * (v2[0] - v1[0])) > 0) + { + facing[i] = true; + list[tris++] = i; + } + else + facing[i] = false; #else // readable version { @@ -179,69 +194,85 @@ void R_Shadow_MakeTriangleShadowFlags(const int *elements, const float *vertex, // I.E. flat, so all points give the same answer) // the normal is not normalized because it is used on both sides of // the comparison, so it's magnitude does not matter - trianglefacinglight[i] = DotProduct(relativelightorigin, temp) >= DotProduct(v0, temp); + if (DotProduct(relativelightorigin, temp) >= DotProduct(v0, temp)) + { + facing[i] = true; + list[tris++] = i; + } + else + facing[i] = false; } #endif } + return tris; } -int R_Shadow_BuildShadowVolumeTriangles(const int *elements, const int *neighbors, int numtris, int numverts, const qbyte *trianglefacinglight, int *out) +int R_Shadow_BuildShadowVolumeTriangles(const int *elements, const int *neighbors, int numverts, const qbyte *facing, const int *facinglist, int numfacing, int *out) { int i, tris; + const int *e, *n; // check each frontface for bordering backfaces, // and cast shadow polygons from those edges, // also create front and back caps for shadow volume - tris = 0; - for (i = 0;i < numtris;i++, elements += 3, neighbors += 3) - { - if (trianglefacinglight[i]) + tris = numfacing * 2; + // output front caps + for (i = 0;i < numfacing;i++) + { + e = elements + facinglist[i] * 3; + out[0] = e[0]; + out[1] = e[1]; + out[2] = e[2]; + out += 3; + } + // output back caps + for (i = 0;i < numfacing;i++) + { + e = elements + facinglist[i] * 3; + out[0] = e[2] + numverts; + out[1] = e[1] + numverts; + out[2] = e[0] + numverts; + out += 3; + } + // output sides around frontfaces + for (i = 0;i < numfacing;i++) + { + n = neighbors + facinglist[i] * 3; + // check the edges + if (n[0] < 0 || !facing[n[0]]) { - // triangle is frontface and therefore casts shadow, - // output front and back caps for shadow volume - // front cap - out[0] = elements[0]; - out[1] = elements[1]; - out[2] = elements[2]; - // rear cap (with flipped winding order) - out[3] = elements[0] + numverts; - out[4] = elements[2] + numverts; - out[5] = elements[1] + numverts; + e = elements + facinglist[i] * 3; + out[0] = e[1]; + out[1] = e[0]; + out[2] = e[0] + numverts; + out[3] = e[1]; + out[4] = e[0] + numverts; + out[5] = e[1] + numverts; + out += 6; + tris += 2; + } + if (n[1] < 0 || !facing[n[1]]) + { + e = elements + facinglist[i] * 3; + out[0] = e[2]; + out[1] = e[1]; + out[2] = e[1] + numverts; + out[3] = e[2]; + out[4] = e[1] + numverts; + out[5] = e[2] + numverts; + out += 6; + tris += 2; + } + if (n[2] < 0 || !facing[n[2]]) + { + e = elements + facinglist[i] * 3; + out[0] = e[0]; + out[1] = e[2]; + out[2] = e[2] + numverts; + out[3] = e[0]; + out[4] = e[2] + numverts; + out[5] = e[0] + numverts; out += 6; tris += 2; - // check the edges - if (neighbors[0] < 0 || !trianglefacinglight[neighbors[0]]) - { - out[0] = elements[1]; - out[1] = elements[0]; - out[2] = elements[0] + numverts; - out[3] = elements[1]; - out[4] = elements[0] + numverts; - out[5] = elements[1] + numverts; - out += 6; - tris += 2; - } - if (neighbors[1] < 0 || !trianglefacinglight[neighbors[1]]) - { - out[0] = elements[2]; - out[1] = elements[1]; - out[2] = elements[1] + numverts; - out[3] = elements[2]; - out[4] = elements[1] + numverts; - out[5] = elements[2] + numverts; - out += 6; - tris += 2; - } - if (neighbors[2] < 0 || !trianglefacinglight[neighbors[2]]) - { - out[0] = elements[0]; - out[1] = elements[2]; - out[2] = elements[2] + numverts; - out[3] = elements[0]; - out[4] = elements[2] + numverts; - out[5] = elements[0] + numverts; - out += 6; - tris += 2; - } } } return tris; @@ -250,16 +281,21 @@ int R_Shadow_BuildShadowVolumeTriangles(const int *elements, const int *neighbor void R_Shadow_ResizeTriangleFacingLight(int numtris) { // make sure trianglefacinglight is big enough for this volume + // ameks ru ertaignelaficgnilhg tsib gie ongu hof rhtsiv lomu e + // m4k3 5ur3 7r14ng13f4c1n5115h7 15 b15 3n0u5h f0r 7h15 v01um3 if (maxtrianglefacinglight < numtris) { maxtrianglefacinglight = numtris; if (trianglefacinglight) Mem_Free(trianglefacinglight); + if (trianglefacinglightlist) + Mem_Free(trianglefacinglightlist); trianglefacinglight = Mem_Alloc(r_shadow_mempool, maxtrianglefacinglight); + trianglefacinglightlist = Mem_Alloc(r_shadow_mempool, sizeof(int) * maxtrianglefacinglight); } } -void R_Shadow_ResizeShadowElements(int numtris) +int *R_Shadow_ResizeShadowElements(int numtris) { // make sure shadowelements is big enough for this volume if (maxshadowelements < numtris * 24) @@ -269,6 +305,19 @@ void R_Shadow_ResizeShadowElements(int numtris) Mem_Free(shadowelements); shadowelements = Mem_Alloc(r_shadow_mempool, maxshadowelements * sizeof(int)); } + return shadowelements; +} + +float *R_Shadow_VertexBuffer(int numvertices) +{ + if (maxshadowvertices < numvertices) + { + maxshadowvertices = numvertices; + if (shadowvertices) + Mem_Free(shadowvertices); + shadowvertices = Mem_Alloc(r_shadow_mempool, maxshadowvertices * sizeof(float[4])); + } + return shadowvertices; } void R_Shadow_Volume(int numverts, int numtris, int *elements, int *neighbors, vec3_t relativelightorigin, float lightradius, float projectdistance) @@ -279,6 +328,8 @@ void R_Shadow_Volume(int numverts, int numtris, int *elements, int *neighbors, v Con_Printf("R_Shadow_Volume: projectdistance %f\n"); return; } + if (!numverts) + return; // terminology: // // frontface: @@ -296,8 +347,8 @@ void R_Shadow_Volume(int numverts, int numtris, int *elements, int *neighbors, v // description: // draws the shadow volumes of the model. // requirements: -// vertex locations must already be in varray_vertex before use. -// varray_vertex must have capacity for numverts * 2. +// vertex locations must already be in vertices before use. +// vertices must have capacity for numverts * 2. // make sure trianglefacinglight is big enough for this volume if (maxtrianglefacinglight < numtris) @@ -308,35 +359,32 @@ void R_Shadow_Volume(int numverts, int numtris, int *elements, int *neighbors, v R_Shadow_ResizeShadowElements(numtris); // check which triangles are facing the light - R_Shadow_MakeTriangleShadowFlags(elements, varray_vertex, numtris, trianglefacinglight, relativelightorigin, lightradius); - - // generate projected vertices - // by clever use of elements we'll construct the whole shadow from - // the unprojected vertices and these projected vertices - R_Shadow_ProjectVertices(varray_vertex, numverts, relativelightorigin, projectdistance); + tris = R_Shadow_MakeTriangleShadowFlags(elements, varray_vertex, numtris, trianglefacinglight, trianglefacinglightlist, relativelightorigin); + if (!tris) + return; // output triangle elements - tris = R_Shadow_BuildShadowVolumeTriangles(elements, neighbors, numtris, numverts, trianglefacinglight, shadowelements); - R_Shadow_RenderVolume(numverts * 2, tris, shadowelements); -} - -void R_Shadow_RenderVolume(int numverts, int numtris, int *elements) -{ - if (!numverts || !numtris) + tris = R_Shadow_BuildShadowVolumeTriangles(elements, neighbors, numverts, trianglefacinglight, trianglefacinglightlist, tris, shadowelements); + if (!tris) return; + + // by clever use of elements we can construct the whole shadow from + // the unprojected vertices and the projected vertices + R_Shadow_ProjectVertices(varray_vertex, numverts, relativelightorigin, projectdistance); + if (r_shadowstage == SHADOWSTAGE_STENCIL) { // increment stencil if backface is behind depthbuffer qglCullFace(GL_BACK); // quake is backwards, this culls front faces qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP); - R_Mesh_Draw(numverts, numtris, elements); + R_Mesh_Draw(numverts * 2, tris, shadowelements); c_rt_shadowmeshes++; c_rt_shadowtris += numtris; // decrement stencil if frontface is behind depthbuffer qglCullFace(GL_FRONT); // quake is backwards, this culls back faces qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP); } - R_Mesh_Draw(numverts, numtris, elements); + R_Mesh_Draw(numverts * 2, tris, shadowelements); c_rt_shadowmeshes++; c_rt_shadowtris += numtris; } @@ -351,7 +399,7 @@ void R_Shadow_RenderShadowMeshVolume(shadowmesh_t *firstmesh) qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP); for (mesh = firstmesh;mesh;mesh = mesh->next) { - R_Mesh_ResizeCheck(mesh->numverts); + R_Mesh_GetSpace(mesh->numverts); memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->elements); c_rtcached_shadowmeshes++; @@ -363,7 +411,7 @@ void R_Shadow_RenderShadowMeshVolume(shadowmesh_t *firstmesh) } for (mesh = firstmesh;mesh;mesh = mesh->next) { - R_Mesh_ResizeCheck(mesh->numverts); + R_Mesh_GetSpace(mesh->numverts); memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4])); R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->elements); c_rtcached_shadowmeshes++; @@ -390,9 +438,9 @@ static void R_Shadow_MakeTextures(void) data[2] = 255; data[3] = 255; r_shadow_blankbumptexture = R_LoadTexture2D(r_shadow_texturepool, "blankbump", 1, 1, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL); - data[0] = 64; - data[1] = 64; - data[2] = 64; + data[0] = 255; + data[1] = 255; + data[2] = 255; data[3] = 255; r_shadow_blankglosstexture = R_LoadTexture2D(r_shadow_texturepool, "blankgloss", 1, 1, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL); data[0] = 255; @@ -946,6 +994,39 @@ int R_Shadow_ScissorForBBox(const float *mins, const float *maxs) return false; } +void R_Shadow_VertexLighting(float *color, int numverts, const float *vertex, const float *normal, const float *lightcolor, const float *relativelightorigin, float lightradius) +{ + float dist, dot, intensity, iradius = 1.0f / lightradius, radius2 = lightradius * lightradius, v[3]; + for (;numverts > 0;numverts--, vertex += 4, color += 4, normal += 4) + { + VectorSubtract(vertex, relativelightorigin, v); + if ((dot = DotProduct(normal, v)) > 0 && (dist = DotProduct(v, v)) < radius2) + { + dist = sqrt(dist); + intensity = pow(1 - (dist * iradius), r_shadow_attenpower) * r_shadow_attenscale * dot / dist; + VectorScale(lightcolor, intensity, color); + } + else + VectorClear(color); + } +} + +void R_Shadow_VertexLightingWithXYAttenuationTexture(float *color, int numverts, const float *vertex, const float *normal, const float *lightcolor, const float *relativelightorigin, float lightradius, const float *zdir) +{ + float dist, dot, intensity, iradius = 1.0f / lightradius, v[3]; + for (;numverts > 0;numverts--, vertex += 4, color += 4, normal += 4) + { + VectorSubtract(vertex, relativelightorigin, v); + if ((dot = DotProduct(normal, v)) > 0 && (dist = fabs(DotProduct(zdir, v))) < lightradius) + { + intensity = pow(1 - (dist * iradius), r_shadow_attenpower) * r_shadow_attenscale * dot / sqrt(DotProduct(v,v)); + VectorScale(lightcolor, intensity, color); + } + else + VectorClear(color); + } +} + // FIXME: this should be done in a vertex program when possible // FIXME: if vertex program not available, this would really benefit from 3DNow! or SSE void R_Shadow_TransformVertices(float *out, int numverts, const float *vertex, const matrix4x4_t *matrix) @@ -991,240 +1072,324 @@ void R_Shadow_GenTexCoords_Specular_NormalCubeMap(float *out, int numverts, cons } } -void R_Shadow_DiffuseLighting(int numverts, int numtriangles, const int *elements, const float *svectors, const float *tvectors, const float *normals, const float *texcoords, const float *relativelightorigin, float lightradius, const float *lightcolor, const matrix4x4_t *matrix_worldtofilter, const matrix4x4_t *matrix_worldtoattenuationxyz, const matrix4x4_t *matrix_worldtoattenuationz, rtexture_t *basetexture, rtexture_t *bumptexture, rtexture_t *lightcubemap) +void R_Shadow_DiffuseLighting(int numverts, int numtriangles, const int *elements, const float *vertices, const float *svectors, const float *tvectors, const float *normals, const float *texcoords, const float *relativelightorigin, float lightradius, const float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *basetexture, rtexture_t *bumptexture, rtexture_t *lightcubemap) { int renders; float color[3]; rmeshstate_t m; memset(&m, 0, sizeof(m)); - if (!bumptexture) - bumptexture = r_shadow_blankbumptexture; - // colorscale accounts for how much we multiply the brightness during combine - // mult is how many times the final pass of the lighting will be - // performed to get more brightness than otherwise possible - // limit mult to 64 for sanity sake - if (r_shadow_texture3d.integer && r_textureunits.integer >= 4) - { - // 3/2 3D combine path - m.tex[0] = R_GetTexture(bumptexture); - m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); - m.tex3d[2] = R_GetTexture(r_shadow_attenuation3dtexture); - m.texcombinergb[0] = GL_REPLACE; - m.texcombinergb[1] = GL_DOT3_RGBA_ARB; - R_Mesh_TextureState(&m); - qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); - GL_Color(1,1,1,1); - memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin); - R_Shadow_TransformVertices(varray_texcoord[2], numverts, varray_vertex, matrix_worldtoattenuationxyz); - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; - - m.tex[0] = R_GetTexture(basetexture); - m.tex[1] = 0; - m.texcubemap[1] = R_GetTexture(lightcubemap); - m.tex3d[2] = 0; - m.texcombinergb[0] = GL_MODULATE; - m.texcombinergb[1] = GL_MODULATE; - R_Mesh_TextureState(&m); - qglColorMask(1,1,1,0); - qglBlendFunc(GL_DST_ALPHA, GL_ONE); - qglEnable(GL_BLEND); - if (lightcubemap) - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtofilter); - - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); - for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + if (gl_dot3arb) + { + if (!bumptexture) + bumptexture = r_shadow_blankbumptexture; + // colorscale accounts for how much we multiply the brightness during combine + // mult is how many times the final pass of the lighting will be + // performed to get more brightness than otherwise possible + // limit mult to 64 for sanity sake + if (r_shadow_texture3d.integer && r_textureunits.integer >= 4) { - GL_Color(color[0], color[1], color[2], 1); + // 3/2 3D combine path + m.tex[0] = R_GetTexture(bumptexture); + m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); + m.tex3d[2] = R_GetTexture(r_shadow_attenuation3dtexture); + m.texcombinergb[0] = GL_REPLACE; + m.texcombinergb[1] = GL_DOT3_RGBA_ARB; + R_Mesh_TextureState(&m); + qglColorMask(0,0,0,1); + qglDisable(GL_BLEND); + GL_Color(1,1,1,1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin); + R_Shadow_TransformVertices(varray_texcoord[2], numverts, vertices, matrix_modeltoattenuationxyz); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; + + m.tex[0] = R_GetTexture(basetexture); + m.tex[1] = 0; + m.texcubemap[1] = R_GetTexture(lightcubemap); + m.tex3d[2] = 0; + m.texcombinergb[0] = GL_MODULATE; + m.texcombinergb[1] = GL_MODULATE; + R_Mesh_TextureState(&m); + qglColorMask(1,1,1,0); + qglBlendFunc(GL_DST_ALPHA, GL_ONE); + qglEnable(GL_BLEND); + + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + { + GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + if (lightcubemap) + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltofilter); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + } } - } - else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && lightcubemap) - { - // 1/2/2 3D combine path - m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture); - R_Mesh_TextureState(&m); - qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); - GL_Color(1,1,1,1); - R_Shadow_TransformVertices(varray_texcoord[0], numverts, varray_vertex, matrix_worldtoattenuationxyz); - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; - - m.tex[0] = R_GetTexture(bumptexture); - m.tex3d[0] = 0; - m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); - m.texcombinergb[0] = GL_REPLACE; - m.texcombinergb[1] = GL_DOT3_RGBA_ARB; - R_Mesh_TextureState(&m); - qglBlendFunc(GL_DST_ALPHA, GL_ZERO); - qglEnable(GL_BLEND); - memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin); - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; - - m.tex[0] = R_GetTexture(basetexture); - m.texcubemap[1] = R_GetTexture(lightcubemap); - m.texcombinergb[0] = GL_MODULATE; - m.texcombinergb[1] = GL_MODULATE; - R_Mesh_TextureState(&m); - qglColorMask(1,1,1,0); - qglBlendFunc(GL_DST_ALPHA, GL_ONE); - if (lightcubemap) - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtofilter); - - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); - for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && lightcubemap) { - GL_Color(color[0], color[1], color[2], 1); + // 1/2/2 3D combine path + m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture); + R_Mesh_TextureState(&m); + qglColorMask(0,0,0,1); + qglDisable(GL_BLEND); + GL_Color(1,1,1,1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Shadow_TransformVertices(varray_texcoord[0], numverts, vertices, matrix_modeltoattenuationxyz); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; + + m.tex[0] = R_GetTexture(bumptexture); + m.tex3d[0] = 0; + m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); + m.texcombinergb[0] = GL_REPLACE; + m.texcombinergb[1] = GL_DOT3_RGBA_ARB; + R_Mesh_TextureState(&m); + qglBlendFunc(GL_DST_ALPHA, GL_ZERO); + qglEnable(GL_BLEND); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + + m.tex[0] = R_GetTexture(basetexture); + m.texcubemap[1] = R_GetTexture(lightcubemap); + m.texcombinergb[0] = GL_MODULATE; + m.texcombinergb[1] = GL_MODULATE; + R_Mesh_TextureState(&m); + qglColorMask(1,1,1,0); + qglBlendFunc(GL_DST_ALPHA, GL_ONE); + + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + { + GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + if (lightcubemap) + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltofilter); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + } } - } - else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && !lightcubemap) - { - // 2/2 3D combine path - m.tex[0] = R_GetTexture(bumptexture); - m.tex3d[0] = 0; - m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); - m.texcombinergb[0] = GL_REPLACE; - m.texcombinergb[1] = GL_DOT3_RGBA_ARB; - R_Mesh_TextureState(&m); - GL_Color(1,1,1,1); - qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); - memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin); - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; - - m.tex[0] = R_GetTexture(basetexture); - m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture); - m.texcombinergb[0] = GL_MODULATE; - m.texcombinergb[1] = GL_MODULATE; - R_Mesh_TextureState(&m); - qglColorMask(1,1,1,0); - qglBlendFunc(GL_DST_ALPHA, GL_ONE); - qglEnable(GL_BLEND); - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtoattenuationxyz); - - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); - for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && !lightcubemap) { - GL_Color(color[0], color[1], color[2], 1); + // 2/2 3D combine path + m.tex[0] = R_GetTexture(bumptexture); + m.tex3d[0] = 0; + m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); + m.texcombinergb[0] = GL_REPLACE; + m.texcombinergb[1] = GL_DOT3_RGBA_ARB; + R_Mesh_TextureState(&m); + GL_Color(1,1,1,1); + qglColorMask(0,0,0,1); + qglDisable(GL_BLEND); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; + + m.tex[0] = R_GetTexture(basetexture); + m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture); + m.texcombinergb[0] = GL_MODULATE; + m.texcombinergb[1] = GL_MODULATE; + R_Mesh_TextureState(&m); + qglColorMask(1,1,1,0); + qglBlendFunc(GL_DST_ALPHA, GL_ONE); + qglEnable(GL_BLEND); + + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + { + GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltoattenuationxyz); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + } } - } - else if (r_textureunits.integer >= 4) - { - // 4/2 2D combine path - m.tex[0] = R_GetTexture(bumptexture); - m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); - m.texcombinergb[0] = GL_REPLACE; - m.texcombinergb[1] = GL_DOT3_RGBA_ARB; - m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture); - m.tex[3] = R_GetTexture(r_shadow_attenuation2dtexture); - R_Mesh_TextureState(&m); - qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); - GL_Color(1,1,1,1); - memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin); - R_Shadow_TransformVertices(varray_texcoord[2], numverts, varray_vertex, matrix_worldtoattenuationxyz); - R_Shadow_TransformVertices(varray_texcoord[3], numverts, varray_vertex, matrix_worldtoattenuationz); - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; - - m.tex[0] = R_GetTexture(basetexture); - m.texcubemap[1] = R_GetTexture(lightcubemap); - m.texcombinergb[0] = GL_MODULATE; - m.texcombinergb[1] = GL_MODULATE; - m.tex[2] = 0; - m.tex[3] = 0; - R_Mesh_TextureState(&m); - qglColorMask(1,1,1,0); - qglBlendFunc(GL_DST_ALPHA, GL_ONE); - qglEnable(GL_BLEND); - if (lightcubemap) - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtofilter); - - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); - for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + else if (r_textureunits.integer >= 4) + { + // 4/2 2D combine path + m.tex[0] = R_GetTexture(bumptexture); + m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); + m.texcombinergb[0] = GL_REPLACE; + m.texcombinergb[1] = GL_DOT3_RGBA_ARB; + m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture); + m.tex[3] = R_GetTexture(r_shadow_attenuation2dtexture); + R_Mesh_TextureState(&m); + qglColorMask(0,0,0,1); + qglDisable(GL_BLEND); + GL_Color(1,1,1,1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin); + R_Shadow_TransformVertices(varray_texcoord[2], numverts, vertices, matrix_modeltoattenuationxyz); + R_Shadow_TransformVertices(varray_texcoord[3], numverts, vertices, matrix_modeltoattenuationz); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + + m.tex[0] = R_GetTexture(basetexture); + m.texcubemap[1] = R_GetTexture(lightcubemap); + m.texcombinergb[0] = GL_MODULATE; + m.texcombinergb[1] = GL_MODULATE; + m.tex[2] = 0; + m.tex[3] = 0; + R_Mesh_TextureState(&m); + qglColorMask(1,1,1,0); + qglBlendFunc(GL_DST_ALPHA, GL_ONE); + qglEnable(GL_BLEND); + + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + { + GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + if (lightcubemap) + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltofilter); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + } + } + else { - GL_Color(color[0], color[1], color[2], 1); + // 2/2/2 2D combine path + m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture); + m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture); + R_Mesh_TextureState(&m); + qglColorMask(0,0,0,1); + qglDisable(GL_BLEND); + GL_Color(1,1,1,1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Shadow_TransformVertices(varray_texcoord[0], numverts, vertices, matrix_modeltoattenuationxyz); + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltoattenuationz); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + + m.tex[0] = R_GetTexture(bumptexture); + m.tex[1] = 0; + m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); + m.texcombinergb[0] = GL_REPLACE; + m.texcombinergb[1] = GL_DOT3_RGBA_ARB; + R_Mesh_TextureState(&m); + qglBlendFunc(GL_DST_ALPHA, GL_ZERO); + qglEnable(GL_BLEND); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; + + m.tex[0] = R_GetTexture(basetexture); + m.texcubemap[1] = R_GetTexture(lightcubemap); + m.texcombinergb[0] = GL_MODULATE; + m.texcombinergb[1] = GL_MODULATE; + R_Mesh_TextureState(&m); + qglColorMask(1,1,1,0); + qglBlendFunc(GL_DST_ALPHA, GL_ONE); + + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + { + GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + if (lightcubemap) + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltofilter); + R_Mesh_Draw(numverts, numtriangles, elements); + c_rt_lightmeshes++; + c_rt_lighttris += numtriangles; + } } } else { - // 2/2/2 2D combine path - m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture); - m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture); - R_Mesh_TextureState(&m); - qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); - GL_Color(1,1,1,1); - R_Shadow_TransformVertices(varray_texcoord[0], numverts, varray_vertex, matrix_worldtoattenuationxyz); - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtoattenuationz); - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; - - m.tex[0] = R_GetTexture(bumptexture); - m.tex[1] = 0; - m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); - m.texcombinergb[0] = GL_REPLACE; - m.texcombinergb[1] = GL_DOT3_RGBA_ARB; - R_Mesh_TextureState(&m); - qglBlendFunc(GL_DST_ALPHA, GL_ZERO); - qglEnable(GL_BLEND); - memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin); - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; - - m.tex[0] = R_GetTexture(basetexture); - m.texcubemap[1] = R_GetTexture(lightcubemap); - m.texcombinergb[0] = GL_MODULATE; - m.texcombinergb[1] = GL_MODULATE; - R_Mesh_TextureState(&m); - qglColorMask(1,1,1,0); - qglBlendFunc(GL_DST_ALPHA, GL_ONE); - if (lightcubemap) - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtofilter); - - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); - for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) + if (r_textureunits.integer >= 2) { - GL_Color(color[0], color[1], color[2], 1); + // voodoo2 +#if 1 + m.tex[0] = R_GetTexture(basetexture); + m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture); + R_Mesh_TextureState(&m); + qglBlendFunc(GL_SRC_ALPHA, GL_ONE); + qglEnable(GL_BLEND); +#else + m.tex[0] = R_GetTexture(basetexture); + m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture); + m.blendfunc1 = GL_SRC_ALPHA; + m.blendfunc2 = GL_ONE; + R_Mesh_State(&m); +#endif + GL_UseColorArray(); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltoattenuationxyz); + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + R_Shadow_VertexLightingWithXYAttenuationTexture(varray_color, numverts, vertices, normals, color, relativelightorigin, lightradius, matrix_modeltofilter->m[2]); + R_Mesh_Draw(numverts, numtriangles, elements); + } + else + { + // voodoo1 +#if 1 + m.tex[0] = R_GetTexture(basetexture); + R_Mesh_TextureState(&m); + qglBlendFunc(GL_SRC_ALPHA, GL_ONE); + qglEnable(GL_BLEND); +#else + m.tex[0] = R_GetTexture(basetexture); + m.blendfunc1 = GL_SRC_ALPHA; + m.blendfunc2 = GL_ONE; + R_Mesh_State(&m); +#endif + GL_UseColorArray(); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + R_Shadow_VertexLighting(varray_color, numverts, vertices, normals, color, relativelightorigin, lightradius); R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; } } } -void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elements, const float *svectors, const float *tvectors, const float *normals, const float *texcoords, const float *relativelightorigin, const float *relativeeyeorigin, float lightradius, const float *lightcolor, const matrix4x4_t *matrix_worldtofilter, const matrix4x4_t *matrix_worldtoattenuationxyz, const matrix4x4_t *matrix_worldtoattenuationz, rtexture_t *glosstexture, rtexture_t *bumptexture, rtexture_t *lightcubemap) +void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elements, const float *vertices, const float *svectors, const float *tvectors, const float *normals, const float *texcoords, const float *relativelightorigin, const float *relativeeyeorigin, float lightradius, const float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *glosstexture, rtexture_t *bumptexture, rtexture_t *lightcubemap) { int renders; float color[3]; rmeshstate_t m; + if (!gl_dot3arb) + return; memset(&m, 0, sizeof(m)); if (!bumptexture) bumptexture = r_shadow_blankbumptexture; @@ -1232,9 +1397,9 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen glosstexture = r_shadow_blankglosstexture; if (r_shadow_gloss.integer >= 2 || (r_shadow_gloss.integer >= 1 && glosstexture != r_shadow_blankglosstexture)) { - if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && lightcubemap) + if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && lightcubemap /*&& gl_support_blendsquare*/) // FIXME: detect blendsquare! { - // 2/0/0/0/1/2 3D combine path + // 2/0/0/0/1/2 3D combine blendsquare path m.tex[0] = R_GetTexture(bumptexture); m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; @@ -1242,8 +1407,10 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen qglColorMask(0,0,0,1); qglDisable(GL_BLEND); GL_Color(1,1,1,1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin, relativeeyeorigin); + R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin, relativeeyeorigin); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; @@ -1257,22 +1424,23 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen qglEnable(GL_BLEND); // these comments are a test run through this math for intensity 0.5 // 0.5 * 0.5 = 0.25 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; // 0.25 * 0.25 = 0.0625 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; // 0.0625 * 0.0625 = 0.00390625 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; + for (renders = 0;renders < 3;renders++) + { + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Mesh_Draw(numverts, numtriangles, elements); + } + c_rt_lightmeshes += 3; + c_rt_lighttris += numtriangles * 3; m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture); R_Mesh_TextureState(&m); qglBlendFunc(GL_DST_ALPHA, GL_ZERO); - R_Shadow_TransformVertices(varray_texcoord[0], numverts, varray_vertex, matrix_worldtoattenuationxyz); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Shadow_TransformVertices(varray_texcoord[0], numverts, vertices, matrix_modeltoattenuationxyz); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; @@ -1283,22 +1451,24 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen R_Mesh_TextureState(&m); qglColorMask(1,1,1,0); qglBlendFunc(GL_DST_ALPHA, GL_ONE); - memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - if (lightcubemap) - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtofilter); - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value * 0.25f, color); for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) { GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + if (lightcubemap) + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltofilter); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; } } - else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && !lightcubemap) + else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && !lightcubemap /*&& gl_support_blendsquare*/) // FIXME: detect blendsquare! { - // 2/0/0/0/2 3D combine path + // 2/0/0/0/2 3D combine blendsquare path m.tex[0] = R_GetTexture(bumptexture); m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; @@ -1306,8 +1476,10 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen qglColorMask(0,0,0,1); qglDisable(GL_BLEND); GL_Color(1,1,1,1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin, relativeeyeorigin); + R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin, relativeeyeorigin); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; @@ -1321,33 +1493,33 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen qglEnable(GL_BLEND); // these comments are a test run through this math for intensity 0.5 // 0.5 * 0.5 = 0.25 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; // 0.25 * 0.25 = 0.0625 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; // 0.0625 * 0.0625 = 0.00390625 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; + for (renders = 0;renders < 3;renders++) + { + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Mesh_Draw(numverts, numtriangles, elements); + } + c_rt_lightmeshes += 3; + c_rt_lighttris += numtriangles * 3; m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture); m.tex[1] = R_GetTexture(glosstexture); R_Mesh_TextureState(&m); - R_Shadow_TransformVertices(varray_texcoord[0], numverts, varray_vertex, matrix_worldtoattenuationxyz); - memcpy(varray_texcoord[1], texcoords, numverts * sizeof(float[4])); qglColorMask(1,1,1,0); qglBlendFunc(GL_DST_ALPHA, GL_ONE); - R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value * 0.25f, color); for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) { GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Shadow_TransformVertices(varray_texcoord[0], numverts, vertices, matrix_modeltoattenuationxyz); + memcpy(varray_texcoord[1], texcoords, numverts * sizeof(float[4])); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; @@ -1355,7 +1527,7 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen } else if (r_textureunits.integer >= 2 /*&& gl_support_blendsquare*/) // FIXME: detect blendsquare! { - // 2/0/0/0/2/2 2D combine path + // 2/0/0/0/2/2 2D combine blendsquare path m.tex[0] = R_GetTexture(bumptexture); m.texcubemap[1] = R_GetTexture(r_shadow_normalscubetexture); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; @@ -1363,8 +1535,10 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen qglColorMask(0,0,0,1); qglDisable(GL_BLEND); GL_Color(1,1,1,1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin, relativeeyeorigin); + R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord[1], numverts, vertices, svectors, tvectors, normals, relativelightorigin, relativeeyeorigin); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; @@ -1378,24 +1552,25 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen qglEnable(GL_BLEND); // these comments are a test run through this math for intensity 0.5 // 0.5 * 0.5 = 0.25 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; // 0.25 * 0.25 = 0.0625 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; // 0.0625 * 0.0625 = 0.00390625 - R_Mesh_Draw(numverts, numtriangles, elements); - c_rt_lightmeshes++; - c_rt_lighttris += numtriangles; + for (renders = 0;renders < 3;renders++) + { + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Mesh_Draw(numverts, numtriangles, elements); + } + c_rt_lightmeshes += 3; + c_rt_lighttris += numtriangles * 3; m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture); m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture); R_Mesh_TextureState(&m); qglBlendFunc(GL_DST_ALPHA, GL_ZERO); - R_Shadow_TransformVertices(varray_texcoord[0], numverts, varray_vertex, matrix_worldtoattenuationxyz); - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtoattenuationz); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + R_Shadow_TransformVertices(varray_texcoord[0], numverts, vertices, matrix_modeltoattenuationxyz); + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltoattenuationz); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; @@ -1405,14 +1580,16 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen R_Mesh_TextureState(&m); qglColorMask(1,1,1,0); qglBlendFunc(GL_DST_ALPHA, GL_ONE); - memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); - if (lightcubemap) - R_Shadow_TransformVertices(varray_texcoord[1], numverts, varray_vertex, matrix_worldtofilter); - VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value, color); + VectorScale(lightcolor, r_colorscale * r_shadow_lightintensityscale.value * 0.25f, color); for (renders = 0;renders < 64 && (color[0] > 0 || color[1] > 0 || color[2] > 0);renders++, color[0] = max(0, color[0] - 1.0f), color[1] = max(0, color[1] - 1.0f), color[2] = max(0, color[2] - 1.0f)) { GL_Color(color[0], color[1], color[2], 1); + R_Mesh_GetSpace(numverts); + memcpy(varray_vertex, vertices, numverts * sizeof(float[4])); + memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4])); + if (lightcubemap) + R_Shadow_TransformVertices(varray_texcoord[1], numverts, vertices, matrix_modeltofilter); R_Mesh_Draw(numverts, numtriangles, elements); c_rt_lightmeshes++; c_rt_lighttris += numtriangles; @@ -1613,11 +1790,14 @@ void R_Shadow_NewWorldLight(vec3_t origin, float radius, vec3_t color, int style // now that we have the buffers big enough, construct shadow volume mesh memcpy(verts, castmesh->verts, castmesh->numverts * sizeof(float[4])); R_Shadow_ProjectVertices(verts, castmesh->numverts, e->origin, r_shadow_projectdistance.value);//, e->lightradius); - R_Shadow_MakeTriangleShadowFlags(castmesh->elements, verts, castmesh->numtriangles, trianglefacinglight, e->origin, e->lightradius); - tris = R_Shadow_BuildShadowVolumeTriangles(castmesh->elements, castmesh->neighbors, castmesh->numtriangles, castmesh->numverts, trianglefacinglight, shadowelements); + tris = R_Shadow_MakeTriangleShadowFlags(castmesh->elements, verts, castmesh->numtriangles, trianglefacinglight, trianglefacinglightlist, e->origin); + tris = R_Shadow_BuildShadowVolumeTriangles(castmesh->elements, castmesh->neighbors, castmesh->numverts, trianglefacinglight, trianglefacinglightlist, tris, shadowelements); // add the constructed shadow volume mesh Mod_ShadowMesh_AddMesh(r_shadow_mempool, e->shadowvolume, castmesh->numverts, verts, tris, shadowelements); } + if (verts) + Mem_Free(verts); + verts = NULL; // we're done with castmesh now Mod_ShadowMesh_Free(castmesh); e->shadowvolume = Mod_ShadowMesh_Finish(r_shadow_mempool, e->shadowvolume); @@ -1683,6 +1863,7 @@ void R_DrawLightSprite(int texnum, const vec3_t origin, vec_t scale, float cr, f R_Mesh_State(&m); GL_Color(cr * r_colorscale, cg * r_colorscale, cb * r_colorscale, ca); + R_Mesh_GetSpace(4); varray_texcoord[0][ 0] = 0;varray_texcoord[0][ 1] = 0; varray_texcoord[0][ 4] = 0;varray_texcoord[0][ 5] = 1; varray_texcoord[0][ 8] = 1;varray_texcoord[0][ 9] = 1; @@ -2035,7 +2216,7 @@ void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void) } if (light <= 0 && islight) light = 300; - radius = bound(15, light * r_editlights_quakelightsizescale.value / scale, 1048576); + radius = min(light * r_editlights_quakelightsizescale.value / scale, 1048576); light = sqrt(bound(0, light, 1048576)) * (1.0f / 16.0f); if (color[0] == 1 && color[1] == 1 && color[2] == 1) VectorCopy(overridecolor, color);