quake2ts 0.0.234 → 0.0.235

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4932,6 +4932,7 @@ precision highp float;
4932
4932
  layout(location = 0) in vec3 a_position;
4933
4933
  layout(location = 1) in vec2 a_texCoord;
4934
4934
  layout(location = 2) in vec2 a_lightmapCoord;
4935
+ layout(location = 3) in float a_lightmapStep;
4935
4936
 
4936
4937
  uniform mat4 u_modelViewProjection;
4937
4938
  uniform vec2 u_texScroll;
@@ -4939,6 +4940,7 @@ uniform vec2 u_lightmapScroll;
4939
4940
 
4940
4941
  out vec2 v_texCoord;
4941
4942
  out vec2 v_lightmapCoord;
4943
+ out float v_lightmapStep;
4942
4944
  out vec3 v_position;
4943
4945
 
4944
4946
  vec2 applyScroll(vec2 uv, vec2 scroll) {
@@ -4948,6 +4950,7 @@ vec2 applyScroll(vec2 uv, vec2 scroll) {
4948
4950
  void main() {
4949
4951
  v_texCoord = applyScroll(a_texCoord, u_texScroll);
4950
4952
  v_lightmapCoord = applyScroll(a_lightmapCoord, u_lightmapScroll);
4953
+ v_lightmapStep = a_lightmapStep;
4951
4954
  v_position = a_position;
4952
4955
  gl_Position = u_modelViewProjection * vec4(a_position, 1.0);
4953
4956
  }`;
@@ -4964,11 +4967,13 @@ const int MAX_DLIGHTS = ${MAX_DLIGHTS};
4964
4967
 
4965
4968
  in vec2 v_texCoord;
4966
4969
  in vec2 v_lightmapCoord;
4970
+ in float v_lightmapStep;
4967
4971
  in vec3 v_position;
4968
4972
 
4969
4973
  uniform sampler2D u_diffuseMap;
4970
4974
  uniform sampler2D u_lightmapAtlas;
4971
4975
  uniform vec4 u_lightStyleFactors;
4976
+ uniform vec4 u_styleLayerMapping; // 0, 1, 2... or -1 if invalid
4972
4977
  uniform float u_alpha;
4973
4978
  uniform bool u_applyLightmap;
4974
4979
  uniform bool u_warp;
@@ -5002,9 +5007,35 @@ void main() {
5002
5007
  vec3 totalLight = vec3(1.0);
5003
5008
 
5004
5009
  if (u_applyLightmap) {
5005
- vec3 light = texture(u_lightmapAtlas, warpCoords(v_lightmapCoord)).rgb;
5006
- float styleScale = dot(u_lightStyleFactors, vec4(1.0));
5007
- totalLight = light * styleScale;
5010
+ // Multi-style lightmap accumulation
5011
+ vec3 light = vec3(0.0);
5012
+ bool hasLight = false;
5013
+
5014
+ vec2 lmBase = warpCoords(v_lightmapCoord);
5015
+
5016
+ // Loop unrolled-ish
5017
+ for (int i = 0; i < 4; i++) {
5018
+ // We can access vec4 components by index in newer GLSL ES, or use direct access
5019
+ float layer = u_styleLayerMapping[i];
5020
+ float factor = u_lightStyleFactors[i];
5021
+
5022
+ if (layer >= -0.5) { // Valid layer (check >= 0 approx)
5023
+ // Offset V by layer * step
5024
+ // Since we packed vertically
5025
+ vec2 offset = vec2(0.0, layer * v_lightmapStep);
5026
+ light += texture(u_lightmapAtlas, lmBase + offset).rgb * factor;
5027
+ hasLight = true;
5028
+ }
5029
+ }
5030
+
5031
+ // If no valid lightmaps found (e.g. unlit surface?), default to full bright?
5032
+ // Or if u_applyLightmap is true, there should be at least one style.
5033
+ // Fallback to 1.0 if accumulator is empty?
5034
+ // In Q2, unlit surfs are fullbright (or use minlight).
5035
+ // If hasLight is false, it means no styles are active.
5036
+ if (!hasLight) light = vec3(1.0);
5037
+
5038
+ totalLight = light; // Dynamic lights add on top or multiply? Q2 adds.
5008
5039
 
5009
5040
  // Add dynamic lights
5010
5041
  for (int i = 0; i < MAX_DLIGHTS; i++) {
@@ -5041,6 +5072,7 @@ void main() {
5041
5072
  o_color = finalColor;
5042
5073
  }`;
5043
5074
  var DEFAULT_STYLE_INDICES = [0, 255, 255, 255];
5075
+ var DEFAULT_STYLE_LAYERS = [0, -1, -1, -1];
5044
5076
  function resolveLightStyles(styleIndices = DEFAULT_STYLE_INDICES, styleValues = []) {
5045
5077
  const factors = new Float32Array(4);
5046
5078
  for (let i = 0; i < 4; i += 1) {
@@ -5084,12 +5116,13 @@ var BspSurfacePipeline = class {
5084
5116
  this.program = ShaderProgram.create(
5085
5117
  gl,
5086
5118
  { vertex: BSP_SURFACE_VERTEX_SOURCE, fragment: BSP_SURFACE_FRAGMENT_SOURCE },
5087
- { a_position: 0, a_texCoord: 1, a_lightmapCoord: 2 }
5119
+ { a_position: 0, a_texCoord: 1, a_lightmapCoord: 2, a_lightmapStep: 3 }
5088
5120
  );
5089
5121
  this.uniformMvp = this.program.getUniformLocation("u_modelViewProjection");
5090
5122
  this.uniformTexScroll = this.program.getUniformLocation("u_texScroll");
5091
5123
  this.uniformLmScroll = this.program.getUniformLocation("u_lightmapScroll");
5092
5124
  this.uniformLightStyles = this.program.getUniformLocation("u_lightStyleFactors");
5125
+ this.uniformStyleLayerMapping = this.program.getUniformLocation("u_styleLayerMapping");
5093
5126
  this.uniformAlpha = this.program.getUniformLocation("u_alpha");
5094
5127
  this.uniformApplyLightmap = this.program.getUniformLocation("u_applyLightmap");
5095
5128
  this.uniformWarp = this.program.getUniformLocation("u_warp");
@@ -5111,6 +5144,7 @@ var BspSurfacePipeline = class {
5111
5144
  const {
5112
5145
  modelViewProjection,
5113
5146
  styleIndices = DEFAULT_STYLE_INDICES,
5147
+ styleLayers = DEFAULT_STYLE_LAYERS,
5114
5148
  styleValues = [],
5115
5149
  diffuseSampler = 0,
5116
5150
  lightmapSampler,
@@ -5133,6 +5167,7 @@ var BspSurfacePipeline = class {
5133
5167
  this.gl.uniform2f(this.uniformTexScroll, finalScrollX, finalScrollY);
5134
5168
  this.gl.uniform2f(this.uniformLmScroll, state.flowOffset[0], state.flowOffset[1]);
5135
5169
  this.gl.uniform4fv(this.uniformLightStyles, styles);
5170
+ this.gl.uniform4fv(this.uniformStyleLayerMapping, styleLayers);
5136
5171
  this.gl.uniform1f(this.uniformAlpha, finalAlpha);
5137
5172
  const applyLightmap = !state.sky && lightmapSampler !== void 0;
5138
5173
  this.gl.uniform1i(this.uniformApplyLightmap, applyLightmap ? 1 : 0);