Thank you for clarifying. I have tried in the vertex shader
scene0 = vec4(.0, .0, 1.0, 1.0 );
vec4 viewPos = inverse(cameraWorldMatrix) * scene0;
scene0 = projectionMatrix * viewPos;
test = scene0.xyz ;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
and
scene0 = vec4(.0, .0, 1.0, 1.0 );
vec4 viewPos = viewMatrix * scene0;
scene0 = modelViewMatrix * viewPos;
test = scene0.xyz - cameraWorldPos;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
```
scene0 = vec4(.0, .0, 1.0, 1.0 );
vec4 viewPos = inverse(cameraWorldMatrix) * scene0;
scene0 = projectionMatrix * viewPos;
test = scene0.xyz ;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
the problem remains, the point displays slightly off depending on the camera orientation. maybe it would be from thecalculated distance in the fragment shader?
The fragment shader is (that i have got from a previous question here: WorldPosition in shader - #2 by HEOJUNFO
):
float depth = getLinearDepth( vUv );
float fragDepth = texture2D(tDepth, vUv).r;
float viewZ = perspectiveDepthToViewZ(fragDepth, cameraNear, cameraFar);
vec4 viewPos = getViewPosition(vUv, fragDepth);
vec4 worldPos = cameraWorldMatrix * viewPos;
//HEATMAP
float intensity = distance(test.xyz, worldPos.xyz );