X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=r_light.c;h=aa35da8ef81bab35d205918b4bc6f54889303df0;hb=d8c2fec3b2fb4a243bfbadfc873fc7d4623c1bcd;hp=395c68c6dbe04f4b7b2f1b88124edd6bae4dc314;hpb=83b77bee53d11d3e694f34e242e15cacdce188cd;p=xonotic%2Fdarkplaces.git diff --git a/r_light.c b/r_light.c index 395c68c6..aa35da8e 100644 --- a/r_light.c +++ b/r_light.c @@ -28,12 +28,36 @@ cvar_t r_lightmodels = {CVAR_SAVE, "r_lightmodels", "1"}; cvar_t r_vismarklights = {0, "r_vismarklights", "1"}; cvar_t r_lightmodelhardness = {CVAR_SAVE, "r_lightmodelhardness", "0.9"}; +static rtexture_t *lightcorona; +static rtexturepool_t *lighttexturepool; + void r_light_start(void) { + float dx, dy; + int x, y, a; + qbyte pixels[32][32][4]; + lighttexturepool = R_AllocTexturePool(); + for (y = 0;y < 32;y++) + { + dy = (y - 15.5f) * (1.0f / 16.0f); + for (x = 0;x < 32;x++) + { + dx = (x - 15.5f) * (1.0f / 16.0f); + a = ((1.0f / (dx * dx + dy * dy + 0.2f)) - (1.0f / (1.0f + 0.2))) * 64.0f / (1.0f / (1.0f + 0.2)); + a = bound(0, a, 255); + pixels[y][x][0] = 255; + pixels[y][x][1] = 255; + pixels[y][x][2] = 255; + pixels[y][x][3] = a; + } + } + lightcorona = R_LoadTexture (lighttexturepool, "lightcorona", 32, 32, &pixels[0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_ALPHA); } void r_light_shutdown(void) { + lighttexturepool = NULL; + lightcorona = NULL; } void r_light_newmap(void) @@ -95,8 +119,8 @@ void R_BuildLightList(void) continue; rd = &r_dlight[r_numdlights++]; VectorCopy(cd->origin, rd->origin); - VectorScale(cd->color, cd->radius * 256.0f, rd->light); - rd->cullradius = (1.0f / 256.0f) * sqrt(DotProduct(rd->light, rd->light)); + VectorScale(cd->color, cd->radius * 128.0f, rd->light); + rd->cullradius = (1.0f / 128.0f) * sqrt(DotProduct(rd->light, rd->light)); // clamp radius to avoid overflowing division table in lightmap code if (rd->cullradius > 2048.0f) rd->cullradius = 2048.0f; @@ -108,6 +132,76 @@ void R_BuildLightList(void) } } +static int coronapolyindex[6] = {0, 1, 2, 0, 2, 3}; + +void R_DrawCoronas(void) +{ + int i; + rmeshinfo_t m; + float tvxyz[4][4], tvst[4][2], scale, viewdist, diff[3], dist; + rdlight_t *rd; + memset(&m, 0, sizeof(m)); + m.transparent = false; + m.blendfunc1 = GL_SRC_ALPHA; + m.blendfunc2 = GL_ONE; + m.depthdisable = true; // magic + m.numtriangles = 2; + m.numverts = 4; + m.index = coronapolyindex; + m.vertex = &tvxyz[0][0]; + m.vertexstep = sizeof(float[4]); + m.tex[0] = R_GetTexture(lightcorona); + m.texcoords[0] = &tvst[0][0]; + m.texcoordstep[0] = sizeof(float[2]); + tvst[0][0] = 0; + tvst[0][1] = 0; + tvst[1][0] = 0; + tvst[1][1] = 1; + tvst[2][0] = 1; + tvst[2][1] = 1; + tvst[3][0] = 1; + tvst[3][1] = 0; + viewdist = DotProduct(r_origin, vpn); + for (i = 0;i < r_numdlights;i++) + { + rd = r_dlight + i; + dist = (DotProduct(rd->origin, vpn) - viewdist); + if (dist >= 24.0f) + { + // trace to a point just barely closer to the eye + VectorSubtract(rd->origin, vpn, diff); + if (TraceLine(r_origin, diff, NULL, NULL, 0, true) == 1) + { + scale = 1.0f / 262144.0f; + //scale = 64.0f / (DotProduct(diff,diff) + 1024.0f); + m.cr = rd->light[0] * scale; + m.cg = rd->light[1] * scale; + m.cb = rd->light[2] * scale; + m.ca = 1; + if (fogenabled) + { + VectorSubtract(rd->origin, r_origin, diff); + m.ca *= 1 - exp(fogdensity/DotProduct(diff,diff)); + } + scale = rd->cullradius * 0.25f; + tvxyz[0][0] = rd->origin[0] - vright[0] * scale - vup[0] * scale; + tvxyz[0][1] = rd->origin[1] - vright[1] * scale - vup[1] * scale; + tvxyz[0][2] = rd->origin[2] - vright[2] * scale - vup[2] * scale; + tvxyz[1][0] = rd->origin[0] - vright[0] * scale + vup[0] * scale; + tvxyz[1][1] = rd->origin[1] - vright[1] * scale + vup[1] * scale; + tvxyz[1][2] = rd->origin[2] - vright[2] * scale + vup[2] * scale; + tvxyz[2][0] = rd->origin[0] + vright[0] * scale + vup[0] * scale; + tvxyz[2][1] = rd->origin[1] + vright[1] * scale + vup[1] * scale; + tvxyz[2][2] = rd->origin[2] + vright[2] * scale + vup[2] * scale; + tvxyz[3][0] = rd->origin[0] + vright[0] * scale - vup[0] * scale; + tvxyz[3][1] = rd->origin[1] + vright[1] * scale - vup[1] * scale; + tvxyz[3][2] = rd->origin[2] + vright[2] * scale - vup[2] * scale; + R_Mesh_Draw(&m); + } + } + } +} + /* ============================================================================= @@ -164,7 +258,7 @@ loc0: } // mark the polygons - surf = cl.worldmodel->surfaces + node->firstsurface; + surf = currentrenderentity->model->surfaces + node->firstsurface; for (i=0 ; inumsurfaces ; i++, surf++) { int d, impacts, impactt; @@ -301,7 +395,7 @@ static void R_VisMarkLights (rdlight_t *rd, int bit, int bitindex) int i, k, m, c, leafnum; msurface_t *surf, **mark; mleaf_t *leaf; - byte *in; + qbyte *in; int row; float low[3], high[3], dist, maxdist; @@ -568,7 +662,7 @@ loc0: if (surf->samples) { - byte *lightmap; + qbyte *lightmap; int maps, line3, size3, dsfrac = ds & 15, dtfrac = dt & 15, scale = 0, r00 = 0, g00 = 0, b00 = 0, r01 = 0, g01 = 0, b01 = 0, r10 = 0, g10 = 0, b10 = 0, r11 = 0, g11 = 0, b11 = 0; line3 = ((surf->extents[0]>>4)+1)*3; size3 = ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting @@ -824,7 +918,7 @@ void R_LightModel(int numverts) VectorCopy(color, avc); avc[3] = a; avc += 4; - av += 3; + av += 4; avn += 3; } }