Open vblegend opened 3 years ago
Is there some workaround to make it works now? I cannot use the library without this fix...
No matter I have fixed it :) If you would be interested then I have created meshlineHotFix.js file with:
import * as THREE from "three";
export const fixedVertexShader = THREE.ShaderChunk['meshline_vert'] = [
'',
'#include <common>',
THREE.ShaderChunk.logdepthbuf_pars_vertex,
THREE.ShaderChunk.fog_pars_vertex,
'',
'attribute vec3 previous;',
'attribute vec3 next;',
'attribute float side;',
'attribute float width;',
'attribute float counters;',
'',
'uniform vec2 resolution;',
'uniform float lineWidth;',
'uniform vec3 color;',
'uniform float opacity;',
'uniform float sizeAttenuation;',
'',
'varying vec2 vUV;',
'varying vec4 vColor;',
'varying float vCounters;',
'',
'vec2 fix( vec4 i, float aspect ) {',
'',
' vec2 res = i.xy / i.w;',
' res.x *= aspect;',
' vCounters = counters;',
' return res;',
'',
'}',
'',
'void main() {',
'',
' float aspect = resolution.x / resolution.y;',
'',
' vColor = vec4( color, opacity );',
' vUV = uv;',
'',
' mat4 m = projectionMatrix * modelViewMatrix;',
' vec4 finalPosition = m * vec4( position, 1.0 );',
' vec4 prevPos = m * vec4( previous, 1.0 );',
' vec4 nextPos = m * vec4( next, 1.0 );',
'',
' vec2 currentP = fix( finalPosition, aspect );',
' vec2 prevP = fix( prevPos, aspect );',
' vec2 nextP = fix( nextPos, aspect );',
'',
' float w = lineWidth * width;',
'',
' vec2 dir;',
' if( nextP == currentP ) dir = normalize( currentP - prevP );',
' else if( prevP == currentP ) dir = normalize( nextP - currentP );',
' else {',
' vec2 dir1 = normalize( currentP - prevP );',
' vec2 dir2 = normalize( nextP - currentP );',
' dir = normalize( dir1 + dir2 );',
'',
' vec2 perp = vec2( -dir1.y, dir1.x );',
' vec2 miter = vec2( -dir.y, dir.x );',
' //w = clamp( w / dot( miter, perp ), 0., 4. * lineWidth * width );',
'',
' }',
'',
' //vec2 normal = ( cross( vec3( dir, 0. ), vec3( 0., 0., 1. ) ) ).xy;',
' vec4 normal = vec4( -dir.y, dir.x, 0., 1. );',
' normal.xy *= .5 * w;',
' normal *= projectionMatrix;',
' if( sizeAttenuation == 0. ) {',
' normal.xy *= finalPosition.w;',
' normal.xy /= ( vec4( resolution, 0., 1. ) * projectionMatrix ).xy;',
' }',
'',
' finalPosition.xy += normal.xy * side;',
'',
' gl_Position = finalPosition;',
'',
THREE.ShaderChunk.logdepthbuf_vertex,
THREE.ShaderChunk.fog_vertex && ' vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );',
THREE.ShaderChunk.fog_vertex,
'}',
].join('\n');
According to this change: https://github.com/dannoshepard/THREE.MeshLine/commit/7268259b27a726987402a4c4112261a4bd8f67ff
And then overriding it in the usage:
import { fixedVertexShader } from "./meshlineHotFix";
// ...
const material = new MeshLineMaterial({
map: null,
useMap: false,
color,
depthWrite: false,
depthTest: false,
resolution: new THREE.Vector2( window.innerWidth, window.innerHeight ),
sizeAttenuation: true,
lineWidth: viewSettings.lineWidth || PARTICLE_SIZE
});
material.vertexShader = fixedVertexShader;
I doubt I'm the only person to have done this, but I've created a published fork (@rivertam/three.meshline@1.5.0
, github here: https://github.com/rivertam/THREE.MeshLine) that's updated to the most recent master
branch + the above fix applied in the upstream.
Seems it would be fixed with the little pull request (1 line added): https://github.com/spite/THREE.MeshLine/pull/134
@spite Could we merge that one to fix this here?
THREE.WebGLProgram: shader error: 1286 35715 false gl.getProgramInfoLog No compiled vertex shader when at least one graphics shader is attached. THREE.WebGLShader: gl.getShaderInfoLog() vertex ERROR: 0:144: 'isPerspectiveMatrix' : no matching overloaded function found 1: #version 300 es 2: 3: #define attribute in 4: #define varying out 5: #define texture2D texture 6: precision highp float; 7: precision highp int; 8: #define HIGH_PRECISION 9: #define SHADER_NAME MeshLineMaterial 10: #define VERTEX_TEXTURES 11: #define GAMMA_FACTOR 2 12: #define MAX_BONES 0 13: #define BONE_TEXTURE 14: #define DOUBLE_SIDED 15: #define USE_LOGDEPTHBUF 16: #define USE_LOGDEPTHBUF_EXT 17: uniform mat4 modelMatrix; 18: uniform mat4 modelViewMatrix; 19: uniform mat4 projectionMatrix; 20: uniform mat4 viewMatrix; 21: uniform mat3 normalMatrix; 22: uniform vec3 cameraPosition; 23: uniform bool isOrthographic; 24: #ifdef USE_INSTANCING 25: attribute mat4 instanceMatrix; 26: #endif 27: attribute vec3 position; 28: attribute vec3 normal; 29: attribute vec2 uv; 30: #ifdef USE_TANGENT 31: attribute vec4 tangent; 32: #endif 33: #ifdef USE_COLOR 34: attribute vec3 color; 35: #endif 36: #ifdef USE_MORPHTARGETS 37: attribute vec3 morphTarget0; 38: attribute vec3 morphTarget1; 39: attribute vec3 morphTarget2; 40: attribute vec3 morphTarget3; 41: #ifdef USE_MORPHNORMALS 42: attribute vec3 morphNormal0; 43: attribute vec3 morphNormal1; 44: attribute vec3 morphNormal2; 45: attribute vec3 morphNormal3; 46: #else 47: attribute vec3 morphTarget4; 48: attribute vec3 morphTarget5; 49: attribute vec3 morphTarget6; 50: attribute vec3 morphTarget7; 51: #endif 52: #endif 53: #ifdef USE_SKINNING 54: attribute vec4 skinIndex; 55: attribute vec4 skinWeight; 56: #endif 57: 58: 59: #ifdef USE_LOGDEPTHBUF 60: #ifdef USE_LOGDEPTHBUF_EXT 61: varying float vFragDepth; 62: varying float vIsPerspective; 63: #else 64: uniform float logDepthBufFC; 65: #endif 66: #endif 67: #ifdef USE_FOG 68: varying float fogDepth; 69: #endif 70: 71: attribute vec3 previous; 72: attribute vec3 next; 73: attribute float side; 74: attribute float width; 75: attribute float counters; 76: 77: uniform vec2 resolution; 78: uniform float lineWidth; 79: uniform vec3 color; 80: uniform float opacity; 81: uniform float sizeAttenuation; 82: 83: varying vec2 vUV; 84: varying vec4 vColor; 85: varying float vCounters; 86: 87: vec2 fix( vec4 i, float aspect ) { 88: 89: vec2 res = i.xy / i.w; 90: res.x = aspect; 91: vCounters = counters; 92: return res; 93: 94: } 95: 96: void main() { 97: 98: float aspect = resolution.x / resolution.y; 99: 100: vColor = vec4( color, opacity ); 101: vUV = uv; 102: 103: mat4 m = projectionMatrix modelViewMatrix; 104: vec4 finalPosition = m vec4( position, 1.0 ); 105: vec4 prevPos = m vec4( previous, 1.0 ); 106: vec4 nextPos = m vec4( next, 1.0 ); 107: 108: vec2 currentP = fix( finalPosition, aspect ); 109: vec2 prevP = fix( prevPos, aspect ); 110: vec2 nextP = fix( nextPos, aspect ); 111: 112: float w = lineWidth width; 113: 114: vec2 dir; 115: if( nextP == currentP ) dir = normalize( currentP - prevP ); 116: else if( prevP == currentP ) dir = normalize( nextP - currentP ); 117: else { 118: vec2 dir1 = normalize( currentP - prevP ); 119: vec2 dir2 = normalize( nextP - currentP ); 120: dir = normalize( dir1 + dir2 ); 121: 122: vec2 perp = vec2( -dir1.y, dir1.x ); 123: vec2 miter = vec2( -dir.y, dir.x ); 124: //w = clamp( w / dot( miter, perp ), 0., 4. lineWidth width ); 125: 126: } 127: 128: //vec2 normal = ( cross( vec3( dir, 0. ), vec3( 0., 0., 1. ) ) ).xy; 129: vec4 normal = vec4( -dir.y, dir.x, 0., 1. ); 130: normal.xy = .5 w; 131: normal = projectionMatrix; 132: if( sizeAttenuation == 0. ) { 133: normal.xy = finalPosition.w; 134: normal.xy /= ( vec4( resolution, 0., 1. ) projectionMatrix ).xy; 135: } 136: 137: finalPosition.xy += normal.xy side; 138: 139: gl_Position = finalPosition; 140: 141: #ifdef USE_LOGDEPTHBUF 142: #ifdef USE_LOGDEPTHBUF_EXT 143: vFragDepth = 1.0 + gl_Position.w; 144: vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); 145: #else 146: if ( isPerspectiveMatrix( projectionMatrix ) ) { 147: gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) logDepthBufFC - 1.0; 148: gl_Position.z = gl_Position.w; 149: } 150: #endif 151: #endif 152: vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); 153: #ifdef USE_FOG 154: fogDepth = - mvPosition.z; 155: #endif 156: }