|
1 | 1 | import * as THREE from 'three';
|
2 | 2 | import Camera from 'Renderer/Camera';
|
3 | 3 | import MainLoop, { MAIN_LOOP_EVENTS, RENDERING_PAUSED } from 'Core/MainLoop';
|
| 4 | +import Capabilities from 'Core/System/Capabilities'; |
4 | 5 | import { COLOR_LAYERS_ORDER_CHANGED } from 'Renderer/ColorLayersOrdering';
|
5 | 6 | import c3DEngine from 'Renderer/c3DEngine';
|
6 | 7 | import RenderMode from 'Renderer/RenderMode';
|
@@ -974,25 +975,32 @@ class View extends THREE.EventDispatcher {
|
974 | 975 | screen.x = (mouse.x / dim.x) * 2 - 1;
|
975 | 976 | screen.y = -(mouse.y / dim.y) * 2 + 1;
|
976 | 977 |
|
977 |
| - // Origin |
978 |
| - ray.origin.copy(camera.position); |
979 |
| - |
980 |
| - // Direction |
981 |
| - ray.direction.set(screen.x, screen.y, 0.5); |
982 |
| - // Unproject |
983 |
| - matrix.multiplyMatrices(camera.matrixWorld, matrix.copy(camera.projectionMatrix).invert()); |
984 |
| - ray.direction.applyMatrix4(matrix); |
985 |
| - ray.direction.sub(ray.origin); |
986 |
| - |
987 |
| - direction.set(0, 0, 1.0); |
988 |
| - direction.applyMatrix4(matrix); |
989 |
| - direction.sub(ray.origin); |
990 |
| - |
991 |
| - const angle = direction.angleTo(ray.direction); |
992 |
| - const orthoZ = g.depthBufferRGBAValueToOrthoZ(buffer, camera); |
993 |
| - const length = orthoZ / Math.cos(angle); |
| 978 | + if (Capabilities.isLogDepthBufferSupported() && camera.type == 'PerspectiveCamera') { |
| 979 | + // TODO: solve this part with gl_FragCoord_Z and unproject |
| 980 | + // Origin |
| 981 | + ray.origin.copy(camera.position); |
| 982 | + |
| 983 | + // Direction |
| 984 | + ray.direction.set(screen.x, screen.y, 0.5); |
| 985 | + // Unproject |
| 986 | + matrix.multiplyMatrices(camera.matrixWorld, matrix.copy(camera.projectionMatrix).invert()); |
| 987 | + ray.direction.applyMatrix4(matrix); |
| 988 | + ray.direction.sub(ray.origin); |
| 989 | + |
| 990 | + direction.set(0, 0, 1.0); |
| 991 | + direction.applyMatrix4(matrix); |
| 992 | + direction.sub(ray.origin); |
| 993 | + |
| 994 | + const angle = direction.angleTo(ray.direction); |
| 995 | + const orthoZ = g.depthBufferRGBAValueToOrthoZ(buffer, camera); |
| 996 | + const length = orthoZ / Math.cos(angle); |
| 997 | + target.addVectors(camera.position, ray.direction.setLength(length)); |
| 998 | + } else { |
| 999 | + const gl_FragCoord_Z = g.depthBufferRGBAValueToOrthoZ(buffer, camera); |
994 | 1000 |
|
995 |
| - target.addVectors(camera.position, ray.direction.setLength(length)); |
| 1001 | + target.set(screen.x, screen.y, gl_FragCoord_Z); |
| 1002 | + target.unproject(camera); |
| 1003 | + } |
996 | 1004 |
|
997 | 1005 | camera.layers.mask = prev;
|
998 | 1006 |
|
|
0 commit comments