adding brdf, but virtual is probably terrible for performance
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#include "BRDF.h"
|
||||
|
||||
glm::vec3 BlinnPhong::evaluate(HitInfo hit, glm::vec3 viewDir, glm::vec3 lightDir, glm::vec3 lightColor)
|
||||
{
|
||||
glm::vec3 normal = hit.normal;
|
||||
float diffuse = std::max(glm::dot(normal, lightDir), 0.0f);
|
||||
glm::vec3 h = glm::normalize(lightDir + viewDir);
|
||||
float specular = pow(std::min(std::max(glm::dot(normal, h), 0.0f), 1.0f), shininess);
|
||||
|
||||
return (albedo * diffuse * lightColor) + (specularColor * specular);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Material.h"
|
||||
|
||||
class BRDF
|
||||
{
|
||||
virtual glm::vec3 evaluate(HitInfo hit, glm::vec3 viewDir, glm::vec3 lightDir, glm::vec3 lightColor) = 0;
|
||||
};
|
||||
|
||||
class BlinnPhong : public BRDF
|
||||
{
|
||||
glm::vec3 albedo = glm::vec3(1, 1, 1);
|
||||
float alpha = 1;
|
||||
glm::vec3 specularColor = glm::vec3(1, 1, 1);
|
||||
float shininess = 0;
|
||||
glm::vec3 emissive = glm::vec3(0, 0, 0);
|
||||
virtual glm::vec3 evaluate(HitInfo hit, glm::vec3 viewDir, glm::vec3 lightDir, glm::vec3 lightColor);
|
||||
};
|
||||
@@ -1,5 +1,7 @@
|
||||
target_sources(RayTracer
|
||||
PRIVATE
|
||||
BRDF.h
|
||||
BRDF.cpp
|
||||
Camera.h
|
||||
Material.h
|
||||
Material.cpp
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
#include "Material.h"
|
||||
#include "Material.h"
|
||||
|
||||
std::unique_ptr<BRDF> Material::evaluate(HitInfo hitInfo)
|
||||
{
|
||||
return std::make_unique<BlinnPhong>();
|
||||
}
|
||||
|
||||
+14
-1
@@ -1,7 +1,20 @@
|
||||
#pragma once
|
||||
#include "Minimal.h"
|
||||
#include "Texture.h"
|
||||
#include "Ray.h"
|
||||
#include "BRDF.h"
|
||||
|
||||
enum class MaterialType
|
||||
{
|
||||
DIFFUSE,
|
||||
SPECULAR,
|
||||
REFRACTIVE,
|
||||
};
|
||||
|
||||
class Material
|
||||
{
|
||||
public:
|
||||
private:
|
||||
std::unique_ptr<BRDF> evaluate(HitInfo hitInfo);
|
||||
PTexture albedoTexture;
|
||||
PTexture emissiveTexture;
|
||||
};
|
||||
+3
-9
@@ -1,20 +1,14 @@
|
||||
#pragma once
|
||||
#include "Minimal.h"
|
||||
#include "Material.h"
|
||||
#include "scene/AABB.h"
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
// material infos
|
||||
// shading parameter
|
||||
// hit data
|
||||
struct IntersectionInfo
|
||||
{
|
||||
float t;
|
||||
glm::vec3 position;
|
||||
glm::vec3 normal;
|
||||
glm::vec3 albedo;
|
||||
glm::vec3 emissive;
|
||||
//....
|
||||
HitInfo hitInfo;
|
||||
MaterialInfo shadingInfo;
|
||||
};
|
||||
class Model
|
||||
{
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
struct Payload
|
||||
{
|
||||
glm::vec3 accumulatedRadiance = glm::vec3(0);
|
||||
glm::vec3 accumulatedMaterial = glm::vec3(0);
|
||||
};
|
||||
|
||||
struct Ray
|
||||
{
|
||||
glm::vec3 origin;
|
||||
glm::vec3 direction;
|
||||
uint32_t depth = 0;
|
||||
Payload payload;
|
||||
};
|
||||
|
||||
struct HitInfo
|
||||
{
|
||||
float t;
|
||||
glm::vec3 position;
|
||||
glm::vec3 normal;
|
||||
glm::vec2 texCoords;
|
||||
};
|
||||
Reference in New Issue
Block a user