Open mncharity opened 4 years ago
Looking at the code it seems that would not work with a Perspective camera indeed. The ray's direction is gonna be different in this case, going from the camera's position towards the fragment's world position.
vec3 rayOrigin = cameraPosition;
vec3 rayDirection = normalize(vPos.xyz - rayOrigin);
And the ray marching stop condition must probably also be adjusted. But yes I'd think it deserves a new shader and share the common code via Shader Chunks?
I'd be happy to review PRs because I probably do not have time in the near future to implement it myself. Also, lots of great things can be done to improve this shader to add realistic lightings and so on ;).
And a WebGL1 implementation of those shaders (for fallback) by emulating the 3D textures would be great too btw :P
https://github.com/mrdoob/three.js/blob/dev/examples/webgl2_materials_texture3d.html#L53 has a cautionary comment
// Create camera (The volume renderer does not work very well with perspective yet)
.This seemed worth an issue. Perhaps VolumeShader can be improved? Perhaps we need a second shader, which works well with perspective? Perhaps the caution is no longer true, can be removed to avoid confusion, and the example reverted to using perspective (to turn up any remaining problems)?
The example switched from PerspectiveCamera to OrthographicCamera in https://github.com/mrdoob/three.js/commit/5ab8129d92e249119f542a362657a1103c55f9df . VolumeShader is https://github.com/mrdoob/three.js/blob/dev/examples/jsm/shaders/VolumeShader.js . Thank you for your work.
@Mugen87 @takahirox @almarklein