├── HeightmapRenderer ├── Commons.cpp ├── Thumbs.db ├── Resources │ ├── Textures │ │ ├── 4141.jpg │ │ ├── Ground10_1.jpg │ │ ├── texture11.jpg │ │ ├── Deep-Freeze.jpg │ │ ├── Dry Grass 2.jpg │ │ ├── Windshield 7 AM.jpg │ │ ├── brokenground_1.jpg │ │ ├── snow_scuffed_ground_1.jpg │ │ ├── grass_leaves_0039_01_preview.jpg │ │ ├── Seamless_grass_texture_by_hhh316.jpg │ │ ├── rough_sand_texture_seamless_by_hhh316-d5r36ec.jpg │ │ ├── seamless_beach_sand_texture_by_hhh316-d4gc86s.jpg │ │ ├── seamless_rock_face_texture_by_hhh316-d4hqxwx.jpg │ │ ├── imgui.ini │ │ └── depositphotos_30900321-Seamless-Texture-of-Rocky-Steppe-Soil..jpg │ └── Shaders │ │ ├── phong.vert │ │ ├── phong.frag │ │ └── terrain.vert ├── LibNoise │ └── include │ │ ├── readme.txt │ │ └── noise │ │ ├── model │ │ ├── model.h │ │ ├── plane.h │ │ ├── sphere.h │ │ ├── cylinder.h │ │ └── line.h │ │ ├── mathconsts.h │ │ ├── module │ │ ├── module.h │ │ ├── invert.h │ │ ├── max.h │ │ ├── min.h │ │ ├── multiply.h │ │ ├── abs.h │ │ ├── add.h │ │ ├── power.h │ │ ├── checkerboard.h │ │ ├── const.h │ │ ├── cache.h │ │ ├── exponent.h │ │ ├── spheres.h │ │ ├── cylinders.h │ │ ├── scalebias.h │ │ ├── clamp.h │ │ ├── blend.h │ │ ├── curve.h │ │ ├── scalepoint.h │ │ ├── rotatepoint.h │ │ └── translatepoint.h │ │ ├── basictypes.h │ │ ├── latlon.h │ │ ├── exception.h │ │ ├── misc.h │ │ ├── noise.h │ │ ├── interp.h │ │ └── noisegen.h ├── main.cpp ├── imgui.ini ├── TerrainQuadtree.cpp ├── app_0.log ├── OpenFileDialog.h ├── TerrainQuadtree.h ├── TerrainMultiTexture.h ├── MainWindow.cpp ├── AppInterface.h ├── OpenFileDialog.cpp ├── TransformationMatrices.h ├── MainWindow.h ├── App.h ├── TransformationMatrices.cpp ├── TerrainChunksGenerator.h ├── Heightmap.h ├── ChunkDetailLevel.cpp ├── Camera.h ├── ChunkDetailLevel.h ├── Commons.h ├── Heightmap.cpp ├── TerrainChunk.h ├── TerrainMultiTexture.cpp ├── TerrainChunksGenerator.cpp ├── HeightmapRenderer.vcxproj.filters ├── Camera.cpp ├── Terrain.h └── HeightmapRenderer.vcxproj ├── README.md ├── HeightmapRenderer.sln ├── .gitattributes └── .gitignore /HeightmapRenderer/Commons.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" -------------------------------------------------------------------------------- /HeightmapRenderer/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Thumbs.db -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/4141.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/4141.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multitexture Terrain Rendering 2 | 3 | Using heightmaps, libnoise for heightmap generation 4 | 5 | ![Screenshot](http://i.imgur.com/oJENm85.jpg) 6 | -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/Ground10_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/Ground10_1.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/texture11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/texture11.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/Deep-Freeze.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/Deep-Freeze.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/Dry Grass 2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/Dry Grass 2.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/Windshield 7 AM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/Windshield 7 AM.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/brokenground_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/brokenground_1.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/readme.txt: -------------------------------------------------------------------------------- 1 | noiseutils library - differences between 0.9.0 and 0.9.0.1 2 | 3 | - Added the noiseutils classes to the noise::utils namespace. 4 | 5 | -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/snow_scuffed_ground_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/snow_scuffed_ground_1.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "App.h" 3 | 4 | int main(void) 5 | { 6 | std::unique_ptr app(App::Instance()); 7 | // start app 8 | app->Run(); 9 | } -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/grass_leaves_0039_01_preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/grass_leaves_0039_01_preview.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/Seamless_grass_texture_by_hhh316.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/Seamless_grass_texture_by_hhh316.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/rough_sand_texture_seamless_by_hhh316-d5r36ec.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/rough_sand_texture_seamless_by_hhh316-d5r36ec.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/seamless_beach_sand_texture_by_hhh316-d4gc86s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/seamless_beach_sand_texture_by_hhh316-d4gc86s.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/seamless_rock_face_texture_by_hhh316-d4hqxwx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/seamless_rock_face_texture_by_hhh316-d4hqxwx.jpg -------------------------------------------------------------------------------- /HeightmapRenderer/imgui.ini: -------------------------------------------------------------------------------- 1 | [Debug] 2 | Pos=427,241 3 | Size=400,400 4 | Collapsed=0 5 | 6 | [Shadow Map] 7 | Pos=60,60 8 | Size=38,32 9 | Collapsed=0 10 | 11 | [ImGui Test] 12 | Pos=506,48 13 | Size=550,680 14 | Collapsed=0 15 | 16 | -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/imgui.ini: -------------------------------------------------------------------------------- 1 | [Debug] 2 | Pos=427,241 3 | Size=400,400 4 | Collapsed=0 5 | 6 | [Shadow Map] 7 | Pos=60,60 8 | Size=38,32 9 | Collapsed=0 10 | 11 | [ImGui Test] 12 | Pos=506,48 13 | Size=550,680 14 | Collapsed=0 15 | 16 | -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Textures/depositphotos_30900321-Seamless-Texture-of-Rocky-Steppe-Soil..jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jose-villegas/TerrainRendering/HEAD/HeightmapRenderer/Resources/Textures/depositphotos_30900321-Seamless-Texture-of-Rocky-Steppe-Soil..jpg -------------------------------------------------------------------------------- /HeightmapRenderer/TerrainQuadtree.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "TerrainQuadtree.h" 3 | 4 | 5 | TerrainQuadtree::TerrainQuadtree() 6 | { 7 | } 8 | 9 | 10 | TerrainQuadtree::~TerrainQuadtree() 11 | { 12 | } 13 | 14 | float Node::heightScale; 15 | 16 | float Node::horizontalScale; 17 | -------------------------------------------------------------------------------- /HeightmapRenderer/app_0.log: -------------------------------------------------------------------------------- 1 | 2015-04-10 18:07:40:1 GLFW 3.1.1 Win32 WGL VisualC 2 | 2015-04-10 18:07:40:2 OpenGL 3.3.11672 Compatibility Profile Contexts, GLSL 3.30 3 | 2015-04-10 18:07:40:3 Boost 1.57.0 4 | 2015-04-10 18:07:40:4 Ocornut's IMGUI 1.38 WIP 5 | 2015-04-10 18:07:40:5 FreeImage 3.17.0 6 | -------------------------------------------------------------------------------- /HeightmapRenderer/OpenFileDialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | class OpenFileDialog 5 | { 6 | public: 7 | OpenFileDialog(void); 8 | 9 | TCHAR*DefaultExtension; 10 | TCHAR*FileName; 11 | TCHAR*Filter; 12 | int FilterIndex; 13 | int Flags; 14 | TCHAR*InitialDir; 15 | HWND Owner; 16 | TCHAR*Title; 17 | 18 | bool ShowDialog(); 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Shaders/phong.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform mat4 ProjectionMatrix, CameraMatrix; 4 | uniform vec3 LightPos; 5 | 6 | layout(location = 0) in vec4 Position; 7 | layout(location = 1) in vec3 Normal; 8 | layout(location = 2) in vec3 TexCoords; 9 | 10 | out vec3 vertNormal; 11 | out vec3 vertViewDir; 12 | out vec3 lightPos; 13 | out float height; 14 | 15 | void main(void) 16 | { 17 | vertNormal = Normal; 18 | vertViewDir = (vec4(0.0, 0.0, 1.0, 1.0) * CameraMatrix).xyz; 19 | gl_Position = ProjectionMatrix * CameraMatrix * Position; 20 | lightPos = (ProjectionMatrix * CameraMatrix * vec4(LightPos, 1.0)).xyz; 21 | height = Position.y; 22 | } -------------------------------------------------------------------------------- /HeightmapRenderer/TerrainQuadtree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TerrainChunk.h" 3 | 4 | class Node 5 | { 6 | private: 7 | // shared data between nodes 8 | static float heightScale; 9 | static float horizontalScale; 10 | private: 11 | std::array edges; 12 | glm::vec3 centerPoint; 13 | std::vector chunks; 14 | public: 15 | Node *parent; 16 | std::array children; 17 | std::array neighbor; 18 | }; 19 | 20 | class TerrainQuadtree 21 | { 22 | private: 23 | std::unique_ptr root; 24 | public: 25 | TerrainQuadtree(); 26 | ~TerrainQuadtree(); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /HeightmapRenderer/TerrainMultiTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | using namespace oglplus; 3 | 4 | class TerrainMultiTexture 5 | { 6 | private: 7 | static const int MAX_TERRAIN_TEXTURE_RANGES = 4; 8 | 9 | Texture texture; 10 | std::array uiTextures; 11 | Context gl; 12 | // range 13 | GLfloat ranges[MAX_TERRAIN_TEXTURE_RANGES * 3]; 14 | 15 | public: 16 | void loadTexture(const std::string &filepath, const int index); 17 | TerrainMultiTexture(); 18 | ~TerrainMultiTexture(); 19 | 20 | void SetTextureRange(const int index, const float start, const float end); 21 | void SetUniforms(Program &program); 22 | GLuint UITextureId(const int index); 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /HeightmapRenderer/MainWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "MainWindow.h" 3 | 4 | GLFWwindow* MainWindow::currentContext = nullptr; 5 | 6 | MainWindow::MainWindow(const std::string &windowTitle, const unsigned int width, 7 | const unsigned int height, GLFWmonitor* monitor /* = nullptr */, 8 | GLFWwindow * share /* = nullptr */) : window(glfwCreateWindow(width, height, 9 | windowTitle.c_str(), monitor, share), glfwDestroyWindow) 10 | { 11 | if(!window) 12 | { 13 | throw std::runtime_error("GLFW3 failed to create a window"); 14 | } 15 | 16 | // set internal class values 17 | this->width = width; 18 | this->height = height; 19 | this->title = windowTitle; 20 | this->monitor = monitor; 21 | this->share = share; 22 | } 23 | 24 | void MainWindow::makeCurrentContext() 25 | { 26 | glfwMakeContextCurrent(this->getWindow()); 27 | currentContext = this->getWindow(); 28 | } -------------------------------------------------------------------------------- /HeightmapRenderer/AppInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Terrain.h" 3 | 4 | class AppInterface 5 | { 6 | public: 7 | float maxHeight; 8 | int meshResolution; 9 | int heightmapResolution; 10 | bool wireframeMode; 11 | float terrainScale; 12 | float ranges[8]; 13 | float terrainRange[3]; 14 | oglplus::Context gl; 15 | float textureRepeat[2]; 16 | bool colorGrading; 17 | float timeScale; 18 | bool pauseTime; 19 | int lightmapFreqAndSize[2]; 20 | int terrainSeed; 21 | bool terrainSeedSet; 22 | bool useRandom; 23 | int occlusionStrenght; 24 | bool geomipmapping; 25 | float geoThreeshold; 26 | bool showBBoxes; 27 | bool frustumCulling; 28 | void initialize(GLFWwindow * window); 29 | void draw(float time); 30 | void render(); 31 | void terminate(); 32 | 33 | AppInterface(); 34 | ~AppInterface(); 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /HeightmapRenderer.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HeightmapRenderer", "HeightmapRenderer\HeightmapRenderer.vcxproj", "{84D4B305-9D38-4B5A-9A15-6DDFEE6D0705}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {84D4B305-9D38-4B5A-9A15-6DDFEE6D0705}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {84D4B305-9D38-4B5A-9A15-6DDFEE6D0705}.Debug|Win32.Build.0 = Debug|Win32 16 | {84D4B305-9D38-4B5A-9A15-6DDFEE6D0705}.Release|Win32.ActiveCfg = Release|Win32 17 | {84D4B305-9D38-4B5A-9A15-6DDFEE6D0705}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /HeightmapRenderer/OpenFileDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "OpenFileDialog.h" 3 | 4 | 5 | OpenFileDialog::OpenFileDialog() 6 | { 7 | this->DefaultExtension = 0; 8 | this->FileName = new TCHAR[MAX_PATH]; 9 | this->Filter = 0; 10 | this->FilterIndex = 0; 11 | this->Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; 12 | this->InitialDir = 0; 13 | this->Owner = 0; 14 | this->Title = 0; 15 | } 16 | 17 | bool OpenFileDialog::ShowDialog() 18 | { 19 | OPENFILENAME ofn; 20 | ZeroMemory(&ofn, sizeof(ofn)); 21 | ofn.lStructSize = sizeof(ofn); 22 | ofn.hwndOwner = this->Owner; 23 | ofn.lpstrDefExt = this->DefaultExtension; 24 | ofn.lpstrFile = this->FileName; 25 | ofn.lpstrFile[0] = '\0'; 26 | ofn.nMaxFile = MAX_PATH; 27 | ofn.lpstrFilter = this->Filter; 28 | ofn.nFilterIndex = this->FilterIndex; 29 | ofn.lpstrInitialDir = this->InitialDir; 30 | ofn.lpstrTitle = this->Title; 31 | ofn.Flags = this->Flags; 32 | GetOpenFileName(&ofn); 33 | 34 | if(_tcslen(this->FileName) == 0) return false; 35 | 36 | return true; 37 | } -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Shaders/phong.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec3 vertNormal; 4 | in vec3 vertViewDir; 5 | in vec3 lightPos; 6 | in float height; 7 | 8 | out vec4 fragColor; 9 | 10 | float blinnPhongSpecular(vec3 lightDirection, vec3 viewDirection, 11 | vec3 surfaceNormal, float shininess) 12 | { 13 | //Calculate Blinn-Phong power 14 | vec3 H = normalize(viewDirection + lightDirection); 15 | return pow(max(0.0, dot(surfaceNormal, H)), shininess); 16 | } 17 | 18 | float lambert(vec3 surfaceNormal, vec3 lightDirection) 19 | { 20 | return max(dot(surfaceNormal, lightDirection), 0.0f); 21 | } 22 | 23 | void main(void) 24 | { 25 | vec3 matColor = vec3(log(height + 1), 0.1, 0.1); 26 | vec3 normal = normalize(vertNormal); 27 | float amb = 0.2; 28 | float diff = 0.0; 29 | float spec = 0.0; 30 | // calculate shading 31 | diff += lambert(normal, lightPos); 32 | 33 | if(diff > 0.0f) 34 | { 35 | spec += blinnPhongSpecular(lightPos, vertViewDir, normal, 16.0f); 36 | } 37 | 38 | fragColor = vec4(matColor, 1.0) * ((diff + spec) + amb); 39 | } -------------------------------------------------------------------------------- /HeightmapRenderer/TransformationMatrices.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class TransformationMatrices 4 | { 5 | private: 6 | static bool projectionMatrixChanged, viewMatrixChanged, modelMatrixChanged; 7 | 8 | static glm::mat4 model; 9 | static glm::mat4 view; 10 | static glm::mat4 projection; 11 | static glm::mat4 normal; 12 | static glm::mat4 modelView; 13 | static glm::mat4 modelViewProjection; 14 | static glm::mat4 viewProjection; 15 | public: 16 | static const glm::mat4 &Projection() { return projection; }; 17 | static const glm::mat4 &View() { return view; }; 18 | static const glm::mat4 &Model() { return model; }; 19 | 20 | static const glm::mat4 &Normal(); 21 | static const glm::mat4 &ModelView(); 22 | static const glm::mat4 &ModelViewProjection(); 23 | 24 | static void Projection(const glm::mat4 &matrix); 25 | static void View(const glm::mat4 &matrix); 26 | static void Model(const glm::mat4 &matrix); 27 | private: 28 | TransformationMatrices(); 29 | ~TransformationMatrices(); 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/model/model.h: -------------------------------------------------------------------------------- 1 | // model.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODEL_H 24 | #define NOISE_MODEL_H 25 | 26 | #include "cylinder.h" 27 | #include "line.h" 28 | #include "plane.h" 29 | #include "sphere.h" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /HeightmapRenderer/MainWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class MainWindow 4 | { 5 | private: 6 | static GLFWwindow* currentContext; 7 | std::unique_ptr window; 8 | // no copy constructor 9 | MainWindow(const MainWindow &rhs); 10 | 11 | public: 12 | MainWindow(const std::string &windowTitle, const unsigned int width, 13 | const unsigned int height, GLFWmonitor* monitor = nullptr, 14 | GLFWwindow * share = nullptr); 15 | virtual ~MainWindow() { this->window.reset(); }; 16 | // return glfw raw window pointer 17 | GLFWwindow * getWindow() const { return this->window.get(); }; 18 | // set up as current rendering context 19 | void makeCurrentContext(); 20 | 21 | const unsigned int windowWidth() { glfwGetWindowSize(this->window.get(), &this->width, &this->height); return width; } 22 | const unsigned int windowHeight() { glfwGetWindowSize(this->window.get(), &this->width, &this->height); return height; } 23 | 24 | protected: 25 | int width; 26 | int height; 27 | std::string title; 28 | GLFWmonitor *monitor; 29 | GLFWwindow *share; 30 | // window handling methods 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /HeightmapRenderer/App.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MainWindow.h" 3 | #include "Terrain.h" 4 | #include "AppInterface.h" 5 | #include "Camera.h" 6 | 7 | class App 8 | { 9 | private: 10 | static oglplus::Context gl; 11 | static App *instance; 12 | bool moveAround = false; 13 | 14 | MainWindow * appWindow; 15 | Camera camera; 16 | Terrain terrain; 17 | AppInterface gui; 18 | 19 | void handleUserInput(GLFWwindow * window, float deltaTime); 20 | 21 | App(const App &rhs); 22 | App(); 23 | // app callbacks 24 | static void onError(int code, const char * description); 25 | static void onKeyPress(GLFWwindow *window, int key, int scancode, int action, 26 | int mods); 27 | static void onMouseWheel(GLFWwindow *window, double xoffset, double yoffset); 28 | static void onWindowResize(GLFWwindow *window, int width, int height); 29 | // app libraries configuration 30 | void Configure(); 31 | MainWindow * CreateContext(); 32 | // app render loop 33 | void Start(); 34 | public: 35 | static App * Instance(); 36 | void Run(); 37 | Terrain &getTerrain() { return terrain; } 38 | Camera &getCamera() { return camera; } 39 | AppInterface &Gui() { return gui; } 40 | 41 | ~App(); 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/mathconsts.h: -------------------------------------------------------------------------------- 1 | // mathconsts.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MATHCONSTS_H 24 | #define NOISE_MATHCONSTS_H 25 | 26 | // For whatever reason, I can't find the basic math consts in the MSVC version 27 | // of math.h. 28 | 29 | namespace noise 30 | { 31 | 32 | /// @addtogroup libnoise 33 | /// @{ 34 | 35 | /// Pi. 36 | const double PI = 3.1415926535897932385; 37 | 38 | /// Square root of 2. 39 | const double SQRT_2 = 1.4142135623730950488; 40 | 41 | /// Square root of 3. 42 | const double SQRT_3 = 1.7320508075688772935; 43 | 44 | /// Converts an angle from degrees to radians. 45 | const double DEG_TO_RAD = PI / 180.0; 46 | 47 | /// Converts an angle from radians to degrees. 48 | const double RAD_TO_DEG = 1.0 / DEG_TO_RAD; 49 | 50 | /// @} 51 | 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/module.h: -------------------------------------------------------------------------------- 1 | // module.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_H 24 | #define NOISE_MODULE_H 25 | 26 | #include "add.h" 27 | #include "abs.h" 28 | #include "billow.h" 29 | #include "blend.h" 30 | #include "cache.h" 31 | #include "checkerboard.h" 32 | #include "clamp.h" 33 | #include "const.h" 34 | #include "curve.h" 35 | #include "cylinders.h" 36 | #include "displace.h" 37 | #include "exponent.h" 38 | #include "invert.h" 39 | #include "max.h" 40 | #include "min.h" 41 | #include "multiply.h" 42 | #include "perlin.h" 43 | #include "power.h" 44 | #include "ridgedmulti.h" 45 | #include "rotatepoint.h" 46 | #include "scalebias.h" 47 | #include "scalepoint.h" 48 | #include "select.h" 49 | #include "spheres.h" 50 | #include "terrace.h" 51 | #include "translatepoint.h" 52 | #include "turbulence.h" 53 | #include "voronoi.h" 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/basictypes.h: -------------------------------------------------------------------------------- 1 | // basictypes.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_BASICTYPES_H 24 | #define NOISE_BASICTYPES_H 25 | 26 | // You may need to modify these constants for your compiler or platform. 27 | 28 | namespace noise 29 | { 30 | 31 | /// @defgroup libnoise libnoise 32 | /// @addtogroup libnoise 33 | /// @{ 34 | 35 | /// Unsigned integer type. 36 | typedef unsigned int uint; 37 | 38 | /// 32-bit unsigned integer type. 39 | typedef unsigned int uint32; 40 | 41 | /// 16-bit unsigned integer type. 42 | typedef unsigned short uint16; 43 | 44 | /// 8-bit unsigned integer type. 45 | typedef unsigned char uint8; 46 | 47 | /// 32-bit signed integer type. 48 | typedef int int32; 49 | 50 | /// 16-bit signed integer type. 51 | typedef short int16; 52 | 53 | /// 8-bit signed integer type. 54 | typedef char int8; 55 | 56 | /// @} 57 | 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /HeightmapRenderer/TransformationMatrices.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "TransformationMatrices.h" 3 | #include "App.h" 4 | 5 | bool TransformationMatrices::modelMatrixChanged = false; 6 | bool TransformationMatrices::projectionMatrixChanged = false; 7 | bool TransformationMatrices::viewMatrixChanged = false; 8 | 9 | glm::mat4 TransformationMatrices::model = glm::mat4(1); 10 | glm::mat4 TransformationMatrices::view = glm::mat4(1); 11 | glm::mat4 TransformationMatrices::projection = glm::mat4(1); 12 | glm::mat4 TransformationMatrices::normal = glm::mat4(1); 13 | glm::mat4 TransformationMatrices::modelView = glm::mat4(1); 14 | glm::mat4 TransformationMatrices::modelViewProjection = glm::mat4(1); 15 | glm::mat4 TransformationMatrices::viewProjection = glm::mat4(1); 16 | 17 | const glm::mat4 & TransformationMatrices::ModelViewProjection() 18 | { 19 | viewProjection = projection * view; 20 | // update frustum planes 21 | App::Instance()->getCamera().calcPlanes(viewProjection); 22 | modelViewProjection = viewProjection * model; 23 | // return new matrix 24 | return modelViewProjection; 25 | } 26 | 27 | const glm::mat4 & TransformationMatrices::ModelView() 28 | { 29 | modelView = view * model; 30 | return modelView; 31 | } 32 | 33 | const glm::mat4 & TransformationMatrices::Normal() 34 | { 35 | normal = glm::transpose(glm::inverse(modelView)); 36 | return normal; 37 | } 38 | 39 | void TransformationMatrices::Projection(const glm::mat4 &matrix) 40 | { 41 | projection = matrix; 42 | } 43 | 44 | void TransformationMatrices::View(const glm::mat4 &matrix) 45 | { 46 | view = matrix; 47 | } 48 | 49 | void TransformationMatrices::Model(const glm::mat4 &matrix) 50 | { 51 | model = matrix; 52 | } 53 | 54 | TransformationMatrices::TransformationMatrices() 55 | { 56 | } 57 | 58 | 59 | TransformationMatrices::~TransformationMatrices() 60 | { 61 | } 62 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/latlon.h: -------------------------------------------------------------------------------- 1 | // latlon.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_LATLON_H 24 | #define NOISE_LATLON_H 25 | 26 | #include 27 | #include "mathconsts.h" 28 | 29 | namespace noise 30 | { 31 | 32 | /// @addtogroup libnoise 33 | /// @{ 34 | 35 | /// Converts latitude/longitude coordinates on a unit sphere into 3D 36 | /// Cartesian coordinates. 37 | /// 38 | /// @param lat The latitude, in degrees. 39 | /// @param lon The longitude, in degrees. 40 | /// @param x On exit, this parameter contains the @a x coordinate. 41 | /// @param y On exit, this parameter contains the @a y coordinate. 42 | /// @param z On exit, this parameter contains the @a z coordinate. 43 | /// 44 | /// @pre lat must range from @b -90 to @b +90. 45 | /// @pre lon must range from @b -180 to @b +180. 46 | void LatLonToXYZ (double lat, double lon, double& x, double& y, double& z); 47 | 48 | /// @} 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /HeightmapRenderer/TerrainChunksGenerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TerrainChunk.h" 3 | using namespace oglplus; 4 | 5 | class TerrainChunksGenerator 6 | { 7 | private: 8 | Context gl; 9 | private: 10 | bool chunksGenerated = false; 11 | // helper for getting x, y from contiguos vectors 12 | glm::vec3 &getVertex(int x, int y); 13 | glm::vec2 &getTexCoord(int x, int y); 14 | glm::vec3 &getNormal(int x, int y); 15 | // mesh parameters data 16 | unsigned int chunkSize; 17 | unsigned int meshSize; 18 | unsigned int meshSizeExponent; 19 | unsigned int chunkSizeExponent; 20 | unsigned int restartIndexToken; 21 | unsigned int chunkCount; 22 | // whole mesh data 23 | std::vector vertices; 24 | std::vector normals; 25 | std::vector texCoords; 26 | // collection of all mesh chunks 27 | std::vector> meshChunks; 28 | // controller for chunk detail level 29 | ChunkDetailLevel chunkDetail; 30 | // deletes all mesh chunks 31 | void deleteMeshChunks(); 32 | public: 33 | // generates all terrain chunks 34 | void generateChunks(std::vector &meshVertices, 35 | std::vector &meshNormals, 36 | std::vector &meshTexCoords, 37 | unsigned int meshSizeExponent, 38 | unsigned int chunkSizeExponent); 39 | // uploads all the chunks buffer objects to the gpu 40 | void bindBufferData(Program &program); 41 | // generated chunks 42 | TerrainChunk &MeshChunk(int x, int y) { return *meshChunks[x][y]; } 43 | unsigned int ChunkCount() const { return chunkCount; } 44 | 45 | TerrainChunksGenerator() {}; 46 | ~TerrainChunksGenerator(); 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/invert.h: -------------------------------------------------------------------------------- 1 | // invert.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_INVERT_H 24 | #define NOISE_MODULE_INVERT_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Noise module that inverts the output value from a source module. 44 | /// 45 | /// @image html moduleinvert.png 46 | /// 47 | /// This noise module requires one source module. 48 | class Invert: public Module 49 | { 50 | 51 | public: 52 | 53 | /// Constructor. 54 | Invert (); 55 | 56 | virtual int GetSourceModuleCount () const 57 | { 58 | return 1; 59 | } 60 | 61 | virtual double GetValue (double x, double y, double z) const; 62 | 63 | }; 64 | 65 | /// @} 66 | 67 | /// @} 68 | 69 | /// @} 70 | 71 | } 72 | 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/max.h: -------------------------------------------------------------------------------- 1 | // max.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_MAX_H 24 | #define NOISE_MODULE_MAX_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the larger of the two output values from two 44 | /// source modules. 45 | /// 46 | /// @image html modulemax.png 47 | /// 48 | /// This noise module requires two source modules. 49 | class Max: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Max (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 2; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/min.h: -------------------------------------------------------------------------------- 1 | // min.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_MIN_H 24 | #define NOISE_MODULE_MIN_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the smaller of the two output values from 44 | /// two source modules. 45 | /// 46 | /// @image html modulemin.png 47 | /// 48 | /// This noise module requires two source modules. 49 | class Min: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Min (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 2; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/multiply.h: -------------------------------------------------------------------------------- 1 | // multiply.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_MULTIPLY_H 24 | #define NOISE_MODULE_MULTIPLY_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the product of the two output values from 44 | /// two source modules. 45 | /// 46 | /// @image html modulemultiply.png 47 | /// 48 | /// This noise module requires two source modules. 49 | class Multiply: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Multiply (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 2; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/abs.h: -------------------------------------------------------------------------------- 1 | // abs.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_ABS_H 24 | #define NOISE_MODULE_ABS_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module { 32 | 33 | /// @addtogroup libnoise 34 | /// @{ 35 | 36 | /// @addtogroup modules 37 | /// @{ 38 | 39 | /// @defgroup modifiermodules Modifier Modules 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the absolute value of the output value from 44 | /// a source module. 45 | /// 46 | /// @image html moduleabs.png 47 | /// 48 | /// This noise module requires one source module. 49 | class Abs: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Abs (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 1; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/add.h: -------------------------------------------------------------------------------- 1 | // add.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_ADD_H 24 | #define NOISE_MODULE_ADD_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup combinermodules Combiner Modules 41 | /// @addtogroup combinermodules 42 | /// @{ 43 | 44 | /// Noise module that outputs the sum of the two output values from two 45 | /// source modules. 46 | /// 47 | /// @image html moduleadd.png 48 | /// 49 | /// This noise module requires two source modules. 50 | class Add: public Module 51 | { 52 | 53 | public: 54 | 55 | /// Constructor. 56 | Add (); 57 | 58 | virtual int GetSourceModuleCount () const 59 | { 60 | return 2; 61 | } 62 | 63 | virtual double GetValue (double x, double y, double z) const; 64 | 65 | }; 66 | 67 | /// @} 68 | 69 | /// @} 70 | 71 | /// @} 72 | 73 | } 74 | 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /HeightmapRenderer/Heightmap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | using namespace noise; 3 | 4 | class Heightmap 5 | { 6 | private: 7 | 8 | float bottomLeft; 9 | float bottomRight; 10 | float topLeft; 11 | float topRigth; 12 | 13 | int width; 14 | int heigth; 15 | // lakes and rivers 16 | module::Billow baseWaterZones; 17 | module::Invert invertBase; 18 | module::Multiply multiplierBase; 19 | module::ScaleBias waterZones; 20 | module::Select waterSelector; 21 | module::ScaleBias flatlandsAndWater; 22 | // mountain terrain 23 | module::ScaleBias mountainTerrain; 24 | module::RidgedMulti baseMountainTerrain; 25 | // flat terrain 26 | module::Billow baseFlatTerrain; 27 | module::ScaleBias flatTerrain; 28 | // interpolates between mountain and flat 29 | module::Perlin terrainType; 30 | module::Select terrainSelector; 31 | // turbulence for the final terrain 32 | module::Turbulence finalTerrain; 33 | // heightmap builders 34 | utils::NoiseMap heightmap; 35 | utils::NoiseMapBuilderPlane heightmapBuilder; 36 | utils::RendererImage renderer; 37 | utils::Image image; 38 | utils::WriterBMP writer; 39 | public: 40 | void * RawImage() { renderer.Render(); return image.GetSlabPtr(); } 41 | 42 | void setBounds(const float bottomLeft, const float topLeft, 43 | const float bottomRight, const float topRigth); 44 | void setSeed(int seed); 45 | void setSize(const int x, const int y); 46 | void build(); 47 | void writeToFile(const std::string & filename); 48 | float getValue(int x, int y); 49 | 50 | // private members getters 51 | float BottomLeft() const { return bottomLeft; } 52 | float BottomRight() const { return bottomRight; } 53 | float TopLeft() const { return topLeft; } 54 | float TopRigth() const { return topRigth; } 55 | int Width() const { return width; } 56 | int Heigth() const { return heigth; } 57 | Heightmap(); 58 | ~Heightmap(); 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /HeightmapRenderer/ChunkDetailLevel.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "ChunkDetailLevel.h" 3 | // pixel error, shared among all chunks 4 | float ChunkDetailLevel::threeshold = 0.35; 5 | 6 | void ChunkDetailLevel::generateDetailLevels(int meshSize, int chunkSize) 7 | { 8 | this->meshSize = meshSize; 9 | this->chunkSize = chunkSize; 10 | restartIndexToken = meshSize * meshSize; 11 | 12 | for(int lodLevel = 0; lodLevel < 3; lodLevel++) 13 | { 14 | int nextSize = (chunkSize - 1) / std::pow(2, lodLevel) + 1; 15 | int stepMultiplier = std::pow(2, lodLevel); 16 | 17 | for(int i = 0; i < nextSize - 1; i++) 18 | { 19 | for(int j = 0; j < nextSize; j++) 20 | { 21 | indicesLoD[lodLevel].push_back( 22 | ((i + 1) * chunkSize + j) * stepMultiplier 23 | ); 24 | indicesLoD[lodLevel].push_back( 25 | (i * chunkSize + j) * stepMultiplier 26 | ); 27 | } 28 | 29 | indicesLoD[lodLevel].push_back(restartIndexToken); 30 | } 31 | } 32 | 33 | indicesCombinationGenerated = true; 34 | } 35 | 36 | void ChunkDetailLevel::bindBufferData() 37 | { 38 | for(int lodLevel = 0; lodLevel < 3; lodLevel++) 39 | { 40 | indicesBuffer[lodLevel].Bind(Buffer::Target::ElementArray); 41 | { 42 | Buffer::Data(Buffer::Target::ElementArray, indicesLoD[lodLevel]); 43 | } 44 | indexSizes[lodLevel] = indicesLoD[lodLevel].size(); 45 | // we don't need the indices once uploaded to gpu 46 | indicesLoD[lodLevel].clear(); 47 | } 48 | 49 | gl.Enable(Capability::PrimitiveRestart); 50 | gl.PrimitiveRestartIndex(restartIndexToken); 51 | } 52 | 53 | void ChunkDetailLevel::bindBuffer(LodLevel levelOfDetail) 54 | { 55 | indicesBuffer[std::min(std::max(0, (int)levelOfDetail), 2)] 56 | .Bind(Buffer::Target::ElementArray); 57 | } 58 | 59 | int ChunkDetailLevel::indicesSize(LodLevel levelOfDetail) 60 | { 61 | return indexSizes[std::min(std::max(0, (int)levelOfDetail), 2)]; 62 | } 63 | 64 | ChunkDetailLevel::ChunkDetailLevel() 65 | { 66 | } 67 | 68 | ChunkDetailLevel::~ChunkDetailLevel() 69 | { 70 | } 71 | -------------------------------------------------------------------------------- /HeightmapRenderer/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | using namespace oglplus; 3 | 4 | class Camera 5 | { 6 | private: 7 | enum Plane 8 | { 9 | Right = 0, 10 | Left, 11 | Bottom, 12 | Top, 13 | Far, 14 | Near 15 | }; 16 | glm::vec4 planes[6]; 17 | 18 | inline int vectorToIndex(const glm::vec3 &v) const 19 | { 20 | int idx = 0; 21 | 22 | if(v.z >= 0) idx |= 1; 23 | 24 | if(v.y >= 0) idx |= 2; 25 | 26 | if(v.x >= 0) idx |= 4; 27 | 28 | return idx; 29 | } 30 | 31 | public: 32 | glm::vec4 getPlane(Plane p) const; 33 | void calcPlanes(const glm::mat4 &matrix); 34 | int halfPlaneTest(const glm::vec3 &p, const glm::vec3 &normal, float offset); 35 | int isBoxInFrustum(const glm::vec3 &origin, const glm::vec3 &halfDim); 36 | 37 | private: 38 | // view matrix 39 | glm::vec3 eye; 40 | glm::vec3 center; 41 | glm::vec3 upVector; 42 | // projection matrix 43 | float fovy; 44 | float aspect; 45 | float nearClip; 46 | float farClip; 47 | // frustum plane, left, right, bottom, up 48 | glm::vec4 frustumP; 49 | // screen size 50 | int width; 51 | int height; 52 | // do not call this one 53 | void perspective(float fovy, float aspect, float nearClip, float farClip); 54 | public: 55 | Camera(); 56 | ~Camera(); 57 | // sets the camera at position looking at lookAt 58 | void lookAt(const glm::vec3 &eye, const glm::vec3 ¢er, 59 | const glm::vec3 &up = glm::vec3(0.0f, 1.0f, 0.0)); 60 | 61 | void perspective(float fovy, int width, int height, float nearClip, 62 | float farClip); 63 | 64 | const glm::vec3 &Position() const { return eye; } 65 | float FarClip() const { return farClip; } 66 | float NearClip() const { return nearClip; } 67 | // frustum plane, left, right, bottom, up 68 | const glm::vec4 &Frustum() const { return frustumP; } 69 | glm::vec2 ScreenSize() { return glm::vec2(width, height); } 70 | }; 71 | 72 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/power.h: -------------------------------------------------------------------------------- 1 | // power.h 2 | // 3 | // Copyright (C) 2004 Owen Jacobson 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is angstrom@lionsanctuary.net 20 | // 21 | 22 | #ifndef NOISE_MODULE_POWER_H 23 | #define NOISE_MODULE_POWER_H 24 | 25 | #include "modulebase.h" 26 | 27 | namespace noise 28 | { 29 | 30 | namespace module 31 | { 32 | 33 | /// @addtogroup libnoise 34 | /// @{ 35 | 36 | /// @addtogroup modules 37 | /// @{ 38 | 39 | /// @defgroup combinermodules Combiner Modules 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that raises the output value from a first source module 44 | /// to the power of the output value from a second source module. 45 | /// 46 | /// @image html modulepower.png 47 | /// 48 | /// The first source module must have an index value of 0. 49 | /// 50 | /// The second source module must have an index value of 1. 51 | /// 52 | /// This noise module requires two source modules. 53 | class Power: public Module 54 | { 55 | 56 | public: 57 | 58 | /// Constructor. 59 | Power (); 60 | 61 | virtual int GetSourceModuleCount () const 62 | { 63 | return 2; 64 | } 65 | 66 | virtual double GetValue (double x, double y, double z) const; 67 | 68 | }; 69 | 70 | /// @} 71 | 72 | /// @} 73 | 74 | /// @} 75 | 76 | } 77 | 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/exception.h: -------------------------------------------------------------------------------- 1 | // exception.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_EXCEPTION_H 24 | #define NOISE_EXCEPTION_H 25 | 26 | namespace noise 27 | { 28 | 29 | /// @addtogroup libnoise 30 | /// @{ 31 | 32 | /// Abstract base class for libnoise exceptions 33 | class Exception 34 | { 35 | }; 36 | 37 | /// Invalid parameter exception 38 | /// 39 | /// An invalid parameter was passed to a libnoise function or method. 40 | class ExceptionInvalidParam: public Exception 41 | { 42 | }; 43 | 44 | /// No module exception 45 | /// 46 | /// Could not retrieve a source module from a noise module. 47 | /// 48 | /// @note If one or more required source modules were not connected to a 49 | /// specific noise module, and its GetValue() method was called, that 50 | /// method will raise a debug assertion instead of this exception. This 51 | /// is done for performance reasons. 52 | class ExceptionNoModule: public Exception 53 | { 54 | }; 55 | 56 | /// Out of memory exception 57 | /// 58 | /// There was not enough memory to perform an action. 59 | class ExceptionOutOfMemory: public Exception 60 | { 61 | }; 62 | 63 | /// Unknown exception 64 | /// 65 | /// libnoise raised an unknown exception. 66 | class ExceptionUnknown: public Exception 67 | { 68 | }; 69 | 70 | /// @} 71 | 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/checkerboard.h: -------------------------------------------------------------------------------- 1 | // checkerboard.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CHECKERBOARD_H 24 | #define NOISE_MODULE_CHECKERBOARD_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup generatormodules 41 | /// @{ 42 | 43 | /// Noise module that outputs a checkerboard pattern. 44 | /// 45 | /// @image html modulecheckerboard.png 46 | /// 47 | /// This noise module outputs unit-sized blocks of alternating values. 48 | /// The values of these blocks alternate between -1.0 and +1.0. 49 | /// 50 | /// This noise module is not really useful by itself, but it is often used 51 | /// for debugging purposes. 52 | /// 53 | /// This noise module does not require any source modules. 54 | class Checkerboard: public Module 55 | { 56 | 57 | public: 58 | 59 | /// Constructor. 60 | Checkerboard (); 61 | 62 | virtual int GetSourceModuleCount () const 63 | { 64 | return 0; 65 | } 66 | 67 | virtual double GetValue (double x, double y, double z) const; 68 | 69 | }; 70 | 71 | /// @} 72 | 73 | /// @} 74 | 75 | /// @} 76 | 77 | } 78 | 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /HeightmapRenderer/ChunkDetailLevel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | using namespace oglplus; 3 | 4 | class ChunkDetailLevel 5 | { 6 | private: 7 | // chunk params 8 | int meshSize; 9 | int chunkSize; 10 | public: 11 | enum LodLevel 12 | { 13 | High = 0, 14 | Medium, 15 | Low, 16 | AvailableLevels 17 | }; 18 | enum LodLevelTransition 19 | { 20 | Top = 0, 21 | Left, 22 | Down, 23 | Right, 24 | TopLeft, 25 | TopDown, 26 | TopRight, 27 | LeftDown, 28 | LeftRight, 29 | DownRight, 30 | TopRightDown, 31 | RightDownLeft, 32 | DownLeftTop, 33 | LeftTopRight, 34 | TopRightDownLeft 35 | }; 36 | private: 37 | // triangle strip primitive restart at 38 | int restartIndexToken; 39 | // base indices configuration for 3 levels of detail 40 | // vectors are cleared once data is uploaded to GPU 41 | std::array, 3> indicesLoD; 42 | std::array, 16>, 3> transitionLod; 43 | private: 44 | Context gl; 45 | // indices count on level of detail 46 | std::array indexSizes; 47 | // avoid creating indices again if mesh has the same configuration 48 | bool indicesCombinationGenerated; 49 | // indices combinations for different lod levels 50 | std::array indicesBuffer; 51 | // thresshold t_ 52 | static float threeshold; 53 | public: 54 | // uploads index data to gpu 55 | void bindBufferData(); 56 | // binds the indices based on lod 57 | void bindBuffer(LodLevel levelOfDetail); 58 | // indices count on level of detail 59 | int indicesSize(LodLevel levelOfDetail); 60 | // generates the 3 LoD indices configurations based on mesh and chunk size 61 | void generateDetailLevels(int meshSize, int chunkSize); 62 | // token to restart the triangle strip 63 | int RestartIndexToken() const { return restartIndexToken; } 64 | // indexes combinations per lod 65 | const std::array, 3> &IndicesLoD() { return indicesLoD; } 66 | 67 | ChunkDetailLevel(); 68 | ~ChunkDetailLevel(); 69 | // chunks size 70 | int ChunkSize() const { return chunkSize; } 71 | int MeshSize() const { return meshSize; } 72 | // sets and getter for pixel threeshold among chunks 73 | static float Threeshold() { return threeshold; } 74 | static void Threeshold(float val) { threeshold = val; } 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /HeightmapRenderer/Commons.h: -------------------------------------------------------------------------------- 1 | // os specific includes 2 | #include 3 | #include 4 | #include 5 | // opengl and context creation headers 6 | #include 7 | #include 8 | // pre-processors 9 | #define GLM_FORCE_RADIANS 10 | #define GLM_FORCE_PURE 11 | #define _USE_MATH_DEFINES 12 | // ogl headers c++ wrapper on opengl 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | // coherent noise generation 24 | #include 25 | #include "noise/interp.h" 26 | #include 27 | // standard and stl library headers 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | // glm math library headers 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | // boost c++ general utils headers 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | // ui library imgui (inmediate mode gui) 68 | #include "ImGui/imgui.h" 69 | #include "ImGui/imgui_impl_glfw_gl3.h" 70 | // image loading library 71 | #include 72 | // parallel patterns library (ppl) from Windows for concurrency and parallelism 73 | #include 74 | // namespace assignations 75 | namespace logging = boost::log; 76 | namespace src = boost::log::sources; 77 | namespace sinks = boost::log::sinks; 78 | namespace keywords = boost::log::keywords; 79 | namespace expr = boost::log::expressions; -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/misc.h: -------------------------------------------------------------------------------- 1 | // misc.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MISC_H 24 | #define NOISE_MISC_H 25 | 26 | namespace noise 27 | { 28 | 29 | /// Clamps a value onto a clamping range. 30 | /// 31 | /// @param value The value to clamp. 32 | /// @param lowerBound The lower bound of the clamping range. 33 | /// @param upperBound The upper bound of the clamping range. 34 | /// 35 | /// @returns 36 | /// - @a value if @a value lies between @a lowerBound and @a upperBound. 37 | /// - @a lowerBound if @a value is less than @a lowerBound. 38 | /// - @a upperBound if @a value is greater than @a upperBound. 39 | /// 40 | /// This function does not modify any parameters. 41 | inline int ClampValue (int value, int lowerBound, int upperBound) 42 | { 43 | if (value < lowerBound) { 44 | return lowerBound; 45 | } else if (value > upperBound) { 46 | return upperBound; 47 | } else { 48 | return value; 49 | } 50 | } 51 | 52 | /// @addtogroup libnoise 53 | /// @{ 54 | 55 | /// Returns the maximum of two values. 56 | /// 57 | /// @param a The first value. 58 | /// @param b The second value. 59 | /// 60 | /// @returns The maximum of the two values. 61 | template 62 | T GetMax (const T& a, const T& b) 63 | { 64 | return (a > b? a: b); 65 | } 66 | 67 | /// Returns the minimum of two values. 68 | /// 69 | /// @param a The first value. 70 | /// @param b The second value. 71 | /// 72 | /// @returns The minimum of the two values. 73 | template 74 | T GetMin (const T& a, const T& b) 75 | { 76 | return (a < b? a: b); 77 | } 78 | 79 | /// Swaps two values. 80 | /// 81 | /// @param a A variable containing the first value. 82 | /// @param b A variable containing the second value. 83 | /// 84 | /// @post The values within the the two variables are swapped. 85 | template 86 | void SwapValues (T& a, T& b) 87 | { 88 | T c = a; 89 | a = b; 90 | b = c; 91 | } 92 | 93 | /// @} 94 | 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/noise.h: -------------------------------------------------------------------------------- 1 | // noise.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_H 24 | #define NOISE_H 25 | 26 | /// @mainpage libnoise 27 | /// 28 | /// @section intro Introduction 29 | /// 30 | /// libnoise is a portable C++ library that is used to generate coherent 31 | /// noise, a type of smoothly-changing noise. libnoise can generate Perlin 32 | /// noise, ridged multifractal noise, and other types of coherent noise. 33 | /// 34 | /// Coherent noise is often used by graphics programmers to generate 35 | /// natural-looking textures, planetary terrain, and other things. It can 36 | /// also be used to move critters in a realistic way. 37 | /// 38 | /// libnoise is known to compile using the following compilers on the 39 | /// following platforms: 40 | /// - Microsoft Visual C++ 5.0 under Microsoft Windows 2000 Service Pack 4 41 | /// - gcc 3.3.4 under Gentoo Linux 10.0 (x86) 42 | /// 43 | /// It is not known if libnoise will compile on 64-bit platforms, although 44 | /// there is a good change that it will. 45 | /// 46 | /// @section noise Noise Modules 47 | /// 48 | /// In libnoise, coherent-noise generators are encapsulated in classes called 49 | /// noise modules. There are many different types of noise modules. 50 | /// Some noise modules can combine or modify the outputs of other noise 51 | /// modules in various ways; you can join these modules together to generate 52 | /// very complex coherent noise. 53 | /// 54 | /// A noise module receives a 3-dimensional input value from the application, 55 | /// computes the noise value given that input value, and returns the resulting 56 | /// value back to the application. 57 | /// 58 | /// If the application passes the same input value to a noise module, the 59 | /// noise module returns the same output value. 60 | /// 61 | /// All noise modules are derived from the noise::module::Module abstract 62 | /// base class. 63 | /// 64 | /// @section contact Contact 65 | /// 66 | /// Contact jas for questions about libnoise. The spam-resistant email 67 | /// address is jlbezigvins@gmzigail.com (For great email, take off every 68 | /// zig.) 69 | 70 | #include "module/module.h" 71 | #include "model/model.h" 72 | #include "misc.h" 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/const.h: -------------------------------------------------------------------------------- 1 | // const.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CONST_H 24 | #define NOISE_MODULE_CONST_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup generatormodules Generator Modules 41 | /// @addtogroup generatormodules 42 | /// @{ 43 | 44 | /// Default constant value for the noise::module::Const noise module. 45 | const double DEFAULT_CONST_VALUE = 0.0; 46 | 47 | /// Noise module that outputs a constant value. 48 | /// 49 | /// @image html moduleconst.png 50 | /// 51 | /// To specify the constant value, call the SetConstValue() method. 52 | /// 53 | /// This noise module is not useful by itself, but it is often used as a 54 | /// source module for other noise modules. 55 | /// 56 | /// This noise module does not require any source modules. 57 | class Const: public Module 58 | { 59 | 60 | public: 61 | 62 | /// Constructor. 63 | /// 64 | /// The default constant value is set to 65 | /// noise::module::DEFAULT_CONST_VALUE. 66 | Const (); 67 | 68 | /// Returns the constant output value for this noise module. 69 | /// 70 | /// @returns The constant output value for this noise module. 71 | double GetConstValue () const 72 | { 73 | return m_constValue; 74 | } 75 | 76 | virtual int GetSourceModuleCount () const 77 | { 78 | return 0; 79 | } 80 | 81 | virtual double GetValue (double x, double y, double z) const 82 | { 83 | return m_constValue; 84 | } 85 | 86 | /// Sets the constant output value for this noise module. 87 | /// 88 | /// @param constValue The constant output value for this noise module. 89 | void SetConstValue (double constValue) 90 | { 91 | m_constValue = constValue; 92 | } 93 | 94 | protected: 95 | 96 | /// Constant value. 97 | double m_constValue; 98 | 99 | }; 100 | 101 | /// @} 102 | 103 | /// @} 104 | 105 | /// @} 106 | 107 | } 108 | 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /HeightmapRenderer/Heightmap.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "Heightmap.h" 3 | 4 | int counter = 0; 5 | 6 | void Heightmap::setBounds(const float bottomLeft, const float topLeft, 7 | const float bottomRight, const float topRigth) 8 | { 9 | this->bottomLeft = bottomLeft; 10 | this->topLeft = topLeft; 11 | this->bottomRight = bottomRight; 12 | this->topRigth = topRigth; 13 | heightmapBuilder.SetBounds(bottomLeft, topLeft, bottomRight, topRigth); 14 | } 15 | 16 | void Heightmap::setSeed(int seed) 17 | { 18 | this->terrainType.SetSeed(seed); 19 | this->baseFlatTerrain.SetSeed(seed); 20 | this->baseMountainTerrain.SetSeed(seed); 21 | this->finalTerrain.SetSeed(seed); 22 | this->baseWaterZones.SetSeed(seed); 23 | } 24 | 25 | void Heightmap::setSize(const int x, const int y) 26 | { 27 | width = x; 28 | heigth = y; 29 | heightmapBuilder.SetDestSize(width, heigth); 30 | } 31 | 32 | void Heightmap::build() 33 | { 34 | heightmapBuilder.Build(); 35 | } 36 | 37 | void Heightmap::writeToFile(const std::string & filename) 38 | { 39 | if(width <= 0 || heigth <= 0) return; 40 | 41 | renderer.Render(); 42 | utils::WriterBMP writer; 43 | writer.SetSourceImage(image); 44 | writer.SetDestFilename(filename + ".bmp"); 45 | writer.WriteDestFile(); 46 | } 47 | 48 | float Heightmap::getValue(int x, int y) 49 | { 50 | return heightmap.GetValue(x, y); 51 | } 52 | 53 | Heightmap::Heightmap() : bottomLeft(0), bottomRight(0), 54 | topRigth(5), topLeft(5), width(0), heigth(0) 55 | { 56 | // mountains 57 | baseMountainTerrain.SetFrequency(0.65); 58 | mountainTerrain.SetSourceModule(0, baseMountainTerrain); 59 | mountainTerrain.SetScale(0.80); 60 | // midlands flat terrain 61 | baseFlatTerrain.SetFrequency(1.75); 62 | flatTerrain.SetSourceModule(0, baseFlatTerrain); 63 | flatTerrain.SetScale(0.075); 64 | flatTerrain.SetBias(-0.65); 65 | // water zones 66 | baseWaterZones.SetFrequency(0.75); 67 | baseWaterZones.SetPersistence(0.45); 68 | invertBase.SetSourceModule(0, baseWaterZones); 69 | waterZones.SetSourceModule(0, invertBase); 70 | waterZones.SetScale(1.65); 71 | waterZones.SetBias(-3.65f); 72 | // terrain boundaries 73 | terrainType.SetFrequency(0.5); 74 | terrainType.SetPersistence(0.25); 75 | // apply water zones to flatlands 76 | multiplierBase.SetSourceModule(0, flatTerrain); 77 | multiplierBase.SetSourceModule(1, waterZones); 78 | flatlandsAndWater.SetSourceModule(0, multiplierBase); 79 | flatlandsAndWater.SetScale(0.15); 80 | flatlandsAndWater.SetBias(-0.75); 81 | // join modules, flat and mountains 82 | terrainSelector.SetSourceModule(0, flatlandsAndWater); 83 | terrainSelector.SetSourceModule(1, mountainTerrain); 84 | terrainSelector.SetControlModule(terrainType); 85 | terrainSelector.SetBounds(-0.15, 35.0); 86 | terrainSelector.SetEdgeFalloff(0.35); 87 | // turbulence 88 | finalTerrain.SetSourceModule(0, terrainSelector); 89 | finalTerrain.SetFrequency(4.0); 90 | finalTerrain.SetPower(0.125); 91 | // finally set source for builder 92 | heightmapBuilder.SetSourceModule(terrainSelector); 93 | heightmapBuilder.SetDestNoiseMap(heightmap); 94 | heightmapBuilder.SetBounds(bottomLeft, topLeft, bottomRight, topRigth); 95 | renderer.SetSourceNoiseMap(heightmap); 96 | renderer.SetDestImage(image); 97 | } 98 | 99 | Heightmap::~Heightmap() 100 | { 101 | } 102 | -------------------------------------------------------------------------------- /HeightmapRenderer/TerrainChunk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ChunkDetailLevel.h" 3 | #include "Camera.h" 4 | using namespace oglplus; 5 | 6 | class BoundingBox 7 | { 8 | private: 9 | // wrapper around the current OpenGL context 10 | Context gl; 11 | // Vertex shader 12 | VertexShader vs; 13 | // Fragment shader 14 | FragmentShader fs; 15 | // Program 16 | Program prog; 17 | 18 | shapes::Cube bbox; 19 | shapes::DrawingInstructions bboxInstructions; 20 | shapes::Cube::IndexArray bboxIndexArray; 21 | 22 | Uniform modelMatrix; 23 | Uniform viewMatrix; 24 | Uniform projectionMatrix; 25 | 26 | // VBOs for the cube's vertices 27 | Buffer verts; 28 | Buffer indices; 29 | 30 | public: 31 | BoundingBox(); 32 | void render(glm::vec3 position, glm::vec3 dimensions); 33 | }; 34 | 35 | class TerrainChunk 36 | { 37 | private: 38 | // debug drawing 39 | static bool debugMode; 40 | static BoundingBox * chunkBBox; 41 | // trapezoid - cube culling per chunk 42 | static bool enableFrustumCulling; 43 | // bounding box position and dimension 44 | glm::vec3 position; 45 | glm::vec3 dimension; 46 | private: 47 | friend class TerrainChunksGenerator; 48 | // shared detail level control between all chunks 49 | // chunkdetail level only stores the index combinations 50 | // of different lod levels 51 | static ChunkDetailLevel * chunkLod; 52 | static Context gl; 53 | private: 54 | // lod level calculations members 55 | float distanceToEye; 56 | // chunk lod level 57 | ChunkDetailLevel::LodLevel currentLoD; 58 | // height change between lod levels per chunk 59 | std::array heightChange; 60 | // defines the distance for selecting the lod level 61 | std::array entropyDistances; 62 | private: 63 | // chunk center vertex 64 | glm::vec3 center; 65 | // mesh data, freed once uploaded to gpu 66 | std::vector vertices; 67 | std::vector normals; 68 | std::vector texCoords; 69 | // mesh data gpu buffers 70 | std::array buffer; 71 | // called on drawElemented 72 | void bindBuffer(Program &program); 73 | public: 74 | TerrainChunk(std::vector & vertices, 75 | std::vector & normals, 76 | std::vector & texCoords, 77 | ChunkDetailLevel * chunkLod, 78 | float maxHeight, float minHeight); 79 | // chunk num vertices = chunkSizeExponent ^ 2 + 1 80 | ~TerrainChunk() {}; 81 | void bindBufferData(Program &program); 82 | // calls glDrawElements with the current lod level indices 83 | void drawElements(Program &program); 84 | // calculates appropiate lod level 85 | void chooseLoDLevel(Camera &camera, const glm::vec3 & position); 86 | // returns the C constant for geomipmapping 87 | float getCameraConstant(Camera &camera); 88 | // generated geometric height changes for geomipmapping (d) 89 | void generatedEntropies(); 90 | // render bboxes 91 | static void DrawBoundingBoxes(bool val) { debugMode = val; } 92 | static bool DrawingBoundingBoxes() { return debugMode; } 93 | // culls the chunk bounding boxes with the frustum trapezoid 94 | static bool EnableFrustumCulling() { return enableFrustumCulling; } 95 | static void EnableFrustumCulling(bool val) { enableFrustumCulling = val; } 96 | }; 97 | 98 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # Roslyn cache directories 20 | *.ide/ 21 | 22 | # MSTest test Results 23 | [Tt]est[Rr]esult*/ 24 | [Bb]uild[Ll]og.* 25 | 26 | #NUNIT 27 | *.VisualState.xml 28 | TestResult.xml 29 | 30 | # Build Results of an ATL Project 31 | [Dd]ebugPS/ 32 | [Rr]eleasePS/ 33 | dlldata.c 34 | 35 | *_i.c 36 | *_p.c 37 | *_i.h 38 | *.ilk 39 | *.meta 40 | *.obj 41 | *.pch 42 | *.pdb 43 | *.pgc 44 | *.pgd 45 | *.rsp 46 | *.sbr 47 | *.tlb 48 | *.tli 49 | *.tlh 50 | *.tmp 51 | *.tmp_proj 52 | *.log 53 | *.vspscc 54 | *.vssscc 55 | .builds 56 | *.pidb 57 | *.svclog 58 | *.scc 59 | 60 | # Chutzpah Test files 61 | _Chutzpah* 62 | 63 | # Visual C++ cache files 64 | ipch/ 65 | *.aps 66 | *.ncb 67 | *.opensdf 68 | *.sdf 69 | *.cachefile 70 | 71 | # Visual Studio profiler 72 | *.psess 73 | *.vsp 74 | *.vspx 75 | 76 | # TFS 2012 Local Workspace 77 | $tf/ 78 | 79 | # Guidance Automation Toolkit 80 | *.gpState 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper*/ 84 | *.[Rr]e[Ss]harper 85 | *.DotSettings.user 86 | 87 | # JustCode is a .NET coding addin-in 88 | .JustCode 89 | 90 | # TeamCity is a build add-in 91 | _TeamCity* 92 | 93 | # DotCover is a Code Coverage Tool 94 | *.dotCover 95 | 96 | # NCrunch 97 | _NCrunch_* 98 | .*crunch*.local.xml 99 | 100 | # MightyMoose 101 | *.mm.* 102 | AutoTest.Net/ 103 | 104 | # Web workbench (sass) 105 | .sass-cache/ 106 | 107 | # Installshield output folder 108 | [Ee]xpress/ 109 | 110 | # DocProject is a documentation generator add-in 111 | DocProject/buildhelp/ 112 | DocProject/Help/*.HxT 113 | DocProject/Help/*.HxC 114 | DocProject/Help/*.hhc 115 | DocProject/Help/*.hhk 116 | DocProject/Help/*.hhp 117 | DocProject/Help/Html2 118 | DocProject/Help/html 119 | 120 | # Click-Once directory 121 | publish/ 122 | 123 | # Publish Web Output 124 | *.[Pp]ublish.xml 125 | *.azurePubxml 126 | ## TODO: Comment the next line if you want to checkin your 127 | ## web deploy settings but do note that will include unencrypted 128 | ## passwords 129 | #*.pubxml 130 | 131 | # NuGet Packages Directory 132 | packages/* 133 | ## TODO: If the tool you use requires repositories.config 134 | ## uncomment the next line 135 | #!packages/repositories.config 136 | 137 | # Enable "build/" folder in the NuGet Packages folder since 138 | # NuGet packages use it for MSBuild targets. 139 | # This line needs to be after the ignore of the build folder 140 | # (and the packages folder if the line above has been uncommented) 141 | !packages/build/ 142 | 143 | # Windows Azure Build Output 144 | csx/ 145 | *.build.csdef 146 | 147 | # Windows Store app package directory 148 | AppPackages/ 149 | 150 | # Others 151 | sql/ 152 | *.Cache 153 | ClientBin/ 154 | [Ss]tyle[Cc]op.* 155 | ~$* 156 | *~ 157 | *.dbmdl 158 | *.dbproj.schemaview 159 | *.pfx 160 | *.publishsettings 161 | node_modules/ 162 | 163 | # RIA/Silverlight projects 164 | Generated_Code/ 165 | 166 | # Backup & report files from converting an old project file 167 | # to a newer Visual Studio version. Backup files are not needed, 168 | # because we have git ;-) 169 | _UpgradeReport_Files/ 170 | Backup*/ 171 | UpgradeLog*.XML 172 | UpgradeLog*.htm 173 | 174 | # SQL Server files 175 | *.mdf 176 | *.ldf 177 | 178 | # Business Intelligence projects 179 | *.rdl.data 180 | *.bim.layout 181 | *.bim_*.settings 182 | 183 | # Microsoft Fakes 184 | FakesAssemblies/ 185 | 186 | # LightSwitch generated files 187 | GeneratedArtifacts/ 188 | _Pvt_Extensions/ 189 | ModelManifest.xml -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/interp.h: -------------------------------------------------------------------------------- 1 | // interp.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_INTERP_H 24 | #define NOISE_INTERP_H 25 | 26 | namespace noise 27 | { 28 | 29 | /// @addtogroup libnoise 30 | /// @{ 31 | 32 | /// Performs cubic interpolation between two values bound between two other 33 | /// values. 34 | /// 35 | /// @param n0 The value before the first value. 36 | /// @param n1 The first value. 37 | /// @param n2 The second value. 38 | /// @param n3 The value after the second value. 39 | /// @param a The alpha value. 40 | /// 41 | /// @returns The interpolated value. 42 | /// 43 | /// The alpha value should range from 0.0 to 1.0. If the alpha value is 44 | /// 0.0, this function returns @a n1. If the alpha value is 1.0, this 45 | /// function returns @a n2. 46 | inline double CubicInterp (double n0, double n1, double n2, double n3, 47 | double a) 48 | { 49 | double p = (n3 - n2) - (n0 - n1); 50 | double q = (n0 - n1) - p; 51 | double r = n2 - n0; 52 | double s = n1; 53 | return p * a * a * a + q * a * a + r * a + s; 54 | } 55 | 56 | /// Performs linear interpolation between two values. 57 | /// 58 | /// @param n0 The first value. 59 | /// @param n1 The second value. 60 | /// @param a The alpha value. 61 | /// 62 | /// @returns The interpolated value. 63 | /// 64 | /// The alpha value should range from 0.0 to 1.0. If the alpha value is 65 | /// 0.0, this function returns @a n0. If the alpha value is 1.0, this 66 | /// function returns @a n1. 67 | inline double LinearInterp (double n0, double n1, double a) 68 | { 69 | return ((1.0 - a) * n0) + (a * n1); 70 | } 71 | 72 | /// Maps a value onto a cubic S-curve. 73 | /// 74 | /// @param a The value to map onto a cubic S-curve. 75 | /// 76 | /// @returns The mapped value. 77 | /// 78 | /// @a a should range from 0.0 to 1.0. 79 | /// 80 | /// The derivitive of a cubic S-curve is zero at @a a = 0.0 and @a a = 81 | /// 1.0 82 | inline double SCurve3 (double a) 83 | { 84 | return (a * a * (3.0 - 2.0 * a)); 85 | } 86 | 87 | /// Maps a value onto a quintic S-curve. 88 | /// 89 | /// @param a The value to map onto a quintic S-curve. 90 | /// 91 | /// @returns The mapped value. 92 | /// 93 | /// @a a should range from 0.0 to 1.0. 94 | /// 95 | /// The first derivitive of a quintic S-curve is zero at @a a = 0.0 and 96 | /// @a a = 1.0 97 | /// 98 | /// The second derivitive of a quintic S-curve is zero at @a a = 0.0 and 99 | /// @a a = 1.0 100 | inline double SCurve5 (double a) 101 | { 102 | double a3 = a * a * a; 103 | double a4 = a3 * a; 104 | double a5 = a4 * a; 105 | return (6.0 * a5) - (15.0 * a4) + (10.0 * a3); 106 | } 107 | 108 | // @} 109 | 110 | } 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/cache.h: -------------------------------------------------------------------------------- 1 | // cache.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CACHE_H 24 | #define NOISE_MODULE_CACHE_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup miscmodules Miscellaneous Modules 41 | /// @addtogroup miscmodules 42 | /// @{ 43 | 44 | /// Noise module that caches the last output value generated by a source 45 | /// module. 46 | /// 47 | /// If an application passes an input value to the GetValue() method that 48 | /// differs from the previously passed-in input value, this noise module 49 | /// instructs the source module to calculate the output value. This 50 | /// value, as well as the ( @a x, @a y, @a z ) coordinates of the input 51 | /// value, are stored (cached) in this noise module. 52 | /// 53 | /// If the application passes an input value to the GetValue() method 54 | /// that is equal to the previously passed-in input value, this noise 55 | /// module returns the cached output value without having the source 56 | /// module recalculate the output value. 57 | /// 58 | /// If an application passes a new source module to the SetSourceModule() 59 | /// method, the cache is invalidated. 60 | /// 61 | /// Caching a noise module is useful if it is used as a source module for 62 | /// multiple noise modules. If a source module is not cached, the source 63 | /// module will redundantly calculate the same output value once for each 64 | /// noise module in which it is included. 65 | /// 66 | /// This noise module requires one source module. 67 | class Cache: public Module 68 | { 69 | 70 | public: 71 | 72 | /// Constructor. 73 | Cache (); 74 | 75 | virtual int GetSourceModuleCount () const 76 | { 77 | return 1; 78 | } 79 | 80 | virtual double GetValue (double x, double y, double z) const; 81 | 82 | virtual void SetSourceModule (int index, const Module& sourceModule) 83 | { 84 | Module::SetSourceModule (index, sourceModule); 85 | m_isCached = false; 86 | } 87 | 88 | protected: 89 | 90 | /// The cached output value at the cached input value. 91 | mutable double m_cachedValue; 92 | 93 | /// Determines if a cached output value is stored in this noise 94 | /// module. 95 | mutable double m_isCached; 96 | 97 | /// @a x coordinate of the cached input value. 98 | mutable double m_xCache; 99 | 100 | /// @a y coordinate of the cached input value. 101 | mutable double m_yCache; 102 | 103 | /// @a z coordinate of the cached input value. 104 | mutable double m_zCache; 105 | 106 | }; 107 | 108 | /// @} 109 | 110 | /// @} 111 | 112 | /// @} 113 | 114 | } 115 | 116 | } 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/exponent.h: -------------------------------------------------------------------------------- 1 | // exponent.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_EXPONENT_H 24 | #define NOISE_MODULE_EXPONENT_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Default exponent for the noise::module::Exponent noise module. 44 | const double DEFAULT_EXPONENT = 1.0; 45 | 46 | /// Noise module that maps the output value from a source module onto an 47 | /// exponential curve. 48 | /// 49 | /// @image html moduleexponent.png 50 | /// 51 | /// Because most noise modules will output values that range from -1.0 to 52 | /// +1.0, this noise module first normalizes this output value (the range 53 | /// becomes 0.0 to 1.0), maps that value onto an exponential curve, then 54 | /// rescales that value back to the original range. 55 | /// 56 | /// This noise module requires one source module. 57 | class Exponent: public Module 58 | { 59 | 60 | public: 61 | 62 | /// Constructor. 63 | /// 64 | /// The default exponent is set to noise::module::DEFAULT_EXPONENT. 65 | Exponent (); 66 | 67 | /// Returns the exponent value to apply to the output value from the 68 | /// source module. 69 | /// 70 | /// @returns The exponent value. 71 | /// 72 | /// Because most noise modules will output values that range from -1.0 73 | /// to +1.0, this noise module first normalizes this output value (the 74 | /// range becomes 0.0 to 1.0), maps that value onto an exponential 75 | /// curve, then rescales that value back to the original range. 76 | double GetExponent () const 77 | { 78 | return m_exponent; 79 | } 80 | 81 | virtual int GetSourceModuleCount () const 82 | { 83 | return 1; 84 | } 85 | 86 | virtual double GetValue (double x, double y, double z) const; 87 | 88 | /// Sets the exponent value to apply to the output value from the 89 | /// source module. 90 | /// 91 | /// @param exponent The exponent value. 92 | /// 93 | /// Because most noise modules will output values that range from -1.0 94 | /// to +1.0, this noise module first normalizes this output value (the 95 | /// range becomes 0.0 to 1.0), maps that value onto an exponential 96 | /// curve, then rescales that value back to the original range. 97 | void SetExponent (double exponent) 98 | { 99 | m_exponent = exponent; 100 | } 101 | 102 | protected: 103 | 104 | /// Exponent to apply to the output value from the source module. 105 | double m_exponent; 106 | 107 | }; 108 | 109 | /// @} 110 | 111 | /// @} 112 | 113 | /// @} 114 | 115 | } 116 | 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /HeightmapRenderer/TerrainMultiTexture.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "TerrainMultiTexture.h" 3 | 4 | 5 | void TerrainMultiTexture::loadTexture(const std::string &filepath, 6 | const int index) 7 | { 8 | if(index < 0 || index >= MAX_TERRAIN_TEXTURE_RANGES) return; 9 | 10 | FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(filepath.c_str()); 11 | 12 | //if still unknown, try to guess the file format from the file extension 13 | if(fif == FIF_UNKNOWN) 14 | { 15 | fif = FreeImage_GetFIFFromFilename(filepath.c_str()); 16 | } 17 | 18 | //if still unkown, exit 19 | if(fif == FIF_UNKNOWN) 20 | { 21 | return; 22 | } 23 | 24 | // pointer to the image once loaded 25 | FIBITMAP *dib = 0; 26 | 27 | //check that the plugin has reading capabilities and load the file 28 | if(FreeImage_FIFSupportsReading(fif)) 29 | { 30 | dib = FreeImage_Load(fif, filepath.c_str()); 31 | } 32 | 33 | // highest quality rescaleing 34 | dib = FreeImage_Rescale(dib, 512, 512, FILTER_BICUBIC); 35 | // no alpha channel for terrain textures 36 | dib = FreeImage_ConvertTo24Bits(dib); 37 | // dib = FreeImage_ConvertTo32Bits(dib); 38 | // get raw data 39 | unsigned char * bits = FreeImage_GetBits(dib); 40 | // get image data 41 | unsigned int width = FreeImage_GetWidth(dib); 42 | unsigned int height = FreeImage_GetHeight(dib); 43 | unsigned int bitsPerPixel = FreeImage_GetBPP(dib); 44 | 45 | // If this somehow one of these failed (they shouldn't), return failure 46 | if((bitsPerPixel == 0) || (height == 0) || (width == 0)) 47 | { 48 | FreeImage_Unload(dib); 49 | return; 50 | } 51 | 52 | // pass data to the texture array 53 | gl.Bound(Texture::Target::_2DArray, this->texture) 54 | .MinFilter(TextureMinFilter::LinearMipmapLinear) 55 | .MagFilter(TextureMagFilter::Linear) 56 | .GenerateMipmap() 57 | .WrapS(TextureWrap::Repeat) 58 | .WrapT(TextureWrap::Repeat) 59 | .Anisotropy(16.0f) 60 | .SubImage3D(0, 0, 0, index, 512, 512, 1, PixelDataFormat::BGR, 61 | PixelDataType::UnsignedByte, bits); 62 | // pass data to interface texture 63 | gl.Bound(Texture::Target::_2D, this->uiTextures[index]) 64 | .Image2D(0, PixelDataInternalFormat::RGB8, 512, 512, 0, PixelDataFormat::BGR, 65 | PixelDataType::UnsignedByte, bits) 66 | .MinFilter(TextureMinFilter::Nearest) 67 | .MagFilter(TextureMagFilter::Nearest) 68 | .WrapS(TextureWrap::ClampToEdge) 69 | .WrapT(TextureWrap::ClampToEdge); 70 | // unload data from memory once uploaded to gpu 71 | FreeImage_Unload(dib); 72 | // set range as texture active 73 | this->ranges[index * 3 + 2] = 1.0f; 74 | } 75 | 76 | TerrainMultiTexture::TerrainMultiTexture() 77 | { 78 | gl.Bound(Texture::Target::_2DArray, this->texture) 79 | .Image3D(0, PixelDataInternalFormat::SRGB8, 512, 512, 4, 0, 80 | PixelDataFormat::BGR, PixelDataType::UnsignedByte, nullptr); 81 | 82 | for(int i = 0; i < MAX_TERRAIN_TEXTURE_RANGES; i++) 83 | { 84 | this->ranges[i * 3] = (float)(i) / MAX_TERRAIN_TEXTURE_RANGES; 85 | this->ranges[i * 3 + 1] = (float)(i + 1) / (MAX_TERRAIN_TEXTURE_RANGES); 86 | this->ranges[i * 3 + 2] = -1.0f; 87 | } 88 | } 89 | 90 | TerrainMultiTexture::~TerrainMultiTexture() 91 | { 92 | } 93 | 94 | void TerrainMultiTexture::SetTextureRange(const int index, const float start, 95 | const float end) 96 | { 97 | if(index < 0 || index >= MAX_TERRAIN_TEXTURE_RANGES) return; 98 | 99 | this->ranges[index * 3] = start; 100 | this->ranges[index * 3 + 1] = end; 101 | } 102 | 103 | void TerrainMultiTexture::SetUniforms(Program &program) 104 | { 105 | Uniform(program, "terrainRange").SetValues(3 * 106 | MAX_TERRAIN_TEXTURE_RANGES, ranges); 107 | } 108 | 109 | GLuint TerrainMultiTexture::UITextureId(const int index) 110 | { 111 | return index >= 0 && index < MAX_TERRAIN_TEXTURE_RANGES ? 112 | GetGLName(uiTextures[index]) : 0; 113 | } 114 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/model/plane.h: -------------------------------------------------------------------------------- 1 | // plane.h 2 | // 3 | // Copyright (C) 2004 Owen Jacobson 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is ojacobson@lionsanctuary.net 20 | // 21 | 22 | #ifndef NOISE_MODEL_PLANE_H 23 | #define NOISE_MODEL_PLANE_H 24 | 25 | #include 26 | #include "../module/modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace model 32 | { 33 | /// @addtogroup libnoise 34 | /// @{ 35 | 36 | /// @addtogroup models 37 | /// @{ 38 | 39 | /// Model that defines the surface of a plane. 40 | /// 41 | /// This model returns an output value from a noise module given the 42 | /// coordinates of an input value located on the surface of an ( @a x, 43 | /// @a z ) plane. 44 | /// 45 | /// To generate an output value, pass the ( @a x, @a z ) coordinates of 46 | /// an input value to the GetValue() method. 47 | /// 48 | /// This model is useful for creating: 49 | /// - two-dimensional textures 50 | /// - terrain height maps for local areas 51 | /// 52 | /// This plane extends infinitely in both directions. 53 | class Plane 54 | { 55 | 56 | public: 57 | 58 | /// Constructor. 59 | Plane (); 60 | 61 | /// Constructor 62 | /// 63 | /// @param module The noise module that is used to generate the output 64 | /// values. 65 | Plane (const module::Module& module); 66 | 67 | /// Returns the noise module that is used to generate the output 68 | /// values. 69 | /// 70 | /// @returns A reference to the noise module. 71 | /// 72 | /// @pre A noise module was passed to the SetModule() method. 73 | const module::Module& GetModule () const 74 | { 75 | assert (m_pModule != NULL); 76 | return *m_pModule; 77 | } 78 | 79 | /// Returns the output value from the noise module given the 80 | /// ( @a x, @a z ) coordinates of the specified input value located 81 | /// on the surface of the plane. 82 | /// 83 | /// @param x The @a x coordinate of the input value. 84 | /// @param z The @a z coordinate of the input value. 85 | /// 86 | /// @returns The output value from the noise module. 87 | /// 88 | /// @pre A noise module was passed to the SetModule() method. 89 | /// 90 | /// This output value is generated by the noise module passed to the 91 | /// SetModule() method. 92 | double GetValue (double x, double z) const; 93 | 94 | /// Sets the noise module that is used to generate the output values. 95 | /// 96 | /// @param module The noise module that is used to generate the output 97 | /// values. 98 | /// 99 | /// This noise module must exist for the lifetime of this object, 100 | /// until you pass a new noise module to this method. 101 | void SetModule (const module::Module& module) 102 | { 103 | m_pModule = &module; 104 | } 105 | 106 | private: 107 | 108 | /// A pointer to the noise module used to generate the output values. 109 | const module::Module* m_pModule; 110 | 111 | }; 112 | 113 | /// @} 114 | 115 | /// @} 116 | 117 | } 118 | 119 | } 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /HeightmapRenderer/TerrainChunksGenerator.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "TerrainChunksGenerator.h" 3 | #include "ChunkDetailLevel.h" 4 | 5 | glm::vec3 & TerrainChunksGenerator::getVertex(int x, int y) 6 | { 7 | return vertices[y * meshSize + x]; 8 | } 9 | 10 | glm::vec2 & TerrainChunksGenerator::getTexCoord(int x, int y) 11 | { 12 | return texCoords[y * meshSize + x]; 13 | } 14 | 15 | glm::vec3 & TerrainChunksGenerator::getNormal(int x, int y) 16 | { 17 | return normals[y * meshSize + x]; 18 | } 19 | 20 | void TerrainChunksGenerator::generateChunks(std::vector 21 | &meshVertices, std::vector &meshNormals, 22 | std::vector &meshTexCoords, unsigned int meshSizeExponent, 23 | unsigned int chunkSizeExponent) 24 | { 25 | this->vertices = std::move(meshVertices); 26 | this->normals = std::move(meshNormals); 27 | this->texCoords = std::move(meshTexCoords); 28 | // set mesh params 29 | this->meshSizeExponent = meshSizeExponent; 30 | this->chunkSizeExponent = chunkSizeExponent; 31 | this->meshSize = std::pow(2, meshSizeExponent) + 1; 32 | this->chunkSize = std::pow(2, chunkSizeExponent) + 1; 33 | this->restartIndexToken = meshSize * meshSize; 34 | // calculate chunk count 35 | chunkCount = (this->meshSize - 1) / (this->chunkSize - 1); 36 | // delete previous chunks and reserve memory for new ones 37 | deleteMeshChunks(); 38 | this->meshChunks.resize(chunkCount); 39 | // create lod controller levels 40 | chunkDetail.generateDetailLevels(meshSize, chunkSize); 41 | 42 | for(int y = 0; y < chunkCount; y++) 43 | { 44 | for(int x = 0; x < chunkCount; x++) 45 | { 46 | std::vector chunkVertices; 47 | std::vector chunkNormals; 48 | std::vector chunkTexCoords; 49 | 50 | for(int i = 0; i < chunkSize; i++) 51 | { 52 | for(int j = 0; j < chunkSize; j++) 53 | { 54 | int xCoord = j + x * (chunkSize - 1); 55 | int yCoord = i + y * (chunkSize - 1); 56 | chunkVertices.push_back(getVertex(xCoord, yCoord)); 57 | chunkNormals.push_back(getNormal(xCoord, yCoord)); 58 | chunkTexCoords.push_back(getTexCoord(xCoord, yCoord)); 59 | } 60 | } 61 | 62 | // get maximim height for current chunk 63 | float chunkMaxHeight = 0.0f; 64 | float chunkMinHeight = 1.0f; 65 | 66 | for each(glm::vec3 vertex in chunkVertices) 67 | { 68 | chunkMaxHeight = vertex.y > chunkMaxHeight ? vertex.y : chunkMaxHeight; 69 | chunkMinHeight = vertex.y < chunkMinHeight ? vertex.y : chunkMinHeight; 70 | } 71 | 72 | this->meshChunks[y].push_back( 73 | new TerrainChunk( 74 | chunkVertices, chunkNormals, chunkTexCoords, 75 | &chunkDetail, chunkMaxHeight, chunkMinHeight 76 | ) 77 | ); 78 | } 79 | } 80 | 81 | chunkDetail.bindBufferData(); 82 | // we don't need these collections anymore 83 | this->vertices.clear(); 84 | this->texCoords.clear(); 85 | this->normals.clear(); 86 | } 87 | 88 | void TerrainChunksGenerator::bindBufferData(Program &program) 89 | { 90 | for each(std::vector hLineChunks in this->meshChunks) 91 | { 92 | for(unsigned int i = 0; i < hLineChunks.size(); i++) 93 | { 94 | hLineChunks[i]->bindBufferData(program); 95 | } 96 | } 97 | } 98 | 99 | TerrainChunksGenerator::~TerrainChunksGenerator() 100 | { 101 | // deallocate chunks 102 | deleteMeshChunks(); 103 | } 104 | 105 | void TerrainChunksGenerator::deleteMeshChunks() 106 | { 107 | for each(std::vector hLineChunks in this->meshChunks) 108 | { 109 | for each(TerrainChunk * chunkPtr in hLineChunks) 110 | { 111 | delete chunkPtr; 112 | } 113 | 114 | hLineChunks.clear(); 115 | } 116 | 117 | meshChunks.clear(); 118 | } 119 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/spheres.h: -------------------------------------------------------------------------------- 1 | // spheres.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_SPHERES_H 24 | #define NOISE_MODULE_SPHERES_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup generatormodules 41 | /// @{ 42 | 43 | /// Default frequency value for the noise::module::Spheres noise module. 44 | const double DEFAULT_SPHERES_FREQUENCY = 1.0; 45 | 46 | /// Noise module that outputs concentric spheres. 47 | /// 48 | /// @image html modulespheres.png 49 | /// 50 | /// This noise module outputs concentric spheres centered on the origin 51 | /// like the concentric rings of an onion. 52 | /// 53 | /// The first sphere has a radius of 1.0. Each subsequent sphere has a 54 | /// radius that is 1.0 unit larger than the previous sphere. 55 | /// 56 | /// The output value from this noise module is determined by the distance 57 | /// between the input value and the the nearest spherical surface. The 58 | /// input values that are located on a spherical surface are given the 59 | /// output value 1.0 and the input values that are equidistant from two 60 | /// spherical surfaces are given the output value -1.0. 61 | /// 62 | /// An application can change the frequency of the concentric spheres. 63 | /// Increasing the frequency reduces the distances between spheres. To 64 | /// specify the frequency, call the SetFrequency() method. 65 | /// 66 | /// This noise module, modified with some low-frequency, low-power 67 | /// turbulence, is useful for generating agate-like textures. 68 | /// 69 | /// This noise module does not require any source modules. 70 | class Spheres: public Module 71 | { 72 | 73 | public: 74 | 75 | /// Constructor. 76 | /// 77 | /// The default frequency is set to 78 | /// noise::module::DEFAULT_SPHERES_FREQUENCY. 79 | Spheres (); 80 | 81 | /// Returns the frequency of the concentric spheres. 82 | /// 83 | /// @returns The frequency of the concentric spheres. 84 | /// 85 | /// Increasing the frequency increases the density of the concentric 86 | /// spheres, reducing the distances between them. 87 | double GetFrequency () const 88 | { 89 | return m_frequency; 90 | } 91 | 92 | virtual int GetSourceModuleCount () const 93 | { 94 | return 0; 95 | } 96 | 97 | virtual double GetValue (double x, double y, double z) const; 98 | 99 | /// Sets the frequenct of the concentric spheres. 100 | /// 101 | /// @param frequency The frequency of the concentric spheres. 102 | /// 103 | /// Increasing the frequency increases the density of the concentric 104 | /// spheres, reducing the distances between them. 105 | void SetFrequency (double frequency) 106 | { 107 | m_frequency = frequency; 108 | } 109 | 110 | protected: 111 | 112 | /// Frequency of the concentric spheres. 113 | double m_frequency; 114 | 115 | }; 116 | 117 | /// @} 118 | 119 | /// @} 120 | 121 | /// @} 122 | 123 | } 124 | 125 | } 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/cylinders.h: -------------------------------------------------------------------------------- 1 | // cylinders.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CYLINDERS_H 24 | #define NOISE_MODULE_CYLINDERS_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup generatormodules 41 | /// @{ 42 | 43 | /// Default frequency value for the noise::module::Cylinders noise module. 44 | const double DEFAULT_CYLINDERS_FREQUENCY = 1.0; 45 | 46 | /// Noise module that outputs concentric cylinders. 47 | /// 48 | /// @image html modulecylinders.png 49 | /// 50 | /// This noise module outputs concentric cylinders centered on the origin. 51 | /// These cylinders are oriented along the @a y axis similar to the 52 | /// concentric rings of a tree. Each cylinder extends infinitely along 53 | /// the @a y axis. 54 | /// 55 | /// The first cylinder has a radius of 1.0. Each subsequent cylinder has 56 | /// a radius that is 1.0 unit larger than the previous cylinder. 57 | /// 58 | /// The output value from this noise module is determined by the distance 59 | /// between the input value and the the nearest cylinder surface. The 60 | /// input values that are located on a cylinder surface are given the 61 | /// output value 1.0 and the input values that are equidistant from two 62 | /// cylinder surfaces are given the output value -1.0. 63 | /// 64 | /// An application can change the frequency of the concentric cylinders. 65 | /// Increasing the frequency reduces the distances between cylinders. To 66 | /// specify the frequency, call the SetFrequency() method. 67 | /// 68 | /// This noise module, modified with some low-frequency, low-power 69 | /// turbulence, is useful for generating wood-like textures. 70 | /// 71 | /// This noise module does not require any source modules. 72 | class Cylinders: public Module 73 | { 74 | 75 | public: 76 | 77 | /// Constructor. 78 | /// 79 | /// The default frequency is set to 80 | /// noise::module::DEFAULT_CYLINDERS_FREQUENCY. 81 | Cylinders (); 82 | 83 | /// Returns the frequency of the concentric cylinders. 84 | /// 85 | /// @returns The frequency of the concentric cylinders. 86 | /// 87 | /// Increasing the frequency increases the density of the concentric 88 | /// cylinders, reducing the distances between them. 89 | double GetFrequency () const 90 | { 91 | return m_frequency; 92 | } 93 | 94 | virtual int GetSourceModuleCount () const 95 | { 96 | return 0; 97 | } 98 | 99 | virtual double GetValue (double x, double y, double z) const; 100 | 101 | /// Sets the frequenct of the concentric cylinders. 102 | /// 103 | /// @param frequency The frequency of the concentric cylinders. 104 | /// 105 | /// Increasing the frequency increases the density of the concentric 106 | /// cylinders, reducing the distances between them. 107 | void SetFrequency (double frequency) 108 | { 109 | m_frequency = frequency; 110 | } 111 | 112 | protected: 113 | 114 | /// Frequency of the concentric cylinders. 115 | double m_frequency; 116 | 117 | }; 118 | 119 | /// @} 120 | 121 | /// @} 122 | 123 | /// @} 124 | 125 | } 126 | 127 | } 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/model/sphere.h: -------------------------------------------------------------------------------- 1 | // sphere.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODEL_SPHERE_H 24 | #define NOISE_MODEL_SPHERE_H 25 | 26 | #include 27 | #include "../module/modulebase.h" 28 | 29 | namespace noise 30 | { 31 | 32 | namespace model 33 | { 34 | 35 | /// @addtogroup libnoise 36 | /// @{ 37 | 38 | /// @addtogroup models 39 | /// @{ 40 | 41 | /// Model that defines the surface of a sphere. 42 | /// 43 | /// @image html modelsphere.png 44 | /// 45 | /// This model returns an output value from a noise module given the 46 | /// coordinates of an input value located on the surface of a sphere. 47 | /// 48 | /// To generate an output value, pass the (latitude, longitude) 49 | /// coordinates of an input value to the GetValue() method. 50 | /// 51 | /// This model is useful for creating: 52 | /// - seamless textures that can be mapped onto a sphere 53 | /// - terrain height maps for entire planets 54 | /// 55 | /// This sphere has a radius of 1.0 unit and its center is located at 56 | /// the origin. 57 | class Sphere 58 | { 59 | 60 | public: 61 | 62 | /// Constructor. 63 | Sphere (); 64 | 65 | /// Constructor 66 | /// 67 | /// @param module The noise module that is used to generate the output 68 | /// values. 69 | Sphere (const module::Module& module); 70 | 71 | /// Returns the noise module that is used to generate the output 72 | /// values. 73 | /// 74 | /// @returns A reference to the noise module. 75 | /// 76 | /// @pre A noise module was passed to the SetModule() method. 77 | const module::Module& GetModule () const 78 | { 79 | assert (m_pModule != NULL); 80 | return *m_pModule; 81 | } 82 | 83 | /// Returns the output value from the noise module given the 84 | /// (latitude, longitude) coordinates of the specified input value 85 | /// located on the surface of the sphere. 86 | /// 87 | /// @param lat The latitude of the input value, in degrees. 88 | /// @param lon The longitude of the input value, in degrees. 89 | /// 90 | /// @returns The output value from the noise module. 91 | /// 92 | /// @pre A noise module was passed to the SetModule() method. 93 | /// 94 | /// This output value is generated by the noise module passed to the 95 | /// SetModule() method. 96 | /// 97 | /// Use a negative latitude if the input value is located on the 98 | /// southern hemisphere. 99 | /// 100 | /// Use a negative longitude if the input value is located on the 101 | /// western hemisphere. 102 | double GetValue (double lat, double lon) const; 103 | 104 | /// Sets the noise module that is used to generate the output values. 105 | /// 106 | /// @param module The noise module that is used to generate the output 107 | /// values. 108 | /// 109 | /// This noise module must exist for the lifetime of this object, 110 | /// until you pass a new noise module to this method. 111 | void SetModule (const module::Module& module) 112 | { 113 | m_pModule = &module; 114 | } 115 | 116 | private: 117 | 118 | /// A pointer to the noise module used to generate the output values. 119 | const module::Module* m_pModule; 120 | 121 | }; 122 | 123 | /// @} 124 | 125 | /// @} 126 | 127 | } 128 | 129 | } 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/model/cylinder.h: -------------------------------------------------------------------------------- 1 | // cylinder.h 2 | // 3 | // Copyright 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODEL_CYLINDER_H 24 | #define NOISE_MODEL_CYLINDER_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include "../module/modulebase.h" 30 | 31 | namespace noise 32 | { 33 | 34 | namespace model 35 | { 36 | 37 | /// @addtogroup libnoise 38 | /// @{ 39 | 40 | /// @defgroup models Models 41 | /// @addtogroup models 42 | /// @{ 43 | 44 | /// Model that defines the surface of a cylinder. 45 | /// 46 | /// @image html modelcylinder.png 47 | /// 48 | /// This model returns an output value from a noise module given the 49 | /// coordinates of an input value located on the surface of a cylinder. 50 | /// 51 | /// To generate an output value, pass the (angle, height) coordinates of 52 | /// an input value to the GetValue() method. 53 | /// 54 | /// This model is useful for creating: 55 | /// - seamless textures that can be mapped onto a cylinder 56 | /// 57 | /// This cylinder has a radius of 1.0 unit and has infinite height. It is 58 | /// oriented along the @a y axis. Its center is located at the origin. 59 | class Cylinder 60 | { 61 | 62 | public: 63 | 64 | /// Constructor. 65 | Cylinder (); 66 | 67 | /// Constructor 68 | /// 69 | /// @param module The noise module that is used to generate the output 70 | /// values. 71 | Cylinder (const module::Module& module); 72 | 73 | /// Returns the noise module that is used to generate the output 74 | /// values. 75 | /// 76 | /// @returns A reference to the noise module. 77 | /// 78 | /// @pre A noise module was passed to the SetModule() method. 79 | const module::Module& GetModule () const 80 | { 81 | assert (m_pModule != NULL); 82 | return *m_pModule; 83 | } 84 | 85 | /// Returns the output value from the noise module given the 86 | /// (angle, height) coordinates of the specified input value located 87 | /// on the surface of the cylinder. 88 | /// 89 | /// @param angle The angle around the cylinder's center, in degrees. 90 | /// @param height The height along the @a y axis. 91 | /// 92 | /// @returns The output value from the noise module. 93 | /// 94 | /// @pre A noise module was passed to the SetModule() method. 95 | /// 96 | /// This output value is generated by the noise module passed to the 97 | /// SetModule() method. 98 | /// 99 | /// This cylinder has a radius of 1.0 unit and has infinite height. 100 | /// It is oriented along the @a y axis. Its center is located at the 101 | /// origin. 102 | double GetValue (double angle, double height) const; 103 | 104 | /// Sets the noise module that is used to generate the output values. 105 | /// 106 | /// @param module The noise module that is used to generate the output 107 | /// values. 108 | /// 109 | /// This noise module must exist for the lifetime of this object, 110 | /// until you pass a new noise module to this method. 111 | void SetModule (const module::Module& module) 112 | { 113 | m_pModule = &module; 114 | } 115 | 116 | private: 117 | 118 | /// A pointer to the noise module used to generate the output values. 119 | const module::Module* m_pModule; 120 | 121 | }; 122 | 123 | /// @} 124 | 125 | /// @} 126 | 127 | } 128 | 129 | } 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /HeightmapRenderer/Resources/Shaders/terrain.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | ///////////////////////////////////////////////////////////////// 4 | 5 | // 6 | // Description : Array and textureless GLSL 2D/3D/4D simplex 7 | // noise functions. 8 | // Author : Ian McEwan, Ashima Arts. 9 | // Maintainer : ijm 10 | // Lastmod : 20110822 (ijm) 11 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 12 | // Distributed under the MIT License. See LICENSE file. 13 | // https://github.com/ashima/webgl-noise 14 | // 15 | 16 | vec3 mod289(vec3 x) { 17 | return x - floor(x * (1.0 / 289.0)) * 289.0; 18 | } 19 | 20 | vec4 mod289(vec4 x) { 21 | return x - floor(x * (1.0 / 289.0)) * 289.0; 22 | } 23 | 24 | vec4 permute(vec4 x) { 25 | return mod289(((x*34.0)+1.0)*x); 26 | } 27 | 28 | vec4 taylorInvSqrt(vec4 r) 29 | { 30 | return 1.79284291400159 - 0.85373472095314 * r; 31 | } 32 | 33 | float snoise(vec3 v) 34 | { 35 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ; 36 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); 37 | 38 | // First corner 39 | vec3 i = floor(v + dot(v, C.yyy) ); 40 | vec3 x0 = v - i + dot(i, C.xxx) ; 41 | 42 | // Other corners 43 | vec3 g = step(x0.yzx, x0.xyz); 44 | vec3 l = 1.0 - g; 45 | vec3 i1 = min( g.xyz, l.zxy ); 46 | vec3 i2 = max( g.xyz, l.zxy ); 47 | 48 | // x0 = x0 - 0.0 + 0.0 * C.xxx; 49 | // x1 = x0 - i1 + 1.0 * C.xxx; 50 | // x2 = x0 - i2 + 2.0 * C.xxx; 51 | // x3 = x0 - 1.0 + 3.0 * C.xxx; 52 | vec3 x1 = x0 - i1 + C.xxx; 53 | vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y 54 | vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y 55 | 56 | // Permutations 57 | i = mod289(i); 58 | vec4 p = permute( permute( permute( 59 | i.z + vec4(0.0, i1.z, i2.z, 1.0 )) 60 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 61 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 )); 62 | 63 | // Gradients: 7x7 points over a square, mapped onto an octahedron. 64 | // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) 65 | float n_ = 0.142857142857; // 1.0/7.0 66 | vec3 ns = n_ * D.wyz - D.xzx; 67 | 68 | vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) 69 | 70 | vec4 x_ = floor(j * ns.z); 71 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N) 72 | 73 | vec4 x = x_ *ns.x + ns.yyyy; 74 | vec4 y = y_ *ns.x + ns.yyyy; 75 | vec4 h = 1.0 - abs(x) - abs(y); 76 | 77 | vec4 b0 = vec4( x.xy, y.xy ); 78 | vec4 b1 = vec4( x.zw, y.zw ); 79 | 80 | //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; 81 | //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; 82 | vec4 s0 = floor(b0)*2.0 + 1.0; 83 | vec4 s1 = floor(b1)*2.0 + 1.0; 84 | vec4 sh = -step(h, vec4(0.0)); 85 | 86 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; 87 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ; 88 | 89 | vec3 p0 = vec3(a0.xy,h.x); 90 | vec3 p1 = vec3(a0.zw,h.y); 91 | vec3 p2 = vec3(a1.xy,h.z); 92 | vec3 p3 = vec3(a1.zw,h.w); 93 | 94 | //Normalise gradients 95 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 96 | p0 *= norm.x; 97 | p1 *= norm.y; 98 | p2 *= norm.z; 99 | p3 *= norm.w; 100 | 101 | // Mix final noise value 102 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0); 103 | m = m * m; 104 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 105 | dot(p2,x2), dot(p3,x3) ) ); 106 | } 107 | 108 | ///////////////////////////////////////////////////////////////// 109 | uniform struct Matrices 110 | { 111 | mat4 modelView; 112 | mat4 modelViewProjection; 113 | mat4 model; 114 | mat4 view; 115 | mat4 projection; 116 | mat4 normal; 117 | } matrix; 118 | 119 | uniform sampler3D bakedLightmaps; 120 | uniform sampler2D realTimeLightmap; 121 | uniform sampler2D heightmapField; 122 | uniform vec2 terrainUVScaling = vec2(25, 25); 123 | uniform vec2 terrainMapSize = vec2(256, 256); 124 | 125 | uniform float currentTime = 1.0f; 126 | 127 | // Input vertex data 128 | layout(location = 0) in vec3 vertexPosition; 129 | layout(location = 1) in vec3 vertexNormal; 130 | layout(location = 2) in vec2 vertexTexCoords; 131 | 132 | // Vertex shader output 133 | out vec2 texCoord; 134 | out vec3 normal; 135 | out vec3 position; 136 | out float height; 137 | 138 | void main() 139 | { 140 | vec4 vertexPos = vec4(vertexPosition, 1.0f); 141 | 142 | height = vertexPosition.y; 143 | 144 | texCoord = vertexTexCoords; 145 | normal = normalize(matrix.normal * vec4(vertexNormal, 0.0f)).xyz; 146 | position = vec3(matrix.modelView * vertexPos); 147 | 148 | gl_Position = matrix.modelViewProjection * vertexPos; 149 | } -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/scalebias.h: -------------------------------------------------------------------------------- 1 | // scalebias.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_SCALEBIAS_H 24 | #define NOISE_MODULE_SCALEBIAS_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Default bias for the noise::module::ScaleBias noise module. 44 | const double DEFAULT_BIAS = 0.0; 45 | 46 | /// Default scale for the noise::module::ScaleBias noise module. 47 | const double DEFAULT_SCALE = 1.0; 48 | 49 | /// Noise module that applies a scaling factor and a bias to the output 50 | /// value from a source module. 51 | /// 52 | /// @image html modulescalebias.png 53 | /// 54 | /// The GetValue() method retrieves the output value from the source 55 | /// module, multiplies it with a scaling factor, adds a bias to it, then 56 | /// outputs the value. 57 | /// 58 | /// This noise module requires one source module. 59 | class ScaleBias: public Module 60 | { 61 | 62 | public: 63 | 64 | /// Constructor. 65 | /// 66 | /// The default bias is set to noise::module::DEFAULT_BIAS. 67 | /// 68 | /// The default scaling factor is set to noise::module::DEFAULT_SCALE. 69 | ScaleBias (); 70 | 71 | /// Returns the bias to apply to the scaled output value from the 72 | /// source module. 73 | /// 74 | /// @returns The bias to apply. 75 | /// 76 | /// The GetValue() method retrieves the output value from the source 77 | /// module, multiplies it with the scaling factor, adds the bias to 78 | /// it, then outputs the value. 79 | double GetBias () const 80 | { 81 | return m_bias; 82 | } 83 | 84 | /// Returns the scaling factor to apply to the output value from the 85 | /// source module. 86 | /// 87 | /// @returns The scaling factor to apply. 88 | /// 89 | /// The GetValue() method retrieves the output value from the source 90 | /// module, multiplies it with the scaling factor, adds the bias to 91 | /// it, then outputs the value. 92 | double GetScale () const 93 | { 94 | return m_scale; 95 | } 96 | 97 | virtual int GetSourceModuleCount () const 98 | { 99 | return 1; 100 | } 101 | 102 | virtual double GetValue (double x, double y, double z) const; 103 | 104 | /// Sets the bias to apply to the scaled output value from the source 105 | /// module. 106 | /// 107 | /// @param bias The bias to apply. 108 | /// 109 | /// The GetValue() method retrieves the output value from the source 110 | /// module, multiplies it with the scaling factor, adds the bias to 111 | /// it, then outputs the value. 112 | void SetBias (double bias) 113 | { 114 | m_bias = bias; 115 | } 116 | 117 | /// Sets the scaling factor to apply to the output value from the 118 | /// source module. 119 | /// 120 | /// @param scale The scaling factor to apply. 121 | /// 122 | /// The GetValue() method retrieves the output value from the source 123 | /// module, multiplies it with the scaling factor, adds the bias to 124 | /// it, then outputs the value. 125 | void SetScale (double scale) 126 | { 127 | m_scale = scale; 128 | } 129 | 130 | protected: 131 | 132 | /// Bias to apply to the scaled output value from the source module. 133 | double m_bias; 134 | 135 | /// Scaling factor to apply to the output value from the source 136 | /// module. 137 | double m_scale; 138 | 139 | }; 140 | 141 | /// @} 142 | 143 | /// @} 144 | 145 | /// @} 146 | 147 | } 148 | 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/clamp.h: -------------------------------------------------------------------------------- 1 | // clamp.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CLAMP_H 24 | #define NOISE_MODULE_CLAMP_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Default lower bound of the clamping range for the noise::module::Clamp 44 | /// noise module. 45 | const double DEFAULT_CLAMP_LOWER_BOUND = -1.0; 46 | 47 | /// Default upper bound of the clamping range for the noise::module::Clamp 48 | /// noise module. 49 | const double DEFAULT_CLAMP_UPPER_BOUND = 1.0; 50 | 51 | /// Noise module that clamps the output value from a source module to a 52 | /// range of values. 53 | /// 54 | /// @image html moduleclamp.png 55 | /// 56 | /// The range of values in which to clamp the output value is called the 57 | /// clamping range. 58 | /// 59 | /// If the output value from the source module is less than the lower 60 | /// bound of the clamping range, this noise module clamps that value to 61 | /// the lower bound. If the output value from the source module is 62 | /// greater than the upper bound of the clamping range, this noise module 63 | /// clamps that value to the upper bound. 64 | /// 65 | /// To specify the upper and lower bounds of the clamping range, call the 66 | /// SetBounds() method. 67 | /// 68 | /// This noise module requires one source module. 69 | class Clamp: public Module 70 | { 71 | 72 | public: 73 | 74 | /// Constructor. 75 | /// 76 | /// The default lower bound of the clamping range is set to 77 | /// noise::module::DEFAULT_CLAMP_LOWER_BOUND. 78 | /// 79 | /// The default upper bound of the clamping range is set to 80 | /// noise::module::DEFAULT_CLAMP_UPPER_BOUND. 81 | Clamp (); 82 | 83 | /// Returns the lower bound of the clamping range. 84 | /// 85 | /// @returns The lower bound. 86 | /// 87 | /// If the output value from the source module is less than the lower 88 | /// bound of the clamping range, this noise module clamps that value 89 | /// to the lower bound. 90 | double GetLowerBound () const 91 | { 92 | return m_lowerBound; 93 | } 94 | 95 | virtual int GetSourceModuleCount () const 96 | { 97 | return 1; 98 | } 99 | 100 | /// Returns the upper bound of the clamping range. 101 | /// 102 | /// @returns The upper bound. 103 | /// 104 | /// If the output value from the source module is greater than the 105 | /// upper bound of the clamping range, this noise module clamps that 106 | /// value to the upper bound. 107 | double GetUpperBound () const 108 | { 109 | return m_upperBound; 110 | } 111 | 112 | virtual double GetValue (double x, double y, double z) const; 113 | 114 | /// Sets the lower and upper bounds of the clamping range. 115 | /// 116 | /// @param lowerBound The lower bound. 117 | /// @param upperBound The upper bound. 118 | /// 119 | /// @pre The lower bound must be less than or equal to the 120 | /// upper bound. 121 | /// 122 | /// @throw noise::ExceptionInvalidParam An invalid parameter was 123 | /// specified; see the preconditions for more information. 124 | /// 125 | /// If the output value from the source module is less than the lower 126 | /// bound of the clamping range, this noise module clamps that value 127 | /// to the lower bound. If the output value from the source module 128 | /// is greater than the upper bound of the clamping range, this noise 129 | /// module clamps that value to the upper bound. 130 | void SetBounds (double lowerBound, double upperBound); 131 | 132 | protected: 133 | 134 | /// Lower bound of the clamping range. 135 | double m_lowerBound; 136 | 137 | /// Upper bound of the clamping range. 138 | double m_upperBound; 139 | 140 | }; 141 | 142 | /// @} 143 | 144 | /// @} 145 | 146 | /// @} 147 | 148 | } 149 | 150 | } 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /HeightmapRenderer/HeightmapRenderer.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | 127 | 128 | Resource Files 129 | 130 | 131 | Resource Files 132 | 133 | 134 | Resource Files 135 | 136 | 137 | Resource Files 138 | 139 | 140 | Resource Files 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/blend.h: -------------------------------------------------------------------------------- 1 | // blend.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_BLEND_H 24 | #define NOISE_MODULE_BLEND_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup selectormodules Selector Modules 41 | /// @addtogroup selectormodules 42 | /// @{ 43 | 44 | /// Noise module that outputs a weighted blend of the output values from 45 | /// two source modules given the output value supplied by a control module. 46 | /// 47 | /// @image html moduleblend.png 48 | /// 49 | /// Unlike most other noise modules, the index value assigned to a source 50 | /// module determines its role in the blending operation: 51 | /// - Source module 0 (upper left in the diagram) outputs one of the 52 | /// values to blend. 53 | /// - Source module 1 (lower left in the diagram) outputs one of the 54 | /// values to blend. 55 | /// - Source module 2 (bottom of the diagram) is known as the control 56 | /// module. The control module determines the weight of the 57 | /// blending operation. Negative values weigh the blend towards the 58 | /// output value from the source module with an index value of 0. 59 | /// Positive values weigh the blend towards the output value from the 60 | /// source module with an index value of 1. 61 | /// 62 | /// An application can pass the control module to the SetControlModule() 63 | /// method instead of the SetSourceModule() method. This may make the 64 | /// application code easier to read. 65 | /// 66 | /// This noise module uses linear interpolation to perform the blending 67 | /// operation. 68 | /// 69 | /// This noise module requires three source modules. 70 | class Blend: public Module 71 | { 72 | 73 | public: 74 | 75 | /// Constructor. 76 | Blend (); 77 | 78 | /// Returns the control module. 79 | /// 80 | /// @returns A reference to the control module. 81 | /// 82 | /// @pre A control module has been added to this noise module via a 83 | /// call to SetSourceModule() or SetControlModule(). 84 | /// 85 | /// @throw noise::ExceptionNoModule See the preconditions for more 86 | /// information. 87 | /// 88 | /// The control module determines the weight of the blending 89 | /// operation. Negative values weigh the blend towards the output 90 | /// value from the source module with an index value of 0. Positive 91 | /// values weigh the blend towards the output value from the source 92 | /// module with an index value of 1. 93 | const Module& GetControlModule () const 94 | { 95 | if (m_pSourceModule == NULL || m_pSourceModule[2] == NULL) { 96 | throw noise::ExceptionNoModule (); 97 | } 98 | return *(m_pSourceModule[2]); 99 | } 100 | 101 | virtual int GetSourceModuleCount () const 102 | { 103 | return 3; 104 | } 105 | 106 | virtual double GetValue (double x, double y, double z) const; 107 | 108 | /// Sets the control module. 109 | /// 110 | /// @param controlModule The control module. 111 | /// 112 | /// The control module determines the weight of the blending 113 | /// operation. Negative values weigh the blend towards the output 114 | /// value from the source module with an index value of 0. Positive 115 | /// values weigh the blend towards the output value from the source 116 | /// module with an index value of 1. 117 | /// 118 | /// This method assigns the control module an index value of 2. 119 | /// Passing the control module to this method produces the same 120 | /// results as passing the control module to the SetSourceModule() 121 | /// method while assigning that noise module an index value of 2. 122 | /// 123 | /// This control module must exist throughout the lifetime of this 124 | /// noise module unless another control module replaces that control 125 | /// module. 126 | void SetControlModule (const Module& controlModule) 127 | { 128 | assert (m_pSourceModule != NULL); 129 | m_pSourceModule[2] = &controlModule; 130 | } 131 | 132 | }; 133 | 134 | /// @} 135 | 136 | /// @} 137 | 138 | /// @} 139 | 140 | } 141 | 142 | } 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /HeightmapRenderer/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Commons.h" 2 | #include "Camera.h" 3 | #include "TransformationMatrices.h" 4 | 5 | Camera::Camera() 6 | { 7 | } 8 | 9 | Camera::~Camera() 10 | { 11 | } 12 | 13 | void Camera::lookAt(const glm::vec3 &eye, const glm::vec3 ¢er, 14 | const glm::vec3 &up/*= glm::vec3(0.0f, 1.0f, 0.0)*/) 15 | { 16 | this->eye = eye; 17 | this->center = center; 18 | this->upVector = up; 19 | TransformationMatrices::View( 20 | glm::lookAt( 21 | eye, 22 | center, 23 | up 24 | ) 25 | ); 26 | } 27 | 28 | glm::vec4 Camera::getPlane(Plane p) const 29 | { 30 | return planes[p]; 31 | } 32 | 33 | void Camera::calcPlanes(const glm::mat4 &matrix) 34 | { 35 | // Extract frustum planes from matrix 36 | // Planes are in format: normal(xyz), offset(w) 37 | planes[Right] = glm::vec4(matrix[0][3] - matrix[0][0], 38 | matrix[1][3] - matrix[1][0], 39 | matrix[2][3] - matrix[2][0], 40 | matrix[3][3] - matrix[3][0]); 41 | planes[Left] = glm::vec4(matrix[0][3] + matrix[0][0], 42 | matrix[1][3] + matrix[1][0], 43 | matrix[2][3] + matrix[2][0], 44 | matrix[3][3] + matrix[3][0]); 45 | planes[Bottom] = glm::vec4(matrix[0][3] + matrix[0][1], 46 | matrix[1][3] + matrix[1][1], 47 | matrix[2][3] + matrix[2][1], 48 | matrix[3][3] + matrix[3][1]); 49 | planes[Top] = glm::vec4(matrix[0][3] - matrix[0][1], 50 | matrix[1][3] - matrix[1][1], 51 | matrix[2][3] - matrix[2][1], 52 | matrix[3][3] - matrix[3][1]); 53 | planes[Far] = glm::vec4(matrix[0][3] - matrix[0][2], 54 | matrix[1][3] - matrix[1][2], 55 | matrix[2][3] - matrix[2][2], 56 | matrix[3][3] - matrix[3][2]); 57 | planes[Near] = glm::vec4(matrix[0][3] + matrix[0][2], 58 | matrix[1][3] + matrix[1][2], 59 | matrix[2][3] + matrix[2][2], 60 | matrix[3][3] + matrix[3][2]); 61 | 62 | // Normalize them 63 | for(int i = 0; i < 6; i++) 64 | { 65 | float invl = sqrt(planes[i].x * planes[i].x + 66 | planes[i].y * planes[i].y + 67 | planes[i].z * planes[i].z); 68 | planes[i] /= invl; 69 | } 70 | } 71 | 72 | int Camera::halfPlaneTest(const glm::vec3 &p, const glm::vec3 &normal, 73 | float offset) 74 | { 75 | float dist = glm::dot(p, normal) + offset; 76 | 77 | if(dist > 0.02) // Point is in front of plane 78 | return 1; 79 | else if(dist < -0.02) // Point is behind plane 80 | return 0; 81 | 82 | return 2; // Point is on plane 83 | } 84 | 85 | int Camera::isBoxInFrustum(const glm::vec3 &origin, const glm::vec3 &halfDim) 86 | { 87 | static const glm::vec3 cornerOffsets[] = 88 | { 89 | glm::vec3(-1.f, -1.f, -1.f), 90 | glm::vec3(-1.f, -1.f, 1.f), 91 | glm::vec3(-1.f, 1.f, -1.f), 92 | glm::vec3(-1.f, 1.f, 1.f), 93 | glm::vec3(1.f, -1.f, -1.f), 94 | glm::vec3(1.f, -1.f, 1.f), 95 | glm::vec3(1.f, 1.f, -1.f), 96 | glm::vec3(1.f, 1.f, 1.f) 97 | }; 98 | int ret = 1; 99 | 100 | for(int i = 0; i < 6; i++) 101 | { 102 | glm::vec3 planeNormal = glm::vec3(planes[i]); 103 | int idx = vectorToIndex(planeNormal); 104 | // Test the farthest point of the box from the plane 105 | // if it's behind the plane, then the entire box will be. 106 | glm::vec3 testPoint = origin + halfDim * cornerOffsets[idx]; 107 | 108 | if(halfPlaneTest(testPoint, planeNormal, planes[i].w) == 0) 109 | { 110 | ret = 0; 111 | break; 112 | } 113 | 114 | // Now, test the closest point to the plane 115 | // If it's behind the plane, then the box is partially inside, otherwise it is entirely inside. 116 | idx = vectorToIndex(-planeNormal); 117 | testPoint = origin + halfDim * cornerOffsets[idx]; 118 | 119 | if(halfPlaneTest(testPoint, planeNormal, planes[i].w) == 0) 120 | { 121 | ret |= 2; 122 | } 123 | } 124 | 125 | return ret; 126 | } 127 | 128 | void Camera::perspective(float fovy, float aspect, float nearClip, 129 | float farClip) 130 | { 131 | this->fovy = fovy; 132 | this->aspect = aspect; 133 | this->nearClip = nearClip; 134 | this->farClip = farClip; 135 | TransformationMatrices::Projection( 136 | glm::perspective(fovy, aspect, nearClip, farClip) 137 | ); 138 | } 139 | 140 | void Camera::perspective(float fovy, int width, int height, float nearClip, 141 | float farClip) 142 | { 143 | this->fovy = fovy; 144 | this->aspect = aspect; 145 | this->nearClip = nearClip; 146 | this->farClip = farClip; 147 | this->width = width; 148 | this->height = height; 149 | this->aspect = (float)width / height; 150 | float ymax = nearClip * glm::tan(fovy * 0.5f); 151 | float xmax = ymax * aspect; 152 | this->frustumP = glm::vec4(-xmax, xmax, -ymax, ymax); 153 | // set scene matrix 154 | TransformationMatrices::Projection( 155 | glm::frustum( 156 | frustumP.x, frustumP.y, frustumP.z, frustumP.w, nearClip, 157 | farClip 158 | ) 159 | ); 160 | } 161 | -------------------------------------------------------------------------------- /HeightmapRenderer/Terrain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Heightmap.h" 3 | #include "TerrainMultiTexture.h" 4 | #include "TerrainChunksGenerator.h" 5 | using namespace oglplus; 6 | 7 | class Terrain 8 | { 9 | private: 10 | // terrain shader uniforms used in the render loop 11 | Uniform lightDirection; 12 | Uniform lightIntensities; 13 | Uniform modelViewProjection; 14 | Uniform modelView; 15 | Uniform normalMatrix; 16 | Uniform currentLightmap; 17 | public: 18 | TerrainChunksGenerator chunkGenerator; 19 | bool useLoDChunks = false; 20 | // represents the amount of time on daylight 21 | const float sunTime = 0.6f; 22 | // scales moon height and nightlight 23 | const float moonAltitude = 1.3f; 24 | // scales sun height at daylight 25 | const float sunAltitude = 1.9f; 26 | // terrain light direction on time 27 | glm::vec3 calculateLightDir(float time); 28 | // terrain light direction and color on time 29 | void calculateLightDir(float time, glm::vec3 &outDir, glm::vec3 &outColor); 30 | // mesh height at position 31 | float heightAt(glm::vec2 position); 32 | private: 33 | void setProgramUniforms(float time); 34 | // multiplies for current time 35 | float timeScale; 36 | // temporal baked ligthmaps data, deleted once 37 | // baking is done 38 | unsigned char * terrainLightmapsData; 39 | // flag to tell the main thread when lightmap baking is done 40 | // upload data to GPU once done 41 | std::atomic bakingDone = false; 42 | std::atomic bakingInProgress = false; 43 | std::atomic earlyExit = false; // used on exit() to stop thread early 44 | // if enabled changes directional light color based on time 45 | bool enableTimeOfTheDayColorGrading = true; 46 | // thread for baking all time of the day lightmaps 47 | std::thread bakingThread; 48 | // freq represents the number of sampler per day 49 | // for example 24 == 1 shadowmap per hour 50 | // call using bakingThread, this is a heavy operation 51 | void bakeTimeOfTheDayShadowmap(int lightmapSize); 52 | private: 53 | // terrain status indicator 54 | bool defaultLightmapsBaked = false; 55 | bool heightmapCreated; 56 | bool meshCreated; 57 | // final index size 58 | unsigned int indexSize; 59 | // mesh data gpu buffers 60 | std::array buffer; 61 | // mesh general data 62 | int meshResolution; 63 | int terrainResolution; 64 | int lightmapResolution; 65 | glm::vec3 meshSampleSquare; 66 | // meshSize * meshSize = vertex count 67 | int meshSize; 68 | float heightScale; 69 | float terrainHorizontalScale; 70 | int lightmapsFrequency; 71 | int terrainSeed; 72 | // utilities 73 | VertexArray terrainMesh; 74 | FragmentShader fragmentShader; 75 | VertexShader vertexShader; 76 | Program program; 77 | Context gl; 78 | // heightmap field texture 79 | Texture heightmapField; 80 | // terrain shadows, generated with heightmap info 81 | Texture terrainShadowmap; 82 | // time of the day 3d texture 83 | Texture terrainTOTDLightmap; 84 | // heightmap generator 85 | Heightmap heightmap; 86 | // multitexture handling class 87 | TerrainMultiTexture terrainTextures; 88 | void createTOTD3DTexture(); 89 | public: 90 | void initialize(); 91 | void render(float time); 92 | // binds the terrain buffers, whole mesh data 93 | void bindBuffers(); 94 | 95 | // lightmap as output, uses terrain resolution for lightmap size 96 | void fastGenerateShadowmapParallel( 97 | glm::vec3 lightDir, 98 | std::vector &lightmap 99 | ); 100 | // lightmap as out with custom lightmap size 101 | void fastGenerateShadowmapParallel( 102 | glm::vec3 lightDir, 103 | std::vector &lightmap, 104 | unsigned int lightmapSize 105 | ); 106 | // writes lightmap to extra lightmap texture, clears vector data 107 | void fastGenerateShadowmapParallel( 108 | glm::vec3 lightDir, 109 | unsigned int lightmapSize 110 | ); 111 | 112 | // creates a terrain of 2^sizeExponent + 1 size 113 | void createTerrain(const int heightmapSize, const glm::vec3 sampleSquare, 114 | int seed); 115 | void createMesh(const int meshResExponent); 116 | void bakeLightmaps(float freq, int lightmapSize); 117 | 118 | // terrain multi texture control functions 119 | void setTextureRepeatFrequency(const glm::vec2 &value); 120 | void setTextureRange(const int index, const float start, const float end); 121 | void loadTexture(const int index, const std::string &filepath); 122 | 123 | // time parameters 124 | void EnableTimeOfTheDayColorGrading(bool val) { enableTimeOfTheDayColorGrading = val; } 125 | void TimeScale(float val) { timeScale = val; } 126 | 127 | // returns terrain multitexture at index 128 | GLuint getTextureId(int index); 129 | // returns terrain extra lightmap, created with fastGenerateShadowmapParallel 130 | GLuint getLightmapId() { return oglplus::GetName(this->terrainShadowmap); }; 131 | 132 | // mesh vertical scaling 133 | void HeightScale(float val); 134 | float HeightScale() const { return this->heightScale; }; 135 | // mesh horizontal scaling (scales x and z) 136 | void TerrainHorizontalScale(float val); 137 | float TerrainHorizontalScale() const { return this->terrainHorizontalScale; }; 138 | 139 | // saves terrain data to a bmp greyscale file 140 | void saveTerrainToFile(const std::string &filename); 141 | 142 | Terrain(); 143 | ~Terrain(); 144 | void Occlusion(float occlusionStrenght); 145 | }; 146 | 147 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/model/line.h: -------------------------------------------------------------------------------- 1 | // line.h 2 | // 3 | // Copyright (C) 2004 Keith Davies 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | 20 | #ifndef NOISE_MODEL_LINE_H 21 | #define NOISE_MODEL_LINE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "../module/modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace model 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup models 38 | /// @{ 39 | 40 | /// Model that defines the displacement of a line segment. 41 | /// 42 | /// This model returns an output value from a noise module given the 43 | /// one-dimensional coordinate of an input value located on a line 44 | /// segment, which can be used as displacements. 45 | /// 46 | /// This class is useful for creating: 47 | /// - roads and rivers 48 | /// - disaffected college students 49 | /// 50 | /// To generate an output value, pass an input value between 0.0 and 1.0 51 | /// to the GetValue() method. 0.0 represents the start position of the 52 | /// line segment and 1.0 represents the end position of the line segment. 53 | class Line 54 | { 55 | 56 | public: 57 | 58 | /// Constructor. 59 | Line (); 60 | 61 | /// Constructor 62 | /// 63 | /// @param module The noise module that is used to generate the output 64 | /// values. 65 | Line (const module::Module& module); 66 | 67 | /// Returns a flag indicating whether the output value is to be 68 | /// attenuated (moved toward 0.0) as the ends of the line segment are 69 | /// approached by the input value. 70 | /// 71 | /// @returns 72 | /// - @a true if the value is to be attenuated 73 | /// - @a false if not. 74 | bool GetAttenuate () const 75 | { 76 | return m_attenuate; 77 | } 78 | 79 | /// Returns the noise module that is used to generate the output 80 | /// values. 81 | /// 82 | /// @returns A reference to the noise module. 83 | /// 84 | /// @pre A noise module was passed to the SetModule() method. 85 | const module::Module& GetModule () const 86 | { 87 | assert (m_pModule != NULL); 88 | return *m_pModule; 89 | } 90 | 91 | /// Returns the output value from the noise module given the 92 | /// one-dimensional coordinate of the specified input value located 93 | /// on the line segment. 94 | /// 95 | /// @param p The distance along the line segment (ranges from 0.0 96 | /// to 1.0) 97 | /// 98 | /// @returns The output value from the noise module. 99 | /// 100 | /// @pre A noise module was passed to the SetModule() method. 101 | /// @pre The start and end points of the line segment were specified. 102 | /// 103 | /// The output value is generated by the noise module passed to the 104 | /// SetModule() method. This value may be attenuated (moved toward 105 | /// 0.0) as @a p approaches either end of the line segment; this is 106 | /// the default behavior. 107 | /// 108 | /// If the value is not to be attenuated, @a p can safely range 109 | /// outside the 0.0 to 1.0 range; the output value will be 110 | /// extrapolated along the line that this segment is part of. 111 | double GetValue (double p) const; 112 | 113 | /// Sets a flag indicating that the output value is to be attenuated 114 | /// (moved toward 0.0) as the ends of the line segment are approached. 115 | /// 116 | /// @param att A flag that specifies whether the output value is to be 117 | /// attenuated. 118 | void SetAttenuate (bool att) 119 | { 120 | m_attenuate = att; 121 | } 122 | 123 | /// Sets the position ( @a x, @a y, @a z ) of the end of the line 124 | /// segment to choose values along. 125 | /// 126 | /// @param x x coordinate of the end position. 127 | /// @param y y coordinate of the end position. 128 | /// @param z z coordinate of the end position. 129 | void SetEndPoint (double x, double y, double z) 130 | { 131 | m_x1 = x; 132 | m_y1 = y; 133 | m_z1 = z; 134 | } 135 | 136 | /// Sets the noise module that is used to generate the output values. 137 | /// 138 | /// @param module The noise module that is used to generate the output 139 | /// values. 140 | /// 141 | /// This noise module must exist for the lifetime of this object, 142 | /// until you pass a new noise module to this method. 143 | void SetModule (const module::Module& module) 144 | { 145 | m_pModule = &module; 146 | } 147 | 148 | /// Sets the position ( @a x, @a y, @a z ) of the start of the line 149 | /// segment to choose values along. 150 | /// 151 | /// @param x x coordinate of the start position. 152 | /// @param y y coordinate of the start position. 153 | /// @param z z coordinate of the start position. 154 | void SetStartPoint (double x, double y, double z) 155 | { 156 | m_x0 = x; 157 | m_y0 = y; 158 | m_z0 = z; 159 | } 160 | 161 | private: 162 | 163 | /// A flag that specifies whether the value is to be attenuated 164 | /// (moved toward 0.0) as the ends of the line segment are approached. 165 | bool m_attenuate; 166 | 167 | /// A pointer to the noise module used to generate the output values. 168 | const module::Module* m_pModule; 169 | 170 | /// @a x coordinate of the start of the line segment. 171 | double m_x0; 172 | 173 | /// @a x coordinate of the end of the line segment. 174 | double m_x1; 175 | 176 | /// @a y coordinate of the start of the line segment. 177 | double m_y0; 178 | 179 | /// @a y coordinate of the end of the line segment. 180 | double m_y1; 181 | 182 | /// @a z coordinate of the start of the line segment. 183 | double m_z0; 184 | 185 | /// @a z coordinate of the end of the line segment. 186 | double m_z1; 187 | 188 | }; 189 | 190 | /// @} 191 | 192 | /// @} 193 | 194 | } 195 | 196 | } 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/curve.h: -------------------------------------------------------------------------------- 1 | // curve.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CURVE_H 24 | #define NOISE_MODULE_CURVE_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// This structure defines a control point. 38 | /// 39 | /// Control points are used for defining splines. 40 | struct ControlPoint 41 | { 42 | 43 | /// The input value. 44 | double inputValue; 45 | 46 | /// The output value that is mapped from the input value. 47 | double outputValue; 48 | 49 | }; 50 | 51 | /// @addtogroup modules 52 | /// @{ 53 | 54 | /// @addtogroup modifiermodules 55 | /// @{ 56 | 57 | /// Noise module that maps the output value from a source module onto an 58 | /// arbitrary function curve. 59 | /// 60 | /// @image html modulecurve.png 61 | /// 62 | /// This noise module maps the output value from the source module onto an 63 | /// application-defined curve. This curve is defined by a number of 64 | /// control points; each control point has an input value 65 | /// that maps to an output value. Refer to the following 66 | /// illustration: 67 | /// 68 | /// @image html curve.png 69 | /// 70 | /// To add the control points to this curve, call the AddControlPoint() 71 | /// method. 72 | /// 73 | /// Since this curve is a cubic spline, an application must add a minimum 74 | /// of four control points to the curve. If this is not done, the 75 | /// GetValue() method fails. Each control point can have any input and 76 | /// output value, although no two control points can have the same input 77 | /// value. There is no limit to the number of control points that can be 78 | /// added to the curve. 79 | /// 80 | /// This noise module requires one source module. 81 | class Curve: public Module 82 | { 83 | 84 | public: 85 | 86 | /// Constructor. 87 | Curve (); 88 | 89 | /// Destructor. 90 | ~Curve (); 91 | 92 | /// Adds a control point to the curve. 93 | /// 94 | /// @param inputValue The input value stored in the control point. 95 | /// @param outputValue The output value stored in the control point. 96 | /// 97 | /// @pre No two control points have the same input value. 98 | /// 99 | /// @throw noise::ExceptionInvalidParam An invalid parameter was 100 | /// specified; see the preconditions for more information. 101 | /// 102 | /// It does not matter which order these points are added. 103 | void AddControlPoint (double inputValue, double outputValue); 104 | 105 | /// Deletes all the control points on the curve. 106 | /// 107 | /// @post All points on the curve are deleted. 108 | void ClearAllControlPoints (); 109 | 110 | /// Returns a pointer to the array of control points on the curve. 111 | /// 112 | /// @returns A pointer to the array of control points. 113 | /// 114 | /// Before calling this method, call GetControlPointCount() to 115 | /// determine the number of control points in this array. 116 | /// 117 | /// It is recommended that an application does not store this pointer 118 | /// for later use since the pointer to the array may change if the 119 | /// application calls another method of this object. 120 | const ControlPoint* GetControlPointArray () const 121 | { 122 | return m_pControlPoints; 123 | } 124 | 125 | /// Returns the number of control points on the curve. 126 | /// 127 | /// @returns The number of control points on the curve. 128 | int GetControlPointCount () const 129 | { 130 | return m_controlPointCount; 131 | } 132 | 133 | virtual int GetSourceModuleCount () const 134 | { 135 | return 1; 136 | } 137 | 138 | virtual double GetValue (double x, double y, double z) const; 139 | 140 | protected: 141 | 142 | /// Determines the array index in which to insert the control point 143 | /// into the internal control point array. 144 | /// 145 | /// @param inputValue The input value of the control point. 146 | /// 147 | /// @returns The array index in which to insert the control point. 148 | /// 149 | /// @pre No two control points have the same input value. 150 | /// 151 | /// @throw noise::ExceptionInvalidParam An invalid parameter was 152 | /// specified; see the preconditions for more information. 153 | /// 154 | /// By inserting the control point at the returned array index, this 155 | /// class ensures that the control point array is sorted by input 156 | /// value. The code that maps a value onto the curve requires a 157 | /// sorted control point array. 158 | int FindInsertionPos (double inputValue); 159 | 160 | /// Inserts the control point at the specified position in the 161 | /// internal control point array. 162 | /// 163 | /// @param insertionPos The zero-based array position in which to 164 | /// insert the control point. 165 | /// @param inputValue The input value stored in the control point. 166 | /// @param outputValue The output value stored in the control point. 167 | /// 168 | /// To make room for this new control point, this method reallocates 169 | /// the control point array and shifts all control points occurring 170 | /// after the insertion position up by one. 171 | /// 172 | /// Because the curve mapping algorithm used by this noise module 173 | /// requires that all control points in the array must be sorted by 174 | /// input value, the new control point should be inserted at the 175 | /// position in which the order is still preserved. 176 | void InsertAtPos (int insertionPos, double inputValue, 177 | double outputValue); 178 | 179 | /// Number of control points on the curve. 180 | int m_controlPointCount; 181 | 182 | /// Array that stores the control points. 183 | ControlPoint* m_pControlPoints; 184 | 185 | }; 186 | 187 | /// @} 188 | 189 | /// @} 190 | 191 | /// @} 192 | 193 | } 194 | 195 | } 196 | 197 | #endif 198 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/scalepoint.h: -------------------------------------------------------------------------------- 1 | // scalepoint.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_SCALEPOINT_H 24 | #define NOISE_MODULE_SCALEPOINT_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup transformermodules 41 | /// @{ 42 | 43 | /// Default scaling factor applied to the @a x coordinate for the 44 | /// noise::module::ScalePoint noise module. 45 | const double DEFAULT_SCALE_POINT_X = 1.0; 46 | 47 | /// Default scaling factor applied to the @a y coordinate for the 48 | /// noise::module::ScalePoint noise module. 49 | const double DEFAULT_SCALE_POINT_Y = 1.0; 50 | 51 | /// Default scaling factor applied to the @a z coordinate for the 52 | /// noise::module::ScalePoint noise module. 53 | const double DEFAULT_SCALE_POINT_Z = 1.0; 54 | 55 | /// Noise module that scales the coordinates of the input value before 56 | /// returning the output value from a source module. 57 | /// 58 | /// @image html modulescalepoint.png 59 | /// 60 | /// The GetValue() method multiplies the ( @a x, @a y, @a z ) coordinates 61 | /// of the input value with a scaling factor before returning the output 62 | /// value from the source module. To set the scaling factor, call the 63 | /// SetScale() method. To set the scaling factor to apply to the 64 | /// individual @a x, @a y, or @a z coordinates, call the SetXScale(), 65 | /// SetYScale() or SetZScale() methods, respectively. 66 | /// 67 | /// This noise module requires one source module. 68 | class ScalePoint: public Module 69 | { 70 | 71 | public: 72 | 73 | /// Constructor. 74 | /// 75 | /// The default scaling factor applied to the @a x coordinate is set 76 | /// to noise::module::DEFAULT_SCALE_POINT_X. 77 | /// 78 | /// The default scaling factor applied to the @a y coordinate is set 79 | /// to noise::module::DEFAULT_SCALE_POINT_Y. 80 | /// 81 | /// The default scaling factor applied to the @a z coordinate is set 82 | /// to noise::module::DEFAULT_SCALE_POINT_Z. 83 | ScalePoint (); 84 | 85 | virtual int GetSourceModuleCount () const 86 | { 87 | return 1; 88 | } 89 | 90 | virtual double GetValue (double x, double y, double z) const; 91 | 92 | /// Returns the scaling factor applied to the @a x coordinate of the 93 | /// input value. 94 | /// 95 | /// @returns The scaling factor applied to the @a x coordinate. 96 | double GetXScale () const 97 | { 98 | return m_xScale; 99 | } 100 | 101 | /// Returns the scaling factor applied to the @a y coordinate of the 102 | /// input value. 103 | /// 104 | /// @returns The scaling factor applied to the @a y coordinate. 105 | double GetYScale () const 106 | { 107 | return m_yScale; 108 | } 109 | 110 | /// Returns the scaling factor applied to the @a z coordinate of the 111 | /// input value. 112 | /// 113 | /// @returns The scaling factor applied to the @a z coordinate. 114 | double GetZScale () const 115 | { 116 | return m_zScale; 117 | } 118 | 119 | /// Sets the scaling factor to apply to the input value. 120 | /// 121 | /// @param scale The scaling factor to apply. 122 | /// 123 | /// The GetValue() method multiplies the ( @a x, @a y, @a z ) 124 | /// coordinates of the input value with a scaling factor before 125 | /// returning the output value from the source module. 126 | void SetScale (double scale) 127 | { 128 | m_xScale = scale; 129 | m_yScale = scale; 130 | m_zScale = scale; 131 | } 132 | 133 | /// Sets the scaling factor to apply to the ( @a x, @a y, @a z ) 134 | /// coordinates of the input value. 135 | /// 136 | /// @param xScale The scaling factor to apply to the @a x coordinate. 137 | /// @param yScale The scaling factor to apply to the @a y coordinate. 138 | /// @param zScale The scaling factor to apply to the @a z coordinate. 139 | /// 140 | /// The GetValue() method multiplies the ( @a x, @a y, @a z ) 141 | /// coordinates of the input value with a scaling factor before 142 | /// returning the output value from the source module. 143 | void SetScale (double xScale, double yScale, double zScale) 144 | { 145 | m_xScale = xScale; 146 | m_yScale = yScale; 147 | m_zScale = zScale; 148 | } 149 | 150 | /// Sets the scaling factor to apply to the @a x coordinate of the 151 | /// input value. 152 | /// 153 | /// @param xScale The scaling factor to apply to the @a x coordinate. 154 | /// 155 | /// The GetValue() method multiplies the ( @a x, @a y, @a z ) 156 | /// coordinates of the input value with a scaling factor before 157 | /// returning the output value from the source module. 158 | void SetXScale (double xScale) 159 | { 160 | m_xScale = xScale; 161 | } 162 | 163 | /// Sets the scaling factor to apply to the @a y coordinate of the 164 | /// input value. 165 | /// 166 | /// @param yScale The scaling factor to apply to the @a y coordinate. 167 | /// 168 | /// The GetValue() method multiplies the ( @a x, @a y, @a z ) 169 | /// coordinates of the input value with a scaling factor before 170 | /// returning the output value from the source module. 171 | void SetYScale (double yScale) 172 | { 173 | m_yScale = yScale; 174 | } 175 | 176 | /// Sets the scaling factor to apply to the @a z coordinate of the 177 | /// input value. 178 | /// 179 | /// @param zScale The scaling factor to apply to the @a z coordinate. 180 | /// 181 | /// The GetValue() method multiplies the ( @a x, @a y, @a z ) 182 | /// coordinates of the input value with a scaling factor before 183 | /// returning the output value from the source module. 184 | void SetZScale (double zScale) 185 | { 186 | m_zScale = zScale; 187 | } 188 | 189 | protected: 190 | 191 | /// Scaling factor applied to the @a x coordinate of the input value. 192 | double m_xScale; 193 | 194 | /// Scaling factor applied to the @a y coordinate of the input value. 195 | double m_yScale; 196 | 197 | /// Scaling factor applied to the @a z coordinate of the input value. 198 | double m_zScale; 199 | 200 | }; 201 | 202 | /// @} 203 | 204 | /// @} 205 | 206 | /// @} 207 | 208 | } 209 | 210 | } 211 | 212 | #endif 213 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/rotatepoint.h: -------------------------------------------------------------------------------- 1 | // rotatepoint.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_ROTATEPOINT_H 24 | #define NOISE_MODULE_ROTATEPOINT_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup transformermodules 41 | /// @{ 42 | 43 | /// Default @a x rotation angle for the noise::module::RotatePoint noise 44 | /// module. 45 | const double DEFAULT_ROTATE_X = 0.0; 46 | 47 | /// Default @a y rotation angle for the noise::module::RotatePoint noise 48 | /// module. 49 | const double DEFAULT_ROTATE_Y = 0.0; 50 | 51 | /// Default @a z rotation angle for the noise::module::RotatePoint noise 52 | /// module. 53 | const double DEFAULT_ROTATE_Z = 0.0; 54 | 55 | /// Noise module that rotates the input value around the origin before 56 | /// returning the output value from a source module. 57 | /// 58 | /// @image html modulerotatepoint.png 59 | /// 60 | /// The GetValue() method rotates the coordinates of the input value 61 | /// around the origin before returning the output value from the source 62 | /// module. To set the rotation angles, call the SetAngles() method. To 63 | /// set the rotation angle around the individual @a x, @a y, or @a z axes, 64 | /// call the SetXAngle(), SetYAngle() or SetZAngle() methods, 65 | /// respectively. 66 | /// 67 | /// The coordinate system of the input value is assumed to be 68 | /// "left-handed" (@a x increases to the right, @a y increases upward, 69 | /// and @a z increases inward.) 70 | /// 71 | /// This noise module requires one source module. 72 | class RotatePoint: public Module 73 | { 74 | 75 | public: 76 | 77 | /// Constructor. 78 | /// 79 | /// The default rotation angle around the @a x axis, in degrees, is 80 | /// set to noise::module::DEFAULT_ROTATE_X. 81 | /// 82 | /// The default rotation angle around the @a y axis, in degrees, is 83 | /// set to noise::module::DEFAULT_ROTATE_Y. 84 | /// 85 | /// The default rotation angle around the @a z axis, in degrees, is 86 | /// set to noise::module::DEFAULT_ROTATE_Z. 87 | RotatePoint (); 88 | 89 | virtual int GetSourceModuleCount () const 90 | { 91 | return 1; 92 | } 93 | 94 | virtual double GetValue (double x, double y, double z) const; 95 | 96 | /// Returns the rotation angle around the @a x axis to apply to the 97 | /// input value. 98 | /// 99 | /// @returns The rotation angle around the @a x axis, in degrees. 100 | double GetXAngle () const 101 | { 102 | return m_xAngle; 103 | } 104 | 105 | /// Returns the rotation angle around the @a y axis to apply to the 106 | /// input value. 107 | /// 108 | /// @returns The rotation angle around the @a y axis, in degrees. 109 | double GetYAngle () const 110 | { 111 | return m_yAngle; 112 | } 113 | 114 | /// Returns the rotation angle around the @a z axis to apply to the 115 | /// input value. 116 | /// 117 | /// @returns The rotation angle around the @a z axis, in degrees. 118 | double GetZAngle () const 119 | { 120 | return m_zAngle; 121 | } 122 | 123 | /// Sets the rotation angles around all three axes to apply to the 124 | /// input value. 125 | /// 126 | /// @param xAngle The rotation angle around the @a x axis, in degrees. 127 | /// @param yAngle The rotation angle around the @a y axis, in degrees. 128 | /// @param zAngle The rotation angle around the @a z axis, in degrees. 129 | /// 130 | /// The GetValue() method rotates the coordinates of the input value 131 | /// around the origin before returning the output value from the 132 | /// source module. 133 | void SetAngles (double xAngle, double yAngle, double zAngle); 134 | 135 | /// Sets the rotation angle around the @a x axis to apply to the input 136 | /// value. 137 | /// 138 | /// @param xAngle The rotation angle around the @a x axis, in degrees. 139 | /// 140 | /// The GetValue() method rotates the coordinates of the input value 141 | /// around the origin before returning the output value from the 142 | /// source module. 143 | void SetXAngle (double xAngle) 144 | { 145 | SetAngles (xAngle, m_yAngle, m_zAngle); 146 | } 147 | 148 | /// Sets the rotation angle around the @a y axis to apply to the input 149 | /// value. 150 | /// 151 | /// @param yAngle The rotation angle around the @a y axis, in degrees. 152 | /// 153 | /// The GetValue() method rotates the coordinates of the input value 154 | /// around the origin before returning the output value from the 155 | /// source module. 156 | void SetYAngle (double yAngle) 157 | { 158 | SetAngles (m_xAngle, yAngle, m_zAngle); 159 | } 160 | 161 | /// Sets the rotation angle around the @a z axis to apply to the input 162 | /// value. 163 | /// 164 | /// @param zAngle The rotation angle around the @a z axis, in degrees. 165 | /// 166 | /// The GetValue() method rotates the coordinates of the input value 167 | /// around the origin before returning the output value from the 168 | /// source module. 169 | void SetZAngle (double zAngle) 170 | { 171 | SetAngles (m_xAngle, m_yAngle, zAngle); 172 | } 173 | 174 | protected: 175 | 176 | /// An entry within the 3x3 rotation matrix used for rotating the 177 | /// input value. 178 | double m_x1Matrix; 179 | 180 | /// An entry within the 3x3 rotation matrix used for rotating the 181 | /// input value. 182 | double m_x2Matrix; 183 | 184 | /// An entry within the 3x3 rotation matrix used for rotating the 185 | /// input value. 186 | double m_x3Matrix; 187 | 188 | /// @a x rotation angle applied to the input value, in degrees. 189 | double m_xAngle; 190 | 191 | /// An entry within the 3x3 rotation matrix used for rotating the 192 | /// input value. 193 | double m_y1Matrix; 194 | 195 | /// An entry within the 3x3 rotation matrix used for rotating the 196 | /// input value. 197 | double m_y2Matrix; 198 | 199 | /// An entry within the 3x3 rotation matrix used for rotating the 200 | /// input value. 201 | double m_y3Matrix; 202 | 203 | /// @a y rotation angle applied to the input value, in degrees. 204 | double m_yAngle; 205 | 206 | /// An entry within the 3x3 rotation matrix used for rotating the 207 | /// input value. 208 | double m_z1Matrix; 209 | 210 | /// An entry within the 3x3 rotation matrix used for rotating the 211 | /// input value. 212 | double m_z2Matrix; 213 | 214 | /// An entry within the 3x3 rotation matrix used for rotating the 215 | /// input value. 216 | double m_z3Matrix; 217 | 218 | /// @a z rotation angle applied to the input value, in degrees. 219 | double m_zAngle; 220 | 221 | }; 222 | 223 | /// @} 224 | 225 | /// @} 226 | 227 | /// @} 228 | 229 | } 230 | 231 | } 232 | 233 | #endif 234 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/module/translatepoint.h: -------------------------------------------------------------------------------- 1 | // translatepoint.h 2 | // 3 | // Copyright (C) 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_TRANSLATEPOINT_H 24 | #define NOISE_MODULE_TRANSLATEPOINT_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup transformermodules 41 | /// @{ 42 | 43 | /// Default translation factor applied to the @a x coordinate for the 44 | /// noise::module::TranslatePoint noise module. 45 | const double DEFAULT_TRANSLATE_POINT_X = 0.0; 46 | 47 | /// Default translation factor applied to the @a y coordinate for the 48 | /// noise::module::TranslatePoint noise module. 49 | const double DEFAULT_TRANSLATE_POINT_Y = 0.0; 50 | 51 | /// Default translation factor applied to the @a z coordinate for the 52 | /// noise::module::TranslatePoint noise module. 53 | const double DEFAULT_TRANSLATE_POINT_Z = 0.0; 54 | 55 | /// Noise module that moves the coordinates of the input value before 56 | /// returning the output value from a source module. 57 | /// 58 | /// @image html moduletranslatepoint.png 59 | /// 60 | /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates of 61 | /// the input value by a translation amount before returning the output 62 | /// value from the source module. To set the translation amount, call 63 | /// the SetTranslation() method. To set the translation amount to 64 | /// apply to the individual @a x, @a y, or @a z coordinates, call the 65 | /// SetXTranslation(), SetYTranslation() or SetZTranslation() methods, 66 | /// respectively. 67 | /// 68 | /// This noise module requires one source module. 69 | class TranslatePoint: public Module 70 | { 71 | 72 | public: 73 | 74 | /// Constructor. 75 | /// 76 | /// The default translation amount to apply to the @a x coordinate is 77 | /// set to noise::module::DEFAULT_TRANSLATE_POINT_X. 78 | /// 79 | /// The default translation amount to apply to the @a y coordinate is 80 | /// set to noise::module::DEFAULT_TRANSLATE_POINT_Y. 81 | /// 82 | /// The default translation amount to apply to the @a z coordinate is 83 | /// set to noise::module::DEFAULT_TRANSLATE_POINT_Z. 84 | TranslatePoint (); 85 | 86 | virtual int GetSourceModuleCount () const 87 | { 88 | return 1; 89 | } 90 | 91 | virtual double GetValue (double x, double y, double z) const; 92 | 93 | /// Returns the translation amount to apply to the @a x coordinate of 94 | /// the input value. 95 | /// 96 | /// @returns The translation amount to apply to the @a x coordinate. 97 | double GetXTranslation () const 98 | { 99 | return m_xTranslation; 100 | } 101 | 102 | /// Returns the translation amount to apply to the @a y coordinate of 103 | /// the input value. 104 | /// 105 | /// @returns The translation amount to apply to the @a y coordinate. 106 | double GetYTranslation () const 107 | { 108 | return m_yTranslation; 109 | } 110 | 111 | /// Returns the translation amount to apply to the @a z coordinate of 112 | /// the input value. 113 | /// 114 | /// @returns The translation amount to apply to the @a z coordinate. 115 | double GetZTranslation () const 116 | { 117 | return m_zTranslation; 118 | } 119 | 120 | /// Sets the translation amount to apply to the input value. 121 | /// 122 | /// @param translation The translation amount to apply. 123 | /// 124 | /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates 125 | /// of the input value by a translation amount before returning the 126 | /// output value from the source module 127 | void SetTranslation (double translation) 128 | { 129 | m_xTranslation = translation; 130 | m_yTranslation = translation; 131 | m_zTranslation = translation; 132 | } 133 | 134 | /// Sets the translation amounts to apply to the ( @a x, @a y, @a z ) 135 | /// coordinates of the input value. 136 | /// 137 | /// @param xTranslation The translation amount to apply to the @a x 138 | /// coordinate. 139 | /// @param yTranslation The translation amount to apply to the @a y 140 | /// coordinate. 141 | /// @param zTranslation The translation amount to apply to the @a z 142 | /// coordinate. 143 | /// 144 | /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates 145 | /// of the input value by a translation amount before returning the 146 | /// output value from the source module 147 | void SetTranslation (double xTranslation, double yTranslation, 148 | double zTranslation) 149 | { 150 | m_xTranslation = xTranslation; 151 | m_yTranslation = yTranslation; 152 | m_zTranslation = zTranslation; 153 | } 154 | 155 | /// Sets the translation amount to apply to the @a x coordinate of the 156 | /// input value. 157 | /// 158 | /// @param xTranslation The translation amount to apply to the @a x 159 | /// coordinate. 160 | /// 161 | /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates 162 | /// of the input value by a translation amount before returning the 163 | /// output value from the source module 164 | void SetXTranslation (double xTranslation) 165 | { 166 | m_xTranslation = xTranslation; 167 | } 168 | 169 | /// Sets the translation amount to apply to the @a y coordinate of the 170 | /// input value. 171 | /// 172 | /// @param yTranslation The translation amount to apply to the @a y 173 | /// coordinate. 174 | /// 175 | /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates 176 | /// of the input value by a translation amount before returning the 177 | /// output value from the source module 178 | void SetYTranslation (double yTranslation) 179 | { 180 | m_yTranslation = yTranslation; 181 | } 182 | 183 | /// Sets the translation amount to apply to the @a z coordinate of the 184 | /// input value. 185 | /// 186 | /// @param zTranslation The translation amount to apply to the @a z 187 | /// coordinate. 188 | /// 189 | /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates 190 | /// of the input value by a translation amount before returning the 191 | /// output value from the source module 192 | void SetZTranslation (double zTranslation) 193 | { 194 | m_zTranslation = zTranslation; 195 | } 196 | 197 | protected: 198 | 199 | /// Translation amount applied to the @a x coordinate of the input 200 | /// value. 201 | double m_xTranslation; 202 | 203 | /// Translation amount applied to the @a y coordinate of the input 204 | /// value. 205 | double m_yTranslation; 206 | 207 | /// Translation amount applied to the @a z coordinate of the input 208 | /// value. 209 | double m_zTranslation; 210 | 211 | }; 212 | 213 | /// @} 214 | 215 | /// @} 216 | 217 | /// @} 218 | 219 | } 220 | 221 | } 222 | 223 | #endif 224 | -------------------------------------------------------------------------------- /HeightmapRenderer/HeightmapRenderer.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {84D4B305-9D38-4B5A-9A15-6DDFEE6D0705} 15 | HeightmapRenderer 16 | 17 | 18 | 19 | Application 20 | true 21 | v120 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v120 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | $(GLFW_HOME)\include;$(GLEW_HOME)\include;$(OGLPLUS_ROOT)\implement;$(OGLPLUS_ROOT)\include;$(BOOST_ROOT);$(GLM_ROOT);$(ProjectDir)LibNoise\include;$(FREEIMAGE_ROOT)\x32;%(AdditionalIncludeDirectories) 48 | _CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;GLEW_STATIC;%(PreprocessorDefinitions) 49 | Commons.h 50 | Use 51 | -Zm200 %(AdditionalOptions) 52 | Default 53 | 54 | 55 | true 56 | $(GLFW_HOME)\lib;$(GLEW_HOME)\lib;$(BOOST_ROOT)\stage\lib;$(ProjectDir)LibNoise\bin;$(FREEIMAGE_ROOT)\x32;%(AdditionalLibraryDirectories) 57 | opengl32.lib;FreeImage.lib;noised.lib;libboost_log-vc120-mt-gd-1_57.lib;glew32sd.lib;glfw3d.lib;%(AdditionalDependencies) 58 | 59 | 60 | 61 | 62 | Level3 63 | MaxSpeed 64 | true 65 | true 66 | true 67 | $(GLFW_HOME)\include;$(GLEW_HOME)\include;$(OGLPLUS_ROOT)\implement;$(OGLPLUS_ROOT)\include;$(BOOST_ROOT);$(GLM_ROOT);$(ProjectDir)LibNoise\include;$(FREEIMAGE_ROOT)\x32;%(AdditionalIncludeDirectories) 68 | _CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;GLEW_STATIC;%(PreprocessorDefinitions) 69 | Use 70 | Commons.h 71 | -Zm200 %(AdditionalOptions) 72 | 73 | 74 | true 75 | true 76 | true 77 | $(GLFW_HOME)\lib;$(GLEW_HOME)\lib;$(BOOST_ROOT)\stage\lib;$(ProjectDir)LibNoise\bin;$(FREEIMAGE_ROOT)\x32;%(AdditionalLibraryDirectories) 78 | opengl32.lib;FreeImage.lib;noise.lib;libboost_log-vc120-mt-1_57.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies) 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | NotUsing 87 | NotUsing 88 | 89 | 90 | NotUsing 91 | NotUsing 92 | 93 | 94 | 95 | 96 | 97 | NotUsing 98 | NotUsing 99 | 100 | 101 | 102 | 103 | Create 104 | Create 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /HeightmapRenderer/LibNoise/include/noise/noisegen.h: -------------------------------------------------------------------------------- 1 | // noisegen.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_NOISEGEN_H 24 | #define NOISE_NOISEGEN_H 25 | 26 | #include 27 | #include "basictypes.h" 28 | 29 | namespace noise 30 | { 31 | 32 | /// @addtogroup libnoise 33 | /// @{ 34 | 35 | /// Enumerates the noise quality. 36 | enum NoiseQuality 37 | { 38 | 39 | /// Generates coherent noise quickly. When a coherent-noise function with 40 | /// this quality setting is used to generate a bump-map image, there are 41 | /// noticeable "creasing" artifacts in the resulting image. This is 42 | /// because the derivative of that function is discontinuous at integer 43 | /// boundaries. 44 | QUALITY_FAST = 0, 45 | 46 | /// Generates standard-quality coherent noise. When a coherent-noise 47 | /// function with this quality setting is used to generate a bump-map 48 | /// image, there are some minor "creasing" artifacts in the resulting 49 | /// image. This is because the second derivative of that function is 50 | /// discontinuous at integer boundaries. 51 | QUALITY_STD = 1, 52 | 53 | /// Generates the best-quality coherent noise. When a coherent-noise 54 | /// function with this quality setting is used to generate a bump-map 55 | /// image, there are no "creasing" artifacts in the resulting image. This 56 | /// is because the first and second derivatives of that function are 57 | /// continuous at integer boundaries. 58 | QUALITY_BEST = 2 59 | 60 | }; 61 | 62 | /// Generates a gradient-coherent-noise value from the coordinates of a 63 | /// three-dimensional input value. 64 | /// 65 | /// @param x The @a x coordinate of the input value. 66 | /// @param y The @a y coordinate of the input value. 67 | /// @param z The @a z coordinate of the input value. 68 | /// @param seed The random number seed. 69 | /// @param noiseQuality The quality of the coherent-noise. 70 | /// 71 | /// @returns The generated gradient-coherent-noise value. 72 | /// 73 | /// The return value ranges from -1.0 to +1.0. 74 | /// 75 | /// For an explanation of the difference between gradient noise and 76 | /// value noise, see the comments for the GradientNoise3D() function. 77 | double GradientCoherentNoise3D (double x, double y, double z, int seed = 0, 78 | NoiseQuality noiseQuality = QUALITY_STD); 79 | 80 | /// Generates a gradient-noise value from the coordinates of a 81 | /// three-dimensional input value and the integer coordinates of a 82 | /// nearby three-dimensional value. 83 | /// 84 | /// @param fx The floating-point @a x coordinate of the input value. 85 | /// @param fy The floating-point @a y coordinate of the input value. 86 | /// @param fz The floating-point @a z coordinate of the input value. 87 | /// @param ix The integer @a x coordinate of a nearby value. 88 | /// @param iy The integer @a y coordinate of a nearby value. 89 | /// @param iz The integer @a z coordinate of a nearby value. 90 | /// @param seed The random number seed. 91 | /// 92 | /// @returns The generated gradient-noise value. 93 | /// 94 | /// @pre The difference between @a fx and @a ix must be less than or equal 95 | /// to one. 96 | /// 97 | /// @pre The difference between @a fy and @a iy must be less than or equal 98 | /// to one. 99 | /// 100 | /// @pre The difference between @a fz and @a iz must be less than or equal 101 | /// to one. 102 | /// 103 | /// A gradient-noise function generates better-quality noise than a 104 | /// value-noise function. Most noise modules use gradient noise for 105 | /// this reason, although it takes much longer to calculate. 106 | /// 107 | /// The return value ranges from -1.0 to +1.0. 108 | /// 109 | /// This function generates a gradient-noise value by performing the 110 | /// following steps: 111 | /// - It first calculates a random normalized vector based on the 112 | /// nearby integer value passed to this function. 113 | /// - It then calculates a new value by adding this vector to the 114 | /// nearby integer value passed to this function. 115 | /// - It then calculates the dot product of the above-generated value 116 | /// and the floating-point input value passed to this function. 117 | /// 118 | /// A noise function differs from a random-number generator because it 119 | /// always returns the same output value if the same input value is passed 120 | /// to it. 121 | double GradientNoise3D (double fx, double fy, double fz, int ix, int iy, 122 | int iz, int seed = 0); 123 | 124 | /// Generates an integer-noise value from the coordinates of a 125 | /// three-dimensional input value. 126 | /// 127 | /// @param x The integer @a x coordinate of the input value. 128 | /// @param y The integer @a y coordinate of the input value. 129 | /// @param z The integer @a z coordinate of the input value. 130 | /// @param seed A random number seed. 131 | /// 132 | /// @returns The generated integer-noise value. 133 | /// 134 | /// The return value ranges from 0 to 2147483647. 135 | /// 136 | /// A noise function differs from a random-number generator because it 137 | /// always returns the same output value if the same input value is passed 138 | /// to it. 139 | int IntValueNoise3D (int x, int y, int z, int seed = 0); 140 | 141 | /// Modifies a floating-point value so that it can be stored in a 142 | /// noise::int32 variable. 143 | /// 144 | /// @param n A floating-point number. 145 | /// 146 | /// @returns The modified floating-point number. 147 | /// 148 | /// This function does not modify @a n. 149 | /// 150 | /// In libnoise, the noise-generating algorithms are all integer-based; 151 | /// they use variables of type noise::int32. Before calling a noise 152 | /// function, pass the @a x, @a y, and @a z coordinates to this function to 153 | /// ensure that these coordinates can be cast to a noise::int32 value. 154 | /// 155 | /// Although you could do a straight cast from double to noise::int32, the 156 | /// resulting value may differ between platforms. By using this function, 157 | /// you ensure that the resulting value is identical between platforms. 158 | inline double MakeInt32Range (double n) 159 | { 160 | if (n >= 1073741824.0) { 161 | return (2.0 * fmod (n, 1073741824.0)) - 1073741824.0; 162 | } else if (n <= -1073741824.0) { 163 | return (2.0 * fmod (n, 1073741824.0)) + 1073741824.0; 164 | } else { 165 | return n; 166 | } 167 | } 168 | 169 | /// Generates a value-coherent-noise value from the coordinates of a 170 | /// three-dimensional input value. 171 | /// 172 | /// @param x The @a x coordinate of the input value. 173 | /// @param y The @a y coordinate of the input value. 174 | /// @param z The @a z coordinate of the input value. 175 | /// @param seed The random number seed. 176 | /// @param noiseQuality The quality of the coherent-noise. 177 | /// 178 | /// @returns The generated value-coherent-noise value. 179 | /// 180 | /// The return value ranges from -1.0 to +1.0. 181 | /// 182 | /// For an explanation of the difference between gradient noise and 183 | /// value noise, see the comments for the GradientNoise3D() function. 184 | double ValueCoherentNoise3D (double x, double y, double z, int seed = 0, 185 | NoiseQuality noiseQuality = QUALITY_STD); 186 | 187 | /// Generates a value-noise value from the coordinates of a 188 | /// three-dimensional input value. 189 | /// 190 | /// @param x The @a x coordinate of the input value. 191 | /// @param y The @a y coordinate of the input value. 192 | /// @param z The @a z coordinate of the input value. 193 | /// @param seed A random number seed. 194 | /// 195 | /// @returns The generated value-noise value. 196 | /// 197 | /// The return value ranges from -1.0 to +1.0. 198 | /// 199 | /// A noise function differs from a random-number generator because it 200 | /// always returns the same output value if the same input value is passed 201 | /// to it. 202 | double ValueNoise3D (int x, int y, int z, int seed = 0); 203 | 204 | /// @} 205 | 206 | } 207 | 208 | #endif 209 | --------------------------------------------------------------------------------