|
@@ -119,7 +119,6 @@ export function modifyShader( material, uniforms, numberOfCurves = 1 ) {
|
|
Object.assign( shader.uniforms, uniforms );
|
|
Object.assign( shader.uniforms, uniforms );
|
|
|
|
|
|
const vertexShader = `
|
|
const vertexShader = `
|
|
- #define USE_ENVMAP
|
|
|
|
uniform sampler2D spineTexture;
|
|
uniform sampler2D spineTexture;
|
|
uniform float pathOffset;
|
|
uniform float pathOffset;
|
|
uniform float pathSegment;
|
|
uniform float pathSegment;
|
|
@@ -131,54 +130,57 @@ export function modifyShader( material, uniforms, numberOfCurves = 1 ) {
|
|
float textureStacks = ${TEXTURE_HEIGHT / 4}.;
|
|
float textureStacks = ${TEXTURE_HEIGHT / 4}.;
|
|
|
|
|
|
${shader.vertexShader}
|
|
${shader.vertexShader}
|
|
- `.replace(
|
|
|
|
- '#include <defaultnormal_vertex>',
|
|
|
|
`
|
|
`
|
|
- vec4 worldPos = modelMatrix * vec4(position, 1.);
|
|
|
|
-
|
|
|
|
- bool bend = flow > 0;
|
|
|
|
- float xWeight = bend ? 0. : 1.;
|
|
|
|
-
|
|
|
|
- #ifdef USE_INSTANCING
|
|
|
|
- float pathOffsetFromInstanceMatrix = instanceMatrix[3][2];
|
|
|
|
- float spineLengthFromInstanceMatrix = instanceMatrix[3][0];
|
|
|
|
- float spinePortion = bend ? (worldPos.x + spineOffset) / spineLengthFromInstanceMatrix : 0.;
|
|
|
|
- float mt = (spinePortion * pathSegment + pathOffset + pathOffsetFromInstanceMatrix)*textureStacks;
|
|
|
|
- #else
|
|
|
|
- float spinePortion = bend ? (worldPos.x + spineOffset) / spineLength : 0.;
|
|
|
|
- float mt = (spinePortion * pathSegment + pathOffset)*textureStacks;
|
|
|
|
- #endif
|
|
|
|
-
|
|
|
|
- mt = mod(mt, textureStacks);
|
|
|
|
- float rowOffset = floor(mt);
|
|
|
|
-
|
|
|
|
- #ifdef USE_INSTANCING
|
|
|
|
- rowOffset += instanceMatrix[3][1] * ${TEXTURE_HEIGHT}.;
|
|
|
|
- #endif
|
|
|
|
-
|
|
|
|
- vec3 spinePos = texture(spineTexture, vec2(mt, (0. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
- vec3 a = texture(spineTexture, vec2(mt, (1. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
- vec3 b = texture(spineTexture, vec2(mt, (2. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
- vec3 c = texture(spineTexture, vec2(mt, (3. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
- mat3 basis = mat3(a, b, c);
|
|
|
|
-
|
|
|
|
- vec3 transformed = basis
|
|
|
|
- * vec3(worldPos.x * xWeight, worldPos.y * 1., worldPos.z * 1.)
|
|
|
|
- + spinePos;
|
|
|
|
-
|
|
|
|
- vec3 transformedNormal = normalMatrix * (basis * objectNormal);
|
|
|
|
- `
|
|
|
|
- ).replace(
|
|
|
|
- '#include <begin_vertex>',
|
|
|
|
- ''
|
|
|
|
- ).replace(
|
|
|
|
- '#include <project_vertex>',
|
|
|
|
- `
|
|
|
|
- vec4 mvPosition = viewMatrix * vec4( transformed, 1.0 );
|
|
|
|
- // vec4 mvPosition = viewMatrix * worldPos;
|
|
|
|
- gl_Position = projectionMatrix * mvPosition;
|
|
|
|
- `
|
|
|
|
- );
|
|
|
|
|
|
+ // chunk import moved in front of modified shader below
|
|
|
|
+ .replace('#include <beginnormal_vertex>', ``)
|
|
|
|
+
|
|
|
|
+ // vec3 transformedNormal declaration overriden below
|
|
|
|
+ .replace('#include <defaultnormal_vertex>', ``)
|
|
|
|
+
|
|
|
|
+ // vec3 transformed declaration overriden below
|
|
|
|
+ .replace('#include <begin_vertex>', ``)
|
|
|
|
+
|
|
|
|
+ // shader override
|
|
|
|
+ .replace(
|
|
|
|
+ /void\s*main\s*\(\)\s*\{/,
|
|
|
|
+`
|
|
|
|
+void main() {
|
|
|
|
+#include <beginnormal_vertex>
|
|
|
|
+
|
|
|
|
+vec4 worldPos = modelMatrix * vec4(position, 1.);
|
|
|
|
+
|
|
|
|
+bool bend = flow > 0;
|
|
|
|
+float xWeight = bend ? 0. : 1.;
|
|
|
|
+
|
|
|
|
+#ifdef USE_INSTANCING
|
|
|
|
+float pathOffsetFromInstanceMatrix = instanceMatrix[3][2];
|
|
|
|
+float spineLengthFromInstanceMatrix = instanceMatrix[3][0];
|
|
|
|
+float spinePortion = bend ? (worldPos.x + spineOffset) / spineLengthFromInstanceMatrix : 0.;
|
|
|
|
+float mt = (spinePortion * pathSegment + pathOffset + pathOffsetFromInstanceMatrix)*textureStacks;
|
|
|
|
+#else
|
|
|
|
+float spinePortion = bend ? (worldPos.x + spineOffset) / spineLength : 0.;
|
|
|
|
+float mt = (spinePortion * pathSegment + pathOffset)*textureStacks;
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+mt = mod(mt, textureStacks);
|
|
|
|
+float rowOffset = floor(mt);
|
|
|
|
+
|
|
|
|
+#ifdef USE_INSTANCING
|
|
|
|
+rowOffset += instanceMatrix[3][1] * ${TEXTURE_HEIGHT}.;
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+vec3 spinePos = texture(spineTexture, vec2(mt, (0. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
+vec3 a = texture(spineTexture, vec2(mt, (1. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
+vec3 b = texture(spineTexture, vec2(mt, (2. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
+vec3 c = texture(spineTexture, vec2(mt, (3. + rowOffset + 0.5) / textureLayers)).xyz;
|
|
|
|
+mat3 basis = mat3(a, b, c);
|
|
|
|
+
|
|
|
|
+vec3 transformed = basis
|
|
|
|
+ * vec3(worldPos.x * xWeight, worldPos.y * 1., worldPos.z * 1.)
|
|
|
|
+ + spinePos;
|
|
|
|
+
|
|
|
|
+vec3 transformedNormal = normalMatrix * (basis * objectNormal);
|
|
|
|
+`);
|
|
|
|
|
|
shader.vertexShader = vertexShader;
|
|
shader.vertexShader = vertexShader;
|
|
|
|
|