ugly-game 0.4.0 → 0.5.0
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/gpuShadow.js +12 -6
- package/package.json +29 -9
package/dist/gpuShadow.js
CHANGED
|
@@ -70,7 +70,7 @@ const MAIN_WGSL = COMMON_WGSL + /* wgsl */ `
|
|
|
70
70
|
@group(0) @binding(2) var shadowMap: texture_depth_2d;
|
|
71
71
|
@group(0) @binding(3) var shadowSamp: sampler_comparison;
|
|
72
72
|
|
|
73
|
-
struct VOut { @builtin(position) clip: vec4<f32>, @location(0) world: vec3<f32>, @location(1) nrm: vec3<f32>, @location(2) hue: f32, @location(3) emis: f32 };
|
|
73
|
+
struct VOut { @builtin(position) clip: vec4<f32>, @location(0) world: vec3<f32>, @location(1) nrm: vec3<f32>, @location(2) hue: f32, @location(3) emis: f32, @location(4) blk: vec3<f32>, @location(5) objN: vec3<f32> };
|
|
74
74
|
|
|
75
75
|
@vertex fn vs(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> VOut {
|
|
76
76
|
let inst = insts[ii];
|
|
@@ -81,6 +81,11 @@ struct VOut { @builtin(position) clip: vec4<f32>, @location(0) world: vec3<f32>,
|
|
|
81
81
|
o.nrm = normalize(qrot(inst.rot, CUBE_NRM[vi] / inst.scl.xyz)); // normal under non-uniform scale + rotation
|
|
82
82
|
o.hue = inst.pos.w;
|
|
83
83
|
o.emis = inst.scl.w;
|
|
84
|
+
// OBJECT-space block coord (per-sub-block units, anchored to the model, NOT world) so per-block AO moves +
|
|
85
|
+
// rotates with the instance (ships/creatures/plants) instead of sliding over a world-anchored grid; scale
|
|
86
|
+
// by inst.scl so a merged LOD cube (scl>1) still shows its sub-blocks. objN = pre-rotation face normal.
|
|
87
|
+
o.blk = (CUBE_POS[vi] + vec3(0.5, 0.5, 0.5)) * inst.scl.xyz;
|
|
88
|
+
o.objN = CUBE_NRM[vi];
|
|
84
89
|
return o;
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -117,12 +122,13 @@ fn blockShade(fx: f32, fz: f32) -> f32 {
|
|
|
117
122
|
let ndl = max(dot(N, -normalize(cam.sun.xyz)), 0.0);
|
|
118
123
|
let base = select(mix(vec3(0.34), hsv(i.hue), 0.62), vec3(0.6, 0.62, 0.66), i.hue < 0.0);
|
|
119
124
|
let sh = shadowFactor(i.world, ndl);
|
|
120
|
-
// in-block coords = the two
|
|
121
|
-
|
|
125
|
+
// in-block coords = the two OBJECT axes not along the (object-space, axis-aligned) face normal — so the AO
|
|
126
|
+
// pattern is anchored to the model's own block grid and translates/rotates with the instance.
|
|
127
|
+
let an = abs(i.objN);
|
|
122
128
|
var fx: f32; var fz: f32;
|
|
123
|
-
if (an.y >= an.x && an.y >= an.z) { fx = fract(i.
|
|
124
|
-
else if (an.x >= an.z) { fx = fract(i.
|
|
125
|
-
else { fx = fract(i.
|
|
129
|
+
if (an.y >= an.x && an.y >= an.z) { fx = fract(i.blk.x); fz = fract(i.blk.z); }
|
|
130
|
+
else if (an.x >= an.z) { fx = fract(i.blk.y); fz = fract(i.blk.z); }
|
|
131
|
+
else { fx = fract(i.blk.x); fz = fract(i.blk.y); }
|
|
126
132
|
let ao = blockShade(fx, fz);
|
|
127
133
|
let lit = base * (cam.sun.w + cam.sunCol.xyz * ndl * sh) * ao;
|
|
128
134
|
return vec4(pow(clamp(lit, vec3(0.0), vec3(1.0)), vec3(0.4545)), 1.0); // gamma
|
package/package.json
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugly-game",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./*": {
|
|
11
|
+
"types": "./dist/*.d.ts",
|
|
12
|
+
"import": "./dist/*.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"preinstall": "npx only-allow pnpm",
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"prepublishOnly": "tsc -p tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"meshoptimizer": "^1.2.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^5.6.0",
|
|
31
|
+
"@types/react": "^19.0.0",
|
|
32
|
+
"@webgpu/types": "^0.1.40"
|
|
33
|
+
}
|
|
14
34
|
}
|