[SOLVED] Get UV1 inside of a shader?

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
            });

            mat.update();

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

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