Commit 5a1d12b6 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

ENH: Adjust depth values in GL14

parent 2938067c
......@@ -122,12 +122,16 @@ MOV skipTest, 1;
MOV finalColour, startingColour;
# Set depth.w > 0 if depth has
# not been set, < 0 otherwise.
# If depth has already been set,
# we want to pass through its
# initial value.
SUB depth.w, 0, finalColour.a;
# Set depth.w < 0 if depth has already been
# set in a previous pass, > 0 otherwise. If
# depth has already been set, we want to pass
# through that value, rather than calculating
# it again. Initial value for a depth texture
# is 1 (and depth textures are clamped to 0
# [closer to screen], 1 [farther from screen]),
# so if it is < 1, we assume it has already
# been set.
SUB depth.w, depth.x, 1;
CMP depth.w, depth.w, -1, 1;
......@@ -209,7 +213,10 @@ MIN skipTest.x, skipTest.x, tempVar.x;
# Check whether the accumulated
# colour alpha is already high enough
# colour alpha is already high enough.
# If it is, we don't consider the
# values from any more samples on the
# ray.
SLT tempVar.x, finalColour.a, 0.95;
MAD tempVar.x, tempVar.x, 2.0, -1;
MIN skipTest.x, skipTest.x, tempVar.x;
......@@ -250,32 +257,53 @@ MUL colour.rgb, colour, colour.a;
SUB tempVar.x, 1, finalColour.a;
MAD tempColour, tempVar.x, colour, finalColour;
# Figure out if we should consider this
# sample for depth calculation:
# - skipTest.x tells us whether this sample
# should be discarded
# - depth.w tells us whether we already have
# a depth value
# - {{ param_screenSize }}.z tells us whether
# we are modulating alpha by voxel intensity
# (depth is calculated differently depending
# on whether we are or not)
#
# If modulating alpha by voxel intensity, we
# take the depth of the first sample on the ray
# with intensity >= 0.1 (voxel values are
# normalised to [0, 1] w.r.t. current display
# range).
#
# If not blending by voxel intensity, we
# take the depth of the first sample.
#
# We accumulate all of these conditionals into
# tempVar.x, such that it is == 0 if we should
# take the depth value from this sample, < 0
# otherwise.
SLT tempVar.x, skipTest.x, 0; # set if should skip
SLT tempVar.y, depth.w, 0; # set if already have depth
SLT tempVar.z, voxValue.x, 0.1; # set if below threshold
ADD tempVar.z, tempVar.z, {{ param_screenSize }}.z; # and blending by intensity
SGE tempVar.z, tempVar.z, 2;
ADD tempVar.x, tempVar.x, tempVar.y;
ADD tempVar.x, tempVar.x, tempVar.z;
MUL tempVar.x, tempVar.x, -1;
# Calculate the screen depth of
# the current ray position. If we
# have just taken our first sample,
# save the depth, as we will use
# it for the final fragment depth.
# Figure out if this is the first
# sample taken by testing whether
# skipTest.x > 0, and depth.w > 0
# (the latter is true if the
# startingColour.a == 0).
ADD depth.y, depth.w, skipTest.x;
MUL depth.y, depth.y, -1;
DP4 depth.z, {{ param_tex2ScreenXform }}, texCoord;
CMP depth.x, depth.y, depth.z, depth.x;
# Calculate the screen depth of the
# current ray position, storing it
# in tempvar.z
DP4 tempVar.z, {{ param_tex2ScreenXform }}, texCoord;
# Save the depth value to depth.x, based on
# conditional tests above.
CMP depth.x, tempVar.x, depth.x, tempVar.z;
# If we have just set the depth,
# set depth.w to < 0 so that we
# don't overwrite the depth on a
# subsequent sample.
SUB depth.y, depth.w, skipTest.x;
MAD depth.y, depth.y, -1, 0.5;
CMP depth.w, depth.y, 1, -1;
CMP depth.w, tempVar.x, depth.w, -1;
# Only update the accumulated colour
......@@ -294,9 +322,25 @@ CMP finalColour, skipTest.x, finalColour, tempColour;
ADD texCoord.xyz, texCoord, {{ param_rayStep }};
ADD clipTexCoord.xyz, clipTexCoord, {{ param_rayStep }};
{% endfor %}
# set tempVar.w to -1 if this is the final
# pass, and we still don't have a depth
# value, 0 otherwise.
SGE tempVar.x, {{ param_settings }}.z, 1;
SGE tempVar.y, depth.w, 1;
ADD tempVar.x, tempVar.x, tempVar.y;
SGE tempVar.x, tempVar.x, 2;
MUL tempVar.w, tempVar.x, -1;
# Calculate the depth value corresponding
# to the very first sample in this ray.
ADD tempVar.xyz, {{ param_rayStep }}, {{ varying_texCoord }};
DP4 tempVar.z, {{ param_tex2ScreenXform }}, tempVar;
# Use it if we don't already have a depth
CMP depth.x, tempVar.w, tempVar.z, depth.x;
# If startingColour.a == 0 and
# finalColour.a == 0,
......
......@@ -256,6 +256,14 @@ def draw3D(self, xform=None, bbox=None):
with glroutines.enabled((gl.GL_VERTEX_ARRAY)), \
glroutines.disabled((gl.GL_BLEND)):
# The depth value for a fragment will
# not necessary be set at the same
# time that the fragment colour is
# set, so we need to use <= for depth
# testing so that unset depth values
# do not cause depth clipping.
gl.glDepthFunc(gl.GL_LEQUAL)
for i in range(outerLoop):
settings = list(settings)
......@@ -280,6 +288,8 @@ def draw3D(self, xform=None, bbox=None):
dest, src = src, dest
gl.glDepthFunc(gl.GL_LESS)
shader.unloadAtts()
shader.unload()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment