diff --git a/engine/Makefile b/engine/Makefile index e0952fef..0d27df02 100644 --- a/engine/Makefile +++ b/engine/Makefile @@ -44,7 +44,7 @@ ifndef BUILD_DEFINES endif # ioquake3 svn version that this is based on -IOQ3_REVISION = 6920 +IOQ3_REVISION = 6925 ############################################################################# # diff --git a/engine/code/asm/vm_x86_64.asm b/engine/code/asm/vm_x86_64.asm index f39289ec..f84eb8f8 100644 --- a/engine/code/asm/vm_x86_64.asm +++ b/engine/code/asm/vm_x86_64.asm @@ -28,19 +28,35 @@ ; Call to compiled code after setting up the register environment for the VM ; prototype: ; uint8_t qvmcall64(int *programStack, int *opStack, intptr_t *instructionPointers, byte *dataBase); +; +; This call-stub has its own custom calling convention due to pushing all non-volatile registers +; to the stack. The game uses set/longjmp which on Windows uses "RtlUnwindEx" to unwind the callstack. +; This function cannot be unwound by default due to the custom calling convention. +; To allow unwinding, we need to add custom SEH unwind data to the function. -qvmcall64 PROC +qvmcall64 PROC FRAME push r12 ; push all non-volatile registers to stack + .pushreg r12 push r13 + .pushreg r13 push r14 + .pushreg r14 push r15 + .pushreg r15 push rdi + .pushreg rdi push rsi + .pushreg rsi push rbx + .pushreg rbx push rbp + .pushreg rbp ; need to save pointer in rcx so we can write back the programData value to caller push rcx + .pushreg rcx + + .endprolog ; custom unwind data ends here ; registers r8 and r9 have correct value already thanx to __fastcall xor rbx, rbx ; opStackOfs starts out being 0 diff --git a/engine/code/renderergl2/glsl/lightall_fp.glsl b/engine/code/renderergl2/glsl/lightall_fp.glsl index 26f9a995..28b59eb7 100644 --- a/engine/code/renderergl2/glsl/lightall_fp.glsl +++ b/engine/code/renderergl2/glsl/lightall_fp.glsl @@ -89,6 +89,9 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap) // current size of search window float size = 1.0 / float(linearSearchSteps); + // adjust position if offset above surface + dp -= ds * r_parallaxMapOffset; + // current depth position float depth = 0.0; @@ -141,7 +144,7 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap) } #endif - return bestDepth; + return bestDepth - r_parallaxMapOffset; } float LightRay(vec2 dp, vec2 ds, sampler2D normalMap) @@ -201,7 +204,7 @@ vec3 CalcSpecular(vec3 specular, float NH, float EH, float roughness) float rr = roughness*roughness; float rrrr = rr*rr; float d = (NH * NH) * (rrrr - 1.0) + 1.0; - float v = (EH * EH) * (roughness + 0.5); + float v = (EH * EH) * (roughness + 0.5) + EPSILON; return specular * (rrrr / (4.0 * d * d * v)); } @@ -261,7 +264,8 @@ void main() float NL, NH, NE, EH, attenuation; #if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) - mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz); + vec3 surfNormal = (!gl_FrontFacing ? var_Normal : -var_Normal).xyz; + mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, surfNormal); viewDir = vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w); E = normalize(viewDir); #endif @@ -332,7 +336,7 @@ void main() N.z = sqrt(clamp((0.25 - N.x * N.x) - N.y * N.y, 0.0, 1.0)); N = tangentToWorld * N; #else - N = var_Normal.xyz; + N = surfNormal; #endif N = normalize(N); @@ -358,7 +362,7 @@ void main() #if !defined(USE_LIGHT_VECTOR) ambientColor = lightColor; - float surfNL = clamp(dot(var_Normal.xyz, L), 0.0, 1.0); + float surfNL = clamp(dot(surfNormal, L), 0.0, 1.0); // reserve 25% ambient to avoid black areas on normalmaps lightColor *= 0.75; diff --git a/engine/code/renderergl2/tr_glsl.c b/engine/code/renderergl2/tr_glsl.c index 0d95d0df..86cca599 100644 --- a/engine/code/renderergl2/tr_glsl.c +++ b/engine/code/renderergl2/tr_glsl.c @@ -1125,6 +1125,8 @@ void GLSL_InitGPUShaders(void) if (r_parallaxMapShadows->integer) Q_strcat(extradefines, 1024, "#define USE_PARALLAXMAP_SHADOWS\n"); + + Q_strcat(extradefines, 1024, va("#define r_parallaxMapOffset %f\n", r_parallaxMapOffset->value)); } } diff --git a/engine/code/renderergl2/tr_init.c b/engine/code/renderergl2/tr_init.c index 6e502f58..945aa02c 100644 --- a/engine/code/renderergl2/tr_init.c +++ b/engine/code/renderergl2/tr_init.c @@ -132,6 +132,7 @@ cvar_t *r_normalMapping; cvar_t *r_specularMapping; cvar_t *r_deluxeMapping; cvar_t *r_parallaxMapping; +cvar_t *r_parallaxMapOffset; cvar_t *r_parallaxMapShadows; cvar_t *r_cubeMapping; cvar_t *r_cubemapSize; @@ -1243,6 +1244,7 @@ void R_Register( void ) r_specularMapping = ri.Cvar_Get( "r_specularMapping", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_deluxeMapping = ri.Cvar_Get( "r_deluxeMapping", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_parallaxMapping = ri.Cvar_Get( "r_parallaxMapping", "0", CVAR_ARCHIVE | CVAR_LATCH ); + r_parallaxMapOffset = ri.Cvar_Get( "r_parallaxMapOffset", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_parallaxMapShadows = ri.Cvar_Get( "r_parallaxMapShadows", "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 ); diff --git a/engine/code/renderergl2/tr_local.h b/engine/code/renderergl2/tr_local.h index 39f6f7a2..668dbbdd 100644 --- a/engine/code/renderergl2/tr_local.h +++ b/engine/code/renderergl2/tr_local.h @@ -1778,6 +1778,7 @@ extern cvar_t *r_normalMapping; extern cvar_t *r_specularMapping; extern cvar_t *r_deluxeMapping; extern cvar_t *r_parallaxMapping; +extern cvar_t *r_parallaxMapOffset; extern cvar_t *r_parallaxMapShadows; extern cvar_t *r_cubeMapping; extern cvar_t *r_cubemapSize; diff --git a/engine/docs/opengl2-readme.md b/engine/docs/opengl2-readme.md index c1a031c7..ee85c02c 100644 --- a/engine/docs/opengl2-readme.md +++ b/engine/docs/opengl2-readme.md @@ -184,6 +184,11 @@ Cvars for advanced material usage: 1 - Use parallax occlusion mapping. 2 - Use relief mapping. (slower) +* `r_parallaxMapOffset` - Set the parallax height offset. + 0 - Values map to -255 - 0. (default) + 0.5 - Values map to -127 - 127. + 1.0 - Values map to 0 - 255. + * `r_parallaxMapShadows` - Enable self-shadowing on parallax map supported materials. 0 - No. (default)