.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_depth_overlay2.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_validation_validate_depth_overlay2.py: Depth Overlay 2 =============== Example (and test) for behavior of the depth buffer w.r.t. overlays, implemented using ``Material.depth_test``. The overlaid object should always be on top. .. GENERATED FROM PYTHON SOURCE LINES 9-56 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_depth_overlay2_001.webp :alt: validate depth overlay2 :srcset: /_gallery/validation/images/sphx_glr_validate_depth_overlay2_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import pylinalg as la # Create a canvas and renderer canvas = RenderCanvas(size=(500, 300)) renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() # Compose a scene with a 3D cube at the origin # Define cubes in the order that we want them rendered cubes = [ (2.0, "#f00", 1), (1.8, "#ff0", 1), (1.6, "#0f0", 2), (1.4, "#0ff", 2), ] # We can mangle them a bit, because we define render order cubes = cubes[2:] + cubes[0:2] for size, color, render_order in cubes: cube = gfx.Mesh( gfx.box_geometry(size, size, size), gfx.MeshPhongMaterial(color=color, side="front", depth_test=False), ) cube.render_order = render_order rot = la.quat_from_euler((0.2, 0.3), order="XY") cube.local.rotation = la.quat_mul(rot, cube.local.rotation) scene.add(cube) # Camera camera = gfx.OrthographicCamera(3, 3) scene.add(camera.add(gfx.DirectionalLight())) canvas.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.199 seconds) .. _sphx_glr_download__gallery_validation_validate_depth_overlay2.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_depth_overlay2.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_depth_overlay2.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_depth_overlay2.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html