 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
rasmus
Joined: 21 Jul 2004 Posts: 17 Location: Göteborg, Sweden
|
Posted: Fri Jul 15, 2005 3:05 am Post subject: Lighting with GU, specular and diffuse? |
|
|
First of all, big thanks to chip for the outstanding work on libGU.
I've been experimenting a bit with lighting, but I can't seem to get a light to be specular and diffuse at the same time. Is it possible?
Basically, this code gives nice diffuse lighting:
| Code: |
ScePspFVector3 lpos = { 5, 0, -20 };
sceGuEnable(GU_STATE_LIGHTING);
sceGuEnable(GU_STATE_LIGHT0);
sceGuLight(0, 0, 0, &lpos);
sceGuLightColor(0, 2, 0xffffff);
|
and this code gives a specular highlight (but no diffuse shading at all)
| Code: |
ScePspFVector3 lpos = { 5, 0, -20 };
sceGuEnable(GU_STATE_LIGHTING);
sceGuEnable(GU_STATE_LIGHT0);
sceGuLight(0, 0, 8, &lpos);
sceGuLightColor(0, 2, 0xffffff);
sceGuSpecular(12.0f);
|
Does anyone know if there is a way to make a diffuse+specular lighting model?
Cheers,
Rasmus |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Fri Jul 15, 2005 5:29 am Post subject: Re: Lighting with GU, specular and diffuse? |
|
|
| rasmus wrote: | First of all, big thanks to chip for the outstanding work on libGU.
I've been experimenting a bit with lighting, but I can't seem to get a light to be specular and diffuse at the same time. Is it possible?
Basically, this code gives nice diffuse lighting:
| Code: |
ScePspFVector3 lpos = { 5, 0, -20 };
sceGuEnable(GU_STATE_LIGHTING);
sceGuEnable(GU_STATE_LIGHT0);
sceGuLight(0, 0, 0, &lpos);
sceGuLightColor(0, 2, 0xffffff);
|
and this code gives a specular highlight (but no diffuse shading at all)
| Code: |
ScePspFVector3 lpos = { 5, 0, -20 };
sceGuEnable(GU_STATE_LIGHTING);
sceGuEnable(GU_STATE_LIGHT0);
sceGuLight(0, 0, 8, &lpos);
sceGuLightColor(0, 2, 0xffffff);
sceGuSpecular(12.0f);
|
Does anyone know if there is a way to make a diffuse+specular lighting model?
Cheers,
Rasmus |
If you look at the source for sceGuLightColor(), you'll notice that passing 1, 2 or 4 sets the different components for a light, and then index 3 & 6 are used to set two components to the same value using just one call... Perhaps you should experiment with the following:
| Code: |
sceGuSendCommandi(0x8f,0xffffff);
sceGuSendCommandi(0x90,0xffffff);
sceGuSendCommandi(0x91,0xffffff);
|
Those would set all color components for light 0 two pure white. Then I would tamper with register 0x5f, which seems to be passed the kind of light used in bits 8-11. I have not spent much time with lights, but I guess I'll have to dig into it soon. :) _________________ GE Dominator |
|
| Back to top |
|
 |
