- r_shadow_attenpower = r_shadow_lightattenuationpower.value;
- r_shadow_attenscale = r_shadow_lightattenuationscale.value;
-#define ATTEN2DSIZE 64
-#define ATTEN3DSIZE 32
- data = (unsigned char *)Mem_Alloc(tempmempool, max(ATTEN3DSIZE*ATTEN3DSIZE*ATTEN3DSIZE*4, ATTEN2DSIZE*ATTEN2DSIZE*4));
+ r_shadow_attenlinearscale = r_shadow_lightattenuationlinearscale.value;
+ r_shadow_attendividebias = r_shadow_lightattenuationdividebias.value;
+ // note this code could suffer byte order issues except that it is multiplying by an integer that reads the same both ways
+ for (x = 0;x < 256;x++)
+ palette[x] = x * 0x01010101;
+ data = (unsigned char *)Mem_Alloc(tempmempool, max(max(ATTEN3DSIZE*ATTEN3DSIZE*ATTEN3DSIZE, ATTEN2DSIZE*ATTEN2DSIZE), ATTEN1DSIZE));
+ // the table includes one additional value to avoid the need to clamp indexing due to minor math errors
+ for (x = 0;x <= ATTENTABLESIZE;x++)
+ {
+ dist = (x + 0.5f) * (1.0f / ATTENTABLESIZE) * (1.0f / 0.9375);
+ intensity = dist < 1 ? ((1.0f - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist)) : 0;
+ r_shadow_attentable[x] = bound(0, intensity, 1);
+ }
+ // 1D gradient texture
+ for (x = 0;x < ATTEN1DSIZE;x++)
+ data[x] = R_Shadow_MakeTextures_SamplePoint((x + 0.5f) * (1.0f / ATTEN1DSIZE) * (1.0f / 0.9375), 0, 0);
+ r_shadow_attenuationgradienttexture = R_LoadTexture2D(r_shadow_texturepool, "attenuation1d", ATTEN1DSIZE, 1, data, TEXTYPE_PALETTE, TEXF_PRECACHE | TEXF_CLAMP | TEXF_ALPHA, palette);
+ // 2D circle texture