-1

I have a simple outline effect based on this post (with slight modifications mainly to the shader - I force render the outline above everything so that I can see it through other objects using gl_FragDepth (I know that it worsens performance, but that isn't a big issue since the outlined object is only drawn once per frame)) and it works perfectly. Now my issue is in the use of another texture - why? because I'm already rendering to a frame buffer which should have sufficient color attachments that I can use instead of the texture you and save a bunch of frame time that way working, but not performant version:

GLbyte* map = new GLbyte[width * height * 4];

glReadBuffer(GL_COLOR_ATTACHMENT0);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, map);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, txrid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, map);
delete[] map;

this produces the result I wanted (along with an occluded example):

enter image description here enter image description here

And my attempt at using the FBO's attachment texture looks like this:

glBindTexture(GL_TEXTURE_2D, fbo->GetTheNeededTexture);

but this results in this mess:

enter image description here

I do realize that the issue is caused by the red channel of my texture being lower than 0.01 (see the shader from the post above), but I wasn't able to fix it (I've tried switching the texture formats, but to no avail). for anyone interested my FBO is based off of Cherno's FBO.

Note: I'm aware that the stencil buffer exists, but my attempts at implementing an outline with it were not successful since the outline width was dependent on how far my camera was from the object (fixable, but still an annoying issue), and , more importantly whenever my object got occluded by another object I could see the outline, but I could also see the occluded part of the object, which is unsatisfactory for my use case.

I'm sorry for my English, I'm not a native speaker. If you have any issues with my question or need more info please message me.

Thanks in advance.

Goubermouche
  • 13
  • 2
  • 5

0 Answers0