minecraft-renderer 0.1.77 → 0.1.78
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/mesherWasm.js +23 -1
- package/dist/minecraft-renderer.js +82 -60
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +418 -396
- package/package.json +1 -1
- package/src/three/chunkMeshManager.ts +8 -1
- package/src/three/shaders/cubeBlockShader.ts +36 -1
- package/src/three/worldRendererThree.ts +6 -0
- package/src/wasm-mesher/tests/shaderCubeInstances.test.ts +12 -1
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import * as nbt from 'prismarine-nbt'
|
|
|
4
4
|
import { Vec3 } from 'vec3'
|
|
5
5
|
import { MesherGeometryOutput } from '../mesher-shared/shared'
|
|
6
6
|
import { getShaderCubeResources, SHADER_CUBES_WORDS_PER_FACE } from '../wasm-mesher/bridge/shaderCubeBridge'
|
|
7
|
-
import { createCubeBlockMaterial, computeSectionOriginRel, setCubeSkyLevel, setCubeLightmapParams, type BlockLightmapParams } from './shaders/cubeBlockShader'
|
|
7
|
+
import { createCubeBlockMaterial, computeSectionOriginRel, setCubeSkyLevel, setCubeShadingTheme, setCubeLightmapParams, type BlockLightmapParams } from './shaders/cubeBlockShader'
|
|
8
8
|
import { computeCameraRelativeUniforms, createGlobalLegacyBlendMaterial, createGlobalLegacyBlockMaterial, createLegacyBlockMaterial, setLegacyCameraOrigin, setLegacySkyLevel, setLegacyLightmapParams, type RenderOrigin } from './shaders/legacyBlockShader'
|
|
9
9
|
import { LEGACY_SECTION_HALF_EXTENT, sectionIntersectsFrustum, setupLegacySectionMatrix, updateLegacySectionCullState } from './legacySectionCull'
|
|
10
10
|
import { createShaderCubeMesh, disposeShaderCubeMesh } from './shaderCubeMesh'
|
|
@@ -266,6 +266,11 @@ export class ChunkMeshManager {
|
|
|
266
266
|
this.blockEntityLightRegistry.setSkyLevel(value)
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
setShadingTheme (theme: 'vanilla' | 'high-contrast', cardinalLight: string): void {
|
|
270
|
+
const cube = this.cubeShaderMaterial ?? (this.isShaderCubesGpuEnabled() ? this.getCubeShaderMaterial() : null)
|
|
271
|
+
if (cube) setCubeShadingTheme(cube, theme, cardinalLight)
|
|
272
|
+
}
|
|
273
|
+
|
|
269
274
|
/** Vanilla-like lightmap curve params (live tuning via window.setBlockLightmap). */
|
|
270
275
|
setBlockLightmapParams (params: BlockLightmapParams): void {
|
|
271
276
|
const cube = this.cubeShaderMaterial ?? (this.isShaderCubesGpuEnabled() ? this.getCubeShaderMaterial() : null)
|
|
@@ -531,6 +536,8 @@ export class ChunkMeshManager {
|
|
|
531
536
|
if (!this.cubeShaderMaterial) {
|
|
532
537
|
this.cubeShaderMaterial = createCubeBlockMaterial()
|
|
533
538
|
this.syncCubeShaderUniforms()
|
|
539
|
+
const cfg = this.worldRenderer.worldRendererConfig
|
|
540
|
+
setCubeShadingTheme(this.cubeShaderMaterial, cfg.shadingTheme, cfg.cardinalLight)
|
|
534
541
|
}
|
|
535
542
|
return this.cubeShaderMaterial
|
|
536
543
|
}
|
|
@@ -199,6 +199,8 @@ uniform float u_skyLevel;
|
|
|
199
199
|
uniform float u_lightCurve;
|
|
200
200
|
uniform float u_minBrightness;
|
|
201
201
|
uniform float u_lightGamma;
|
|
202
|
+
uniform float u_shadingTheme; // 0 = vanilla, 1 = high-contrast
|
|
203
|
+
uniform float u_cardinalLight; // 0 = default, 1 = nether
|
|
202
204
|
|
|
203
205
|
in float v_blockLight;
|
|
204
206
|
in float v_skyLight;
|
|
@@ -248,6 +250,24 @@ void applyFog() {
|
|
|
248
250
|
|
|
249
251
|
${APPLY_LIGHTMAP_GLSL}
|
|
250
252
|
|
|
253
|
+
const vec3 FACE_NORMAL[6] = vec3[6](
|
|
254
|
+
vec3(0.0, 1.0, 0.0), // UP
|
|
255
|
+
vec3(0.0,-1.0, 0.0), // DOWN
|
|
256
|
+
vec3(1.0, 0.0, 0.0), // EAST
|
|
257
|
+
vec3(-1.0,0.0, 0.0), // WEST
|
|
258
|
+
vec3(0.0, 0.0, 1.0), // SOUTH
|
|
259
|
+
vec3(0.0, 0.0,-1.0) // NORTH
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
float sideShadingFromFaceId(int faceId, float theme, float cardinal) {
|
|
263
|
+
vec3 n = FACE_NORMAL[faceId];
|
|
264
|
+
float hc = 0.8 + 0.5 * max(0.0, 0.66*n.x + 0.66*n.y + 0.33*n.z);
|
|
265
|
+
float nether = 0.5 + abs(0.1*n.x + 0.4*n.y + 0.3*n.z);
|
|
266
|
+
float vanilla = 0.75 + 0.25*n.y + 0.05*(abs(n.z) - 3.0*abs(n.x));
|
|
267
|
+
float nonHc = mix(vanilla, nether, cardinal);
|
|
268
|
+
return mix(nonHc, hc, theme);
|
|
269
|
+
}
|
|
270
|
+
|
|
251
271
|
void main() {
|
|
252
272
|
// Atlas sample (pixelated, no filtering)
|
|
253
273
|
ivec2 atlasSize = textureSize(u_atlas, 0);
|
|
@@ -294,7 +314,9 @@ void main() {
|
|
|
294
314
|
|
|
295
315
|
float L = max(v_blockLight, min(v_skyLight, u_skyLevel));
|
|
296
316
|
float Lm = applyLightmap(L);
|
|
297
|
-
float
|
|
317
|
+
float aoFactor = mix(0.8 * v_ao + 0.2, v_ao, u_shadingTheme);
|
|
318
|
+
float side = sideShadingFromFaceId(v_faceId, u_shadingTheme, u_cardinalLight);
|
|
319
|
+
float brightness = Lm * aoFactor * side;
|
|
298
320
|
|
|
299
321
|
// Opaque full cubes: always alpha 1 (legacy uses cutout material; avoids seeing blocks behind)
|
|
300
322
|
FragColor = vec4(baseColor.rgb * tint * brightness, 1.0);
|
|
@@ -317,6 +339,8 @@ export function createCubeBlockMaterial(): THREE.ShaderMaterial {
|
|
|
317
339
|
u_tintPalette: { value: null },
|
|
318
340
|
u_debugMode: { value: 0 },
|
|
319
341
|
u_skyLevel: { value: 1.0 },
|
|
342
|
+
u_shadingTheme: { value: 1.0 },
|
|
343
|
+
u_cardinalLight: { value: 0.0 },
|
|
320
344
|
u_lightCurve: { value: DEFAULT_LIGHTMAP_PARAMS.curve },
|
|
321
345
|
u_minBrightness: { value: DEFAULT_LIGHTMAP_PARAMS.minBrightness },
|
|
322
346
|
u_lightGamma: { value: DEFAULT_LIGHTMAP_PARAMS.gamma },
|
|
@@ -344,6 +368,17 @@ export function setCubeSkyLevel (material: THREE.ShaderMaterial, value: number):
|
|
|
344
368
|
if (u) u.value = value
|
|
345
369
|
}
|
|
346
370
|
|
|
371
|
+
export function setCubeShadingTheme (
|
|
372
|
+
material: THREE.ShaderMaterial,
|
|
373
|
+
theme: 'vanilla' | 'high-contrast',
|
|
374
|
+
cardinalLight: string,
|
|
375
|
+
): void {
|
|
376
|
+
const t = material.uniforms.u_shadingTheme
|
|
377
|
+
if (t) t.value = theme === 'high-contrast' ? 1.0 : 0.0
|
|
378
|
+
const c = material.uniforms.u_cardinalLight
|
|
379
|
+
if (c) c.value = cardinalLight === 'nether' ? 1.0 : 0.0
|
|
380
|
+
}
|
|
381
|
+
|
|
347
382
|
export function setCubeLightmapParams (
|
|
348
383
|
material: THREE.ShaderMaterial,
|
|
349
384
|
params: BlockLightmapParams,
|
|
@@ -549,6 +549,12 @@ export class WorldRendererThree extends WorldRendererCommon {
|
|
|
549
549
|
this.chunkMeshManager.syncCubeShaderUniforms()
|
|
550
550
|
this.chunkMeshManager.syncLegacyShaderUniforms()
|
|
551
551
|
})
|
|
552
|
+
const pushShading = () => {
|
|
553
|
+
const cfg = this.worldRendererConfig
|
|
554
|
+
this.chunkMeshManager.setShadingTheme(cfg.shadingTheme, cfg.cardinalLight)
|
|
555
|
+
}
|
|
556
|
+
this.onReactiveConfigUpdated('shadingTheme', pushShading)
|
|
557
|
+
this.onReactiveConfigUpdated('cardinalLight', pushShading)
|
|
552
558
|
this.onReactiveConfigUpdated('futuristicReveal', () => {
|
|
553
559
|
this.updateModulesFromConfig()
|
|
554
560
|
})
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from '../bridge/shaderCubeBridge'
|
|
18
18
|
import { GlobalBlockBuffer } from '../../three/globalBlockBuffer'
|
|
19
19
|
import { buildVisibleCubeSpans } from '../../three/cubeDrawSpans'
|
|
20
|
-
import { createCubeBlockMaterial, computeSectionOriginRel } from '../../three/shaders/cubeBlockShader'
|
|
20
|
+
import { createCubeBlockMaterial, computeSectionOriginRel, setCubeShadingTheme } from '../../three/shaders/cubeBlockShader'
|
|
21
21
|
import * as THREE from 'three'
|
|
22
22
|
import { renderWasmOutputToGeometry } from '../bridge/render-from-wasm'
|
|
23
23
|
|
|
@@ -36,6 +36,17 @@ beforeEach(() => {
|
|
|
36
36
|
resetShaderCubeResources()
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
+
test('setCubeShadingTheme: maps theme and cardinalLight to shader uniforms', () => {
|
|
40
|
+
const mat = createCubeBlockMaterial()
|
|
41
|
+
setCubeShadingTheme(mat, 'vanilla', 'default')
|
|
42
|
+
expect(mat.uniforms.u_shadingTheme.value).toBe(0)
|
|
43
|
+
expect(mat.uniforms.u_cardinalLight.value).toBe(0)
|
|
44
|
+
setCubeShadingTheme(mat, 'high-contrast', 'nether')
|
|
45
|
+
expect(mat.uniforms.u_shadingTheme.value).toBe(1)
|
|
46
|
+
expect(mat.uniforms.u_cardinalLight.value).toBe(1)
|
|
47
|
+
mat.dispose()
|
|
48
|
+
})
|
|
49
|
+
|
|
39
50
|
test('packWord2: AO diagonal flip sets bit 12', () => {
|
|
40
51
|
const words: number[] = []
|
|
41
52
|
const block = {
|