Skip to content

Commit

Permalink
MODERN: Make use of precalculated lm vlen in lightmap shader.
Browse files Browse the repository at this point in the history
Also better readability of using vec4 to match host side float[4], even if
alignment should have worked out just fine before.
  • Loading branch information
dsvensson committed Jan 24, 2025
1 parent 9e200ba commit feca102
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/glm_brushmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void GLM_CreateBrushModelVAO(void)
surfaces[i].normal[3] = surf->plane->dist;
memcpy(surfaces[i].lm_vecs0, surf->lmvecs[0], sizeof(surf->lmvecs[0]));
memcpy(surfaces[i].lm_vecs1, surf->lmvecs[1], sizeof(surf->lmvecs[1]));
surfaces[i].lm_vecs0[3] = surf->lmvlen[0];
surfaces[i].lm_vecs1[3] = surf->lmvlen[1];
}
buffers.Create(r_buffer_brushmodel_surface_data, buffertype_storage, "brushmodel-surfs", cl.worldmodel->numsurfaces * sizeof(vbo_world_surface_t), surfaces, bufferusage_constant_data);
Q_free(surfaces);
Expand Down
4 changes: 2 additions & 2 deletions src/glsl/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ struct AliasModel {

struct model_surface {
vec4 normal;
vec3 vecs0;
vec3 vecs1;
vec4 vecs0;
vec4 vecs1;
};
13 changes: 5 additions & 8 deletions src/glsl/lighting.compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ void main()
blocklight.a = 0;

vec4 Plane = surfaces[surfaceNumber].normal;
vec3 PlaneMins0 = surfaces[surfaceNumber].vecs0;
vec3 PlaneMins1 = surfaces[surfaceNumber].vecs1;
vec4 PlaneMins0 = surfaces[surfaceNumber].vecs0;
vec4 PlaneMins1 = surfaces[surfaceNumber].vecs1;

float vlen0 = length(PlaneMins0);
vlen0 = vlen0 > 0.0f ? 1.0f / vlen0 : 0;

float vlen1 = length(PlaneMins1);
vlen1 = vlen1 > 0.0f ? 1.0f / vlen1 : 0;
float vlen0 = PlaneMins0.w;
float vlen1 = PlaneMins1.w;

// Build static lights: default to black
vec4 baseLightmap = vec4(0, 0, 0, 0);
Expand Down Expand Up @@ -80,7 +77,7 @@ void main()
minlight = rad - minlight;

vec3 impact = lightPositions[i].xyz - Plane.xyz * dist;
vec2 local = vec2(dot(impact, PlaneMins0), dot(impact, PlaneMins1));
vec2 local = vec2(dot(impact, PlaneMins0.xyz), dot(impact, PlaneMins1.xyz));

int sd = int(abs(local[0] - sdelta) * vlen0); // sdelta = s * (1 << surf->lmshift) + surf->texturemins[0] - surf->lmvecs[0][3];
int td = int(abs(local[1] - tdelta) * vlen1); // tdelta = t * (1 << surf->lmshift) + surf->texturemins[1] - surf->lmvecs[1][3];
Expand Down

0 comments on commit feca102

Please sign in to comment.