From: havoc Date: Tue, 3 Nov 2009 05:29:39 +0000 (+0000) Subject: replace FogPoint_* functions with RSurf_FogVertex X-Git-Tag: xonotic-v0.1.0preview~1223 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4a59293de079131a2671368caf7c56727c44d8ac;p=xonotic%2Fdarkplaces.git replace FogPoint_* functions with RSurf_FogVertex rename rsurface.modelorg to rsurface.localvieworigin git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9419 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_particles.c b/cl_particles.c index d7cef616..46216744 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -2133,6 +2133,9 @@ void R_DrawDecal_TransparentCallback(const entity_render_t *ent, const rtlight_t float alphascale = (1.0f / 65536.0f) * cl_particles_alpha.value * r_refdef.view.colorscale; float particle_vertex3f[BATCHSIZE*12], particle_texcoord2f[BATCHSIZE*8], particle_color4f[BATCHSIZE*16]; + // set up global fogging in worldspace (RSurf_FogVertex depends on this) + VectorCopy(r_refdef.view.origin, rsurface.localvieworigin); + r_refdef.stats.decals += numsurfaces; R_Mesh_Matrix(&identitymatrix); R_Mesh_ResetTextureState(); @@ -2155,7 +2158,7 @@ void R_DrawDecal_TransparentCallback(const entity_render_t *ent, const rtlight_t c4f = particle_color4f + 16*surfacelistindex; ca = d->alpha * alphascale; if (r_refdef.fogenabled) - ca *= FogPoint_World(d->org); + ca *= RSurf_FogVertex(d->org); Vector4Set(c4f, d->color[0] * ca, d->color[1] * ca, d->color[2] * ca, 1); Vector4Copy(c4f, c4f + 4); Vector4Copy(c4f, c4f + 8); @@ -2284,6 +2287,9 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtligh vec4_t colormultiplier; float particle_vertex3f[BATCHSIZE*12], particle_texcoord2f[BATCHSIZE*8], particle_color4f[BATCHSIZE*16]; + // set up global fogging in worldspace (RSurf_FogVertex depends on this) + VectorCopy(r_refdef.view.origin, rsurface.localvieworigin); + Vector4Set(colormultiplier, r_refdef.view.colorscale * (1.0 / 256.0f), r_refdef.view.colorscale * (1.0 / 256.0f), r_refdef.view.colorscale * (1.0 / 256.0f), cl_particles_alpha.value * (1.0 / 256.0f)); r_refdef.stats.particles += numsurfaces; @@ -2317,7 +2323,7 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtligh case PBLEND_ADD: // additive and modulate can just fade out in fog (this is correct) if (r_refdef.fogenabled) - c4f[3] *= FogPoint_World(p->org); + c4f[3] *= RSurf_FogVertex(p->org); // collapse alpha into color for these blends (so that the particlefont does not need alpha on most textures) c4f[0] *= c4f[3]; c4f[1] *= c4f[3]; @@ -2336,7 +2342,7 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtligh // mix in the fog color if (r_refdef.fogenabled) { - fog = FogPoint_World(p->org); + fog = RSurf_FogVertex(p->org); ifog = 1 - fog; c4f[0] = c4f[0] * fog + r_refdef.fogcolor[0] * ifog; c4f[1] = c4f[1] * fog + r_refdef.fogcolor[1] * ifog; diff --git a/client.h b/client.h index d9fb6ab5..06ce0674 100644 --- a/client.h +++ b/client.h @@ -1410,9 +1410,7 @@ void Debug_PolygonEnd(void); extern qboolean sb_showscores; -float FogPoint_World(const vec3_t p); -float FogPoint_Model(const vec3_t p); -float FogForDistance(vec_t dist); +float RSurf_FogVertex(const vec3_t p); typedef struct r_refdef_stats_s { diff --git a/gl_rmain.c b/gl_rmain.c index 12402b28..d4041367 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -259,22 +259,6 @@ void FOG_clear(void) r_refdef.fog_end = 0; } -float FogForDistance(vec_t dist) -{ - unsigned int fogmasktableindex = (unsigned int)(dist * r_refdef.fogmasktabledistmultiplier); - return r_refdef.fogmasktable[min(fogmasktableindex, FOGMASKTABLEWIDTH - 1)]; -} - -float FogPoint_World(const vec3_t p) -{ - return FogForDistance(VectorDistance((p), r_refdef.view.origin)); -} - -float FogPoint_Model(const vec3_t p) -{ - return FogForDistance(VectorDistance((p), rsurface.modelorg) * Matrix4x4_ScaleFromMatrix(&rsurface.matrix)); -} - static void R_BuildBlankTextures(void) { unsigned char data[4]; @@ -1486,10 +1470,10 @@ typedef enum shaderpermutation_e SHADERPERMUTATION_SHADOWMAPRECT = 1<<11, ///< (lightsource) use shadowmap rectangle texture as light filter SHADERPERMUTATION_SHADOWMAPCUBE = 1<<12, ///< (lightsource) use shadowmap cubemap texture as light filter SHADERPERMUTATION_SHADOWMAP2D = 1<<13, ///< (lightsource) use shadowmap rectangle texture as light filter - SHADERPERMUTATION_SHADOWMAPPCF = 1<<14, //< (lightsource) use percentage closer filtering on shadowmap test results - SHADERPERMUTATION_SHADOWMAPPCF2 = 1<<15, //< (lightsource) use higher quality percentage closer filtering on shadowmap test results - SHADERPERMUTATION_SHADOWSAMPLER = 1<<16, //< (lightsource) use hardware shadowmap test - SHADERPERMUTATION_SHADOWMAPVSDCT = 1<<17, //< (lightsource) use virtual shadow depth cube texture for shadowmap indexing + SHADERPERMUTATION_SHADOWMAPPCF = 1<<14, ///< (lightsource) use percentage closer filtering on shadowmap test results + SHADERPERMUTATION_SHADOWMAPPCF2 = 1<<15, ///< (lightsource) use higher quality percentage closer filtering on shadowmap test results + SHADERPERMUTATION_SHADOWSAMPLER = 1<<16, ///< (lightsource) use hardware shadowmap test + SHADERPERMUTATION_SHADOWMAPVSDCT = 1<<17, ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing SHADERPERMUTATION_LIMIT = 1<<18, ///< size of permutations array SHADERPERMUTATION_COUNT = 18 ///< size of shaderpermutationinfo array } @@ -2236,7 +2220,7 @@ void R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, f if (r_glsl_permutation->loc_ReflectOffset >= 0) qglUniform1fARB(r_glsl_permutation->loc_ReflectOffset, rsurface.texture->reflectmin); } if (r_glsl_permutation->loc_SceneBrightness >= 0) qglUniform1fARB(r_glsl_permutation->loc_SceneBrightness, r_refdef.view.colorscale); - if (r_glsl_permutation->loc_EyePosition >= 0) qglUniform3fARB(r_glsl_permutation->loc_EyePosition, rsurface.modelorg[0], rsurface.modelorg[1], rsurface.modelorg[2]); + if (r_glsl_permutation->loc_EyePosition >= 0) qglUniform3fARB(r_glsl_permutation->loc_EyePosition, rsurface.localvieworigin[0], rsurface.localvieworigin[1], rsurface.localvieworigin[2]); if (r_glsl_permutation->loc_Color_Pants >= 0) { if (rsurface.texture->currentskinframe->pants) @@ -4939,6 +4923,9 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa R_Mesh_Matrix(&identitymatrix); R_Mesh_ResetTextureState(); + // set up global fogging in worldspace (RSurf_FogVertex depends on this) + VectorCopy(r_refdef.view.origin, rsurface.localvieworigin); + vertex3f[ 0] = mins[0];vertex3f[ 1] = mins[1];vertex3f[ 2] = mins[2]; // vertex3f[ 3] = maxs[0];vertex3f[ 4] = mins[1];vertex3f[ 5] = mins[2]; vertex3f[ 6] = mins[0];vertex3f[ 7] = maxs[1];vertex3f[ 8] = mins[2]; @@ -4952,7 +4939,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa { for (i = 0, v = vertex3f, c = color4f;i < 8;i++, v += 3, c += 4) { - f1 = FogPoint_World(v); + f1 = RSurf_FogVertex(v); f2 = 1 - f1; c[0] = c[0] * f1 + r_refdef.fogcolor[0] * f2; c[1] = c[1] * f1 + r_refdef.fogcolor[1] * f2; @@ -5071,6 +5058,10 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, const rtlight int i; float f1, f2, *c; float color4f[6*4]; + + // set up global fogging in worldspace (RSurf_FogVertex depends on this) + VectorCopy(r_refdef.view.origin, rsurface.localvieworigin); + // this is only called once per entity so numsurfaces is always 1, and // surfacelist is always {0}, so this code does not handle batches R_Mesh_Matrix(&ent->matrix); @@ -5102,7 +5093,7 @@ void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, const rtlight memcpy(color4f, nomodelcolor4f, sizeof(float[6*4])); R_Mesh_ColorPointer(color4f, 0, 0); Matrix4x4_OriginFromMatrix(&ent->matrix, org); - f1 = FogPoint_World(org); + f1 = RSurf_FogVertex(org); f2 = 1 - f1; for (i = 0, c = color4f;i < 6;i++, c += 4) { @@ -5173,8 +5164,11 @@ void R_DrawSprite(int blendfunc1, int blendfunc2, rtexture_t *texture, rtexture_ float fog = 1.0f; float vertex3f[12]; + // set up global fogging in worldspace (RSurf_FogVertex depends on this) + VectorCopy(r_refdef.view.origin, rsurface.localvieworigin); + if (r_refdef.fogenabled && !depthdisable) // TODO maybe make the unfog effect a separate flag? - fog = FogPoint_World(origin); + fog = RSurf_FogVertex(origin); R_Mesh_Matrix(&identitymatrix); GL_BlendFunc(blendfunc1, blendfunc2); @@ -5738,7 +5732,7 @@ void RSurf_ActiveWorldEntity(void) rsurface.matrix = identitymatrix; rsurface.inversematrix = identitymatrix; R_Mesh_Matrix(&identitymatrix); - VectorCopy(r_refdef.view.origin, rsurface.modelorg); + VectorCopy(r_refdef.view.origin, rsurface.localvieworigin); VectorSet(rsurface.modellight_ambient, 0, 0, 0); VectorSet(rsurface.modellight_diffuse, 0, 0, 0); VectorSet(rsurface.modellight_lightdir, 0, 0, 1); @@ -5805,7 +5799,7 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q rsurface.matrix = ent->matrix; rsurface.inversematrix = ent->inversematrix; R_Mesh_Matrix(&rsurface.matrix); - Matrix4x4_Transform(&rsurface.inversematrix, r_refdef.view.origin, rsurface.modelorg); + Matrix4x4_Transform(&rsurface.inversematrix, r_refdef.view.origin, rsurface.localvieworigin); rsurface.modellight_ambient[0] = ent->modellight_ambient[0] * ent->colormod[0]; rsurface.modellight_ambient[1] = ent->modellight_ambient[1] * ent->colormod[1]; rsurface.modellight_ambient[2] = ent->modellight_ambient[2] * ent->colormod[2]; @@ -5916,6 +5910,14 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q rsurface.texcoordtexture2f = rsurface.modeltexcoordtexture2f; } +float RSurf_FogVertex(const float *v) +{ + float len = VectorDistance(rsurface.localvieworigin, v); + unsigned int fogmasktableindex; + fogmasktableindex = (unsigned int)(len * r_refdef.fogmasktabledistmultiplier); + return r_refdef.fogmasktable[min(fogmasktableindex, FOGMASKTABLEWIDTH - 1)]; +} + static const int quadedges[6][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}}; void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generatetangents, int texturenumsurfaces, msurface_t **texturesurfacelist) { @@ -6115,7 +6117,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta VectorSubtract(end, start, up); VectorNormalize(up); // calculate a forward vector to use instead of the original plane normal (this is how we get a new right vector) - VectorSubtract(rsurface.modelorg, center, forward); + VectorSubtract(rsurface.localvieworigin, center, forward); //Matrix4x4_Transform3x3(&rsurface.inversematrix, r_refdef.view.forward, forward); VectorNegate(forward, forward); VectorReflect(forward, 0, up, forward); @@ -6301,7 +6303,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta float viewer[3], d, reflected[3], worldreflected[3]; - VectorSubtract(rsurface.modelorg, vertex, viewer); + VectorSubtract(rsurface.localvieworigin, vertex, viewer); // VectorNormalize(viewer); d = DotProduct(normal, viewer); @@ -6651,7 +6653,7 @@ static void RSurf_DrawBatch_GL11_ApplyFog(int texturenumsurfaces, msurface_t **t const msurface_t *surface = texturesurfacelist[texturesurfaceindex]; for (i = 0, v = (rsurface.vertex3f + 3 * surface->num_firstvertex), c = (rsurface.lightmapcolor4f + 4 * surface->num_firstvertex), c2 = (rsurface.array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4, c2 += 4) { - f = FogPoint_Model(v); + f = RSurf_FogVertex(v); c2[0] = c[0] * f; c2[1] = c[1] * f; c2[2] = c[2] * f; @@ -6666,7 +6668,7 @@ static void RSurf_DrawBatch_GL11_ApplyFog(int texturenumsurfaces, msurface_t **t const msurface_t *surface = texturesurfacelist[texturesurfaceindex]; for (i = 0, v = (rsurface.vertex3f + 3 * surface->num_firstvertex), c2 = (rsurface.array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c2 += 4) { - f = FogPoint_Model(v); + f = RSurf_FogVertex(v); c2[0] = f; c2[1] = f; c2[2] = f; @@ -6693,7 +6695,7 @@ static void RSurf_DrawBatch_GL11_ApplyFogToFinishedVertexColors(int texturenumsu const msurface_t *surface = texturesurfacelist[texturesurfaceindex]; for (i = 0, v = (rsurface.vertex3f + 3 * surface->num_firstvertex), c = (rsurface.lightmapcolor4f + 4 * surface->num_firstvertex), c2 = (rsurface.array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4, c2 += 4) { - f = FogPoint_Model(v); + f = RSurf_FogVertex(v); c2[0] = c[0] * f + r_refdef.fogcolor[0] * (1 - f); c2[1] = c[1] * f + r_refdef.fogcolor[1] * (1 - f); c2[2] = c[2] * f + r_refdef.fogcolor[2] * (1 - f); @@ -7176,7 +7178,7 @@ static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, msurface_t **t const msurface_t *surface = texturesurfacelist[texturesurfaceindex]; for (i = 0, v = (rsurface.vertex3f + 3 * surface->num_firstvertex), c = (rsurface.array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4) { - f = 1 - FogPoint_Model(v); + f = 1 - RSurf_FogVertex(v); c[0] = layercolor[0]; c[1] = layercolor[1]; c[2] = layercolor[2]; @@ -7305,7 +7307,7 @@ static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, msurface_t **t const msurface_t *surface = texturesurfacelist[texturesurfaceindex]; for (i = 0, v = (rsurface.vertex3f + 3 * surface->num_firstvertex), c = (rsurface.array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4) { - f = 1 - FogPoint_Model(v); + f = 1 - RSurf_FogVertex(v); c[0] = layer->color[0]; c[1] = layer->color[1]; c[2] = layer->color[2]; diff --git a/model_shared.c b/model_shared.c index dcf5d8c7..963140bd 100644 --- a/model_shared.c +++ b/model_shared.c @@ -1361,9 +1361,9 @@ void Mod_Terrain_SurfaceRecurseChunk(dp_model_t *model, int stepsize, int x, int return; VectorSet(mins, model->terrain.mins[0] + x * stepsize * model->terrain.scale[0], model->terrain.mins[1] + y * stepsize * model->terrain.scale[1], model->terrain.mins[2]); VectorSet(maxs, model->terrain.mins[0] + (x+1) * stepsize * model->terrain.scale[0], model->terrain.mins[1] + (y+1) * stepsize * model->terrain.scale[1], model->terrain.maxs[2]); - viewvector[0] = bound(mins[0], modelorg, maxs[0]) - model->terrain.vieworigin[0]; - viewvector[1] = bound(mins[1], modelorg, maxs[1]) - model->terrain.vieworigin[1]; - viewvector[2] = bound(mins[2], modelorg, maxs[2]) - model->terrain.vieworigin[2]; + viewvector[0] = bound(mins[0], localvieworigin, maxs[0]) - model->terrain.vieworigin[0]; + viewvector[1] = bound(mins[1], localvieworigin, maxs[1]) - model->terrain.vieworigin[1]; + viewvector[2] = bound(mins[2], localvieworigin, maxs[2]) - model->terrain.vieworigin[2]; if (stepsize > 1 && VectorLength(viewvector) < stepsize*model->terrain.scale[0]*r_terrain_lodscale.value) { // too close for this stepsize, emit as 4 chunks instead diff --git a/r_lightning.c b/r_lightning.c index fd2daa4a..2209963e 100644 --- a/r_lightning.c +++ b/r_lightning.c @@ -219,7 +219,7 @@ void R_FogLightningBeam_Vertex3f_Color4f(const float *v, float *c, int numverts, float fog; for (i = 0;i < numverts;i++, v += 3, c += 4) { - fog = FogPoint_World(v); + fog = RSurf_FogVertex(v); c[0] = r * fog; c[1] = g * fog; c[2] = b * fog; @@ -236,6 +236,10 @@ void R_DrawLightningBeam_TransparentCallback(const entity_render_t *ent, const r float vertex3f[12*3]; float texcoord2f[12*2]; float color4f[12*4]; + + // set up global fogging in worldspace (RSurf_FogVertex depends on this) + VectorCopy(r_refdef.view.origin, rsurface.localvieworigin); + R_Mesh_Matrix(&identitymatrix); GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); GL_DepthMask(false); diff --git a/r_shadow.c b/r_shadow.c index 000f1c19..d79438bc 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -2354,7 +2354,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu if (r_refdef.fogenabled) { float f; - f = FogPoint_Model(vertex3f); + f = RSurf_FogVertex(vertex3f); VectorScale(color4f, f, color4f); } color4f[3] = 1; @@ -2369,7 +2369,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu { float f; Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v); - f = FogPoint_Model(vertex3f); + f = RSurf_FogVertex(vertex3f); VectorScale(color4f, f, color4f); } color4f[3] = 1; @@ -2402,7 +2402,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu if (r_refdef.fogenabled) { float f; - f = FogPoint_Model(vertex3f); + f = RSurf_FogVertex(vertex3f); VectorScale(color4f, f, color4f); } } @@ -2424,7 +2424,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu if (r_refdef.fogenabled) { float f; - f = FogPoint_Model(vertex3f); + f = RSurf_FogVertex(vertex3f); VectorScale(color4f, f, color4f); } } @@ -2461,7 +2461,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu if (r_refdef.fogenabled) { float f; - f = FogPoint_Model(vertex3f); + f = RSurf_FogVertex(vertex3f); VectorScale(color4f, f, color4f); } } @@ -2484,7 +2484,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu if (r_refdef.fogenabled) { float f; - f = FogPoint_Model(vertex3f); + f = RSurf_FogVertex(vertex3f); VectorScale(color4f, f, color4f); } } @@ -2530,7 +2530,7 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(int firstvertex, int nu { VectorSubtract(rsurface.entitylightorigin, vertex3f, lightdir); VectorNormalize(lightdir); - VectorSubtract(rsurface.modelorg, vertex3f, eyedir); + VectorSubtract(rsurface.localvieworigin, vertex3f, eyedir); VectorNormalize(eyedir); VectorAdd(lightdir, eyedir, halfdir); // the cubemap normalizes this for us diff --git a/render.h b/render.h index 5298ca95..6c6df724 100644 --- a/render.h +++ b/render.h @@ -315,7 +315,7 @@ typedef struct rsurfacestate_s // special coloring of glow textures vec3_t glowmod; // view location in model space - vec3_t modelorg; // TODO: rename this + vec3_t localvieworigin; // polygon offset data for submodels float basepolygonfactor; float basepolygonoffset;