Fixed bugs, updated engine, added mouse offset, updated .gitignore
This commit is contained in:
parent
672758f7ec
commit
c9aa6b9f52
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
CMakeFiles
|
||||
CMakeCache.txt
|
||||
cmake-build-debug
|
||||
.idea
|
||||
.vscode
|
||||
build
|
||||
|
@ -18,6 +18,9 @@ cmake_policy(SET CMP0074 NEW)
|
||||
# Convert relative paths to absolute in target_sources()
|
||||
cmake_policy(SET CMP0076 NEW)
|
||||
|
||||
# Use new OpenGL
|
||||
cmake_policy(SET CMP0072 NEW)
|
||||
|
||||
# Copy files from source directory to destination directory, substituting any
|
||||
# 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_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
|
||||
find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h
|
||||
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_package(glfw3 CONFIG REQUIRED)
|
||||
|
||||
# Find GLEW
|
||||
|
||||
|
||||
find_package(GLEW REQUIRED)
|
||||
|
||||
if(GLEW_FOUND)
|
||||
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_LIBRARIES: ${GLEW_LIBRARIES}")
|
||||
#message(STATUS "GLEW_LIBRARIES: ${GLEW_LIBRARIES}")
|
||||
else()
|
||||
message(FATAL_ERROR "GLEW not found")
|
||||
endif()
|
||||
@ -105,22 +83,18 @@ endif()
|
||||
|
||||
# Find stb_image
|
||||
|
||||
find_path(stb_image_INCLUDE_DIR stb_image.h
|
||||
HINTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/stb
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib
|
||||
${stb_image_ROOT})
|
||||
find_package(Stb REQUIRED)
|
||||
|
||||
if(stb_image_INCLUDE_DIR)
|
||||
message(STATUS "stb_image_INCLUDE_DIR: ${stb_image_INCLUDE_DIR}")
|
||||
if(Stb_INCLUDE_DIR)
|
||||
message(STATUS "Stb_INCLUDE_DIR: ${Stb_INCLUDE_DIR}")
|
||||
else()
|
||||
message(FATAL_ERROR "stb_image not found")
|
||||
endif()
|
||||
|
||||
# Find ComputeEngine
|
||||
|
||||
find_path(ComputeEngine_LIB_DIR ComputeEngine.lib
|
||||
find_path(ComputeEngine_LIB_DIR
|
||||
NAMES
|
||||
ComputeEngine.lib
|
||||
libComputeEngine.a
|
||||
HINTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib
|
||||
@ -128,7 +102,11 @@ ${ComputeEngine_ROOT}
|
||||
${ComputeEngine_ROOT}/lib
|
||||
${ComputeEngine_ROOT}/lib/Release
|
||||
${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)
|
||||
message(STATUS "ComputeEngine_LIB_DIR: ${ComputeEngine_LIB_DIR}")
|
||||
@ -138,6 +116,7 @@ endif()
|
||||
|
||||
find_path(ComputeEngine_INCLUDE_DIR ComputeEngine.h
|
||||
HINTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ComputeEngine/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib
|
||||
${ComputeEngine_ROOT}
|
||||
@ -150,20 +129,39 @@ else()
|
||||
message(FATAL_ERROR "ComputeEngine.h not found")
|
||||
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_subdirectory(src)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${GLFW_INCLUDE_DIR}
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
${stb_image_INCLUDE_DIR}
|
||||
${Stb_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_libraries(${PROJECT_NAME} "glfw3.lib" "opengl32.lib" "glew32s.lib" "ComputeEngine.lib")
|
||||
target_link_directories(${PROJECT_NAME} PUBLIC ${GLFW_LIB_DIR} ${GLEW_LIBRARIES} ${ComputeEngine_LIB_DIR} ${ComputeEngine_INCLUDE_DIR})
|
||||
|
||||
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
|
||||
file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR}/Release)
|
||||
file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR})
|
||||
#file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR}/Release)
|
||||
#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
7
make_all.sh
Executable 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
|
@ -4,9 +4,9 @@
|
||||
//layout(local_size_x = 8, local_size_y = 8) in;
|
||||
layout(local_size_x = 1) in;
|
||||
|
||||
//#define LORENZ
|
||||
#define CLIFFORD
|
||||
//#define DREAM
|
||||
#define LORENZ
|
||||
// #define CLIFFORD
|
||||
// #define DREAM
|
||||
|
||||
layout(rgba32f) uniform image2D img_output;
|
||||
uniform sampler2D u_skybox;
|
||||
@ -31,7 +31,7 @@ layout(std140, binding=2) uniform shader_data{
|
||||
int _sample; // 4 64
|
||||
int _samples; // 4 68
|
||||
float dt; // 4 72
|
||||
vec2 padding; // 4 * 2 80
|
||||
vec2 mouse_movement; // 4 * 2 80
|
||||
};
|
||||
layout (std430, binding = 3) coherent buffer object_data{
|
||||
SceneObject objects[];
|
||||
@ -75,6 +75,13 @@ ivec2 GetPixelCoords(float x, float y){
|
||||
void main(){
|
||||
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 y = objects[id].position.y;
|
||||
float z = objects[id].position.z;
|
||||
@ -88,44 +95,51 @@ void main(){
|
||||
vec4 color = vec4(0);
|
||||
|
||||
//color = mix(color, pixel, .99999f);
|
||||
color = mix(color, pixel, .9999f);
|
||||
//color = mix(color, pixel, .2f);
|
||||
color = mix(color, pixel, .99f);
|
||||
// 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;
|
||||
// for(int i = 0; i < iterations; i++){
|
||||
|
||||
float x_dot = s*(y - x);
|
||||
float y_dot = r*x - y - x*z;
|
||||
float z_dot = x*y - b*z;
|
||||
#ifdef LORENZ
|
||||
float s=10.0f;
|
||||
float r=28.0f;
|
||||
float b=2.667f;
|
||||
|
||||
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
|
||||
float x_dot = s*(y - x);
|
||||
float y_dot = r*x - y - x*z;
|
||||
float z_dot = x*y - b*z;
|
||||
|
||||
#ifdef CLIFFORD
|
||||
float a =-1.7f;
|
||||
float b = 1.8f;
|
||||
float c =-1.9f;
|
||||
float d =-0.4f;
|
||||
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
|
||||
|
||||
objects[id].position.x = sin(a*y)+c*cos(a*x);
|
||||
objects[id].position.y = sin(b*x)+d*cos(b*y);
|
||||
#endif
|
||||
#ifdef CLIFFORD
|
||||
float a =-1.7f;
|
||||
float b = 1.8f;
|
||||
float c =-1.9f;
|
||||
float d =-0.4f;
|
||||
|
||||
#ifdef DREAM
|
||||
float a =-2.8276f;
|
||||
float b = 1.2813f;
|
||||
float c =1.9655f;
|
||||
float d =0.597f;
|
||||
objects[id].position.x = sin(a*y)+c*cos(a*x);
|
||||
objects[id].position.y = sin(b*x)+d*cos(b*y);
|
||||
#endif
|
||||
|
||||
objects[id].position.x = sin(y*b)+c*sin(x*b);
|
||||
objects[id].position.y = sin(x*a)+d*sin(y*a);
|
||||
#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
|
||||
|
||||
// x = objects[id].position.x;
|
||||
// y = objects[id].position.y;
|
||||
// z = objects[id].position.z;
|
||||
// }
|
||||
}
|
@ -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
|
||||
*/
|
||||
}
|
@ -18,7 +18,7 @@ public:
|
||||
int _sample = 1;
|
||||
int samples = 1;
|
||||
float dt = .000001f;
|
||||
std::array<float, 2> padding = {0, 0};
|
||||
std::array<float, 2> mouse_movement = {0, 0};
|
||||
void UpdateSeed();
|
||||
void UpdateWindowSize(int width, int height);
|
||||
void GetWindowSize(int& width, int& height);
|
||||
|
35
src/Utils.h
35
src/Utils.h
@ -4,21 +4,34 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define ASSERT(x) if(!(x)){ cout << "[ERROR] " << #x << '\n';\
|
||||
__debugbreak();}
|
||||
//#define GLCall(x) glClearError();\
|
||||
// x;\
|
||||
// ASSERT(glErrorCheck())
|
||||
#ifdef _MSC_VER
|
||||
#define DEBUG_BREAK __debugbreak();
|
||||
#else
|
||||
#include <csignal>
|
||||
#define DEBUG_BREAK raise(SIGTRAP);
|
||||
#endif
|
||||
|
||||
#define GLCall(x) \
|
||||
glClearError();\
|
||||
x;\
|
||||
if(!(glErrorCheck())){ cout << "[ERROR] " << #x << '\n';\
|
||||
__debugbreak();}
|
||||
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
|
||||
#define ASSERT(x) \
|
||||
if (!(x)) \
|
||||
{ \
|
||||
std::cout << "[ERROR] " << #x << '\n'; \
|
||||
DEBUG_BREAK \
|
||||
}
|
||||
|
||||
#define GLCall(x) \
|
||||
glClearError(); \
|
||||
x; \
|
||||
if (!(glErrorCheck())) \
|
||||
{ \
|
||||
std::cout << "[ERROR] " << #x << '\n'; \
|
||||
DEBUG_BREAK \
|
||||
}
|
||||
|
||||
void PrintSizeLimits();
|
||||
bool glErrorCheck();
|
||||
void glClearError();
|
||||
float getRand();
|
||||
|
||||
bool fileExists(const std::string & name);
|
||||
bool fileExists(const std::string &name);
|
||||
|
209
src/main.cpp
209
src/main.cpp
@ -1,4 +1,5 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
//#define HYDROGEN
|
||||
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
@ -17,16 +18,16 @@
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
float sensitivity = 10.0f;
|
||||
|
||||
void UpdateKeys(ComputeEngine& renderer, CameraData& camera, std::vector<SceneObject>& objects, shader_data_t& shader_data, Texture& tex_output) {
|
||||
if (renderer.IsKeyClicked(GLFW_KEY_P)) {
|
||||
void UpdateKeys(ComputeEngine &renderer, std::vector<SceneObject> &objects, shader_data_t &shader_data, Texture &tex_output)
|
||||
{
|
||||
if (renderer.IsKeyClicked(GLFW_KEY_P))
|
||||
{
|
||||
renderer.SwitchInput();
|
||||
}
|
||||
if (renderer.GetInput()) {
|
||||
if (renderer.IsKeyClicked(GLFW_KEY_F11)) {
|
||||
if (renderer.GetInput())
|
||||
{
|
||||
if (renderer.IsKeyClicked(GLFW_KEY_F11))
|
||||
renderer.SwitchFullScreen();
|
||||
}
|
||||
if (renderer.IsKeyClicked(GLFW_KEY_ESCAPE))
|
||||
renderer.CloseWindow();
|
||||
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());
|
||||
}
|
||||
|
||||
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();
|
||||
UpdateKeys(renderer, camera, objects, shader_data, tex_output);
|
||||
UpdateKeys(renderer, objects, shader_data, tex_output);
|
||||
|
||||
double dx, dy;
|
||||
renderer.GetMouseDelta(dx, dy);
|
||||
dx *= (renderer.GetFrametime() / 1000.0);
|
||||
dy *= (renderer.GetFrametime() / 1000.0);
|
||||
|
||||
camera.rotateCamera(dx, dy);
|
||||
camera.updateCameraData(renderer.GetFrametime() / 1000.0);
|
||||
shader_data.mouse_movement[0] = (float)dx;
|
||||
shader_data.mouse_movement[1] = (float)dy;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -59,79 +61,90 @@ int main(void)
|
||||
int width = 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
|
||||
shader_data_t shader_data = {};
|
||||
shader_data.screenSize = { width, height };
|
||||
shader_data.iterations = 2;
|
||||
shader_data.samples = 1;
|
||||
shader_data.dt = .0000001;
|
||||
|
||||
// create scene
|
||||
const int spheres = 0;
|
||||
|
||||
int points = 0;
|
||||
float mul = 5;
|
||||
|
||||
std::vector<SceneObject> objects;
|
||||
//objects.reserve(points);
|
||||
//for (int i = 0; i < points; i++) {
|
||||
// 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;
|
||||
//}
|
||||
shader_data.screenSize = {width, height};
|
||||
#ifdef HYDROGEN
|
||||
// init renderer
|
||||
ComputeEngine renderer(width, height, "Hydrogen wave function", true);
|
||||
Shader shader("shaders/hydrogen_wave/pixelCompute.compute");
|
||||
Program pixel_program(shader);
|
||||
#else
|
||||
// init renderer
|
||||
ComputeEngine renderer(width, height, "Attractors", true);
|
||||
Shader shader("shaders/attractors/objectCompute.compute");
|
||||
Shader pixelShader("shaders/attractors/pixelCompute.compute");
|
||||
Program compute_program(shader);
|
||||
Program pixel_program(pixelShader);
|
||||
#endif
|
||||
|
||||
// init textures
|
||||
Texture tex_output("img_output", width, height);
|
||||
|
||||
// init buffers
|
||||
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
|
||||
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
|
||||
compute_program.BindTextureImage(tex_output, 0);
|
||||
pixel_program.BindTextureImage(tex_output, 0);
|
||||
|
||||
compute_program.SetUniform1i("width", width);
|
||||
compute_program.SetUniform1i("height", height);
|
||||
#ifdef HYDROGEN
|
||||
pixel_program.SetUniform1i("width", width);
|
||||
pixel_program.SetUniform1i("height", height);
|
||||
int n, l, m;
|
||||
n = 4;
|
||||
l = 2;
|
||||
m = 1;
|
||||
compute_program.SetUniform1i("quantum_n", n);
|
||||
compute_program.SetUniform1i("quantum_l", l);
|
||||
compute_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();
|
||||
pixel_program.SetUniform1i("quantum_n", n);
|
||||
pixel_program.SetUniform1i("quantum_l", l);
|
||||
pixel_program.SetUniform1i("quantum_m", m);
|
||||
|
||||
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
|
||||
UpdateInput(renderer, camera, objects, shader_data, tex_output);
|
||||
UpdateInput(renderer, objects, shader_data, tex_output);
|
||||
|
||||
phi += (renderer.GetFrametime() / 1000.0) * M_PI * 0.5;
|
||||
|
||||
@ -139,71 +152,39 @@ int main(void)
|
||||
printf("phi: %.2f\n", phi);
|
||||
|
||||
// update variables
|
||||
compute_program.SetUniform1f("u_phi", phi);
|
||||
pixel_program.SetUniform1f("u_phi", phi);
|
||||
|
||||
// dispatch compute shader
|
||||
compute_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight());
|
||||
pixel_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight());
|
||||
|
||||
renderer.UpdateFrametime();
|
||||
|
||||
// draw rendered image
|
||||
renderer.DrawTexture(tex_output);
|
||||
#else
|
||||
// update input
|
||||
UpdateInput(renderer, objects, shader_data, tex_output);
|
||||
|
||||
shader_data.UpdateSeed();
|
||||
// update buffers
|
||||
data_buffer.Update(&shader_data);
|
||||
|
||||
/*
|
||||
if (0) {
|
||||
// update input
|
||||
camera.SetChanged(false);
|
||||
UpdateInput(renderer, camera, objects, shader_data, tex_output);
|
||||
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());
|
||||
|
||||
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();
|
||||
// dispatch compute shader
|
||||
compute_program.DispatchCompute((int)objects.size());
|
||||
|
||||
camera.UpdateWindowSize(shader_data.GetWidth(), shader_data.GetHeight());
|
||||
camera.CopyData(shader_data);
|
||||
// dispatch compute shader
|
||||
pixel_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight());
|
||||
|
||||
// update buffers
|
||||
data_buffer.Update(&shader_data);
|
||||
//objects_buffer.Update(&objects);
|
||||
|
||||
renderer.m_PixelComputeProgram.SetUniform("_pass", renderer.m_framecount);
|
||||
|
||||
// dispatch compute shader
|
||||
renderer.DispatchObjectCompute(objects.size());
|
||||
|
||||
// dispatch compute shader
|
||||
renderer.DispatchPixelCompute(shader_data.GetWidth(), shader_data.GetHeight());
|
||||
|
||||
//print frametime
|
||||
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);
|
||||
|
||||
//printf("x %.2f y %.2f\n", objects[0].position[0], objects[0].position[1]);
|
||||
}
|
||||
//print 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();
|
||||
}
|
||||
*/
|
||||
renderer.UpdateFrametime();
|
||||
renderer.DrawTexture(tex_output);
|
||||
#endif
|
||||
}
|
||||
|
||||
//print average frametime
|
||||
// print average frametime
|
||||
printf("Avg frametime: %.3f", renderer.GetAverageFrametime());
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user