X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=r_shadow.c;h=8c6972d1da1038dd6fdddae05004978d08e4fe5c;hp=b8127bd009970e640c256879a289e970d2e17ecc;hb=adb4f5d3e2fa8c1729454071171dac33c65845ff;hpb=d3cbe906d0eedcff735096a08340d8ca90457fa9 diff --git a/r_shadow.c b/r_shadow.c index b8127bd0..8c6972d1 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -151,10 +151,8 @@ qbyte *r_shadow_buffer_surfacepvs; int *r_shadow_buffer_surfacelist; rtexturepool_t *r_shadow_texturepool; -rtexture_t *r_shadow_normalcubetexture; rtexture_t *r_shadow_attenuation2dtexture; rtexture_t *r_shadow_attenuation3dtexture; -rtexture_t *r_shadow_blankwhitecubetexture; // lights are reloaded when this changes char r_shadow_mapname[MAX_QPATH]; @@ -391,10 +389,8 @@ void r_shadow_start(void) int i; // allocate vertex processing arrays numcubemaps = 0; - r_shadow_normalcubetexture = NULL; r_shadow_attenuation2dtexture = NULL; r_shadow_attenuation3dtexture = NULL; - r_shadow_blankwhitecubetexture = NULL; r_shadow_texturepool = NULL; r_shadow_filters_texturepool = NULL; R_Shadow_ValidateCvars(); @@ -496,10 +492,8 @@ void r_shadow_shutdown(void) } } numcubemaps = 0; - r_shadow_normalcubetexture = NULL; r_shadow_attenuation2dtexture = NULL; r_shadow_attenuation3dtexture = NULL; - r_shadow_blankwhitecubetexture = NULL; R_FreeTexturePool(&r_shadow_texturepool); R_FreeTexturePool(&r_shadow_filters_texturepool); maxshadowelements = 0; @@ -941,79 +935,16 @@ void R_Shadow_RenderVolume(int numvertices, int numtriangles, const float *verte static void R_Shadow_MakeTextures(void) { - int x, y, z, d, side; - float v[3], s, t, intensity; + int x, y, z, d; + float v[3], intensity; qbyte *data; R_FreeTexturePool(&r_shadow_texturepool); r_shadow_texturepool = R_AllocTexturePool(); r_shadow_attenpower = r_shadow_lightattenuationpower.value; r_shadow_attenscale = r_shadow_lightattenuationscale.value; -#define NORMSIZE 64 #define ATTEN2DSIZE 64 #define ATTEN3DSIZE 32 - data = Mem_Alloc(tempmempool, max(6*NORMSIZE*NORMSIZE*4, max(ATTEN3DSIZE*ATTEN3DSIZE*ATTEN3DSIZE*4, ATTEN2DSIZE*ATTEN2DSIZE*4))); - r_shadow_blankwhitecubetexture = NULL; - r_shadow_normalcubetexture = NULL; - if (gl_texturecubemap) - { - data[ 0] = 255;data[ 1] = 255;data[ 2] = 255;data[ 3] = 255; - data[ 4] = 255;data[ 5] = 255;data[ 6] = 255;data[ 7] = 255; - data[ 8] = 255;data[ 9] = 255;data[10] = 255;data[11] = 255; - data[12] = 255;data[13] = 255;data[14] = 255;data[15] = 255; - data[16] = 255;data[17] = 255;data[18] = 255;data[19] = 255; - data[20] = 255;data[21] = 255;data[22] = 255;data[23] = 255; - r_shadow_blankwhitecubetexture = R_LoadTextureCubeMap(r_shadow_texturepool, "blankwhitecube", 1, data, TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL); - for (side = 0;side < 6;side++) - { - for (y = 0;y < NORMSIZE;y++) - { - for (x = 0;x < NORMSIZE;x++) - { - s = (x + 0.5f) * (2.0f / NORMSIZE) - 1.0f; - t = (y + 0.5f) * (2.0f / NORMSIZE) - 1.0f; - switch(side) - { - case 0: - v[0] = 1; - v[1] = -t; - v[2] = -s; - break; - case 1: - v[0] = -1; - v[1] = -t; - v[2] = s; - break; - case 2: - v[0] = s; - v[1] = 1; - v[2] = t; - break; - case 3: - v[0] = s; - v[1] = -1; - v[2] = -t; - break; - case 4: - v[0] = s; - v[1] = -t; - v[2] = 1; - break; - case 5: - v[0] = -s; - v[1] = -t; - v[2] = -1; - break; - } - intensity = 127.0f / sqrt(DotProduct(v, v)); - data[((side*NORMSIZE+y)*NORMSIZE+x)*4+0] = 128.0f + intensity * v[0]; - data[((side*NORMSIZE+y)*NORMSIZE+x)*4+1] = 128.0f + intensity * v[1]; - data[((side*NORMSIZE+y)*NORMSIZE+x)*4+2] = 128.0f + intensity * v[2]; - data[((side*NORMSIZE+y)*NORMSIZE+x)*4+3] = 255; - } - } - } - r_shadow_normalcubetexture = R_LoadTextureCubeMap(r_shadow_texturepool, "normalcube", NORMSIZE, data, TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL); - } + data = Mem_Alloc(tempmempool, max(ATTEN3DSIZE*ATTEN3DSIZE*ATTEN3DSIZE*4, ATTEN2DSIZE*ATTEN2DSIZE*4)); for (y = 0;y < ATTEN2DSIZE;y++) { for (x = 0;x < ATTEN2DSIZE;x++) @@ -1133,15 +1064,6 @@ void R_Shadow_Stage_ShadowVolumes(void) // this is changed by every shadow render so its value here is unimportant qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } - GL_Clear(GL_STENCIL_BUFFER_BIT); - c_rt_clears++; - // LordHavoc note: many shadow volumes reside entirely inside the world - // (that is to say they are entirely bounded by their lit surfaces), - // which can be optimized by handling things as an inverted light volume, - // with the shadow boundaries of the world being simulated by an altered - // (129) bias to stencil clearing on such lights - // FIXME: generate inverted light volumes for use as shadow volumes and - // optimize for them as noted above } void R_Shadow_Stage_Light(int shadowtest) @@ -1171,7 +1093,6 @@ void R_Shadow_Stage_Light(int shadowtest) // stencil is 128 (values other than this mean shadow) qglStencilFunc(GL_EQUAL, 128, ~0); r_shadowstage = SHADOWSTAGE_LIGHT; - c_rt_lights++; } void R_Shadow_Stage_End(void) @@ -1566,6 +1487,18 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, int renders; float color[3], color2[3], colorscale; rmeshstate_t m; + if (glosstexture && r_shadow_gloss.integer >= 1 && r_shadow_glossintensity.value > 0 && specularscale > 0) + specularscale = specularscale * r_shadow_glossintensity.value; + else if (!glosstexture && r_shadow_gloss.integer >= 2 && r_shadow_gloss2intensity.value > 0 && r_shadow_glossintensity.value > 0 && specularscale > 0) + { + glosstexture = r_texture_white; + specularscale = specularscale * r_shadow_gloss2intensity.value; + } + else + { + glosstexture = r_texture_black; + specularscale = 0; + } if (!basetexture) basetexture = r_texture_white; if (!bumptexture) @@ -1576,24 +1509,6 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, lightcolorpants = vec3_origin; if (!lightcolorshirt) lightcolorshirt = vec3_origin; - specularscale *= r_shadow_glossintensity.value; - if (!glosstexture) - { - if (r_shadow_gloss.integer >= 2) - { - glosstexture = r_texture_white; - specularscale *= r_shadow_gloss2intensity.value; - } - else - { - glosstexture = r_texture_black; - specularscale = 0; - } - } - if (r_shadow_gloss.integer < 1) - specularscale = 0; - if (!lightcubemap) - lightcubemap = r_shadow_blankwhitecubetexture; if ((ambientscale + diffusescale) * (VectorLength2(lightcolorbase) + VectorLength2(lightcolorpants) + VectorLength2(lightcolorshirt)) + specularscale * VectorLength2(lightcolorbase) <= 0.001) return; if (visiblelighting) @@ -2009,7 +1924,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.tex[0] = R_GetTexture(bumptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin); @@ -2074,7 +1989,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.tex[0] = R_GetTexture(bumptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin); @@ -2111,7 +2026,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.tex[0] = R_GetTexture(bumptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin); @@ -2146,7 +2061,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.tex[0] = R_GetTexture(bumptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin); @@ -2227,7 +2142,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.tex[0] = R_GetTexture(bumptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin); @@ -2284,7 +2199,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.pointer_vertex = vertex3f; m.tex[0] = R_GetTexture(bumptexture); m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin, relativeeyeorigin); @@ -2358,7 +2273,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.pointer_vertex = vertex3f; m.tex[0] = R_GetTexture(bumptexture); m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin, relativeeyeorigin); @@ -2411,7 +2326,7 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, m.pointer_vertex = vertex3f; m.tex[0] = R_GetTexture(bumptexture); m.pointer_texcoord[0] = texcoord2f; - m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); + m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin, relativeeyeorigin); @@ -2883,6 +2798,8 @@ void R_DrawRTLight(rtlight_t *rtlight, int visiblelighting, int visiblevolumes) if (R_Shadow_ScissorForBBox(cullmins, cullmaxs)) return; + c_rt_lights++; + shadow = rtlight->shadow && (rtlight->isstatic ? r_rtworldshadows : r_rtdlightshadows); usestencil = false; @@ -2897,6 +2814,8 @@ void R_DrawRTLight(rtlight_t *rtlight, int visiblelighting, int visiblevolumes) else { R_Shadow_Stage_ShadowVolumes(); + GL_Clear(GL_STENCIL_BUFFER_BIT); + c_rt_clears++; usestencil = true; } ent = r_refdef.worldentity;