This topic is 3148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to draw line on the y axis from 1 to -1, but the closer it is to zero the more it will be transparent. I am able to draw a line from 1 to -1 just fine, however, when I try to make the middle (closer to 0) fade it will just fade near -1. I figure the alpha should be "float fAlpha = abs(IN.pixelOutPos.y);" because that logically makes sense to me as it will approach zero, it will have more alpha, than the more it going to -1, it will have less alpha (due to abs(pos.y)). Does anyone know what the problem may be? This image would describe what I am getting, and what I want to get (I don't know how to embed images?) http://img52.imageshack.us/img52/3619/linefail.jpg Here is my shader
float4x4 worldViewProjectionMatrix;

struct VS_INPUT
{
float3 position : POSITION;
float3 color : COLOR0;
};

struct VS_OUTPUT
{
float4 outPos : POSITION;
float3 color : COLOR0;
float3 pixelOutPos : COLOR1;
};

struct PS_INPUT
{
float3 color : COLOR0;
float3 pixelOutPos : COLOR1;
};

VS_OUTPUT VS(VS_INPUT IN)
{
VS_OUTPUT OUT;

OUT.outPos = mul(float4(IN.position, 1.0f), worldViewProjectionMatrix);
OUT.color = IN.color;
OUT.pixelOutPos = IN.position;

return OUT;
}

float4 PS(PS_INPUT IN) : COLOR
{
float fAlpha = abs(IN.pixelOutPos.y);
return float4(IN.color, fAlpha);
}

technique Test
{
pass
{
AlphaBlendEnable = true;
DestBlend = 6;
SrcBlend = 5;

}
}



##### Share on other sites
Calculating final alpha with abs(y) sounds fine for your desired goal, but only if in the pixel shader y is in the range [-1,1] (and has been interpolated properly).

Hmmmmm, I think now I see the problem. You pass along the position with a color semantic. One might think that's ok, since colors get interpolated as well. But I think since you use shader model 2 the value will be clamped to normalized color value, i.e. between 0 and 1.

Maybe it's not that, but try using a different semantic, for a start. Normally one uses TEXCOORD0 or any other tex coord.

(edit)
If that does not help, make somehow sure y is in the desired range, for instance with PIX.

##### Share on other sites
Is your input vertices position.y are in -1 and 1 ?
I mean, is your line vertices defined in local space like so p0(0,-1,0) ; p1(0,1,0) because you are outputing the untransformed position to the pixel shader if I'm not mistaken.

##### Share on other sites
It seems that because I was using COLOR0 it was clamping the values, I switched it to TEXCOORD0 and everything is not working fine.

Thank you both for the help =)

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Who's Online (See full list)

There are no registered users currently online

×