it does something

This commit is contained in:
Dynamitos
2025-01-26 19:43:06 +01:00
parent 98020d4455
commit cc2f92aaab
12 changed files with 199 additions and 89 deletions
+4 -2
View File
@@ -1,11 +1,13 @@
#include "BRDF.h"
#include "Model.h"
glm::vec3 BlinnPhong::evaluate(HitInfo hit, glm::vec3 viewDir, glm::vec3 lightDir, glm::vec3 lightColor)
glm::vec3 BRDF::evaluate(HitInfo hit, glm::vec3 viewDir, glm::vec3 lightDir, glm::vec3 lightColor)
{
// todo: switch for materialtype, this is blinnphong
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);
}
}
+6 -5
View File
@@ -1,17 +1,18 @@
#pragma once
#include "Material.h"
#include <glm/glm.hpp>
class BRDF
enum class MaterialType
{
virtual glm::vec3 evaluate(HitInfo hit, glm::vec3 viewDir, glm::vec3 lightDir, glm::vec3 lightColor) = 0;
BlinnPhong
};
class BlinnPhong : public BRDF
struct 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);
MaterialType materialType;
glm::vec3 evaluate(struct HitInfo hit, glm::vec3 viewDir, glm::vec3 lightDir, glm::vec3 lightColor);
};
+8 -2
View File
@@ -1,6 +1,12 @@
#include "Material.h"
#include "BRDF.h"
std::unique_ptr<BRDF> Material::evaluate(HitInfo hitInfo)
BRDF Material::evaluate(HitInfo hitInfo)
{
return std::make_unique<BlinnPhong>();
return BRDF{
.albedo = glm::vec3(hitInfo.texCoords, 0),
.alpha = 1,
.emissive = glm::vec3(0, 0, 0),
.materialType = MaterialType::BlinnPhong,
};
}
+1 -8
View File
@@ -4,17 +4,10 @@
#include "Ray.h"
#include "BRDF.h"
enum class MaterialType
{
DIFFUSE,
SPECULAR,
REFRACTIVE,
};
class Material
{
public:
std::unique_ptr<BRDF> evaluate(HitInfo hitInfo);
BRDF evaluate(HitInfo hitInfo);
PTexture albedoTexture;
PTexture emissiveTexture;
};
+1 -1
View File
@@ -8,7 +8,7 @@
struct IntersectionInfo
{
HitInfo hitInfo;
MaterialInfo shadingInfo;
BRDF brdf;
};
class Model
{
+6 -3
View File
@@ -4,15 +4,15 @@
struct Payload
{
glm::vec3 accumulatedRadiance = glm::vec3(0);
glm::vec3 accumulatedMaterial = glm::vec3(0);
glm::vec3 accumulatedMaterial = glm::vec3(1);
uint32_t depth = 0;
float emissive = 1;
};
struct Ray
{
glm::vec3 origin;
glm::vec3 direction;
uint32_t depth = 0;
Payload payload;
};
struct HitInfo
@@ -20,5 +20,8 @@ struct HitInfo
float t;
glm::vec3 position;
glm::vec3 normal;
// not entirely sure what that does
// its the normal being flipped based on some dot product
glm::vec3 normalLight;
glm::vec2 texCoords;
};