Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on ssao #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Initial work on ssao #91

wants to merge 2 commits into from

Conversation

Janos95
Copy link

@Janos95 Janos95 commented Aug 22, 2020

This patch provides a ssao example. The computation of the occlusion factor can either be done with a fragment shader or with a compute shader. Three TODOs:

  • Add depth reconstruction.
  • Port to WebGL.
  • Write Docs.

Here is a little sneak peak
ssao

This PR is in commission for Vhite Rabbit.

@mosra mosra added this to the 2020.0b milestone Aug 22, 2020
Copy link
Owner

@mosra mosra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this will need to wait (together with #89) until September to get merged -- I'm too busy, sorry about that. Here's an initial review pass to get the ball rolling :)

If you want to save me some time, could you add a doc/ssao.dox file that:

  • is based off one of the other files (for example the arcball camera)
  • references a 800x600 screenshot image
  • lists you as an author
  • properly credits the Armadillo model
  • lists controls
  • lists all example source files

It doesn't need to be perfect, just something to get started.

This is great work, thanks a lot! 👍

Shaders::SSAOApply _ssaoApply{NoCreate};
Shaders::SSAO _ssao{NoCreate};

::Magnum::Shaders::Phong _phong{NoCreate};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly because of this I wouldn't introduce another Shaders namespace here.

I'd suggest GeometryShader, SsaoApplyShader and SsaoShader instead, and for consistency having different capitalization, SsaoExample as well. Sorry for the boring rename work and thanks in advance :)

{
const Vector2 dpiScaling = this->dpiScaling({});
Configuration conf;
conf.setTitle("Magnum SSAOApply Example")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
conf.setTitle("Magnum SSAOApply Example")
conf.setTitle("Magnum SSAO Example")

probably some find&replace gone wild? :)

std::uniform_real_distribution<float> distr(-1,1);
Containers::Array<Vector4> noise(Containers::NoInit, 16);
for (Vector4& n : noise)
n = Vector4{distr(engine),distr(engine),0,0};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That reminds me I need to merge mosra/magnum#432 as well 🙈

@@ -0,0 +1,10 @@
layout(location = 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the same license header as you have in the SSAOExample.cpp to all shaders and other cpp/h files as well?

@@ -0,0 +1,43 @@

#pragma once
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, can you use the usual include guards as elsewhere? #ifndef Magnum_Examples_<classname>_h etc

Comment on lines 50 to 51
GL::Shader vert{GL::Version::GL420, GL::Shader::Type::Vertex};
GL::Shader frag{GL::Version::GL420, GL::Shader::Type::Fragment};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GL::Shader vert{GL::Version::GL420, GL::Shader::Type::Vertex};
GL::Shader frag{GL::Version::GL420, GL::Shader::Type::Fragment};
GL::Shader vert{GL::Version::GL330, GL::Shader::Type::Vertex};
GL::Shader frag{GL::Version::GL330, GL::Shader::Type::Fragment};

I assume you wanted 330 since you're asserting for that above? :)


UnsignedInt _projectionUniform = 0;

Containers::Array<Vector3> _randomSamples;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, do we actually need to store this if it's uploaded in the constructor and never used again?

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.
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent of this license header seems off compared to other files :)

NormalUnit = 1,
AlbedoUnit = 2,
OcclusionFactorUnit = 3
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be probably defined in an unnamed namespace inside the cpp, as it's not used publicly in any way.

Same in the SSAO shader.

}

_profiler.endFrame();
_profiler.printStatistics(10);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're awesome -- I just wanted to suggest hooking up the profiler and you already did that. Can you share the numbers from it? I'm interested, especially comparing fragment and compute implementation.

Comment on lines 258 to 261
_framebuffer.attachTexture(GL::Framebuffer::BufferAttachment::Depth, _depth, 0)
.attachTexture(GL::Framebuffer::ColorAttachment{0}, _albedo, 0)
.attachTexture(GL::Framebuffer::ColorAttachment{1}, _positions, 0)
.attachTexture(GL::Framebuffer::ColorAttachment{2}, _normals, 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This together with checkStatus() would be probably better to be done in constructor, instead of in every frame?

_framebuffer.mapForDraw({
{Shaders::SSAO::AmbientOcclusionOutput, GL::Framebuffer::ColorAttachment{3}},
});
_ssao.draw(GL::Mesh{}.setCount(3));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and below) also (it's still a VAO creation + destruction every time, not sure how much effort that needs in the driver).

implementation.

rework and add imgui
@mosra mosra mentioned this pull request Sep 26, 2020
33 tasks
@Janos95 Janos95 closed this Jun 10, 2022
@mosra mosra reopened this Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants