Archived

This topic is now archived and is closed to further replies.

Trouble setting up light

This topic is 5127 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

Hey all, im trying to recreate a pointlight i have in my modelling program, but dont quite get the right results... the way i want my light: x: 2.050 y: 0.006 z: 1.130 hue: 32.8 saturation: 0.615 intensity: 2 falloff. dist: 0 Ive tried the following, but it doesnt get me where I want to go float lightPosition[] = { 2.05f, 0.006f, 1.13f, 1.0f }; float lightDiffuse[] = { 1.0f, 0.5f, 0.0f, 0 }; glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); Can any1 help me?

Share this post


Link to post
Share on other sites
I''m assuming your trying to create a spotlight, not just an ambient type of light(you have no ambient color for your light...)?

here is what i did to create a specific spotlight:
float ambience[4] = {1,0,0,1};
float position[4] = {0,1,1,1};

glLightfv(GL_LIGHT1, GL_AMBIENT, ambience);
glLightfv(GL_LIGHT1, GL_DIFFUSE, ambience);

glLightfv(GL_LIGHT1, GL_POSITION, position);

position[0] = 0;
position[1] = 1;
position[2] = -1;

glLightfv( GL_LIGHT1, GL_SPOT_DIRECTION, position);
glLighti( GL_LIGHT1, GL_SPOT_EXPONENT,10);
glLighti( GL_LIGHT1, GL_SPOT_CUTOFF, 50);

glLightf( GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.52);
glLightf( GL_LIGHT1, GL_LINEAR_ATTENUATION, 0);
glLightf( GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0);

glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);

attenuation deals with how far the light travels before dissapating to "noise". The exponent and cutoff deal with the angle the light projects and some intensity, and spot direction tells the light where it should be pointing.

hope that helps somewhat

Share this post


Link to post
Share on other sites
actually i need a pointlight... thats different isnt it? and no, i havent set up any ambient lighting yet, cuz i will probably not use it at all, but am not sure yet

Share this post


Link to post
Share on other sites
Where abouts in your code do you make your glLightfv calls? Are you in modelview mode with an identity matrix? What is actually wrong with your light? Is it just in the wrong position or does it not light things as expected? Any chance we could see screenshots of what you want and what you''re getting? Can I use any more question marks in this post?

Enigma

Share this post


Link to post
Share on other sites
i cant put up screens anywhere but what i''d like is to change e.g. the range and the brightness of the spotlight. I get it positioned almost right, but not entirely, but in the 3D editor i have one that is brighter than the 1.0f in opengl

Share this post


Link to post
Share on other sites
that would be great check your mail.

screen1 shows what it currently looks like in my program
screen2 shows what im trying to create, but is captured from the 3D program. (oh and just in case anyone wants to post it: I know an opengl light cant get that lensflare but thats not the issue here either)

Share this post


Link to post
Share on other sites
OK, now that I can see what you''re aiming for:

I''m guessing falloff. dist means that the light doesn''t attenuate, so leave the light with:
constant attenuation: 1
linear attenuation: 0
quadratic attenuation: 0

You need to either implement per-pixel lighting or tesselate your tabletop to get decent lighting on that.

To increase the brightness beyond the 1.0f allowed by OpenGL try either multiple lights sources or a vertex program which scales up the light contribution.

The very bright region on the table is due to the reflection and will be very difficult to emulate. If you really want this effect I would try one of:
a spotlight directed from the light source to the table
a fragment program to calculate reflected light

hope this helps,

Enigma

Share this post


Link to post
Share on other sites
the multiple lights is a good idea!

the main part of the table, not yet seen in the current image is subdivided so itll get smoother. it will also have a reflecion when im done... not sure yet how im gonna do the lightreflection

in the end im not going to use the flare you see here, but an actual flame, with a transparent quad over it to simulate the streaks from the flare a candleflame produces. those will be mirrored anyway.

did anyone notice the fsaa? :D

Share this post


Link to post
Share on other sites
quote:
Original post by Enigma
The very bright region on the table is due to the reflection and will be very difficult to emulate.


Sorry, must have been having a really dumb moment while posting that - specular lighting will probably help!

Enigma

[edited by - Enigma on December 1, 2003 6:09:09 PM]

Share this post


Link to post
Share on other sites
I was really missing the obvious solutions, wasn''t I! Instead of using multiple lights you can scale a lights contribution by changing the constant attenuation. For a light of brightness equivalent to 2.0f, use a light brightness of 1.0f and a constant attenuation of 0.5f.

Enigma

Share this post


Link to post
Share on other sites