Skip to content

Extension update: <3D Sprite> #1956

@Carrotstudio0

Description

@Carrotstudio0

Changes

Bug Fixes

Fixed Sudden Background Appearance Issue

  • Resolved rendering artifacts where backgrounds would suddenly appear or flash during sprite rendering
  • Improved depth buffer management with proper depthWrite, depthTest, and depthFunc settings
  • Added polygon offset (polygonOffsetFactor: -1, polygonOffsetUnits: -1) to prevent z-fighting between overlapping surfaces
  • Enhanced alpha testing with alphaTest: 0.5 threshold to eliminate semi-transparent pixel artifacts
  • Implemented premultiplied alpha blending for cleaner transparency handling

JavaScript Compatibility Fix

  • Replaced optional chaining operator (?.) with traditional null checking for better compatibility with GDevelop's JavaScript runtime
  • Ensures the extension works across all GDevelop versions without syntax errors

New Features

Advanced Material System

  • Double-sided rendering - Sprites now render correctly from both front and back
  • Enhanced shadow support - Objects can now cast and receive shadows properly
  • Tone mapping integration - Improved color accuracy and lighting response
  • Fog support - Sprites properly interact with scene fog effects
  • Emissive lighting - Added subtle glow effect with configurable intensity

Dynamic Auto-Rotation System- Velocity-based pitch rotation - Sprites automatically tilt based on vertical movement speed (max 15°)

  • Velocity-based yaw rotation - Sprites lean into horizontal movement direction (max 10°)
  • Smooth interpolation - All rotations use lerp for fluid, natural motion
  • Toggle support - Can be enabled/disabled via setAutoRotation(bool)

Depth Perspective Effects

  • Distance-based scaling - Objects automatically scale down as they move further away
  • Height-based scaling - Additional scaling factor based on Y position for enhanced depth perception
  • Realistic 3D feel - Creates convincing pseudo-3D perspective in 2D scenes

Dynamic Render Ordering

  • Z-position based sorting - Automatic render order calculation using Z and Y coordinates
  • Prevents visual layering issues - Ensures sprites render in correct depth order
  • Manual depth offset - Additional control via setDepthOffset(number) method

Enhanced Control Methods

  • setDepthOffset(offset) - Manually adjust sprite depth position
  • setAutoRotation(enabled) - Toggle automatic rotation behavior on/off
  • setRotationAngle(axis, angle) - Set specific rotation angles on X, Y, or Z axis

Performance Optimizations

  • Frustum culling enabled - Off-screen objects are automatically skipped
  • Vertex color support - Added vertex color attributes for advanced rendering techniques
  • Optimized rotation order - Using YXZ order for more natural sprite orientation

Technical Improvements

  • Improved collision mask handling - Better support for custom collision shapes
  • Enhanced AABB calculations - More accurate bounding box updates
  • Material update optimization - Settings now properly sync on frame changes
  • Better shadow rendering - Separated castShadow and shadowSide controls
Image

How to use the new features

Auto Rotation

Enable dynamic tilting based on movement:

sprite3DRenderer.setAutoRotation(true);  // Enable (default)
sprite3DRenderer.setAutoRotation(false); // Disable

Manual Rotation

Set specific angles in degrees:

sprite3DRenderer.setRotationAngle('x', 45);  // Pitch
sprite3DRenderer.setRotationAngle('y', 30);  // Yaw
sprite3DRenderer.setRotationAngle('z', 90);  // Roll

Depth Offset

Adjust sprite layering:

sprite3DRenderer.setDepthOffset(10);   // Move forward
sprite3DRenderer.setDepthOffset(-10);  // Move backward
sprite3DRenderer.setDepthOffset(0);    // Reset

Automatic Features

These work automatically with no code needed:

  • Depth-based scaling (distant objects appear smaller)
  • Shadow casting and receiving
  • Improved transparency rendering
  • Z-fighting prevention

Checklist

  • I've followed all of the best practices.
  • I confirm that this extension can be integrated to this GitHub repository, distributed and MIT licensed.
  • I am aware that the extension may be updated by anyone, and do not need my explicit consent to do so.

Example file

Sprite3DExample.zip

Extension file

Sprite3D.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔄 Extension updateAn update for an existing extension🧪 Experimental extensionAn extension submission to be merged with a lightweight review.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions