extract time to file
This commit is contained in:
parent
5cc2c3d92b
commit
4700579877
|
@ -23,7 +23,7 @@ layout (location = 13) uniform Sphere _spheres[SPHERES];
|
||||||
layout(local_size_x = 1, local_size_y = 1) in; // size of local work group - 1 pixel
|
layout(local_size_x = 1, local_size_y = 1) in; // size of local work group - 1 pixel
|
||||||
layout(rgba32f, binding = 0) uniform image2D img_output; // rgba32f defines internal format, image2d for random write to output texture
|
layout(rgba32f, binding = 0) uniform image2D img_output; // rgba32f defines internal format, image2d for random write to output texture
|
||||||
|
|
||||||
const float INF = 20.0;
|
const float INF = 30.0;
|
||||||
const float PI = 3.14159;
|
const float PI = 3.14159;
|
||||||
|
|
||||||
struct Ray
|
struct Ray
|
||||||
|
@ -75,9 +75,6 @@ Ray createCameraRay(vec2 uv)
|
||||||
dir = _camll + uv.x*_camh + uv.y*_camv;
|
dir = _camll + uv.x*_camh + uv.y*_camv;
|
||||||
dir = normalize(dir);
|
dir = normalize(dir);
|
||||||
|
|
||||||
float max_x = 5.0;
|
|
||||||
float max_y = 5.0;
|
|
||||||
|
|
||||||
Ray ray;
|
Ray ray;
|
||||||
ray.origin = _cpos;
|
ray.origin = _cpos;
|
||||||
ray.direction = dir;
|
ray.direction = dir;
|
||||||
|
|
60
src/main.c
60
src/main.c
|
@ -1,5 +1,6 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
#include "sphere.h"
|
#include "sphere.h"
|
||||||
|
|
||||||
|
@ -11,14 +12,9 @@ const int HEIGHT = 420;
|
||||||
// input
|
// input
|
||||||
int checkQuit();
|
int checkQuit();
|
||||||
|
|
||||||
// time
|
|
||||||
float time();
|
|
||||||
|
|
||||||
void updateUniforms(GLuint shaderProgram);
|
void updateUniforms(GLuint shaderProgram);
|
||||||
void updateCameraUniforms(GLuint shaderProgram);
|
void updateCameraUniforms(GLuint shaderProgram);
|
||||||
|
|
||||||
void updateSphereUniform(GLuint shaderProgram, struct Sphere sphere);
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create a window and opengl context
|
// create a window and opengl context
|
||||||
|
@ -66,51 +62,10 @@ int main()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeSpheres(struct Sphere *spheres, int count)
|
|
||||||
{
|
|
||||||
float t = time();
|
|
||||||
|
|
||||||
vec3 albedos[] =
|
|
||||||
{
|
|
||||||
{0.0,0.0,1.0},
|
|
||||||
{0.0,1.0,0.0},
|
|
||||||
{0.0,1.0,1.0},
|
|
||||||
{1.0,0.0,0.0},
|
|
||||||
{1.0,0.0,1.0},
|
|
||||||
{1.0,1.0,0.0},
|
|
||||||
{1.0,1.0,1.0}
|
|
||||||
};
|
|
||||||
|
|
||||||
// distance from center
|
|
||||||
float d = 6.0;
|
|
||||||
float radius = 0.5;
|
|
||||||
float x;
|
|
||||||
vec3 sc = {0.0,0.0,1.0};
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
x = t*0.1 + 2.0*CGLM_PI * i/(float)count;
|
|
||||||
sc[0] = sin(x)*d;
|
|
||||||
sc[2] = cos(x)*d;
|
|
||||||
|
|
||||||
float ic = i/(float)count;
|
|
||||||
float r = sin(ic);
|
|
||||||
float g = sin(ic+1.0);
|
|
||||||
float b = sin(ic+2.0);
|
|
||||||
g = 1.0;
|
|
||||||
b = 1.0;
|
|
||||||
|
|
||||||
vec3 col = {r,g,b};
|
|
||||||
glm_vec3_scale(col, 0.5, col);
|
|
||||||
glm_vec3_adds(col, 0.5, col);
|
|
||||||
|
|
||||||
spheres[i] = makeSphere(sc,radius,col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateUniforms(GLuint shaderProgram)
|
void updateUniforms(GLuint shaderProgram)
|
||||||
{
|
{
|
||||||
float t = time(); // time
|
float t = now();
|
||||||
float sin_t = sin(t);
|
float sin_t = sin(t);
|
||||||
int tLocation = glGetUniformLocation(shaderProgram, "_t");
|
int tLocation = glGetUniformLocation(shaderProgram, "_t");
|
||||||
glUniform4f(tLocation, t, sin_t, (1.0 + sin_t)*0.5, 0.0f);
|
glUniform4f(tLocation, t, sin_t, (1.0 + sin_t)*0.5, 0.0f);
|
||||||
|
@ -137,7 +92,7 @@ void updateCameraUniforms(GLuint shaderProgram)
|
||||||
int inverseProjLocation = glGetUniformLocation(shaderProgram, "_cameraInverseProjection");
|
int inverseProjLocation = glGetUniformLocation(shaderProgram, "_cameraInverseProjection");
|
||||||
glUniformMatrix4fv(inverseProjLocation, 1, GL_FALSE, proji[0]);
|
glUniformMatrix4fv(inverseProjLocation, 1, GL_FALSE, proji[0]);
|
||||||
|
|
||||||
float t = time();
|
float t = now();
|
||||||
|
|
||||||
vec3 cdir, cright, cup;
|
vec3 cdir, cright, cup;
|
||||||
vec3 up = {0.1*sin(t),1.0,0.2*cos(t)}; // world up
|
vec3 up = {0.1*sin(t),1.0,0.2*cos(t)}; // world up
|
||||||
|
@ -145,7 +100,7 @@ void updateCameraUniforms(GLuint shaderProgram)
|
||||||
|
|
||||||
// lookat vector and view matrix
|
// lookat vector and view matrix
|
||||||
float d = 10.0 + sin(t);
|
float d = 10.0 + sin(t);
|
||||||
float pt = -t*0.1;
|
float pt = -t;
|
||||||
vec3 cpos = {sin(pt)*d,cos(0.5*t)*5.0,cos(pt)*d}; // camera pos
|
vec3 cpos = {sin(pt)*d,cos(0.5*t)*5.0,cos(pt)*d}; // camera pos
|
||||||
vec3 tpos = {0.0,0.0,0.0}; // target pos
|
vec3 tpos = {0.0,0.0,0.0}; // target pos
|
||||||
glm_vec3_sub(cpos,tpos,cdir); // look dir (inverted cause opengl noises)
|
glm_vec3_sub(cpos,tpos,cdir); // look dir (inverted cause opengl noises)
|
||||||
|
@ -212,13 +167,6 @@ void updateCameraUniforms(GLuint shaderProgram)
|
||||||
glUniform3f(camllLocation, camll[0], camll[1], camll[2]);
|
glUniform3f(camllLocation, camll[0], camll[1], camll[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float time()
|
|
||||||
{
|
|
||||||
// ms / 1000.0 = seconds since start
|
|
||||||
return (float)SDL_GetTicks() / 1000.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
int checkQuit()
|
int checkQuit()
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
42
src/sphere.c
42
src/sphere.c
|
@ -1,5 +1,47 @@
|
||||||
#include "sphere.h"
|
#include "sphere.h"
|
||||||
|
|
||||||
|
void makeSpheres(struct Sphere *spheres, int count)
|
||||||
|
{
|
||||||
|
//float t = time();
|
||||||
|
|
||||||
|
vec3 albedos[] =
|
||||||
|
{
|
||||||
|
{0.0,0.0,1.0},
|
||||||
|
{0.0,1.0,0.0},
|
||||||
|
{0.0,1.0,1.0},
|
||||||
|
{1.0,0.0,0.0},
|
||||||
|
{1.0,0.0,1.0},
|
||||||
|
{1.0,1.0,0.0},
|
||||||
|
{1.0,1.0,1.0}
|
||||||
|
};
|
||||||
|
|
||||||
|
// distance from center
|
||||||
|
float d = 6.0;
|
||||||
|
float radius = 0.5;
|
||||||
|
float x;
|
||||||
|
vec3 sc = {0.0,0.0,1.0};
|
||||||
|
|
||||||
|
float t = now();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
x = 2.0*CGLM_PI * (float)i/(float)count;
|
||||||
|
sc[0] = sin(x)*d;
|
||||||
|
sc[1] = sin(x*3.0-2.5*sin(t));
|
||||||
|
sc[2] = cos(x)*d;
|
||||||
|
|
||||||
|
float ic = i/(float)count*CGLM_PI*2.0;
|
||||||
|
float r = sin(ic);
|
||||||
|
float g = sin(ic+CGLM_PI/1.5);
|
||||||
|
float b = sin(ic+2.0*CGLM_PI/1.5);
|
||||||
|
|
||||||
|
vec3 col = {r,g,b};
|
||||||
|
glm_vec3_scale(col, 0.5, col);
|
||||||
|
glm_vec3_adds(col, 0.5, col);
|
||||||
|
|
||||||
|
spheres[i] = makeSphere(sc,radius,col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Sphere makeSphere(vec3 center, float radius, vec3 albedo)
|
struct Sphere makeSphere(vec3 center, float radius, vec3 albedo)
|
||||||
{
|
{
|
||||||
struct Sphere s;
|
struct Sphere s;
|
||||||
|
|
|
@ -7,12 +7,15 @@
|
||||||
|
|
||||||
#include <cglm/vec3.h>
|
#include <cglm/vec3.h>
|
||||||
|
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
struct Sphere
|
struct Sphere
|
||||||
{
|
{
|
||||||
vec4 cr;
|
vec4 cr;
|
||||||
vec3 albedo;
|
vec3 albedo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void makeSpheres(struct Sphere *spheres, int count);
|
||||||
struct Sphere makeSphere(vec3 center, float radius, vec3 albedo);
|
struct Sphere makeSphere(vec3 center, float radius, vec3 albedo);
|
||||||
void updateSphereUniform(GLuint shaderProgram, struct Sphere sphere);
|
void updateSphereUniform(GLuint shaderProgram, struct Sphere sphere);
|
||||||
void updateSphereUniforms(GLuint shaderProgram, struct Sphere *spheres, int count);
|
void updateSphereUniforms(GLuint shaderProgram, struct Sphere *spheres, int count);
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
|
float now()
|
||||||
|
{
|
||||||
|
return (float)SDL_GetTicks() / 1000.0;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
// seconds since program start
|
||||||
|
float now();
|
4
todo.md
4
todo.md
|
@ -17,10 +17,10 @@
|
||||||
* [ ] do a 'fract
|
* [ ] do a 'fract
|
||||||
* [-] depth
|
* [-] depth
|
||||||
* [x] acquire value
|
* [x] acquire value
|
||||||
* [ ] depth texture
|
|
||||||
* [ ] acquire randomness
|
* [ ] acquire randomness
|
||||||
* [ ] acceleration time !
|
* [ ] acceleration time !
|
||||||
* [ ] auxiliary textures: g buffer
|
* [ ] auxiliary textures
|
||||||
|
* [ ] depth buffer
|
||||||
* [ ] frame blending
|
* [ ] frame blending
|
||||||
* [ ] maybe do some fractals
|
* [ ] maybe do some fractals
|
||||||
* [ ] mandelbrot
|
* [ ] mandelbrot
|
||||||
|
|
Loading…
Reference in New Issue