@maptalks/gpu 0.123.0 → 0.124.1

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @maptalks/gpu v0.123.0
2
+ * @maptalks/gpu v0.124.1
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2026 maptalks.com
5
5
  */
@@ -25,23 +25,23 @@ getGlobal()[WGSL_KEY] = sources;
25
25
 
26
26
  var analysisDepthFrag = "struct FragUniforms {\n logDepthBufFC: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: FragUniforms;\nconst PackUpscale: f32 = 256.0 / 255.0;\nconst UnpackDownscale: f32 = 255.0 / 256.0;\nconst PackFactors: vec3f = vec3f(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0);\nconst UnpackFactors: vec4f = vec4f(UnpackDownscale / PackFactors, UnpackDownscale);\nconst ShiftRight8: f32 = 1.0 / 256.0;\nfn packDepthToRGBA(v: f32) -> vec4f {\n var r: vec4f = vec4f(fract(v * PackFactors), v);\n r = vec4f(r.x, r.yzw - r.xyz * ShiftRight8);\n return r * PackUpscale;\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let fragCoordZ: f32 = vertexOutput.vHighPrecisionZW[0] / vertexOutput.vHighPrecisionZW[1];\n var glFragColor: vec4f = packDepthToRGBA(fragCoordZ);\n return glFragColor;\n}";
27
27
 
28
- var analysisDepthVert = "#include <get_output>\nstruct Uniforms {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n#ifdef HAS_ALTITUDE\nstruct VertexInput {\n @location($i) aPosition: vec2f,\n @location($i) aAltitude: f32,\n};\n#else\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\n#endif\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vHighPrecisionZW: vec2f,\n @location($o) vFragDepth: f32,\n};\n#ifdef HAS_ALTITUDE\nfn unpackVTPosition(vertexInput: VertexInput) -> vec3f {\n return vec3f(vertexInput.aPosition, vertexInput.aAltitude);\n}\n#endif\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n #ifdef HAS_ALTITUDE\n let i: vec3f = unpackVTPosition(vertexInput);\n let j: vec4f = vec4f(i, 1.0);\n output.position = uniforms.projViewModelMatrix * j;\n #else\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n output.position = uniforms.projViewModelMatrix * localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.vFragDepth = 1.0 + output.position.w;\n output.vHighPrecisionZW = output.position.zw;\n return output;\n}";
28
+ var analysisDepthVert = "#include <get_output>\nstruct Uniforms {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n#ifdef HAS_ALTITUDE\nstruct VertexInput {\n @location($i) aPosition: vec2f,\n @location($i) aAltitude: f32,\n};\n#else\nstruct VertexInput {\n #include <position_vert>\n};\n#endif\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vHighPrecisionZW: vec2f,\n @location($o) vFragDepth: f32,\n};\n#ifdef HAS_ALTITUDE\nfn unpackVTPosition(vertexInput: VertexInput) -> vec3f {\n return vec3f(vertexInput.aPosition, vertexInput.aAltitude);\n}\n#endif\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n #ifdef HAS_ALTITUDE\n let i: vec3f = unpackVTPosition(vertexInput);\n let j: vec4f = vec4f(i, 1.0);\n output.position = uniforms.projViewModelMatrix * j;\n #else\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n output.position = uniforms.projViewModelMatrix * localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.vFragDepth = 1.0 + output.position.w;\n output.vHighPrecisionZW = output.position.zw;\n return output;\n}";
29
29
 
30
30
  var analysisExcavateExtentFrag = "@fragment\nfn main() -> @location(0) vec4f {\n return vec4f(1.0, 0.0, 0.0, 1.0);\n}";
31
31
 
32
- var analysisExcavateExtentVert = "#include <get_output>\nstruct Uniforms {\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
32
+ var analysisExcavateExtentVert = "#include <get_output>\nstruct Uniforms {\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
33
33
 
34
34
  var analysisFloodFrag = "struct FloodAnalysisUniforms {\n extent: vec4f,\n waterHeight: f32,\n hasExtent: f32,\n analysisType: f32,\n};\n@group(0) @binding($b) var<uniform> floodAnalysisUniforms: FloodAnalysisUniforms;\n@group(0) @binding($b) var extentMap: texture_2d<f32>;\n@group(0) @binding($b) var extentMapSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let extent = floodAnalysisUniforms.extent;\n let waterHeight = floodAnalysisUniforms.waterHeight;\n let hasExtent = floodAnalysisUniforms.hasExtent;\n let analysisType = floodAnalysisUniforms.analysisType;\n let width = extent.z - extent.x;\n let height = extent.y - extent.w;\n let uvInExtent = vec2f(\n (vertexOutput.vWorldPosition.x - extent.x) / width,\n (vertexOutput.vWorldPosition.y - extent.w) / height\n );\n let extentColor = textureSample(extentMap, extentMapSampler, uvInExtent);\n var compare: bool;\n if (analysisType == 1.0) {\n compare = vertexOutput.flood_height < waterHeight;\n } else {\n compare = vertexOutput.flood_height >= waterHeight;\n }\n var color: vec4f = vec4f(0.0);\n if (compare) {\n if (hasExtent == 1.0) {\n if (extentColor.r > 0.0) {\n color = vec4f(1.0, 0.0, 0.0, 1.0);\n }\n } else {\n color = vec4f(1.0, 0.0, 0.0, 1.0);\n }\n }\n return color;\n}";
35
35
 
36
- var analysisFloodVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n projViewMatrix: mat4x4f\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPosition: vec4f,\n @location($o) flood_height: f32,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let worldPosition = uniforms.modelMatrix * localPosition;\n output.position = shaderUniforms.projViewMatrix * worldPosition;\n output.vWorldPosition = worldPosition;\n output.flood_height = worldPosition.z;\n return output;\n}";
36
+ var analysisFloodVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n projViewMatrix: mat4x4f\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPosition: vec4f,\n @location($o) flood_height: f32,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let worldPosition = uniforms.modelMatrix * localPosition;\n output.position = shaderUniforms.projViewMatrix * worldPosition;\n output.vWorldPosition = worldPosition;\n output.flood_height = worldPosition.z;\n return output;\n}";
37
37
 
38
38
  var analysisInsightFrag = "@group(0) @binding($b) var depthMap: texture_2d<f32>;\n@group(0) @binding($b) var depthMapSampler: sampler;\nconst UnpackDownscale: f32 = 255.0 / 256.0;\nconst PackFactors: vec3f = vec3f(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0);\nconst UnpackFactors: vec4f = vec4f(UnpackDownscale / PackFactors, UnpackDownscale);\nfn unpackRGBAToDepth(v: vec4f) -> f32 {\n return dot(v, UnpackFactors);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let viewpoint = vertexOutput.viewpoint;\n let shadowCoord = vec3f((viewpoint.xy / viewpoint.w) / 2.0 + 0.5, viewpoint.z / viewpoint.w);\n let rgbaDepth = textureSample(depthMap, depthMapSampler, shadowCoord.xy);\n let depth = unpackRGBAToDepth(rgbaDepth);\n var color: vec4f;\n if (shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 &&\n shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 &&\n shadowCoord.z <= 1.0) {\n if (depth < 0.001) {\n color = vec4f(0.0, 1.0, 0.0, 1.0); } else {\n if (shadowCoord.z <= depth + 0.002) {\n color = vec4f(0.0, 1.0, 0.0, 1.0); } else {\n color = vec4f(1.0, 0.0, 0.0, 1.0); }\n }\n } else {\n color = vec4f(0.0, 0.0, 1.0, 1.0); }\n return color;\n}";
39
39
 
40
- var analysisInsightVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n insight_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.insight_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
40
+ var analysisInsightVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n insight_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.insight_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
41
41
 
42
42
  var analysisViewshedFrag = "struct FragUniforms {\n near: f32,\n far: f32,\n};\n#ifdef HAS_HELPERLINE\n struct HelperUniforms {\n lineColor: vec3f,\n };\n#endif\n@group(0) @binding($b) var<uniform> uniforms: FragUniforms;\n#ifdef HAS_HELPERLINE\n @group(0) @binding($b) var<uniform> helperUniforms: HelperUniforms;\n#endif\n@group(0) @binding($b) var depthMap: texture_2d<f32>;\n@group(0) @binding($b) var depthMapSampler: sampler;\nconst UnpackDownscale: f32 = 255.0 / 256.0;\nconst PackFactors: vec3f = vec3f(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0);\nconst UnpackFactors: vec4f = vec4f(UnpackDownscale / PackFactors, UnpackDownscale);\nfn unpackRGBAToDepth(v: vec4f) -> f32 {\n return dot(v, UnpackFactors);\n}\nfn linear(value: f32) -> f32 {\n let near = uniforms.near;\n let far = uniforms.far;\n let z = value * 2.0 - 1.0;\n return (2.0 * near * far) / (far + near - z * (far - near));\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n #ifdef HAS_HELPERLINE\n return vec4f(helperUniforms.lineColor, 0.009);\n #else\n let near = uniforms.near;\n let far = uniforms.far;\n let viewpoint = vertexOutput.viewpoint;\n let shadowCoord: vec3f = vec3f((viewpoint.xy / viewpoint.w) / 2.0 + 0.5, viewpoint.z / viewpoint.w);\n let rgbaDepth: vec4f = textureSample(depthMap, depthMapSampler, shadowCoord.xy);\n let depth: f32 = unpackRGBAToDepth(rgbaDepth);\n let linearDepth: f32 = linear(depth);\n let linearZ: f32 = linear(shadowCoord.z);\n if (shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 &&\n shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 &&\n linearZ >= near && linearZ <= far - near) {\n if (linearZ <= linearDepth) {\n return vec4f(0.0, 1.0, 0.0, 1.0); } else {\n return vec4f(1.0, 0.0, 0.0, 1.0); }\n } else {\n return vec4f(0.0, 0.0, 1.0, 1.0);\n }\n #endif\n}";
43
43
 
44
- var analysisViewshedVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n viewshed_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.viewshed_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
44
+ var analysisViewshedVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n viewshed_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.viewshed_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
45
45
 
46
46
  var glAnalysisFrag = "struct FragmentUniforms {\n resolution: vec2f,\n #ifdef HAS_FLOODANALYSE\n flood_waterColor: vec3f,\n flood_waterOpacity: f32,\n #endif\n #ifdef HAS_VIEWSHED\n viewshed_visibleColor: vec4f,\n viewshed_invisibleColor: vec4f,\n #endif\n #ifdef HAS_INSIGHT\n insight_visibleColor: vec4f,\n insight_invisibleColor: vec4f,\n #endif\n #ifdef HAS_CROSSCUT\n cutLineColor: vec4f,\n #endif\n #ifdef HAS_HEIGHTLIMIT\n limitColor: vec3f,\n #endif\n};\n#ifdef HAS_FLOODANALYSE\n @group(0) @binding($b) var floodMap: texture_2d<f32>;\n @group(0) @binding($b) var floodMapSampler: sampler;\n#endif\n#ifdef HAS_SKYLINE\n @group(0) @binding($b) var skylineMap: texture_2d<f32>;\n @group(0) @binding($b) var skylineMapSampler: sampler;\n#endif\n#ifdef HAS_VIEWSHED\n @group(0) @binding($b) var viewshedMap: texture_2d<f32>;\n @group(0) @binding($b) var viewshedMapSampler: sampler;\n#endif\n#ifdef HAS_INSIGHT\n @group(0) @binding($b) var insightMap: texture_2d<f32>;\n @group(0) @binding($b) var insightMapSampler: sampler;\n#endif\n#ifdef HAS_CUT\n @group(0) @binding($b) var meshesMap: texture_2d<f32>;\n @group(0) @binding($b) var meshesMapSampler: sampler;\n @group(0) @binding($b) var invisibleMap: texture_2d<f32>;\n @group(0) @binding($b) var invisibleMapSampler: sampler;\n#endif\n#ifdef HAS_EXCAVATE\n @group(0) @binding($b) var excavateMap: texture_2d<f32>;\n @group(0) @binding($b) var excavateMapSampler: sampler;\n#endif\n#ifdef HAS_CROSSCUT\n @group(0) @binding($b) var crosscutMap: texture_2d<f32>;\n @group(0) @binding($b) var crosscutMapSampler: sampler;\n#endif\n#ifdef HAS_HEIGHTLIMIT\n @group(0) @binding($b) var heightLimitMap: texture_2d<f32>;\n @group(0) @binding($b) var heightLimitMapSampler: sampler;\n#endif\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var sceneMap: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var sceneMap: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var sceneMapSampler: sampler;\n@group(0) @binding($b) var<uniform> uniforms: FragmentUniforms;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var glFragColor: vec4f;\n var uv = vertexOutput.vTexCoord;\n uv.y = 1.0 - uv.y;\n #ifdef HAS_MULTISAMPLED\n let sceneColor = textureLoad(sceneMap, vec2i(uv * uniforms.resolution), 0);\n #else\n let sceneColor = textureSample(sceneMap, sceneMapSampler, uv);\n #endif\n glFragColor = sceneColor;\n #ifdef HAS_VIEWSHED\n let viewshedColor = textureSample(viewshedMap, viewshedMapSampler, uv);\n if (viewshedColor.r > 0.99) {\n glFragColor = vec4f(\n mix(uniforms.viewshed_invisibleColor.rgb, sceneColor.rgb, uniforms.viewshed_invisibleColor.a),\n sceneColor.a\n );\n } else if (viewshedColor.g > 0.99) {\n glFragColor = vec4f(\n mix(uniforms.viewshed_visibleColor.rgb, sceneColor.rgb, uniforms.viewshed_visibleColor.a),\n sceneColor.a\n );\n } else if (viewshedColor.a < 0.01) {\n glFragColor = vec4f(viewshedColor.rgb, 1.0);\n }\n #endif\n #ifdef HAS_FLOODANALYSE\n let floodColor = textureSample(floodMap, floodMapSampler, uv);\n if (floodColor.r > 0.0) {\n glFragColor = vec4f(\n mix(glFragColor.rgb, uniforms.flood_waterColor, uniforms.flood_waterOpacity),\n glFragColor.a\n );\n }\n #endif\n #ifdef HAS_SKYLINE\n let skylineColor = textureSample(skylineMap, skylineMapSampler, uv);\n if (skylineColor.r > 0.0 || skylineColor.g > 0.0 || skylineColor.b > 0.0) {\n glFragColor = skylineColor;\n }\n #endif\n #ifdef HAS_INSIGHT\n let insightColor = textureSample(insightMap, insightMapSampler, uv);\n if (insightColor.g > 0.0) {\n glFragColor = uniforms.insight_visibleColor;\n } else if (insightColor.r > 0.0) {\n glFragColor = uniforms.insight_invisibleColor;\n }\n #endif\n #ifdef HAS_CUT\n let cutColor = textureSample(invisibleMap, invisibleMapSampler, uv);\n let meshesMapColor = textureSample(meshesMap, meshesMapSampler, uv);\n if (cutColor.r == 1.0 && cutColor.g == 0.0 && cutColor.b == 0.0) {\n glFragColor = meshesMapColor;\n } else if (cutColor.r == 0.0 && cutColor.g == 1.0 && cutColor.b == 0.0) {\n glFragColor = meshesMapColor;\n } else if (cutColor.r == 0.0 && cutColor.g == 0.0 && cutColor.b == 1.0) {\n glFragColor = sceneColor;\n }\n #endif\n #ifdef HAS_EXCAVATE\n let excavateColor = textureSample(excavateMap, excavateMapSampler, uv);\n if (excavateColor.r == 1.0 && excavateColor.g == 0.0 && excavateColor.b == 0.0) {\n glFragColor = sceneColor;\n } else {\n glFragColor = excavateColor;\n }\n #endif\n #ifdef HAS_CROSSCUT\n let crosscutColor = textureSample(crosscutMap, crosscutMapSampler, uv);\n if (crosscutColor.r > 0.0) {\n glFragColor = vec4f(\n mix(uniforms.cutLineColor.rgb, glFragColor.rgb, 0.99),\n glFragColor.a\n );\n }\n #endif\n #ifdef HAS_HEIGHTLIMIT\n let heightLimitColor = textureSample(heightLimitMap, heightLimitMapSampler, uv);\n if (heightLimitColor.r > 0.0) {\n glFragColor = vec4f(\n mix(uniforms.limitColor, glFragColor.rgb, 0.6),\n glFragColor.a\n );\n }\n #endif\n return glFragColor;\n}";
47
47
 
@@ -55,11 +55,11 @@ var glTerrainSkinFrag = "struct TerrrainSkinUniforms {\n tileSize: f32,\n
55
55
 
56
56
  var glTerrainSkinVert = "struct VertexInput {\n @location($i) aPosition: vec2i\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n vertexOutput.position = vec4f(vec2f(vertexInput.aPosition), 0.0, 1.0);\n return vertexOutput;\n}";
57
57
 
58
- var glTerrainVert = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_vert>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n#endif\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n heightScale: f32,\n};\nstruct TerrainUniforms {\n minAltitude: f32,\n projViewModelMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vUv: vec2f,\n};\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aTexCoord: vec2f,\n};\n@group(0) @binding($b) var<uniform> matrixUniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n var position = vec4f(vertexInput.aPosition.xy, (vertexInput.aPosition.z + uniforms.minAltitude) * matrixUniforms.heightScale, 1.0);\n position = uniforms.positionMatrix * position;\n #ifdef HAS_MASK_EXTENT\n vertexOutput.position = matrixUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix, vertexOutput);\n #else\n vertexOutput.position = uniforms.projViewModelMatrix * position;\n #endif\n vertexOutput.vUv = vertexInput.aTexCoord;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &vertexOutput);\n #endif\n return vertexOutput;\n}";
58
+ var glTerrainVert = "#include <common_pack_float>\n#include <mask_vert>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n#endif\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n heightScale: f32,\n};\nstruct TerrainUniforms {\n minAltitude: f32,\n projViewModelMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vUv: vec2f,\n};\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aTexCoord: vec2f,\n};\n@group(0) @binding($b) var<uniform> matrixUniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@group(0) @binding($b) var flatMaskSampler: sampler;\n@group(0) @binding($b) var flatMask: texture_2d<f32>;\n@vertex\nfn main(\n vertexInput: VertexInput,\n) -> VertexOutput {\n var vertexOutput: VertexOutput;\n var uv: vec2f = vertexInput.aTexCoord;\n let encodedHeight: vec4f = textureSampleLevel(flatMask, flatMaskSampler, uv, 0.0);\n var altitude: f32 = vertexInput.aPosition.z;\n if (length(encodedHeight) < 2.0) {\n let maskHeight: f32 = decodeFloat32(encodedHeight);\n altitude = min(vertexInput.aPosition.z, maskHeight);\n }\n var position: vec4f = vec4f(vertexInput.aPosition.xy, (altitude + uniforms.minAltitude) * matrixUniforms.heightScale, 1.0);\n position = uniforms.positionMatrix * position;\n #ifdef HAS_MASK_EXTENT\n vertexOutput.position = matrixUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix, vertexOutput);\n #else\n vertexOutput.position = uniforms.projViewModelMatrix * position;\n #endif\n vertexOutput.vUv = vertexInput.aTexCoord;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &vertexOutput);\n #endif\n return vertexOutput;\n}";
59
59
 
60
- var glStandardFrag = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f,\n #ifdef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: array<vec3f, 9>,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n #ifndef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterMapSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = shaderUniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterMapSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, shaderUniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n #ifdef MESH_ENV_EXPO\n let environmentExposure = materialUniforms.environmentExposure;\n #else\n let environmentExposure = shaderUniforms.environmentExposure;\n #endif\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag = shadow_blend(rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n glFragColor.rgb = snow(glFragColor, getMaterialNormalMap(), 1.0);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
60
+ var glStandardFrag = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f,\n #ifdef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n #ifdef IS_LINE_EXTRUSION\n lineOpacity: f32,\n #else\n polygonOpacity: f32,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: array<vec3f, 9>,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n #ifndef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterMapSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = shaderUniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterMapSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, shaderUniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n #ifdef MESH_ENV_EXPO\n let environmentExposure = materialUniforms.environmentExposure;\n #else\n let environmentExposure = shaderUniforms.environmentExposure;\n #endif\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag = shadow_blend(rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n #if IS_LINE_EXTRUSION\n alpha *= uniforms.lineOpacity;\n #else\n alpha *= uniforms.polygonOpacity;\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n let snowColor = snow(glFragColor, getMaterialNormalMap(), 1.0);\n glFragColor = vec4f(snowColor, glFragColor.a);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
61
61
 
62
- var glStandardVert = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n @location($i) aTexCoord: vec2f,\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT\n @location($i) aTangent: vec4f,\n #elif HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n #endif\n}\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifdef HAS_SSR\n @location($o) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($o) vViewTangent: vec4f,\n #endif\n #endif\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($o) vModelTangent: vec4f,\n @location($o) vModelBiTangent: vec3f,\n #endif\n @location($o) vModelVertex: vec3f,\n #if HAS_MAP\n @location($o) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #if HAS_COLOR0\n @location($o) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($o) vTangentViewPos: vec3f,\n @location($o) vTangentFragPos: vec3f,\n #endif\n}\nstruct ShaderUniforms {\n cameraPosition: vec3f,\n projMatrix: mat4x4f,\n}\nstruct Uniforms {\n uvOrigin: vec2f,\n uvScale: vec2f,\n uvOffset: vec2f,\n uvRotation: f32,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n #ifdef HAS_SSR\n modelViewNormalMatrix: mat3x3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nvar<private> Vertex: vec3f;\nvar<private> Normal: vec3f;\nvar<private> Tangent: vec4f;\nconst mid = 0.5;\nfn toTangentFrame(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nstruct TangentFrame {\n n: vec3f,\n t: vec3f\n}\nfn toTangentFrameWithTangent(q: vec4f) -> TangentFrame {\n var out: TangentFrame;\n out.n = toTangentFrame(q);\n out.t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n return out;\n}\nfn rotateUV(uv: vec2f, rotation: f32) -> vec2f {\n return vec2f(\n cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,\n cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid\n );\n}\n#if HAS_MAP\nfn transformTexcoord(uv: vec2f) -> vec2f {\n let decodedTexCoord = decode_getTexcoord(uv);\n #ifdef HAS_RANDOM_TEX\n let origin = uniforms.uvOrigin;\n let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;\n return (origin % 1.0) + texCoord;\n #else\n var origin = uniforms.uvOrigin;\n var texCoord = decodedTexCoord * uniforms.uvScale;\n if (uniforms.uvRotation != 0.0) {\n origin = rotateUV(origin, uniforms.uvRotation);\n texCoord = rotateUV(texCoord, uniforms.uvRotation);\n }\n return (origin % 1.0) + texCoord + uniforms.uvOffset;\n #endif\n}\n#endif\nfn transposeMat3(inMat: mat3x3f) -> mat3x3f {\n let i0 = inMat[0];\n let i1 = inMat[1];\n let i2 = inMat[2];\n return mat3x3f(\n vec3f(i0.x, i1.x, i2.x),\n vec3f(i0.y, i1.y, i2.y),\n vec3f(i0.z, i1.z, i2.z)\n );\n}\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);\n let localVertex = getPosition(linePosition, input);\n #else\n let localVertex = getPosition(vec3f(input.aPosition.xyz), input);\n #endif\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n let position = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelViewMatrix * position;\n output.vViewVertex = viewVertex;\n #ifdef HAS_MASK_EXTENT\n output.position = shaderUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = shaderUniforms.projMatrix * viewVertex;\n #endif\n #ifdef PICKING_MODE\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= f32(input.aColor.a);\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= f32(input.aColor0.a);\n #endif\n fbo_picking_setData(input, &output, output.position.w, alpha != 0.0);\n #else\n #if HAS_MAP\n output.vTexCoord = transformTexcoord(input.aTexCoord);\n #ifdef HAS_AO_MAP\n output.vTexCoord1 = transformTexcoord(input.aTexCoord1);\n #endif\n #ifdef HAS_I3S_UVREGION\n output.vUvRegion = input.uvRegion / 65535.0;\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n let positionNormalMatrix = mat3x3f(\n localPositionMatrix[0].xyz,\n localPositionMatrix[1].xyz,\n localPositionMatrix[2].xyz\n );\n let normalMatrix = uniforms.modelNormalMatrix * positionNormalMatrix;\n #if HAS_TANGENT\n let tangentFrame = toTangentFrameWithTangent(input.aTangent);\n Normal = tangentFrame.n;\n let t = tangentFrame.t;\n output.vModelTangent = vec4f(normalMatrix * t, input.aTangent.w);\n #else\n Normal = decode_getNormal(vec3f(input.aNormal.xyz));\n #endif\n let localNormal = Normal;\n output.vModelNormal = normalMatrix * localNormal;\n #else\n Normal = vec3f(0);\n output.vModelNormal = vec3f(0);\n #endif\n #if HAS_TANGENT\n output.vModelBiTangent = cross(output.vModelNormal, output.vModelTangent.xyz) * sign(input.aTangent.w);\n #endif\n #ifdef HAS_SSR\n let ssrNormalMatrix = uniforms.modelViewNormalMatrix * positionNormalMatrix;\n output.vViewNormal = ssrNormalMatrix * Normal;\n #if HAS_TANGENT\n let localTangent = vec4f(t, input.aTangent.w);\n output.vViewTangent = vec4f(ssrNormalMatrix * localTangent.xyz, localTangent.w);\n #endif\n #endif\n #if HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(input, &output);\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n output.vColor0 = vec4f(vec3f(input.aColor0), 255.0) / 255.0;\n #else\n output.vColor0 = vec4f(input.aColor0) / 255.0;\n #endif\n #endif\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &output);\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n let TBN = transposeMat3(mat3x3f(output.vModelTangent.xyz, output.vModelBiTangent, output.vModelNormal));\n output.vTangentViewPos = TBN * shaderUniforms.cameraPosition;\n output.vTangentFragPos = TBN * output.vModelVertex;\n #endif\n #ifdef HAS_VERTEX_COLOR\n vertexColor_update(input, &output);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);\n output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);\n #endif\n #endif\n return output;\n}";
62
+ var glStandardVert = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #include <position_vert>\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n #ifdef HAS_DRACO_TEXCOORD\n @location($i) aTexCoord: vec2u,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT\n @location($i) aTangent: vec4f,\n #elif HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #elif NORMAL_IS_UINT\n @location($i) aNormal: vec4u,\n #else\n @location($i) aNormal: vec3f,\n #endif\n #endif\n}\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifdef HAS_SSR\n @location($o) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($o) vViewTangent: vec4f,\n #endif\n #endif\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($o) vModelTangent: vec4f,\n @location($o) vModelBiTangent: vec3f,\n #endif\n @location($o) vModelVertex: vec3f,\n #if HAS_MAP\n @location($o) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #if HAS_COLOR0\n @location($o) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($o) vTangentViewPos: vec3f,\n @location($o) vTangentFragPos: vec3f,\n #endif\n}\nstruct ShaderUniforms {\n cameraPosition: vec3f,\n projMatrix: mat4x4f,\n}\nstruct Uniforms {\n uvOrigin: vec2f,\n uvScale: vec2f,\n uvOffset: vec2f,\n uvRotation: f32,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n #ifdef HAS_SSR\n modelViewNormalMatrix: mat3x3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nvar<private> Vertex: vec3f;\nvar<private> Normal: vec3f;\nvar<private> Tangent: vec4f;\nconst mid = 0.5;\nfn toTangentFrame(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nstruct TangentFrame {\n n: vec3f,\n t: vec3f\n}\nfn toTangentFrameWithTangent(q: vec4f) -> TangentFrame {\n var out: TangentFrame;\n out.n = toTangentFrame(q);\n out.t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n return out;\n}\nfn rotateUV(uv: vec2f, rotation: f32) -> vec2f {\n return vec2f(\n cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,\n cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid\n );\n}\n#if HAS_MAP\nfn transformTexcoord(uv: vec2f) -> vec2f {\n let decodedTexCoord = decode_getTexcoord(uv);\n #ifdef HAS_RANDOM_TEX\n let origin = uniforms.uvOrigin;\n let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;\n return (origin % 1.0) + texCoord;\n #else\n var origin = uniforms.uvOrigin;\n var texCoord = decodedTexCoord * uniforms.uvScale;\n if (uniforms.uvRotation != 0.0) {\n origin = rotateUV(origin, uniforms.uvRotation);\n texCoord = rotateUV(texCoord, uniforms.uvRotation);\n }\n return (origin % 1.0) + texCoord + uniforms.uvOffset;\n #endif\n}\n#endif\nfn transposeMat3(inMat: mat3x3f) -> mat3x3f {\n let i0 = inMat[0];\n let i1 = inMat[1];\n let i2 = inMat[2];\n return mat3x3f(\n vec3f(i0.x, i1.x, i2.x),\n vec3f(i0.y, i1.y, i2.y),\n vec3f(i0.z, i1.z, i2.z)\n );\n}\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);\n let localVertex = getPosition(linePosition, input);\n #else\n let localVertex = getPosition(vec3f(input.aPosition.xyz), input);\n #endif\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n let position = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelViewMatrix * position;\n output.vViewVertex = viewVertex;\n #ifdef HAS_MASK_EXTENT\n output.position = shaderUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = shaderUniforms.projMatrix * viewVertex;\n #endif\n #ifdef PICKING_MODE\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= f32(input.aColor.a);\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= f32(input.aColor0.a);\n #endif\n fbo_picking_setData(input, &output, output.position.w, alpha != 0.0);\n #else\n #if HAS_MAP\n output.vTexCoord = transformTexcoord(input.aTexCoord.xy);\n #ifdef HAS_AO_MAP\n output.vTexCoord1 = transformTexcoord(input.aTexCoord1);\n #endif\n #ifdef HAS_I3S_UVREGION\n output.vUvRegion = input.uvRegion / 65535.0;\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n let positionNormalMatrix = mat3x3f(\n localPositionMatrix[0].xyz,\n localPositionMatrix[1].xyz,\n localPositionMatrix[2].xyz\n );\n let normalMatrix = uniforms.modelNormalMatrix * positionNormalMatrix;\n #if HAS_TANGENT\n let tangentFrame = toTangentFrameWithTangent(input.aTangent);\n Normal = tangentFrame.n;\n let t = tangentFrame.t;\n output.vModelTangent = vec4f(normalMatrix * t, input.aTangent.w);\n #else\n Normal = decode_getNormal(vec3f(input.aNormal.xyz));\n #endif\n let localNormal = Normal;\n output.vModelNormal = normalMatrix * localNormal;\n #else\n Normal = vec3f(0);\n output.vModelNormal = vec3f(0);\n #endif\n #if HAS_TANGENT\n output.vModelBiTangent = cross(output.vModelNormal, output.vModelTangent.xyz) * sign(input.aTangent.w);\n #endif\n #ifdef HAS_SSR\n let ssrNormalMatrix = uniforms.modelViewNormalMatrix * positionNormalMatrix;\n output.vViewNormal = ssrNormalMatrix * Normal;\n #if HAS_TANGENT\n let localTangent = vec4f(t, input.aTangent.w);\n output.vViewTangent = vec4f(ssrNormalMatrix * localTangent.xyz, localTangent.w);\n #endif\n #endif\n #if HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(input, &output);\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n output.vColor0 = vec4f(vec3f(input.aColor0), 255.0) / 255.0;\n #else\n output.vColor0 = vec4f(input.aColor0) / 255.0;\n #endif\n #endif\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &output);\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n let TBN = transposeMat3(mat3x3f(output.vModelTangent.xyz, output.vModelBiTangent, output.vModelNormal));\n output.vTangentViewPos = TBN * shaderUniforms.cameraPosition;\n output.vTangentFragPos = TBN * output.vModelVertex;\n #endif\n #ifdef HAS_VERTEX_COLOR\n vertexColor_update(input, &output);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);\n output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);\n #endif\n #endif\n return output;\n}";
63
63
 
64
64
  var glBloomCombineFrag = "\nstruct BloomCombineUniforms {\n bloomFactor: f32,\n bloomRadius: f32,\n rgbmRange: f32,\n enableAA: f32,\n outputSize: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: BloomCombineUniforms;\n@group(0) @binding($b) var TextureBloomBlur1: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur1Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur2: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur2Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur3: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur3Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur4: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur4Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur5: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur5Sampler: sampler;\n#ifdef HAS_MULTISAMPLED\n@group(0) @binding($b) var TextureInput: texture_multisampled_2d<f32>;\n@group(0) @binding($b) var TextureSource: texture_multisampled_2d<f32>;\n#else\n@group(0) @binding($b) var TextureInput: texture_2d<f32>;\n@group(0) @binding($b) var TextureSource: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var TextureInputSampler: sampler;\n@group(0) @binding($b) var TextureSourceSampler: sampler;\nvar<private> gTexCoord: vec2f;\n#include <srgb_frag>\nfn decodeRGBM(color: vec4f, range: f32) -> vec3f {\n if (range <= 0.0) {\n return color.rgb;\n }\n return range * color.rgb * color.a;\n}\nfn getRadiusFactored(value: f32, middle: f32) -> f32 {\n return mix(value, middle * 2.0 - value, uniforms.bloomRadius);\n}\nfn fetchSourceTexel(uv: vec2f) -> vec4f {\n#ifdef HAS_MULTISAMPLED\n return textureLoad(TextureSource, vec2i(uv * vec2f(uniforms.outputSize)), 0);\n#else\n return textureSample(TextureSource, TextureSourceSampler, uv);\n#endif\n}\nfn fetchInputTexel(uv: vec2f) -> vec4f {\n#ifdef HAS_MULTISAMPLED\n return textureLoad(TextureInput, vec2i(uv * vec2f(uniforms.outputSize)), 0);\n#else\n return textureSample(TextureInput, TextureInputSampler, uv);\n#endif\n}\nfn bloomCombine() -> vec4f {\n var bloom: vec3f = vec3f(0.0);\n let midVal: f32 = 0.6;\n let factor1: f32 = 1.1;\n let factor2: f32 = 0.9;\n let factor3: f32 = 0.6;\n let factor4: f32 = 0.3;\n let factor5: f32 = 0.1;\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur1, TextureBloomBlur1Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor1, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur2, TextureBloomBlur2Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor2, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur3, TextureBloomBlur3Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor3, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur4, TextureBloomBlur4Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor4, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur5, TextureBloomBlur5Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor5, midVal);\n var bloomInputColor: vec4f;\n if (uniforms.enableAA == 1.0) {\n } else {\n bloomInputColor = fetchInputTexel(gTexCoord);\n }\n bloomInputColor = vec4f(mix(vec3f(0.0), bloomInputColor.rgb, sign(bloomInputColor.a)), bloomInputColor.a);\n let srcColor = fetchSourceTexel(gTexCoord);\n let bloomAlpha: f32 = sqrt((bloom.r + bloom.g + bloom.b) / 3.0);\n let bloomColor: vec4f = vec4f(linearTosRGB(bloom * uniforms.bloomFactor), bloomAlpha);\n return bloomInputColor + srcColor * (1.0 - bloomInputColor.a) + bloomColor;\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let fragCoord = vec2f(vertexOutput.position.xy);\n gTexCoord = fragCoord / uniforms.outputSize;\n let color = bloomCombine();\n return color;\n}";
65
65
 
@@ -91,7 +91,7 @@ var glImageVert = "struct Uniforms {\n projViewModelMatrix : mat4x4f\n}\n@gro
91
91
 
92
92
  var glPhongFrag = "struct LightUniforms {\n light0_viewDirection: vec3f,\n ambientColor: vec3f,\n light0_diffuse: vec4f,\n lightSpecular: vec3f,\n cameraPosition: vec3f,\n #ifdef HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n};\nstruct MaterialUniforms {\n environmentExposure: f32,\n specularStrength: f32,\n baseColorFactor: vec4f,\n materialShininess: f32,\n alphaTest: f32,\n#ifdef HAS_EXTRUSION_OPACITY\n extrusionOpacityRange: vec2f,\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n diffuseFactor: vec4f,\n specularFactor: vec3f,\n#endif\n#ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n lineOpacity: f32,\n#else\n polygonFill: vec4f,\n polygonOpacity: f32,\n#endif\n};\n@group(0) @binding($b) var<uniform> lightUniforms: LightUniforms;\n@group(0) @binding($b) var<uniform> materialUniforms: MaterialUniforms;\n#ifdef HAS_BASECOLOR_MAP\n@group(0) @binding($b) var baseColorTextureSampler: sampler;\n@group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_AO_MAP\n@group(0) @binding($b) var occlusionTextureSampler: sampler;\n@group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_NORMAL_MAP\n@group(0) @binding($b) var normalTextureSampler: sampler;\n@group(0) @binding($b) var normalTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_EMISSIVE_MAP\n@group(0) @binding($b) var emissiveTextureSampler: sampler;\n@group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n#ifdef HAS_DIFFUSE_MAP\n@group(0) @binding($b) var diffuseTextureSampler: sampler;\n@group(0) @binding($b0) var diffuseTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n@group(0) @binding($b1) var specularGlossinessTextureSampler: sampler;\n@group(0) @binding($b2) var specularGlossinessTexture: texture_2d<f32>;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_frag>\n#endif\n#include <highlight_frag>\n#include <mask_frag>\n#include <vertex_color_frag>\n#ifdef HAS_MAP\n #include <compute_texcoord_frag>\n#endif\nfn transformNormal(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_NORMAL_MAP\n let n = normalize(vertexOutput.vNormal);\n let normal = textureSample(normalTexture, normalTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).xyz * 2.0 - 1.0;\n#ifdef HAS_TANGENT\n let t = normalize(vertexOutput.vTangent.xyz);\n let b = normalize(cross(n, t) * sign(vertexOutput.vTangent.w));\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n#else\n return normalize(normal);\n#endif\n#else\n return normalize(vertexOutput.vNormal);\n#endif\n}\nfn getBaseColor(vertexOutput: VertexOutput) -> vec4f {\n#ifdef HAS_BASECOLOR_MAP\n return textureSample(baseColorTexture, baseColorTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput));\n#elif HAS_DIFFUSE_MAP\n return textureSample(diffuseTexture, diffuseTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput));\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.diffuseFactor;\n#else\n return materialUniforms.baseColorFactor;\n#endif\n}\nfn getSpecularColor(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n return textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).rgb;\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.specularFactor;\n#else\n return vec3f(1.0);\n#endif\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let baseColor = getBaseColor(vertexOutput);\n#ifdef SHADING_MODEL_UNLIT\n let ambientColor = vec3f(1.0);\n#else\n let ambientColor = lightUniforms.ambientColor;\n#endif\n var ambient = materialUniforms.environmentExposure * ambientColor * baseColor.rgb;\n#ifdef HAS_INSTANCE_COLOR\n ambient *= vertexOutput.vInstanceColor.rgb;\n#endif\n let norm = transformNormal(vertexOutput);\n let lightDir = normalize(-lightUniforms.light0_viewDirection);\n var diff = max(dot(norm, lightDir), 0.0);\n#ifdef SHADING_MODEL_UNLIT\n let lightDiffuse = vec3f(0.0);\n#else\n let lightDiffuse = lightUniforms.light0_diffuse.rgb;\n#endif\n var diffuse = lightDiffuse * diff * baseColor.rgb;\n#if HAS_COLOR || HAS_COLOR0\n var color = vertexOutput.vColor.rgb;\n#elif IS_LINE_EXTRUSION\n var color = materialUniforms.lineColor.rgb;\n#else\n var color = materialUniforms.polygonFill.rgb;\n#endif\n#ifdef HAS_INSTANCE_COLOR\n color *= vertexOutput.vInstanceColor.rgb;\n#endif\n ambient *= color.rgb;\n diffuse *= color.rgb;\n let viewDir = normalize(lightUniforms.cameraPosition - vertexOutput.vFragPos);\n let halfwayDir = normalize(lightDir + viewDir);\n var spec = pow(max(dot(norm, halfwayDir), 0.0), materialUniforms.materialShininess);\n#ifdef SHADING_MODEL_UNLIT\n let lightSpecular = vec3f(0.0);\n#else\n let lightSpecular = lightUniforms.lightSpecular;\n#endif\n var specular = materialUniforms.specularStrength * lightSpecular * spec * getSpecularColor(vertexOutput);\n#ifdef HAS_OCCLUSION_MAP\n let ao = textureSample(occlusionTexture, occlusionTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput1)).r;\n ambient *= ao;\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n diffuse = shadow_blend(diffuse, shadowCoeff).rgb;\n specular = shadow_blend(specular, shadowCoeff).rgb;\n ambient = shadow_blend(ambient, shadowCoeff).rgb;\n#endif\n var result = ambient + diffuse + specular;\n#ifdef HAS_EMISSIVE_MAP\n let emit = textureSample(emissiveTexture, emissiveTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).rgb;\n result += emit;\n#endif\n#ifdef IS_LINE_EXTRUSION\n var fragColor = vec4f(result, materialUniforms.lineOpacity * baseColor.a);\n#else\n var fragColor = vec4f(result, materialUniforms.polygonOpacity * baseColor.a);\n#endif\n#if HAS_COLOR || HAS_COLOR0\n let colorAlpha = vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n let colorAlpha = materialUniforms.lineColor.a;\n#else\n let colorAlpha = materialUniforms.polygonFill.a;\n#endif\n fragColor *= colorAlpha;\n#ifdef HAS_EXTRUSION_OPACITY\n let topAlpha = materialUniforms.extrusionOpacityRange.x;\n let bottomAlpha = materialUniforms.extrusionOpacityRange.y;\n let alpha = topAlpha + vertexOutput.vExtrusionOpacity * (bottomAlpha - topAlpha);\n let alpha = clamp(alpha, 0.0, 1.0);\n fragColor *= alpha;\n#endif\n if (fragColor.a < materialUniforms.alphaTest) {\n discard;\n }\n#ifdef HAS_VERTEX_COLOR\n fragColor *= vertexColor_get();\n#endif\n#ifdef HAS_HEATMAP\n fragColor = heatmap_getColor(fragColor);\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n fragColor = highlight_blendColor(fragColor, vertexOutput);\n#endif\n#ifdef HAS_LAYER_OPACITY\n fragColor *= lightUniforms.layerOpacity;\n#endif\n#ifdef HAS_MASK_EXTENT\n fragColor = setMask(fragColor);\n#endif\n return fragColor;\n}";
