Why cameraPosition in PointsMaterial shader set to 0,0,0?

On this page, it says that the cameraPosition is the position of the camera in world space: three.js docs

However, when I use it in my vertex shader it appears to always be set to 0,0,0 despite where I move my camera in my scene.

vec4 localPosition = vec4( position, 1.);
vec4 worldPosition = modelMatrix * localPosition;
vec3 look = normalize( vec3(cameraPosition) - vec3(worldPosition) );
vec3 transformed = vec3( position ) + look;

Why is it always set to 0,0,0 ?

It seems like it isn’t set when using a PointsMaterial.

Here is example of issue… If you change the material type, it works, but if you use PointsMaterial, the cameraPosition isn’t set.
Why does the PointsMaterial not set the cameraPosition?

1 Like

Seems as though the webglrenderer doesn’t set it due to the material type…

I found this in the webglrenderer code ( three.js/WebGLRenderer.js at 19359e3aefc32f08d1383412042b6bb2405b2ea9 · mrdoob/three.js · GitHub ):

            // load material specific uniforms
			// (shader material also gets them for the sake of genericity)

			if ( material.isShaderMaterial ||
				material.isMeshPhongMaterial ||
				material.isMeshToonMaterial ||
				material.isMeshStandardMaterial ||
				material.envMap ) {

				const uCamPos = p_uniforms.map.cameraPosition;

				if ( uCamPos !== undefined ) {

					uCamPos.setValue( _gl,
						_vector3.setFromMatrixPosition( camera.matrixWorld ) );



If I add to my code:

material.isShaderMaterial = true;

Then the camera position is set correctly… I don’t know if this is good to set that, but it seems to work now…

1 Like