Activity

praneelpatel0

The goal of this stage was to implement physically based lighting and introduce shadows, allowing the renderer to simulate how light interacts with surfaces in a realistic way.

Diffuse lighting was implemented using Lambert’s cosine law, which models how light scatters off rough surfaces. At each ray–object intersection, the surface normal is compared with the direction to a point light source using a dot product. This determines how bright the surface appears based on its orientation relative to the light.

To improve realism, shadow rays were introduced. After a surface is hit, a secondary ray is cast toward the light source to test whether another object blocks the light. If an intersection occurs before the light is reached, the surface is considered to be in shadow and only receives ambient illumination.

This stage marks a major step toward realism. Objects are no longer just shaded based on orientation but now respond to light visibility within the scene. The renderer now produces images with clear depth cues, lighting direction, and object shadows, all derived from physically meaningful ray calculations.

Attachment
0
praneelpatel0

The goal of this task was to expand the ray tracing engine to handle multiple objects and a basic scene layout, laying the groundwork for more realistic rendering and depth perception. Previously, the engine could generate a single floating sphere with a sky gradient. Now, I wanted to create a scene that feels more like a real 3D space.

I added a “ground plane” by simulating a large sphere beneath the floating sphere. This allows the scene to have a sense of scale and perspective without adding complex geometry. The engine now supports multiple objects by checking ray intersections with each sphere in the scene and choosing the nearest hit. Each intersection still calculates the surface normal.

With this setup, the engine can render a floating sphere above a ground plane while maintaining a smooth sky gradient in the background. Look at the attached image for the rendering!

Attachment
1

Comments

kuratus89
kuratus89 2 months ago

The scene setup is elegant and well thought out. Supporting multiple object intersections and selecting the nearest hit demonstrates a solid understanding of ray tracing fundamentals and scene composition.

praneelpatel0

The goal of this stage was to build the core mathematical and physical foundation of the ray tracing engine. Before rendering any objects or realistic lighting, I needed a way to represent 3D space, light rays, and a camera, and then convert that information into an image.

  • I built a 3D vector system (Vec3 class) to represent 3D vectors. This class includes vector addition and subtraction, scalar multiplication and division, magnitude, vector normalization, and dot product.
  • I created a Ray class to model the light rays using a parametric equation: A ray vector with a origin vector and distance vector with respect to time.
  • I implemented a simple pinhole camera model. For each pixel in the image, a ray is generated from the camera origin, the ray passes through a virtual viewport, the ray’s direction is that pixel’s position.
  • The rendered outputs PPM file format, allowing raw pixel data to be written correctly without external libraries.

The program successfully generates a smooth sky gradient image by mapping ray direction to color. Each pixel is the result of a physically meaningful ray calculation rather than a simple screen-space effect.

Stay tuned for the source code!

Attachment
2

Comments

07mandao
07mandao 2 months ago

epic

elite_punith
elite_punith 2 months ago

great