Re: Alphablending



A question more about those alpha channels, in the images. How do you set
them? i can't imagine you set them per pixel...

If you take a paint program like Photoshop or Gimp for example, you can
"paint" into the alpha channel.. there are many modes and tools to do
this, but it usually looks like grayscale. It's possible to overlay the
alpha channel so that it blends to some preset color, default in
Photoshop is red.. then you paint and so on.. this is something artists
know better.

Sometimes the alpha data is machine generated, for example, you could
model a leaf in 3d modeling software like Maya, Lightwave, 3dsmax..
then render it, the renderers usually write the translucency into alpha
channel in the rendered image. When you save the rendered image in 32
bit format, you get the translucency information stored with the color
data. Then you can use the rendered leaf as texture (with per pixel
translucency information generated by the machine). The edges usually
get translucency of 0.5, 0.75, etc.. anything between 1.0 and 0.0
making the edges smooth. :)

Just few ways.. or you might have a 100% color image, then load alpha
as a MASK. This is very useful for rendering FONTS for example: you can
have FULL COLOR fonts, and alpha is the mask what is drawn with what
intensity. So the mask can be totally separate from the actual colors..
though it's a good idea to combine the two into 32 bit before rendering
if possible (to avoid reading from many arrays simultaneously).

Is PixelShading, as done by hardware, related to this topic in some way`?

Not really, infact, in GLSL, Cg and HLSL which all are shading
languages used with Direct3D or OpenGL the alpha blending is not
defined at all in the fragment (or pixel-) shaders at all. Pixel
shaders are programs which are executed to compute the color of the
fragment, you can write pretty much anything you want and the language
is HLL.

The DirectX uses intermediate shading language which is assembler-like,
which is what is "executed" by the graphics processor. It doesn't
matter what mechanism is used for this execution, the code can be
executed as-is in state machine that reflects the language 1-to-1, or
it can be translated into something the hardware understands, that
doesn't matter, the main difference between OpenGL GLSL and HLSL (D3D's
shading language) is that HLSL is always translated to intermediate
binary/assembler and then that is loaded to the graphics driver (and
ultimately into the graphics processor).

GLSL is slightly different: the intermediate presentation is never
exposed to the client (eg. programmer, like you and me). The only input
is in form of high level shading language (GLSL ;) and the driver takes
it from there, parsing the code, generating any errors if they arise,
optimizing and generating the final microcode that is executed by the
graphics processor. :)

GLSL gives more work to the driver author, as it is much more complex
to implement all compiler from the frontend to the backend, with HLSL a
lot of work is already done so it is "easier" to someone writing the
drivers.

But to answer your question, the answer is "not really", except for
implementation details that arise from the situation. There *could* be
a dedicated alpha blending "unit" there in hardware doing the "write to
framebuffer" stage of the pipeline, it's possible. But since we have
already programmable hardware (!) it is also possible, that the alpha
blending is kind of "appended" to the client's program and the code is
generated from there. Ofcourse from details like this arise a lot of
issues what might be the best way to go about these things.. the
dedicated unit would spend "gates" (=transistors) in the chip, but on
the other hand implementing the blending with existing hardware (the
shading unit implementation) would make the driver more complicated
(and code possibly a tiny bit slower). On the other hand, it would put
the existing hardware into better use.. leaving some budget over for
using the "dedicated" gates to improve the performance in general.

It's really implementation level detail and not very interesting to
programmer's point of view.

How can I do pixel shading in software, and what is it really?

You can do it, it means that you can load a program presented in some
format to your renderer and execute it. It means the code isn't "fixed"
but rather, you use the "shader" to configure your pixel pipeline to
execute the program. The most efficient way to do this is to compile
the shader and generate native x86 binary, then call it. But this is a
lot of work. It takes years to do this kind of thing properly.


Why is Vertical slice a better primitive then Scanline? I ask because I
found my Vertical line to me much slower then the Horizontal line.

I meant trapezoid, should have been more careful with my choise of
words.. the reason is that we might not want to have the overhead of
function call per scanline, the reason for this is that number of
triangles are increasing rapidly these days so the triangles end up
being fairly tiny in number of pixels on the screen. If we have only
thousands of triangles, not tens of thousands or more, call per
scanline is all okay.


But theres several words here that I dont know what means. I can lookup
barycentric coordinates, for instance, but I just did, and the first
explanation wasnt very clear. Many thanks for your time if you like to
explain it in human terms.

Most explanations end up that way, there are some really good ones but
no URL's spring to mind. But the basic idea is that barycentric
coordinate is the weight of areas, it's easier to explain with a
schematic picture, you should find nice ones with google. :)

But it all boils down to that you can express any point within a
triangle with three coordinates. In 2D the traditional way is to
express the points in (x,y) but (x,y) can be outside of a triangle
without any ground rules. Barycentric coordinates, however, cannot. :)

Let's call them (A,B,C) the SUM of A, B and C is _always_ 1.0 when the
point is inside a triangle. Therefore, we need only two of these
coordinates (so we come back to two coordinates just like with x,y).

Example, if we know A and B, the C is (1.0 - A - B), because the SUM is
always 1.0

If we have values at vertices, let's call them a,b and c. We can solve
value at ANY point within the triangle by doing a simple scalar
product:

v = A*a + B*b + C*c;

Where (a,b,c) were the values at vertices and (A,B,C) are the current
barycentric coordinates. It's cool as that.

For instance, if we are are point (a), the barycentric coordinate would
be: (A=1.0,B=0.0,C=0.0) .. similiarly, B=1.0 means we are at vertex b,
and so on.

Interpolating barycentric coordinates goes just like anything else you
might be interpolating across the triangle. Infact, you might want to
interpolate A/w, B/w and C/w so that you are interpolating *perspective
corrected* barycentrics, then when you solve the A,B and C with 1/w at
any point in triangle you might fancy, you get perspective correction
for ALL the gradients "for free" (at the cost of keeping barycentric
perspective corrected :)

Infact, OpenGL rasterization rules, if fragment is within the triangle
or not, are based on barycentric coordinates too! This is in the OpenGL
reference manual, which is online at www.opengl.org .. these little
buggers of coordinates are a real convenience I can tell you that. I
used to work without them and things were pretty okay and smooth, not
so inefficient but when they are applied with some thinking, the
results get so much better, and more important, things are kept really
simple.. can't go much wrong when things are not unnecessarily
complicated. There is most likely even better ways about these things
and I am more than hungry to learn about them. Most likely I won't
invent them, though, but read about them sometime when someone makes
progress but all the same: cool stuff is happening, sometimes takes a
while to even learn about things that are going on all the time.

\(^_^)/

.



Relevant Pages

  • Re: Alphablending
    ... "paint" into the alpha channel.. ... Then you can use the rendered leaf as texture (with per pixel ... Its not diretcly a triangle, its a rectangle where only two sides are parallell and two are not. ... Barycentric coordinates, however, cannot. ...
    (alt.lang.asm)
  • Re: Edge hiding
    ... geometry is recieved as 3D qads that I converted to triangle pairs. ... after rendering the solid model. ... > the pixel shader. ... > For eliminating only one edge, you could try alpha ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Problem with glReadPixels and alpha value
    ... indeces this will result in an alpha value of zero (I'm working on an Intel ... say only points would be rendered, then the rendering in the back buffer ... while on ATI cards it is zero. ...
    (comp.graphics.api.opengl)
  • Re: Will video editing programs be ported to Linux?
    ... and licensing costs may be significant in some places. ... > Rendering was mentioned, but in the case studies I've read GNU/Linux ... > There are ample distributed queuing systems for GNU/Linux and Unix ... > In one case they used Alpha processors, so they had a choice of OS; ...
    (alt.linux)
  • Re: Transparent Image Copy to Clipboard Adds Blue BG
    ... alpha transparency fine. ... > a bitmap with CreateDIBSection and then pre-multiply the alpha ... > for rendering. ... > a paste of an alpha channel bitmap must be aware that the alpha ...
    (microsoft.public.dotnet.framework.drawing)