static void ComputeLightmapColorPointSample( dface_t* pFace, directlight_t* pSkylight, Vector2D const& luv, float scale, Vector pColor[MAX_LIGHTSTYLES] ) { // face unaffected by light if (pFace->lightofs == -1 ) return; int smax = ( pFace->m_LightmapTextureSizeInLuxels[0] ) + 1; int tmax = ( pFace->m_LightmapTextureSizeInLuxels[1] ) + 1; // luv is in the space of the accumulated lightmap page; we need to convert // it to be in the space of the surface int ds = clamp( (int)luv.x, 0, smax-1 ); int dt = clamp( (int)luv.y, 0, tmax-1 ); int offset = smax * tmax; if ( SurfHasBumpedLightmaps( pFace ) ) offset *= ( NUM_BUMP_VECTS + 1 ); ColorRGBExp32* pLightmap = (ColorRGBExp32*)&pdlightdata->Base()[pFace->lightofs]; pLightmap += dt * smax + ds; for (int maps = 0 ; maps < MAXLIGHTMAPS && pFace->styles[maps] != 255 ; ++maps) { int style = pFace->styles[maps]; Vector color; color[0] = TexLightToLinear( pLightmap->r, pLightmap->exponent ); color[1] = TexLightToLinear( pLightmap->g, pLightmap->exponent ); color[2] = TexLightToLinear( pLightmap->b, pLightmap->exponent ); ComputeAmbientFromSurface( pFace, pSkylight, color ); pColor[style] += color * scale; pLightmap += offset; } }
static void ComputeLightmapColorFromAverage( dface_t* pFace, directlight_t* pSkylight, float scale, Vector pColor[MAX_LIGHTSTYLES] ) { texinfo_t* pTex = &texinfo[pFace->texinfo]; if (pTex->flags & SURF_SKY) { if (pSkylight) { // add in sky ambient Vector amb = pSkylight->light.intensity / 255.0f; pColor[0] += amb * scale; } return; } for (int maps = 0 ; maps < MAXLIGHTMAPS && pFace->styles[maps] != 255 ; ++maps) { ColorRGBExp32* pAvgColor = dface_AvgLightColor( pFace, maps ); // this code expects values from [0..1] not [0..255] Vector color; color[0] = TexLightToLinear( pAvgColor->r, pAvgColor->exponent ); color[1] = TexLightToLinear( pAvgColor->g, pAvgColor->exponent ); color[2] = TexLightToLinear( pAvgColor->b, pAvgColor->exponent ); ComputeAmbientFromSurface( pFace, pSkylight, color ); int style = pFace->styles[maps]; pColor[style] += color * scale; } }
void ColorRGBExp32ToVector( const ColorRGBExp32& in, Vector& out ) { Assert( s_bMathlibInitialized ); // FIXME: Why is there a factor of 255 built into this? out.x = 255.0f * TexLightToLinear( in.r, in.exponent ); out.y = 255.0f * TexLightToLinear( in.g, in.exponent ); out.z = 255.0f * TexLightToLinear( in.b, in.exponent ); }
//----------------------------------------------------------------------------- // Computes the lightmap color at a particular point //----------------------------------------------------------------------------- static void ComputeLightmapColorFromAverage( msurfacelighting_t *pLighting, bool bUseLightStyles, Vector& c ) { int nMaxMaps = bUseLightStyles ? MAXLIGHTMAPS : 1; for (int maps = 0 ; maps < nMaxMaps && pLighting->m_nStyles[maps] != 255 ; ++maps) { float scale = LightStyleValue( pLighting->m_nStyles[maps] ); ColorRGBExp32* pAvgColor = pLighting->AvgLightColor(maps); c[0] += TexLightToLinear( pAvgColor->r, pAvgColor->exponent ) * scale; c[1] += TexLightToLinear( pAvgColor->g, pAvgColor->exponent ) * scale; c[2] += TexLightToLinear( pAvgColor->b, pAvgColor->exponent ) * scale; } }
//----------------------------------------------------------------------------- // Computes the lightmap color at a particular point //----------------------------------------------------------------------------- static void ComputeLightmapColor( SurfaceHandle_t surfID, int ds, int dt, bool bUseLightStyles, Vector& c ) { msurfacelighting_t *pLighting = SurfaceLighting( surfID ); ColorRGBExp32* pLightmap = pLighting->m_pSamples; if( !pLightmap ) { static int messagecount = 0; if ( ++messagecount < 10 ) { // Stop spamming. I heard you already!!! ConMsg( "hit surface has no samples\n" ); } return; } int smax = ( pLighting->m_LightmapExtents[0] ) + 1; int tmax = ( pLighting->m_LightmapExtents[1] ) + 1; int offset = smax * tmax; if ( SurfHasBumpedLightmaps( surfID ) ) { offset *= ( NUM_BUMP_VECTS + 1 ); } pLightmap += dt * smax + ds; int nMaxMaps = bUseLightStyles ? MAXLIGHTMAPS : 1; for (int maps = 0 ; maps < nMaxMaps && pLighting->m_nStyles[maps] != 255 ; ++maps) { float scale = LightStyleValue( pLighting->m_nStyles[maps] ); c[0] += TexLightToLinear( pLightmap->r, pLightmap->exponent ) * scale; c[1] += TexLightToLinear( pLightmap->g, pLightmap->exponent ) * scale; c[2] += TexLightToLinear( pLightmap->b, pLightmap->exponent ) * scale; // Check version 32 in source safe for some debugging crap pLightmap += offset; } }