Skip to content

Commit

Permalink
Merge branch 'rend2-unified-wip' into rend2-builds
Browse files Browse the repository at this point in the history
  • Loading branch information
SomaZ committed Feb 19, 2024
2 parents b8a9537 + 05415f8 commit a35e31a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
6 changes: 3 additions & 3 deletions shared/rd-rend2/glsl/refraction.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ void main()
normal = DeformNormal( position, normal );
#endif

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

#if defined(USE_TCGEN)
vec2 tex = GenTexCoords(u_TCGen0, wsPosition.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
Expand Down Expand Up @@ -390,7 +391,6 @@ void main()
#endif

mat3 inverseModel = inverse(mat3(u_ModelMatrix));
mat4 MVP = u_viewProjectionMatrix * u_ModelMatrix;

vec3 refraction_vec = normalize(refract(ws_ViewDir, ws_Normal, etaR));
vec3 new_pos = (distance * refraction_vec) + wsPosition.xyz;
Expand Down
66 changes: 44 additions & 22 deletions shared/rd-rend2/glsl/shadowvolume.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,6 @@ layout(std140) uniform Entity

in vec3 var_Position[];

void quad(in vec3 first, in vec3 second, in vec3 L, in mat4 MVP)
{
gl_Position = MVP * vec4(first, 1.0);
EmitVertex();
gl_Position = MVP * vec4(first - L, 1.0);
EmitVertex();
gl_Position = MVP * vec4(second, 1.0);
EmitVertex();
gl_Position = MVP * vec4(second - L, 1.0);
EmitVertex();
EndPrimitive();
}

void main()
{
vec3 BmA = var_Position[1].xyz - var_Position[0].xyz;
Expand All @@ -106,27 +93,62 @@ void main()

if (dot(cross(BmA,CmA), -u_ModelLightDir.xyz) > 0.0) {
vec3 L = u_ModelLightDir.xyz*u_LocalLightOrigin.w;

vec4 positions[6] = vec4[6](
u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[0], 1.0),
u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[1], 1.0),
u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[2], 1.0),
u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[0] - L, 1.0),
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 = u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[0].xyz, 1.0);
gl_Position = positions[0];
EmitVertex();
gl_Position = u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[1].xyz, 1.0);
gl_Position = positions[1];
EmitVertex();
gl_Position = u_viewProjectionMatrix * u_ModelMatrix * vec4(var_Position[2].xyz, 1.0);
gl_Position = positions[2];
EmitVertex();
EndPrimitive();

// sides
quad(var_Position[0], var_Position[1], L, MVP);
quad(var_Position[1], var_Position[2], L, MVP);
quad(var_Position[2], var_Position[0], L, MVP);
gl_Position = positions[0];
EmitVertex();
gl_Position = positions[3];
EmitVertex();
gl_Position = positions[1];
EmitVertex();
gl_Position = positions[4];
EmitVertex();
EndPrimitive();

gl_Position = positions[1];
EmitVertex();
gl_Position = positions[4];
EmitVertex();
gl_Position = positions[2];
EmitVertex();
gl_Position = positions[5];
EmitVertex();
EndPrimitive();

gl_Position = positions[2];
EmitVertex();
gl_Position = positions[5];
EmitVertex();
gl_Position = positions[0];
EmitVertex();
gl_Position = positions[3];
EmitVertex();
EndPrimitive();

// back cap
gl_Position = MVP * vec4(var_Position[2].xyz - L, 1.0);
gl_Position = positions[5];
EmitVertex();
gl_Position = MVP * vec4(var_Position[1].xyz - L, 1.0);
gl_Position = positions[4];
EmitVertex();
gl_Position = MVP * vec4(var_Position[0].xyz - L, 1.0);
gl_Position = positions[3];
EmitVertex();
EndPrimitive();
}
Expand Down
2 changes: 1 addition & 1 deletion shared/rd-rend2/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@ static void R_LoadSubmodels( world_t *worldData, int worldIndex, lump_t *l ) {
model->data.bmodel = out;
if (worldIndex >= 0)
{
Com_sprintf( model->name, sizeof( model->name ), "*%d-%d", worldIndex, i );
Com_sprintf( model->name, sizeof( model->name ), "*%d-%d", worldIndex+1, i );
}
else
{
Expand Down
3 changes: 0 additions & 3 deletions shared/rd-rend2/tr_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,12 +1917,9 @@ static void R_AddEntitySurface(const trRefdef_t *refdef, trRefEntity_t *ent, int
case RT_ORIENTED_QUAD:
case RT_ELECTRICITY:
case RT_LINE:
#ifndef REND2_SP
case RT_ORIENTEDLINE:
#else
case RT_LATHE:
case RT_CLOUDS:
#endif
case RT_CYLINDER:
case RT_SABER_GLOW:
// self blood sprites, talk balloons, etc should not be drawn in the primary
Expand Down
2 changes: 1 addition & 1 deletion shared/rd-rend2/tr_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static qhandle_t RE_RegisterBSP(const char *name)
}

char bspModelIdent[MAX_QPATH];
Com_sprintf(bspModelIdent, sizeof(bspModelIdent), "*%d-0", bspIndex);
Com_sprintf(bspModelIdent, sizeof(bspModelIdent), "*%d-0", bspIndex+1);

qhandle_t modelHandle = CModelCache->GetModelHandle(bspModelIdent);
if (modelHandle == -1)
Expand Down

0 comments on commit a35e31a

Please sign in to comment.