Skip to content

el-dockerr/PixelTrace-Render-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

PixelTrace - True Light Simulation Renderer

PixelTrace Render Example

๐ŸŒŸ What Makes PixelTrace Different?

PixelTrace is not a rendering engine. It's a light simulation.

While traditional game engines and renderers use clever tricks to approximate what things look like, PixelTrace simulates how light actually behaves in the real world. This is the difference between painting a picture of reality and letting reality paint itself.


๐Ÿ”ฌ The Philosophy: Physics, Not Tricks

How Traditional Engines Work (The Tricks)

Most rendering engines use rasterization and a collection of hacks accumulated over decades:

Technique What It Fakes The Problem
Shadow Maps Shadows Aliased edges, limited resolution, no soft shadows
Screen-Space Reflections Reflections Can't reflect objects outside the screen
Ambient Occlusion (SSAO) Indirect shadows Only approximates local occlusion
Light Probes Global illumination Static, pre-baked, doesn't react to changes
Reflection Probes Environment reflections Low resolution, parallax errors
Bloom Light glow Post-process effect, not real light scatter
Fake Subsurface Scattering Light through skin Shader trick, not actual light transport

These tricks are fast, but they're fundamentally lies. They approximate what a human expects to see, not what physics dictates they would see.

How PixelTrace Works (The Truth)

PixelTrace uses Light Tracing (also called Photon Tracing) - a physically accurate simulation:

1. Light leaves the source (like a real photon)
2. Light travels through space
3. Light hits a surface
4. Light bounces (specular) or scatters (diffuse)
5. If the camera can see that illuminated point โ†’ pixel is colored
6. Repeat billions of times

This is exactly how your eyes work:

  • You don't see objects. You see light that bounced off objects.
  • PixelTrace simulates this directly.

๐Ÿ‘๏ธ Simulating Human Vision

Why "Reverse" Ray Tracing?

Traditional ray tracing shoots rays from the camera into the scene. This is computationally efficient but backwards from reality.

In nature:

Sun โ†’ Surface โ†’ Surface โ†’ Surface โ†’ Eye

In traditional ray tracing:

Eye โ†’ Surface โ†’ Surface โ†’ Light (backwards!)

In PixelTrace:

Light โ†’ Surface โ†’ Surface โ†’ Camera (natural!)

By tracing light forward from sources, PixelTrace naturally captures phenomena that are extremely difficult to fake:

Phenomenon Traditional Engines PixelTrace
Caustics (light focusing through glass) Special case shaders Emerges naturally
Color bleeding (light picks up surface color) Fake with probes Physically accurate
Soft shadows Multiple shadow maps Natural penumbra
Indirect illumination Baked lightmaps Real-time accurate
Multiple light bounces Usually 1-2 max Unlimited

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Light Source                      โ”‚
โ”‚            (emits rays in all directions)            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Ray Tracing                        โ”‚
โ”‚  โ€ข Find intersection with scene geometry             โ”‚
โ”‚  โ€ข Calculate surface properties                      โ”‚
โ”‚  โ€ข Determine energy transfer                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ–ผ                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Specular Bounce โ”‚     โ”‚ Diffuse Scatter โ”‚
โ”‚ (mirror reflect)โ”‚     โ”‚ (spread in      โ”‚
โ”‚                 โ”‚     โ”‚  hemisphere)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚
                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Camera Visibility Test                  โ”‚
โ”‚  โ€ข Project hit point to screen coordinates           โ”‚
โ”‚  โ€ข Check if camera can see the point                 โ”‚
โ”‚  โ€ข Check for occlusion                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   ScreenStack                        โ”‚
โ”‚         (accumulates light contributions)            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽจ Current Features

  • True Light Tracing: Light emanates from sources, not camera
  • Spherical Light Emission: Configurable angular resolution
  • Specular Reflection: Perfect mirror bounces
  • Diffuse Scattering: Light spreads across surfaces realistically
  • Energy Conservation: Light loses energy with each bounce
  • Material System: Ambient, diffuse, specular, shininess properties
  • JSON Scene Format: Easy to create and modify scenes
  • Multi-bounce Illumination: Configurable bounce depth

