-1

This is what I'm seeing: Lines across the model

To provide some perspective for the image, the torus is behind the model. The model is transparent. Those lines appear on the model. I don't want those lines to appear.

Can someone explain what I'm seeing? I don't know what to search for. I tried:

  • Weird lines
  • Line artifacts
  • Artifacts

etc. etc. but I could find nothing relevant. I understand that my question is vague, but, if someone could name my problem, I think I can identify the problematic code!

Anish Ramaswamy
  • 2,248
  • 3
  • 25
  • 62
  • you might have either z-buffer issues or something that is connected to color banding. – Daniel Mošmondor Nov 11 '13 at 06:01
  • @DanielMošmondor, Looking into those right now. Thanks! Will post my results. – Anish Ramaswamy Nov 11 '13 at 06:03
  • @godel9, I understand. I would love to post a snippet/SSCCE, but I have no idea what is causing my problem. Anyway, in my key handler, when 'b' is pressed, I enable blending and call `glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)`. If any other key is pressed, I disable blending. – Anish Ramaswamy Nov 11 '13 at 06:06
  • @AnishRam do you only use pure blending? Why do you have there a distorted sphere at the right top? Or does this actually look like this. To your problem, it could be a problem with that you render also the back faces of your transparent objects, that could result in some of them being rendered and some not. – t.niese Nov 11 '13 at 06:15
  • @t.niese, Yeah that's supposed to be that distorted (this is some test model). Anyway, so I enabled back face culling and it fixed this problem! I'm quite confused now. Why would that change anything? Could you please explain? – Anish Ramaswamy Nov 11 '13 at 06:22

1 Answers1

1

If you render transparencies you need to keep different thing in mind. Normally you render in OpenGL with z-buffer testing and writing enabled. So if a face is rendered OpenGL looks which pixels are visible testing them against the z-buffer. If it is visible it is drawn with the blending setting and its z value is written into the z-buffer. If not it is discarded.

If you don't render your faces in the correct z-order (from back to front out of the view direction) they are rendered in the order they arrive in the pipeline.

The artifacts appear when e.g. for some areas the pixels of the back-faces are rendered before the overlaying pixels of the front-faces, and if for some areas the pixels of the front faces are rendered before the one of the back face. So for some areas of your object you have a blending of background - backface - frontface and for some areas you only have background - forntface.

I know that explanation is not accurate, but i hope you get what i mean. Otherwise feel free to ask.

t.niese
  • 32,069
  • 7
  • 56
  • 86
  • Okay! That makes sense. But, for those spheres, I just use gluSphere(). So how would I know which faces are rendered in which order? – Anish Ramaswamy Nov 11 '13 at 06:40
  • You won't know. Transparencies is one of the complicated parts in GC. There are different techniques to render transparencies [Weighted Average or Dual Depth Peeling](http://developer.download.nvidia.com/SDK/10/opengl/src/dual_depth_peeling/doc/DualDepthPeeling.pdf). Doing z-sorting is really expansive (There are approaches to solve this `Depth-Presorted Triangle Lists [Ge Chen 2012]`, but thats also not an easy task). Btw, do you use fixed function pipeline (`glBegin`, `glEnd` ..) if so you should switch over to learn how shaders work, because the fixed function pipeline is deprecated. – t.niese Nov 11 '13 at 06:51
  • Well that you won't know is not fully true. They are passed in the order `gluSphere` creates them. – t.niese Nov 11 '13 at 07:02
  • I am using shaders. Should I not be using the `glBlendFunc` with shaders? Is `glBlendFunc` also deprecated? There are so many deprecated OpenGL tutorials around, it's so hard to find non-deprecated stuff! – Anish Ramaswamy Nov 11 '13 at 07:07
  • `glBlendFunc` is not deprecated, not sure what `gluSphere` uses, because it's no part of OpenGL itself and I never used it. You can check which functions are deprecated in the reference card of OpenGL e.g. [OpenGL 4.2 API Reference Card](http://www.opengl.org/sdk/docs/reference_card/opengl42-quick-reference-card.pdf) (the blue one are deprecated). – t.niese Nov 11 '13 at 07:11
  • Thanks! This has been very useful :) – Anish Ramaswamy Nov 11 '13 at 07:14