]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
speed up decal creation in newdecalsystem by using BIH for finding the affected triangles
[xonotic/darkplaces.git] / model_brush.c
index 2f7caae247973d4d86ed8c5910996d4a7ccc3299..1cadbecb2e56445214a7ebcf2cd3f7172fd244b4 100644 (file)
@@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 //cvar_t r_subdivide_size = {CVAR_SAVE, "r_subdivide_size", "128", "how large water polygons should be (smaller values produce more polygons which give better warping effects)"};
 cvar_t r_novis = {0, "r_novis", "0", "draws whole level, see also sv_cullentities_pvs 0"};
-cvar_t r_picmipworld = {CVAR_SAVE, "r_picmipworld", "1", "whether gl_picmip shall apply to world textures too"};
 cvar_t r_nosurftextures = {0, "r_nosurftextures", "0", "pretends there was no texture lump found in the q1bsp/hlbsp loading (useful for debugging this rare case)"};
 cvar_t r_subdivisions_tolerance = {0, "r_subdivisions_tolerance", "4", "maximum error tolerance on curve subdivision for rendering purposes (in other words, the curves will be given as many polygons as necessary to represent curves at this quality)"};
 cvar_t r_subdivisions_mintess = {0, "r_subdivisions_mintess", "0", "minimum number of subdivisions (values above 0 will smooth curves that don't need it)"};
