Fixed bugs, updated engine, added mouse offset, updated .gitignore

This commit is contained in:
Dawid Pietrykowski 2023-06-06 19:52:49 +02:00
parent 672758f7ec
commit c9aa6b9f52
9 changed files with 237 additions and 353 deletions

4
.gitignore vendored
View File

@ -1,2 +1,6 @@
CMakeFiles CMakeFiles
CMakeCache.txt CMakeCache.txt
cmake-build-debug
.idea
.vscode
build

View File

@ -18,6 +18,9 @@ cmake_policy(SET CMP0074 NEW)
# Convert relative paths to absolute in target_sources() # Convert relative paths to absolute in target_sources()
cmake_policy(SET CMP0076 NEW) cmake_policy(SET CMP0076 NEW)
# Use new OpenGL
cmake_policy(SET CMP0072 NEW)
# Copy files from source directory to destination directory, substituting any # Copy files from source directory to destination directory, substituting any
# variables. Create destination directory if it does not exist. # variables. Create destination directory if it does not exist.
@ -56,43 +59,18 @@ set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h find_package(glfw3 CONFIG REQUIRED)
HINTS
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/lib
${GLFW_ROOT}
${GLFW_ROOT}/include)
if(GLFW_INCLUDE_DIR)
message(STATUS "GLFW_INCLUDE_DIR: ${GLFW_INCLUDE_DIR}")
else()
message(FATAL_ERROR "glfw3.h not found")
endif()
find_path(GLFW_LIB_DIR glfw3.lib
HINTS
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/lib
${GLFW_ROOT}/lib
${GLFW_ROOT}/lib-vc2019
${GLFW_ROOT}/lib-vc2017
${GLFW_ROOT}/lib-vc2015)
if(GLFW_LIB_DIR)
message(STATUS "GLFW_LIB_DIR: ${GLFW_LIB_DIR}")
else()
message(FATAL_ERROR "glfw3.lib not found")
endif()
# Find GLEW # Find GLEW
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
if(GLEW_FOUND) if(GLEW_FOUND)
set(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIRS}) set(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIRS})
get_filename_component(GLEW_LIBRARIES ${GLEW_LIBRARIES} DIRECTORY) #get_filename_component(GLEW_LIBRARIES ${GLEW_LIBRARIES} DIRECTORY)
message(STATUS "GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}") message(STATUS "GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}")
message(STATUS "GLEW_LIBRARIES: ${GLEW_LIBRARIES}") #message(STATUS "GLEW_LIBRARIES: ${GLEW_LIBRARIES}")
else() else()
message(FATAL_ERROR "GLEW not found") message(FATAL_ERROR "GLEW not found")
endif() endif()
@ -105,22 +83,18 @@ endif()
# Find stb_image # Find stb_image
find_path(stb_image_INCLUDE_DIR stb_image.h find_package(Stb REQUIRED)
HINTS
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/stb
${CMAKE_CURRENT_SOURCE_DIR}/lib
${stb_image_ROOT})
if(stb_image_INCLUDE_DIR) if(Stb_INCLUDE_DIR)
message(STATUS "stb_image_INCLUDE_DIR: ${stb_image_INCLUDE_DIR}") message(STATUS "Stb_INCLUDE_DIR: ${Stb_INCLUDE_DIR}")
else() else()
message(FATAL_ERROR "stb_image not found") message(FATAL_ERROR "stb_image not found")
endif() endif()
# Find ComputeEngine find_path(ComputeEngine_LIB_DIR
NAMES
find_path(ComputeEngine_LIB_DIR ComputeEngine.lib ComputeEngine.lib
libComputeEngine.a
HINTS HINTS
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}/lib
@ -128,7 +102,11 @@ ${ComputeEngine_ROOT}
${ComputeEngine_ROOT}/lib ${ComputeEngine_ROOT}/lib
${ComputeEngine_ROOT}/lib/Release ${ComputeEngine_ROOT}/lib/Release
${ComputeEngine_ROOT}/build/lib ${ComputeEngine_ROOT}/build/lib
${ComputeEngine_ROOT}/build/lib/Release) ${ComputeEngine_ROOT}/build/lib/Release
ComputeEngine/lib
ComputeEngine/lib/Release
ComputeEngine/build/lib
ComputeEngine/build/lib/Release)
if(ComputeEngine_LIB_DIR) if(ComputeEngine_LIB_DIR)
message(STATUS "ComputeEngine_LIB_DIR: ${ComputeEngine_LIB_DIR}") message(STATUS "ComputeEngine_LIB_DIR: ${ComputeEngine_LIB_DIR}")
@ -138,6 +116,7 @@ endif()
find_path(ComputeEngine_INCLUDE_DIR ComputeEngine.h find_path(ComputeEngine_INCLUDE_DIR ComputeEngine.h
HINTS HINTS
${CMAKE_CURRENT_SOURCE_DIR}/ComputeEngine/src
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}/lib
${ComputeEngine_ROOT} ${ComputeEngine_ROOT}
@ -150,20 +129,39 @@ else()
message(FATAL_ERROR "ComputeEngine.h not found") message(FATAL_ERROR "ComputeEngine.h not found")
endif() endif()
message(STATUS "GLFW_INCLUDE_DIR: ${GLFW_INCLUDE_DIR}")
message(STATUS "OPENGL_INCLUDE_DIR: ${OPENGL_INCLUDE_DIR}")
message(STATUS "stb_image_INCLUDE_DIR: ${stb_image_INCLUDE_DIR}")
message(STATUS "GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}")
message(STATUS "ComputeEngine_INCLUDE_DIR: ${ComputeEngine_INCLUDE_DIR}")
# Add source # Add source
add_subdirectory(src) add_subdirectory(src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
${GLFW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}
${stb_image_INCLUDE_DIR} ${Stb_INCLUDE_DIR}
${ComputeEngine_INCLUDE_DIR} ${ComputeEngine_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}) ${ComputeEngine_INCLUDE_DIRS}
${GLEW_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PUBLIC ${GLFW_LIB_DIR} ${GLEW_LIBRARIES} ${ComputeEngine_LIB_DIR}) target_link_directories(${PROJECT_NAME} PUBLIC ${GLFW_LIB_DIR} ${GLEW_LIBRARIES} ${ComputeEngine_LIB_DIR} ${ComputeEngine_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} "glfw3.lib" "opengl32.lib" "glew32s.lib" "ComputeEngine.lib")
if(WIN32)
target_link_libraries(${PROJECT_NAME} glfw GLEW::GLEW ComputeEngine)
else()
target_link_libraries(${PROJECT_NAME} glfw OpenGL::GL GLEW::GLEW ComputeEngine)
endif()
# Copy shaders, assets and configs for binaries to access # Copy shaders, assets and configs for binaries to access
file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR}/Release) #file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR}/Release)
file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR}) #file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR})
add_custom_target(copy_shaders ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/shaders" "${CMAKE_BINARY_DIR}/shaders"
COMMENT "Copy shaders to build tree"
VERBATIM)
add_dependencies(${PROJECT_NAME} copy_shaders)

