From: havoc Date: Thu, 8 Sep 2005 04:15:17 +0000 (+0000) Subject: moved waterscrollmatrix handling into texture->currentexmatrix to simplify texture... X-Git-Tag: xonotic-v0.1.0preview~4579 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3414b4e51b6a0dd029614fe0a56fa755e510c463;p=xonotic%2Fdarkplaces.git moved waterscrollmatrix handling into texture->currentexmatrix to simplify texture matrix shaders like water, and added support in R_Shadow_RenderLighting functions git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5696 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_rmain.c b/gl_rmain.c index 0a1dbd84..49004019 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1487,6 +1487,10 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t) t->currentmaterialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_TRANSPARENT; if (ent->effects & EF_NODEPTHTEST) t->currentmaterialflags |= MATERIALFLAG_NODEPTHTEST; + if (t->currentmaterialflags & MATERIALFLAG_WATER && r_waterscroll.value != 0) + t->currenttexmatrix = r_waterscrollmatrix; + else + t->currenttexmatrix = r_identitymatrix; } void R_UpdateAllTextureInfo(entity_render_t *ent) @@ -1725,7 +1729,6 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text qboolean doglow; qboolean dofogpass; qboolean fogallpasses; - qboolean waterscrolling; qboolean dopants; qboolean doshirt; qboolean dofullbrightpants; @@ -1772,8 +1775,6 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); else GL_BlendFunc(GL_ONE, GL_ZERO); - // water waterscrolling in texture matrix - waterscrolling = (texture->currentmaterialflags & MATERIALFLAG_WATER) && r_waterscroll.value != 0; if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) qglDisable(GL_CULL_FACE); if (texture->currentmaterialflags & MATERIALFLAG_SKY) @@ -1827,7 +1828,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text m.texcombinergb[0] = GL_REPLACE; m.texcombinergb[1] = GL_REPLACE; Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value); - m.texmatrix[1] = r_waterscrollmatrix; + m.texmatrix[1] = texture->currenttexmatrix; R_Mesh_State(&m); GL_Color(1, 1, 1, texture->currentalpha); @@ -1893,8 +1894,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text { memset(&m, 0, sizeof(m)); m.tex[1] = R_GetTexture(basetexture); - if (waterscrolling) - m.texmatrix[1] = r_waterscrollmatrix; + m.texmatrix[1] = texture->currenttexmatrix; m.texrgbscale[1] = 2; m.pointer_color = varray_color4f; R_Mesh_State(&m); @@ -1961,8 +1961,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1); memset(&m, 0, sizeof(m)); m.tex[0] = R_GetTexture(basetexture); - if (waterscrolling) - m.texmatrix[0] = r_waterscrollmatrix; + m.texmatrix[0] = texture->currenttexmatrix; R_Mesh_State(&m); for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++) { @@ -1978,8 +1977,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text { memset(&m, 0, sizeof(m)); m.tex[0] = R_GetTexture(basetexture); - if (waterscrolling) - m.texmatrix[0] = r_waterscrollmatrix; + m.texmatrix[0] = texture->currenttexmatrix; m.pointer_color = varray_color4f; colorscale = 2; if (gl_combine.integer) @@ -2033,8 +2031,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); memset(&m, 0, sizeof(m)); m.tex[0] = R_GetTexture(texture->skin.pants); - if (waterscrolling) - m.texmatrix[0] = r_waterscrollmatrix; + m.texmatrix[0] = texture->currenttexmatrix; m.pointer_color = varray_color4f; colorscale = 2; if (gl_combine.integer) @@ -2088,8 +2085,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); memset(&m, 0, sizeof(m)); m.tex[0] = R_GetTexture(texture->skin.shirt); - if (waterscrolling) - m.texmatrix[0] = r_waterscrollmatrix; + m.texmatrix[0] = texture->currenttexmatrix; m.pointer_color = varray_color4f; colorscale = 2; if (gl_combine.integer) @@ -2145,8 +2141,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text GL_DepthMask(false); memset(&m, 0, sizeof(m)); m.tex[0] = R_GetTexture(texture->skin.base); - if (waterscrolling) - m.texmatrix[0] = r_waterscrollmatrix; + m.texmatrix[0] = texture->currenttexmatrix; m.pointer_color = varray_color4f; colorscale = 1; if (gl_combine.integer && (ent->colormod[0] > 1 || ent->colormod[1] > 1 || ent->colormod[2] > 1)) @@ -2197,8 +2192,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text GL_DepthMask(false); memset(&m, 0, sizeof(m)); m.tex[0] = R_GetTexture(texture->skin.glow); - if (waterscrolling) - m.texmatrix[0] = r_waterscrollmatrix; + m.texmatrix[0] = texture->currenttexmatrix; m.pointer_color = varray_color4f; R_Mesh_State(&m); r = 1; @@ -2237,8 +2231,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text GL_DepthMask(false); memset(&m, 0, sizeof(m)); m.tex[0] = R_GetTexture(texture->skin.fog); - if (waterscrolling) - m.texmatrix[0] = r_waterscrollmatrix; + m.texmatrix[0] = texture->currenttexmatrix; R_Mesh_State(&m); r = fogcolor[0]; g = fogcolor[1]; diff --git a/model_shared.h b/model_shared.h index 9e8f2118..b2b72fa6 100644 --- a/model_shared.h +++ b/model_shared.h @@ -169,10 +169,13 @@ typedef struct texture_s // set if animated or there is an alternate frame set // (this is an optimization in the renderer) int animated; + // the current texture frame in animation struct texture_s *currentframe; // current alpha of the texture float currentalpha; + // current texture transform matrix (used for water scrolling) + matrix4x4_t currenttexmatrix; // q3bsp char name[64]; diff --git a/r_shadow.c b/r_shadow.c index 723e5b61..f42ddc56 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -296,7 +296,7 @@ const char *builtinshader_light_vert = "void main(void)\n" "{\n" " // copy the surface texcoord\n" -" TexCoord = gl_MultiTexCoord0.st;\n" +" TexCoord = vec2(gl_TextureMatrix[0] * glMultiTexCoord0);\n" "\n" " // transform vertex position into light attenuation/cubemap space\n" " // (-1 to +1 across the light box)\n" @@ -1613,6 +1613,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en qboolean doambientshirt = r_shadow_rtlight->ambientscale * VectorLength2(lightcolorshirt) > 0.00001 && shirttexture != r_texture_black; qboolean dodiffuseshirt = r_shadow_rtlight->diffusescale * VectorLength2(lightcolorshirt) > 0.00001 && shirttexture != r_texture_black; qboolean dospecular = specularscale * VectorLength2(lightcolorbase) > 0.00001 && glosstexture != r_texture_black; + //qboolean dowatershader = (texture->currentmaterialflags & MATERIALFLAG_WATER) && r_watershader.value; // TODO: add direct pants/shirt rendering if (doambientpants || dodiffusepants) R_Shadow_RenderSurfacesLighting_Light_GLSL(ent, texture, numsurfaces, surfacelist, lightcolorpants, vec3_origin, vec3_origin, pantstexture, r_texture_black, r_texture_black, normalmaptexture, r_texture_black, 0, modelorg); @@ -1620,6 +1621,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en R_Shadow_RenderSurfacesLighting_Light_GLSL(ent, texture, numsurfaces, surfacelist, lightcolorshirt, vec3_origin, vec3_origin, shirttexture, r_texture_black, r_texture_black, normalmaptexture, r_texture_black, 0, modelorg); if (!doambientbase && !dodiffusebase && !dospecular) return; + R_Mesh_TexMatrix(0, &texture->currenttexmatrix); R_Mesh_TexBind(0, R_GetTexture(normalmaptexture)); R_Mesh_TexBind(1, R_GetTexture(basetexture)); R_Mesh_TexBind(2, R_GetTexture(glosstexture)); @@ -1640,7 +1642,6 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en rsurface_normal3f = varray_normal3f; Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer); } - R_Mesh_VertexPointer(rsurface_vertex3f); R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f); R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f); R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f); @@ -1712,6 +1713,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en #endif m.tex[1] = R_GetTexture(basetexture); m.pointer_texcoord[1] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[1] = texture->currenttexmatrix; m.texcubemap[2] = R_GetTexture(r_shadow_lightcubemap); #ifdef USETEXMATRIX m.pointer_texcoord3f[2] = rsurface_vertex3f; @@ -1737,6 +1739,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en #endif m.tex[1] = R_GetTexture(basetexture); m.pointer_texcoord[1] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[1] = texture->currenttexmatrix; GL_BlendFunc(GL_ONE, GL_ONE); } else if (r_textureunits.integer >= 4 && r_shadow_lightcubemap != r_texture_whitecube) @@ -1762,6 +1765,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en #endif m.tex[2] = R_GetTexture(basetexture); m.pointer_texcoord[2] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[2] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[3] = R_GetTexture(r_shadow_lightcubemap); @@ -1798,6 +1802,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en #endif m.tex[2] = R_GetTexture(basetexture); m.pointer_texcoord[2] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[2] = texture->currenttexmatrix; GL_BlendFunc(GL_ONE, GL_ONE); } else @@ -1834,6 +1839,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(basetexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[1] = R_GetTexture(r_shadow_lightcubemap); @@ -1880,6 +1886,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.tex[0] = R_GetTexture(normalmaptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -1905,6 +1912,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(basetexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[1] = R_GetTexture(r_shadow_lightcubemap); @@ -1945,6 +1953,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.tex[0] = R_GetTexture(normalmaptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -1961,6 +1970,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(basetexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[1] = R_GetTexture(r_shadow_lightcubemap); @@ -1982,6 +1992,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.tex[0] = R_GetTexture(normalmaptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -1999,6 +2010,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(basetexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture); #ifdef USETEXMATRIX m.pointer_texcoord3f[1] = rsurface_vertex3f; @@ -2017,6 +2029,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.tex[0] = R_GetTexture(normalmaptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -2050,6 +2063,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(basetexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[1] = R_GetTexture(r_shadow_lightcubemap); @@ -2098,6 +2112,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.tex[0] = R_GetTexture(normalmaptexture); m.texcombinergb[0] = GL_REPLACE; m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -2114,6 +2129,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(basetexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[1] = R_GetTexture(r_shadow_lightcubemap); @@ -2155,6 +2171,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(normalmaptexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -2209,6 +2226,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(glosstexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[1] = R_GetTexture(r_shadow_lightcubemap); @@ -2229,6 +2247,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(normalmaptexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -2265,6 +2284,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(glosstexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture); #ifdef USETEXMATRIX m.pointer_texcoord3f[1] = rsurface_vertex3f; @@ -2282,6 +2302,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(normalmaptexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube); m.texcombinergb[1] = GL_DOT3_RGBA_ARB; m.pointer_texcoord3f[1] = varray_texcoord3f[1]; @@ -2344,6 +2365,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en m.pointer_vertex = rsurface_vertex3f; m.tex[0] = R_GetTexture(glosstexture); m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f; + m.texmatrix[0] = texture->currenttexmatrix; if (r_shadow_lightcubemap != r_texture_whitecube) { m.texcubemap[1] = R_GetTexture(r_shadow_lightcubemap); @@ -2436,8 +2458,8 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t * Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer); } // OpenGL 1.1 path (anything) - R_Mesh_VertexPointer(rsurface_vertex3f); R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f); + R_Mesh_TexMatrix(0, &texture->currenttexmatrix); if (r_textureunits.integer >= 2) { // voodoo2 or TNT