-
- /* twosided lighting */
- if( trace->twoSided )
- angle = fabs( angle );
-
- /* attenuate */
- if( light->flags & LIGHT_ATTEN_LINEAR )
- {
- add = angle * light->photons * linearScale - (dist * light->fade);
- if( add < 0.0f )
- add = 0.0f;
- }
- else
- add = light->photons / (dist * dist) * angle;
-
- /* handle spotlights */
- if( light->type == EMIT_SPOT )
- {
- float distByNormal, radiusAtDist, sampleRadius;
- vec3_t pointAtDist, distToSample;
-
- /* do cone calculation */
+
+ /* angle attenuation */
+ if ( light->flags & LIGHT_ATTEN_ANGLE ) {
+ /* standard Lambert attenuation */
+ float dot = DotProduct( trace->normal, trace->direction );
+
+ /* twosided lighting */
+ if ( trace->twoSided && dot < 0 ) {
+ dot = -dot;
+
+ /* no deluxemap contribution from "other side" light */
+ doAddDeluxe = qfalse;
+ }
+
+ /* 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;
+ if ( angle > 1.0f ) {
+ angle = 1.0f;
+ }
+ }
+
+ /* attenuate */
+ if ( light->flags & LIGHT_ATTEN_LINEAR ) {
+ add = angle * light->photons * linearScale - ( dist * light->fade );
+ if ( add < 0.0f ) {
+ add = 0.0f;
+ }
+
+ if ( deluxemap ) {
+ if ( angledDeluxe ) {
+ addDeluxe = angle * light->photons * linearScale - ( dist * light->fade );
+ }
+ else{
+ addDeluxe = light->photons * linearScale - ( dist * light->fade );
+ }
+
+ if ( addDeluxe < 0.0f ) {
+ addDeluxe = 0.0f;
+ }
+ }
+ }
+ else
+ {
+ add = ( light->photons / ( dist * dist ) ) * angle;
+ if ( add < 0.0f ) {
+ add = 0.0f;
+ }
+
+ if ( deluxemap ) {
+ if ( angledDeluxe ) {
+ addDeluxe = ( light->photons / ( dist * dist ) ) * angle;
+ }
+ else{
+ addDeluxe = ( light->photons / ( dist * dist ) );
+ }
+ }
+
+ if ( addDeluxe < 0.0f ) {
+ addDeluxe = 0.0f;
+ }
+ }
+
+ /* handle spotlights */
+ if ( light->type == EMIT_SPOT ) {
+ float distByNormal, radiusAtDist, sampleRadius;
+ vec3_t pointAtDist, distToSample;
+
+ /* do cone calculation */