@@ -46,6 +45,8 @@ cvar_t mod_q3bsp_debugtracebrush = {0, "mod_q3bsp_debugtracebrush", "0", "select
 cvar_t mod_q3bsp_lightmapmergepower = {CVAR_SAVE, "mod_q3bsp_lightmapmergepower", "4", "merges the quake3 128x128 lightmap textures into larger lightmap group textures to speed up rendering, 1 = 256x256, 2 = 512x512, 3 = 1024x1024, 4 = 2048x2048, 5 = 4096x4096, ..."};
 cvar_t mod_q3bsp_nolightmaps = {CVAR_SAVE, "mod_q3bsp_nolightmaps", "0", "do not load lightmaps in Q3BSP maps (to save video RAM, but be warned: it looks ugly)"};
 cvar_t mod_q3bsp_tracelineofsight_brushes = {0, "mod_q3bsp_tracelineofsight_brushes", "0", "enables culling of entities behind detail brushes, curves, etc"};
+cvar_t mod_q3shader_default_offsetmapping = {CVAR_SAVE, "mod_q3shader_default_offsetmapping", "1", "use offsetmapping by default on all surfaces"};
+
 cvar_t mod_q1bsp_polygoncollisions = {0, "mod_q1bsp_polygoncollisions", "0", "disables use of precomputed cliphulls and instead collides with polygons (uses Bounding Interval Hierarchy optimizations)"};
 cvar_t mod_collision_bih = {0, "mod_collision_bih", "1", "enables use of generated Bounding Interval Hierarchy tree instead of compiled bsp tree in collision code"};
 cvar_t mod_recalculatenodeboxes = {0, "mod_recalculatenodeboxes", "1", "enables use of generated node bounding boxes based on BSP tree portal reconstruction, rather than the node boxes supplied by the map compiler"};
@@ -60,7 +61,6 @@ void Mod_BrushInit(void)
 {
 //     Cvar_RegisterVariable(&r_subdivide_size);
        Cvar_RegisterVariable(&r_novis);
-       Cvar_RegisterVariable(&r_picmipworld);
        Cvar_RegisterVariable(&r_nosurftextures);
        Cvar_RegisterVariable(&r_subdivisions_tolerance);
        Cvar_RegisterVariable(&r_subdivisions_mintess);
@@ -78,6 +78,7 @@ void Mod_BrushInit(void)
        Cvar_RegisterVariable(&mod_q3bsp_lightmapmergepower);
        Cvar_RegisterVariable(&mod_q3bsp_nolightmaps);
        Cvar_RegisterVariable(&mod_q3bsp_tracelineofsight_brushes);
+       Cvar_RegisterVariable(&mod_q3shader_default_offsetmapping);
        Cvar_RegisterVariable(&mod_q1bsp_polygoncollisions);
        Cvar_RegisterVariable(&mod_collision_bih);
        Cvar_RegisterVariable(&mod_recalculatenodeboxes);
@@ -1465,6 +1466,8 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                tx->reflectfactor = 1;
                Vector4Set(tx->reflectcolor4f, 1, 1, 1, 1);
                tx->r_water_wateralpha = 1;
+               tx->offsetmapping = OFFSETMAPPING_OFF;
+               tx->offsetscale = 1;
                tx->specularscalemod = 1;
                tx->specularpowermod = 1;
        }
@@ -1573,7 +1576,9 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                        // LordHavoc: HL sky textures are entirely different than quake
                        if (!loadmodel->brush.ishlbsp && !strncmp(tx->name, "sky", 3) && mtwidth == mtheight * 2)
                        {
-                               data = loadimagepixelsbgra(tx->name, false, false, r_texture_convertsRGB_skin.integer);
+                               data = loadimagepixelsbgra(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s/%s", mapname, tx->name), false, false, r_texture_convertsRGB_skin.integer, NULL);
+                               if (!data)
+                                       data = loadimagepixelsbgra(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s", tx->name), false, false, r_texture_convertsRGB_skin.integer, NULL);
                                if (data && image_width == image_height * 2)
                                {
                                        R_Q1BSP_LoadSplitSky(data, image_width, image_height, 4);
@@ -1584,9 +1589,9 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                        }
                        else
                        {
-                               skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s/%s", mapname, tx->name), TEXF_ALPHA | TEXF_MIPMAP | (r_picmipworld.integer ? TEXF_PICMIP : 0) | TEXF_COMPRESS, false);
+                               skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s/%s", mapname, tx->name), TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS, false);
                                if (!skinframe)
-                                       skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s", tx->name), TEXF_ALPHA | TEXF_MIPMAP | (r_picmipworld.integer ? TEXF_PICMIP : 0) | TEXF_COMPRESS, false);
+                                       skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va("textures/%s", tx->name), TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS, false);
                                if (!skinframe)
                                {
                                        // did not find external texture, load it from the bsp or wad3
@@ -1603,13 +1608,13 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                                                {
                                                        tx->width = image_width;
                                                        tx->height = image_height;
-                                                       skinframe = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_ALPHA | TEXF_MIPMAP | (r_picmipworld.integer ? TEXF_PICMIP : 0), pixels, image_width, image_height);
+                                                       skinframe = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, pixels, image_width, image_height);
                                                }
                                                if (freepixels)
                                                        Mem_Free(freepixels);
                                        }
                                        else if (mtdata) // texture included
-                                               skinframe = R_SkinFrame_LoadInternalQuake(tx->name, TEXF_MIPMAP | (r_picmipworld.integer ? TEXF_PICMIP : 0), false, r_fullbrights.integer, mtdata, tx->width, tx->height);
+                                               skinframe = R_SkinFrame_LoadInternalQuake(tx->name, TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, false, r_fullbrights.integer, mtdata, tx->width, tx->height);
                                }
                                // if skinframe is still NULL the "missing" texture will be used
                                if (skinframe)
@@ -2451,9 +2456,9 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                                loadmodel->brushq3.num_mergedlightmaps = lightmapnumber + 1;
                                loadmodel->brushq3.data_lightmaps = Mem_Realloc(loadmodel->mempool, loadmodel->brushq3.data_lightmaps, loadmodel->brushq3.num_mergedlightmaps * sizeof(loadmodel->brushq3.data_lightmaps[0]));
                                loadmodel->brushq3.data_deluxemaps = Mem_Realloc(loadmodel->mempool, loadmodel->brushq3.data_deluxemaps, loadmodel->brushq3.num_mergedlightmaps * sizeof(loadmodel->brushq3.data_deluxemaps[0]));
-                               loadmodel->brushq3.data_lightmaps[lightmapnumber] = lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_ALLOWUPDATES, NULL);
+                               loadmodel->brushq3.data_lightmaps[lightmapnumber] = lightmaptexture = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_ALLOWUPDATES, -1, NULL);
                                if (loadmodel->brushq1.nmaplightdata)
-                                       loadmodel->brushq3.data_deluxemaps[lightmapnumber] = deluxemaptexture = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_ALLOWUPDATES, NULL);
+                                       loadmodel->brushq3.data_deluxemaps[lightmapnumber] = deluxemaptexture = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%i", lightmapnumber), lightmapsize, lightmapsize, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_ALLOWUPDATES, -1, NULL);
                                lightmapnumber++;
                                Mod_AllocLightmap_Reset(&allocState);
                                Mod_AllocLightmap_Block(&allocState, ssize, tsize, &lightmapx, &lightmapy);
@@ -3681,7 +3686,7 @@ void Mod_Q1BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
                                mod->DrawSky = R_Q1BSP_DrawSky;
 
                        for (j = 0, surface = &mod->data_surfaces[mod->firstmodelsurface];j < mod->nummodelsurfaces;j++, surface++)
