TinyRaytracer 0.1
A simple C++ raytracer
|
#include "libpng.h"
#include "helper.hpp"
#include "keywords.hpp"
#include "struct.hpp"
#include <vector>
#include <tuple>
Go to the source code of this file.
Functions | |
void | render (Image &img) |
The render function that loops over the screen of pixels. More... | |
RGBA | shootPrimaryRay (double x, double y) |
Shoots a primary ray into the scene, at pixel location (x,y). More... | |
ObjectInfo | hitNearest (Ray &ray) |
Gets the nearest object in the path of the ray. More... | |
ObjectInfo | hitMiss () |
Does nothing. More... | |
RGBA | diffuseLight (const ObjectInfo &obj) |
Get the diffuse light color,with shadow checking. More... | |
RGBA | reflectionLight (const Ray &ray, const ObjectInfo &obj) |
Get the reflection light color. More... | |
RGBA | refractionLight (const Ray &ray, const ObjectInfo &obj) |
Get the refraction light color. More... | |
RGBA | globalIllumination (const ObjectInfo &obj, int gi_bounce) |
Get the global illumination light color. More... | |
ObjectInfo | checkPlane (Ray &ray, bool exit_early=false) |
Check if any planes are intersecting with the ray. More... | |
RGBA | getColorSun (double lambert, RGB objColor, RGB lightColor) |
Get the Color of Sun (directional light) More... | |
RGBA | getColorBulb (double lambert, RGB objColor, RGB lightColor, double t) |
Get the Color of Bulb (scene light) More... | |
RGBA | getTexture () |
ObjectInfo checkPlane | ( | Ray & | ray, |
bool | exit_early | ||
) |
Check if any planes are intersecting with the ray.
ray | The ray to check against. |
exit_early | For shadow checking purposes, exit early if a plane is in the way, casting shadows. Do not set to true with bulb(light in scene). |
The parametric distance t is calculated. If t < 0, this means that the ray intersection is behind the ray origin, which means no intersection. Else, calculate the intersection point with t.
RGBA diffuseLight | ( | const ObjectInfo & | obj | ) |
Get the diffuse light color,with shadow checking.
obj | The objectInfo instance with the intersection information. |
The diffuse light color is checked by creating a shadow ray from the intersection point and the normal. This ray is checked against all light sources, and the actual color is found with the lambert light model. If a object totally obstructs a shadow ray, that ray does not contribute to the diffuse lighting.
Get the Color of Bulb (scene light)
lambert | The lambert constant. |
objColor | The color of the object. |
lightColor | The color of the light. |
This function applies the lambert constant to the light color and get the correct color by blending the colors of the light and the object, and applys light intensity falloff. Also takes care of exposure.`
Get the Color of Sun (directional light)
lambert | The lambert constant. |
objColor | The color of the object. |
lightColor | The color of the light. |
This function applies the lambert constant to the light color and get the correct color by blending the colors of the light and the object. Also takes care of exposure.
RGBA globalIllumination | ( | const ObjectInfo & | obj, |
int | gi_bounce | ||
) |
Get the global illumination light color.
obj | The objectInfo instance with the intersection information. |
gi_bounce | Remaining bounces for global illumination rays. |
A gi ray is created by selecting a new ray in the sphere at the intersection point. This gi ray, after intersection, can create more gi rays based on the remaining gi bounce.
ObjectInfo hitMiss | ( | ) |
Does nothing.
ObjectInfo hitNearest | ( | Ray & | ray | ) |
Gets the nearest object in the path of the ray.
ray | The ray to trace. |
RGBA reflectionLight | ( | const Ray & | ray, |
const ObjectInfo & | obj | ||
) |
Get the reflection light color.
ray | The ray which caused the reflection. |
obj | The objectInfo instance with the intersection information. |
The reflection ray is calculated and checked against all objects in the scene. If the reflection ray did hit an object, a full light calculation is performed to achieve the reflection lighting effect.
RGBA refractionLight | ( | const Ray & | ray, |
const ObjectInfo & | obj | ||
) |
Get the refraction light color.
ray | The ray which caused the refraction. |
obj | The objectInfo instance with the intersection information. |
The refraction discriminant (k) is calculated and if k < 0, total internal refraction occur, which is treated as reflection. If not, the refraction ray is calculated, and checked against all objects again(this currently only works for spheres and could be optimized). When the ray hits the object again, the final refraction ray is calculated using the inverse of the ior ratio during ray entrance. After the ray exits, full light calculation is performed.
void render | ( | Image & | img | ) |
The render function that loops over the screen of pixels.
img | The image to render on. |
Loops over all pixels in the canvas and shoots a primary ray at that pixel. Shoot multiple rays if anti-alising is on.
RGBA shootPrimaryRay | ( | double | x, |
double | y | ||
) |
Shoots a primary ray into the scene, at pixel location (x,y).
x | x coordinate of the pixel. |
y | y coordinate of the pixel. |
This function shoots one primary ray for the pixel (x,y). It will calculate the color for the pixel with the nearest object the primary ray hit, and the final color will be the blend of diffuse, reflect, refract and global illumination color. The latter three could create more rays that will bounce in the scene.