Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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".

share|improve this answer
    
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. –  Logon Nov 7 '12 at 8:50
    
Hmm, can you describe your idea a bit more. this is starting to sound more like light volumes than gradients. –  Tordin Nov 7 '12 at 8:51
    
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. –  Logon Nov 7 '12 at 8:54
    
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? –  Tordin Nov 7 '12 at 8:56
2  
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. –  Tordin Nov 7 '12 at 9:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.