From 34d4382446de8c079d3ceae42faec0b1bacc9b8f Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 21 Mar 2003 21:52:04 +0000 Subject: [PATCH] Thanks to IceDagger for pointing out this important optimization to multipass specular rendering - removes one pass (dropping from 6 to 5 passes on GF2, 5 to 4 passes on GF3/Radeon) by squaring specular even on the first pass git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2845 d7cf8633-e32d-0410-b094-e92efae38249 --- r_shadow.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/r_shadow.c b/r_shadow.c index de429d0b..26ad0124 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -1412,13 +1412,15 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen { if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && lightcubemap /*&& gl_support_blendsquare*/) // FIXME: detect blendsquare! { - // 2/0/0/0/1/2 3D combine blendsquare path + // 2/0/0/1/2 3D combine blendsquare path m.tex[0] = R_GetTexture(bumptexture); m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; R_Mesh_TextureState(&m); qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); + // this squares the result + qglEnable(GL_BLEND); + qglBlendFunc(GL_SRC_ALPHA, GL_ZERO); GL_Color(1,1,1,1); R_Mesh_GetSpace(numverts); R_Mesh_CopyVertex3f(vertex3f, numverts); @@ -1434,12 +1436,11 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen R_Mesh_TextureState(&m); // square alpha in framebuffer a few times to make it shiny qglBlendFunc(GL_ZERO, GL_DST_ALPHA); - qglEnable(GL_BLEND); // these comments are a test run through this math for intensity 0.5 - // 0.5 * 0.5 = 0.25 - // 0.25 * 0.25 = 0.0625 - // 0.0625 * 0.0625 = 0.00390625 - for (renders = 0;renders < 3;renders++) + // 0.5 * 0.5 = 0.25 (done by the BlendFunc earlier) + // 0.25 * 0.25 = 0.0625 (this is another pass) + // 0.0625 * 0.0625 = 0.00390625 (this is another pass) + for (renders = 0;renders < 2;renders++) { R_Mesh_GetSpace(numverts); R_Mesh_CopyVertex3f(vertex3f, numverts); @@ -1484,13 +1485,15 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen } else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && !lightcubemap /*&& gl_support_blendsquare*/) // FIXME: detect blendsquare! { - // 2/0/0/0/2 3D combine blendsquare path + // 2/0/0/2 3D combine blendsquare path m.tex[0] = R_GetTexture(bumptexture); m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; R_Mesh_TextureState(&m); qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); + // this squares the result + qglEnable(GL_BLEND); + qglBlendFunc(GL_SRC_ALPHA, GL_ZERO); GL_Color(1,1,1,1); R_Mesh_GetSpace(numverts); R_Mesh_CopyVertex3f(vertex3f, numverts); @@ -1506,12 +1509,11 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen R_Mesh_TextureState(&m); // square alpha in framebuffer a few times to make it shiny qglBlendFunc(GL_ZERO, GL_DST_ALPHA); - qglEnable(GL_BLEND); // these comments are a test run through this math for intensity 0.5 - // 0.5 * 0.5 = 0.25 - // 0.25 * 0.25 = 0.0625 - // 0.0625 * 0.0625 = 0.00390625 - for (renders = 0;renders < 3;renders++) + // 0.5 * 0.5 = 0.25 (done by the BlendFunc earlier) + // 0.25 * 0.25 = 0.0625 (this is another pass) + // 0.0625 * 0.0625 = 0.00390625 (this is another pass) + for (renders = 0;renders < 2;renders++) { R_Mesh_GetSpace(numverts); R_Mesh_CopyVertex3f(vertex3f, numverts); @@ -1548,13 +1550,15 @@ 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 blendsquare path + // 2/0/0/2/2 2D combine blendsquare path m.tex[0] = R_GetTexture(bumptexture); m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; R_Mesh_TextureState(&m); qglColorMask(0,0,0,1); - qglDisable(GL_BLEND); + // this squares the result + qglEnable(GL_BLEND); + qglBlendFunc(GL_SRC_ALPHA, GL_ZERO); GL_Color(1,1,1,1); R_Mesh_GetSpace(numverts); R_Mesh_CopyVertex3f(vertex3f, numverts); @@ -1570,12 +1574,11 @@ void R_Shadow_SpecularLighting(int numverts, int numtriangles, const int *elemen R_Mesh_TextureState(&m); // square alpha in framebuffer a few times to make it shiny qglBlendFunc(GL_ZERO, GL_DST_ALPHA); - qglEnable(GL_BLEND); // these comments are a test run through this math for intensity 0.5 - // 0.5 * 0.5 = 0.25 - // 0.25 * 0.25 = 0.0625 - // 0.0625 * 0.0625 = 0.00390625 - for (renders = 0;renders < 3;renders++) + // 0.5 * 0.5 = 0.25 (done by the BlendFunc earlier) + // 0.25 * 0.25 = 0.0625 (this is another pass) + // 0.0625 * 0.0625 = 0.00390625 (this is another pass) + for (renders = 0;renders < 2;renders++) { R_Mesh_GetSpace(numverts); R_Mesh_CopyVertex3f(vertex3f, numverts); -- 2.39.2