Main Menu

Shadow Casting Demo - PlayBASIC Source Code

Member

  The Shadows Demo is a 3D simulation written in PlayBASIC that renders a scene filled with animated cubes and vertical frame-like goal structures under a dynamic light source. It demonstrates basic 3D projection, object creation, face coloring, movement animation, and real-time shadow effects, though the actual shadow drawing appears to be simplified or symbolic rather than full shadow mapping.







📐 Key Features & Flow

1. Projection Setup

* The scene uses a simple 3D to 2D projection method:
 * `ProjectionX#` and `ProjectionY#` define the projection scaling.
 * The screen center is calculated using `getscreenwidth()` and `getscreenheight()`.


2. Geometry Initialization

• A cube is defined with:
 • 8 vertices (points in 3D space).
 • 6 faces (each face has 4 indices pointing to those vertices).
• These values are read into arrays (`Points#()` and `Faces()`).


3. Object Types and Buffers

• Several user-defined types (`tVertex3`, `tFace`, `tObject`) are used to store:
 • Object positions, scales, rotations.
 • Raw, rotated, projected, and shadow vertex data.
 • Face information and color indices.


4. Scene Construction: MakeScene()

• Creates:
 • Several goal frame structures using `MakeGoal()` (U-shaped objects).
 • Dozens of randomly placed cubes via `NewCube()` with randomized scale and animation.



5. Lighting

• A `tLight` type represents the light source.
 • It has a dynamic position that moves in a sinusoidal path for a smooth animated lighting effect.
 • A sprite visually represents the light in the scene.


6. Main Loop (`Do...Loop`)

Every frame:
• The screen is cleared and a list of 3D rays (`tRays`) is allocated.
• The scene is rendered in two passes:
 • Pass 0: Render geometry into a buffer with blending inkmode.
 • Pass 1: Capture geometry to scene and clear buffer.
• Objects are drawn with `drawobject()`.
• Light and camera are rendered on top.
• Object animations are updated via `StepObjects()`.
• Light moves using sin/cos functions to simulate a swinging overhead light.
• Camera can be moved with arrow keys.
• Pressing [Enter] regenerates the scene.

7. Rendering

• `ProjectPoint()` projects a 3D point to 2D screen space.
• `DrawLight()` draws the light sprite at the projected light position.
• Cubes are created with vertices and faces using `NewCube()`:
 • Each face gets a random color.
 • Object buffers are initialized and filled with geometry data.



🎯 Main Purpose

The demo showcases how to:
• Build and animate multiple 3D objects.
• Project 3D geometry to 2D screen space.
• Simulate dynamic lighting.
• Maintain structured vertex/face data per object.
• Use custom types and buffers for modular object management.



🧱 Visual Output

• You'll see a field of colorful spinning cubes and vertical U-shaped frames.
• A glowing light sprite moves above the scene.
• The camera can be moved in X/Z directions using the arrow keys.
• Realistic shadows are implied but not explicitly drawn; however, structure for shadow projection is prepared (`ShadowVertexBuffer`, `DrawRays`, etc.).


#lowpoly #coding #3d #demo #shadows  #retrodev #retro #softwarerendering
#CodingTutorial  #GameProgramming  #GraphicsProgramming  #CodeExample  #GameDesign  #IndieGames  #DevLog  #ClassicGameDev  #ProgrammersLife  #GameDevCommunity

Download

   Attached bellow

Member

#1
Shadow Casting With Animated Characters

    This version extends upon the previous demo and includes an animated 3D character in the test scene as well as the random cubes and goal posts.    The demo computes the shadows at every vertex in the scene and then renders them to the ground..  It's one of those simple ideas that creates an interesting result. 

    The object loading is handled by a PolyWOLF objects library,  which has been expanding to support loading and saving it's own binary format objects.  To create the object in these scene I load it into PolyWolf and then saved it out.  That way there's no need to including various object loading formats just for a simple 3d scene..


   

 
Download

  Attached bellow