Advertisement Jump to content
Sign in to follow this  

making a gradient texture

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to make a texture that fades from white to black. What's the best way to do this? I was thinking of drawing a line one pixel wide of each color, but I think there must be a better way. Please let me know if you have any ideas. Thanks

Share this post

Link to post
Share on other sites
That's the way I'm doing it now. I figured it should be easy to generate procedurely in directx, but I feel I'm missing something.

Share this post

Link to post
Share on other sites
You can used coloured vertices and then set the color of each vertex. DirectX will then interpolate between nthe vertex colors and create a gradient. This will only work for basic color gradients, though.

Share this post

Link to post
Share on other sites
For procedural generation, you have 3 options:
1) Utilize the FFP gouraud shading. As interest86 notes, this is rather limited.
2) Use texture shaders. This will provide you with more freedom.
3) Create and lock a dynamic texture, then write whatever you want.

Share this post

Link to post
Share on other sites
Two days ago I wrote a function for it:

D3DXVECTOR4 Gradient(const D3DCOLORVALUE Color1, const D3DCOLORVALUE Color2,
const int numSteps, const int Step)
if(Color1 == Color2)
return D3DXVECTOR4(Color1.a, Color1.r, Color1.g, Color1.b);
return D3DXVECTOR4(Color1.r - (((Color1.r - Color2.r) / (float)numSteps) * Step),
Color1.g - (((Color1.g - Color2.g) / (float)numSteps) * Step),
Color1.b - (((Color1.b - Color2.b) / (float)numSteps) * Step),
Color1.a - (((Color1.a - Color2.a) / (float)numSteps) * Step));

My accusations for the bad layout, but I was in a hurry.

The function returns a D3DXVECTOR4, the x member presents red channel, y = green, z = blue and the w member presents the alpha channel.

The function requires, the 2 colorsvalues (I think this is self-explainatory, if not feel free to ask), the number of steps to gradient with and the position in the line of steps.

Color1 = 0xFFFFFFFF
Color2 = 0x00FFFFFF
numSteps = 256
Step = 3

Color1 != Color2, so you can calc gradient
return = D3DXVECTOR(0xFF, 0xFF, 0xFF, 0xFC)

I hope this explains a bit. I use this function for pixel by pixel calculation, just as you suggest in the beginning.

[Edited by - Xeile on September 11, 2005 11:44:50 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!