]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
sound mixing: PROPERLY detect silent sounds. Old code would cut off sounds at -15dB...
[xonotic/darkplaces.git] / gl_rmain.c
index 5688709d4171c99bbe375f487bb29959d0e3f43c..a7116cfee4fccd20be42f70c790441edde154a3c 100644 (file)
@@ -5325,6 +5325,7 @@ void R_View_UpdateWithScissor(const int *myscissor)
        R_View_WorldVisibility(r_refdef.view.useclipplane);
        R_View_UpdateEntityVisible();
        R_View_UpdateEntityLighting();
+       R_AnimCache_CacheVisibleEntities();
 }
 
 void R_View_Update(void)
@@ -5334,6 +5335,7 @@ void R_View_Update(void)
        R_View_WorldVisibility(r_refdef.view.useclipplane);
        R_View_UpdateEntityVisible();
        R_View_UpdateEntityLighting();
+       R_AnimCache_CacheVisibleEntities();
 }
 
 float viewscalefpsadjusted = 1.0f;
@@ -5627,26 +5629,34 @@ static void R_Water_StartFrame(void)
 void R_Water_AddWaterPlane(msurface_t *surface, int entno)
 {
        int planeindex, bestplaneindex, vertexindex;
-       vec3_t mins, maxs, normal, center;
+       vec3_t mins, maxs, normal, center, v, n;
        vec_t planescore, bestplanescore;
        mplane_t plane;
        r_waterstate_waterplane_t *p;
        texture_t *t = R_GetCurrentTexture(surface->texture);
 
+       rsurface.texture = t;
        RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_NOGAPS, 1, ((const msurface_t **)&surface));
+       // if the model has no normals, it's probably off-screen and they were not generated, so don't add it anyway
+       if (!rsurface.batchnormal3f || rsurface.batchnumvertices < 1)
+               return;
        // average the vertex normals, find the surface bounds (after deformvertexes)
-       VectorClear(normal);
-       VectorCopy(rsurface.batchvertex3f, mins);
-       VectorCopy(rsurface.batchvertex3f, maxs);
-       for (vertexindex = 0;vertexindex < rsurface.batchnumvertices;vertexindex++)
-       {
-               VectorAdd(normal, rsurface.batchnormal3f + vertexindex*3, normal);
-               mins[0] = min(mins[0], rsurface.batchvertex3f[vertexindex*3+0]);
-               mins[1] = min(mins[1], rsurface.batchvertex3f[vertexindex*3+1]);
-               mins[2] = min(mins[2], rsurface.batchvertex3f[vertexindex*3+2]);
-               maxs[0] = max(maxs[0], rsurface.batchvertex3f[vertexindex*3+0]);
-               maxs[1] = max(maxs[1], rsurface.batchvertex3f[vertexindex*3+1]);
-               maxs[2] = max(maxs[2], rsurface.batchvertex3f[vertexindex*3+2]);
+       Matrix4x4_Transform(&rsurface.matrix, rsurface.batchvertex3f, v);
+       Matrix4x4_Transform3x3(&rsurface.matrix, rsurface.batchnormal3f, n);
+       VectorCopy(n, normal);
+       VectorCopy(v, mins);
+       VectorCopy(v, maxs);
+       for (vertexindex = 1;vertexindex < rsurface.batchnumvertices;vertexindex++)
+       {
+               Matrix4x4_Transform(&rsurface.matrix, rsurface.batchvertex3f + vertexindex*3, v);
+               Matrix4x4_Transform3x3(&rsurface.matrix, rsurface.batchnormal3f + vertexindex*3, n);
+               VectorAdd(normal, n, normal);
+               mins[0] = min(mins[0], v[0]);
+               mins[1] = min(mins[1], v[1]);
+               mins[2] = min(mins[2], v[2]);
+               maxs[0] = max(maxs[0], v[0]);
+               maxs[1] = max(maxs[1], v[1]);
+               maxs[2] = max(maxs[2], v[2]);
        }
        VectorNormalize(normal);
        VectorMAM(0.5f, mins, 0.5f, maxs, center);
@@ -5658,8 +5668,8 @@ void R_Water_AddWaterPlane(msurface_t *surface, int entno)
        if (PlaneDiff(r_refdef.view.origin, &plane) < 0)
        {
                // skip backfaces (except if nocullface is set)
-               if (!(t->currentmaterialflags & MATERIALFLAG_NOCULLFACE))
-                       return;
+//             if (!(t->currentmaterialflags & MATERIALFLAG_NOCULLFACE))
+//                     return;
                VectorNegate(plane.normal, plane.normal);
                plane.dist *= -1;
                PlaneClassify(&plane);
@@ -5673,7 +5683,7 @@ void R_Water_AddWaterPlane(msurface_t *surface, int entno)
        {
                if(p->camera_entity == t->camera_entity)
                {
-                       planescore = 100.0f - 100.0f * DotProduct(plane.normal, p->plane.normal) + fabs(plane.dist - p->plane.dist) * 25.0f;
+                       planescore = 1.0f - DotProduct(plane.normal, p->plane.normal) + fabs(plane.dist - p->plane.dist) * 0.001f;
                        if (bestplaneindex < 0 || bestplanescore > planescore)
                        {
                                bestplaneindex = planeindex;
@@ -5685,12 +5695,11 @@ void R_Water_AddWaterPlane(msurface_t *surface, int entno)
        p = r_waterstate.waterplanes + planeindex;
 
        // if this surface does not fit any known plane rendered this frame, add one
-       if ((planeindex < 0 || bestplanescore > 100.0f) && r_waterstate.numwaterplanes < r_waterstate.maxwaterplanes)
+       if ((planeindex < 0 || bestplanescore > 0.001f) && r_waterstate.numwaterplanes < r_waterstate.maxwaterplanes)
        {
                // store the new plane
-               planeindex = r_waterstate.numwaterplanes;
+               planeindex = r_waterstate.numwaterplanes++;
                p = r_waterstate.waterplanes + planeindex;
-               r_waterstate.numwaterplanes++;
                p->plane = plane;
                // clear materialflags and pvs
                p->materialflags = 0;
@@ -7040,10 +7049,6 @@ void R_RenderScene(void)
                }
        }
 
-       R_AnimCache_CacheVisibleEntities();
-       if (r_timereport_active)
-               R_TimeReport("animation");
-
        R_Shadow_PrepareLights();
        if (r_shadows.integer > 0 && r_refdef.lightmapintensity > 0)
                R_Shadow_PrepareModelShadows();
@@ -7849,6 +7854,9 @@ texture_t *R_GetCurrentTexture(texture_t *t)
                t->currentmaterialflags |= MATERIALFLAG_ADD | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW;
        else if (t->currentalpha < 1)
                t->currentmaterialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW;
+       // LordHavoc: prevent bugs where code checks add or alpha at higher priority than customblend by clearing these flags
+       if (t->currentmaterialflags & MATERIALFLAG_CUSTOMBLEND)
+               t->currentmaterialflags &= ~(MATERIALFLAG_ADD | MATERIALFLAG_ALPHA);
        if (rsurface.ent_flags & RENDER_DOUBLESIDED)
                t->currentmaterialflags |= MATERIALFLAG_NOSHADOW | MATERIALFLAG_NOCULLFACE;
        if (rsurface.ent_flags & (RENDER_NODEPTHTEST | RENDER_VIEWMODEL))