]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_shadow.c
Move rt* states and the ambient value into r_refdef_scene. Menu now uses fullbright...
[xonotic/darkplaces.git] / r_shadow.c
index f2b4137f15758fb5c5bbdbbf01751948cb4d47b3..d0bba73792f5c45cb7ef6fa34804f75a7d5a4212 100644 (file)
@@ -995,12 +995,12 @@ static void R_Shadow_MakeTextures(void)
        R_Shadow_MakeTextures_MakeCorona();
 
        // Editor light sprites
-       r_editlights_sprcursor = Draw_CachePic("gfx/editlights/cursor", true);
-       r_editlights_sprlight = Draw_CachePic("gfx/editlights/light", true);
-       r_editlights_sprnoshadowlight = Draw_CachePic("gfx/editlights/noshadow", true);
-       r_editlights_sprcubemaplight = Draw_CachePic("gfx/editlights/cubemaplight", true);
-       r_editlights_sprcubemapnoshadowlight = Draw_CachePic("gfx/editlights/cubemapnoshadowlight", true);
-       r_editlights_sprselection = Draw_CachePic("gfx/editlights/selection", true);
+       r_editlights_sprcursor = Draw_CachePic ("gfx/editlights/cursor");
+       r_editlights_sprlight = Draw_CachePic ("gfx/editlights/light");
+       r_editlights_sprnoshadowlight = Draw_CachePic ("gfx/editlights/noshadow");
+       r_editlights_sprcubemaplight = Draw_CachePic ("gfx/editlights/cubemaplight");
+       r_editlights_sprcubemapnoshadowlight = Draw_CachePic ("gfx/editlights/cubemapnoshadowlight");
+       r_editlights_sprselection = Draw_CachePic ("gfx/editlights/selection");
 }
 
 void R_Shadow_ValidateCvars(void)
@@ -1134,10 +1134,11 @@ void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent)
        if (r_shadow_rendermode == R_SHADOW_RENDERMODE_LIGHT_GLSL)
        {
                R_Mesh_TexBindCubeMap(GL20TU_CUBE, R_GetTexture(rsurface.rtlight->currentcubemap)); // light filter
-               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
                GL_ColorMask(r_refdef.view.colormask[0], r_refdef.view.colormask[1], r_refdef.view.colormask[2], 0);
-               CHECKGLERROR
        }
+       else if (r_shadow_rendermode == R_SHADOW_RENDERMODE_LIGHT_VERTEX)
+               R_Mesh_ColorPointer(rsurface.array_color4f, 0, 0);
+       GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
 }
 
 void R_Shadow_RenderMode_VisibleShadowVolumes(void)
