Jump to content
  • Advertisement

Archived

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

Ruudje

Trouble setting up light

This topic is 5434 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
Advertisement
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
If you want to e-mail me the screenshots <enigma@navs-transition.net> I''ll add them to this thread for you.

Enigma

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!