ugly-game 0.15.49 → 0.15.50
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/dist/assets/gpuProps.d.ts +9 -0
- package/dist/assets/gpuProps.js +46 -10
- package/package.json +17 -16
|
@@ -30,6 +30,15 @@ export interface PropMesh {
|
|
|
30
30
|
clearcoat?: number;
|
|
31
31
|
/** Analytic studio/sky reflection strength. Defaults to 1 for PBR materials. */
|
|
32
32
|
reflectionStrength?: number;
|
|
33
|
+
/** Caller-owned, linear HDR equirectangular environment with roughness mip levels. */
|
|
34
|
+
environment?: GPUTexture;
|
|
35
|
+
/** Caller-owned OpenGL (+Y) tangent normal map, linear format. */
|
|
36
|
+
normalMap?: GPUTexture;
|
|
37
|
+
/** Caller-owned linear occlusion/roughness/metalness map (RGB). */
|
|
38
|
+
ormMap?: GPUTexture;
|
|
39
|
+
normalScale?: number;
|
|
40
|
+
/** Repetition for normal/ORM maps; albedo UVs are unchanged. */
|
|
41
|
+
detailRepeat?: number;
|
|
33
42
|
positions: Float32Array;
|
|
34
43
|
normals: Float32Array;
|
|
35
44
|
colors: Float32Array;
|
package/dist/assets/gpuProps.js
CHANGED
|
@@ -34,8 +34,11 @@ struct Inst { m: mat4x4<f32>, d0: vec4<f32>, d1: vec4<f32>, d2: vec4<f32>, d3: v
|
|
|
34
34
|
// alpha-test cutoff (0 ⇒ no test, which is every model that predates it).
|
|
35
35
|
// mat = opacity, cutoff, roughness (-1 = legacy), metalness.
|
|
36
36
|
// coat = clearcoat, reflection strength, unused, unused.
|
|
37
|
-
struct Mat { mat: vec4<f32>, coat: vec4<f32> };
|
|
37
|
+
struct Mat { mat: vec4<f32>, coat: vec4<f32>, maps: vec4<f32> };
|
|
38
38
|
@group(2) @binding(2) var<uniform> mtl: Mat;
|
|
39
|
+
@group(2) @binding(3) var environmentTex: texture_2d<f32>;
|
|
40
|
+
@group(2) @binding(4) var normalTex: texture_2d<f32>;
|
|
41
|
+
@group(2) @binding(5) var ormTex: texture_2d<f32>;
|
|
39
42
|
@group(1) @binding(0) var shadowMap: texture_depth_2d_array; // the SAME cascaded sun shadow map the terrain cubes sample
|
|
40
43
|
@group(1) @binding(1) var shadowSamp: sampler_comparison;
|
|
41
44
|
struct VO { @builtin(position) pos: vec4<f32>, @location(0) world: vec3<f32>, @location(1) n: vec3<f32>, @location(2) c: vec3<f32>, @location(3) l: vec3<f32>, @location(4) uv: vec2<f32> };
|
|
@@ -205,6 +208,11 @@ fn studioEnv(r: vec3<f32>, rough: f32) -> vec3<f32> {
|
|
|
205
208
|
c += vec3(2.5, 2.35, 2.1) * (stripA + stripB) * (1.0 - rough * 0.7);
|
|
206
209
|
return c;
|
|
207
210
|
}
|
|
211
|
+
fn environment(r: vec3<f32>, rough: f32) -> vec3<f32> {
|
|
212
|
+
if (mtl.coat.z < 0.5) { return studioEnv(r,rough); }
|
|
213
|
+
let uv=vec2(atan2(r.z,r.x)/6.2831853+0.5,acos(clamp(r.y,-1.0,1.0))/3.14159265);
|
|
214
|
+
return textureSampleLevel(environmentTex,albedoSamp,uv,rough*mtl.coat.w).rgb;
|
|
215
|
+
}
|
|
208
216
|
fn fresnel(f0: vec3<f32>, cosTheta: f32) -> vec3<f32> {
|
|
209
217
|
return f0 + (vec3(1.0) - f0) * pow(1.0 - clamp(cosTheta, 0.0, 1.0), 5.0);
|
|
210
218
|
}
|
|
@@ -223,7 +231,18 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
223
231
|
return select(c * 12.92, 1.055 * pow(max(c, vec3(0.0)), vec3(1.0/2.4)) - 0.055, c > vec3(0.0031308));
|
|
224
232
|
}
|
|
225
233
|
@fragment fn fs(i: VO) -> @location(0) vec4<f32> {
|
|
226
|
-
|
|
234
|
+
var N = normalize(i.n);
|
|
235
|
+
let materialUV=i.uv*mtl.maps.w;
|
|
236
|
+
let px=dpdx(i.world); let py=dpdy(i.world);
|
|
237
|
+
let tx=dpdx(materialUV); let ty=dpdy(materialUV);
|
|
238
|
+
let mapN=textureSample(normalTex,albedoSamp,materialUV).xyz*2.0-1.0;
|
|
239
|
+
let orm=textureSample(ormTex,albedoSamp,materialUV).rgb;
|
|
240
|
+
if(mtl.maps.x>0.5) {
|
|
241
|
+
let T=cross(py,N)*tx.x+cross(N,px)*ty.x;
|
|
242
|
+
let B=cross(py,N)*tx.y+cross(N,px)*ty.y;
|
|
243
|
+
let inv=inverseSqrt(max(max(dot(T,T),dot(B,B)),0.000001));
|
|
244
|
+
N=normalize(N*mapN.z+(T*mapN.x+B*mapN.y)*inv*mtl.maps.z);
|
|
245
|
+
}
|
|
227
246
|
let ff = select(1.0, 0.5 + 0.85 * fixedFill(N, u.up.xyz), u.up.w > 0.5); // fixed fill (fall back to flat amb if no up)
|
|
228
247
|
let d = clamp(dot(N, -normalize(u.sun.xyz)), 0.0, 1.0);
|
|
229
248
|
let sh = mix(1.0, shadowFactor(i.world, d), u.sun.w); // u.sun.w = shadow-receive enable (0 ⇒ off, byte-identical for demo)
|
|
@@ -252,8 +271,8 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
252
271
|
let nl = max(dot(N, L), 0.0);
|
|
253
272
|
let nh = max(dot(N, H), 0.0);
|
|
254
273
|
let vh = max(dot(V, H), 0.0);
|
|
255
|
-
let rough = clamp(mtl.mat.z, 0.045, 1.0);
|
|
256
|
-
let metal = clamp(mtl.mat.w, 0.0, 1.0);
|
|
274
|
+
let rough = clamp(mtl.mat.z * select(1.0,orm.g,mtl.maps.y>0.5), 0.045, 1.0);
|
|
275
|
+
let metal = clamp(mtl.mat.w * select(1.0,orm.b,mtl.maps.y>0.5), 0.0, 1.0);
|
|
257
276
|
// Vertex/instance tints are display sRGB, while albedo textures use sRGB GPU
|
|
258
277
|
// formats (and arrive decoded). Legacy props keep their historical path.
|
|
259
278
|
let albedo = srgbToLinear(i.c) * tex.rgb;
|
|
@@ -262,11 +281,13 @@ fn linearToSrgb(c: vec3<f32>) -> vec3<f32> {
|
|
|
262
281
|
let kd = (vec3(1.0)-F) * (1.0-metal);
|
|
263
282
|
let direct = (kd * albedo / 3.14159265 + F * ggx(nh,nv,nl,rough)) * u.sunCol.xyz * nl * sh * 2.5;
|
|
264
283
|
let R = reflect(-V,N);
|
|
265
|
-
let env =
|
|
284
|
+
let env = environment(R,rough) * mtl.coat.y;
|
|
266
285
|
let reflected = env * fresnel(f0,nv) * (1.0-rough*0.6);
|
|
267
|
-
let
|
|
286
|
+
let ambient=mix(u.amb.xyz,environment(N,1.0)*0.45,select(0.0,0.6,mtl.coat.z>0.5));
|
|
287
|
+
let ao=select(1.0,orm.r,mtl.maps.y>0.5);
|
|
288
|
+
let diffuse = albedo * ambient * (0.6 + 0.4*max(N.y,0.0)) * (1.0-metal)*ao;
|
|
268
289
|
let coatF = fresnel(vec3(0.04),nv) * mtl.coat.x;
|
|
269
|
-
let coating =
|
|
290
|
+
let coating = environment(R,0.12) * coatF * mtl.coat.y;
|
|
270
291
|
let hdr = (direct + diffuse + reflected) * (vec3(1.0)-coatF) + coating;
|
|
271
292
|
// Smooth highlight compression preserves saturated paint rather than
|
|
272
293
|
// clipping reflected softboxes to a flat white patch.
|
|
@@ -563,6 +584,11 @@ export class GpuPropsRenderer {
|
|
|
563
584
|
visibility: GPUShaderStage.FRAGMENT,
|
|
564
585
|
buffer: { type: 'uniform' },
|
|
565
586
|
},
|
|
587
|
+
...[3, 4, 5].map((binding) => ({
|
|
588
|
+
binding,
|
|
589
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
590
|
+
texture: { sampleType: 'float' },
|
|
591
|
+
})),
|
|
566
592
|
],
|
|
567
593
|
});
|
|
568
594
|
this.drawBGL = [bgl0, bgl1, bgl2];
|
|
@@ -821,7 +847,7 @@ export class GpuPropsRenderer {
|
|
|
821
847
|
const alpha = m.alpha ?? 1;
|
|
822
848
|
const cutout = m.cutout ?? 0;
|
|
823
849
|
const matBuf = dev.createBuffer({
|
|
824
|
-
size:
|
|
850
|
+
size: 48,
|
|
825
851
|
usage: U.UNIFORM | U.COPY_DST,
|
|
826
852
|
});
|
|
827
853
|
dev.queue.writeBuffer(matBuf, 0, new Float32Array([
|
|
@@ -831,8 +857,12 @@ export class GpuPropsRenderer {
|
|
|
831
857
|
m.metalness ?? 0,
|
|
832
858
|
m.clearcoat ?? 0,
|
|
833
859
|
m.reflectionStrength ?? 1,
|
|
834
|
-
0,
|
|
835
|
-
0,
|
|
860
|
+
m.environment ? 1 : 0,
|
|
861
|
+
m.environment ? m.environment.mipLevelCount - 1 : 0,
|
|
862
|
+
m.normalMap ? 1 : 0,
|
|
863
|
+
m.ormMap ? 1 : 0,
|
|
864
|
+
m.normalScale ?? 1,
|
|
865
|
+
m.detailRepeat ?? 1,
|
|
836
866
|
]));
|
|
837
867
|
return {
|
|
838
868
|
alpha,
|
|
@@ -850,6 +880,12 @@ export class GpuPropsRenderer {
|
|
|
850
880
|
{ binding: 0, resource: (tex ?? this.white).createView() },
|
|
851
881
|
{ binding: 1, resource: this.sampler },
|
|
852
882
|
{ binding: 2, resource: { buffer: matBuf } },
|
|
883
|
+
{
|
|
884
|
+
binding: 3,
|
|
885
|
+
resource: (m.environment ?? this.white).createView(),
|
|
886
|
+
},
|
|
887
|
+
{ binding: 4, resource: (m.normalMap ?? this.white).createView() },
|
|
888
|
+
{ binding: 5, resource: (m.ormMap ?? this.white).createView() },
|
|
853
889
|
],
|
|
854
890
|
}),
|
|
855
891
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugly-game",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -15,6 +15,21 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"preinstall": "npx only-allow pnpm",
|
|
20
|
+
"build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
21
|
+
"lint": "ugly-app lint",
|
|
22
|
+
"lint:fix": "ugly-app lint --fix",
|
|
23
|
+
"test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
|
|
24
|
+
"test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
|
|
25
|
+
"test:flight-browser": "playwright test -c playwright.flight.config.ts",
|
|
26
|
+
"test:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
|
|
27
|
+
"test:types": "tsc -p tsconfig.test.json",
|
|
28
|
+
"test:package-types": "node tools/packageTypesSmoke.mjs",
|
|
29
|
+
"pretty": "prettier --write .",
|
|
30
|
+
"prepublishOnly": "pnpm run pretty && ugly-app lint && tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
31
|
+
"test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts"
|
|
32
|
+
},
|
|
18
33
|
"dependencies": {
|
|
19
34
|
"@webgpu/types": "^0.1.40",
|
|
20
35
|
"meshoptimizer": "^1.2.0"
|
|
@@ -30,19 +45,5 @@
|
|
|
30
45
|
"typescript": "^5.6.0",
|
|
31
46
|
"ugly-app": "^0.1.841",
|
|
32
47
|
"wesl": "0.7.28"
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"preinstall": "npx only-allow pnpm",
|
|
36
|
-
"build": "tsc -p tsconfig.json && mkdir -p dist/assets/basis && cp src/assets/basis/basis_transcoder.js src/assets/basis/basis_transcoder.bin dist/assets/basis/",
|
|
37
|
-
"lint": "ugly-app lint",
|
|
38
|
-
"lint:fix": "ugly-app lint --fix",
|
|
39
|
-
"test": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/*.test.mts && pnpm run test:gpu-skin",
|
|
40
|
-
"test:flight": "node --experimental-strip-types --import ./tools/tsResolve.mjs --test src/flight*.test.mts",
|
|
41
|
-
"test:flight-browser": "playwright test -c playwright.flight.config.ts",
|
|
42
|
-
"test:flight-perf": "playwright test -c playwright.flight.config.ts --grep 'CPU and retained-memory'",
|
|
43
|
-
"test:types": "tsc -p tsconfig.test.json",
|
|
44
|
-
"test:package-types": "node tools/packageTypesSmoke.mjs",
|
|
45
|
-
"pretty": "prettier --write .",
|
|
46
|
-
"test:gpu-skin": "node --experimental-transform-types --import ./tools/tsResolve.mjs --test src/assets/gpuSkin.test.mts"
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
|
+
}
|