In my (almost) enclosed tunnel, I've found that there is almost no lighting inside it. Is it possible to get ambient lighting to light inside it, or does spot lights need to be used ?
Ive noticed an issue with ambient lighting.
It seems as if only half an object may light up.
And the other half is in a sortof ambient darkness.
It is possible that your tunnel was created in the ambient shadow direction.
This might be caused by 2 things.....
1. video card and/or drivers...VC might be old? (i know mine is older)
2. Direction object is created(axes) will have a direct effect on how it will react to ambient lights. The vector normals are reacting in a specific way, and are always the same reaction in an ambient light. You might have better results if you create your tunnel in a new direction during creation, then rotate it to where you need it in your scene.
I think we should debug this issue..
I would really like to get this figgured out because i experience the "darkness" in ambient lights as well.
This should help us solve where the problem is:
Can you make a sample.exe, and also....make a screenshot.
I will run it and i will make a screenshot and i will post it here, we can then compare notes.
Its the latest nVidia video drivers for Windows 7 (191.07)
This is what I get when the program starts (the green lines are for collision detection), and also a short while inside the tunnel.
The executable is aloso included
[attachment deleted by admin]
It looks the same on my computer too.
It is strange, the effect of "greyness" on the inside of the tunnel.
Are you using any special effects on the inside of the tunnel?
I analyzed your object with that tool i made, in showroom.
I noticed something odd about the tunnel object, which might need some attention.
The object surface triangle "faces" are rendering to the inside of the object, and the backsides, are on the outside....it is inside-out.
This happens during the time of creation of the object, where the order of vertice placement , is reversed. The rotation of placement of each point must be reversed, to be placed in the other direction.
Other than that, without seeing the code, i cant really understand why it is so dark in the middle.
There are no special effects on anything (yet) - everything is untextured. All the graphics were created in AC3D and exported with Gernot's routine. There tunnel is just a cylinder with the centre removed.
If the vertices are inverted, then I wonder if that's the cause of the lighting problem? If so, any idea how to get it the correct way around ?
Post some sample code!
// --------------------------------- //
// Project: TheRunningCube
// Start: Saturday, November 14, 2009
// IDE Version: 7.171
CONSTANT SECTION_STEP = 3.98
FUNCTION setupStage%:stage AS tStageInfo
LOCAL currentZ
LOCAL length
stage.stageNumber%=2
length=100.0
DIM stage.tunnel[0]
DIM stage.segments[0]
DIM stage.objects[0]
// First, do the lead in
addBeginingOrEnding(stage,currentZ,SECTION_STEP,TRUE)
// Then we do the main part
addTunnelAndSegments(stage,currentZ,SECTION_STEP,length)
// Add the ending
addBeginingOrEnding(stage,currentZ,SECTION_STEP,FALSE)
ENDFUNCTION
// Add the begining or ending section
FUNCTION addBeginingOrEnding%:stageInfo AS tStageInfo,BYREF currentZ,sectionStep,isBegining%
LOCAL loop%
IF isBegining%=TRUE
currentZ=0.0
ENDIF
FOR loop%=1 TO 15
addTunnel(stageInfo,currentZ,sectionStep)
NEXT
ENDFUNCTION
// Add a tunnel segment
FUNCTION addTunnel%:stageInfo AS tStageInfo,BYREF currentZ,sectionStep
LOCAL stage AS tStage
stage.outOfRange%=FALSE
stage.shapeID%=1
stage.textureID%=0
stage.passedBy%=0
stage.x=0.0
stage.y=0.0
stage.z=currentZ
stage.angleX=0.0
stage.angleSpeed=0.0
DIMPUSH stageInfo.tunnel[],stage
INC currentZ,sectionStep
ENDFUNCTION
FUNCTION addSegment%:stageInfo AS tStageInfo,currentZ,sectionStep
LOCAL stage AS tStage
// Add a segment
stage.outOfRange%=FALSE
stage.shapeID%=9
stage.textureID%=0
stage.passedBy%=0
stage.x=0.0
stage.y=0.0
stage.z=currentZ
// Choose a starting angle for it
stage.angleX=RND(359.0)
IF stageInfo.stageNumber%>1
stage.angleSpeed=(RND(5.0)-2.5)/100.0
ELSE
stage.angleSpeed=0.0
ENDIF
DIMPUSH stageInfo.segments[],stage
ENDFUNCTION
// Now we add all the segments
FUNCTION addTunnelAndSegments%:stageInfo AS tStageInfo,BYREF currentZ,sectionStep,length
LOCAL ignore
LOCAL segmentStep%
segmentStep%=0
WHILE length>0.0
ignore=currentZ
addTunnel(stageInfo,ignore,sectionStep)
IF MOD(segmentStep%,5)=0 THEN addSegment(stageInfo,currentZ,sectionStep)
INC segmentStep%
DEC length
INC currentZ,sectionStep
WEND
ENDFUNCTION
FUNCTION displayStage%:stageInfo AS tStageInfo
LOCAL tunnel AS tStage
LOCAL segment AS tStage
LOCAL object AS tStage
// Display the tunnel
FOREACH tunnel IN stageInfo.tunnel[]
X_MOVEMENT tunnel.x,tunnel.y,tunnel.z
X_ROTATION tunnel.angleX,0,0,1
X_DRAWOBJ tunnel.shapeID%,0
NEXT
// Segments
FOREACH segment IN stageInfo.segments[]
X_MOVEMENT segment.x,segment.y,segment.z
X_ROTATION segment.angleX,0,0,1
X_DRAWOBJ segment.shapeID%,0
NEXT
FOREACH object IN stageInfo.objects[]
X_MOVEMENT object.x,object.y,object.z
X_ROTATION object.angleX,0,0,1
X_DRAWOBJ object.shapeID%,0
NEXT
ENDFUNCTION
FUNCTION updateAnimation%:stageInfo AS tStageInfo,speed
LOCAL tunnel AS tStage
LOCAL segment AS tStage
LOCAL object AS tStage
// Update tunnel stuff
FOREACH tunnel IN stageInfo.tunnel[]
tunnel.angleX=wrapF(tunnel.angleX+(speed*tunnel.angleSpeed),0.0,360.0)
NEXT
// Segment stuff
FOREACH segment IN stageInfo.segments[]
segment.angleX=wrapF(segment.angleX+(speed*segment.angleSpeed),0.0,360.0)
NEXT
// And now any objects
FOREACH object IN stageInfo.objects[]
NEXT
ENDFUNCTION
// --------------------------------- //
// Project: TheRunningCube
// Start: Tuesday, November 03, 2009
// IDE Version: 7.163
CONSTANT PLAYER_COLLISIONSPHERESIZE = 0.45
FUNCTION setupPlayers%:stageInfo AS tStageInfo,numPlaying%
LOCAL vPort AS tViewPort
LOCAL player AS tPlayer
LOCAL loop%,viewPortType%
DIM players[0]
SELECT numPlaying%
CASE 1
viewPortType%=VIEWPORT_SINGLEPLAYER%
CASE 2
viewPortType%=VIEWPORT_TWOPLAYER_HORZSPLIT%
CASE 3
CASE 4
viewPortType%=VIEWPORT_FOURPLAYER%
ENDSELECT
setupViewPorts(viewPortType%)
FOR loop%=1 TO numPlaying%
player.shapeID%=OBJECT_PLAYER%
player.textureID%=0
player.playerIndex%=PLAYER_1%+loop%
player.shapeX=0.0
player.shapeY=0.0
player.shapeZ=0.0
player.speedZ=0.0
player.reverseDistance=0.0
player.score%=0
player.lives%=3
player.time=0.0
DIMPUSH players[],player
NEXT
DEBUG "Size : "+BOUNDS(players[],0)+"\n"
ENDFUNCTION
// This positions the players sphere (which isn't seen), and the camera thats in front of it
FUNCTION displayPlayerCamera%:player AS tPlayer
X_CAMERA player.shapeX,player.shapeY,player.shapeZ-5.0,player.shapeX,player.shapeY,player.shapeZ+500.0
ENDFUNCTION
FUNCTION displayPlayerShape%:player AS tPlayer,stageInfo AS tStageInfo,speed
LOCAL loop AS tStage
LOCAL tunnel AS tStage
LOCAL segment AS tStage
LOCAL p2%
X_MOVEMENT player.shapeX,player.shapeY,player.shapeZ
X_DRAWOBJ player.shapeID%,0
// Check for collision with tunnel
FOREACH tunnel IN stageInfo.tunnel[]
IF X_COLLISION(tunnel.shapeID%,0.0,PLAYER_COLLISIONSPHERESIZE,tunnel.x,tunnel.y,tunnel.z)
// Reduce slightly
player.speedZ=constrainF(player.speedZ-(speed*0.05),0.1,0.75)
ENDIF
NEXT
p2%=POW(2,player.playerIndex%-1)
DEBUG "P2%:"+p2%+"\n"
// Check for collision with segment
FOREACH segment IN stageInfo.segments[]
// Only deal with it if its not been passed by already
IF bAND(segment.passedBy%,p2%)=0
// Only do 3D check if we're moving forward
IF player.speedZ>0.0
IF X_COLLISION(segment.shapeID%,0.0,PLAYER_COLLISIONSPHERESIZE,segment.x,segment.y,segment.z)
// We move the player back a bit, and reset the speed
player.speedZ=0.0-(player.speedZ*2.0)
player.reverseDistance=30.0*SECTION_STEP
DEBUG "Collision with segment\n"
ELSE
IF segment.z<player.shapeZ
// Successfully passed by
segment.passedBy%=bOR(segment.passedBy%,p2%)
// Increase speed
player.speedZ=constrainF(player.speedZ+(speed*0.01),0.1,5.0)
DEBUG "Speed Increase!\n"
ENDIF
ENDIF
ENDIF
ENDIF
NEXT
ENDFUNCTION
FUNCTION movePlayer%:player AS tPlayer,speed
INC player.shapeX,MOUSEAXIS(0)*speed*-0.015
INC player.shapeY,MOUSEAXIS(1)*speed*-0.015
ENDFUNCTION
// Update players Z position
FUNCTION updatePlayer:player AS tPlayer,speed
LOCAL maxNormalSpeed = 0.5
INC player.shapeZ,speed*player.speedZ*0.01
IF player.reverseDistance>0.0
DEC player.reverseDistance,speed
ELSE
IF player.speedZ<0.5
player.speedZ=MIN(player.speedZ+(speed*0.05),maxNormalSpeed)
ENDIF
ENDIF
DEBUG "Speed : "+player.speedZ+"\n"
ENDFUNCTION
FUNCTION displayStatusDisplay%:vPort AS tViewPort,player AS tPlayer,count%
LOCAL tempS$,tempL$,tempT$
LOCAL font%
tempS$=RIGHT$(SCORE_PAD$+player.score%,LEN(SCORE_PAD$))
tempL$=RIGHT$(LIVES_PAD$+player.lives%,LEN(LIVES_PAD$))
tempT$="00:00"
IF (count%<>1 AND options.screenWidth%<1024)
font%=1
ELSE
font%=2
ENDIF
SETFONT font%
PRINT tempS$,vPort.x%,vPort.y%
PRINT tempL$,(vPort.x%+vPort.width%)-(LEN(tempL$)*fontLoadData[font%].xSize%),vPort.y%
PRINT tempT$,((vPort.width%-(LEN(tempT$)*fontLoadData[font%].xSize%))/2)+vPort.x%,vPort.y%
ENDFUNCTION
The main loop
FUNCTION _mainLoop%:
LOCAL speed
LOCAL vPort AS tViewPort
LOCAL pIndex%
speed=0.0
WHILE TRUE
FOREACH vPort IN playersViewPort[]
pIndex%=vPort.playerIndex%-PLAYER_1
VIEWPORT vPort.x%,vPort.y%,vPort.width%,vPort.height%
X_MAKE3D 1.0,1000.0,45.0
displayPlayerCamera(players[pIndex%])
X_AMBIENT_LT 0,RGB(255,255,0)
// Display players track
displayStage(stage)
// Players
displayPlayerShape(players[pIndex%],stage,speed)
updatePlayer(players[vPort.playerIndex%-PLAYER_1],speed)
movePlayer(players[vPort.playerIndex%-PLAYER_1],speed)
X_DRAWAXES 0.0,0.0,0.0
// Display status for player
X_MAKE2D
displayStatusDisplay(vPort,players[vPort.playerIndex%-PLAYER_1],BOUNDS(playersViewPort[],0))
NEXT
// Do update
//FOREACH vPort IN playersViewPort[]
//NEXT
updateAnimation(stage,speed)
SHOWSCREEN
speed=moveSpeed(options.screenWidth%,options.screenHeight%)
WEND
ENDFUNCTION
It looks like I need to set the X_CULLMODE to -1 and the lighting is okay, although how the graphics are displayed isn't... :S
However, texturing is a problem
[attachment deleted by admin]
How are your objects created? I mean perhaps you need to invert there vertexes. :noggin:
Looks like a problem with your normals? Normals facing the wrong way or even at the wrong angle will screw with lighting no end. Are all yours facing towards the centre of the tunnel?
No idea - its all been created in AC3D (as seperate items using the built-in shapes), and then exported... I've tried the "Flip Normal" and "Change Vertex Order" menu items, but it looks like they dont do anything useful.
If you've got AC3D, I've included all the graphics.
It appears all normals are facing outwards (which is correct)
[attachment deleted by admin]
hmm, no special effects.
And nothing blocking the camera, other than those obstacles?
Since you are willing to open the code, please pack it all into one rar file as a complete project which can be compiled.
And, as people are examining this project, please take the time to create a new tunnel piece, so we can be sure this isnt the problem.
If you use my 3d object analyzer(showroom), you will see some issues with your object..
1. the triangle count reveals 132 triangles.....this is bad because there should only be 96...you can make this observation too, do the count simply by looking at it and multipying the triangles per segment...it should only be 96
2. the triangles are drawn backwards, the insides are facing out and visa versa.
3. all the vertex normals are facing outwards.
There is difinetly somethign wrong with the ac3d program and this primitive.
Personally, since this object is so simple, i would just use glbasic to create it.
Currently, with your object, you are only revealing 24 triangle to the player, which is 108 triangles less than what the object has.
Make it with only 24 triangle facing inward.
Try this if you dont want to use glbasic to make it:
Make a tube the same length as your tunnel.....and remove the end caps, then flip the normals so they face inward...you should end up with only 24 triangles, if the object is 12 sided.
Normals look ok, though there are some missing polygons in your tunnels sections (although that wouldn't explain your problem). Also Id apply smoothing groups for better lighting, ONCE it starts to work properly.
Do you have some problem example source to look at?
Update: Well since the normals are messed up in GLB and OK in AC3D, it kinda points towards an import bug IMHO.
This is the complete project - you'll need to adjust the Routines stuff a bit (because of where I put it), but it is complete.
I seem to get a somewhat better result from gameSpace - however, only half the tunnel is textured... :S
Did try it with the arrow graphic from the Object Analyser, but lighting is still not correct...
[attachment deleted by admin]
Very interesting..
The lighting seems much better now, everything in the tunnel is very visible.
It seems nothing is wrong.
Did you find a solution here?
Other than lighting, i only see a quarter of the tunnel.
But in the analyzer i see the whole tunnel..which has correct faces now btw.
Hm.. I have no idea. For the "ambient light", internally I use a directional light at camera point in camera looking direction. You can try a point or a directional light yourself:
// This positions the players sphere (which isn't seen), and the camera thats in front of it
FUNCTION displayPlayerCamera%:player AS tPlayer
X_CAMERA player.shapeX,player.shapeY,player.shapeZ-5.0,player.shapeX,player.shapeY,player.shapeZ+500.0
X_SPOT_LT 0, RGB(255,255,255), player.shapeX,player.shapeY,player.shapeZ-555.0, 0,0,1, 360
ENDFUNCTION
Beware: Each triangle is rendered with the lighting values calculated by the vertex normals relative to the light source position. The pixels drawn on the driangle are interpolated then.
Thus, when you make a biiiig triangle and make a point light in the center, the triangle will be dark, because the corners are far away from the light and thus lightes dark. the center of the triangle is just interpolated from the corners, thus dark.
Yes, the tunnel section for some reason only partially visible when textured - no idea why though.
It does seem that there might be a problem with the exporter with AC3D (or with AC3D itself) as gameSpace seems to give the correct results.
Try making smaller triangles as Gernot suggested.
Assuming using the increase vertices would decrease the size of the triangles, then not much changes...
[attachment deleted by admin]
Make sure that the texture size is 2^n x 2^m even in AC3D. Texture coordinates are converted incorrectly, else.
Right...the object is using a 33x33 map named(i assume) StartTile.png
If im not mistaking you intended to use TunnelTexture.png instead.
I replaced it in my copy...it is working(screenshot) :
[attachment deleted by admin]
Gernot, does ambient light have an origin, internally?
Quote from: Kitty Hello on 2009-Nov-16
For the "ambient light", internally I use a directional light at camera point in camera looking direction.
Seems origin is the camera
I "see" the light now, GLBasic doesnt have ambient opengl lighting...this is why we see bright and dark spots on models when we only use x_ambient_lt, because it is specular and possibly a tiny amount of diffuse.
What we need is a light option to access as many models of light as possible, for instance:
ambient light
specular light
diffuse light
This would help us produce more accurate representations of the models we see in 3d model creation programs.
This is something i found on http://www.falloutsoftware.com/tutorials/gl/gl8.htm
It is opengl code for ambient lighting.
Glfloat global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
Quote from: Ocean on 2009-Nov-16
Quote from: Hemlos on 2009-Nov-16
Gernot, does ambient light have an origin, internally?
http://www.glbasic.com/forum/index.php?topic=3818.msg27859#msg27859
Err yah i get the picture, everyone jumps my bones when i ask a stupid question.
As i said in my last post, we need access to the 3 light models, not just a combined single light type.
Indeed, the question was actually worded incorrectly...here is my correction..
Gernot, how can we access ambient, specualar, and diffuse lighting individually with GLBasic?
Yes, it does appear correctly now :)
My temporary solution for wierd x_ambientlt anomolies is this function below.
It prevents the strange rotating bright and dark spots when the camera moves, and completely surrounds the object from all directions.
X_MyAmbientLight( White, 0 , 0 , 0 ) //Color,X,Y,Z
FUNCTION X_MyAmbientLight: Color,X,Y,Z
X_SPOT_LT 0,Color, X+100 ,Y ,Z ,X,Y,Z,360
X_SPOT_LT 1,Color, X ,Y+100 ,Z ,X,Y,Z,360
X_SPOT_LT 2,Color, X ,Y ,Z+100 ,X,Y,Z,360
X_SPOT_LT 3,Color, X-100 ,Y ,Z ,X,Y,Z,360
X_SPOT_LT 4,Color, X ,Y-100 ,Z ,X,Y,Z,360
X_SPOT_LT 5,Color, X ,Y ,Z-100 ,X,Y,Z,360
ENDFUNCTION
Hopefully there will be a solution to acess internal spec, amb and diff lights.
the OpenGL wrapper can use that. I didn't enable true ambient light for one reason I can't remember since a few years now...
I remember why you didnt add it....it was an assumption that all the 3d programmers who were using glbasic as a "basic" thing.
Assumption was, to a new guy, the ambient light looked like crap.
But the reality of it is, ambient light adjustment is actually pretty important, to be mixed with the other 2 light styles.
What do you mean the wrapper can use that?
Can we get access to the different lights somehow(specular,ambient,diffuse)?
Feature request * 3 here(all 3 light style). =D
You can never go wrong with more lighting options :)
At least the problem seems to be mostly with AC3D :)
I figgured out how to get rid of the greyness of X_AMBIENT_LT
Check this message for snippet:
http://www.glbasic.com/forum/index.php?topic=3849.0