I am trying to think of a way to generate a gradient like this picture:

a radial gradient

Something like this GetGradientTexture(360f,100(width),100(height)), or if i want a directional light (like a flashlight) 180f,10,200.

But I can't really think of a good way to do this. Does anyone have anything that can push me in the right direction?


To do that circular type of gradient you can just take the length from the "Point" by doing. this code gives you a straight gradient.

vec1 = [ 1, 1, 1 ]; // this is your start point.
vec2 = [ 2, 2, 2 ]; // this is your endpoint.
vec3 = vec1 - vec2;
grad = sqrt(dot(vec3,vec3));

and if you want to other ways of gradient, you most of the time only calculate lengths.

And a directional light is not like a flashlight, or well, not meant to be use like that. A Spotlight is more like a flashlight. (With a light cone, and falloff ) The directional lighte is more like a "Global sun light".

| improve this answer | |
  • \$\begingroup\$ Yes spotlight is more the word i was talking about it. It is going to be used for windows of houses so it cannot be circular. \$\endgroup\$ – Logon Nov 7 '12 at 8:50
  • \$\begingroup\$ Hmm, can you describe your idea a bit more. this is starting to sound more like light volumes than gradients. \$\endgroup\$ – Tordin Nov 7 '12 at 8:51
  • \$\begingroup\$ The lighting i need to use is just Draw the world then draw a lighting layer by using gradients to let light through. Some places i need circle gradients white -> Blank sometimes i need a triangle-ish, check the picture to see what i mean. \$\endgroup\$ – Logon Nov 7 '12 at 8:54
  • \$\begingroup\$ i saw the picture, it´s just a cirkular gradient. this dosent tell me much about what you ACTUALY are trying to do. are you trying to calulate lights for your level in realtime? or do you try to bakeout the lights? \$\endgroup\$ – Tordin Nov 7 '12 at 8:56
  • 2
    \$\begingroup\$ yes, now i understad :) well, that is a bit complicated, you need to render the light volume to a texture, that you can reuse. but it would save you more time to do them in photoshop, and from there, scale and rotate them acording to what you want ingame. Otherwise, Read on how to calculate light. that will probably give you a better startingpoint. \$\endgroup\$ – Tordin Nov 7 '12 at 9:27

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.