fix(web): declare card shader UV uniforms
three.js does not auto-declare uniforms added via onBeforeCompile, so the injected uMapRepeat/uMapOffset were undeclared and the card shader failed to compile, rendering cards transparent. Prepend the declarations to the vertex shader.
This commit is contained in:
@@ -14,6 +14,14 @@ import * as THREE from 'three';
|
||||
* refreshed from `map.matrix` every frame, overwriting any per-material
|
||||
* transform we set on the shared texture.
|
||||
*/
|
||||
// Uniforms added via `onBeforeCompile` are not auto-declared by three.js, so
|
||||
// they must be declared in the GLSL explicitly (the built-in `mapTransform` is
|
||||
// declared in `uv_pars_vertex.glsl.js`).
|
||||
const UNIFORM_DECLS = /* glsl */ `
|
||||
uniform vec2 uMapRepeat;
|
||||
uniform vec2 uMapOffset;
|
||||
`;
|
||||
|
||||
const VERTEX_INJECT = /* glsl */ `
|
||||
#include <uv_vertex>
|
||||
vMapUv = uv * uMapRepeat + uMapOffset;
|
||||
@@ -36,9 +44,8 @@ export function applyMapTransform(
|
||||
material.onBeforeCompile = (shader) => {
|
||||
shader.uniforms.uMapRepeat = { value: r };
|
||||
shader.uniforms.uMapOffset = { value: o };
|
||||
shader.vertexShader = shader.vertexShader.replace(
|
||||
'#include <uv_vertex>',
|
||||
VERTEX_INJECT,
|
||||
);
|
||||
shader.vertexShader =
|
||||
UNIFORM_DECLS +
|
||||
shader.vertexShader.replace('#include <uv_vertex>', VERTEX_INJECT);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user