@ -1 +1 @@
Subproject commit b2e43b2ea76e8d8d0fa674b2ec2ec515cbb82765 Subproject commit 24064274c5a41559f547408faf97708031b36f0b

7
make_all.sh Executable file
View File

@ -0,0 +1,7 @@
ComputeEngine_ROOT=$(dirname $0)/ComputeEngine
vcpkg_ROOT=$1
cmake -B ComputeEngine/build -S ComputeEngine -DCMAKE_TOOLCHAIN_FILE=$vcpkg_ROOT
cmake --build ComputeEngine/build --config Release
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=$vcpkg_ROOT
cmake --build build --config Release

View File

@ -4,9 +4,9 @@
//layout(local_size_x = 8, local_size_y = 8) in; //layout(local_size_x = 8, local_size_y = 8) in;
layout(local_size_x = 1) in; layout(local_size_x = 1) in;
//#define LORENZ #define LORENZ
#define CLIFFORD // #define CLIFFORD
//#define DREAM // #define DREAM
layout(rgba32f) uniform image2D img_output; layout(rgba32f) uniform image2D img_output;
uniform sampler2D u_skybox; uniform sampler2D u_skybox;
@ -31,7 +31,7 @@ layout(std140, binding=2) uniform shader_data{
int _sample; // 4 64 int _sample; // 4 64
int _samples; // 4 68 int _samples; // 4 68
float dt; // 4 72 float dt; // 4 72
vec2 padding; // 4 * 2 80 vec2 mouse_movement; // 4 * 2 80
}; };
layout (std430, binding = 3) coherent buffer object_data{ layout (std430, binding = 3) coherent buffer object_data{
SceneObject objects[]; SceneObject objects[];
@ -75,6 +75,13 @@ ivec2 GetPixelCoords(float x, float y){
void main(){ void main(){
int id = int(gl_GlobalInvocationID.x); int id = int(gl_GlobalInvocationID.x);
if(mouse_movement.x != 0 || mouse_movement.y != 0)
{
objects[id].position.x -= mouse_movement.x * 3;
objects[id].position.y += mouse_movement.y * 3;
return;
}
float x = objects[id].position.x; float x = objects[id].position.x;
float y = objects[id].position.y; float y = objects[id].position.y;
float z = objects[id].position.z; float z = objects[id].position.z;
@ -88,14 +95,16 @@ void main(){
vec4 color = vec4(0); vec4 color = vec4(0);
//color = mix(color, pixel, .99999f); //color = mix(color, pixel, .99999f);
color = mix(color, pixel, .9999f); color = mix(color, pixel, .99f);
//color = mix(color, pixel, .2f); // color = mix(color, pixel, .2f);
//imageStore(img_output, coords, pixel + color * .05f); //imageStore(img_output, coords, pixel + color * .05f);
//imageStore(img_output, coords, pixel + color * .0001f); //imageStore(img_output, coords, pixel + color * .0001f);
imageStore(img_output, coords, color); imageStore(img_output, coords, color);
#ifdef LORENZ // for(int i = 0; i < iterations; i++){
#ifdef LORENZ
float s=10.0f; float s=10.0f;
float r=28.0f; float r=28.0f;
float b=2.667f; float b=2.667f;
@ -107,9 +116,9 @@ void main(){
objects[id].position.x += x_dot * .001f * dt; objects[id].position.x += x_dot * .001f * dt;
objects[id].position.y += y_dot * .001f * dt; objects[id].position.y += y_dot * .001f * dt;
objects[id].position.z += z_dot * .001f * dt; objects[id].position.z += z_dot * .001f * dt;
#endif #endif
#ifdef CLIFFORD #ifdef CLIFFORD
float a =-1.7f; float a =-1.7f;
float b = 1.8f; float b = 1.8f;
float c =-1.9f; float c =-1.9f;
@ -117,9 +126,9 @@ void main(){
objects[id].position.x = sin(a*y)+c*cos(a*x); objects[id].position.x = sin(a*y)+c*cos(a*x);
objects[id].position.y = sin(b*x)+d*cos(b*y); objects[id].position.y = sin(b*x)+d*cos(b*y);
#endif #endif
#ifdef DREAM #ifdef DREAM
float a =-2.8276f; float a =-2.8276f;
float b = 1.2813f; float b = 1.2813f;
float c =1.9655f; float c =1.9655f;
@ -127,5 +136,10 @@ void main(){
objects[id].position.x = sin(y*b)+c*sin(x*b); objects[id].position.x = sin(y*b)+c*sin(x*b);
objects[id].position.y = sin(x*a)+d*sin(y*a); objects[id].position.y = sin(x*a)+d*sin(y*a);
#endif #endif
// x = objects[id].position.x;
// y = objects[id].position.y;
// z = objects[id].position.z;
// }
} }

View File

@ -1,133 +0,0 @@
#version 430 core
#define PI 3.1415926538f
//layout(local_size_x = 8, local_size_y = 8) in;
layout(local_size_x = 1) in;
//#define LORENZ
#define CLIFFORD
//#define DREAM
layout(rgba32f) uniform image2D img_output;
uniform sampler2D u_skybox;
uniform sampler2D u_tex1;
uniform sampler2D u_tex2;
uniform sampler2D u_tex3;
uniform sampler2D u_tex4;
uniform sampler2D u_tex5;
struct SceneObject{
vec4 position;
};
layout(std140, binding=2) uniform shader_data{
vec4 camera_position; // 4 * 4 16
vec4 camera_rotation; // 4 * 4 32
vec2 _PixelOffset; // 4 * 2 40
ivec2 screenSize; // 4 * 2 48
int iterations; // 4 52
float _Seed; // 4 56
int objectcount; // 4 60
int _sample; // 4 64
int _samples; // 4 68
float dt; // 4 72
vec2 padding; // 4 * 2 80
};
layout (std430, binding = 3) coherent buffer object_data{
SceneObject objects[];
};
float distlimit = 500;
float seed = _Seed;
int samples = _samples;
vec2 _Pixel;
float rand(){
float result = fract(sin(seed / 100.0f * dot(_Pixel, vec2(12.9898f, 78.233f))) * 43758.5453f);
seed += 1.0f;
return result;
}
ivec2 GetPixelCoords(float x, float y){
#ifdef LORENZ
float div = 30.0f;
#endif
#ifdef CLIFFORD
float div = 3.0f;
#endif
#ifdef DREAM
float div = 3.0f;
#endif
x = x / div;
y = y / div;
x += 1;
y += 1;
x /= 2.0f;
y /= 2.0f;
return ivec2(int(x * screenSize.x + 0.5f), int(y * screenSize.y + 0.5f));
}
void main(){
/*
int id = int(gl_GlobalInvocationID.x);
float x = objects[id].position.x;
float y = objects[id].position.y;
float z = objects[id].position.z;
ivec2 coords = GetPixelCoords(x, y);
vec4 pixel = imageLoad(img_output, coords);
//vec4 color = (vec4(249.0f, 29.0f, 0.0f, 255.0f) / 255.0f);
//vec4 color = (vec4(249.0f, 29.0f, 0.0f, 255.0f) / 255.0f);
vec4 color = vec4(0);
//color = mix(color, pixel, .99999f);
color = mix(color, pixel, .9999f);
//color = mix(color, pixel, .2f);
//imageStore(img_output, coords, pixel + color * .05f);
//imageStore(img_output, coords, pixel + color * .0001f);
imageStore(img_output, coords, color);
#ifdef LORENZ
float s=10.0f;
float r=28.0f;
float b=2.667f;
float x_dot = s*(y - x);
float y_dot = r*x - y - x*z;
float z_dot = x*y - b*z;
objects[id].position.x += x_dot * .001f * dt;
objects[id].position.y += y_dot * .001f * dt;
objects[id].position.z += z_dot * .001f * dt;
#endif
#ifdef CLIFFORD
float a =-1.7f;
float b = 1.8f;
float c =-1.9f;
float d =-0.4f;
objects[id].position.x = sin(a*y)+c*cos(a*x);
objects[id].position.y = sin(b*x)+d*cos(b*y);
#endif
#ifdef DREAM
float a =-2.8276f;
float b = 1.2813f;
float c =1.9655f;
float d =0.597f;
objects[id].position.x = sin(y*b)+c*sin(x*b);
objects[id].position.y = sin(x*a)+d*sin(y*a);
#endif
*/
}

View File

@ -18,7 +18,7 @@ public:
int _sample = 1; int _sample = 1;
int samples = 1; int samples = 1;
float dt = .000001f; float dt = .000001f;
std::array<float, 2> padding = {0, 0}; std::array<float, 2> mouse_movement = {0, 0};
void UpdateSeed(); void UpdateSeed();
void UpdateWindowSize(int width, int height); void UpdateWindowSize(int width, int height);
void GetWindowSize(int& width, int& height); void GetWindowSize(int& width, int& height);

View File

@ -4,21 +4,34 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#define ASSERT(x) if(!(x)){ cout << "[ERROR] " << #x << '\n';\ #ifdef _MSC_VER
__debugbreak();} #define DEBUG_BREAK __debugbreak();
//#define GLCall(x) glClearError();\ #else
// x;\ #include <csignal>
// ASSERT(glErrorCheck()) #define DEBUG_BREAK raise(SIGTRAP);
#endif
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define ASSERT(x) \
if (!(x)) \
{ \
std::cout << "[ERROR] " << #x << '\n'; \
DEBUG_BREAK \
}
#define GLCall(x) \ #define GLCall(x) \
glClearError();\ glClearError(); \
x;\ x; \
if(!(glErrorCheck())){ cout << "[ERROR] " << #x << '\n';\ if (!(glErrorCheck())) \
__debugbreak();} { \
std::cout << "[ERROR] " << #x << '\n'; \
DEBUG_BREAK \
}
void PrintSizeLimits(); void PrintSizeLimits();
bool glErrorCheck(); bool glErrorCheck();
void glClearError(); void glClearError();
float getRand(); float getRand();
bool fileExists(const std::string & name); bool fileExists(const std::string &name);

View File

@ -1,4 +1,5 @@
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
//#define HYDROGEN
#include <math.h> #include <math.h>
#include <cmath> #include <cmath>
@ -17,16 +18,16 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
float sensitivity = 10.0f; void UpdateKeys(ComputeEngine &renderer, std::vector<SceneObject> &objects, shader_data_t &shader_data, Texture &tex_output)
{
void UpdateKeys(ComputeEngine& renderer, CameraData& camera, std::vector<SceneObject>& objects, shader_data_t& shader_data, Texture& tex_output) { if (renderer.IsKeyClicked(GLFW_KEY_P))
if (renderer.IsKeyClicked(GLFW_KEY_P)) { {
renderer.SwitchInput(); renderer.SwitchInput();
} }
if (renderer.GetInput()) { if (renderer.GetInput())
if (renderer.IsKeyClicked(GLFW_KEY_F11)) { {
if (renderer.IsKeyClicked(GLFW_KEY_F11))
renderer.SwitchFullScreen(); renderer.SwitchFullScreen();
}
if (renderer.IsKeyClicked(GLFW_KEY_ESCAPE)) if (renderer.IsKeyClicked(GLFW_KEY_ESCAPE))
renderer.CloseWindow(); renderer.CloseWindow();
if (renderer.IsKeyClicked(GLFW_KEY_L)) if (renderer.IsKeyClicked(GLFW_KEY_L))
@ -39,17 +40,18 @@ void UpdateKeys(ComputeEngine& renderer, CameraData& camera, std::vector<SceneOb
tex_output.Resize(shader_data.GetWidth(), shader_data.GetHeight()); tex_output.Resize(shader_data.GetWidth(), shader_data.GetHeight());
} }
void UpdateInput(ComputeEngine& renderer, CameraData& camera, std::vector<SceneObject>& objects, shader_data_t& shader_data, Texture& tex_output) { void UpdateInput(ComputeEngine &renderer, std::vector<SceneObject> &objects, shader_data_t &shader_data, Texture &tex_output)
{
renderer.PollEvents(); renderer.PollEvents();
UpdateKeys(renderer, camera, objects, shader_data, tex_output); UpdateKeys(renderer, objects, shader_data, tex_output);
double dx, dy; double dx, dy;
renderer.GetMouseDelta(dx, dy); renderer.GetMouseDelta(dx, dy);
dx *= (renderer.GetFrametime() / 1000.0); dx *= (renderer.GetFrametime() / 1000.0);
dy *= (renderer.GetFrametime() / 1000.0); dy *= (renderer.GetFrametime() / 1000.0);
camera.rotateCamera(dx, dy); shader_data.mouse_movement[0] = (float)dx;
camera.updateCameraData(renderer.GetFrametime() / 1000.0); shader_data.mouse_movement[1] = (float)dy;
} }
int main(void) int main(void)
@ -59,79 +61,90 @@ int main(void)
int width = 1024; int width = 1024;
int height = 1024; int height = 1024;
// init renderer
ComputeEngine renderer(width, height, "Hydrogen wave function", true);
Shader shader("../shaders/hydrogen_wave/pixelCompute.compute");
Program compute_program(shader);
// init data for shader // init data for shader
shader_data_t shader_data = {}; shader_data_t shader_data = {};
shader_data.screenSize = { width, height }; shader_data.screenSize = {width, height};
shader_data.iterations = 2; #ifdef HYDROGEN
shader_data.samples = 1; // init renderer
shader_data.dt = .0000001; ComputeEngine renderer(width, height, "Hydrogen wave function", true);
Shader shader("shaders/hydrogen_wave/pixelCompute.compute");
// create scene Program pixel_program(shader);
const int spheres = 0; #else
// init renderer
int points = 0; ComputeEngine renderer(width, height, "Attractors", true);
float mul = 5; Shader shader("shaders/attractors/objectCompute.compute");
Shader pixelShader("shaders/attractors/pixelCompute.compute");
std::vector<SceneObject> objects; Program compute_program(shader);
//objects.reserve(points); Program pixel_program(pixelShader);
//for (int i = 0; i < points; i++) { #endif
// objects.push_back(SceneObject());
// objects[i].position[0] = (getRand() - 0.5f) * mul;
// objects[i].position[1] = (getRand() - 0.5f) * mul;
// objects[i].position[2] = (getRand() - 0.5f) * mul;
//}
// init textures // init textures
Texture tex_output("img_output", width, height); Texture tex_output("img_output", width, height);
// init buffers // init buffers
UBO data_buffer(2); UBO data_buffer(2);
//SSBO objects_buffer(3);
std::vector<SceneObject> objects;
// create scene
#ifdef HYDROGEN
shader_data.iterations = 2;
shader_data.samples = 1;
shader_data.dt = .05f;
#else
shader_data.dt = 1.5f;
shader_data.iterations = 10;
SSBO objects_buffer(3);
int points = 20000;
float mul = 25;
objects.reserve(points);
for (int i = 0; i < points; i++)
{
objects.emplace_back();
objects[i].position[0] = (getRand() - 0.5f) * mul;
objects[i].position[1] = (getRand() - 0.5f) * mul;
objects[i].position[2] = (getRand() - 0.5f) * mul;
}
objects_buffer.Set(&objects);
#endif
// fill buffers with data // fill buffers with data
data_buffer.Set(&shader_data); data_buffer.Set(&shader_data);
//objects_buffer.Set(&objects);
// init camera
CameraData camera;
camera.position = { 0, 15, -47 };
camera.rotation = { -23, 0, 0 };
camera.sensitivity = sensitivity;
camera.m_width = width;
camera.m_height = height;
camera.CopyData(shader_data);
// bind textures // bind textures
compute_program.BindTextureImage(tex_output, 0); pixel_program.BindTextureImage(tex_output, 0);
compute_program.SetUniform1i("width", width); #ifdef HYDROGEN
compute_program.SetUniform1i("height", height); pixel_program.SetUniform1i("width", width);
pixel_program.SetUniform1i("height", height);
int n, l, m; int n, l, m;
n = 4; n = 4;
l = 2; l = 2;
m = 1; m = 1;
compute_program.SetUniform1i("quantum_n", n); pixel_program.SetUniform1i("quantum_n", n);
compute_program.SetUniform1i("quantum_l", l); pixel_program.SetUniform1i("quantum_l", l);
compute_program.SetUniform1i("quantum_m", m); pixel_program.SetUniform1i("quantum_m", m);
// dispatch compute shader
//renderer.DispatchPixelCompute(shader_data.GetWidth(), shader_data.GetHeight());
printf("width: %d\ height: %d\n", shader_data.GetWidth(), shader_data.GetHeight());
printf("points: %d\n", objects.size());
float last_dt = renderer.GetFrametime();
float phi = 0; float phi = 0;
while (!renderer.ShouldClose()) { pixel_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight());
#else
compute_program.BindTextureImage(tex_output, 0);
pixel_program.SetUniform1i("_pass", 0);
pixel_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight());
printf("points: %d\n", (int)objects.size());
#endif
printf("width: %d\ height: %d\n", shader_data.GetWidth(), shader_data.GetHeight());
while (!renderer.ShouldClose())
{
#ifdef HYDROGEN
// update input // update input
UpdateInput(renderer, camera, objects, shader_data, tex_output); UpdateInput(renderer, objects, shader_data, tex_output);
phi += (renderer.GetFrametime() / 1000.0) * M_PI * 0.5; phi += (renderer.GetFrametime() / 1000.0) * M_PI * 0.5;
@ -139,71 +152,39 @@ int main(void)
printf("phi: %.2f\n", phi); printf("phi: %.2f\n", phi);
// update variables // update variables
compute_program.SetUniform1f("u_phi", phi); pixel_program.SetUniform1f("u_phi", phi);
// dispatch compute shader // dispatch compute shader
compute_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight()); pixel_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight());
renderer.UpdateFrametime(); renderer.UpdateFrametime();
// draw rendered image // draw rendered image
renderer.DrawTexture(tex_output); renderer.DrawTexture(tex_output);
#else
/*
if (0) {
// update input // update input
camera.SetChanged(false); UpdateInput(renderer, objects, shader_data, tex_output);
UpdateInput(renderer, camera, objects, shader_data, tex_output);
shader_data.UpdateSeed(); shader_data.UpdateSeed();
//shader_data.dt = (renderer.m_framecount - 1 % 40 != 0) ? renderer.GetFrametime() : last_dt;
shader_data.dt = .5f;
shader_data.objectcount = objects.size();
camera.UpdateWindowSize(shader_data.GetWidth(), shader_data.GetHeight());
camera.CopyData(shader_data);
// update buffers // update buffers
data_buffer.Update(&shader_data); data_buffer.Update(&shader_data);
//objects_buffer.Update(&objects);
renderer.m_PixelComputeProgram.SetUniform("_pass", renderer.m_framecount); if(shader_data.mouse_movement[0] != 0 || shader_data.mouse_movement[1] != 0)
pixel_program.SetUniform1i("_pass", 0);
else
pixel_program.SetUniform1i("_pass", renderer.GetFramecount());
// dispatch compute shader // dispatch compute shader
renderer.DispatchObjectCompute(objects.size()); compute_program.DispatchCompute((int)objects.size());
// dispatch compute shader // dispatch compute shader
renderer.DispatchPixelCompute(shader_data.GetWidth(), shader_data.GetHeight()); pixel_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight());
//print frametime renderer.UpdateFrametime();
if (renderer.m_framecount % 5 == 0) {
//printf("%.2f ms\n", renderer.GetFrametime());
//printf("%.2f ms\n", shader_data.dt);
// draw rendered image
renderer.DrawTexture(tex_output); renderer.DrawTexture(tex_output);
#endif
//printf("x %.2f y %.2f\n", objects[0].position[0], objects[0].position[1]);
} }
//print frametime // print average frametime
if (renderer.m_framecount % 1000 == 0) {
//printf("%.2f ms\n", renderer.GetFrametime());
printf("%.2f ms\n", shader_data.dt);
// draw rendered image
//renderer.DrawTexture(tex_output);
//printf("x %.2f y %.2f\n", objects[0].position[0], objects[0].position[1]);
}
// glFinish call
renderer.Finish();
}
*/
}
//print average frametime
printf("Avg frametime: %.3f", renderer.GetAverageFrametime()); printf("Avg frametime: %.3f", renderer.GetAverageFrametime());
return 0; return 0;