From: Holger Z. <hz...@us...> - 2005-01-12 12:14:37
|
Update of /cvsroot/jake2/jake2/src/jake2/render/fastjogl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6887/src/jake2/render/fastjogl Modified Files: Light.java Log Message: small performance improvements Index: Light.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Light.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Light.java 22 Sep 2004 19:22:11 -0000 1.9 --- Light.java 12 Jan 2005 12:14:27 -0000 1.10 *************** *** 209,213 **** float[] lightspot = { 0, 0, 0 }; // vec3_t ! int RecursiveLightPoint(mnode_t node, float[] start, float[] end) { if (node.contents != -1) --- 209,215 ---- float[] lightspot = { 0, 0, 0 }; // vec3_t ! ! float scalef = 1.0f/255; ! int RecursiveLightPoint(mnode_t node, float[] start, float[] end) { if (node.contents != -1) *************** *** 220,224 **** ByteBuffer lightmap; int maps; - float[] mid = { 0, 0, 0 }; // calculate mid point --- 222,225 ---- *************** *** 235,238 **** --- 236,240 ---- float frac = front / (front - back); + float[] mid = { 0, 0, 0 }; mid[0] = start[0] + (end[0] - start[0]) * frac; mid[1] = start[1] + (end[1] - start[1]) * frac; *************** *** 252,256 **** int surfIndex = node.firstsurface; ! float[] scale = { 0, 0, 0 }; for (i = 0; i < node.numsurfaces; i++, surfIndex++) { surf = r_worldmodel.surfaces[surfIndex]; --- 254,260 ---- int surfIndex = node.firstsurface; ! float scale0; ! float scale1; ! float scale2; for (i = 0; i < node.numsurfaces; i++, surfIndex++) { surf = r_worldmodel.surfaces[surfIndex]; *************** *** 284,288 **** Math3D.VectorCopy(Globals.vec3_origin, pointcolor); if (lightmap != null) { - //float[] scale = {0, 0, 0}; float[] rgb; lightmapIndex += 3 * (dt * ((surf.extents[0] >> 4) + 1) + ds); --- 288,291 ---- *************** *** 291,304 **** && surf.styles[maps] != (byte) 255; maps++) { rgb = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb; ! scale[0] = gl_modulate.value * rgb[0]; ! scale[1] = gl_modulate.value * rgb[1]; ! scale[2] = gl_modulate.value * rgb[2]; pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) ! * scale[0] * (1.0f / 255); pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) ! * scale[1] * (1.0f / 255); pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) ! * scale[2] * (1.0f / 255); lightmapIndex += 3 * ((surf.extents[0] >> 4) + 1) * ((surf.extents[1] >> 4) + 1); --- 294,307 ---- && surf.styles[maps] != (byte) 255; maps++) { rgb = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb; ! scale0 = gl_modulate.value * rgb[0]; ! scale1 = gl_modulate.value * rgb[1]; ! scale2 = gl_modulate.value * rgb[2]; pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) ! * scale0 * scalef; pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) ! * scale1 * scalef; pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) ! * scale2 * scalef; lightmapIndex += 3 * ((surf.extents[0] >> 4) + 1) * ((surf.extents[1] >> 4) + 1); *************** *** 319,331 **** assert (color.length == 3) : "rgb bug"; - float[] end = { 0, 0, 0 }; - dlight_t dl; - float add; - if (r_worldmodel.lightdata == null) { color[0] = color[1] = color[2] = 1.0f; return; } ! end[0] = p[0]; end[1] = p[1]; --- 322,331 ---- assert (color.length == 3) : "rgb bug"; if (r_worldmodel.lightdata == null) { color[0] = color[1] = color[2] = 1.0f; return; } ! ! float[] end = { 0, 0, 0 }; end[0] = p[0]; end[1] = p[1]; *************** *** 343,354 **** // add dynamic lights // for (int lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) { dl = r_newrefdef.dlights[lnum]; Math3D.VectorSubtract(currententity.origin, dl.origin, end); ! add = dl.intensity - Math3D.VectorLength(end); ! add *= (1.0f / 256); if (add > 0) { ! Math3D.VectorMA(color, add, dl.color, color); } } --- 343,356 ---- // add dynamic lights // + float add; + dlight_t dl; for (int lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) { dl = r_newrefdef.dlights[lnum]; Math3D.VectorSubtract(currententity.origin, dl.origin, end); ! add = (dl.intensity - Math3D.VectorLength(end)); ! if (add > 0) { ! Math3D.VectorMA(color, add * scalef, dl.color, color); } } *************** *** 369,373 **** float fdist, frad, fminlight; float[] impact = { 0, 0, 0 }; - float[] local = { 0, 0, 0 }; int s, t; dlight_t dl; --- 371,374 ---- *************** *** 379,382 **** --- 380,385 ---- mtexinfo_t tex = surf.texinfo; + float local0; + float local1; for (int lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) { if ((surf.dlightbits & (1 << lnum)) == 0) *************** *** 399,405 **** } ! local[0] = Math3D.DotProduct(impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0]; ! local[1] = Math3D.DotProduct(impact, tex.vecs[1]) + tex.vecs[1][3] - surf.texturemins[1]; --- 402,408 ---- } ! local0 = Math3D.DotProduct(impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0]; ! local1 = Math3D.DotProduct(impact, tex.vecs[1]) + tex.vecs[1][3] - surf.texturemins[1]; *************** *** 407,416 **** int pfBLindex = 0; for (t = 0, ftacc = 0; t < tmax; t++, ftacc += 16) { ! td = (int) (local[1] - ftacc); if (td < 0) td = -td; for (s = 0, fsacc = 0; s < smax; s++, fsacc += 16, pfBLindex += 3) { ! sd = (int) (local[0] - fsacc); if (sd < 0) --- 410,419 ---- int pfBLindex = 0; for (t = 0, ftacc = 0; t < tmax; t++, ftacc += 16) { ! td = (int) (local1 - ftacc); if (td < 0) td = -td; for (s = 0, fsacc = 0; s < smax; s++, fsacc += 16, pfBLindex += 3) { ! sd = (int) (local0 - fsacc); if (sd < 0) *************** *** 452,457 **** int r, g, b, a, max; int i, j; - ByteBuffer lightmap; - float[] scale = { 0, 0, 0 }; int nummaps; float[] bl; --- 455,458 ---- *************** *** 493,500 **** ; ! lightmap = surf.samples; int lightmapIndex = 0; // add all the lightmaps if (nummaps == 1) { int maps; --- 494,504 ---- ; ! ByteBuffer lightmap = surf.samples; int lightmapIndex = 0; // add all the lightmaps + float scale0; + float scale1; + float scale2; if (nummaps == 1) { int maps; *************** *** 505,514 **** int blp = 0; ! for (i = 0; i < 3; i++) ! scale[i] = gl_modulate.value ! * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; ! if (scale[0] == 1.0F && scale[1] == 1.0F ! && scale[2] == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; --- 509,521 ---- int blp = 0; ! // for (i = 0; i < 3; i++) ! // scale[i] = gl_modulate.value ! // * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; ! scale0 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0]; ! scale1 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1]; ! scale2 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2]; ! if (scale0 == 1.0F && scale1 == 1.0F ! && scale2 == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; *************** *** 519,527 **** for (i = 0; i < size; i++) { bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) ! * scale[0]; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) ! * scale[1]; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) ! * scale[2]; } } --- 526,534 ---- for (i = 0; i < size; i++) { bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) ! * scale0; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) ! * scale1; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) ! * scale2; } } *************** *** 541,550 **** int blp = 0; ! for (i = 0; i < 3; i++) ! scale[i] = gl_modulate.value ! * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; ! if (scale[0] == 1.0F && scale[1] == 1.0F ! && scale[2] == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; --- 548,566 ---- int blp = 0; ! // for (i = 0; i < 3; i++) ! // scale[i] = gl_modulate.value ! // * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; ! scale0 = gl_modulate.value ! * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0]; ! scale1 = gl_modulate.value ! * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1]; ! scale2 = gl_modulate.value ! * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2]; ! ! ! ! if (scale0 == 1.0F && scale1 == 1.0F ! && scale2 == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; *************** *** 555,563 **** for (i = 0; i < size; i++) { bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) ! * scale[0]; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) ! * scale[1]; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) ! * scale[2]; } } --- 571,579 ---- for (i = 0; i < size; i++) { bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) ! * scale0; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) ! * scale1; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) ! * scale2; } } *************** *** 631,636 **** } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; ! dest.put(destp++, (a << 24) | (b << 16) | (g << 8) ! | (r << 0)); } } --- 647,651 ---- } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; ! dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r); } } *************** *** 697,703 **** // try faking colored lighting a = 255 - ((r + g + b) / 3); ! r *= a / 255.0f; ! g *= a / 255.0f; ! b *= a / 255.0f; break; case 'A': --- 712,719 ---- // try faking colored lighting a = 255 - ((r + g + b) / 3); ! float af = a / 255.0f; ! r *= af; ! g *= af; ! b *= af; break; case 'A': *************** *** 708,713 **** } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; ! dest.put(destp++, (a << 24) | (b << 16) | (g << 8) ! | (r << 0)); } } --- 724,728 ---- } //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; ! dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r); } } |