Fix rendering depth pass

This commit is contained in:
fieldOfView 2018-03-13 19:44:53 +01:00
parent 0caea24afc
commit 73558c9e36
3 changed files with 10 additions and 8 deletions

View file

@ -17,7 +17,7 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
# Note that in order to increase precision, the 24 bit depth value is encoded into all three of the R,G & B channels
class DepthPass(RenderPass):
def __init__(self, width: int, height: int):
super().__init__("preview", width, height, 0)
super().__init__("depth", width, height)
self._renderer = Application.getInstance().getRenderer()
@ -29,7 +29,9 @@ class DepthPass(RenderPass):
if not self._shader:
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "camera_distance.shader"))
self._gl.glClearColor(0.0, 0.0, 0.0, 0.0)
width, height = self.getSize()
self._gl.glViewport(0, 0, width, height)
self._gl.glClearColor(1.0, 1.0, 1.0, 0.0)
self._gl.glClear(self._gl.GL_COLOR_BUFFER_BIT | self._gl.GL_DEPTH_BUFFER_BIT)
# Create a new batch to be rendered
@ -57,4 +59,5 @@ class DepthPass(RenderPass):
return None
distance = output.pixel(px, py) # distance in micron, from in r, g & b channels
return distance / 1000.
distance = (distance & 0x00ffffff) / 1000. # drop the alpha channel and covert to mm
return distance

View file

@ -31,8 +31,7 @@ class SupportEraser(Tool):
active_camera = self._controller.getScene().getActiveCamera()
# Create depth pass for picking
render_width, render_height = active_camera.getWindowSize()
depth_pass = DepthPass(int(render_width), int(render_height))
depth_pass = DepthPass(active_camera.getViewportWidth(), active_camera.getViewportHeight())
depth_pass.render()
distance = depth_pass.getDepthAtPosition(event.x, event.y)

View file

@ -63,9 +63,9 @@ fragment41core =
highp float distance_to_camera = distance(v_vertex, u_viewPosition) * 1000.; // distance in micron
vec3 encoded; // encode float into 3 8-bit channels; this gives a precision of a micron at a range of up to ~16 meter
encoded.b = floor(distance_to_camera / 65536.0);
encoded.g = floor((distance_to_camera - encoded.b * 65536.0) / 256.0);
encoded.r = floor(distance_to_camera - encoded.b * 65536.0 - encoded.g * 256.0);
encoded.r = floor(distance_to_camera / 65536.0);
encoded.g = floor((distance_to_camera - encoded.r * 65536.0) / 256.0);
encoded.b = floor(distance_to_camera - encoded.r * 65536.0 - encoded.g * 256.0);
frag_color.rgb = encoded / 255.;
frag_color.a = 1.0;