How to make a texture always face the camera?

For that example, you could just have added the plane as child to the camera, with the appropriate offset. If you need a moving plane, but still want the plane to face the camera, you can do like I did for each sphere in my spheres example. The principle is to add the vertex position in view space. For just a single object, you could just add in a uniform position that you apply the modelViewMatrix to, and then add the vertex position before applying the projectionMatrix. (Or even projecting first and adding in the projected space.)

You are right. Making the plane a child to the camera would have been an improvement and saved some calculations. That particular project turned out to be a dead end because of performance issues. However, I was hoping that the equations would be useful for purposes of this thread.

But as I read the discussion of your project, I was reminded that what I designed is commonly called a “billboard” and there are probably a million examples of how to create those.

So, in this case, my reply - while well intended - probably contributes nothing useful to this thread and can be ignored.

I think in general having multiple methods in the arsenal can be useful. :smiley:
(Edit: removed off-topic stuff)

(Edit: removed off-topic reply)

(Edit: removed off-topic stuff)

@ken.kin So, for a on-topic (but still blind) advice:

  • I suggest computing (as needed) a (not necessarily the smallest) bounding sphere for the geometry (geometry.computeBoundingSphere(), geometry.boundingSphere), and scaling it by the object scale (assumed uniform for now).
  • Pass the view-space center and radius of the sphere to the shaders. (E.g. using object.onBeforeRender.)
  • In the vertex shader, make sure to calculate view space position of the vertex and pass it in a varying. ( viewMatrix*vec4(position, 1.);)
  • In the fragment shader, transform view space xy position by subtracting the sphere center, dividing by two times the sphere radius and adding vec2(1.0). (vec2 uv = (viewPos.xy-sphereCenter.xy)/(2.*sphereRadius)+vec2(1.);)
  • The resulting vector is an uv for the texture lookup. (vec4 color = texture2D(map, uv);)

(Edit: removed off-topic reply)