From 1ac5652bfe118c5db931d3d4a9c0c4758647b461 Mon Sep 17 00:00:00 2001 From: SomaZ <17459161+SomaZ@users.noreply.github.com> Date: Mon, 6 May 2024 20:56:28 +0200 Subject: [PATCH 1/5] [rend2] Fixing shaders spriteUbo again it's an UNsigned integer, make sure to use unsigned integers... related bad fix: 9a61f07f2763612c33d5948d13fb32344a66c6dc --- shared/rd-rend2/tr_bsp.cpp | 2 +- shared/rd-rend2/tr_shader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/rd-rend2/tr_bsp.cpp b/shared/rd-rend2/tr_bsp.cpp index 7208fb04e2..8af2e90921 100644 --- a/shared/rd-rend2/tr_bsp.cpp +++ b/shared/rd-rend2/tr_bsp.cpp @@ -4017,7 +4017,7 @@ static void R_GenerateSurfaceSprites( const world_t *world, int worldIndex ) for (int i = 0; i < tr.numShaders; i++) { const shader_t *shader = tr.shaders[i]; - if (shader->spriteUbo != -1) + if (shader->spriteUbo != 0) continue; numSpriteStages += shader->numSurfaceSpriteStages; diff --git a/shared/rd-rend2/tr_shader.cpp b/shared/rd-rend2/tr_shader.cpp index 6991eef201..1f6556b5b0 100644 --- a/shared/rd-rend2/tr_shader.cpp +++ b/shared/rd-rend2/tr_shader.cpp @@ -3810,7 +3810,7 @@ static shader_t *GeneratePermanentShader( void ) { } RB_AddShaderToShaderInstanceUBO(newShader); - newShader->spriteUbo = -1; + newShader->spriteUbo = 0; SortNewShader(); From 6029f910f2940ff45af201f377559856c1d83052 Mon Sep 17 00:00:00 2001 From: SomaZ <17459161+SomaZ@users.noreply.github.com> Date: Tue, 14 May 2024 00:58:52 +0200 Subject: [PATCH 2/5] [rend2] Fix korriban shaders with multiply blend stages Stages that are used to get some more detail shouldnt be collapsed with lighting because it will multiply lighting again and again which leads to incorrect darkening --- shared/rd-rend2/tr_shader.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/rd-rend2/tr_shader.cpp b/shared/rd-rend2/tr_shader.cpp index 1f6556b5b0..74510362b1 100644 --- a/shared/rd-rend2/tr_shader.cpp +++ b/shared/rd-rend2/tr_shader.cpp @@ -3372,6 +3372,14 @@ static qboolean CollapseStagesToGLSL(void) if (pStage->bundle[0].tcGen >= TCGEN_LIGHTMAP && pStage->bundle[0].tcGen <= TCGEN_LIGHTMAP3) continue; + if (i > 0) + { + int blendBits = pStage->stateBits & (GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS); + if (blendBits == (GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO) || + blendBits == (GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR)) + continue; + } + diffuse = pStage; parallax = qfalse; lightmap = NULL; From 574197f1c103b7c6c2c07e52eab9fc3ace786e1a Mon Sep 17 00:00:00 2001 From: SomaZ <17459161+SomaZ@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:27:26 +0200 Subject: [PATCH 3/5] [rend2] Fix alpha test issue on lighted surfaces with tcMods --- shared/rd-rend2/tr_shade.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shared/rd-rend2/tr_shade.cpp b/shared/rd-rend2/tr_shade.cpp index c694dc56e5..9f87005a97 100644 --- a/shared/rd-rend2/tr_shade.cpp +++ b/shared/rd-rend2/tr_shade.cpp @@ -1256,6 +1256,9 @@ static shaderProgram_t *SelectShaderProgram( int stageIndex, shaderStage_t *stag { index |= LIGHTDEF_USE_ALPHA_TEST; }*/ + + if (stage->bundle[0].tcGen != TCGEN_TEXTURE || (stage->bundle[0].numTexMods)) + index |= LIGHTDEF_USE_TCGEN_AND_TCMOD; // TODO: remove light vertex def and fix parallax usage on unlit stages like glow stages if (stage->glslShaderIndex & LIGHTDEF_USE_PARALLAXMAP && From aac82ec393c6d5184ef488821b33ef32f29fad5f Mon Sep 17 00:00:00 2001 From: SomaZ <17459161+SomaZ@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:36:59 +0200 Subject: [PATCH 4/5] [rend2] Fix surface sprites vertex colors behaviour Vanilla doesn't use rgbGens for surface sprites, only the approximated lighting from the emitting surfaces vertex colors. --- shared/rd-rend2/tr_bsp.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shared/rd-rend2/tr_bsp.cpp b/shared/rd-rend2/tr_bsp.cpp index 8af2e90921..1971c62a5d 100644 --- a/shared/rd-rend2/tr_bsp.cpp +++ b/shared/rd-rend2/tr_bsp.cpp @@ -3823,7 +3823,8 @@ static int R_CreateSurfaceSpritesVertexData( const srfVert_t *verts = bspSurf->verts; const glIndex_t *indexes = bspSurf->indexes; - vec4_t color = { 1.0, 1.0, 1.0, 1.0 }; +#if 0 + vec4_t color = { 1.0f, 1.0f, 1.0f, 1.0f }; if (stage->rgbGen == CGEN_CONST) { color[0] = stage->constantColor[0]; @@ -3835,6 +3836,13 @@ static int R_CreateSurfaceSpritesVertexData( stage->rgbGen == CGEN_EXACT_VERTEX || stage->rgbGen == CGEN_VERTEX_LIT || stage->rgbGen == CGEN_EXACT_VERTEX_LIT); +#else + // Vanilla behaviour is always: color by vertex color of the emitting surface + // even just the blue component used for all three color channels to be exact + // in pseudo code: outVert.rgb = inVert.bbb; + bool vertexLit = true; + vec4_t color = { 1.0f, 1.0f, 1.0f, 1.0f }; +#endif int numSprites = 0; for ( int i = 0, numIndexes = bspSurf->numIndexes; i < numIndexes; i += 3 ) From 664bab7ceccecb8d0f9475077731c35499e5e871 Mon Sep 17 00:00:00 2001 From: SomaZ <17459161+SomaZ@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:47:21 +0200 Subject: [PATCH 5/5] [rend2-sp] Fix G2API_SetNewOrigin incorrect drop error Fixes https://github.com/SomaZ/OpenJK/issues/54 Co-Authored-By: AntiAnti <17278566+antianti@users.noreply.github.com> --- code/rd-rend2/G2_API.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/code/rd-rend2/G2_API.cpp b/code/rd-rend2/G2_API.cpp index babe6f0534..5a290a7423 100644 --- a/code/rd-rend2/G2_API.cpp +++ b/code/rd-rend2/G2_API.cpp @@ -2201,23 +2201,12 @@ qboolean G2API_SetNewOrigin(CGhoul2Info* ghlInfo, const int boltIndex) { if (G2_SetupModelPointers(ghlInfo)) { - if (boltIndex < 0) + // check for valid boltIndex before applying new origin + if (boltIndex >= 0 && boltIndex < (int)ghlInfo->mBltlist.size()) { - char modelName[MAX_QPATH]; - if (ghlInfo->currentModel && ghlInfo->currentModel->name[0]) - { - strcpy(modelName, ghlInfo->currentModel->name); - } - else - { - strcpy(modelName, "[Unknown - unexpected]"); - } - - Com_Error(ERR_DROP, "Bad boltindex (%i) trying to SetNewOrigin (naughty naughty!)\nModel %s\n", boltIndex, modelName); + ghlInfo->mNewOrigin = boltIndex; + ghlInfo->mFlags |= GHOUL2_NEWORIGIN; } - - ghlInfo->mNewOrigin = boltIndex; - ghlInfo->mFlags |= GHOUL2_NEWORIGIN; return qtrue; } return qfalse;