Lighting non-textured polygons

bl0ckeduser
Posts: 5
Joined: Fri Dec 02, 2011 9:55 pm

Lighting non-textured polygons

Post by bl0ckeduser » Fri Dec 02, 2011 10:06 pm

Hello, I'm a hobbyist programmer. I'm porting a desktop 3D game written for OpenGL to libnds.
Does anyone know if libnds' GL implementation supports lighting non-textured polygons ?
I've tried to get this to work, but to no avail, so I'm tempted to suppose that it is simply not supported.
Thank you for your time.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Lighting non-textured polygons

Post by elhobbs » Sun Dec 04, 2011 8:35 pm

I believe it is supported. do you have some code that we could look at?

bl0ckeduser
Posts: 5
Joined: Fri Dec 02, 2011 9:55 pm

Re: Lighting non-textured polygons

Post by bl0ckeduser » Sun Dec 04, 2011 9:26 pm

Yes. My source code is here: http://github.com/bl0ckeduser/clown3d-DS.
The relevant part is in main.c. For reference, there is standard GL code which sucessfully lights the polygons (guarded by "#ifdef PC_TARGET").

Discostew
Posts: 103
Joined: Sun Mar 08, 2009 7:24 pm

Re: Lighting non-textured polygons

Post by Discostew » Mon Dec 05, 2011 4:21 am

Should be pretty simple. Make sure you've got lights active via glPolyFmt(), and make sure textures are disabled, either by glDisable( ) for global effect, or use glBindTexture( ) if you want textured and non-textured polygons together.

However, by doing that, you effectively lose the ability to use glColor to assign polygons an actual color, mixed with the color the lights give. I think OpenGL does this too unless I'm mistaken, but if you want the polygons to have their own color mixed with the lights, you can use textures to do this. An 8x8 texture of the particular color would do the job.

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Lighting non-textured polygons

Post by mtheall » Mon Dec 05, 2011 4:54 am

You should be able to use an 8x8 all-white texture and use glColor to set the vertex color. It would be better than a texture for each color. Plus you have the advantage of setting color by vertex instead of being limited per face.

bl0ckeduser
Posts: 5
Joined: Fri Dec 02, 2011 9:55 pm

Re: Lighting non-textured polygons

Post by bl0ckeduser » Mon Dec 05, 2011 5:02 am

Discostew wrote:However, by doing that, you effectively lose the ability to use glColor to assign polygons an actual color, mixed with the color the lights give. I think OpenGL does this too unless I'm mistaken, but if you want the polygons to have their own color mixed with the lights, you can use textures to do this. An 8x8 texture of the particular color would do the job.
With OpenGL I managed to light glColor'ed polygons.

Discostew and mtheall, the texture hacks you suggest sound like good solutions, I will be trying these.

(Sorry if my replies come in late, they must be approved by an admin before they appear).

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Lighting non-textured polygons

Post by elhobbs » Mon Dec 05, 2011 4:25 pm

as discostew pointed out, you cannot use hardware lights and glColor on the same polygon. hardware lights set the vertex color when you call glNormal - one overwrites the other.

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Lighting non-textured polygons

Post by mtheall » Mon Dec 05, 2011 7:36 pm

elhobbs wrote:as discostew pointed out, you cannot use hardware lights and glColor on the same polygon. hardware lights set the vertex color when you call glNormal - one overwrites the other.
Most definitely you can! How do I know? Because I've done it before. Granted, I haven't tried it with textures enabled, but I don't think that will make a difference. From my experience, using the Normal command does not set the vertex color; it "multiplies" the intensity of the light by some factor that involves the angle of incidence, then it multiplies the result with the vertex color, then you have a final vertex color.

The following ROM demonstrates this. Press the 'down' key until you reach "Open file..." then press 'A'. Then select one of the models and press 'A'. Of particular interest is bowserSmooth.bin. It takes advantage of normals to give the appearance of smoothness. Make sure you try out the various lights. The lights constantly move to different directions. Unfortunately, I only made them white light. I may provide an updated version with different color lights so you can see the effect it will have.

http://mtheall.com/modelviewer.nds

bl0ckeduser
Posts: 5
Joined: Fri Dec 02, 2011 9:55 pm

Re: Lighting non-textured polygons

Post by bl0ckeduser » Mon Dec 05, 2011 8:46 pm

mtheall wrote:
elhobbs wrote:as discostew pointed out, you cannot use hardware lights and glColor on the same polygon. hardware lights set the vertex color when you call glNormal - one overwrites the other.
Most definitely you can! How do I know? Because I've done it before. Granted, I haven't tried it with textures enabled, but I don't think that will make a difference. From my experience, using the Normal command does not set the vertex color; it "multiplies" the intensity of the light by some factor that involves the angle of incidence, then it multiplies the result with the vertex color, then you have a final vertex color.

The following ROM demonstrates this. Press the 'down' key until you reach "Open file..." then press 'A'. Then select one of the models and press 'A'. Of particular interest is bowserSmooth.bin. It takes advantage of normals to give the appearance of smoothness. Make sure you try out the various lights. The lights constantly move to different directions. Unfortunately, I only made them white light. I may provide an updated version with different color lights so you can see the effect it will have.

http://mtheall.com/modelviewer.nds
Nice. That's exactly what I'm trying to do. Did you do this with the white texture hack ?

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Lighting non-textured polygons

Post by mtheall » Mon Dec 05, 2011 8:51 pm

No these models are textureless (textures are not enabled). However, you should be able to do this with textures enabled with an all-white texture. I will try to convert my example to do so.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest