views:

233

answers:

3

I'm wondering how I could create a gradient wuth multiple stops and a direction if I'm making polygons. Right now I'm creating gradients by changing the color of the verticies but this is limiting. Is there another way to do this?

Thanks

+1  A: 

The most flexible way is probably to create a texture with the gradient you want, and then apply that to your geometry.

thekidder
But I want to be able to change the direction vector on the go so a fixed texture wouldn't cut it. (sort of like a Photoshop gradient)
Milo
You should be able to rotate your texture projection.
Xavier Ho
+2  A: 

One option you may have is to render a simple polygon with a gradient to a texture, which you then use to texture your actual polygon.

Then you can rotate the source polygon and anything textured with its image will have its gradient rotate as well, without the actual geometry changing.

Chris Cooper
This is a nice solution, I'm not sure what to do about steps though but I'll figure it out hopefully
Milo
@user146780 Haha yes, to be honest, I don't actually know how to render to a texture, but I DO know it can be done. And as you seem to agree, I think this works in theory. ;D
Chris Cooper
A: 

If you're using a shader, you can pass your vertex world positions into your vertex shader and they'll interpolate to your fragment shader, so for every fragment, you'll get where it is in world-space (of course you can use any space). Then it's just a matter of choosing whatever transfer function to change that value to a color. You can make any kind of elaborate algorithm using b-splines or whatever in your fragment shader.

voodoogiant