Is it possible to get the camera position when overriding the gsplatCustomize shader chunk?
This would be extremly useful to do effects based on splat distance to camera.
Is it possible to get the camera position when overriding the gsplatCustomize shader chunk?
This would be extremly useful to do effects based on splat distance to camera.
not automatically, but you can add any uniforms and pass what you need to those shaders. Similarly how parameters (lets say the center here) gets set:
Yep that works. I thought there might be a better solution. I know there is a uniform view_position in the standard shader. Altough that one is in the fragment shader.
Follow up question:
The camera position is in world space. The center of modifyCenter however is in the gsplat model space.
Whats the best way to convert one space to the other?
EDIT: I’ve tried converting with matrix_model however it only gets defined later in the shader.
yep, for this you can simply add the uniform to your shader, and the engine will supply the value automatically.
GLSL
uniform vec3 view_position;
WGSL
uniform view_position: vec3f;
I think in your case, maybe you need to convert the camera position to model space before setting it as uniform.
Alright I calculated the camera position in model space and supplied it to the shader:
this._worldToModelMatrix.copy(this.entity.getWorldTransform());
this._worldToModelMatrix.invert();
this._worldToModelMatrix.transformPoint(this.camera.getPosition(), this._transformedPoint);
this._cameraPositionArray[0] = this._transformedPoint.x;
this._cameraPositionArray[1] = this._transformedPoint.y;
this._cameraPositionArray[2] = this._transformedPoint.z;
this.entity.gsplat.material.setParameter('uCameraPosition', this._cameraPositionArray);
Works perfectly