Implement light sampling and improve filter

This commit is contained in:
2024-11-25 16:15:29 +01:00
parent 33324d728a
commit f7562f0c96
12 changed files with 548 additions and 486 deletions
+1
View File
@@ -2,3 +2,4 @@
*.exr *.exr
./*.png ./*.png
ray_trace ray_trace
.vscode
+1 -1
View File
@@ -1,7 +1,7 @@
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
EXT = .exe EXT = .exe
CFLAGS = -O2 -DNDEBUG -I3p -I3p/glad/include -I3p/glfw-3.4.bin.WIN64/include -L3p/glfw-3.4.bin.WIN64/lib-mingw-w64 CFLAGS = -O2 -DNDEBUG -I3p -I3p/glad/include -I3p/glfw-3.4.bin.WIN64/include -L3p/glfw-3.4.bin.WIN64/lib-mingw-w64 -ggdb
LDFLAGS = -lglfw3 -lopengl32 -lgdi32 LDFLAGS = -lglfw3 -lopengl32 -lgdi32
else else
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
+1 -1
View File
@@ -80,7 +80,7 @@ sphere
sphere sphere
emission_color {1 1 1} emission_color {1 1 1}
emission_power 5 emission_power 10
metallic 0 metallic 0
reflectance 0 reflectance 0
roughness 1 roughness 1
+1 -1
View File
@@ -50,7 +50,7 @@ cube
cube cube
emission_color {1 1 1} emission_color {1 1 1}
emission_power 1 emission_power 10
metallic 0 metallic 0
reflectance 1 reflectance 1
roughness 0 roughness 0
+79
View File
@@ -0,0 +1,79 @@
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {1 1 1}
origin {0 0 0}
size {5 0 5}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {0.63 0.065 0.05}
origin {0 0 0}
size {5 5 0}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {0.14 0.45 0.091}
origin {0 0 5}
size {5 5 0}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {1 1 1}
origin {0 5 0}
size {5 0 5}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {1 1 1}
origin {5 0 0}
size {0 5 5}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 0
albedo {1 1 1}
origin {3 0 1}
size {1.5 3.2 1.7}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 0
albedo {1 1 1}
origin {1 0 3}
size {1 1.4 1.2}
cube
emission_color {1.0 0.843 0.682}
emission_power 10
metallic 0
reflectance 0
roughness 0
albedo {1 1 1}
origin {2 4.99 2}
size {1 0 1}
+69
View File
@@ -0,0 +1,69 @@
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {1 1 1}
origin {0 0 0}
size {5 0 5}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {0.63 0.065 0.05}
origin {0 0 0}
size {5 5 0}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {0.14 0.45 0.091}
origin {0 0 5}
size {5 5 0}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {1 1 1}
origin {0 5 0}
size {5 0 5}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {1 1 1}
origin {5 0 0}
size {0 5 5}
cube
emission_color {0 0 0}
emission_power 0
metallic 0
reflectance 0
roughness 1
albedo {1 1 1}
origin {3 0 0.5}
size {1.5 3.2 4}
cube
emission_color {1.0 0.843 0.682}
emission_power 20
metallic 0
reflectance 0
roughness 0
albedo {1 1 1}
origin {2 4.99 2}
size {1 0 1}
+3 -1
View File
@@ -39,6 +39,8 @@ void free_cubemap(Cubemap *c)
} }
} }
#include "vector.h"
Vector3 sample_cubemap(Cubemap *c, Vector3 dir) Vector3 sample_cubemap(Cubemap *c, Vector3 dir)
{ {
float abs_x = absf(dir.x); float abs_x = absf(dir.x);
@@ -49,7 +51,7 @@ Vector3 sample_cubemap(Cubemap *c, Vector3 dir)
float u; float u;
float v; float v;
float eps = 0; float eps = 0.0001;
if (abs_x > abs_y && abs_x > abs_z) { if (abs_x > abs_y && abs_x > abs_z) {
// X dominant // X dominant
+373 -478
View File
File diff suppressed because it is too large Load Diff
+11 -1
View File
@@ -71,5 +71,15 @@ static uint64_t wyhash64(void) {
float random_float(void) float random_float(void)
{ {
return (float) wyhash64() / UINT64_MAX; return (float) rand() / RAND_MAX;
}
bool is_space(char c)
{
return c == ' ' || c == '\r' || c == '\t' || c == '\n';
}
bool is_digit(char c)
{
return c >= '0' && c <= '9';
} }
+2 -2
View File
@@ -31,7 +31,7 @@ For more information, please refer to <http://unlicense.org/>
char *load_file(const char *file, size_t *size); char *load_file(const char *file, size_t *size);
inline bool is_space(char c) { return c == ' ' || c == '\r' || c == '\t' || c == '\n'; } bool is_space(char c);
inline bool is_digit(char c) { return c >= '0' && c <= '9'; } bool is_digit(char c);
float random_float(void); float random_float(void);
+5
View File
@@ -76,6 +76,11 @@ bool isnanv(Vector3 v)
return isnan(v.x) || isnan(v.y) || isnan(v.z); return isnan(v.x) || isnan(v.y) || isnan(v.z);
} }
bool isinfv(Vector3 v)
{
return isinf(v.x) || isinf(v.y) || isinf(v.z);
}
bool iszerof(float f) bool iszerof(float f)
{ {
return f < 0.0001 && f > -0.0001; return f < 0.0001 && f > -0.0001;
+1
View File
@@ -68,6 +68,7 @@ float absf(float x);
float clamp(float x, float min, float max); float clamp(float x, float min, float max);
Vector3 maxv(Vector3 a, Vector3 b); Vector3 maxv(Vector3 a, Vector3 b);
bool isnanv(Vector3 v); bool isnanv(Vector3 v);
bool isinfv(Vector3 v);
bool iszerof(float f); bool iszerof(float f);
bool iszerov(Vector3 v); bool iszerov(Vector3 v);
float avgv(Vector3 v); float avgv(Vector3 v);