How to write a shader that always face to the camera with transform chunk

I tried to do it but I’m not expert with shaders, does anyone know how to make it so object always faces to camera or how can I make it so the 3D model displays like 2D object on screen?

I was going to use particle billboard function but couldn’t understand how it works tbh.

    vec3 viewUp = matrix_viewInverse[1].xyz;
    vec3 viewFor = matrix_viewInverse[2].xyz;
    vec3 viewRight = matrix_viewInverse[0].xyz;
    vec3 posCam = matrix_viewInverse[3].xyz;

    mat3 billMat;
    billMat[2] = -viewFor;
    billMat[0] = -viewRight;
    billMat[1] = -viewUp;
    vec3 pos = billMat * vec3(quadXY, 0);

    localMat = billMat;

    return pos;
}

Hi @commention,

@devMidgard released an example of something similar for a grass shader, here is the public project:

https://playcanvas.com/project/602568/overview/grass-project-webgl-1

It uses 3D planes rotated to look towards the camera in the shader (just make sure to flip the texture, it’s an older project :innocent: ).

3 Likes