Advertisement

OpenGL SuperBible SSAO example

Started by November 03, 2020 10:20 PM
6 comments, last by taby 4 years, 2 months ago

I have copied the SSAO code from the OpenGL SuperBible 7 repository on GitHub. The source is at: https://github.com/sjhalayka/opengl4_stlview

Has anyone played with this SSAO code before? I'm wondering how to go about using a custom background colour.

i haven't played with this code before, AND i dunno if this is what u mean….but if u look in main.h, you'll see this:

vec3 background_colour(1.0f, 1.0f, 1.0f); // <--- change here

it is used in main.cpp here:

glClearColor(background_colour.x, background_colour.y, background_colour.z, 1);

if u change those 1.0f to anything between 0.0f and 1.0f, you would have customised the background colour;

if this is not what u mean then please clarify your question ?

Until then ?

Advertisement

I'm sorry, I should have taken that code out. It makes no difference in the output.

As far as I can tell, it's related to this code in display_func():

...
const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
static const GLfloat one = 1.0f;
static const GLenum draw_buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };

glBindFramebuffer(GL_FRAMEBUFFER, render_fbo);
glEnable(GL_DEPTH_TEST);

glClearBufferfv(GL_COLOR, 0, black);
glClearBufferfv(GL_COLOR, 1, black);
glClearBufferfv(GL_DEPTH, 0, &one);
...

When I use black[] = {0.0f, 0.0f, 0.0f, 0.0f}; I get a normal background:

However, when I change black, to say, orange, I get a ghostly background. Not at all what I want:

 

When I alter the ssao.fs.glsl file to include this code, it works. I'd rather not use a hack though. ?

if(my_depth <= 1.0)
{
	color = background_colour;
	return;
}

That's a good workaround, try this as well:

call

glClearBufferfv(GL_COLOR, 0, put your orange colour here)

then in the ssao.fs.gl shader, try and use this in place of what you call the “hack”:

if (depth <= 1)
{
	 color = textureLod(sColor, P, 0);
	 return;
}

this way u don't have to feed background_color into the shader …. see if that works

Until then ?

It's strange. What you propose works quite well, thank you. However, if I read in that colour data at the beginning of the shader and try to use it at the end of the shader, it doesn't work. Like:

colour = object_level * object_color +
         mix(vec4(0.0), vec4(background_colour*ao_amount), ssao_level);

It works fine when I set the background colour as a uniform. So strange.

Advertisement

Thanks again. I ended up going with your approach, even though it does not allow me to add a colourful tinge to the AO shading. The reason I went with your approach is because it allows me to draw things like an axis, using the flat colour shader. If I use my old method it does not draw the axis, or it's covered up, or drawn in orange, none of which I wanted. LOL

This topic is closed to new replies.

Advertisement