rasmus
Joined: 21 Jul 2004 Posts: 17 Location: Göteborg, Sweden
|
Posted: Fri Jul 15, 2005 9:21 pm Post subject: |
|
|
I've done a bit of experimenting and here are my results:
On the light type register (0x5f on light 0) it seems bit 1 switches between specular and diffuse lighting (1 is specular, 0 is diffuse). Bit 8-9 changes the light direction somewhat, so I guess it changes point / directional / spot light or something like that. It does not affect specular/diffuse though. Bit 0 is really interesting though. It turns on some kind of component that increases when the light hit the surface near grazing angle. It is also raised to the power of sceSpecular() register. Does anyone know what this lighting model is called?
The three color components for each light source (0x8f..0x91 on light 0) are in order amibent, diffuse/specular and grazing angle color.
It seems I'm not getting any closer to a combined diffuse specular light though :( |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Sat Jul 16, 2005 12:49 am Post subject: |
|
|
| rasmus wrote: | I've done a bit of experimenting and here are my results:
On the light type register (0x5f on light 0) it seems bit 1 switches between specular and diffuse lighting (1 is specular, 0 is diffuse). Bit 8-9 changes the light direction somewhat, so I guess it changes point / directional / spot light or something like that. It does not affect specular/diffuse though. Bit 0 is really interesting though. It turns on some kind of component that increases when the light hit the surface near grazing angle. It is also raised to the power of sceSpecular() register. Does anyone know what this lighting model is called?
The three color components for each light source (0x8f..0x91 on light 0) are in order amibent, diffuse/specular and grazing angle color.
It seems I'm not getting any closer to a combined diffuse specular light though :( |
I did some experimenting of my own last night, and I've commited my results to PSPSDK. This should help you and others get lighting working. I'll commit a new sample as soon as I've cleaned it up and verified my results, but you should be able to use the new defines in pspgu to your advantage before this. Do note however that this new version of pspgu has a lot of other changes when it comes to defines, which WILL break your app, but it will be easy to fix.
There are, as you say, three different kind of lights available: directional, pointlights and spotlights.
From what I can see, you can combine lights to enable parts of the equation. Remember sceGuLightColor() and how it sets its registers? Well it turns out this is how you enable lights aswell, so for example to setup a diffuse light this:
| Code: |
ScePspFVector3 lpos = { 5, 0, -20 };
sceGuEnable(GU_LIGHTING);
sceGuEnable(GU_LIGHT0);
sceGuLight(0, GU_DIRECTIONAL, GU_DIFFUSE, &lpos);
sceGuLightColor(0, GU_DIFFUSE, 0xffffff);
|
To get diffuse AND specular, you can do this:
| Code: |
ScePspFVector3 lpos = { 5, 0, -20 };
sceGuEnable(GU_LIGHTING);
sceGuEnable(GU_LIGHT0);
sceGuLight(0, GU_DIRECTIONAL, GU_DIFFUSE_AND_SPECULAR, &lpos);
sceGuLightColor(0, GU_DIFFUSE, 0xffffff);
sceGuLightColor(0, GU_SPECULAR, 0xff00ff);
|
and GU_DIFFUSE_AND_SPECULAR is simply the value 6, or (GU_DIFFUSE|GU_SPECULAR). To set them both in one go you do:
| Code: |
sceGuLightColor(0,GU_DIFFUSE_AND_SPECULAR,0xffffff);
|
From what I understood in sceGuLight(), lights can contain either ambient & diffuse (giving you a virtual 5th light if you want to have global changes) or diffuse & specular. Components are filtered, so that you can only either pass in GU_AMBIENT_AND_DIFFUSE or GU_DIFFUSE_AND_SPECULAR to this function to switch between light type 0 and 1.
ALSO, this exposed that you can apparently pass in the value '8' as a component which enables light type 2, and this might be some other kind of lighting-model. I have not yet figured it out, so it is still undocumented. _________________ GE Dominator |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Sun Jul 17, 2005 6:59 am Post subject: |
|
|
Ok, I've submitted a light-sample after cleaning the code up and enabling a few more lights. You'll clearly see both diffuse & specular in that sample, or you're probably blind. :)
Then again, one of the beers last night might have blinded you... ;) _________________ GE Dominator |
|
| Back to top |
|
 |
Arwin
Joined: 12 Jul 2005 Posts: 426
|
Posted: Mon Jul 18, 2005 8:12 pm Post subject: |
|
|
| chp wrote: | Ok, I've submitted a light-sample after cleaning the code up and enabling a few more lights. You'll clearly see both diffuse & specular in that sample, or you're probably blind. :)
Then again, one of the beers last night might have blinded you... ;) |
Thanks for that, I was looking forward to seeing the GPU/VPU in action ... |
|
| Back to top |
|
 |
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|