OpenGL2: Use correct sunlight color for sunlight specular.

This commit is contained in:
SmileTheory 2015-12-09 05:25:58 -08:00
parent 08ecc3a80a
commit c07cc282d0
2 changed files with 18 additions and 26 deletions

View file

@ -361,13 +361,6 @@ void main()
#endif
reflectance = CalcDiffuse(diffuse.rgb, EH, NH, roughness);
#if defined(USE_SHADOWMAP) && defined(SHADOWMAP_MODULATE)
// bit of a hack, with modulated shadowmaps, add specular to sunlight
H = normalize(var_PrimaryLightDir.xyz + E);
EH = clamp(dot(E, H), 0.0, 1.0);
NH = clamp(dot(N, H), 0.0, 1.0);
reflectance += shadowValue * CalcSpecular(specular.rgb, NH, NL, NE, EH, roughness);
#endif
gl_FragColor.rgb = lightColor * reflectance * (attenuation * NL);
gl_FragColor.rgb += ambientColor * (diffuse.rgb + specular.rgb);
@ -403,7 +396,7 @@ void main()
gl_FragColor.rgb += cubeLightColor * reflectance;
#endif
#if defined(USE_PRIMARY_LIGHT)
#if defined(USE_PRIMARY_LIGHT) || defined(SHADOWMAP_MODULATE)
vec3 L2, H2;
float NL2, EH2, NH2;
@ -419,10 +412,14 @@ void main()
EH2 = clamp(dot(E, H2), 0.0, 1.0);
NH2 = clamp(dot(N, H2), 0.0, 1.0);
reflectance = CalcDiffuse(diffuse.rgb, EH2, NH2, roughness);
reflectance += CalcSpecular(specular.rgb, NH2, NL2, NE, EH2, roughness);
reflectance = CalcSpecular(specular.rgb, NH2, NL2, NE, EH2, roughness);
lightColor = u_PrimaryLightColor * var_Color.rgb;
// bit of a hack, with modulated shadowmaps, ignore diffuse
#if !defined(SHADOWMAP_MODULATE)
reflectance += CalcDiffuse(diffuse.rgb, EH2, NH2, roughness);
#endif
lightColor = u_PrimaryLightColor;
#if defined(r_lightGamma)
lightColor = pow(lightColor, vec3(r_lightGamma));

View file

@ -335,35 +335,30 @@ void RE_BeginScene(const refdef_t *fd)
}
else
{
#if defined(USE_OVERBRIGHT)
float scale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8);
#else
float scale = (1 << r_mapOverBrightBits->integer) / 255.0f;
#endif
tr.refdef.colorScale = r_forceSun->integer ? r_forceSunMapLightScale->value : tr.mapLightScale;
if (r_forceSun->integer)
VectorScale(tr.sunLight, scale * r_forceSunLightScale->value, tr.refdef.sunCol);
else
VectorScale(tr.sunLight, scale, tr.refdef.sunCol);
if (r_sunlightMode->integer == 1)
{
tr.refdef.sunCol[0] =
tr.refdef.sunCol[1] =
tr.refdef.sunCol[2] = 1.0f;
tr.refdef.sunAmbCol[0] =
tr.refdef.sunAmbCol[1] =
tr.refdef.sunAmbCol[2] = r_forceSun->integer ? r_forceSunAmbientScale->value : tr.sunShadowScale;
}
else
{
#if defined(USE_OVERBRIGHT)
float scale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8);
#else
float scale = (1 << r_mapOverBrightBits->integer) / 255.0f;
#endif
if (r_forceSun->integer)
{
VectorScale(tr.sunLight, scale * r_forceSunLightScale->value, tr.refdef.sunCol);
VectorScale(tr.sunLight, scale * r_forceSunAmbientScale->value, tr.refdef.sunAmbCol);
}
else
{
VectorScale(tr.sunLight, scale, tr.refdef.sunCol);
VectorScale(tr.sunLight, scale * tr.sunShadowScale, tr.refdef.sunAmbCol);
}
}
}