Sign in to follow this  

get mipmaps from framebuffer

Recommended Posts

Posted (edited)

Hello!

 

In my project, I render a deferred scene to a final frame buffer. Afterwards, I do a screen-space reflection pass. I want to mix in some glossiness and specularity with the SSR, and I thought the best way would be to use the mipmaps from the final scene framebuffer.

 

However, in my shader, whenever I call textureLod( sampler, position, mip ), it always returns the color value from the main sampler, not the mipmaps no matter what the mip level is.

 

Here is the generic code I use to initialize a framebuffer:

this.fboId = glGenFramebuffers();
this.textureId = glGenTextures();
this.depthTextureId = glGenTextures();

// Initialize color texture
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
int internalFormat = highPrecision?(soloChannel?GL_R16F:GL_RGBA16F):(soloChannel?GL_R8:GL_RGBA8);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, GL_RGBA, GL_FLOAT, (java.nio.ByteBuffer)null);

// Initialize depth texture
glBindTexture(GL_TEXTURE_2D, depthTextureId);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, (java.nio.ByteBuffer)null);

// Bind FBO
glBindFramebuffer(GL_FRAMEBUFFER, fboId);

// Bind diffuse to FBO
glBindTexture(GL_TEXTURE_2D, textureId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0);
glGenerateMipmap(GL_TEXTURE_2D);

// Bind depth to FBO
glBindTexture(GL_TEXTURE_2D, depthTextureId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTextureId, 0);
glGenerateMipmap(GL_TEXTURE_2D);

Can anyone spot what I am doing wrong?

Edited by orange451

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this