├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── build-gcc.sh ├── build-mingw.bat ├── build-msvc15.bat ├── build-msvc16.bat ├── cmake └── utils.cmake ├── codemeta.json ├── doc ├── build-instructions.md ├── code-reading-hints.md ├── images │ ├── screenshot.png │ └── unable-to-start.png ├── troubleshooting.md └── user-manual.md ├── download-full-data.bat ├── download-full-data.sh ├── download-minimal-data.bat ├── download-minimal-data.sh ├── share ├── scenes │ ├── .gitignore │ ├── ball.json │ ├── coffee-roaster-anim.json │ ├── large-beach.json │ ├── nut01-heap.json │ ├── single-grain.json │ └── small-beach.json ├── scripts │ ├── augen_octahedron2camera.py │ ├── blender_export_point_buffer.py │ ├── blender_export_transform_matrix.py │ ├── blender_import_cameramesh.py │ ├── blender_import_point_buffer.py │ ├── blender_octaedron2camera.py │ ├── blender_operator_import_xyz.py │ ├── dev │ │ └── add_behavior.py │ ├── make_fibonacci.py │ ├── make_octahedron.py │ └── operator_octahedron_add.py ├── shaders │ ├── bake-impostor-atlas.frag.glsl │ ├── bake-impostor-atlas.geo.glsl │ ├── bake-impostor-atlas.vert.glsl │ ├── basic-world.frag.glsl │ ├── basic-world.vert.glsl │ ├── deferred-shader.frag.glsl │ ├── deferred-shader.geo.glsl │ ├── deferred-shader.vert.glsl │ ├── depth-to-color.frag.glsl │ ├── depth-to-color.vert.glsl │ ├── far-grain.frag.glsl │ ├── far-grain.geo.glsl │ ├── far-grain.vert.glsl │ ├── generate-mipmap-zbuffer.frag.glsl │ ├── generate-mipmap-zbuffer.vert.glsl │ ├── gltf-mesh.frag.glsl │ ├── gltf-mesh.vert.glsl │ ├── grain │ │ ├── discriminate.inc.glsl │ │ ├── globalatomic-splitter.comp.glsl │ │ ├── occlusion-culling.frag.glsl │ │ ├── occlusion-culling.vert.glsl │ │ ├── procedural-color.inc.glsl │ │ └── random-grains.inc.glsl │ ├── impostor-grain.frag.glsl │ ├── impostor-grain.geo.glsl │ ├── impostor-grain.vert.glsl │ ├── include │ │ ├── anim.inc.glsl │ │ ├── bsdf-old.inc.glsl │ │ ├── bsdf.inc.glsl │ │ ├── depth.inc.glsl │ │ ├── frustum.inc.glsl │ │ ├── gbuffer.inc.glsl │ │ ├── gbuffer2.inc.glsl │ │ ├── gbuffer3.inc.glsl │ │ ├── impostor.inc.glsl │ │ ├── lean-mapping.inc.glsl │ │ ├── light.inc.glsl │ │ ├── octahedron.inc.glsl │ │ ├── random.inc.glsl │ │ ├── raytracing.inc.glsl │ │ ├── sprite.inc.glsl │ │ ├── standard-material.inc.glsl │ │ ├── standard-posteffect.geo.inc.glsl │ │ ├── standard-posteffect.vert.inc.glsl │ │ ├── uniform │ │ │ └── camera.inc.glsl │ │ ├── utils.inc.glsl │ │ └── zbuffer.inc.glsl │ ├── instance-grain.frag.glsl │ ├── instance-grain.vert.glsl │ ├── light-gizmo.frag.glsl │ ├── light-gizmo.vert.glsl │ ├── mipmap-using-alpha.frag.glsl │ ├── mipmap-using-alpha.geo.glsl │ ├── mipmap-using-alpha.vert.glsl │ ├── posteffect.frag.glsl │ ├── posteffect.vert.glsl │ ├── quad.frag.glsl │ ├── quad.vert.glsl │ ├── standard-mesh.frag.glsl │ └── standard-mesh.vert.glsl └── test │ ├── hzb-test-scene-camera.bin │ ├── hzb-test-scene-occlusion.mtl │ ├── hzb-test-scene-occlusion.obj │ ├── hzb-test-scene-pawn.mtl │ ├── hzb-test-scene-pawn.obj │ └── hzb.json └── src ├── CMakeLists.txt ├── External ├── CMakeLists.txt ├── nanoflann │ ├── CMakeLists.txt │ └── include │ │ └── nanoflann.hpp ├── refl-cpp │ ├── CMakeLists.txt │ └── include │ │ ├── magic_enum.hpp │ │ └── refl.hpp └── tinygltf │ ├── CMakeLists.txt │ ├── LICENSE │ ├── include │ ├── json.hpp │ ├── stb_image.h │ ├── stb_image_write.h │ └── tiny_gltf.h │ └── src │ └── tiny_gltf.cpp └── GrainViewer ├── AnimationManager.cpp ├── AnimationManager.h ├── Behavior.h ├── Behavior ├── FarGrainRenderer.cpp ├── FarGrainRenderer.h ├── GltfDataBehavior.cpp ├── GltfDataBehavior.h ├── GrainBehavior.cpp ├── GrainBehavior.h ├── ImpostorGrainRenderer.cpp ├── ImpostorGrainRenderer.h ├── InstanceGrainRenderer.cpp ├── InstanceGrainRenderer.h ├── LightGizmo.cpp ├── LightGizmo.h ├── MeshDataBehavior.cpp ├── MeshDataBehavior.h ├── MeshRenderer.cpp ├── MeshRenderer.h ├── PointCloudDataBehavior.cpp ├── PointCloudDataBehavior.h ├── PointCloudSplitter.cpp ├── PointCloudSplitter.h ├── PointCloudView.h ├── QuadMeshData.cpp ├── QuadMeshData.h ├── TransformBehavior.cpp └── TransformBehavior.h ├── BehaviorRegistry.cpp ├── BehaviorRegistry.h ├── BehaviorRegistryEntry.h ├── CMakeLists.txt ├── Camera.cpp ├── Camera.h ├── EnvironmentVariables.cpp ├── EnvironmentVariables.h ├── Filtering.cpp ├── Filtering.h ├── Framebuffer.cpp ├── Framebuffer.h ├── Framebuffer2.cpp ├── Framebuffer2.h ├── GlBuffer.cpp ├── GlBuffer.h ├── GlDeferredShader.cpp ├── GlDeferredShader.h ├── GlTexture.cpp ├── GlTexture.h ├── GlobalTimer.cpp ├── GlobalTimer.h ├── IBehaviorHolder.h ├── IPointCloudData.h ├── ImpostorAtlasMaterial.cpp ├── ImpostorAtlasMaterial.h ├── Light.cpp ├── Light.h ├── Logger.cpp ├── Logger.h ├── Mesh.cpp ├── Mesh.h ├── OpenGL ├── PointCloud.cpp ├── PointCloud.h ├── PostEffect.cpp ├── PostEffect.h ├── RenderType.h ├── ResourceManager.cpp ├── ResourceManager.h ├── RuntimeObject.cpp ├── RuntimeObject.h ├── Scene.cpp ├── Scene.h ├── Scene_load.cpp ├── SerializationType.h ├── Shader.cpp ├── Shader.h ├── ShaderPool.cpp ├── ShaderPool.h ├── ShaderPreprocessor.cpp ├── ShaderPreprocessor.h ├── ShaderProgram.cpp ├── ShaderProgram.h ├── ShadowMap.cpp ├── ShadowMap.h ├── StandardMaterial.cpp ├── StandardMaterial.h ├── Tools ├── PointCloudConvert.cpp ├── filterPointToPointDistance.cpp └── filterPointToPointDistance.h ├── Triangle.h ├── TurntableCamera.cpp ├── TurntableCamera.h ├── Ui ├── DeferredShadingDialog.cpp ├── DeferredShadingDialog.h ├── Dialog.h ├── FarGrainRendererDialog.cpp ├── FarGrainRendererDialog.h ├── GlobalTimerDialog.cpp ├── GlobalTimerDialog.h ├── GrainBehaviorDialog.cpp ├── GrainBehaviorDialog.h ├── Gui.cpp ├── Gui.h ├── ImpostorGrainRendererDialog.cpp ├── ImpostorGrainRendererDialog.h ├── InstanceGrainRendererDialog.cpp ├── InstanceGrainRendererDialog.h ├── LightGizmoDialog.cpp ├── LightGizmoDialog.h ├── MeshRendererDialog.cpp ├── MeshRendererDialog.h ├── PointCloudSplitterDialog.cpp ├── PointCloudSplitterDialog.h ├── QuadMeshDataDialog.cpp ├── QuadMeshDataDialog.h ├── SceneDialog.cpp ├── SceneDialog.h ├── TestGui.cpp ├── TestGui.h ├── TransformDialog.cpp ├── TransformDialog.h ├── Widgets.cpp ├── Widgets.h ├── Window.cpp ├── Window.h ├── WorldDialog.cpp └── WorldDialog.h ├── ViewLayerMask.cpp ├── ViewLayerMask.h ├── World.cpp ├── World.h ├── bufferFillers.cpp ├── bufferFillers.h ├── main.cpp └── utils ├── ReflectionAttributes.h ├── ScopedFramebufferOverride.h ├── behaviorutils.cpp ├── behaviorutils.h ├── debug.cpp ├── debug.h ├── fileutils.cpp ├── fileutils.h ├── guiutils.cpp ├── guiutils.h ├── impostor.glsl.cpp ├── impostor.glsl.h ├── jsonutils.cpp ├── jsonutils.h ├── mathutils.cpp ├── mathutils.h ├── shader.cpp ├── shader.h ├── strutils.cpp └── strutils.h /.gitignore: -------------------------------------------------------------------------------- 1 | build*/ 2 | releases/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/External/glfw"] 2 | path = src/External/glfw 3 | url = https://github.com/glfw/glfw 4 | [submodule "src/External/glad"] 5 | path = src/External/glad 6 | url = https://github.com/Dav1dde/glad 7 | [submodule "src/External/imgui"] 8 | path = src/External/imgui 9 | url = https://github.com/ocornut/imgui 10 | [submodule "src/External/glm"] 11 | path = src/External/glm 12 | url = https://github.com/g-truc/glm 13 | [submodule "src/External/rapidjson"] 14 | path = src/External/rapidjson 15 | url = https://github.com/Tencent/rapidjson/ 16 | [submodule "src/External/tinyobjloader"] 17 | path = src/External/tinyobjloader 18 | url = https://github.com/syoyo/tinyobjloader 19 | [submodule "src/External/tinyexr"] 20 | path = src/External/tinyexr 21 | url = https://github.com/syoyo/tinyexr 22 | [submodule "src/External/modernglad"] 23 | path = src/External/modernglad 24 | url = https://github.com/eliemichel/ModernGlad 25 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of GrainViewer, the reference implementation of: 2 | # 3 | # Michel, Élie and Boubekeur, Tamy (2020). 4 | # Real Time Multiscale Rendering of Dense Dynamic Stackings, 5 | # Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 6 | # https://doi.org/10.1111/cgf.14135 7 | # 8 | # Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 9 | # 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy 11 | # of this software and associated documentation files (the “Software”), to 12 | # deal in the Software without restriction, including without limitation the 13 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 14 | # sell copies of the Software, and to permit persons to whom the Software is 15 | # furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included in 18 | # all copies or substantial portions of the Software. 19 | # 20 | # The Software is provided “as is”, without warranty of any kind, express or 21 | # implied, including but not limited to the warranties of merchantability, 22 | # fitness for a particular purpose and non-infringement. In no event shall the 23 | # authors or copyright holders be liable for any claim, damages or other 24 | # liability, whether in an action of contract, tort or otherwise, arising 25 | # from, out of or in connection with the software or the use or other dealings 26 | # in the Software. 27 | 28 | cmake_minimum_required(VERSION 3.0...3.7) 29 | project(GrainViewer) 30 | 31 | include(cmake/utils.cmake) 32 | 33 | option(DEV_MOD "Build in dev mode, use share directory from source tree rather than installation tree. This is useful when hacking on shaders." ON) 34 | option(DOWNLOAD_EXAMPLE_DATA "Download additionnal example data" ON) 35 | option(GIT_SUBMODULE "Check submodules during build" ON) 36 | 37 | fetch_submodules() 38 | fetch_example_data() 39 | 40 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 41 | 42 | add_subdirectory(src) 43 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GrainViewer, released under the MIT license 2 | 3 | Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the “Software”), to 7 | deal in the Software without restriction, including without limitation the 8 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | sell copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | The Software is provided “as is”, without warranty of any kind, express or 16 | implied, including but not limited to the warranties of merchantability, 17 | fitness for a particular purpose and non-infringement. In no event shall the 18 | authors or copyright holders be liable for any claim, damages or other 19 | liability, whether in an action of contract, tort or otherwise, arising 20 | from, out of or in connection with the software or the use or other dealings 21 | in the Software. 22 | -------------------------------------------------------------------------------- /build-gcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Get git submodules 4 | # This only has to run once, you can then comment it out if it takes too long 5 | git submodule update --init --recursive 6 | 7 | # Place all build related files in a specific directory. 8 | # Whenever you'd like to clean the build and restart it from scratch, you can 9 | # delete this directory without worrying about deleting important files. 10 | mkdir build-gcc 11 | cd build-gcc 12 | 13 | # Call cmake to generate the Makefile. You can then build with 'make' and 14 | # install with 'make install' 15 | cmake .. -DCMAKE_BUILD_TYPE=Debug 16 | 17 | # Check that it run all right 18 | if [ $? -eq 0 ] 19 | then 20 | echo Successful 21 | else 22 | echo Unsuccessful 23 | fi 24 | -------------------------------------------------------------------------------- /build-mingw.bat: -------------------------------------------------------------------------------- 1 | :: Get git submodules 2 | :: This only has to run once, you can then comment it out if it takes too long 3 | git submodule update --init --recursive 4 | 5 | :: Place all build related files in a specific directory. 6 | :: Whenever you'd like to clean the build and restart it from scratch, you can 7 | :: delete this directory without worrying about deleting important files. 8 | mkdir build-mingw 9 | cd build-mingw 10 | 11 | :: Call cmake to generate the MinGW solution 12 | cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug 13 | 14 | @echo off 15 | :: Check that it run all right 16 | if errorlevel 1 ( 17 | echo Unsuccessful 18 | ) else ( 19 | echo Successful 20 | echo "You can now run 'mingw32-make' in directory 'build-mingw'" 21 | ) 22 | pause 23 | -------------------------------------------------------------------------------- /build-msvc15.bat: -------------------------------------------------------------------------------- 1 | :: Get git submodules 2 | :: This only has to run once, you can then comment it out if it takes too long 3 | git submodule update --init --recursive 4 | 5 | :: Place all build related files in a specific directory. 6 | :: Whenever you'd like to clean the build and restart it from scratch, you can 7 | :: delete this directory without worrying about deleting important files. 8 | mkdir build-msvc15 9 | cd build-msvc15 10 | 11 | :: Call cmake to generate the all configured Visual Studio solution 12 | cmake .. -G "Visual Studio 15 2017 Win64" 13 | 14 | @echo off 15 | :: Check that it run all right 16 | if errorlevel 1 ( 17 | echo Unsuccessful 18 | ) else ( 19 | echo Successful 20 | ) 21 | pause 22 | -------------------------------------------------------------------------------- /build-msvc16.bat: -------------------------------------------------------------------------------- 1 | :: Get git submodules 2 | :: This only has to run once, you can then comment it out if it takes too long 3 | git submodule update --init --recursive 4 | 5 | :: Place all build related files in a specific directory. 6 | :: Whenever you'd like to clean the build and restart it from scratch, you can 7 | :: delete this directory without worrying about deleting important files. 8 | mkdir build-msvc16 9 | cd build-msvc16 10 | 11 | :: Call cmake to generate the all configured Visual Studio solution 12 | cmake .. -G "Visual Studio 16 2019" -A x64 13 | 14 | @echo off 15 | :: Check that it run all right 16 | if errorlevel 1 ( 17 | echo Unsuccessful 18 | ) else ( 19 | echo Successful 20 | ) 21 | pause 22 | -------------------------------------------------------------------------------- /codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", 3 | "@type": "SoftwareSourceCode", 4 | "license": "https://spdx.org/licenses/MIT", 5 | "codeRepository": "git+https://github.com/eliemichel/GrainViewer", 6 | "dateCreated": "2017-06-01", 7 | "datePublished": "2020-12-04", 8 | "dateModified": "2020-12-04", 9 | "downloadUrl": "https://github.com/eliemichel/GrainViewer/releases/tag/v1.0.0", 10 | "issueTracker": "https://github.com/eliemichel/GrainViewer/issues", 11 | "name": "Grain Viewer", 12 | "version": "1.0.0", 13 | "identifier": "10.1111/cgf.14135", 14 | "description": "Real-time multi-scale renderer of fully dynamic dense grain stackings.", 15 | "applicationCategory": "Computer Graphics", 16 | "releaseNotes": "Initial release", 17 | "developmentStatus": "inactive", 18 | "referencePublication": "https://doi.org/10.1111/cgf.14135", 19 | "keywords": [ 20 | "real-time", 21 | "level-of-detail", 22 | "rendering", 23 | "computer graphics" 24 | ], 25 | "programmingLanguage": [ 26 | "C++" 27 | ], 28 | "operatingSystem": [ 29 | "Window", 30 | "linux" 31 | ], 32 | "softwareRequirements": [ 33 | "Python 3", 34 | "CMake 3.7", 35 | "C++17" 36 | ], 37 | "relatedLink": [ 38 | "https://perso.telecom-paristech.fr/boubek/papers/RTStacking/" 39 | ], 40 | "author": [ 41 | { 42 | "@type": "Person", 43 | "@id": "https://orcid.org/0000-0002-2147-3427", 44 | "givenName": "Élie", 45 | "familyName": "Michel", 46 | "email": "elie.michel@telecom-paris.fr", 47 | "affiliation": { 48 | "@type": "Organization", 49 | "name": "LTCI, Télécom Paris, Institut Polytechnique de Paris" 50 | } 51 | } 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /doc/code-reading-hints.md: -------------------------------------------------------------------------------- 1 | Code Reading Hints 2 | ================== 3 | 4 | *Here are some misc notes about design choices.* 5 | 6 | ### Properties 7 | 8 | Usually when there is a `struct Properties` defined inside of a class, its fields are declared for introspection with `REFL_FIELD`s at the end of the file (that must be in global scope unfortunately). 9 | 10 | These properties are used automatically for serialization, UI drawing and shader uniforms. Note that not all parts of the code migrated to this design yet. 11 | 12 | ### Grain Rendering 13 | 14 | Core code bits specific to grain rendering is located within the [`Behavior`](src/GrainViewer/Behavior) directory. The remaining is more of a basic generic engine. A grain stacking object will typically follow this pattern in the json scene file: 15 | 16 | ```json 17 | { 18 | "type": "RuntimeObject", 19 | "behaviors": [ 20 | { "type": "TransformBehavior", ... }, 21 | { "type": "MeshDataBehavior", ... }, 22 | { "type": "PointCloudDataBehavior", ... }, 23 | { "type": "GrainBehavior", ... }, 24 | { "type": "PointCloudSplitter", ... }, 25 | { "type": "InstanceGrainRenderer", ... }, 26 | { "type": "ImpostorGrainRenderer", ... }, 27 | { "type": "FarGrainRenderer", ... }, 28 | ] 29 | }, 30 | ``` 31 | 32 | Each of these behaviors is defined in a separate class, the last four correspond to the four steps of the rendering pipeline as described in Figure 2 of the reference paper. The `MeshDataBehavior` defines the geometry of a single grain, and the `PointCloudDataBehavior` tells where the grains are. The `SandBehavior` defines the grain size and may either load or bake the impostor atlases at init time. And the `Transform` is just a global affine transform applyed to the whole object. 33 | 34 | You may omit the `Transform` and some of the `Renderers`. You can also omit the `PointCloudSplitter`, in which case all renderers will render all grains so in this case you'll likely want to set up only one renderer. 35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliemichel/GrainViewer/2c08409dc7717f75a653f05437344f4a868835ed/doc/images/screenshot.png -------------------------------------------------------------------------------- /doc/images/unable-to-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliemichel/GrainViewer/2c08409dc7717f75a653f05437344f4a868835ed/doc/images/unable-to-start.png -------------------------------------------------------------------------------- /doc/troubleshooting.md: -------------------------------------------------------------------------------- 1 | ## Troubleshooting 2 | 3 | This is a list of common issues. If you are encountering any difficulty that is not already listed here, please fill in an issue in the [bug tracker](https://github.com/eliemichel/GrainViewer/issues). 4 | 5 | ### Unable to start 6 | 7 | When using Visual Studio, if you encounter this error dialog when trying to run the solution generated by CMake: 8 | 9 | ![Start up issue](images/unable-to-start.png) 10 | 11 | Right click on *GrainViewer* in the solution explorer (right panel, in default Visual Studio window layout) and chose "Set as StartUp Project". 12 | -------------------------------------------------------------------------------- /download-full-data.bat: -------------------------------------------------------------------------------- 1 | :: Download additionnal heavy data, that does not belong in a git repo 2 | set ZIPFILE=share\scenes\GrainViewer-Additional-Data-v1.0.0.zip 3 | powershell -command "Start-BitsTransfer -Source https://perso.telecom-paristech.fr/emichel/share/GrainViewer-Additional-Data-v1.0.0.zip -Destination %ZIPFILE%" 4 | powershell -command "Expand-Archive %ZIPFILE% share\scenes" 5 | del %ZIPFILE% 6 | 7 | @echo off 8 | :: Check that it run all right 9 | if errorlevel 1 ( 10 | echo Unsuccessful 11 | ) else ( 12 | echo Successful 13 | ) 14 | pause 15 | -------------------------------------------------------------------------------- /download-full-data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Download additionnal heavy data, that does not belong in a git repo 5 | ZIPFILE=share/scenes/GrainViewer-Additional-Data-v1.0.0.zip 6 | if [ ! -f "$ZIPFILE" ]; then 7 | wget https://perso.telecom-paristech.fr/emichel/share/GrainViewer-Additional-Data-v1.0.0.zip -O $ZIPFILE 8 | fi 9 | unzip $ZIPFILE -d share/scenes 10 | rm $ZIPFILE 11 | 12 | # Check that it run all right 13 | if [ $? -eq 0 ] 14 | then 15 | echo Successful 16 | else 17 | echo Unsuccessful 18 | fi 19 | -------------------------------------------------------------------------------- /download-minimal-data.bat: -------------------------------------------------------------------------------- 1 | :: Download minimal additionnal data, that does not belong in a git repo 2 | set ZIPFILE=share\scenes\GrainViewer-Additional-MinimalData-v1.0.0.zip 3 | powershell -command "Start-BitsTransfer -Source https://perso.telecom-paristech.fr/emichel/share/GrainViewer-Additional-MinimalData-v1.0.0.zip -Destination %ZIPFILE%" 4 | powershell -command "Expand-Archive %ZIPFILE% share\scenes" 5 | del %ZIPFILE% 6 | 7 | @echo off 8 | :: Check that it run all right 9 | if errorlevel 1 ( 10 | echo Unsuccessful 11 | ) else ( 12 | echo Successful 13 | ) 14 | pause 15 | -------------------------------------------------------------------------------- /download-minimal-data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Download minimal additionnal data, that does not belong in a git repo 5 | ZIPFILE=share/scenes/GrainViewer-Additional-MinimalData-v1.0.0.zip 6 | if [ ! -f "$ZIPFILE" ]; then 7 | wget https://perso.telecom-paristech.fr/emichel/share/GrainViewer-Additional-MinimalData-v1.0.0.zip -O $ZIPFILE 8 | fi 9 | unzip $ZIPFILE -d share/scenes 10 | rm $ZIPFILE 11 | 12 | # Check that it run all right 13 | if [ $? -eq 0 ] 14 | then 15 | echo Successful 16 | else 17 | echo Unsuccessful 18 | fi 19 | -------------------------------------------------------------------------------- /share/scenes/.gitignore: -------------------------------------------------------------------------------- 1 | Impostors/ 2 | Meshes/ 3 | PointClouds/ 4 | Textures/ 5 | *.zip 6 | -------------------------------------------------------------------------------- /share/scripts/augen_octahedron2camera.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import struct 3 | from math import sqrt 4 | 5 | def cross(a, b): 6 | return [ 7 | a[1] * b[2] - a[2] * b[1], 8 | a[2] * b[0] - a[0] * b[2], 9 | a[0] * b[1] - a[1] * b[0] 10 | ] 11 | 12 | def dot(a, b): 13 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] 14 | 15 | def normalized(a): 16 | s = 1 / sqrt(dot(a, a)) 17 | return [ a[0] * s, a[1] * s, a[2] * s ] 18 | 19 | def mul(m, a): 20 | return [ 21 | dot(m[0], a), 22 | dot(m[1], a), 23 | dot(m[2], a) 24 | ] 25 | 26 | def opp(a): 27 | return [-a[0], -a[1], -a[2]] 28 | 29 | def lookFrom(p): 30 | z = p 31 | x = normalized(cross([0,0,1], z)) 32 | y = normalized(cross(z, x)) 33 | invp = opp(mul([x, y, z], p)) 34 | return [ 35 | [x[0], x[1], x[2], invp[0]], 36 | [y[0], y[1], y[2], invp[1]], 37 | [z[0], z[1], z[2], invp[2]], 38 | [0, 0, 0, 1], 39 | ] 40 | 41 | def write_view_matrix(inputFilename, outputFilepath): 42 | with open(outputFilepath, 'wb') as outFile: 43 | for i, line in enumerate(open(inputFilename, 'r')): 44 | coords = [float(x) for x in line.split()] 45 | if len(coords) != 3: 46 | print("Unable to parse line: %s " % line) 47 | exit(1) 48 | 49 | mat = lookFrom(coords) 50 | print(mat) 51 | column_major_data = tuple(mat[i][j] for j in range(4) for i in range(4)) 52 | outFile.write(struct.pack("f"*16, *column_major_data)) 53 | 54 | if __name__ == "__main__": 55 | inputFilename = sys.argv[1] if len(sys.argv) > 1 else "octahedron.xyz" 56 | outputFilepath = sys.argv[2] if len(sys.argv) > 2 else "octahedron_camera.bin" 57 | write_view_matrix(inputFilename, outputFilepath) 58 | -------------------------------------------------------------------------------- /share/scripts/blender_import_point_buffer.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | from bpy_extras.object_utils import object_data_add 3 | import struct 4 | 5 | def read_point_cloud(context, filepath): 6 | print("running read_some_data...") 7 | f = open(filepath, 'rb') 8 | 9 | point_count = int(struct.unpack("f", f.read(4))[0]) 10 | f.read(4) # anim 11 | print("Loading {} points...".format(point_count)) 12 | points = [(0.,0.,0.)]*point_count 13 | for i in range(point_count): 14 | points[i] = struct.unpack("fff", f.read(3*4)) 15 | f.close() 16 | 17 | mesh = bpy.data.meshes.new(name="Point Cloud") 18 | mesh.from_pydata(points, [], []) 19 | object_data_add(context, mesh) 20 | 21 | return {'FINISHED'} 22 | 23 | from bpy_extras.io_utils import ImportHelper 24 | from bpy.props import StringProperty, BoolProperty, EnumProperty 25 | from bpy.types import Operator 26 | 27 | 28 | class ImportPointBuffer(Operator, ImportHelper): 29 | """Import simple point cloud from XYZ ascii file""" 30 | bl_idname = "import.bin_point_cloud" # important since its how bpy.ops.import_test.some_data is constructed 31 | bl_label = "Import Point Cloud" 32 | 33 | # ImportHelper mixin class uses this 34 | filename_ext = ".bin" 35 | 36 | filter_glob: StringProperty( 37 | default="*.bin", 38 | options={'HIDDEN'}, 39 | maxlen=255, # Max internal buffer length, longer would be clamped. 40 | ) 41 | 42 | def execute(self, context): 43 | return read_point_cloud(context, self.filepath) 44 | 45 | 46 | def menu_func_import(self, context): 47 | self.layout.operator(ImportPointBuffer.bl_idname, text="Import Point Cloud") 48 | 49 | 50 | def register(): 51 | bpy.utils.register_class(ImportPointBuffer) 52 | bpy.types.TOPBAR_MT_file_import.append(menu_func_import) 53 | 54 | 55 | def unregister(): 56 | bpy.utils.unregister_class(ImportPointBuffer) 57 | bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) 58 | 59 | 60 | if __name__ == "__main__": 61 | register() 62 | -------------------------------------------------------------------------------- /share/scripts/blender_octaedron2camera.py: -------------------------------------------------------------------------------- 1 | # 2 | # Blender script to place camera from a set of points 3 | # 4 | from mathutils import Vector, Matrix 5 | import bpy 6 | 7 | def lookFrom(p): 8 | y = Vector([0,0,1]) 9 | z = p 10 | x = y.cross(z).normalized() 11 | y = z.cross(x).normalized() 12 | return Matrix.Translation(p) @ Matrix([x, y, z]).transposed().to_4x4() 13 | 14 | camera = bpy.context.scene.camera 15 | 16 | for i, line in enumerate(open('octahedron.xyz', 'r')): 17 | coords = [float(x) for x in line.split()] 18 | if len(coords) != 3: 19 | print("Unable to parse line: %s " % line) 20 | exit(1) 21 | 22 | p = Vector(coords) 23 | camera.matrix_world = lookFrom(p) 24 | camera.keyframe_insert(data_path="location", frame=i) 25 | camera.keyframe_insert(data_path="rotation_euler", frame=i) 26 | -------------------------------------------------------------------------------- /share/scripts/blender_operator_import_xyz.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | from bpy_extras.object_utils import object_data_add 3 | 4 | def read_xyz(context, filepath): 5 | print("running read_some_data...") 6 | f = open(filepath, 'r', encoding='utf-8') 7 | points = [] 8 | for line in f: 9 | coords = [float(c) for c in line.split()[0:3]] 10 | points.append(coords) 11 | f.close() 12 | 13 | mesh = bpy.data.meshes.new(name="Point Cloud") 14 | mesh.from_pydata(points, [], []) 15 | object_data_add(context, mesh) 16 | 17 | return {'FINISHED'} 18 | 19 | 20 | from bpy_extras.io_utils import ImportHelper 21 | from bpy.props import StringProperty, BoolProperty, EnumProperty 22 | from bpy.types import Operator 23 | 24 | 25 | class ImportXYZ(Operator, ImportHelper): 26 | """Import simple point cloud from XYZ ascii file""" 27 | bl_idname = "import.xyz_point_cloud" # important since its how bpy.ops.import_test.some_data is constructed 28 | bl_label = "Import XYZ Point Cloud" 29 | 30 | # ImportHelper mixin class uses this 31 | filename_ext = ".xyz" 32 | 33 | filter_glob: StringProperty( 34 | default="*.xyz", 35 | options={'HIDDEN'}, 36 | maxlen=255, # Max internal buffer length, longer would be clamped. 37 | ) 38 | 39 | def execute(self, context): 40 | return read_xyz(context, self.filepath) 41 | 42 | 43 | def menu_func_import(self, context): 44 | self.layout.operator(ImportXYZ.bl_idname, text="Import XYZ Point Cloud") 45 | 46 | 47 | def register(): 48 | bpy.utils.register_class(ImportXYZ) 49 | bpy.types.TOPBAR_MT_file_import.append(menu_func_import) 50 | 51 | 52 | def unregister(): 53 | bpy.utils.unregister_class(ImportXYZ) 54 | bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) 55 | 56 | 57 | if __name__ == "__main__": 58 | register() 59 | -------------------------------------------------------------------------------- /share/scripts/make_fibonacci.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from random import random 3 | from math import pi, sqrt, sin, cos, acos 4 | 5 | """ 6 | Generate point cloud, that you can then use with blender_import_cameramesh.py 7 | to generate camera positions to render impostor textures. 8 | """ 9 | 10 | from numpy import arange, pi, sin, cos, arccos 11 | 12 | def make_fibonacci(n, output_filename): 13 | PHI = (1 + 5**0.5)/2 14 | i = arange(0, n) 15 | theta = 2 *pi * i / PHI 16 | phi = arccos(1 - 2*(i+0.5)/n) 17 | xs, ys, zs = cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi); 18 | 19 | with open(output_filename, 'w') as f: 20 | for (x, y, z) in zip(xs, ys, zs): 21 | f.write("%f %f %f\n" % (x, y, z)) 22 | 23 | if __name__ == "__main__": 24 | n = int(sys.argv[1]) if len(sys.argv) >= 2 else 128 25 | output_filename = sys.argv[2] if len(sys.argv) >= 3 else "fibonacci.xyz" 26 | make_fibonacci(n, output_filename) 27 | -------------------------------------------------------------------------------- /share/scripts/make_octahedron.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from random import random 3 | from math import pi, sqrt, sin, cos, acos 4 | 5 | """ 6 | Generate point cloud, that you can then use with blender_import_cameramesh.py 7 | to generate camera positions to render impostor textures. 8 | """ 9 | 10 | def make_octahedron(n, output_filename): 11 | r = 1 12 | sqrt2 = sqrt(2.0) 13 | 14 | octahedron = [] 15 | for eps in [-1, 1]: 16 | for i in range(n): 17 | u = float(i) / (n - 1) 18 | for j in range(n): 19 | v = float(j) / (n - 1) 20 | x = (u + v - 1.0) 21 | y = (u - v) 22 | z = eps * (1 - (abs(x) + abs(y))) 23 | octahedron.append((x, y, z)) 24 | 25 | with open(output_filename, 'w') as f: 26 | for (x, y, z) in octahedron: 27 | d = 1.0 / sqrt(x*x + y*y + z*z) 28 | f.write("%f %f %f\n" % (x*d, y*d, z*d)) 29 | 30 | if __name__ == "__main__": 31 | n = int(sys.argv[1]) if len(sys.argv) >= 2 else 8 32 | output_filename = sys.argv[2] if len(sys.argv) >= 3 else "octahedron.xyz" 33 | make_octahedron(n, output_filename) 34 | -------------------------------------------------------------------------------- /share/shaders/bake-impostor-atlas.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #pragma opt BLIT 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | #ifdef BLIT 8 | 9 | layout (location = 0) out vec4 out_normalAlpha; 10 | layout (location = 1) out vec4 out_baseColor; 11 | layout (location = 2) out vec4 out_metallicRoughness; 12 | 13 | uniform sampler2DArray uNormalAlpha; 14 | uniform sampler2DArray uBaseColor; 15 | uniform sampler2DArray uMetallicRoughness; 16 | 17 | uniform float uMultiplier = 1.0; 18 | 19 | void main() { 20 | ivec3 co = ivec3(ivec2(gl_FragCoord.xy), gl_Layer); 21 | out_normalAlpha = texelFetch(uNormalAlpha, co, 0) * uMultiplier; 22 | out_baseColor = texelFetch(uBaseColor, co, 0) * uMultiplier; 23 | out_metallicRoughness = texelFetch(uMetallicRoughness, co, 0) * uMultiplier; 24 | } 25 | 26 | /////////////////////////////////////////////////////////////////////////////// 27 | #else // BLIT 28 | 29 | in GeometryData { 30 | vec3 position_ws; 31 | vec3 normal_ws; 32 | vec3 tangent_ws; 33 | vec2 uv; 34 | flat uint materialId; 35 | } geo; 36 | 37 | layout (location = 0) out vec4 out_normalAlpha; 38 | layout (location = 1) out vec4 out_baseColor; 39 | layout (location = 2) out vec4 out_metallicRoughness; 40 | 41 | #include "include/gbuffer2.inc.glsl" 42 | #include "include/standard-material.inc.glsl" 43 | uniform StandardMaterial uMaterial[3]; 44 | 45 | uniform float uNormalMapping = 10.0; 46 | uniform float uMultiplier = 1.0; 47 | 48 | void main() { 49 | SurfacePoint surf = SurfacePoint( 50 | geo.position_ws, 51 | geo.normal_ws, 52 | -geo.tangent_ws, 53 | geo.uv, 54 | uNormalMapping 55 | ); 56 | 57 | GFragment fragment = SampleStandardMaterial(uMaterial[geo.materialId], surf); 58 | 59 | out_normalAlpha.rgb = normalize(fragment.normal.xyz) * 0.5 + 0.5; 60 | out_normalAlpha.a = 1.0; 61 | out_baseColor.rgb = fragment.baseColor.rgb; 62 | out_baseColor.a = 1.0; 63 | out_metallicRoughness.x = fragment.metallic; 64 | out_metallicRoughness.y = fragment.roughness; 65 | out_metallicRoughness.a = 1.0; 66 | 67 | //out_normalAlpha *= uMultiplier; 68 | //out_baseColor *= uMultiplier; 69 | //out_metallicRoughness *= uMultiplier; 70 | } 71 | 72 | /////////////////////////////////////////////////////////////////////////////// 73 | #endif // BLIT 74 | -------------------------------------------------------------------------------- /share/shaders/bake-impostor-atlas.geo.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #pragma opt BLIT 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | #ifdef BLIT 8 | 9 | #include "include/standard-posteffect.geo.inc.glsl" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | #else // BLIT 13 | 14 | in VertexData { 15 | vec3 position_ws; 16 | vec3 normal_ws; 17 | vec3 tangent_ws; 18 | vec2 uv; 19 | flat uint materialId; 20 | flat int layer; 21 | } vert[]; 22 | 23 | out GeometryData { 24 | vec3 position_ws; 25 | vec3 normal_ws; 26 | vec3 tangent_ws; 27 | vec2 uv; 28 | flat uint materialId; 29 | } geo; 30 | 31 | uniform uint uReducedViewCount = 1; 32 | uniform vec2 uScreenSpaceOffset = vec2(0.0); 33 | 34 | #include "include/uniform/camera.inc.glsl" 35 | #include "include/utils.inc.glsl" 36 | #include "include/raytracing.inc.glsl" 37 | #include "include/gbuffer2.inc.glsl" 38 | #include "include/impostor.inc.glsl" 39 | uniform mat4 uProjectionMatrix; 40 | 41 | layout (triangles) in; 42 | layout (triangle_strip, max_vertices = 3) out; 43 | 44 | // this is just a passthrough geo shader 45 | void main() { 46 | int layer = vert[0].layer; 47 | gl_Layer = layer; 48 | mat4 bakingViewMatrix = (InverseBakingViewMatrix(uint(layer), uReducedViewCount)); 49 | 50 | for (int i = 0; i < gl_in.length(); i++) { 51 | geo.position_ws = vert[i].position_ws; 52 | geo.normal_ws = vert[i].normal_ws; 53 | geo.tangent_ws = vert[i].tangent_ws; 54 | geo.uv = vert[i].uv; 55 | geo.materialId = vert[i].materialId; 56 | gl_Position = uProjectionMatrix * bakingViewMatrix * vec4(geo.position_ws, 1.0); 57 | gl_Position.y *= -1; 58 | gl_Position.xy += uScreenSpaceOffset * gl_Position.w; 59 | EmitVertex(); 60 | } 61 | EndPrimitive(); 62 | } 63 | 64 | /////////////////////////////////////////////////////////////////////////////// 65 | #endif // BLIT 66 | -------------------------------------------------------------------------------- /share/shaders/bake-impostor-atlas.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #pragma opt BLIT 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | #ifdef BLIT 8 | 9 | #include "include/standard-posteffect.vert.inc.glsl" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | #else // BLIT 13 | 14 | // From MeshDataBehavior VAO 15 | layout (location = 0) in vec3 position; 16 | layout (location = 1) in vec3 normal; 17 | layout (location = 2) in vec2 uv; 18 | layout (location = 3) in uint materialId; 19 | layout (location = 4) in vec3 tangent; 20 | 21 | out VertexData { 22 | vec3 position_ws; 23 | vec3 normal_ws; 24 | vec3 tangent_ws; 25 | vec2 uv; 26 | flat uint materialId; 27 | flat int layer; 28 | } vert; 29 | 30 | uniform mat4 uModelMatrix; 31 | 32 | void main() { 33 | vert.position_ws = (uModelMatrix * vec4(position, 1.0)).xyz; 34 | vert.normal_ws = mat3(uModelMatrix) * normal; 35 | vert.tangent_ws = tangent; 36 | vert.uv = vec2(uv.x, 1.-uv.y); 37 | vert.materialId = materialId; 38 | vert.layer = gl_InstanceID; 39 | } 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | #endif // BLIT 43 | -------------------------------------------------------------------------------- /share/shaders/basic-world.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #pragma variant ALL_BLACK 5 | 6 | in vec3 direction; 7 | 8 | layout (location = 0) out vec4 color1; 9 | layout (location = 1) out uvec4 color2; 10 | layout (location = 2) out uvec4 color3; 11 | 12 | uniform samplerCube cubemap; 13 | uniform samplerCubeArray filteredCubemaps; 14 | 15 | const uint nbSamples = 1024; 16 | 17 | #include "include/gbuffer.inc.glsl" 18 | 19 | void main() { 20 | //vec4 color = texture(cubemap, direction); 21 | 22 | GFragment fragment; 23 | fragment.baseColor = vec3(1.0, 0.0, 0.0); 24 | fragment.ws_coord = vec3(direction * 1000.0); 25 | fragment.material_id = worldMaterial; 26 | fragment.normal = direction; 27 | 28 | #ifdef ALL_BLACK 29 | color1 = vec4(0.001); 30 | color2 = uvec4(0.0); 31 | color3 = uvec4(0.0); 32 | #else // ALL_BLACK 33 | packGFragment(fragment, color1, color2, color3); 34 | #endif // ALL_BLACK 35 | } 36 | -------------------------------------------------------------------------------- /share/shaders/basic-world.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 position; 4 | 5 | out vec3 direction; 6 | 7 | #include "include/uniform/camera.inc.glsl" 8 | 9 | void main() { 10 | vec4 pos = projectionMatrix * mat4(mat3(viewMatrix)) * vec4(position, 0.001f); 11 | gl_Position = pos.xyww; 12 | direction = position; 13 | } 14 | -------------------------------------------------------------------------------- /share/shaders/deferred-shader.geo.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | layout(points) in; 4 | layout(triangle_strip, max_vertices = 4) out; 5 | 6 | out vec2 uv_coords; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4( 1.0, 1.0, 0.5, 1.0 ); 11 | uv_coords = vec2( 1.0, 1.0 ); 12 | EmitVertex(); 13 | 14 | gl_Position = vec4(-1.0, 1.0, 0.5, 1.0 ); 15 | uv_coords = vec2( 0.0, 1.0 ); 16 | EmitVertex(); 17 | 18 | gl_Position = vec4( 1.0,-1.0, 0.5, 1.0 ); 19 | uv_coords = vec2( 1.0, 0.0 ); 20 | EmitVertex(); 21 | 22 | gl_Position = vec4(-1.0,-1.0, 0.5, 1.0 ); 23 | uv_coords = vec2( 0.0, 0.0 ); 24 | EmitVertex(); 25 | 26 | EndPrimitive(); 27 | } 28 | -------------------------------------------------------------------------------- /share/shaders/deferred-shader.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | 3 | void main() { 4 | gl_Position = vec4(0.0); 5 | } 6 | -------------------------------------------------------------------------------- /share/shaders/depth-to-color.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) out vec4 color; 5 | 6 | in vec2 uv; 7 | 8 | uniform sampler2D uMainTexture; 9 | uniform int uMipMapLevel = 0; 10 | uniform float uNear; 11 | uniform float uFar; 12 | 13 | void main() { 14 | float depth = textureLod(uMainTexture, uv, uMipMapLevel).r; 15 | float ndc = depth * 2.0 - 1.0; 16 | float linearDepth = (2.0 * uNear * uFar) / (uFar + uNear - ndc * (uFar - uNear)); 17 | linearDepth /= uFar; 18 | float remappedDepth = depth; 19 | color = vec4(vec3(linearDepth), 1.0); 20 | } 21 | -------------------------------------------------------------------------------- /share/shaders/depth-to-color.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) in vec3 position; 5 | 6 | out vec2 uv; 7 | 8 | void main() { 9 | gl_Position = vec4(position, 1.0); 10 | uv = position.xy * .5 + .5; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /share/shaders/far-grain.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #pragma varopt PASS_BLIT_TO_MAIN_FBO 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | #ifdef PASS_BLIT_TO_MAIN_FBO 8 | 9 | #include "include/standard-posteffect.vert.inc.glsl" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | #else // PASS_BLIT_TO_MAIN_FBO 13 | 14 | layout (location = 0) in vec4 position; 15 | 16 | struct PointCloundVboEntry { 17 | vec4 position; 18 | }; 19 | layout(std430, binding = 0) restrict readonly buffer pointsSsbo { 20 | PointCloundVboEntry pointVertexAttributes[]; 21 | }; 22 | layout (std430, binding = 1) restrict readonly buffer pointElementsSsbo { 23 | uint pointElements[]; 24 | }; 25 | 26 | out VertexData { 27 | vec3 position_ws; 28 | vec3 originalPosition_ws; // for procedural color 29 | float radius; 30 | uint vertexId; 31 | } outData; 32 | 33 | uniform mat4 modelMatrix; 34 | uniform mat4 viewModelMatrix; 35 | 36 | uniform float uGrainRadius = 0.005; 37 | 38 | uniform uint uFrameCount; 39 | uniform uint uPointCount; 40 | uniform float uFps = 25.0; 41 | uniform float uTime; 42 | uniform bool uUseAnimation = true; 43 | 44 | uniform bool uUsePointElements = true; 45 | 46 | #include "include/anim.inc.glsl" 47 | 48 | void main() { 49 | uint pointId = 50 | uUsePointElements 51 | ? pointElements[gl_VertexID] 52 | : gl_VertexID; 53 | 54 | uint animPointId = 55 | uUseAnimation 56 | ? AnimatedPointId2(pointId, uFrameCount, uPointCount, uTime, uFps) 57 | : pointId; 58 | 59 | vec3 p = 60 | uUsePointElements 61 | ? pointVertexAttributes[animPointId].position.xyz 62 | : position.xyz; 63 | 64 | #ifdef PROCEDURAL_ANIM0 65 | float t = uTime * 0.; 66 | p *= 1 + sin(t * 2.0 + p.y * 2.0) * 0.1 * sin(atan(p.x, p.z) * 10.0); 67 | #endif // PROCEDURAL_ANIM0 68 | 69 | outData.radius = uGrainRadius; 70 | outData.position_ws = (modelMatrix * vec4(p, 1.0)).xyz; 71 | outData.originalPosition_ws = (modelMatrix * vec4(p, 1.0)).xyz; 72 | outData.vertexId = pointId; 73 | outData.vertexId = animPointId%20; // WTF? 74 | } 75 | 76 | /////////////////////////////////////////////////////////////////////////////// 77 | #endif // PASS_BLIT_TO_MAIN_FBO 78 | -------------------------------------------------------------------------------- /share/shaders/generate-mipmap-zbuffer.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | in vec2 uv; 5 | 6 | uniform sampler2D previousLevel; 7 | 8 | void main() { 9 | ivec2 d = ivec2(-1, 0); 10 | ivec2 xy = ivec2(2 * gl_FragCoord.xy); 11 | float z00 = texelFetch(previousLevel, xy + d.yy, 0).r; 12 | float z10 = texelFetch(previousLevel, xy + d.xy, 0).r; 13 | float z01 = texelFetch(previousLevel, xy + d.yx, 0).r; 14 | float z11 = texelFetch(previousLevel, xy + d.xx, 0).r; 15 | gl_FragDepth = max(max(z00, z01), max(z10, z11)); 16 | } 17 | -------------------------------------------------------------------------------- /share/shaders/generate-mipmap-zbuffer.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) in vec3 position; 5 | 6 | out vec2 uv; 7 | 8 | void main() { 9 | gl_Position = vec4(position, 1.0); 10 | uv = position.xy * .5 + .5; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /share/shaders/gltf-mesh.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | in vec3 position_ws; 5 | in vec3 normal_ws; 6 | in vec3 normal_cs; 7 | in vec3 tangent_ws; 8 | in vec2 uv0_ts; 9 | in vec2 uv1_ts; 10 | in vec3 color0_srgb; 11 | 12 | layout (location = 0) out vec4 gbuffer_color1; 13 | layout (location = 1) out uvec4 gbuffer_color2; 14 | layout (location = 2) out uvec4 gbuffer_color3; 15 | 16 | uniform struct Material { 17 | vec3 baseColor; 18 | float metallic; 19 | float roughness; 20 | sampler2D baseColorMap; 21 | sampler2D normalMap; 22 | sampler2D metallicRoughnessMap; 23 | bool hasBaseColorMap; 24 | bool hasNormalMap; 25 | bool hasMetallicRoughnessMap; 26 | } material[3]; 27 | 28 | uniform vec4 baseColor = vec4(1.0, 0.5, 0.0, 1.0); 29 | uniform float height = 0.0; 30 | uniform float metallic = 1.0; 31 | uniform float roughness = 0.7; 32 | uniform float occlusion = 1.0; 33 | uniform vec3 emission = vec3(0.0, 0.0, 0.0); 34 | uniform vec3 normal = vec3(0.5, 0.5, 1.0); 35 | uniform float normal_mapping = 1.0; 36 | 37 | #include "include/gbuffer.inc.glsl" 38 | 39 | void main() { 40 | int matId = 0; 41 | vec3 normal = normal_ws; 42 | if (normal_mapping > 0 && material[matId].hasNormalMap) { 43 | vec3 normal_ts = vec3(texture(material[matId].normalMap, uv0_ts)) * 2.0 - 1.0; 44 | // Normal mapping 45 | mat3 TBN = mat3( 46 | normalize(cross(normal_ws, tangent_ws)), 47 | normalize(tangent_ws), 48 | normalize(normal_ws) 49 | ); 50 | normal = normalize(normal_ws * normal_mapping + TBN * normal_ts); 51 | } 52 | 53 | GFragment fragment; 54 | fragment.baseColor = baseColor.rgb; 55 | if (material[matId].hasBaseColorMap) { 56 | fragment.baseColor = texture(material[matId].baseColorMap, uv0_ts).rgb; 57 | } else { 58 | fragment.baseColor = material[matId].baseColor; 59 | } 60 | fragment.roughness = roughness; 61 | fragment.metallic = metallic; 62 | if (material[matId].hasMetallicRoughnessMap) { 63 | vec4 t = texture(material[matId].metallicRoughnessMap, uv0_ts); 64 | fragment.metallic = t.x; 65 | fragment.roughness = t.y; 66 | } else { 67 | fragment.roughness = material[matId].roughness; 68 | fragment.metallic = material[matId].metallic; 69 | } 70 | fragment.normal = normalize(normal); 71 | fragment.ws_coord = position_ws; 72 | fragment.material_id = pbrMaterial; 73 | fragment.emission = vec3(0.0); 74 | fragment.alpha = 1.0; 75 | 76 | packGFragment(fragment, gbuffer_color1, gbuffer_color2, gbuffer_color3); 77 | } 78 | -------------------------------------------------------------------------------- /share/shaders/gltf-mesh.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | // From MeshDataBehavior VAO 5 | layout (location = 0) in vec3 position; 6 | layout (location = 1) in vec3 normal; 7 | layout (location = 2) in vec3 tangent; 8 | layout (location = 3) in vec2 uv0; 9 | layout (location = 4) in vec2 uv1; 10 | layout (location = 5) in vec3 color0; 11 | 12 | out vec3 position_ws; 13 | out vec3 normal_ws; 14 | out vec3 normal_cs; 15 | out vec3 tangent_ws; 16 | out vec2 uv0_ts; 17 | out vec2 uv1_ts; 18 | out vec3 color0_srgb; 19 | 20 | uniform mat4 modelMatrix; 21 | uniform mat4 viewModelMatrix; 22 | #include "include/uniform/camera.inc.glsl" 23 | 24 | void main() { 25 | gl_Position = projectionMatrix * viewMatrix * vec4(position - vec3(4.1, 12.7, 2.4), 1.0); 26 | position_ws = (modelMatrix * vec4(position, 1.0)).xyz; 27 | normal_ws = mat3(modelMatrix) * normal; 28 | normal_cs = mat3(viewModelMatrix) * normal; 29 | tangent_ws = tangent; 30 | uv0_ts = uv0; 31 | uv1_ts = uv1; 32 | color0_srgb = color0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /share/shaders/grain/occlusion-culling.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | in Geometry { 5 | vec4 position_cs; 6 | float radius; 7 | } geo; 8 | 9 | layout (location = 0) out vec4 out_color; 10 | 11 | #include "../include/uniform/camera.inc.glsl" 12 | 13 | #include "../include/utils.inc.glsl" 14 | #include "../include/raytracing.inc.glsl" 15 | 16 | void main() { 17 | /* 18 | Ray ray_cs = fragmentRay(gl_FragCoord, projectionMatrix); 19 | vec3 hitPosition; 20 | if (!intersectRaySphere(hitPosition, ray_cs, geo.position_cs.xyz, geo.radius)) { 21 | discard; // not recommended 22 | } 23 | */ 24 | out_color = geo.position_cs; 25 | } 26 | -------------------------------------------------------------------------------- /share/shaders/grain/occlusion-culling.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | struct PointCloundVboEntry { 5 | vec4 position; 6 | }; 7 | layout(std430, binding = 1) restrict readonly buffer points { 8 | PointCloundVboEntry vbo[]; 9 | }; 10 | 11 | out Geometry { 12 | vec4 position_cs; 13 | float radius; 14 | } geo; 15 | 16 | uniform float uOuterOverInnerRadius = 1.0 / 0.5; 17 | uniform float uGrainRadius; 18 | uniform float uGrainInnerRadiusRatio; 19 | uniform float uOccluderMapSpriteScale = 0.2; 20 | 21 | uniform uint uFrameCount; 22 | uniform uint uPointCount; 23 | uniform float uTime; 24 | uniform float uFps = 25.0; 25 | 26 | uniform mat4 modelMatrix; 27 | uniform mat4 viewModelMatrix; 28 | #include "../include/uniform/camera.inc.glsl" 29 | 30 | #include "../include/utils.inc.glsl" 31 | #include "../include/sprite.inc.glsl" 32 | #include "../include/anim.inc.glsl" 33 | 34 | void main() { 35 | uint pointId = AnimatedPointId2(gl_VertexID, uFrameCount, uPointCount, uTime, uFps); 36 | 37 | vec4 position_ms = vec4(vbo[pointId].position.xyz, 1.0); 38 | geo.position_cs = viewModelMatrix * position_ms; 39 | geo.radius = uGrainRadius * uGrainInnerRadiusRatio; // inner radius 40 | gl_Position = projectionMatrix * geo.position_cs; 41 | // The *.15 has no explaination, but it empirically increases occlusion culling 42 | gl_PointSize = SpriteSize(geo.radius, gl_Position) * uOccluderMapSpriteScale; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /share/shaders/grain/procedural-color.inc.glsl: -------------------------------------------------------------------------------- 1 | #include "random-grains.inc.glsl" 2 | 3 | uniform sampler2D uColormapTexture; 4 | 5 | vec3 proceduralColor(vec3 pos, uint pointId) { 6 | vec3 baseColor = vec3(0.0); 7 | 8 | #if defined(PROCEDURAL_BASECOLOR) 9 | 10 | float r = randomGrainColorFactor(int(pointId)); 11 | baseColor = texture(uColormapTexture, vec2(r, 0.0)).rgb; 12 | 13 | #elif defined(PROCEDURAL_BASECOLOR2) 14 | 15 | float r0 = randomGrainColorFactor(int(pointId)); 16 | float r = pos.z*.6 + mix(0.35, 0.3, sin(pos.x*.5+.5))*r0; 17 | if (r0 < 0.5) { 18 | r = 1. - r0; 19 | } 20 | baseColor = texture(uColormapTexture, vec2(r, 0.0)).rgb; 21 | baseColor *= mix(vec3(0.9, 0.9, 0.9), vec3(1.6, 2.0, 2.0), r0); 22 | 23 | #elif defined(PROCEDURAL_BASECOLOR3) 24 | 25 | float r = randomGrainColorFactor(int(pointId)); 26 | float u = pow(0.5 + pos.z * 0.5, 3.0); 27 | if (r < 0.1) u = 0.01; 28 | if (r > 0.9) u = 0.99; 29 | baseColor = texture(uColormapTexture, vec2(clamp(u + (r - 0.5) * 0.2, 0.01, 0.99), 0.0)).rgb; 30 | 31 | // Add a blue dot 32 | float th = 0.01; 33 | if (abs(atan(pos.y, pos.x)) < th && abs(atan(pos.z, pos.x)) < th) { 34 | baseColor = vec3(0.0, 0.2, 0.9); 35 | } 36 | 37 | baseColor = mix(baseColor, baseColor.bgr, smoothstep(0.75, 0.73, length(pos))); 38 | 39 | #elif defined(PROCEDURAL_BASECOLOR_BLACK) 40 | 41 | baseColor = vec3(0.0, 0.0, 0.0); 42 | 43 | #endif // PROCEDURAL_BASECOLOR 44 | 45 | return baseColor; 46 | } 47 | 48 | bool isUsingProceduralColor() { 49 | #if defined(PROCEDURAL_BASECOLOR) || defined(PROCEDURAL_BASECOLOR2) || defined(PROCEDURAL_BASECOLOR3) || defined(PROCEDURAL_BASECOLOR_BLACK) 50 | return true; 51 | #define USING_PRECEDURAL_COLOR 52 | #else 53 | return false; 54 | #endif // PROCEDURAL_BASECOLOR 55 | } 56 | -------------------------------------------------------------------------------- /share/shaders/grain/random-grains.inc.glsl: -------------------------------------------------------------------------------- 1 | // requires random.inc.glsl 2 | #pragma variant NO_GRAIN_ROTATION 3 | 4 | mat3 randomGrainOrientation(int id) { 5 | vec3 vx = normalize(randVec(vec3(id, id, id))); 6 | vec3 vy = normalize(cross(vec3(0,0,sign(-vx) * 1 + .001), vx)); 7 | vec3 vz = normalize(cross(vx, vy)); 8 | float t = 0.0; 9 | return mat3(vx, vy * cos(t) - vz * sin(t), vy * sin(t) + vz * cos(t)); 10 | } 11 | 12 | mat4 randomGrainMatrix(int id, vec3 position_ws) { 13 | #ifdef NO_GRAIN_ROTATION 14 | mat3 rot = mat3(1.0); 15 | #else // NO_GRAIN_ROTATION 16 | mat3 rot = randomGrainOrientation(id); 17 | #endif // NO_GRAIN_ROTATION 18 | return mat4( 19 | vec4(rot[0], 0.0), 20 | vec4(rot[1], 0.0), 21 | vec4(rot[2], 0.0), 22 | vec4(- rot * position_ws, 1.0) 23 | ); 24 | } 25 | 26 | // Used to query colorramp image 27 | float randomGrainColorFactor(int id) { 28 | //return float(id) * .1; 29 | return fract(dot(vec2(id*.01, id*.213) ,vec2(12.9898,78.233))*.01); 30 | return randv2(vec2(id*.01, id*.213)); 31 | } 32 | -------------------------------------------------------------------------------- /share/shaders/impostor-grain.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 430 core 2 | #include "sys:defines" 3 | 4 | #pragma varopt PASS_BLIT_TO_MAIN_FBO 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | #ifdef PASS_BLIT_TO_MAIN_FBO 8 | 9 | #include "include/standard-posteffect.vert.inc.glsl" 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | #else // PASS_BLIT_TO_MAIN_FBO 13 | 14 | out VertexData { 15 | uint id; 16 | } vert; 17 | 18 | // All the vertex shader is in the geometry shader to allow for whole poitn discard 19 | void main() { 20 | vert.id = gl_VertexID; 21 | } 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | #endif // PASS 25 | -------------------------------------------------------------------------------- /share/shaders/include/anim.inc.glsl: -------------------------------------------------------------------------------- 1 | 2 | // depreciated 3 | uint AnimatedPointId(uint pointId, uint frameCount, uint pointCount, float time, float fps) { 4 | uint pointCountPerFrame = pointCount / frameCount; 5 | uint frame = uint(time * fps) % max(1, frameCount); 6 | return pointId + pointCountPerFrame * frame; 7 | } 8 | 9 | // better: pointCount is the point count per frame, not the total size of the buffer 10 | uint AnimatedPointId2(uint pointId, uint frameCount, uint pointCount, float time, float fps) { 11 | uint frame = uint(time * fps) % max(1, frameCount); 12 | return pointId + pointCount * frame; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /share/shaders/include/depth.inc.glsl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // Deapth related functions (require a camera ubo) 3 | 4 | void setFragmentDepth(vec3 position_cs) { 5 | vec4 clipPos = projectionMatrix * vec4(position_cs, 1.0); 6 | float ndcDepth = clipPos.z / clipPos.w; 7 | gl_FragDepth = ((gl_DepthRange.diff * ndcDepth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0; 8 | } 9 | -------------------------------------------------------------------------------- /share/shaders/include/frustum.inc.glsl: -------------------------------------------------------------------------------- 1 | /** 2 | * Parameter 'planes' contains coefficients (a, b, c, d) such that (x,y,z) is a point of the plane iff ax+by+cz+d=0 3 | * There are six frustum planes, in this order: left, right, top, bottom, near, far 4 | * See http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf for explaination 5 | */ 6 | void ExtractFrustumPlanes(const mat4 projectionMatrix, out vec4 planes[6]) { 7 | mat4 m = transpose(projectionMatrix); 8 | planes[0] = m[3] + m[0]; 9 | planes[1] = m[3] - m[0]; 10 | planes[2] = m[3] + m[1]; 11 | planes[3] = m[3] - m[1]; 12 | planes[4] = m[3] + m[2]; 13 | planes[5] = m[3] - m[2]; 14 | } 15 | 16 | /** 17 | * Frustum culling of a sphere at position p of radius r 18 | */ 19 | bool SphereFrustumCulling(const mat4 projectionMatrix, vec3 p, float radius) { 20 | vec4 planes[6]; 21 | ExtractFrustumPlanes(projectionMatrix, planes); 22 | for (int i = 0; i < 5; i++) { 23 | float dist = dot(vec4(p, 1.0), planes[i]); 24 | if (dist < -radius) return true; // sphere culled 25 | } 26 | return false; 27 | } 28 | -------------------------------------------------------------------------------- /share/shaders/include/lean-mapping.inc.glsl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // LEAN-mapping related functions 3 | // 4 | 5 | struct LeanStatistics { 6 | vec2 B; 7 | vec3 sigma; 8 | float Det; 9 | }; 10 | 11 | /** 12 | * Call this on level 0 of mip maps (then generate other mip maps for lean 13 | * maps in a standard way). 14 | * tn: input normal map in tangent space 15 | * t1, t2: packed lean statistics 16 | * s: scale parameter from eq 5 17 | * sc: scale parameter to fit packing in high definition range 18 | */ 19 | void normalToLeanMaps(const in vec3 tn, out vec4 t1, out vec4 t2, float s, float sc) { 20 | vec3 N = vec3(2.0 * tn.xy - 1.0, tn.z); 21 | 22 | vec2 B = N.xy / (sc * N.z); 23 | vec3 M = vec3(B.x * B.x + 1.0 / s, B.y * B.y + 1.0 / s, B.x * B.y); 24 | 25 | t1 = vec4(tn, M.z * 0.5 + 0.5); 26 | t2 = vec4(B * 0.5 + 0.5, M.xy); 27 | } 28 | 29 | LeanStatistics unpackLeanStatistics(const vec4 t1, const vec4 t2, float sc) { 30 | // unpack normal 31 | vec3 N = vec3(2.0 * t1.xy - 1.0, t1.z); 32 | 33 | // unpack B and M 34 | vec2 B = (2.0 * t2.xy - 1.0) * sc; 35 | vec3 M = vec3(t2.zw, 2.0 * t1.w - 1.0) * sc * sc; 36 | 37 | // convert M to sigma 38 | vec3 sigma = M - vec3(B * B, B.x * B.y); 39 | float Det = sigma.x * sigma.y - sigma.z * sigma.z; 40 | 41 | return LeanStatistics(B, sigma, Det); 42 | } 43 | 44 | /** 45 | * Get specular from half-vector 46 | */ 47 | float leanSpecular(const LeanStatistics stats, const vec3 h) { 48 | if (stats.Det <= 0.0) return 0.0; 49 | 50 | // compute specular 51 | vec2 h_bar = h.xy / h.z - stats.B; 52 | float e = ( 53 | h_bar.x * h_bar.x * stats.sigma.y 54 | + h_bar.y * h_bar.y * stats.sigma.x 55 | - 2.0 * h_bar.x * h_bar.y * stats.sigma.z 56 | ); 57 | return exp(-0.5 * e / stats.Det) / sqrt(stats.Det); 58 | } 59 | -------------------------------------------------------------------------------- /share/shaders/include/octahedron.inc.glsl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // Octahedric projection/unprojection functions 3 | 4 | /** 5 | * Return the index of the closest octaedral map cell corresponding to the given direction 6 | */ 7 | int directionToViewIndex(vec3 direction_gs, int nb = 8) { 8 | float l1 = abs(direction_gs.x) + abs(direction_gs.y) + abs(direction_gs.z); 9 | vec3 l1UnitDirection = direction_gs / l1; 10 | float x = l1UnitDirection.x; 11 | float y = l1UnitDirection.y; 12 | float u = (x + y + 1) * 0.5; 13 | float v = (x - y + 1) * 0.5; 14 | int layer = int(round(u * (nb - 1))) * nb + int(round(v * (nb - 1))); 15 | if (l1UnitDirection.z > 0) { 16 | layer += nb*nb; 17 | } 18 | return layer; 19 | } 20 | 21 | /** 22 | * Returns indices of the fourth directions enclosing the target direction in the octahedron cell 23 | */ 24 | void directionToViewIndexAll(in vec3 direction_gs, out int idx1, out int idx2, out int idx3, out int idx4, out float du, out float dv, in int nb = 8) { 25 | float l1 = abs(direction_gs.x) + abs(direction_gs.y) + abs(direction_gs.z); 26 | vec3 l1UnitDirection = direction_gs / l1; 27 | float x = l1UnitDirection.x; 28 | float y = l1UnitDirection.y; 29 | float u = (x + y + 1) * 0.5; 30 | float v = (x - y + 1) * 0.5; 31 | idx1 = int(floor(u * (nb - 1))) * nb + int(floor(v * (nb - 1))); 32 | idx2 = int(ceil(u * (nb - 1))) * nb + int(floor(v * (nb - 1))); 33 | idx3 = int(floor(u * (nb - 1))) * nb + int(ceil(v * (nb - 1))); 34 | idx4 = int(ceil(u * (nb - 1))) * nb + int(ceil(v * (nb - 1))); 35 | if (l1UnitDirection.z > 0) { 36 | idx1 += nb*nb; 37 | idx2 += nb*nb; 38 | idx3 += nb*nb; 39 | idx4 += nb*nb; 40 | } 41 | du = fract(u * (nb - 1)); 42 | dv = fract(v * (nb - 1)); 43 | } 44 | 45 | vec3 viewIndexToDirection(int viewIndex, int nb = 8) { 46 | float eps = -1.0; 47 | if (viewIndex >= nb * nb) { 48 | eps = 1.0; 49 | viewIndex -= nb * nb; 50 | } 51 | int i = viewIndex / nb; 52 | int j = viewIndex % nb; 53 | float u = float(i) / (nb - 1); 54 | float v = float(j) / (nb - 1); 55 | float x = (u + v - 1.0); 56 | float y = (u - v); 57 | float z = eps * (1.0 - (abs(x) + abs(y))); 58 | return normalize(vec3(x, y, z)); 59 | } 60 | -------------------------------------------------------------------------------- /share/shaders/include/random.inc.glsl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // Random generation functions 3 | 4 | float randv2(vec2 co){ 5 | return fract(sin(dot(co ,vec2(12.9898,78.233))) * 43758.5453); 6 | } 7 | float rand(vec3 co){ 8 | return randv2(vec2(randv2(co.xy/100.0f), randv2(co.yz/100.0f))); 9 | } 10 | float rand2(vec3 co){ 11 | float a = rand(co); 12 | return rand(vec3(a,a+1,a+2)); 13 | } 14 | float rand3(vec3 co){ 15 | float a = rand(co); 16 | float b = rand(co); 17 | return rand(vec3(a,b,a+b)); 18 | } 19 | vec3 randVec(vec3 co) { 20 | return vec3(rand(co), rand2(co), rand3(co)) * 2.f - vec3(1.f); 21 | } 22 | 23 | float length2(vec3 v) { 24 | return dot(v,v); 25 | } 26 | -------------------------------------------------------------------------------- /share/shaders/include/raytracing.inc.glsl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // Ray-tracing routines 3 | 4 | // requires that you include utils.inc.glsl for isOrthographic() and uniforms/camera.inc.glsl for resolution 5 | 6 | struct Ray { 7 | vec3 origin; 8 | vec3 direction; 9 | }; 10 | 11 | /** 12 | * Apply an affine transformation matrix to a ray 13 | */ 14 | Ray TransformRay(Ray ray, mat4 transform) { 15 | Ray transformed_ray; 16 | transformed_ray.origin = (transform * vec4(ray.origin, 1)).xyz; 17 | transformed_ray.direction = mat3(transform) * ray.direction; 18 | return transformed_ray; 19 | } 20 | 21 | /** 22 | * Get the ray corresponding to a pixel, in camera space 23 | */ 24 | Ray fragmentRay(in vec4 fragCoord, in mat4 projectionMatrix) { 25 | vec2 uv = fragCoord.xy / resolution.xy * 2.f - vec2(1.f); 26 | 27 | if (isOrthographic(projectionMatrix)) { 28 | float a = 1.0 / projectionMatrix[0][0]; 29 | float b = a * projectionMatrix[3][0]; 30 | float c = 1.0 / projectionMatrix[1][1]; 31 | float d = c * projectionMatrix[3][1]; 32 | return Ray( 33 | vec3(a * uv.x + b, c * uv.y + d, 0.0), 34 | vec3(0.0, 0.0, -1.f) 35 | ); 36 | } else { 37 | float fx = projectionMatrix[0][0]; 38 | float fy = projectionMatrix[1][1]; 39 | return Ray( 40 | vec3(0.0), 41 | vec3(uv.x / fx, uv.y / fy, -1.f) 42 | ); 43 | } 44 | } 45 | 46 | 47 | bool intersectRaySphere(out vec3 hitPosition, in Ray ray, in vec3 center, in float radius) { 48 | vec3 o = center - ray.origin; 49 | float d2 = dot(ray.direction, ray.direction); 50 | float r2 = radius * radius; 51 | float l2 = dot(o, o); 52 | float dp = dot(ray.direction, o); 53 | float delta = dp * dp / d2 - l2 + r2; 54 | 55 | if (delta >= 0) { 56 | float lambda = dp / d2 - sqrt(delta / d2); 57 | if (lambda < 0) lambda += 2. * sqrt(delta / d2); 58 | if (lambda >= 0) { 59 | hitPosition = ray.origin + lambda * ray.direction; 60 | return true; 61 | } 62 | } 63 | 64 | return false; 65 | } 66 | 67 | 68 | vec3 intersectRayPlane(in Ray ray, in vec3 pointOnPlane, in vec3 planeNormal) { 69 | vec3 o = pointOnPlane - ray.origin; 70 | float lambda = dot(o, planeNormal) / dot(ray.direction, planeNormal); 71 | return ray.origin + lambda * ray.direction; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /share/shaders/include/sprite.inc.glsl: -------------------------------------------------------------------------------- 1 | // Requires a "include/uniform/camera.inc.glsl" and "include/utils.inc.glsl" 2 | 3 | /** 4 | * Estimate projection of sphere on screen to determine sprite size (diameter). 5 | * (TODO: actually, this is the diameter...) 6 | */ 7 | float SpriteSize(float radius, vec4 position_clipspace) { 8 | if (isOrthographic(projectionMatrix)) { 9 | float a = projectionMatrix[0][0] * resolution.x; 10 | float c = projectionMatrix[1][1] * resolution.y; 11 | return max(a, c) * radius; 12 | } else { 13 | return max(resolution.x, resolution.y) * projectionMatrix[1][1] * radius / position_clipspace.w; 14 | } 15 | } 16 | 17 | float SpriteSize_Botsch03(float radius, vec4 position_cameraspace) { 18 | if (isOrthographic(projectionMatrix)) { 19 | return 2.0 * radius * resolution.y / (uTop - uBottom); 20 | } 21 | return 2.0 * radius * uNear / abs(position_cameraspace.z) * resolution.y / (uTop - uBottom); 22 | } 23 | 24 | /** 25 | * Corrects to take into account the fact that projected bounding spheres are 26 | * ellipses, not circles. Returns ellipse's largest radius. 27 | */ 28 | float SpriteSize_Botsch03_corrected(float radius, vec4 position_cameraspace) { 29 | if (isOrthographic(projectionMatrix)) { 30 | return 2.0 * radius * resolution.y / (uTop - uBottom); 31 | } 32 | float l2 = dot(position_cameraspace.xyz, position_cameraspace.xyz); 33 | float z = position_cameraspace.z; 34 | float z2 = z * z; 35 | float r2 = radius * radius; 36 | return 2.0 * radius * uNear * sqrt(l2 - r2) / abs(r2 - z2) * resolution.y / (uTop - uBottom); 37 | } 38 | -------------------------------------------------------------------------------- /share/shaders/include/standard-material.inc.glsl: -------------------------------------------------------------------------------- 1 | // Requires gbuffer.inc.glsl 2 | 3 | struct StandardMaterial { 4 | sampler2D baseColorMap; 5 | sampler2D normalMap; 6 | sampler2D metallicRoughnessMap; 7 | sampler2D metallicMap; 8 | sampler2D roughnessMap; 9 | vec3 baseColor; 10 | float metallic; 11 | float roughness; 12 | bool hasBaseColorMap; 13 | bool hasNormalMap; 14 | bool hasMetallicRoughnessMap; 15 | bool hasMetallicMap; 16 | bool hasRoughnessMap; 17 | }; 18 | 19 | struct SurfacePoint { 20 | vec3 position_ws; 21 | vec3 normal_ws; 22 | vec3 tangent_ws; 23 | vec2 uv; 24 | float normal_mapping; 25 | }; 26 | 27 | GFragment SampleStandardMaterial(const StandardMaterial mat, const SurfacePoint geo) { 28 | GFragment fragment; 29 | 30 | // Normal 31 | vec3 normal = geo.normal_ws; 32 | if (geo.normal_mapping > 0 && mat.hasNormalMap) { 33 | vec3 normal_ts = vec3(texture(mat.normalMap, geo.uv)) * 2.0 - 1.0; 34 | // Normal mapping 35 | mat3 TBN = mat3( 36 | normalize(-geo.tangent_ws), 37 | normalize(-cross(geo.normal_ws, geo.tangent_ws)), 38 | normalize(geo.normal_ws) 39 | ); 40 | normal = geo.normal_ws + TBN * normal_ts * geo.normal_mapping; 41 | } 42 | fragment.normal = normalize(normal); 43 | 44 | // Base Color 45 | if (mat.hasBaseColorMap) { 46 | fragment.baseColor = texture(mat.baseColorMap, geo.uv).rgb; 47 | } else { 48 | fragment.baseColor = mat.baseColor; 49 | } 50 | 51 | // Metallic/Roughness 52 | if (mat.hasMetallicRoughnessMap) { 53 | vec4 t = texture(mat.metallicRoughnessMap, geo.uv); 54 | fragment.metallic = t.x; 55 | fragment.roughness = t.y; 56 | } else { 57 | if (mat.hasMetallicMap) { 58 | fragment.metallic = texture(mat.metallicMap, geo.uv).r; 59 | } else { 60 | fragment.metallic = mat.metallic; 61 | } 62 | if (mat.hasRoughnessMap) { 63 | fragment.roughness = texture(mat.roughnessMap, geo.uv).r; 64 | } else { 65 | fragment.roughness = mat.roughness; 66 | } 67 | } 68 | 69 | // Other attributes 70 | fragment.ws_coord = geo.position_ws; 71 | fragment.material_id = pbrMaterial; 72 | fragment.emission = vec3(0.0); 73 | fragment.alpha = 1.0; 74 | return fragment; 75 | } 76 | -------------------------------------------------------------------------------- /share/shaders/include/standard-posteffect.geo.inc.glsl: -------------------------------------------------------------------------------- 1 | 2 | in vec2 vertUv[]; 3 | in flat int vertLayer[]; 4 | out vec2 uv; 5 | 6 | layout(triangles) in; 7 | layout(triangle_strip, max_vertices = 3) out; 8 | 9 | // this is just a passthrough geo shader 10 | void main() { 11 | gl_Layer = vertLayer[0]; 12 | for (int i = 0; i < gl_in.length(); i++) { 13 | gl_Position = gl_in[i].gl_Position; 14 | uv = vertUv[i]; 15 | EmitVertex(); 16 | } 17 | EndPrimitive(); 18 | } 19 | -------------------------------------------------------------------------------- /share/shaders/include/standard-posteffect.vert.inc.glsl: -------------------------------------------------------------------------------- 1 | // just a regular post effect 2 | 3 | layout (location = 0) in vec4 position; 4 | 5 | out vec2 vertUv; 6 | out flat int vertLayer; 7 | 8 | void main() { 9 | gl_Position = vec4(position.xyz, 1.0); 10 | vertUv = position.xy * .5 + .5; 11 | vertLayer = gl_InstanceID; 12 | } 13 | -------------------------------------------------------------------------------- /share/shaders/include/uniform/camera.inc.glsl: -------------------------------------------------------------------------------- 1 | 2 | layout (std140) uniform Camera { 3 | mat4 viewMatrix; 4 | mat4 projectionMatrix; 5 | mat4 inverseViewMatrix; 6 | vec2 resolution; 7 | float uNear; 8 | float uFar; 9 | float uLeft; 10 | float uRight; 11 | float uTop; 12 | float uBottom; 13 | }; 14 | -------------------------------------------------------------------------------- /share/shaders/include/utils.inc.glsl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // Misc utility functions 3 | 4 | const float pi = 3.1415926535897932384626433832795; 5 | const float PI = 3.1415926535897932384626433832795; 6 | const float HALF_SQRT2 = 0.7071067811865476; 7 | 8 | vec3 color2normal(in vec4 color) { 9 | return normalize(vec3(color) * 2.0 - vec3(1.0)); 10 | } 11 | 12 | vec4 normal2color(in vec3 normal, in float alpha) { 13 | return vec4(normal * 0.5 + vec3(0.5), alpha); 14 | } 15 | 16 | bool isOrthographic(mat4 projectionMatrix) { 17 | return abs(projectionMatrix[3][3]) > 0.01; 18 | } 19 | 20 | vec3 cameraPosition(mat4 viewMatrix) { 21 | return transpose(mat3(viewMatrix)) * vec3(viewMatrix[3][0], viewMatrix[3][1], viewMatrix[3][2]); 22 | } 23 | 24 | float getNearDistance(mat4 projectionMatrix) { 25 | return isOrthographic(projectionMatrix) 26 | ? (projectionMatrix[3][2] - 1) / projectionMatrix[2][2] 27 | : projectionMatrix[3][2] / (projectionMatrix[2][2] - 1); 28 | } 29 | 30 | float getFarDistance(mat4 projectionMatrix) { 31 | return isOrthographic(projectionMatrix) 32 | ? (projectionMatrix[3][2] - 1) / projectionMatrix[2][2] 33 | : projectionMatrix[3][2] / (projectionMatrix[2][2] + 1); 34 | } 35 | -------------------------------------------------------------------------------- /share/shaders/include/zbuffer.inc.glsl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////// 2 | // Z-Buffer utils 3 | // Requires a "include/uniform/camera.inc.glsl" and "include/utils.inc.glsl" 4 | 5 | // CHange these uniforms if using glDepthRange() 6 | uniform float uDepthRangeMin = 0.0f; 7 | uniform float uDepthRangeMax = 1.0f; 8 | 9 | float linearizeDepth(float logDepth) { 10 | float in01 = (logDepth - uDepthRangeMin) / (uDepthRangeMax - uDepthRangeMin); 11 | return (2.0 * uNear * uFar) / (uFar + uNear - (in01 * 2.0 - 1.0) * (uFar - uNear)); 12 | } 13 | 14 | float unlinearizeDepth(float linearDepth) { 15 | //return (uFar + uNear - (2.0 * uNear * uFar) / linearDepth) / (uFar - uNear) * 0.5 + 0.5; 16 | float in01 = (uFar + uNear - (2.0 * uNear * uFar) / linearDepth) / (uFar - uNear) * 0.5 + 0.5; 17 | return uDepthRangeMin + in01 * (uDepthRangeMax - uDepthRangeMin); 18 | } 19 | -------------------------------------------------------------------------------- /share/shaders/instance-grain.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #pragma variant PROCEDURAL_BASECOLOR 5 | 6 | //#define PROCEDURAL_BASECOLOR 7 | 8 | in VertexData { 9 | vec3 normal_ws; 10 | vec3 position_ws; 11 | vec3 tangent_ws; 12 | vec2 uv; 13 | flat uint materialId; 14 | vec3 baseColor; 15 | flat uint id; 16 | } vert; 17 | 18 | #define OUT_GBUFFER 19 | #include "include/gbuffer2.inc.glsl" 20 | 21 | #include "include/standard-material.inc.glsl" 22 | uniform StandardMaterial uMaterial[3]; 23 | 24 | uniform float uNormalMapping = 5.0; 25 | 26 | uniform bool uDebugRenderType = false; 27 | uniform vec3 uDebugRenderColor = vec3(172.0/255.0, 23.0/255.0, 1.0/255.0); 28 | 29 | #include "include/random.inc.glsl" 30 | #include "grain/procedural-color.inc.glsl" 31 | 32 | void main() { 33 | SurfacePoint surf = SurfacePoint( 34 | vert.position_ws, 35 | vert.normal_ws, 36 | vert.tangent_ws, 37 | vert.uv, 38 | uNormalMapping 39 | ); 40 | 41 | GFragment fragment = SampleStandardMaterial(uMaterial[vert.materialId], surf); 42 | 43 | if (uDebugRenderType) { 44 | fragment.baseColor = uDebugRenderColor; 45 | } else if (isUsingProceduralColor()) { 46 | fragment.baseColor = vert.baseColor.rgb; 47 | //float r = randomGrainColorFactor(int(vert.id)); 48 | //float s = randomGrainColorFactor(int(vert.id) + 436); 49 | //fragment.baseColor += vec3(r - 0.1, s - 0.5, 0.0) * 0.05; 50 | } 51 | 52 | autoPackGFragment(fragment); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /share/shaders/instance-grain.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) in vec3 position; 5 | layout (location = 1) in vec3 normal; 6 | layout (location = 2) in vec2 uv; 7 | layout (location = 3) in uint materialId; 8 | layout (location = 4) in vec3 tangent; 9 | 10 | struct PointCloundVboEntry { 11 | vec4 position; 12 | }; 13 | layout(std430, binding = 0) restrict readonly buffer pointsSsbo { 14 | PointCloundVboEntry pointVertexAttributes[]; 15 | }; 16 | layout (std430, binding = 1) restrict readonly buffer pointElementsSsbo { 17 | uint pointElements[]; 18 | }; 19 | 20 | out VertexData { 21 | vec3 normal_ws; 22 | vec3 position_ws; 23 | vec3 tangent_ws; 24 | vec2 uv; 25 | flat uint materialId; 26 | vec3 baseColor; 27 | flat uint id; 28 | } vert; 29 | 30 | uniform mat4 modelMatrix; 31 | uniform mat4 viewModelMatrix; 32 | #include "include/uniform/camera.inc.glsl" 33 | 34 | #pragma variant PROCEDURAL_BASECOLOR 35 | 36 | uniform float uGrainRadius = 0.005; 37 | uniform float uGrainMeshScale = 4.5; 38 | 39 | uniform uint uFrameCount; 40 | uniform uint uPointCount; 41 | uniform float uFps = 25.0; 42 | uniform float uTime; 43 | 44 | uniform bool uUseAnimation = true; 45 | uniform bool uUsePointElements = true; 46 | 47 | #include "include/random.inc.glsl" 48 | #include "include/anim.inc.glsl" 49 | #include "grain/procedural-color.inc.glsl" 50 | 51 | void main() { 52 | uint pointId = 53 | uUsePointElements 54 | ? pointElements[gl_InstanceID] 55 | : gl_InstanceID; 56 | 57 | uint animPointId = 58 | uUseAnimation 59 | ? AnimatedPointId2(pointId, uFrameCount, uPointCount, uTime, uFps) 60 | : pointId; 61 | 62 | vec3 grainCenter_ws = (modelMatrix * vec4(pointVertexAttributes[animPointId].position.xyz, 1.0)).xyz; 63 | 64 | pointId = animPointId%20; // WTF? 65 | mat3 ws_from_gs = transpose(mat3(randomGrainMatrix(int(pointId), grainCenter_ws))); 66 | 67 | vec3 vertexPosition = position; 68 | vec4 p = vec4(ws_from_gs * vertexPosition * uGrainRadius * uGrainMeshScale + grainCenter_ws, 1.0); 69 | 70 | vert.position_ws = p.xyz; 71 | vert.normal_ws = ws_from_gs * normal; 72 | vert.tangent_ws = tangent; 73 | vert.uv = vec2(uv.x, 1.-uv.y); 74 | vert.materialId = materialId; 75 | vert.baseColor = proceduralColor(vert.position_ws, pointId); 76 | vert.id = pointId; 77 | 78 | gl_Position = projectionMatrix * viewMatrix * vec4(vert.position_ws, 1.0); 79 | } 80 | -------------------------------------------------------------------------------- /share/shaders/light-gizmo.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | in vec3 position_ws; 5 | 6 | layout (location = 0) out vec4 gbuffer_color1; 7 | layout (location = 1) out uvec4 gbuffer_color2; 8 | layout (location = 2) out uvec4 gbuffer_color3; 9 | 10 | uniform vec4 baseColor = vec4(0.0, 0.0, 0.0, 1.0); 11 | uniform float height = 0.0; 12 | uniform float metallic = 0.0; 13 | uniform float roughness = 0.0; 14 | uniform float occlusion = 1.0; 15 | uniform vec3 emission = vec3(0.1, 0.1, 0.1); 16 | uniform vec3 normal = vec3(0.5, 0.5, 1.0); 17 | uniform float normal_mapping = 0.0; 18 | 19 | #include "include/gbuffer.inc.glsl" 20 | 21 | void main() { 22 | GFragment fragment; 23 | fragment.baseColor = baseColor.rgb; 24 | fragment.normal = normalize(normal * 2. - 1.); 25 | fragment.ws_coord = position_ws; 26 | fragment.material_id = pbrMaterial; 27 | fragment.roughness = roughness; 28 | fragment.metallic = metallic; 29 | fragment.emission = emission; 30 | fragment.alpha = 1.0; 31 | packGFragment(fragment, gbuffer_color1, gbuffer_color2, gbuffer_color3); 32 | } 33 | -------------------------------------------------------------------------------- /share/shaders/light-gizmo.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) in vec3 position; 5 | 6 | out vec3 position_ws; 7 | 8 | uniform mat4 modelMatrix; 9 | uniform mat4 viewModelMatrix; 10 | #include "include/uniform/camera.inc.glsl" 11 | 12 | uniform mat4 lightProjectionMatrix; 13 | uniform mat4 lightInverseViewMatrix; 14 | 15 | #include "include/utils.inc.glsl" 16 | 17 | void main() { 18 | vec3 v = position; 19 | 20 | float n, f, l, r, b, t; 21 | if (isOrthographic(lightProjectionMatrix)) { 22 | n = (lightProjectionMatrix[3][2] - 1) / lightProjectionMatrix[2][2]; 23 | f = (lightProjectionMatrix[3][2] - 1) / lightProjectionMatrix[2][2]; 24 | l = -(lightProjectionMatrix[3][0] - 1) / lightProjectionMatrix[0][0]; 25 | r = -(lightProjectionMatrix[3][0] + 1) / lightProjectionMatrix[0][0]; 26 | b = -(lightProjectionMatrix[3][1] - 1) / lightProjectionMatrix[1][1]; 27 | t = -(lightProjectionMatrix[3][1] + 1) / lightProjectionMatrix[1][1]; 28 | 29 | v = vec3(mix(l, r, v.x), mix(b, t, v.y), -mix(n, f, v.y)); 30 | } 31 | else { 32 | n = lightProjectionMatrix[3][2] / (lightProjectionMatrix[2][2] - 1); 33 | f = lightProjectionMatrix[3][2] / (lightProjectionMatrix[2][2] + 1); 34 | l = (lightProjectionMatrix[2][0] - 1) / lightProjectionMatrix[0][0]; 35 | r = (lightProjectionMatrix[2][0] + 1) / lightProjectionMatrix[0][0]; 36 | b = (lightProjectionMatrix[2][1] - 1) / lightProjectionMatrix[1][1]; 37 | t = (lightProjectionMatrix[2][1] + 1) / lightProjectionMatrix[1][1]; 38 | 39 | float s = mix(n, f, v.z); 40 | v = vec3(mix(l, r, v.x) * s, mix(b, t, v.y) * s, -s); 41 | } 42 | 43 | position_ws = (modelMatrix * lightInverseViewMatrix * vec4(v, 1.0)).xyz; 44 | gl_Position = projectionMatrix * viewMatrix * vec4(position_ws, 1.0); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /share/shaders/mipmap-using-alpha.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | in vec2 vertUv; 5 | 6 | uniform sampler2DArray uPreviousLevel; // previous level, where alpha is valid 7 | uniform sampler2DArray uAlphaLevel; // current level, alpha texture 8 | uniform int uLevel; 9 | uniform int uLayer; 10 | uniform bool isPremultiplied = false; 11 | 12 | layout (location = 0) out vec4 out_color; 13 | 14 | void main() { 15 | ivec2 d = ivec2(-1, 0); 16 | ivec3 xyz = ivec3(ivec2(2 * gl_FragCoord.xy), uLayer); 17 | 18 | vec4 c00 = texelFetch(uPreviousLevel, xyz + d.yyy, 0); 19 | vec4 c10 = texelFetch(uPreviousLevel, xyz + d.xyy, 0); 20 | vec4 c01 = texelFetch(uPreviousLevel, xyz + d.yxy, 0); 21 | vec4 c11 = texelFetch(uPreviousLevel, xyz + d.xxy, 0); 22 | 23 | float a00 = c00.a; 24 | float a10 = c10.a; 25 | float a01 = c01.a; 26 | float a11 = c11.a; 27 | 28 | if (uLevel == 0) { 29 | a00 = texelFetch(uAlphaLevel, xyz + d.yyy, 0).a; 30 | a10 = texelFetch(uAlphaLevel, xyz + d.xyy, 0).a; 31 | a01 = texelFetch(uAlphaLevel, xyz + d.yxy, 0).a; 32 | a11 = texelFetch(uAlphaLevel, xyz + d.xxy, 0).a; 33 | } 34 | 35 | float sum = a00 + a10 + a01 + a11; 36 | //if (isPremultiplied) { 37 | //} else { 38 | out_color.rgb = c00.rgb * a00 + c10.rgb * a10 + c01.rgb * a01 + c11.rgb * a11; 39 | out_color.rgb /= sum; 40 | out_color.a = sum * 0.25; 41 | // out_color.rgb = c00.rgb + c10.rgb + c01.rgb + c11.rgb; 42 | //} 43 | 44 | //out_color = (c00 + c01 + c10 + c11) * 0.25; 45 | //out_color = vec4(1.0, 0.5, 0.0, 1.0); 46 | } 47 | -------------------------------------------------------------------------------- /share/shaders/mipmap-using-alpha.geo.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #extension GL_EXT_geometry_shader4 : enable // to use gl_PositionIn[] 5 | 6 | in vec2 vertUv[]; 7 | out vec2 uv; 8 | 9 | uniform int uLayer; 10 | 11 | layout(triangles) in; 12 | layout(triangle_strip, max_vertices = 3) out; 13 | 14 | void main() { 15 | gl_Layer = uLayer; 16 | 17 | for (int i = 0; i < gl_VerticesIn; i++) { 18 | gl_Position = gl_PositionIn[i]; 19 | uv = vertUv[i]; 20 | EmitVertex(); 21 | } 22 | EndPrimitive(); 23 | } 24 | -------------------------------------------------------------------------------- /share/shaders/mipmap-using-alpha.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | #include "include/standard-posteffect.vert.inc.glsl" 5 | -------------------------------------------------------------------------------- /share/shaders/posteffect.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) out vec4 color; 5 | 6 | in vec2 uv; 7 | 8 | uniform sampler2D uMainTexture; 9 | uniform int uMipMapLevel = 0; 10 | uniform float uNear; 11 | uniform float uFar; 12 | 13 | void main() { 14 | float depth = textureLod(uMainTexture, uv, uMipMapLevel).r; 15 | float ndc = depth * 2.0 - 1.0; 16 | float linearDepth = (2.0 * uNear * uFar) / (uFar + uNear - ndc * (uFar - uNear)); 17 | linearDepth /= uFar; 18 | float remappedDepth = depth; 19 | color = vec4(vec3(linearDepth), 1.0); 20 | } 21 | -------------------------------------------------------------------------------- /share/shaders/posteffect.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) in vec3 position; 5 | 6 | out vec2 uv; 7 | 8 | void main() { 9 | gl_Position = vec4(position, 1.0); 10 | uv = position.xy * .5 + .5; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /share/shaders/quad.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | in vec2 uv; 5 | layout (location = 0) out vec4 color; 6 | 7 | uniform sampler2D uTexture; 8 | 9 | void main() { 10 | color = texture(uTexture, uv); 11 | } 12 | -------------------------------------------------------------------------------- /share/shaders/quad.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | layout (location = 0) in vec2 iUv; 5 | 6 | out vec2 uv; 7 | 8 | uniform vec2 uPosition; 9 | uniform vec2 uSize; 10 | uniform vec2 uResolution; 11 | 12 | vec2 mapToClipSpace(vec2 pixelCo) { 13 | return (pixelCo / uResolution * 2. - 1.) * vec2(1,-1); 14 | } 15 | 16 | void main() { 17 | gl_Position = vec4(mapToClipSpace(uPosition + iUv * uSize), 0.0, 1.0); 18 | uv = iUv; 19 | } 20 | -------------------------------------------------------------------------------- /share/shaders/standard-mesh.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | in GeometryData { 5 | vec3 position_ws; 6 | vec3 normal_ws; 7 | vec3 tangent_ws; 8 | vec2 uv; 9 | flat uint materialId; 10 | } geo; 11 | 12 | 13 | #define OUT_GBUFFER 14 | #include "include/gbuffer2.inc.glsl" 15 | 16 | #include "include/standard-material.inc.glsl" 17 | uniform StandardMaterial uMaterial[3]; 18 | 19 | uniform float uNormalMapping = 1.0; 20 | 21 | void main() { 22 | SurfacePoint surf = SurfacePoint( 23 | geo.position_ws, 24 | geo.normal_ws, 25 | geo.tangent_ws, 26 | geo.uv, 27 | uNormalMapping 28 | ); 29 | 30 | GFragment fragment = SampleStandardMaterial(uMaterial[geo.materialId], surf); 31 | 32 | fragment.roughness = pow(fragment.roughness, 0.5); 33 | //fragment.metallic = 0.0; 34 | //fragment.roughness = 0.2; 35 | //fragment.normal = normalize(cross(geo.normal_ws, geo.tangent_ws)); 36 | //fragment.normal = normalize(vec3(texture(uMaterial[geo.materialId].normalMap, geo.uv)) * 2.0 - 1.0); 37 | 38 | autoPackGFragment(fragment); 39 | } 40 | -------------------------------------------------------------------------------- /share/shaders/standard-mesh.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 core 2 | #include "sys:defines" 3 | 4 | // From MeshDataBehavior VAO 5 | layout (location = 0) in vec3 position; 6 | layout (location = 1) in vec3 normal; 7 | layout (location = 2) in vec2 uv; 8 | layout (location = 3) in uint materialId; 9 | layout (location = 4) in vec3 tangent; 10 | 11 | out GeometryData { 12 | vec3 position_ws; 13 | vec3 normal_ws; 14 | vec3 tangent_ws; 15 | vec2 uv; 16 | flat uint materialId; 17 | } geo; 18 | 19 | uniform mat4 modelMatrix; 20 | uniform mat4 viewModelMatrix; 21 | #include "include/uniform/camera.inc.glsl" 22 | 23 | void main() { 24 | gl_Position = projectionMatrix * viewModelMatrix * vec4(position, 1.0); 25 | geo.position_ws = (modelMatrix * vec4(position, 1.0)).xyz; 26 | geo.normal_ws = mat3(modelMatrix) * normal; 27 | geo.tangent_ws = tangent; 28 | geo.uv = vec2(uv.x, 1.-uv.y); 29 | geo.materialId = 0;//materialId; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /share/test/hzb-test-scene-camera.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliemichel/GrainViewer/2c08409dc7717f75a653f05437344f4a868835ed/share/test/hzb-test-scene-camera.bin -------------------------------------------------------------------------------- /share/test/hzb-test-scene-occlusion.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'hzb-test-scene.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material 5 | Ns 323.999994 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.450000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /share/test/hzb-test-scene-pawn.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'hzb-test-scene.blend' 2 | # Material Count: 1 3 | 4 | newmtl None 5 | Ns 500 6 | Ka 0.8 0.8 0.8 7 | Kd 0.8 0.8 0.8 8 | Ks 0.8 0.8 0.8 9 | d 1 10 | illum 2 11 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of GrainViewer, the reference implementation of: 2 | # 3 | # Michel, Élie and Boubekeur, Tamy (2020). 4 | # Real Time Multiscale Rendering of Dense Dynamic Stackings, 5 | # Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 6 | # https://doi.org/10.1111/cgf.14135 7 | # 8 | # Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 9 | # 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy 11 | # of this software and associated documentation files (the “Software”), to 12 | # deal in the Software without restriction, including without limitation the 13 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 14 | # sell copies of the Software, and to permit persons to whom the Software is 15 | # furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included in 18 | # all copies or substantial portions of the Software. 19 | # 20 | # The Software is provided “as is”, without warranty of any kind, express or 21 | # implied, including but not limited to the warranties of merchantability, 22 | # fitness for a particular purpose and non-infringement. In no event shall the 23 | # authors or copyright holders be liable for any claim, damages or other 24 | # liability, whether in an action of contract, tort or otherwise, arising 25 | # from, out of or in connection with the software or the use or other dealings 26 | # in the Software. 27 | 28 | # We first include external libraries on which this project depends 29 | add_subdirectory(External) 30 | 31 | # Then we build our project 32 | add_subdirectory(GrainViewer) 33 | -------------------------------------------------------------------------------- /src/External/nanoflann/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(nanoflann) 3 | 4 | add_library(nanoflann INTERFACE) 5 | target_include_directories(nanoflann INTERFACE include) 6 | -------------------------------------------------------------------------------- /src/External/refl-cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This projects puts together two different header only libraries, namely refl-cpp and magic_enum 2 | 3 | cmake_minimum_required(VERSION 3.0) 4 | project(refl-cpp) 5 | 6 | add_library(refl-cpp INTERFACE) 7 | target_include_directories(refl-cpp INTERFACE include) 8 | -------------------------------------------------------------------------------- /src/External/tinygltf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(tinygltf) 3 | 4 | set(SRC 5 | include/tiny_gltf.h 6 | include/json.hpp 7 | include/stb_image.h 8 | include/stb_image_write.h 9 | src/tiny_gltf.cpp 10 | ) 11 | 12 | add_library(tinygltf ${SRC}) 13 | target_include_directories(tinygltf PUBLIC include/) 14 | target_compile_definitions( 15 | tinygltf PUBLIC 16 | -DTINYGLTF_USE_CPP14 17 | ) 18 | set_property(TARGET tinygltf PROPERTY FOLDER "External") 19 | -------------------------------------------------------------------------------- /src/External/tinygltf/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Syoyo Fujita, Aurélien Chatelain and many contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/External/tinygltf/src/tiny_gltf.cpp: -------------------------------------------------------------------------------- 1 | #define TINYGLTF_IMPLEMENTATION 2 | #define STB_IMAGE_IMPLEMENTATION 3 | #define STB_IMAGE_WRITE_IMPLEMENTATION 4 | #include "tiny_gltf.h" 5 | -------------------------------------------------------------------------------- /src/GrainViewer/AnimationManager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "AnimationManager.h" 31 | 32 | void AnimationManager::addAnimation(std::function && anim) 33 | { 34 | m_anims.push_back(std::move(anim)); 35 | } 36 | 37 | void AnimationManager::clear() { 38 | m_anims.clear(); 39 | } 40 | 41 | void AnimationManager::update(float time, int frame) 42 | { 43 | for (const auto & ch : m_anims) { 44 | ch(time, frame); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/GrainViewer/AnimationManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | #include 34 | 35 | /** 36 | * Animations are callbacks called every frame 37 | */ 38 | class AnimationManager { 39 | public: 40 | void addAnimation(std::function && anim); 41 | void clear(); 42 | void update(float time, int frame); 43 | 44 | private: 45 | std::vector> m_anims; 46 | }; 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Behavior/GrainBehavior.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "GrainBehavior.h" 31 | #include "TransformBehavior.h" 32 | #include "ShaderPool.h" 33 | 34 | #include "utils/jsonutils.h" 35 | #include "utils/behaviorutils.h" 36 | 37 | bool GrainBehavior::deserialize(const rapidjson::Value & json) 38 | { 39 | autoDeserialize(json, m_properties); 40 | jrArray(json, "atlases", m_atlases); 41 | return true; 42 | } 43 | -------------------------------------------------------------------------------- /src/GrainViewer/Behavior/LightGizmo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Behavior.h" 33 | #include "ShaderProgram.h" 34 | 35 | #include 36 | 37 | class ShaderProgram; 38 | class GlBuffer; 39 | 40 | /** 41 | * Renderer component used to visualize spot light frustum 42 | */ 43 | class LightGizmo : public Behavior { 44 | public: 45 | // Behavior implementation 46 | bool deserialize(const rapidjson::Value& json) override; 47 | void start() override; 48 | void render(const Camera& camera, const World& world, RenderType target) const override; 49 | 50 | private: 51 | std::string m_shaderName = "LightGizmo"; 52 | int m_lightIndex = 0; 53 | std::shared_ptr m_shader; 54 | std::unique_ptr m_vertexBuffer; 55 | GLuint m_vao; 56 | }; 57 | 58 | registerBehaviorType(LightGizmo) 59 | 60 | -------------------------------------------------------------------------------- /src/GrainViewer/Behavior/QuadMeshData.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "QuadMeshData.h" 31 | 32 | #include "utils/behaviorutils.h" 33 | 34 | void QuadMeshData::start() 35 | { 36 | m_vbo = std::make_unique(GL_ARRAY_BUFFER); 37 | m_vbo->importBlock(std::vector{ 38 | { 0, 0 }, 39 | { 1, 0 }, 40 | { 0, 1 }, 41 | { 1, 1 } 42 | }); 43 | m_vbo->addBlockAttribute(0, 2); // uv 44 | 45 | glCreateVertexArrays(1, &m_vao); 46 | glBindVertexArray(m_vao); 47 | m_vbo->bind(); 48 | m_vbo->enableAttributes(m_vao); 49 | glBindVertexArray(0); 50 | 51 | m_vbo->finalize(); 52 | } 53 | 54 | void QuadMeshData::onDestroy() 55 | { 56 | glDeleteVertexArrays(1, &m_vao); 57 | } 58 | 59 | void QuadMeshData::draw() const 60 | { 61 | glBindVertexArray(m_vao); 62 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 63 | } 64 | -------------------------------------------------------------------------------- /src/GrainViewer/Behavior/QuadMeshData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | #include "Behavior.h" 34 | #include "GlBuffer.h" 35 | #include 36 | #include 37 | 38 | /** 39 | * Simple mesh data behavior containing just a quad, used e.g. for post effects 40 | */ 41 | class QuadMeshData : public Behavior { 42 | public: 43 | // Behavior implementation 44 | void start() override; 45 | void onDestroy() override; 46 | 47 | void draw() const; 48 | 49 | private: 50 | std::unique_ptr m_vbo; 51 | GLuint m_vao = 0; 52 | }; 53 | 54 | registerBehaviorType(QuadMeshData) 55 | -------------------------------------------------------------------------------- /src/GrainViewer/BehaviorRegistry.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Behavior/PointCloudSplitter.h" // for RenderModel 33 | 34 | #include 35 | #include 36 | 37 | class Behavior; 38 | class RuntimeObject; 39 | class IPointCloudData; 40 | 41 | class BehaviorRegistry { 42 | public: 43 | /** 44 | * Add a behavior to a RuntimeObject shared pointer 45 | * TODO: Find a way to avoid this function 46 | */ 47 | static void addBehavior( 48 | std::shared_ptr & b, 49 | std::shared_ptr & obj, 50 | const std::string & type 51 | ); 52 | 53 | /** 54 | * TODO: Our component system does not play along well with inheritance, hence 55 | * this registry that emulates something that would ideally be like 56 | * getComponent() 57 | */ 58 | static std::weak_ptr getPointCloudDataComponent( 59 | Behavior& behavior, 60 | PointCloudSplitter::RenderModel preferedModel = PointCloudSplitter::RenderModel::None); 61 | }; 62 | -------------------------------------------------------------------------------- /src/GrainViewer/BehaviorRegistryEntry.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | template 33 | struct BehaviorRegistryEntry { 34 | static const char* Name() { return "object"; } 35 | }; 36 | 37 | #define registerBehaviorType(T) \ 38 | registerSerializationType(T) \ 39 | template<> struct BehaviorRegistryEntry { \ 40 | static const char *Name() { return #T; } \ 41 | }; 42 | -------------------------------------------------------------------------------- /src/GrainViewer/EnvironmentVariables.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "EnvironmentVariables.h" 31 | 32 | #include 33 | 34 | EnvironmentVariables & EnvironmentVariables::GetInstance() noexcept 35 | { 36 | static EnvironmentVariables s_instance; 37 | return s_instance; 38 | } 39 | 40 | std::string EnvironmentVariables::eval(const std::string value) const 41 | { 42 | return std::regex_replace(value, std::regex("\\$BASEFILE"), baseFile); 43 | } 44 | -------------------------------------------------------------------------------- /src/GrainViewer/EnvironmentVariables.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | /** 35 | * Environement variables are used for substitution of patterns like $BASEFILE in scene files 36 | * They are not os' env variables, rather a local definition of it. 37 | * TODO: This name might be misleading, rename into sth else than "environment"? 38 | * (This is a singleton class) 39 | */ 40 | struct EnvironmentVariables { 41 | public: 42 | // static API 43 | static EnvironmentVariables& GetInstance() noexcept; 44 | static std::string Eval(const std::string value) { return GetInstance().eval(value); } 45 | 46 | EnvironmentVariables& operator=(const EnvironmentVariables&) = delete; 47 | EnvironmentVariables(const EnvironmentVariables&) = delete; 48 | 49 | private: 50 | EnvironmentVariables() {} 51 | std::string eval(const std::string value) const; 52 | 53 | public: 54 | std::string baseFile; 55 | }; 56 | -------------------------------------------------------------------------------- /src/GrainViewer/Framebuffer2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | class GlTexture; 35 | 36 | /** 37 | * New version of Framebuffer, but teh latter is used in so many places that as 38 | * a transitional solution it is better to have two versions at the same time. 39 | */ 40 | class Framebuffer2 { 41 | public: 42 | Framebuffer2(); 43 | ~Framebuffer2(); 44 | Framebuffer2(Framebuffer2&) = delete; 45 | Framebuffer2& operator=(Framebuffer2&) = delete; 46 | Framebuffer2(Framebuffer2&&) = default; 47 | Framebuffer2& operator=(Framebuffer2&&) = default; 48 | 49 | void bind() const; 50 | bool check() const; 51 | GLuint raw() const { return m_raw; } 52 | void attachTexture(int attachment, const GlTexture & texture, GLint level); 53 | void attachDepthTexture(const GlTexture& texture, GLint level); 54 | 55 | // Enables drawing to attachements 0, 1, ..., n - 1 56 | void enableDrawBuffers(int n); 57 | 58 | private: 59 | GLuint m_raw; 60 | }; 61 | 62 | -------------------------------------------------------------------------------- /src/GrainViewer/IPointCloudData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | #include "GlBuffer.h" 34 | #include 35 | 36 | /** 37 | * Interface common to all behaviors that can be used as point clouds by point-based renderers 38 | */ 39 | class IPointCloudData { 40 | public: 41 | virtual GLsizei pointCount() const = 0; 42 | virtual GLsizei frameCount() const = 0; 43 | virtual GLuint vao() const = 0; 44 | virtual const GlBuffer& vbo() const = 0; 45 | virtual std::shared_ptr ebo() const { return nullptr; } // if null, then regular array is used as element buffer 46 | virtual GLint pointOffset() const { return 0; } // offset in the ebo 47 | }; 48 | -------------------------------------------------------------------------------- /src/GrainViewer/Logger.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | class Logger { 37 | public: 38 | enum Level 39 | { 40 | LDEBUG, 41 | LVERBOSE, 42 | LINFO, 43 | LWARNING, 44 | LERROR 45 | }; 46 | 47 | public: 48 | Logger(const char *func, const char *file, int line, enum Level level = LINFO); 49 | ~Logger(); 50 | 51 | inline std::ostream &stream() { return m_ss; } 52 | 53 | private: 54 | static void align(std::stringstream &ss); 55 | static void init(); 56 | 57 | private: 58 | std::ostringstream m_ss; 59 | 60 | private: 61 | static size_t align_width; 62 | }; 63 | 64 | #define DEBUG_LOG Logger(__func__, __FILE__, __LINE__, Logger::LDEBUG).stream() 65 | #define LOG Logger(__func__, __FILE__, __LINE__, Logger::LINFO).stream() 66 | #define WARN_LOG Logger(__func__, __FILE__, __LINE__, Logger::LWARNING).stream() 67 | #define ERR_LOG Logger(__func__, __FILE__, __LINE__, Logger::LERROR).stream() 68 | 69 | -------------------------------------------------------------------------------- /src/GrainViewer/Mesh.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Triangle.h" 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | /** 40 | * Simple wrapper around TinyObj loading routines 41 | */ 42 | class Mesh { 43 | public: 44 | Mesh(const std::string & filename); 45 | std::vector triangles() const; 46 | std::vector diffuseTextures() const; 47 | std::vector bumpTextures() const; 48 | 49 | inline tinyobj::attrib_t attrib() const { return m_attrib; } 50 | inline std::vector shapes() const { return m_shapes; } 51 | inline std::vector materials() const { return m_materials; } 52 | 53 | inline const std::string baseDir() const { return m_baseDir; } 54 | 55 | private: 56 | std::string m_baseDir; 57 | tinyobj::attrib_t m_attrib; 58 | std::vector m_shapes; 59 | std::vector m_materials; 60 | }; 61 | -------------------------------------------------------------------------------- /src/GrainViewer/OpenGL: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | // Always make this file the first include 33 | 34 | #ifdef _WIN32 35 | #include // Avoid issue with APIENTRY redefinition in Glad 36 | #endif // _WIN32 37 | 38 | // If you have trouble with modern glad, just switch to normal glad here 39 | //#include 40 | #include // Adds warning about obsolete non-DSA functions 41 | -------------------------------------------------------------------------------- /src/GrainViewer/PostEffect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | #include 34 | 35 | /** 36 | * A large quad covering the whole screen 37 | */ 38 | class PostEffect 39 | { 40 | public: 41 | // Use static instance 42 | static void Draw(bool disableDepthTest = true); 43 | static void DrawInstanced(int n); 44 | static void DrawWithDepthTest() { Draw(false); } 45 | 46 | public: 47 | PostEffect(); 48 | ~PostEffect(); 49 | void draw(bool disableDepthTest = true, int instances = 1); 50 | 51 | private: 52 | GLuint m_vao; 53 | GLuint m_vbo; 54 | 55 | private: 56 | static std::unique_ptr s_instance; 57 | }; 58 | -------------------------------------------------------------------------------- /src/GrainViewer/RenderType.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | /** 33 | * Context provided to the render() function of objects 34 | */ 35 | enum class RenderType 36 | { 37 | /** 38 | * Direct rendering, without deferred shading 39 | */ 40 | Direct, 41 | 42 | /** 43 | * Default render type (deferred shading) 44 | */ 45 | Default, 46 | 47 | /** 48 | * Shadow map rendering, only depth matters 49 | */ 50 | ShadowMap, 51 | }; 52 | -------------------------------------------------------------------------------- /src/GrainViewer/RuntimeObject.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "IBehaviorHolder.h" 33 | #include "Camera.h" 34 | #include "World.h" 35 | #include "RenderType.h" 36 | #include "ViewLayerMask.h" 37 | 38 | #include 39 | #include 40 | 41 | /** 42 | * Objects of a scene. Such objects are mostly defined by the behaviors 43 | * attached to them; they delegate all the methods to the behaviors. 44 | */ 45 | class RuntimeObject : public IBehaviorHolder { 46 | public: 47 | RuntimeObject(); 48 | 49 | void start(); 50 | void reloadShaders(); 51 | void update(float time, int frame); 52 | void render(const Camera & camera, const World & world, RenderType target) const; 53 | void onPreRender(const Camera& camera, const World& world, RenderType target); 54 | void onPostRender(float time, int frame); 55 | 56 | bool deserialize(const rapidjson::Value& json); 57 | 58 | std::string name; 59 | ViewLayerMask viewLayers; 60 | }; 61 | -------------------------------------------------------------------------------- /src/GrainViewer/SerializationType.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | template 33 | struct SerializationType { 34 | static const char* Name() { return "object"; } 35 | }; 36 | 37 | #define registerSerializationType(T) \ 38 | template<> struct SerializationType { static const char* Name() { return #T; } }; 39 | 40 | registerSerializationType(int) 41 | registerSerializationType(float) 42 | registerSerializationType(std::string) 43 | -------------------------------------------------------------------------------- /src/GrainViewer/ShadowMap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Framebuffer.h" 33 | #include "Camera.h" 34 | 35 | #include 36 | 37 | #include 38 | 39 | // TODO: use the new Framebuffer2 class, and have the fbo be a member rather 40 | // than inheriting from it 41 | // TODO: handle directional lights (only handling point light at the moment) 42 | class ShadowMap : public Framebuffer { 43 | public: 44 | ShadowMap( 45 | const glm::vec3 & lightPosition, 46 | const glm::vec3 & lightLookAt = glm::vec3(0.0), 47 | size_t size = 1024, 48 | const std::vector & colorLayerInfos = {} 49 | ); 50 | 51 | void setLookAt(const glm::vec3 & position, const glm::vec3 & lookAt); 52 | void setProjection(float fov, float nearDistance, float farDistance); 53 | 54 | const Camera & camera() const { return m_camera; } 55 | 56 | private: 57 | void updateProjectionMatrix(); 58 | 59 | private: 60 | Camera m_camera; 61 | float m_fov = 35.0f; 62 | float m_near = 0.1f; 63 | float m_far = 20.f; 64 | }; 65 | 66 | -------------------------------------------------------------------------------- /src/GrainViewer/StandardMaterial.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | #include "GlTexture.h" 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | class ShaderProgram; 43 | 44 | /** 45 | * A material is a set of attributes that can be used by rendering behaviors. 46 | */ 47 | struct StandardMaterial 48 | { 49 | glm::vec3 baseColor = glm::vec3(1.0f, 0.5f, 0.0f); 50 | GLfloat metallic = 0.0f; 51 | GLfloat roughness = 0.5f; 52 | std::unique_ptr baseColorMap; 53 | std::unique_ptr normalMap; 54 | std::unique_ptr metallicRoughnessMap; 55 | std::unique_ptr metallicMap; 56 | std::unique_ptr roughnessMap; 57 | 58 | bool deserialize(const rapidjson::Value& json); 59 | void fromTinyObj(const tinyobj::material_t & mat, const std::string& textureRoot); 60 | // return the next available texture unit 61 | GLuint setUniforms(const ShaderProgram& shader, const std::string & prefix, GLuint nextTextureUnit) const; 62 | }; 63 | -------------------------------------------------------------------------------- /src/GrainViewer/Tools/filterPointToPointDistance.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | bool filterPointToPointDistance(const std::string & inputFilename, const std::string & outputFilename); 35 | 36 | -------------------------------------------------------------------------------- /src/GrainViewer/TurntableCamera.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Camera.h" 33 | 34 | #include 35 | 36 | class TurntableCamera : public Camera { 37 | public: 38 | TurntableCamera(); 39 | 40 | void update(float time) override {} 41 | 42 | void deserialize(const rapidjson::Value& json, const EnvironmentVariables& env, std::shared_ptr animations) override; 43 | std::ostream& serialize(std::ostream& out) override; 44 | 45 | protected: 46 | void updateDeltaMouseRotation(float x1, float y1, float x2, float y2) override; 47 | void updateDeltaMouseZoom(float x1, float y1, float x2, float y2) override; 48 | void updateDeltaMousePanning(float x1, float y1, float x2, float y2) override; 49 | void tilt(float theta); 50 | 51 | private: 52 | /** 53 | * Construct view matrix given quat, center and zoom 54 | */ 55 | void updateViewMatrix(); 56 | 57 | private: 58 | glm::vec3 m_center; 59 | glm::quat m_quat; 60 | float m_zoom; 61 | float m_sensitivity; // relative to screen size 62 | float m_zoomSensitivity; 63 | }; 64 | 65 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/DeferredShadingDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "GlDeferredShader.h" 34 | 35 | #include 36 | 37 | class DeferredShadingDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void drawHandles(float x, float y, float w, float h) override; 41 | void setController(std::weak_ptr shading) { m_cont = shading; } 42 | 43 | private: 44 | std::weak_ptr m_cont; 45 | }; 46 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/FarGrainRendererDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "FarGrainRendererDialog.h" 31 | #include "utils/guiutils.h" 32 | #include "utils/behaviorutils.h" 33 | 34 | #include 35 | 36 | void FarGrainRendererDialog::draw() 37 | { 38 | if (auto cont = m_cont.lock()) { 39 | if (ImGui::CollapsingHeader("FarGrainRenderer", ImGuiTreeNodeFlags_DefaultOpen)) { 40 | bool enabled = cont->isEnabled(); 41 | ImGui::Checkbox("Enabled", &enabled); 42 | cont->setEnabled(enabled); 43 | 44 | BeginDisable(!enabled); 45 | autoUi(cont->properties()); 46 | EndDisable(!enabled); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/FarGrainRendererDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "Behavior/FarGrainRenderer.h" 34 | 35 | #include 36 | 37 | class FarGrainRendererDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(FarGrainRendererDialog, FarGrainRenderer) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/GlobalTimerDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "GlobalTimer.h" 34 | 35 | #include 36 | 37 | class GlobalTimerDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setController(std::weak_ptr timer) { m_cont = timer; } 41 | void drawHandles(float x, float y, float w, float h); 42 | 43 | private: 44 | std::weak_ptr m_cont; 45 | }; 46 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/GrainBehaviorDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "GrainBehaviorDialog.h" 31 | #include "utils/guiutils.h" 32 | #include "utils/behaviorutils.h" 33 | #include 34 | 35 | void GrainBehaviorDialog::draw() 36 | { 37 | if (auto cont = m_cont.lock()) { 38 | if (ImGui::CollapsingHeader("GrainBehavior", ImGuiTreeNodeFlags_DefaultOpen)) { 39 | bool enabled = cont->isEnabled(); 40 | ImGui::Checkbox("Enabled", &enabled); 41 | cont->setEnabled(enabled); 42 | 43 | BeginDisable(!enabled); 44 | autoUi(cont->properties()); 45 | EndDisable(!enabled); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/GrainBehaviorDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Behavior/GrainBehavior.h" 33 | #include "Dialog.h" 34 | 35 | #include 36 | 37 | class GrainBehaviorDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(GrainBehaviorDialog, GrainBehavior) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/ImpostorGrainRendererDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "ImpostorGrainRendererDialog.h" 31 | #include "utils/guiutils.h" 32 | #include "utils/behaviorutils.h" 33 | #include 34 | 35 | void ImpostorGrainRendererDialog::draw() 36 | { 37 | if (auto cont = m_cont.lock()) { 38 | if (ImGui::CollapsingHeader("ImpostorGrainRenderer", ImGuiTreeNodeFlags_DefaultOpen)) { 39 | bool enabled = cont->isEnabled(); 40 | ImGui::Checkbox("Enabled", &enabled); 41 | cont->setEnabled(enabled); 42 | 43 | BeginDisable(!enabled); 44 | autoUi(cont->properties()); 45 | EndDisable(!enabled); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/ImpostorGrainRendererDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Behavior/ImpostorGrainRenderer.h" 33 | #include "Dialog.h" 34 | 35 | #include 36 | 37 | class ImpostorGrainRendererDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(ImpostorGrainRendererDialog, ImpostorGrainRenderer) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/InstanceGrainRendererDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "InstanceGrainRendererDialog.h" 31 | #include "utils/guiutils.h" 32 | #include "utils/behaviorutils.h" 33 | #include 34 | 35 | void InstanceGrainRendererDialog::draw() 36 | { 37 | if (auto cont = m_cont.lock()) { 38 | if (ImGui::CollapsingHeader("InstanceGrainRenderer", ImGuiTreeNodeFlags_DefaultOpen)) { 39 | bool enabled = cont->isEnabled(); 40 | ImGui::Checkbox("Enabled", &enabled); 41 | cont->setEnabled(enabled); 42 | 43 | BeginDisable(!enabled); 44 | autoUi(cont->properties()); 45 | EndDisable(!enabled); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/InstanceGrainRendererDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Behavior/InstanceGrainRenderer.h" 33 | #include "Dialog.h" 34 | 35 | #include 36 | 37 | class InstanceGrainRendererDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(InstanceGrainRendererDialog, InstanceGrainRenderer) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/LightGizmoDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "LightGizmoDialog.h" 31 | 32 | #include "utils/guiutils.h" 33 | 34 | #include 35 | 36 | void LightGizmoDialog::draw() 37 | { 38 | if (auto cont = m_cont.lock()) { 39 | if (ImGui::CollapsingHeader("Light Gizmo", ImGuiTreeNodeFlags_DefaultOpen)) { 40 | bool enabled = cont->isEnabled(); 41 | ImGui::Checkbox("Enabled", &enabled); 42 | cont->setEnabled(enabled); 43 | 44 | //BeginDisable(!enabled); 45 | //EndDisable(!enabled); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/LightGizmoDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "Behavior/LightGizmo.h" 34 | 35 | #include 36 | 37 | class LightGizmoDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(LightGizmoDialog, LightGizmo) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/MeshRendererDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "MeshRendererDialog.h" 31 | #include "utils/guiutils.h" 32 | #include "utils/behaviorutils.h" 33 | #include 34 | 35 | void MeshRendererDialog::draw() 36 | { 37 | if (auto cont = m_cont.lock()) { 38 | if (ImGui::CollapsingHeader("MeshRenderer", ImGuiTreeNodeFlags_DefaultOpen)) { 39 | bool enabled = cont->isEnabled(); 40 | ImGui::Checkbox("Enabled", &enabled); 41 | cont->setEnabled(enabled); 42 | 43 | BeginDisable(!enabled); 44 | autoUi(cont->properties()); 45 | EndDisable(!enabled); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/MeshRendererDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Behavior/MeshRenderer.h" 33 | #include "Dialog.h" 34 | 35 | #include 36 | 37 | class MeshRendererDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(MeshRendererDialog, MeshRenderer) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/PointCloudSplitterDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "PointCloudSplitterDialog.h" 31 | #include "utils/guiutils.h" 32 | #include "utils/behaviorutils.h" 33 | #include "utils/strutils.h" 34 | 35 | #include 36 | 37 | void PointCloudSplitterDialog::draw() 38 | { 39 | if (auto cont = m_cont.lock()) { 40 | if (ImGui::CollapsingHeader("PointCloudSplitter", ImGuiTreeNodeFlags_DefaultOpen)) { 41 | bool enabled = cont->isEnabled(); 42 | ImGui::Checkbox("Enabled", &enabled); 43 | cont->setEnabled(enabled); 44 | 45 | BeginDisable(!enabled); 46 | autoUi(cont->properties()); 47 | EndDisable(!enabled); 48 | 49 | ImGui::Text("\nInfo"); 50 | constexpr auto names = magic_enum::enum_names(); 51 | const auto& counters = cont->counters(); 52 | for (int i = 0; i < counters.size(); ++i) { 53 | ImGui::Text(MAKE_STR(" - " << names[i] << ": " << counters[i].count << "(@" << counters[i].offset << ")").c_str()); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/PointCloudSplitterDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "Behavior/PointCloudSplitter.h" 34 | 35 | #include 36 | 37 | class PointCloudSplitterDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(PointCloudSplitterDialog, PointCloudSplitter) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/QuadMeshDataDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "QuadMeshDataDialog.h" 31 | #include "utils/guiutils.h" 32 | #include "utils/behaviorutils.h" 33 | #include 34 | 35 | void QuadMeshDataDialog::draw() 36 | { 37 | if (auto cont = m_cont.lock()) { 38 | if (ImGui::CollapsingHeader("QuadMeshData", ImGuiTreeNodeFlags_DefaultOpen)) { 39 | bool enabled = cont->isEnabled(); 40 | ImGui::Checkbox("Enabled", &enabled); 41 | cont->setEnabled(enabled); 42 | 43 | BeginDisable(!enabled); 44 | // 45 | EndDisable(!enabled); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/QuadMeshDataDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Behavior/QuadMeshData.h" 33 | #include "Dialog.h" 34 | 35 | #include 36 | 37 | class QuadMeshDataDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(QuadMeshDataDialog, QuadMeshData) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/SceneDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "SceneDialog.h" 31 | #include "Light.h" 32 | #include "utils/guiutils.h" 33 | #include "utils/behaviorutils.h" 34 | 35 | #include 36 | #include 37 | 38 | void SceneDialog::draw() 39 | { 40 | if (auto cont = m_cont.lock()) { 41 | if (ImGui::CollapsingHeader("Scene", ImGuiTreeNodeFlags_DefaultOpen)) { 42 | if (ImGui::Button("Take Screenshot")) { 43 | cont->takeScreenshot(); 44 | } 45 | 46 | if (cont->isPaused()) { 47 | if (ImGui::Button("Play")) { 48 | cont->play(); 49 | } 50 | } 51 | else { 52 | if (ImGui::Button("Pause")) { 53 | cont->pause(); 54 | } 55 | } 56 | 57 | autoUi(cont->properties()); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/SceneDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "Scene.h" 34 | 35 | #include 36 | 37 | class SceneDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setController(std::weak_ptr scene) { m_cont = scene; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/TestGui.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | class Window; 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | /** 39 | * Gui for tests, displaying a progress bar and some debug info 40 | */ 41 | class TestGui { 42 | public: 43 | TestGui(std::shared_ptr window); 44 | ~TestGui(); 45 | 46 | void updateProgress(float progress); 47 | void addMessage(const std::string & msg); 48 | 49 | void render(); 50 | 51 | // event callbacks 52 | void onResize(int width, int height); 53 | void onMouseButton(int button, int action, int mods); 54 | void onKey(int key, int scancode, int action, int mods); 55 | void onCursorPosition(double x, double y); 56 | 57 | private: 58 | void setupCallbacks(); 59 | 60 | private: 61 | std::weak_ptr m_window; 62 | 63 | float m_windowWidth; 64 | float m_windowHeight; 65 | 66 | float m_progress = 0; 67 | std::vector m_messages; 68 | 69 | bool m_isMouseMoveStarted; 70 | }; 71 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/TransformDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "TransformDialog.h" 31 | #include "utils/guiutils.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | void TransformDialog::draw() 38 | { 39 | if (auto cont = m_cont.lock()) { 40 | if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) { 41 | // Post Transform 42 | glm::mat4 postTransform = cont->postTransform(); 43 | glm::vec3 translate = postTransform[3]; 44 | ImGui::SliderFloat3("Post Translate", glm::value_ptr(translate), -1.0f, 1.0f, "%.5f"); 45 | for (int k = 0 ; k < 3 ; ++k) postTransform[3][k] = translate[k]; 46 | cont->setPostTransform(postTransform); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/TransformDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "Behavior/TransformBehavior.h" 34 | 35 | #include 36 | 37 | class TransformDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setControlledBehavior(std::weak_ptr behavior) { m_cont = behavior; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | 46 | registerDialogForBehavior(TransformDialog, TransformBehavior) 47 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/Widgets.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "Widgets.h" 31 | #include "imgui.h" 32 | #include "imgui_internal.h" 33 | 34 | bool ProgressBar(const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col) { 35 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 36 | if (window->SkipItems) 37 | return false; 38 | 39 | ImGuiContext& g = *GImGui; 40 | const ImGuiStyle& style = g.Style; 41 | const ImGuiID id = window->GetID(label); 42 | 43 | ImVec2 pos = window->DC.CursorPos; 44 | ImVec2 size = size_arg; 45 | size.x -= style.FramePadding.x * 2; 46 | 47 | const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y)); 48 | ImGui::ItemSize(bb, style.FramePadding.y); 49 | if (!ImGui::ItemAdd(bb, id)) 50 | return false; 51 | 52 | // Render 53 | window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + size.x, bb.Max.y), bg_col); 54 | window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + size.x * value, bb.Max.y), fg_col); 55 | return true; 56 | } 57 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/Widgets.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | /** 35 | * A set of extra ImGui widgets 36 | */ 37 | bool ProgressBar(const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col); 38 | 39 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/Window.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | struct GLFWwindow; 33 | 34 | /** 35 | * Simple wrapper around GLFWwindow 36 | * also creating an OpenGL 4.5 context using glad 37 | */ 38 | class Window { 39 | public: 40 | Window(int width, int height, const char *title); 41 | ~Window(); 42 | 43 | /** 44 | * @return the raw GLFWwindow object, or nullptr if initialization failed. 45 | */ 46 | GLFWwindow *glfw() const; 47 | 48 | /** 49 | * @return true iff window has correctly been initialized 50 | */ 51 | bool isValid() const; 52 | 53 | void pollEvents() const; 54 | void swapBuffers() const; 55 | bool shouldClose() const; 56 | 57 | private: 58 | GLFWwindow *m_window = nullptr; 59 | }; 60 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/WorldDialog.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "WorldDialog.h" 31 | #include "utils/guiutils.h" 32 | 33 | #include 34 | 35 | void WorldDialog::draw() 36 | { 37 | if (auto cont = m_cont.lock()) { 38 | if (ImGui::CollapsingHeader("World", ImGuiTreeNodeFlags_DefaultOpen)) { 39 | // World 40 | bool shadowMaps = cont->isShadowMapEnabled(); 41 | ImGui::Checkbox("Shadow Maps (global toggle)", &shadowMaps); 42 | cont->setShadowMapEnabled(shadowMaps); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/GrainViewer/Ui/WorldDialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include "Dialog.h" 33 | #include "World.h" 34 | 35 | #include 36 | 37 | class WorldDialog : public Dialog { 38 | public: 39 | void draw() override; 40 | void setController(std::weak_ptr world) { m_cont = world; } 41 | 42 | private: 43 | std::weak_ptr m_cont; 44 | }; 45 | -------------------------------------------------------------------------------- /src/GrainViewer/ViewLayerMask.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "ViewLayerMask.h" 31 | #include "utils/jsonutils.h" 32 | 33 | bool ViewLayerMask::deserialize(const rapidjson::Value& json) 34 | { 35 | if (!json.IsString()) return false; 36 | 37 | std::string maskStr = json.GetString(); 38 | m_mask = 0; 39 | uint64_t bit = 1; 40 | for (const char& c : maskStr) { 41 | if (c == '1') { 42 | m_mask |= bit; 43 | } 44 | bit = bit << 1; 45 | } 46 | 47 | return true; 48 | } 49 | 50 | bool ViewLayerMask::operator&(const ViewLayerMask& other) const 51 | { 52 | return (other.m_mask & m_mask) != 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/GrainViewer/ViewLayerMask.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | class ViewLayerMask { 35 | public: 36 | bool deserialize(const rapidjson::Value& json); 37 | uint64_t raw() const { return m_mask; } 38 | bool operator&(const ViewLayerMask& other) const; 39 | 40 | private: 41 | uint64_t m_mask = -1; // -1 puts all bits to 1, meaning "visible on all layers" 42 | }; 43 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/ReflectionAttributes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | /** 35 | * Custom attributes for introspection tags (see refl.cpp's doc) 36 | */ 37 | namespace ReflectionAttributes { 38 | 39 | struct HideInDialog : refl::attr::usage::member { 40 | constexpr HideInDialog() { } 41 | }; 42 | 43 | struct Range : refl::attr::usage::member { 44 | const float minimum; 45 | const float maximum; 46 | constexpr Range(const float minimum, const float maximum) 47 | : minimum(minimum), maximum(maximum) 48 | {} 49 | }; 50 | 51 | } // ReflectionAttributes 52 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/ScopedFramebufferOverride.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | /** 35 | * Restore framebuffer bindings upon destruction 36 | */ 37 | class ScopedFramebufferOverride { 38 | public: 39 | ScopedFramebufferOverride() { 40 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &m_drawFboId); 41 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &m_readFboId); 42 | } 43 | ~ScopedFramebufferOverride() { 44 | restore(); 45 | } 46 | void restore() { 47 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_drawFboId); 48 | glBindFramebuffer(GL_READ_FRAMEBUFFER, m_readFboId); 49 | } 50 | 51 | private: 52 | GLint m_drawFboId = 0; 53 | GLint m_readFboId = 0; 54 | }; 55 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/behaviorutils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "behaviorutils.h" 31 | 32 | std::string toDisplayName(const std::string& name) { 33 | std::vector chars; 34 | chars.reserve(name.size()); 35 | for (char c : name) { 36 | if (chars.size() == 0) { 37 | chars.push_back(std::toupper(c)); 38 | } 39 | else if (std::isupper(c)) { 40 | chars.push_back(' '); 41 | chars.push_back(c); 42 | } 43 | else { 44 | chars.push_back(c); 45 | } 46 | } 47 | return std::string(chars.begin(), chars.end()); 48 | } 49 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | #ifdef _WIN32 35 | #include 36 | #else 37 | #define APIENTRY 38 | #endif 39 | 40 | /** 41 | * Setup the opengl debug callback 42 | */ 43 | void enableGlDebug(); 44 | 45 | /** 46 | * Callback to use with glDebugMessageCallback 47 | * credits: https://blog.nobel-joergensen.com/2013/02/17/debugging-opengl-part-2-using-gldebugmessagecallback/ 48 | */ 49 | void APIENTRY openglCallbackFunction(GLenum source, 50 | GLenum type, 51 | GLuint id, 52 | GLenum severity, 53 | GLsizei length, 54 | const GLchar* message, 55 | const void* userParam); 56 | 57 | #ifdef GLAD_DEBUG 58 | /** 59 | * logs every gl call to the console 60 | */ 61 | void openglPreFunction(const char *name, void *funcptr, int len_args, ...); 62 | #endif 63 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/guiutils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "guiutils.h" 31 | 32 | #include 33 | #include 34 | 35 | void BeginDisable(bool disable) { 36 | if (disable) { 37 | ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); 38 | ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); 39 | } 40 | } 41 | 42 | void EndDisable(bool disable) { 43 | if (disable) { 44 | ImGui::PopItemFlag(); 45 | ImGui::PopStyleVar(); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/guiutils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | // Some extensions to imgui 33 | 34 | void BeginDisable(bool disable); 35 | void EndDisable(bool disable); 36 | 37 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/impostor.glsl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | // (almost) mutant code replicated from impostor.inc.glsl 35 | // comments are in the cpp 36 | 37 | namespace glsl { 38 | using namespace glm; 39 | 40 | mat4 InverseBakingViewMatrix(uint i, uint n); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/mathutils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | // Assuming x > 0 33 | int ilog2(int x); 34 | 35 | float djerf(float x); 36 | float djerfinv(float u); 37 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/shader.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #include "shader.h" 31 | 32 | #include 33 | 34 | bool checkShader(GLuint shader, const char *name) { 35 | int ok; 36 | 37 | glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); 38 | if (!ok) { 39 | int len; 40 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len); 41 | char *log = new char[len]; 42 | glGetShaderInfoLog(shader, len, &len, log); 43 | std::cerr 44 | << "Unable to compile " << name << ". OpenGL returned:" << std::endl 45 | << log << std::endl << std::endl; 46 | delete[] log; 47 | } 48 | 49 | return ok; 50 | } 51 | 52 | bool checkProgram(GLuint program) { 53 | int ok; 54 | 55 | glGetProgramiv(program, GL_LINK_STATUS, &ok); 56 | if (!ok) { 57 | int len; 58 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len); 59 | char *log = new char[len]; 60 | glGetProgramInfoLog(program, len, &len, log); 61 | std::cerr 62 | << "ERROR: Unable to link program. OpenGL returned:" << std::endl 63 | << log << std::endl << std::endl; 64 | delete[] log; 65 | } 66 | 67 | return ok; 68 | } 69 | -------------------------------------------------------------------------------- /src/GrainViewer/utils/shader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of GrainViewer, the reference implementation of: 3 | * 4 | * Michel, Élie and Boubekeur, Tamy (2020). 5 | * Real Time Multiscale Rendering of Dense Dynamic Stackings, 6 | * Computer Graphics Forum (Proc. Pacific Graphics 2020), 39: 169-179. 7 | * https://doi.org/10.1111/cgf.14135 8 | * 9 | * Copyright (c) 2017 - 2020 -- Télécom Paris (Élie Michel ) 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the “Software”), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * The Software is provided “as is”, without warranty of any kind, express or 22 | * implied, including but not limited to the warranties of merchantability, 23 | * fitness for a particular purpose and non-infringement. In no event shall the 24 | * authors or copyright holders be liable for any claim, damages or other 25 | * liability, whether in an action of contract, tort or otherwise, arising 26 | * from, out of or in connection with the software or the use or other dealings 27 | * in the Software. 28 | */ 29 | 30 | #pragma once 31 | 32 | #include 33 | 34 | /** 35 | * Check that the last shader compilation went good, and if not display the 36 | * compilation error message. 37 | */ 38 | bool checkShader(GLuint shader, const char *name); 39 | 40 | /** 41 | * Check that the last program linking went good, and if not display the 42 | * linking error message. 43 | */ 44 | bool checkProgram(GLuint program); 45 | --------------------------------------------------------------------------------