-                               if (surface->texture->basematerialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION))
+                               if (surface->texture->basematerialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION | MATERIALFLAG_CAMERA))
                                        break;
                        if (j < mod->nummodelsurfaces)
                                mod->DrawAddWaterPlanes = R_Q1BSP_DrawAddWaterPlanes;
@@ -3733,11 +3738,13 @@ void Mod_Q1BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
 
                if (mod_q1bsp_polygoncollisions.integer)
                {
-                       Mod_MakeCollisionBIH(mod, true);
+                       Mod_MakeCollisionBIH(mod, true, &mod->collision_bih);
                        // point traces and contents checks still use the bsp tree
                        mod->TraceLine = Mod_CollisionBIH_TraceLine;
                        mod->TraceBox = Mod_CollisionBIH_TraceBox;
                }
+               else
+                       Mod_MakeCollisionBIH(mod, true, &mod->render_bih);
 
                // generate VBOs and other shared data before cloning submodels
                if (i == 0)
@@ -4276,13 +4283,10 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l)
                strlcpy (out[i].name, in[i].name, sizeof (out[i].name));
                out[i].surfaceflags = LittleLong(in[i].surfaceflags);
                out[i].supercontents = Mod_Q3BSP_SuperContentsFromNativeContents(loadmodel, LittleLong(in[i].contents));
-               if (cls.state != ca_dedicated)
-               {
-                       Mod_LoadTextureFromQ3Shader(out + i, out[i].name, true, true, TEXF_MIPMAP | (r_picmipworld.integer ? TEXF_PICMIP : 0) | TEXF_COMPRESS);
-                       // restore the surfaceflags and supercontents
-                       out[i].surfaceflags = LittleLong(in[i].surfaceflags);
-                       out[i].supercontents = Mod_Q3BSP_SuperContentsFromNativeContents(loadmodel, LittleLong(in[i].contents));
-               }
+               Mod_LoadTextureFromQ3Shader(out + i, out[i].name, true, true, TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS);
+               // restore the surfaceflags and supercontents
+               out[i].surfaceflags = LittleLong(in[i].surfaceflags);
+               out[i].supercontents = Mod_Q3BSP_SuperContentsFromNativeContents(loadmodel, LittleLong(in[i].contents));
        }
 }
 
@@ -4571,7 +4575,7 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump)
                if (developer_loading.integer)
                        Con_Printf("Using external lightmaps\n");
                FS_StripExtension(loadmodel->name, mapname, sizeof(mapname));
-               inpixels[0] = loadimagepixelsbgra(va("%s/lm_%04d", mapname, 0), false, false, false);
+               inpixels[0] = loadimagepixelsbgra(va("%s/lm_%04d", mapname, 0), false, false, false, NULL);
                if(!inpixels[0])
                        return;
 
@@ -4591,7 +4595,7 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump)
 
                for(count = 1; ; ++count)
                {
-                       inpixels[count] = loadimagepixelsbgra(va("%s/lm_%04d", mapname, count), false, false, false);
+                       inpixels[count] = loadimagepixelsbgra(va("%s/lm_%04d", mapname, count), false, false, false, NULL);
                        if(!inpixels[count])
                                break; // we got all of them
                        if(image_width != size || image_height != size)
@@ -4725,9 +4729,9 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump)
                                        ;
                                if (developer_loading.integer)
                                        Con_Printf("lightmap merge texture #%i is %ix%i (%i of %i used)\n", lightmapindex, mergewidth*size, mergeheight*size, min(j, mergewidth*mergeheight), mergewidth*mergeheight);
-                               loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), mergewidth * size, mergeheight * size, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : TEXF_ALLOWUPDATES), NULL);
+                               loadmodel->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), mergewidth * size, mergeheight * size, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : TEXF_ALLOWUPDATES), -1, NULL);
                                if (loadmodel->brushq3.data_deluxemaps)
-                                       loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), mergewidth * size, mergeheight * size, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : TEXF_ALLOWUPDATES), NULL);
+                                       loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), mergewidth * size, mergeheight * size, NULL, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : TEXF_ALLOWUPDATES), -1, NULL);
                        }
                        mergewidth = R_TextureWidth(loadmodel->brushq3.data_lightmaps[lightmapindex]) / size;
                        mergeheight = R_TextureHeight(loadmodel->brushq3.data_lightmaps[lightmapindex]) / size;
@@ -4741,9 +4745,9 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump)
                {
                        // figure out which merged lightmap texture this fits into
                        if (loadmodel->brushq3.deluxemapping && (i & 1))
-                               loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), size, size, convertedpixels, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : 0), NULL);
+                               loadmodel->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("deluxemap%04i", lightmapindex), size, size, convertedpixels, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bspdeluxemaps.integer ? TEXF_COMPRESS : 0), -1, NULL);
                        else
-                               loadmodel->brushq3.data_lightmaps [lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), size, size, convertedpixels, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : 0), NULL);
+                               loadmodel->brushq3.data_lightmaps [lightmapindex] = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", lightmapindex), size, size, convertedpixels, TEXTYPE_BGRA, TEXF_FORCELINEAR | (gl_texturecompression_q3bsplightmaps.integer ? TEXF_COMPRESS : 0), -1, NULL);
                }
        }
 
@@ -5122,7 +5126,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        finalwidth = Q3PatchDimForTess(patchsize[0],xtess); //((patchsize[0] - 1) * xtess) + 1;
                        finalheight = Q3PatchDimForTess(patchsize[1],ytess); //((patchsize[1] - 1) * ytess) + 1;
                        finalvertices = finalwidth * finalheight;
-                       finaltriangles = (finalwidth - 1) * (finalheight - 1) * 2;
+                       oldnumtriangles = finaltriangles = (finalwidth - 1) * (finalheight - 1) * 2;
                        type = Q3FACETYPE_MESH;
                        // generate geometry
                        // (note: normals are skipped because they get recalculated)
@@ -5147,7 +5151,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        finalwidth = Q3PatchDimForTess(patchsize[0],cxtess); //((patchsize[0] - 1) * cxtess) + 1;
                        finalheight = Q3PatchDimForTess(patchsize[1],cytess); //((patchsize[1] - 1) * cytess) + 1;
                        finalvertices = finalwidth * finalheight;
-                       finaltriangles = (finalwidth - 1) * (finalheight - 1) * 2;
+                       oldnumtriangles2 = finaltriangles = (finalwidth - 1) * (finalheight - 1) * 2;
 
                        // legacy collision geometry implementation
                        out->deprecatedq3data_collisionvertex3f = (float *)Mem_Alloc(loadmodel->mempool, sizeof(float[3]) * finalvertices);
@@ -5158,11 +5162,9 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        Q3PatchTriangleElements(out->deprecatedq3data_collisionelement3i, finalwidth, finalheight, 0);
 
                        //Mod_SnapVertices(3, out->num_vertices, (loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex), 0.25);
-                       Mod_SnapVertices(3, out->num_collisionvertices, out->deprecatedq3data_collisionvertex3f, 1);
+                       Mod_SnapVertices(3, finalvertices, out->deprecatedq3data_collisionvertex3f, 1);
 
-                       oldnumtriangles = out->num_triangles;
-                       oldnumtriangles2 = out->num_collisiontriangles;
-                       out->num_collisiontriangles = Mod_RemoveDegenerateTriangles(out->num_collisiontriangles, out->deprecatedq3data_collisionelement3i, out->deprecatedq3data_collisionelement3i, out->deprecatedq3data_collisionvertex3f);
+                       out->num_collisiontriangles = Mod_RemoveDegenerateTriangles(finaltriangles, out->deprecatedq3data_collisionelement3i, out->deprecatedq3data_collisionelement3i, out->deprecatedq3data_collisionvertex3f);
 
                        // now optimize the collision mesh by finding triangle bboxes...
                        Mod_Q3BSP_BuildBBoxes(out->deprecatedq3data_collisionelement3i, out->num_collisiontriangles, out->deprecatedq3data_collisionvertex3f, &out->deprecatedq3data_collisionbbox6f, &out->deprecatedq3num_collisionbboxstride, mod_q3bsp_curves_collisions_stride.integer);
@@ -5174,9 +5176,19 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        Q3PatchTesselateFloat(3, sizeof(float[3]), surfacecollisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, cxtess, cytess);
                        Q3PatchTriangleElements(surfacecollisionelement3i, finalwidth, finalheight, collisionvertices);
                        Mod_SnapVertices(3, finalvertices, surfacecollisionvertex3f, 1);
-                       oldnumtriangles = out->num_triangles;
-                       oldnumtriangles2 = out->num_collisiontriangles;
-                       out->num_collisiontriangles = Mod_RemoveDegenerateTriangles(out->num_collisiontriangles, surfacecollisionelement3i, surfacecollisionelement3i, loadmodel->brush.data_collisionvertex3f);
+#if 1
+                       // remove this once the legacy code is removed
+                       {
+                               int nc = out->num_collisiontriangles;
+#endif
+                       out->num_collisiontriangles = Mod_RemoveDegenerateTriangles(finaltriangles, surfacecollisionelement3i, surfacecollisionelement3i, loadmodel->brush.data_collisionvertex3f);
+#if 1
+                               if(nc != out->num_collisiontriangles)
+                               {
+                                       Con_Printf("number of collision triangles differs between BIH and BSP. FAIL.\n");
+                               }
+                       }
+#endif
 
                        if (developer_extra.integer)
                                Con_DPrintf("Mod_Q3BSP_LoadFaces: %ix%i curve became %i:%i vertices / %i:%i triangles (%i:%i degenerate)\n", patchsize[0], patchsize[1], out->num_vertices, out->num_collisionvertices, oldnumtriangles, oldnumtriangles2, oldnumtriangles - out->num_triangles, oldnumtriangles2 - out->num_collisiontriangles);
@@ -5739,7 +5751,8 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
        const int *e;
        const texture_t *texture;
        int axis;
-#if 0
+#define BIHLINECLIP
+#ifdef BIHLINECLIP
        int sideflags;
        vec_t frontdist1;
        vec_t frontdist2;
@@ -5747,7 +5760,7 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
        vec_t backdist1;
        vec_t backdist2;
        vec_t backfrac;
-       vec3_t clipped[2];
+       vec3_t clipped, newstart, newend;
 #endif
        vec3_t segmentmins;
        vec3_t segmentmaxs;
@@ -5765,7 +5778,7 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
                        return;
 #endif
                axis = node->type - BIH_SPLITX;
-#if 1
+#if 0
                if (segmentmins[axis] <= node->backmax)
                {
                        if (segmentmaxs[axis] >= node->frontmin)
@@ -5777,10 +5790,10 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
                else
                        return; // trace falls between children
 #else
-               frontdist1 = start[axis] - node->backmax;
-               frontdist2 = end[axis] - node->backmax;
-               backdist1 = start[axis] - node->frontmin;
-               backdist2 = end[axis] - node->frontmin;
+               frontdist1 = start[axis] - node->frontmin;
+               frontdist2 = end[axis] - node->frontmin;
+               backdist1 = start[axis] - node->backmax;
+               backdist2 = end[axis] - node->backmax;
                sideflags = 0;
                if (frontdist1 < 0)
                        sideflags |= 1;
@@ -5790,6 +5803,18 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
                        sideflags |= 4;
                if (backdist2 < 0)
                        sideflags |= 8;
+#if 0
+               if (sideflags & 12)
+               {
+                       if ((sideflags & 3) != 3)
+                               Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+                       nodenum = node->back;
+               }
+               else if ((sideflags & 3) != 3)
+                       nodenum = node->front;
+               else
+                       return; // trace falls between children
+#else
                switch(sideflags)
                {
                case 0:
@@ -5798,28 +5823,30 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
                        continue;
                case 1:
                        // START end START END
+#ifdef BIHLINECLIP
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[0]);
-                       start = clipped[0];
+                       VectorLerp(start, frontfrac, end, newstart); start = newstart;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#endif
                        nodenum = node->front;
                        break;
                case 2:
+#ifdef BIHLINECLIP
                        // start END START END
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[0]);
-                       end = clipped[0];
+                       VectorLerp(start, frontfrac, end, newend); end = newend;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#endif
                        nodenum = node->front;
                        break;
                case 3:
@@ -5828,119 +5855,135 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
                case 4:
                        // start end start END
                        Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#ifdef BIHLINECLIP
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       end = clipped[0];
+                       VectorLerp(start, backfrac, end, newend); end = newend;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#endif
                        nodenum = node->back;
                        break;
                case 5:
                        // START end start END
+#ifdef BIHLINECLIP
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[1]);
-                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, clipped[1], end, linestart, lineend);
+                       VectorLerp(start, frontfrac, end, clipped);
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, clipped, end, linestart, lineend);
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       end = clipped[0];
+                       VectorLerp(start, backfrac, end, newend); end = newend;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#else
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#endif
                        nodenum = node->back;
                        break;
                case 6:
                        // start END start END
+#ifdef BIHLINECLIP
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[1]);
-                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, clipped[1], linestart, lineend);
+                       VectorLerp(start, frontfrac, end, clipped);
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, clipped, linestart, lineend);
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       end = clipped[0];
+                       VectorLerp(start, backfrac, end, newend); end = newend;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#else
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#endif
                        nodenum = node->back;
                        break;
                case 7:
                        // START END start END
+#ifdef BIHLINECLIP
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       end = clipped[0];
+                       VectorLerp(start, backfrac, end, newend); end = newend;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#endif
                        nodenum = node->back;
                        break;
                case 8:
                        // start end START end
                        Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#ifdef BIHLINECLIP
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       start = clipped[0];
+                       VectorLerp(start, backfrac, end, newstart); start = newstart;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#endif
                        nodenum = node->back;
                        break;
                case 9:
                        // START end START end
+#ifdef BIHLINECLIP
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[1]);
-                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, clipped[1], end, linestart, lineend);
+                       VectorLerp(start, frontfrac, end, clipped);
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, clipped, end, linestart, lineend);
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       start = clipped[0];
+                       VectorLerp(start, backfrac, end, newstart); start = newstart;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#else
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#endif
                        nodenum = node->back;
                        break;
                case 10:
                        // start END START end
+#ifdef BIHLINECLIP
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[1]);
-                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, clipped[1], linestart, lineend);
+                       VectorLerp(start, frontfrac, end, clipped);
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, clipped, linestart, lineend);
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       start = clipped[0];
+                       VectorLerp(start, backfrac, end, newstart); start = newstart;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#else
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#endif
                        nodenum = node->back;
                        break;
                case 11:
                        // START END START end
+#ifdef BIHLINECLIP
                        backfrac = backdist1 / (backdist1 - backdist2);
-                       VectorLerp(start, backfrac, end, clipped[0]);
-                       start = clipped[0];
+                       VectorLerp(start, backfrac, end, newstart); start = newstart;
                        segmentmins[0] = min(start[0], end[0]);
                        segmentmins[1] = min(start[1], end[1]);
                        segmentmins[2] = min(start[2], end[2]);
                        segmentmaxs[0] = max(start[0], end[0]);
                        segmentmaxs[1] = max(start[1], end[1]);
                        segmentmaxs[2] = max(start[2], end[2]);
+#endif
                        nodenum = node->back;
                        break;
                case 12:
@@ -5950,16 +5993,24 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
                        break;
                case 13:
                        // START end start end
+#ifdef BIHLINECLIP
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[1]);
-                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, clipped[1], end, linestart, lineend);
+                       VectorLerp(start, frontfrac, end, clipped);
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, clipped, end, linestart, lineend);
+#else
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#endif
                        nodenum = node->back;
                        break;
                case 14:
                        // start END start end
+#ifdef BIHLINECLIP
                        frontfrac = frontdist1 / (frontdist1 - frontdist2);
-                       VectorLerp(start, frontfrac, end, clipped[1]);
-                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, clipped[1], linestart, lineend);
+                       VectorLerp(start, frontfrac, end, clipped);
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, clipped, linestart, lineend);
+#else
+                       Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace, model, node->front, start, end, linestart, lineend);
+#endif
                        nodenum = node->back;
                        break;
                case 15:
@@ -5967,6 +6018,7 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model
                        nodenum = node->back;
                        continue;
                }
+#endif
 #endif
        }
        if (!model->collision_bih.leafs)
@@ -6009,11 +6061,11 @@ static void Mod_CollisionBIH_TraceBrush_RecursiveBIHNode(trace_t *trace, dp_mode
        {
                node = model->collision_bih.nodes + nodenum;
                axis = node->type - BIH_SPLITX;
-#if 0
-#if 0
+#if 1
                if (!BoxesOverlap(segmentmins, segmentmaxs, node->mins, node->maxs))
                        return;
 #endif
+#if 0
                Mod_CollisionBIH_TraceBrush_RecursiveBIHNode(trace, model, node->front, thisbrush_start, thisbrush_end, segmentmins, segmentmaxs);
                nodenum = node->back;
                continue;
@@ -6539,7 +6591,7 @@ static int Mod_Q3BSP_PointSuperContents(struct model_s *model, int frame, const
        return supercontents;
 }
 
-void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces)
+bih_t *Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces, bih_t *out)
 {
        int j;
        int bihnumleafs;
@@ -6574,40 +6626,47 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces)
                        if (brush->colbrushf)
                                bihnumleafs++;
                for (j = 0, surface = model->data_surfaces + model->firstmodelsurface;j < nummodelsurfaces;j++, surface++)
-                       bihnumleafs += surface->num_collisiontriangles;
+               {
+                       if (surface->texture->basematerialflags & MATERIALFLAG_MESHCOLLISIONS)
+                               bihnumleafs += surface->num_triangles + surface->num_collisiontriangles;
+                       else
+                               bihnumleafs += surface->num_collisiontriangles;
+               }
        }
 
        if (!bihnumleafs)
