Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7562f0c96 | ||
|
|
33324d728a | ||
|
|
b3f51f305a | ||
|
|
058f9f8a3e | ||
|
|
9cb3b83b9b | ||
|
|
33de0c2799 |
+2
-1
@@ -1,4 +1,5 @@
|
||||
*.exe
|
||||
*.exr
|
||||
./*.png
|
||||
ray_trace
|
||||
ray_trace
|
||||
.vscode
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
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
|
||||
else
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ sphere
|
||||
|
||||
sphere
|
||||
emission_color {1 1 1}
|
||||
emission_power 5
|
||||
emission_power 10
|
||||
metallic 0
|
||||
reflectance 0
|
||||
roughness 1
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ cube
|
||||
|
||||
cube
|
||||
emission_color {1 1 1}
|
||||
emission_power 1
|
||||
emission_power 10
|
||||
metallic 0
|
||||
reflectance 1
|
||||
roughness 0
|
||||
|
||||
+79
@@ -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
@@ -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}
|
||||
+15
-4
@@ -21,8 +21,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#include "camera.h"
|
||||
|
||||
static bool first_mouse = true;
|
||||
static float yaw = -90.0f;
|
||||
static float pitch = 0.0f;
|
||||
static float yaw = 0;
|
||||
static float pitch = -3.5;
|
||||
static float last_x = 800.0f / 2.0;
|
||||
static float last_y = 600.0f / 2.0;
|
||||
static float fov = 30.0f;
|
||||
@@ -30,10 +30,21 @@ static float fov = 30.0f;
|
||||
static float delta_time = 0.0f;
|
||||
static float last_frame = 0.0f;
|
||||
|
||||
static Vector3 camera_pos = {5, 5, 5};
|
||||
static Vector3 camera_front = {-1, -1, -1};
|
||||
static Vector3 camera_pos = {-3, 2.5, 2.5};
|
||||
static Vector3 camera_front = {1, 0, 0};
|
||||
static Vector3 camera_up = {0, 1, 0};
|
||||
|
||||
#include <stdio.h>
|
||||
void print_camera(void)
|
||||
{
|
||||
fprintf(stderr, "camera:\n");
|
||||
fprintf(stderr, " pos={%f %f %f}\n", camera_pos.x, camera_pos.y, camera_pos.z);
|
||||
fprintf(stderr, " front={%f %f %f}\n", camera_front.x, camera_front.y, camera_front.z);
|
||||
fprintf(stderr, " up={%f %f %f}\n", camera_up.x, camera_up.y, camera_up.z);
|
||||
fprintf(stderr, " yaw=%f\n", yaw);
|
||||
fprintf(stderr, " pitch=%f\n", pitch);
|
||||
}
|
||||
|
||||
Vector3 get_camera_pos(void)
|
||||
{
|
||||
return camera_pos;
|
||||
|
||||
@@ -39,6 +39,8 @@ void free_cubemap(Cubemap *c)
|
||||
}
|
||||
}
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
Vector3 sample_cubemap(Cubemap *c, Vector3 dir)
|
||||
{
|
||||
float abs_x = absf(dir.x);
|
||||
@@ -49,7 +51,7 @@ Vector3 sample_cubemap(Cubemap *c, Vector3 dir)
|
||||
|
||||
float u;
|
||||
float v;
|
||||
float eps = 0;
|
||||
float eps = 0.0001;
|
||||
|
||||
if (abs_x > abs_y && abs_x > abs_z) {
|
||||
// X dominant
|
||||
|
||||
+711
-292
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,29 @@
|
||||
/*
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org/>
|
||||
*/
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -33,21 +32,21 @@
|
||||
#ifdef _WIN32
|
||||
#define WIN32_MEAN_AND_LEAN
|
||||
#include <windows.h>
|
||||
typedef CRITICAL_SECTION os_mutex_t;
|
||||
typedef CRITICAL_SECTION os_mutex_t;
|
||||
typedef CONDITION_VARIABLE os_condvar_t;
|
||||
#elif defined(__linux__)
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
typedef pthread_mutex_t os_mutex_t;
|
||||
typedef pthread_cond_t os_condvar_t;
|
||||
typedef pthread_cond_t os_condvar_t;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN32
|
||||
void *data;
|
||||
#else
|
||||
#else
|
||||
sem_t data;
|
||||
#endif
|
||||
#endif
|
||||
} os_semaphore_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -62,24 +61,27 @@ void sleep_ms(float ms);
|
||||
|
||||
void os_mutex_create(os_mutex_t *mutex);
|
||||
void os_mutex_delete(os_mutex_t *mutex);
|
||||
void os_mutex_lock(os_mutex_t *mutex);
|
||||
void os_mutex_lock (os_mutex_t *mutex);
|
||||
void os_mutex_unlock(os_mutex_t *mutex);
|
||||
|
||||
void os_condvar_create(os_condvar_t *condvar);
|
||||
void os_condvar_delete(os_condvar_t *condvar);
|
||||
bool os_condvar_wait(os_condvar_t *condvar, os_mutex_t *mutex, int timeout_ms);
|
||||
bool os_condvar_wait (os_condvar_t *condvar, os_mutex_t *mutex, int timeout_ms);
|
||||
void os_condvar_signal(os_condvar_t *condvar);
|
||||
|
||||
void semaphore_create(semaphore_t *sem, int count);
|
||||
void semaphore_delete(semaphore_t *sem);
|
||||
bool semaphore_wait(semaphore_t *sem, int count, int timeout_ms);
|
||||
bool semaphore_wait (semaphore_t *sem, int count, int timeout_ms);
|
||||
void semaphore_signal(semaphore_t *sem, int count);
|
||||
|
||||
bool os_semaphore_create(os_semaphore_t *sem, int count, int max);
|
||||
bool os_semaphore_delete(os_semaphore_t *sem);
|
||||
bool os_semaphore_wait(os_semaphore_t *sem);
|
||||
bool os_semaphore_wait (os_semaphore_t *sem);
|
||||
bool os_semaphore_signal(os_semaphore_t *sem);
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_MEAN_AND_LEAN
|
||||
#include <windows.h>
|
||||
@@ -93,5 +95,5 @@ typedef void *os_threadreturn;
|
||||
|
||||
uint64_t get_thread_id(void);
|
||||
|
||||
void os_thread_create(os_thread *thread, void *arg, os_threadreturn (*func)(void*));
|
||||
os_threadreturn os_thread_join(os_thread thread);
|
||||
void os_thread_create(os_thread *thread, void *arg, os_threadreturn (*func)(void*));
|
||||
os_threadreturn os_thread_join(os_thread thread);
|
||||
+4
-2
@@ -114,8 +114,10 @@ static bool intersect_sphere(Ray r, Sphere s, float *t)
|
||||
float discr = b*b - 4*a*c;
|
||||
|
||||
if (discr > 0) {
|
||||
float s0 = (- b + sqrt(discr)) / (2 * a);
|
||||
float s1 = (- b - sqrt(discr)) / (2 * a);
|
||||
float u = -0.5 * b / a;
|
||||
float v = 0.5 * sqrt(discr) / a;
|
||||
float s0 = u + v;
|
||||
float s1 = u - v;
|
||||
if (s0 > s1) {
|
||||
float tmp = s0;
|
||||
s0 = s1;
|
||||
|
||||
+11
-1
@@ -71,5 +71,15 @@ static uint64_t wyhash64(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
@@ -31,7 +31,7 @@ For more information, please refer to <http://unlicense.org/>
|
||||
|
||||
char *load_file(const char *file, size_t *size);
|
||||
|
||||
inline bool is_space(char c) { return c == ' ' || c == '\r' || c == '\t' || c == '\n'; }
|
||||
inline bool is_digit(char c) { return c >= '0' && c <= '9'; }
|
||||
bool is_space(char c);
|
||||
bool is_digit(char c);
|
||||
|
||||
float random_float(void);
|
||||
@@ -76,6 +76,11 @@ bool isnanv(Vector3 v)
|
||||
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)
|
||||
{
|
||||
return f < 0.0001 && f > -0.0001;
|
||||
|
||||
@@ -68,6 +68,7 @@ float absf(float x);
|
||||
float clamp(float x, float min, float max);
|
||||
Vector3 maxv(Vector3 a, Vector3 b);
|
||||
bool isnanv(Vector3 v);
|
||||
bool isinfv(Vector3 v);
|
||||
bool iszerof(float f);
|
||||
bool iszerov(Vector3 v);
|
||||
float avgv(Vector3 v);
|
||||
|
||||
Reference in New Issue
Block a user