How does the interpolation in a fragment shader work when it comes to the alpha parameter?

I'm programming a shader with SharpDX, DirectX11. My idea is to interpolate 2 3d points of a segment, so that I'll have the position interpolated in between in the pixel shader. But I want to know what happens with the alpha parameter when that position is blocked by another polygon.

For instance, if alpha is 1.0 at the left end of my segment and 0.0 at the other one. What is the value of alpha in the middle, 0.5? Or does it depend on the visibility at that point (meaning it could be, for instance, 1.0 OR 0.0 depending on if that part of the segment is hidden by a poolygon?

| improve this question | | | | |

Alpha has nothing to do with the depth test. All vertex shader outputs just get interpolated across the pixels, and don't change based on per-pixel visibility. In your example, if an alpha parameter is output from the vertex shader as 0 at one end and 1 at the other end of the rectangle, it will be 0.5 in the center.

| improve this answer | | | | |

Think you're confusing some concepts there.

It also depends on which inputs you feed to your shader, because the most simple shader doesn't need any inputs at all.

The following would be a minimalistic fragment shader in GLSL, but I think it would work in HLSL as well (or with minimalistic changes):

float4 main() {
    float4 color;
    color.rgba = 1;
    return color;

This would simply set any and all pixels to plain white. You could of course set an alpha value based on the position, but that's a bit more tricky.

Your second part of the question isn't 100% clear to me: If a part of your polygon is hidden behind something else (i.e. the depth test fails), then the graphics card won't even execute your shader code for that pixel (optimization). This is also the reason why the render order is important when working with alpha transparency. You could of course disable depth testing and then adjust the pixel color based on the depth at that position (either completely transparent/hidden or based on depth etc.).

There's no general concept or solution to your question. It really depends on what you're aiming for.

| improve this answer | | | | |
  • \$\begingroup\$ Ok, maybe my question wasn't clear enough. First part: I meant I'm passing two 3D points with their position and color from a Geometry Shader, and there's a pixel shader recieving them. About the second part, I think you've solved that (the pixel shader won't execute and the polygon hiding my pixel will be rendered. My aim is to create a quad for each line segment to use a pencil-like texture. The problem is this quad will be covered by the very polygon (the original line wouldn't). So for every pixel I can't use the standard depth, so I have to check the it "on the line instead". \$\endgroup\$ – c4sh Nov 13 '13 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.