-               return;
+               return NULL;
 
        // allocate the memory for the BIH leaf nodes
        bihleafs = Mem_Alloc(loadmodel->mempool, sizeof(bih_leaf_t) * bihnumleafs);
 
        // now populate the BIH leaf nodes
        bihleafindex = 0;
-       if (userendersurfaces)
+
+       // add render surfaces
+       renderelement3i = model->surfmesh.data_element3i;
+       rendervertex3f = model->surfmesh.data_vertex3f;
+       for (j = 0, surface = model->data_surfaces + model->firstmodelsurface;j < nummodelsurfaces;j++, surface++)
        {
-               // add render surfaces
-               renderelement3i = model->surfmesh.data_element3i;
-               rendervertex3f = model->surfmesh.data_vertex3f;
-               for (j = 0, surface = model->data_surfaces + model->firstmodelsurface;j < nummodelsurfaces;j++, surface++)
+               for (triangleindex = 0, e = renderelement3i + 3*surface->num_firsttriangle;triangleindex < surface->num_triangles;triangleindex++, e += 3)
                {
-                       for (triangleindex = 0, e = renderelement3i + 3*surface->num_firsttriangle;triangleindex < surface->num_triangles;triangleindex++, e += 3)
-                       {
-                               bihleafs[bihleafindex].type = BIH_RENDERTRIANGLE;
-                               bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures;
-                               bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firsttriangle;
-                               bihleafs[bihleafindex].mins[0] = min(rendervertex3f[3*e[0]+0], min(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) - 1;
-                               bihleafs[bihleafindex].mins[1] = min(rendervertex3f[3*e[0]+1], min(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) - 1;
-                               bihleafs[bihleafindex].mins[2] = min(rendervertex3f[3*e[0]+2], min(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) - 1;
-                               bihleafs[bihleafindex].maxs[0] = max(rendervertex3f[3*e[0]+0], max(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) + 1;
-                               bihleafs[bihleafindex].maxs[1] = max(rendervertex3f[3*e[0]+1], max(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) + 1;
-                               bihleafs[bihleafindex].maxs[2] = max(rendervertex3f[3*e[0]+2], max(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) + 1;
-                               bihleafindex++;
-                       }
+                       if (!userendersurfaces && !(surface->texture->basematerialflags & MATERIALFLAG_MESHCOLLISIONS))
+                               continue;
+                       bihleafs[bihleafindex].type = BIH_RENDERTRIANGLE;
+                       bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures;
+                       bihleafs[bihleafindex].surfaceindex = surface - model->data_surfaces;
+                       bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firsttriangle;
+                       bihleafs[bihleafindex].mins[0] = min(rendervertex3f[3*e[0]+0], min(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) - 1;
+                       bihleafs[bihleafindex].mins[1] = min(rendervertex3f[3*e[0]+1], min(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) - 1;
+                       bihleafs[bihleafindex].mins[2] = min(rendervertex3f[3*e[0]+2], min(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) - 1;
+                       bihleafs[bihleafindex].maxs[0] = max(rendervertex3f[3*e[0]+0], max(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) + 1;
+                       bihleafs[bihleafindex].maxs[1] = max(rendervertex3f[3*e[0]+1], max(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) + 1;
+                       bihleafs[bihleafindex].maxs[2] = max(rendervertex3f[3*e[0]+2], max(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) + 1;
+                       bihleafindex++;
                }
        }
-       else
+
+       if (!userendersurfaces)
        {
                // add collision brushes
                for (brushindex = 0, brush = model->brush.data_brushes + brushindex+model->firstmodelbrush;brushindex < nummodelbrushes;brushindex++, brush++)
@@ -6616,6 +6675,7 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces)
                                continue;
                        bihleafs[bihleafindex].type = BIH_BRUSH;
                        bihleafs[bihleafindex].textureindex = brush->texture - model->data_textures;
+                       bihleafs[bihleafindex].surfaceindex = -1;
                        bihleafs[bihleafindex].itemindex = brushindex+model->firstmodelbrush;
                        VectorCopy(brush->colbrushf->mins, bihleafs[bihleafindex].mins);
                        VectorCopy(brush->colbrushf->maxs, bihleafs[bihleafindex].maxs);
@@ -6631,6 +6691,7 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces)
                        {
                                bihleafs[bihleafindex].type = BIH_COLLISIONTRIANGLE;
                                bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures;
+                               bihleafs[bihleafindex].surfaceindex = surface - model->data_surfaces;
                                bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firstcollisiontriangle;
                                bihleafs[bihleafindex].mins[0] = min(collisionvertex3f[3*e[0]+0], min(collisionvertex3f[3*e[1]+0], collisionvertex3f[3*e[2]+0])) - 1;
                                bihleafs[bihleafindex].mins[1] = min(collisionvertex3f[3*e[0]+1], min(collisionvertex3f[3*e[1]+1], collisionvertex3f[3*e[2]+1])) - 1;
@@ -6650,17 +6711,19 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces)
        temp_leafsortscratch = temp_leafsort + bihnumleafs;
 
        // now build it
-       BIH_Build(&model->collision_bih, bihnumleafs, bihleafs, bihmaxnodes, bihnodes, temp_leafsort, temp_leafsortscratch);
+       BIH_Build(out, bihnumleafs, bihleafs, bihmaxnodes, bihnodes, temp_leafsort, temp_leafsortscratch);
 
        // we're done with the temporary data
        Mem_Free(temp_leafsort);
 
        // resize the BIH nodes array if it over-allocated
-       if (model->collision_bih.maxnodes > model->collision_bih.numnodes)
+       if (out->maxnodes > out->numnodes)
        {
-               model->collision_bih.maxnodes = model->collision_bih.numnodes;
-               model->collision_bih.nodes = Mem_Realloc(loadmodel->mempool, model->collision_bih.nodes, model->collision_bih.numnodes * sizeof(bih_node_t));
+               out->maxnodes = out->numnodes;
+               out->nodes = Mem_Realloc(loadmodel->mempool, out->nodes, out->numnodes * sizeof(bih_node_t));
        }
+
+       return out;
 }
 
 static int Mod_Q3BSP_SuperContentsFromNativeContents(dp_model_t *model, int nativecontents)
@@ -6971,12 +7034,13 @@ void Mod_Q3BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
                        mod->DrawSky = R_Q1BSP_DrawSky;
 
                for (j = 0;j < mod->nummodelsurfaces;j++)
-                       if (mod->data_surfaces[j + mod->firstmodelsurface].texture->basematerialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION))
+                       if (mod->data_surfaces[j + mod->firstmodelsurface].texture->basematerialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION | MATERIALFLAG_CAMERA))
                                break;
                if (j < mod->nummodelsurfaces)
                        mod->DrawAddWaterPlanes = R_Q1BSP_DrawAddWaterPlanes;
 
-               Mod_MakeCollisionBIH(mod, false);
+               Mod_MakeCollisionBIH(mod, false, &mod->collision_bih);
+               Mod_MakeCollisionBIH(mod, true, &mod->render_bih);
 
                // generate VBOs and other shared data before cloning submodels
                if (i == 0)
@@ -7413,7 +7477,8 @@ void Mod_OBJ_Load(dp_model_t *mod, void *buffer, void *bufferend)
        Mod_BuildTextureVectorsFromNormals(0, loadmodel->surfmesh.num_vertices, loadmodel->surfmesh.num_triangles, loadmodel->surfmesh.data_vertex3f, loadmodel->surfmesh.data_texcoordtexture2f, loadmodel->surfmesh.data_normal3f, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.data_svector3f, loadmodel->surfmesh.data_tvector3f, true);
        Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
 
-       Mod_MakeCollisionBIH(loadmodel, true);
+       Mod_MakeCollisionBIH(loadmodel, true, &mod->collision_bih);
+       mod->render_bih = mod->collision_bih;
 }
 
 
@@ -8105,7 +8170,7 @@ void Mod_OBJ_Load(dp_model_t *mod, void *buffer, void *bufferend)
        loadmodel->num_textures = numtextures;
        loadmodel->data_textures = Mem_Alloc(loadmodel->mempool, loadmodel->num_textures * sizeof(texture_t));
        for (i = 0;i < numtextures;i++)
-               Mod_LoadTextureFromQ3Shader(loadmodel->data_textures + i, texturenames[i], true, true, TEXF_MIPMAP | TEXF_ALPHA | (r_picmipworld.integer ? TEXF_PICMIP : 0) | TEXF_COMPRESS);
+               Mod_LoadTextureFromQ3Shader(loadmodel->data_textures + i, texturenames[i], true, true, TEXF_MIPMAP | TEXF_ALPHA | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS);
 
        // free the texturenames array since we are now done with it
        for (i = 0;i < numtextures;i++)