Class ScreenSpaceTessellator

java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.tessellation.ScreenSpaceTessellator

public class ScreenSpaceTessellator extends Object
Tessellates textured polygons based on screen-space edge lengths.

This tessellator splits triangles recursively based on how large they appear on screen (in pixels), rather than world-space dimensions. This provides per-polygon level-of-detail tessellation that adapts to camera distance naturally.

Tessellation algorithm:

  1. Compute screen-space lengths of all three edges (pixels)
  2. If longest edge ≤ maxScreenPixels, emit the triangle as-is
  3. Otherwise, split the longest edge at its midpoint
  4. Interpolate: world coordinates, texture coordinates, screen coordinates, Z-depth
  5. Recurse on the two resulting sub-triangles

Safeguards against excessive tessellation:

  • Maximum recursion depth (prevents infinite/very deep recursion)
  • Maximum triangles per original polygon (hard limit on output)
  • Maximum screen-space edge length (skip tessellation for huge off-screen polygons)

The resulting TessellatedTexturedTriangle instances have pre-computed screen coordinates, avoiding redundant transformation during the render phase.

See Also:
  • Constructor Details

    • ScreenSpaceTessellator

      public ScreenSpaceTessellator(double maxScreenPixels)
      Creates a tessellator with the specified maximum screen-space edge length.
      Parameters:
      maxScreenPixels - the maximum allowed edge length in screen pixels; edges longer than this will be subdivided
  • Method Details

    • setMaxScreenPixels

      public void setMaxScreenPixels(double maxScreenPixels)
      Updates the maximum screen-space edge length threshold.

      This method allows adaptive tessellation control by updating the threshold before each tessellation operation. Called from AdaptiveTessellationController.

      Parameters:
      maxScreenPixels - the new maximum allowed edge length in screen pixels
    • getResult

      public List<TessellatedTexturedTriangle> getResult()
      Returns the list of tessellated triangles.
      Returns:
      the resulting tessellated triangles
    • tessellate

      public void tessellate(TexturedTriangle original)
      Tessellates the given textured triangle into smaller triangles.

      After calling this method, retrieve the resulting sub-triangles via getResult(). The original triangle's texture reference and backface culling settings are preserved on all sub-triangles.

      Safeguards prevent excessive tessellation when the polygon is extremely large on screen (e.g., when camera is very close).

      Parameters:
      original - the triangle to tessellate (must have screen coords computed)