|
-
Feb 11th, 2011, 07:28 AM
#1
Thread Starter
Not NoteMe
Convert If...Else to formula
I'm writing a pixel shader that will be used to draw a slider type control that has min/max and current values.
Any pixel before the current value should be full colour (original texture alpha level), anything shortly after should gradually fade away, and anything far after the current value should be fully transparent.
Currently i have this code:
Code:
if (textureCoordinate.x < SliderValue)
{
return TileColour;
}
else if(textureCoordinate.x < SliderValue + (SliderValue / 10))
{
float Proportion = (SliderValue + (SliderValue / 10) - textureCoordinate.x) / (SliderValue / 10);
return float4(TileColour.rgb, TileColour.a * Proportion);
}
else
{
return 0;
}
However, conditionals are slow on a graphics card, so i'd ideally like to get this down to a single formula.
The SliderValue is in range 0 to 1, as are texture coordinates. The TileColour variable is the original texture colour. TileColour.a is the original alpha level of the texture (range 0..1, 0 for transparent).
The first part deals with pixels before the slider value.The last part deals with pixels far after the slider value,
The middle bit deals with pixels within a range shortly after the slider value (when the slider value is low this range is small, when the slider value is high the range is high). Basically i'm defining a range that's 1 tenth the size of the current slider value. Pixels within that range i want to fade from fully oblique to fully transparent.
This code produces the effect i want, but i'd like it in a single formula if possible.
Hopefully i've explained this enough to take away any need for knowledge of pixel shaders!!
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|