๐Ÿ“Š Comparison with Industry Standards

Feature Unreal/Unity Traditional Path Tracer PixelTrace
Light direction Cameraโ†’Scene Cameraโ†’Light Lightโ†’Camera
Real-time capable Yes (with tricks) No Future goal
Physically accurate No Yes Yes
Caustics Fake/None Difficult Natural
Matches human vision Approximation Backwards Exact model

๐Ÿš€ Future Improvements

Short Term

  • Sphere primitive support
  • Plane/ground support
  • Multiple light sources
  • Transparent materials (glass, water)
  • Texture mapping

Medium Term

  • Refraction (light bending through materials)
  • Volumetric effects (fog, atmosphere)
  • Area lights (soft shadows)
  • Depth of field
  • Motion blur

Long Term

  • GPU acceleration (CUDA/OpenCL)
  • Real-time progressive rendering
  • Spectral rendering (wavelength-accurate color)
  • Polarization effects
  • Fluorescence

๐Ÿง  The Vision

"The goal is not to render images. The goal is to simulate reality and let images emerge."

Most engines ask: "How do I make this look right?"

PixelTrace asks: "How does light actually work?"

When you simulate physics correctly, correct images are the inevitable result. There are no edge cases to handle, no special shaders to write, no tricks to learn. Just physics.

This is the first step toward true visual simulation - rendering that works exactly like human vision, because it follows the same physical laws.


๐Ÿ“ Project Structure

PixelTrace/
โ”œโ”€โ”€ main.cpp              # Application entry point
โ”œโ”€โ”€ ScreenStack.h/cpp     # Pixel buffer (virtual screen)
โ”œโ”€โ”€ PixelTraceRenderer.h/cpp  # Core light tracing engine
โ”œโ”€โ”€ Scene.h/cpp           # Scene loader (JSON)
โ”œโ”€โ”€ Vec3.h                # 3D vector mathematics
โ”œโ”€โ”€ Ray.h                 # Light ray structure
โ”œโ”€โ”€ HitResult.h           # Intersection results
โ”œโ”€โ”€ Intersect.h           # Geometry intersection tests
โ”œโ”€โ”€ CameraProjection.h    # World-to-screen projection
โ”œโ”€โ”€ Camera.h              # Camera definition
โ”œโ”€โ”€ Light.h               # Light source definition
โ”œโ”€โ”€ Material.h            # Surface material properties
โ”œโ”€โ”€ SceneObject.h         # Scene object definition
โ””โ”€โ”€ scenes/
    โ””โ”€โ”€ default_scene.json  # Example scene

๐ŸŽฎ Usage

// Configure the renderer
PixelTraceRenderer renderer(screenStack);
renderer.SetAngleStep(0.1f);    // Light ray density (smaller = more rays)
renderer.SetMaxBounces(3);       // How many times light can bounce

// Load and render
renderer.LoadScene("scenes/default_scene.json");
renderer.Render();

๐Ÿ› ๏ธ Build (Ubuntu / Linux)

Prerequisites

  • CMake 3.16+
  • GCC/G++ with C++17 support
  • Make or Ninja

Build

cmake -S . -B build
cmake --build build -j

Run

./build/PixelTrace

By default this renders PixelTrace/scenes/default_scene.json and writes a render.ppm image in the current working directory.

You can also pass custom paths:

./build/PixelTrace <scene.json> <output.ppm>

Output Format Notes

  • Linux (current path): the renderer writes a .ppm file.
  • Why PPM: it is intentionally simple and dependency-free, so output works reliably without adding extra image libraries.
  • Windows: the Win32 entry point opens a real-time render window and displays pixels directly while rendering.

If needed, convert PPM to PNG after rendering:

convert render.ppm render.png

๐Ÿ“œ License

This project is a proof-of-concept demonstrating physically-based light simulation.


"We don't see the world. We see the light that the world reflects into our eyes. PixelTrace simulates exactly that."

About

A true light render engine.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors