From c0c45d325df8abeec7239ba600f6b23de1848d9c Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Mon, 14 May 2018 18:30:59 -0700 Subject: [PATCH] OpenGL2: Readd r_deluxeSpecular. https://github.com/ioquake/ioq3/issues/369 --- code/renderergl2/glsl/lightall_fp.glsl | 11 +++++++++++ code/renderergl2/tr_glsl.c | 2 ++ code/renderergl2/tr_init.c | 2 ++ code/renderergl2/tr_local.h | 1 + 4 files changed, 16 insertions(+) diff --git a/code/renderergl2/glsl/lightall_fp.glsl b/code/renderergl2/glsl/lightall_fp.glsl index 8e7c9b4a..6465bd84 100644 --- a/code/renderergl2/glsl/lightall_fp.glsl +++ b/code/renderergl2/glsl/lightall_fp.glsl @@ -309,6 +309,9 @@ void main() NL = clamp(dot(N, L), 0.0, 1.0); NE = clamp(dot(N, E), 0.0, 1.0); + H = normalize(L + E); + EH = clamp(dot(E, H), 0.0, 1.0); + NH = clamp(dot(N, H), 0.0, 1.0); #if defined(USE_SPECULARMAP) vec4 specular = texture2D(u_SpecularMap, texCoords); @@ -351,6 +354,14 @@ void main() reflectance = CalcDiffuse(diffuse.rgb, NH, EH, roughness); + #if defined(r_deluxeSpecular) + #if defined(USE_LIGHT_VECTOR) + reflectance += CalcSpecular(specular.rgb, NH, EH, roughness) * r_deluxeSpecular; + #else + reflectance += CalcSpecular(specular.rgb, NH, EH, pow(roughness, r_deluxeSpecular)); + #endif + #endif + gl_FragColor.rgb = lightColor * reflectance * (attenuation * NL); gl_FragColor.rgb += ambientColor * diffuse.rgb; diff --git a/code/renderergl2/tr_glsl.c b/code/renderergl2/tr_glsl.c index 70ad8165..5de135be 100644 --- a/code/renderergl2/tr_glsl.c +++ b/code/renderergl2/tr_glsl.c @@ -1067,6 +1067,8 @@ void GLSL_InitGPUShaders(void) if (r_cubeMapping->integer) Q_strcat(extradefines, 1024, "#define USE_CUBEMAP\n"); + else if (r_deluxeSpecular->value > 0.000001f) + Q_strcat(extradefines, 1024, va("#define r_deluxeSpecular %f\n", r_deluxeSpecular->value)); switch (r_glossType->integer) { diff --git a/code/renderergl2/tr_init.c b/code/renderergl2/tr_init.c index 2a91d538..4cd0273b 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -133,6 +133,7 @@ cvar_t *r_deluxeMapping; cvar_t *r_parallaxMapping; cvar_t *r_cubeMapping; cvar_t *r_cubemapSize; +cvar_t *r_deluxeSpecular; cvar_t *r_pbr; cvar_t *r_baseNormalX; cvar_t *r_baseNormalY; @@ -1229,6 +1230,7 @@ void R_Register( void ) r_parallaxMapping = ri.Cvar_Get( "r_parallaxMapping", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_cubeMapping = ri.Cvar_Get( "r_cubeMapping", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_cubemapSize = ri.Cvar_Get( "r_cubemapSize", "128", CVAR_ARCHIVE | CVAR_LATCH ); + r_deluxeSpecular = ri.Cvar_Get("r_deluxeSpecular", "0.3", CVAR_ARCHIVE | CVAR_LATCH); r_pbr = ri.Cvar_Get("r_pbr", "0", CVAR_ARCHIVE | CVAR_LATCH); r_baseNormalX = ri.Cvar_Get( "r_baseNormalX", "1.0", CVAR_ARCHIVE | CVAR_LATCH ); r_baseNormalY = ri.Cvar_Get( "r_baseNormalY", "1.0", CVAR_ARCHIVE | CVAR_LATCH ); diff --git a/code/renderergl2/tr_local.h b/code/renderergl2/tr_local.h index 238fb075..15ddae65 100644 --- a/code/renderergl2/tr_local.h +++ b/code/renderergl2/tr_local.h @@ -1718,6 +1718,7 @@ extern cvar_t *r_deluxeMapping; extern cvar_t *r_parallaxMapping; extern cvar_t *r_cubeMapping; extern cvar_t *r_cubemapSize; +extern cvar_t *r_deluxeSpecular; extern cvar_t *r_pbr; extern cvar_t *r_baseNormalX; extern cvar_t *r_baseNormalY;