Compare commits
12 Commits
8349039167
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c62ce6bce | |||
| 1e918d5370 | |||
| a2ba43fe79 | |||
| dbca360da2 | |||
| 627380e3e2 | |||
| 12315d2791 | |||
| 7cafe6544b | |||
| 545708571d | |||
| 4f71ecfd6d | |||
| 4a57bb1357 | |||
| a6cad08505 | |||
| b5f6758400 |
@@ -4,8 +4,13 @@ project(64kDemo VERSION 0.1
|
|||||||
DESCRIPTION "CPU SDF Renderer"
|
DESCRIPTION "CPU SDF Renderer"
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
|
set (CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
SET(CMAKE_CXX_FLAGS "-Os -s")
|
SET(CMAKE_CXX_FLAGS "-Os -s")
|
||||||
|
|
||||||
|
|
||||||
add_executable(one main.cpp)
|
add_executable(one main.cpp)
|
||||||
|
|
||||||
target_link_libraries(one m glfw GLEW GL)
|
find_package(glm REQUIRED)
|
||||||
|
|
||||||
|
target_link_libraries(one m glfw GLEW GL glm::glm)
|
||||||
|
|||||||
40
PerformanceAnalyser.hpp
Normal file
40
PerformanceAnalyser.hpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include <GL/glew.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class PerformanceAnalyser {
|
||||||
|
private:
|
||||||
|
double lastFrameTime = 0;
|
||||||
|
int frameCount = 0;
|
||||||
|
double timeAcc = 0;
|
||||||
|
double lastFps = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PerformanceAnalyser(int framesToAcc = 10, bool autoPrint = true)
|
||||||
|
: framesToAcc(framesToAcc), autoPrint(autoPrint) {};
|
||||||
|
|
||||||
|
int framesToAcc;
|
||||||
|
bool autoPrint;
|
||||||
|
|
||||||
|
int getFPS() { return lastFps; }
|
||||||
|
|
||||||
|
void update(float time) {
|
||||||
|
|
||||||
|
timeAcc += (time - lastFrameTime);
|
||||||
|
lastFrameTime = time;
|
||||||
|
frameCount++;
|
||||||
|
|
||||||
|
if (frameCount == framesToAcc) {
|
||||||
|
|
||||||
|
lastFps = double(framesToAcc) / timeAcc;
|
||||||
|
|
||||||
|
if (autoPrint) {
|
||||||
|
std::cout << "Fps: " << std::round(lastFps * 10.0) * 0.1 << "\n"
|
||||||
|
<< std::flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
frameCount = 0;
|
||||||
|
timeAcc = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
14
build.sh
Executable file
14
build.sh
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cd build
|
||||||
|
cmake --build .
|
||||||
|
CMD="#!/bin/bash
|
||||||
|
dd bs=1 skip=%s<\$0|unlzma>/tmp/C;chmod +x /tmp/C;trap '' HUP;/tmp/C&"
|
||||||
|
COUNT=$(printf "$CMD" | wc -c)
|
||||||
|
EXTRA=$(printf "$COUNT" | wc -c)
|
||||||
|
COUNT=$((COUNT + EXTRA + 1))
|
||||||
|
echo "$CMD" | sed 's/%s/'"$COUNT"'/' > two
|
||||||
|
chmod +x two
|
||||||
|
sstrip one
|
||||||
|
lzma -9 one
|
||||||
|
cat one.lzma >> two
|
||||||
|
rm one.lzma
|
||||||
14
main.cpp
14
main.cpp
@@ -1,7 +1,9 @@
|
|||||||
#include "FullScreenQuad.hpp"
|
#include "FullScreenQuad.hpp"
|
||||||
|
#include "PerformanceAnalyser.hpp"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
const char *vertexShaderSource =
|
const char *vertexShaderSource =
|
||||||
#include "fsq.glsl"
|
#include "fsq.glsl"
|
||||||
@@ -104,7 +106,15 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
FullScreenQuad fsq{};
|
FullScreenQuad fsq{};
|
||||||
|
|
||||||
|
PerformanceAnalyser perf{};
|
||||||
|
|
||||||
|
double time = glfwGetTime();
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
|
||||||
|
time = glfwGetTime();
|
||||||
|
perf.update(time);
|
||||||
|
|
||||||
processInput(window);
|
processInput(window);
|
||||||
/* Render here */
|
/* Render here */
|
||||||
|
|
||||||
@@ -112,8 +122,12 @@ int main(int argc, char **argv) {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(shaderProgram);
|
glUseProgram(shaderProgram);
|
||||||
|
|
||||||
int aspectLocation = glGetUniformLocation(shaderProgram, "aspect");
|
int aspectLocation = glGetUniformLocation(shaderProgram, "aspect");
|
||||||
glUniform1f(aspectLocation, aspect);
|
glUniform1f(aspectLocation, aspect);
|
||||||
|
int timeLocation = glGetUniformLocation(shaderProgram, "t");
|
||||||
|
glUniform1f(timeLocation, 2. * time);
|
||||||
|
|
||||||
glBindVertexArray(fsq.getVAO());
|
glBindVertexArray(fsq.getVAO());
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
- [ ] Shader Management
|
- [ ] Shader Management
|
||||||
- [ ] Configure Preprocessor
|
- [ ] Configure Preprocessor
|
||||||
- [ ] Shader Storage
|
- [ ] Shader Storage
|
||||||
|
- [x] Binary compression
|
||||||
|
|
||||||
|
- [x] C++ Math Lib
|
||||||
|
|
||||||
- [ ] SDF
|
- [ ] SDF
|
||||||
- [ ] Basic Shape Rendering
|
- [ ] Basic Shape Rendering
|
||||||
@@ -25,7 +28,7 @@
|
|||||||
- [ ] Rounding
|
- [ ] Rounding
|
||||||
- [ ] Boolean
|
- [ ] Boolean
|
||||||
- [ ] Infinite
|
- [ ] Infinite
|
||||||
- [ ] Displacement
|
- [x] Displacement
|
||||||
- [ ] Twist
|
- [ ] Twist
|
||||||
- [ ] Bend
|
- [ ] Bend
|
||||||
|
|
||||||
|
|||||||
20
sdf.glsl
20
sdf.glsl
@@ -5,6 +5,7 @@ out vec4 FragColor;
|
|||||||
in vec2 texCoords;
|
in vec2 texCoords;
|
||||||
|
|
||||||
uniform float aspect;
|
uniform float aspect;
|
||||||
|
uniform float t;
|
||||||
|
|
||||||
vec3 center = vec3(0.0,-4.0,20.0);
|
vec3 center = vec3(0.0,-4.0,20.0);
|
||||||
float radius = 5.0;
|
float radius = 5.0;
|
||||||
@@ -27,7 +28,7 @@ struct Ray {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ray createRay(vec3 dir, vec3 pos){
|
Ray createRay(vec3 dir, vec3 pos){
|
||||||
return Ray(dir, pos, .0, .0, SmallHit(80.,0.,false), vec3(.0));
|
return Ray(dir, pos, .0, .0, SmallHit(80.,0.,false), vec3(1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ray applyMin(Ray ray, float min) {
|
Ray applyMin(Ray ray, float min) {
|
||||||
@@ -51,7 +52,7 @@ Ray applyMin(Ray ray, float min) {
|
|||||||
|
|
||||||
|
|
||||||
float planeMin(vec3 pos){
|
float planeMin(vec3 pos){
|
||||||
return pos.y - planeHeight;
|
return pos.y - planeHeight+ 0.2*sin(5*pos.x+t)*sin(5*pos.y+t)*sin(5*pos.z+t);
|
||||||
}
|
}
|
||||||
|
|
||||||
float sphereMin(vec3 pos){
|
float sphereMin(vec3 pos){
|
||||||
@@ -87,11 +88,13 @@ Ray march(Ray ray){
|
|||||||
//ray.min = minFn(ray.pos);
|
//ray.min = minFn(ray.pos);
|
||||||
ray = minFn(ray);
|
ray = minFn(ray);
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while(( c < 200) && (ray.min < 100.0f) && (ray.min > 0.01f) ) {
|
while(( c < 1000) && (ray.min < 100.0f) && (ray.min > 0.01f) ) {
|
||||||
ray = minFn(ray);
|
ray = minFn(ray);
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
|
if(ray.min > 0.01){
|
||||||
|
ray.color = vec3(1.0);
|
||||||
|
}
|
||||||
return ray;
|
return ray;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,11 +144,14 @@ void main()
|
|||||||
|
|
||||||
light *= shLeve;
|
light *= shLeve;
|
||||||
|
|
||||||
|
Ray reflectR = createRay(reflect(ray.dir,normal),ray.pos + 0.1* normal);
|
||||||
|
reflectR = march(reflectR);
|
||||||
|
|
||||||
if(ray.min <= 0.2){
|
if(ray.min <= 0.2){
|
||||||
//FragColor = vec4(vec3(shRay.small.min)*0.1,1.0);
|
//FragColor = vec4(0,1,0,1.0);
|
||||||
FragColor = vec4(ray.color * (light+0.3), 1.0);
|
FragColor = vec4(mix(ray.color,reflectR.color,0.3) * (light+0.3), 1.0);
|
||||||
} else {
|
} else {
|
||||||
FragColor = vec4(.0,0.0,0.0,1.0);
|
FragColor = vec4(ray.color,1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user