Search code examples
three.jsglsl

World Position in glsl for three.js instanced mesh


I’m trying to get world space texture coordinate for instanced meshes in three.js using glsl, it works for individual objects but not for instanced meshes.

W_Pos = (modelMatrix * vec4(position,1.0)).xyz;

individual objects enter image description here

instances instances

any help?


Solution

  • I'm so dumb, the answer was in the docs, i had read that before but it completely slipped my mind lel.

    W_Pos = instanceMatrix * vec3(position,1.0).xyz;
    

    https://threejs.org/docs/?q=web#api/en/renderers/webgl/WebGLProgram