⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 light.java

📁 JAKE2用JAVA写的queck2的3D游戏开发引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /*     * =============== R_AddDynamicLights ===============     */    void R_AddDynamicLights(msurface_t surf) {        int lnum;        int sd, td;        float fdist, frad, fminlight;        float[] impact = { 0, 0, 0 };        float[] local = { 0, 0, 0 };        int s, t;        int i;        int smax, tmax;        mtexinfo_t tex;        dlight_t dl;        float[] pfBL;        float fsacc, ftacc;        smax = (surf.extents[0] >> 4) + 1;        tmax = (surf.extents[1] >> 4) + 1;        tex = surf.texinfo;        for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) {            if ((surf.dlightbits & (1 << lnum)) == 0)                continue; // not lit by this light            dl = r_newrefdef.dlights[lnum];            frad = dl.intensity;            fdist = Math3D.DotProduct(dl.origin, surf.plane.normal)                    - surf.plane.dist;            frad -= Math.abs(fdist);            // rad is now the highest intensity on the plane            fminlight = DLIGHT_CUTOFF; // FIXME: make configurable?            if (frad < fminlight)                continue;            fminlight = frad - fminlight;            for (i = 0; i < 3; i++) {                impact[i] = dl.origin[i] - surf.plane.normal[i] * fdist;            }            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];            pfBL = s_blocklights;            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)                        sd = -sd;                    if (sd > td)                        fdist = sd + (td >> 1);                    else                        fdist = td + (sd >> 1);                    if (fdist < fminlight) {                        pfBL[pfBLindex + 0] += (frad - fdist) * dl.color[0];                        pfBL[pfBLindex + 1] += (frad - fdist) * dl.color[1];                        pfBL[pfBLindex + 2] += (frad - fdist) * dl.color[2];                    }                }            }        }    }    /*     * * R_SetCacheState     */    void R_SetCacheState(msurface_t surf) {        int maps;        for (maps = 0; maps < Defines.MAXLIGHTMAPS                && surf.styles[maps] != (byte) 255; maps++) {            surf.cached_light[maps] = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].white;        }    }    /*     * =============== R_BuildLightMap     *      * Combine and scale multiple lightmaps into the floating format in     * blocklights ===============     */    void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride) {        int smax, tmax;        int r, g, b, a, max;        int i, j, size;        ByteBuffer lightmap;        float[] scale = { 0, 0, 0, 0 };        int nummaps;        float[] bl;        lightstyle_t style;        int monolightmap;        if ((surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33                | Defines.SURF_TRANS66 | Defines.SURF_WARP)) != 0)            Com.Error(Defines.ERR_DROP,                    "R_BuildLightMap called for non-lit surface");        smax = (surf.extents[0] >> 4) + 1;        tmax = (surf.extents[1] >> 4) + 1;        size = smax * tmax;        if (size > ((s_blocklights.length * Defines.SIZE_OF_FLOAT) >> 4))            Com.Error(Defines.ERR_DROP, "Bad s_blocklights size");        try {            // set to full bright if no light data            if (surf.samples == null) {                int maps;                for (i = 0; i < size * 3; i++)                    s_blocklights[i] = 255;                for (maps = 0; maps < Defines.MAXLIGHTMAPS                        && surf.styles[maps] != (byte) 255; maps++) {                    style = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF];                }                // goto store;                throw new longjmpException();            }            // count the # of maps            for (nummaps = 0; nummaps < Defines.MAXLIGHTMAPS                    && surf.styles[nummaps] != (byte) 255; nummaps++)                ;            lightmap = surf.samples;            int lightmapIndex = 0;            // add all the lightmaps            if (nummaps == 1) {                int maps;                for (maps = 0; maps < Defines.MAXLIGHTMAPS                        && surf.styles[maps] != (byte) 255; maps++) {                    bl = s_blocklights;                    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;                            bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;                            bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;                        }                    } else {                        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];                        }                    }                    //lightmap += size*3; // skip to next lightmap                }            } else {                int maps;                //			memset( s_blocklights, 0, sizeof( s_blocklights[0] ) * size *                // 3 );                Arrays.fill(s_blocklights, 0, size * 3, 0.0f);                for (maps = 0; maps < Defines.MAXLIGHTMAPS                        && surf.styles[maps] != (byte) 255; maps++) {                    bl = s_blocklights;                    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;                            bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;                            bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;                        }                    } else {                        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];                        }                    }                    //lightmap += size*3; // skip to next lightmap                }            }            // add all the dynamic lights            if (surf.dlightframe == r_framecount)                R_AddDynamicLights(surf);            // label store:        } catch (longjmpException store) {        }        // put into texture format        stride -= smax;        bl = s_blocklights;        int blp = 0;        monolightmap = gl_monolightmap.string.charAt(0);        int destp = 0;        if (monolightmap == '0') {            for (i = 0; i < tmax; i++, destp += stride) {                dest.position(destp);                for (j = 0; j < smax; j++) {                    r = (int) bl[blp++];                    g = (int) bl[blp++];                    b = (int) bl[blp++];                    // catch negative lights                    if (r < 0)                        r = 0;                    if (g < 0)                        g = 0;                    if (b < 0)                        b = 0;                    /*                     * * determine the brightest of the three color components                     */                    if (r > g)                        max = r;                    else                        max = g;                    if (b > max)                        max = b;                    /*                     * * alpha is ONLY used for the mono lightmap case. For this                     * reason * we set it to the brightest of the color                     * components so that * things don't get too dim.                     */                    a = max;                    /*                     * * rescale all the color components if the intensity of                     * the greatest * channel exceeds 1.0                     */                    if (max > 255) {                        float t = 255.0F / max;                        r = (int) (r * t);                        g = (int) (g * t);                        b = (int) (b * t);                        a = (int) (a * t);                    }                    r &= 0xFF;                    g &= 0xFF;                    b &= 0xFF;                    a &= 0xFF;                    dest.put(destp++, (a << 24) | (b << 16) | (g << 8)                            | (r << 0));                }            }        } else {            for (i = 0; i < tmax; i++, destp += stride) {                dest.position(destp);                for (j = 0; j < smax; j++) {                    r = (int) bl[blp++];                    g = (int) bl[blp++];                    b = (int) bl[blp++];                    // catch negative lights                    if (r < 0)                        r = 0;                    if (g < 0)                        g = 0;                    if (b < 0)                        b = 0;                    /*                     * * determine the brightest of the three color components                     */                    if (r > g)                        max = r;                    else                        max = g;                    if (b > max)                        max = b;                    /*                     * * alpha is ONLY used for the mono lightmap case. For this                     * reason * we set it to the brightest of the color                     * components so that * things don't get too dim.                     */                    a = max;                    /*                     * * rescale all the color components if the intensity of                     * the greatest * channel exceeds 1.0                     */                    if (max > 255) {                        float t = 255.0F / max;                        r = (int) (r * t);                        g = (int) (g * t);                        b = (int) (b * t);                        a = (int) (a * t);                    }                    /*                     * * So if we are doing alpha lightmaps we need to set the                     * R, G, and B * components to 0 and we need to set alpha to                     * 1-alpha.                     */                    switch (monolightmap) {                    case 'L':                    case 'I':                        r = a;                        g = b = 0;                        break;                    case 'C':                        // 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':                    default:                        r = g = b = 0;                        a = 255 - a;                        break;                    }                    r &= 0xFF;                    g &= 0xFF;                    b &= 0xFF;                    a &= 0xFF;                    dest.put(destp++, (a << 24) | (b << 16) | (g << 8)                            | (r << 0));                }            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -