minecraft-renderer 0.1.76 → 0.1.77
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/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
vi.mock('./utils/skins', () => ({
|
|
5
|
+
stevePngUrl: '',
|
|
6
|
+
loadSkinImage: vi.fn(),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
import { PlayerObject } from 'skinview3d'
|
|
10
|
+
import { configurePlayerSkinMaterials } from './createPlayerObject'
|
|
11
|
+
|
|
12
|
+
describe('configurePlayerSkinMaterials', () => {
|
|
13
|
+
it('configures cutout materials and log-depth bias on arm/leg mats only', () => {
|
|
14
|
+
const playerObject = new PlayerObject()
|
|
15
|
+
const skin = playerObject.skin as any
|
|
16
|
+
|
|
17
|
+
configurePlayerSkinMaterials(playerObject)
|
|
18
|
+
|
|
19
|
+
const allMaterials = [
|
|
20
|
+
skin.layer1Material,
|
|
21
|
+
skin.layer1MaterialBiased,
|
|
22
|
+
skin.layer2Material,
|
|
23
|
+
skin.layer2MaterialBiased,
|
|
24
|
+
]
|
|
25
|
+
for (const mat of allMaterials) {
|
|
26
|
+
expect(mat.transparent).toBe(false)
|
|
27
|
+
expect(mat.alphaTest).toBe(0.1)
|
|
28
|
+
expect(mat.depthWrite).toBe(true)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
expect(skin.layer1MaterialBiased.userData.logDepthBiasApplied).toBe(true)
|
|
32
|
+
expect(skin.layer2MaterialBiased.userData.logDepthBiasApplied).toBe(true)
|
|
33
|
+
expect(typeof skin.layer1MaterialBiased.onBeforeCompile).toBe('function')
|
|
34
|
+
expect(typeof skin.layer2MaterialBiased.onBeforeCompile).toBe('function')
|
|
35
|
+
expect(skin.layer1MaterialBiased.onBeforeCompile).toBe(skin.layer2MaterialBiased.onBeforeCompile)
|
|
36
|
+
|
|
37
|
+
expect(skin.layer1Material.userData.logDepthBiasApplied).toBeUndefined()
|
|
38
|
+
expect(skin.layer2Material.userData.logDepthBiasApplied).toBeUndefined()
|
|
39
|
+
expect(skin.layer1Material.onBeforeCompile).not.toBe(skin.layer1MaterialBiased.onBeforeCompile)
|
|
40
|
+
expect(skin.layer2Material.onBeforeCompile).not.toBe(skin.layer2MaterialBiased.onBeforeCompile)
|
|
41
|
+
|
|
42
|
+
const firstCompile = skin.layer1MaterialBiased.onBeforeCompile
|
|
43
|
+
configurePlayerSkinMaterials(playerObject)
|
|
44
|
+
expect(skin.layer1MaterialBiased.onBeforeCompile).toBe(firstCompile)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -10,7 +10,30 @@ export type PlayerObjectType = PlayerObject & {
|
|
|
10
10
|
realUsername: string
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const LOG_DEPTH_BIAS = -2e-4 // tune visually; negative ≈ polygonOffset “closer”
|
|
14
|
+
|
|
15
|
+
function patchLogDepthBiasShader (shader: THREE.WebGLProgramParametersWithUniforms): void {
|
|
16
|
+
shader.uniforms.uLogDepthBias = { value: LOG_DEPTH_BIAS }
|
|
17
|
+
shader.fragmentShader = shader.fragmentShader.replace(
|
|
18
|
+
'#include <logdepthbuf_pars_fragment>',
|
|
19
|
+
`#include <logdepthbuf_pars_fragment>\nuniform float uLogDepthBias;`
|
|
20
|
+
)
|
|
21
|
+
shader.fragmentShader = shader.fragmentShader.replace(
|
|
22
|
+
'#include <logdepthbuf_fragment>',
|
|
23
|
+
`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
|
|
24
|
+
gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5 + uLogDepthBias;
|
|
25
|
+
#endif`
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function applyLogDepthBias (material: THREE.Material): void {
|
|
30
|
+
if (material.userData.logDepthBiasApplied) return
|
|
31
|
+
material.userData.logDepthBiasApplied = true
|
|
32
|
+
material.onBeforeCompile = patchLogDepthBiasShader
|
|
33
|
+
material.needsUpdate = true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Log-depth world: opaque cutout mats (alphaTest + depthWrite, not transparent sort). */
|
|
14
37
|
export function configurePlayerSkinMaterials (playerObject: PlayerObject): void {
|
|
15
38
|
const skin = playerObject.skin as any
|
|
16
39
|
const materials = [
|
|
@@ -20,10 +43,12 @@ export function configurePlayerSkinMaterials (playerObject: PlayerObject): void
|
|
|
20
43
|
skin.layer2MaterialBiased,
|
|
21
44
|
]
|
|
22
45
|
for (const mat of materials) {
|
|
23
|
-
mat.transparent =
|
|
46
|
+
mat.transparent = false
|
|
24
47
|
mat.alphaTest = 0.1
|
|
25
48
|
mat.depthWrite = true
|
|
26
49
|
}
|
|
50
|
+
applyLogDepthBias(skin.layer1MaterialBiased)
|
|
51
|
+
applyLogDepthBias(skin.layer2MaterialBiased)
|
|
27
52
|
}
|
|
28
53
|
|
|
29
54
|
export function createPlayerObject (options: {
|