93
93
 
94
- var glPhongVert = "struct VertexInput {\n#if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n#else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n#endif\n#ifdef HAS_MAP\n #if HAS_DRACO_TEXCOORD || HAS_COMPRESSED_INT16_TEXCOORD_0\n @location($i) aTexCoord: vec2i,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n#ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR\n @location($i) aColor: vec4f,\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n @location($i) aColor0: vec3f,\n#else\n @location($i) aColor0: vec4f,\n#endif\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n @location($i) aExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($i) aTangent: vec4f,\n#endif\n#ifdef HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n#endif\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vFragPos: vec3f,\n @location($o) vNormal: vec3f,\n#ifdef HAS_MAP\n @location($o) vTexCoord: vec2f,\n#ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR || HAS_COLOR0\n @location($o) vColor: vec4f,\n#endif\n#if HAS_EXTRUSION_OPACITY\n @location($o) vExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($o) vTangent: vec4f,\n#endif\n};\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n projViewMatrix: mat4x4f,\n};\nstruct ModelUniforms {\n modelNormalMatrix: mat3x3f,\n modelViewMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n uvScale: vec2f,\n uvOffset: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> modelUniforms: ModelUniforms;\n#include <line_extrusion_vert>\n#include <highlight_vert>\n#include <get_output>\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_vert>\n#endif\n#include <vertex_color_vert>\nfn toTangentFrame1(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nfn toTangentFrame(q: vec4f, n: ptr<function, vec3f>, t: ptr<function, vec3f>) {\n *n = toTangentFrame1(q);\n *t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput : VertexOutput;\n#if IS_LINE_EXTRUSION\n let localPosition = getPosition(getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput), vertexInput);\n#else\n let localPosition = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n#endif\n let localPositionMatrix = getPositionMatrix(vertexInput, &vertexOutput, modelUniforms.positionMatrix);\n vertexOutput.vFragPos = (modelUniforms.modelMatrix * localPositionMatrix * localPosition).xyz;\n#if HAS_NORMAL || HAS_TANGENT\n let localNormalMatrix = modelUniforms.modelNormalMatrix * mat3x3f(localPositionMatrix[0].xyz, localPositionMatrix[1].xyz, localPositionMatrix[2].xyz);\n var Normal: vec3f;\n#if HAS_TANGENT\n var t: vec3f;\n toTangentFrame(vertexInput.aTangent, Normal, t);\n vertexOutput.vTangent = vec4f(localNormalMatrix * t, vertexInput.aTangent.w);\n#else\n Normal = decode_getNormal(vec3f(vertexInput.aNormal.xyz));\n#endif\n let localNormal = appendMorphNormal(Normal, vertexInput);\n vertexOutput.vNormal = normalize(localNormalMatrix * localNormal);\n#else\n vertexOutput.vNormal = vec3f(0.0);\n#endif\n var jitteredProjection = uniforms.projMatrix;\n#ifdef HAS_MASK_EXTENT\n vertexOutput.position = jitteredProjection * getMaskPosition(localPositionMatrix * localPosition, uniforms.modelMatrix);\n#else\n vertexOutput.position = jitteredProjection * modelUniforms.modelViewMatrix * localPositionMatrix * localPosition;\n#endif\n#ifdef HAS_MAP\n let decodedTexCoord = decode_getTexcoord(vec2f(vertexInput.aTexCoord));\n vertexOutput.vTexCoord = decodedTexCoord * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_AO_MAP\n let decodedTexCoord1 = decode_getTexcoord(vec2f(vertexInput.aTexCoord1));\n vertexOutput.vTexCoord1 = decodedTexCoord1 * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n vertexOutput.vExtrusionOpacity = vertexInput.aExtrusionOpacity;\n#endif\n#if HAS_COLOR\n vertexOutput.vColor = vertexInput.aColor / 255.0;\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n vertexOutput.vColor = vec4f(vertexInput.aColor0 / 255.0, 1.0);\n#else\n vertexOutput.vColor = vertexInput.aColor0 / 255.0;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localPositionMatrix * localPosition, &vertexOutput);\n#endif\n#ifdef HAS_I3S_UVREGION\n vertexOutput.vUvRegion = vertexInput.uvRegion / 65535.0;\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(vertexInput, &vertexOutput);\n#endif\n#ifdef HAS_VERTEX_COLOR\n vertexColor_update(vertexInput, &vertexOutput);\n#endif\n return vertexOutput;\n}";
94
+ var glPhongVert = "struct VertexInput {\n#include <position_vert>\n#ifdef HAS_MAP\n #if HAS_DRACO_TEXCOORD || HAS_COMPRESSED_INT16_TEXCOORD_0\n @location($i) aTexCoord: vec2i,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n#ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR\n @location($i) aColor: vec4f,\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n @location($i) aColor0: vec3f,\n#else\n @location($i) aColor0: vec4f,\n#endif\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n @location($i) aExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($i) aTangent: vec4f,\n#endif\n#ifdef HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #elif NORMAL_IS_UINT\n @location($i) aNormal: vec4u,\n #else\n @location($i) aNormal: vec3f,\n #endif\n#endif\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vFragPos: vec3f,\n @location($o) vNormal: vec3f,\n#ifdef HAS_MAP\n @location($o) vTexCoord: vec2f,\n#ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR || HAS_COLOR0\n @location($o) vColor: vec4f,\n#endif\n#if HAS_EXTRUSION_OPACITY\n @location($o) vExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($o) vTangent: vec4f,\n#endif\n};\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n projViewMatrix: mat4x4f,\n};\nstruct ModelUniforms {\n modelNormalMatrix: mat3x3f,\n modelViewMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n uvScale: vec2f,\n uvOffset: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> modelUniforms: ModelUniforms;\n#include <line_extrusion_vert>\n#include <highlight_vert>\n#include <get_output>\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_vert>\n#endif\n#include <vertex_color_vert>\nfn toTangentFrame1(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nfn toTangentFrame(q: vec4f, n: ptr<function, vec3f>, t: ptr<function, vec3f>) {\n *n = toTangentFrame1(q);\n *t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput : VertexOutput;\n#if IS_LINE_EXTRUSION\n let localPosition = getPosition(getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput), vertexInput);\n#else\n let localPosition = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n#endif\n let localPositionMatrix = getPositionMatrix(vertexInput, &vertexOutput, modelUniforms.positionMatrix);\n vertexOutput.vFragPos = (modelUniforms.modelMatrix * localPositionMatrix * localPosition).xyz;\n#if HAS_NORMAL || HAS_TANGENT\n let localNormalMatrix = modelUniforms.modelNormalMatrix * mat3x3f(localPositionMatrix[0].xyz, localPositionMatrix[1].xyz, localPositionMatrix[2].xyz);\n var Normal: vec3f;\n#if HAS_TANGENT\n var t: vec3f;\n toTangentFrame(vertexInput.aTangent, Normal, t);\n vertexOutput.vTangent = vec4f(localNormalMatrix * t, vertexInput.aTangent.w);\n#else\n Normal = decode_getNormal(vec3f(vertexInput.aNormal.xyz));\n#endif\n let localNormal = appendMorphNormal(Normal, vertexInput);\n vertexOutput.vNormal = normalize(localNormalMatrix * localNormal);\n#else\n vertexOutput.vNormal = vec3f(0.0);\n#endif\n var jitteredProjection = uniforms.projMatrix;\n#ifdef HAS_MASK_EXTENT\n vertexOutput.position = jitteredProjection * getMaskPosition(localPositionMatrix * localPosition, uniforms.modelMatrix);\n#else\n vertexOutput.position = jitteredProjection * modelUniforms.modelViewMatrix * localPositionMatrix * localPosition;\n#endif\n#ifdef HAS_MAP\n let decodedTexCoord = decode_getTexcoord(vec2f(vertexInput.aTexCoord));\n vertexOutput.vTexCoord = decodedTexCoord * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_AO_MAP\n let decodedTexCoord1 = decode_getTexcoord(vec2f(vertexInput.aTexCoord1));\n vertexOutput.vTexCoord1 = decodedTexCoord1 * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n vertexOutput.vExtrusionOpacity = vertexInput.aExtrusionOpacity;\n#endif\n#if HAS_COLOR\n vertexOutput.vColor = vertexInput.aColor / 255.0;\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n vertexOutput.vColor = vec4f(vertexInput.aColor0 / 255.0, 1.0);\n#else\n vertexOutput.vColor = vertexInput.aColor0 / 255.0;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localPositionMatrix * localPosition, &vertexOutput);\n#endif\n#ifdef HAS_I3S_UVREGION\n vertexOutput.vUvRegion = vertexInput.uvRegion / 65535.0;\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(vertexInput, &vertexOutput);\n#endif\n#ifdef HAS_VERTEX_COLOR\n vertexColor_update(vertexInput, &vertexOutput);\n#endif\n return vertexOutput;\n}";
95
95
 
96
96
  var glQuadFrag = "#define SHADER_NAME QUAD\nstruct QuadFragUniforms {\n outputSize: vec2f,\n inputSize: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: QuadFragUniforms;\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var TextureInput: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var TextureInput: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var TextureInputSampler: sampler;\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n let uv = vertexOutput.position.xy;\n #ifdef HAS_MULTISAMPLED\n let color = textureLoad(TextureInput, vec2i(uv / uniforms.outputSize * uniforms.inputSize), 0);\n #else\n let color = textureSample(TextureInput, TextureInputSampler, uv / uniforms.outputSize);\n #endif\n return color;\n}";
97
97
 
@@ -103,13 +103,29 @@ var glShadowDisplayVert = "#include <vsm_shadow_vert>\nstruct VertexInput {\n
103
103
 
104
104
  var glVsmMappingFrag = "#ifdef PACK_FLOAT\n #include <common_pack_float>\n#endif\nstruct FragmentOutput {\n @location(0) color: vec4f,\n};\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n var color: vec4f;\n #if USE_ESM\n #ifdef PACK_FLOAT\n color = common_encodeDepth(vertexOutput.position.z);\n #else\n color = vec4f(vertexOutput.position.z, 0.0, 0.0, 1.0);\n #endif\n #endif\n return color;\n}";
105
105
 
106
- var glVsmMappingVert = "#include <line_extrusion_vert>\n#include <get_output>\nstruct ShadowMappingUniforms {\n lightProjViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n};\nstruct VertexInput {\n @location($i) aPosition: POSITION_TYPE_3,\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@group(0) @binding($b) var<uniform> uniforms: ShadowMappingUniforms;\n@vertex\nfn main(\n vertexInput: VertexInput\n) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let localVertex = getPosition(linePosition, vertexInput);\n #else\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.position = uniforms.lightProjViewModelMatrix * localPositionMatrix * localVertex;\n return output;\n}";
106
+ var glVsmMappingVert = "#include <line_extrusion_vert>\n#include <get_output>\nstruct ShadowMappingUniforms {\n lightProjViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n};\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@group(0) @binding($b) var<uniform> uniforms: ShadowMappingUniforms;\n@vertex\nfn main(\n vertexInput: VertexInput\n) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let localVertex = getPosition(linePosition, vertexInput);\n #else\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.position = uniforms.lightProjViewModelMatrix * localPositionMatrix * localVertex;\n return output;\n}";
107
107
 
108
108
  var glSkyboxFrag = "#include <hsv_frag>\nstruct SkyboxUniforms {\n hsv: vec3f,\n #ifdef USE_AMBIENT\n diffuseSPH: array<vec3f, 9>,\n #else\n bias: f32,\n size: f32,\n #endif\n environmentExposure: f32,\n backgroundIntensity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: SkyboxUniforms;\n#ifndef USE_AMBIENT\n @group(0) @binding($b) var cubeMap: texture_cube<f32>;\n @group(0) @binding($b) var cubeMapSampler: sampler;\n#endif\nfn textureCubeFixed(tex: texture_cube<f32>, texSampler: sampler, R: vec3f, size: f32, bias: f32) -> vec4f {\n var dir: vec3f = R;\n return textureSampleLevel(tex, texSampler, dir, bias);\n}\nfn computeDiffuseSPH(normal: vec3f, diffuseSPH: array<vec3f, 9>) -> vec3f {\n let x: f32 = normal.x;\n let y: f32 = normal.y;\n let z: f32 = normal.z;\n var result: vec3f = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x * x - y * y)\n );\n return max(result, vec3f(0.0));\n}\nfn pseudoRandom(fragCoord: vec2f) -> f32 {\n var p3: vec3f = fract(vec3f(fragCoord.x, fragCoord.y, fragCoord.x) * 0.1031);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n}\n#if TONE_MAPPING\n const toneMappingExposure: f32 = 1.0;\n fn RRTAndODTFit(v: vec3f) -> vec3f {\n let a: vec3f = v * (v + 0.0245786) - 0.000090537;\n let b: vec3f = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n }\n fn ACESFilmicToneMapping(color: vec3f) -> vec3f {\n const ACESInputMat: mat3x3f = mat3x3f(\n vec3f(0.59719, 0.07600, 0.02840),\n vec3f(0.35458, 0.90834, 0.13383),\n vec3f(0.04823, 0.01566, 0.83777)\n );\n const ACESOutputMat: mat3x3f = mat3x3f(\n vec3f(1.60475, -0.10208, -0.00327),\n vec3f(-0.53108, 1.10813, -0.07276),\n vec3f(-0.07367, -0.00605, 1.07602)\n );\n var adjustedColor: vec3f = color * toneMappingExposure / 0.6;\n adjustedColor = ACESInputMat * adjustedColor;\n adjustedColor = RRTAndODTFit(adjustedColor);\n adjustedColor = ACESOutputMat * adjustedColor;\n return clamp(adjustedColor, 0, 1);\n }\n fn toneMapping(color: vec3f) -> vec3f {\n return ACESFilmicToneMapping(color);\n }\n fn sRGBTransferOETF(value: vec4f) -> vec4f {\n var result: vec3f;\n let threshold: vec3f = vec3f(0.0031308);\n for (var i: i32 = 0; i < 3; i++) {\n if (value[i] <= threshold[i]) {\n result[i] = value[i] * 12.92;\n } else {\n result[i] = pow(value[i], 0.41666) * 1.055 - 0.055;\n }\n }\n return vec4f(result, value.a);\n }\n fn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n }\n#endif\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var envColor: vec4f;\n #ifdef USE_AMBIENT\n var normal: vec3f = normalize(\n vertexOutput.vWorldPos +\n mix(-0.5/255.0, 0.5/255.0, pseudoRandom(vertexOutput.fragCoord.xy)) * 2.0\n );\n envColor = vec4f(computeDiffuseSPH(normal, uniforms.diffuseSPH), 1.0);\n #else\n envColor = textureCubeFixed(\n cubeMap,\n cubeMapSampler,\n vertexOutput.vWorldPos,\n uniforms.size,\n uniforms.bias\n );\n #endif\n var rgb = envColor.rgb;\n rgb *= uniforms.environmentExposure;\n rgb *= uniforms.backgroundIntensity;\n if (length(uniforms.hsv) > 0.0) {\n rgb = hsv_apply3(clamp(rgb, vec3f(0.0), vec3f(1.0)), uniforms.hsv);\n }\n #if TONE_MAPPING\n rgb = toneMapping(rgb);\n let fragColor = linearToOutputTexel(vec4f(rgb, envColor.a));\n #else\n let fragColor = vec4f(rgb, envColor.a);\n #endif\n return fragColor;\n}";
109
109
 
110
110
  var glSkyboxVert = "struct Uniforms {\n projMatrix: mat4x4f,\n viewMatrix: mat4x4f,\n transformMatrix: mat3x3f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPos: vec3f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n output.vWorldPos = vertexInput.aPosition;\n let viewMatrix = uniforms.viewMatrix;\n let m3 = mat3x3f(viewMatrix[0].xyz, viewMatrix[1].xyz, viewMatrix[2].xyz) * uniforms.transformMatrix;\n let rotViewMatrix: mat4x4f = mat4x4f(\n vec4<f32>(m3[0], 0.0),\n vec4<f32>(m3[1], 0.0),\n vec4<f32>(m3[2], 0.0),\n vec4<f32>(0.0, 0.0, 0.0, 1.0)\n );\n let clipPos: vec4f = uniforms.projMatrix * rotViewMatrix * vec4f(output.vWorldPos, 1.0);\n output.position = vec4f(clipPos.xy, clipPos.w, clipPos.w);\n return output;\n}";
111
111
 
112
- var layer3dtilesPickingVert = "#include <get_output>\n#include <fbo_picking_vert>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n #ifdef HAS_MASK_EXTENT\n modelViewMatrix: mat4x4f,\n #endif\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let position: vec4f = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelMatrix * position;\n let projMatrix = shaderUniforms.projMatrix;\n #ifdef HAS_MASK_EXTENT\n output.position = projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = projMatrix * viewVertex;\n #endif\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= vertexInput.aColor.a;\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= vertexInput.aColor0.a;\n #endif\n fbo_picking_setData(vertexInput, &output, output.position.w, alpha != 0.0);\n return output;\n}";
112
+ var glSnowFrag = "struct SnowUniforms {\n fixedC: vec3f,\n};\n@group(0) @binding($b) var<uniform> snowUniforms: SnowUniforms;\n@group(0) @binding($b) var perlinTexture: texture_2d<f32>;\n@group(0) @binding($b) var perlinTextureSampler: sampler;\nfn lerp(a: f32, b: f32, w: f32) -> f32 {\n return a + w * (b - a);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let snowIntense = textureSample(perlinTexture, perlinTextureSampler, vertexOutput.vTexCoord).r;\n let r = lerp(0.5, snowUniforms.fixedC.x, snowIntense);\n let g = lerp(0.5, snowUniforms.fixedC.y, snowIntense);\n let b = lerp(0.5, snowUniforms.fixedC.z, snowIntense);\n return vec4f(r, g, b, 1.0);\n}";
113
+
114
+ var glSnowVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n @location($i) aTexCoord: vec2f\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vTexCoord: vec2f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = shaderUniforms.projMatrix * uniforms.modelViewMatrix * localPosition;\n output.vTexCoord = vertexInput.aTexCoord;\n return output;\n}";
115
+
116
+ var glRainFrag = "struct RainUniforms {\n diffuse: vec3f,\n opacity: f32,\n};\n@group(0) @binding($b) var<uniform> rainUniforms: RainUniforms;\n@group(0) @binding($b) var rainMap: texture_2d<f32>;\n@group(0) @binding($b) var rainMapSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let rainColor = textureSample(rainMap, rainMapSampler, vertexOutput.vTexCoord);\n var diffuseColor = vec4f(rainUniforms.diffuse, rainUniforms.opacity);\n diffuseColor *= rainColor;\n return diffuseColor;\n}";
117
+
118
+ var glRainVert = "#include <get_output>\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aNormal: vec3f,\n @location($i) aTexCoord: vec2f,\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vTexCoord: vec2f,\n};\nstruct Uniforms {\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n top: f32,\n bottom: f32,\n};\nstruct VertexShaderUniforms {\n projMatrix: mat4x4f,\n cameraPosition: vec3f,\n time: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: VertexShaderUniforms;\nfn angle(x: f32, y: f32) -> f32 {\n return atan2(y, x);\n}\nfn getFoot(camera: vec2f, normal: vec2f, pos: vec2f) -> vec2f {\n var position = vec2f(0.0, 0.0);\n let distanceLen = distance(pos, normal);\n var a = angle(camera.x - normal.x, camera.y - normal.y);\n if pos.x > normal.x {\n a -= 0.785;\n } else {\n a += 0.785;\n }\n position.x = cos(a) * distanceLen;\n position.y = sin(a) * distanceLen;\n return position + normal;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let foot = getFoot(\n vec2f(shaderUniforms.cameraPosition.x, shaderUniforms.cameraPosition.z),\n vec2f(vertexInput.aNormal.x, vertexInput.aNormal.z),\n vec2f(localPosition.x, localPosition.z)\n );\n let height = uniforms.top - uniforms.bottom;\n var y = vertexInput.aNormal.y - uniforms.bottom - height * shaderUniforms.time;\n if y < 0.0 {\n y += height;\n }\n let ratio = (1.0 - y / height) * (1.0 - y / height);\n y = height * (1.0 - ratio);\n y += uniforms.bottom;\n y += vertexInput.aPosition.y - vertexInput.aNormal.y;\n let finalLocalPosition = vec4f(foot.x, y, foot.y, 1.0);\n output.position = shaderUniforms.projMatrix *\n uniforms.modelViewMatrix *\n localPositionMatrix *\n finalLocalPosition;\n output.vTexCoord = vertexInput.aTexCoord;\n return output;\n}";
119
+
120
+ var glRipplesFrag = "struct RippleEffectUniforms {\n rippleRadius: f32,\n density: f32,\n time: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: RippleEffectUniforms;\nfn hash3(p: vec2f) -> vec3f {\n let q = vec3f(\n dot(p, vec2f(127.1, 311.7)),\n dot(p, vec2f(269.5, 183.3)),\n dot(p, vec2f(419.2, 371.9))\n );\n return fract(sin(q) * 43758.5453);\n}\nfn noise(x: vec2f) -> f32 {\n let v = x * uniforms.density / 4000.0;\n let p = floor(v);\n let f = fract(v);\n var va: f32 = 0.0;\n for (var j: i32 = -4; j <= 4; j++) {\n for (var i: i32 = -4; i <= 4; i++) {\n let g = vec2f(f32(i), f32(j));\n let o = hash3(p + g);\n let r = g - f + o.xy;\n let d = sqrt(dot(r, r));\n let ripple = max(mix(smoothstep(0.99, 0.999, max(cos(d - uniforms.time * 2.0 + (o.x + o.y) * 5.0), 0.0)), 0.0, d), 0.0);\n va += ripple;\n }\n }\n return va;\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let uv = vertexOutput.vTexCoord;\n let radius = 24.0 / (uniforms.rippleRadius * 0.01);\n let f = noise(radius * uv) * smoothstep(0.0, 0.4, sin(uv.x * 3.151592) * sin(uv.y * 3.141592));\n let normal = vec3f(-dpdx(f), -dpdy(f), -dpdy(f));\n return vec4f(normal, 1.0);\n}";
121
+
122
+ var glFogFrag = "struct WeatherUniforms {\n time: f32,\n resolution: vec2f,\n #ifdef HAS_SNOW\n snowIntensity: f32,\n #endif\n #ifdef HAS_FOG\n fogColor: vec3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: WeatherUniforms;\n#ifdef HAS_RAIN\n @group(0) @binding($b) var ripplesMapSampler: sampler;\n @group(0) @binding($b) var ripplesMap: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var sceneMapSampler: sampler;\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var sceneMap: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var sceneMap: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var mixFactorMapSampler: sampler;\n#ifdef HAS_MULTISAMPLED_MAP\n @group(0) @binding($b) var mixFactorMap: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var mixFactorMap: texture_2d<f32>;\n#endif\nconst HASHSCALE1 = 0.1031;\nconst HASHSCALE3 = vec3f(0.1031, 0.1030, 0.0973);\nconst HASHSCALE4 = vec4f(0.1031, 0.1030, 0.0973, 0.1099);\nconst SIZE_RATE = 0.5;\nconst XSPEED = 0.2;\nconst YSPEED = 0.5;\nconst LAYERS = 20.0;\nfn lerp(a: f32, b: f32, w: f32) -> f32 {\n return a + w * (b - a);\n}\nfn Hash11(p: f32) -> f32 {\n var p3 = fract(vec3f(p) * HASHSCALE1);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n}\nfn Hash22(p: vec2f) -> vec2f {\n var p3 = fract(vec3f(p.x, p.y, p.x) * HASHSCALE3);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.xx + p3.yz) * p3.zy);\n}\nfn Rand22(co: vec2f) -> vec2f {\n let x = fract(sin(dot(co, vec2f(122.9898, 783.233))) * 43758.5453);\n let y = fract(sin(dot(co, vec2f(457.6537, 537.2793))) * 37573.5913);\n return vec2f(x, y);\n}\n#ifdef HAS_SNOW\n fn SnowSingleLayer(uv: vec2f, layer: f32) -> vec3f {\n var uv_mut = uv * (2.0 + layer);\n let speedX = XSPEED * uniforms.snowIntensity;\n let xOffset = uv_mut.y * (((Hash11(layer) * 2.0 - 1.0) * 0.5 + 1.0) * speedX);\n let yOffset = YSPEED * uniforms.time;\n uv_mut += vec2f(xOffset, yOffset);\n let rgrid = Hash22(floor(uv_mut) + (31.1759 * layer));\n uv_mut = fract(uv_mut);\n uv_mut -= (rgrid * 2.0 - 1.0) * 0.35;\n uv_mut -= 0.5;\n let r = length(uv_mut);\n let circleSize = 0.05 * (1.0 + 0.3 * sin(uniforms.time * SIZE_RATE));\n let val = smoothstep(circleSize, -circleSize, r);\n let col = vec3f(val, val, val) * rgrid.x;\n return col;\n }\n fn snowFlower(fragCoord: vec2f) -> vec3f {\n var acc = vec3f(0.0, 0.0, 0.0);\n var uv = fragCoord / uniforms.resolution;\n uv.y = 1.0 - uv.y;\n uv *= vec2f(uniforms.resolution.x / uniforms.resolution.y, 1.0);\n let layers = LAYERS * uniforms.snowIntensity;\n for (var i: f32 = 0.0; i < layers; i += 1.0) {\n acc += SnowSingleLayer(uv, i);\n }\n return acc;\n }\n fn snow(sceneColor: vec4f, normalColor: vec4f, height: f32) -> vec3f {\n let snowIntense = normalColor.b;\n let fixedC = vec3f(1.0, 1.0, 1.0);\n if (height < 1.0) {\n let r = lerp(0.5, fixedC.x, snowIntense);\n let g = lerp(0.5, fixedC.y, snowIntense);\n let b = lerp(0.5, fixedC.z, snowIntense);\n return vec3f(r, g, b);\n } else {\n let r = lerp(sceneColor.r, fixedC.x, snowIntense);\n let g = lerp(sceneColor.g, fixedC.y, snowIntense);\n let b = lerp(sceneColor.b, fixedC.z, snowIntense);\n return vec3f(r, g, b);\n }\n }\n#endif\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n var uv = vertexOutput.vTexCoord;\n uv.y = 1.0 - uv.y;\n #ifdef HAS_MULTISAMPLED\n var sceneColor = textureLoad(sceneMap, vec2i(uv * uniforms.resolution), 0);\n #else\n var sceneColor = textureSample(sceneMap, sceneMapSampler, uv);\n #endif\n var glFragColor = sceneColor;\n #ifdef HAS_MULTISAMPLED_MAP\n let mixFactorColor = textureLoad(mixFactorMap, vec2i(uv * uniforms.resolution), 0);\n #else\n let mixFactorColor = textureSample(mixFactorMap, mixFactorMapSampler, uv);\n #endif\n #ifdef HAS_RAIN\n let ripplesColor = textureSample(ripplesMap, ripplesMapSampler, uv);\n if (mixFactorColor.g < 1.0) {\n sceneColor = mix(sceneColor, ripplesColor, 0.4);\n }\n glFragColor = sceneColor;\n #endif\n #ifdef HAS_SNOW\n let fragCoord = vertexOutput.position.xy;\n let snowFlowerColor = snowFlower(fragCoord);\n glFragColor = vec4f(sceneColor.rgb + snowFlowerColor, sceneColor.a);\n #endif\n #ifdef HAS_FOG\n let mixFactor = mixFactorColor.r;\n let mixColor = mix(uniforms.fogColor, glFragColor.rgb, mixFactor);\n glFragColor = vec4f(mixColor, sceneColor.a);\n #endif\n return glFragColor;\n}";
123
+
124
+ var glFogMixFactorVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n @location($i) aTexCoord: vec2f\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPosition: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = shaderUniforms.projMatrix * uniforms.modelViewMatrix * localPosition;\n let worldPosition = uniforms.modelMatrix * localPosition;\n output.vWorldPosition = worldPosition;\n return output;\n}";
125
+
126
+ var glFogMixFactorFrag = "struct FogEffectUniforms {\n fogDist: vec2f,\n cameraPosition: vec3f,\n rainDepth: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: FogEffectUniforms;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let worldPosition = vertexOutput.vWorldPosition;\n let dir = vec3f(\n worldPosition.x - uniforms.cameraPosition.x,\n worldPosition.y - uniforms.cameraPosition.y,\n worldPosition.z - uniforms.cameraPosition.z\n );\n let dist = length(dir);\n let fogFactor = clamp(1.0 - (dist - uniforms.fogDist.x) / (uniforms.fogDist.y - uniforms.fogDist.x), 0.0, 1.0);\n var gl_FragColor: vec4f;\n if (worldPosition.z < uniforms.rainDepth) {\n gl_FragColor = vec4f(fogFactor, 0.0, 0.0, 1.0);\n } else {\n gl_FragColor = vec4f(fogFactor, 1.0, 0.0, 1.0);\n }\n return gl_FragColor;\n}";
127
+
128
+ var layer3dtilesPickingVert = "#include <get_output>\n#include <fbo_picking_vert>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n #ifdef HAS_MASK_EXTENT\n modelViewMatrix: mat4x4f,\n #endif\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let position: vec4f = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelMatrix * position;\n let projMatrix = shaderUniforms.projMatrix;\n #ifdef HAS_MASK_EXTENT\n output.position = projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = projMatrix * viewVertex;\n #endif\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= vertexInput.aColor.a;\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= vertexInput.aColor0.a;\n #endif\n fbo_picking_setData(vertexInput, &output, output.position.w, alpha != 0.0);\n return output;\n}";
113
129
 
114
130
  var layerVideoVideoFrag = "struct FragUniforms {\n opacity: f32\n}\n@group(0) @binding($b) var videoTexture: texture_2d<f32>;\n@group(0) @binding($b) var videoTextureSampler: sampler;\n@group(0) @binding($b) var<uniform> fragUniforms: FragUniforms;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let color = textureSample(videoTexture, videoTextureSampler, vertexOutput.vTexCoords);\n return color * fragUniforms.opacity;\n}";
115
131
 
@@ -157,6 +173,10 @@ var vtTextVert = "#define SHADER_NAME TEXT_VERT\n#define RAD 0.0174532925\nstruc
157
173
 
158
174
  var vtTubeVert = "#define EXTRUDE_SCALE 63.0\n#define EXTRUDE_MOD 64.0\n#define MAX_LINE_DISTANCE 65535.0\nstruct TubeUniforms {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n centiMeterToLocal: vec2f,\n lineWidth: f32,\n modelViewMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n modelMatrix: mat4x4f,\n tileResolution: f32,\n tileRatio: f32,\n};\nstruct TubeShaderUniforms {\n resolution: f32,\n}\n@group(0) @binding($b) var<uniform> uniforms: TubeUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: TubeShaderUniforms;\nstruct VertexInput {\n #ifdef HAS_ALTITUDE\n @location($i) aPosition: POSITION_TYPE_2,\n @location($i) aAltitude: f32,\n #else\n @location($i) aPosition: POSITION_TYPE_3,\n #endif\n @location($i) aTubeNormal: vec4i,\n #ifdef HAS_LINE_WIDTH\n @location($i) aLineWidth: u32,\n #endif\n #ifdef HAS_PATTERN\n @location($i) aLinesofar: u32,\n @location($i) aTexInfo: vec4u,\n @location($i) aNormalDistance: i32,\n #if HAS_PATTERN_ANIM\n @location($i) aLinePatternAnimSpeed: i32,\n #endif\n #if HAS_PATTERN_GAP\n @location($i) aLinePatternGap: i32,\n #endif\n #endif\n #ifdef HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifndef PICKING_MODE\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n @location($o) vModelVertex: vec3f,\n #ifdef HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #ifdef HAS_PATTERN\n @location($o) vLinesofar: f32,\n @location($o) vTexInfo: vec4f,\n @location($o) vNormalY: f32,\n @location($o) vPatternHeight: f32,\n #if HAS_PATTERN_ANIM\n @location($o) vLinePatternAnimSpeed: f32,\n #endif\n #if HAS_PATTERN_GAP\n @location($o) vLinePatternGap: f32,\n #endif\n #endif\n #endif\n};\n#include <vt_position_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#else\n #if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n #endif\n#endif\n#include <highlight_vert>\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n #ifdef HAS_LINE_WIDTH\n let myLineWidth = input.aLineWidth;\n #else\n let myLineWidth = uniforms.lineWidth;\n #endif\n let halfwidth = myLineWidth / 2.0;\n let tubeNormal = vec3f(input.aTubeNormal.xyz) / EXTRUDE_SCALE;\n let position = unpackVTPosition(input);\n var localVertex = vec4f(position, 1.0);\n let dxy = tubeNormal.xy * halfwidth * uniforms.centiMeterToLocal;\n let dz = tubeNormal.z * halfwidth;\n localVertex = vec4f(localVertex.xy + dxy, localVertex.z + dz, localVertex.w);\n output.position = uniforms.projViewModelMatrix * localVertex;\n #ifdef PICKING_MODE\n fbo_picking_setData(input, &output, output.position.w, true);\n #else\n output.vViewVertex = uniforms.modelViewMatrix * localVertex;\n let localNormal = normalize(tubeNormal);\n output.vModelNormal = uniforms.modelNormalMatrix * localNormal;\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localVertex);\n #endif\n #ifdef HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #ifdef HAS_PATTERN\n let scale = uniforms.tileResolution / shaderUniforms.resolution;\n #ifdef HAS_ALTITUDE\n let linesofar = f32(input.aLinesofar) - halfwidth * uniforms.centiMeterToLocal.y * f32(input.aNormalDistance) / EXTRUDE_SCALE;\n #else\n let linesofar = f32(input.aLinesofar);\n #endif\n output.vLinesofar = linesofar / uniforms.tileRatio * scale;\n output.vTexInfo = vec4f(vec2f(input.aTexInfo.xy), vec2f(input.aTexInfo.zw) + 1.0);\n output.vPatternHeight = myLineWidth * uniforms.centiMeterToLocal.x / uniforms.tileRatio * scale;\n output.vNormalY = f32(input.aTubeNormal.w) / EXTRUDE_SCALE;\n #if HAS_PATTERN_ANIM\n output.vLinePatternAnimSpeed = input.aLinePatternAnimSpeed / 127.0;\n #endif\n #if HAS_PATTERN_GAP\n output.vLinePatternGap = f32(input.aLinePatternGap) / 10.0;\n #endif\n #endif\n #if HAS_HIGHLIGHT_COLOR || HAS_HIGHLIGHT_OPACITY\n highlight_setVarying(input, &output);\n #endif\n #endif\n return output;\n}";
159
175
 
176
+ var vtFlatMaskFrag = "#include <common_pack_float>\n@fragment\nfn main(output: VertexOutput) -> @location(0) vec4f {\n return encodeFloat32(output.vAltitude);\n}";
177
+
178
+ var vtFlatMaskVert = "struct VertexInput {\n#ifdef HAS_ALTITUDE\n @location($i) aPosition: POSITION_TYPE_2,\n @location($i) aAltitude: f32,\n#else\n @location($i) aPosition: POSITION_TYPE_3,\n#endif\n}\nstruct UniformsStruct {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: UniformsStruct;\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vAltitude: f32,\n}\n#include <vt_position_vert>\n@vertex\nfn main(\n input: VertexInput,\n) -> VertexOutput {\n let position = unpackVTPosition(input);\n var output: VertexOutput;\n var localVertex = uniforms.positionMatrix * vec4f(position, 1.0);\n output.vAltitude = localVertex.z / 100;\n localVertex.z = 0;\n output.position = uniforms.projViewModelMatrix * localVertex;\n return output;\n}";
179
+
160
180
  registerWGSLSource('analysis_depth_frag', analysisDepthFrag);
161
181
  registerWGSLSource('analysis_depth_vert', analysisDepthVert);
162
182
  registerWGSLSource('analysis_excavateExtent_frag', analysisExcavateExtentFrag);
@@ -167,6 +187,7 @@ registerWGSLSource('analysis_insight_frag', analysisInsightFrag);
167
187
  registerWGSLSource('analysis_insight_vert', analysisInsightVert);
168
188
  registerWGSLSource('analysis_viewshed_frag', analysisViewshedFrag);
169
189
  registerWGSLSource('analysis_viewshed_vert', analysisViewshedVert);
190
+
170
191
  registerWGSLSource('gl_analysis_frag', glAnalysisFrag);
171
192
  registerWGSLSource('gl_fill_frag', glFillFrag);
172
193
  registerWGSLSource('gl_fill_vert', glFillVert);
@@ -200,9 +221,20 @@ registerWGSLSource('gl_vsm_mapping_frag', glVsmMappingFrag);
200
221
  registerWGSLSource('gl_vsm_mapping_vert', glVsmMappingVert);
201
222
  registerWGSLSource('gl_skybox_frag', glSkyboxFrag);
202
223
  registerWGSLSource('gl_skybox_vert', glSkyboxVert);
224
+ registerWGSLSource('gl_snow_frag', glSnowFrag);
225
+ registerWGSLSource('gl_snow_vert', glSnowVert);
226
+ registerWGSLSource('gl_rain_frag', glRainFrag);
227
+ registerWGSLSource('gl_rain_vert', glRainVert);
228
+ registerWGSLSource('gl_ripples_vert', glSnowVert);
229
+ registerWGSLSource('gl_ripples_frag', glRipplesFrag);
230
+ registerWGSLSource('gl_fog_frag', glFogFrag);
231
+ registerWGSLSource('gl_fog_mixFactor_vert', glFogMixFactorVert);
232
+ registerWGSLSource('gl_fog_mixFactor_frag', glFogMixFactorFrag);
233
+
203
234
  registerWGSLSource('layer_3dtiles_picking_vert', layer3dtilesPickingVert);
204
235
  registerWGSLSource('layer_video_video_frag', layerVideoVideoFrag);
205
236
  registerWGSLSource('layer_video_video_vert', layerVideoVideoVert);
237
+
206
238
  registerWGSLSource('vt_billboard_frag', vtBillboardFrag);
207
239
  registerWGSLSource('vt_billboard_vert', vtBillboardVert);
208
240
  registerWGSLSource('vt_collision_frag', vtCollisionFrag);
@@ -224,5 +256,7 @@ registerWGSLSource('vt_text_frag', vtTextFrag);
224
256
  registerWGSLSource('vt_text_line_vert', vtTextLineVert);
225
257
  registerWGSLSource('vt_text_vert', vtTextVert);
226
258
  registerWGSLSource('vt_tube_vert', vtTubeVert);
259
+ registerWGSLSource('vt_flat_mask_frag', vtFlatMaskFrag);
260
+ registerWGSLSource('vt_flat_mask_vert', vtFlatMaskVert);
227
261
 
228
- typeof console !== 'undefined' && console.log('@maptalks/gpu v0.123.0');
262
+ typeof console !== 'undefined' && console.log('@maptalks/gpu v0.124.1');
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @maptalks/gpu v0.123.0
2
+ * @maptalks/gpu v0.124.1
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2026 maptalks.com
5
5
  */
@@ -30,23 +30,23 @@
30
30
 
31
31
  var analysisDepthFrag = "struct FragUniforms {\n logDepthBufFC: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: FragUniforms;\nconst PackUpscale: f32 = 256.0 / 255.0;\nconst UnpackDownscale: f32 = 255.0 / 256.0;\nconst PackFactors: vec3f = vec3f(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0);\nconst UnpackFactors: vec4f = vec4f(UnpackDownscale / PackFactors, UnpackDownscale);\nconst ShiftRight8: f32 = 1.0 / 256.0;\nfn packDepthToRGBA(v: f32) -> vec4f {\n var r: vec4f = vec4f(fract(v * PackFactors), v);\n r = vec4f(r.x, r.yzw - r.xyz * ShiftRight8);\n return r * PackUpscale;\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let fragCoordZ: f32 = vertexOutput.vHighPrecisionZW[0] / vertexOutput.vHighPrecisionZW[1];\n var glFragColor: vec4f = packDepthToRGBA(fragCoordZ);\n return glFragColor;\n}";
32
32
 
33
- var analysisDepthVert = "#include <get_output>\nstruct Uniforms {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n#ifdef HAS_ALTITUDE\nstruct VertexInput {\n @location($i) aPosition: vec2f,\n @location($i) aAltitude: f32,\n};\n#else\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\n#endif\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vHighPrecisionZW: vec2f,\n @location($o) vFragDepth: f32,\n};\n#ifdef HAS_ALTITUDE\nfn unpackVTPosition(vertexInput: VertexInput) -> vec3f {\n return vec3f(vertexInput.aPosition, vertexInput.aAltitude);\n}\n#endif\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n #ifdef HAS_ALTITUDE\n let i: vec3f = unpackVTPosition(vertexInput);\n let j: vec4f = vec4f(i, 1.0);\n output.position = uniforms.projViewModelMatrix * j;\n #else\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n output.position = uniforms.projViewModelMatrix * localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.vFragDepth = 1.0 + output.position.w;\n output.vHighPrecisionZW = output.position.zw;\n return output;\n}";
33
+ var analysisDepthVert = "#include <get_output>\nstruct Uniforms {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n#ifdef HAS_ALTITUDE\nstruct VertexInput {\n @location($i) aPosition: vec2f,\n @location($i) aAltitude: f32,\n};\n#else\nstruct VertexInput {\n #include <position_vert>\n};\n#endif\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vHighPrecisionZW: vec2f,\n @location($o) vFragDepth: f32,\n};\n#ifdef HAS_ALTITUDE\nfn unpackVTPosition(vertexInput: VertexInput) -> vec3f {\n return vec3f(vertexInput.aPosition, vertexInput.aAltitude);\n}\n#endif\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n #ifdef HAS_ALTITUDE\n let i: vec3f = unpackVTPosition(vertexInput);\n let j: vec4f = vec4f(i, 1.0);\n output.position = uniforms.projViewModelMatrix * j;\n #else\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n output.position = uniforms.projViewModelMatrix * localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.vFragDepth = 1.0 + output.position.w;\n output.vHighPrecisionZW = output.position.zw;\n return output;\n}";
34
34
 
35
35
  var analysisExcavateExtentFrag = "@fragment\nfn main() -> @location(0) vec4f {\n return vec4f(1.0, 0.0, 0.0, 1.0);\n}";
36
36
 
37
- var analysisExcavateExtentVert = "#include <get_output>\nstruct Uniforms {\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
37
+ var analysisExcavateExtentVert = "#include <get_output>\nstruct Uniforms {\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
38
38
 
39
39
  var analysisFloodFrag = "struct FloodAnalysisUniforms {\n extent: vec4f,\n waterHeight: f32,\n hasExtent: f32,\n analysisType: f32,\n};\n@group(0) @binding($b) var<uniform> floodAnalysisUniforms: FloodAnalysisUniforms;\n@group(0) @binding($b) var extentMap: texture_2d<f32>;\n@group(0) @binding($b) var extentMapSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let extent = floodAnalysisUniforms.extent;\n let waterHeight = floodAnalysisUniforms.waterHeight;\n let hasExtent = floodAnalysisUniforms.hasExtent;\n let analysisType = floodAnalysisUniforms.analysisType;\n let width = extent.z - extent.x;\n let height = extent.y - extent.w;\n let uvInExtent = vec2f(\n (vertexOutput.vWorldPosition.x - extent.x) / width,\n (vertexOutput.vWorldPosition.y - extent.w) / height\n );\n let extentColor = textureSample(extentMap, extentMapSampler, uvInExtent);\n var compare: bool;\n if (analysisType == 1.0) {\n compare = vertexOutput.flood_height < waterHeight;\n } else {\n compare = vertexOutput.flood_height >= waterHeight;\n }\n var color: vec4f = vec4f(0.0);\n if (compare) {\n if (hasExtent == 1.0) {\n if (extentColor.r > 0.0) {\n color = vec4f(1.0, 0.0, 0.0, 1.0);\n }\n } else {\n color = vec4f(1.0, 0.0, 0.0, 1.0);\n }\n }\n return color;\n}";
40
40
 
41
- var analysisFloodVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n projViewMatrix: mat4x4f\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPosition: vec4f,\n @location($o) flood_height: f32,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let worldPosition = uniforms.modelMatrix * localPosition;\n output.position = shaderUniforms.projViewMatrix * worldPosition;\n output.vWorldPosition = worldPosition;\n output.flood_height = worldPosition.z;\n return output;\n}";
41
+ var analysisFloodVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n projViewMatrix: mat4x4f\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPosition: vec4f,\n @location($o) flood_height: f32,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let worldPosition = uniforms.modelMatrix * localPosition;\n output.position = shaderUniforms.projViewMatrix * worldPosition;\n output.vWorldPosition = worldPosition;\n output.flood_height = worldPosition.z;\n return output;\n}";
42
42
 
43
43
  var analysisInsightFrag = "@group(0) @binding($b) var depthMap: texture_2d<f32>;\n@group(0) @binding($b) var depthMapSampler: sampler;\nconst UnpackDownscale: f32 = 255.0 / 256.0;\nconst PackFactors: vec3f = vec3f(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0);\nconst UnpackFactors: vec4f = vec4f(UnpackDownscale / PackFactors, UnpackDownscale);\nfn unpackRGBAToDepth(v: vec4f) -> f32 {\n return dot(v, UnpackFactors);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let viewpoint = vertexOutput.viewpoint;\n let shadowCoord = vec3f((viewpoint.xy / viewpoint.w) / 2.0 + 0.5, viewpoint.z / viewpoint.w);\n let rgbaDepth = textureSample(depthMap, depthMapSampler, shadowCoord.xy);\n let depth = unpackRGBAToDepth(rgbaDepth);\n var color: vec4f;\n if (shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 &&\n shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 &&\n shadowCoord.z <= 1.0) {\n if (depth < 0.001) {\n color = vec4f(0.0, 1.0, 0.0, 1.0); } else {\n if (shadowCoord.z <= depth + 0.002) {\n color = vec4f(0.0, 1.0, 0.0, 1.0); } else {\n color = vec4f(1.0, 0.0, 0.0, 1.0); }\n }\n } else {\n color = vec4f(0.0, 0.0, 1.0, 1.0); }\n return color;\n}";
44
44
 
45
- var analysisInsightVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n insight_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.insight_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
45
+ var analysisInsightVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n insight_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.insight_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
46
46
 
47
47
  var analysisViewshedFrag = "struct FragUniforms {\n near: f32,\n far: f32,\n};\n#ifdef HAS_HELPERLINE\n struct HelperUniforms {\n lineColor: vec3f,\n };\n#endif\n@group(0) @binding($b) var<uniform> uniforms: FragUniforms;\n#ifdef HAS_HELPERLINE\n @group(0) @binding($b) var<uniform> helperUniforms: HelperUniforms;\n#endif\n@group(0) @binding($b) var depthMap: texture_2d<f32>;\n@group(0) @binding($b) var depthMapSampler: sampler;\nconst UnpackDownscale: f32 = 255.0 / 256.0;\nconst PackFactors: vec3f = vec3f(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0);\nconst UnpackFactors: vec4f = vec4f(UnpackDownscale / PackFactors, UnpackDownscale);\nfn unpackRGBAToDepth(v: vec4f) -> f32 {\n return dot(v, UnpackFactors);\n}\nfn linear(value: f32) -> f32 {\n let near = uniforms.near;\n let far = uniforms.far;\n let z = value * 2.0 - 1.0;\n return (2.0 * near * far) / (far + near - z * (far - near));\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n #ifdef HAS_HELPERLINE\n return vec4f(helperUniforms.lineColor, 0.009);\n #else\n let near = uniforms.near;\n let far = uniforms.far;\n let viewpoint = vertexOutput.viewpoint;\n let shadowCoord: vec3f = vec3f((viewpoint.xy / viewpoint.w) / 2.0 + 0.5, viewpoint.z / viewpoint.w);\n let rgbaDepth: vec4f = textureSample(depthMap, depthMapSampler, shadowCoord.xy);\n let depth: f32 = unpackRGBAToDepth(rgbaDepth);\n let linearDepth: f32 = linear(depth);\n let linearZ: f32 = linear(shadowCoord.z);\n if (shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 &&\n shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 &&\n linearZ >= near && linearZ <= far - near) {\n if (linearZ <= linearDepth) {\n return vec4f(0.0, 1.0, 0.0, 1.0); } else {\n return vec4f(1.0, 0.0, 0.0, 1.0); }\n } else {\n return vec4f(0.0, 0.0, 1.0, 1.0);\n }\n #endif\n}";
48
48
 
49
- var analysisViewshedVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n viewshed_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.viewshed_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
49
+ var analysisViewshedVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n projViewModelMatrix: mat4x4f,\n};\nstruct ShaderUniforms {\n viewshed_projViewMatrixFromViewpoint: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.viewpoint = shaderUniforms.viewshed_projViewMatrixFromViewpoint * uniforms.modelMatrix * localPosition;\n output.position = uniforms.projViewModelMatrix * localPosition;\n return output;\n}";
50
50
 
51
51
  var glAnalysisFrag = "struct FragmentUniforms {\n resolution: vec2f,\n #ifdef HAS_FLOODANALYSE\n flood_waterColor: vec3f,\n flood_waterOpacity: f32,\n #endif\n #ifdef HAS_VIEWSHED\n viewshed_visibleColor: vec4f,\n viewshed_invisibleColor: vec4f,\n #endif\n #ifdef HAS_INSIGHT\n insight_visibleColor: vec4f,\n insight_invisibleColor: vec4f,\n #endif\n #ifdef HAS_CROSSCUT\n cutLineColor: vec4f,\n #endif\n #ifdef HAS_HEIGHTLIMIT\n limitColor: vec3f,\n #endif\n};\n#ifdef HAS_FLOODANALYSE\n @group(0) @binding($b) var floodMap: texture_2d<f32>;\n @group(0) @binding($b) var floodMapSampler: sampler;\n#endif\n#ifdef HAS_SKYLINE\n @group(0) @binding($b) var skylineMap: texture_2d<f32>;\n @group(0) @binding($b) var skylineMapSampler: sampler;\n#endif\n#ifdef HAS_VIEWSHED\n @group(0) @binding($b) var viewshedMap: texture_2d<f32>;\n @group(0) @binding($b) var viewshedMapSampler: sampler;\n#endif\n#ifdef HAS_INSIGHT\n @group(0) @binding($b) var insightMap: texture_2d<f32>;\n @group(0) @binding($b) var insightMapSampler: sampler;\n#endif\n#ifdef HAS_CUT\n @group(0) @binding($b) var meshesMap: texture_2d<f32>;\n @group(0) @binding($b) var meshesMapSampler: sampler;\n @group(0) @binding($b) var invisibleMap: texture_2d<f32>;\n @group(0) @binding($b) var invisibleMapSampler: sampler;\n#endif\n#ifdef HAS_EXCAVATE\n @group(0) @binding($b) var excavateMap: texture_2d<f32>;\n @group(0) @binding($b) var excavateMapSampler: sampler;\n#endif\n#ifdef HAS_CROSSCUT\n @group(0) @binding($b) var crosscutMap: texture_2d<f32>;\n @group(0) @binding($b) var crosscutMapSampler: sampler;\n#endif\n#ifdef HAS_HEIGHTLIMIT\n @group(0) @binding($b) var heightLimitMap: texture_2d<f32>;\n @group(0) @binding($b) var heightLimitMapSampler: sampler;\n#endif\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var sceneMap: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var sceneMap: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var sceneMapSampler: sampler;\n@group(0) @binding($b) var<uniform> uniforms: FragmentUniforms;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var glFragColor: vec4f;\n var uv = vertexOutput.vTexCoord;\n uv.y = 1.0 - uv.y;\n #ifdef HAS_MULTISAMPLED\n let sceneColor = textureLoad(sceneMap, vec2i(uv * uniforms.resolution), 0);\n #else\n let sceneColor = textureSample(sceneMap, sceneMapSampler, uv);\n #endif\n glFragColor = sceneColor;\n #ifdef HAS_VIEWSHED\n let viewshedColor = textureSample(viewshedMap, viewshedMapSampler, uv);\n if (viewshedColor.r > 0.99) {\n glFragColor = vec4f(\n mix(uniforms.viewshed_invisibleColor.rgb, sceneColor.rgb, uniforms.viewshed_invisibleColor.a),\n sceneColor.a\n );\n } else if (viewshedColor.g > 0.99) {\n glFragColor = vec4f(\n mix(uniforms.viewshed_visibleColor.rgb, sceneColor.rgb, uniforms.viewshed_visibleColor.a),\n sceneColor.a\n );\n } else if (viewshedColor.a < 0.01) {\n glFragColor = vec4f(viewshedColor.rgb, 1.0);\n }\n #endif\n #ifdef HAS_FLOODANALYSE\n let floodColor = textureSample(floodMap, floodMapSampler, uv);\n if (floodColor.r > 0.0) {\n glFragColor = vec4f(\n mix(glFragColor.rgb, uniforms.flood_waterColor, uniforms.flood_waterOpacity),\n glFragColor.a\n );\n }\n #endif\n #ifdef HAS_SKYLINE\n let skylineColor = textureSample(skylineMap, skylineMapSampler, uv);\n if (skylineColor.r > 0.0 || skylineColor.g > 0.0 || skylineColor.b > 0.0) {\n glFragColor = skylineColor;\n }\n #endif\n #ifdef HAS_INSIGHT\n let insightColor = textureSample(insightMap, insightMapSampler, uv);\n if (insightColor.g > 0.0) {\n glFragColor = uniforms.insight_visibleColor;\n } else if (insightColor.r > 0.0) {\n glFragColor = uniforms.insight_invisibleColor;\n }\n #endif\n #ifdef HAS_CUT\n let cutColor = textureSample(invisibleMap, invisibleMapSampler, uv);\n let meshesMapColor = textureSample(meshesMap, meshesMapSampler, uv);\n if (cutColor.r == 1.0 && cutColor.g == 0.0 && cutColor.b == 0.0) {\n glFragColor = meshesMapColor;\n } else if (cutColor.r == 0.0 && cutColor.g == 1.0 && cutColor.b == 0.0) {\n glFragColor = meshesMapColor;\n } else if (cutColor.r == 0.0 && cutColor.g == 0.0 && cutColor.b == 1.0) {\n glFragColor = sceneColor;\n }\n #endif\n #ifdef HAS_EXCAVATE\n let excavateColor = textureSample(excavateMap, excavateMapSampler, uv);\n if (excavateColor.r == 1.0 && excavateColor.g == 0.0 && excavateColor.b == 0.0) {\n glFragColor = sceneColor;\n } else {\n glFragColor = excavateColor;\n }\n #endif\n #ifdef HAS_CROSSCUT\n let crosscutColor = textureSample(crosscutMap, crosscutMapSampler, uv);\n if (crosscutColor.r > 0.0) {\n glFragColor = vec4f(\n mix(uniforms.cutLineColor.rgb, glFragColor.rgb, 0.99),\n glFragColor.a\n );\n }\n #endif\n #ifdef HAS_HEIGHTLIMIT\n let heightLimitColor = textureSample(heightLimitMap, heightLimitMapSampler, uv);\n if (heightLimitColor.r > 0.0) {\n glFragColor = vec4f(\n mix(uniforms.limitColor, glFragColor.rgb, 0.6),\n glFragColor.a\n );\n }\n #endif\n return glFragColor;\n}";
52
52
 
@@ -60,11 +60,11 @@
60
60
 
61
61
  var glTerrainSkinVert = "struct VertexInput {\n @location($i) aPosition: vec2i\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n vertexOutput.position = vec4f(vec2f(vertexInput.aPosition), 0.0, 1.0);\n return vertexOutput;\n}";
62
62
 
63
- var glTerrainVert = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_vert>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n#endif\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n heightScale: f32,\n};\nstruct TerrainUniforms {\n minAltitude: f32,\n projViewModelMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vUv: vec2f,\n};\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aTexCoord: vec2f,\n};\n@group(0) @binding($b) var<uniform> matrixUniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n var position = vec4f(vertexInput.aPosition.xy, (vertexInput.aPosition.z + uniforms.minAltitude) * matrixUniforms.heightScale, 1.0);\n position = uniforms.positionMatrix * position;\n #ifdef HAS_MASK_EXTENT\n vertexOutput.position = matrixUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix, vertexOutput);\n #else\n vertexOutput.position = uniforms.projViewModelMatrix * position;\n #endif\n vertexOutput.vUv = vertexInput.aTexCoord;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &vertexOutput);\n #endif\n return vertexOutput;\n}";
63
+ var glTerrainVert = "#include <common_pack_float>\n#include <mask_vert>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n#endif\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n heightScale: f32,\n};\nstruct TerrainUniforms {\n minAltitude: f32,\n projViewModelMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vUv: vec2f,\n};\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aTexCoord: vec2f,\n};\n@group(0) @binding($b) var<uniform> matrixUniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@group(0) @binding($b) var flatMaskSampler: sampler;\n@group(0) @binding($b) var flatMask: texture_2d<f32>;\n@vertex\nfn main(\n vertexInput: VertexInput,\n) -> VertexOutput {\n var vertexOutput: VertexOutput;\n var uv: vec2f = vertexInput.aTexCoord;\n let encodedHeight: vec4f = textureSampleLevel(flatMask, flatMaskSampler, uv, 0.0);\n var altitude: f32 = vertexInput.aPosition.z;\n if (length(encodedHeight) < 2.0) {\n let maskHeight: f32 = decodeFloat32(encodedHeight);\n altitude = min(vertexInput.aPosition.z, maskHeight);\n }\n var position: vec4f = vec4f(vertexInput.aPosition.xy, (altitude + uniforms.minAltitude) * matrixUniforms.heightScale, 1.0);\n position = uniforms.positionMatrix * position;\n #ifdef HAS_MASK_EXTENT\n vertexOutput.position = matrixUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix, vertexOutput);\n #else\n vertexOutput.position = uniforms.projViewModelMatrix * position;\n #endif\n vertexOutput.vUv = vertexInput.aTexCoord;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &vertexOutput);\n #endif\n return vertexOutput;\n}";
64
64
 
65
- var glStandardFrag = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f,\n #ifdef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: array<vec3f, 9>,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n #ifndef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterMapSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = shaderUniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterMapSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, shaderUniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n #ifdef MESH_ENV_EXPO\n let environmentExposure = materialUniforms.environmentExposure;\n #else\n let environmentExposure = shaderUniforms.environmentExposure;\n #endif\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag = shadow_blend(rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n glFragColor.rgb = snow(glFragColor, getMaterialNormalMap(), 1.0);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
65
+ var glStandardFrag = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f,\n #ifdef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n #ifdef IS_LINE_EXTRUSION\n lineOpacity: f32,\n #else\n polygonOpacity: f32,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: array<vec3f, 9>,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n #ifndef MESH_ENV_EXPO\n environmentExposure: f32,\n #endif\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterMapSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = shaderUniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterMapSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, shaderUniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n #ifdef MESH_ENV_EXPO\n let environmentExposure = materialUniforms.environmentExposure;\n #else\n let environmentExposure = shaderUniforms.environmentExposure;\n #endif\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag = shadow_blend(rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n #if IS_LINE_EXTRUSION\n alpha *= uniforms.lineOpacity;\n #else\n alpha *= uniforms.polygonOpacity;\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n let snowColor = snow(glFragColor, getMaterialNormalMap(), 1.0);\n glFragColor = vec4f(snowColor, glFragColor.a);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
66
66
 
