ubuntu20
4 years ago
12 changed files with 143 additions and 22 deletions
-
10Material.cpp
-
13Material.h
-
25Object.cpp
-
11Object.h
-
1Ray.h
-
63Scene.cpp
-
8Vector3.cpp
-
2Vector3.h
-
4raytracing.vcxproj
-
12raytracing.vcxproj.filters
-
10util.cpp
-
2util.h
@ -0,0 +1,10 @@ |
|||
#include "Material.h"
|
|||
#include "Ray.h"
|
|||
#include <math.h>
|
|||
bool LamberMaterial::Scatter(const Ray & input_ray, const HitPoint & hit_point, Ray & out_ray) |
|||
{ |
|||
Vector3 random_vector = UnitRandomVector3InSphere(); |
|||
Vector3 new_direction = hit_point.mNormal + random_vector; |
|||
out_ray.Set(hit_point.mPosition, new_direction, input_ray.mLightAttenuation*mDiffuse); |
|||
return true; |
|||
} |
@ -0,0 +1,13 @@ |
|||
#pragma once |
|||
#include "Vector3.h" |
|||
class Ray; |
|||
class Material { |
|||
public: |
|||
virtual bool Scatter(const Ray& input_ray, const HitPoint& hit_point, Ray& out_ray) = 0; |
|||
}; |
|||
class LamberMaterial : public Material { |
|||
public: |
|||
Vector3 mDiffuse; |
|||
LamberMaterial(const Vector3 diffuse) { mDiffuse = diffuse; } |
|||
bool Scatter(const Ray& input_ray, const HitPoint& hit_point, Ray& out_ray); |
|||
}; |
@ -0,0 +1,25 @@ |
|||
#include "Object.h"
|
|||
#include "Material.h"
|
|||
#include "Ray.h"
|
|||
#include <math.h>
|
|||
|
|||
Object::Object(Geometry * g, Material * m) |
|||
{ |
|||
mGeometry = g; |
|||
mMaterial = m; |
|||
} |
|||
|
|||
void Object::Set(Geometry * g, Material * m) |
|||
{ |
|||
mGeometry = g; |
|||
mMaterial = m; |
|||
} |
|||
|
|||
bool Object::HitTest(const Ray & input_ray, float min_distance, float max_distance, HitPoint & hit_point) |
|||
{ |
|||
if (mGeometry->HitTest(input_ray, min_distance, max_distance, hit_point)) { |
|||
hit_point.mMaterial = mMaterial; |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
@ -0,0 +1,11 @@ |
|||
#pragma once |
|||
#include "Vector3.h" |
|||
class Material; |
|||
class Object { |
|||
public: |
|||
Geometry *mGeometry; |
|||
Material *mMaterial; |
|||
Object(Geometry* g, Material* m); |
|||
void Set(Geometry* g, Material* m); |
|||
bool HitTest(const Ray& input_ray, float min_distance, float max_distance, HitPoint& hit_point); |
|||
}; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue