PDA

View Full Version : Overlapping alpha blended polygons

cub31993
10-03-2011, 01:17 AM
Hi there!

I have an issue which I don't know how to solve.
I have two overlapping polygons which are alpha blended. The problem is that the place they overlap eachother is much darker than the rest.

Is there any way to avoid it and have the same alpha even there they overlap?

Wasabi
10-03-2011, 03:07 AM
Well, the usual way color alpha-shadding is calculated is basically

FinalColor = Color1*alpha1 + (1-alpha1)*Color2*alpha2 + [other polygons] + (1-alpha1)*(1-alpha2)*BackgroundColor

This being the case, if you only have one polygon, your color values will always be lower than if there is an overlap, since you then don't have all those other additions.

ZbuffeR
10-03-2011, 04:28 AM
What is your blend func ?
Screenshot ?

cub31993
10-03-2011, 04:37 AM
It looks like this:

http://img831.imageshack.us/img831/7181/device2l.png (http://imageshack.us/photo/my-images/831/device2l.png/)

And i want it to look like this:

http://img266.imageshack.us/img266/4631/correctx.png (http://imageshack.us/photo/my-images/266/correctx.png/)

GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA this is the function i use to achieve transparency.

ZbuffeR
10-03-2011, 04:43 AM
Use the stencil buffer :
- clear to 0
- set stencil test to pass only when stencil value is 0
- set 1 on draw

cub31993
10-03-2011, 05:13 AM
How do i do that?

//Sorry but i'm completly new in OpenGL

ZbuffeR
10-05-2011, 01:09 AM
Search for opengl stencil tutorials, that should get you started.

When you ask for a stencil buffer, it will store a number for each pixel, and can test for specific values to restrict drawing to some pixels.

What you want to do is similar to :