Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

462
Views
ThreeJS: Shader UVs not defined if glTF model contains no texture

I'm importing a glTF model that contains a UV set, and I want to assign a texture to it dynamically in ThreeJS by injecting shader code into the existing using onBeforeCompile().

So far everything works, however if I remove the test texture from the model in Blender and re-export it, then the shader refuses to compile with a vUv undeclared identifier error. When viewing the geometry buffer attributes in the debugging console, the UV maps seem to be defined, but aren't getting defined in the shader for some reason.

I don't want to export the model with a texture, that would mean loading the texture twice (once when the model was loaded, once when the texture is loaded dynamically).

Does anyone know how to get around this?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

the UV maps seem to be defined, but aren't getting defined in the shader for some reason.

That happens because built-in materials only define the vUv varying if maps are sampled in the fragment shader. Since you have removed all maps from your asset, no varying is defined.

One solution to solve the problem is to define the varying manually via onBeforeCompile() by overwriting the uv_pars_fragment shader chunk with just varying vec2 vUv;.

about 4 years ago · Juan Pablo Isaza Report

0

After quite a bit of digging I found I can just set

material.defines.USE_UV = '';

And it will enable the UVs for the model

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!