-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch showcases a screen space ambient occlusion
implementation. rework and add imgui
- Loading branch information
Showing
20 changed files
with
1,670 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/cmake-* | ||
.idea/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# | ||
# This file is part of Magnum. | ||
# | ||
# Original authors — credit is appreciated but not required: | ||
# | ||
# 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 — | ||
# Vladimír Vondruš <mosra@centrum.cz> | ||
# 2020 — Janos Meny <janos.meny@gmail.com> | ||
# | ||
# This is free and unencumbered software released into the public domain. | ||
# | ||
# Anyone is free to copy, modify, publish, use, compile, sell, or distribute | ||
# this software, either in source code form or as a compiled binary, for any | ||
# purpose, commercial or non-commercial, and by any means. | ||
# | ||
# In jurisdictions that recognize copyright laws, the author or authors of | ||
# this software dedicate any and all copyright interest in the software to | ||
# the public domain. We make this dedication for the benefit of the public | ||
# at large and to the detriment of our heirs and successors. We intend this | ||
# dedication to be an overt act of relinquishment in perpetuity of all | ||
# present and future rights to this software under copyright law. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.4) | ||
|
||
project(MagnumSSAOExample CXX) | ||
|
||
# Add module path in case this is project root | ||
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) | ||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../../modules/" ${CMAKE_MODULE_PATH}) | ||
endif() | ||
|
||
set(SSAO_EXAMPLE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
set(SSAO_EXAMPLE_INSTALL_DIR ${MAGNUM_DATA_INSTALL_DIR}/examples/ssao) | ||
|
||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/configure.h) | ||
|
||
find_package(Corrade REQUIRED Main) | ||
find_package(Magnum REQUIRED | ||
GL | ||
MeshTools | ||
Shaders | ||
SceneGraph | ||
Trade | ||
Sdl2Application | ||
DebugTools) | ||
find_package(MagnumIntegration REQUIRED ImGui) | ||
|
||
set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON) | ||
|
||
corrade_add_resource(SSAO_Rcs Shaders/resources.conf) | ||
|
||
add_executable(magnum-ssao WIN32 | ||
SsaoExample.cpp | ||
../arcball/ArcBall.cpp | ||
Shaders/DeferredGeometryShader.cpp | ||
Shaders/DeferredGeometryShader.h | ||
Shaders/SsaoShader.cpp | ||
Shaders/SsaoShader.h | ||
Shaders/SsaoApplyShader.cpp | ||
Shaders/SsaoApplyShader.h | ||
${SSAO_Rcs}) | ||
|
||
target_link_libraries(magnum-ssao PRIVATE | ||
Corrade::Main | ||
Magnum::Application | ||
Magnum::GL | ||
Magnum::Magnum | ||
Magnum::MeshTools | ||
Magnum::Trade | ||
Magnum::Shaders | ||
Magnum::DebugTools | ||
MagnumIntegration::ImGui) | ||
|
||
target_include_directories(magnum-ssao PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
install(TARGETS magnum-ssao DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) | ||
install(FILES Armadillo.ply DESTINATION ${MAGNUM_DATA_INSTALL_DIR}/examples/ssao) | ||
|
||
# Make the executable a default target to build & run in Visual Studio | ||
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT magnum-ssao) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
This file is part of Magnum. | ||
Original authors — credit is appreciated but not required: | ||
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 — | ||
Vladimír Vondruš <mosra@centrum.cz> | ||
2020 — Janos Meny <janos.meny@gmail.com> | ||
This is free and unencumbered software released into the public domain. | ||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute | ||
this software, either in source code form or as a compiled binary, for any | ||
purpose, commercial or non-commercial, and by any means. | ||
In jurisdictions that recognize copyright laws, the author or authors of | ||
this software dedicate any and all copyright interest in the software to | ||
the public domain. We make this dedication for the benefit of the public | ||
at large and to the detriment of our heirs and successors. We intend this | ||
dedication to be an overt act of relinquishment in perpetuity of all | ||
present and future rights to this software under copyright law. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
in highp vec3 viewPosition; | ||
in highp vec3 viewNormal; | ||
|
||
layout(location = 0) | ||
out highp vec4 color; | ||
layout(location = 1) | ||
out highp vec3 position; | ||
layout(location = 2) | ||
out highp vec3 normal; | ||
|
||
uniform vec4 diffuseColor; | ||
|
||
void main() { | ||
color = diffuseColor; | ||
position = viewPosition; | ||
normal = viewNormal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
This file is part of Magnum. | ||
Original authors — credit is appreciated but not required: | ||
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 — | ||
Vladimír Vondruš <mosra@centrum.cz> | ||
2020 — Janos Meny <janos.meny@gmail.com> | ||
This is free and unencumbered software released into the public domain. | ||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute | ||
this software, either in source code form or as a compiled binary, for any | ||
purpose, commercial or non-commercial, and by any means. | ||
In jurisdictions that recognize copyright laws, the author or authors of | ||
this software dedicate any and all copyright interest in the software to | ||
the public domain. We make this dedication for the benefit of the public | ||
at large and to the detriment of our heirs and successors. We intend this | ||
dedication to be an overt act of relinquishment in perpetuity of all | ||
present and future rights to this software under copyright law. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
in highp vec4 position; | ||
layout(location = 5) //@TODO get rid of layout specifier | ||
in highp vec3 normal; | ||
|
||
uniform mat4 transformation; | ||
uniform mat3 normalMatrix; | ||
uniform mat4 projection; | ||
|
||
out highp vec3 viewPosition; | ||
out highp vec3 viewNormal; | ||
|
||
void main(){ | ||
vec4 position4 = transformation*position; | ||
|
||
viewPosition = position4.xyz; | ||
viewNormal = normalMatrix*normal; | ||
|
||
gl_Position = projection*position4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
This file is part of Magnum. | ||
Original authors — credit is appreciated but not required: | ||
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 — | ||
Vladimír Vondruš <mosra@centrum.cz> | ||
2020 — Janos Meny <janos.meny@gmail.com> | ||
This is free and unencumbered software released into the public domain. | ||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute | ||
this software, either in source code form or as a compiled binary, for any | ||
purpose, commercial or non-commercial, and by any means. | ||
In jurisdictions that recognize copyright laws, the author or authors of | ||
this software dedicate any and all copyright interest in the software to | ||
the public domain. We make this dedication for the benefit of the public | ||
at large and to the detriment of our heirs and successors. We intend this | ||
dedication to be an overt act of relinquishment in perpetuity of all | ||
present and future rights to this software under copyright law. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "DeferredGeometryShader.h" | ||
|
||
#include <Corrade/Utility/Resource.h> | ||
#include <Corrade/Containers/Reference.h> | ||
|
||
#include <Magnum/GL/Shader.h> | ||
#include <Magnum/GL/Version.h> | ||
#include <Magnum/GL/Context.h> | ||
#include <Magnum/Math/Matrix4.h> | ||
#include <Magnum/Math/Matrix3.h> | ||
#include <Magnum/Math/Color.h> | ||
|
||
namespace Magnum { namespace Examples { | ||
|
||
DeferredGeometryShader::DeferredGeometryShader() { | ||
MAGNUM_ASSERT_GL_VERSION_SUPPORTED(GL::Version::GL330); | ||
|
||
const Utility::Resource rs{"ssao-data"}; | ||
|
||
GL::Shader vert{GL::Version::GL330, GL::Shader::Type::Vertex}; | ||
GL::Shader frag{GL::Version::GL330, GL::Shader::Type::Fragment}; | ||
|
||
vert.addSource(rs.get("DeferredGeometry.vert")); | ||
|
||
frag.addSource(rs.get("DeferredGeometry.frag")); | ||
|
||
CORRADE_INTERNAL_ASSERT_OUTPUT(GL::Shader::compile({vert, frag})); | ||
|
||
attachShaders({vert, frag}); | ||
|
||
CORRADE_INTERNAL_ASSERT_OUTPUT(link()); | ||
|
||
bindAttributeLocation(Position::Location, "position"); | ||
bindAttributeLocation(Normal::Location, "normal"); | ||
|
||
bindFragmentDataLocation(AlbedoOutput, "color"); | ||
bindFragmentDataLocation(PositionsOutput, "position"); | ||
bindFragmentDataLocation(NormalsOutput, "normal"); | ||
|
||
_transformationUniform = uniformLocation("transformation"); | ||
_normalMatrixUniform = uniformLocation("normalMatrix"); | ||
_projectionUniform = uniformLocation("projection"); | ||
_diffuseColorUniform = uniformLocation("diffuseColor"); | ||
} | ||
|
||
DeferredGeometryShader& DeferredGeometryShader::setTransformation(const Matrix4& transformation){ | ||
setUniform(_transformationUniform, transformation); | ||
return *this; | ||
} | ||
|
||
DeferredGeometryShader& DeferredGeometryShader::setNormalMatrix(const Matrix3x3& normalMatrix){ | ||
setUniform(_normalMatrixUniform, normalMatrix); | ||
return *this; | ||
} | ||
|
||
DeferredGeometryShader& DeferredGeometryShader::setProjection(const Matrix4& projection) { | ||
setUniform(_projectionUniform, projection); | ||
return *this; | ||
} | ||
|
||
DeferredGeometryShader& DeferredGeometryShader::setDiffuseColor(const Color4 &color) { | ||
setUniform(_diffuseColorUniform, color); | ||
return *this; | ||
} | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef Magnum_Examples_Ssao_DeferredGeometryShader_h | ||
#define Magnum_Examples_Ssao_DeferredGeometryShader_h | ||
|
||
/* | ||
This file is part of Magnum. | ||
Original authors — credit is appreciated but not required: | ||
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 — | ||
Vladimír Vondruš <mosra@centrum.cz> | ||
2020 — Janos Meny <janos.meny@gmail.com> | ||
This is free and unencumbered software released into the public domain. | ||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute | ||
this software, either in source code form or as a compiled binary, for any | ||
purpose, commercial or non-commercial, and by any means. | ||
In jurisdictions that recognize copyright laws, the author or authors of | ||
this software dedicate any and all copyright interest in the software to | ||
the public domain. We make this dedication for the benefit of the public | ||
at large and to the detriment of our heirs and successors. We intend this | ||
dedication to be an overt act of relinquishment in perpetuity of all | ||
present and future rights to this software under copyright law. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <Magnum/GL/AbstractShaderProgram.h> | ||
#include <Magnum/Shaders/Generic.h> | ||
#include <Magnum/GL/GL.h> | ||
|
||
namespace Magnum { namespace Examples { | ||
|
||
class DeferredGeometryShader : public Magnum::GL::AbstractShaderProgram { | ||
public: | ||
|
||
using Position = Magnum::Shaders::Generic3D::Position; | ||
using Normal = Magnum::Shaders::Generic3D::Normal; | ||
using TextureCoordinates = Magnum::Shaders::Generic3D::TextureCoordinates; | ||
|
||
enum { | ||
AlbedoOutput = 0, | ||
PositionsOutput = 1, | ||
NormalsOutput = 2, | ||
}; | ||
|
||
explicit DeferredGeometryShader(Magnum::NoCreateT) : Magnum::GL::AbstractShaderProgram{Magnum::NoCreate} {}; | ||
|
||
explicit DeferredGeometryShader(); | ||
|
||
DeferredGeometryShader& setTransformation(const Matrix4& transformation); | ||
|
||
DeferredGeometryShader& setNormalMatrix(const Matrix3x3& normalMatrix); | ||
|
||
DeferredGeometryShader& setProjection(const Matrix4& projection); | ||
|
||
DeferredGeometryShader& setDiffuseColor(const Color4& color); | ||
|
||
private: | ||
|
||
Int _transformationUniform, | ||
_normalMatrixUniform, | ||
_projectionUniform, | ||
_diffuseColorUniform; | ||
}; | ||
|
||
}} | ||
|
||
#endif |
Oops, something went wrong.