From 23a825c1f13f4773d65828ae876cc29ab2ed99cf Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 14 Feb 2010 20:12:11 +0100 Subject: [PATCH] half lambert lighting by jal (option: -lightanglehl) --- tools/quake3/q3map2/game_darkplaces.h | 1 + tools/quake3/q3map2/game_dq.h | 1 + tools/quake3/q3map2/game_ef.h | 1 + tools/quake3/q3map2/game_etut.h | 1 + tools/quake3/q3map2/game_ja.h | 1 + tools/quake3/q3map2/game_jk2.h | 1 + tools/quake3/q3map2/game_nexuiz.h | 1 + tools/quake3/q3map2/game_prophecy.h | 1 + tools/quake3/q3map2/game_qfusion.h | 5 +- tools/quake3/q3map2/game_quake3.h | 1 + tools/quake3/q3map2/game_quakelive.h | 1 + tools/quake3/q3map2/game_sof2.h | 1 + tools/quake3/q3map2/game_tenebrae.h | 1 + tools/quake3/q3map2/game_tremulous.h | 1 + tools/quake3/q3map2/game_wolf.h | 1 + tools/quake3/q3map2/game_wolfet.h | 1 + tools/quake3/q3map2/light.c | 82 ++++++++++++++++++++++----- tools/quake3/q3map2/q3map2.h | 4 ++ 18 files changed, 91 insertions(+), 15 deletions(-) diff --git a/tools/quake3/q3map2/game_darkplaces.h b/tools/quake3/q3map2/game_darkplaces.h index 04699d46..d6bae515 100644 --- a/tools/quake3/q3map2/game_darkplaces.h +++ b/tools/quake3/q3map2/game_darkplaces.h @@ -58,6 +58,7 @@ game_t struct 1.0f, /* lightmap compensate */ 0.3f, /* lightgrid scale */ 0.6f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qtrue, /* disable shader lightstyles hack */ qtrue, /* keep light entities on bsp */ 4, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_dq.h b/tools/quake3/q3map2/game_dq.h index d9f7fd54..1c42633e 100644 --- a/tools/quake3/q3map2/game_dq.h +++ b/tools/quake3/q3map2/game_dq.h @@ -58,6 +58,7 @@ game_t struct 1.0f, /* lightmap compensate */ 0.3f, /* lightgrid scale */ 0.6f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qtrue, /* disable shader lightstyles hack */ qtrue, /* keep light entities on bsp */ 4, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_ef.h b/tools/quake3/q3map2/game_ef.h index 36171801..84ea664c 100644 --- a/tools/quake3/q3map2/game_ef.h +++ b/tools/quake3/q3map2/game_ef.h @@ -117,6 +117,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_etut.h b/tools/quake3/q3map2/game_etut.h index 8f2f2973..87d32b55 100644 --- a/tools/quake3/q3map2/game_etut.h +++ b/tools/quake3/q3map2/game_etut.h @@ -152,6 +152,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_ja.h b/tools/quake3/q3map2/game_ja.h index f63429dd..3d25129e 100644 --- a/tools/quake3/q3map2/game_ja.h +++ b/tools/quake3/q3map2/game_ja.h @@ -71,6 +71,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_jk2.h b/tools/quake3/q3map2/game_jk2.h index 0ce673ec..056baf01 100644 --- a/tools/quake3/q3map2/game_jk2.h +++ b/tools/quake3/q3map2/game_jk2.h @@ -68,6 +68,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_nexuiz.h b/tools/quake3/q3map2/game_nexuiz.h index 2e205d2a..4d496c33 100644 --- a/tools/quake3/q3map2/game_nexuiz.h +++ b/tools/quake3/q3map2/game_nexuiz.h @@ -67,6 +67,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qtrue, /* disable shader lightstyles hack */ qtrue, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_prophecy.h b/tools/quake3/q3map2/game_prophecy.h index f16a515e..704c9971 100644 --- a/tools/quake3/q3map2/game_prophecy.h +++ b/tools/quake3/q3map2/game_prophecy.h @@ -58,6 +58,7 @@ game_t struct 1.0f, /* lightmap compensate */ 0.4f, /* lightgrid scale */ 0.6f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qtrue, /* disable shader lightstyles hack */ qtrue, /* keep light entities on bsp */ 4, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_qfusion.h b/tools/quake3/q3map2/game_qfusion.h index 5a1b2ad3..7645ad0a 100644 --- a/tools/quake3/q3map2/game_qfusion.h +++ b/tools/quake3/q3map2/game_qfusion.h @@ -119,10 +119,11 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qtrue, /* light angle attenuation uses half-lambert curve */ qtrue, /* disable shader lightstyles hack */ - qfalse, /* keep light entities on bsp */ + qtrue, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ - qfalse, /* patch casting enabled */ + qtrue, /* patch casting enabled */ qtrue, /* compile deluxemaps */ 0, /* deluxemaps default mode */ 256, /* minimap size */ diff --git a/tools/quake3/q3map2/game_quake3.h b/tools/quake3/q3map2/game_quake3.h index 949cffdd..98d4c4b8 100644 --- a/tools/quake3/q3map2/game_quake3.h +++ b/tools/quake3/q3map2/game_quake3.h @@ -116,6 +116,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_quakelive.h b/tools/quake3/q3map2/game_quakelive.h index 0a0e48c1..1a509272 100644 --- a/tools/quake3/q3map2/game_quakelive.h +++ b/tools/quake3/q3map2/game_quakelive.h @@ -68,6 +68,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_sof2.h b/tools/quake3/q3map2/game_sof2.h index db96aa51..931ec69c 100644 --- a/tools/quake3/q3map2/game_sof2.h +++ b/tools/quake3/q3map2/game_sof2.h @@ -143,6 +143,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_tenebrae.h b/tools/quake3/q3map2/game_tenebrae.h index e6d6637b..ab312158 100644 --- a/tools/quake3/q3map2/game_tenebrae.h +++ b/tools/quake3/q3map2/game_tenebrae.h @@ -116,6 +116,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qtrue, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_tremulous.h b/tools/quake3/q3map2/game_tremulous.h index 3228d64e..5d422629 100644 --- a/tools/quake3/q3map2/game_tremulous.h +++ b/tools/quake3/q3map2/game_tremulous.h @@ -74,6 +74,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_wolf.h b/tools/quake3/q3map2/game_wolf.h index 300d8842..157bfe3a 100644 --- a/tools/quake3/q3map2/game_wolf.h +++ b/tools/quake3/q3map2/game_wolf.h @@ -133,6 +133,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/game_wolfet.h b/tools/quake3/q3map2/game_wolfet.h index cd924011..3495f0dc 100644 --- a/tools/quake3/q3map2/game_wolfet.h +++ b/tools/quake3/q3map2/game_wolfet.h @@ -70,6 +70,7 @@ game_t struct 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ 1.0f, /* lightgrid ambient scale */ + qfalse, /* light angle attenuation uses half-lambert curve */ qfalse, /* disable shader lightstyles hack */ qfalse, /* keep light entities on bsp */ 8, /* default patchMeta subdivisions tolerance */ diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index feb8ebc9..deff9677 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -865,7 +865,33 @@ int LightContributionToSample( trace_t *trace ) dist = 16.0f; /* angle attenuation */ - angle = (light->flags & LIGHT_ATTEN_ANGLE) ? DotProduct( trace->normal, trace->direction ) : 1.0f; + if( light->flags & LIGHT_ATTEN_ANGLE ) + { + /* standard Lambert attenuation */ + float dot = DotProduct( trace->normal, trace->direction ); + + /* twosided lighting */ + if( trace->twoSided ) + dot = fabs( dot ); + + /* jal: optional half Lambert attenuation (http://developer.valvesoftware.com/wiki/Half_Lambert) */ + if( lightAngleHL ) + { + if( dot > 0.001f ) // skip coplanar + { + if( dot > 1.0f ) dot = 1.0f; + dot = ( dot * 0.5f ) + 0.5f; + dot *= dot; + } + else + dot = 0; + } + + angle = dot; + } + else + angle = 1.0f; + if( light->angleScale != 0.0f ) { angle /= light->angleScale; @@ -873,10 +899,6 @@ int LightContributionToSample( trace_t *trace ) angle = 1.0f; } - /* twosided lighting */ - if( trace->twoSided ) - angle = fabs( angle ); - /* attenuate */ if( light->flags & LIGHT_ATTEN_LINEAR ) { @@ -918,15 +940,34 @@ int LightContributionToSample( trace_t *trace ) /* get origin and direction */ VectorAdd( trace->origin, light->origin, trace->end ); dist = SetupTrace( trace ); - + /* angle attenuation */ - angle = (light->flags & LIGHT_ATTEN_ANGLE) - ? DotProduct( trace->normal, trace->direction ) - : 1.0f; - - /* twosided lighting */ - if( trace->twoSided ) - angle = fabs( angle ); + if( light->flags & LIGHT_ATTEN_ANGLE ) + { + /* standard Lambert attenuation */ + float dot = DotProduct( trace->normal, trace->direction ); + + /* twosided lighting */ + if( trace->twoSided ) + dot = fabs( dot ); + + /* jal: optional half Lambert attenuation (http://developer.valvesoftware.com/wiki/Half_Lambert) */ + if( lightAngleHL ) + { + if( dot > 0.001f ) // skip coplanar + { + if( dot > 1.0f ) dot = 1.0f; + dot = ( dot * 0.5f ) + 0.5f; + dot *= dot; + } + else + dot = 0; + } + + angle = dot; + } + else + angle = 1.0f; /* attenuate */ add = light->photons * angle; @@ -1880,6 +1921,10 @@ int LightMain( int argc, char **argv ) gridAmbientScale = game->gridAmbientScale; Sys_Printf( " lightgrid ambient scale: %f\n", gridAmbientScale ); + lightAngleHL = game->lightAngleHL; + if( lightAngleHL ) + Sys_Printf( " half lambert light angle attenuation enabled \n" ); + noStyles = game->noStyles; if (noStyles == qtrue) Sys_Printf( " shader lightstyles hack: disabled\n" ); @@ -2416,6 +2461,17 @@ int LightMain( int argc, char **argv ) loMem = qtrue; Sys_Printf( "Enabling low-memory (potentially slower) lighting mode\n" ); } + else if( !strcmp( argv[ i ], "-lightanglehl" ) ) + { + if( ( atoi( argv[ i + 1 ] ) != 0 ) != lightAngleHL ) + { + lightAngleHL = ( atoi( argv[ i + 1 ] ) != 0 ); + if( lightAngleHL ) + Sys_Printf( "Enabling half lambert light angle attenuation\n" ); + else + Sys_Printf( "Disabling half lambert light angle attenuation\n" ); + } + } else if( !strcmp( argv[ i ], "-nostyle" ) || !strcmp( argv[ i ], "-nostyles" ) ) { noStyles = qtrue; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 44425df0..498f656b 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -562,6 +562,7 @@ typedef struct game_s float lightmapCompensate; /* default lightmap compensate value */ float gridScale; /* vortex: default lightgrid scale (affects both directional and ambient spectres) */ float gridAmbientScale; /* vortex: default lightgrid ambient spectre scale */ + qboolean lightAngleHL; /* jal: use half-lambert curve for light angle attenuation */ qboolean noStyles; /* use lightstyles hack or not */ qboolean keepLights; /* keep light entities on bsp */ int patchSubdivisions; /* default patch subdivisions tolerance */ @@ -2217,6 +2218,9 @@ Q_EXTERN float pointScale Q_ASSIGN( 7500.0f ); Q_EXTERN float areaScale Q_ASSIGN( 0.25f ); Q_EXTERN float skyScale Q_ASSIGN( 1.0f ); Q_EXTERN float bounceScale Q_ASSIGN( 0.25f ); + +/* jal: alternative angle attenuation curve */ +Q_EXTERN qboolean lightAngleHL Q_ASSIGN( qfalse ); /* vortex: gridscale and gridambientscale */ Q_EXTERN float gridScale Q_ASSIGN( 1.0f ); -- 2.39.2