Hi guys, I am actually trying to achieve the next feature: I got a plane on my scene with a custom shader, I apply to the shader a 2D texture , I would want to have the texture facing the camera when I move the camera, but not to have the plane geometry moving, like a billboard but only for the texture.
I actually struggle to figure out the abstraction, understand that i need to get the camera’s position, and plane position, but dont understand how to create the “rotation” effect, if somebody can help, it will be appreciated.
Thanks a lot!
Maybe you mean using plane’s vertexes like uv coordinates.
2 Likes
instead of uv you can use FragCoord.xy / screen width or similar if you want the mesh to appear as a portal onto a texture.
For fragment shader need to send screen size attributes:
Javascript:
mat["screen"]=new THREE.ShaderMaterial({
uniforms:{
screenSize:{value:[screen.width,screen.height]},
Fragment Shader:
uniform vec2 screenSize;
void(){
vec4 diffuse=texture2D(map,gl_FragCoord.xy/screenSize)
};
If without screenSize uniform:
Vertex shader:
varying vec3 v2D;
void main(){
v2D=gl_Position.xyw;
}
Fragment shader:
varying vec3 v2D;
void main(){
vec4 diffuse=texture2D(map,(v2D.xy/v2D.z+1.0)*0.5);
}