https://github.com/xuyanwen2012/toytracer
A toy Ray-tracer implemented with c++ & glm
https://github.com/xuyanwen2012/toytracer
cpp cpp11 raytracer raytracing
Last synced: 11 months ago
JSON representation
A toy Ray-tracer implemented with c++ & glm
- Host: GitHub
- URL: https://github.com/xuyanwen2012/toytracer
- Owner: xuyanwen2012
- Created: 2019-10-13T05:19:56.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-18T20:46:08.000Z (almost 7 years ago)
- Last Synced: 2025-04-15T00:33:59.702Z (over 1 year ago)
- Topics: cpp, cpp11, raytracer, raytracing
- Language: C++
- Homepage:
- Size: 3.66 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🎺 ToyTracer
> CMPM 164, Fall 2019
This repo is for homework 2B.
A naive toy Ray Tracer built from ~~scract~~ (given up), used a third-party library [OpenGL Mathematics](https://github.com/g-truc/glm) (*GLM*).
## Outputs

With 1280x720, Gama 2.2, FoV 90, Max Recursion Depth 10.
## Features
- `Phong Lighting`: Has 3 solid spherical objects with 2 shperical lights and 1 directional light using the Phong lighting model.
- `Relection & Refraction`: Have 3 spherical objects different material, including shadows.
- `Additonal Shapes`: Have Triangle shape, Plane shape.
- `Fresnel Effect`
- `Gamma Correction`
- `Modern C++ Practices`
## Sample Code
Sphere Implementation
```c++
#pragma once
#include
#include "Element.h"
class Sphere : public Element
{
public:
Sphere(Material material, const glm::vec3& center, const float radius) :
Element(material),
origin_(center),
radius_(radius)
{
}
bool Intersect(const Ray& ray, float& dist) override
{
return intersectRaySphere(
ray.GetOrigin(), ray.GetDirection(),
origin_, radius_ * radius_,
dist
);
}
glm::vec3 GetSurfaceNormal(glm::vec3& hit_point) override
{
return (hit_point - origin_) / radius_; // from glm
}
glm::vec2 TextureCoords(glm::vec3& hit_point) override
{
const auto hit_vec = hit_point - origin_;
return {
(1.0 + atan2(hit_vec.z, hit_vec.x)) / glm::pi() * 0.5f,
acos(hit_vec.y / radius_) / glm::pi()
};
}
private:
glm::vec3 origin_;
float radius_;
};
```
## Meta
Yanwen Xu – [UCSC](https://people.ucsc.edu/~yxu83/) – yxu83@ucsc.edu