summaryrefslogtreecommitdiff
path: root/src/renderergl2/tr_shader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderergl2/tr_shader.c')
-rw-r--r--src/renderergl2/tr_shader.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/renderergl2/tr_shader.c b/src/renderergl2/tr_shader.c
index 98e8776e..b4a120ca 100644
--- a/src/renderergl2/tr_shader.c
+++ b/src/renderergl2/tr_shader.c
@@ -955,17 +955,23 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
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->specularScale[3] = log(exponent) / log(8192.0);
+ if (r_glossIsRoughness->integer)
+ stage->specularScale[3] = powf(2.0f / (exponent + 2.0), 0.25);
+ else
+ {
+ // Change shininess to gloss
+ // Assumes max exponent of 8190 and min of 0, must change here if altered in lightall_fp.glsl
+ exponent = CLAMP(exponent, 0.0f, 8190.0f);
+ stage->specularScale[3] = (log2f(exponent + 2.0f) - 1.0f) / 12.0f;
+ }
}
//
// gloss <value>
//
else if (!Q_stricmp(token, "gloss"))
{
+ float gloss;
+
token = COM_ParseExt(text, qfalse);
if ( token[0] == 0 )
{
@@ -973,7 +979,38 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
continue;
}
- stage->specularScale[3] = atof( token );
+ gloss = atof(token);
+
+ if (r_glossIsRoughness->integer)
+ stage->specularScale[3] = exp2f(-3.0f * gloss);
+ else
+ stage->specularScale[3] = gloss;
+ }
+ //
+ // roughness <value>
+ //
+ else if (!Q_stricmp(token, "roughness"))
+ {
+ float roughness;
+
+ token = COM_ParseExt(text, qfalse);
+ if (token[0] == 0)
+ {
+ ri.Printf(PRINT_WARNING, "WARNING: missing parameter for roughness in shader '%s'\n", shader.name);
+ continue;
+ }
+
+ roughness = atof(token);
+
+ if (r_glossIsRoughness->integer)
+ stage->specularScale[3] = roughness;
+ else
+ {
+ if (roughness >= 0.125)
+ stage->specularScale[3] = log2f(1.0f / roughness) / 3.0f;
+ else
+ stage->specularScale[3] = 1.0f;
+ }
}
//
// parallaxDepth <value>