commit 672758f7ec9d9328c67f619d59f6e839e71b2967 Author: Dawid Pietrykowski Date: Wed Nov 9 23:54:43 2022 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e0aba9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +CMakeFiles +CMakeCache.txt diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a26395e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ComputeEngine"] + path = ComputeEngine + url = https://git.dawidpietrykowski.com/Personal/ComputeEngine.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..2f3fc4b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,169 @@ +cmake_minimum_required(VERSION 3.10) + +# So library linking is more sane. +cmake_policy(SET CMP0003 NEW) + +# So syntax problems are errors. +cmake_policy(SET CMP0010 NEW) + +# Input directories must have CMakeLists.txt +cmake_policy(SET CMP0014 NEW) + +# Compile definitions. +cmake_policy(SET CMP0043 NEW) + +# Use ROOT variables in find_package. +cmake_policy(SET CMP0074 NEW) + +# Convert relative paths to absolute in target_sources() +cmake_policy(SET CMP0076 NEW) + +# Copy files from source directory to destination directory, substituting any +# variables. Create destination directory if it does not exist. + +macro(configure_files srcDir destDir) + message(STATUS "Configuring directory ${destDir}") + make_directory(${destDir}) + + file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*) + foreach(templateFile ${templateFiles}) + set(srcTemplatePath ${srcDir}/${templateFile}) + if(NOT IS_DIRECTORY ${srcTemplatePath}) + message(STATUS "Configuring file ${templateFile}") + configure_file( + ${srcTemplatePath} + ${destDir}/${templateFile} + @ONLY) + endif(NOT IS_DIRECTORY ${srcTemplatePath}) + endforeach(templateFile) +endmacro(configure_files) + +# Initialize project + +project(ComputePlayground) + +# Add executable +add_executable(${PROJECT_NAME}) + +set(default_build_type "Release") +set(CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}/bin) + +set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + +# Find GLFW + +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 GLEW + +find_package(GLEW REQUIRED) + +if(GLEW_FOUND) +set(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIRS}) +get_filename_component(GLEW_LIBRARIES ${GLEW_LIBRARIES} DIRECTORY) +message(STATUS "GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}") +message(STATUS "GLEW_LIBRARIES: ${GLEW_LIBRARIES}") +else() +message(FATAL_ERROR "GLEW not found") +endif() + +# Find OpenGL + +if(NOT WIN32) + find_package(OpenGL REQUIRED) +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}) + +if(stb_image_INCLUDE_DIR) +message(STATUS "stb_image_INCLUDE_DIR: ${stb_image_INCLUDE_DIR}") +else() +message(FATAL_ERROR "stb_image not found") +endif() + +# Find ComputeEngine + +find_path(ComputeEngine_LIB_DIR ComputeEngine.lib +HINTS +${CMAKE_CURRENT_SOURCE_DIR}/include +${CMAKE_CURRENT_SOURCE_DIR}/lib +${ComputeEngine_ROOT} +${ComputeEngine_ROOT}/lib +${ComputeEngine_ROOT}/lib/Release +${ComputeEngine_ROOT}/build/lib +${ComputeEngine_ROOT}/build/lib/Release) + +if(ComputeEngine_LIB_DIR) +message(STATUS "ComputeEngine_LIB_DIR: ${ComputeEngine_LIB_DIR}") +else() +message(FATAL_ERROR "ComputeEngine.lib not found") +endif() + +find_path(ComputeEngine_INCLUDE_DIR ComputeEngine.h +HINTS +${CMAKE_CURRENT_SOURCE_DIR}/include +${CMAKE_CURRENT_SOURCE_DIR}/lib +${ComputeEngine_ROOT} +${ComputeEngine_ROOT}/include +${ComputeEngine_ROOT}/build/include) + +if(ComputeEngine_INCLUDE_DIR) +message(STATUS "ComputeEngine_INCLUDE_DIR: ${ComputeEngine_INCLUDE_DIR}") +else() +message(FATAL_ERROR "ComputeEngine.h not found") +endif() + +# Add source + +add_subdirectory(src) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src +${GLFW_INCLUDE_DIR} +${OPENGL_INCLUDE_DIR} +${stb_image_INCLUDE_DIR} +${ComputeEngine_INCLUDE_DIR} +${GLEW_INCLUDE_DIR}) + +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") + +# Copy shaders, assets and configs for binaries to access +file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR}/Release) +file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR}) \ No newline at end of file diff --git a/ComputeEngine b/ComputeEngine new file mode 160000 index 0000000..b2e43b2 --- /dev/null +++ b/ComputeEngine @@ -0,0 +1 @@ +Subproject commit b2e43b2ea76e8d8d0fa674b2ec2ec515cbb82765 diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..d6adc5a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Dawid Pietrykowski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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 OR COPYRIGHT HOLDERS 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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..b663151 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +## Dependencies + +* OpenGL +* GLFW +* GLEW +* [stb_image](https://github.com/nothings/stb) + +## Build + +* Clone this directory +* Run git submodule init +* Run git submodule update +* Specify these root directories for dependencies in [make_all.bat](make_all.bat) script: + * GLFW_ROOT + * GLEW_ROOT + * stb_image_ROOT + +* Run [make_all.bat](make_all.bat). +* Run [build.bat](build.bat). + +## Keys +Window + +* Screenshot - L +* Disable input to window - P +* Close application - ESC + +## License and copyright + +© Dawid Pietrykowski + +Licensed under the [MIT LICENSE](LICENSE) \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100755 index 0000000..b4ae87f --- /dev/null +++ b/build.bat @@ -0,0 +1,8 @@ +@echo off + +set GLFW_ROOT= +set GLEW_ROOT= +set stb_image_ROOT= +set ComputeEngine_ROOT=%CD%/ComputeEngine + +cmake --build build --config Release \ No newline at end of file diff --git a/build_user.bat b/build_user.bat new file mode 100755 index 0000000..cd4b546 --- /dev/null +++ b/build_user.bat @@ -0,0 +1,8 @@ +@echo off + +set GLFW_ROOT=C:/lib/glfw-3.3.4.bin.WIN64 +set GLEW_ROOT=C:/lib/glew-2.1.0_x64 +set stb_image_ROOT=C:/lib/stb +set ComputeEngine_ROOT=%CD%/ComputeEngine + +cmake --build build --config Release \ No newline at end of file diff --git a/make_all.bat b/make_all.bat new file mode 100755 index 0000000..01e8af2 --- /dev/null +++ b/make_all.bat @@ -0,0 +1,10 @@ +@echo off + +set GLFW_ROOT= +set GLEW_ROOT= +set stb_image_ROOT= +set ComputeEngine_ROOT=%CD%/ComputeEngine + +cmake -B ComputeEngine/build -S ComputeEngine -DGLFW_ROOT=%GLFW_ROOT% -DGLEW_ROOT=%GLEW_ROOT% -Dstb_image_ROOT=%stb_image_ROOT% +cmake --build ComputeEngine/build --config Release +cmake -B build -S . -DGLFW_ROOT=%GLFW_ROOT% -DGLEW_ROOT=%GLEW_ROOT% -Dstb_image_ROOT=%stb_image_ROOT% -DComputeEngine_ROOT=%ComputeEngine_ROOT% \ No newline at end of file diff --git a/make_all_user.bat b/make_all_user.bat new file mode 100755 index 0000000..9ed8907 --- /dev/null +++ b/make_all_user.bat @@ -0,0 +1,10 @@ +@echo off + +set GLFW_ROOT=C:/lib/glfw-3.3.4.bin.WIN64 +set GLEW_ROOT=C:/lib/glew-2.1.0_x64 +set stb_image_ROOT=C:/lib/stb +set ComputeEngine_ROOT=%CD%/ComputeEngine + +cmake -B ComputeEngine/build -S ComputeEngine -DGLFW_ROOT=%GLFW_ROOT% -DGLEW_ROOT=%GLEW_ROOT% -Dstb_image_ROOT=%stb_image_ROOT% +cmake --build ComputeEngine/build --config Release +cmake -B build -S . -DGLFW_ROOT=%GLFW_ROOT% -DGLEW_ROOT=%GLEW_ROOT% -Dstb_image_ROOT=%stb_image_ROOT% -DComputeEngine_ROOT=%ComputeEngine_ROOT% \ No newline at end of file diff --git a/old/1.png b/old/1.png new file mode 100755 index 0000000..efdee06 Binary files /dev/null and b/old/1.png differ diff --git a/old/Hydrogen_Density_Plots1.png b/old/Hydrogen_Density_Plots1.png new file mode 100755 index 0000000..a796153 Binary files /dev/null and b/old/Hydrogen_Density_Plots1.png differ diff --git a/old/heatmap.png b/old/heatmap.png new file mode 100755 index 0000000..bab538e Binary files /dev/null and b/old/heatmap.png differ diff --git a/old/screenshots/screenshot - Copy (2).jpg b/old/screenshots/screenshot - Copy (2).jpg new file mode 100755 index 0000000..5cbcb29 Binary files /dev/null and b/old/screenshots/screenshot - Copy (2).jpg differ diff --git a/old/screenshots/screenshot - Copy (3).jpg b/old/screenshots/screenshot - Copy (3).jpg new file mode 100755 index 0000000..ef099e9 Binary files /dev/null and b/old/screenshots/screenshot - Copy (3).jpg differ diff --git a/old/screenshots/screenshot - Copy (4).jpg b/old/screenshots/screenshot - Copy (4).jpg new file mode 100755 index 0000000..a6e6a43 Binary files /dev/null and b/old/screenshots/screenshot - Copy (4).jpg differ diff --git a/old/screenshots/screenshot - Copy (5).jpg b/old/screenshots/screenshot - Copy (5).jpg new file mode 100755 index 0000000..c3053b4 Binary files /dev/null and b/old/screenshots/screenshot - Copy (5).jpg differ diff --git a/old/screenshots/screenshot - Copy (6).jpg b/old/screenshots/screenshot - Copy (6).jpg new file mode 100755 index 0000000..1bd0b5f Binary files /dev/null and b/old/screenshots/screenshot - Copy (6).jpg differ diff --git a/old/screenshots/screenshot - Copy (7).jpg b/old/screenshots/screenshot - Copy (7).jpg new file mode 100755 index 0000000..7753ab2 Binary files /dev/null and b/old/screenshots/screenshot - Copy (7).jpg differ diff --git a/old/screenshots/screenshot - Copy (8).jpg b/old/screenshots/screenshot - Copy (8).jpg new file mode 100755 index 0000000..e40b78b Binary files /dev/null and b/old/screenshots/screenshot - Copy (8).jpg differ diff --git a/old/screenshots/screenshot - Copy.jpg b/old/screenshots/screenshot - Copy.jpg new file mode 100755 index 0000000..00fe0d8 Binary files /dev/null and b/old/screenshots/screenshot - Copy.jpg differ diff --git a/old/screenshots/screenshot1.jpg b/old/screenshots/screenshot1.jpg new file mode 100755 index 0000000..eff129c Binary files /dev/null and b/old/screenshots/screenshot1.jpg differ diff --git a/old/screenshots/screenshot10.jpg b/old/screenshots/screenshot10.jpg new file mode 100755 index 0000000..11e6bc2 Binary files /dev/null and b/old/screenshots/screenshot10.jpg differ diff --git a/old/screenshots/screenshot11.jpg b/old/screenshots/screenshot11.jpg new file mode 100755 index 0000000..646e04c Binary files /dev/null and b/old/screenshots/screenshot11.jpg differ diff --git a/old/screenshots/screenshot12.jpg b/old/screenshots/screenshot12.jpg new file mode 100755 index 0000000..c102ace Binary files /dev/null and b/old/screenshots/screenshot12.jpg differ diff --git a/old/screenshots/screenshot13.jpg b/old/screenshots/screenshot13.jpg new file mode 100755 index 0000000..c102ace Binary files /dev/null and b/old/screenshots/screenshot13.jpg differ diff --git a/old/screenshots/screenshot14.jpg b/old/screenshots/screenshot14.jpg new file mode 100755 index 0000000..3d6cb21 Binary files /dev/null and b/old/screenshots/screenshot14.jpg differ diff --git a/old/screenshots/screenshot15.jpg b/old/screenshots/screenshot15.jpg new file mode 100755 index 0000000..a79bf84 Binary files /dev/null and b/old/screenshots/screenshot15.jpg differ diff --git a/old/screenshots/screenshot16.jpg b/old/screenshots/screenshot16.jpg new file mode 100755 index 0000000..a3a4ff9 Binary files /dev/null and b/old/screenshots/screenshot16.jpg differ diff --git a/old/screenshots/screenshot2.jpg b/old/screenshots/screenshot2.jpg new file mode 100755 index 0000000..59b530e Binary files /dev/null and b/old/screenshots/screenshot2.jpg differ diff --git a/old/screenshots/screenshot3.jpg b/old/screenshots/screenshot3.jpg new file mode 100755 index 0000000..910737c Binary files /dev/null and b/old/screenshots/screenshot3.jpg differ diff --git a/old/screenshots/screenshot4.jpg b/old/screenshots/screenshot4.jpg new file mode 100755 index 0000000..7d7ec95 Binary files /dev/null and b/old/screenshots/screenshot4.jpg differ diff --git a/old/screenshots/screenshot5.jpg b/old/screenshots/screenshot5.jpg new file mode 100755 index 0000000..986336a Binary files /dev/null and b/old/screenshots/screenshot5.jpg differ diff --git a/old/screenshots/screenshot6.jpg b/old/screenshots/screenshot6.jpg new file mode 100755 index 0000000..e8f5359 Binary files /dev/null and b/old/screenshots/screenshot6.jpg differ diff --git a/old/screenshots/screenshot7.jpg b/old/screenshots/screenshot7.jpg new file mode 100755 index 0000000..c720445 Binary files /dev/null and b/old/screenshots/screenshot7.jpg differ diff --git a/old/screenshots/screenshot8.jpg b/old/screenshots/screenshot8.jpg new file mode 100755 index 0000000..d02269c Binary files /dev/null and b/old/screenshots/screenshot8.jpg differ diff --git a/old/screenshots/screenshot9.jpg b/old/screenshots/screenshot9.jpg new file mode 100755 index 0000000..623e5a3 Binary files /dev/null and b/old/screenshots/screenshot9.jpg differ diff --git a/rebuild_user.bat b/rebuild_user.bat new file mode 100755 index 0000000..3c8af29 --- /dev/null +++ b/rebuild_user.bat @@ -0,0 +1,4 @@ +rmdir /s /q build +rmdir /s /q ComputeEngine\build +make_all_user.bat +build_user.bat \ No newline at end of file diff --git a/shaders/attractors/objectCompute.compute b/shaders/attractors/objectCompute.compute new file mode 100755 index 0000000..ffe226a --- /dev/null +++ b/shaders/attractors/objectCompute.compute @@ -0,0 +1,131 @@ +#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 +} \ No newline at end of file diff --git a/shaders/attractors/pixelCompute.compute b/shaders/attractors/pixelCompute.compute new file mode 100755 index 0000000..350dc0a --- /dev/null +++ b/shaders/attractors/pixelCompute.compute @@ -0,0 +1,27 @@ +#version 430 core + +layout(local_size_x = 8, local_size_y = 8) in; + +layout(rgba32f) uniform image2D img_output; + +uniform int _pass; + +//vec4 base_color = vec4(1); +vec4 base_color = vec4(209, 227, 255, 255) / 255.0f; + +void main(){ + ivec2 id = ivec2(gl_GlobalInvocationID.xy); + + vec4 pixel = imageLoad(img_output, id); + + //imageStore(img_output, id, pixel * 0.998f); + //imageStore(img_output, id, vec4(1) * (_pass * 0.001f)); + if(_pass != 0){ + //imageStore(img_output, id, mix(pixel, base_color, 0.001f)); + imageStore(img_output, id, mix(pixel, base_color, 0.005f)); + } + else + imageStore(img_output, id, base_color); + + //imageStore(img_output, id, clamp(pixel - vec4(.00001f), vec4(0), vec4(1))); +} \ No newline at end of file diff --git a/shaders/hydrogen_wave/objectCompute.compute b/shaders/hydrogen_wave/objectCompute.compute new file mode 100755 index 0000000..18f76b6 --- /dev/null +++ b/shaders/hydrogen_wave/objectCompute.compute @@ -0,0 +1,133 @@ +#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 +*/ +} \ No newline at end of file diff --git a/shaders/hydrogen_wave/pixelCompute.compute b/shaders/hydrogen_wave/pixelCompute.compute new file mode 100755 index 0000000..14fee73 --- /dev/null +++ b/shaders/hydrogen_wave/pixelCompute.compute @@ -0,0 +1,147 @@ +#version 430 core + +#define PI 3.14159265359 + +layout(local_size_x = 8, local_size_y = 8) in; + +layout(rgba32f) uniform image2D img_output; + +uniform int width; +uniform int height; + +uniform int quantum_n; +uniform int quantum_l; +uniform int quantum_m; + +uniform float u_phi = 0; +//vec4 base_color = vec4(1); +vec4 base_color = vec4(209, 227, 255, 255) / 255.0f; + +const double a0 = 5.29177210903e-11; +const double h = 6.582119569e-16; +const double mq = 9.10938356e-31; +const double e = 8.8541878128e-12; +const double q = 1.60217662e-19; + +int factorial(int n){ + int res = 1; + for(int i = 2; i <= n; i++){ + res *= i; + } + return res; +} +double laguerre(double x, int n, double a){ + if(n == 1) + return 1 + a - x; + else + return 1; +} +double harmonics(double theta, double phi){ + double res = 1; + + if(quantum_m == 0 && quantum_l == 2){ + res *= 0.25; + res *= sqrt(5.0/PI); + res *= (3 * pow(cos(float(theta)), 2) - 1); + }else if(quantum_m == 1 && quantum_l == 2){ + res *= 0.5; + res *= sqrt(15.0/PI); + res *= sin(float(theta)) * cos(float(phi)) * cos(float(theta)); + } + + return res; +} +double wave_function(double r, double theta, double phi){ + double p1 = pow(float(2/(quantum_n*a0)),3); + double p21 = factorial(quantum_n-quantum_l-1); + double p22 = (2 * quantum_n * factorial(quantum_n+quantum_l)); + double root = sqrt(p1 * (p21/p22)); + + double exponent = exp(float(-r/(quantum_n*a0))); + + double p3 = pow(float((2 * r)/(quantum_n * a0)), quantum_l); + + double lag = laguerre((2 * r)/(quantum_n * a0), quantum_n - quantum_l - 1, 2 * quantum_l + 1); + + double Y = harmonics(theta, phi); + + double wave = exponent * root * p3 * lag * Y; + //return root / 2e13 + (quantum_n+quantum_l+quantum_m+ r) * 0.000001f; + //return wave / 1e14; + //return (wave * wave) / 2.28e27; + return (wave * wave) / 1e27; + //return (sin(float(r/sqrt(2)) * 10) + 1.0) * 0.5 + (quantum_n+quantum_l+quantum_m) * 0.000001f; +} + +vec4 heatmap(float x){ + vec4 colors[6]; + + colors[0] = vec4(0); + colors[1] = vec4(58, 20, 78, 255) / 255.0f; + colors[2] = vec4(148, 50, 99, 255) / 255.0f; + colors[3] = vec4(249, 114, 13, 255) / 255.0f; + colors[4] = vec4(255, 198, 76, 255) / 255.0f; + colors[5] = vec4(1); + + colors[0].w = 0.0f; + colors[1].w = 0.1f; + colors[2].w = 0.25f; + colors[3].w = 0.5f; + colors[4].w = 0.75f; + colors[5].w = 1.0f; + + int index = -1; + for(int i = 1; i < 6; i++){ + if(x <= colors[i].w){ + index = i; + break; + } + } + + vec4 res; + if(index != -1){ + float range = colors[index].w - colors[index - 1].w; + res = mix(colors[index - 1], colors[index], (x - colors[index - 1].w)/range); + }else + res = colors[5]; + res.w = 1; + return res; +} + +void main(){ + ivec2 id = ivec2(gl_GlobalInvocationID.xy); + + vec2 offset = vec2(0.0f, 0.0f); + + float x; + float y; + + // map x,y to [-1,1] + x = ((((float(id.x) - 0.5f + offset.x)/float(width))) - 0.5f) * 2.0f; + y = ((((float(id.y) - 0.5f + offset.y)/float(height))) - 0.5f) * 2.0f; + + double raw_r = sqrt(pow(x, 2) + pow(y, 2)); + double r = raw_r * 35 * a0; + double theta = acos(float(y/raw_r)); + float phi = u_phi; + + vec4 base_color = vec4(0); + + vec4 max_color = vec4(1); + + // double n_ang ; + + // if(x > 0){ + // n_ang = mod(theta + phi, PI); + // }else + // n_ang = mod(theta - phi, PI); + + float val = 4.0f * float(wave_function(r, theta, phi)); + //val = 1 - exp(-1 * val * 5); + + //vec4 pixel = mix(base_color, max_color, val); + vec4 pixel = heatmap(val); + + imageStore(img_output, id, pixel); + //imageStore(img_output, id, heatmap(float(raw_r))); +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100755 index 0000000..5751154 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(${PROJECT_NAME} +PUBLIC +main.cpp +DataStructures.cpp +DataStructures.h +Utils.cpp +Utils.h +) \ No newline at end of file diff --git a/src/DataStructures.cpp b/src/DataStructures.cpp new file mode 100755 index 0000000..7735d81 --- /dev/null +++ b/src/DataStructures.cpp @@ -0,0 +1,181 @@ +#define _USE_MATH_DEFINES +#include +#include +#include +#include +#include +#include +#include +void CameraData::accCamera(float acc[3], float time) { + for (int i = 0; i < 3; i++) + acceleration[i] += acc[i] * acc_mul; +} + +void CameraData::rotateCamera(float dx, float dy) { + rotation[1] += dx * sensitivity * (500.0f/m_width); + if (rotation[0] + dy * sensitivity * (500.0f / m_width) < -90) + rotation[0] = -90; + else if (rotation[0] + dy * sensitivity * (500.0f / m_width) > 90) + rotation[0] = 90; + else + rotation[0] += dy * sensitivity * (500.0f / m_width); + + + rotation[1] = (float)fmod(rotation[1], 360); + + if((abs(dx) > 0.0001f) || (abs(dy) > 0.0001f)) + m_changed = true; +} + +void CameraData::CopyData(shader_data_t& shader_data) { + shader_data.camera_position = { position[0], position[1], position[2], 0 }; + shader_data.camera_rotation = { rotation[0], rotation[1], rotation[2], 0 }; +} + +bool CameraData::HasChanged() { + return m_changed; +} + +void CameraData::SetChanged(bool ch) { + m_changed = ch; +} + +float DegToRad(float deg) { + return (float)(deg * (M_PI / 180.0f)); +} + +void CameraData::updateCameraData(float time, GLFWwindow* window) { + std::vector> move_vectors; + std::vector forward = { cos(DegToRad(rotation[1])), 0.0f, sin(DegToRad(rotation[1])) }; + std::vector up = { 0, 1.0f, 0 }; + std::vector right = { cos(DegToRad(rotation[1] + 90)), 0.0f, sin(DegToRad(rotation[1] + 90)) }; + move_vectors.push_back(forward); + move_vectors.push_back(up); + move_vectors.push_back(right); + //update position + for (int i = 0; i < 3; i++) { + temp[0] = position[i]; + temp[1] = rotation[i]; + + //acceleration[0] = 1.0f * acc_mul; + + float accell = 0; + //if (true) { + + for (int x = 0; x < 3; x++) + accell += acceleration[x] * move_vectors[x][i]; + accell *= time; + + velocity[i] += accell; + + if (velocity[i] > max_v[i]) + velocity[i] = max_v[i]; + else if (velocity[i] < -max_v[i]) + velocity[i] = -max_v[i]; + + position[i] += velocity[i] * time; + //} + //else { + float sum = abs(velocity[0]) + abs(velocity[1]) + abs(velocity[2]); + float part_friction = abs((velocity[i] / sum)) * friction; + if (sum != 0) { + if (velocity[i] > 0) { + if (part_friction * time > velocity[i]) + velocity[i] = 0; + else + velocity[i] -= part_friction * time; + } + else if (velocity[i] < 0) { + if (part_friction * time < velocity[i]) + velocity[i] = 0; + else + velocity[i] += part_friction * time; + } + position[i] += velocity[i] * time; + } + //} + + if ((temp[0] != position[i]) || (temp[1] != rotation[i])) + m_changed = true; + } + for (int i = 0; i < 3; i++) + acceleration[i] = 0; + +} +void CameraData::updateCameraData(float time) { + std::vector> move_vectors; + std::vector forward = { cos(DegToRad(rotation[1])), 0, sin(DegToRad(rotation[1])) }; + std::vector up = { 0, 1.0f, 0 }; + std::vector right = { cos(DegToRad(rotation[1] + 90)), sin(DegToRad(rotation[0])), sin(DegToRad(rotation[1] + 90)) }; + + move_vectors.push_back(forward); + move_vectors.push_back(up); + move_vectors.push_back(right); + + //update position + for (int i = 0; i < 3; i++) { + temp[0] = position[i]; + temp[1] = rotation[i]; + + float accell = 0; + + for (int x = 0; x < 3; x++) + accell += acceleration[x] * move_vectors[x][i]; + accell *= time; + + velocity[i] += accell; + + if (velocity[i] > max_v[i]) + velocity[i] = max_v[i]; + else if (velocity[i] < -max_v[i]) + velocity[i] = -max_v[i]; + + position[i] += velocity[i] * time; + + float sum = abs(velocity[0]) + abs(velocity[1]) + abs(velocity[2]); + float part_friction = abs((velocity[i] / sum)) * friction; + if (sum != 0) { + if (velocity[i] > 0) { + if (part_friction * time > velocity[i]) + velocity[i] = 0; + else + velocity[i] -= part_friction * time; + } + else if (velocity[i] < 0) { + if (part_friction * time < velocity[i]) + velocity[i] = 0; + else + velocity[i] += part_friction * time; + } + position[i] += velocity[i] * time; + } + + if ((temp[0] != position[i]) || (temp[1] != rotation[i])) + m_changed = true; + } + for (int i = 0; i < 3; i++) + acceleration[i] = 0; + +} + +void shader_data_t::UpdateSeed() { + _Seed = getRand(); +} +void shader_data_t::UpdateWindowSize(int width, int height) { + screenSize[0] = width; + screenSize[1] = height; +} +void shader_data_t::GetWindowSize(int& width, int& height) { + width = screenSize[0]; + height = screenSize[1]; +} +int shader_data_t::GetWidth() { + return screenSize[0]; +} +int shader_data_t::GetHeight() { + return screenSize[1]; +} +void CameraData::UpdateWindowSize(int width, int height) { + m_width = width; + m_height = height; +} \ No newline at end of file diff --git a/src/DataStructures.h b/src/DataStructures.h new file mode 100755 index 0000000..acecc31 --- /dev/null +++ b/src/DataStructures.h @@ -0,0 +1,77 @@ +#pragma once +#include +#include +#include +#include +#include + +struct shader_data_t +{ +public: + std::array camera_position = { 0, 0, 0, 0 }; + std::array camera_rotation = { 0, 0, 0, 0 }; + std::array _PixelOffset = { 0.5f, 0.5f }; + std::array screenSize = { 0, 0 }; + int iterations = 5; + float _Seed = getRand(); + int objectcount = 0; + int _sample = 1; + int samples = 1; + float dt = .000001f; + std::array padding = {0, 0}; + void UpdateSeed(); + void UpdateWindowSize(int width, int height); + void GetWindowSize(int& width, int& height); + int GetWidth(); + int GetHeight(); +}; +struct CameraData { + std::array velocity = { 0, 0, 0 }; + std::array max_v = { 30, 30, 30}; + std::array position = { 0, 0, 0 }; + std::array rotation = { 0, 0, 0 }; + std::array acceleration = { 0, 0, 0 }; + float friction = 30.0f; + float acc_mul = 50.0f; + bool m_changed = false; + bool breakk = false; + float sensitivity = 3.0f; + int m_width, m_height; + void accCamera(float acc[3], float time); + void rotateCamera(float dx, float dy); + void CopyData(shader_data_t& shader_data); + + bool HasChanged(); + + void SetChanged(bool ch); + + float temp[2]; + + void updateCameraData(float time, GLFWwindow* window); + void updateCameraData(float time); + void UpdateWindowSize(int width, int height); +}; + +//struct SceneObject { +// std::array position = { 0, 0, 0, 0 }; +// std::array size = { 1, 1, 1, 1 }; +// std::array orientation = { 0, 0, 0, 0 }; +// std::array albedo = { 1, 1, 1, 1 }; +// std::array specular = { 0, 0, 0, 0 }; +// std::array emission = { 0, 0, 0, 0 }; +// //0 - diffuse +// //1 - specular +// //2 - normal +// //3 - emission +// std::array texture_id = { 0, 0, 0, 0 }; +// float refractive_index = 1; +// float transparency = 0; +// float smoothness = 0; +// int type = 0; +// int offset = 0; +// int vert_num = 0; +// std::array padding; +//}; +struct SceneObject { + std::array position = { 0, 0, 0, 0 }; +}; \ No newline at end of file diff --git a/src/Utils.cpp b/src/Utils.cpp new file mode 100755 index 0000000..d84cafb --- /dev/null +++ b/src/Utils.cpp @@ -0,0 +1,83 @@ +#pragma once +#include + +#include +#include +#include +#include + +using std::cout; +using std::endl; + +bool glErrorCheck() { + bool no_err = true; + + GLenum error = glGetError(); + while (error) { + std::string err_str; + switch (error) { + case GL_NO_ERROR: + err_str = "GL_NO_ERROR"; + break; + case GL_INVALID_ENUM: + err_str = "GL_INVALID_ENUM"; + break; + case GL_INVALID_VALUE: + err_str = "GL_INVALID_VALUE"; + break; + case GL_INVALID_OPERATION: + err_str = "GL_INVALID_OPERATION"; + break; + case GL_INVALID_FRAMEBUFFER_OPERATION: + err_str = "GL_INVALID_FRAMEBUFFER_OPERATION"; + break; + case GL_OUT_OF_MEMORY: + err_str = "GL_OUT_OF_MEMORY"; + break; + default: + err_str = "GL_UNKNOWN_ERROR"; + break; + } + + cout << err_str << endl; + + error = glGetError(); + + no_err = false; + return no_err; + } + + return no_err; +} + +void glClearError() { + while (glGetError() != GL_NO_ERROR); +} + +void PrintSizeLimits() { + GLint size; + GLint size2; + + glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &size); + std::cout << "GL_MAX_TEXTURE_BUFFER_SIZE is " << ((float)size * 32.0f / 1073741824.0f) << " GB" << endl; + glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &size); + std::cout << "GL_MAX_SHADER_STORAGE_BLOCK_SIZE is " << ((float)size / 1073741824.0f) << " GB" << endl; + glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &size); + std::cout << "GL_MAX_UNIFORM_BLOCK_SIZE is " << ((float)size / 1024.0f) << " KB" << endl; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size); + std::cout << "GL_MAX_TEXTURE_SIZE is " << ((float)size / 1024.0f) << " MB" << endl; + glGetIntegerv(GL_MAX_IMAGE_UNITS, &size); + std::cout << "GL_MAX_IMAGE_UNITS is " << size << endl; + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &size); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, &size2); + std::cout << "GL_MAX_COMPUTE_WORK_GROUP_SIZE is " << size << ", " << size2 << endl; +} + +float getRand() { + return (float)((double)rand() / (RAND_MAX)); +} + +bool fileExists(const std::string& name) { + struct stat buffer; + return (stat(name.c_str(), &buffer) == 0); +} \ No newline at end of file diff --git a/src/Utils.h b/src/Utils.h new file mode 100755 index 0000000..563fc93 --- /dev/null +++ b/src/Utils.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +#define ASSERT(x) if(!(x)){ cout << "[ERROR] " << #x << '\n';\ +__debugbreak();} +//#define GLCall(x) glClearError();\ +// x;\ +// ASSERT(glErrorCheck()) + +#define GLCall(x) \ + glClearError();\ + x;\ + if(!(glErrorCheck())){ cout << "[ERROR] " << #x << '\n';\ + __debugbreak();} + +void PrintSizeLimits(); +bool glErrorCheck(); +void glClearError(); +float getRand(); + +bool fileExists(const std::string & name); diff --git a/src/main.cpp b/src/main.cpp new file mode 100755 index 0000000..39913eb --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,210 @@ +#define _USE_MATH_DEFINES + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DataStructures.h" +#include + +using std::cout; +using std::endl; + +float sensitivity = 10.0f; + +void UpdateKeys(ComputeEngine& renderer, CameraData& camera, std::vector& 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)) { + renderer.SwitchFullScreen(); + } + if (renderer.IsKeyClicked(GLFW_KEY_ESCAPE)) + renderer.CloseWindow(); + if (renderer.IsKeyClicked(GLFW_KEY_L)) + renderer.SaveScreen("screenshots/screenshot"); + } + int width, height; + shader_data.GetWindowSize(width, height); + renderer.GetWindowSize(shader_data.screenSize[0], shader_data.screenSize[1]); + if (width != shader_data.GetWidth() || height != shader_data.GetHeight()) + tex_output.Resize(shader_data.GetWidth(), shader_data.GetHeight()); +} + +void UpdateInput(ComputeEngine& renderer, CameraData& camera, std::vector& objects, shader_data_t& shader_data, Texture& tex_output) { + renderer.PollEvents(); + UpdateKeys(renderer, camera, 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); +} + +int main(void) +{ + srand((unsigned)time(0)); + + 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 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; + //} + + // init textures + Texture tex_output("img_output", width, height); + + // init buffers + UBO data_buffer(2); + //SSBO objects_buffer(3); + + // 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); + + compute_program.SetUniform1i("width", width); + compute_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(); + + float phi = 0; + + while (!renderer.ShouldClose()) { + // update input + UpdateInput(renderer, camera, objects, shader_data, tex_output); + + phi += (renderer.GetFrametime() / 1000.0) * M_PI * 0.5; + + phi = std::fmod(phi, M_PI); + printf("phi: %.2f\n", phi); + + // update variables + compute_program.SetUniform1f("u_phi", phi); + + // dispatch compute shader + compute_program.DispatchCompute(shader_data.GetWidth(), shader_data.GetHeight()); + + renderer.UpdateFrametime(); + + // draw rendered image + renderer.DrawTexture(tex_output); + + + /* + if (0) { + // update input + camera.SetChanged(false); + UpdateInput(renderer, camera, objects, shader_data, tex_output); + + 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 + 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(); + } + */ + } + + //print average frametime + printf("Avg frametime: %.3f", renderer.GetAverageFrametime()); + + return 0; +} \ No newline at end of file diff --git a/src/main.h b/src/main.h new file mode 100755 index 0000000..d0fefa3 --- /dev/null +++ b/src/main.h @@ -0,0 +1,2 @@ +#pragma once +#include