]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
half lambert lighting by jal (option: -lightanglehl)
authorRudolf Polzer <rpolzer@grawp.div0.qc.to>
Sun, 14 Feb 2010 19:12:11 +0000 (20:12 +0100)
committerRudolf Polzer <rpolzer@grawp.div0.qc.to>
Sun, 14 Feb 2010 19:12:11 +0000 (20:12 +0100)
18 files changed:
tools/quake3/q3map2/game_darkplaces.h
tools/quake3/q3map2/game_dq.h
tools/quake3/q3map2/game_ef.h
tools/quake3/q3map2/game_etut.h
tools/quake3/q3map2/game_ja.h
tools/quake3/q3map2/game_jk2.h
tools/quake3/q3map2/game_nexuiz.h
tools/quake3/q3map2/game_prophecy.h
tools/quake3/q3map2/game_qfusion.h
tools/quake3/q3map2/game_quake3.h
tools/quake3/q3map2/game_quakelive.h
tools/quake3/q3map2/game_sof2.h
tools/quake3/q3map2/game_tenebrae.h
tools/quake3/q3map2/game_tremulous.h
tools/quake3/q3map2/game_wolf.h
tools/quake3/q3map2/game_wolfet.h
tools/quake3/q3map2/light.c
tools/quake3/q3map2/q3map2.h

index 04699d464db1c014620ca9c420eb22c0575b5e04..d6bae515a57c93abb8e32052f2bbb1e8be35bfbc 100644 (file)
@@ -58,6 +58,7 @@ game_t struct
        1.0f,                           /* lightmap compensate */\r
        0.3f,                           /* lightgrid scale */\r
        0.6f,                           /* lightgrid ambient scale */\r
+       qfalse,                         /* light angle attenuation uses half-lambert curve */\r
        qtrue,                          /* disable shader lightstyles hack */\r
        qtrue,                          /* keep light entities on bsp */\r
        4,                                      /* default patchMeta subdivisions tolerance */\r
index d9f7fd542180865d26fbed4855851b91b4b955f2..1c42633ea0b3ce86406f9a1ab6f4dcc3890c1336 100644 (file)
@@ -58,6 +58,7 @@ game_t struct
        1.0f,                           /* lightmap compensate */\r
        0.3f,                           /* lightgrid scale */\r
        0.6f,                           /* lightgrid ambient scale */\r
+       qfalse,                         /* light angle attenuation uses half-lambert curve */\r
        qtrue,                          /* disable shader lightstyles hack */\r
        qtrue,                          /* keep light entities on bsp */\r
        4,                                      /* default patchMeta subdivisions tolerance */\r
index 3617180120792146598135949c1d7c09b8c599b4..84ea664cb5d0ca06eb688e4e08991fc88b712f3d 100644 (file)
@@ -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 */
index 8f2f29730aa705881ea1a9b6ee048ca0d0a628d6..87d32b5563e0ea262079c6f5eb9d7d682891a85b 100644 (file)
@@ -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 */
index f63429dd3a0afb17f590508716748a10e460ca15..3d25129edffe929a85cde8698d0036de7a68862b 100644 (file)
@@ -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 */
index 0ce673ecd498c1133305b736dd5f785bec282521..056baf015bfb64e18f01956146a0590c733ede1e 100644 (file)
@@ -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 */
index 2e205d2af56b03336dbafe8a460184c5587d92a3..4d496c339c25993b6375018525936ee2791069ac 100644 (file)
@@ -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 */
index f16a515eec6c2cfd5993734a50d00940f824821e..704c99710d590af3fd51a5069049caa8fbe44120 100644 (file)
@@ -58,6 +58,7 @@ game_t struct
        1.0f,                           /* lightmap compensate */\r
        0.4f,                           /* lightgrid scale */\r
        0.6f,                           /* lightgrid ambient scale */\r
+       qfalse,                         /* light angle attenuation uses half-lambert curve */\r
        qtrue,                          /* disable shader lightstyles hack */\r
        qtrue,                          /* keep light entities on bsp */\r
        4,                                      /* default patchMeta subdivisions tolerance */\r
index 5a1b2ad38aad242bb4e9005cccffef57517277ff..7645ad0a384556939af78e8a8c41a43c8fcae43a 100644 (file)
@@ -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 */
index 949cffdd9efaab213813bb4b994aeeaa9c1494d8..98d4c4b8245c1481e76211a853853abbc253d761 100644 (file)
@@ -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 */
index 0a0e48c17e4aa327aca194975652265127f8f6d7..1a509272b3a80c88ca9408485d64ac0046da33ca 100644 (file)
@@ -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 */
index db96aa5161d57d64eba88b0cc683c4bce77fedd6..931ec69c640c47e96e12ab88826afe4e6b79d4c4 100644 (file)
@@ -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 */
index e6d6637b51bd4c55c0a4687cf764be99b8a0f160..ab3121587f4dbc4a38011bc9081b6a906785dbae 100644 (file)
@@ -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 */
index 3228d64e1f4088d16d2677b2f11c22076f905c80..5d4226291883e4693e3ec9a83dfa09fb25cec7e9 100644 (file)
@@ -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 */
index 300d8842eed92130b8ad3aa50e91ee02ddf3134a..157bfe3ae8897570b1413f336b3e9be5de121448 100644 (file)
@@ -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 */
index cd924011aacf589fa84a850ddb43efb72db519c5..3495f0dcfc6ba67ab4a220ac05251f70fd446c3e 100644 (file)
@@ -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 */
index feb8ebc942db9c434cb80f5f222121a74ad48fc6..deff96777d84b699abe112e972f1aaaaee2f182f 100644 (file)
@@ -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;
index 44425df09fa8c974b9d711625c32d12f1cebe186..498f656be12c9b7f4043ac8edbc6d347568341d2 100644 (file)
@@ -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 );