|
------------------------------------------------------
| Constants for glass types used for blending |
| with the function STATE_polygon_set_translucent() |
| Note that these constants are only relevant when |
| hardware rendering is used. |
------------------------------------------------------
One doesnt really have to read the explanations (though it
is quite simple) , you can test the different options and
pick the one you like.
The default. The polygon will be 100% opaque.
#define DISABLE_BLENDING 0
Filter glass can be used to block rgb channels
like when looking through a cellophane paper
For example if the color of the polygon is (red==255,0,0)
Then when looking through this polygon the whole world will
be painted with red. The blending formula for DARK_FILTER_GLASS
is NEW_PIXEL=SRC*DEST (SRC is the pixel of our polygon. DEST
is the pixel in the background and NEW_PIXEL is final result.
Example: We have a room with a window. We look outside through
the window. Lets examine the rendering process
when rendering a specific pixel of the window.
The computer takes a pixel from the window
(for example 0,0,64 == dark blue == 0, 0, 0.25 in [0-1] rgb scale)
and another pixel from outside the room that is exactly on the
line connecting between the eye (camera) and the pixel of the window
for example lets say that this line hits a cloud so our second pixel
is gray (rgb== 128,128,128 == 0.5, 0.5, 0.5 in [0-1] rgb scale) now
lets calculate the final pixel that we will have on the window
according to the function NEW_PIXEL=SRC*DEST == (0,0, 0.25)*(0.5, 0.5, 0.5)
== 0*0.5, 0*0.5, 0.25*0.5= (0,0,0.125) == (0,0,32 in [0-255] scale)
== very dark blue.
This blending formula is called DARK_... because the result pixel is
darker or equal to the src pixel
#define DARK_FILTER_GLASS 0x31
The blending formula for FILTER_GLASS is NEW_PIXEL=2*SRC*DEST
This formula is usually better than DARK_FILTER_GLASS since
the result pixel is less dark.
#define FILTER_GLASS 0x33
The blending formula for OPAQUE_FILTER_GLASS is
NEW_PIXEL=SRC*SRC + SRC*DEST. It is similar to FILTER_GLASS
It is called OPAQUE_... since it is a little bit more opaque than
FILTER_GLASS
#define OPAQUE_FILTER_GLASS 0x43
Create the effect of normal glass. Here is what happens when looking through
this glass: The light from bright objects easily penetrates the window
while the light from darker objects is reflected from the glass (in this case
you get to see the bitmap of the window and not what is outside ...)
Using this type of glass you can control the level of translucency
Bright pixel in the bitmap will be totally opaque while dark pixel will
blend with the background. Make a bright bitmap if you want your window
to be more opaque. Make a dark bitmap if you want it to be more transparent.
Note this side effect, the view outside the window will always look brighter
than what it really is. This effect simulate our eye behavior. When we sit
in a dark room and we open a window we are overwhelmed by the light. Once we get outside,
we get used to it and it doesnt seem to be as bright as we felt before
Here is the blending formula for this window:
NEW_PIXEL= SRC(1-DEST)+DEST. Note that if DEST=(R,B,G) than 1-DEST is (1-R, 1-G,1-B)
when working in [0-1] scale.
#define NORMAL_GLASS 0x52
It is the only glass
that make a real blending without decreasing or increasing the light.
It is also the only one who gives a total control on the level of
transparency, from being total opaque to being total transparent.
Bright pixel in the bitmap will be totally opaque while dark pixel will
be transparent. Make a bright bitmap if you want your window
to be more opaque. Make a dark window if you want it to be more transparent.
The blending formula for this glass is
NEW_PIXEL=SRC*SRC+DEST*(1-SRC)
#define CONTROL_GLASS 0x44
Has the side effect of making the outside look brighter
It is called transparent because the glass is a little bit
more transparent than the other types.
A dark bitmap (for the window) will make a very transparent glass
a bright bitmap will make a bright blend between the window and the outside.
Here is the blending formula:
NEW_PIXEL=DEST+SRC*DEST
#define BRIGHT_TRANSPARENT_GLASS 0x32
Similar to BRIGHT_TRANSPARENT_GLASS only a little bit less transparent
Here is the blending formula:
NEW_PIXEL=DEST+SRC*SRC
#define BRIGHT_TRANSLUCENT_GLASS 0x42
similar to BRIGHT_TRANSLUCENT_GLASS only that
the glass is more opaque. This glass can also be used to block color channels
like with the filter modes (FILTER_GLASS).
Here is the blending formula:
NEW_PIXEL=SRC+SRC*DEST
#define BRIGHT_OPAQUE_GLASS 0x23
This glass is special. It has the
simple blending formula NEW_PIXEL=SRC+DEST
Usually this type of blending is used for
simulating light because of its additive characteristic
If used as a window glass then we should use a dark bitmap
otherwise we will have a very bright saturated window.
#define LIGHT_SOURCE_GLASS 0x22
This glass creates a special effect. When looking
through it, it inverts the world that we see.
The blending formula is:
NEW_PIXEL=SRC*(1-DEST).Note that if DEST=(R,B,G) than 1-DEST is (1-R, 1-G,1-B)
when working in [0-1] scale.
#define INVERSE_GLASS 0x51
one of the most useful filters
Using this filter one can control the transparency of the polygon very accurately
using the vertices alpha channel or using textures with alpha component
See STATE_point_set_alpha()
#define ALPHA_FILTER 0x56
Makes the polygon transparent as if it was glass
Above are the different types of glass.
call this function with DISABLE_BLENDING to
change to normal rendering (100% opaque)
The default is DISABLE_BLENDING
Example: STATE_polygon_set_translucent(my_poly,NORMAL_GLASS);
Note that it will only work with hardware rendering
( see STATE_3D_card_check_hardware_support())
|