Skip to content

Commit 2c46b3d

Browse files
committed
Dispatch all instances immediately if depth_sort is false
Disables special handling of transparency and translucency.
1 parent 8f134fb commit 2c46b3d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

docs/canvas3d.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ other. The default is `:over`.
144144
`depth_sort=` [ `true` | `false` ]
145145
: Controls the depth-sorting phase of [instance ordering](#instance-ordering).
146146
Setting this to `false` will result in instances of the same model being
147-
dispatched for rendering in an arbitrary order. The default is `true`.
147+
dispatched for rendering in an arbitrary order and will disrupt correct handling
148+
of transparent and translucent objects. The default is `true`.
148149

149150
`depth_test=` [ `true` | `false` ]
150151
: Turn off OpenGL depth-testing for this render group if set to `false`, the
@@ -223,12 +224,13 @@ transparency to render incorrectly. Depth sorting can be controlled for a
223224
specific render group with the `depth_sort` attribute.
224225

225226
Turning off depth sorting will cause all instances to be dispatched to the GPU
226-
in an arbitrary order instead of front-to-back or back-to-front. For
227-
non-transparent objects this will have no visual effect as the depth buffer
228-
will resolve overlaps. However, for overlapping transparent objects this may
229-
result in odd inversions. When rendering large numbers of small, non-transparent
230-
objects, it may be faster to turn off depth sorting and let the depth buffer
231-
handle overlaps. If depth buffer testing has been disabled with
227+
in an arbitrary order instead of front-to-back or back-to-front, regardless
228+
of whether they have transparency or translucency. For non-transparent objects
229+
this will have no visual effect as the depth buffer will resolve overlaps.
230+
However, transparent and translucent objects will likely render incorrectly,
231+
showing the wrong objects behind. When rendering large numbers of small,
232+
non-transparent objects, it may be faster to turn off depth sorting and let the
233+
depth buffer handle overlaps. If depth buffer testing has been disabled with
232234
`depth_test=false`, then depth sorting is also automatically disabled.
233235

234236

src/flitter/render/window/canvas3d.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,11 @@ cdef void render(render_target, RenderGroup render_group, Camera camera, glctx,
807807
for i in indices:
808808
instance = instances[i]
809809
material = instance.material
810-
if material.translucency > 0:
811-
translucent_objects.append((zs[i] if depth_sorted else 0, model, instance))
812-
transparent_objects.append((-zs[i] if depth_sorted else 0, model, instance))
813-
elif (material.transparency > 0 or has_transparency_texture):
814-
transparent_objects.append((-zs[i] if depth_sorted else 0, model, instance))
810+
if depth_sorted and material.translucency > 0:
811+
translucent_objects.append((zs[i], model, instance))
812+
transparent_objects.append((-zs[i], model, instance))
813+
elif depth_sorted and (material.transparency > 0 or has_transparency_texture):
814+
transparent_objects.append((-zs[i], model, instance))
815815
else:
816816
src = instance.model_matrix.numbers
817817
dest = &instances_data[k, 0]

0 commit comments

Comments
 (0)