Sign in to follow this  
SMcNeil

Spolight and glNormal3F(..)

Recommended Posts

Hi, I'm trying to understand the glNormal3d(...) with respects to spotlighting. I have an image that is placed a the center of a 3D environment. glBegin( GL_QUADS ); glTexCoord2f( 0, 0 ); glVertex3f( -2.0, 1.0, 0.0 ); glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 1 ); glVertex3f( -2.0, -1.0, 0.0 ); glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 1, 1 ); glVertex3f( 2.0, -1.0, 0.0 ); glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 1, 0 ); glVertex3f( 2.0, 1.0, 0.0 ); glNormal3f( 0.00, 0.00, 1.00 ); glEnd(); I have the spotlight moving from the left to the right pointing at the center of the picture. Once this sence is done, I move onto another scene. The efect of this technique is to give the illusion that small portions of the image (text) is being illuminated. I am unclear as to how one picks the proper values for the glNormal3f(...), (if indeed this is the problem.) I am unclear if this is a lighting problem or the way light is being 'reflected' (hense glNormal3f(..)). How do I go about picking the proper vaules to get the right effect? Thanks for the help, Sabrina

Share this post


Link to post
Share on other sites
the proper value for glnormal3f is the vertex-normal... im not sure what the problem is ... (to find the normal, cross-product the two vectors leadin to the point..)

Share this post


Link to post
Share on other sites
Lighting in opengl is per vertex. Thus if you one have a handful of polygons (or one as appears to be the case for you) you will not see the effect you expect. Either tesselate your geometry or use some sort of per pixel lighting. For a light accross text effect you might be best off with a very simple lightmap.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The light is calculated per vertex and then interpolated, if you want a spotlight effect you will need to split the quad into many smaller ones(or use a shader to get per-pixel lighting).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ehm??
glTexCoord2f( 0, 0 ); glVertex3f( -2.0, 1.0, 0.0 ); glNormal3f( 0.00, 0.00, 1.00 );

i think first use glNormal before glVertex. et.
glTexCoord2f( 0, 0 ); glNormal3f( 0.00, 0.00, 1.00 );glVertex3f( -2.0, 1.0, 0.0 );

in your case normal for first vertex is undefined . nad for proper normal cross product 2 vectros of quad leading to point.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
ehm??
glTexCoord2f( 0, 0 ); glVertex3f( -2.0, 1.0, 0.0 ); glNormal3f( 0.00, 0.00, 1.00 );

i think first use glNormal before glVertex. et.
glTexCoord2f( 0, 0 ); glNormal3f( 0.00, 0.00, 1.00 );glVertex3f( -2.0, 1.0, 0.0 );

in your case normal for first vertex is undefined . nad for proper normal cross product 2 vectros of quad leading to point.
The default normal is well defined, and it is (0,0,1), so in his/her (Sabrina - I guess her) case she wouldn't notice anything wrong (unless of course she is changing it again somewhere later in the frame and rendering again). It's true that a vertex's normal must be defined before calling glVertex however.

To the OP, I recommend reading thoroughly the Lighting Chapter of the Red Book if you haven't already. It explains exactly what normals are and how they work with the lighting equations.

Share this post


Link to post
Share on other sites


Opps, Yes the code is
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 0 ); glVertex3f( -2.0, 1.0, 0.0 );

I posted via copy and past in the wrong order.

As far as per-pixel lighting recommendation, I've been goggling this subject as well. I'm not finding much success on 'How to' tutorials, or even some basic introduction into the subject. To be sure I'm on the right track as far as researching the subject, does this take advantage of the extensions, i.e. "GLee" libraries?

Sabrina.

Share this post


Link to post
Share on other sites

Hi,

First, sorry what I am about to do (copy and past some code).
I want a light source to start from the left side of the screen and move to the right side of the screen, while the Y and Z axis remain fixed. The effect that I am looking for is to have the light illuminate the center of the picture.

I have been poring over documents, tutorials, and books, but I am not seeing what I might be doing wrong.

I have been tweaking material and lighting values to no end, and still I am not getting good lighting. Nate Robins has a good tutorial on this subject, but I am not seeing what I am doing wrong with respects to his settings.

I'd appreciate another set of eyes and have someone look at the code below.

Thank you.

Sabrina.



bool SomeClass::Initialize( void )
{
SomePic.LoadImage(_T("Pic.tga") );

glCullFace(GL_BACK);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );

glShadeModel(GL_SMOOTH);
glEnable( GL_BLEND );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

Reset();

Light.SetCutOff(90.00f);
Light.SetSpotExponent(30.00f);

Material.SetAmbient( 0.50, 0.50, 0.50, 1.00 );
Material.SetDiffuse( 0.50, 0.50, 0.50, 1.00 );
Material.SetSpecular( 0.33, 0.33, 0.33, 1.00 );
Material.SetEmissive( 0.00, 0.00, 0.00, 0.00 );
Material.SetShininess(100.00f);


Camera.SetUp( 0.00f, 0.00f, 7.00f, 0.00f, 0.00f, 0.00f, 0.00f, 1.00f, 0.00f );
return ( true );
}


void SomeClass::Reset( void )
{
LightMovmentX = -5.00f ;

Light.SetPosition( LightMovmentX, 0.00f, 1.00f, 1.00f );
Light.SetDirection( 0.00f, 0.06f, -1.00f );
Light.SetAmbient( 0.00f, 0.00f, 0.00f, 1.00f );
Light.SetDiffuse( 0.50f, 0.50f, 0.50f, 1.00f );
Light.SetSpecular( 0.50f, 0.50f, 0.50f, 1.00f );
Light.SetAttenuation( 1.00f, 0.00f, 0.00f );
Light.EnableLighting( true );
}



void SomeClass::OnRender( const float fTick )
{
Camera.Update( .001f );
LightMovmentX = LightMovmentX + 0.050;
Light.SetPosition( LightMovmentX, 0.06, 4.00f, 1.00f );
Light.BindLight();

Material.BindMaterial();
DrawBackground();
}

Share this post


Link to post
Share on other sites
Don't worry about posting some code along with your question, it makes it easier to see what might be wrong. Just use the source tags in the future, it makes it much easier to read. See the FAQ for the tags you can use.

From what I'm assuming those functions are doing, your code looks alright. What exactly is wrong with the lighting? Could you post a screenshot? What does your DrawBackground function look like? Are you drawing just one quad? I think that may be the problem but we can't be sure without a little more information.

Drawing just one big quad is a problem because standard lighting is done per-vertex. So if light is only hitting the center of the quad but not the corners (where the vertices are) it will appear as though no light is hitting it at all. You will need to tesselate the quad more to fix it, assuming that is indeed your problem.

Share this post


Link to post
Share on other sites

Thought I had the tags in after reading the FAQ for posting, I got them now.

Thanks for taking a look at the code, its often heplful to have a second pair of eyes. Anyway, I have a screen shot of whats going on here The screen shots in question are at the bottom of the page.

Nate Robins has a good tutorial on the subject of lighting, I've been looking at his example closley and I'm stumped as to why my lighting is not working the way I have hoped for. You did mention "...tesselate the quad...", this is somewhat new to me (I had to google the term). From what I am understanding is that I would need more vertices/quads, right? If indeed this is necessary after reviewing the code below, could you provide some code or link so I have a better idea of what I need to do?

Thanks again,

Sabrina



// Just draw our picture (tga) to the background.
void SomeClass::DrawBackground( void )
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

EngineLogo.Bind();
glBegin( GL_QUADS );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 0 ); glVertex3f( -1.0, 0.50, 0.0 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 1 ); glVertex3f( -1.0, -0.50, 0.0 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 1, 1 ); glVertex3f( 1.0, -0.50, 0.0 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 1, 0 ); glVertex3f( 1.0, 0.50, 0.0 );
glEnd();
EngineLogo.UnBind();
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by SMcNeil
...
Thanks for taking a look at the code, its often heplful to have a second pair of eyes. Anyway, I have a screen shot of whats going on here The screen shots in question are at the bottom of the page.
...
You're welcome and... ouch! BMPs are not very bandwidth friendly, I don't mind though 'cause I'm at work right now. [grin] From those screenshots it definitely looks like the single quad is the problem you're having.
Quote:
Original post by SMcNeil
...
You did mention "...tesselate the quad...", this is somewhat new to me (I had to google the term). From what I am understanding is that I would need more vertices/quads, right?
...
That's correct. You want to subdivide your quad so that it contains more vertices. I'm not sure if this is schoolwork or not but I'll err on the side of caution and just briefly explain it. The code itself is pretty simple. It also helps to work it out on paper

Sorry for the ASCII art...
    ^
|
y |-------+
| |
| |
| |
+------------>
0 x
That's what you have right now. What you want is something like this...
    ^
|
y |-------+
| | |
y/2 |---+---|
| | |
+------------>
0 x/2 x
You will most likely want more than just one subdivision but if you write it properly you should just have to change a couple variables for the number of subdivisions on the x- and y-axes. And remember the texture coordinates will need to be subdivided similarly.

[Edited by - Kalidor on May 26, 2006 3:33:41 PM]

Share this post


Link to post
Share on other sites
Hi,

Yea, BMP's are bad, I should know better :) I have a avi file here now up now demostraiting the effect I'm getting. No this is not homework (thank god!)

I had that same idea of make smaller quads as denostrated by your example. At first I was not sure what "tesselate" ment, but lucky I was ahead of myself.(?) I did play around with sub-dividing the larger quad into progressively smaller quads. I also was going to sub-divide each of those quads into smaller quads. I did not see any diffrene between having one quad and having quads within a sub-quads (confused?) I dont think I saw a diffreance with sub-divions of quads verus having only one quad. (now I'm confused, hehe) Here's what I did. ( sorry more code )


// I draw a quad for the pic and "past" it to the quad.
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 0 ); glVertex3f( -1.00, 0.50, 0.00 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 1 ); glVertex3f( -1.00, -0.50, 0.00 );
glNormal3f( 0.00, 0.00, 1.00 ) glTexCoord2f( 1, 1 ); glVertex3f( 1.00, -0.50, 0.00 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 1, 0 ); glVertex3f( 1.00, 0.50, 0.00 );

// Here I draw a smaller quad inside the larger one above. (this quad is 1/2 the size)
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 0 ); glVertex3f( -0.50, 0.25, 0.00 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 0, 1 ); glVertex3f( -0.50, -0.25, 0.00 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 1, 1 ); glVertex3f( 0.50, -0.25, 0.00 );
glNormal3f( 0.00, 0.00, 1.00 ); glTexCoord2f( 1, 0 ); glVertex3f( 0.50, 0.25, 0.00 );




Advice?


Thanks again.

Sabrina.

Share this post


Link to post
Share on other sites
Sorry for the delay...
Quote:
Original post by SMcNeil
Yea, BMP's are bad, I should know better :) I have a avi file here now up now demostraiting the effect I'm getting.
We're having some network trouble here (don't worry, it's not from your BMPs [grin]) so I'll check the video later if this doesn't help.

Okay, it does seem like you are a little confused about what I meant by subdividing the quad. What I mean is that instead of drawing your one larger quad you draw 4 quads that are each 1/4th the size of the original such that they take up the same area on the screen. So one quad for the top-left quarter of the original, one for the bottom-left quarter, etc.

Instead of having your one quad like this...
glVertex3f(-1.0,  0.5, 0.0);
glVertex3f(-1.0, -0.5, 0.0 );
glVertex3f( 1.0, -0.5, 0.0 );
glVertex3f( 1.0, 0.5, 0.0 );
...you would have 4 like this...
glVertex3f(-1.0,  0.5, 0.0);
glVertex3f(-1.0, 0.0, 0.0);
glVertex3f( 0.0, 0.0, 0.0);
glVertex3f( 0.0, 0.5, 0.0);

glVertex3f(-1.0, 0.0, 0.0);
glVertex3f(-1.0, -0.5, 0.0);
glVertex3f( 0.0, -0.5, 0.0);
glVertex3f( 0.0, 0.0, 0.0);

glVertex3f( 0.0, 0.0, 0.0);
glVertex3f( 0.0, -0.5, 0.0);
glVertex3f( 1.0, -0.5, 0.0);
glVertex3f( 1.0, 0.0, 0.0);

glVertex3f( 0.0, 0.5, 0.0);
glVertex3f( 0.0, 0.0, 0.0);
glVertex3f( 1.0, 0.0, 0.0);
glVertex3f( 1.0, 0.5, 0.0);


That basically adds an extra vertex to the center of the original quad so you will get some lighting when the spotlight shines only on the center. It probably won't look very good though so you will have to tesselate it more for better quality lighting.

You can write a nested for-loop with variables that control the width, height, and the number of segments to create on the x- and y-axes. If you need any help with that feel free to PM me.

[Edited by - Kalidor on May 30, 2006 1:06:08 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this