Author Topic: Scene lighting  (Read 6035 times)

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« on: 2008-Feb-12 »
Hi,
please look at the project in the zip
http://members.optusnet.com.au/~ingle.m/3droom.zip
When I run this I can see the model OK even though I have not made any lights. If I add a light nothing changes. I think I am missing something fundamental here. (Note I have added extra stuff to the T3DEntity file)
Any help appreciated
Matthew

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« Reply #1 on: 2008-Feb-14 »
No takers???
Matthew

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Scene lighting
« Reply #2 on: 2008-Feb-14 »
Have you tried the examples that comes with GL-Basic? I think there is some with 3D and lighting in there.

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« Reply #3 on: 2008-Feb-14 »
In the light example I can see no difference in the "off", "ambient" ,"multitexture" and "spot" modes. The "bump" and "cartoon" modes do appear to have shadows but I can't say that there is any variation in the light (no attenuation). The shadows example likewise show a shadow but again the rest of the lighting is pretty uniformly lit. Am I expecting too much??
Thanks
MAtthew

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« Reply #4 on: 2008-Feb-17 »
Anyone tried the example? I just don't seem to be able to understand how to set up the lights. I assumed that if there were no lights then you should be unable to see anything. Is this a wrong assumption?

Anyone?
Thanks
Matthew

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Scene lighting
« Reply #5 on: 2008-Feb-17 »
I'm not sure how it works in GL-Basic but if you have no lights it's supposed to work on the ambient light wich gives no shadows at least in Pov-Ray. Is there such a setting?

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« Reply #6 on: 2008-Feb-17 »
I am not working with shadows at the moment. I just don't know if the lights are working in 3D. I have made two small examples. The first just draws a plane and puts the camera 10 units away from it. No lighting commands. The plane shows in the 3d view when the program is run.
Code: (glbasic) [Select]
// --------------------------------- //
// Project: lights2
// Start: Sunday, February 17, 2008
// IDE Version: 5.173

//create a plane to catch the light
MakePlane(1)

//Main loop
WHILE TRUE

X_MAKE3D 0.1,500,90
X_CAMERA 0,0,15,0,0,0
X_DRAWOBJ 1,0

SHOWSCREEN
WEND




FUNCTION MakePlane:pn
X_OBJSTART pn
X_OBJADDVERTEX -10,-10,0,0,1,RGB(128,128,128)
X_OBJADDVERTEX -10,10,0,0,0,RGB(128,128,128)
X_OBJADDVERTEX 10,10,0,1,0,RGB(128,128,128)
X_OBJADDVERTEX 10,-10,0,1,1,RGB(128,128,128)
X_OBJADDVERTEX -10,-10,0,0,1,RGB(128,128,128)
X_OBJEND
ENDFUNCTION
Now I add a spot light to the scene and you can turn it on and off, change the cutoff angle and move it forwards and back along the z axis. I can't see any difference here to the first program. So what is the light doing??
Code: (glbasic) [Select]
// --------------------------------- //
// Project: Lights
// Start: Sunday, February 17, 2008
// IDE Version: 5.173
//create a plane to catch the light
MakePlane(1)
//create a varaible to alter the cutoff
LOCAL cutoff=90
//and one to hold the z value of the light
LOCAL lightz=20
//a toggle for the light
LOCAL On=1
LIMITFPS 12
//Main loop
WHILE TRUE

X_MAKE3D 0.1,500,90
X_CAMERA 0,0,15,0,0,0
X_DRAWOBJ 1,0
IF On =1 THEN X_SPOT_LT 0,RGB(255,255,255),0,0,lightz,0,0,-1,cutoff

IF KEY(45)=1 THEN On=ABS(On-1)
IF KEY(37)=1
cutoff=cutoff-1
IF cutoff<5 THEN cutoff=5
ENDIF
IF KEY(38)=1
cutoff=cutoff+1
IF cutoff>180 THEN cutoff=180
ENDIF
IF KEY(30)=1 THEN lightz=lightz-1
IF KEY(44)=1 THEN lightz=lightz+1

X_MAKE2D
PRINT "Use K and L to change the cutoff angle",0,10
PRINT "Use A and Z to move the light on the Z axis",0,20
PRINT "Use X to toggle the light on and off",0,30
PRINT "The light is pointing into the screen always",0,40
PRINT "On Value: "+On,0,80
PRINT "Cutoff Angle: "+cutoff,0,100
PRINT "Light at 0,0,"+lightz,0,120



SHOWSCREEN
WEND




FUNCTION MakePlane:pn
X_OBJSTART pn
X_OBJADDVERTEX -10,-10,0,0,1,RGB(128,128,128)
X_OBJADDVERTEX -10,10,0,0,0,RGB(128,128,128)
X_OBJADDVERTEX 10,10,0,1,0,RGB(128,128,128)
X_OBJADDVERTEX 10,-10,0,1,1,RGB(128,128,128)
X_OBJADDVERTEX -10,-10,0,0,1,RGB(128,128,128)
X_OBJEND
ENDFUNCTION
So my question really is - have I just missed out doing something or are the lights not working. Any help would be greatly appreciated
Matthew

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10851
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Scene lighting
« Reply #7 on: 2008-Feb-17 »
uhm.. could you put the light before the X_DRAWOBJ, please?

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« Reply #8 on: 2008-Feb-17 »
I just tried that. It has made a difference. There is now a difference in turning the light on and off. I have tried varying the cutoff and the distance from the plane and the lighting does not seem tovary smoothly but rather "jumps" between finite states. Eg leave the light at its start point and vary the cutoff. You will see what I mean. Similarly leave the cutoff at the start value and move the light toward the plane. For me the light switshes state when it is closer to the plane than the camera. I was expecting (hopong) that the cutoff would show a shrinking ring of illumination . Sorry to be a pain.

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« Reply #9 on: 2008-Feb-21 »
Bump??

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10851
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Scene lighting
« Reply #10 on: 2008-Feb-21 »
Well, the cutoff is just an angle that decides if a vertex gets lit or not.
You're only drawing a 4 noded quad. Don't expect a circular ring on it. You must use a finer mesh for these effects, as the lighting is per vertex, not per pixel.
So, for lights, please use a sphere or a donut or whatever. Not just one polygon.

Offline matty47

  • Mr. Drawsprite
  • **
  • Posts: 71
    • View Profile
    • Matt and Marg's Homesite
Scene lighting
« Reply #11 on: 2008-Feb-21 »
Thanks I will try this. As I said I probably missed something.
Thanks for your patience

moonmoon

  • Guest
Scene lighting
« Reply #12 on: 2008-Feb-22 »
I got the information.