Skip to content

Commit

Permalink
Rend2 upstream updates (#189)
Browse files Browse the repository at this point in the history
* [rend2] Fixing local position based rgb and tc Gens

Broke some in SomaZ@a257512#diff-f17621117755ac0b403c963e0eb2d08e8fb088bc6b32c0d077915b71bd93311c

* [rend2] Fix parallax mapping on alpha tested stages

The parallax offset simply never got applied to the prepass, which created a mismatch between depth and actual stage rendering.

* [rend2] Match glsl files to upstream

* [Shared] Fixup renderer naming inconsistencies since project rebrand

---------

Co-authored-by: SomaZ <[email protected]>
  • Loading branch information
taysta and SomaZ authored Apr 24, 2024
1 parent 258031c commit 0f18e9e
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 57 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ option(BuildPortableVersion "Build portable version (does not read or write file

option(BuildMPEngine "Whether to create projects for the MP client (taystjk.x86.exe)" ON)
option(BuildMPRdVanilla "Whether to create projects for the MP default renderer (rd-taystjk_x86.dll)" ON)
option(BuildMPRdVulkan "Whether to create projects for the MP vulkan renderer (rd-vulkan_x86.dll)" ON)
option(BuildMPRdVulkan "Whether to create projects for the MP vulkan renderer (rd-vulkant_x86.dll)" ON)
option(BuildMPDed "Whether to create projects for the MP dedicated server (taystjkded.exe)" ON)
option(BuildMPGame "Whether to create projects for the MP server-side gamecode (jampgamex86.dll)" ON)
option(BuildMPCGame "Whether to create projects for the MP clientside gamecode (cgamex86.dll)" ON)
option(BuildMPUI "Whether to create projects for the MP UI code (uix86.dll)" ON)
option(BuildMPRend2 "Whether to create projects for the EXPERIMENTAL MP rend2 renderer (rd-rend2e_x86.dll)" ON)
option(BuildMPRend2 "Whether to create projects for the EXPERIMENTAL MP rend2 renderer (rd-rend2t_x86.dll)" ON)

option(BuildDiscordRichPresence "Whether to build with Discord Rich Presence integration" ON)

Expand Down
4 changes: 2 additions & 2 deletions assets/japro/ui/jamp/ingame_setup.menu
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@
visible 0
descText "Configure rend2 video options"
cvarTest "cl_renderer"
hideCvar { "rd-taystjk" , "rd-vulkan" }
hideCvar { "rd-taystjk" , "rd-vulkant" }

action
{
Expand Down Expand Up @@ -1676,7 +1676,7 @@
visible 0
descText "Rend2 video settings"
cvarTest "cl_renderer"
hideCvar { "rd-taystjk" , "rd-vulkan" }
hideCvar { "rd-taystjk" , "rd-vulkant" }

action
{
Expand Down
4 changes: 2 additions & 2 deletions assets/japro/ui/jamp/setup.menu
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@
visible 0
descText "Advanced video settings"
cvarTest "cl_renderer"
hideCvar { "rd-taystjk" , "rd-vulkan" }
hideCvar { "rd-taystjk" , "rd-vulkant" }

action
{
Expand Down Expand Up @@ -1465,7 +1465,7 @@
visible 0
descText "Advanced video settings"
cvarTest "cl_renderer"
hideCvar { "rd-taystjk" , "rd-vulkan" }
hideCvar { "rd-taystjk" , "rd-vulkant" }

action
{
Expand Down
6 changes: 3 additions & 3 deletions codemp/ui/ui_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6222,7 +6222,7 @@ void UI_UpdateVideoSetup ( void )
trap->Cvar_Set ( "cg_shadows", UI_Cvar_VariableString ( "ui_cg_shadows" ) );
//Rend2 menu
trap->Cvar_Set ( "cl_renderer", UI_Cvar_VariableString ( "ui_cl_renderer" ) );
if (!Q_stricmp(UI_Cvar_VariableString ( "ui_cl_renderer" ), "rd-rend2e")) {
if (!Q_stricmp(UI_Cvar_VariableString ( "ui_cl_renderer" ), "rd-rend2t")) {
trap->Cvar_Set ( "r_hdr", UI_Cvar_VariableString ( "ui_r_hdr" ) );
trap->Cvar_Set ( "r_tonemap", UI_Cvar_VariableString ( "ui_r_tonemap" ) );
trap->Cvar_Set ( "r_autoexposure", UI_Cvar_VariableString ( "ui_r_autoexposure" ) );
Expand Down Expand Up @@ -6350,7 +6350,7 @@ void UI_GetVideoSetup ( void )
//Rend2 menu
trap->Cvar_Register ( NULL, "ui_cl_renderer", "0", CVAR_ROM|CVAR_INTERNAL );
trap->Cvar_Set ( "ui_cl_renderer", UI_Cvar_VariableString ( "cl_renderer" ) );
if (!Q_stricmp(UI_Cvar_VariableString ( "ui_cl_renderer" ), "rd-rend2e")) {
if (!Q_stricmp(UI_Cvar_VariableString ( "ui_cl_renderer" ), "rd-rend2t")) {
trap->Cvar_Register ( NULL, "ui_r_hdr", "0", CVAR_ROM|CVAR_INTERNAL );
trap->Cvar_Register ( NULL, "ui_r_tonemap", "0", CVAR_ROM|CVAR_INTERNAL );
trap->Cvar_Register ( NULL, "ui_r_autoexposure", "0", CVAR_ROM|CVAR_INTERNAL );
Expand Down Expand Up @@ -6393,7 +6393,7 @@ void UI_GetVideoSetup ( void )
trap->Cvar_Set ( "ui_r_allowExtensions", UI_Cvar_VariableString ( "r_allowExtensions" ) );
trap->Cvar_Set ( "ui_cg_shadows", UI_Cvar_VariableString ( "cg_shadows" ) );
//Rend2 menu
if (!Q_stricmp(UI_Cvar_VariableString ( "ui_cl_renderer" ), "rd-rend2e")) {
if (!Q_stricmp(UI_Cvar_VariableString ( "ui_cl_renderer" ), "rd-rend2t")) {
trap->Cvar_Set ( "ui_r_hdr", UI_Cvar_VariableString ( "r_hdr" ) );
trap->Cvar_Set ( "ui_r_tonemap", UI_Cvar_VariableString ( "r_tonemap" ) );
trap->Cvar_Set ( "ui_r_autoexposure", UI_Cvar_VariableString ( "r_autoexposure" ) );
Expand Down
12 changes: 5 additions & 7 deletions shared/rd-rend2/glsl/fogpass.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
};

layout(std140) uniform ShaderInstance
Expand Down Expand Up @@ -226,10 +225,10 @@ void main()
normal = DeformNormal( position, normal );
#endif

mat4 MVP = u_viewProjectionMatrix * u_ModelMatrix;
gl_Position = MVP * vec4(position, 1.0);
vec4 wsPosition = u_ModelMatrix * vec4(position, 1.0);
gl_Position = u_viewProjectionMatrix * wsPosition;

var_WSPosition = (u_ModelMatrix * vec4(position, 1.0)).xyz;
var_WSPosition = wsPosition.xyz;
#if defined(USE_ALPHA_TEST)
var_TexCoords = attr_TexCoord0;
#endif
Expand Down Expand Up @@ -281,12 +280,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
};

uniform int u_FogIndex;
Expand Down
28 changes: 14 additions & 14 deletions shared/rd-rend2/glsl/generic.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
float u_entityTime;
};

#if defined(USE_DEFORM_VERTEXES) || defined(USE_RGBAGEN)
Expand Down Expand Up @@ -285,7 +283,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED:
{
vec3 viewer = normalize(u_LocalViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).yz;
tex.s = ref.x * -0.5 + 0.5;
tex.t = ref.y * 0.5 + 0.5;
Expand All @@ -294,7 +293,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED_SP:
{
vec3 viewer = normalize(u_LocalViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).xy;
tex.s = ref.x * -0.5;
tex.t = ref.y * -0.5;
Expand Down Expand Up @@ -381,10 +381,12 @@ vec4 CalcColor(vec3 position, vec3 normal)
return color;
}

vec3 viewer = u_LocalViewOrigin - position;
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = localOrigin - position;

if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
{
// TODO: Handle specular on player models and misc_model_statics correctly
vec3 lightDir = normalize(vec3(-960.0, 1980.0, 96.0) - position);
vec3 reflected = -reflect(lightDir, normal);

Expand Down Expand Up @@ -438,11 +440,11 @@ void main()
normal = DeformNormal( position, normal );
#endif

mat4 MVP = u_viewProjectionMatrix * u_ModelMatrix;
gl_Position = MVP * vec4(position, 1.0);
vec4 wsPosition = u_ModelMatrix * vec4(position, 1.0);
gl_Position = u_viewProjectionMatrix * wsPosition;

#if defined(USE_TCGEN)
vec2 tex = GenTexCoords(u_TCGen0, position, normal, u_TCGen0Vector0, u_TCGen0Vector1);
vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
#else
vec2 tex = attr_TexCoord0.st;
#endif
Expand All @@ -465,14 +467,14 @@ void main()
else
{
#if defined(USE_RGBAGEN)
var_Color = CalcColor(position, normal);
var_Color = CalcColor(position.xyz, normal);
#else
var_Color = u_VertColor * attr_Color + u_BaseColor;
#endif
}

#if defined(USE_FOG)
var_WSPosition = (u_ModelMatrix * vec4(position, 1.0)).xyz;
var_WSPosition = wsPosition.xyz;
#endif
}

Expand Down Expand Up @@ -509,13 +511,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
float u_entityTime;
};

uniform sampler2D u_DiffuseMap;
Expand Down
23 changes: 11 additions & 12 deletions shared/rd-rend2/glsl/lightall.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
float u_entityTime;
};

#if defined(USE_SKELETAL_ANIMATION)
Expand Down Expand Up @@ -159,7 +157,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED:
{
vec3 viewer = normalize(u_LocalViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).yz;
tex.s = ref.x * -0.5 + 0.5;
tex.t = ref.y * 0.5 + 0.5;
Expand All @@ -168,7 +167,8 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3

case TCGEN_ENVIRONMENT_MAPPED_SP:
{
vec3 viewer = normalize(u_LocalViewOrigin - position);
vec3 localOrigin = (inverse(u_ModelMatrix) * vec4(u_ViewOrigin, 1.0)).xyz;
vec3 viewer = normalize(localOrigin - position);
vec2 ref = reflect(viewer, normal).xy;
tex.s = ref.x * -0.5;
tex.t = ref.y * -0.5;
Expand Down Expand Up @@ -258,8 +258,10 @@ void main()
#endif
#endif

vec4 wsPosition = u_ModelMatrix * vec4(position, 1.0);

#if defined(USE_TCGEN)
vec2 texCoords = GenTexCoords(u_TCGen0, position, normal, u_TCGen0Vector0, u_TCGen0Vector1);
vec2 texCoords = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
#else
vec2 texCoords = attr_TexCoord0.st;
#endif
Expand All @@ -272,10 +274,9 @@ void main()

vec4 disintegration = CalcColor(position);

mat4 MVP = u_viewProjectionMatrix * u_ModelMatrix;
gl_Position = MVP * vec4(position, 1.0);
gl_Position = u_viewProjectionMatrix * wsPosition;

position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
position = wsPosition.xyz;
normal = normalize(mat3(u_ModelMatrix) * normal);
#if defined(PER_PIXEL_LIGHTING)
tangent = normalize(mat3(u_ModelMatrix) * tangent);
Expand Down Expand Up @@ -367,13 +368,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
float u_entityTime;
};

struct Light
Expand Down
23 changes: 9 additions & 14 deletions shared/rd-rend2/glsl/refraction.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
float u_entityTime;
};

#if defined(USE_DEFORM_VERTEXES) || defined(USE_RGBAGEN)
Expand Down Expand Up @@ -231,14 +229,14 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
}
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
{
vec3 viewer = normalize(u_LocalViewOrigin - position);
vec3 viewer = normalize(u_ViewOrigin - position);
vec2 ref = reflect(viewer, normal).yz;
tex.s = ref.x * -0.5 + 0.5;
tex.t = ref.y * 0.5 + 0.5;
}
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED_SP)
{
vec3 viewer = normalize(u_LocalViewOrigin - position);
vec3 viewer = normalize(u_ViewOrigin - position);
vec2 ref = reflect(viewer, normal).xy;
tex.s = ref.x * -0.5;
tex.t = ref.y * -0.5;
Expand Down Expand Up @@ -288,7 +286,7 @@ vec4 CalcColor(vec3 position, vec3 normal)
color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0);
}

vec3 viewer = u_LocalViewOrigin - position;
vec3 viewer = u_ViewOrigin - position;

if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
{
Expand Down Expand Up @@ -354,7 +352,7 @@ void main()
gl_Position = MVP * vec4(position, 1.0);

#if defined(USE_TCGEN)
vec2 tex = GenTexCoords(u_TCGen0, position, normal, u_TCGen0Vector0, u_TCGen0Vector1);
vec2 tex = GenTexCoords(u_TCGen0, wsPosition.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
#else
vec2 tex = attr_TexCoord0.st;
#endif
Expand Down Expand Up @@ -383,7 +381,6 @@ void main()
#endif
}

vec3 ws_Position = mat3(u_ModelMatrix) * position;
vec3 ws_Normal = normalize(mat3(u_ModelMatrix) * normal);
vec3 ws_ViewDir = (u_ViewForward + u_ViewLeft * -gl_Position.x) + u_ViewUp * gl_Position.y;

Expand All @@ -396,17 +393,17 @@ void main()
mat3 inverseModel = inverse(mat3(u_ModelMatrix));

vec3 refraction_vec = normalize(refract(ws_ViewDir, ws_Normal, etaR));
vec3 new_pos = (distance * refraction_vec) + ws_Position;
vec3 new_pos = (distance * refraction_vec) + wsPosition.xyz;
var_RefractPosR = vec4(inverseModel * new_pos, 1.0);
var_RefractPosR = MVP * var_RefractPosR;

refraction_vec = normalize(refract(ws_ViewDir, ws_Normal, etaG));
new_pos = (distance * refraction_vec) + ws_Position;
new_pos = (distance * refraction_vec) + wsPosition.xyz;
var_RefractPosG = vec4(inverseModel * new_pos, 1.0);
var_RefractPosG = MVP * var_RefractPosG;

refraction_vec = normalize(refract(ws_ViewDir, ws_Normal, etaB));
new_pos = (distance * refraction_vec) + ws_Position;
new_pos = (distance * refraction_vec) + wsPosition.xyz;
var_RefractPosB = vec4(inverseModel * new_pos, 1.0);
var_RefractPosB = MVP * var_RefractPosB;
}
Expand All @@ -429,13 +426,11 @@ layout(std140) uniform Entity
mat4 u_ModelMatrix;
vec4 u_LocalLightOrigin;
vec3 u_AmbientLight;
float u_LocalLightRadius;
float u_entityTime;
vec3 u_DirectedLight;
float u_FXVolumetricBase;
vec3 u_ModelLightDir;
float u_VertexLerp;
vec3 u_LocalViewOrigin;
float u_entityTime;
};

uniform sampler2D u_TextureMap;
Expand Down
2 changes: 1 addition & 1 deletion shared/rd-rend2/glsl/shadowvolume.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void main()
u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[1] - L, 1.0),
u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[2] - L, 1.0)
);

// front cap, avoids z-fighting with other shaders by NOT using the MVP, the other surfaces won't create z-fighting
gl_Position = positions[0];
EmitVertex();
Expand Down
Loading

0 comments on commit 0f18e9e

Please sign in to comment.