diff options
author | SmileTheory <SmileTheory@gmail.com> | 2013-09-16 00:54:26 -0700 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2014-06-17 17:43:34 +0100 |
commit | 75fe4796280cc95fe6b96cc9c9df5d74fc478ffa (patch) | |
tree | d031d5af29fb83215f6d140df94e5d4b48ce7309 /src/renderergl2/tr_shader.c | |
parent | 57ba5d4419af6c57be928ca57da090622411215f (diff) |
#5979: Cubemap support for opengl2.
Diffstat (limited to 'src/renderergl2/tr_shader.c')
-rw-r--r-- | src/renderergl2/tr_shader.c | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/src/renderergl2/tr_shader.c b/src/renderergl2/tr_shader.c index 6bf4fa43..5057b436 100644 --- a/src/renderergl2/tr_shader.c +++ b/src/renderergl2/tr_shader.c @@ -911,8 +911,8 @@ static qboolean ParseStage( shaderStage_t *stage, char **text ) else if(!Q_stricmp(token, "specularMap")) { stage->type = ST_SPECULARMAP; - stage->materialInfo[0] = 0.04f; - stage->materialInfo[1] = 256.0f; + stage->materialInfo[0] = 1.0f; + stage->materialInfo[1] = 1.0f; } else { @@ -938,12 +938,35 @@ static qboolean ParseStage( shaderStage_t *stage, char **text ) // else if (!Q_stricmp(token, "specularexponent")) { + float exponent; + token = COM_ParseExt(text, qfalse); if ( token[0] == 0 ) { ri.Printf( PRINT_WARNING, "WARNING: missing parameter for specular exponent in shader '%s'\n", shader.name ); continue; } + + exponent = atof( token ); + + // Change shininess to gloss + // FIXME: assumes max exponent of 8192 and min of 1, must change here if altered in lightall_fp.glsl + exponent = CLAMP(exponent, 1.0, 8192.0); + + stage->materialInfo[1] = log(exponent) / log(8192.0); + } + // + // gloss <value> + // + else if (!Q_stricmp(token, "gloss")) + { + token = COM_ParseExt(text, qfalse); + if ( token[0] == 0 ) + { + ri.Printf( PRINT_WARNING, "WARNING: missing parameter for gloss in shader '%s'\n", shader.name ); + continue; + } + stage->materialInfo[1] = atof( token ); } // @@ -1927,7 +1950,7 @@ static void ComputeVertexAttribs(void) shader.vertexAttribs |= ATTR_NORMAL; #ifdef USE_VERT_TANGENT_SPACE - if (pStage->glslShaderIndex & LIGHTDEF_USE_NORMALMAP) + if ((pStage->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) && !(r_normalMapping->integer == 0 && r_specularMapping->integer == 0)) { shader.vertexAttribs |= ATTR_BITANGENT | ATTR_TANGENT; } @@ -2201,7 +2224,6 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse, { //ri.Printf(PRINT_ALL, ", normalmap %s", normal->bundle[0].image[0]->imgName); diffuse->bundle[TB_NORMALMAP] = normal->bundle[0]; - defs |= LIGHTDEF_USE_NORMALMAP; if (parallax && r_parallaxMapping->integer) defs |= LIGHTDEF_USE_PARALLAXMAP; } @@ -2219,13 +2241,22 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse, if (normalImg) { diffuse->bundle[TB_NORMALMAP] = diffuse->bundle[0]; + diffuse->bundle[TB_NORMALMAP].numImageAnimations = 0; diffuse->bundle[TB_NORMALMAP].image[0] = normalImg; - defs |= LIGHTDEF_USE_NORMALMAP; if (parallax && r_parallaxMapping->integer) defs |= LIGHTDEF_USE_PARALLAXMAP; } } + + if (!diffuse->bundle[TB_NORMALMAP].image[0]) + { + // use 0x80 image, shader will interpret as (0,0,1) + diffuse->bundle[TB_NORMALMAP] = diffuse->bundle[0]; + diffuse->bundle[TB_NORMALMAP].numImageAnimations = 0; + diffuse->bundle[TB_NORMALMAP].image[0] = tr.greyImage; + //ri.Printf(PRINT_ALL, ", normalmap %s", diffuse->bundle[TB_NORMALMAP].image[0]->imgName); + } } if (r_specularMapping->integer) @@ -2236,7 +2267,18 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse, diffuse->bundle[TB_SPECULARMAP] = specular->bundle[0]; diffuse->materialInfo[0] = specular->materialInfo[0]; diffuse->materialInfo[1] = specular->materialInfo[1]; - defs |= LIGHTDEF_USE_SPECULARMAP; + } + else if (lightmap || useLightVector || useLightVertex) + { + // use a white image, materialinfo will do the rest + diffuse->bundle[TB_SPECULARMAP] = diffuse->bundle[0]; + diffuse->bundle[TB_SPECULARMAP].numImageAnimations = 0; + diffuse->bundle[TB_SPECULARMAP].image[0] = tr.whiteImage; + if (!diffuse->materialInfo[0]) + diffuse->materialInfo[0] = r_baseSpecular->value; + if (!diffuse->materialInfo[1]) + diffuse->materialInfo[1] = r_baseGloss->value; + //ri.Printf(PRINT_ALL, ", specularmap %s", diffuse->bundle[TB_SPECULARMAP].image[0]->imgName); } } @@ -2540,6 +2582,22 @@ static qboolean CollapseStagesToGLSL(void) } } + // convert any remaining lightingdiffuse stages to a lighting pass + for (i = 0; i < MAX_SHADER_STAGES; i++) + { + shaderStage_t *pStage = &stages[i]; + + if (!pStage->active) + continue; + + if (pStage->rgbGen == CGEN_LIGHTING_DIFFUSE) + { + pStage->glslShaderGroup = tr.lightallShader; + pStage->glslShaderIndex = LIGHTDEF_USE_LIGHT_VECTOR; + } + } + + return numStages; } |