[SOLVED] Get UV1 inside of a shader?


I’m wondering how to pass or force UV1 data into a fragment shader. I’ve seen the forceUv1 variable here but am unsure exactly how to pass it in.

When using the UV1 in the shader I’m currently getting:

ERROR: 0:185: 'vUv1' : undeclared identifier 


I’ve never tried it but I believe something like this may work:

this.material.onUpdateShader( function(options){
   options.forceUv1 = true;
   return options;

Thanks for your the help, but unfortunately that didn’t work.

Try posting an issue in the engine repo, maybe someone from the engine team knows how this is triggered.

This works, I’ve just tested it:

            // this generates this in shader: vec2 uv1 = getUv1();
            mat.onUpdateShader = function(options) {
                options.forceUv1 = true;
                return options;
            // you need texture assigned to slot that uses uv1. 
            // Set some texture to lightMap slot (unless you already have some texture assigned). 
            // This generates VS instructions that output uv1 to fragment shader 
            // (varying vec2 vUv1; vUv1 = uv1;) 
            mat.lightMap = new pc.Texture(this.app.graphicsDevice, {
                width: 1,
                height: 1,
                format: pc.PIXELFORMAT_R8_G8_B8


I tried this custom fragment shader and that outputs UV1 as expected

void getAlbedo() {
    dAlbedo = vec3(vUv1.x, vUv1.y, 0.0);

Ah thank you. I think my issue was that I wasn’t assigning a texture.