DCEmulation

dreamcast development • homebrew software • hardware hacking • indie games • emulators • and more!
Back to main site
It is currently Sat Mar 28, 2015 8:07 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Tue Jan 13, 2015 3:16 pm 
Offline
Insane DCEmu
Insane DCEmu

Joined: Sat Sep 22, 2007 7:43 pm
Posts: 108
Location: Braga - Portugal
Good Evening.

I'm starting to implement lightning into my framework, but the light appears to move with the camera, despite the light having fixed coordinates.
This results in very odd artifacts.
Any ideas on what might be the issue?


https://bitbucket.org/jae686/vidfdc/src/c9311d72c4fe351c097717a7a232a45e0ca623bc/src/dc_render.c#cl-407

Image

Best Regards.


Top
 Profile  
 
PostPosted: Tue Jan 13, 2015 3:20 pm 
Offline
Insane DCEmu
Insane DCEmu
User avatar

Joined: Sun Apr 20, 2014 7:45 am
Posts: 126
Does glLoadIdentity before glLight fix the issue?

https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
Quote:
GL_POSITION
params contains four integer or floating-point values that specify
the position of the light in homogeneous object coordinates.
Both integer and floating-point values are mapped directly.
Neither integer nor floating-point values are clamped.

The position is transformed by the modelview matrix when
glLight is called (just as if it were a point)
,
and it is stored in eye coordinates.
If the
w
component of the position is 0,
the light is treated as a directional source.
Diffuse and specular lighting calculations take the light's direction,
but not its actual position,
into account,
and attenuation is disabled.
Otherwise,
diffuse and specular lighting calculations are based on the actual location
of the light in eye coordinates,
and attenuation is enabled.
The initial position is (0, 0, 1, 0);
thus, the initial light source is directional,
parallel to, and in the direction of the



-
z


axis.

I.e., the light's position is not absolute, but affected by the modelview matrix just like a vertex would be.

_________________
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with some small fixes): https://bitbucket.org/bogglez/lxdream


Top
 Profile  
 
PostPosted: Wed Jan 14, 2015 1:14 pm 
Offline
Insane DCEmu
Insane DCEmu

Joined: Sat Sep 22, 2007 7:43 pm
Posts: 108
Location: Braga - Portugal
Good evening.
You mean like this :

Code:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   // INIT LIGHTS
   
   glMatrixMode(GL_PROJECTION);
   glLoadMatrixf(projectionMatrix);
   glMatrixMode(GL_MODELVIEW);
   
   glLoadIdentity();

   glShadeModel(GL_SMOOTH);

   gluLookAt(c->start_pos.x, c->start_pos.y, c->start_pos.z, c->start_looking_direction.x, c->start_looking_direction.y, c->start_looking_direction.z, 0.0, 0.0, 1.0);

   glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
   glLightfv(GL_LIGHT0, GL_SPECULAR, light_color);
   
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);



It still does not appear to work..


Top
 Profile  
 
PostPosted: Wed Jan 14, 2015 1:18 pm 
Offline
DC Developer
DC Developer
User avatar

Joined: Fri Jun 18, 2010 7:29 pm
Posts: 465
What you are seeing is called "specular lighting."
Specular lighting is the reflected light off a surface, dependent upon view position.
So as the camera moves, so does the angle of reflection, hence the variance of light as you observed.

You are only setting the specular term of the light source in your code; what you really want to do there is set the diffuse term of the light source
instead of this
Code:
glLightfv(GL_LIGHT0, GL_SPECULAR, light_color);

try this
Code:
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color);


In GL, and my API, you can also set the material parameters, meaning you can simulate different surface types; a material set with a large specular term would simulate a highly reflective surface, a material set with a no specular term would simulate a non-reflective surface


Top
 Profile  
 
PostPosted: Wed Jan 14, 2015 2:07 pm 
Offline
Insane DCEmu
Insane DCEmu
User avatar

Joined: Sun Apr 20, 2014 7:45 am
Posts: 126
Jae686 wrote:
Good evening.
You mean like this :

Code:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   // INIT LIGHTS
   
   glMatrixMode(GL_PROJECTION);
   glLoadMatrixf(projectionMatrix);
   glMatrixMode(GL_MODELVIEW);
   
   glLoadIdentity();

   glShadeModel(GL_SMOOTH);

   gluLookAt(c->start_pos.x, c->start_pos.y, c->start_pos.z, c->start_looking_direction.x, c->start_looking_direction.y, c->start_looking_direction.z, 0.0, 0.0, 1.0);

   glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
   glLightfv(GL_LIGHT0, GL_SPECULAR, light_color);
   
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);



It still does not appear to work..

Imagine the light is like any other mesh. To position a mesh you would perform matrix operations, then draw the mesh, then pop the matrix stack or move somewhere else using matrix operations.

The first glLoadIdentity() reset the model view matrix to the origin of the world. gluLookAt then moves you to the position of the camera. If you now call glLightfv(GL_LIGHT0, GL_POSITION, light_pos), your light will therefore always be where the camera is.
I noticed in your code that you called glLightfv without calling any matrix code before, so you would have the same matrix as you had at the end of the previous frame.
Call glLoadIdentity, then glLightfv, then gluLookAt. The position supplied to glLightfv is then absolute.

Also check out what ph3nom said, I didn't check for that.

_________________
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with some small fixes): https://bitbucket.org/bogglez/lxdream


Top
 Profile  
 
PostPosted: Wed Jan 21, 2015 2:37 pm 
Offline
Insane DCEmu
Insane DCEmu

Joined: Sat Sep 22, 2007 7:43 pm
Posts: 108
Location: Braga - Portugal
Well, declaring the glLight before or after glLookat or the geometry declaration did not work. The only occasion were the light was fixed relative to the scene was only when I've declared the lights on initialization.

Any thoughts?


Top
 Profile  
 
PostPosted: Wed Jan 21, 2015 2:45 pm 
Offline
Insane DCEmu
Insane DCEmu
User avatar

Joined: Sun Apr 20, 2014 7:45 am
Posts: 126
Uhm, actually I don't see any matrix code in gl-light.c:171. I think params should be multiplied with the current model view matrix there? Ph3nom should know.

_________________
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with some small fixes): https://bitbucket.org/bogglez/lxdream


Top
 Profile  
 
PostPosted: Thu Jan 22, 2015 2:05 pm 
Offline
Insane DCEmu
Insane DCEmu

Joined: Sat Sep 22, 2007 7:43 pm
Posts: 108
Location: Braga - Portugal
bogglez , how would I get the light position coords transformed under the current glLib ?


Top
 Profile  
 
PostPosted: Fri Jan 23, 2015 3:30 pm 
Offline
Insane DCEmu
Insane DCEmu
User avatar

Joined: Sun Apr 20, 2014 7:45 am
Posts: 126
You would need to apply the same matrix as to the triangles' vertices. So ModelViewMatrix * lightPos. See for example gl-arrays.c:221. _glKosMatrixLoadModelView() seems to load the matrix into the matrix register, then mat_trans* will apply the matrix to a point.

I didn't check in-depth, but if this is indeed not done, then it's a bug and Ph3nom will be interested in fixing it.
For the time being you may decide to just supply a light position that you multiplied with a matrix before yourself.

_________________
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with some small fixes): https://bitbucket.org/bogglez/lxdream


Top
 Profile  
 
PostPosted: Tue Feb 03, 2015 11:41 am 
Offline
Insane DCEmu
Insane DCEmu

Joined: Sat Sep 22, 2007 7:43 pm
Posts: 108
Location: Braga - Portugal
PH3NOM, any thoughts on the issue ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group