OpenGL Pixelated area on stencil buffer

This topic is 891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So i'm trying to archive an effect where i have an area of the screen that will be lower resolution to the rest. And i just wanna ask if my thinking is right.

I have 2 FBO's, they each share the same renderBuffer, so i can use the same stencil to both. but have a different resolution on the texture i draw the scene to.

My draw loop looks somthing like this:

Attach the full resolution FBO
Clear depth and stencil.
Draw the scene in full resolution.
Draw to stencil buffer the area that will be pixelated
Attach the FBO with low res texture
Clear depth
See if the stencil is equal to 1 and if so draw to the low res texture:
state->StencilFunc(GL_EQUAL, 1, 0xFF);
Draw the scene again but this time to the low res texture.
Later i combine the 2 textures and then have a pixelated area on the screen in the shape of my stencil.

First it feels like there should be a better way to do this that does not require drawing the scene twice.

Second i don't actually know if i can use the same RenderBuffer on 2 different FBO's in the way I'm thinking.

I have implemented my solution, but it is currently not working, so i just wanna know if this way is possible, or if there is a better way to implement this since i'm quite new to OpenGL.

What I'm currently getting working is using the stencil and hiding objects that are behind it, but i'm not able to get the second part, where i'm drawing to the LowRes texture, it always come out black.

If you want to look on my code I'm happy to provide any samples needed.

Share on other sites

Since you are using a renderbuffer that I'm assuming is the size of your the larger resolution texture. Then whenever you bind the FBO with the lower resolution texture you have to change the viewport and possible scissor area to match, the area that was stenciled out.

Share on other sites

Since you are using a renderbuffer that I'm assuming is the size of your the larger resolution texture. Then whenever you bind the FBO with the lower resolution texture you have to change the viewport and possible scissor area to match, the area that was stenciled out.

Ah, that makes sense, i got the rendering to the second FBO working last night, but there was some obvious problem with what it chose to render, but it's probably as you said with the viewport, I'm going to implement that and see if it works :)

Share on other sites

So, I've been trying to get this working. I can get it working with 2 separate Renderbuffers, and the Viewport/scissor works as i expect, but when I'm trying it with the same renderbuffer for both FBO's, i cant get the viewports/scissor to get the right proportions.

Right now i have one FBO with 1920x1080 RenderBuffer, and 1920x1080 textures, and another FBO with the same RenderBuffer bound, but the textures are 480x270.

Can i make the renderbuffer (Depth+stencil) a texture instead? Will this help me solve the problem, or is it possible to do with renderbuffers, im just doing my viewports incorrectly?

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 35
• 23
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631702
• Total Posts
3001812
×