@matchomag/cs2-replay 0.0.0-stage → 0.3.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.
- package/README.md +9 -2
- package/bin/demo-replay-darwin-amd64 +0 -0
- package/bin/demo-replay-darwin-arm64 +0 -0
- package/bin/demo-replay-linux-amd64 +0 -0
- package/bin/demo-replay-linux-arm64 +0 -0
- package/bin/demo-replay-windows-amd64.exe +0 -0
- package/bin/demo-replay.js +22 -0
- package/dist/2d/index.js +1 -0
- package/dist/3d/index.js +11 -0
- package/dist/chunks/actors-EZRYEB4I.js +177 -0
- package/dist/chunks/chunk-5BFKVD63.js +1 -0
- package/dist/chunks/chunk-D5ST2XVO.js +106 -0
- package/dist/chunks/chunk-DQPOBPMK.js +1 -0
- package/dist/chunks/chunk-FBSLUYGT.js +1 -0
- package/dist/chunks/chunk-Q37CWKZX.js +12 -0
- package/dist/chunks/chunk-VSIECNZM.js +1 -0
- package/dist/chunks/chunk-YJG3LSSB.js +1 -0
- package/dist/chunks/chunk-YO73RW3Y.js +1 -0
- package/dist/chunks/look-2WBUGHMJ.js +669 -0
- package/dist/index.js +1 -0
- package/dist/maps/index.js +1 -0
- package/dist/parse/index.js +1 -0
- package/dist/parse/wasm/replay.wasm +0 -0
- package/dist/parse/worker.js +1 -0
- package/dist/types/2d/index.d.ts +17 -0
- package/dist/types/2d/radar.d.ts +35 -0
- package/dist/types/3d/actors.d.ts +90 -0
- package/dist/types/3d/characters/anim.d.ts +93 -0
- package/dist/types/3d/characters/ao.d.ts +3 -0
- package/dist/types/3d/characters/body.d.ts +37 -0
- package/dist/types/3d/characters/builder.d.ts +82 -0
- package/dist/types/3d/characters/index.d.ts +74 -0
- package/dist/types/3d/characters/rig.d.ts +73 -0
- package/dist/types/3d/characters/textures.d.ts +4 -0
- package/dist/types/3d/characters/viewmodel.d.ts +51 -0
- package/dist/types/3d/characters/weapons.d.ts +25 -0
- package/dist/types/3d/follow.d.ts +43 -0
- package/dist/types/3d/fx/batch.d.ts +87 -0
- package/dist/types/3d/fx/context.d.ts +34 -0
- package/dist/types/3d/fx/explosion.d.ts +14 -0
- package/dist/types/3d/fx/fire.d.ts +11 -0
- package/dist/types/3d/fx/index.d.ts +84 -0
- package/dist/types/3d/fx/lights.d.ts +25 -0
- package/dist/types/3d/fx/meshes.d.ts +18 -0
- package/dist/types/3d/fx/misc.d.ts +15 -0
- package/dist/types/3d/fx/random.d.ts +21 -0
- package/dist/types/3d/fx/smoke.d.ts +10 -0
- package/dist/types/3d/fx/textures.d.ts +29 -0
- package/dist/types/3d/fx/types.d.ts +117 -0
- package/dist/types/3d/greybox.d.ts +22 -0
- package/dist/types/3d/index.d.ts +127 -0
- package/dist/types/3d/look.d.ts +49 -0
- package/dist/types/3d/markers.d.ts +23 -0
- package/dist/types/3d/smoke/volume.d.ts +95 -0
- package/dist/types/3d/smoke/voxels.d.ts +87 -0
- package/dist/types/3d/world/index.d.ts +179 -0
- package/dist/types/3d/world/look.d.ts +16 -0
- package/dist/types/3d/world/material.d.ts +128 -0
- package/dist/types/3d/world/post.d.ts +75 -0
- package/dist/types/3d/world/probes.d.ts +39 -0
- package/dist/types/3d/world/release.d.ts +28 -0
- package/dist/types/3d/world/stage.d.ts +84 -0
- package/dist/types/core/format.d.ts +163 -0
- package/dist/types/core/live.d.ts +115 -0
- package/dist/types/core/model.d.ts +164 -0
- package/dist/types/core/playback.d.ts +82 -0
- package/dist/types/core/theme.d.ts +46 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/maps/index.d.ts +258 -0
- package/dist/types/parse/index.d.ts +108 -0
- package/dist/types/ui/shell.d.ts +131 -0
- package/dist/types/ui/styles.d.ts +1 -0
- package/package.json +68 -4
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
import{a as W,f as Fe,g as Ue,j as ke}from"./chunk-YO73RW3Y.js";import{a as z,b as U,c as Be,d as _e,e as Ge,f as Oe,g as ce,h as Pe,i as Ie,j as We,k as Ve,l as ze,m as Ne,o as je}from"./chunk-Q37CWKZX.js";import"./chunk-VSIECNZM.js";import"./chunk-YJG3LSSB.js";import*as ie from"three";import*as T from"three";import*as p from"three";import{FullScreenQuad as pt}from"three/addons/postprocessing/Pass.js";var vt=16,_=12,F=z+2,O=[F*4,F*4,F],ue=4,me=6e4,Et=3,re=class{constructor(e,t={}){this.camera=e;let n=new Uint8Array(O[0]*O[1]*O[2]*4);for(let u=0;u<n.length;u+=4)n[u]=n[u+1]=255;this.atlas=new p.Data3DTexture(n,...O),this.atlas.format=p.RGBAFormat,this.atlas.type=p.UnsignedByteType,this.atlas.minFilter=this.atlas.magFilter=p.LinearFilter,this.atlas.wrapS=this.atlas.wrapT=this.atlas.wrapR=p.ClampToEdgeWrapping,this.atlas.unpackAlignment=1,this.atlas.needsUpdate=!0,this.noise=gt();let r=(t.quality??"high")==="high",o=u=>new p.WebGLRenderTarget(1,1,{type:p.HalfFloatType,format:u,depthBuffer:!1,minFilter:p.NearestFilter,magFilter:p.NearestFilter});this.halfDepth=o(p.RedFormat),this.half=o(p.RGBAFormat),this.out=o(p.RGBAFormat);let s={uProjInv:{value:new p.Matrix4},uCamWorld:{value:new p.Matrix4},uCamPos:{value:new p.Vector3}};this.depthMat=new p.ShaderMaterial({uniforms:{tDepth:{value:null},uFull:{value:new p.Vector2},...s},defines:{FAR:me.toFixed(1)},vertexShader:de,fragmentShader:Tt,depthTest:!1,depthWrite:!1}),this.uniforms={tDepthH:{value:this.halfDepth.texture},tVol:{value:this.atlas},tNoise:{value:this.noise},uAtlasInv:{value:new p.Vector3(1/O[0],1/O[1],1/O[2])},...s,uCount:{value:0},sMin:{value:te(_)},sBoxMin:{value:te(_)},sBoxMax:{value:te(_)},sOff:{value:te(_)},sTime:{value:fe(_)},sLight:{value:fe(_)},uBlast:{value:fe(ue)},uBlastCount:{value:0},uSunDir:{value:new p.Vector3(0,1,0)},uSunColor:{value:new p.Color(1,1,1)},uFog:{value:new p.Vector2(1e5,1e6)},uFogColor:{value:new p.Color(0,0,0)},uStep:{value:r?.11:.18}},this.marchMat=new p.ShaderMaterial({uniforms:this.uniforms,defines:{ACTIVE:_,MAX_BLASTS:ue,MAX_STEPS:r?96:56,CELL:U.toFixed(6),D_SCALE:_e.toFixed(1),R_SCALE:Ge.toFixed(1),OD_MAX:Pe.toFixed(1),FAR:me.toFixed(1)},vertexShader:de,fragmentShader:bt,depthTest:!1,depthWrite:!1}),this.compositeMat=new p.ShaderMaterial({uniforms:{tScene:{value:null},tDepth:{value:null},tSmoke:{value:this.half.texture},tDepthH:{value:this.halfDepth.texture},uHalf:{value:new p.Vector2(1,1)},uRect:{value:this.rect},...s},defines:{FAR:me.toFixed(1)},vertexShader:de,fragmentShader:xt,depthTest:!1,depthWrite:!1})}camera;clouds=new Map;cloudSrc=new Map;slotOf=new Map;slotId=new Array(vt).fill(null);atlas;world=null;lighting={sunDirection:new p.Vector3(.4,.8,.3).normalize(),sunColor:new p.Color(2.5,2.2,1.9),ambient:new p.Color(.25,.27,.3)};probe={ambient:new p.Color,sun:1};v=new p.Vector3;noise;quad=new pt;depthMat;marchMat;compositeMat;halfDepth;half;out;size=new p.Vector2(1,1);rect=new p.Vector4(0,0,1,1);corner=new p.Vector3;uniforms;enabled=!1;setWorld(e){this.world=e}setLighting(e){if(!e.sunDirection.equals(this.lighting.sunDirection)){for(let t of this.clouds.values())t&&(t.light=null);for(let[t,n]of this.slotOf){let r=this.clouds.get(t);r&&this.upload(n,r)}}this.lighting=e}setFog(e){let t=this.uniforms;e?(t.uFog.value.set(e.near,e.far),t.uFogColor.value.copy(e.color)):t.uFog.value.set(1e5,1e6)}setSize(e,t){this.size.set(e,t);let n=Math.max(1,Math.ceil(e/2)),r=Math.max(1,Math.ceil(t/2));this.halfDepth.setSize(n,r),this.half.setSize(n,r),this.out.setSize(e,t),this.compositeMat.uniforms.uHalf.value.set(n,r),this.depthMat.uniforms.uFull.value.set(e,t)}cloud(e){let t=this.clouds.get(e.id);if(t!==void 0&&this.cloudSrc.get(e.id)===e.voxels)return t;let n=null,r=e.voxels?Oe(e.voxels):null;if(r&&r.seeds.length)n=ce(r,e.center);else if(this.world){let s=z/2*U,u=e.center.clone();u.y+=s-16*U+.02,n=ce(We(Ne(this.world,u)),u)}t=n?{field:n,light:null}:null,this.clouds.set(e.id,t),this.cloudSrc.set(e.id,e.voxels);let o=this.slotOf.get(e.id);return t&&o!==void 0&&this.upload(o,t),t}upload(e,t){let n=t.field;t.light??=Ie(n,this.lighting.sunDirection);let r=t.light,[o,s]=O,u=e%4*F,m=Math.floor(e/4)*F,l=this.atlas.image.data,b=(d,f)=>{for(let v=0;v<f;v++,d+=4)l[d]=l[d+1]=255,l[d+2]=l[d+3]=0};for(let d=0;d<F;d++)for(let f=0;f<F;f++){let v=((d*s+m+f)*o+u)*4;if(d===0||f===0||d===F-1||f===F-1){b(v,F);continue}b(v,1);let E=((d-1)*z+(f-1))*z;for(let w=0;w<z;w++){let L=v+(w+1)*4,M=(E+w)*2;l[L]=n.data[M],l[L+1]=n.data[M+1],l[L+2]=r[M],l[L+3]=r[M+1]}b(v+(F-1)*4,1)}this.atlas.needsUpdate=!0}update(e,t=[]){let n=this.uniforms,r=new Set,o=[];for(let d of e){if(d.age<0||d.remaining<=0)continue;let f=this.cloud(d);!f||!f.field.cells||(o.push({s:d,c:f}),r.add(d.id))}if(o.length>_){let d=this.camera.position;o.sort((f,v)=>f.s.center.distanceToSquared(d)-v.s.center.distanceToSquared(d)),o.length=_}for(let[d,f]of this.slotOf)r.has(d)||(this.slotOf.delete(d),this.slotId[f]=null);let s=this.lighting;this.camera.updateMatrixWorld();let m=this.rect.set(1,1,0,0),l=0;for(let{s:d,c:f}of o){let v=f.field,E=this.slotOf.get(d.id);if(E===void 0){if(E=this.slotId.indexOf(null),E<0)continue;this.slotId[E]=d.id,this.slotOf.set(d.id,E),this.upload(E,f)}n.sMin.value[l].copy(v.min);let w=.25,L=n.sBoxMin.value[l].set(v.min.x+v.lo[0]*U-w,v.min.y+v.lo[2]*U-w,v.min.z+v.lo[1]*U-w),M=n.sBoxMax.value[l].set(v.min.x+v.hi[0]*U+w,v.min.y+v.hi[2]*U+w,v.min.z+v.hi[1]*U+w);this.cover(L,M),n.sOff.value[l].set(E%4*F+1,Math.floor(E/4)*F+1,1);let y=Math.min(1,Math.max(0,1-d.remaining/Et));n.sTime.value[l].set(d.age,y,Be+1.2*y*y,d.id*.6180339%1);let k=s.ambient,V=1;this.v.copy(d.center),this.v.y+=1.2,s.probes?.sample(this.v,this.probe)&&(k=this.probe.ambient,V=this.probe.sun),n.sLight.value[l].set(k.r,k.g,k.b,V),l++}n.uCount.value=l;let b=0;for(let d of t)b>=ue||d.age<0||d.age>7||n.uBlast.value[b++].set(d.position.x,d.position.y,d.position.z,d.age);n.uBlastCount.value=b,n.uSunDir.value.copy(s.sunDirection).normalize(),n.uSunColor.value.copy(s.sunColor),this.enabled=l>0&&m.z>m.x&&m.w>m.y}cover(e,t){let n=this.rect,r=this.corner,o=this.camera;for(let s=0;s<8;s++){if(r.set(s&1?t.x:e.x,s&2?t.y:e.y,s&4?t.z:e.z),r.applyMatrix4(o.matrixWorldInverse),r.z>-o.near){n.set(0,0,1,1);return}r.applyMatrix4(o.projectionMatrix),n.x=Math.min(n.x,r.x*.5+.5),n.y=Math.min(n.y,r.y*.5+.5),n.z=Math.max(n.z,r.x*.5+.5),n.w=Math.max(n.w,r.y*.5+.5)}n.set(Math.max(0,n.x),Math.max(0,n.y),Math.min(1,n.z),Math.min(1,n.w))}get active(){return this.uniforms.uCount.value}render(e,t){let n=this.camera,r=this.depthMat.uniforms;r.uProjInv.value.copy(n.projectionMatrixInverse),r.uCamWorld.value.copy(n.matrixWorld),r.uCamPos.value.setFromMatrixPosition(n.matrixWorld),r.tDepth.value=t.depthTexture;let o=this.rect,s=this.half.width,u=this.half.height,m=Math.max(0,Math.floor(o.x*s)-2),l=Math.max(0,Math.floor(o.y*u)-2),b=Math.min(s,Math.ceil(o.z*s)+2),d=Math.min(u,Math.ceil(o.w*u)+2),f=e.getRenderTarget(),v=e.autoClear;e.autoClear=!1;for(let[w,L]of[[this.halfDepth,this.depthMat],[this.half,this.marchMat]])w.scissor.set(m,l,b-m,d-l),w.scissorTest=!0,this.quad.material=L,e.setRenderTarget(w),this.quad.render(e);let E=this.compositeMat.uniforms;return E.tScene.value=t.texture,E.tDepth.value=t.depthTexture,this.quad.material=this.compositeMat,e.setRenderTarget(this.out),this.quad.render(e),e.setRenderTarget(f),e.autoClear=v,this.out.texture}dispose(){this.atlas.dispose(),this.noise.dispose();for(let e of[this.depthMat,this.marchMat,this.compositeMat])e.dispose();for(let e of[this.halfDepth,this.half,this.out])e.dispose();this.quad.dispose(),this.clouds.clear(),this.cloudSrc.clear()}};function gt(){let e=new Uint8Array(32768),t=625341585;for(let u=0;u<e.length;u++)t^=t<<13,t^=t>>>17,t^=t<<5,e[u]=t>>>0&255;let n=(u,m,l,b)=>b[((l+32)%32*32+(m+32)%32)*32+(u+32)%32],r=e;for(let u=0;u<3;u++){let m=new Float32Array(e.length);for(let l=0;l<32;l++)for(let b=0;b<32;b++)for(let d=0;d<32;d++){let f=0;for(let v=-1;v<=1;v++)f+=(u===0?n(d+v,b,l,r):u===1?n(d,b+v,l,r):n(d,b,l+v,r))*(v?.25:.5);m[(l*32+b)*32+d]=f}r=m}Array.from({length:e.length},(u,m)=>m).sort((u,m)=>r[u]-r[m]).forEach((u,m)=>e[u]=Math.round(m/(e.length-1)*255));let s=new p.Data3DTexture(e,32,32,32);return s.format=p.RedFormat,s.minFilter=s.magFilter=p.LinearFilter,s.wrapS=s.wrapT=s.wrapR=p.RepeatWrapping,s.unpackAlignment=1,s.needsUpdate=!0,s}var te=a=>Array.from({length:a},()=>new p.Vector3),fe=a=>Array.from({length:a},()=>new p.Vector4),de=`
|
|
2
|
+
varying vec2 vUv;
|
|
3
|
+
void main() { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }`,$e=`
|
|
4
|
+
uniform mat4 uProjInv;
|
|
5
|
+
float rayDist(vec2 uv, float depth) {
|
|
6
|
+
if (depth >= 0.999999) return FAR;
|
|
7
|
+
vec4 vp = uProjInv * vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
|
8
|
+
return min(length(vp.xyz / vp.w), FAR);
|
|
9
|
+
}`,Tt=`
|
|
10
|
+
precision highp float;
|
|
11
|
+
varying vec2 vUv;
|
|
12
|
+
uniform sampler2D tDepth;
|
|
13
|
+
uniform vec2 uFull;
|
|
14
|
+
${$e}
|
|
15
|
+
void main() {
|
|
16
|
+
ivec2 h = ivec2(gl_FragCoord.xy);
|
|
17
|
+
ivec2 lim = ivec2(uFull) - 1;
|
|
18
|
+
ivec2 f = h * 2;
|
|
19
|
+
float a = texelFetch(tDepth, min(f, lim), 0).x;
|
|
20
|
+
float b = texelFetch(tDepth, min(f + ivec2(1, 0), lim), 0).x;
|
|
21
|
+
float c = texelFetch(tDepth, min(f + ivec2(0, 1), lim), 0).x;
|
|
22
|
+
float d = texelFetch(tDepth, min(f + ivec2(1, 1), lim), 0).x;
|
|
23
|
+
float z = ((h.x + h.y) & 1) == 0 ? min(min(a, b), min(c, d)) : max(max(a, b), max(c, d));
|
|
24
|
+
gl_FragColor = vec4(rayDist(vUv, z), 0.0, 0.0, 1.0);
|
|
25
|
+
}`,bt=`
|
|
26
|
+
precision highp float;
|
|
27
|
+
precision highp sampler3D;
|
|
28
|
+
varying vec2 vUv;
|
|
29
|
+
uniform sampler2D tDepthH;
|
|
30
|
+
uniform sampler3D tVol;
|
|
31
|
+
uniform sampler3D tNoise;
|
|
32
|
+
uniform vec3 uAtlasInv;
|
|
33
|
+
uniform mat4 uProjInv;
|
|
34
|
+
uniform mat4 uCamWorld;
|
|
35
|
+
uniform vec3 uCamPos;
|
|
36
|
+
uniform int uCount;
|
|
37
|
+
uniform vec3 sMin[ACTIVE];
|
|
38
|
+
uniform vec3 sBoxMin[ACTIVE];
|
|
39
|
+
uniform vec3 sBoxMax[ACTIVE];
|
|
40
|
+
uniform vec3 sOff[ACTIVE];
|
|
41
|
+
uniform vec4 sTime[ACTIVE]; // age, dissolve 0..1, reach (cells), random
|
|
42
|
+
uniform vec4 sLight[ACTIVE]; // ambient rgb, sun visibility
|
|
43
|
+
uniform vec4 uBlast[MAX_BLASTS];
|
|
44
|
+
uniform int uBlastCount;
|
|
45
|
+
uniform vec3 uSunDir;
|
|
46
|
+
uniform vec3 uSunColor;
|
|
47
|
+
uniform vec2 uFog;
|
|
48
|
+
uniform vec3 uFogColor;
|
|
49
|
+
uniform float uStep;
|
|
50
|
+
|
|
51
|
+
const float SIGMA = 9.0; // extinction per metre at full density
|
|
52
|
+
const float ALBEDO = 0.86;
|
|
53
|
+
|
|
54
|
+
vec2 boxHit(vec3 ro, vec3 rd, vec3 bmin, vec3 bmax) {
|
|
55
|
+
vec3 inv = 1.0 / rd;
|
|
56
|
+
vec3 a = (bmin - ro) * inv, b = (bmax - ro) * inv;
|
|
57
|
+
vec3 lo = min(a, b), hi = max(a, b);
|
|
58
|
+
return vec2(max(max(lo.x, lo.y), lo.z), min(min(hi.x, hi.y), hi.z));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// When a cell fills: everything near the seeds within the first frames, the rest
|
|
62
|
+
// creeping out over ~3.5 s (fitted to when the server sent each brick), and nothing
|
|
63
|
+
// before the front from the canister gets there (so it pours from the grenade).
|
|
64
|
+
float fillTime(float d, float r) {
|
|
65
|
+
float ts = d <= 2.5 ? 0.0 : d <= 4.0 ? (d - 2.5) / 1.5 * 0.75 : d <= 5.0 ? 0.75 + (d - 4.0) * 1.15 : 1.9 + (d - 5.0) * 1.7;
|
|
66
|
+
float tc = 0.07 * r + 0.004 * r * r;
|
|
67
|
+
return max(ts, tc);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// HE blasts open a hole that refills over ~5 s (core 200 units, feathered to 240).
|
|
71
|
+
float blastOpen(vec3 p) {
|
|
72
|
+
float k = 1.0;
|
|
73
|
+
for (int b = 0; b < MAX_BLASTS; b++) {
|
|
74
|
+
if (b >= uBlastCount) break;
|
|
75
|
+
float age = uBlast[b].w;
|
|
76
|
+
float rec = pow(smoothstep(0.5, 5.0, age), 1.8);
|
|
77
|
+
float radius = mix(5.08, 0.0, rec);
|
|
78
|
+
float dist = length(p - uBlast[b].xyz);
|
|
79
|
+
float hole = 1.0 - smoothstep(radius, radius + 1.0, dist);
|
|
80
|
+
k *= 1.0 - hole * (1.0 - mix(0.02, 1.0, rec));
|
|
81
|
+
}
|
|
82
|
+
return k;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Billowy detail, three octaves churning slowly upwards (the noise's blobs are ~0.11/f m
|
|
86
|
+
// across): x: lumps of ~1.5 m that shape the outline, y: puffs of ~0.7 m, folded
|
|
87
|
+
// (1 - |2n - 1|) into rounded billows, z: ~0.3 m detail on their surface.
|
|
88
|
+
vec3 billows(vec3 p, float age, float seed) {
|
|
89
|
+
vec3 q = p + vec3(seed * 17.0, 0.0, seed * 9.0);
|
|
90
|
+
float a = texture(tNoise, q * 0.075 + vec3(0.0, -age * 0.004, 0.0)).r;
|
|
91
|
+
float b = texture(tNoise, q * 0.16 + vec3(age * 0.006, -age * 0.011, 0.0)).r;
|
|
92
|
+
float c = texture(tNoise, q * 0.38 - vec3(0.0, age * 0.02, age * 0.012)).r;
|
|
93
|
+
return vec3(a, 1.0 - abs(2.0 * b - 1.0), c);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
float ign(vec2 p) { return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); }
|
|
97
|
+
|
|
98
|
+
float hg(float c, float g) { float g2 = g * g; return (1.0 - g2) / pow(1.0 + g2 - 2.0 * g * c, 1.5); }
|
|
99
|
+
|
|
100
|
+
void main() {
|
|
101
|
+
float tMax = texelFetch(tDepthH, ivec2(gl_FragCoord.xy), 0).r;
|
|
102
|
+
vec4 vp = uProjInv * vec4(vUv * 2.0 - 1.0, 1.0, 1.0);
|
|
103
|
+
vec3 rd = normalize((uCamWorld * vec4(normalize(vp.xyz / vp.w), 0.0)).xyz);
|
|
104
|
+
vec3 ro = uCamPos;
|
|
105
|
+
|
|
106
|
+
float t0 = 1e9, t1 = 0.0;
|
|
107
|
+
int hit = 0;
|
|
108
|
+
for (int i = 0; i < ACTIVE; i++) {
|
|
109
|
+
if (i >= uCount) break;
|
|
110
|
+
vec2 h = boxHit(ro, rd, sBoxMin[i], sBoxMax[i]);
|
|
111
|
+
h.x = max(h.x, 0.0);
|
|
112
|
+
h.y = min(h.y, tMax);
|
|
113
|
+
if (h.y > h.x) {
|
|
114
|
+
t0 = min(t0, h.x);
|
|
115
|
+
t1 = max(t1, h.y);
|
|
116
|
+
hit |= 1 << i;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (hit == 0) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); return; }
|
|
120
|
+
|
|
121
|
+
float len = t1 - t0;
|
|
122
|
+
int steps = int(clamp(ceil(len / uStep), 4.0, float(MAX_STEPS)));
|
|
123
|
+
float dt = len / float(steps);
|
|
124
|
+
float jit = ign(gl_FragCoord.xy);
|
|
125
|
+
float cosT = dot(rd, uSunDir);
|
|
126
|
+
float phase = mix(hg(cosT, 0.35), hg(cosT, -0.15), 0.45);
|
|
127
|
+
// Smoke is grey: the sun's and sky's tints come through, but muted.
|
|
128
|
+
vec3 sunC = mix(vec3(dot(uSunColor, vec3(0.2126, 0.7152, 0.0722))), uSunColor, 0.45);
|
|
129
|
+
float T = 1.0;
|
|
130
|
+
vec3 L = vec3(0.0);
|
|
131
|
+
float tSum = 0.0, wSum = 0.0;
|
|
132
|
+
for (int s = 0; s < MAX_STEPS; s++) {
|
|
133
|
+
if (s >= steps || T < 0.005) break;
|
|
134
|
+
float t = t0 + (float(s) + jit) * dt;
|
|
135
|
+
vec3 p = ro + rd * t;
|
|
136
|
+
float dens = 0.0, sunOD = 0.0, skyOD = 0.0, sunVis = 0.0, puff = 0.0;
|
|
137
|
+
vec3 amb = vec3(0.0);
|
|
138
|
+
for (int i = 0; i < ACTIVE; i++) {
|
|
139
|
+
if (i >= uCount) break;
|
|
140
|
+
if ((hit & (1 << i)) == 0) continue;
|
|
141
|
+
vec3 c = (p - sMin[i]) / CELL;
|
|
142
|
+
if (any(lessThan(c, vec3(0.0))) || any(greaterThan(c, vec3(32.0)))) continue;
|
|
143
|
+
vec4 v = texture(tVol, (sOff[i] + c.xzy) * uAtlasInv);
|
|
144
|
+
float d = v.r * 255.0 / D_SCALE;
|
|
145
|
+
vec4 tm = sTime[i];
|
|
146
|
+
if (d > tm.z + 2.4) continue; // beyond any lump of the outline
|
|
147
|
+
float r = v.g * 255.0 / R_SCALE;
|
|
148
|
+
vec3 n = billows(p, tm.x, tm.w);
|
|
149
|
+
// The outline: the fill reach, pushed in and out by lumps, billows and detail.
|
|
150
|
+
// The growing front is lumpy too: billows arrive a little early or late.
|
|
151
|
+
float tA = fillTime(d, r) + (0.5 - n.x) * 0.7 + (0.6 - n.y) * 0.35;
|
|
152
|
+
float grow = smoothstep(tA - 0.05, tA + 0.3, tm.x);
|
|
153
|
+
float lumps = (n.x - 0.5) * 2.6 + (n.y - 0.6) * 1.5 + (n.z - 0.5) * 0.6;
|
|
154
|
+
float inside = tm.z - d + lumps;
|
|
155
|
+
float edge = smoothstep(0.0, 0.7, inside);
|
|
156
|
+
// Dissolve from the outside in.
|
|
157
|
+
float dis = 1.0 - smoothstep(0.0, 0.55, tm.y * 1.55 - (1.0 - clamp(d / tm.z, 0.0, 1.0)) * 0.6 + (n.x - 0.5) * 0.45);
|
|
158
|
+
float di = grow * edge * dis;
|
|
159
|
+
if (di <= 0.002) continue;
|
|
160
|
+
di *= mix(0.85, 1.1, n.y);
|
|
161
|
+
// Baked self-shadowing of the grown cloud, thinner while it grows and dissolves. It was
|
|
162
|
+
// baked for the smooth outline: where the billows dip below it, the surface is lit as
|
|
163
|
+
// the surface, not as the inside it would be without them.
|
|
164
|
+
float k = smoothstep(0.0, 3.0, tm.x) * (1.0 - tm.y);
|
|
165
|
+
vec2 od = max(v.ba * v.ba * OD_MAX - max(0.0, -lumps) * CELL, 0.0) * k;
|
|
166
|
+
dens += di;
|
|
167
|
+
sunOD += od.x * di;
|
|
168
|
+
skyOD += od.y * di;
|
|
169
|
+
sunVis += sLight[i].a * di;
|
|
170
|
+
puff += n.y * di;
|
|
171
|
+
vec3 a = sLight[i].rgb;
|
|
172
|
+
amb += mix(vec3(dot(a, vec3(0.2126, 0.7152, 0.0722))), a, 0.35) * di;
|
|
173
|
+
}
|
|
174
|
+
if (dens <= 0.002) continue;
|
|
175
|
+
dens *= blastOpen(p);
|
|
176
|
+
float w = 1.0 / dens;
|
|
177
|
+
sunOD *= w; skyOD *= w; sunVis *= w; puff *= w; amb *= w;
|
|
178
|
+
// Light through the cloud: single scattering plus softer terms standing in for the
|
|
179
|
+
// light that scatters many times inside (keeps the shaded side from going black).
|
|
180
|
+
float Ts = (exp(-4.5 * sunOD) + 0.5 * exp(-1.2 * sunOD) + 0.25 * exp(-0.4 * sunOD)) / 1.75;
|
|
181
|
+
float sky = mix(0.32, 1.0, exp(-1.4 * skyOD)) * mix(0.82, 1.08, puff);
|
|
182
|
+
vec3 Ls = ALBEDO * (sunC * sunVis * Ts * phase * 0.6 + amb * 1.15 * sky);
|
|
183
|
+
float a = 1.0 - exp(-SIGMA * dens * dt);
|
|
184
|
+
L += T * a * Ls;
|
|
185
|
+
tSum += T * a * t;
|
|
186
|
+
wSum += T * a;
|
|
187
|
+
T *= 1.0 - a;
|
|
188
|
+
}
|
|
189
|
+
// The scene's fog over the smoke, at its average depth.
|
|
190
|
+
if (wSum > 0.0) {
|
|
191
|
+
float f = clamp((tSum / wSum - uFog.x) / (uFog.y - uFog.x), 0.0, 1.0);
|
|
192
|
+
L = mix(L, uFogColor * (1.0 - T), f);
|
|
193
|
+
}
|
|
194
|
+
gl_FragColor = vec4(L, T);
|
|
195
|
+
}
|
|
196
|
+
`,xt=`
|
|
197
|
+
precision highp float;
|
|
198
|
+
varying vec2 vUv;
|
|
199
|
+
uniform sampler2D tScene;
|
|
200
|
+
uniform sampler2D tDepth;
|
|
201
|
+
uniform sampler2D tSmoke;
|
|
202
|
+
uniform sampler2D tDepthH;
|
|
203
|
+
uniform vec2 uHalf;
|
|
204
|
+
uniform vec4 uRect;
|
|
205
|
+
${$e}
|
|
206
|
+
void main() {
|
|
207
|
+
vec4 scene = texture2D(tScene, vUv);
|
|
208
|
+
if (vUv.x < uRect.x || vUv.y < uRect.y || vUv.x > uRect.z || vUv.y > uRect.w) { gl_FragColor = scene; return; }
|
|
209
|
+
float t = rayDist(vUv, texelFetch(tDepth, ivec2(gl_FragCoord.xy), 0).x);
|
|
210
|
+
vec2 hp = vUv * uHalf;
|
|
211
|
+
ivec2 c = ivec2(floor(hp));
|
|
212
|
+
ivec2 lim = ivec2(uHalf) - 1;
|
|
213
|
+
vec4 acc = vec4(0.0), best = vec4(0.0, 0.0, 0.0, 1.0);
|
|
214
|
+
float wSum = 0.0, bestDiff = 1e9;
|
|
215
|
+
for (int y = -1; y <= 1; y++)
|
|
216
|
+
for (int x = -1; x <= 1; x++) {
|
|
217
|
+
ivec2 q = clamp(c + ivec2(x, y), ivec2(0), lim);
|
|
218
|
+
vec2 o = abs(vec2(q) + 0.5 - hp);
|
|
219
|
+
float tent = max(0.0, 1.3 - o.x) * max(0.0, 1.3 - o.y);
|
|
220
|
+
if (tent <= 0.0) continue;
|
|
221
|
+
vec4 s = texelFetch(tSmoke, q, 0);
|
|
222
|
+
float diff = abs(texelFetch(tDepthH, q, 0).r - t) / max(t, 0.05);
|
|
223
|
+
float w = tent * (1.0 - smoothstep(0.01, 0.06, diff)) + 1e-5;
|
|
224
|
+
acc += s * w;
|
|
225
|
+
wSum += w;
|
|
226
|
+
if (diff < bestDiff) { bestDiff = diff; best = s; }
|
|
227
|
+
}
|
|
228
|
+
vec4 sm = wSum > 0.01 ? acc / wSum : best;
|
|
229
|
+
gl_FragColor = vec4(scene.rgb * sm.a + sm.rgb, scene.a);
|
|
230
|
+
}
|
|
231
|
+
`;import*as c from"three";import{GLTFLoader as Ut}from"three/addons/loaders/GLTFLoader.js";import{KTX2Loader as kt}from"three/addons/loaders/KTX2Loader.js";import{MeshoptDecoder as Bt}from"three/addons/libs/meshopt_decoder.module.js";import*as g from"three";function qe(){return{cs2Irradiance:{value:null},cs2Directional:{value:null},cs2SunShadow:{value:null},cs2LightmapScale:{value:Math.PI},cs2Directionality:{value:1},cs2EnvStrength:{value:1},cs2Debug:{value:0},cs2NormalFlipY:{value:0},cs2EnvAtlas:{value:null},cs2EnvVol:{value:null},cs2EnvGrid:{value:null},cs2EnvGridOrigin:{value:new g.Vector3},cs2EnvGridDims:{value:new g.Vector3(1,1,1)},cs2EnvGridCell:{value:2},cs2EnvAtlasInfo:{value:new g.Vector4(1,1,1,1)},cs2EnvCols:{value:16},cs2EnvLevels:{value:Array.from({length:6},()=>new g.Vector3)},cs2EnvProbes:{value:0},cs2Wind:{value:new g.Vector4(0,1,1,0)}}}var Rt=new g.DataTexture(new Uint8Array([255,255,255,255]),1,1);Rt.needsUpdate=!0;function he(a,e){let t=new g.Matrix3;return a&&t.setUvTransform(a.offset[0],a.offset[1],a.scale[0],a.scale[1],a.rotation,a.center[0],a.center[1]),e&&t.premultiply(new g.Matrix3().makeScale(e[0],e[1])),t}function wt(a,e=[1,1,1,1]){let t=a?.value??e;return new g.Vector4(t[0]??1,t[1]??1,t[2]??1,t[3]??1)}function Xe(a,e,t,n){let r=new g.MeshStandardMaterial({roughness:1,metalness:0});r.name=a.name;let o={},s={},u=a.layers??[],m=u[0]??{},l=a.family==="layered"||a.family==="twoway"?u[1]:void 0,b=(f,v,E,w)=>{let L=t(v,E);return L?(s[f]={value:L},o[w]="",!0):(s[`${f}Const`]={value:wt(v)},!1)};if(b("cs2Color1",m.color,"color","CS2_COLOR1"),b("cs2Normal1",m.normal,"linear","CS2_NORMAL1"),s.cs2Uv1={value:he(m.uv)},s.cs2Tint1={value:new g.Color().fromArray(m.tint??[1,1,1])},s.cs2Rough1={value:new g.Vector3(m.roughness?.[0]??1,m.roughness?.[1]??1,m.roughnessValue??-1)},s.cs2Metal1={value:m.metal?1:0},s.cs2HeightAdj={value:new g.Vector4(m.heightScale??1,m.heightZero??.5,l?.heightScale??1,l?.heightZero??.5)},s.cs2VColorMode={value:new g.Vector2(m.vertexColorMode??0,l?.vertexColorMode??0)},a.family==="layered"&&(o.CS2_LAYERED="",b("cs2Height1",m.height,"linear","CS2_HEIGHT1")),l&&(o.CS2_LAYER2="",b("cs2Color2",l.color,"color","CS2_COLOR2"),b("cs2Normal2",l.normal,"linear","CS2_NORMAL2"),a.family==="layered"&&b("cs2Height2",l.height,"linear","CS2_HEIGHT2"),s.cs2Uv2={value:l.uv?he(l.uv):he(m.uv,l.uvScale2)},s.cs2Tint2={value:new g.Color().fromArray(l.tint??[1,1,1])},s.cs2Rough2={value:new g.Vector3(l.roughness?.[0]??1,l.roughness?.[1]??1,l.roughnessValue??-1)},s.cs2Metal2={value:l.metal?1:0},s.cs2BlendSoftness={value:a.blendSoftness??.1}),a.family==="twoway"&&(o.CS2_TWOWAY="",b("cs2Mask",a.mask,"linear","CS2_MASK"),s.cs2Metalness2={value:new g.Vector2(m.metalness??0,l?.metalness??0)}),(a.family==="standard"||a.family==="glass"||a.family==="unlit")&&(b("cs2AoTex",a.ao,"linear","CS2_AOTEX"),b("cs2MetalTex",a.metalnessMap,"linear","CS2_METALTEX"),a.tintMask&&b("cs2TintMask",a.tintMask,"linear","CS2_TINTMASK"),s.cs2Metalness={value:a.metalness??0},a.selfIllum)){let f=a.selfIllum;b("cs2SelfIllum",f.mask,"linear","CS2_SELFILLUM_MASK"),o.CS2_SELFILLUM="",s.cs2SelfIllumStrength={value:(f.scale??1)*Math.pow(2,f.brightness??0)},s.cs2SelfIllumTint={value:new g.Color().fromArray(f.tint??[1,1,1])}}s.cs2MatTint={value:new g.Color().fromArray(a.tint??[1,1,1])},a.lightmapped&&(o.CS2_LIGHTMAP=""),n.hasBlend&&(o.CS2_BLEND_ATTR=""),n.hasColor&&(r.vertexColors=!0,a.foliage||(o.CS2_VCOLOR=""),a.vertexColor&&!a.foliage&&(o.CS2_VCOLOR_ALPHA=""),a.wind&&(a.wind.sway[0]>0||a.wind.flutter[0]>0)&&(o.CS2_WIND="",s.cs2WindSway={value:new g.Vector4(...a.wind.sway.slice(0,4))},s.cs2WindFlutter={value:new g.Vector4(...a.wind.flutter.slice(0,4))})),n.envProbes&&(o.CS2_ENVPROBES=""),a.family==="unlit"&&(o.CS2_UNLIT=""),a.black&&(o.CS2_BLACK=""),a.family==="glass"&&(o.CS2_GLASS=""),a.mod2x&&(o.CS2_MOD2X=""),r.side=a.doubleSided?g.DoubleSide:g.FrontSide,a.alphaTest&&!a.translucent&&(r.alphaTest=a.alphaTest,r.alphaToCoverage=!0),(a.translucent||a.mod2x||a.family==="glass")&&(r.transparent=!0,r.depthWrite=!1),a.opacity!=null&&(s.cs2Opacity={value:a.opacity}),(a.decal||a.mod2x)&&(r.polygonOffset=!0,r.polygonOffsetFactor=-1,r.polygonOffsetUnits=-4),a.mod2x&&(r.blending=g.CustomBlending,r.blendSrc=g.DstColorFactor,r.blendDst=g.SrcColorFactor,r.blendEquation=g.AddEquation);let d=Object.keys(o).sort().join(",")+`|${r.side}|${r.alphaTest>0}|${r.transparent}`;return r.customProgramCacheKey=()=>d,r.userData.cs2=a,r.userData.cs2Uniforms=s,r.onBeforeCompile=f=>{Object.assign(f.uniforms,s,e),f.defines={...f.defines,...o},f.vertexShader=yt(f.vertexShader,s),f.fragmentShader=Ct(f.fragmentShader,s)},r}function yt(a,e){let t="cs2WindSway"in e;return a.replace("#include <common>",`#include <common>
|
|
232
|
+
varying vec3 vCs2WorldPos;
|
|
233
|
+
${t?`uniform vec4 cs2WindSway;
|
|
234
|
+
uniform vec4 cs2WindFlutter;
|
|
235
|
+
uniform vec4 cs2Wind;`:""}
|
|
236
|
+
varying vec2 vCs2Uv;
|
|
237
|
+
varying vec3 vCs2T;
|
|
238
|
+
varying vec3 vCs2B;
|
|
239
|
+
#ifdef CS2_LIGHTMAP
|
|
240
|
+
#ifndef USE_UV1
|
|
241
|
+
attribute vec2 uv1;
|
|
242
|
+
#endif
|
|
243
|
+
varying vec2 vCs2Lm;
|
|
244
|
+
#endif
|
|
245
|
+
#ifdef CS2_BLEND_ATTR
|
|
246
|
+
attribute vec4 _blend;
|
|
247
|
+
#endif
|
|
248
|
+
varying vec4 vCs2Blend;
|
|
249
|
+
#ifndef USE_TANGENT
|
|
250
|
+
attribute vec4 tangent;
|
|
251
|
+
#endif`).replace("#include <uv_vertex>",`#include <uv_vertex>
|
|
252
|
+
vCs2Uv = uv;
|
|
253
|
+
#ifdef CS2_LIGHTMAP
|
|
254
|
+
vCs2Lm = uv1;
|
|
255
|
+
#endif
|
|
256
|
+
#ifdef CS2_BLEND_ATTR
|
|
257
|
+
vCs2Blend = _blend;
|
|
258
|
+
#else
|
|
259
|
+
vCs2Blend = vec4(0.0, 0.0, 0.0, 1.0);
|
|
260
|
+
#endif`).replace("#include <normal_vertex>",`#include <normal_vertex>
|
|
261
|
+
vCs2T = normalize((modelViewMatrix * vec4(tangent.xyz, 0.0)).xyz);
|
|
262
|
+
vCs2B = normalize(cross(normalize(transformedNormal), vCs2T) * tangent.w);`).replace("#include <begin_vertex>",t?St:"#include <begin_vertex>").replace("#include <project_vertex>",`#include <project_vertex>
|
|
263
|
+
vCs2WorldPos = (modelMatrix * vec4(transformed, 1.0)).xyz;`)}var St=`#include <begin_vertex>
|
|
264
|
+
{
|
|
265
|
+
vec3 wp = (modelMatrix * vec4(transformed, 1.0)).xyz;
|
|
266
|
+
float t = cs2Wind.w;
|
|
267
|
+
float strength = cs2Wind.z;
|
|
268
|
+
vec3 wdir = vec3(cs2Wind.x, 0.0, cs2Wind.y);
|
|
269
|
+
#if defined(USE_COLOR_ALPHA) || defined(USE_COLOR)
|
|
270
|
+
float wS = pow(clamp(color.r, 0.0, 1.0), max(cs2WindSway.z, 0.05));
|
|
271
|
+
float wF = pow(clamp(color.b, 0.0, 1.0), max(cs2WindFlutter.z, 0.05));
|
|
272
|
+
#else
|
|
273
|
+
float wS = 0.0, wF = 0.0;
|
|
274
|
+
#endif
|
|
275
|
+
float ph = dot(wp.xz, vec2(0.23, 0.17)) * cs2WindSway.w;
|
|
276
|
+
float sp = cs2WindSway.y;
|
|
277
|
+
float sway = strength * (0.55 + 0.3 * sin(t * sp * 2.1 + ph) + 0.15 * sin(t * sp * 5.3 + ph * 1.9));
|
|
278
|
+
vec3 off = wdir * sway * wS * cs2WindSway.x * 0.11;
|
|
279
|
+
off += cross(wdir, vec3(0.0, 1.0, 0.0)) * sin(t * sp * 1.6 + ph * 1.3) * wS * cs2WindSway.x * 0.03 * strength;
|
|
280
|
+
off.y -= dot(off, off) * 2.0;
|
|
281
|
+
float fph = dot(wp, vec3(1.7, 2.3, 1.3)) * cs2WindFlutter.w * 2.5;
|
|
282
|
+
float fl = 0.6 * sin(t * cs2WindFlutter.y * 10.0 + fph) + 0.4 * sin(t * cs2WindFlutter.y * 16.3 + fph * 1.31);
|
|
283
|
+
off += objectNormal * fl * wF * cs2WindFlutter.x * 0.022 * (0.6 + 0.4 * strength);
|
|
284
|
+
transformed += off;
|
|
285
|
+
}`;function Ht(a){let e=[];for(let[t,n]of Object.entries(a)){let r=n.value,o=r instanceof g.Texture?"sampler2D":r instanceof g.Matrix3?"mat3":r instanceof g.Color?"vec3":r instanceof g.Vector4?"vec4":r instanceof g.Vector3?"vec3":r instanceof g.Vector2?"vec2":"float";e.push(`uniform ${o} ${t};`)}return e.join(`
|
|
286
|
+
`)}function Ct(a,e){let t=`
|
|
287
|
+
varying vec2 vCs2Uv;
|
|
288
|
+
varying vec3 vCs2T;
|
|
289
|
+
varying vec3 vCs2B;
|
|
290
|
+
varying vec4 vCs2Blend;
|
|
291
|
+
#ifdef CS2_LIGHTMAP
|
|
292
|
+
varying vec2 vCs2Lm;
|
|
293
|
+
#endif
|
|
294
|
+
uniform sampler2D cs2Irradiance;
|
|
295
|
+
uniform sampler2D cs2Directional;
|
|
296
|
+
uniform sampler2D cs2SunShadow;
|
|
297
|
+
uniform float cs2LightmapScale;
|
|
298
|
+
uniform float cs2Directionality;
|
|
299
|
+
uniform float cs2EnvStrength;
|
|
300
|
+
uniform float cs2Debug;
|
|
301
|
+
uniform float cs2NormalFlipY;
|
|
302
|
+
varying vec3 vCs2WorldPos;
|
|
303
|
+
#ifdef CS2_ENVPROBES
|
|
304
|
+
${Dt}
|
|
305
|
+
#endif
|
|
306
|
+
${Ht(e).split(`
|
|
307
|
+
`).filter(o=>!/cs2Wind(Sway|Flutter)/.test(o)).join(`
|
|
308
|
+
`)}
|
|
309
|
+
|
|
310
|
+
vec4 cs2Sample(sampler2D t, mat3 m) { return texture2D(t, (m * vec3(vCs2Uv, 1.0)).xy); }
|
|
311
|
+
vec3 cs2DecodeNormal(vec4 t) {
|
|
312
|
+
vec3 n = t.xyz * 2.0 - 1.0;
|
|
313
|
+
n.y *= mix(1.0, -1.0, cs2NormalFlipY);
|
|
314
|
+
return normalize(vec3(n.xy, max(n.z, 0.001)));
|
|
315
|
+
}
|
|
316
|
+
float cs2Rough(float r, vec3 adj) {
|
|
317
|
+
if (adj.z >= 0.0) return adj.z;
|
|
318
|
+
return clamp(((r - 0.5) * adj.y + 0.5) * adj.x, 0.0, 1.0);
|
|
319
|
+
}
|
|
320
|
+
// Layer 2 coverage from vertex paint, shaped by the two height maps so the edge
|
|
321
|
+
// follows the texture (mortar lines, worn edges) instead of the triangle.
|
|
322
|
+
float cs2HeightBlend(float paint, float h1, float h2, float softness) {
|
|
323
|
+
float t = clamp(paint * 1.1 - 0.05, 0.0, 1.0);
|
|
324
|
+
float d = (h2 - h1) * 0.5 + (t * 2.0 - 1.0) * 0.75;
|
|
325
|
+
float s = clamp(softness, 0.02, 0.5);
|
|
326
|
+
return smoothstep(-s, s, d);
|
|
327
|
+
}
|
|
328
|
+
`,n=`
|
|
329
|
+
vec3 cs2Albedo = vec3(1.0);
|
|
330
|
+
float cs2Alpha = 1.0;
|
|
331
|
+
float cs2RoughV = 1.0;
|
|
332
|
+
float cs2MetalV = 0.0;
|
|
333
|
+
float cs2AO = 1.0;
|
|
334
|
+
vec3 cs2N = vec3(0.0, 0.0, 1.0);
|
|
335
|
+
vec3 cs2Emissive = vec3(0.0);
|
|
336
|
+
{
|
|
337
|
+
#ifdef CS2_COLOR1
|
|
338
|
+
vec4 c1 = cs2Sample(cs2Color1, cs2Uv1);
|
|
339
|
+
#else
|
|
340
|
+
vec4 c1 = cs2Color1Const;
|
|
341
|
+
#endif
|
|
342
|
+
#ifdef CS2_NORMAL1
|
|
343
|
+
vec4 n1 = cs2Sample(cs2Normal1, cs2Uv1);
|
|
344
|
+
#else
|
|
345
|
+
vec4 n1 = vec4(0.5, 0.5, 1.0, 1.0);
|
|
346
|
+
#endif
|
|
347
|
+
#ifdef CS2_HEIGHT1
|
|
348
|
+
vec4 h1 = cs2Sample(cs2Height1, cs2Uv1);
|
|
349
|
+
#else
|
|
350
|
+
vec4 h1 = vec4(0.5, 1.0, 1.0, 0.0);
|
|
351
|
+
#endif
|
|
352
|
+
vec3 vcol = vec3(1.0);
|
|
353
|
+
float valpha = 1.0;
|
|
354
|
+
#ifdef CS2_VCOLOR
|
|
355
|
+
vcol = vColor.rgb;
|
|
356
|
+
#ifdef USE_COLOR_ALPHA
|
|
357
|
+
valpha = vColor.a;
|
|
358
|
+
#endif
|
|
359
|
+
#endif
|
|
360
|
+
c1.rgb *= cs2Tint1;
|
|
361
|
+
#ifdef CS2_LAYERED
|
|
362
|
+
float vmask1 = cs2VColorMode.x > 1.5 ? 0.0 : (cs2VColorMode.x > 0.5 ? h1.g : 1.0);
|
|
363
|
+
#ifndef CS2_LAYER2
|
|
364
|
+
vmask1 = h1.g;
|
|
365
|
+
#endif
|
|
366
|
+
c1.rgb *= mix(vec3(1.0), vcol, vmask1);
|
|
367
|
+
float ao1 = c1.a;
|
|
368
|
+
c1.a = 1.0;
|
|
369
|
+
#else
|
|
370
|
+
float ao1 = 1.0;
|
|
371
|
+
#endif
|
|
372
|
+
float r1 = cs2Rough(n1.a, cs2Rough1);
|
|
373
|
+
float m1 = cs2Metal1 > 0.5 ? h1.a : 0.0;
|
|
374
|
+
vec3 N1 = cs2DecodeNormal(n1);
|
|
375
|
+
|
|
376
|
+
cs2Albedo = c1.rgb;
|
|
377
|
+
cs2Alpha = c1.a;
|
|
378
|
+
cs2RoughV = r1;
|
|
379
|
+
cs2MetalV = m1;
|
|
380
|
+
cs2AO = ao1;
|
|
381
|
+
cs2N = N1;
|
|
382
|
+
|
|
383
|
+
#ifdef CS2_LAYER2
|
|
384
|
+
#ifdef CS2_COLOR2
|
|
385
|
+
vec4 c2 = cs2Sample(cs2Color2, cs2Uv2);
|
|
386
|
+
#else
|
|
387
|
+
vec4 c2 = cs2Color2Const;
|
|
388
|
+
#endif
|
|
389
|
+
#ifdef CS2_NORMAL2
|
|
390
|
+
vec4 n2 = cs2Sample(cs2Normal2, cs2Uv2);
|
|
391
|
+
#else
|
|
392
|
+
vec4 n2 = vec4(0.5, 0.5, 1.0, 1.0);
|
|
393
|
+
#endif
|
|
394
|
+
c2.rgb *= cs2Tint2;
|
|
395
|
+
float w;
|
|
396
|
+
#ifdef CS2_TWOWAY
|
|
397
|
+
#ifdef CS2_MASK
|
|
398
|
+
float mk = cs2Sample(cs2Mask, cs2Uv2).r;
|
|
399
|
+
#else
|
|
400
|
+
float mk = 0.5;
|
|
401
|
+
#endif
|
|
402
|
+
w = cs2HeightBlend(vCs2Blend.x, 1.0 - mk, mk, vCs2Blend.w);
|
|
403
|
+
float ao2 = 1.0;
|
|
404
|
+
float m2 = cs2Metalness2.y;
|
|
405
|
+
cs2MetalV = cs2Metalness2.x;
|
|
406
|
+
c2.rgb *= vcol;
|
|
407
|
+
cs2Albedo *= vcol;
|
|
408
|
+
#else
|
|
409
|
+
#ifdef CS2_HEIGHT2
|
|
410
|
+
vec4 h2 = cs2Sample(cs2Height2, cs2Uv2);
|
|
411
|
+
#else
|
|
412
|
+
vec4 h2 = vec4(0.5, 1.0, 1.0, 0.0);
|
|
413
|
+
#endif
|
|
414
|
+
float vmask2 = cs2VColorMode.y > 1.5 ? 0.0 : (cs2VColorMode.y > 0.5 ? h2.g : 1.0);
|
|
415
|
+
c2.rgb *= mix(vec3(1.0), vcol, vmask2);
|
|
416
|
+
float ao2 = c2.a;
|
|
417
|
+
c2.a = 1.0;
|
|
418
|
+
float m2 = cs2Metal2 > 0.5 ? h2.a : 0.0;
|
|
419
|
+
float hh1 = (h1.r - cs2HeightAdj.y) * cs2HeightAdj.x;
|
|
420
|
+
float hh2 = (h2.r - cs2HeightAdj.w) * cs2HeightAdj.z;
|
|
421
|
+
w = cs2HeightBlend(vCs2Blend.x, hh1, hh2, cs2BlendSoftness + vCs2Blend.w * 0.25);
|
|
422
|
+
#endif
|
|
423
|
+
float r2 = cs2Rough(n2.a, cs2Rough2);
|
|
424
|
+
vec3 N2 = cs2DecodeNormal(n2);
|
|
425
|
+
cs2Albedo = mix(cs2Albedo, c2.rgb, w);
|
|
426
|
+
cs2RoughV = mix(cs2RoughV, r2, w);
|
|
427
|
+
cs2MetalV = mix(cs2MetalV, m2, w);
|
|
428
|
+
cs2AO = mix(cs2AO, ao2, w);
|
|
429
|
+
cs2N = normalize(mix(cs2N, N2, w));
|
|
430
|
+
#endif
|
|
431
|
+
|
|
432
|
+
#if !defined(CS2_LAYERED) && !defined(CS2_TWOWAY)
|
|
433
|
+
// Standard family: tint by vertex colour (prop tint), optionally masked.
|
|
434
|
+
#ifdef CS2_TINTMASK
|
|
435
|
+
float tm = cs2Sample(cs2TintMask, cs2Uv1).r;
|
|
436
|
+
cs2Albedo *= mix(vec3(1.0), vcol * cs2MatTint, tm);
|
|
437
|
+
#else
|
|
438
|
+
cs2Albedo *= vcol * cs2MatTint;
|
|
439
|
+
#endif
|
|
440
|
+
#ifdef CS2_AOTEX
|
|
441
|
+
cs2AO = cs2Sample(cs2AoTex, cs2Uv1).r;
|
|
442
|
+
#endif
|
|
443
|
+
#ifdef CS2_METALTEX
|
|
444
|
+
cs2MetalV = cs2Sample(cs2MetalTex, cs2Uv1).g;
|
|
445
|
+
#else
|
|
446
|
+
cs2MetalV = cs2Metalness;
|
|
447
|
+
#endif
|
|
448
|
+
#ifdef CS2_SELFILLUM
|
|
449
|
+
#ifdef CS2_SELFILLUM_MASK
|
|
450
|
+
float sim = cs2Sample(cs2SelfIllum, cs2Uv1).r;
|
|
451
|
+
#else
|
|
452
|
+
float sim = 1.0;
|
|
453
|
+
#endif
|
|
454
|
+
cs2Emissive = cs2Albedo * cs2SelfIllumTint * sim * cs2SelfIllumStrength;
|
|
455
|
+
#endif
|
|
456
|
+
#endif
|
|
457
|
+
#ifdef CS2_VCOLOR_ALPHA
|
|
458
|
+
cs2Alpha *= valpha;
|
|
459
|
+
#endif
|
|
460
|
+
}
|
|
461
|
+
#ifdef CS2_BLACK
|
|
462
|
+
cs2Albedo = vec3(0.0);
|
|
463
|
+
#endif
|
|
464
|
+
diffuseColor.rgb *= cs2Albedo;
|
|
465
|
+
diffuseColor.a *= cs2Alpha;
|
|
466
|
+
${"cs2Opacity"in e?"diffuseColor.a *= cs2Opacity;":""}
|
|
467
|
+
`;return a.replace("#include <common>",`#include <common>
|
|
468
|
+
${t}`).replace("#include <map_fragment>",n).replace("#include <color_fragment>","").replace("#include <roughnessmap_fragment>","float roughnessFactor = clamp(cs2RoughV, 0.04, 1.0);").replace("#include <metalnessmap_fragment>","float metalnessFactor = clamp(cs2MetalV, 0.0, 1.0);").replace("#include <normal_fragment_maps>",`{
|
|
469
|
+
vec3 T = normalize(vCs2T), B = normalize(vCs2B);
|
|
470
|
+
#ifdef DOUBLE_SIDED
|
|
471
|
+
T *= faceDirection; B *= faceDirection;
|
|
472
|
+
#endif
|
|
473
|
+
normal = normalize(mat3(T, B, normal) * cs2N);
|
|
474
|
+
}`).replace("#include <emissivemap_fragment>",`#include <emissivemap_fragment>
|
|
475
|
+
totalEmissiveRadiance += cs2Emissive;`).replace("#include <lights_fragment_begin>",`float cs2SunVis = 1.0;
|
|
476
|
+
#ifdef CS2_LIGHTMAP
|
|
477
|
+
cs2SunVis = 1.0 - texture2D(cs2SunShadow, vCs2Lm).r;
|
|
478
|
+
#endif
|
|
479
|
+
${Ke}`).replace("#include <lights_fragment_maps>",Mt).replace("#include <aomap_fragment>",`reflectedLight.indirectDiffuse *= cs2AO;
|
|
480
|
+
reflectedLight.indirectSpecular *= cs2AO * cs2SpecOcc;
|
|
481
|
+
#include <aomap_fragment>`).replace("#include <opaque_fragment>",`#include <opaque_fragment>
|
|
482
|
+
#ifdef CS2_UNLIT
|
|
483
|
+
gl_FragColor.rgb = diffuseColor.rgb;
|
|
484
|
+
#endif
|
|
485
|
+
#ifdef CS2_MOD2X
|
|
486
|
+
gl_FragColor = vec4(mix(vec3(0.5), cs2Albedo, diffuseColor.a), 1.0);
|
|
487
|
+
#endif
|
|
488
|
+
if (cs2Debug > 0.5) {
|
|
489
|
+
if (cs2Debug < 1.5) gl_FragColor.rgb = diffuseColor.rgb;
|
|
490
|
+
else if (cs2Debug < 2.5) gl_FragColor.rgb = (reflectedLight.directDiffuse + reflectedLight.indirectDiffuse) / max(diffuseColor.rgb, vec3(0.02));
|
|
491
|
+
else if (cs2Debug < 3.5) gl_FragColor.rgb = normal * 0.5 + 0.5;
|
|
492
|
+
#ifdef CS2_LIGHTMAP
|
|
493
|
+
else if (cs2Debug < 4.5) { vec2 g = floor(vCs2Lm * 256.0); gl_FragColor.rgb = vec3(mod(g.x + g.y, 2.0) * 0.5 + 0.25) * vec3(fract(vCs2Lm * 8.0), 1.0); }
|
|
494
|
+
else if (cs2Debug < 5.5) gl_FragColor.rgb = vec3(cs2SunVis);
|
|
495
|
+
#endif
|
|
496
|
+
else gl_FragColor.rgb = vec3(1.0, 0.0, 1.0);
|
|
497
|
+
}`)}var Ke=g.ShaderChunk.lights_fragment_begin.replace("getDirectionalLightInfo( directionalLight, directLight );",`getDirectionalLightInfo( directionalLight, directLight );
|
|
498
|
+
directLight.color *= cs2SunVis;`);Ke===g.ShaderChunk.lights_fragment_begin&&console.warn("cs2-replay: three.js light chunk changed; baked sun shadows are off");var Mt=`
|
|
499
|
+
float cs2SpecOcc = 1.0;
|
|
500
|
+
#if defined( RE_IndirectDiffuse )
|
|
501
|
+
#ifdef CS2_LIGHTMAP
|
|
502
|
+
{
|
|
503
|
+
vec3 cs2Irr = texture2D(cs2Irradiance, vCs2Lm).rgb;
|
|
504
|
+
vec4 cs2Ahd = texture2D(cs2Directional, vCs2Lm);
|
|
505
|
+
vec2 cs2Dxy = cs2Ahd.xy * 2.0 - 1.0;
|
|
506
|
+
float cs2Dz = sqrt(max(0.0, 1.0 - dot(cs2Dxy, cs2Dxy)));
|
|
507
|
+
vec3 cs2Ld = normalize(vec3(cs2Dxy, max(cs2Dz, 0.087)));
|
|
508
|
+
float cs2Flat = clamp(cs2Ahd.z, 0.0, 1.0);
|
|
509
|
+
float cs2Shaped = max(dot(cs2Ld, cs2N), 0.0) / max(cs2Ld.z, 0.05);
|
|
510
|
+
cs2Irr *= mix(1.0, cs2Flat + (1.0 - cs2Flat) * cs2Shaped, cs2Directionality);
|
|
511
|
+
cs2SpecOcc = mix(1.0, cs2Ahd.a, cs2Directionality);
|
|
512
|
+
irradiance = cs2Irr * cs2LightmapScale;
|
|
513
|
+
}
|
|
514
|
+
#elif defined( CS2_ENVPROBES ) && defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
515
|
+
{
|
|
516
|
+
// No lightmap (props, glass): diffuse from the local probe's roughest level.
|
|
517
|
+
float pw;
|
|
518
|
+
vec3 nW = inverseTransformDirection( geometryNormal, viewMatrix );
|
|
519
|
+
vec3 pe = cs2EnvProbe( vCs2WorldPos, nW, 1.0, pw );
|
|
520
|
+
iblIrradiance += PI * pe + getIBLIrradiance( geometryNormal ) * ( 1.0 - pw );
|
|
521
|
+
}
|
|
522
|
+
#elif defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
523
|
+
iblIrradiance += getIBLIrradiance( geometryNormal );
|
|
524
|
+
#endif
|
|
525
|
+
#endif
|
|
526
|
+
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
527
|
+
#ifdef CS2_ENVPROBES
|
|
528
|
+
{
|
|
529
|
+
// The map's own reflection probes, box-projected; the sky where none covers.
|
|
530
|
+
vec3 rv = reflect( - geometryViewDir, geometryNormal );
|
|
531
|
+
rv = normalize( mix( rv, geometryNormal, material.roughness * material.roughness ) );
|
|
532
|
+
vec3 rW = inverseTransformDirection( rv, viewMatrix );
|
|
533
|
+
float pw;
|
|
534
|
+
vec3 pr = cs2EnvProbe( vCs2WorldPos, rW, material.roughness, pw );
|
|
535
|
+
radiance += ( pr + getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ) * ( 1.0 - pw ) ) * cs2EnvStrength;
|
|
536
|
+
}
|
|
537
|
+
#else
|
|
538
|
+
radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ) * cs2EnvStrength;
|
|
539
|
+
#endif
|
|
540
|
+
#endif
|
|
541
|
+
`,Dt=`
|
|
542
|
+
uniform sampler2D cs2EnvAtlas;
|
|
543
|
+
uniform highp sampler2D cs2EnvVol;
|
|
544
|
+
uniform highp sampler3D cs2EnvGrid;
|
|
545
|
+
uniform vec3 cs2EnvGridOrigin;
|
|
546
|
+
uniform vec3 cs2EnvGridDims;
|
|
547
|
+
uniform float cs2EnvGridCell;
|
|
548
|
+
uniform vec4 cs2EnvAtlasInfo;
|
|
549
|
+
uniform float cs2EnvCols;
|
|
550
|
+
uniform vec3 cs2EnvLevels[6];
|
|
551
|
+
uniform float cs2EnvProbes;
|
|
552
|
+
vec2 cs2OctEncode(vec3 n) {
|
|
553
|
+
n /= abs(n.x) + abs(n.y) + abs(n.z);
|
|
554
|
+
vec2 p = n.xy;
|
|
555
|
+
if (n.z < 0.0) p = (1.0 - abs(n.yx)) * vec2(n.x >= 0.0 ? 1.0 : -1.0, n.y >= 0.0 ? 1.0 : -1.0);
|
|
556
|
+
return p * 0.5 + 0.5;
|
|
557
|
+
}
|
|
558
|
+
vec3 cs2EnvTap(vec2 tile, int level, vec2 uv) {
|
|
559
|
+
vec3 L = cs2EnvLevels[level];
|
|
560
|
+
return texture2D(cs2EnvAtlas, (tile + L.xy + 1.0 + uv * L.z) * cs2EnvAtlasInfo.xy).rgb;
|
|
561
|
+
}
|
|
562
|
+
vec3 cs2EnvProbe(vec3 wpos, vec3 wdir, float rough, out float wsum) {
|
|
563
|
+
wsum = 0.0;
|
|
564
|
+
vec3 acc = vec3(0.0);
|
|
565
|
+
if (cs2EnvProbes < 0.5) return acc;
|
|
566
|
+
vec3 g = (wpos - cs2EnvGridOrigin) / cs2EnvGridCell;
|
|
567
|
+
if (any(lessThan(g, vec3(0.0))) || any(greaterThanEqual(g, cs2EnvGridDims))) return acc;
|
|
568
|
+
vec4 cand = floor(texelFetch(cs2EnvGrid, ivec3(g), 0) * 255.0 + 0.5);
|
|
569
|
+
float lv = clamp(rough, 0.0, 1.0) * 5.0;
|
|
570
|
+
int l0 = int(floor(lv));
|
|
571
|
+
int l1 = min(l0 + 1, 5);
|
|
572
|
+
for (int k = 0; k < 4; k++) {
|
|
573
|
+
float id = cand[k];
|
|
574
|
+
if (id < 0.5) break;
|
|
575
|
+
int row = int(id) - 1;
|
|
576
|
+
vec4 m0 = texelFetch(cs2EnvVol, ivec2(0, row), 0);
|
|
577
|
+
vec4 m1 = texelFetch(cs2EnvVol, ivec2(1, row), 0);
|
|
578
|
+
vec4 m2 = texelFetch(cs2EnvVol, ivec2(2, row), 0);
|
|
579
|
+
vec4 bmin = texelFetch(cs2EnvVol, ivec2(3, row), 0);
|
|
580
|
+
vec4 bmax = texelFetch(cs2EnvVol, ivec2(4, row), 0);
|
|
581
|
+
vec4 fade = texelFetch(cs2EnvVol, ivec2(5, row), 0);
|
|
582
|
+
vec3 lp = vec3(dot(m0.xyz, wpos) + m0.w, dot(m1.xyz, wpos) + m1.w, dot(m2.xyz, wpos) + m2.w);
|
|
583
|
+
vec3 dd = min(lp - bmin.xyz, bmax.xyz - lp);
|
|
584
|
+
if (min(min(dd.x, dd.y), dd.z) < 0.0) continue;
|
|
585
|
+
vec3 fw = vec3(fade.x > 0.0 ? clamp(dd.x / fade.x, 0.0, 1.0) : 1.0, fade.y > 0.0 ? clamp(dd.y / fade.y, 0.0, 1.0) : 1.0, fade.z > 0.0 ? clamp(dd.z / fade.z, 0.0, 1.0) : 1.0);
|
|
586
|
+
float w = fw.x * fw.y * fw.z;
|
|
587
|
+
// Box projection: where the reflected ray leaves the box, seen from the capture point.
|
|
588
|
+
vec3 ld = normalize(vec3(dot(m0.xyz, wdir), dot(m1.xyz, wdir), dot(m2.xyz, wdir)));
|
|
589
|
+
vec3 tf = max((bmax.xyz - lp) / ld, (bmin.xyz - lp) / ld);
|
|
590
|
+
vec3 dir = lp + ld * min(min(tf.x, tf.y), tf.z);
|
|
591
|
+
vec2 uv = cs2OctEncode(normalize(dir));
|
|
592
|
+
vec2 tile = vec2(mod(bmin.w, cs2EnvCols), floor(bmin.w / cs2EnvCols + 0.001)) * cs2EnvAtlasInfo.zw;
|
|
593
|
+
vec3 c = mix(cs2EnvTap(tile, l0, uv), cs2EnvTap(tile, l1, uv), lv - float(l0));
|
|
594
|
+
float take = w * (1.0 - wsum);
|
|
595
|
+
acc += c * take;
|
|
596
|
+
wsum += take;
|
|
597
|
+
if (wsum > 0.995) break;
|
|
598
|
+
}
|
|
599
|
+
return acc;
|
|
600
|
+
}
|
|
601
|
+
`;import*as P from"three";import{MeshoptDecoder as Lt}from"three/addons/libs/meshopt_decoder.module.js";function At(){this.array=null}var pe=a=>a.isInterleavedBufferAttribute?a.data:a;function Ze(a,e){let t=new Set,n=new Set;for(let r of a){let o=r.geometry;o.boundingBox||o.computeBoundingBox(),o.boundingSphere||o.computeBoundingSphere();for(let s of Object.values(o.attributes))t.add(pe(s));o.index&&t.add(o.index),e?.(r)&&(o.attributes.position&&n.add(pe(o.attributes.position)),o.index&&n.add(o.index))}for(let r of t)n.has(r)||r.onUpload(At)}async function Je(a,e,t=24e6){let n=[];e.traverse(m=>m.isMesh&&n.push(m));let r=new Set,o=m=>{let l=0,b=m.geometry;for(let d of[...Object.values(b.attributes),b.index]){let f=d&&pe(d).array;!f||r.has(f)||(r.add(f),l+=f.byteLength??0)}return l},s=[[]],u=0;for(let m of n){let l=o(m);u>0&&u+l>t&&(s.push([]),u=0),s[s.length-1].push(m),u+=l}for(let m=0;m<s.length;m++)m>0&&await new Promise(l=>setTimeout(l,0)),Ft(a,e,new Set(s[m]))}function Ft(a,e,t){let n=e.parent,r=new P.Scene;r.overrideMaterial=new P.MeshBasicMaterial({colorWrite:!1,depthWrite:!1,depthTest:!1}),r.add(e);let o=[];e.traverse(m=>{let l=m;if(!l.isMesh)return;let{frustumCulled:b,visible:d}=l,{count:f}=l.geometry.drawRange,v=(Array.isArray(l.material)?l.material:[l.material]).map(E=>[E,E.allowOverride]);l.visible=t.has(l),l.frustumCulled=!1,l.geometry.drawRange.count=0;for(let[E]of v)E.allowOverride=!0;o.push(()=>{l.visible=d,l.frustumCulled=b,l.geometry.drawRange.count=f;for(let[E,w]of v)E.allowOverride=w})});let s=new P.WebGLRenderTarget(1,1,{depthBuffer:!1}),u=a.getRenderTarget();try{a.setRenderTarget(s),a.render(r,new P.PerspectiveCamera)}finally{a.setRenderTarget(u),o.forEach(m=>m()),r.remove(e),n?.add(e),s.dispose(),r.overrideMaterial.dispose()}}function et(a){let e=a.onUpdate;a.onUpdate=t=>{e?.(t),a.onUpdate=e,ve(a)}}function ve(a){if(a.isCompressedTexture){a.mipmaps=[];return}let e=a.image;if(e){if("data"in e)e.data=null;else if(typeof ImageBitmap<"u"&&e instanceof ImageBitmap){let{width:t,height:n}=e;e.close(),a.image={width:t,height:n}}}}var Ye=0;async function tt(a){Ye++===0&&Qe(1);try{return await a()}finally{--Ye===0&&Qe(0)}}function Qe(a){try{Lt.useWorkers(a)}catch{}}var _t={color:[200,200,200,255],normal:[128,128,255,200],linear:[128,255,255,0]};async function rt(a,e,t={}){let n=t.store??null,o=/\.json([?#]|$)/i.test(a)?await Fe(a,n):null,s=new URL(o?.url??a,location.href),u=null,m=null,l=0,b=0;if(o){u=It(o,t.tier??"low");let i=e.extensions.has("EXT_texture_compression_bptc")&&e.extensions.has("WEBGL_compressed_texture_s3tc");m=t.lightmaps==="compat"||!i?"compat":"bc",t.lightmaps==="bc"&&!i&&console.warn("cs2-replay: this GPU has no BC6H/BC7/BC1 support; using the compat lightmaps"),l=Ue(o,u,m).reduce((h,x)=>h+x.bytes,0)}let d=(i,h,x)=>t.onProgress?.({phase:i,loaded:h,total:x}),f=async(i,h)=>{let x=o?S=>{b+=S,d(h,Math.min(b,l),l)}:void 0;if(n)return n.fetch(i,x);let C=await fetch(i);if(!C.ok)throw new Error(`${C.status} ${i}`);return ke(C,x)},v=new Ut().setMeshoptDecoder(Bt),E=(await tt(async()=>{if(!o)return v.loadAsync(a,h=>d("geometry",h.loaded,h.total));let i=new URL(o.geometry.file,s).href;return v.parseAsync(await f(i,"geometry"),i.slice(0,i.lastIndexOf("/")+1))})).scene,w=t.keepCpuCopies!==!0,L=i=>{w&&et(i),e.initTexture(i)},M=E.userData.cs2??{version:0,lightmaps:{}},y=qe(),k=[],V=o&&u?o.tiers[u]:null,j=new Map;V?.textures.forEach(([i,h],x)=>j.set(i,{url:new URL(`${o.textureBase}${h}.ktx2`,s).href,order:x}));let it=t.ktx2!==!1||!!o,$=null;it&&($=new kt().setTranscoderPath(t.transcoderPath??`https://cdn.jsdelivr.net/npm/three@0.${c.REVISION}.0/examples/jsm/libs/basis/`).detectSupport(e));let Te=()=>{$?.dispose(),$=null},I=!1,be,xe=new Promise((i,h)=>be=h);xe.catch(()=>{});let Q=i=>Promise.race([i,xe]),lt=Ot(4),ct=Math.min(8,e.capabilities.getMaxAnisotropy()),q=new Map,Re=new Map,ut=(i,h,x)=>{let C=o?i?.tex:i?.uri;if(!C||o&&!j.has(C))return null;let S=x==="normal"?"normal":h,H=`${C}|${S}`,D=q.get(H);if(!D){let B=_t[S],A=new c.DataTexture(new Uint8Array(B),1,1);A.colorSpace=S==="color"?c.SRGBColorSpace:c.NoColorSpace,A.needsUpdate=!0,D={key:H,slot:i,kind:S,placeholder:A,users:[]},q.set(H,D),Re.set(A,D)}return D.placeholder},we=0,ye=0,Se=[];E.traverse(i=>{if(i.isLight)return;let x=i;if(!x.isMesh)return;Se.push(x);let C=x.material,S=C.userData?.cs2;C.dispose();let H=x.geometry;if(ye++,we+=(H.index?H.index.count:H.attributes.position.count)/3,!S){x.material=new c.MeshStandardMaterial({color:8421504});return}let B=Xe(S,y,(A,ee)=>ut(A,ee,Gt(S,A)?"normal":void 0),{hasColor:!!H.attributes.color,hasBlend:!!H.attributes._blend,hasUv2:!!H.attributes.uv2,envProbes:!!M.reflections});for(let A of Object.values(B.userData.cs2Uniforms)){let ee=A.value instanceof c.Texture?Re.get(A.value):void 0;ee&&ee.users.push(A)}x.material=B,x.receiveShadow=!0,x.castShadow=t.worldShadows===!0&&!B.transparent&&!(B.alphaTest>0)&&!S.decal&&S.family!=="unlit",x.matrixAutoUpdate=!1,x.updateMatrix(),B.transparent&&(x.renderOrder=S.decal||S.mod2x?1:2)});for(let i of E.children.filter(h=>h.isLight))i.removeFromParent();w&&Ze(Se,t.keepPositions?ze:null),await Je(e,E);let mt=async i=>{let h=$&&(o||i.slot.ktx2)?$:null,x;if(h){let C=o?j.get(i.slot.tex).url:new URL(i.slot.ktx2,s).href,S=await Q(f(C,"textures"));x=await Q(new Promise((H,D)=>h.parse(S,H,D)))}else x=await Q(f(new URL(i.slot.uri,s).href,"textures").then(Ee)),x.colorSpace=i.kind==="color"?c.SRGBColorSpace:c.NoColorSpace,x.generateMipmaps=!0,x.minFilter=c.LinearMipmapLinearFilter;if(I)return x.dispose();x.wrapS=x.wrapT=c.RepeatWrapping,x.anisotropy=ct,x.needsUpdate=!0,await Q(lt(()=>{if(I)return x.dispose();i.texture=x;for(let C of i.users)C.value=x;i.placeholder.dispose(),L(x)}))},le=[...q.values()];o&&le.sort((i,h)=>j.get(i.slot.tex).order-j.get(h.slot.tex).order);let He=0,Ce=()=>Pt(le,t.concurrency??12,async i=>{if(!I){try{await mt(i)}catch(h){I||console.warn(`cs2-replay: texture ${i.slot.tex??i.slot.uri}: ${h}`)}He++,!o&&!I&&d("textures",He,le.length)}}),Me=()=>{if(!I){I=!0,be(new Error("disposed")),Te(),E.traverse(i=>{let h=i;h.isMesh&&(h.geometry.dispose(),h.material.dispose())});for(let i of q.values())i.texture?.dispose(),i.placeholder.dispose();k.forEach(i=>i.dispose())}},De=i=>{throw Me(),i},G=[],Z=i=>h=>{y[i].value=h,k.push(h),L(h)};if(o&&V&&m){let i=m==="bc"?o.lightmaps.bc[V.lightmaps]:o.lightmaps.compat,h=async(C,S)=>{if(!C)return;let H=await f(new URL(C.file,s).href,"lightmaps");Z(S)(await Vt(H,C))},x=(C,S)=>C.catch(H=>console.warn(`cs2-replay: ${S}: ${H}`));G.push(x(h(i?.irradiance,"cs2Irradiance"),"irradiance"),x(h(i?.sunShadow,"cs2SunShadow"),"sun shadow"),x(h(i?.directional,"cs2Directional"),"directional lightmap"))}else{let i=M.lightmaps??{};if(i.irradiance){let h=i.irradiance;G.push(f(new URL(h.uri,s).href,"lightmaps").then(async x=>Z("cs2Irradiance")(await ae(x,h.width,h.height,h.uri))))}if(i.sunShadow){let h=i.sunShadow;G.push(f(new URL(h.uri,s).href,"lightmaps").then(async x=>Z("cs2SunShadow")(await nt(x,h.width,h.height,h.uri))))}if(i.directional){let h=i.directional;G.push(f(new URL(h.uri,s).href,"lightmaps").then(async x=>Z("cs2Directional")(at(await Ee(x)))))}}y.cs2Irradiance.value=X([.25,.25,.25],c.FloatType),y.cs2SunShadow.value=X([0,0,0,0]),y.cs2Directional.value=X([128,128,255,255]);let J=null;if(M.sky){let i=M.sky;J=zt(await f(new URL(i.uri,s).href,"lightmaps").then(h=>ae(h,i.width,i.height,i.uri)).catch(De)),J.mapping=c.EquirectangularReflectionMapping,k.push(J)}if(M.reflections){let i=M.reflections;G.push((async()=>{let[h,x,C]=await Promise.all([f(new URL(i.atlas.uri,s).href,"lightmaps"),f(new URL(i.volumes.uri,s).href,"lightmaps").then(K),f(new URL(i.grid.uri,s).href,"lightmaps").then(K)]),S=await ae(h,i.atlas.width,i.atlas.height,i.atlas.uri),H=new c.DataTexture(new Float32Array(x),i.volumes.stride/4,i.volumes.count,c.RGBAFormat,c.FloatType);H.minFilter=H.magFilter=c.NearestFilter,H.needsUpdate=!0;let D=new c.Data3DTexture(new Uint8Array(C),...i.grid.dims);D.minFilter=D.magFilter=c.NearestFilter,D.unpackAlignment=1,D.needsUpdate=!0,y.cs2EnvAtlas.value=S,y.cs2EnvVol.value=H,y.cs2EnvGrid.value=D,y.cs2EnvGridOrigin.value.fromArray(i.grid.origin),y.cs2EnvGridDims.value.fromArray(i.grid.dims),y.cs2EnvGridCell.value=i.grid.cell,y.cs2EnvAtlasInfo.value.set(1/i.atlas.width,1/i.atlas.height,i.atlas.tile[0],i.atlas.tile[1]),y.cs2EnvCols.value=i.atlas.cols,i.atlas.levels.forEach((B,A)=>y.cs2EnvLevels.value[A]?.fromArray(B)),y.cs2EnvProbes.value=1,k.push(S,H,D),[S,H,D].forEach(L)})().catch(h=>console.warn(`cs2-replay: reflections: ${h}`)))}y.cs2EnvAtlas.value=X([0,0,0,255]),y.cs2EnvVol.value=X([0,0,0,0],c.FloatType);{let i=new c.Data3DTexture(new Uint8Array(4),1,1,1);i.needsUpdate=!0,y.cs2EnvGrid.value=i}M.wind&&y.cs2Wind.value.set(M.wind.direction[0],M.wind.direction[2],1,0);let Le=null;if(M.probes){let i=M.probes;G.push(f(new URL(i.uri,s).href,"lightmaps").then(h=>{Le=je(h,i.step,i.bounds)},h=>console.warn(`cs2-replay: probes: ${h}`)))}let ft=(o?Promise.all(G).then(Ce):Ce()).finally(Te);await Promise.all(G).catch(De);let Ae=M.sun,dt=new c.Vector3(...Ae?.direction??[.4,.8,.3]).normalize(),ht=new c.Color().setRGB(...Ae?.color??[2.5,2.2,1.9],c.LinearSRGBColorSpace);return{root:E,env:M,uniforms:y,sunDirection:dt,sunColor:ht,sky:J,probes:Le,textures:ft,stats:{drawCalls:ye,triangles:Math.round(we),textures:q.size},manifest:o,tier:u,lightmapMode:m,bytes:l,dispose:Me}}function Gt(a,e){return e?a.layers?.some(t=>t.normal===e)??!1:!1}function Ot(a){let e=[],t=!1,n=()=>{t=!1;let o=performance.now()+a,s=0;for(;s<e.length&&(s===0||performance.now()<o);)e[s++]();e.splice(0,s),e.length&&r()},r=()=>{t||(t=!0,setTimeout(n,0))};return o=>new Promise((s,u)=>{e.push(()=>{try{o(),s()}catch(m){u(m)}}),r()})}async function Pt(a,e,t){let n=0;await Promise.all(Array.from({length:Math.min(e,a.length)},async()=>{for(;n<a.length;)await t(a[n++])}))}function It(a,e){if(a.tiers[e])return e;let t=W.indexOf(e),n=[...W].filter(r=>a.tiers[r]).sort((r,o)=>Math.abs(W.indexOf(r)-t)-Math.abs(W.indexOf(o)-t)||W.indexOf(r)-W.indexOf(o));if(!n.length)throw new Error(`${a.map}: the manifest has no tiers`);return n[0]}async function Ee(a){let e=await createImageBitmap(new Blob([a]),{premultiplyAlpha:"none",colorSpaceConversion:"none",imageOrientation:"from-image"}),t=new c.Texture(e);return t.flipY=!1,t.needsUpdate=!0,t}function at(a){return a.colorSpace=c.NoColorSpace,a.generateMipmaps=!1,a.minFilter=c.LinearFilter,a.needsUpdate=!0,a}async function nt(a,e,t,n){let r;if(n.endsWith(".png")){let s=await createImageBitmap(new Blob([a]),{premultiplyAlpha:"none",colorSpaceConversion:"none"}),m=new OffscreenCanvas(s.width,s.height).getContext("2d",{willReadFrequently:!0});m.drawImage(s,0,0);let l=m.getImageData(0,0,s.width,s.height).data;r=new Uint8Array(s.width*s.height);for(let b=0;b<r.length;b++)r[b]=l[b*4];e=s.width,t=s.height,s.close()}else if(r=new Uint8Array(await K(a)),r.length!==e*t)throw new Error(`${n}: expected ${e}x${t} texels, got ${r.length}`);let o=new c.DataTexture(r,e,t,c.RedFormat,c.UnsignedByteType);return o.minFilter=c.LinearFilter,o.magFilter=c.LinearFilter,o.generateMipmaps=!1,o.unpackAlignment=1,o.needsUpdate=!0,o}async function K(a){let e=new Uint8Array(a,0,Math.min(2,a.byteLength));return e[0]===31&&e[1]===139?new Response(new Blob([a]).stream().pipeThrough(new DecompressionStream("gzip"))).arrayBuffer():a}var Wt={bc6h:{format:c.RGB_BPTC_UNSIGNED_Format,block:16},bc7:{format:c.RGBA_BPTC_Format,block:16},bc1:{format:c.RGB_S3TC_DXT1_Format,block:8}};async function Vt(a,e){if(e.format==="rgb9e5")return ae(a,e.width,e.height,e.file);if(e.format==="r8")return nt(a,e.width,e.height,e.file);if(e.format==="png")return at(await Ee(a));let{format:t,block:n}=Wt[e.format],r=new Uint8Array(await K(a)),o=Math.ceil(e.width/4)*Math.ceil(e.height/4)*n;if(r.length!==o)throw new Error(`${e.file}: expected ${o} bytes of ${e.format}, got ${r.length}`);let s=new c.CompressedTexture([{data:r,width:e.width,height:e.height}],e.width,e.height,t,e.format==="bc6h"?c.HalfFloatType:c.UnsignedByteType);return s.colorSpace=e.format==="bc6h"?c.LinearSRGBColorSpace:c.NoColorSpace,s.minFilter=c.LinearFilter,s.magFilter=c.LinearFilter,s.generateMipmaps=!1,s.flipY=!1,s.needsUpdate=!0,s}async function ae(a,e,t,n){let r=new Uint32Array(await K(a));if(r.length!==e*t)throw new Error(`${n}: expected ${e}x${t} texels, got ${r.length}`);let o=new c.DataTexture(r,e,t,c.RGBFormat,c.UnsignedInt5999Type);return o.colorSpace=c.LinearSRGBColorSpace,o.minFilter=c.LinearFilter,o.magFilter=c.LinearFilter,o.generateMipmaps=!1,o.flipY=!1,o.needsUpdate=!0,o}function zt(a){let{width:e,height:t}=a.image,n=a.image.data,r=new Uint16Array(e*t*4),o=c.DataUtils.toHalfFloat(1);for(let u=0;u<n.length;u++){let m=n[u],l=Math.pow(2,(m>>>27)-15-9);r[u*4]=c.DataUtils.toHalfFloat((m&511)*l),r[u*4+1]=c.DataUtils.toHalfFloat((m>>>9&511)*l),r[u*4+2]=c.DataUtils.toHalfFloat((m>>>18&511)*l),r[u*4+3]=o}a.dispose();let s=new c.DataTexture(r,e,t,c.RGBAFormat,c.HalfFloatType);return s.colorSpace=c.LinearSRGBColorSpace,s.minFilter=c.LinearFilter,s.magFilter=c.LinearFilter,s.generateMipmaps=!1,s.needsUpdate=!0,s}function X(a,e=c.UnsignedByteType){let t=e===c.FloatType?new c.DataTexture(new Float32Array([a[0],a[1],a[2],1]),1,1,c.RGBAFormat,c.FloatType):new c.DataTexture(new Uint8Array([a[0],a[1],a[2],a[3]??255]),1,1);return t.needsUpdate=!0,t}import*as R from"three";import{FullScreenQuad as Nt,Pass as jt}from"three/addons/postprocessing/Pass.js";var ge={tonemap:{exposureBias:0,shoulderStrength:0,linearStrength:.001,linearAngle:.001,toeStrength:1,toeNum:1,toeDenom:1,whitePoint:1.5},exposure:{min:.8,max:1.2,speedUp:1,speedDown:1,compensation:0},bloom:{screenStrength:.1261,addStrength:0,threshold:1.055,thresholdWidth:1.661,weights:[.151085,.151085,.151085,.151085,.395662],tints:[[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]]}},ot=.2,ne=5,N="varying vec2 vUv; void main() { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }";function Y(a,e,t={}){return new R.WebGLRenderTarget(Math.max(1,a),Math.max(1,e),{type:R.HalfFloatType,depthBuffer:!1,minFilter:R.LinearFilter,magFilter:R.LinearFilter,...t})}var oe=class extends jt{settings;fixedDelta=null;exposureOverride=null;quad=new Nt;lum;adapt;bright=[];blurTmp=[];lumMat;adaptMat;brightMat;downMat;blurMat;finalMat;first=!0;last=0;constructor(e,t,n=ge){super(),this.settings=n,this.lum=Y(128,128,{generateMipmaps:!0,minFilter:R.LinearMipmapLinearFilter,format:R.RGFormat}),this.adapt=[Y(1,1,{minFilter:R.NearestFilter,magFilter:R.NearestFilter,format:R.RedFormat}),Y(1,1,{minFilter:R.NearestFilter,magFilter:R.NearestFilter,format:R.RedFormat})];for(let r=0;r<ne;r++)this.bright.push(Y(1,1)),this.blurTmp.push(Y(1,1));this.lumMat=new R.ShaderMaterial({uniforms:{tColor:{value:null}},vertexShader:N,fragmentShader:`
|
|
602
|
+
varying vec2 vUv; uniform sampler2D tColor;
|
|
603
|
+
void main() {
|
|
604
|
+
vec3 c = texture2D(tColor, vUv).rgb;
|
|
605
|
+
float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
|
|
606
|
+
// Centre-weighted: what the player looks at counts most.
|
|
607
|
+
vec2 d = vUv - 0.5;
|
|
608
|
+
float w = 1.0 - 0.6 * smoothstep(0.1, 0.6, length(d));
|
|
609
|
+
gl_FragColor = vec4(log(max(l, 1e-4)) * w, w, 0.0, 1.0);
|
|
610
|
+
}`}),this.adaptMat=new R.ShaderMaterial({uniforms:{tLum:{value:null},tPrev:{value:null},uKey:{value:ot},uRange:{value:new R.Vector2},uRate:{value:new R.Vector2},uFirst:{value:1},uOverride:{value:-1}},vertexShader:N,fragmentShader:`
|
|
611
|
+
varying vec2 vUv; uniform sampler2D tLum; uniform sampler2D tPrev; uniform float uKey; uniform vec2 uRange; uniform vec2 uRate; uniform float uFirst; uniform float uOverride;
|
|
612
|
+
void main() {
|
|
613
|
+
vec2 m = textureLod(tLum, vec2(0.5), 10.0).rg; // weighted log-luminance, weight
|
|
614
|
+
float avg = exp(m.r / max(m.g, 1e-4));
|
|
615
|
+
float target = clamp(uKey / max(avg, 1e-4), uRange.x, uRange.y);
|
|
616
|
+
if (uOverride > 0.0) target = uOverride;
|
|
617
|
+
float prev = texture2D(tPrev, vec2(0.5)).r;
|
|
618
|
+
float k = target > prev ? uRate.x : uRate.y; // brightening vs darkening
|
|
619
|
+
float e = uFirst > 0.5 || uOverride > 0.0 ? target : mix(prev, target, k);
|
|
620
|
+
gl_FragColor = vec4(e, 0.0, 0.0, 1.0);
|
|
621
|
+
}`}),this.brightMat=new R.ShaderMaterial({uniforms:{tColor:{value:null},tExposure:{value:null},uThreshold:{value:new R.Vector2}},vertexShader:N,fragmentShader:`
|
|
622
|
+
varying vec2 vUv; uniform sampler2D tColor; uniform sampler2D tExposure; uniform vec2 uThreshold;
|
|
623
|
+
void main() {
|
|
624
|
+
float e = texture2D(tExposure, vec2(0.5)).r;
|
|
625
|
+
vec3 c = texture2D(tColor, vUv).rgb * e;
|
|
626
|
+
float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
|
|
627
|
+
float w = smoothstep(uThreshold.x, uThreshold.x + uThreshold.y, l);
|
|
628
|
+
gl_FragColor = vec4(min(c * w, vec3(64.0)), 1.0);
|
|
629
|
+
}`}),this.downMat=new R.ShaderMaterial({uniforms:{tColor:{value:null},uTexel:{value:new R.Vector2}},vertexShader:N,fragmentShader:`
|
|
630
|
+
varying vec2 vUv; uniform sampler2D tColor; uniform vec2 uTexel;
|
|
631
|
+
void main() {
|
|
632
|
+
vec3 c = texture2D(tColor, vUv + uTexel * vec2(-1.0, -1.0)).rgb + texture2D(tColor, vUv + uTexel * vec2(1.0, -1.0)).rgb
|
|
633
|
+
+ texture2D(tColor, vUv + uTexel * vec2(-1.0, 1.0)).rgb + texture2D(tColor, vUv + uTexel * vec2(1.0, 1.0)).rgb;
|
|
634
|
+
gl_FragColor = vec4(c * 0.25, 1.0);
|
|
635
|
+
}`}),this.blurMat=new R.ShaderMaterial({uniforms:{tColor:{value:null},uDir:{value:new R.Vector2}},vertexShader:N,fragmentShader:`
|
|
636
|
+
varying vec2 vUv; uniform sampler2D tColor; uniform vec2 uDir;
|
|
637
|
+
void main() {
|
|
638
|
+
// 9-tap Gaussian (sigma ~2 texels) with linear-sampling offsets.
|
|
639
|
+
vec3 c = texture2D(tColor, vUv).rgb * 0.2270270270;
|
|
640
|
+
c += (texture2D(tColor, vUv + uDir * 1.3846153846).rgb + texture2D(tColor, vUv - uDir * 1.3846153846).rgb) * 0.3162162162;
|
|
641
|
+
c += (texture2D(tColor, vUv + uDir * 3.2307692308).rgb + texture2D(tColor, vUv - uDir * 3.2307692308).rgb) * 0.0702702703;
|
|
642
|
+
gl_FragColor = vec4(c, 1.0);
|
|
643
|
+
}`}),this.finalMat=new R.ShaderMaterial({uniforms:{tColor:{value:null},tExposure:{value:null},tBloom0:{value:null},tBloom1:{value:null},tBloom2:{value:null},tBloom3:{value:null},tBloom4:{value:null},uWeights:{value:[]},uABC:{value:new R.Vector3},uDEF:{value:new R.Vector3},uWhite:{value:1.5},uBias:{value:1},uScreen:{value:0},uAdd:{value:0}},vertexShader:N,fragmentShader:`
|
|
644
|
+
varying vec2 vUv;
|
|
645
|
+
uniform sampler2D tColor, tExposure, tBloom0, tBloom1, tBloom2, tBloom3, tBloom4;
|
|
646
|
+
uniform vec3 uWeights[5];
|
|
647
|
+
uniform vec3 uABC, uDEF;
|
|
648
|
+
uniform float uWhite, uBias, uScreen, uAdd;
|
|
649
|
+
// Source 2 filmic: F(x) = (x(Ax + CB) + DE) / (x(Ax + B) + DF) - E/F, in a form that
|
|
650
|
+
// doesn't cancel catastrophically (the DE\xB7F terms drop out).
|
|
651
|
+
vec3 filmic(vec3 x) {
|
|
652
|
+
float A = uABC.x, B = uABC.y, C = uABC.z, D = uDEF.x, E = uDEF.y, F = uDEF.z;
|
|
653
|
+
return x * (A * x * (F - E) + B * (C * F - E)) / (F * (x * (A * x + B) + D * F));
|
|
654
|
+
}
|
|
655
|
+
vec3 tonemap(vec3 x) { return clamp(filmic(x) / filmic(vec3(uWhite)), 0.0, 1.0); }
|
|
656
|
+
vec3 toSRGB(vec3 c) { return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, c)); }
|
|
657
|
+
void main() {
|
|
658
|
+
float e = texture2D(tExposure, vec2(0.5)).r * uBias;
|
|
659
|
+
vec3 hdr = texture2D(tColor, vUv).rgb * e;
|
|
660
|
+
vec3 b = texture2D(tBloom0, vUv).rgb * uWeights[0] + texture2D(tBloom1, vUv).rgb * uWeights[1] + texture2D(tBloom2, vUv).rgb * uWeights[2]
|
|
661
|
+
+ texture2D(tBloom3, vUv).rgb * uWeights[3] + texture2D(tBloom4, vUv).rgb * uWeights[4];
|
|
662
|
+
vec3 c = tonemap(hdr + b * uAdd);
|
|
663
|
+
vec3 bl = tonemap(b) * uScreen;
|
|
664
|
+
c = 1.0 - (1.0 - c) * (1.0 - bl); // screen blend
|
|
665
|
+
c = toSRGB(clamp(c, 0.0, 1.0));
|
|
666
|
+
// Dither away banding in the sky and smoke.
|
|
667
|
+
float n = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715))));
|
|
668
|
+
gl_FragColor = vec4(c + (n - 0.5) / 255.0, 1.0);
|
|
669
|
+
}`}),this.setSize(e,t)}setSize(e,t){let n=e,r=t;for(let o=0;o<ne;o++)n=Math.max(1,Math.round(n/2)),r=Math.max(1,Math.round(r/2)),this.bright[o].setSize(n,r),this.blurTmp[o].setSize(n,r)}draw(e,t,n){this.quad.material=t,e.setRenderTarget(n),this.quad.render(e)}render(e,t,n){this.renderTexture(e,n.texture,this.renderToScreen?null:t)}renderTexture(e,t,n){let r=this.settings,o=performance.now()/1e3,s=this.fixedDelta??Math.min(.25,Math.max(0,this.last?o-this.last:0));this.last=o,this.lumMat.uniforms.tColor.value=t,this.draw(e,this.lumMat,this.lum);let[u,m]=this.adapt,l=this.adaptMat.uniforms;l.tLum.value=this.lum.texture,l.tPrev.value=u.texture,l.uRange.value.set(r.exposure.min,r.exposure.max),l.uKey.value=ot*Math.pow(2,r.exposure.compensation),l.uRate.value.set(1-Math.exp(-s*r.exposure.speedUp*1.5),1-Math.exp(-s*r.exposure.speedDown*1.5)),l.uFirst.value=this.first?1:0,l.uOverride.value=this.exposureOverride??-1,this.draw(e,this.adaptMat,m),this.adapt=[m,u],this.first=!1;let b=m.texture,d=this.brightMat.uniforms;d.tColor.value=t,d.tExposure.value=b,d.uThreshold.value.set(r.bloom.threshold,r.bloom.thresholdWidth),this.draw(e,this.brightMat,this.bright[0]);for(let E=0;E<ne;E++){E>0&&(this.downMat.uniforms.tColor.value=this.bright[E-1].texture,this.downMat.uniforms.uTexel.value.set(.5/this.bright[E-1].width,.5/this.bright[E-1].height),this.draw(e,this.downMat,this.bright[E]));let w=this.blurMat.uniforms;w.tColor.value=this.bright[E].texture,w.uDir.value.set(1/this.bright[E].width,0),this.draw(e,this.blurMat,this.blurTmp[E]),w.tColor.value=this.blurTmp[E].texture,w.uDir.value.set(0,1/this.bright[E].height),this.draw(e,this.blurMat,this.bright[E])}let f=this.finalMat.uniforms;f.tColor.value=t,f.tExposure.value=b;for(let E=0;E<ne;E++)f[`tBloom${E}`].value=this.bright[E].texture;f.uWeights.value=r.bloom.weights.map((E,w)=>new R.Vector3(...r.bloom.tints[w]??[1,1,1]).multiplyScalar(E));let v=r.tonemap;f.uABC.value.set(v.shoulderStrength,v.linearStrength,v.linearAngle),f.uDEF.value.set(v.toeStrength,v.toeNum,v.toeDenom),f.uWhite.value=v.whitePoint,f.uBias.value=Math.pow(2,v.exposureBias),f.uScreen.value=r.bloom.screenStrength,f.uAdd.value=r.bloom.addStrength,this.draw(e,this.finalMat,n)}dispose(){for(let e of[this.lum,...this.adapt,...this.bright,...this.blurTmp])e.dispose();for(let e of[this.lumMat,this.adaptMat,this.brightMat,this.downMat,this.blurMat,this.finalMat])e.dispose();this.quad.dispose()}};function $t(a,e){let t=a.image,n=new Uint16Array(t.data.length),r=T.DataUtils.toHalfFloat(e);for(let s=0;s<n.length;s++)n[s]=Math.min(t.data[s],r);let o=new T.DataTexture(n,t.width,t.height,T.RGBAFormat,T.HalfFloatType);return o.mapping=T.EquirectangularReflectionMapping,o.colorSpace=T.LinearSRGBColorSpace,o.minFilter=o.magFilter=T.LinearFilter,o.needsUpdate=!0,o}var se=class{constructor(e,t,n,r={}){this.gl=e;this.scene=t;this.camera=n;this.opts=r;e.shadowMap.enabled=!0,e.shadowMap.type=T.PCFSoftShadowMap,e.toneMapping=T.NoToneMapping,e.outputColorSpace=T.SRGBColorSpace;let o=this.sun.shadow;o.mapSize.setScalar(r.shadowMapSize??2048);let s=r.shadowExtent??30;Object.assign(o.camera,{left:-s,right:s,top:s,bottom:-s,near:1,far:400}),o.camera.updateProjectionMatrix(),o.bias=-4e-4,o.normalBias=.04,o.radius=2,this.sun.castShadow=!0,t.add(this.sun,this.sun.target,this.fill);let u=e.getDrawingBufferSize(new T.Vector2);this.target=new T.WebGLRenderTarget(u.x,u.y,{type:T.HalfFloatType,samples:r.samples??4,depthTexture:new T.DepthTexture(u.x,u.y,T.FloatType)}),this.smoke=new re(n,{quality:r.quality}),this.smoke.setSize(u.x,u.y),this.post=new oe(u.x,u.y),r.exposure!=null&&(this.post.exposureOverride=r.exposure),this.pmrem=new T.PMREMGenerator(e),e.domElement.addEventListener("webglcontextlost",this.onLost),e.domElement.addEventListener("webglcontextrestored",this.onRestored)}gl;scene;camera;opts;sun=new T.DirectionalLight(16777215,Math.PI);fill=new T.HemisphereLight(16777215,16777215,0);map=null;smoke;post;fixedDelta=null;time=0;lastFrame=0;target;pmrem;envRT=null;skyRT=null;v=new T.Vector3;url=null;loads=0;disposed=!1;latest=null;onLost=()=>{this.map&&(this.envRT?.dispose(),this.skyRT?.dispose(),this.envRT=this.skyRT=null,this.scene.background=new T.Color(9417689),this.scene.environment=null,!this.opts.keepCpuCopies&&(this.scene.remove(this.map.root),this.smoke.setWorld(null),this.map.dispose(),this.map=null))};onRestored=()=>{if(this.url){if(this.opts.keepCpuCopies)return void(this.map&&this.setSky(this.map));this.load(this.url,null).catch(e=>console.warn(`cs2-replay: reloading the map after a lost WebGL context: ${e}`))}};load(e,t){let n=++this.loads;this.url=e;let r=s=>{if(n===this.loads)return!1;if(this.map===s&&(this.map=null,this.smoke.setWorld(null)),s.dispose(),this.disposed)throw new Error("cs2-replay: the stage was disposed while the map loaded");return!0},o=rt(e,this.gl,this.opts).then(async s=>{if(r(s))return this.latest;this.setMap(s);try{if(await t?.(s),r(s))return this.latest;await this.precompile(s.root)}catch(u){throw this.map===s&&(this.map=null,this.smoke.setWorld(null)),s.dispose(),u}return r(s)?this.latest:(this.scene.add(s.root),this.gl.getContext().isContextLost()&&!this.opts.keepCpuCopies&&(s.root.visible=!1),s)});return this.latest=o,o}async precompile(e){let t=this.gl,n=t.getRenderTarget();t.setRenderTarget(this.target);let r;try{r=[t.compileAsync(e,this.camera,this.scene),t.compileAsync(this.scene,this.camera)]}finally{t.setRenderTarget(n)}await Promise.all(r)}setMap(e){this.map&&(this.scene.remove(this.map.root),this.map.dispose()),this.map=e;let t=e.env;if(this.sun.color.copy(e.sunColor),this.sun.intensity=Math.PI,this.setSky(e),t.fog){let r=new T.Color().setRGB(...t.fog.color,T.LinearSRGBColorSpace);this.scene.fog=new T.Fog(r,t.fog.start,t.fog.end/Math.max(.2,t.fog.maxOpacity)),this.smoke.setFog(this.scene.fog)}let n=t.sun?.skyColor??[.1,.2,.42];this.fill.color.setRGB(n[0],n[1],n[2],T.LinearSRGBColorSpace),this.fill.groundColor.setRGB(.12,.1,.08,T.LinearSRGBColorSpace),this.fill.intensity=.6,this.post.settings=qt(t),this.smoke.setWorld(e.root),this.smoke.setLighting({sunDirection:e.sunDirection,sunColor:e.sunColor,ambient:new T.Color().setRGB(...t.sun?.skyColor??[.1,.2,.42],T.LinearSRGBColorSpace),probes:e.probes})}setSky(e){this.envRT?.dispose(),this.skyRT?.dispose(),this.envRT=this.skyRT=null;let t=e.sky;if(!t){this.scene.background=new T.Color(9417689),this.scene.environment=null;return}let n=$t(t,12);this.envRT=this.pmrem.fromEquirectangular(n),n.dispose(),this.scene.environment=this.envRT.texture,this.skyRT=new T.WebGLCubeRenderTarget(t.image.height).fromEquirectangularTexture(this.gl,t),this.scene.background=this.skyRT.texture,t.dispose(),this.opts.keepCpuCopies||ve(t);let r=Math.atan2(e.sunDirection.z,e.sunDirection.x),o=r-(e.env.sky?.sunAzimuth??r);this.scene.backgroundRotation.set(0,o,0),this.scene.environmentRotation.set(0,o,0),this.scene.environmentIntensity=1}windStrength(e){let t=this.map?.env.wind;if(!t)return 1;let n=Math.max(1,(t.speed[0]+t.speed[1])/2),r=0,o=0,s=v=>{let E=Math.sin(v*127.1+311.7)*43758.5453;return E-Math.floor(E)},u=v=>t.gustDelay[0]+(t.gustDelay[1]-t.gustDelay[0])*s(v),m=(e%3600+3600)%3600;for(;r+u(o)<m;)r+=u(o++);let l=m-r,b=Math.max(.5,t.gustDuration),d=l<b?Math.sin(Math.PI*l/b)**2:0,f=t.gust[0]+(t.gust[1]-t.gust[0])*s(o+.5);return 1+d*Math.max(0,f/n-1)}update(){let e=this.map?.sunDirection;if(!e)return;let t=this.camera.getWorldDirection(this.v).multiplyScalar((this.opts.shadowExtent??30)*.6).add(this.camera.position),n=2*(this.opts.shadowExtent??30)/this.sun.shadow.mapSize.x;t.set(Math.round(t.x/n)*n,Math.round(t.y/n)*n,Math.round(t.z/n)*n),this.sun.target.position.copy(t),this.sun.position.copy(t).addScaledVector(e,150),this.sun.target.updateMatrixWorld()}get renderTarget(){return this.target}render(){let e=performance.now()/1e3,t=this.fixedDelta??Math.min(.25,Math.max(0,this.lastFrame?e-this.lastFrame:0));this.lastFrame=e,this.time+=t,this.post.fixedDelta=this.fixedDelta;let n=this.map?.uniforms;n&&n.cs2Wind.value.set(n.cs2Wind.value.x,n.cs2Wind.value.y,this.windStrength(this.time),this.time),this.update();let r=this.gl,o=this.smoke.enabled;this.target.resolveDepthBuffer=o,r.setRenderTarget(this.target),r.render(this.scene,this.camera);let s=o?this.smoke.render(r,this.target):this.target.texture;this.post.renderTexture(r,s,null)}setSize(e,t){let n=this.gl.getPixelRatio(),r=Math.max(1,Math.round(e*n)),o=Math.max(1,Math.round(t*n));this.target.setSize(r,o),this.smoke.setSize(r,o),this.post.setSize(r,o)}dispose(){this.disposed=!0,this.loads++,this.gl.domElement.removeEventListener("webglcontextlost",this.onLost),this.gl.domElement.removeEventListener("webglcontextrestored",this.onRestored),this.map?.dispose(),this.skyRT?.dispose(),this.envRT?.dispose(),this.pmrem.dispose(),this.target.depthTexture?.dispose(),this.target.dispose(),this.smoke.dispose(),this.post.dispose(),this.sun.dispose()}};function qt(a){let e=structuredClone(ge),t=a.tonemap;t&&Object.assign(e.tonemap,Object.fromEntries(Object.entries(t).filter(([,r])=>typeof r=="number"))),a.exposure&&Object.assign(e.exposure,a.exposure);let n=a.bloom;if(n){for(let r of["screenStrength","addStrength","threshold","thresholdWidth"])typeof n[r]=="number"&&(e.bloom[r]=n[r]);n.blurWeights?.length===5&&(e.bloom.weights=n.blurWeights),n.blurTints?.length===5&&(e.bloom.tints=n.blurTints)}return e}var st=class{prepareFirst=!0;game;maps=new WeakMap;constructor(e,t,n,r,o){this.game=new se(e,t,n,{...r,keepPositions:o?Ve(o):!1})}async load(e,t){return this.wrap(await this.game.load(e,t&&(n=>t(this.wrap(n)))))}wrap(e){let t=this.maps.get(e);if(t)return t;let n=this.game,r=new ie.Color().setRGB(...e.env.sun?.skyColor??[.1,.2,.4],ie.LinearSRGBColorSpace).multiplyScalar(.5);return t={root:e.root,drawCalls:e.stats.drawCalls,triangles:e.stats.triangles,textures:e.textures,actors:{lighting:{sun:n.sun,hemi:n.fill,ambient:r},probes:e.probes,smoke:n.smoke},...e.tier?{tier:e.tier,lightmapMode:e.lightmapMode??void 0,bytes:e.bytes}:{}},this.maps.set(e,t),t}render(){this.game.render()}setSize(e,t){this.game.setSize(e,t)}dispose(){this.game.dispose()}};export{st as GameLook};
|