67
- var glStandardVert = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n @location($i) aTexCoord: vec2f,\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT\n @location($i) aTangent: vec4f,\n #elif HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n #endif\n}\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifdef HAS_SSR\n @location($o) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($o) vViewTangent: vec4f,\n #endif\n #endif\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($o) vModelTangent: vec4f,\n @location($o) vModelBiTangent: vec3f,\n #endif\n @location($o) vModelVertex: vec3f,\n #if HAS_MAP\n @location($o) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #if HAS_COLOR0\n @location($o) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($o) vTangentViewPos: vec3f,\n @location($o) vTangentFragPos: vec3f,\n #endif\n}\nstruct ShaderUniforms {\n cameraPosition: vec3f,\n projMatrix: mat4x4f,\n}\nstruct Uniforms {\n uvOrigin: vec2f,\n uvScale: vec2f,\n uvOffset: vec2f,\n uvRotation: f32,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n #ifdef HAS_SSR\n modelViewNormalMatrix: mat3x3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nvar<private> Vertex: vec3f;\nvar<private> Normal: vec3f;\nvar<private> Tangent: vec4f;\nconst mid = 0.5;\nfn toTangentFrame(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nstruct TangentFrame {\n n: vec3f,\n t: vec3f\n}\nfn toTangentFrameWithTangent(q: vec4f) -> TangentFrame {\n var out: TangentFrame;\n out.n = toTangentFrame(q);\n out.t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n return out;\n}\nfn rotateUV(uv: vec2f, rotation: f32) -> vec2f {\n return vec2f(\n cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,\n cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid\n );\n}\n#if HAS_MAP\nfn transformTexcoord(uv: vec2f) -> vec2f {\n let decodedTexCoord = decode_getTexcoord(uv);\n #ifdef HAS_RANDOM_TEX\n let origin = uniforms.uvOrigin;\n let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;\n return (origin % 1.0) + texCoord;\n #else\n var origin = uniforms.uvOrigin;\n var texCoord = decodedTexCoord * uniforms.uvScale;\n if (uniforms.uvRotation != 0.0) {\n origin = rotateUV(origin, uniforms.uvRotation);\n texCoord = rotateUV(texCoord, uniforms.uvRotation);\n }\n return (origin % 1.0) + texCoord + uniforms.uvOffset;\n #endif\n}\n#endif\nfn transposeMat3(inMat: mat3x3f) -> mat3x3f {\n let i0 = inMat[0];\n let i1 = inMat[1];\n let i2 = inMat[2];\n return mat3x3f(\n vec3f(i0.x, i1.x, i2.x),\n vec3f(i0.y, i1.y, i2.y),\n vec3f(i0.z, i1.z, i2.z)\n );\n}\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);\n let localVertex = getPosition(linePosition, input);\n #else\n let localVertex = getPosition(vec3f(input.aPosition.xyz), input);\n #endif\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n let position = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelViewMatrix * position;\n output.vViewVertex = viewVertex;\n #ifdef HAS_MASK_EXTENT\n output.position = shaderUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = shaderUniforms.projMatrix * viewVertex;\n #endif\n #ifdef PICKING_MODE\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= f32(input.aColor.a);\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= f32(input.aColor0.a);\n #endif\n fbo_picking_setData(input, &output, output.position.w, alpha != 0.0);\n #else\n #if HAS_MAP\n output.vTexCoord = transformTexcoord(input.aTexCoord);\n #ifdef HAS_AO_MAP\n output.vTexCoord1 = transformTexcoord(input.aTexCoord1);\n #endif\n #ifdef HAS_I3S_UVREGION\n output.vUvRegion = input.uvRegion / 65535.0;\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n let positionNormalMatrix = mat3x3f(\n localPositionMatrix[0].xyz,\n localPositionMatrix[1].xyz,\n localPositionMatrix[2].xyz\n );\n let normalMatrix = uniforms.modelNormalMatrix * positionNormalMatrix;\n #if HAS_TANGENT\n let tangentFrame = toTangentFrameWithTangent(input.aTangent);\n Normal = tangentFrame.n;\n let t = tangentFrame.t;\n output.vModelTangent = vec4f(normalMatrix * t, input.aTangent.w);\n #else\n Normal = decode_getNormal(vec3f(input.aNormal.xyz));\n #endif\n let localNormal = Normal;\n output.vModelNormal = normalMatrix * localNormal;\n #else\n Normal = vec3f(0);\n output.vModelNormal = vec3f(0);\n #endif\n #if HAS_TANGENT\n output.vModelBiTangent = cross(output.vModelNormal, output.vModelTangent.xyz) * sign(input.aTangent.w);\n #endif\n #ifdef HAS_SSR\n let ssrNormalMatrix = uniforms.modelViewNormalMatrix * positionNormalMatrix;\n output.vViewNormal = ssrNormalMatrix * Normal;\n #if HAS_TANGENT\n let localTangent = vec4f(t, input.aTangent.w);\n output.vViewTangent = vec4f(ssrNormalMatrix * localTangent.xyz, localTangent.w);\n #endif\n #endif\n #if HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(input, &output);\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n output.vColor0 = vec4f(vec3f(input.aColor0), 255.0) / 255.0;\n #else\n output.vColor0 = vec4f(input.aColor0) / 255.0;\n #endif\n #endif\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &output);\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n let TBN = transposeMat3(mat3x3f(output.vModelTangent.xyz, output.vModelBiTangent, output.vModelNormal));\n output.vTangentViewPos = TBN * shaderUniforms.cameraPosition;\n output.vTangentFragPos = TBN * output.vModelVertex;\n #endif\n #ifdef HAS_VERTEX_COLOR\n vertexColor_update(input, &output);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);\n output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);\n #endif\n #endif\n return output;\n}";
67
+ var glStandardVert = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #include <position_vert>\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n #ifdef HAS_DRACO_TEXCOORD\n @location($i) aTexCoord: vec2u,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT\n @location($i) aTangent: vec4f,\n #elif HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #elif NORMAL_IS_UINT\n @location($i) aNormal: vec4u,\n #else\n @location($i) aNormal: vec3f,\n #endif\n #endif\n}\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifdef HAS_SSR\n @location($o) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($o) vViewTangent: vec4f,\n #endif\n #endif\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($o) vModelTangent: vec4f,\n @location($o) vModelBiTangent: vec3f,\n #endif\n @location($o) vModelVertex: vec3f,\n #if HAS_MAP\n @location($o) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #if HAS_COLOR0\n @location($o) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($o) vTangentViewPos: vec3f,\n @location($o) vTangentFragPos: vec3f,\n #endif\n}\nstruct ShaderUniforms {\n cameraPosition: vec3f,\n projMatrix: mat4x4f,\n}\nstruct Uniforms {\n uvOrigin: vec2f,\n uvScale: vec2f,\n uvOffset: vec2f,\n uvRotation: f32,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n #ifdef HAS_SSR\n modelViewNormalMatrix: mat3x3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nvar<private> Vertex: vec3f;\nvar<private> Normal: vec3f;\nvar<private> Tangent: vec4f;\nconst mid = 0.5;\nfn toTangentFrame(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nstruct TangentFrame {\n n: vec3f,\n t: vec3f\n}\nfn toTangentFrameWithTangent(q: vec4f) -> TangentFrame {\n var out: TangentFrame;\n out.n = toTangentFrame(q);\n out.t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n return out;\n}\nfn rotateUV(uv: vec2f, rotation: f32) -> vec2f {\n return vec2f(\n cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,\n cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid\n );\n}\n#if HAS_MAP\nfn transformTexcoord(uv: vec2f) -> vec2f {\n let decodedTexCoord = decode_getTexcoord(uv);\n #ifdef HAS_RANDOM_TEX\n let origin = uniforms.uvOrigin;\n let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;\n return (origin % 1.0) + texCoord;\n #else\n var origin = uniforms.uvOrigin;\n var texCoord = decodedTexCoord * uniforms.uvScale;\n if (uniforms.uvRotation != 0.0) {\n origin = rotateUV(origin, uniforms.uvRotation);\n texCoord = rotateUV(texCoord, uniforms.uvRotation);\n }\n return (origin % 1.0) + texCoord + uniforms.uvOffset;\n #endif\n}\n#endif\nfn transposeMat3(inMat: mat3x3f) -> mat3x3f {\n let i0 = inMat[0];\n let i1 = inMat[1];\n let i2 = inMat[2];\n return mat3x3f(\n vec3f(i0.x, i1.x, i2.x),\n vec3f(i0.y, i1.y, i2.y),\n vec3f(i0.z, i1.z, i2.z)\n );\n}\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);\n let localVertex = getPosition(linePosition, input);\n #else\n let localVertex = getPosition(vec3f(input.aPosition.xyz), input);\n #endif\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n let position = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelViewMatrix * position;\n output.vViewVertex = viewVertex;\n #ifdef HAS_MASK_EXTENT\n output.position = shaderUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = shaderUniforms.projMatrix * viewVertex;\n #endif\n #ifdef PICKING_MODE\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= f32(input.aColor.a);\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= f32(input.aColor0.a);\n #endif\n fbo_picking_setData(input, &output, output.position.w, alpha != 0.0);\n #else\n #if HAS_MAP\n output.vTexCoord = transformTexcoord(input.aTexCoord.xy);\n #ifdef HAS_AO_MAP\n output.vTexCoord1 = transformTexcoord(input.aTexCoord1);\n #endif\n #ifdef HAS_I3S_UVREGION\n output.vUvRegion = input.uvRegion / 65535.0;\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n let positionNormalMatrix = mat3x3f(\n localPositionMatrix[0].xyz,\n localPositionMatrix[1].xyz,\n localPositionMatrix[2].xyz\n );\n let normalMatrix = uniforms.modelNormalMatrix * positionNormalMatrix;\n #if HAS_TANGENT\n let tangentFrame = toTangentFrameWithTangent(input.aTangent);\n Normal = tangentFrame.n;\n let t = tangentFrame.t;\n output.vModelTangent = vec4f(normalMatrix * t, input.aTangent.w);\n #else\n Normal = decode_getNormal(vec3f(input.aNormal.xyz));\n #endif\n let localNormal = Normal;\n output.vModelNormal = normalMatrix * localNormal;\n #else\n Normal = vec3f(0);\n output.vModelNormal = vec3f(0);\n #endif\n #if HAS_TANGENT\n output.vModelBiTangent = cross(output.vModelNormal, output.vModelTangent.xyz) * sign(input.aTangent.w);\n #endif\n #ifdef HAS_SSR\n let ssrNormalMatrix = uniforms.modelViewNormalMatrix * positionNormalMatrix;\n output.vViewNormal = ssrNormalMatrix * Normal;\n #if HAS_TANGENT\n let localTangent = vec4f(t, input.aTangent.w);\n output.vViewTangent = vec4f(ssrNormalMatrix * localTangent.xyz, localTangent.w);\n #endif\n #endif\n #if HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(input, &output);\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n output.vColor0 = vec4f(vec3f(input.aColor0), 255.0) / 255.0;\n #else\n output.vColor0 = vec4f(input.aColor0) / 255.0;\n #endif\n #endif\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &output);\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n let TBN = transposeMat3(mat3x3f(output.vModelTangent.xyz, output.vModelBiTangent, output.vModelNormal));\n output.vTangentViewPos = TBN * shaderUniforms.cameraPosition;\n output.vTangentFragPos = TBN * output.vModelVertex;\n #endif\n #ifdef HAS_VERTEX_COLOR\n vertexColor_update(input, &output);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);\n output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);\n #endif\n #endif\n return output;\n}";
68
68
 
69
69
  var glBloomCombineFrag = "\nstruct BloomCombineUniforms {\n bloomFactor: f32,\n bloomRadius: f32,\n rgbmRange: f32,\n enableAA: f32,\n outputSize: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: BloomCombineUniforms;\n@group(0) @binding($b) var TextureBloomBlur1: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur1Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur2: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur2Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur3: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur3Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur4: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur4Sampler: sampler;\n@group(0) @binding($b) var TextureBloomBlur5: texture_2d<f32>;\n@group(0) @binding($b) var TextureBloomBlur5Sampler: sampler;\n#ifdef HAS_MULTISAMPLED\n@group(0) @binding($b) var TextureInput: texture_multisampled_2d<f32>;\n@group(0) @binding($b) var TextureSource: texture_multisampled_2d<f32>;\n#else\n@group(0) @binding($b) var TextureInput: texture_2d<f32>;\n@group(0) @binding($b) var TextureSource: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var TextureInputSampler: sampler;\n@group(0) @binding($b) var TextureSourceSampler: sampler;\nvar<private> gTexCoord: vec2f;\n#include <srgb_frag>\nfn decodeRGBM(color: vec4f, range: f32) -> vec3f {\n if (range <= 0.0) {\n return color.rgb;\n }\n return range * color.rgb * color.a;\n}\nfn getRadiusFactored(value: f32, middle: f32) -> f32 {\n return mix(value, middle * 2.0 - value, uniforms.bloomRadius);\n}\nfn fetchSourceTexel(uv: vec2f) -> vec4f {\n#ifdef HAS_MULTISAMPLED\n return textureLoad(TextureSource, vec2i(uv * vec2f(uniforms.outputSize)), 0);\n#else\n return textureSample(TextureSource, TextureSourceSampler, uv);\n#endif\n}\nfn fetchInputTexel(uv: vec2f) -> vec4f {\n#ifdef HAS_MULTISAMPLED\n return textureLoad(TextureInput, vec2i(uv * vec2f(uniforms.outputSize)), 0);\n#else\n return textureSample(TextureInput, TextureInputSampler, uv);\n#endif\n}\nfn bloomCombine() -> vec4f {\n var bloom: vec3f = vec3f(0.0);\n let midVal: f32 = 0.6;\n let factor1: f32 = 1.1;\n let factor2: f32 = 0.9;\n let factor3: f32 = 0.6;\n let factor4: f32 = 0.3;\n let factor5: f32 = 0.1;\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur1, TextureBloomBlur1Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor1, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur2, TextureBloomBlur2Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor2, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur3, TextureBloomBlur3Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor3, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur4, TextureBloomBlur4Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor4, midVal);\n bloom += (vec4f(decodeRGBM(textureSample(TextureBloomBlur5, TextureBloomBlur5Sampler, gTexCoord), uniforms.rgbmRange), 1.0)).rgb * getRadiusFactored(factor5, midVal);\n var bloomInputColor: vec4f;\n if (uniforms.enableAA == 1.0) {\n } else {\n bloomInputColor = fetchInputTexel(gTexCoord);\n }\n bloomInputColor = vec4f(mix(vec3f(0.0), bloomInputColor.rgb, sign(bloomInputColor.a)), bloomInputColor.a);\n let srcColor = fetchSourceTexel(gTexCoord);\n let bloomAlpha: f32 = sqrt((bloom.r + bloom.g + bloom.b) / 3.0);\n let bloomColor: vec4f = vec4f(linearTosRGB(bloom * uniforms.bloomFactor), bloomAlpha);\n return bloomInputColor + srcColor * (1.0 - bloomInputColor.a) + bloomColor;\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let fragCoord = vec2f(vertexOutput.position.xy);\n gTexCoord = fragCoord / uniforms.outputSize;\n let color = bloomCombine();\n return color;\n}";
70
70
 
@@ -96,7 +96,7 @@
96
96
 
97
97
  var glPhongFrag = "struct LightUniforms {\n light0_viewDirection: vec3f,\n ambientColor: vec3f,\n light0_diffuse: vec4f,\n lightSpecular: vec3f,\n cameraPosition: vec3f,\n #ifdef HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n};\nstruct MaterialUniforms {\n environmentExposure: f32,\n specularStrength: f32,\n baseColorFactor: vec4f,\n materialShininess: f32,\n alphaTest: f32,\n#ifdef HAS_EXTRUSION_OPACITY\n extrusionOpacityRange: vec2f,\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n diffuseFactor: vec4f,\n specularFactor: vec3f,\n#endif\n#ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n lineOpacity: f32,\n#else\n polygonFill: vec4f,\n polygonOpacity: f32,\n#endif\n};\n@group(0) @binding($b) var<uniform> lightUniforms: LightUniforms;\n@group(0) @binding($b) var<uniform> materialUniforms: MaterialUniforms;\n#ifdef HAS_BASECOLOR_MAP\n@group(0) @binding($b) var baseColorTextureSampler: sampler;\n@group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_AO_MAP\n@group(0) @binding($b) var occlusionTextureSampler: sampler;\n@group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_NORMAL_MAP\n@group(0) @binding($b) var normalTextureSampler: sampler;\n@group(0) @binding($b) var normalTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_EMISSIVE_MAP\n@group(0) @binding($b) var emissiveTextureSampler: sampler;\n@group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n#ifdef HAS_DIFFUSE_MAP\n@group(0) @binding($b) var diffuseTextureSampler: sampler;\n@group(0) @binding($b0) var diffuseTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n@group(0) @binding($b1) var specularGlossinessTextureSampler: sampler;\n@group(0) @binding($b2) var specularGlossinessTexture: texture_2d<f32>;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_frag>\n#endif\n#include <highlight_frag>\n#include <mask_frag>\n#include <vertex_color_frag>\n#ifdef HAS_MAP\n #include <compute_texcoord_frag>\n#endif\nfn transformNormal(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_NORMAL_MAP\n let n = normalize(vertexOutput.vNormal);\n let normal = textureSample(normalTexture, normalTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).xyz * 2.0 - 1.0;\n#ifdef HAS_TANGENT\n let t = normalize(vertexOutput.vTangent.xyz);\n let b = normalize(cross(n, t) * sign(vertexOutput.vTangent.w));\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n#else\n return normalize(normal);\n#endif\n#else\n return normalize(vertexOutput.vNormal);\n#endif\n}\nfn getBaseColor(vertexOutput: VertexOutput) -> vec4f {\n#ifdef HAS_BASECOLOR_MAP\n return textureSample(baseColorTexture, baseColorTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput));\n#elif HAS_DIFFUSE_MAP\n return textureSample(diffuseTexture, diffuseTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput));\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.diffuseFactor;\n#else\n return materialUniforms.baseColorFactor;\n#endif\n}\nfn getSpecularColor(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n return textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).rgb;\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.specularFactor;\n#else\n return vec3f(1.0);\n#endif\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let baseColor = getBaseColor(vertexOutput);\n#ifdef SHADING_MODEL_UNLIT\n let ambientColor = vec3f(1.0);\n#else\n let ambientColor = lightUniforms.ambientColor;\n#endif\n var ambient = materialUniforms.environmentExposure * ambientColor * baseColor.rgb;\n#ifdef HAS_INSTANCE_COLOR\n ambient *= vertexOutput.vInstanceColor.rgb;\n#endif\n let norm = transformNormal(vertexOutput);\n let lightDir = normalize(-lightUniforms.light0_viewDirection);\n var diff = max(dot(norm, lightDir), 0.0);\n#ifdef SHADING_MODEL_UNLIT\n let lightDiffuse = vec3f(0.0);\n#else\n let lightDiffuse = lightUniforms.light0_diffuse.rgb;\n#endif\n var diffuse = lightDiffuse * diff * baseColor.rgb;\n#if HAS_COLOR || HAS_COLOR0\n var color = vertexOutput.vColor.rgb;\n#elif IS_LINE_EXTRUSION\n var color = materialUniforms.lineColor.rgb;\n#else\n var color = materialUniforms.polygonFill.rgb;\n#endif\n#ifdef HAS_INSTANCE_COLOR\n color *= vertexOutput.vInstanceColor.rgb;\n#endif\n ambient *= color.rgb;\n diffuse *= color.rgb;\n let viewDir = normalize(lightUniforms.cameraPosition - vertexOutput.vFragPos);\n let halfwayDir = normalize(lightDir + viewDir);\n var spec = pow(max(dot(norm, halfwayDir), 0.0), materialUniforms.materialShininess);\n#ifdef SHADING_MODEL_UNLIT\n let lightSpecular = vec3f(0.0);\n#else\n let lightSpecular = lightUniforms.lightSpecular;\n#endif\n var specular = materialUniforms.specularStrength * lightSpecular * spec * getSpecularColor(vertexOutput);\n#ifdef HAS_OCCLUSION_MAP\n let ao = textureSample(occlusionTexture, occlusionTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput1)).r;\n ambient *= ao;\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n diffuse = shadow_blend(diffuse, shadowCoeff).rgb;\n specular = shadow_blend(specular, shadowCoeff).rgb;\n ambient = shadow_blend(ambient, shadowCoeff).rgb;\n#endif\n var result = ambient + diffuse + specular;\n#ifdef HAS_EMISSIVE_MAP\n let emit = textureSample(emissiveTexture, emissiveTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).rgb;\n result += emit;\n#endif\n#ifdef IS_LINE_EXTRUSION\n var fragColor = vec4f(result, materialUniforms.lineOpacity * baseColor.a);\n#else\n var fragColor = vec4f(result, materialUniforms.polygonOpacity * baseColor.a);\n#endif\n#if HAS_COLOR || HAS_COLOR0\n let colorAlpha = vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n let colorAlpha = materialUniforms.lineColor.a;\n#else\n let colorAlpha = materialUniforms.polygonFill.a;\n#endif\n fragColor *= colorAlpha;\n#ifdef HAS_EXTRUSION_OPACITY\n let topAlpha = materialUniforms.extrusionOpacityRange.x;\n let bottomAlpha = materialUniforms.extrusionOpacityRange.y;\n let alpha = topAlpha + vertexOutput.vExtrusionOpacity * (bottomAlpha - topAlpha);\n let alpha = clamp(alpha, 0.0, 1.0);\n fragColor *= alpha;\n#endif\n if (fragColor.a < materialUniforms.alphaTest) {\n discard;\n }\n#ifdef HAS_VERTEX_COLOR\n fragColor *= vertexColor_get();\n#endif\n#ifdef HAS_HEATMAP\n fragColor = heatmap_getColor(fragColor);\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n fragColor = highlight_blendColor(fragColor, vertexOutput);\n#endif\n#ifdef HAS_LAYER_OPACITY\n fragColor *= lightUniforms.layerOpacity;\n#endif\n#ifdef HAS_MASK_EXTENT\n fragColor = setMask(fragColor);\n#endif\n return fragColor;\n}";
98
98
 
99
- var glPhongVert = "struct VertexInput {\n#if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n#else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n#endif\n#ifdef HAS_MAP\n #if HAS_DRACO_TEXCOORD || HAS_COMPRESSED_INT16_TEXCOORD_0\n @location($i) aTexCoord: vec2i,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n#ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR\n @location($i) aColor: vec4f,\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n @location($i) aColor0: vec3f,\n#else\n @location($i) aColor0: vec4f,\n#endif\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n @location($i) aExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($i) aTangent: vec4f,\n#endif\n#ifdef HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n#endif\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vFragPos: vec3f,\n @location($o) vNormal: vec3f,\n#ifdef HAS_MAP\n @location($o) vTexCoord: vec2f,\n#ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR || HAS_COLOR0\n @location($o) vColor: vec4f,\n#endif\n#if HAS_EXTRUSION_OPACITY\n @location($o) vExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($o) vTangent: vec4f,\n#endif\n};\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n projViewMatrix: mat4x4f,\n};\nstruct ModelUniforms {\n modelNormalMatrix: mat3x3f,\n modelViewMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n uvScale: vec2f,\n uvOffset: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> modelUniforms: ModelUniforms;\n#include <line_extrusion_vert>\n#include <highlight_vert>\n#include <get_output>\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_vert>\n#endif\n#include <vertex_color_vert>\nfn toTangentFrame1(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nfn toTangentFrame(q: vec4f, n: ptr<function, vec3f>, t: ptr<function, vec3f>) {\n *n = toTangentFrame1(q);\n *t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput : VertexOutput;\n#if IS_LINE_EXTRUSION\n let localPosition = getPosition(getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput), vertexInput);\n#else\n let localPosition = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n#endif\n let localPositionMatrix = getPositionMatrix(vertexInput, &vertexOutput, modelUniforms.positionMatrix);\n vertexOutput.vFragPos = (modelUniforms.modelMatrix * localPositionMatrix * localPosition).xyz;\n#if HAS_NORMAL || HAS_TANGENT\n let localNormalMatrix = modelUniforms.modelNormalMatrix * mat3x3f(localPositionMatrix[0].xyz, localPositionMatrix[1].xyz, localPositionMatrix[2].xyz);\n var Normal: vec3f;\n#if HAS_TANGENT\n var t: vec3f;\n toTangentFrame(vertexInput.aTangent, Normal, t);\n vertexOutput.vTangent = vec4f(localNormalMatrix * t, vertexInput.aTangent.w);\n#else\n Normal = decode_getNormal(vec3f(vertexInput.aNormal.xyz));\n#endif\n let localNormal = appendMorphNormal(Normal, vertexInput);\n vertexOutput.vNormal = normalize(localNormalMatrix * localNormal);\n#else\n vertexOutput.vNormal = vec3f(0.0);\n#endif\n var jitteredProjection = uniforms.projMatrix;\n#ifdef HAS_MASK_EXTENT\n vertexOutput.position = jitteredProjection * getMaskPosition(localPositionMatrix * localPosition, uniforms.modelMatrix);\n#else\n vertexOutput.position = jitteredProjection * modelUniforms.modelViewMatrix * localPositionMatrix * localPosition;\n#endif\n#ifdef HAS_MAP\n let decodedTexCoord = decode_getTexcoord(vec2f(vertexInput.aTexCoord));\n vertexOutput.vTexCoord = decodedTexCoord * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_AO_MAP\n let decodedTexCoord1 = decode_getTexcoord(vec2f(vertexInput.aTexCoord1));\n vertexOutput.vTexCoord1 = decodedTexCoord1 * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n vertexOutput.vExtrusionOpacity = vertexInput.aExtrusionOpacity;\n#endif\n#if HAS_COLOR\n vertexOutput.vColor = vertexInput.aColor / 255.0;\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n vertexOutput.vColor = vec4f(vertexInput.aColor0 / 255.0, 1.0);\n#else\n vertexOutput.vColor = vertexInput.aColor0 / 255.0;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localPositionMatrix * localPosition, &vertexOutput);\n#endif\n#ifdef HAS_I3S_UVREGION\n vertexOutput.vUvRegion = vertexInput.uvRegion / 65535.0;\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(vertexInput, &vertexOutput);\n#endif\n#ifdef HAS_VERTEX_COLOR\n vertexColor_update(vertexInput, &vertexOutput);\n#endif\n return vertexOutput;\n}";
99
+ var glPhongVert = "struct VertexInput {\n#include <position_vert>\n#ifdef HAS_MAP\n #if HAS_DRACO_TEXCOORD || HAS_COMPRESSED_INT16_TEXCOORD_0\n @location($i) aTexCoord: vec2i,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n#ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR\n @location($i) aColor: vec4f,\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n @location($i) aColor0: vec3f,\n#else\n @location($i) aColor0: vec4f,\n#endif\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n @location($i) aExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($i) aTangent: vec4f,\n#endif\n#ifdef HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #elif NORMAL_IS_UINT\n @location($i) aNormal: vec4u,\n #else\n @location($i) aNormal: vec3f,\n #endif\n#endif\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vFragPos: vec3f,\n @location($o) vNormal: vec3f,\n#ifdef HAS_MAP\n @location($o) vTexCoord: vec2f,\n#ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR || HAS_COLOR0\n @location($o) vColor: vec4f,\n#endif\n#if HAS_EXTRUSION_OPACITY\n @location($o) vExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($o) vTangent: vec4f,\n#endif\n};\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n projViewMatrix: mat4x4f,\n};\nstruct ModelUniforms {\n modelNormalMatrix: mat3x3f,\n modelViewMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n uvScale: vec2f,\n uvOffset: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> modelUniforms: ModelUniforms;\n#include <line_extrusion_vert>\n#include <highlight_vert>\n#include <get_output>\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_vert>\n#endif\n#include <vertex_color_vert>\nfn toTangentFrame1(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nfn toTangentFrame(q: vec4f, n: ptr<function, vec3f>, t: ptr<function, vec3f>) {\n *n = toTangentFrame1(q);\n *t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput : VertexOutput;\n#if IS_LINE_EXTRUSION\n let localPosition = getPosition(getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput), vertexInput);\n#else\n let localPosition = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n#endif\n let localPositionMatrix = getPositionMatrix(vertexInput, &vertexOutput, modelUniforms.positionMatrix);\n vertexOutput.vFragPos = (modelUniforms.modelMatrix * localPositionMatrix * localPosition).xyz;\n#if HAS_NORMAL || HAS_TANGENT\n let localNormalMatrix = modelUniforms.modelNormalMatrix * mat3x3f(localPositionMatrix[0].xyz, localPositionMatrix[1].xyz, localPositionMatrix[2].xyz);\n var Normal: vec3f;\n#if HAS_TANGENT\n var t: vec3f;\n toTangentFrame(vertexInput.aTangent, Normal, t);\n vertexOutput.vTangent = vec4f(localNormalMatrix * t, vertexInput.aTangent.w);\n#else\n Normal = decode_getNormal(vec3f(vertexInput.aNormal.xyz));\n#endif\n let localNormal = appendMorphNormal(Normal, vertexInput);\n vertexOutput.vNormal = normalize(localNormalMatrix * localNormal);\n#else\n vertexOutput.vNormal = vec3f(0.0);\n#endif\n var jitteredProjection = uniforms.projMatrix;\n#ifdef HAS_MASK_EXTENT\n vertexOutput.position = jitteredProjection * getMaskPosition(localPositionMatrix * localPosition, uniforms.modelMatrix);\n#else\n vertexOutput.position = jitteredProjection * modelUniforms.modelViewMatrix * localPositionMatrix * localPosition;\n#endif\n#ifdef HAS_MAP\n let decodedTexCoord = decode_getTexcoord(vec2f(vertexInput.aTexCoord));\n vertexOutput.vTexCoord = decodedTexCoord * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_AO_MAP\n let decodedTexCoord1 = decode_getTexcoord(vec2f(vertexInput.aTexCoord1));\n vertexOutput.vTexCoord1 = decodedTexCoord1 * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n vertexOutput.vExtrusionOpacity = vertexInput.aExtrusionOpacity;\n#endif\n#if HAS_COLOR\n vertexOutput.vColor = vertexInput.aColor / 255.0;\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n vertexOutput.vColor = vec4f(vertexInput.aColor0 / 255.0, 1.0);\n#else\n vertexOutput.vColor = vertexInput.aColor0 / 255.0;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localPositionMatrix * localPosition, &vertexOutput);\n#endif\n#ifdef HAS_I3S_UVREGION\n vertexOutput.vUvRegion = vertexInput.uvRegion / 65535.0;\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(vertexInput, &vertexOutput);\n#endif\n#ifdef HAS_VERTEX_COLOR\n vertexColor_update(vertexInput, &vertexOutput);\n#endif\n return vertexOutput;\n}";
100
100
 
101
101
  var glQuadFrag = "#define SHADER_NAME QUAD\nstruct QuadFragUniforms {\n outputSize: vec2f,\n inputSize: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: QuadFragUniforms;\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var TextureInput: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var TextureInput: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var TextureInputSampler: sampler;\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n let uv = vertexOutput.position.xy;\n #ifdef HAS_MULTISAMPLED\n let color = textureLoad(TextureInput, vec2i(uv / uniforms.outputSize * uniforms.inputSize), 0);\n #else\n let color = textureSample(TextureInput, TextureInputSampler, uv / uniforms.outputSize);\n #endif\n return color;\n}";
102
102
 
@@ -108,13 +108,29 @@
108
108
 
109
109
  var glVsmMappingFrag = "#ifdef PACK_FLOAT\n #include <common_pack_float>\n#endif\nstruct FragmentOutput {\n @location(0) color: vec4f,\n};\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n var color: vec4f;\n #if USE_ESM\n #ifdef PACK_FLOAT\n color = common_encodeDepth(vertexOutput.position.z);\n #else\n color = vec4f(vertexOutput.position.z, 0.0, 0.0, 1.0);\n #endif\n #endif\n return color;\n}";
110
110
 
111
- var glVsmMappingVert = "#include <line_extrusion_vert>\n#include <get_output>\nstruct ShadowMappingUniforms {\n lightProjViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n};\nstruct VertexInput {\n @location($i) aPosition: POSITION_TYPE_3,\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@group(0) @binding($b) var<uniform> uniforms: ShadowMappingUniforms;\n@vertex\nfn main(\n vertexInput: VertexInput\n) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let localVertex = getPosition(linePosition, vertexInput);\n #else\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.position = uniforms.lightProjViewModelMatrix * localPositionMatrix * localVertex;\n return output;\n}";
111
+ var glVsmMappingVert = "#include <line_extrusion_vert>\n#include <get_output>\nstruct ShadowMappingUniforms {\n lightProjViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n};\nstruct VertexInput {\n #include <position_vert>\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f\n};\n@group(0) @binding($b) var<uniform> uniforms: ShadowMappingUniforms;\n@vertex\nfn main(\n vertexInput: VertexInput\n) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let localVertex = getPosition(linePosition, vertexInput);\n #else\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n #endif\n output.position = uniforms.lightProjViewModelMatrix * localPositionMatrix * localVertex;\n return output;\n}";
112
112
 
113
113
  var glSkyboxFrag = "#include <hsv_frag>\nstruct SkyboxUniforms {\n hsv: vec3f,\n #ifdef USE_AMBIENT\n diffuseSPH: array<vec3f, 9>,\n #else\n bias: f32,\n size: f32,\n #endif\n environmentExposure: f32,\n backgroundIntensity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: SkyboxUniforms;\n#ifndef USE_AMBIENT\n @group(0) @binding($b) var cubeMap: texture_cube<f32>;\n @group(0) @binding($b) var cubeMapSampler: sampler;\n#endif\nfn textureCubeFixed(tex: texture_cube<f32>, texSampler: sampler, R: vec3f, size: f32, bias: f32) -> vec4f {\n var dir: vec3f = R;\n return textureSampleLevel(tex, texSampler, dir, bias);\n}\nfn computeDiffuseSPH(normal: vec3f, diffuseSPH: array<vec3f, 9>) -> vec3f {\n let x: f32 = normal.x;\n let y: f32 = normal.y;\n let z: f32 = normal.z;\n var result: vec3f = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x * x - y * y)\n );\n return max(result, vec3f(0.0));\n}\nfn pseudoRandom(fragCoord: vec2f) -> f32 {\n var p3: vec3f = fract(vec3f(fragCoord.x, fragCoord.y, fragCoord.x) * 0.1031);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n}\n#if TONE_MAPPING\n const toneMappingExposure: f32 = 1.0;\n fn RRTAndODTFit(v: vec3f) -> vec3f {\n let a: vec3f = v * (v + 0.0245786) - 0.000090537;\n let b: vec3f = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n }\n fn ACESFilmicToneMapping(color: vec3f) -> vec3f {\n const ACESInputMat: mat3x3f = mat3x3f(\n vec3f(0.59719, 0.07600, 0.02840),\n vec3f(0.35458, 0.90834, 0.13383),\n vec3f(0.04823, 0.01566, 0.83777)\n );\n const ACESOutputMat: mat3x3f = mat3x3f(\n vec3f(1.60475, -0.10208, -0.00327),\n vec3f(-0.53108, 1.10813, -0.07276),\n vec3f(-0.07367, -0.00605, 1.07602)\n );\n var adjustedColor: vec3f = color * toneMappingExposure / 0.6;\n adjustedColor = ACESInputMat * adjustedColor;\n adjustedColor = RRTAndODTFit(adjustedColor);\n adjustedColor = ACESOutputMat * adjustedColor;\n return clamp(adjustedColor, 0, 1);\n }\n fn toneMapping(color: vec3f) -> vec3f {\n return ACESFilmicToneMapping(color);\n }\n fn sRGBTransferOETF(value: vec4f) -> vec4f {\n var result: vec3f;\n let threshold: vec3f = vec3f(0.0031308);\n for (var i: i32 = 0; i < 3; i++) {\n if (value[i] <= threshold[i]) {\n result[i] = value[i] * 12.92;\n } else {\n result[i] = pow(value[i], 0.41666) * 1.055 - 0.055;\n }\n }\n return vec4f(result, value.a);\n }\n fn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n }\n#endif\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var envColor: vec4f;\n #ifdef USE_AMBIENT\n var normal: vec3f = normalize(\n vertexOutput.vWorldPos +\n mix(-0.5/255.0, 0.5/255.0, pseudoRandom(vertexOutput.fragCoord.xy)) * 2.0\n );\n envColor = vec4f(computeDiffuseSPH(normal, uniforms.diffuseSPH), 1.0);\n #else\n envColor = textureCubeFixed(\n cubeMap,\n cubeMapSampler,\n vertexOutput.vWorldPos,\n uniforms.size,\n uniforms.bias\n );\n #endif\n var rgb = envColor.rgb;\n rgb *= uniforms.environmentExposure;\n rgb *= uniforms.backgroundIntensity;\n if (length(uniforms.hsv) > 0.0) {\n rgb = hsv_apply3(clamp(rgb, vec3f(0.0), vec3f(1.0)), uniforms.hsv);\n }\n #if TONE_MAPPING\n rgb = toneMapping(rgb);\n let fragColor = linearToOutputTexel(vec4f(rgb, envColor.a));\n #else\n let fragColor = vec4f(rgb, envColor.a);\n #endif\n return fragColor;\n}";
114
114
 
115
115
  var glSkyboxVert = "struct Uniforms {\n projMatrix: mat4x4f,\n viewMatrix: mat4x4f,\n transformMatrix: mat3x3f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPos: vec3f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n output.vWorldPos = vertexInput.aPosition;\n let viewMatrix = uniforms.viewMatrix;\n let m3 = mat3x3f(viewMatrix[0].xyz, viewMatrix[1].xyz, viewMatrix[2].xyz) * uniforms.transformMatrix;\n let rotViewMatrix: mat4x4f = mat4x4f(\n vec4<f32>(m3[0], 0.0),\n vec4<f32>(m3[1], 0.0),\n vec4<f32>(m3[2], 0.0),\n vec4<f32>(0.0, 0.0, 0.0, 1.0)\n );\n let clipPos: vec4f = uniforms.projMatrix * rotViewMatrix * vec4f(output.vWorldPos, 1.0);\n output.position = vec4f(clipPos.xy, clipPos.w, clipPos.w);\n return output;\n}";
116
116
 
117
- var layer3dtilesPickingVert = "#include <get_output>\n#include <fbo_picking_vert>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n #ifdef HAS_MASK_EXTENT\n modelViewMatrix: mat4x4f,\n #endif\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n #else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let position: vec4f = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelMatrix * position;\n let projMatrix = shaderUniforms.projMatrix;\n #ifdef HAS_MASK_EXTENT\n output.position = projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = projMatrix * viewVertex;\n #endif\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= vertexInput.aColor.a;\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= vertexInput.aColor0.a;\n #endif\n fbo_picking_setData(vertexInput, &output, output.position.w, alpha != 0.0);\n return output;\n}";
117
+ var glSnowFrag = "struct SnowUniforms {\n fixedC: vec3f,\n};\n@group(0) @binding($b) var<uniform> snowUniforms: SnowUniforms;\n@group(0) @binding($b) var perlinTexture: texture_2d<f32>;\n@group(0) @binding($b) var perlinTextureSampler: sampler;\nfn lerp(a: f32, b: f32, w: f32) -> f32 {\n return a + w * (b - a);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let snowIntense = textureSample(perlinTexture, perlinTextureSampler, vertexOutput.vTexCoord).r;\n let r = lerp(0.5, snowUniforms.fixedC.x, snowIntense);\n let g = lerp(0.5, snowUniforms.fixedC.y, snowIntense);\n let b = lerp(0.5, snowUniforms.fixedC.z, snowIntense);\n return vec4f(r, g, b, 1.0);\n}";
118
+
119
+ var glSnowVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n @location($i) aTexCoord: vec2f\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vTexCoord: vec2f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = shaderUniforms.projMatrix * uniforms.modelViewMatrix * localPosition;\n output.vTexCoord = vertexInput.aTexCoord;\n return output;\n}";
120
+
121
+ var glRainFrag = "struct RainUniforms {\n diffuse: vec3f,\n opacity: f32,\n};\n@group(0) @binding($b) var<uniform> rainUniforms: RainUniforms;\n@group(0) @binding($b) var rainMap: texture_2d<f32>;\n@group(0) @binding($b) var rainMapSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let rainColor = textureSample(rainMap, rainMapSampler, vertexOutput.vTexCoord);\n var diffuseColor = vec4f(rainUniforms.diffuse, rainUniforms.opacity);\n diffuseColor *= rainColor;\n return diffuseColor;\n}";
122
+
123
+ var glRainVert = "#include <get_output>\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aNormal: vec3f,\n @location($i) aTexCoord: vec2f,\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vTexCoord: vec2f,\n};\nstruct Uniforms {\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n top: f32,\n bottom: f32,\n};\nstruct VertexShaderUniforms {\n projMatrix: mat4x4f,\n cameraPosition: vec3f,\n time: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: VertexShaderUniforms;\nfn angle(x: f32, y: f32) -> f32 {\n return atan2(y, x);\n}\nfn getFoot(camera: vec2f, normal: vec2f, pos: vec2f) -> vec2f {\n var position = vec2f(0.0, 0.0);\n let distanceLen = distance(pos, normal);\n var a = angle(camera.x - normal.x, camera.y - normal.y);\n if pos.x > normal.x {\n a -= 0.785;\n } else {\n a += 0.785;\n }\n position.x = cos(a) * distanceLen;\n position.y = sin(a) * distanceLen;\n return position + normal;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let foot = getFoot(\n vec2f(shaderUniforms.cameraPosition.x, shaderUniforms.cameraPosition.z),\n vec2f(vertexInput.aNormal.x, vertexInput.aNormal.z),\n vec2f(localPosition.x, localPosition.z)\n );\n let height = uniforms.top - uniforms.bottom;\n var y = vertexInput.aNormal.y - uniforms.bottom - height * shaderUniforms.time;\n if y < 0.0 {\n y += height;\n }\n let ratio = (1.0 - y / height) * (1.0 - y / height);\n y = height * (1.0 - ratio);\n y += uniforms.bottom;\n y += vertexInput.aPosition.y - vertexInput.aNormal.y;\n let finalLocalPosition = vec4f(foot.x, y, foot.y, 1.0);\n output.position = shaderUniforms.projMatrix *\n uniforms.modelViewMatrix *\n localPositionMatrix *\n finalLocalPosition;\n output.vTexCoord = vertexInput.aTexCoord;\n return output;\n}";
124
+
125
+ var glRipplesFrag = "struct RippleEffectUniforms {\n rippleRadius: f32,\n density: f32,\n time: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: RippleEffectUniforms;\nfn hash3(p: vec2f) -> vec3f {\n let q = vec3f(\n dot(p, vec2f(127.1, 311.7)),\n dot(p, vec2f(269.5, 183.3)),\n dot(p, vec2f(419.2, 371.9))\n );\n return fract(sin(q) * 43758.5453);\n}\nfn noise(x: vec2f) -> f32 {\n let v = x * uniforms.density / 4000.0;\n let p = floor(v);\n let f = fract(v);\n var va: f32 = 0.0;\n for (var j: i32 = -4; j <= 4; j++) {\n for (var i: i32 = -4; i <= 4; i++) {\n let g = vec2f(f32(i), f32(j));\n let o = hash3(p + g);\n let r = g - f + o.xy;\n let d = sqrt(dot(r, r));\n let ripple = max(mix(smoothstep(0.99, 0.999, max(cos(d - uniforms.time * 2.0 + (o.x + o.y) * 5.0), 0.0)), 0.0, d), 0.0);\n va += ripple;\n }\n }\n return va;\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let uv = vertexOutput.vTexCoord;\n let radius = 24.0 / (uniforms.rippleRadius * 0.01);\n let f = noise(radius * uv) * smoothstep(0.0, 0.4, sin(uv.x * 3.151592) * sin(uv.y * 3.141592));\n let normal = vec3f(-dpdx(f), -dpdy(f), -dpdy(f));\n return vec4f(normal, 1.0);\n}";
126
+
127
+ var glFogFrag = "struct WeatherUniforms {\n time: f32,\n resolution: vec2f,\n #ifdef HAS_SNOW\n snowIntensity: f32,\n #endif\n #ifdef HAS_FOG\n fogColor: vec3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: WeatherUniforms;\n#ifdef HAS_RAIN\n @group(0) @binding($b) var ripplesMapSampler: sampler;\n @group(0) @binding($b) var ripplesMap: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var sceneMapSampler: sampler;\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var sceneMap: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var sceneMap: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var mixFactorMapSampler: sampler;\n#ifdef HAS_MULTISAMPLED_MAP\n @group(0) @binding($b) var mixFactorMap: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var mixFactorMap: texture_2d<f32>;\n#endif\nconst HASHSCALE1 = 0.1031;\nconst HASHSCALE3 = vec3f(0.1031, 0.1030, 0.0973);\nconst HASHSCALE4 = vec4f(0.1031, 0.1030, 0.0973, 0.1099);\nconst SIZE_RATE = 0.5;\nconst XSPEED = 0.2;\nconst YSPEED = 0.5;\nconst LAYERS = 20.0;\nfn lerp(a: f32, b: f32, w: f32) -> f32 {\n return a + w * (b - a);\n}\nfn Hash11(p: f32) -> f32 {\n var p3 = fract(vec3f(p) * HASHSCALE1);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n}\nfn Hash22(p: vec2f) -> vec2f {\n var p3 = fract(vec3f(p.x, p.y, p.x) * HASHSCALE3);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.xx + p3.yz) * p3.zy);\n}\nfn Rand22(co: vec2f) -> vec2f {\n let x = fract(sin(dot(co, vec2f(122.9898, 783.233))) * 43758.5453);\n let y = fract(sin(dot(co, vec2f(457.6537, 537.2793))) * 37573.5913);\n return vec2f(x, y);\n}\n#ifdef HAS_SNOW\n fn SnowSingleLayer(uv: vec2f, layer: f32) -> vec3f {\n var uv_mut = uv * (2.0 + layer);\n let speedX = XSPEED * uniforms.snowIntensity;\n let xOffset = uv_mut.y * (((Hash11(layer) * 2.0 - 1.0) * 0.5 + 1.0) * speedX);\n let yOffset = YSPEED * uniforms.time;\n uv_mut += vec2f(xOffset, yOffset);\n let rgrid = Hash22(floor(uv_mut) + (31.1759 * layer));\n uv_mut = fract(uv_mut);\n uv_mut -= (rgrid * 2.0 - 1.0) * 0.35;\n uv_mut -= 0.5;\n let r = length(uv_mut);\n let circleSize = 0.05 * (1.0 + 0.3 * sin(uniforms.time * SIZE_RATE));\n let val = smoothstep(circleSize, -circleSize, r);\n let col = vec3f(val, val, val) * rgrid.x;\n return col;\n }\n fn snowFlower(fragCoord: vec2f) -> vec3f {\n var acc = vec3f(0.0, 0.0, 0.0);\n var uv = fragCoord / uniforms.resolution;\n uv.y = 1.0 - uv.y;\n uv *= vec2f(uniforms.resolution.x / uniforms.resolution.y, 1.0);\n let layers = LAYERS * uniforms.snowIntensity;\n for (var i: f32 = 0.0; i < layers; i += 1.0) {\n acc += SnowSingleLayer(uv, i);\n }\n return acc;\n }\n fn snow(sceneColor: vec4f, normalColor: vec4f, height: f32) -> vec3f {\n let snowIntense = normalColor.b;\n let fixedC = vec3f(1.0, 1.0, 1.0);\n if (height < 1.0) {\n let r = lerp(0.5, fixedC.x, snowIntense);\n let g = lerp(0.5, fixedC.y, snowIntense);\n let b = lerp(0.5, fixedC.z, snowIntense);\n return vec3f(r, g, b);\n } else {\n let r = lerp(sceneColor.r, fixedC.x, snowIntense);\n let g = lerp(sceneColor.g, fixedC.y, snowIntense);\n let b = lerp(sceneColor.b, fixedC.z, snowIntense);\n return vec3f(r, g, b);\n }\n }\n#endif\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n var uv = vertexOutput.vTexCoord;\n uv.y = 1.0 - uv.y;\n #ifdef HAS_MULTISAMPLED\n var sceneColor = textureLoad(sceneMap, vec2i(uv * uniforms.resolution), 0);\n #else\n var sceneColor = textureSample(sceneMap, sceneMapSampler, uv);\n #endif\n var glFragColor = sceneColor;\n #ifdef HAS_MULTISAMPLED_MAP\n let mixFactorColor = textureLoad(mixFactorMap, vec2i(uv * uniforms.resolution), 0);\n #else\n let mixFactorColor = textureSample(mixFactorMap, mixFactorMapSampler, uv);\n #endif\n #ifdef HAS_RAIN\n let ripplesColor = textureSample(ripplesMap, ripplesMapSampler, uv);\n if (mixFactorColor.g < 1.0) {\n sceneColor = mix(sceneColor, ripplesColor, 0.4);\n }\n glFragColor = sceneColor;\n #endif\n #ifdef HAS_SNOW\n let fragCoord = vertexOutput.position.xy;\n let snowFlowerColor = snowFlower(fragCoord);\n glFragColor = vec4f(sceneColor.rgb + snowFlowerColor, sceneColor.a);\n #endif\n #ifdef HAS_FOG\n let mixFactor = mixFactorColor.r;\n let mixColor = mix(uniforms.fogColor, glFragColor.rgb, mixFactor);\n glFragColor = vec4f(mixColor, sceneColor.a);\n #endif\n return glFragColor;\n}";
128
+
129
+ var glFogMixFactorVert = "#include <get_output>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n @location($i) aTexCoord: vec2f\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPosition: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localPosition: vec4f = localPositionMatrix * getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n output.position = shaderUniforms.projMatrix * uniforms.modelViewMatrix * localPosition;\n let worldPosition = uniforms.modelMatrix * localPosition;\n output.vWorldPosition = worldPosition;\n return output;\n}";
130
+
131
+ var glFogMixFactorFrag = "struct FogEffectUniforms {\n fogDist: vec2f,\n cameraPosition: vec3f,\n rainDepth: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: FogEffectUniforms;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let worldPosition = vertexOutput.vWorldPosition;\n let dir = vec3f(\n worldPosition.x - uniforms.cameraPosition.x,\n worldPosition.y - uniforms.cameraPosition.y,\n worldPosition.z - uniforms.cameraPosition.z\n );\n let dist = length(dir);\n let fogFactor = clamp(1.0 - (dist - uniforms.fogDist.x) / (uniforms.fogDist.y - uniforms.fogDist.x), 0.0, 1.0);\n var gl_FragColor: vec4f;\n if (worldPosition.z < uniforms.rainDepth) {\n gl_FragColor = vec4f(fogFactor, 0.0, 0.0, 1.0);\n } else {\n gl_FragColor = vec4f(fogFactor, 1.0, 0.0, 1.0);\n }\n return gl_FragColor;\n}";
132
+
133
+ var layer3dtilesPickingVert = "#include <get_output>\n#include <fbo_picking_vert>\nstruct Uniforms {\n modelMatrix: mat4x4f,\n #ifdef HAS_MASK_EXTENT\n modelViewMatrix: mat4x4f,\n #endif\n positionMatrix: mat4x4f\n};\nstruct ShaderUniforms {\n projMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nstruct VertexInput {\n #include <position_vert>\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) viewpoint: vec4f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix: mat4x4f = getPositionMatrix(vertexInput, &output, uniforms.positionMatrix);\n let localVertex = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n let position: vec4f = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelMatrix * position;\n let projMatrix = shaderUniforms.projMatrix;\n #ifdef HAS_MASK_EXTENT\n output.position = projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = projMatrix * viewVertex;\n #endif\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= vertexInput.aColor.a;\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= vertexInput.aColor0.a;\n #endif\n fbo_picking_setData(vertexInput, &output, output.position.w, alpha != 0.0);\n return output;\n}";
118
134
 
119
135
  var layerVideoVideoFrag = "struct FragUniforms {\n opacity: f32\n}\n@group(0) @binding($b) var videoTexture: texture_2d<f32>;\n@group(0) @binding($b) var videoTextureSampler: sampler;\n@group(0) @binding($b) var<uniform> fragUniforms: FragUniforms;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let color = textureSample(videoTexture, videoTextureSampler, vertexOutput.vTexCoords);\n return color * fragUniforms.opacity;\n}";
120
136
 
@@ -162,6 +178,10 @@
162
178
 
163
179
  var vtTubeVert = "#define EXTRUDE_SCALE 63.0\n#define EXTRUDE_MOD 64.0\n#define MAX_LINE_DISTANCE 65535.0\nstruct TubeUniforms {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n centiMeterToLocal: vec2f,\n lineWidth: f32,\n modelViewMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n modelMatrix: mat4x4f,\n tileResolution: f32,\n tileRatio: f32,\n};\nstruct TubeShaderUniforms {\n resolution: f32,\n}\n@group(0) @binding($b) var<uniform> uniforms: TubeUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: TubeShaderUniforms;\nstruct VertexInput {\n #ifdef HAS_ALTITUDE\n @location($i) aPosition: POSITION_TYPE_2,\n @location($i) aAltitude: f32,\n #else\n @location($i) aPosition: POSITION_TYPE_3,\n #endif\n @location($i) aTubeNormal: vec4i,\n #ifdef HAS_LINE_WIDTH\n @location($i) aLineWidth: u32,\n #endif\n #ifdef HAS_PATTERN\n @location($i) aLinesofar: u32,\n @location($i) aTexInfo: vec4u,\n @location($i) aNormalDistance: i32,\n #if HAS_PATTERN_ANIM\n @location($i) aLinePatternAnimSpeed: i32,\n #endif\n #if HAS_PATTERN_GAP\n @location($i) aLinePatternGap: i32,\n #endif\n #endif\n #ifdef HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifndef PICKING_MODE\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n @location($o) vModelVertex: vec3f,\n #ifdef HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #ifdef HAS_PATTERN\n @location($o) vLinesofar: f32,\n @location($o) vTexInfo: vec4f,\n @location($o) vNormalY: f32,\n @location($o) vPatternHeight: f32,\n #if HAS_PATTERN_ANIM\n @location($o) vLinePatternAnimSpeed: f32,\n #endif\n #if HAS_PATTERN_GAP\n @location($o) vLinePatternGap: f32,\n #endif\n #endif\n #endif\n};\n#include <vt_position_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#else\n #if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n #endif\n#endif\n#include <highlight_vert>\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n #ifdef HAS_LINE_WIDTH\n let myLineWidth = input.aLineWidth;\n #else\n let myLineWidth = uniforms.lineWidth;\n #endif\n let halfwidth = myLineWidth / 2.0;\n let tubeNormal = vec3f(input.aTubeNormal.xyz) / EXTRUDE_SCALE;\n let position = unpackVTPosition(input);\n var localVertex = vec4f(position, 1.0);\n let dxy = tubeNormal.xy * halfwidth * uniforms.centiMeterToLocal;\n let dz = tubeNormal.z * halfwidth;\n localVertex = vec4f(localVertex.xy + dxy, localVertex.z + dz, localVertex.w);\n output.position = uniforms.projViewModelMatrix * localVertex;\n #ifdef PICKING_MODE\n fbo_picking_setData(input, &output, output.position.w, true);\n #else\n output.vViewVertex = uniforms.modelViewMatrix * localVertex;\n let localNormal = normalize(tubeNormal);\n output.vModelNormal = uniforms.modelNormalMatrix * localNormal;\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localVertex);\n #endif\n #ifdef HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #ifdef HAS_PATTERN\n let scale = uniforms.tileResolution / shaderUniforms.resolution;\n #ifdef HAS_ALTITUDE\n let linesofar = f32(input.aLinesofar) - halfwidth * uniforms.centiMeterToLocal.y * f32(input.aNormalDistance) / EXTRUDE_SCALE;\n #else\n let linesofar = f32(input.aLinesofar);\n #endif\n output.vLinesofar = linesofar / uniforms.tileRatio * scale;\n output.vTexInfo = vec4f(vec2f(input.aTexInfo.xy), vec2f(input.aTexInfo.zw) + 1.0);\n output.vPatternHeight = myLineWidth * uniforms.centiMeterToLocal.x / uniforms.tileRatio * scale;\n output.vNormalY = f32(input.aTubeNormal.w) / EXTRUDE_SCALE;\n #if HAS_PATTERN_ANIM\n output.vLinePatternAnimSpeed = input.aLinePatternAnimSpeed / 127.0;\n #endif\n #if HAS_PATTERN_GAP\n output.vLinePatternGap = f32(input.aLinePatternGap) / 10.0;\n #endif\n #endif\n #if HAS_HIGHLIGHT_COLOR || HAS_HIGHLIGHT_OPACITY\n highlight_setVarying(input, &output);\n #endif\n #endif\n return output;\n}";
164
180
 
181
+ var vtFlatMaskFrag = "#include <common_pack_float>\n@fragment\nfn main(output: VertexOutput) -> @location(0) vec4f {\n return encodeFloat32(output.vAltitude);\n}";
182
+
183
+ var vtFlatMaskVert = "struct VertexInput {\n#ifdef HAS_ALTITUDE\n @location($i) aPosition: POSITION_TYPE_2,\n @location($i) aAltitude: f32,\n#else\n @location($i) aPosition: POSITION_TYPE_3,\n#endif\n}\nstruct UniformsStruct {\n projViewModelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n}\n@group(0) @binding($b) var<uniform> uniforms: UniformsStruct;\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vAltitude: f32,\n}\n#include <vt_position_vert>\n@vertex\nfn main(\n input: VertexInput,\n) -> VertexOutput {\n let position = unpackVTPosition(input);\n var output: VertexOutput;\n var localVertex = uniforms.positionMatrix * vec4f(position, 1.0);\n output.vAltitude = localVertex.z / 100;\n localVertex.z = 0;\n output.position = uniforms.projViewModelMatrix * localVertex;\n return output;\n}";
184
+
165
185
  registerWGSLSource('analysis_depth_frag', analysisDepthFrag);
166
186
  registerWGSLSource('analysis_depth_vert', analysisDepthVert);
167
187
  registerWGSLSource('analysis_excavateExtent_frag', analysisExcavateExtentFrag);
@@ -172,6 +192,7 @@
172
192
  registerWGSLSource('analysis_insight_vert', analysisInsightVert);
173
193
  registerWGSLSource('analysis_viewshed_frag', analysisViewshedFrag);
174
194
  registerWGSLSource('analysis_viewshed_vert', analysisViewshedVert);
195
+
175
196
  registerWGSLSource('gl_analysis_frag', glAnalysisFrag);
176
197
  registerWGSLSource('gl_fill_frag', glFillFrag);
177
198
  registerWGSLSource('gl_fill_vert', glFillVert);
@@ -205,9 +226,20 @@
205
226
  registerWGSLSource('gl_vsm_mapping_vert', glVsmMappingVert);
206
227
  registerWGSLSource('gl_skybox_frag', glSkyboxFrag);
207
228
  registerWGSLSource('gl_skybox_vert', glSkyboxVert);
229
+ registerWGSLSource('gl_snow_frag', glSnowFrag);
230
+ registerWGSLSource('gl_snow_vert', glSnowVert);
231
+ registerWGSLSource('gl_rain_frag', glRainFrag);
232
+ registerWGSLSource('gl_rain_vert', glRainVert);
233
+ registerWGSLSource('gl_ripples_vert', glSnowVert);
234
+ registerWGSLSource('gl_ripples_frag', glRipplesFrag);
235
+ registerWGSLSource('gl_fog_frag', glFogFrag);
236
+ registerWGSLSource('gl_fog_mixFactor_vert', glFogMixFactorVert);
237
+ registerWGSLSource('gl_fog_mixFactor_frag', glFogMixFactorFrag);
238
+
208
239
  registerWGSLSource('layer_3dtiles_picking_vert', layer3dtilesPickingVert);
209
240
  registerWGSLSource('layer_video_video_frag', layerVideoVideoFrag);
210
241
  registerWGSLSource('layer_video_video_vert', layerVideoVideoVert);
242
+
211
243
  registerWGSLSource('vt_billboard_frag', vtBillboardFrag);
212
244
  registerWGSLSource('vt_billboard_vert', vtBillboardVert);
213
245
  registerWGSLSource('vt_collision_frag', vtCollisionFrag);
@@ -229,7 +261,9 @@
229
261
  registerWGSLSource('vt_text_line_vert', vtTextLineVert);
230
262
  registerWGSLSource('vt_text_vert', vtTextVert);
231
263
  registerWGSLSource('vt_tube_vert', vtTubeVert);
264
+ registerWGSLSource('vt_flat_mask_frag', vtFlatMaskFrag);
265
+ registerWGSLSource('vt_flat_mask_vert', vtFlatMaskVert);
232
266
 
233
- typeof console !== 'undefined' && console.log('@maptalks/gpu v0.123.0');
267
+ typeof console !== 'undefined' && console.log('@maptalks/gpu v0.124.1');
234
268
 
235
269
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptalks/gpu",
3
- "version": "0.123.0",
3
+ "version": "0.124.1",
4
4
  "description": "WebGL infrastrcture for maptalks",
5
5
  "main": "dist/maptalksgpu.js",
6
6
  "module": "dist/maptalksgpu.es.js",
@@ -17,7 +17,7 @@
17
17
  "author": "fuzhenn",
18
18
  "license": "UNLICENSED",
19
19
  "dependencies": {
20
- "@maptalks/gl": "0.123.0"
20
+ "@maptalks/gl": "0.124.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@rollup/plugin-commonjs": "^25.0.7",