-#define SHADERPERMUTATION_COLORMAPPING (1<<0) // indicates this is a colormapped skin
-#define SHADERPERMUTATION_CONTRASTBOOST (1<<1) // r_glsl_contrastboost boosts the contrast at low color levels (similar to gamma)
-#define SHADERPERMUTATION_FOG (1<<2) // tint the color by fog color or black if using additive blend mode
-#define SHADERPERMUTATION_CUBEFILTER (1<<3) // (lightsource) use cubemap light filter
-#define SHADERPERMUTATION_GLOW (1<<4) // (lightmap) blend in an additive glow texture
-#define SHADERPERMUTATION_DIFFUSE (1<<5) // (lightsource) whether to use directional shading
-#define SHADERPERMUTATION_SPECULAR (1<<6) // (lightsource or deluxemapping) render specular effects
-#define SHADERPERMUTATION_REFLECTION (1<<7) // normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
-#define SHADERPERMUTATION_OFFSETMAPPING (1<<8) // adjust texcoords to roughly simulate a displacement mapped surface
-#define SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING (1<<9) // adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
-#define SHADERPERMUTATION_MODEBASE (1<<10) // multiplier for the SHADERMODE_ values to get a valid index
+typedef struct shaderpermutationinfo_s
+{
+ const char *pretext;
+ const char *name;
+}
+shaderpermutationinfo_t;
+
+typedef struct shadermodeinfo_s
+{
+ const char *vertexfilename;
+ const char *geometryfilename;
+ const char *fragmentfilename;
+ const char *pretext;
+ const char *name;
+}
+shadermodeinfo_t;
+
+typedef enum shaderpermutation_e
+{
+ SHADERPERMUTATION_COLORMAPPING = 1<<0, // indicates this is a colormapped skin
+ SHADERPERMUTATION_CONTRASTBOOST = 1<<1, // r_glsl_contrastboost boosts the contrast at low color levels (similar to gamma)
+ SHADERPERMUTATION_FOG = 1<<2, // tint the color by fog color or black if using additive blend mode
+ SHADERPERMUTATION_CUBEFILTER = 1<<3, // (lightsource) use cubemap light filter
+ SHADERPERMUTATION_GLOW = 1<<4, // (lightmap) blend in an additive glow texture
+ SHADERPERMUTATION_DIFFUSE = 1<<5, // (lightsource) whether to use directional shading
+ SHADERPERMUTATION_SPECULAR = 1<<6, // (lightsource or deluxemapping) render specular effects
+ SHADERPERMUTATION_REFLECTION = 1<<7, // normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
+ SHADERPERMUTATION_OFFSETMAPPING = 1<<8, // adjust texcoords to roughly simulate a displacement mapped surface
+ SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING = 1<<9, // adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
+ SHADERPERMUTATION_LIMIT = 1<<10, // size of permutations array
+ SHADERPERMUTATION_COUNT = 10 // size of shaderpermutationinfo array
+}
+shaderpermutation_t;
- {"#define MODE_FLATCOLOR\n", " flatcolor"},
- {"#define MODE_VERTEXCOLOR\n", " vertexcolor"},
- {"#define MODE_LIGHTMAP\n", " lightmap"},
- {"#define MODE_LIGHTDIRECTIONMAP_MODELSPACE\n", " lightdirectionmap_modelspace"},
- {"#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n", " lightdirectionmap_tangentspace"},
- {"#define MODE_LIGHTDIRECTION\n", " lightdirection"},
- {"#define MODE_LIGHTSOURCE\n", " lightsource"},
- {"#define MODE_REFRACTION\n", " refraction"},
- {"#define MODE_WATER\n", " water"},
- {NULL, NULL}
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_FLATCOLOR\n", " flatcolor"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_VERTEXCOLOR\n", " vertexcolor"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTMAP\n", " lightmap"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_MODELSPACE\n", " lightdirectionmap_modelspace"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n", " lightdirectionmap_tangentspace"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTION\n", " lightdirection"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTSOURCE\n", " lightsource"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_REFRACTION\n", " refraction"},
+ {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_WATER\n", " water"},
- i = permutation / SHADERPERMUTATION_MODEBASE;
- vertstrings_list[vertstrings_count++] = shadermodeinfo[i][0];
- geomstrings_list[geomstrings_count++] = shadermodeinfo[i][0];
- fragstrings_list[fragstrings_count++] = shadermodeinfo[i][0];
- strlcat(permutationname, shadermodeinfo[i][1], sizeof(permutationname));
- for (i = 0;shaderpermutationinfo[i][0];i++)
+ vertexstring = R_GLSL_GetText(modeinfo->vertexfilename, true);
+ geometrystring = R_GLSL_GetText(modeinfo->geometryfilename, false);
+ fragmentstring = R_GLSL_GetText(modeinfo->fragmentfilename, false);
+
+ strlcat(permutationname, shadermodeinfo[mode].vertexfilename, sizeof(permutationname));
+
+ // the first pretext is which type of shader to compile as
+ // (later these will all be bound together as a program object)
+ vertstrings_list[vertstrings_count++] = "#define VERTEX_SHADER\n";
+ geomstrings_list[geomstrings_count++] = "#define GEOMETRY_SHADER\n";
+ fragstrings_list[fragstrings_count++] = "#define FRAGMENT_SHADER\n";
+
+ // the second pretext is the mode (for example a light source)
+ vertstrings_list[vertstrings_count++] = shadermodeinfo[mode].pretext;
+ geomstrings_list[geomstrings_count++] = shadermodeinfo[mode].pretext;
+ fragstrings_list[fragstrings_count++] = shadermodeinfo[mode].pretext;
+ strlcat(permutationname, modeinfo->name, sizeof(permutationname));
+
+ // now add all the permutation pretexts
+ for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
- shaderstring = (char *)FS_LoadFile(filename, r_main_mempool, false, NULL);
- shaderfound = false;
- if (shaderstring)
- {
- Con_DPrint("from disk... ");
- vertstrings_list[vertstrings_count++] = shaderstring;
- geomstrings_list[geomstrings_count++] = shaderstring;
- fragstrings_list[fragstrings_count++] = shaderstring;
- shaderfound = true;
- }
- else if (!strcmp(filename, "glsl/default.glsl"))
- {
- vertstrings_list[vertstrings_count++] = builtinshaderstring;
- geomstrings_list[geomstrings_count++] = builtinshaderstring;
- fragstrings_list[fragstrings_count++] = builtinshaderstring;
- shaderfound = true;
- }
- // clear any lists that are not needed by this shader
- if (!(shadertype & SHADERTYPE_USES_VERTEXSHADER))
+
+ // now append the shader text itself
+ vertstrings_list[vertstrings_count++] = vertexstring;
+ geomstrings_list[geomstrings_count++] = geometrystring;
+ fragstrings_list[fragstrings_count++] = fragmentstring;
+
+ // if any sources were NULL, clear the respective list
+ if (!vertexstring)
- p->loc_Texture_Normal = qglGetUniformLocationARB(p->program, "Texture_Normal");
- p->loc_Texture_Color = qglGetUniformLocationARB(p->program, "Texture_Color");
- p->loc_Texture_Gloss = qglGetUniformLocationARB(p->program, "Texture_Gloss");
- p->loc_Texture_Cube = qglGetUniformLocationARB(p->program, "Texture_Cube");
- p->loc_Texture_Attenuation = qglGetUniformLocationARB(p->program, "Texture_Attenuation");
- p->loc_Texture_FogMask = qglGetUniformLocationARB(p->program, "Texture_FogMask");
- p->loc_Texture_Pants = qglGetUniformLocationARB(p->program, "Texture_Pants");
- p->loc_Texture_Shirt = qglGetUniformLocationARB(p->program, "Texture_Shirt");
- p->loc_Texture_Lightmap = qglGetUniformLocationARB(p->program, "Texture_Lightmap");
- p->loc_Texture_Deluxemap = qglGetUniformLocationARB(p->program, "Texture_Deluxemap");
- p->loc_Texture_Glow = qglGetUniformLocationARB(p->program, "Texture_Glow");
- p->loc_Texture_Refraction = qglGetUniformLocationARB(p->program, "Texture_Refraction");
- p->loc_Texture_Reflection = qglGetUniformLocationARB(p->program, "Texture_Reflection");
- p->loc_FogColor = qglGetUniformLocationARB(p->program, "FogColor");
- p->loc_LightPosition = qglGetUniformLocationARB(p->program, "LightPosition");
- p->loc_EyePosition = qglGetUniformLocationARB(p->program, "EyePosition");
- p->loc_LightColor = qglGetUniformLocationARB(p->program, "LightColor");
- p->loc_Color_Pants = qglGetUniformLocationARB(p->program, "Color_Pants");
- p->loc_Color_Shirt = qglGetUniformLocationARB(p->program, "Color_Shirt");
- p->loc_FogRangeRecip = qglGetUniformLocationARB(p->program, "FogRangeRecip");
- p->loc_AmbientScale = qglGetUniformLocationARB(p->program, "AmbientScale");
- p->loc_DiffuseScale = qglGetUniformLocationARB(p->program, "DiffuseScale");
- p->loc_SpecularPower = qglGetUniformLocationARB(p->program, "SpecularPower");
- p->loc_SpecularScale = qglGetUniformLocationARB(p->program, "SpecularScale");
- p->loc_GlowScale = qglGetUniformLocationARB(p->program, "GlowScale");
- p->loc_SceneBrightness = qglGetUniformLocationARB(p->program, "SceneBrightness");
- p->loc_OffsetMapping_Scale = qglGetUniformLocationARB(p->program, "OffsetMapping_Scale");
- p->loc_TintColor = qglGetUniformLocationARB(p->program, "TintColor");
- p->loc_AmbientColor = qglGetUniformLocationARB(p->program, "AmbientColor");
- p->loc_DiffuseColor = qglGetUniformLocationARB(p->program, "DiffuseColor");
- p->loc_SpecularColor = qglGetUniformLocationARB(p->program, "SpecularColor");
- p->loc_LightDir = qglGetUniformLocationARB(p->program, "LightDir");
- p->loc_ContrastBoostCoeff = qglGetUniformLocationARB(p->program, "ContrastBoostCoeff");
+ p->loc_Texture_Normal = qglGetUniformLocationARB(p->program, "Texture_Normal");
+ p->loc_Texture_Color = qglGetUniformLocationARB(p->program, "Texture_Color");
+ p->loc_Texture_Gloss = qglGetUniformLocationARB(p->program, "Texture_Gloss");
+ p->loc_Texture_Glow = qglGetUniformLocationARB(p->program, "Texture_Glow");
+ p->loc_Texture_FogMask = qglGetUniformLocationARB(p->program, "Texture_FogMask");
+ p->loc_Texture_Pants = qglGetUniformLocationARB(p->program, "Texture_Pants");
+ p->loc_Texture_Shirt = qglGetUniformLocationARB(p->program, "Texture_Shirt");
+ p->loc_Texture_Lightmap = qglGetUniformLocationARB(p->program, "Texture_Lightmap");
+ p->loc_Texture_Deluxemap = qglGetUniformLocationARB(p->program, "Texture_Deluxemap");
+ p->loc_Texture_Refraction = qglGetUniformLocationARB(p->program, "Texture_Refraction");
+ p->loc_Texture_Reflection = qglGetUniformLocationARB(p->program, "Texture_Reflection");
+ p->loc_Texture_Attenuation = qglGetUniformLocationARB(p->program, "Texture_Attenuation");
+ p->loc_Texture_Cube = qglGetUniformLocationARB(p->program, "Texture_Cube");
+ p->loc_FogColor = qglGetUniformLocationARB(p->program, "FogColor");
+ p->loc_LightPosition = qglGetUniformLocationARB(p->program, "LightPosition");
+ p->loc_EyePosition = qglGetUniformLocationARB(p->program, "EyePosition");
+ p->loc_LightColor = qglGetUniformLocationARB(p->program, "LightColor");
+ p->loc_Color_Pants = qglGetUniformLocationARB(p->program, "Color_Pants");
+ p->loc_Color_Shirt = qglGetUniformLocationARB(p->program, "Color_Shirt");
+ p->loc_FogRangeRecip = qglGetUniformLocationARB(p->program, "FogRangeRecip");
+ p->loc_AmbientScale = qglGetUniformLocationARB(p->program, "AmbientScale");
+ p->loc_DiffuseScale = qglGetUniformLocationARB(p->program, "DiffuseScale");
+ p->loc_SpecularPower = qglGetUniformLocationARB(p->program, "SpecularPower");
+ p->loc_SpecularScale = qglGetUniformLocationARB(p->program, "SpecularScale");
+ p->loc_GlowScale = qglGetUniformLocationARB(p->program, "GlowScale");
+ p->loc_SceneBrightness = qglGetUniformLocationARB(p->program, "SceneBrightness");
+ p->loc_OffsetMapping_Scale = qglGetUniformLocationARB(p->program, "OffsetMapping_Scale");
+ p->loc_TintColor = qglGetUniformLocationARB(p->program, "TintColor");
+ p->loc_AmbientColor = qglGetUniformLocationARB(p->program, "AmbientColor");
+ p->loc_DiffuseColor = qglGetUniformLocationARB(p->program, "DiffuseColor");
+ p->loc_SpecularColor = qglGetUniformLocationARB(p->program, "SpecularColor");
+ p->loc_LightDir = qglGetUniformLocationARB(p->program, "LightDir");
+ p->loc_ContrastBoostCoeff = qglGetUniformLocationARB(p->program, "ContrastBoostCoeff");
- if (p->loc_Texture_Normal >= 0) qglUniform1iARB(p->loc_Texture_Normal, 0);
- if (p->loc_Texture_Color >= 0) qglUniform1iARB(p->loc_Texture_Color, 1);
- if (p->loc_Texture_Gloss >= 0) qglUniform1iARB(p->loc_Texture_Gloss, 2);
- if (p->loc_Texture_Cube >= 0) qglUniform1iARB(p->loc_Texture_Cube, 3);
- if (p->loc_Texture_FogMask >= 0) qglUniform1iARB(p->loc_Texture_FogMask, 4);
- if (p->loc_Texture_Pants >= 0) qglUniform1iARB(p->loc_Texture_Pants, 5);
- if (p->loc_Texture_Shirt >= 0) qglUniform1iARB(p->loc_Texture_Shirt, 6);
- if (p->loc_Texture_Lightmap >= 0) qglUniform1iARB(p->loc_Texture_Lightmap, 7);
- if (p->loc_Texture_Deluxemap >= 0) qglUniform1iARB(p->loc_Texture_Deluxemap, 8);
- if (p->loc_Texture_Glow >= 0) qglUniform1iARB(p->loc_Texture_Glow, 9);
- if (p->loc_Texture_Attenuation >= 0) qglUniform1iARB(p->loc_Texture_Attenuation, 10);
- if (p->loc_Texture_Refraction >= 0) qglUniform1iARB(p->loc_Texture_Refraction, 11);
- if (p->loc_Texture_Reflection >= 0) qglUniform1iARB(p->loc_Texture_Reflection, 12);
+ if (p->loc_Texture_Normal >= 0) qglUniform1iARB(p->loc_Texture_Normal , GL20TU_NORMAL);
+ if (p->loc_Texture_Color >= 0) qglUniform1iARB(p->loc_Texture_Color , GL20TU_COLOR);
+ if (p->loc_Texture_Gloss >= 0) qglUniform1iARB(p->loc_Texture_Gloss , GL20TU_GLOSS);
+ if (p->loc_Texture_Glow >= 0) qglUniform1iARB(p->loc_Texture_Glow , GL20TU_GLOW);
+ if (p->loc_Texture_Pants >= 0) qglUniform1iARB(p->loc_Texture_Pants , GL20TU_PANTS);
+ if (p->loc_Texture_Shirt >= 0) qglUniform1iARB(p->loc_Texture_Shirt , GL20TU_SHIRT);
+ if (p->loc_Texture_FogMask >= 0) qglUniform1iARB(p->loc_Texture_FogMask , GL20TU_FOGMASK);
+ if (p->loc_Texture_Lightmap >= 0) qglUniform1iARB(p->loc_Texture_Lightmap , GL20TU_LIGHTMAP);
+ if (p->loc_Texture_Deluxemap >= 0) qglUniform1iARB(p->loc_Texture_Deluxemap , GL20TU_DELUXEMAP);
+ if (p->loc_Texture_Attenuation >= 0) qglUniform1iARB(p->loc_Texture_Attenuation , GL20TU_ATTENUATION);
+ if (p->loc_Texture_Cube >= 0) qglUniform1iARB(p->loc_Texture_Cube , GL20TU_CUBE);
+ if (p->loc_Texture_Refraction >= 0) qglUniform1iARB(p->loc_Texture_Refraction , GL20TU_REFRACTION);
+ if (p->loc_Texture_Reflection >= 0) qglUniform1iARB(p->loc_Texture_Reflection , GL20TU_REFLECTION);
- r_view.frustum[0].normal[0] = 0 - 1.0 / r_view.frustum_x;
- r_view.frustum[0].normal[1] = 0 - 0;
- r_view.frustum[0].normal[2] = -1 - 0;
- r_view.frustum[1].normal[0] = 0 + 1.0 / r_view.frustum_x;
- r_view.frustum[1].normal[1] = 0 + 0;
- r_view.frustum[1].normal[2] = -1 + 0;
- r_view.frustum[2].normal[0] = 0 - 0;
- r_view.frustum[2].normal[1] = 0 - 1.0 / r_view.frustum_y;
- r_view.frustum[2].normal[2] = -1 - 0;
- r_view.frustum[3].normal[0] = 0 + 0;
- r_view.frustum[3].normal[1] = 0 + 1.0 / r_view.frustum_y;
- r_view.frustum[3].normal[2] = -1 + 0;
+ r_refdef.view.frustum[0].normal[0] = 0 - 1.0 / r_refdef.view.frustum_x;
+ r_refdef.view.frustum[0].normal[1] = 0 - 0;
+ r_refdef.view.frustum[0].normal[2] = -1 - 0;
+ r_refdef.view.frustum[1].normal[0] = 0 + 1.0 / r_refdef.view.frustum_x;
+ r_refdef.view.frustum[1].normal[1] = 0 + 0;
+ r_refdef.view.frustum[1].normal[2] = -1 + 0;
+ r_refdef.view.frustum[2].normal[0] = 0 - 0;
+ r_refdef.view.frustum[2].normal[1] = 0 - 1.0 / r_refdef.view.frustum_y;
+ r_refdef.view.frustum[2].normal[2] = -1 - 0;
+ r_refdef.view.frustum[3].normal[0] = 0 + 0;
+ r_refdef.view.frustum[3].normal[1] = 0 + 1.0 / r_refdef.view.frustum_y;
+ r_refdef.view.frustum[3].normal[2] = -1 + 0;
- r_view.frustum[0].normal[0] = m[3] - m[0];
- r_view.frustum[0].normal[1] = m[7] - m[4];
- r_view.frustum[0].normal[2] = m[11] - m[8];
- r_view.frustum[0].dist = m[15] - m[12];
-
- r_view.frustum[1].normal[0] = m[3] + m[0];
- r_view.frustum[1].normal[1] = m[7] + m[4];
- r_view.frustum[1].normal[2] = m[11] + m[8];
- r_view.frustum[1].dist = m[15] + m[12];
-
- r_view.frustum[2].normal[0] = m[3] - m[1];
- r_view.frustum[2].normal[1] = m[7] - m[5];
- r_view.frustum[2].normal[2] = m[11] - m[9];
- r_view.frustum[2].dist = m[15] - m[13];
-
- r_view.frustum[3].normal[0] = m[3] + m[1];
- r_view.frustum[3].normal[1] = m[7] + m[5];
- r_view.frustum[3].normal[2] = m[11] + m[9];
- r_view.frustum[3].dist = m[15] + m[13];
-
- r_view.frustum[4].normal[0] = m[3] - m[2];
- r_view.frustum[4].normal[1] = m[7] - m[6];
- r_view.frustum[4].normal[2] = m[11] - m[10];
- r_view.frustum[4].dist = m[15] - m[14];
-
- r_view.frustum[5].normal[0] = m[3] + m[2];
- r_view.frustum[5].normal[1] = m[7] + m[6];
- r_view.frustum[5].normal[2] = m[11] + m[10];
- r_view.frustum[5].dist = m[15] + m[14];
+ r_refdef.view.frustum[0].normal[0] = m[3] - m[0];
+ r_refdef.view.frustum[0].normal[1] = m[7] - m[4];
+ r_refdef.view.frustum[0].normal[2] = m[11] - m[8];
+ r_refdef.view.frustum[0].dist = m[15] - m[12];
+
+ r_refdef.view.frustum[1].normal[0] = m[3] + m[0];
+ r_refdef.view.frustum[1].normal[1] = m[7] + m[4];
+ r_refdef.view.frustum[1].normal[2] = m[11] + m[8];
+ r_refdef.view.frustum[1].dist = m[15] + m[12];
+
+ r_refdef.view.frustum[2].normal[0] = m[3] - m[1];
+ r_refdef.view.frustum[2].normal[1] = m[7] - m[5];
+ r_refdef.view.frustum[2].normal[2] = m[11] - m[9];
+ r_refdef.view.frustum[2].dist = m[15] - m[13];
+
+ r_refdef.view.frustum[3].normal[0] = m[3] + m[1];
+ r_refdef.view.frustum[3].normal[1] = m[7] + m[5];
+ r_refdef.view.frustum[3].normal[2] = m[11] + m[9];
+ r_refdef.view.frustum[3].dist = m[15] + m[13];
+
+ r_refdef.view.frustum[4].normal[0] = m[3] - m[2];
+ r_refdef.view.frustum[4].normal[1] = m[7] - m[6];
+ r_refdef.view.frustum[4].normal[2] = m[11] - m[10];
+ r_refdef.view.frustum[4].dist = m[15] - m[14];
+
+ r_refdef.view.frustum[5].normal[0] = m[3] + m[2];
+ r_refdef.view.frustum[5].normal[1] = m[7] + m[6];
+ r_refdef.view.frustum[5].normal[2] = m[11] + m[10];
+ r_refdef.view.frustum[5].dist = m[15] + m[14];
- slopex = 1.0 / r_view.frustum_x;
- slopey = 1.0 / r_view.frustum_y;
- VectorMA(r_view.forward, -slopex, r_view.left, r_view.frustum[0].normal);
- VectorMA(r_view.forward, slopex, r_view.left, r_view.frustum[1].normal);
- VectorMA(r_view.forward, -slopey, r_view.up , r_view.frustum[2].normal);
- VectorMA(r_view.forward, slopey, r_view.up , r_view.frustum[3].normal);
- VectorCopy(r_view.forward, r_view.frustum[4].normal);
+ slopex = 1.0 / r_refdef.view.frustum_x;
+ slopey = 1.0 / r_refdef.view.frustum_y;
+ VectorMA(r_refdef.view.forward, -slopex, r_refdef.view.left, r_refdef.view.frustum[0].normal);
+ VectorMA(r_refdef.view.forward, slopex, r_refdef.view.left, r_refdef.view.frustum[1].normal);
+ VectorMA(r_refdef.view.forward, -slopey, r_refdef.view.up , r_refdef.view.frustum[2].normal);
+ VectorMA(r_refdef.view.forward, slopey, r_refdef.view.up , r_refdef.view.frustum[3].normal);
+ VectorCopy(r_refdef.view.forward, r_refdef.view.frustum[4].normal);
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, -1024 * slopex, r_view.left, -1024 * slopey, r_view.up, r_view.frustumcorner[0]);
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, 1024 * slopex, r_view.left, -1024 * slopey, r_view.up, r_view.frustumcorner[1]);
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, -1024 * slopex, r_view.left, 1024 * slopey, r_view.up, r_view.frustumcorner[2]);
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, 1024 * slopex, r_view.left, 1024 * slopey, r_view.up, r_view.frustumcorner[3]);
+ VectorMAMAMAM(1, r_refdef.view.origin, 1024, r_refdef.view.forward, -1024 * slopex, r_refdef.view.left, -1024 * slopey, r_refdef.view.up, r_refdef.view.frustumcorner[0]);
+ VectorMAMAMAM(1, r_refdef.view.origin, 1024, r_refdef.view.forward, 1024 * slopex, r_refdef.view.left, -1024 * slopey, r_refdef.view.up, r_refdef.view.frustumcorner[1]);
+ VectorMAMAMAM(1, r_refdef.view.origin, 1024, r_refdef.view.forward, -1024 * slopex, r_refdef.view.left, 1024 * slopey, r_refdef.view.up, r_refdef.view.frustumcorner[2]);
+ VectorMAMAMAM(1, r_refdef.view.origin, 1024, r_refdef.view.forward, 1024 * slopex, r_refdef.view.left, 1024 * slopey, r_refdef.view.up, r_refdef.view.frustumcorner[3]);
- VectorScale(r_view.left, -r_view.ortho_x, r_view.frustum[0].normal);
- VectorScale(r_view.left, r_view.ortho_x, r_view.frustum[1].normal);
- VectorScale(r_view.up, -r_view.ortho_y, r_view.frustum[2].normal);
- VectorScale(r_view.up, r_view.ortho_y, r_view.frustum[3].normal);
- VectorCopy(r_view.forward, r_view.frustum[4].normal);
- r_view.frustum[0].dist = DotProduct (r_view.origin, r_view.frustum[0].normal) + r_view.ortho_x;
- r_view.frustum[1].dist = DotProduct (r_view.origin, r_view.frustum[1].normal) + r_view.ortho_x;
- r_view.frustum[2].dist = DotProduct (r_view.origin, r_view.frustum[2].normal) + r_view.ortho_y;
- r_view.frustum[3].dist = DotProduct (r_view.origin, r_view.frustum[3].normal) + r_view.ortho_y;
- r_view.frustum[4].dist = DotProduct (r_view.origin, r_view.frustum[4].normal) + r_refdef.nearclip;
+ VectorScale(r_refdef.view.left, -r_refdef.view.ortho_x, r_refdef.view.frustum[0].normal);
+ VectorScale(r_refdef.view.left, r_refdef.view.ortho_x, r_refdef.view.frustum[1].normal);
+ VectorScale(r_refdef.view.up, -r_refdef.view.ortho_y, r_refdef.view.frustum[2].normal);
+ VectorScale(r_refdef.view.up, r_refdef.view.ortho_y, r_refdef.view.frustum[3].normal);
+ VectorCopy(r_refdef.view.forward, r_refdef.view.frustum[4].normal);
+ r_refdef.view.frustum[0].dist = DotProduct (r_refdef.view.origin, r_refdef.view.frustum[0].normal) + r_refdef.view.ortho_x;
+ r_refdef.view.frustum[1].dist = DotProduct (r_refdef.view.origin, r_refdef.view.frustum[1].normal) + r_refdef.view.ortho_x;
+ r_refdef.view.frustum[2].dist = DotProduct (r_refdef.view.origin, r_refdef.view.frustum[2].normal) + r_refdef.view.ortho_y;
+ r_refdef.view.frustum[3].dist = DotProduct (r_refdef.view.origin, r_refdef.view.frustum[3].normal) + r_refdef.view.ortho_y;
+ r_refdef.view.frustum[4].dist = DotProduct (r_refdef.view.origin, r_refdef.view.frustum[4].normal) + r_refdef.nearclip;
// now blend on the bloom texture
GL_BlendFunc(GL_ONE, GL_ONE);
R_Mesh_TexBind(0, R_GetTexture(r_bloomstate.texture_screen));
R_Mesh_TexCoordPointer(0, 2, r_bloomstate.screentexcoord2f, 0, 0);
}
R_Mesh_Draw(0, 4, 2, polygonelements, 0, 0);
// now blend on the bloom texture
GL_BlendFunc(GL_ONE, GL_ONE);
R_Mesh_TexBind(0, R_GetTexture(r_bloomstate.texture_screen));
R_Mesh_TexCoordPointer(0, 2, r_bloomstate.screentexcoord2f, 0, 0);
}
R_Mesh_Draw(0, 4, 2, polygonelements, 0, 0);
- Vector4Set(t->lightmapcolor, ent->colormod[0] * colorscale, ent->colormod[1] * colorscale, ent->colormod[2] * colorscale, t->currentalpha);
- R_Texture_AddLayer(t, depthmask, blendfunc1, blendfunc2, TEXTURELAYERTYPE_LITTEXTURE, currentbasetexture, &t->currenttexmatrix, ent->colormod[0] * colorscale, ent->colormod[1] * colorscale, ent->colormod[2] * colorscale, t->currentalpha);
- if (r_ambient.value >= (1.0f/64.0f))
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, currentbasetexture, &t->currenttexmatrix, ent->colormod[0] * r_ambient.value * (1.0f / 64.0f), ent->colormod[1] * r_ambient.value * (1.0f / 64.0f), ent->colormod[2] * r_ambient.value * (1.0f / 64.0f), t->currentalpha);
+ VectorScale(t->lightmapcolor, r_ambient.value * (1.0f / 64.0f), ambientcolor);
+ VectorScale(t->lightmapcolor, colorscale, t->lightmapcolor);
+ // basic lit geometry
+ R_Texture_AddLayer(t, depthmask, blendfunc1, blendfunc2, TEXTURELAYERTYPE_LITTEXTURE, currentbasetexture, &t->currenttexmatrix, t->lightmapcolor[0], t->lightmapcolor[1], t->lightmapcolor[2], t->lightmapcolor[3]);
+ // add pants/shirt if needed
- {
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->currentskinframe->pants, &t->currenttexmatrix, ent->colormap_pantscolor[0] * ent->colormod[0] * colorscale, ent->colormap_pantscolor[1] * ent->colormod[1] * colorscale, ent->colormap_pantscolor[2] * ent->colormod[2] * colorscale, t->currentalpha);
- if (r_ambient.value >= (1.0f/64.0f))
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->currentskinframe->pants, &t->currenttexmatrix, ent->colormap_pantscolor[0] * ent->colormod[0] * r_ambient.value * (1.0f / 64.0f), ent->colormap_pantscolor[1] * ent->colormod[1] * r_ambient.value * (1.0f / 64.0f), ent->colormap_pantscolor[2] * ent->colormod[2] * r_ambient.value * (1.0f / 64.0f), t->currentalpha);
- }
+ R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->currentskinframe->pants, &t->currenttexmatrix, ent->colormap_pantscolor[0] * t->lightmapcolor[0], ent->colormap_pantscolor[1] * t->lightmapcolor[1], ent->colormap_pantscolor[2] * t->lightmapcolor[2], t->lightmapcolor[3]);
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->currentskinframe->shirt, &t->currenttexmatrix, ent->colormap_shirtcolor[0] * ent->colormod[0] * colorscale, ent->colormap_shirtcolor[1] * ent->colormod[1] * colorscale, ent->colormap_shirtcolor[2] * ent->colormod[2] * colorscale, t->currentalpha);
- if (r_ambient.value >= (1.0f/64.0f))
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->currentskinframe->shirt, &t->currenttexmatrix, ent->colormap_shirtcolor[0] * ent->colormod[0] * r_ambient.value * (1.0f / 64.0f), ent->colormap_shirtcolor[1] * ent->colormod[1] * r_ambient.value * (1.0f / 64.0f), ent->colormap_shirtcolor[2] * ent->colormod[2] * r_ambient.value * (1.0f / 64.0f), t->currentalpha);
+ R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, currentbasetexture, &t->currenttexmatrix, ambientcolor[0], ambientcolor[1], ambientcolor[2], t->lightmapcolor[3]);
+ if (VectorLength2(ent->colormap_pantscolor) >= (1.0f / 1048576.0f) && t->currentskinframe->pants)
+ R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->currentskinframe->pants, &t->currenttexmatrix, ent->colormap_pantscolor[0] * ambientcolor[0], ent->colormap_pantscolor[1] * ambientcolor[1], ent->colormap_pantscolor[2] * ambientcolor[2], t->lightmapcolor[3]);
+ if (VectorLength2(ent->colormap_shirtcolor) >= (1.0f / 1048576.0f) && t->currentskinframe->shirt)
+ R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->currentskinframe->shirt, &t->currenttexmatrix, ent->colormap_shirtcolor[0] * ambientcolor[0], ent->colormap_shirtcolor[1] * ambientcolor[1], ent->colormap_shirtcolor[2] * ambientcolor[2], t->lightmapcolor[3]);
- R_Mesh_TexBind(0, R_GetTexture(rsurface.texture->currentskinframe->nmap));
- R_Mesh_TexBind(1, R_GetTexture(rsurface.texture->basetexture));
- R_Mesh_TexBind(2, R_GetTexture(rsurface.texture->glosstexture));
- R_Mesh_TexBind(4, R_GetTexture(r_texture_fogattenuation));
- R_Mesh_TexBind(5, R_GetTexture(rsurface.texture->currentskinframe->pants));
- R_Mesh_TexBind(6, R_GetTexture(rsurface.texture->currentskinframe->shirt));
- if (rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT)
- {
- R_Mesh_TexBind(7, R_GetTexture(r_texture_grey128));
- R_Mesh_TexBind(8, R_GetTexture(r_texture_blanknormalmap));
- R_Mesh_ColorPointer(NULL, 0, 0);
- }
- else if (rsurface.uselightmaptexture)
- {
- R_Mesh_TexBind(7, R_GetTexture(texturesurfacelist[0]->lightmaptexture));
- R_Mesh_TexBind(8, R_GetTexture(texturesurfacelist[0]->deluxemaptexture));
+ R_Mesh_TexBind(GL20TU_NORMAL, R_GetTexture(rsurface.texture->currentskinframe->nmap));
+ R_Mesh_TexBind(GL20TU_COLOR, R_GetTexture(rsurface.texture->basetexture));
+ R_Mesh_TexBind(GL20TU_GLOSS, R_GetTexture(rsurface.texture->glosstexture));
+ R_Mesh_TexBind(GL20TU_GLOW, R_GetTexture(rsurface.texture->currentskinframe->glow));
+ R_Mesh_TexBind(GL20TU_PANTS, R_GetTexture(rsurface.texture->currentskinframe->pants));
+ R_Mesh_TexBind(GL20TU_SHIRT, R_GetTexture(rsurface.texture->currentskinframe->shirt));
+ R_Mesh_TexBind(GL20TU_FOGMASK, R_GetTexture(r_texture_fogattenuation));
+ if (rsurface.uselightmaptexture || (rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
R_Mesh_TexCoordPointer(2, 3, rsurface.tvector3f, rsurface.tvector3f_bufferobject, rsurface.tvector3f_bufferoffset);
R_Mesh_TexCoordPointer(3, 3, rsurface.normal3f, rsurface.normal3f_bufferobject, rsurface.normal3f_bufferoffset);
R_Mesh_TexCoordPointer(4, 2, rsurface.modeltexcoordlightmap2f, rsurface.modeltexcoordlightmap2f_bufferobject, rsurface.modeltexcoordlightmap2f_bufferoffset);
R_Mesh_TexCoordPointer(2, 3, rsurface.tvector3f, rsurface.tvector3f_bufferobject, rsurface.tvector3f_bufferoffset);
R_Mesh_TexCoordPointer(3, 3, rsurface.normal3f, rsurface.normal3f_bufferobject, rsurface.normal3f_bufferoffset);
R_Mesh_TexCoordPointer(4, 2, rsurface.modeltexcoordlightmap2f, rsurface.modeltexcoordlightmap2f_bufferobject, rsurface.modeltexcoordlightmap2f_bufferoffset);