To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.cadOpen lugnet.cad in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 CAD / 14873
14872  |  14874
Subject: 
Re: White noise around model with colored background
Newsgroups: 
lugnet.cad
Date: 
Wed, 10 Oct 2007 05:40:30 GMT
Viewed: 
2728 times
  
In lugnet.cad, Don Heyse wrote:
   In lugnet.cad, Travis Cobbs wrote:

   What we need it the ability to have the blending not occur in the color channel at all when the background is fully tranparent. As far as I know, that’s not possible.

Ok, I had a little time over the weekend to spend with the Red book, and I think I may have it now. Hopefully not too late to make it into LDView version 3.0 RC 2. ;^)

So to eliminate the halo, what we want to put around the image edges of the destination buffer is the unblended source RGB colors and the antialiasing coverage values in the alpha channel. I think if you turn on antialiasing, and don’t enable blending, that’s exactly what you get. However, we only want it on the outside edges (the halo). Everywhere else we want to do the normal alpha blending to composite the antialiased lines with whatever lies behind it. This sounds like a 2 pass operation to me.

Well, it’s certainly long past LDView 3.0 RC 2, but I did finally come back to this. After spending a few hours getting nice alpha data into the image file for transparent parts, I realized that the same set of steps would probably work for the edge lines. So, I gave it a try, and sure enough, it worked. See here:

http://www.halibut.com/~tcobbs/ldraw/private/AAAlphaDemo.html

My sequence doesn’t really match your suggestions, but it uses the overall concept. Here’s what I did:

First of all, enable stencil writes (always pass) to set stencil to 2 while drawing all solid geometry. After we’ve done that, we’ll draw the lines, and then draw the transparent polygons. Do the following setup for each pass for both lines and transparency, but draw all three passes of lines, then all three passes of transparency.

Pass one setup:
  • Enable color writes; disable alpha writes; enable stencil writes
  • Enable depth test, with GL_LEQUAL as depth func.
  • Enable stencil test; set to pass when stencil value == 0, and increment the stencil value when it passes and Z passes.
  • Disable blending
  • For lines, enable line smoothing.
Pass Two setup:
  • Disable color writes; enable alpha writes.
  • Set stencil to pass when stencil value == 1, and not update the stencil value ever.
  • Disable depth test.
  • Enable blending, and use glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE_MINUS_SRC_ALPHA)
Pass Three setup:
  • Enable color writes; disable alpha writes
  • Disable stencil test
  • Enable depth test, with GL_LESS as depth func.
  • glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
The first pass sets the color buffer in spots that were previously unset (stencil is zero, so they haven’t been drawn to and still have background color), and sets the stencil to 1 to prevent multiple writes to the same pixel during this pass, and to set up a mask for the next pass. As long as the transparent polygons are drawn back to front, that means that the furthest transparent polygon color gets laid down. For lines, I should sort also, but don’t. They’re usually thin enough that it hopefully won’t be visible. Note that for the lines around the model, pretty much only the partially transparent parts that stick out during antialiasing will get written here, since we don’t write anywhere that the model has already drawn to.

The second pass essentially bumps the destination alpha up a little bit for each layer, but only in the spots that were written to in pass one. So two layers will have a higher (more opaque) alpha value than one. Note that this pass will redraw all the geometry drawn in the first pass, and that pass didn’t touch the destination alpha values. Since all we care about are the number of layers at each pixel, and we’re only writing to pixels that don’t have any non-transparent geometry, we don’t want to depth test. We also don’t need to sort, but since my transparent geometry is already sorted, it still gets drawn sorted.

The third pass does the color blending. Since the depth test is set to GL_LESS, the initial polygons drawn in pass one don’t get redrawn. There’s no stencil test, so transparent shapes that come in front of opaque shapes get drawn here.

--Travis



Message has 1 Reply:
  Re: White noise around model with colored background
 
(...) I forgot to mention, but while the above page looks very similar to the page I posted recently on a lugnet.cad.ray thread, it is different in a very important way. The image on the above page was saved out of LDView at 800x600, which is the (...) (17 years ago, 10-Oct-07, to lugnet.cad, FTX)

Message is in Reply To:
  Re: White noise around model with colored background
 
(...) Ok, I had a little time over the weekend to spend with the Red book, and I think I may have it now. Hopefully not too late to make it into LDView version 3.0 RC 2. ;^) So to eliminate the halo, what we want to put around the image edges of the (...) (19 years ago, 20-Jun-05, to lugnet.cad)

18 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR