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;
angle = 1.0f;
}
- /* twosided lighting */
- if( trace->twoSided )
- angle = fabs( angle );
-
/* attenuate */
if( light->flags & LIGHT_ATTEN_LINEAR )
{
/* 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;
void TraceGrid( int num )
{
- int i, j, x, y, z, mod, step, numCon, numStyles;
- float d;
+ int i, j, x, y, z, mod, numCon, numStyles;
+ float d, step;
vec3_t baseOrigin, cheapColor, color, thisdir;
rawGridPoint_t *gp;
bspGridPoint_t *bgp;
contribution_t contributions[ MAX_CONTRIBUTIONS ];
trace_t trace;
-
/* get grid points */
gp = &rawGridPoints[ num ];
bgp = &bspGridPoints[ num ];
{
/* try to nudge the origin around to find a valid point */
VectorCopy( trace.origin, baseOrigin );
- for( step = 0.05; step <= 0.5; step += 0.05 )
+ for( step = 0; (step += 0.005) <= 1.0; )
{
- for( i = 0; i < 8; i++ )
- {
- VectorCopy( baseOrigin, trace.origin );
- if( i & 1 )
- trace.origin[ 0 ] += step * gridSize[0];
- else
- trace.origin[ 0 ] -= step * gridSize[0];
+ VectorCopy( baseOrigin, trace.origin );
+ trace.origin[ 0 ] += step * (Random() - 0.5) * gridSize[0];
+ trace.origin[ 1 ] += step * (Random() - 0.5) * gridSize[1];
+ trace.origin[ 2 ] += step * (Random() - 0.5) * gridSize[2];
- if( i & 2 )
- trace.origin[ 1 ] += step * gridSize[1];
- else
- trace.origin[ 1 ] -= step * gridSize[1];
-
- if( i & 4 )
- trace.origin[ 2 ] += step * gridSize[2];
- else
- trace.origin[ 2 ] -= step * gridSize[2];
-
- /* ydnar: changed to find cluster num */
- trace.cluster = ClusterForPointExt( trace.origin, VERTEX_EPSILON );
- if( trace.cluster >= 0 )
- break;
- }
-
- if( i != 8 )
+ /* ydnar: changed to find cluster num */
+ trace.cluster = ClusterForPointExt( trace.origin, VERTEX_EPSILON );
+ if( trace.cluster >= 0 )
break;
}
/* can't find a valid point at all */
- if( step > 0.5 )
+ if( step > 1.0 )
return;
}
vec3_t color;
float f;
int b, bt;
- qboolean minVertex, minGrid;
+ qboolean minVertex, minGrid, ps;
const char *value;
SetupEnvelopes( qtrue, fastgrid );
Sys_Printf( "--- TraceGrid ---\n" );
+ inGrid = qtrue;
RunThreadsOnIndividual( numRawGridPoints, qtrue, TraceGrid );
+ inGrid = qfalse;
Sys_Printf( "%d x %d x %d = %d grid\n",
gridBounds[ 0 ], gridBounds[ 1 ], gridBounds[ 2 ], numBSPGridPoints );
gridBoundsCulled = 0;
Sys_Printf( "--- BounceGrid ---\n" );
+ inGrid = qtrue;
RunThreadsOnIndividual( numRawGridPoints, qtrue, TraceGrid );
+ inGrid = qfalse;
Sys_FPrintf( SYS_VRB, "%9d grid points envelope culled\n", gridEnvelopeCulled );
Sys_FPrintf( SYS_VRB, "%9d grid points bounds culled\n", gridBoundsCulled );
}
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" );
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;