@@ -1526,9 +1527,6 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(int firstvertex, int nu
 static void R_Shadow_RenderLighting_VisibleLighting(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, const vec3_t lightcolorbase, const vec3_t lightcolorpants, const vec3_t lightcolorshirt, rtexture_t *basetexture, rtexture_t *pantstexture, rtexture_t *shirttexture, rtexture_t *normalmaptexture, rtexture_t *glosstexture, float ambientscale, float diffusescale, float specularscale, qboolean dopants, qboolean doshirt)
 {
        // used to display how many times a surface is lit for level design purposes
-       GL_Color(0.1 * r_refdef.view.colorscale, 0.025 * r_refdef.view.colorscale, 0, 1);
-       R_Mesh_ColorPointer(NULL, 0, 0);
-       R_Mesh_ResetTextureState();
        R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 }
 
@@ -2270,8 +2268,6 @@ static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertice
        VectorScale(lightcolorpants, diffusescale * 2 * r_refdef.view.colorscale, diffusecolorpants);
        VectorScale(lightcolorshirt, ambientscale * 2 * r_refdef.view.colorscale, ambientcolorshirt);
        VectorScale(lightcolorshirt, diffusescale * 2 * r_refdef.view.colorscale, diffusecolorshirt);
-       GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
-       R_Mesh_ColorPointer(rsurface.array_color4f, 0, 0);
        memset(&m, 0, sizeof(m));
        m.tex[0] = R_GetTexture(basetexture);
        m.texmatrix[0] = rsurface.texture->currenttexmatrix;
@@ -2805,6 +2801,7 @@ void R_Shadow_SetupEntityLight(const entity_render_t *ent)
 {
        // set up properties for rendering light onto this entity
        RSurf_ActiveModelEntity(ent, true, true);
+       GL_AlphaTest(false);
        Matrix4x4_Concat(&rsurface.entitytolight, &rsurface.rtlight->matrix_worldtolight, &ent->matrix);
        Matrix4x4_Concat(&rsurface.entitytoattenuationxyz, &matrix_attenuationxyz, &rsurface.entitytolight);
        Matrix4x4_Concat(&rsurface.entitytoattenuationz, &matrix_attenuationz, &rsurface.entitytolight);
@@ -2820,6 +2817,7 @@ void R_Shadow_DrawWorldLight(int numsurfaces, int *surfacelist, const unsigned c
 
        // set up properties for rendering light onto this entity
        RSurf_ActiveWorldEntity();
+       GL_AlphaTest(false);
        rsurface.entitytolight = rsurface.rtlight->matrix_worldtolight;
        Matrix4x4_Concat(&rsurface.entitytoattenuationxyz, &matrix_attenuationxyz, &rsurface.entitytolight);
        Matrix4x4_Concat(&rsurface.entitytoattenuationz, &matrix_attenuationz, &rsurface.entitytolight);
@@ -3030,7 +3028,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
        // count this light in the r_speeds
        r_refdef.stats.lights++;
 
-       if (r_showshadowvolumes.integer && r_refdef.view.showdebug && numsurfaces + numshadowentities + numshadowentities_noselfshadow && rtlight->shadow && (rtlight->isstatic ? r_refdef.rtworldshadows : r_refdef.rtdlightshadows))
+       if (r_showshadowvolumes.integer && r_refdef.view.showdebug && numsurfaces + numshadowentities + numshadowentities_noselfshadow && rtlight->shadow && (rtlight->isstatic ? r_refdef.scene.rtworldshadows : r_refdef.scene.rtdlightshadows))
        {
                // optionally draw visible shape of the shadow volumes
                // for performance analysis by level designers
@@ -3043,7 +3041,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        R_Shadow_DrawEntityShadow(shadowentities_noselfshadow[i]);
        }
 
-       if (gl_stencil && numsurfaces + numshadowentities + numshadowentities_noselfshadow && rtlight->shadow && (rtlight->isstatic ? r_refdef.rtworldshadows : r_refdef.rtdlightshadows))
+       if (gl_stencil && numsurfaces + numshadowentities + numshadowentities_noselfshadow && rtlight->shadow && (rtlight->isstatic ? r_refdef.scene.rtworldshadows : r_refdef.scene.rtdlightshadows))
        {
                // draw stencil shadow volumes to mask off pixels that are in shadow
                // so that they won't receive lighting
@@ -3136,7 +3134,7 @@ void R_ShadowVolumeLighting(qboolean visible)
 
        R_Shadow_RenderMode_Begin();
 
-       flag = r_refdef.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
+       flag = r_refdef.scene.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
        if (r_shadow_debuglight.integer >= 0)
        {
                lightindex = r_shadow_debuglight.integer;
@@ -3153,7 +3151,7 @@ void R_ShadowVolumeLighting(qboolean visible)
                                R_DrawRTLight(&light->rtlight, visible);
                }
        }
-       if (r_refdef.rtdlight)
+       if (r_refdef.scene.rtdlight)
                for (lnum = 0;lnum < r_refdef.scene.numlights;lnum++)
                        R_DrawRTLight(&r_refdef.scene.lights[lnum], visible);
 
@@ -3258,7 +3256,7 @@ void R_DrawCoronas(void)
        if (r_coronas.value < (1.0f / 256.0f) && !gl_flashblend.integer)
                return;
        R_Mesh_Matrix(&identitymatrix);
-       flag = r_refdef.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
+       flag = r_refdef.scene.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
        // FIXME: these traces should scan all render entities instead of cl.world
        for (lightindex = 0;lightindex < Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray);lightindex++)
        {
@@ -3391,6 +3389,9 @@ rtexture_t *R_Shadow_LoadCubemap(const char *basename)
        // if a cubemap loaded, upload it
        if (cubemappixels)
        {
+               if (developer_loading.integer)
+                       Con_Printf("loading cubemap \"%s\"\n", basename);
+
                if (!r_shadow_filters_texturepool)
                        r_shadow_filters_texturepool = R_AllocTexturePool();
                cubemaptexture = R_LoadTextureCubeMap(r_shadow_filters_texturepool, basename, cubemapsize, cubemappixels, TEXTYPE_BGRA, TEXF_PRECACHE | (gl_texturecompression_lightcubemaps.integer ? TEXF_COMPRESS : 0), NULL);
@@ -3398,11 +3399,15 @@ rtexture_t *R_Shadow_LoadCubemap(const char *basename)
        }
        else
        {
-               Con_Printf("Failed to load Cubemap \"%s\", tried ", basename);
-               for (j = 0;j < 3;j++)
-                       for (i = 0;i < 6;i++)
-                               Con_Printf("%s\"%s%s.tga\"", j + i > 0 ? ", " : "", basename, suffix[j][i].suffix);
-               Con_Print(" and was unable to find any of them.\n");
+               Con_DPrintf("failed to load cubemap \"%s\"\n", basename);
+               if (developer_loading.integer)
+               {
+                       Con_Printf("(tried tried images ");
+                       for (j = 0;j < 3;j++)
+                               for (i = 0;i < 6;i++)
+                                       Con_Printf("%s\"%s%s.tga\"", j + i > 0 ? ", " : "", basename, suffix[j][i].suffix);
+                       Con_Print(" and was unable to find any of them).\n");
+               }
        }
        return cubemaptexture;
 }
@@ -3425,6 +3430,14 @@ rtexture_t *R_Shadow_Cubemap(const char *basename)
 
 void R_Shadow_FreeCubemaps(void)
 {
+       int i;
+       for (i = 0;i < numcubemaps;i++)
+       {
+               if (developer_loading.integer)
+                       Con_Printf("unloading cubemap \"%s\"\n", cubemaps[i].basename);
+               R_FreeTexture(cubemaps[i].texture);
+       }
+
        numcubemaps = 0;
        R_FreeTexturePool(&r_shadow_filters_texturepool);
 }
@@ -4659,7 +4672,7 @@ void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffu
 
        if (!r_fullbright.integer && r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.LightPoint)
        {
-               ambientcolor[0] = ambientcolor[1] = ambientcolor[2] = r_ambient.value * (2.0f / 128.0f);
+               ambientcolor[0] = ambientcolor[1] = ambientcolor[2] = r_refdef.scene.ambient * (2.0f / 128.0f);
                r_refdef.scene.worldmodel->brush.LightPoint(r_refdef.scene.worldmodel, p, ambientcolor, diffusecolor, diffusenormal);
        }
        else