From 2d5c40b14b6bdba99443bd22b68e3dcddc345801 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 5 Apr 2011 07:51:52 +0000 Subject: [PATCH] added backface culling optimization to cl_decals_newsystem, this helps in many cases git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11023 d7cf8633-e32d-0410-b094-e92efae38249 --- client.h | 1 + gl_rmain.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/client.h b/client.h index 909a5e22..af413434 100644 --- a/client.h +++ b/client.h @@ -35,6 +35,7 @@ typedef struct tridecal_s float texcoord2f[3][2]; float vertex3f[3][3]; float color4f[3][4]; + float plane[4]; // backface culling // how long this decal has lived so far (the actual fade begins at cl_decals_time) float lived; // if >= 0 this indicates the decal should follow an animated triangle diff --git a/gl_rmain.c b/gl_rmain.c index 0fbb9ad7..758673f6 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -10404,6 +10404,9 @@ static void R_DecalSystem_SpawnTriangle(decalsystem_t *decalsystem, const float decal->texcoord2f[1][1] = t1[1]; decal->texcoord2f[2][0] = t2[0]; decal->texcoord2f[2][1] = t2[1]; + TriangleNormal(v0, v1, v2, decal->plane); + VectorNormalize(decal->plane); + decal->plane[3] = DotProduct(v0, decal->plane); } extern cvar_t cl_decals_bias; @@ -10857,6 +10860,10 @@ static void R_DrawModelDecals_Entity(entity_render_t *ent) if (surfacevisible && !surfacevisible[decal->surfaceindex]) continue; + // skip backfaces + if (decal->triangleindex < 0 && DotProduct(r_refdef.view.origin, decal->plane) < decal->plane[3]) + continue; + // update color values for fading decals if (decal->lived >= cl_decals_time.value) alpha = 1 - faderate * (decal->lived - cl_decals_time.value); -- 2.39.2