├── .gitignore ├── .gitmodules ├── .travis.yml ├── 3rdParty ├── CMakeLists.txt └── GL3W │ ├── CMakeLists.txt │ ├── gl3w.cpp │ ├── gl3w.h │ └── glcorearb.h ├── CMakeLists.txt ├── LICENSE ├── README.md ├── Shader ├── display │ ├── 2D │ │ ├── 2d_display.fs.glsl │ │ └── 2d_display.vs.glsl │ └── 3D │ │ ├── Shadow.fs.glsl │ │ ├── Shadow.tcs.glsl │ │ ├── Shadow.tes.glsl │ │ ├── Shadow.vs.glsl │ │ ├── dispmap.fs.glsl │ │ ├── dispmap.tcs.glsl │ │ ├── dispmap.tes.glsl │ │ ├── dispmap.vs.glsl │ │ ├── waterDispmap.fs.glsl │ │ ├── waterDispmap.tcs.glsl │ │ ├── waterDispmap.tes.glsl │ │ ├── waterDispmap.vs.glsl │ │ ├── waterFlow.fs.glsl │ │ └── waterFlow.vs.glsl └── simulation │ ├── climat │ ├── climat.fs.glsl │ └── climat.vs.glsl │ ├── ice │ ├── ice_Sim.fs.glsl │ └── ice_Sim.vs.glsl │ ├── moist │ ├── moist_Sim.fs.glsl │ └── moist_Sim.vs.glsl │ ├── rock │ ├── rock_Sim.fs.glsl │ └── rock_Sim.vs.glsl │ ├── soil │ ├── soil_Sim.fs.glsl │ └── soil_Sim.vs.glsl │ ├── temp │ ├── temp_Sim.fs.glsl │ └── temp_Sim.vs.glsl │ ├── water │ ├── water_Sim.fs.glsl │ └── water_Sim.vs.glsl │ └── wind │ ├── wind_Sim.fs.glsl │ └── wind_Sim.vs.glsl ├── Thesis.pdf ├── cmake ├── FindAntTweakBar.cmake ├── FindGLFW.cmake ├── FindGLM.cmake └── FindLibNoise.cmake ├── include ├── 3DRender │ ├── Camera.h │ ├── Light.h │ ├── Shadows.h │ ├── WaterRender.h │ ├── display3D.h │ ├── landscapeRender.h │ └── plane.h ├── RendToTex.h ├── ShaderLoader.h ├── TextureLoader.h ├── display2D.h ├── inputHandler.h ├── simpleRender.h └── simulation.h ├── install.sh ├── res └── grass_normals.png ├── run.sh ├── screenshots ├── 3DMap.png ├── Climat.png └── heightmap.png ├── scripts └── installDependencies.sh └── src ├── 3DRender ├── CMakeLists.txt ├── Camera.cpp ├── Light.cpp ├── Shadows.cpp ├── WaterRender.cpp ├── display3D.cpp ├── landscapeRender.cpp └── plane.cpp ├── CMakeLists.txt ├── RendToTex.cpp ├── ShaderLoader.cpp ├── TextureLoader.cpp ├── display2D.cpp ├── inputHandler.cpp ├── main.cpp ├── simpleRender.cpp └── simulation.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | nbproject/* 3 | /outputIMG/ 4 | anttweakbar/* -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rdParty/RTplatec"] 2 | path = 3rdParty/RTplatec 3 | url = https://github.com/tarTG/RTplatec.git 4 | [submodule "3rdParty/--force"] 5 | path = 3rdParty/--force 6 | url = https://github.com/tarTG/RTplatec.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: generic 3 | 4 | dist: trusty 5 | sudo: required 6 | 7 | cache: 8 | apt: true 9 | 10 | compiler: 11 | - gcc 12 | - clang 13 | 14 | matrix: 15 | include: 16 | - env: CXX=g++-6 CC=gcc-6 17 | addons: 18 | apt: 19 | packages: 20 | - g++-6 21 | sources: &sources 22 | - ubuntu-toolchain-r-test 23 | - llvm-toolchain-precise 24 | - llvm-toolchain-precise-3.8 25 | - env: CXX=clang++-3.8 CC=clang-3.8 26 | addons: 27 | apt: 28 | packages: 29 | - clang-3.8 30 | - libc++-dev 31 | sources: *sources 32 | script: 33 | - if [[ "$CXX" == clang* ]]; then export CXXFLAGS="-stdlib=libc++"; fi 34 | - mkdir build && cd build 35 | - cmake .. 36 | - make all 37 | 38 | 39 | # disable the default submodule logic 40 | git: 41 | submodules: false 42 | 43 | # use sed to replace the SSH URL with the public URL, then init and update submodules 44 | before_install: 45 | - sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules 46 | - git submodule update --init --recursive 47 | - sudo scripts/installDependencies.sh 48 | 49 | 50 | -------------------------------------------------------------------------------- /3rdParty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory(GL3W) 3 | add_subdirectory(RTplatec) -------------------------------------------------------------------------------- /3rdParty/GL3W/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(GL3W 3 | gl3w.cpp) -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(RTWG) 4 | 5 | set(PROJECT_VERSION 0.0) 6 | 7 | message(STATUS "~~~ ${PROJECT_NAME} - v${PROJECT_VERSION} ~~~") 8 | 9 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 10 | 11 | find_package(GLFW REQUIRED) 12 | find_package(DevIL REQUIRED) 13 | find_package(X11 REQUIRED) 14 | find_package(AntTweakBar REQUIRED) 15 | find_package(OpenGL REQUIRED) 16 | find_package(GLM REQUIRED) 17 | 18 | 19 | include_directories("${GLFW_INCLUDE_DIR}" ) 20 | include_directories("${ANTTWEAKBAR_INCLUDE_DIR}" ) 21 | include_directories("${IL_INCLUDE_DIR}" ) 22 | include_directories("${GLM_INCLUDE_DIRS}" ) 23 | 24 | include_directories("include" ) 25 | include_directories("include/3DRender" ) 26 | 27 | include_directories("3rdParty" ) 28 | 29 | 30 | add_definitions( -std=c++14 ) 31 | 32 | add_subdirectory("3rdParty") 33 | add_subdirectory("src") 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RTWG 2 | [![Build Status](https://travis-ci.org/tarTG/RTWG.svg?branch=master)](https://travis-ci.org/tarTG/RTWG) 3 | 4 | The Real-Time World Generation project aims to provide a tool for world/terrain generation based on procedural algorithms and cellular automata simulation. 5 | This is the result of my Masterthesis on the University of Applied Sciences in Rosenheim, which can be 6 | 7 | **The thesis is available [here](https://github.com/tarTG/RTWG/blob/master/Thesis.pdf)** 8 | 9 | 10 | ## Demo Video 11 | 12 | [![screenshots/3DMap.png](http://img.youtube.com/vi/lntbdItSFtg/0.jpg)](http://www.youtube.com/watch?v=lntbdItSFtg) 13 | 14 | ## Features 15 | 16 | - Start world is generated thought prozedural algorithmen or imported heightmap 17 | - Realtime simulation and manipulation of water, wind, soil, moist, ice, plate-tectonic, temperature and the resulting climate zones 18 | - 2D and 3D representation 19 | - PNG Export of all data 20 | 21 | ## Requirements 22 | 23 | - OpenGL 4.+ 24 | - a C++14 compiler 25 | - currently only tested under Debian/Ubuntu-based Linux 26 | 27 | ## Installation 28 | 29 | - go to the RTWG folder 30 | - sudo sh install.sh 31 | - start the program with run.sh 32 | 33 | If you start the program, you have to wait for a short time, until the heightmap is generated. 34 | 35 | 36 | ## Controls 37 | 38 | **Key** | **Description** 39 | -----|------ 40 | Tab | toogle between 3D / 2D 41 | w/s/a/d | camera movement in 3D 42 | Shift + Mouse | camera movement in 3D 43 | 44 | 45 | Simulation view can be changed on top "General" Bar (Current Display) 46 | 47 | A detailed description of all parameters can be found in the [wiki](https://github.com/tarTG/RTWG/wiki). 48 | 49 | ## Example images 50 | 51 | Here is an example that is generated throught this tool. 52 | 53 | ### Heigthmap 54 | 55 | ![](screenshots/heightmap.png?raw=true) 56 | 57 | ### Climate zones 58 | 59 | ![](screenshots/Climat.png?raw=true) 60 | 61 | ### 3D representation 62 | 63 | ![](screenshots/3DMap.png?raw=true) 64 | 65 | 66 | ## Further plans 67 | 68 | - More simulations (like water temperature or global water movements) 69 | - Direct manipulation (like adding water on a specific place) 70 | - Faster Plate tectonic(via Shaders, faster but less accurate) 71 | - More manipulation options 72 | - a config file for startup parameters 73 | 74 | ## Credits 75 | - Maxis SimEarth where i got the original idea 76 | - original platec developer Lauri Viitanen ( http://sourceforge.net/projects/platec/ ) 77 | - water errosion is heavily inspired by https://github.com/pyalot/craftscape 78 | - some ideas are taken from https://github.com/Mindwerks/worldengine 79 | - a lot of world generation tools out there, where i got a lot of interessting ideas 80 | 81 | -------------------------------------------------------------------------------- /Shader/display/2D/2d_display.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | 8 | layout (binding = 0) uniform sampler2D tex; 9 | /*layout (binding = 1) uniform sampler2D soil; 10 | layout (binding = 2) uniform sampler2D water; 11 | layout (binding = 3) uniform sampler2D temp; 12 | layout (binding = 4) uniform sampler2D moist; 13 | layout (binding = 5) uniform sampler2D wind; 14 | layout (binding = 6) uniform sampler2D ice; 15 | layout (binding = 7) uniform sampler2D mixtex; 16 | layout (binding = 8) uniform sampler2D shadow;*/ 17 | 18 | 19 | uniform uint currentSelection; 20 | uniform ivec2 WindowDimension = ivec2(800,600); 21 | 22 | vec3 getTexValue(sampler2D tex, float x, float y) 23 | { 24 | // return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 25 | vec2 div = textureSize(tex,0)/vec2(WindowDimension); 26 | return texture(tex, (div*gl_FragCoord.xy)/(textureSize(tex,0))).xyz; 27 | } 28 | 29 | 30 | vec3 renderHeightMap(float c) 31 | { 32 | const float COLOR_STEP= 0.5f; 33 | vec3 color = vec3(0.0); 34 | if (c < 0.5) 35 | color = vec3(0.0, 0.0, 0.25 + 1.5 * c); 36 | else if (c < 1.0) 37 | color = vec3(0.0, 2 * (c - 0.5), 1.0); 38 | else 39 | { 40 | c -= 1.0; 41 | if (c < 1.0 * COLOR_STEP) 42 | color = vec3(0.0, 0.5 + 0.5 * c / COLOR_STEP, 0.0); 43 | else if (c < 1.5 * COLOR_STEP) 44 | color = vec3(2 * (c - 1.0 * COLOR_STEP) / COLOR_STEP, 1.0, 0.0); 45 | else if (c < 2.0 * COLOR_STEP) 46 | color = vec3(1.0, 1.0 -(c - 1.5 * COLOR_STEP)/COLOR_STEP, 0); 47 | else if (c < 3.0 * COLOR_STEP) 48 | color = vec3(1.0 - 0.5 * (c - 2.0 * COLOR_STEP) / COLOR_STEP, 49 | 0.5 - 0.25 * (c - 2.0 * COLOR_STEP) / COLOR_STEP, 50 | 0); 51 | else if (c < 5.0 * COLOR_STEP) 52 | color = vec3(0.5 - 0.125 * (c - 3.0 * COLOR_STEP) / (2*COLOR_STEP), 53 | 0.25 + 0.125 * (c - 3.0 * COLOR_STEP) / (2*COLOR_STEP), 54 | 0.375 * (c - 3.0 * COLOR_STEP) / (2*COLOR_STEP)); 55 | else if (c < 8.0 * COLOR_STEP) 56 | color = vec3(0.375 + 0.625 * (c - 5.0 * COLOR_STEP) / (3*COLOR_STEP), 57 | 0.375 + 0.625 * (c - 5.0 * COLOR_STEP) / (3*COLOR_STEP), 58 | 0.375 + 0.625 * (c - 5.0 * COLOR_STEP) / (3*COLOR_STEP)); 59 | else 60 | { 61 | c -= 8.0 * COLOR_STEP; 62 | while (c > 2.0 * COLOR_STEP) 63 | c -= 2.0 * COLOR_STEP; 64 | 65 | color = vec3(1, 1 , 1); 66 | } 67 | } 68 | return color; 69 | } 70 | 71 | 72 | 73 | out vec3 color; 74 | 75 | void main() 76 | { 77 | 78 | switch(currentSelection) 79 | { 80 | case 0: 81 | color = renderHeightMap(getTexValue(tex,0.0,0.0).x); 82 | break; 83 | case 1: 84 | color = getTexValue(tex,0.0,0.0).xyz*10; 85 | break; 86 | case 2: 87 | color = abs(getTexValue(tex,0.0,0.0).xyz)*5; 88 | // color = vec3(length(getTexValue(water,0.0,0.0).yz),0.0,0.0); 89 | break; 90 | case 3: 91 | color = getTexValue(tex,0.0,0.0).xyz; 92 | break; 93 | case 4: 94 | color = getTexValue(tex,0.0,0.0).xxx; 95 | break; 96 | case 5: 97 | color = getTexValue(tex,0.0,0.0).xyz; 98 | break; 99 | case 6: 100 | color = getTexValue(tex,0.0,0.0).xyz; 101 | break; 102 | case 7: 103 | case 8: 104 | color = getTexValue(tex,0.0,0.0).xyz; 105 | break; 106 | } 107 | 108 | 109 | 110 | 111 | 112 | } 113 | -------------------------------------------------------------------------------- /Shader/display/2D/2d_display.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | 8 | 9 | void main() 10 | { 11 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 12 | vec4( 1.0, -1.0, 0.5, 1.0), 13 | vec4(-1.0, 1.0, 0.5, 1.0), 14 | vec4( 1.0, 1.0, 0.5, 1.0)); 15 | //move vertex 16 | gl_Position = vertices[gl_VertexID]; 17 | } 18 | -------------------------------------------------------------------------------- /Shader/display/3D/Shadow.fs.glsl: -------------------------------------------------------------------------------- 1 | #version 430 core 2 | 3 | 4 | layout (location = 0) out float depth; 5 | 6 | void main() 7 | { 8 | 9 | } -------------------------------------------------------------------------------- /Shader/display/3D/Shadow.tcs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | 4 | //height texture 5 | layout (binding = 0) uniform sampler2D rock; 6 | layout (binding = 1) uniform sampler2D soil; 7 | layout (binding = 2) uniform sampler2D water; 8 | layout (binding = 3) uniform sampler2D temp; 9 | layout (binding = 4) uniform sampler2D moist; 10 | layout (binding = 5) uniform sampler2D wind; 11 | layout (binding = 6) uniform sampler2D ice; 12 | layout (binding = 7) uniform sampler2D mixtex; 13 | 14 | uniform mat4 depthMVP; //model view matrix 15 | uniform mat4 model_matrix; 16 | 17 | in vec2 texCoord[]; 18 | out vec2 texCoordT[]; 19 | // Inputs from vertex shader 20 | 21 | 22 | layout(vertices = 4) out; 23 | 24 | 25 | bool segmentInFrustum(vec4 p1, vec4 p2) { 26 | 27 | if ((p1.x < -p1.w && p2.x < -p2.w) || (p1.x > p1.w && p2.x > p2.w) || 28 | // (p1.y < -p1.w && p2.y < -p2.w) || (p1.y > p1.w && p2.y > p2.w) || 29 | (p1.z < -p1.w && p2.z < -p2.w) || (p1.z > p1.w && p2.z > p2.w)) 30 | return true; 31 | else 32 | return false; 33 | 34 | } 35 | 36 | 37 | void main() 38 | { 39 | if(gl_InvocationID == 0) 40 | { 41 | vec4 v0 = depthMVP *model_matrix* gl_in[0].gl_Position; 42 | vec4 v1 = depthMVP * model_matrix*gl_in[1].gl_Position; 43 | vec4 v2 = depthMVP *model_matrix*gl_in[2].gl_Position; 44 | vec4 v3 = depthMVP *model_matrix*gl_in[3].gl_Position; 45 | 46 | v0 /= v0.w; 47 | v1 /= v1.w; 48 | v2 /= v2.w; 49 | v3 /= v3.w; 50 | 51 | 52 | if(all(bvec4(segmentInFrustum(v0,v1), segmentInFrustum(v0,v2), segmentInFrustum(v2,v3),segmentInFrustum(v3,v1)))){ 53 | gl_TessLevelInner[0] = 0; 54 | gl_TessLevelInner[1] = 0; 55 | gl_TessLevelOuter[0] = 0; 56 | gl_TessLevelOuter[1] = 0; 57 | gl_TessLevelOuter[2] = 0; 58 | gl_TessLevelOuter[3] = 0; 59 | } 60 | else{ 61 | 62 | gl_TessLevelInner[0] = 10; 63 | gl_TessLevelInner[1] = 10; 64 | gl_TessLevelOuter[0] = 10; 65 | gl_TessLevelOuter[1] = 10; 66 | gl_TessLevelOuter[2] = 10; 67 | gl_TessLevelOuter[3] = 10; 68 | 69 | } 70 | } 71 | 72 | texCoordT[gl_InvocationID] = texCoord[gl_InvocationID]; 73 | gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Shader/display/3D/Shadow.tes.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | //incoming tesselated primitives 4 | layout (quads) in; 5 | //height texture 6 | layout (binding = 0) uniform sampler2D rock; 7 | layout (binding = 1) uniform sampler2D soil; 8 | layout (binding = 2) uniform sampler2D water; 9 | layout (binding = 3) uniform sampler2D temp; 10 | layout (binding = 4) uniform sampler2D moist; 11 | layout (binding = 5) uniform sampler2D wind; 12 | layout (binding = 6) uniform sampler2D ice; 13 | layout (binding = 7) uniform sampler2D mixtex; 14 | 15 | uniform mat4 depthMVP; //model view matrix 16 | uniform mat4 model_matrix; 17 | 18 | 19 | 20 | in vec2 texCoordT[]; 21 | out vec2 texcoordF; 22 | 23 | 24 | uniform ivec2 dimensions; 25 | 26 | float height(float u, float v) 27 | { 28 | return texture(rock, vec2(u,v)).x + texture(soil , vec2(u,v)).x+ texture(water , vec2(u,v)).x;// + texture(ice , vec2(u,v)).x); 29 | } 30 | 31 | 32 | void main() 33 | { 34 | float u = gl_TessCoord.x; 35 | float v = gl_TessCoord.y; 36 | 37 | vec3 p0 = gl_in[0].gl_Position.xyz; 38 | vec3 p1 =gl_in[1].gl_Position.xyz ; 39 | vec3 p2 =gl_in[2].gl_Position.xyz; 40 | vec3 p3 = gl_in[3].gl_Position.xyz; 41 | 42 | 43 | vec2 t1 = mix(texCoordT[0], texCoordT[1], u); 44 | vec2 t2 = mix(texCoordT[2], texCoordT[3], u); 45 | texcoordF = mix(t2, t1, v); 46 | 47 | vec3 p_1 = mix(p0 , p1, u); 48 | vec3 p_2 = mix(p2, p3, u); 49 | 50 | vec3 q =mix(p_2, p_1, v) ; 51 | q.y = texture(rock,texcoordF).x; 52 | 53 | 54 | 55 | gl_Position = (depthMVP *model_matrix ) * vec4(q,1.0) ; 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Shader/display/3D/Shadow.vs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | //outgoing tesselation coordinates 4 | in vec4 position; 5 | out vec2 texCoord; 6 | 7 | uniform ivec2 dimensions; 8 | 9 | 10 | void main(void) 11 | { 12 | texCoord = position.xz/vec2(dimensions); 13 | gl_Position = position; 14 | } 15 | -------------------------------------------------------------------------------- /Shader/display/3D/dispmap.fs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | 4 | in VS_OUT 5 | { 6 | vec3 N; 7 | vec3 L; 8 | vec3 V; 9 | } vs_out; 10 | 11 | 12 | in vec2 texcoordF; 13 | 14 | layout (binding = 0) uniform sampler2D rock; 15 | layout (binding = 1) uniform sampler2D soil; 16 | layout (binding = 2) uniform sampler2D water; 17 | layout (binding = 3) uniform sampler2D temp; 18 | layout (binding = 4) uniform sampler2D moist; 19 | layout (binding = 5) uniform sampler2D wind; 20 | layout (binding = 6) uniform sampler2D ice; 21 | layout (binding = 7) uniform sampler2D mixtex; 22 | layout (binding = 8) uniform sampler2DShadow shadow_tex; 23 | 24 | layout (binding = 9) uniform sampler2DArray texArray; 25 | 26 | 27 | 28 | const uint texIndexDirt = 0; 29 | const uint texIndexBeachSand = 1; 30 | const uint texIndexforestWarm = 2; 31 | const uint texIndexRock = 3; 32 | const uint texIndexrainForest = 4; 33 | const uint texIndexDesert = 5; 34 | const uint texIndexSnow = 6; 35 | const uint texIndextundraCold = 7; 36 | const uint texIndextundraWet = 8; 37 | const uint texIndexWater = 9; 38 | 39 | uniform uint currentSelection = 7; 40 | 41 | vec3 getTexValue(sampler2D tex, float x, float y) 42 | { 43 | // return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 44 | 45 | return texture(tex,texcoordF).xyz; 46 | } 47 | 48 | vec3 getTexValue(sampler2DArray tex,uint layer, float x, float y) 49 | { 50 | // return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 51 | 52 | return texture(tex,vec3(fract(texcoordF*10),layer)).xyz; 53 | } 54 | 55 | vec3 calcTextureColor() 56 | { 57 | vec3 color; 58 | const vec3 Color_Polar_desert = vec3(1.0,1.0,1.0); 59 | const vec3 Color_Subpolar_dry_tundra = vec3(0.5,0.5,0.5); 60 | const vec3 Color_Subpolar_moist_tundra = vec3(0.38,0.5,0.5); 61 | const vec3 Color_Subpolar_wet_tundra = vec3(0.25,0.5,0.5); 62 | const vec3 Color_Subpolar_rain_tundra = vec3(0.125,0.5,0.75); 63 | const vec3 Color_Boreal_desert = vec3(0.62,0.62,0.5); 64 | const vec3 Color_Boreal_dry_scrub = vec3(0.5,0.62,0.62); 65 | const vec3 Color_Boreal_moist_forest = vec3(0.37,0.62,0.5); 66 | const vec3 Color_Boreal_wet_forest = vec3(0.25,0.62,0.56); 67 | const vec3 Color_Boreal_rain_forest = vec3(0.125,0.62,0.75); 68 | const vec3 Color_Cool_temperate_desert = vec3(0.75,0.75,0.5); 69 | const vec3 Color_Cool_temperate_desert_scrub = vec3(0.62,0.75,0.5); 70 | const vec3 Color_Cool_temperate_steppe = vec3(0.5,0.75,0.5); 71 | const vec3 Color_Cool_temperate_moist_forest = vec3(0.37,0.75,0.5); 72 | const vec3 Color_Cool_temperate_wet_forest = vec3(0.25,0.75,0.56); 73 | const vec3 Color_Cool_temperate_rain_forest = vec3(0.125,0.75,0.75); 74 | const vec3 Color_Warm_temperate_desert = vec3(0.87,0.8,0.5); 75 | const vec3 Color_Warm_temperate_desert_scrub = vec3(0.81,0.8,0.5); 76 | const vec3 Color_Warm_temperate_thorn_scrub = vec3(0.62,0.8,0.5); 77 | const vec3 Color_Warm_temperate_dry_forest = vec3(0.5,0.8,0.5); 78 | const vec3 Color_Warm_temperate_moist_forest = vec3(0.37,0.8,0.5); 79 | const vec3 Color_Warm_temperate_wet_forest = vec3(0.25,0.8,0.56); 80 | const vec3 Color_Warm_temperate_rain_forest = vec3(0.125,0.8,0.75); 81 | const vec3 Color_Subtropical_desert = vec3(0.92,0.95,0.5); 82 | const vec3 Color_Subtropical_desert_scrub = vec3(0.82,0.95,0.5); 83 | const vec3 Color_Subtropical_thorn_woodland = vec3(0.69,0.95,0.5); 84 | const vec3 Color_Subtropical_dry_forest = vec3(0.5,0.95,0.5); 85 | const vec3 Color_Subtropical_moist_forest = vec3(0.37,0.95,0.5); 86 | const vec3 Color_Subtropical_wet_forest = vec3(0.25,0.95,0.56); 87 | const vec3 Color_Subtropical_rain_forest = vec3(0.125,0.95,0.69); 88 | const vec3 Color_Tropical_desert = vec3(1.0,1.0,0.5); 89 | const vec3 Color_Tropical_desert_scrub = vec3(0.88,1.0,0.5); 90 | const vec3 Color_Tropical_thorn_woodland = vec3(0.75,1.0,0.5); 91 | const vec3 Color_Tropical_very_dry_forest = vec3(0.63,1.0,0.5); 92 | const vec3 Color_Tropical_dry_forest = vec3(0.5,1.0,0.5); 93 | const vec3 Color_Tropical_moist_forest = vec3(0.37,1.0,0.5); 94 | const vec3 Color_Tropical_wet_forest = vec3(0.25,1.0,0.56); 95 | const vec3 Color_Tropical_rain_forest = vec3(0.125,1.0,0.62); 96 | const vec3 Color_Ocean = vec3(0.0,0.0,0.5); 97 | const vec3 Color_River = vec3(0.0,0.4,0.8); 98 | const vec3 Color_Sand = vec3(0.0,0.0,0.0); 99 | const vec3 Color_Rock = vec3(0.0,0.0,0.0); 100 | const vec3 Color_Lake = vec3(0.0,0.0,0.7); 101 | 102 | 103 | /* float tempZone = getTexValue(mixtex,0.0,0.0).y 104 | if(tempZone == 0.5) 105 | //subpolar 106 | else if(tempZone==0.62) 107 | //boreal 108 | else if(tempZone==0.75) 109 | //cool 110 | else if(tempZone==0.8) 111 | //warm 112 | else if(tempZone==0.95) 113 | //subtropical 114 | else 115 | //tropicla*/ 116 | color = getTexValue(mixtex,0.0,0.0);; 117 | // color = mix(color,getTexValue(texArray,texIndexSnow,0.0,0.0),getTexValue(ice,0.0,0.0).x); 118 | //color = mix(color,getTexValue(texArray,texIndexWater,0.0,0.0),getTexValue(water,0.0,0.0).x); 119 | // color = mix(color,getTexValue(texArray,texIndexDirt,0.0,0.0),getTexValue(soil,0.0,0.0).x); 120 | 121 | return color; 122 | } 123 | 124 | 125 | 126 | 127 | 128 | in vec4 shadowCoord; 129 | out vec3 color; 130 | 131 | void main() 132 | { 133 | 134 | switch(currentSelection) 135 | { 136 | case 0: 137 | color.x = getTexValue(rock,0.0,0.0).x ; 138 | color.y = getTexValue(rock,0.0,0.0).x -1.5; 139 | color.z = getTexValue(rock,0.0,0.0).x -3.0; 140 | break; 141 | case 1: 142 | color = getTexValue(soil,0.0,0.0).xyz*10; 143 | break; 144 | case 2: 145 | 146 | color = vec3(abs(getTexValue(water,0.0,0.0).xyz)); 147 | 148 | break; 149 | case 3: 150 | color = getTexValue(temp,0.0,0.0).xyz; 151 | break; 152 | case 4: 153 | color = vec3(getTexValue(moist,0.0,0.0).x,0.0,0.0); 154 | break; 155 | case 5: 156 | color = getTexValue(wind,0.0,0.0).xyz; 157 | break; 158 | case 6: 159 | color = getTexValue(ice,0.0,0.0).xyz; 160 | break; 161 | case 7: 162 | color = getTexValue(mixtex,0.0,0.0).xyz; 163 | break; 164 | case 8: 165 | color = calcTextureColor(); 166 | break; 167 | } 168 | 169 | 170 | 171 | if( currentSelection == 8) 172 | { 173 | vec3 N = normalize(vs_out.N); 174 | vec3 L = normalize(vs_out.L); 175 | vec3 V = normalize(vs_out.V); 176 | 177 | 178 | vec4 v_diffuse = max(dot(N,L), 0.0) * vec4(0.3,0.3,0.0,0.0); 179 | vec4 v_specular= vec4(0.0,0.0,0.0,0.0); 180 | if(dot(N,L) < 0.0) 181 | { 182 | } 183 | else 184 | { 185 | 186 | v_specular = pow(max(dot(reflect(-L,N),V),0.0), 0.99) * vec4(0.7); 187 | 188 | } 189 | float visibility = 0.0; 190 | vec3 sCoord = shadowCoord.xyz/ shadowCoord.w; 191 | 192 | 193 | if(shadowCoord.w <= 0.f || (sCoord.x < 0 || sCoord.y < 0) || (sCoord.x >= 1 || sCoord.y >= 1)) 194 | { 195 | visibility = 1.0; 196 | } 197 | else 198 | { 199 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(1,1)).x; 200 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(1,-1)).x; 201 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(-1,1)).x; 202 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(-1,-1)).x; 203 | visibility /= 4.0; 204 | } 205 | color = (visibility *v_diffuse.xyz) + 0.6*color;//(texture2D(shadow_tex, (shadowCoord.xy)/textureSize(shadow_tex,0)).z ) ; 206 | } 207 | } 208 | 209 | 210 | -------------------------------------------------------------------------------- /Shader/display/3D/dispmap.tcs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | 4 | //height texture 5 | layout (binding = 0) uniform sampler2D rock; 6 | layout (binding = 1) uniform sampler2D soil; 7 | layout (binding = 2) uniform sampler2D water; 8 | layout (binding = 3) uniform sampler2D temp; 9 | layout (binding = 4) uniform sampler2D moist; 10 | layout (binding = 5) uniform sampler2D wind; 11 | layout (binding = 6) uniform sampler2D ice; 12 | layout (binding = 7) uniform sampler2D mixtex; 13 | 14 | uniform mat4 mv_matrix; //model view matrix 15 | uniform mat4 proj_matrix; //projection matrix 16 | 17 | in vec2 texCoord[]; 18 | out vec2 texCoordT[]; 19 | // Inputs from vertex shader 20 | 21 | 22 | 23 | 24 | 25 | layout(vertices = 4) out; 26 | 27 | uniform vec2 screen_size = vec2(800,600);; 28 | uniform float lod_factor = 4.0; 29 | 30 | bool segmentInFrustum(vec4 p1, vec4 p2) { 31 | 32 | if ((p1.x < -p1.w && p2.x < -p2.w) || (p1.x > p1.w && p2.x > p2.w) || 33 | // (p1.y < -p1.w && p2.y < -p2.w) || (p1.y > p1.w && p2.y > p2.w) || 34 | (p1.z < -p1.w && p2.z < -p2.w) || (p1.z > p1.w && p2.z > p2.w)) 35 | return true; 36 | else 37 | return false; 38 | 39 | } 40 | 41 | vec2 screen_space(vec4 vertex){ 42 | return (clamp(vertex.xy, -1.3, 1.3)+1) * (screen_size*0.5); 43 | } 44 | 45 | float level(vec2 v0, vec2 v1){ 46 | return clamp(distance(v0, v1)/lod_factor, 1, 64); 47 | } 48 | 49 | void main() 50 | { 51 | if(gl_InvocationID == 0) 52 | { 53 | vec4 v0 = proj_matrix * mv_matrix * gl_in[0].gl_Position; 54 | vec4 v1 = proj_matrix * mv_matrix * gl_in[1].gl_Position; 55 | vec4 v2 = proj_matrix * mv_matrix *gl_in[2].gl_Position; 56 | vec4 v3 = proj_matrix * mv_matrix *gl_in[3].gl_Position; 57 | 58 | v0 /= v0.w; 59 | v1 /= v1.w; 60 | v2 /= v2.w; 61 | v3 /= v3.w; 62 | 63 | 64 | if(all(bvec4(segmentInFrustum(v0,v1), segmentInFrustum(v0,v2), segmentInFrustum(v2,v3),segmentInFrustum(v3,v1)))){ 65 | gl_TessLevelInner[0] = 0; 66 | gl_TessLevelInner[1] = 0; 67 | gl_TessLevelOuter[0] = 0; 68 | gl_TessLevelOuter[1] = 0; 69 | gl_TessLevelOuter[2] = 0; 70 | gl_TessLevelOuter[3] = 0; 71 | } 72 | else{ 73 | float l0 = length(v0.xy - v1.xy)*7+1; 74 | float l1 = length(v0.xy - v2.xy)*7 +1; 75 | float l2 = length(v2.xy - v3.xy)*7 +1; 76 | float l3 = length(v3.xy - v1.xy)*7 +1; 77 | 78 | 79 | /* gl_TessLevelInner[0] = mix(l0, l1, 0.5); 80 | gl_TessLevelInner[1] = mix(l2, l3, 0.5); 81 | gl_TessLevelOuter[0] = l0; 82 | gl_TessLevelOuter[1] = l1; 83 | gl_TessLevelOuter[2] = l2; 84 | gl_TessLevelOuter[3] = l3;*/ 85 | gl_TessLevelInner[0] = 15; 86 | gl_TessLevelInner[1] = 15; 87 | gl_TessLevelOuter[0] = 15; 88 | gl_TessLevelOuter[1] = 15; 89 | gl_TessLevelOuter[2] = 15; 90 | gl_TessLevelOuter[3] = 15; 91 | } 92 | } 93 | 94 | texCoordT[gl_InvocationID] = texCoord[gl_InvocationID]; 95 | gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Shader/display/3D/dispmap.tes.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | //incoming tesselated primitives 4 | layout (quads) in; 5 | //height texture 6 | layout (binding = 0) uniform sampler2D rock; 7 | layout (binding = 1) uniform sampler2D soil; 8 | layout (binding = 2) uniform sampler2D water; 9 | layout (binding = 3) uniform sampler2D temp; 10 | layout (binding = 4) uniform sampler2D moist; 11 | layout (binding = 5) uniform sampler2D wind; 12 | layout (binding = 6) uniform sampler2D ice; 13 | layout (binding = 7) uniform sampler2D mixtex; 14 | 15 | uniform mat4 mv_matrix; //model view matrix 16 | uniform mat4 proj_matrix; //projection matrix 17 | uniform vec3 light_pos = vec3(0.0, 0.0,0.0); 18 | uniform mat4 model_matrix; 19 | uniform mat4 shadowMVP; 20 | 21 | 22 | in vec2 texCoordT[]; 23 | out vec2 texcoordF; 24 | 25 | out vec4 shadowCoord; 26 | 27 | out VS_OUT 28 | { 29 | vec3 N; 30 | vec3 L; 31 | vec3 V; 32 | } vs_out; 33 | 34 | 35 | uniform ivec2 dimensions; 36 | 37 | float height(vec2 coord) 38 | { 39 | return texture(rock, coord).x + texture(soil , coord).x; 40 | } 41 | 42 | vec3 calcNormal (vec2 tCoord, vec2 dist) 43 | { 44 | vec2 p = 1.0/textureSize(rock,0); 45 | vec3 v1 = vec3(0.0, height(tCoord + (p*vec2(0.0,-1.0))) , p.y*-1.0); 46 | vec3 v2 = vec3(p.x*1.0, height(tCoord + (p*vec2(1.0,0.0))) , 0.0); 47 | vec3 v3 = vec3(0.0, height(tCoord + (p*vec2(0.0,1.0))) , p.y*1.0); 48 | vec3 v4 = vec3(p.x*-1.0, height(tCoord + (p*vec2(-1.0,0.0))), 0.0); 49 | return normalize(normalize(cross(v1,v2))+normalize(cross(v2,v3))+normalize(cross(v3,v4))+normalize(cross(v4,v1))); 50 | 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | void main() 61 | { 62 | 63 | float u = gl_TessCoord.x; 64 | float v = gl_TessCoord.y; 65 | vec3 p0 = gl_in[0].gl_Position.xyz ; 66 | vec3 p1 =gl_in[1].gl_Position.xyz ; 67 | vec3 p2 =gl_in[2].gl_Position.xyz; 68 | vec3 p3 = gl_in[3].gl_Position.xyz ; 69 | 70 | 71 | vec2 dist = gl_in[0].gl_Position.xz-gl_in[1].gl_Position.xz; 72 | 73 | vec2 t1 = mix(texCoordT[0], texCoordT[1], u); 74 | vec2 t2 = mix(texCoordT[2], texCoordT[3], u); 75 | texcoordF = mix(t2, t1, v); 76 | 77 | vec3 p_1 = mix(p0 , p1, u); 78 | vec3 p_2 = mix(p2, p3, u); 79 | 80 | vec3 q =mix(p_2, p_1, v) ; 81 | q.y = height( texcoordF); 82 | 83 | shadowCoord = (shadowMVP *model_matrix) * vec4(q,1.0) ; 84 | 85 | gl_Position = proj_matrix * mv_matrix * vec4(q,1.0) ; 86 | vec4 pos = model_matrix *vec4(q,1.0); 87 | 88 | 89 | vec4 Nposition = model_matrix *vec4(q,1.0); 90 | 91 | vec3 lpos = vec3(dimensions.x*0.5,0.0,dimensions.y*0.5) - light_pos; 92 | vs_out.N = transpose(inverse(mat3(model_matrix))) * calcNormal(texcoordF,dist); 93 | vs_out.L = lpos - ((Nposition.xyz)/Nposition.w); 94 | vs_out.V = -((Nposition.xyz)/Nposition.w); 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Shader/display/3D/dispmap.vs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | //outgoing tesselation coordinates 4 | in vec4 position; 5 | out vec2 texCoord; 6 | 7 | 8 | uniform mat4 mv_matrix; 9 | uniform mat4 proj_matrix; 10 | 11 | uniform ivec2 dimensions; 12 | 13 | 14 | 15 | 16 | 17 | void main(void) 18 | { 19 | texCoord = (position.xz+vec2(0.5))/vec2(dimensions); 20 | gl_Position = position; 21 | } 22 | -------------------------------------------------------------------------------- /Shader/display/3D/waterDispmap.fs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | 4 | in VS_OUT 5 | { 6 | vec3 N; 7 | vec3 L; 8 | vec3 V; 9 | } vs_out; 10 | 11 | #define PI 3.14159265358979323846 12 | 13 | in vec2 texcoordF; 14 | in vec2 tessCoord; 15 | layout (binding = 0) uniform sampler2D rock; 16 | layout (binding = 1) uniform sampler2D soil; 17 | layout (binding = 2) uniform sampler2D water; 18 | layout (binding = 3) uniform sampler2D temp; 19 | layout (binding = 4) uniform sampler2D moist; 20 | layout (binding = 5) uniform sampler2D wind; 21 | layout (binding = 6) uniform sampler2D ice; 22 | layout (binding = 7) uniform sampler2D mixtex; 23 | layout (binding = 8) uniform sampler2DShadow shadow_tex; 24 | 25 | layout (binding = 9) uniform sampler2D waterNormals; 26 | layout (binding = 11) uniform sampler2D waterFlow; 27 | 28 | uniform ivec2 dimensions; 29 | uniform float waterSpeed; 30 | 31 | in vec4 position; 32 | 33 | vec3 getTexValue(sampler2D tex, float x, float y) 34 | { 35 | 36 | return texture(tex,texcoordF+ (vec2(x,y)/textureSize(tex,0))).xyz; 37 | } 38 | 39 | 40 | vec3 getnormal() 41 | { 42 | 43 | 44 | vec2 mid= getTexValue(waterFlow, 0,0).xy*-waterSpeed; 45 | vec2 down = (getTexValue(waterFlow, -1,1).xy*-waterSpeed+mid)*0.5; 46 | vec2 top = (getTexValue(waterFlow, 1, 1).xy*-waterSpeed+mid)*0.5; 47 | vec2 right = (getTexValue(waterFlow, -1, -1).xy*-waterSpeed+mid)*0.5; 48 | vec2 left = (getTexValue(waterFlow,1,-1 ).xy*-waterSpeed+mid)*0.5; 49 | 50 | 51 | 52 | vec3 downt = normalize(texture2D(waterNormals,(texcoordF+(vec2(-1,1)/textureSize(waterFlow,0)))*400+down).xyz*2-1); 53 | vec3 topt = normalize(texture2D(waterNormals,(texcoordF+(vec2(1,1)/textureSize(waterFlow,0)))*400+top).xyz*2-1); 54 | vec3 rightt = normalize(texture2D(waterNormals,(texcoordF+(vec2(-1,-1)/textureSize(waterFlow,0)))*400+right).xyz*2-1); 55 | vec3 leftt = normalize(texture2D(waterNormals,(texcoordF+(vec2(1,-1)/textureSize(waterFlow,0)))*400+left).xyz*2-1); 56 | 57 | vec3 normal1 = mix(downt, topt,tessCoord.x); 58 | vec3 normal2 = mix(rightt, leftt, tessCoord.x); 59 | vec3 normal = mix(normal2,normal1,tessCoord.y); 60 | return normalize(normal); 61 | } 62 | 63 | 64 | in vec4 shadowCoord; 65 | out vec4 color; 66 | 67 | void main() 68 | { 69 | 70 | vec3 w = getTexValue(water, 0, 0); 71 | 72 | 73 | 74 | float speed_factor = clamp(length(w.yz)/0.02, 0.0, 1.0); 75 | float depth_factor = clamp(w.x/0.01, 0.0, 1.0); 76 | 77 | vec3 deep = vec3(0.0, 51.0/255.0, 128.0/255.0)*0.5; 78 | vec3 flatw = vec3(0.0/255.0, 100.0/255.0, 130.0/255.0)*0.7; 79 | 80 | vec3 tcolor = mix(flatw, deep, sqrt(clamp(w.x/0.0075, 0.0, 1.0))); 81 | 82 | vec3 base_normal = normalize(vs_out.N); 83 | vec3 tangent = normalize(cross(base_normal, vec3(0.0, 0.0, 1.0))); 84 | vec3 bitangent = normalize(cross(tangent, base_normal)); 85 | mat3 orthobasis = mat3(tangent, base_normal, bitangent); 86 | vec3 detail_normal = orthobasis * getnormal(); 87 | vec3 normal = normalize(mix(base_normal*0.5+detail_normal*0.5, detail_normal, speed_factor)); 88 | normal = normalize(mix(normal, base_normal, sqrt(clamp(w.x/0.0075, 0.0, 1.0))*0.75)); 89 | 90 | vec3 N =normal; 91 | vec3 L = normalize(vs_out.L); 92 | vec3 V = normalize(vs_out.V); 93 | 94 | 95 | vec3 v_diffuse = max(dot(N,L), 0.0) * vec3(0.0, 90.0/255.0, 120.0/255.0); 96 | vec3 v_specular= vec3(0.00,0.0,0.0); 97 | float spec; 98 | if(dot(N,L) >= 0.0) 99 | { 100 | v_specular = pow(max(dot(reflect(-L,N),V),0.0), 0.5) * vec3(0.5,0.5, 0.8); 101 | } 102 | 103 | float visibility = 0.0; 104 | vec3 sCoord = shadowCoord.xyz/ shadowCoord.w; 105 | 106 | if(shadowCoord.w <= 0.f || (sCoord.x < 0 || sCoord.y < 0) || (sCoord.x >= 1 || sCoord.y >= 1)) 107 | { 108 | visibility = 1.0; 109 | } 110 | else 111 | { 112 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(1,1)).x; 113 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(1,-1)).x; 114 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(-1,1)).x; 115 | visibility += textureProjOffset(shadow_tex,vec4(sCoord,1.0),ivec2(-1,-1)).x; 116 | visibility /= 4.0; 117 | } 118 | 119 | color =vec4((v_diffuse.xyz + tcolor +v_specular) *visibility,depth_factor) ; 120 | 121 | 122 | if(w.x <0.04 && length(w.yz) < 0.02) 123 | color = mix(vec4(0.0),vec4(color.xyz,1.0),(w.x+length(w.yz))*40) ;; 124 | } 125 | 126 | 127 | -------------------------------------------------------------------------------- /Shader/display/3D/waterDispmap.tcs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | 4 | //height texture 5 | layout (binding = 0) uniform sampler2D rock; 6 | layout (binding = 1) uniform sampler2D soil; 7 | layout (binding = 2) uniform sampler2D water; 8 | layout (binding = 3) uniform sampler2D temp; 9 | layout (binding = 4) uniform sampler2D moist; 10 | layout (binding = 5) uniform sampler2D wind; 11 | layout (binding = 6) uniform sampler2D ice; 12 | layout (binding = 7) uniform sampler2D mixtex; 13 | 14 | uniform mat4 mv_matrix; //model view matrix 15 | uniform mat4 proj_matrix; //projection matrix 16 | 17 | in vec2 texCoord[]; 18 | out vec2 texCoordT[]; 19 | // Inputs from vertex shader 20 | 21 | 22 | 23 | 24 | 25 | layout(vertices = 4) out; 26 | 27 | uniform vec2 screen_size = vec2(800,600);; 28 | uniform float lod_factor = 4.0; 29 | 30 | bool segmentInFrustum(vec4 p1, vec4 p2) { 31 | 32 | if ((p1.x < -p1.w && p2.x < -p2.w) || (p1.x > p1.w && p2.x > p2.w) || 33 | // (p1.y < -p1.w && p2.y < -p2.w) || (p1.y > p1.w && p2.y > p2.w) || 34 | (p1.z < -p1.w && p2.z < -p2.w) || (p1.z > p1.w && p2.z > p2.w)) 35 | return true; 36 | else 37 | return false; 38 | 39 | } 40 | 41 | vec2 screen_space(vec4 vertex){ 42 | return (clamp(vertex.xy, -1.3, 1.3)+1) * (screen_size*0.5); 43 | } 44 | 45 | float level(vec2 v0, vec2 v1){ 46 | return clamp(distance(v0, v1)/lod_factor, 1, 64); 47 | } 48 | 49 | void main() 50 | { 51 | if(gl_InvocationID == 0) 52 | { 53 | vec4 v0 = proj_matrix * mv_matrix * gl_in[0].gl_Position; 54 | vec4 v1 = proj_matrix * mv_matrix * gl_in[1].gl_Position; 55 | vec4 v2 = proj_matrix * mv_matrix *gl_in[2].gl_Position; 56 | vec4 v3 = proj_matrix * mv_matrix *gl_in[3].gl_Position; 57 | 58 | v0 /= v0.w; 59 | v1 /= v1.w; 60 | v2 /= v2.w; 61 | v3 /= v3.w; 62 | 63 | 64 | if(all(bvec4(segmentInFrustum(v0,v1), segmentInFrustum(v0,v2), segmentInFrustum(v2,v3),segmentInFrustum(v3,v1)))){ 65 | gl_TessLevelInner[0] = 0; 66 | gl_TessLevelInner[1] = 0; 67 | gl_TessLevelOuter[0] = 0; 68 | gl_TessLevelOuter[1] = 0; 69 | gl_TessLevelOuter[2] = 0; 70 | gl_TessLevelOuter[3] = 0; 71 | } 72 | else{ 73 | float l0 = length(v0.xy - v1.xy)*7+1; 74 | float l1 = length(v0.xy - v2.xy)*7 +1; 75 | float l2 = length(v2.xy - v3.xy)*7 +1; 76 | float l3 = length(v3.xy - v1.xy)*7 +1; 77 | 78 | 79 | /* gl_TessLevelInner[0] = mix(l0, l1, 0.5); 80 | gl_TessLevelInner[1] = mix(l2, l3, 0.5); 81 | gl_TessLevelOuter[0] = l0; 82 | gl_TessLevelOuter[1] = l1; 83 | gl_TessLevelOuter[2] = l2; 84 | gl_TessLevelOuter[3] = l3;*/ 85 | gl_TessLevelInner[0] = 15; 86 | gl_TessLevelInner[1] = 15; 87 | gl_TessLevelOuter[0] = 15; 88 | gl_TessLevelOuter[1] = 15; 89 | gl_TessLevelOuter[2] = 15; 90 | gl_TessLevelOuter[3] = 15; 91 | } 92 | } 93 | 94 | texCoordT[gl_InvocationID] = texCoord[gl_InvocationID]; 95 | gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Shader/display/3D/waterDispmap.tes.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | //incoming tesselated primitives 4 | layout (quads) in; 5 | //height texture 6 | layout (binding = 0) uniform sampler2D rock; 7 | layout (binding = 1) uniform sampler2D soil; 8 | layout (binding = 2) uniform sampler2D water; 9 | layout (binding = 3) uniform sampler2D temp; 10 | layout (binding = 4) uniform sampler2D moist; 11 | layout (binding = 5) uniform sampler2D wind; 12 | layout (binding = 6) uniform sampler2D ice; 13 | layout (binding = 7) uniform sampler2D mixtex; 14 | 15 | uniform mat4 mv_matrix; //model view matrix 16 | uniform mat4 proj_matrix; //projection matrix 17 | uniform vec3 light_pos = vec3(0.0, 0.0,0.0); 18 | uniform mat4 model_matrix; 19 | uniform mat4 shadowMVP; 20 | 21 | 22 | in vec2 texCoordT[]; 23 | out vec2 texcoordF; 24 | out vec4 position; 25 | out vec4 shadowCoord; 26 | out vec2 tessCoord; 27 | out VS_OUT 28 | { 29 | vec3 N; 30 | vec3 L; 31 | vec3 V; 32 | } vs_out; 33 | 34 | 35 | uniform ivec2 dimensions; 36 | 37 | float height(vec2 coord) 38 | { 39 | return texture(rock, coord).x + texture(soil , coord).x+ texture(water , coord).x; 40 | } 41 | 42 | vec3 calcNormal (vec2 tCoord, vec2 dist) 43 | { 44 | vec2 p = 1.0/textureSize(rock,0); 45 | vec3 v1 = vec3(0.0, height(tCoord + (p*vec2(0.0,-1.0))) , p.y*-1.0); 46 | vec3 v2 = vec3(p.x*1.0, height(tCoord + (p*vec2(1.0,0.0))) , 0.0); 47 | vec3 v3 = vec3(0.0, height(tCoord + (p*vec2(0.0,1.0))) , p.y*1.0); 48 | vec3 v4 = vec3(p.x*-1.0, height(tCoord + (p*vec2(-1.0,0.0))), 0.0); 49 | return normalize(normalize(cross(v1,v2))+normalize(cross(v2,v3))+normalize(cross(v3,v4))+normalize(cross(v4,v1))); 50 | 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | void main() 61 | { 62 | 63 | float u = gl_TessCoord.x; 64 | float v = gl_TessCoord.y; 65 | vec3 p0 = gl_in[0].gl_Position.xyz ; 66 | vec3 p1 =gl_in[1].gl_Position.xyz ; 67 | vec3 p2 =gl_in[2].gl_Position.xyz; 68 | vec3 p3 = gl_in[3].gl_Position.xyz ; 69 | 70 | tessCoord = gl_TessCoord.xy; 71 | vec2 dist = gl_in[0].gl_Position.xz-gl_in[1].gl_Position.xz; 72 | 73 | vec2 t1 = mix(texCoordT[0], texCoordT[1], u); 74 | vec2 t2 = mix(texCoordT[2], texCoordT[3], u); 75 | texcoordF = mix(t2, t1, v); 76 | 77 | vec3 p_1 = mix(p0 , p1, u); 78 | vec3 p_2 = mix(p2, p3, u); 79 | 80 | vec3 q =mix(p_2, p_1, v) ; 81 | position = vec4(q,1.0); 82 | 83 | 84 | q.y = (height(texcoordF) ); 85 | 86 | shadowCoord = (shadowMVP *model_matrix) * vec4(q,1.0) ; 87 | 88 | 89 | gl_Position = proj_matrix * mv_matrix * vec4(q,1.0) ; 90 | vec4 Nposition = model_matrix *vec4(q,1.0); 91 | 92 | vec3 lpos = vec3(dimensions.x*0.5,0.0,dimensions.y*0.5) - light_pos; 93 | vs_out.N = transpose(inverse(mat3(model_matrix))) * calcNormal(texcoordF,dist); 94 | vs_out.L = lpos - ((Nposition.xyz)/Nposition.w); 95 | vs_out.V = -((Nposition.xyz)/Nposition.w); 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /Shader/display/3D/waterDispmap.vs.glsl: -------------------------------------------------------------------------------- 1 | #version 420 core 2 | 3 | //outgoing tesselation coordinates 4 | in vec4 position; 5 | out vec2 texCoord; 6 | 7 | 8 | uniform mat4 mv_matrix; 9 | uniform mat4 proj_matrix; 10 | 11 | uniform ivec2 dimensions; 12 | 13 | 14 | 15 | 16 | 17 | 18 | void main(void) 19 | { 20 | texCoord = (position.xz+vec2(0.5))/vec2(dimensions); 21 | gl_Position = position; 22 | } 23 | -------------------------------------------------------------------------------- /Shader/display/3D/waterFlow.fs.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 430 core 3 | 4 | out vec3 color; 5 | 6 | layout (binding = 0) uniform sampler2D rock; 7 | layout (binding = 1) uniform sampler2D soil; 8 | layout (binding = 2) uniform sampler2D water; 9 | layout (binding = 3) uniform sampler2D temp; 10 | layout (binding = 4) uniform sampler2D moist; 11 | layout (binding = 5) uniform sampler2D wind; 12 | layout (binding = 6) uniform sampler2D ice; 13 | 14 | layout (binding = 9) uniform sampler2D flows; 15 | 16 | 17 | vec3 getTexValue(sampler2D tex, float x, float y) 18 | { 19 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 20 | } 21 | 22 | 23 | void main() 24 | { 25 | color = vec3(getTexValue(flows,0.0,0.0).xy + ((getTexValue(water, 0,0).yz)*0.001)/(getTexValue(water, 0,0).x*0.1+0.001),0.0); 26 | } 27 | -------------------------------------------------------------------------------- /Shader/display/3D/waterFlow.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | 8 | void main() 9 | { 10 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 11 | vec4( 1.0, -1.0, 0.5, 1.0), 12 | vec4(-1.0, 1.0, 0.5, 1.0), 13 | vec4( 1.0, 1.0, 0.5, 1.0)); 14 | //move vertex 15 | gl_Position = vertices[gl_VertexID]; 16 | } 17 | -------------------------------------------------------------------------------- /Shader/simulation/climat/climat.fs.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 430 core 3 | 4 | const vec3 Color_Polar_desert = vec3(1.0,1.0,1.0); 5 | const vec3 Color_Subpolar_dry_tundra = vec3(0.5,0.5,0.5); 6 | const vec3 Color_Subpolar_moist_tundra = vec3(0.38,0.5,0.5); 7 | const vec3 Color_Subpolar_wet_tundra = vec3(0.25,0.5,0.5); 8 | const vec3 Color_Subpolar_rain_tundra = vec3(0.125,0.5,0.75); 9 | const vec3 Color_Boreal_desert = vec3(0.62,0.62,0.5); 10 | const vec3 Color_Boreal_dry_scrub = vec3(0.5,0.62,0.62); 11 | const vec3 Color_Boreal_moist_forest = vec3(0.37,0.62,0.5); 12 | const vec3 Color_Boreal_wet_forest = vec3(0.25,0.62,0.56); 13 | const vec3 Color_Boreal_rain_forest = vec3(0.125,0.62,0.75); 14 | const vec3 Color_Cool_temperate_desert = vec3(0.75,0.75,0.5); 15 | const vec3 Color_Cool_temperate_desert_scrub = vec3(0.62,0.75,0.5); 16 | const vec3 Color_Cool_temperate_steppe = vec3(0.5,0.75,0.5); 17 | const vec3 Color_Cool_temperate_moist_forest = vec3(0.37,0.75,0.5); 18 | const vec3 Color_Cool_temperate_wet_forest = vec3(0.25,0.75,0.56); 19 | const vec3 Color_Cool_temperate_rain_forest = vec3(0.125,0.75,0.75); 20 | const vec3 Color_Warm_temperate_desert = vec3(0.87,0.8,0.5); 21 | const vec3 Color_Warm_temperate_desert_scrub = vec3(0.81,0.8,0.5); 22 | const vec3 Color_Warm_temperate_thorn_scrub = vec3(0.62,0.8,0.5); 23 | const vec3 Color_Warm_temperate_dry_forest = vec3(0.5,0.8,0.5); 24 | const vec3 Color_Warm_temperate_moist_forest = vec3(0.37,0.8,0.5); 25 | const vec3 Color_Warm_temperate_wet_forest = vec3(0.25,0.8,0.56); 26 | const vec3 Color_Warm_temperate_rain_forest = vec3(0.125,0.8,0.75); 27 | const vec3 Color_Subtropical_desert = vec3(0.92,0.95,0.5); 28 | const vec3 Color_Subtropical_desert_scrub = vec3(0.82,0.95,0.5); 29 | const vec3 Color_Subtropical_thorn_woodland = vec3(0.69,0.95,0.5); 30 | const vec3 Color_Subtropical_dry_forest = vec3(0.5,0.95,0.5); 31 | const vec3 Color_Subtropical_moist_forest = vec3(0.37,0.95,0.5); 32 | const vec3 Color_Subtropical_wet_forest = vec3(0.25,0.95,0.56); 33 | const vec3 Color_Subtropical_rain_forest = vec3(0.125,0.95,0.69); 34 | const vec3 Color_Tropical_desert = vec3(1.0,1.0,0.5); 35 | const vec3 Color_Tropical_desert_scrub = vec3(0.88,1.0,0.5); 36 | const vec3 Color_Tropical_thorn_woodland = vec3(0.75,1.0,0.5); 37 | const vec3 Color_Tropical_very_dry_forest = vec3(0.63,1.0,0.5); 38 | const vec3 Color_Tropical_dry_forest = vec3(0.5,1.0,0.5); 39 | const vec3 Color_Tropical_moist_forest = vec3(0.37,1.0,0.5); 40 | const vec3 Color_Tropical_wet_forest = vec3(0.25,1.0,0.56); 41 | const vec3 Color_Tropical_rain_forest = vec3(0.125,1.0,0.62); 42 | const vec3 Color_Ocean = vec3(0.0,0.0,0.4); 43 | const vec3 Color_River = vec3(0.0,0.4,0.8); 44 | const vec3 Color_Sand = vec3(0.0,0.0,0.0); 45 | const vec3 Color_Rock = vec3(0.0,0.0,0.0); 46 | const vec3 Color_Lake = vec3(0.0,0.0,0.8); 47 | 48 | 49 | const uint alpine = 1; 50 | const uint boreal = 2; 51 | const uint cool = 3; 52 | const uint warm = 4; 53 | const uint subtropical = 5; 54 | const uint tropical = 6; 55 | 56 | const uint superarid = 1; 57 | const uint perarid = 2; 58 | const uint arid = 3; 59 | const uint semiarid = 4; 60 | const uint subhumid = 5; 61 | const uint humid = 6; 62 | const uint perhumid = 7; 63 | const uint superhumid = 8; 64 | 65 | 66 | const float temp_alpine = -0.8; 67 | const float temp_boreal = -0.3; 68 | const float temp_cool = 0.0; 69 | const float temp_warm = 0.25; 70 | const float temp_subtropical= 0.5; 71 | const float temp_tropical = 0.8; 72 | 73 | const float humidity_superarid = 0.1; 74 | const float humidity_perarid = 0.25; 75 | const float humidity_arid = 0.35; 76 | const float humidity_semiarid = 0.5; 77 | const float humidity_subhumid = 0.6; 78 | const float humidity_humid = 0.75; 79 | const float humidity_perhumid = 0.8; 80 | const float humidity_superhumid = 1.0; 81 | 82 | layout (binding = 0) uniform sampler2D rock; 83 | layout (binding = 1) uniform sampler2D soil; 84 | layout (binding = 2) uniform sampler2D water; 85 | layout (binding = 3) uniform sampler2D temp; 86 | layout (binding = 4) uniform sampler2D moist; 87 | layout (binding = 5) uniform sampler2D wind; 88 | layout (binding = 6) uniform sampler2D ice; 89 | 90 | out vec3 color; 91 | 92 | 93 | 94 | 95 | vec3 getTexValue(sampler2D tex, float x, float y) 96 | { 97 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 98 | } 99 | 100 | float getGround(float x, float y) 101 | { 102 | return texture2D(rock, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(rock,0))).x 103 | + texture2D(soil, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(soil,0))).x; 104 | } 105 | 106 | 107 | uint getHumidityZone() 108 | { 109 | float humidity = getTexValue(moist, 0.0,0.0).x; 110 | if(humidity <= humidity_superarid) 111 | { 112 | return superarid; 113 | } 114 | if(humidity <= humidity_perarid) 115 | { 116 | return perarid; 117 | } 118 | if(humidity <= humidity_arid) 119 | { 120 | return arid; 121 | } 122 | if(humidity <= humidity_semiarid) 123 | { 124 | return semiarid; 125 | } 126 | if(humidity <= humidity_subhumid) 127 | { 128 | return subhumid; 129 | } 130 | if(humidity <= humidity_humid) 131 | { 132 | return humid; 133 | } 134 | if(humidity <= humidity_perhumid) 135 | { 136 | return perhumid; 137 | } 138 | return superhumid; 139 | } 140 | 141 | uint getTemperatureZone() 142 | { 143 | float temperature = getTexValue(temp, 0.0,0.0).x; 144 | if(temperature <= temp_alpine) 145 | { 146 | return alpine; 147 | } 148 | if(temperature <= temp_boreal) 149 | { 150 | return boreal; 151 | } 152 | if(temperature <= temp_cool) 153 | { 154 | return cool; 155 | } 156 | if(temperature <= temp_warm) 157 | { 158 | return warm; 159 | } 160 | if(temperature <= temp_subtropical) 161 | { 162 | return subtropical; 163 | } 164 | return tropical; 165 | } 166 | 167 | 168 | 169 | 170 | void main() 171 | { 172 | vec3 value ; 173 | if(getTexValue(ice, 0.0,0.0).x > 0.1) 174 | { 175 | value = Color_Polar_desert; 176 | } 177 | 178 | else if(getTexValue(water, 0.0,0.0).x > 0.1) 179 | { 180 | if(getGround(0.0,0.0) < 0.2) 181 | { 182 | value = Color_Ocean; 183 | 184 | } 185 | 186 | else 187 | { 188 | value = Color_Lake; 189 | } 190 | } 191 | else if(abs(getTexValue(water, 0.0,0.0).y) > 0.005 || abs(getTexValue(water, 0.0,0.0).z) > 0.005) 192 | { 193 | value = Color_River; 194 | } 195 | else 196 | { 197 | uint tempZone = getTemperatureZone(); 198 | uint humidZone = getHumidityZone(); 199 | switch(tempZone) 200 | { 201 | case alpine: 202 | { 203 | switch(humidZone) 204 | { 205 | case superarid: 206 | { 207 | value = Color_Subpolar_dry_tundra; 208 | break; 209 | } 210 | case perarid: 211 | { 212 | value = Color_Subpolar_moist_tundra; 213 | break; 214 | } 215 | case arid: 216 | { 217 | value = Color_Subpolar_wet_tundra; 218 | break; 219 | } 220 | default: 221 | { 222 | value = Color_Subpolar_rain_tundra; 223 | break; 224 | } 225 | } 226 | break; 227 | } 228 | case boreal: 229 | { 230 | switch(humidZone) 231 | { 232 | case superarid: 233 | { 234 | value = Color_Boreal_desert; 235 | break; 236 | } 237 | case perarid: 238 | { 239 | value = Color_Boreal_dry_scrub; 240 | break; 241 | } 242 | case arid: 243 | { 244 | value = Color_Boreal_moist_forest; 245 | break; 246 | } 247 | case semiarid: 248 | { 249 | value = Color_Boreal_wet_forest; 250 | break; 251 | } 252 | default: 253 | { 254 | value = Color_Boreal_rain_forest; 255 | break; 256 | } 257 | } 258 | break; 259 | } 260 | 261 | case cool: 262 | { 263 | switch(humidZone) 264 | { 265 | case superarid: 266 | { 267 | value = Color_Cool_temperate_desert; 268 | break; 269 | } 270 | case perarid: 271 | { 272 | value = Color_Cool_temperate_desert_scrub; 273 | break; 274 | } 275 | case arid: 276 | { 277 | value = Color_Cool_temperate_steppe; 278 | break; 279 | } 280 | case semiarid: 281 | { 282 | value = Color_Cool_temperate_moist_forest; 283 | break; 284 | } 285 | case subhumid: 286 | { 287 | value = Color_Cool_temperate_wet_forest; 288 | break; 289 | } 290 | default: 291 | { 292 | value = Color_Cool_temperate_rain_forest; 293 | break; 294 | } 295 | } 296 | break; 297 | } 298 | case warm: 299 | { 300 | switch(humidZone) 301 | { 302 | case superarid: 303 | { 304 | value = Color_Warm_temperate_desert; 305 | break; 306 | } 307 | case perarid: 308 | { 309 | value = Color_Warm_temperate_desert_scrub; 310 | break; 311 | } 312 | case arid: 313 | { 314 | value = Color_Warm_temperate_thorn_scrub; 315 | break; 316 | } 317 | case semiarid: 318 | { 319 | value = Color_Warm_temperate_dry_forest; 320 | break; 321 | } 322 | case subhumid: 323 | { 324 | value = Color_Warm_temperate_moist_forest; 325 | break; 326 | } 327 | case humid: 328 | { 329 | value = Color_Warm_temperate_wet_forest; 330 | break; 331 | } 332 | default: 333 | { 334 | value = Color_Warm_temperate_rain_forest; 335 | break; 336 | } 337 | } 338 | break; 339 | } 340 | case subtropical: 341 | { 342 | switch(humidZone) 343 | { 344 | case superarid: 345 | { 346 | value = Color_Subtropical_desert; 347 | break; 348 | } 349 | case perarid: 350 | { 351 | value = Color_Subtropical_desert_scrub; 352 | break; 353 | } 354 | case arid: 355 | { 356 | value = Color_Subtropical_thorn_woodland; 357 | break; 358 | } 359 | case semiarid: 360 | { 361 | value = Color_Subtropical_dry_forest; 362 | break; 363 | } 364 | case subhumid: 365 | { 366 | value = Color_Subtropical_moist_forest; 367 | break; 368 | } 369 | case humid: 370 | { 371 | value = Color_Subtropical_wet_forest; 372 | break; 373 | } 374 | default: 375 | { 376 | value = Color_Subtropical_rain_forest; 377 | break; 378 | } 379 | } 380 | break; 381 | } 382 | case tropical: 383 | { 384 | switch(humidZone) 385 | { 386 | case superarid: 387 | { 388 | value = Color_Tropical_desert; 389 | break; 390 | } 391 | case perarid: 392 | { 393 | value = Color_Tropical_desert_scrub; 394 | break; 395 | } 396 | case arid: 397 | { 398 | value = Color_Tropical_thorn_woodland; 399 | break; 400 | } 401 | case semiarid: 402 | { 403 | value = Color_Tropical_very_dry_forest; 404 | break; 405 | } 406 | case subhumid: 407 | { 408 | value = Color_Tropical_dry_forest; 409 | break; 410 | } 411 | case humid: 412 | { 413 | value = Color_Tropical_moist_forest; 414 | break; 415 | } 416 | case perhumid: 417 | { 418 | value = Color_Tropical_wet_forest; 419 | break; 420 | } 421 | default: 422 | { 423 | value = Color_Tropical_rain_forest; 424 | break; 425 | } 426 | } 427 | break; 428 | } 429 | default: 430 | { 431 | if(getTexValue(soil,0.0,0.0).x >0.0) 432 | value = Color_Sand; 433 | else 434 | value = Color_Rock; 435 | } 436 | } 437 | } 438 | color = value; 439 | } 440 | -------------------------------------------------------------------------------- /Shader/simulation/climat/climat.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | 8 | void main() 9 | { 10 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 11 | vec4( 1.0, -1.0, 0.5, 1.0), 12 | vec4(-1.0, 1.0, 0.5, 1.0), 13 | vec4( 1.0, 1.0, 0.5, 1.0)); 14 | //move vertex 15 | gl_Position = vertices[gl_VertexID]; 16 | } 17 | -------------------------------------------------------------------------------- /Shader/simulation/ice/ice_Sim.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | 8 | layout (binding = 0) uniform sampler2D rock; 9 | layout (binding = 1) uniform sampler2D soil; 10 | layout (binding = 2) uniform sampler2D water; 11 | layout (binding = 3) uniform sampler2D temp; 12 | layout (binding = 4) uniform sampler2D moist; 13 | layout (binding = 5) uniform sampler2D wind; 14 | layout (binding = 6) uniform sampler2D ice; 15 | 16 | out vec3 color; 17 | 18 | uniform float iceTemperature; 19 | 20 | 21 | vec3 getTexValue(sampler2D tex, float x, float y) 22 | { 23 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 24 | } 25 | 26 | float getGround(float x, float y) 27 | { 28 | return getTexValue(rock,x,y).x + getTexValue(soil,x,y).x; 29 | 30 | } 31 | 32 | 33 | float exchange(float g1, float l1, vec2 dir) 34 | { 35 | float g2 = getGround(dir.x, dir.y); 36 | float l2 = getTexValue(ice, dir.x, dir.y).x; 37 | float change = g2 -g1; 38 | return clamp(change, -l1*0.01, l2*0.01); 39 | 40 | } 41 | 42 | 43 | void main() 44 | { 45 | vec2 top = vec2(0,1), bot = vec2(0,-1), left = vec2(-1,0), right = vec2(1,0), current= vec2(0,0); 46 | 47 | 48 | float newIce = getTexValue(ice,0,0).x; 49 | float temperature = getTexValue(temp,0,0).x; 50 | float ground = getGround(0,0); 51 | float melt = 0.0; 52 | if((temperature < iceTemperature)) 53 | newIce += mix(0.002,0.007,temperature+1); 54 | else 55 | { 56 | newIce -= mix(0.002,0.007,temperature+1); 57 | melt = clamp(abs(clamp(newIce,0.0,1.0)-getTexValue(ice,0,0).x),0.0,1.0); 58 | } 59 | 60 | float v = ( 61 | exchange(ground, newIce, top) + 62 | exchange(ground, newIce, bot) + 63 | exchange(ground, newIce, left) + 64 | exchange(ground, newIce, right) 65 | ); 66 | 67 | 68 | newIce = newIce + v; 69 | newIce = clamp(newIce,0.0,1.0); 70 | color = vec3(newIce,melt ,0.00); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Shader/simulation/ice/ice_Sim.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | 8 | void main() 9 | { 10 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 11 | vec4( 1.0, -1.0, 0.5, 1.0), 12 | vec4(-1.0, 1.0, 0.5, 1.0), 13 | vec4( 1.0, 1.0, 0.5, 1.0)); 14 | //move vertex 15 | gl_Position = vertices[gl_VertexID]; 16 | } 17 | -------------------------------------------------------------------------------- /Shader/simulation/moist/moist_Sim.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | layout (binding = 0) uniform sampler2D rock; 8 | layout (binding = 1) uniform sampler2D soil; 9 | layout (binding = 2) uniform sampler2D water; 10 | layout (binding = 3) uniform sampler2D temp; 11 | layout (binding = 4) uniform sampler2D moist; 12 | layout (binding = 5) uniform sampler2D wind; 13 | layout (binding = 6) uniform sampler2D ice; 14 | 15 | out vec3 color; 16 | 17 | 18 | uniform float waterAddFactor = 1; 19 | uniform float landRemoveFactor = 1; 20 | 21 | 22 | vec3 getTexValue(sampler2D tex, float x, float y) 23 | { 24 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 25 | } 26 | 27 | float getGround(float x, float y) 28 | { 29 | return getTexValue(rock,x,y).x + getTexValue(soil,x,y).x; 30 | 31 | } 32 | 33 | float diffuse( float h1, float x, float y) 34 | { 35 | 36 | float h2 = getTexValue(moist, x, y).x; 37 | 38 | float diff = (h2-h1)/8.0; 39 | return clamp(diff, -h1/2.0, h2/2.0); 40 | } 41 | 42 | 43 | void main() 44 | { 45 | float new_moist = 0.0; 46 | float temperature = getTexValue(temp,0.0,0.0).x; 47 | 48 | 49 | if(getTexValue(ice,0.0,0.0).x > 0.001) 50 | { 51 | new_moist = -0.003; 52 | } 53 | else if(getTexValue(water,0.0,0.0).x > 0.04) //if water is high enough 54 | { 55 | new_moist += 0.003 * waterAddFactor; 56 | } 57 | else 58 | { 59 | new_moist *= mix(0.3,0.7,clamp(temperature,0.0,1.0)) ; 60 | new_moist -= landRemoveFactor*0.001; 61 | } 62 | 63 | new_moist = (getTexValue(moist, 0, 0).x+new_moist) ; 64 | 65 | 66 | 67 | 68 | float tf = 0.4; 69 | float tm = 0.4; 70 | 71 | vec3 w = getTexValue(wind, 0.0, 0.0); 72 | vec3 g = getTexValue(moist, 0.0, 0.0); 73 | 74 | vec3 w_left = getTexValue(wind, -1.0, 0.0); 75 | vec3 w_right = getTexValue(wind, 1.0, 0.0); 76 | vec3 w_top = getTexValue(wind, 0.0, 1.0); 77 | vec3 w_bot = getTexValue(wind, 0.0, -1.0); 78 | 79 | vec3 g_left = getTexValue(moist, -1.0, 0.0); 80 | vec3 g_right = getTexValue(moist, 1.0, 0.0); 81 | vec3 g_top = getTexValue(moist, 0.0, 1.0); 82 | vec3 g_bot = getTexValue(moist, 0.0, -1.0); 83 | //change temperature based on wind direction 84 | float moist_transported_off = (min(abs(tf*w.x), tm) + min(abs(w.y*tf), tm))*g.x; 85 | 86 | float moist_transported_in = ( 87 | clamp(w_left.x*tf, 0.0, tm) * g_left.x + 88 | clamp(-w_right.x*tf, 0.0, tm) * g_right.x + 89 | clamp(-w_top.y*tf, 0.0, tm) * g_top.x + 90 | clamp(w_bot.y*tf, 0.0, tm) * g_bot.x 91 | ); 92 | new_moist += (moist_transported_in ) - moist_transported_off; 93 | 94 | 95 | new_moist = new_moist + diffuse(new_moist, 0.0, 1.0) + diffuse(new_moist, 0.0, -1.0) ; 96 | new_moist = new_moist + diffuse(new_moist, 1.0, 0.0) + diffuse(new_moist, - 1.0, 0.0) ; 97 | 98 | 99 | 100 | 101 | new_moist = clamp(new_moist, 0.0, 1.0 ); 102 | 103 | color = vec3(new_moist,0.0,0.0); 104 | } 105 | -------------------------------------------------------------------------------- /Shader/simulation/moist/moist_Sim.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | void main() { 8 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 9 | vec4( 1.0, -1.0, 0.5, 1.0), 10 | vec4(-1.0, 1.0, 0.5, 1.0), 11 | vec4( 1.0, 1.0, 0.5, 1.0)); 12 | //move vertex 13 | gl_Position = vertices[gl_VertexID]; 14 | } 15 | -------------------------------------------------------------------------------- /Shader/simulation/rock/rock_Sim.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | uniform float min_therm_limit = 1; 8 | uniform float max_therm_limit = 1; 9 | 10 | uniform float threm_factor = 2; 11 | 12 | layout (binding = 0) uniform sampler2D rock; 13 | layout (binding = 1) uniform sampler2D soil; 14 | layout (binding = 2) uniform sampler2D water; 15 | layout (binding = 3) uniform sampler2D temp; 16 | layout (binding = 4) uniform sampler2D moist; 17 | layout (binding = 5) uniform sampler2D wind; 18 | layout (binding = 6) uniform sampler2D ice; 19 | 20 | layout (location = 0) out float color; 21 | 22 | vec3 getTexValue(sampler2D tex, float x, float y) 23 | { 24 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 25 | } 26 | float getGround(float x, float y) 27 | { 28 | return getTexValue(rock,x,y).x + getTexValue(soil,x,y).x; 29 | 30 | } 31 | 32 | 33 | float thermal_erosion( float h1, float x, float y) 34 | { 35 | 36 | float h2 = getTexValue(rock, x, y).x; 37 | float diff = 0.0; 38 | if(abs(h2-h1) < max_therm_limit && abs(h2-h1) > min_therm_limit && getTexValue(water, 0, 0).x < 0.05) 39 | { 40 | diff = (h2-h1)/8.0; 41 | } 42 | return diff*threm_factor*0.04; 43 | } 44 | 45 | 46 | void main() 47 | { 48 | color = texture2D(rock, (gl_FragCoord.xy)/textureSize(rock,0)).x; //get height 49 | color -= getTexValue(soil,0,0).y ; //subtract new generated soil 50 | 51 | if(threm_factor > 0.0) 52 | { 53 | color += thermal_erosion(color, 0.0, 1.0) + thermal_erosion(color, 0.0, -1.0); 54 | color += thermal_erosion(color, 1.0, 0.0) + thermal_erosion(color, - 1.0, 0.0); 55 | color += (thermal_erosion(color, 1.0, 1.0) + thermal_erosion(color, - 1.0, 1.0))*0.25; 56 | color += (thermal_erosion(color, 1.0, -1.0) + thermal_erosion(color, - 1.0, - 1.0))*0.25; 57 | } 58 | 59 | 60 | 61 | color = max(0.001,color); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Shader/simulation/rock/rock_Sim.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | void main() 8 | { 9 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 10 | vec4( 1.0, -1.0, 0.5, 1.0), 11 | vec4(-1.0, 1.0, 0.5, 1.0), 12 | vec4( 1.0, 1.0, 0.5, 1.0)); 13 | //move vertex 14 | gl_Position = vertices[gl_VertexID]; 15 | } 16 | -------------------------------------------------------------------------------- /Shader/simulation/soil/soil_Sim.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | layout (binding = 0) uniform sampler2D rock; 8 | layout (binding = 1) uniform sampler2D soil; 9 | layout (binding = 2) uniform sampler2D water; 10 | layout (binding = 3) uniform sampler2D temp; 11 | layout (binding = 4) uniform sampler2D moist; 12 | layout (binding = 5) uniform sampler2D wind; 13 | layout (binding = 6) uniform sampler2D ice; 14 | 15 | uniform float errodeFactor = 1; 16 | uniform float soilDiffuseFactor = 1; 17 | out vec3 color; 18 | 19 | 20 | vec3 getTexValue(sampler2D tex, float x, float y) 21 | { 22 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 23 | } 24 | 25 | float getGround(float x, float y) 26 | { 27 | return getTexValue(rock,x,y).x + getTexValue(soil,x,y).x; 28 | 29 | } 30 | 31 | 32 | float exchange(float g1, vec3 l1, float x, float y) 33 | { 34 | float g2 = getTexValue(rock,x, y).x; 35 | vec3 l2 = getTexValue(soil, x, y); 36 | float change = ( (g2+l2.x)-(g1+l1.x))*0.125 ; 37 | change = clamp(change, -l1.x/2.0, l2.x/2.0)*0.08; 38 | return change; 39 | } 40 | 41 | void main() { 42 | 43 | float tf = 0.0015; 44 | float tm = 0.5; 45 | 46 | 47 | vec3 g = getTexValue(soil, 0.0, 0.0); 48 | vec3 g1 = getTexValue(rock, 0.0, 0.0); 49 | 50 | vec3 w = getTexValue(water, 0.0, 0.0); 51 | 52 | float erroded = (length(w.yz)*0.00004 * errodeFactor)/(w.x+0.001+ g.x); 53 | erroded = clamp(erroded,0.0,g1.x); 54 | g.y = erroded; 55 | g.x += erroded; 56 | 57 | 58 | vec3 w_left = getTexValue(water, -1.0, 0.0); 59 | vec3 w_right = getTexValue(water, 1.0, 0.0); 60 | vec3 w_top = getTexValue(water, 0.0, 1.0); 61 | vec3 w_bot = getTexValue(water, 0.0, -1.0); 62 | 63 | vec3 g_left = getTexValue(soil, -1.0, 0.0); 64 | vec3 g_right = getTexValue(soil, 1.0, 0.0); 65 | vec3 g_top = getTexValue(soil, 0.0, 1.0); 66 | vec3 g_bot = getTexValue(soil, 0.0, -1.0); 67 | 68 | float soil_transported_off = (min(abs(w.y*tf/(w.x+0.001)), tm) + min(abs(w.z*tf/(w.x+0.001)), tm))*g.x; 69 | 70 | float soil_transported_in = ( 71 | clamp(w_left.y*tf/(w_left.x+0.001), 0.0, tm) * g_left.x + 72 | clamp(-w_right.y*tf/(w_right.x+0.001), 0.0, tm) * g_right.x + 73 | clamp(-w_top.z*tf/(w_top.x+0.001), 0.0, tm) * g_top.x + 74 | clamp(w_bot.z*tf/(w_bot.x+0.001), 0.0, tm) * g_bot.x 75 | ); 76 | g.x += (soil_transported_in- soil_transported_off ) ; 77 | 78 | g.x = max(0.0,g.x) ; 79 | float c = ( 80 | exchange(g1.x,g, 1.0, 0.0) + 81 | exchange(g1.x,g, -1.0, 0.0) + 82 | exchange(g1.x,g, 0.0, 1.0) + 83 | exchange(g1.x,g, 0.0, -1.0) 84 | ); 85 | g.x += (c *soilDiffuseFactor); 86 | 87 | 88 | 89 | /* if(g.x > 0.2) //if soil threashold is reached 90 | { 91 | g.x -= 0.001; //add to landmass 92 | g.y += 0.001; 93 | }*/ 94 | 95 | // g.x = max(0.0,g.x) ; 96 | 97 | color = g; 98 | 99 | 100 | } 101 | -------------------------------------------------------------------------------- /Shader/simulation/soil/soil_Sim.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | void main() 8 | { 9 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 10 | vec4( 1.0, -1.0, 0.5, 1.0), 11 | vec4(-1.0, 1.0, 0.5, 1.0), 12 | vec4( 1.0, 1.0, 0.5, 1.0)); 13 | //move vertex 14 | gl_Position = vertices[gl_VertexID]; 15 | } 16 | -------------------------------------------------------------------------------- /Shader/simulation/temp/temp_Sim.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | #define PI 3.14159265358979323846 8 | 9 | layout (binding = 0) uniform sampler2D rock; 10 | layout (binding = 1) uniform sampler2D soil; 11 | layout (binding = 2) uniform sampler2D water; 12 | layout (binding = 3) uniform sampler2D temp; 13 | layout (binding = 4) uniform sampler2D moist; 14 | layout (binding = 5) uniform sampler2D wind; 15 | layout (binding = 6) uniform sampler2D ice; 16 | 17 | uniform float latFactor = 2.0; 18 | uniform float sunAngle = 0.0; 19 | uniform float heightCooldown = 1.0; 20 | uniform float timeFactorTemp = 1.0; 21 | uniform float rotationSpeed = 1.0; 22 | uniform float DayNightFactor = 1.0; 23 | 24 | out vec3 color; 25 | 26 | vec3 getTexValue(sampler2D tex, float x, float y) 27 | { 28 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 29 | } 30 | 31 | float getGround(float x, float y) 32 | { 33 | return getTexValue(rock,x,y).x + getTexValue(soil,x,y).x; 34 | 35 | } 36 | 37 | 38 | float diffuse( float h1, float x, float y) 39 | { 40 | 41 | float h2 = getTexValue(temp, x, y).x; 42 | 43 | float diff = (h2-h1)/4.0; 44 | return diff;// clamp(diff, -h1/2.0, h2/2.0); 45 | } 46 | 47 | float getDayNightValue(float temperature) 48 | { 49 | float x = gl_FragCoord.x/(textureSize(temp,0)).x * PI* 2 - (timeFactorTemp); 50 | float sunlight = sin(PI* 0.5 * cos(x))*0.7 +0.5 ; 51 | if( (gl_FragCoord.y+ sunAngle)/textureSize(temp,0).y < sunlight) 52 | return temperature; 53 | 54 | return 0.5 *DayNightFactor; 55 | 56 | 57 | } 58 | 59 | 60 | void main() 61 | { 62 | //set temp on latitude 63 | float latitude = (((gl_FragCoord.xy+vec2(0.0,sunAngle))/textureSize(temp,0)).y ) ; 64 | float temperature = clamp(cos(latitude*2*PI +PI ) ,-1.0,1.0) + latFactor; 65 | 66 | temperature = getDayNightValue(temperature) ; 67 | float heigth = getGround(0.0,0.0); 68 | float waterheight = getTexValue(water,0.0,0.0).x; 69 | 70 | if(heigth > heightCooldown) 71 | temperature -= 1.2 * heigth; 72 | 73 | 74 | 75 | 76 | if( getTexValue(water,0.0,0.0).x > 0.1) 77 | temperature = (temperature * 0.003)+ getTexValue(temp,0.0,0.0).x; 78 | else 79 | temperature = (temperature * 0.006)+ getTexValue(temp,0.0,0.0).x; 80 | 81 | 82 | float tf = 0.5; 83 | float tm = 0.9; 84 | 85 | 86 | vec3 w = getTexValue(wind, 0.0, 0.0); 87 | vec3 g = getTexValue(temp, 0.0, 0.0); 88 | 89 | vec3 w_left = getTexValue(wind, -1.0, 0.0); 90 | vec3 w_right = getTexValue(wind, 1.0, 0.0); 91 | vec3 w_top = getTexValue(wind, 0.0, 1.0); 92 | vec3 w_bot = getTexValue(wind, 0.0, -1.0); 93 | 94 | vec3 g_left = getTexValue(temp, -1.0, 0.0); 95 | vec3 g_right = getTexValue(temp, 1.0, 0.0); 96 | vec3 g_top = getTexValue(temp, 0.0, 1.0); 97 | vec3 g_bot = getTexValue(temp, 0.0, -1.0); 98 | //change temperature based on wind direction 99 | float heat_transported_off = (min(abs(tf*w.x), tm) + min(abs(w.y*tf), tm))*g.x; 100 | 101 | float heat_transported_in = ( 102 | clamp(w_left.x*tf, 0.0, tm) * g_left.x + 103 | clamp(-w_right.x*tf, 0.0, tm) * g_right.x + 104 | clamp(-w_top.y*tf, 0.0, tm) * g_top.x + 105 | clamp(w_bot.y*tf, 0.0, tm) * g_bot.x 106 | ); 107 | temperature += (heat_transported_in - heat_transported_off ) ; 108 | 109 | 110 | temperature = temperature + diffuse(temperature, 0.0, 1.0) + diffuse(temperature, 0.0, -1.0); 111 | temperature = temperature + diffuse(temperature, 1.0, 0.0) + diffuse(temperature, - 1.0, 0.0); 112 | 113 | temperature = clamp(temperature, -1.0,1.0); 114 | color = vec3(temperature,0.0,-temperature); 115 | 116 | } 117 | -------------------------------------------------------------------------------- /Shader/simulation/temp/temp_Sim.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | void main() { 8 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 9 | vec4( 1.0, -1.0, 0.5, 1.0), 10 | vec4(-1.0, 1.0, 0.5, 1.0), 11 | vec4( 1.0, 1.0, 0.5, 1.0)); 12 | //move vertex 13 | gl_Position = vertices[gl_VertexID]; 14 | } 15 | -------------------------------------------------------------------------------- /Shader/simulation/water/water_Sim.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | uniform float rain, evaporate ; 8 | uniform float sea_level = 0.8; 9 | 10 | layout (binding = 0) uniform sampler2D rock; 11 | layout (binding = 1) uniform sampler2D soil; 12 | layout (binding = 2) uniform sampler2D water; 13 | layout (binding = 3) uniform sampler2D temp; 14 | layout (binding = 4) uniform sampler2D moist; 15 | layout (binding = 5) uniform sampler2D wind; 16 | layout (binding = 6) uniform sampler2D ice; 17 | 18 | out vec3 color; 19 | 20 | 21 | vec3 getTexValue(sampler2D tex, float x, float y) 22 | { 23 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 24 | } 25 | 26 | float getGround(float x, float y) 27 | { 28 | return getTexValue(rock,x,y).x + getTexValue(soil,x,y).x; 29 | 30 | } 31 | 32 | vec3 exchange(float g1, vec3 l1, vec3 c1, float x, float y) 33 | { 34 | float g2 = getGround( x, y); 35 | vec3 c2 = getTexValue(water, x, y).xyz; 36 | float change = (g2+c2.x) - (g1+l1.x); 37 | change = clamp(change*0.25, -c1.x*0.25, c2.x*0.25); 38 | return vec3(change, vec2(-x*change, -y*change)); 39 | } 40 | 41 | 42 | vec3 diffuse(float t1, float h1, vec2 off) 43 | { 44 | float t2 = getGround(off.x,off.y); 45 | float h2 = getTexValue(water, off.x, off.y).x; 46 | float f1 = t1+h1; 47 | float f2 = t2+h2; 48 | float diff = (f2-f1)/2.0; 49 | diff = clamp(diff*0.65, -h1/2.0, h2/2.0); 50 | return vec3(diff, (-off)*diff); 51 | } 52 | 53 | void main(void) 54 | { 55 | 56 | float ground = getGround(0, 0); 57 | float temperature = getTexValue(temp, 0, 0).x; 58 | vec3 result = getTexValue(water, 0, 0); 59 | 60 | 61 | 62 | 63 | //diffuse 64 | vec3 result1 = diffuse(ground,result.x, vec2(0.0, 1.0)) + diffuse(ground,result.x, vec2(0.0, -1.0)); 65 | vec3 result2 = diffuse(ground,result.x, vec2(1.0, 0.0)) + diffuse(ground,result.x, vec2(- 1.0, 0.0)); 66 | 67 | result += mix(result1,result2,0.5); 68 | 69 | vec3 last = getTexValue(water, 0, 0); 70 | //flows 71 | vec3 v = ( 72 | exchange(ground, last,result, 1.0, 0.0) + 73 | exchange(ground, last,result, -1.0, 0.0) + 74 | exchange(ground, last,result, 0.0, 1.0) + 75 | exchange(ground, last,result, 0.0, -1.0) 76 | )*vec3(0.25, 0.25, 0.25); 77 | 78 | result = result + v; 79 | 80 | 81 | result.x -= 0.000007 * (evaporate*(temperature+2 )); 82 | result.x += .000022 * (rain* getTexValue(moist, 0, 0).x); 83 | result.x += getTexValue(ice, 0.0, 0.0).y*0.01; 84 | 85 | 86 | 87 | //calcualte water movement based on movements around 88 | result.yz = ( 89 | getTexValue(water,-1.0, 1.0).yz*1.0 + getTexValue(water,0.0, 1.0).yz*1.4 + getTexValue(water,1.0, 1.0).yz*1.0 + 90 | getTexValue(water,-1.0, 0.0).yz*1.4 + result.yz*300.0 + getTexValue(water,1.0, 0.0).yz*1.4 + 91 | getTexValue(water,-1.0, -1.0).yz*1.0 + getTexValue(water,0.0, -1.0).yz*1.4 + getTexValue(water,1.0, -1.0).yz*1.0 92 | )*0.98*(1.0/(300.0+1.4*4.0+4.0)); 93 | 94 | 95 | // result.yz = clamp( result.yz,vec2(-1.0),vec2(1.0)); 96 | result.x = clamp( result.x,sea_level -ground,10.0); 97 | 98 | 99 | 100 | color = result; 101 | 102 | } 103 | -------------------------------------------------------------------------------- /Shader/simulation/water/water_Sim.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | 8 | 9 | void main() 10 | { 11 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 12 | vec4( 1.0, -1.0, 0.5, 1.0), 13 | vec4(-1.0, 1.0, 0.5, 1.0), 14 | vec4( 1.0, 1.0, 0.5, 1.0)); 15 | //move vertex 16 | gl_Position = vertices[gl_VertexID]; 17 | } 18 | -------------------------------------------------------------------------------- /Shader/simulation/wind/wind_Sim.fs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | #define PI 3.14159265358979323846 8 | 9 | layout (binding = 0) uniform sampler2D rock; 10 | layout (binding = 1) uniform sampler2D soil; 11 | layout (binding = 2) uniform sampler2D water; 12 | layout (binding = 3) uniform sampler2D temp; 13 | layout (binding = 4) uniform sampler2D moist; 14 | layout (binding = 5) uniform sampler2D wind; 15 | layout (binding = 6) uniform sampler2D ice; 16 | 17 | 18 | layout (binding = 8) uniform sampler2D noiseTex; 19 | 20 | uniform float distorsionFaktor = 1.0; 21 | uniform float globelWindFaktor = 1.0; 22 | uniform float localPressureFaktor = 1.0; 23 | uniform float timeFactorWind = 0.0; 24 | uniform float windspeed = 0.0; 25 | 26 | out vec3 color; 27 | 28 | 29 | 30 | float getNoiseValue(vec2 coord) 31 | { 32 | return (texture2D(noiseTex,((gl_FragCoord.xy )/textureSize(noiseTex,0)+coord)+vec2(sign((gl_FragCoord.y/textureSize(noiseTex,0).y)-0.5)*(timeFactorWind*0.001),0.0)).x * 2) -1; 33 | } 34 | 35 | vec3 getTexValue(sampler2D tex, float x, float y) 36 | { 37 | return texture2D(tex, fract((gl_FragCoord.xy+vec2(x,y))/textureSize(tex,0))).xyz; 38 | } 39 | 40 | float getGround(float x, float y) 41 | { 42 | return getTexValue(rock,x,y).x + getTexValue(soil,x,y).x; 43 | } 44 | 45 | 46 | float calculatePressure(vec2 dir) 47 | { 48 | float pressure = (-getTexValue(temp,dir.x, dir.y).x +1.0) + 1.0-( getTexValue(moist,dir.x, dir.y).x ) ; 49 | pressure = 1/(getGround(dir.x, dir.y).x + getTexValue(water,dir.x, dir.y).x) *10; 50 | 51 | return pressure; 52 | } 53 | 54 | vec2 getWindDirection(vec2 dir, float curPressure, float dirPressure) 55 | { 56 | return dir * ( dirPressure-curPressure) ; 57 | } 58 | 59 | float getGlobalWindDirectionX() 60 | { 61 | float latitude = (gl_FragCoord.xy/textureSize(wind,0)).y +0.1; 62 | 63 | return clamp((-(cos(latitude*11))* globelWindFaktor)+(getNoiseValue(vec2(0.5))*distorsionFaktor),-1.0,1.0); 64 | 65 | } 66 | 67 | float getGlobalWindDirectionY() 68 | { 69 | float latitude = fract((gl_FragCoord.xy/textureSize(rock,0)).y ); 70 | 71 | float ret = clamp((-cos(latitude*PI*3)* globelWindFaktor)+(getNoiseValue(vec2(0.0))*distorsionFaktor),-1.0,1.0); 72 | 73 | return ret; 74 | } 75 | 76 | 77 | vec3 diffuse( vec3 h1, float x, float y) 78 | { 79 | 80 | vec3 h2 = getTexValue(wind, x, y); 81 | 82 | vec3 diff = (h2-h1) /4.0; 83 | return diff; 84 | } 85 | 86 | 87 | 88 | void main() 89 | { 90 | vec2 top = vec2(0,1), bot = vec2(0,-1), left = vec2(-1,0), right = vec2(1,0), current= vec2(0,0); 91 | 92 | 93 | vec2 windDirection; 94 | float pressure = calculatePressure(current) ; 95 | 96 | windDirection.y = (getWindDirection(top,pressure,getTexValue(wind,top.x , top.y).z).y + getWindDirection(bot,pressure,getTexValue(wind,bot.x , bot.y).z).y) ; 97 | windDirection.x = (getWindDirection(left,pressure,getTexValue(wind,left.x , left.y).z).x + getWindDirection(right,pressure,getTexValue(wind,right.x , right.y).z).x); 98 | 99 | windDirection *= localPressureFaktor; 100 | //-temp , -altitude, -moist 101 | 102 | 103 | windDirection.xy += ( 104 | getTexValue(wind,-1.0, 1.0).xy*1.0 + getTexValue(wind,0.0, 1.0).xy*1.4 + getTexValue(wind,1.0, 1.0).xy*1.0 + 105 | getTexValue(wind,-1.0, 0.0).xy*1.4 +windDirection.xy*400.0 + getTexValue(wind,1.0, 0.0).xy*1.4 + 106 | getTexValue(wind,-1.0, -1.0).xy*1.0 + getTexValue(wind,0.0, -1.0).xy*1.4 + getTexValue(wind,1.0, -1.0).xy*1.0 107 | )/(400.0+1.4*4.0+4.0); 108 | 109 | windDirection= vec2(getGlobalWindDirectionX(),getGlobalWindDirectionY()) + windDirection ; 110 | 111 | 112 | vec3 ret = vec3(windDirection,-pressure); 113 | ret +=( diffuse(ret, 0.0, 1.0) + diffuse(ret, 0.0, -1.0)) ; 114 | ret += (diffuse(ret, 1.0, 0.0) + diffuse(ret, - 1.0, 0.0)) ; 115 | 116 | ret.xy = clamp(ret.xy ,-1.0,1.0); 117 | 118 | color = ret;// 119 | 120 | } 121 | -------------------------------------------------------------------------------- /Shader/simulation/wind/wind_Sim.vs.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample dummy shader to check the highlighter plugin. 3 | */ 4 | 5 | #version 430 core 6 | 7 | void main() { 8 | const vec4 vertices[] = vec4[](vec4(-1.0, -1.0, 0.5, 1.0), 9 | vec4( 1.0, -1.0, 0.5, 1.0), 10 | vec4(-1.0, 1.0, 0.5, 1.0), 11 | vec4( 1.0, 1.0, 0.5, 1.0)); 12 | //move vertex 13 | gl_Position = vertices[gl_VertexID]; 14 | } 15 | -------------------------------------------------------------------------------- /Thesis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tarTG/RTWG/6cbf782c47c360dcf4bf5ca9b0d1b999d85dac38/Thesis.pdf -------------------------------------------------------------------------------- /cmake/FindAntTweakBar.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Try to find AntTweakBar library and include path. 3 | # Once done this will define 4 | # 5 | # ANTTWEAKBAR_FOUND 6 | # ANTTWEAKBAR_INCLUDE_DIR 7 | # ANTTWEAKBAR_LIBRARY 8 | # 9 | 10 | IF (WIN32) 11 | IF( CMAKE_SIZEOF_VOID_P EQUAL 8 ) 12 | SET( BITS "64" ) 13 | ELSE() 14 | SET( BITS "" ) 15 | ENDIF() 16 | 17 | FIND_PATH( ANTTWEAKBAR_INCLUDE_DIR AntTweakBar.h PATHS 18 | ${CMAKE_CURRENT_LIST_DIR}/../external/AntTweakBar/include 19 | $ENV{ANTTWEAKBAR_ROOT}/include 20 | DOC "The directory where AntTweakBar.h resides") 21 | 22 | FIND_LIBRARY( ANTTWEAKBAR_LIBRARY AntTweakBar${BITS} PATHS 23 | IF( CMAKE_SIZEOF_VOID_P EQUAL 8 ) 24 | ${CMAKE_CURRENT_LIST_DIR}/../external/AntTweakBar/lib/x64 25 | ELSE() 26 | ${CMAKE_CURRENT_LIST_DIR}/../external/AntTweakBar/lib/win32 27 | ENDIF() 28 | # ${CMAKE_CURRENT_LIST_DIR}/../external/AntTweakBar/lib/x64 29 | $ENV{ANTTWEAKBAR_ROOT}/lib 30 | DOC "The AntTweakBar library") 31 | else() 32 | FIND_PATH(ANTTWEAKBAR_INCLUDE_DIR AntTweakBar.h PATHS 33 | ${CMAKE_CURRENT_LIST_DIR}/../external/AntTweakBar/include/ 34 | /usr/local/include 35 | /usr/X11/include 36 | /usr/include 37 | NO_DEFAULT_PATH) 38 | 39 | FIND_LIBRARY( ANTTWEAKBAR_LIBRARY AntTweakBar PATHS 40 | /usr/local/lib 41 | /usr/X11 42 | /usr 43 | ${CMAKE_CURRENT_LIST_DIR}/../external/AntTweakBar/lib/x11 44 | PATH_SUFFIXES a lib64 lib dylib NO_DEFAULT_PATH) 45 | endif() 46 | 47 | if(ANTTWEAKBAR_INCLUDE_DIR AND ANTTWEAKBAR_LIBRARY) 48 | message(STATUS "Found ANTTWEAKBAR: ${ANTTWEAKBAR_LIBRARY}") 49 | set(ANTTWEAKBAR_FOUND TRUE) 50 | endif() 51 | 52 | #message(STATUS "ANTTWEAKBAR_INCLUDE_DIR: ${ANTTWEAKBAR_INCLUDE_DIR}") 53 | #message(STATUS "ANTTWEAKBAR_LIBRARY: ${ANTTWEAKBAR_LIBRARY}") 54 | -------------------------------------------------------------------------------- /cmake/FindGLFW.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 Pixar 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "Apache License") 5 | # with the following modification; you may not use this file except in 6 | # compliance with the Apache License and the following modification to it: 7 | # Section 6. Trademarks. is deleted and replaced with: 8 | # 9 | # 6. Trademarks. This License does not grant permission to use the trade 10 | # names, trademarks, service marks, or product names of the Licensor 11 | # and its affiliates, except as required to comply with Section 4(c) of 12 | # the License and to reproduce the content of the NOTICE file. 13 | # 14 | # You may obtain a copy of the Apache License at 15 | # 16 | # http://www.apache.org/licenses/LICENSE-2.0 17 | # 18 | # Unless required by applicable law or agreed to in writing, software 19 | # distributed under the Apache License with the above modification is 20 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 | # KIND, either express or implied. See the Apache License for the specific 22 | # language governing permissions and limitations under the Apache License. 23 | # 24 | 25 | # Try to find GLFW library and include path. 26 | # Once done this will define 27 | # 28 | # GLFW_FOUND 29 | # GLFW_INCLUDE_DIR 30 | # GLFW_LIBRARIES 31 | # 32 | 33 | find_path( GLFW_INCLUDE_DIR 34 | NAMES 35 | GLFW/glfw3.h 36 | HINTS 37 | "${GLFW_LOCATION}/include" 38 | "$ENV{GLFW_LOCATION}/include" 39 | PATHS 40 | "$ENV{PROGRAMFILES}/GLFW/include" 41 | "${OPENGL_INCLUDE_DIR}" 42 | /usr/openwin/share/include 43 | /usr/openwin/include 44 | /usr/X11R6/include 45 | /usr/include/X11 46 | /opt/graphics/OpenGL/include 47 | /opt/graphics/OpenGL/contrib/libglfw 48 | /usr/local/include 49 | /usr/include/GL 50 | /usr/include 51 | DOC 52 | "The directory where GLFW/glfw3.h resides" 53 | ) 54 | 55 | # 56 | # XXX: Do we still need to search for GL/glfw.h? 57 | # 58 | find_path( GLFW_INCLUDE_DIR 59 | NAMES 60 | GL/glfw.h 61 | HINTS 62 | "${GLFW_LOCATION}/include" 63 | "$ENV{GLFW_LOCATION}/include" 64 | PATHS 65 | "$ENV{PROGRAMFILES}/GLFW/include" 66 | "${OPENGL_INCLUDE_DIR}" 67 | /usr/openwin/share/include 68 | /usr/openwin/include 69 | /usr/X11R6/include 70 | /usr/include/X11 71 | /opt/graphics/OpenGL/include 72 | /opt/graphics/OpenGL/contrib/libglfw 73 | /usr/local/include 74 | /usr/include/GL 75 | /usr/include 76 | DOC 77 | "The directory where GL/glfw.h resides" 78 | ) 79 | 80 | if (WIN32) 81 | if(CYGWIN) 82 | find_library( GLFW_glfw_LIBRARY 83 | NAMES 84 | glfw32 85 | HINTS 86 | "${GLFW_LOCATION}/lib" 87 | "${GLFW_LOCATION}/lib/x64" 88 | "$ENV{GLFW_LOCATION}/lib" 89 | PATHS 90 | "${OPENGL_LIBRARY_DIR}" 91 | /usr/lib 92 | /usr/lib/w32api 93 | /usr/local/lib 94 | /usr/X11R6/lib 95 | DOC 96 | "The GLFW library" 97 | ) 98 | else() 99 | find_library( GLFW_glfw_LIBRARY 100 | NAMES 101 | glfw32 102 | glfw32s 103 | glfw 104 | glfw3 105 | HINTS 106 | "${GLFW_LOCATION}/lib" 107 | "${GLFW_LOCATION}/lib/x64" 108 | "${GLFW_LOCATION}/lib-msvc110" 109 | "${GLFW_LOCATION}/lib-vc2012" 110 | "$ENV{GLFW_LOCATION}/lib" 111 | "$ENV{GLFW_LOCATION}/lib/x64" 112 | "$ENV{GLFW_LOCATION}/lib-msvc110" 113 | "$ENV{GLFW_LOCATION}/lib-vc2012" 114 | PATHS 115 | "$ENV{PROGRAMFILES}/GLFW/lib" 116 | "${OPENGL_LIBRARY_DIR}" 117 | DOC 118 | "The GLFW library" 119 | ) 120 | endif() 121 | else () 122 | if (APPLE) 123 | find_library( GLFW_glfw_LIBRARY glfw 124 | NAMES 125 | glfw 126 | glfw3 127 | HINTS 128 | "${GLFW_LOCATION}/lib" 129 | "${GLFW_LOCATION}/lib/cocoa" 130 | "$ENV{GLFW_LOCATION}/lib" 131 | "$ENV{GLFW_LOCATION}/lib/cocoa" 132 | PATHS 133 | /usr/local/lib 134 | ) 135 | set(GLFW_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX") 136 | set(GLFW_corevideo_LIBRARY "-framework CoreVideo" CACHE STRING "CoreVideo framework for OSX") 137 | set(GLFW_iokit_LIBRARY "-framework IOKit" CACHE STRING "IOKit framework for OSX") 138 | else () 139 | # (*)NIX 140 | 141 | find_package(Threads REQUIRED) 142 | 143 | find_package(X11 REQUIRED) 144 | 145 | if(NOT X11_Xrandr_FOUND) 146 | message(FATAL_ERROR "Xrandr library not found - required for GLFW") 147 | endif() 148 | 149 | if(NOT X11_xf86vmode_FOUND) 150 | message(FATAL_ERROR "xf86vmode library not found - required for GLFW") 151 | endif() 152 | 153 | if(NOT X11_Xcursor_FOUND) 154 | message(FATAL_ERROR "Xcursor library not found - required for GLFW") 155 | endif() 156 | 157 | if(NOT X11_Xinerama_FOUND) 158 | message(FATAL_ERROR "Xinerama library not found - required for GLFW") 159 | endif() 160 | 161 | list(APPEND GLFW_x11_LIBRARY "${X11_Xrandr_LIB}" "${X11_Xxf86vm_LIB}" "${X11_Xcursor_LIB}" "${X11_Xinerama_LIB}" "${CMAKE_THREAD_LIBS_INIT}" -lrt -lXi) 162 | 163 | find_library( GLFW_glfw_LIBRARY 164 | NAMES 165 | glfw 166 | glfw3 167 | HINTS 168 | "${GLFW_LOCATION}/lib" 169 | "$ENV{GLFW_LOCATION}/lib" 170 | "${GLFW_LOCATION}/lib/x11" 171 | "$ENV{GLFW_LOCATION}/lib/x11" 172 | PATHS 173 | /usr/lib64 174 | /usr/lib 175 | /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE} 176 | /usr/local/lib64 177 | /usr/local/lib 178 | /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE} 179 | /usr/openwin/lib 180 | /usr/X11R6/lib 181 | DOC 182 | "The GLFW library" 183 | ) 184 | endif (APPLE) 185 | endif (WIN32) 186 | 187 | set( GLFW_FOUND "NO" ) 188 | 189 | if(GLFW_INCLUDE_DIR) 190 | 191 | if(GLFW_glfw_LIBRARY) 192 | set( GLFW_LIBRARIES "${GLFW_glfw_LIBRARY}" 193 | "${GLFW_x11_LIBRARY}" 194 | "${GLFW_cocoa_LIBRARY}" 195 | "${GLFW_iokit_LIBRARY}" 196 | "${GLFW_corevideo_LIBRARY}" ) 197 | set( GLFW_FOUND "YES" ) 198 | set (GLFW_LIBRARY "${GLFW_LIBRARIES}") 199 | set (GLFW_INCLUDE_PATH "${GLFW_INCLUDE_DIR}") 200 | endif(GLFW_glfw_LIBRARY) 201 | 202 | 203 | # Tease the GLFW_VERSION numbers from the lib headers 204 | function(parseVersion FILENAME VARNAME) 205 | 206 | set(PATTERN "^#define ${VARNAME}.*$") 207 | 208 | file(STRINGS "${GLFW_INCLUDE_DIR}/${FILENAME}" TMP REGEX ${PATTERN}) 209 | 210 | string(REGEX MATCHALL "[0-9]+" TMP ${TMP}) 211 | 212 | set(${VARNAME} ${TMP} PARENT_SCOPE) 213 | 214 | endfunction() 215 | 216 | 217 | if(EXISTS "${GLFW_INCLUDE_DIR}/GL/glfw.h") 218 | 219 | parseVersion(GL/glfw.h GLFW_VERSION_MAJOR) 220 | parseVersion(GL/glfw.h GLFW_VERSION_MINOR) 221 | parseVersion(GL/glfw.h GLFW_VERSION_REVISION) 222 | 223 | elseif(EXISTS "${GLFW_INCLUDE_DIR}/GLFW/glfw3.h") 224 | 225 | parseVersion(GLFW/glfw3.h GLFW_VERSION_MAJOR) 226 | parseVersion(GLFW/glfw3.h GLFW_VERSION_MINOR) 227 | parseVersion(GLFW/glfw3.h GLFW_VERSION_REVISION) 228 | 229 | endif() 230 | 231 | if(${GLFW_VERSION_MAJOR} OR ${GLFW_VERSION_MINOR} OR ${GLFW_VERSION_REVISION}) 232 | set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}.${GLFW_VERSION_REVISION}") 233 | set(GLFW_VERSION_STRING "${GLFW_VERSION}") 234 | mark_as_advanced(GLFW_VERSION) 235 | endif() 236 | 237 | endif(GLFW_INCLUDE_DIR) 238 | 239 | include(FindPackageHandleStandardArgs) 240 | 241 | find_package_handle_standard_args(GLFW 242 | REQUIRED_VARS 243 | GLFW_INCLUDE_DIR 244 | GLFW_LIBRARIES 245 | VERSION_VAR 246 | GLFW_VERSION 247 | ) 248 | 249 | mark_as_advanced( 250 | GLFW_INCLUDE_DIR 251 | GLFW_LIBRARIES 252 | GLFW_glfw_LIBRARY 253 | GLFW_cocoa_LIBRARY 254 | ) 255 | 256 | 257 | 258 | -------------------------------------------------------------------------------- /cmake/FindGLM.cmake: -------------------------------------------------------------------------------- 1 | # FindGLM - attempts to locate the glm matrix/vector library. 2 | # 3 | # This module defines the following variables (on success): 4 | # GLM_INCLUDE_DIRS - where to find glm/glm.hpp 5 | # GLM_FOUND - if the library was successfully located 6 | # 7 | # It is trying a few standard installation locations, but can be customized 8 | # with the following variables: 9 | # GLM_ROOT_DIR - root directory of a glm installation 10 | # Headers are expected to be found in either: 11 | # /glm/glm.hpp OR 12 | # /include/glm/glm.hpp 13 | # This variable can either be a cmake or environment 14 | # variable. Note however that changing the value 15 | # of the environment varible will NOT result in 16 | # re-running the header search and therefore NOT 17 | # adjust the variables set by this module. 18 | 19 | #============================================================================= 20 | # Copyright 2012 Carsten Neumann 21 | # 22 | # Distributed under the OSI-approved BSD License (the "License"); 23 | # see accompanying file Copyright.txt for details. 24 | # 25 | # This software is distributed WITHOUT ANY WARRANTY; without even the 26 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | # See the License for more information. 28 | #============================================================================= 29 | # (To distribute this file outside of CMake, substitute the full 30 | # License text for the above reference.) 31 | 32 | # default search dirs 33 | SET(_glm_HEADER_SEARCH_DIRS 34 | "/usr/include" 35 | "/usr/local/include") 36 | 37 | # check environment variable 38 | SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}") 39 | 40 | IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) 41 | SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}") 42 | ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) 43 | 44 | # put user specified location at beginning of search 45 | IF(GLM_ROOT_DIR) 46 | SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}" 47 | "${GLM_ROOT_DIR}/include" 48 | ${_glm_HEADER_SEARCH_DIRS}) 49 | ENDIF(GLM_ROOT_DIR) 50 | 51 | # locate header 52 | FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp" 53 | PATHS ${_glm_HEADER_SEARCH_DIRS}) 54 | 55 | INCLUDE(FindPackageHandleStandardArgs) 56 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG 57 | GLM_INCLUDE_DIR) 58 | 59 | IF(GLM_FOUND) 60 | SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") 61 | 62 | MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}") 63 | ENDIF(GLM_FOUND) 64 | -------------------------------------------------------------------------------- /cmake/FindLibNoise.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Locate libnoise. 3 | # This module defines 4 | # LIBNOISE_LIBRARIES 5 | # LIBNOISE_FOUND, if false, do not try to link to libnoise 6 | # LIBNOISE_INCLUDE_DIR, where to find the headers 7 | 8 | FIND_PATH(LIBNOISE_INCLUDE_DIR noise.h 9 | $ENV{LIBNOISE_DIR} 10 | NO_DEFAULT_PATH 11 | PATH_SUFFIXES include 12 | ) 13 | 14 | FIND_PATH(LIBNOISE_INCLUDE_DIR "noise.h" 15 | PATHS 16 | ${CMAKE_SOURCE_DIR}/include 17 | ~/Library/Frameworks/noise/Headers 18 | /Library/Frameworks/noise/Headers 19 | /usr/local/include/noise 20 | /usr/local/include/noise 21 | /usr/local/include 22 | /usr/include/libnoise 23 | /usr/include/noise 24 | /usr/include/noise 25 | /usr/include 26 | /sw/include/noise 27 | /sw/include/noise 28 | /sw/include # Fink 29 | /opt/local/include/noise 30 | /opt/local/include/noise 31 | /opt/local/include # DarwinPorts 32 | /opt/csw/include/noise 33 | /opt/csw/include/noise 34 | /opt/csw/include # Blastwave 35 | /opt/include/noise 36 | /opt/include/noise 37 | /opt/include 38 | PATH_SUFFIXES noise 39 | ) 40 | 41 | FIND_LIBRARY(LIBNOISE_LIBRARIES 42 | NAMES libnoise noise libnoiseutils noiseutils 43 | PATHS 44 | $ENV{LIBNOISE_DIR} 45 | NO_DEFAULT_PATH 46 | PATH_SUFFIXES lib64 lib so 47 | ) 48 | 49 | FIND_LIBRARY(LIBNOISE_LIBRARIES 50 | NAMES libnoise noise libnoiseutils noiseutils 51 | PATHS 52 | ${CMAKE_SOURCE_DIR}/lib 53 | ~/Library/Frameworks 54 | /Library/Frameworks 55 | /usr/local 56 | /usr 57 | /sw 58 | /opt/local 59 | /opt/csw 60 | /opt 61 | /usr/freeware 62 | PATH_SUFFIXES lib64 lib so 63 | ) 64 | 65 | message("LIBNOISE_INCLUDE_DIR: ${LIBNOISE_INCLUDE_DIR}") 66 | 67 | SET(LIBNOISE_FOUND "NO") 68 | IF(LIBNOISE_LIBRARY AND LIBNOISE_INCLUDE_DIR) 69 | SET(LIBNOISE_FOUND "YES") 70 | ENDIF(LIBNOISE_LIBRARY AND LIBNOISE_INCLUDE_DIR) 71 | 72 | -------------------------------------------------------------------------------- /include/3DRender/Camera.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: camaraHandler.h 3 | * Author: tg 4 | * 5 | * Created on 19. Februar 2015, 08:24 6 | */ 7 | 8 | #ifndef CAMARAHANDLER_H 9 | #define CAMARAHANDLER_H 10 | #define GLM_FORCE_RADIANS 11 | #include 12 | #include 13 | 14 | 15 | class Camera 16 | { 17 | public: 18 | Camera() = default; 19 | 20 | void SetCamera_look_at(glm::vec3 camera_look_at); 21 | 22 | void SetCamera_position(glm::vec3 camera_position); 23 | 24 | void SetMove_camera(bool move_camera); 25 | 26 | void SetField_of_view(double field_of_view); 27 | 28 | void SetAspect(double aspect); 29 | 30 | void Update(uint64_t time); 31 | 32 | void SetPitch(double degrees); 33 | 34 | void SetRoll(double degrees); 35 | 36 | void SetYaw(double degrees); 37 | 38 | void MoveX(double distance); 39 | 40 | void MoveY(double distance); 41 | 42 | void MoveZ(double distance); 43 | 44 | void MoveHead(double x, double y); 45 | 46 | void setViewport(int x, int y, int width, int height); 47 | 48 | void setClipping(double near_clip, double far_clip); 49 | 50 | glm::mat4 getProjection(); 51 | 52 | glm::mat4 getView(); 53 | 54 | glm::vec2 getViewPort(); 55 | 56 | void loadViewPort(); 57 | 58 | private: 59 | 60 | uint32_t viewport_x, viewport_y; 61 | uint32_t window_width, window_heigth; 62 | 63 | double aspect, field_of_view, near_clip,far_clip; 64 | 65 | float scale, roll, pitch, yaw; 66 | float max_pitch = 25, max_roll = 25, max_yaw= 25; 67 | 68 | bool move_camera; 69 | 70 | glm::vec3 camera_position, camera_position_delta; 71 | glm::vec3 camera_look_at; 72 | glm::vec3 camera_direction; 73 | 74 | glm::vec3 camera_up {0,-1,0}; 75 | glm::quat rot_quat; 76 | glm::vec3 last_position; 77 | 78 | glm::mat4 projection; 79 | }; 80 | 81 | #endif /* CAMARAHANDLER_H */ 82 | 83 | -------------------------------------------------------------------------------- /include/3DRender/Light.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: LightManager.h 3 | * Author: tg 4 | * 5 | * Created on 23. April 2015, 01:53 6 | */ 7 | 8 | #ifndef LIGHTMANAGER_H 9 | #define LIGHTMANAGER_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | struct Light_Data 18 | { 19 | typedef glm::vec3 position; 20 | typedef uint32_t LightID; 21 | LightID id; 22 | glm::vec3 Color; 23 | position Position; 24 | 25 | }; 26 | 27 | class Light 28 | { 29 | public: 30 | 31 | /** 32 | * Add light into szene 33 | * @param id - id of the Light 34 | * @param Color - color of the Light 35 | * @param Position - Position of the Light 36 | */ 37 | Light(Light_Data::LightID id,glm::vec3 Color, Light_Data::position Position); 38 | 39 | 40 | /** 41 | * Change Color of the light 42 | * @param id - id of the light 43 | * @param Color - the new color 44 | */ 45 | void changeColor(const glm::vec3& Color); 46 | 47 | /** 48 | * Change Position of the Light 49 | * @param id - id of the light 50 | * @param Position - new Position 51 | */ 52 | void changePosition(const Light_Data::position& Position); 53 | 54 | /** 55 | * Get current Data of the light 56 | * @return 57 | */ 58 | Light_Data& getCurrentData() ; 59 | 60 | private: 61 | 62 | 63 | Light_Data currentData; ///< vector of all lights 64 | 65 | }; 66 | #endif -------------------------------------------------------------------------------- /include/3DRender/Shadows.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: Shadows.h 9 | * Author: tg 10 | * 11 | * Created on 2. November 2016, 11:51 12 | */ 13 | 14 | #ifndef SHADOWS_H 15 | #define SHADOWS_H 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "ShaderLoader.h" 24 | #include "plane.h" 25 | 26 | #include 27 | 28 | 29 | class Shadows 30 | { 31 | public: 32 | Shadows(std::shared_ptr terrainPlain ); 33 | 34 | void init(const std::string& shaderPath); 35 | void exit(); 36 | void render(const glm::vec3& lightPosition); 37 | 38 | const glm::mat4 getBiasedDepthMVP(); 39 | 40 | GLuint getDepthTexture() const; 41 | 42 | 43 | 44 | private: 45 | GLuint shaderID, depthFBO, depthTexture; 46 | glm::mat4 depthMVP; 47 | std::shared_ptr terrainPlain; 48 | 49 | }; 50 | 51 | #endif /* SHADOWS_H */ 52 | 53 | -------------------------------------------------------------------------------- /include/3DRender/WaterRender.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: WaterRender.h 9 | * Author: tg 10 | * 11 | * Created on 2. November 2016, 11:49 12 | */ 13 | 14 | #ifndef WATERRENDER_H 15 | #define WATERRENDER_H 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "RendToTex.h" 26 | #include "TextureLoader.h" 27 | #include "ShaderLoader.h" 28 | #include "Camera.h" 29 | #include "Shadows.h" 30 | #include "Light.h" 31 | 32 | class WaterRender 33 | { 34 | public: 35 | WaterRender(std::shared_ptr terrainPlain,const glm::ivec2& textureDimension); 36 | 37 | void init(const std::string& shaderPath,const std::string& normalTexturePath, TwBar* Bar3d); 38 | 39 | void render(std::shared_ptr camera, std::shared_ptr shadows, std::shared_ptr light, const float time); 40 | 41 | void exit(); 42 | 43 | private: 44 | GLuint waterProgram, waterNormals; 45 | std::shared_ptr terrainPlain; 46 | std::unique_ptr waterFlows; 47 | glm::ivec2 textureDimension; 48 | float movementTime = 0.f; 49 | 50 | }; 51 | 52 | #endif /* WATERRENDER_H */ 53 | 54 | -------------------------------------------------------------------------------- /include/3DRender/display3D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: display3D.h 9 | * Author: tg 10 | * 11 | * Created on 3. November 2016, 10:51 12 | */ 13 | 14 | #ifndef DISPLAY3D_H 15 | #define DISPLAY3D_H 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "TextureLoader.h" 25 | #include "ShaderLoader.h" 26 | #include "Camera.h" 27 | #include "landscapeRender.h" 28 | #include "WaterRender.h" 29 | #include "Shadows.h" 30 | #include "Light.h" 31 | #include "plane.h" 32 | #include "inputHandler.h" 33 | #include "simulation.h" 34 | #include 35 | #include 36 | 37 | class display3D 38 | { 39 | public: 40 | display3D(const uint32_t windowLenght,const uint32_t windowHeight, 41 | const uint32_t textureLenght,const uint32_t textureHeight); 42 | 43 | void init(); 44 | 45 | void render(float frameTime,simulation* sim); 46 | 47 | void handleCameraInput(GLFWwindow* window); 48 | bool isRender3D() const; 49 | 50 | private: 51 | 52 | void initCamera(); 53 | 54 | std::shared_ptr landscaperender; 55 | std::shared_ptr camera; 56 | std::shared_ptr waterRender; 57 | std::shared_ptr shadows; 58 | std::shared_ptr light; 59 | std::shared_ptr terrainPlain; 60 | std::chrono::time_point buttonWait; 61 | bool render3D = true; 62 | glm::dvec2 prevMousePosition = glm::dvec2(0.0); 63 | glm::ivec2 windowDimension; 64 | glm::ivec2 textureDimension; 65 | GLuint vao; 66 | TwBar* Bar3D; 67 | }; 68 | 69 | #endif /* DISPLAY3D_H */ 70 | 71 | -------------------------------------------------------------------------------- /include/3DRender/landscapeRender.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: landscapeRender.h 9 | * Author: tg 10 | * 11 | * Created on 2. November 2016, 11:50 12 | */ 13 | 14 | #ifndef LANDSCAPERENDER_H 15 | #define LANDSCAPERENDER_H 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "TextureLoader.h" 25 | #include "ShaderLoader.h" 26 | #include 27 | #include "plane.h" 28 | #include "Shadows.h" 29 | #include "Camera.h" 30 | #include "Light.h" 31 | 32 | class landscapeRender 33 | { 34 | public: 35 | landscapeRender(std::shared_ptr terrainPlain); 36 | 37 | void init(const std::string& shaderPath); 38 | 39 | void render(std::shared_ptr camera, std::shared_ptr shadow,std::shared_ptr light,const uint32_t currentDisplay); 40 | 41 | void exit(); 42 | 43 | private: 44 | std::shared_ptr terrainPlain; 45 | GLuint displayProgram; 46 | 47 | }; 48 | 49 | #endif /* LANDSCAPERENDER_H */ 50 | 51 | -------------------------------------------------------------------------------- /include/3DRender/plane.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: plane.h 9 | * Author: tg 10 | * 11 | * Created on 4. November 2016, 10:06 12 | */ 13 | 14 | #ifndef PLANE_H 15 | #define PLANE_H 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | class plane { 24 | public: 25 | plane(glm::ivec2 planeDimension, glm::vec3 position, glm::vec3 rotation, glm::vec3 scale); 26 | 27 | uint32_t getPlaneVertices() const; 28 | 29 | glm::ivec2 getPlaneDimension() const; 30 | 31 | GLuint getVao_plane() const; 32 | 33 | glm::fmat4 getModel_matrix() const; 34 | 35 | glm::vec3 getScale() const; 36 | 37 | void setScale(const glm::vec3 scale); 38 | 39 | 40 | 41 | 42 | private: 43 | 44 | void generatePlane(int width, int height); 45 | 46 | glm::fmat4 model_matrix; 47 | glm::mat4 scaleMat; 48 | glm::vec3 scaleVec; 49 | 50 | GLuint vbo_plane,vao_plane, vbo_indexbuffer; 51 | glm::ivec2 planeDimension; 52 | uint32_t planeVertices; 53 | 54 | 55 | }; 56 | 57 | #endif /* PLANE_H */ 58 | 59 | -------------------------------------------------------------------------------- /include/RendToTex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: RendToTex.h 9 | * Author: tg 10 | * 11 | * Created on 15. Februar 2016, 11:02 12 | */ 13 | 14 | #ifndef RENDTOTEX_H 15 | #define RENDTOTEX_H 16 | 17 | 18 | #include "GL3W/gl3w.h" 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include "ShaderLoader.h" 25 | #include "TextureLoader.h" 26 | 27 | class RendToTex 28 | { 29 | public: 30 | RendToTex() = default; 31 | RendToTex(const std::string& shaderPath, unsigned int textureWidth, unsigned int textureHeight, const GLuint colorFormat,const GLuint interpolation = GL_LINEAR); 32 | 33 | void setUniforms(const std::vector>& uniforms); 34 | 35 | 36 | void exit(); 37 | 38 | void update(); 39 | 40 | GLuint getSourceTexture(); 41 | 42 | GLuint getDestinationTexture(); 43 | 44 | void generateParameterBar(TwBar *bar,const std::string& subSectionName,const std::vector options); 45 | 46 | void generateActivationBar(TwBar *bar,const std::string& subSectionName); 47 | 48 | 49 | void swapTexture(); 50 | 51 | void setTexture(const float* data); 52 | 53 | void setParameterValue(const std::string& parameter, float value); 54 | 55 | float getParameterValue(const std::string& parameter); 56 | 57 | float* getTexture(); 58 | 59 | void reset(); 60 | 61 | ILuint prepareExport(); 62 | void setEnable(GLboolean enable); 63 | 64 | private: 65 | std::array textureBuffer; 66 | std::vector> v_Uniforms; 67 | std::array fboBuffer; 68 | unsigned int sourceBuffer = 0; 69 | unsigned int destinationBuffer = 1; 70 | unsigned int textureWidth; 71 | unsigned int textureHeight; 72 | GLuint colorFormat; 73 | GLuint shaderID; 74 | GLuint pixelBuffer; 75 | GLboolean enable; 76 | 77 | 78 | 79 | 80 | }; 81 | 82 | #endif /* RENDTOTEX_H */ 83 | 84 | -------------------------------------------------------------------------------- /include/ShaderLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: ShaderLoader.h 9 | * Author: tartg 10 | * 11 | * Created on 18. Oktober 2016, 12:39 12 | */ 13 | 14 | #ifndef SHADERLOADER_H 15 | #define SHADERLOADER_H 16 | 17 | #include "../3rdParty/GL3W/gl3w.h" 18 | #include "../3rdParty/GL3W/glcorearb.h" 19 | #include 20 | #include 21 | 22 | class ShaderLoader { 23 | public: 24 | 25 | /** 26 | * generate a new openGL shader program 27 | * @param pathName - path and name of the shaders 28 | * @return Id of the shader program 29 | */ 30 | static GLuint generateProgram(const std::string& pathName); 31 | private: 32 | 33 | /** 34 | * load Shaders for file 35 | * @param filename - name of the shader file 36 | * @param shader_type - type of the shader file 37 | * @return ID of the shader pipeline step 38 | */ 39 | static GLuint loadShaders(const std::string filename, GLenum shader_type); 40 | 41 | /** 42 | * Attach shader to program 43 | * @param program - program ID 44 | * @param filename - filename of the shader 45 | * @param shader_type - typ of the shader 46 | */ 47 | static void attachShader(GLuint& program, std::string filename,GLenum shader_type); 48 | 49 | 50 | 51 | 52 | 53 | }; 54 | 55 | #endif /* SHADERLOADER_H */ 56 | 57 | -------------------------------------------------------------------------------- /include/TextureLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: TextureLoader.h 9 | * Author: tg 10 | * 11 | * Created on 14. Januar 2016, 12:50 12 | */ 13 | 14 | #ifndef TEXTURELOADER_H 15 | #define TEXTURELOADER_H 16 | 17 | #include "../3rdParty/GL3W/gl3w.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class TextureLoader { 25 | public: 26 | 27 | static GLuint load2DTexture(const std::string& fileName, const GLuint OUTcolorFormat, const GLuint OUTvalueFormat, 28 | const ILint INcolorFormat, const ILint INvalueFormat); 29 | 30 | static ILuint load2DTexture(const std::string& fileName, const ILint INcolorFormat, const ILint INvalueFormat); 31 | 32 | static GLuint loadEmpty2DTexture(const int width, const int height, const GLuint OUTcolorFormat, const GLuint OUTvalueFormat, const GLuint interplolation = GL_NEAREST); 33 | 34 | static GLuint load2DTextureArray(const std::vector& fileNames, const GLuint OUTcolorFormat, const GLuint OUTvalueFormat, 35 | const ILint INcolorFormat, const ILint INvalueFormat); 36 | 37 | static GLuint generateNoiseTexture(const int width, const int height,const int seed, const float roughness,const int turbulence); 38 | 39 | static ILuint SaveTexture(ILuint Width, ILuint Height, std::string FileName, ILuint Texture); 40 | private: 41 | 42 | }; 43 | 44 | #endif /* TEXTURELOADER_H */ 45 | 46 | -------------------------------------------------------------------------------- /include/display2D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: display2D.h 9 | * Author: tg 10 | * 11 | * Created on 27. Oktober 2016, 10:55 12 | */ 13 | 14 | #ifndef DISPLAY2D_H 15 | #define DISPLAY2D_H 16 | 17 | #include "GL3W/gl3w.h" 18 | #include 19 | #include 20 | #include "ShaderLoader.h" 21 | 22 | 23 | class display2D { 24 | public: 25 | display2D(const std::string& shaderPath); 26 | 27 | void render(std::array windowDimensions, unsigned int currentSelection, GLuint textureID); 28 | 29 | void exit(); 30 | private: 31 | GLuint displayProgram, vao; 32 | 33 | }; 34 | 35 | #endif /* DISPLAY2D_H */ 36 | 37 | -------------------------------------------------------------------------------- /include/inputHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: inputHandler.h 9 | * Author: tartg 10 | * 11 | * Created on 18. Oktober 2016, 10:35 12 | */ 13 | 14 | #ifndef INPUTHANDLER_H 15 | #define INPUTHANDLER_H 16 | 17 | #include 18 | #include 19 | 20 | 21 | /* 22 | * Simple input Handler 23 | */ 24 | class inputHandler { 25 | public: 26 | 27 | /** 28 | * Constructor for input Handling 29 | */ 30 | inputHandler(GLFWwindow* window); 31 | 32 | /** 33 | * Generate a new anttweak bar 34 | * @param description - Name of the bar 35 | * @return referenze to the Bar. Destruction is handled in exit. 36 | */ 37 | static TwBar* createNewBar(const std::string& name, const std::string& description); 38 | 39 | /** 40 | * update all anttweak bars 41 | */ 42 | void update(); 43 | 44 | /** 45 | * Close input handling 46 | */ 47 | void exit(); 48 | 49 | 50 | private: 51 | 52 | GLFWwindow* window; //reference to the window 53 | float scorllpos; 54 | }; 55 | 56 | #endif /* INPUTHANDLER_H */ 57 | 58 | -------------------------------------------------------------------------------- /include/simpleRender.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: simpleRender.h 9 | * Author: tartg 10 | * 11 | * Created on 18. Oktober 2016, 10:08 12 | */ 13 | 14 | #ifndef SIMPLERENDER_H 15 | #define SIMPLERENDER_H 16 | 17 | #include "GL3W/gl3w.h" 18 | #include 19 | #include 20 | #include 21 | 22 | /* 23 | * Class to handle simple render stuff 24 | */ 25 | class simpleRender 26 | { 27 | public: 28 | /** 29 | * Constructor for simpleRender 30 | * @param windowLength - lenght of the window 31 | * @param windowHeight - height of the window 32 | * @param windowTitle - titel of the window 33 | */ 34 | simpleRender(uint32_t windowLength, uint32_t windowHeight,std::string windowTitle); 35 | 36 | /** 37 | * initialize GLFW, GL3W, OpenGL context and window 38 | */ 39 | uint32_t init(); 40 | 41 | /** 42 | * clear content of the window 43 | */ 44 | void clearWindow(); 45 | 46 | /** 47 | * swap buffers and poll events 48 | */ 49 | void render(); 50 | 51 | /** 52 | * close OpenGL context and window 53 | */ 54 | void exit(); 55 | 56 | /** 57 | * get Pointer to the window 58 | */ 59 | GLFWwindow* getWindow() const; 60 | 61 | 62 | 63 | 64 | private: 65 | uint32_t windowHeight,windowLength; //window dimensions 66 | std::string windowTitle; //window title 67 | GLFWwindow* window; //window refrence 68 | }; 69 | 70 | #endif /* SIMPLERENDER_H */ 71 | 72 | -------------------------------------------------------------------------------- /include/simulation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: simulation.h 9 | * Author: tg 10 | * 11 | * Created on 27. Oktober 2016, 10:54 12 | */ 13 | 14 | #ifndef SIMULATION_H 15 | #define SIMULATION_H 16 | 17 | #include "GL3W/gl3w.h" 18 | #include 19 | #include "inputHandler.h" 20 | #include "RendToTex.h" 21 | #include 22 | #include 23 | #include "RTplatec/include/lithosphere.hpp" 24 | class simulation 25 | { 26 | public: 27 | enum DataType 28 | { 29 | ROCK = 0, 30 | SOIL = 1, 31 | WATER = 2, 32 | TEMP = 3, 33 | MOIST = 4, 34 | WIND = 5, 35 | ICE = 6, 36 | CLIMAT = 7, 37 | render3D = 8 38 | }; 39 | simulation(unsigned int texureWidth, unsigned int textureHeight); 40 | 41 | void init(); 42 | 43 | void initLithosphere( float sea_level, float _folding_ratio, uint32_t aggr_ratio_abs, 44 | float aggr_ratio_rel, uint32_t _max_plates, float terrainNoiseRoughness); 45 | 46 | GLuint getTextureID(const simulation::DataType type); 47 | 48 | void update(); 49 | 50 | void exit(); 51 | 52 | void restart(); 53 | 54 | void newWorld(); 55 | DataType getCurrentDisplay() const; 56 | 57 | void setTexturesBindings(); 58 | 59 | void unsetTexturesBindings(); 60 | private: 61 | 62 | void saveTextures(); 63 | 64 | void initGUIElements(); 65 | 66 | static constexpr int getDataTypeSize(){ return static_cast(DataType::CLIMAT); }; 67 | 68 | 69 | TwBar* parameterBar, *activationBar, *general ; 70 | std::vector v_texData; 71 | unsigned int textureWidth, textureHeight; 72 | GLuint vao, windNoiseID; 73 | std::unique_ptr ground; 74 | long lastSeed; 75 | DataType currentDisplay = CLIMAT; 76 | bool enable_tectonic = false; //bool for enabling/disabling tectonic 77 | float tectonicSeaLevel,terrainNoiseRoughness; 78 | float lastSeaLevel; 79 | bool pause = false; 80 | 81 | 82 | 83 | }; 84 | 85 | #endif /* SIMULATION_H */ 86 | 87 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | 2 | set -ex 3 | 4 | git submodule update --init --recursive 5 | scripts/installDependencies.sh 6 | mkdir build 7 | cd build 8 | cmake .. 9 | make all 10 | -------------------------------------------------------------------------------- /res/grass_normals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tarTG/RTWG/6cbf782c47c360dcf4bf5ca9b0d1b999d85dac38/res/grass_normals.png -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | set -ex 4 | 5 | build/src/rtwg -------------------------------------------------------------------------------- /screenshots/3DMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tarTG/RTWG/6cbf782c47c360dcf4bf5ca9b0d1b999d85dac38/screenshots/3DMap.png -------------------------------------------------------------------------------- /screenshots/Climat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tarTG/RTWG/6cbf782c47c360dcf4bf5ca9b0d1b999d85dac38/screenshots/Climat.png -------------------------------------------------------------------------------- /screenshots/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tarTG/RTWG/6cbf782c47c360dcf4bf5ca9b0d1b999d85dac38/screenshots/heightmap.png -------------------------------------------------------------------------------- /scripts/installDependencies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | if [[ 'lsb_release -ds' != "Ubuntu 16.04" ]] # glfw allready in the ubuntu 16.04 repository 5 | then 6 | add-apt-repository -y ppa:pyglfw/pyglfw && sudo apt-get update -qq 7 | fi 8 | 9 | apt-get install -y --no-install-recommends g++ libglu1-mesa-dev freeglut3-dev mesa-common-dev libglfw3-dev libxrandr-dev libxi-dev libxxf86vm-dev libxcursor1 libxcursor-dev libxinerama-dev libnoise-dev libglm-dev libdevil-dev 10 | 11 | #install anttweak bar 12 | mkdir anttweakbar 13 | cd anttweakbar 14 | wget 'https://sourceforge.net/projects/anttweakbar/files/AntTweakBar_116.zip' 15 | unzip AntTweakBar_116.zip 16 | cd AntTweakBar 17 | cd src 18 | make 19 | cd .. 20 | cd include 21 | cp AntTweakBar.h /usr/local/include 22 | cd .. 23 | cd lib 24 | cp libAntTweakBar.so /usr/local/lib/ 25 | cd .. 26 | cd .. 27 | cd .. 28 | 29 | -------------------------------------------------------------------------------- /src/3DRender/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( rtwg3D 2 | Camera.cpp 3 | Shadows.cpp 4 | WaterRender.cpp 5 | landscapeRender.cpp 6 | Light.cpp 7 | display3D.cpp 8 | plane.cpp 9 | ) 10 | 11 | 12 | 13 | SET(SHADER_PATH "${PROJECT_SOURCE_DIR}/Shader/") 14 | ADD_DEFINITIONS(-DSHADER_PATH="${SHADER_PATH}") 15 | SET(RESOURCES_PATH "${PROJECT_SOURCE_DIR}/res/") 16 | ADD_DEFINITIONS(-DRESOURCES_PATH="${RESOURCES_PATH}") -------------------------------------------------------------------------------- /src/3DRender/Camera.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: camaraHandler.cpp 3 | * Author: tg 4 | * 5 | * Created on 19. Februar 2015, 08:24 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "Camera.h" 13 | 14 | 15 | void Camera::Update(uint64_t time) 16 | { 17 | camera_direction = glm::normalize(camera_look_at - camera_position); 18 | 19 | glm::vec3 axis = glm::cross(camera_direction,camera_up); 20 | glm::quat pitch_quat = glm::angleAxis(pitch ,camera_up); 21 | glm::quat roll_quat = glm::angleAxis(roll ,axis); 22 | glm::quat temp = glm::cross(pitch_quat,roll_quat); 23 | temp = glm::normalize(temp); 24 | 25 | camera_direction = glm::rotate(temp,camera_direction); 26 | camera_position += camera_position_delta; 27 | camera_look_at = camera_position + camera_direction * 1.0f; 28 | camera_position_delta = glm::vec3(0.0); 29 | pitch *= 0.1; 30 | roll *= 0.1; 31 | } 32 | 33 | void Camera::SetPitch(double degrees) 34 | { 35 | if(degrees < -max_pitch) 36 | { 37 | degrees = -max_pitch; 38 | } 39 | else if(degrees > max_pitch) 40 | { 41 | degrees = max_pitch; 42 | } 43 | 44 | pitch += degrees; 45 | 46 | if(pitch > 360.0f) 47 | { 48 | pitch -= 360.0f; 49 | } 50 | else if(pitch < -360.0f) 51 | { 52 | pitch += 360.0f; 53 | } 54 | } 55 | 56 | void Camera::SetRoll(double degrees) 57 | { 58 | if(degrees < -max_roll) 59 | { 60 | degrees = -max_roll; 61 | } 62 | else if(degrees > max_roll) 63 | { 64 | degrees = max_roll; 65 | } 66 | 67 | roll += degrees; 68 | 69 | if(roll > 360.0f) 70 | { 71 | roll -= 360.0f; 72 | } 73 | else if(roll < -360.0f) 74 | { 75 | roll += 360.0f; 76 | } 77 | } 78 | 79 | void Camera::SetYaw(double degrees) 80 | { 81 | if(degrees < -max_yaw) 82 | { 83 | degrees = -max_yaw; 84 | } 85 | else if(degrees > max_yaw) 86 | { 87 | degrees = max_yaw; 88 | } 89 | 90 | yaw += degrees; 91 | 92 | if(yaw > 360.0f) 93 | { 94 | yaw -= 360.0f; 95 | } 96 | else if(yaw < -360.0f) 97 | { 98 | yaw += 360.0f; 99 | } 100 | } 101 | 102 | void Camera::MoveX(double distance) 103 | { 104 | camera_position_delta += glm::cross(camera_direction,camera_up) * (float)distance; 105 | 106 | } 107 | 108 | void Camera::MoveY(double distance) 109 | { 110 | camera_position_delta += camera_up * (float)distance; 111 | } 112 | 113 | void Camera::MoveZ(double distance) 114 | { 115 | camera_position_delta += camera_direction * (float)distance; 116 | } 117 | 118 | void Camera::MoveHead(double x, double y) 119 | { 120 | 121 | SetPitch(x); 122 | SetRoll(y); 123 | 124 | } 125 | 126 | void Camera::setViewport(int x, int y, int width, int height) 127 | { 128 | viewport_x = x; 129 | viewport_y = y; 130 | window_width = width; 131 | window_heigth = height; 132 | aspect = (double)width/ (double)height; 133 | projection = glm::perspective(field_of_view,aspect,near_clip,far_clip); 134 | } 135 | 136 | void Camera::setClipping(double near_clip, double far_clip) 137 | { 138 | this->near_clip = near_clip; 139 | this->far_clip = far_clip; 140 | projection = glm::perspective(field_of_view,aspect,near_clip,far_clip); 141 | } 142 | 143 | glm::mat4 Camera::getProjection() 144 | { 145 | return projection; 146 | } 147 | 148 | glm::mat4 Camera::getView() 149 | { 150 | return glm::lookAt(camera_look_at,camera_position,camera_up); 151 | } 152 | 153 | 154 | 155 | void Camera::loadViewPort() 156 | { 157 | glViewport(viewport_x,viewport_y,window_width,window_heigth); 158 | } 159 | 160 | 161 | void Camera::SetCamera_look_at(glm::vec3 camera_look_at) 162 | { 163 | this->camera_look_at = camera_look_at; 164 | } 165 | 166 | void Camera::SetCamera_position(glm::vec3 camera_position) 167 | { 168 | this->camera_position = camera_position; 169 | } 170 | 171 | void Camera::SetMove_camera(bool move_camera) 172 | { 173 | this->move_camera = move_camera; 174 | } 175 | 176 | void Camera::SetField_of_view(double field_of_view) 177 | { 178 | this->field_of_view = field_of_view; 179 | projection = glm::perspective(field_of_view,aspect,near_clip,far_clip); 180 | } 181 | 182 | void Camera::SetAspect(double aspect) { 183 | this->aspect = aspect; 184 | } 185 | 186 | glm::vec2 Camera::getViewPort() 187 | { 188 | return glm::vec2(viewport_x,viewport_y); 189 | } 190 | -------------------------------------------------------------------------------- /src/3DRender/Light.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: Light.cpp 9 | * Author: tg 10 | * 11 | * Created on 3. November 2016, 10:55 12 | */ 13 | 14 | #include "Light.h" 15 | 16 | Light::Light(Light_Data::LightID id, glm::vec3 Color, Light_Data::position Position) : 17 | currentData({id,Color,Position}) 18 | { 19 | } 20 | 21 | void Light::changeColor(const glm::vec3& Color) 22 | { 23 | currentData.Color = Color; 24 | } 25 | 26 | void Light::changePosition(const Light_Data::position& Position) 27 | { 28 | currentData.Position = Position; 29 | } 30 | 31 | Light_Data& Light::getCurrentData() 32 | { 33 | return currentData; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/3DRender/Shadows.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: Shadows.cpp 9 | * Author: tg 10 | * 11 | * Created on 2. November 2016, 11:51 12 | */ 13 | 14 | 15 | #include "Shadows.h" 16 | 17 | 18 | Shadows::Shadows(std::shared_ptr terrainPlain ) 19 | :terrainPlain(terrainPlain) 20 | { 21 | } 22 | 23 | void Shadows::init(const std::string& shaderPath) 24 | { 25 | glBindVertexArray(terrainPlain->getVao_plane()); 26 | 27 | shaderID = ShaderLoader::generateProgram(shaderPath); 28 | glGenFramebuffers(1, &depthFBO); 29 | glBindFramebuffer(GL_FRAMEBUFFER,depthFBO); 30 | 31 | glGenTextures(1,&depthTexture); 32 | glBindTexture(GL_TEXTURE_2D, depthTexture); 33 | glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, 1024,1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT,nullptr); 34 | 35 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //setup Opengl Texture 36 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 37 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); //setup Opengl Texture 38 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); 39 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_FUNC,GL_LEQUAL); //setup Opengl Texture 40 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_COMPARE_MODE,0x884E); 41 | 42 | glFramebufferTexture(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,depthTexture,0); 43 | glDrawBuffer(GL_NONE); 44 | 45 | 46 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 47 | 48 | glBindTexture(GL_TEXTURE_2D, 0); 49 | glBindVertexArray(0); 50 | } 51 | 52 | void Shadows::render(const glm::vec3& lightPosition) 53 | { 54 | glBindFramebuffer(GL_FRAMEBUFFER,depthFBO); 55 | glCullFace(GL_FRONT); 56 | 57 | glViewport(0,0,1024, 1024); 58 | 59 | glClear(GL_DEPTH_BUFFER_BIT); 60 | glUseProgram(shaderID); 61 | 62 | 63 | 64 | glUniform2iv(glGetUniformLocation(shaderID, "dimensions"),1,glm::value_ptr(terrainPlain->getPlaneDimension())); 65 | 66 | 67 | 68 | depthMVP = glm::ortho(-30.0f, 30.0f, -30.0f, 30.0f, -100.0f, 20000.0f) 69 | * glm::lookAt( lightPosition*glm::vec3(10),glm::vec3(terrainPlain->getPlaneDimension().x/2.0,5.0,terrainPlain->getPlaneDimension().y/2.0), glm::vec3(0,1,0)) 70 | * glm::mat4(1.0) ; 71 | glUniformMatrix4fv(glGetUniformLocation(shaderID,"depthMVP"), 1, GL_FALSE, 72 | glm::value_ptr(depthMVP)); 73 | glUniformMatrix4fv(glGetUniformLocation(shaderID, "model_matrix"),1,GL_FALSE,glm::value_ptr( terrainPlain->getModel_matrix())); 74 | 75 | glDrawElements(GL_PATCHES,terrainPlain->getPlaneVertices(), GL_UNSIGNED_INT, 0); 76 | glUseProgram(0); 77 | glBindFramebuffer(GL_FRAMEBUFFER,0); 78 | glClear( GL_DEPTH_BUFFER_BIT); 79 | 80 | 81 | glCullFace(GL_BACK); 82 | } 83 | 84 | const glm::mat4 Shadows::getBiasedDepthMVP() 85 | { 86 | glm::mat4 biasMatrix(0.5,0.0,0.0,0.0, 87 | 0.0,0.5,0.0,0.0, 88 | 0.0,0.0,0.5,0.0, 89 | 0.5,0.5,0.5,1.0); 90 | return biasMatrix*depthMVP; 91 | } 92 | 93 | GLuint Shadows::getDepthTexture() const 94 | { 95 | return depthTexture; 96 | } 97 | 98 | 99 | void Shadows::exit() 100 | { 101 | glDeleteFramebuffers(1,&depthFBO); 102 | glDeleteProgram(shaderID); 103 | glDeleteTextures(1,&depthTexture); 104 | } 105 | -------------------------------------------------------------------------------- /src/3DRender/WaterRender.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: WaterRender.cpp 9 | * Author: tg 10 | * 11 | * Created on 2. November 2016, 11:49 12 | */ 13 | 14 | 15 | #include 16 | 17 | #include "WaterRender.h" 18 | #include "plane.h" 19 | 20 | WaterRender::WaterRender(std::shared_ptr terrainPlain,const glm::ivec2& textureDimension) 21 | :terrainPlain(terrainPlain), textureDimension(textureDimension) 22 | { 23 | 24 | } 25 | 26 | 27 | void WaterRender::init(const std::string& shaderPath, const std::string& normalTexturePath, TwBar* Bar3d) 28 | { 29 | glBindVertexArray(terrainPlain->getVao_plane()); 30 | 31 | waterNormals = TextureLoader::load2DTexture(normalTexturePath,GL_RGB, GL_UNSIGNED_BYTE, 32 | IL_RGB,IL_UNSIGNED_BYTE); 33 | 34 | waterProgram = ShaderLoader::generateProgram(shaderPath); 35 | 36 | waterFlows = std::make_unique(std::string(SHADER_PATH ) + "display/3D/waterFlow",textureDimension.x,textureDimension.y,GL_RGB,GL_NEAREST); 37 | waterFlows->setUniforms({{3.0,"WaterSpeed"}}); 38 | waterFlows->generateParameterBar(Bar3d ,"",{"min=0.0 max = 10.0 step = 0.1"}); 39 | 40 | glBindVertexArray(0); 41 | } 42 | 43 | 44 | void WaterRender::render(std::shared_ptr camera, std::shared_ptr shadows,std::shared_ptr light, const float time) 45 | { 46 | 47 | glViewport(0.0,0.0,textureDimension.x,textureDimension.y); 48 | glActiveTexture(GL_TEXTURE9); 49 | glBindTexture(GL_TEXTURE_2D, waterFlows->getSourceTexture()); 50 | waterFlows->update(); 51 | glActiveTexture(GL_TEXTURE9); 52 | glBindTexture(GL_TEXTURE_2D, 0); 53 | camera->loadViewPort(); 54 | 55 | 56 | auto transform = terrainPlain->getModel_matrix(); 57 | 58 | glDepthMask(GL_FALSE); 59 | glEnable(GL_BLEND); 60 | glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); 61 | glUseProgram(waterProgram); 62 | 63 | 64 | glUniform2iv(glGetUniformLocation(waterProgram, "dimensions"),1,glm::value_ptr(terrainPlain->getPlaneDimension())); 65 | 66 | glUniformMatrix4fv(glGetUniformLocation(waterProgram,"shadowMVP"), 1, GL_FALSE, 67 | glm::value_ptr(shadows->getBiasedDepthMVP())); 68 | glUniformMatrix4fv(glGetUniformLocation(waterProgram, "model_matrix"),1,GL_FALSE,glm::value_ptr( transform )); 69 | glUniformMatrix4fv(glGetUniformLocation(waterProgram, "mv_matrix"),1,GL_FALSE,glm::value_ptr( camera->getView()* transform )); 70 | glUniformMatrix4fv(glGetUniformLocation(waterProgram, "proj_matrix"),1,GL_FALSE,glm::value_ptr(camera->getProjection() )); 71 | glUniform3fv(glGetUniformLocation(waterProgram, "light_pos"),1,glm::value_ptr(light->getCurrentData().Position )); 72 | glUniform3fv(glGetUniformLocation(waterProgram, "light_color"),1,glm::value_ptr(light->getCurrentData().Color )); 73 | 74 | 75 | glUniform1f(glGetUniformLocation(waterProgram, "waterSpeed"),5.0); 76 | 77 | glActiveTexture(GL_TEXTURE8); 78 | glBindTexture(GL_TEXTURE_2D, shadows->getDepthTexture()); 79 | 80 | glActiveTexture(GL_TEXTURE9); 81 | glBindTexture(GL_TEXTURE_2D, waterNormals); 82 | 83 | glActiveTexture(GL_TEXTURE11); 84 | glBindTexture(GL_TEXTURE_2D, waterFlows->getDestinationTexture()); 85 | 86 | 87 | glDrawElements(GL_PATCHES,terrainPlain->getPlaneVertices(), GL_UNSIGNED_INT, 0); 88 | glUseProgram(0); 89 | 90 | glDisable(GL_BLEND); 91 | 92 | glDepthMask(GL_TRUE); 93 | glBindVertexArray(0); 94 | glActiveTexture(GL_TEXTURE9); 95 | glBindTexture(GL_TEXTURE_2D, 0); 96 | 97 | glActiveTexture(GL_TEXTURE10); 98 | glBindTexture(GL_TEXTURE_2D, 0); 99 | 100 | glActiveTexture(GL_TEXTURE11); 101 | glBindTexture(GL_TEXTURE_2D, 0); 102 | 103 | waterFlows->swapTexture(); 104 | 105 | } 106 | 107 | void WaterRender::exit() 108 | { 109 | 110 | } 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /src/3DRender/display3D.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: display3D.cpp 9 | * Author: tg 10 | * 11 | * Created on 3. November 2016, 10:51 12 | */ 13 | 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "display3D.h" 21 | #include "simpleRender.h" 22 | #include "simulation.h" 23 | 24 | display3D::display3D(const uint32_t windowLenght, const uint32_t windowHeight, const uint32_t textureLenght, const uint32_t textureHeight) 25 | : windowDimension(glm::ivec2(windowLenght,windowHeight)), textureDimension(glm::ivec2(textureLenght,textureHeight)) 26 | { 27 | } 28 | 29 | 30 | void display3D::init() 31 | { 32 | initCamera(); 33 | 34 | 35 | terrainPlain = std::make_shared(glm::ivec2(80,80),glm::vec3(0.0),glm::vec3(0.0),glm::vec3(1.0)); 36 | 37 | landscaperender = std::make_shared(terrainPlain); 38 | shadows = std::make_shared(terrainPlain); 39 | waterRender = std::make_shared(terrainPlain,textureDimension); 40 | light = std::make_shared( 0,glm::vec3(0),glm::vec3(40)); 41 | 42 | Bar3D = inputHandler::createNewBar("3DControls","position='608 8' size='200 200'"); 43 | TwAddVarRW(Bar3D,"Light Position",TW_TYPE_DIR3F,&(light->getCurrentData().Position),"opened='true'"); 44 | // TwAddVarRW(Bar3D,"Light Color",TW_TYPE_COLOR3F,&(light->getCurrentData().Color),""); 45 | 46 | glBindVertexArray(terrainPlain->getVao_plane()); 47 | 48 | landscaperender->init(std::string(SHADER_PATH) + "display/3D/dispmap"); 49 | shadows->init(std::string(SHADER_PATH) + "display/3D/Shadow"); 50 | waterRender->init(std::string(SHADER_PATH) + "display/3D/waterDispmap",std::string(RESOURCES_PATH) + "grass_normals.png",Bar3D); 51 | glBindVertexArray(0); 52 | TwAddVarCB(Bar3D,"Terrain Scaling",TW_TYPE_FLOAT,[](const void *value, void *clientData){ static_cast(clientData)->setScale(glm::vec3(*(static_cast(value)),static_cast(clientData)->getScale().y,*(static_cast(value))));}, 53 | []( void *value, void *clientData){ *(static_cast< float*>(value)) = static_cast(clientData)->getScale().x;},terrainPlain.get(),"min=0.1 max = 30.0 step = 0.1" ); 54 | TwAddVarCB(Bar3D,"Terrain Height",TW_TYPE_FLOAT,[](const void *value, void *clientData){ static_cast(clientData)->setScale(glm::vec3(static_cast(clientData)->getScale().x,*(static_cast(value)),static_cast(clientData)->getScale().z));}, 55 | []( void *value, void *clientData){ *(static_cast< float*>(value)) = static_cast(clientData)->getScale().y;},terrainPlain.get(),"min=0.1 max = 30.0 step = 0.1" ); 56 | 57 | } 58 | 59 | void display3D::render(float frameTime,simulation* sim) 60 | { 61 | 62 | sim->setTexturesBindings(); 63 | 64 | camera->Update(frameTime); 65 | //0891A = GL_CLAMP_VERTEX_COLOR, 0x891B = GL_CLAMP_FRAGMENT_COLOR 66 | glClampColor(0x891A, GL_FALSE); 67 | glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); 68 | glClampColor(0x891B, GL_FALSE); 69 | glBindVertexArray(terrainPlain->getVao_plane()); 70 | 71 | 72 | shadows->render(light->getCurrentData().Position); 73 | camera->setViewport(0.0,0.0,windowDimension.x,windowDimension.y); 74 | camera->loadViewPort(); 75 | landscaperender->render(camera,shadows,light,sim->getCurrentDisplay()); 76 | waterRender->render(camera,shadows,light,frameTime); 77 | 78 | glBindVertexArray(0); 79 | glClampColor(0x891A, GL_TRUE); 80 | glClampColor(GL_CLAMP_READ_COLOR, GL_TRUE); 81 | glClampColor(0x891B, GL_TRUE); 82 | sim->unsetTexturesBindings(); 83 | 84 | } 85 | 86 | void display3D::initCamera() 87 | { 88 | camera = std::make_unique(); 89 | camera->setClipping(0.5f,10000.0f); 90 | camera->SetMove_camera(true); 91 | camera->SetCamera_look_at(glm::vec3(-5.0,2.0,5.0)); 92 | camera->setViewport(0, 0, windowDimension.x, windowDimension.y); 93 | camera->SetField_of_view(55.0f); 94 | camera->SetCamera_position(glm::vec3(2.0,2.0,1.0)); 95 | } 96 | 97 | void display3D::handleCameraInput(GLFWwindow* window) 98 | { 99 | glm::dvec2 newpos; 100 | glfwGetCursorPos(window, &newpos.x, &newpos.y); 101 | 102 | 103 | 104 | if(glfwGetKey(window,GLFW_KEY_LEFT_SHIFT)== GLFW_PRESS) 105 | { 106 | camera->MoveHead((prevMousePosition.x -newpos.x)*-0.01,(prevMousePosition.y-newpos.y)*0.01); 107 | } 108 | prevMousePosition = newpos; 109 | if(glfwGetKey(window,GLFW_KEY_A) == GLFW_PRESS) 110 | { 111 | camera->MoveX(-0.7); 112 | } 113 | if(glfwGetKey(window,GLFW_KEY_D) == GLFW_PRESS) 114 | { 115 | camera->MoveX(0.7); 116 | } 117 | if(glfwGetKey(window,GLFW_KEY_W) == GLFW_PRESS) 118 | { 119 | camera->MoveZ(-0.7); 120 | } 121 | if(glfwGetKey(window,GLFW_KEY_S) == GLFW_PRESS) 122 | { 123 | camera->MoveZ(0.7); 124 | } 125 | //ugly workaround for bug in GLFW3 126 | if(glfwGetKey(window,GLFW_KEY_TAB) == GLFW_PRESS && ((std::chrono::duration_cast(std::chrono::steady_clock::now() - buttonWait)).count() > 200)) 127 | { 128 | buttonWait = std::chrono::steady_clock::now() ; 129 | render3D = !render3D; 130 | 131 | } 132 | 133 | 134 | } 135 | 136 | bool display3D::isRender3D() const 137 | { 138 | return render3D; 139 | } 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /src/3DRender/landscapeRender.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: landscapeRender.cpp 9 | * Author: tg 10 | * 11 | * Created on 2. November 2016, 11:50 12 | */ 13 | 14 | #include "landscapeRender.h" 15 | 16 | landscapeRender::landscapeRender(std::shared_ptr terrainPlain ) 17 | :terrainPlain(terrainPlain) 18 | { 19 | } 20 | 21 | void landscapeRender::init(const std::string& shaderPath) 22 | { 23 | displayProgram = ShaderLoader::generateProgram(shaderPath); 24 | } 25 | 26 | void landscapeRender::render(std::shared_ptr camera, std::shared_ptr shadow,std::shared_ptr light,const uint32_t currentDisplay) 27 | { 28 | glUseProgram(displayProgram); 29 | 30 | glUniformMatrix4fv(glGetUniformLocation(displayProgram, "model_matrix"),1,GL_FALSE,glm::value_ptr( terrainPlain->getModel_matrix() )); 31 | glUniformMatrix4fv(glGetUniformLocation(displayProgram, "mv_matrix"),1,GL_FALSE,glm::value_ptr( camera->getView() *terrainPlain->getModel_matrix() )); 32 | glUniformMatrix4fv(glGetUniformLocation(displayProgram, "proj_matrix"),1,GL_FALSE,glm::value_ptr(camera->getProjection() )); 33 | glUniform3fv(glGetUniformLocation(displayProgram, "light_pos"),1,glm::value_ptr(light->getCurrentData().Position )); 34 | glUniform3fv(glGetUniformLocation(displayProgram, "light_color"),1,glm::value_ptr(light->getCurrentData().Color )); 35 | 36 | glUniform1ui(glGetUniformLocation(displayProgram, "currentSelection"),currentDisplay); 37 | 38 | glUniform2iv(glGetUniformLocation(displayProgram, "dimensions"),1,glm::value_ptr(terrainPlain->getPlaneDimension())); 39 | glUniformMatrix4fv(glGetUniformLocation(displayProgram,"shadowMVP"), 1, GL_FALSE, glm::value_ptr(shadow->getBiasedDepthMVP())); 40 | 41 | glActiveTexture(GL_TEXTURE8); 42 | glBindTexture(GL_TEXTURE_2D, shadow->getDepthTexture()); 43 | 44 | 45 | glDrawElements(GL_PATCHES,terrainPlain->getPlaneVertices(), GL_UNSIGNED_INT, 0); 46 | glUseProgram(0); 47 | 48 | glActiveTexture(GL_TEXTURE8); 49 | glBindTexture(GL_TEXTURE_2D, 0); 50 | 51 | } 52 | 53 | void landscapeRender::exit() 54 | { 55 | glDeleteProgram(displayProgram); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/3DRender/plane.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: plane.cpp 9 | * Author: tg 10 | * 11 | * Created on 4. November 2016, 10:06 12 | */ 13 | 14 | #include "plane.h" 15 | 16 | plane::plane(glm::ivec2 planeDimension,glm::vec3 position, glm::vec3 rotation, glm::vec3 scale) 17 | :planeDimension(planeDimension) ,scaleVec(scale) 18 | { 19 | model_matrix = glm::translate(glm::mat4(1.0f), position); 20 | 21 | model_matrix = glm::rotate(model_matrix, rotation.x,glm::fvec3(1.0f,0.0f,0.0f)); 22 | model_matrix = glm::rotate(model_matrix, rotation.y,glm::fvec3(0.0f,1.0f,0.0f)); 23 | model_matrix = glm::rotate(model_matrix, rotation.z,glm::fvec3(0.0f,0.0f,1.0f)); 24 | 25 | model_matrix *= glm::scale(scale); 26 | 27 | generatePlane(planeDimension.x, planeDimension.y); 28 | 29 | } 30 | 31 | glm::ivec2 plane::getPlaneDimension() const 32 | { 33 | return planeDimension; 34 | } 35 | 36 | uint32_t plane::getPlaneVertices() const 37 | { 38 | return planeVertices; 39 | } 40 | 41 | GLuint plane::getVao_plane() const 42 | { 43 | return vao_plane; 44 | } 45 | 46 | glm::fmat4 plane::getModel_matrix() const 47 | { 48 | return model_matrix; 49 | } 50 | 51 | glm::vec3 plane::getScale() const 52 | { 53 | return scaleVec; 54 | } 55 | 56 | void plane::setScale(const glm::vec3 scale) 57 | { 58 | scaleMat = glm::scale(model_matrix, scale / scaleVec); 59 | model_matrix = scaleMat; 60 | scaleVec = scale; 61 | } 62 | 63 | 64 | 65 | void plane::generatePlane(int width, int height) 66 | { 67 | 68 | std::vector vertices = std::vector((width)*(height)*3,0.0); 69 | std::vector indices = std::vector((width-1)*(height-1)*6); 70 | 71 | unsigned int index = 0; 72 | 73 | for (int x = 0; x < width; x++) 74 | { 75 | for (int z = 0; z < ((height)*3); z+=3) 76 | { 77 | vertices[index++] = (GLfloat)x; 78 | vertices[index++] =(GLfloat) 0.0f; 79 | vertices[index++] = (GLfloat)(z/3.0); 80 | } 81 | } 82 | 83 | index = 0; 84 | 85 | for (unsigned int x = 0; x < width-1 ; x++) 86 | { 87 | for (unsigned int z = 0; z < height-1; z++) 88 | { 89 | unsigned int offset = x * height + z; 90 | indices[index] = (offset + 1); 91 | indices[index + 1] = (offset + 0); 92 | indices[index + 2] = (offset + height+1); 93 | indices[index + 3] = (offset + height); 94 | index += 4; 95 | } 96 | } 97 | glGenVertexArrays(1, &vao_plane); 98 | glBindVertexArray(vao_plane); 99 | glPatchParameteri(GL_PATCH_VERTICES,4); 100 | glGenBuffers(1, &vbo_plane); 101 | glBindBuffer(GL_ARRAY_BUFFER, vbo_plane); 102 | glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat),vertices.data(), GL_STATIC_DRAW); 103 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 104 | glEnableVertexAttribArray(0); 105 | 106 | glGenBuffers(1, &vbo_indexbuffer); 107 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_indexbuffer); 108 | glBufferData(GL_ELEMENT_ARRAY_BUFFER,indices.size() * sizeof(GLuint), indices.data(), GL_STATIC_DRAW); 109 | 110 | planeVertices = indices.size(); 111 | glBindBuffer(GL_ARRAY_BUFFER, 0); //free buffer 112 | glBindVertexArray(0); 113 | } -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( rtwg 2 | main.cpp 3 | ShaderLoader.cpp 4 | inputHandler.cpp 5 | simpleRender.cpp 6 | RendToTex.cpp 7 | TextureLoader.cpp 8 | display2D.cpp 9 | simulation.cpp 10 | ) 11 | 12 | add_subdirectory("3DRender") 13 | 14 | 15 | SET(SHADER_PATH "${PROJECT_SOURCE_DIR}/Shader/") 16 | ADD_DEFINITIONS(-DSHADER_PATH="${SHADER_PATH}") 17 | 18 | SET(RESOURCES_PATH "${PROJECT_SOURCE_DIR}/res/") 19 | ADD_DEFINITIONS(-DRESOURCES_PATH="${RESOURCES_PATH}") 20 | 21 | SET(OUTPUT_PATH "${PROJECT_SOURCE_DIR}/outputIMG/") 22 | ADD_DEFINITIONS(-DOUTPUT_PATH="${OUTPUT_PATH}") 23 | 24 | 25 | target_link_libraries(rtwg GL3W RTplatec rtwg3D dl ${OPENGL_LIBRARIES} ${GLFW_LIBRARIES} 26 | ${IL_LIBRARIES} ${ILU_LIBRARIES} ${ILUT_LIBRARIES} 27 | ${ANTTWEAKBAR_LIBRARY} ${LIBNOISE_LIBRARIES} ${X11_LIBRARIES}) -------------------------------------------------------------------------------- /src/RendToTex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: RendToTex.cpp 9 | * Author: tg 10 | * 11 | * Created on 15. Februar 2016, 11:02 12 | */ 13 | 14 | #include 15 | #include 16 | #include "cstring" 17 | 18 | #include "RendToTex.h" 19 | 20 | 21 | RendToTex::RendToTex(const std::string& shaderPath, unsigned int textureWidth, unsigned int textureHeight, const GLuint colorFormat, const GLuint interpolation) 22 | : textureWidth(textureWidth), textureHeight(textureHeight), colorFormat(colorFormat), enable(true) 23 | { 24 | shaderID = ShaderLoader::generateProgram(shaderPath); 25 | glGenFramebuffers(2,fboBuffer.data()); 26 | glGenBuffers(1,&pixelBuffer); 27 | 28 | glBindFramebuffer(GL_FRAMEBUFFER,fboBuffer.at(sourceBuffer)); 29 | 30 | textureBuffer.at(sourceBuffer) = TextureLoader::loadEmpty2DTexture(textureWidth, textureHeight,colorFormat,GL_FLOAT ,interpolation); 31 | 32 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureBuffer.at(sourceBuffer), 0); 33 | glBindBuffer(GL_FRAMEBUFFER,0); 34 | 35 | glBindFramebuffer(GL_FRAMEBUFFER,fboBuffer.at(destinationBuffer)); 36 | 37 | textureBuffer.at(destinationBuffer) = TextureLoader::loadEmpty2DTexture(textureWidth, textureHeight,colorFormat,GL_FLOAT,interpolation); 38 | 39 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureBuffer.at(destinationBuffer), 0); 40 | 41 | glBindBuffer(GL_FRAMEBUFFER,0); 42 | glBindTexture(GL_TEXTURE_2D, 0); 43 | reset(); 44 | } 45 | 46 | void RendToTex::setUniforms(const std::vector >& uniforms) 47 | { 48 | v_Uniforms = std::move(uniforms); 49 | } 50 | 51 | 52 | 53 | void RendToTex::update() 54 | { 55 | if(!enable) 56 | return; 57 | glUseProgram(shaderID); 58 | 59 | glBindFramebuffer(GL_FRAMEBUFFER,fboBuffer.at(destinationBuffer)); 60 | static const GLenum draw_buffers[] = {GL_COLOR_ATTACHMENT0 }; 61 | glDrawBuffers(1 ,draw_buffers); 62 | 63 | 64 | for(const auto& uni : v_Uniforms) 65 | { 66 | glUniform1f(glGetUniformLocation(shaderID, uni.second.c_str()),uni.first); 67 | } 68 | 69 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 70 | 71 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 72 | 73 | glUseProgram(0); 74 | } 75 | 76 | void RendToTex::generateParameterBar(TwBar* bar, const std::string& subSectionName, const std::vector options) 77 | { 78 | for(auto& uni : v_Uniforms) 79 | { 80 | std::string s= "group='" + subSectionName + "' " + options.at(std::distance(v_Uniforms.data(),&uni)).c_str(); 81 | TwAddVarRW(bar,uni.second.c_str(),TW_TYPE_FLOAT,&uni.first,s.c_str() ); 82 | } 83 | } 84 | 85 | void RendToTex::generateActivationBar(TwBar* bar, const std::string& subSectionName) 86 | { 87 | std::string s= "group='" + subSectionName + "' "; 88 | std::string name_1 = "Enable " + subSectionName; 89 | TwAddVarRW(bar,name_1.c_str(),TW_TYPE_BOOLCPP,&enable,s.c_str() ); 90 | std::string name_2 = "Reset " + subSectionName; 91 | TwAddButton(bar,name_2.c_str(),[](void* clientData){static_cast(clientData)->reset();},this,s.c_str()); 92 | } 93 | 94 | 95 | GLuint RendToTex::getSourceTexture() 96 | { 97 | return textureBuffer.at(sourceBuffer); 98 | } 99 | 100 | GLuint RendToTex::getDestinationTexture() 101 | { 102 | return textureBuffer.at(destinationBuffer); 103 | } 104 | 105 | 106 | void RendToTex::swapTexture() 107 | { 108 | if(enable) 109 | std::swap(sourceBuffer,destinationBuffer); 110 | } 111 | 112 | float* RendToTex::getTexture() 113 | { 114 | 115 | float* tmp; 116 | if(colorFormat == GL_RED) 117 | { 118 | tmp= new float[textureHeight* textureWidth ]; 119 | glActiveTexture(GL_TEXTURE0); 120 | glBindTexture(GL_TEXTURE_2D, getSourceTexture()); 121 | 122 | glGetTexImage(GL_TEXTURE_2D,0,GL_RED,GL_FLOAT,tmp); 123 | } 124 | else 125 | { 126 | tmp= new float[textureHeight* textureWidth *3]; 127 | glActiveTexture(GL_TEXTURE0); 128 | glBindTexture(GL_TEXTURE_2D, getSourceTexture()); 129 | 130 | glGetTexImage(GL_TEXTURE_2D,0,GL_RGB,GL_FLOAT,tmp); 131 | } 132 | 133 | // glBindBuffer(GL_PIXEL_PACK_BUFFER,pixelBuffer); 134 | // glReadPixels(0,0,textureWidth,textureLenght,GL_RED,GL_FLOAT,tmp); 135 | // 136 | // glBufferData(GL_PIXEL_PACK_BUFFER,textureLenght* textureWidth * sizeof(float),0,GL_STREAM_READ); 137 | // GLfloat* ptr = (GLfloat*)glMapBuffer(GL_PIXEL_PACK_BUFFER,GL_READ_ONLY); 138 | // if(ptr ) 139 | // { 140 | // memcpy(tmp,ptr,textureLenght* textureWidth * sizeof(float)); 141 | // } 142 | // glUnmapBuffer(GL_PIXEL_PACK_BUFFER); 143 | // //load texture to graphic card 144 | // // glTexSubImage2D(GL_TEXTURE_2D,0,0,0, textureWidth, textureLenght, colorFormat, GL_FLOAT,0); 145 | // 146 | // 147 | // glBindBuffer(GL_PIXEL_PACK_BUFFER,0); 148 | glBindTexture(GL_TEXTURE_2D,0); 149 | return tmp; 150 | } 151 | 152 | void RendToTex::setTexture(const float* data) 153 | { 154 | glActiveTexture(GL_TEXTURE0); 155 | glBindTexture(GL_TEXTURE_2D, getSourceTexture()); 156 | 157 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER,pixelBuffer); 158 | 159 | if(colorFormat == GL_RED) 160 | { 161 | glBufferData(GL_PIXEL_UNPACK_BUFFER,textureHeight* textureWidth * sizeof(float),0,GL_STREAM_DRAW); 162 | GLubyte* ptr = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER,GL_WRITE_ONLY); 163 | if(ptr ) 164 | { 165 | memcpy(ptr,data,textureHeight* textureWidth * sizeof(float)); 166 | } 167 | } 168 | else 169 | { 170 | glBufferData(GL_PIXEL_UNPACK_BUFFER,textureHeight* textureWidth * sizeof(float) *3 ,0,GL_STREAM_DRAW); 171 | GLubyte* ptr = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER,GL_WRITE_ONLY); 172 | 173 | if(ptr ) 174 | { 175 | memcpy(ptr,data,textureHeight* textureWidth * sizeof(float)*3); 176 | } 177 | } 178 | 179 | glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); 180 | //load texture to graphic card 181 | glTexSubImage2D(GL_TEXTURE_2D,0,0,0, textureWidth, textureHeight, colorFormat, GL_FLOAT,0); 182 | 183 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0); 184 | glBindTexture(GL_TEXTURE_2D,0); 185 | } 186 | 187 | void RendToTex::exit() 188 | { 189 | glDeleteProgram(shaderID); 190 | glDeleteBuffers(1,&pixelBuffer); 191 | glDeleteBuffers(2,&fboBuffer[0]); 192 | glDeleteTextures(2,&textureBuffer[0]); 193 | } 194 | 195 | void RendToTex::reset() 196 | { 197 | std::vector emtpyData; 198 | if(colorFormat == GL_RED) 199 | { 200 | emtpyData = std::vector(textureWidth*textureHeight,0.0); 201 | } 202 | else 203 | { 204 | emtpyData = std::vector(textureWidth*textureHeight*3,0.0); 205 | } 206 | setTexture(emtpyData.data()); 207 | } 208 | 209 | void RendToTex::setParameterValue(const std::string& parameter, float value) 210 | { 211 | auto itr = std::find_if(v_Uniforms.begin(),v_Uniforms.end(),[&](auto val){return val.second.compare(parameter) == 0;}); 212 | if(itr != v_Uniforms.end()) 213 | { 214 | itr->first = value; 215 | } 216 | 217 | } 218 | 219 | float RendToTex::getParameterValue(const std::string& parameter) 220 | { 221 | auto itr = std::find_if(v_Uniforms.begin(),v_Uniforms.end(),[&](auto val){return val.second.compare(parameter) == 0;}); 222 | if(itr != v_Uniforms.end()) 223 | { 224 | return itr->first; 225 | } 226 | else 227 | { 228 | return 0; //TODO: here we need an exception 229 | } 230 | } 231 | 232 | 233 | ILuint RendToTex::prepareExport() 234 | { 235 | ilInit(); 236 | std::vector imgData; 237 | 238 | //set all data to RGB format 239 | float* texData = getTexture(); 240 | imgData.resize(textureWidth*textureHeight*3,0.0); 241 | if(colorFormat == GL_RED) 242 | { 243 | 244 | 245 | for(int i = 0, j = 0; i < textureWidth*textureHeight*3; i += 3, ++j) 246 | { 247 | imgData[i] = texData[j]; 248 | imgData[i+1] = texData[j]; 249 | imgData[i+2] = texData[j]; 250 | } 251 | } 252 | else 253 | { 254 | imgData = std::vector(texData,texData+(textureWidth*textureHeight*3)); 255 | } 256 | 257 | //set all values between 0 and 1 258 | float lowest = *std::min_element(imgData.begin(), imgData.end()); 259 | float highest = *std::max_element(imgData.begin(), imgData.end()); 260 | 261 | if(lowest < 0.0) 262 | { 263 | lowest = -lowest; 264 | highest = highest + lowest; 265 | std::for_each(imgData.begin(),imgData.end(),[&](auto& f){ f+= lowest;}); 266 | } 267 | 268 | std::for_each(imgData.begin(),imgData.end(), [&](auto& value) {value = (value - lowest) / (highest - lowest);}); 269 | 270 | ILuint id; 271 | ilGenImages(1, &id); 272 | 273 | ilBindImage(id); 274 | ilTexImage(textureWidth,textureHeight,1,3,IL_RGB,IL_FLOAT,imgData.data()); 275 | 276 | ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE); 277 | 278 | 279 | return id; 280 | } 281 | 282 | void RendToTex::setEnable(GLboolean enable) 283 | { 284 | this->enable = enable; 285 | } 286 | 287 | -------------------------------------------------------------------------------- /src/ShaderLoader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: ShaderLoader.cpp 9 | * Author: tartg 10 | * 11 | * Created on 18. Oktober 2016, 12:39 12 | */ 13 | 14 | #include 15 | 16 | #include "ShaderLoader.h" 17 | 18 | GLuint ShaderLoader::generateProgram(const std::string& pathName) 19 | { 20 | GLuint program = glCreateProgram(); //create a new program 21 | 22 | //try to load and attach shader stages 23 | ShaderLoader::attachShader(program,pathName + ".vs.glsl",GL_VERTEX_SHADER); 24 | 25 | ShaderLoader::attachShader(program, pathName + ".tcs.glsl", GL_TESS_CONTROL_SHADER); 26 | 27 | ShaderLoader::attachShader(program, pathName + ".tes.glsl",GL_TESS_EVALUATION_SHADER); 28 | 29 | ShaderLoader::attachShader(program, pathName + ".gs.glsl", GL_GEOMETRY_SHADER); 30 | 31 | ShaderLoader::attachShader(program,pathName + ".fs.glsl",GL_FRAGMENT_SHADER); 32 | 33 | ShaderLoader::attachShader(program, pathName + ".cs.glsl",GL_COMPUTE_SHADER); 34 | 35 | //link program 36 | glLinkProgram(program); 37 | GLint status; 38 | glGetProgramiv(program, GL_LINK_STATUS, &status); //get program status 39 | 40 | if (!status) //if there is an error 41 | { 42 | //print error to console 43 | char buffer[4096]; 44 | glGetProgramInfoLog(program, 4096, NULL, buffer); 45 | std::stringstream s; 46 | s << buffer; 47 | std::cout << "Error Program link in " << s.str()<< std::endl; 48 | glDeleteProgram(program); 49 | return 0; 50 | } 51 | return program; //return ID 52 | } 53 | 54 | void ShaderLoader::attachShader(GLuint& program, std::string filename, GLenum shader_type) 55 | { 56 | GLuint ret = loadShaders( filename,shader_type); //load shader 57 | if(ret != 0) //if shader exists 58 | glAttachShader(program, ret); //attach to program 59 | } 60 | 61 | 62 | 63 | GLuint ShaderLoader::loadShaders(const std::string filename, GLenum shader_type) 64 | { 65 | GLuint result = 0; 66 | FILE * fp; 67 | size_t filesize; 68 | char * data; 69 | 70 | 71 | fp = fopen(filename.c_str(), "rb"); //read from file 72 | 73 | if (!fp) //if not available 74 | return result; //return 0 75 | 76 | //get filesize 77 | fseek(fp, 0, SEEK_END); 78 | filesize = ftell(fp); 79 | fseek(fp, 0, SEEK_SET); //reset file pointer 80 | 81 | data = new char [filesize + 1]; //create buffer 82 | 83 | if (!data) //if this fails 84 | return result; //return 0 85 | 86 | auto index = fread(data, 1, filesize, fp); //read data from file to buffer 87 | data[index] = 0; 88 | fclose(fp); //close file 89 | 90 | result = glCreateShader(shader_type); //create shader 91 | 92 | if (!result) //if shader is not created 93 | return result; //return 0 94 | 95 | glShaderSource(result, 1, &data, NULL); //add shader source 96 | 97 | //compie shader 98 | glCompileShader(result); 99 | 100 | GLint status = 0; 101 | glGetShaderiv(result, GL_COMPILE_STATUS, &status); //get shader status 102 | 103 | if (!status) //if there is an error, print to console 104 | { 105 | char buffer[4096] ; 106 | glGetShaderInfoLog(result, 4096, NULL, buffer); 107 | std::stringstream s; 108 | s <<"Fail Shader " << filename << " in " << buffer; 109 | std::cout << s.str() << std::endl; 110 | glDeleteShader(result); 111 | } 112 | 113 | delete[] data; //delete buffer 114 | 115 | return result; //return shader ID 116 | 117 | } -------------------------------------------------------------------------------- /src/TextureLoader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: TextureLoader.cpp 9 | * Author: tg 10 | * 11 | * Created on 14. Januar 2016, 12:50 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include "TextureLoader.h" 18 | #include 19 | 20 | 21 | GLuint TextureLoader::load2DTexture(const std::string& fileName, const GLuint OUTcolorFormat, const GLuint OUTvalueFormat, 22 | const ILint INcolorFormat, const ILint INvalueFormat) 23 | { 24 | ILuint imgID =0; //id of the image 25 | ilInit(); //init DevIL 26 | 27 | GLuint textureID; 28 | 29 | ilGenImages(1,&imgID); //generate image ID 30 | glGenTextures(1,&textureID); //generate Texture ID 31 | ilBindImage(imgID); //bind Image 32 | 33 | 34 | //some devIL options 35 | ilEnable(IL_ORIGIN_SET); 36 | ilOriginFunc(IL_ORIGIN_LOWER_LEFT); 37 | if(ilLoadImage(fileName.c_str())) //try to load image 38 | { 39 | if(!ilConvertImage(INcolorFormat,INvalueFormat)) 40 | return 0; //convert image 41 | 42 | glBindTexture(GL_TEXTURE_2D, textureID); 43 | 44 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //setup Opengl Texture 45 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 46 | 47 | //load texture 48 | 49 | glTexImage2D(GL_TEXTURE_2D,0,OUTcolorFormat, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, OUTcolorFormat, OUTvalueFormat,ilGetData()); 50 | glBindTexture(GL_TEXTURE_2D, 0); 51 | } 52 | else //if image loading didn't work. print error 53 | { 54 | std::stringstream s; 55 | s <<"Could not load texture " << fileName.c_str(); 56 | std::cout << s.str()<< std::endl; 57 | } 58 | 59 | 60 | ilDeleteImage(imgID); //delete image 61 | return textureID; 62 | } 63 | 64 | GLuint TextureLoader::load2DTextureArray(const std::vector& fileNames, const GLuint OUTcolorFormat, const GLuint OUTvalueFormat, const ILint INcolorFormat, const ILint INvalueFormat) 65 | { 66 | ILuint imgID =0; //id of the image 67 | ilInit(); //init DevIL 68 | ilGenImages(1,&imgID); //generate image ID 69 | ilBindImage(imgID); //bind Image 70 | GLuint textureID; 71 | 72 | glGenTextures(1,&textureID); //generate Texture ID 73 | 74 | glBindTexture(GL_TEXTURE_2D_ARRAY, textureID); 75 | unsigned int index = 0; 76 | 77 | for(auto fileName : fileNames) 78 | { 79 | 80 | 81 | if(ilLoadImage(fileName.c_str())) //try to load image 82 | { 83 | ilEnable(IL_ORIGIN_SET); 84 | ilOriginFunc(IL_ORIGIN_LOWER_LEFT); 85 | 86 | if(!ilConvertImage(INcolorFormat,INvalueFormat)) 87 | { 88 | std::stringstream s; 89 | s <<"Could not convert texture " << fileName.c_str(); 90 | std::cout << s.str()<< std::endl; 91 | continue; 92 | } 93 | iluScale(1024,1024,ilGetInteger(IL_IMAGE_DEPTH)); 94 | if(index == 0) 95 | { 96 | glTexImage3D(GL_TEXTURE_2D_ARRAY,0, OUTcolorFormat,ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),fileNames.size(),0,OUTcolorFormat, OUTvalueFormat, 0); 97 | } 98 | 99 | glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //setup Opengl Texture 100 | glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 101 | glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_T,GL_REPEAT); //setup Opengl Texture 102 | glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_S,GL_REPEAT); 103 | //load texture 104 | 105 | glTexSubImage3D(GL_TEXTURE_2D_ARRAY,0,0,0,index, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 1, OUTcolorFormat, OUTvalueFormat,ilGetData()); 106 | 107 | } 108 | else //if image loading didn't work. print error 109 | { 110 | std::stringstream s; 111 | s <<"Could not load texture " << fileName.c_str(); 112 | std::cout << s.str()<< std::endl; 113 | } 114 | ++index; 115 | 116 | } 117 | glBindTexture(GL_TEXTURE_2D_ARRAY, 0); 118 | ilDeleteImage(imgID); //delete image 119 | return textureID; 120 | 121 | } 122 | 123 | 124 | 125 | 126 | 127 | 128 | GLuint TextureLoader::loadEmpty2DTexture(const int width, const int lenght, const GLuint OUTcolorFormat, const GLuint OUTvalueFormat, const GLuint interplolation) 129 | { 130 | //load texture 131 | // std::vector data(width *lenght * 3,0.0); 132 | 133 | GLuint textureID; 134 | 135 | glGenTextures(1,&textureID); //generate Texture ID 136 | 137 | glBindTexture(GL_TEXTURE_2D, textureID); 138 | 139 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,interplolation); //setup Opengl Texture 140 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,interplolation); 141 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER); //setup Opengl Texture 142 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER); 143 | // glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16F, width, lenght, 0, OUTcolorFormat, OUTvalueFormat,nullptr); 144 | if(OUTcolorFormat == GL_RED) 145 | { 146 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, width, lenght); 147 | } 148 | else 149 | { 150 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB32F, width, lenght); 151 | } 152 | glBindTexture(GL_TEXTURE_2D, 0); 153 | 154 | 155 | return textureID; 156 | } 157 | 158 | GLuint TextureLoader::generateNoiseTexture(const int width, const int lenght,const int seed, const float roughness,const int turbulence) 159 | { 160 | GLuint noiseID; 161 | 162 | std::vector noiseMap = std::vector(width *lenght,0.0); 163 | FractalGenerator::noiseTurbulence(noiseMap.data(),width,lenght,seed,roughness,turbulence); 164 | const float lowest = *std::min_element(noiseMap.begin(), noiseMap.end()); 165 | const float highest = *std::max_element(noiseMap.begin(), noiseMap.end()); 166 | const float medium = highest - lowest; 167 | 168 | std::for_each(noiseMap.begin(), noiseMap.end(), [&](auto& value) {value = (value - lowest) / medium;}); 169 | 170 | glGenTextures(1,&noiseID); //generate Texture ID 171 | 172 | glBindTexture(GL_TEXTURE_2D, noiseID); 173 | 174 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //setup Opengl Texture 175 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 176 | 177 | glTexImage2D(GL_TEXTURE_2D,0,GL_RED, width, lenght, 0, GL_RED, GL_FLOAT,noiseMap.data()); 178 | 179 | glBindTexture(GL_TEXTURE_2D, 0); 180 | return noiseID; 181 | } 182 | 183 | ILuint TextureLoader::load2DTexture(const std::string& fileName, const ILint INcolorFormat, const ILint INvalueFormat) 184 | { 185 | ILuint imgID =0; //id of the image 186 | ilInit(); //init DevIL 187 | ilGenImages(1,&imgID); //generate image ID 188 | ilBindImage(imgID); //bind Image 189 | 190 | 191 | if(ilLoadImage(fileName.c_str())) //try to load image 192 | { 193 | ilEnable(IL_ORIGIN_SET); 194 | ilOriginFunc(IL_ORIGIN_LOWER_LEFT); 195 | iluFlipImage(); 196 | 197 | if(!ilConvertImage(INcolorFormat,INvalueFormat)) 198 | { 199 | std::stringstream s; 200 | s <<"Could not convert texture " << fileName.c_str(); 201 | std::cout << s.str()<< std::endl; 202 | return 0; 203 | } 204 | 205 | 206 | } 207 | else //if image loading didn't work. print error 208 | { 209 | std::stringstream s; 210 | s <<"Could not load texture " << fileName.c_str(); 211 | std::cout << s.str()<< std::endl; 212 | return 0; //convert image 213 | 214 | } 215 | 216 | return imgID; 217 | } 218 | 219 | 220 | 221 | ILuint TextureLoader::SaveTexture(ILuint Width, ILuint Height, std::string FileName, ILuint Texture) 222 | { 223 | ilEnable(IL_FILE_OVERWRITE); 224 | 225 | 226 | ilBindImage(Texture); 227 | 228 | 229 | 230 | ilSave(IL_PNG, FileName.c_str()); 231 | 232 | ilDisable(IL_FILE_OVERWRITE); 233 | 234 | if(ilGetError() != IL_NO_ERROR) 235 | return ilGetError(); 236 | 237 | return IL_NO_ERROR; 238 | } -------------------------------------------------------------------------------- /src/display2D.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: display2D.cpp 9 | * Author: tg 10 | * 11 | * Created on 27. Oktober 2016, 10:55 12 | */ 13 | 14 | 15 | #include 16 | 17 | #include "display2D.h" 18 | 19 | display2D::display2D(const std::string& shaderPath) 20 | { 21 | glGenVertexArrays(1, &vao); 22 | glBindVertexArray(vao); 23 | displayProgram = ShaderLoader::generateProgram(std::string(SHADER_PATH ) +shaderPath); 24 | glBindVertexArray(0); 25 | } 26 | void display2D::render(std::array windowDimensions, unsigned int currentSelection, GLuint textureID) 27 | { 28 | glViewport(0,0,windowDimensions.at(0),windowDimensions.at(1)); 29 | glBindVertexArray(vao); 30 | 31 | glUseProgram(displayProgram); 32 | 33 | glActiveTexture(GL_TEXTURE0); 34 | glBindTexture(GL_TEXTURE_2D,textureID); 35 | 36 | glUniform1ui(glGetUniformLocation(displayProgram, "currentSelection"),currentSelection); 37 | glUniform2iv(glGetUniformLocation(displayProgram, "WindowDimension"),1,windowDimensions.data()); 38 | 39 | 40 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 41 | glBindTexture(GL_TEXTURE_2D,0); 42 | glUseProgram(0); 43 | glBindVertexArray(0); 44 | } 45 | 46 | void display2D::exit() 47 | { 48 | glDeleteProgram(displayProgram); 49 | glDeleteVertexArrays(1,&vao); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/inputHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: inputHandler.cpp 9 | * Author: tartg 10 | * 11 | * Created on 18. Oktober 2016, 10:35 12 | */ 13 | 14 | #include 15 | 16 | #include "inputHandler.h" 17 | 18 | static void windowSizeCallback(GLFWwindow*,int newWidth, int newHeight) 19 | { 20 | TwWindowSize(newWidth, newHeight);glViewport(0, 0, newWidth, newHeight); 21 | } 22 | 23 | static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods) 24 | { 25 | TwEventMouseButtonGLFW(button,action); 26 | } 27 | static void cursorPosCallback(GLFWwindow* window, double x, double y) 28 | { 29 | TwEventMousePosGLFW((int)x,(int)y); 30 | } 31 | 32 | static void scrollCallback(GLFWwindow* window, double x, double y) 33 | { 34 | static double lastscrollPos = 0; 35 | lastscrollPos += y; 36 | TwEventMouseWheelGLFW(lastscrollPos ); 37 | } 38 | 39 | static void keyCallback(GLFWwindow* window,int key, int scancode, int action, int mods) 40 | { 41 | TwEventKeyGLFW(key,action); 42 | } 43 | 44 | static void charCallback(GLFWwindow* window,unsigned int codepoint) 45 | { 46 | TwEventCharGLFW(codepoint,1); 47 | } 48 | 49 | 50 | inputHandler::inputHandler(GLFWwindow* window) : window(window) 51 | { 52 | //get window dimensions 53 | int width,height; 54 | glfwGetWindowSize(window,&width, &height); 55 | // Initialize AntTweakBar 56 | TwInit(TW_OPENGL_CORE, NULL); 57 | TwWindowSize(width, height); 58 | 59 | 60 | // Set GLFW event callbacks 61 | // - Redirect window size changes to the callback function WindowSizeCB 62 | glfwSetWindowSizeCallback(window,windowSizeCallback); 63 | // - Directly redirect GLFW mouse button events to AntTweakBar 64 | glfwSetMouseButtonCallback(window,mouseButtonCallback); 65 | // - Directly redirect GLFW mouse position events to AntTweakBar 66 | glfwSetCursorPosCallback(window,cursorPosCallback); 67 | // - Directly redirect GLFW mouse wheel events to AntTweakBar 68 | glfwSetScrollCallback(window,scrollCallback); 69 | // - Directly redirect GLFW key events to AntTweakBar 70 | glfwSetKeyCallback(window,keyCallback); 71 | // - Directly redirect GLFW char events to AntTweakBar 72 | glfwSetCharCallback(window,charCallback); 73 | } 74 | 75 | TwBar* inputHandler::createNewBar(const std::string& name, const std::string& description) 76 | { 77 | TwBar* bar = TwNewBar(name.c_str()); 78 | TwDefine(std::string(name +" " + description).c_str()); 79 | return bar; 80 | } 81 | 82 | 83 | void inputHandler::update() 84 | { 85 | // Draw tweak bars 86 | TwDraw(); 87 | 88 | } 89 | 90 | 91 | void inputHandler::exit() 92 | { 93 | TwTerminate(); 94 | } 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: main.cpp 9 | * Author: tg 10 | * 11 | * Created on 27. Oktober 2016, 10:56 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include "simulation.h" 18 | #include "display2D.h" 19 | #include "simpleRender.h" 20 | #include "display3D.h" 21 | 22 | using namespace std; 23 | 24 | /* 25 | * 26 | */ 27 | int main(int argc, char** argv) 28 | { 29 | float frameTime; //current frame time 30 | bool enable_tectonic = true; //bool for enabling/disabling tectonic 31 | int windowWidth = 1600, windowHeight= 900; //start values for window dimensions 32 | int textureWidth = 1400, textureHeight= 900; 33 | srand(time(NULL)); //initialize random number generator 34 | 35 | //generate a new lithosphere. 36 | 37 | //initalize rendering 38 | std::unique_ptr render = std::make_unique(windowWidth,windowHeight,""); 39 | 40 | if(render->init() != 0) //if something faild 41 | { 42 | std::cout << "Failed to init window!"; 43 | return 0; //close program 44 | } 45 | //initalize input handler 46 | std::unique_ptr input = std::make_unique(render->getWindow()); 47 | 48 | std::unique_ptr sim = std::make_unique(textureWidth,textureHeight); 49 | sim->init(); 50 | sim->initLithosphere(0.56,0.01,8000000, 3.00,10,0.7); 51 | 52 | std::unique_ptr disp = std::make_unique("display/2D/2d_display"); 53 | std::unique_ptr disp3D = std::make_unique(windowWidth,windowHeight,textureWidth,textureHeight); 54 | 55 | disp3D->init(); 56 | //initialize time counter 57 | auto timeBeforeLoop = std::chrono::high_resolution_clock::now(); 58 | 59 | /** Init OpenGL stuff*/ 60 | 61 | while( !glfwGetKey(render->getWindow(),GLFW_KEY_ESCAPE)) //as long as "ESCAPE" isn't pressed 62 | { 63 | 64 | timeBeforeLoop = std::chrono::high_resolution_clock::now(); //get timestamp 65 | //get current window size 66 | glfwGetWindowSize(render->getWindow(),&windowWidth, &windowHeight); 67 | 68 | render->clearWindow(); //clear window 69 | disp3D->handleCameraInput(render->getWindow()); 70 | 71 | sim->update(); 72 | if(disp3D->isRender3D()) 73 | { 74 | disp->render({windowWidth,windowHeight},sim->getCurrentDisplay(),sim->getTextureID(sim->getCurrentDisplay())); 75 | } 76 | else 77 | { 78 | disp3D->render(frameTime,sim.get()); 79 | } 80 | input->update(); //handle input 81 | 82 | 83 | 84 | 85 | render->render(); //swap buffers and render 86 | 87 | //calculate frame time 88 | frameTime = 1.f/(std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - timeBeforeLoop).count()/1000.f); // the difference 89 | 90 | std::ostringstream ss; 91 | ss << "RTWG " << frameTime; 92 | glfwSetWindowTitle(render->getWindow(),ss.str().c_str()); 93 | } 94 | 95 | 96 | 97 | input->exit(); //close input stuff 98 | sim->exit(); 99 | disp->exit(); 100 | render->exit(); //close opengl Context 101 | 102 | 103 | //quit 104 | return 0; 105 | } 106 | 107 | -------------------------------------------------------------------------------- /src/simpleRender.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: simpleRender.cpp 9 | * Author: tartg 10 | * 11 | * Created on 18. Oktober 2016, 10:09 12 | */ 13 | 14 | #include "simpleRender.h" 15 | 16 | 17 | 18 | 19 | simpleRender::simpleRender(uint32_t windowLength, uint32_t windowHeight, std::string windowTitle) : 20 | windowHeight(windowHeight),windowLength(windowLength), windowTitle(windowTitle) 21 | { 22 | } 23 | 24 | uint32_t simpleRender::init() 25 | { 26 | if (!glfwInit()) //try to init glfw 27 | return 1; 28 | 29 | //set OpenGL context to Version 4.4 30 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,4); 31 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,4); 32 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE); 33 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 34 | //create Window 35 | window = glfwCreateWindow(windowLength, windowHeight, windowTitle.c_str(), NULL, NULL); 36 | if (!window) //if window does not exist 37 | { 38 | glfwTerminate(); //close context 39 | return 1; 40 | } 41 | //set context to window 42 | glfwMakeContextCurrent(window); 43 | glfwSwapInterval(0); 44 | 45 | if(gl3wInit() != 0) //init gl3w 46 | { 47 | glfwTerminate(); 48 | return 1; 49 | } 50 | return 0; 51 | } 52 | 53 | void simpleRender::clearWindow() 54 | { 55 | glEnable(GL_DEPTH_TEST); 56 | glDepthFunc(GL_LESS); 57 | glEnable(GL_CULL_FACE); 58 | glCullFace(GL_BACK); 59 | 60 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); //clear Color buffer and Depth Buffer 61 | const GLfloat black[] = {116.f/255.0,208.f/255.0,241.f/255.0, 1.0f }; 62 | const GLfloat ones[] = { 1.0f }; 63 | glClearBufferfv(GL_COLOR, 0,black); 64 | glClearBufferfv(GL_DEPTH, 0, ones); 65 | 66 | } 67 | 68 | 69 | void simpleRender::render() 70 | { 71 | /* Swap front and back buffers */ 72 | glfwSwapBuffers(window); 73 | 74 | 75 | /* Poll for and process events */ 76 | glfwPollEvents(); 77 | } 78 | 79 | 80 | 81 | void simpleRender::exit() 82 | { 83 | glfwDestroyWindow(window);//destryo window 84 | glfwTerminate(); //exit glfw 85 | } 86 | 87 | GLFWwindow* simpleRender::getWindow() const 88 | { 89 | return window; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /src/simulation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /* 8 | * File: simulation.cpp 9 | * Author: tg 10 | * 11 | * Created on 27. Oktober 2016, 10:54 12 | */ 13 | 14 | #include "simulation.h" 15 | 16 | 17 | simulation::simulation(unsigned int textureWidth, unsigned int textureHeight) : textureWidth(textureWidth),textureHeight(textureHeight), 18 | v_texData(std::vector(getDataTypeSize()+1)) 19 | { 20 | } 21 | 22 | 23 | void simulation::init() 24 | { 25 | lastSeed = rand(); 26 | 27 | glGenVertexArrays(1, &vao); 28 | glBindVertexArray(vao); 29 | initGUIElements(); 30 | //init Rock 31 | v_texData.at(ROCK) = RendToTex(std::string(SHADER_PATH ) + std::string("simulation/rock/rock_Sim"),textureWidth,textureHeight,GL_RED); 32 | v_texData.at(ROCK).setUniforms({{0.3,"min_therm_limit"},{3.0,"max_therm_limit"},{0.0,"threm_factor"}}); 33 | v_texData.at(ROCK).generateParameterBar(parameterBar,"Rock",{"min=0.0 max = 10.0 step = 0.1","min=0.0 max = 10.0 step = 0.1","min=0.0 max = 5.0 step = 0.1"}); 34 | v_texData.at(ROCK).generateActivationBar(activationBar,"Rock"); 35 | 36 | //init Soil 37 | v_texData.at(SOIL) = RendToTex(std::string(SHADER_PATH ) + "simulation/soil/soil_Sim",textureWidth,textureHeight,GL_RGB); 38 | v_texData.at(SOIL).setUniforms({{1.0,"errodeFactor"},{1.0,"soilDiffuseFactor"}}); 39 | v_texData.at(SOIL).generateParameterBar(parameterBar,"Soil",{"min=0.0 max = 2.0 step = 0.1","min=0.0 max = 2.0 step = 0.1"}); 40 | v_texData.at(SOIL).generateActivationBar(activationBar,"Soil"); 41 | //init Water 42 | v_texData.at(WATER) = RendToTex(std::string(SHADER_PATH ) + "simulation/water/water_Sim",textureWidth,textureHeight,GL_RGB); 43 | v_texData.at(WATER).setUniforms({{1.0,"rain"},{1.0,"evaporate"},{0.95,"sea_level"}}); 44 | v_texData.at(WATER).generateParameterBar(parameterBar,"Water",{"min=0.0 max = 2.0 step = 0.01","min=0.0 max = 2.0 step = 0.01","min=0.0 max = 10.0 step = 0.01"}); 45 | v_texData.at(WATER).generateActivationBar(activationBar,"Water"); 46 | 47 | //init temperature 48 | v_texData.at(TEMP) = RendToTex(std::string(SHADER_PATH ) + "simulation/temp/temp_Sim",textureWidth,textureHeight,GL_RGB); 49 | v_texData.at(TEMP).setUniforms({{0.0,"latFactor"},{0.0,"sunAngle"},{2.5,"heightCooldown"},{0.0,"timeFactorTemp"},{-0.02,"rotationSpeed"},{-0.2,"DayNightFactor"}}); 50 | v_texData.at(TEMP).generateParameterBar(parameterBar,"Temperature",{"min=-5.0 max=5.0 step= 0.1","min=-40 max=40 step = 1.0","min=1.0 max = 7.0 step = 0.1","visible=false","min=-1.0 max = 1.0 step = 0.001","min=-2.0 max = 2.0 step = 0.1"}); 51 | v_texData.at(TEMP).generateActivationBar(activationBar,"Temperature"); 52 | 53 | //init moist 54 | v_texData.at(MOIST) = RendToTex(std::string(SHADER_PATH ) + "simulation/moist/moist_Sim",textureWidth,textureHeight,GL_RGB); 55 | v_texData.at(MOIST).setUniforms({{1.0,"waterAddFactor"},{0.0,"landRemoveFactor"}}); 56 | v_texData.at(MOIST).generateParameterBar(parameterBar,"Moist",{"min=0.0 max=5.0 step= 0.1","min=0.0 max=5.0 step = 0.1"}); 57 | v_texData.at(MOIST).generateActivationBar(activationBar,"Moist"); 58 | 59 | //init wind 60 | v_texData.at(WIND) = RendToTex(std::string(SHADER_PATH ) + "simulation/wind/wind_Sim",textureWidth,textureHeight,GL_RGB); 61 | v_texData.at(WIND).setUniforms({{1.0,"distorsionFaktor"},{1.0,"globelWindFaktor"},{1.0,"localPressureFaktor"},{0.0,"timeFactorWind"},{0.001,"windspeed"},{1.1,"windNoiseRoughness"},{4,"windNoiseTurbulence"}}); 62 | v_texData.at(WIND).generateParameterBar(parameterBar,"Wind",{"min=-2.0 max=2.0 step=0.1","min=-2.0 max = 2.0 step = 0.1","min=-2.0 max = 2.0 step = 0.1","visible=false","min=-1.0 max = 1.0 step = 0.001","min=0.0 max = 8.0 step = 0.1","min=1 max = 20 step = 1"}); 63 | v_texData.at(WIND).generateActivationBar(activationBar,"Wind"); 64 | windNoiseID = TextureLoader::generateNoiseTexture(textureWidth, textureHeight,rand(),v_texData.at(WIND).getParameterValue("windNoiseRoughness"),v_texData.at(WIND).getParameterValue("windNoiseTurbulence")); 65 | TwAddButton(parameterBar,"New Distortion",[](void* client_data) 66 | { 67 | simulation* tmpPointer = static_cast(client_data); 68 | glDeleteTextures(1, &tmpPointer->windNoiseID); 69 | tmpPointer->windNoiseID = TextureLoader::generateNoiseTexture(tmpPointer->textureWidth,tmpPointer->textureHeight,rand(),tmpPointer->v_texData[WIND].getParameterValue("windNoiseRoughness"),tmpPointer->v_texData.at(WIND).getParameterValue("windNoiseTurbulence")); 70 | } 71 | ,this,"group='Wind' " ); 72 | 73 | 74 | //init ice 75 | v_texData.at(ICE) = RendToTex(std::string(SHADER_PATH ) + "simulation/ice/ice_Sim",textureWidth,textureHeight,GL_RGB); 76 | v_texData.at(ICE).setUniforms({{-0.7,"iceTemperature"}}); 77 | v_texData.at(ICE).generateParameterBar(parameterBar,"Ice",{"min=-1.0 max=1.0 step=0.1"}); 78 | v_texData.at(ICE).generateActivationBar(activationBar,"Ice"); 79 | 80 | //init climat 81 | v_texData.at(CLIMAT) = RendToTex(std::string(SHADER_PATH ) + "simulation/climat/climat",textureWidth,textureHeight,GL_RGB); 82 | 83 | 84 | glBindVertexArray(0); 85 | } 86 | 87 | void simulation::initGUIElements() 88 | { 89 | TwEnumVal twdisplayEnum[] = { {DataType::ROCK, "Rock"}, {DataType::SOIL, "Soil"}, {DataType::WATER, "Water"}, {DataType::TEMP, "Temp"}, 90 | {DataType::MOIST, "Moist"}, {DataType::WIND, "Wind"}, {DataType::ICE, "Ice"}, {DataType::CLIMAT, "Climat"}, {DataType::render3D, "3D"}}; 91 | TwType twDisplay; 92 | // Defining season enum type 93 | twDisplay = TwDefineEnum("SeasonType", twdisplayEnum, 9); 94 | parameterBar = inputHandler::createNewBar("Parameters","position='8 8' size='200 500'"); 95 | activationBar = inputHandler::createNewBar("Activation","position='208 8' size='200 400'"); 96 | general = inputHandler::createNewBar("General","position='408 8' size='200 130'"); 97 | 98 | TwAddVarRW(general, "Current Display", twDisplay, ¤tDisplay, NULL); 99 | 100 | TwAddButton(general,"Restart",[](void *clientData){static_cast(clientData)->restart();},this,"help='Restart this world.' "); 101 | TwAddButton(general,"New World",[](void *clientData){static_cast(clientData)->newWorld();},this,"help='Create a new World.' "); 102 | TwAddButton(general,"Export",[](void *clientData){static_cast(clientData)->saveTextures();},this,"help='Export all textures.' "); 103 | TwAddVarRW(general,"Pause all", TW_TYPE_BOOLCPP,&this->pause,"help='Pause the simulation' "); 104 | } 105 | 106 | void simulation::initLithosphere(float sea_level, float _folding_ratio, uint32_t aggr_ratio_abs, float aggr_ratio_rel, uint32_t _max_plates, float terrainNoiseRoughness) 107 | { 108 | tectonicSeaLevel = sea_level; 109 | this->terrainNoiseRoughness =terrainNoiseRoughness; 110 | ground = std::unique_ptr(new lithosphere(lastSeed, textureWidth, textureHeight,tectonicSeaLevel,_folding_ratio,aggr_ratio_abs,aggr_ratio_rel,_max_plates,terrainNoiseRoughness)); 111 | glClampColor(0x891A, GL_FALSE); 112 | glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); 113 | glClampColor(0x891B, GL_FALSE); 114 | v_texData.at(ROCK).setTexture(ground->getTopography()); 115 | glClampColor(0x891A, GL_TRUE); 116 | glClampColor(GL_CLAMP_READ_COLOR, GL_TRUE); 117 | glClampColor(0x891B, GL_TRUE); 118 | 119 | 120 | // TwAddVarRW(parameterBar,"update Rate",TW_TYPE_UINT32,&tectonicUpdate,"group='Tectonic' min=0.0 max = 100.0 step=1.0 help='Tectonic update Rate.'" ); 121 | TwAddVarRW(parameterBar,"Noise Roughness",TW_TYPE_FLOAT,&this->terrainNoiseRoughness,"group='Tectonic' max=4 min = 0.1 step=0.1 help='set roughness of terrain' " ); 122 | TwAddVarRW(parameterBar,"SeaLevel",TW_TYPE_FLOAT,&tectonicSeaLevel,"group='Tectonic' max=1.0 min = 0.0 step=0.02 help='set sea Level for next terrain' " ); 123 | TwAddVarRW(parameterBar,"max Plates",TW_TYPE_UINT32,&ground->max_plates,"group='Tectonic' min=1.0 max = 10.0 help='Max Plate count for next start.'" ); 124 | TwAddVarRW(parameterBar,"Folding Ratio",TW_TYPE_FLOAT,&ground->folding_ratio,"group='Tectonic' max=1.0 min=0.0 step='0.001' help='Percent of overlapping crust that is folded.' " ); 125 | TwAddVarRW(parameterBar,"Aggr Overlap Rel",TW_TYPE_FLOAT,&ground->aggr_overlap_rel,"group='Tectonic' max=3.00 min=0.0 step='0.03' help='% of overlapping area -> aggregation.' " ); 126 | TwAddVarRW(parameterBar,"Aggr Overlap Abs",TW_TYPE_UINT32,&ground->aggr_overlap_abs,"group='Tectonic' max=8000000 min=0.0 step='2000' help='# of overlapping pixels -> aggregation.' " ); 127 | 128 | auto lam = [](void *clientData) 129 | { 130 | simulation* tmpPointer = static_cast(clientData); 131 | if(tmpPointer->enable_tectonic == false) 132 | { 133 | tmpPointer->lastSeaLevel = tmpPointer->v_texData[WATER].getParameterValue("sea_level"); 134 | tmpPointer->v_texData.at(WATER).setParameterValue("sea_level",0.0); 135 | tmpPointer->v_texData.at(WATER).reset(); 136 | tmpPointer->v_texData.at(WATER).setEnable(false); 137 | tmpPointer->enable_tectonic = true; 138 | } 139 | else 140 | { 141 | tmpPointer->v_texData.at(WATER).setParameterValue("sea_level",tmpPointer->lastSeaLevel); 142 | tmpPointer->v_texData.at(WATER).setEnable(true); 143 | tmpPointer->enable_tectonic = false; 144 | } 145 | 146 | }; 147 | TwAddButton(activationBar,"enable/disable",lam,this,"group='Tectonic' help='Enable/Disable tectonic update.' " ); 148 | 149 | TwAddButton(activationBar,"New Tectonic",[](void *clientData){static_cast(clientData)->restart();},ground.get(),"group='Tectonic' help='Generate new Plates.'" ); 150 | 151 | 152 | } 153 | GLuint simulation::getTextureID(const DataType type) 154 | { 155 | return v_texData.at(std::min(type,DataType::CLIMAT)).getSourceTexture(); 156 | } 157 | 158 | 159 | void simulation::update() 160 | { 161 | if(pause) 162 | return; 163 | glViewport(0,0,textureWidth,textureHeight); 164 | glBindVertexArray(vao); 165 | glActiveTexture(GL_TEXTURE8); 166 | glBindTexture(GL_TEXTURE_2D, windNoiseID); 167 | 168 | v_texData.at(WIND).setParameterValue( "timeFactorWind",v_texData.at(WIND).getParameterValue("timeFactorWind")+v_texData.at(WIND).getParameterValue("windspeed")); 169 | v_texData.at(TEMP).setParameterValue( "timeFactorTemp",v_texData.at(TEMP).getParameterValue("timeFactorTemp")+v_texData.at(TEMP).getParameterValue("rotationSpeed")); 170 | 171 | //0891A = GL_CLAMP_VERTEX_COLOR, 0x891B = GL_CLAMP_FRAGMENT_COLOR 172 | glClampColor(0x891A, GL_FALSE); 173 | glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); 174 | glClampColor(0x891B, GL_FALSE); 175 | 176 | if(enable_tectonic) 177 | { 178 | ground->setTopography(v_texData.at(ROCK).getTexture()); 179 | ground->update(); 180 | v_texData.at(ROCK).setTexture(ground->getTopography()); 181 | } 182 | 183 | setTexturesBindings(); 184 | 185 | std::for_each(v_texData.begin(), v_texData.end() ,[&](auto& data) 186 | { data.update(); 187 | }); 188 | 189 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 190 | 191 | glActiveTexture(GL_TEXTURE8); 192 | glBindTexture(GL_TEXTURE_2D, 0); 193 | 194 | glClampColor(0x891A, GL_TRUE); 195 | glClampColor(GL_CLAMP_READ_COLOR, GL_TRUE); 196 | glClampColor(0x891B, GL_TRUE); 197 | glBindVertexArray(0); 198 | 199 | std::for_each(v_texData.begin(), v_texData.end(),[&](auto& data) 200 | { data.swapTexture(); 201 | }); 202 | unsetTexturesBindings(); 203 | } 204 | 205 | void simulation::restart() 206 | { 207 | std::for_each(v_texData.begin(), v_texData.end() ,[&](auto& data) 208 | { data.reset(); 209 | }); 210 | 211 | 212 | 213 | TwRemoveVar(parameterBar,"Noise Roughness" ); 214 | TwRemoveVar(parameterBar,"SeaLevel"); 215 | TwRemoveVar(parameterBar,"max Plates"); 216 | TwRemoveVar(parameterBar,"Folding Ratio" ); 217 | TwRemoveVar(parameterBar,"Aggr Overlap Rel"); 218 | TwRemoveVar(parameterBar,"Aggr Overlap Abs"); 219 | TwRemoveVar(activationBar,"New Tectonic"); 220 | 221 | initLithosphere(tectonicSeaLevel,ground->folding_ratio,ground->aggr_overlap_abs,ground->aggr_overlap_rel,ground->max_plates,terrainNoiseRoughness); 222 | } 223 | 224 | 225 | 226 | void simulation::newWorld() 227 | { 228 | lastSeed = rand(); 229 | glDeleteTextures(1,&windNoiseID); 230 | windNoiseID = TextureLoader::generateNoiseTexture(textureWidth, textureHeight,rand(),v_texData.at(WIND).getParameterValue("windNoiseRoughness"),v_texData.at(WIND).getParameterValue("windNoiseTurbulence")); 231 | 232 | 233 | restart(); 234 | } 235 | 236 | 237 | 238 | void simulation::exit() 239 | { 240 | glDeleteVertexArrays(1,&vao); 241 | glDeleteTextures(1,&windNoiseID); 242 | std::for_each(v_texData.begin(), v_texData.end(),[](auto& data){data.exit();}); 243 | } 244 | 245 | simulation::DataType simulation::getCurrentDisplay() const 246 | { 247 | return currentDisplay; 248 | } 249 | 250 | void simulation::setTexturesBindings() 251 | { 252 | //set texture bindings 253 | for(int i = 0; i <= CLIMAT; ++i) 254 | { 255 | glActiveTexture(GL_TEXTURE0 + i); 256 | glBindTexture(GL_TEXTURE_2D, v_texData.at(i).getSourceTexture()); 257 | } 258 | 259 | } 260 | 261 | void simulation::unsetTexturesBindings() 262 | { 263 | 264 | 265 | for(int i = CLIMAT; i >= 0 ; --i) 266 | { 267 | glActiveTexture(GL_TEXTURE0 + i); 268 | glBindTexture(GL_TEXTURE_2D, 0); 269 | } 270 | } 271 | 272 | 273 | 274 | void simulation::saveTextures() 275 | { 276 | int i= 0; 277 | std::vector names = {"Rock","Soil"," Water","Temp","Moist","Wind","Ice","Climat"}; 278 | for(auto& val : v_texData) 279 | { 280 | ILuint index = val.prepareExport(); 281 | TextureLoader::SaveTexture(textureWidth,textureHeight,std::string(OUTPUT_PATH) + names.at(i) + "_data.png",index); 282 | ++i; 283 | ilDeleteImage(index); 284 | } 285 | 286 | } --------------------------------------------------------------------------------