I am working on a 3d racing game. Everything works so far, got a nice racing course, a player who camera follows smoothly in loopings and such, as well as three enemies who drive on the track as well. Now, I wanted to apply lights and shading to everything and I read a lot in this forum and tries so many things, but cant make it work properly.
This is the code in short (often speaks more than thousand words):
WHILE TRUE
X_MAKE3D 1, 1000, 90
//Setting the camera
X_CAMERAUP Cam.front, Cam.side, Cam.up
X_CAMERA Cam.x, Cam.y, Cam.z, Cam.dx, Cam.dy,Cam.dz
//Light Rendering
FOREACH e IN Enemies[] //Three enemies in total, shall have a 90degree light at their front vector
X_SPOT_LT e.number, e.color,e.x, e.y, e.z, e.frontx, e.fronty, e.frontz, 90
NEXT
//Object Rendering
FOREACH o IN self.object[]; //All objects are rendered (Racing course, Enemies, Players etc..)
X_MOVEMENT o.x,o.y,o.z
X_SETTEXTURE o.tex,-1
X_DRAWOBJ o.obj ,0
NEXT
X_MAKE2D
SHOWSCREEN
WEND
I tried to include the command:
X_SPOT_LT -3, color,x,y, z, 0,0, 0, 360
after the pipeline, and rendered the object agains. I also tried the value of "-2" for toon shading and took some code from the examples file of glbasic:
X_LOADSHADER(13, "shader/toon.vert", "shader/toon.frag")
DIMDATA cheap[], .5, 1
DIMDATA nice[], .3, .6, .6, .6, .6, .6, .6, .7, 1, 1, 1, 1, 1, 1, 1, 1
X_SETCELSHADES nice[]
however I cant get shadows working at all, and the lights arenot very bright. I tried Cullmode 1 and -1 as well as using bump mapping and ambient light. I cant even describe what i did and what failed. I am just an amateuer and hope someone can explaine properly how can i achieve the following things:
draw the objects (racing course, vehicles)
4 bright Spotlights in total for each vehicle.
shading
enclosed a little screenshot (with only 1 enemy, and without skybox) I reduced everything to the bare minimum for these testings:
I'm interested in your race track as I am trying something similar. Any chance of video demo?
Sh sh sh shadows :sick:. It's tricky but the 3D samples folder that demonstrates it. As object need to be drawn twice, it's cuts the processing time in half.
Normal spotlight
Draw objects
Turn on shadow spot light
Draw objects (again same)
Cast shadow spot light color
For each of a maximum of seven spotlights (num 0 - 7) there is a shadow light and repeated objects drawn (doubled), then another shadow spotlight. :doubt:
Here's my shadow room low and hires tests:
https://www.youtube.com/watch?v=5k2FRHlL5tI
8)
From 3D Samples folder:
..\Samples\3D\Shadows\Shadows.gbas
// --------------------------------- //
// Project: Shadows
// Start: Thursday, January 19, 2006
// IDE Version: 3.011
// konstante Werte / Constant values
LOCAL image, none, shadow, sphere, donut, cube, spot_ang, lmode, phi, lx
LOCAL ly, lz, i, psi, px, py, pz, j
none = -1
image = 0
donut = 0
cube = 1
sphere = 2
// Create Primitives
CreateTorus (donut, 10, 20, 36, 12, 2, 2, RGB(255,255,255))
CreateCube (cube, -1000, RGB(255, 255, 255))
// Grafiken laden / load graphics
LOADSPRITE "image.bmp", image
//LOADBUMPTEXTURE "bump.bmp", bump
LOCAL mx, my, b1, b2 // compiler warning
WHILE TRUE
// naja... / well...
mx = mx + MOUSEAXIS(0)
// MOUSESTATE mx, my, b1, b2
// 1000 ist weit genug hier / 1000 is far enough here
X_MAKE3D 1, 1700, 45
// ein Winkel für alles / one angle for everything
phi = GETTIMERALL() / 250
// eine Lichtposition / a light position
lx = SIN(-phi*3)*300
ly = 20 //(SIN(3*phi)-COS(4*phi))*100
lz = COS(-phi*3)*300
// Maus X=drehen / Mouse X=turn
X_CAMERA 400*COS(mx),120,400*SIN(mx), 0,0,0
// Licht als Punkt zeichnen / Draw light as dot
X_DOT lx,ly,lz,32,RGB(255,255,255)
// Texture setzen / Set texture
X_SETTEXTURE image, none
X_CULLMODE 1
X_SPOT_LT 0, RGB(255,255,255), lx,ly,lz, -lx,-ly,-lz, 360
// Würfel zeichnen / Draw Cube
X_DRAWOBJ cube, 0
// Donut zeichnen / Draw Donut
X_MOVEMENT 0,0,0
X_ROTATION 45, 1,0,0
X_DRAWOBJ donut,0
// Schatten einschalten / turn on Shadows
X_SPOT_LT -3, 0, lx,ly,lz, -lx,-ly,-lz, 360
// neuzechnen von schatten-werfenden Objekten
// re-draw shadow casting objects
X_MOVEMENT 0,0,0
X_ROTATION 45, 1,0,0
X_DRAWOBJ donut,0
// Schatten zeichnen / draw shadows
X_SPOT_LT -3, RGB(0,0,64), 0,0,0, 0,0,0, 0
// oder / or
// X_MAKE2D, SHOWSCREEN, X_MAKE3D
// zum Zurechtfinden / for navigation
X_DRAWAXES 0,0,0
X_MAKE2D
PRINT my, 0,0
SHOWSCREEN
WEND
Thank you, suddenly things works, cant describe how happy i am :enc:
Of course I just begin to understand the process: did I get you right that for each light that shall cast a shadow I have to use the complete pipeline?
Such as...
For each light
Set Normal spotlight //(for example light Number 1 with player coordinates)
// hmm, I included a light with -1 value here as well for bumpmapping, how can this be handled?
Draw objects
Turn on shadow spot light //(Number -3 with player coordinates?)
Draw objects
Cast shadow spot light color // (player coordinates, how can i set color?)
next
anyway i make so much progress and I am greatful for your help. I couldnt get any results with toon shading yet. I wonder how it works. Check this video I just uploaded to youtube, where i am testing todays results: https://www.youtube.com/watch?v=L6J1Mw6xve8&feature=youtu.be
Looks great! Is the track procedurally done?
Wow, for real....so cool....even loops. =D :good: :coke:
Now how is the track designed and constructed? How do you calculate track gravity/orientation?
Again, in regards to the toon shader; Are you settting X_SETSHADER?
..\Samples\3D\Shaders\Shaders.gbas
// --------------------------------- //
// Project: Shaders
// Start: Monday, September 25, 2006
// IDE Version: 3.262
LOCAL shaders$[], num, current$
IF X_LOADSHADER(13, "toon.vert", "toon.frag") = FALSE
PRINT "Shader failed to load: ", 100,100
SHOWSCREEN
MOUSEWAIT
END
ENDIF
CreateTorus(0, 5, 10, 12, 9, 2, 2, RGB(0xff, 0xff, 0xff))
// CreateSphere(0, 10, 9, RGB(0xff, 0xff, 0xff) )
WHILE TRUE
DRAWRECT 0,0,640,480,RGB(255,128,0)
X_MAKE3D 1,500, 45
X_CAMERA 0,0,-100, 0,0,0
X_SPOT_LT 0, RGB(255,255,255),100,100,-1000, -.1,-.1,1, 360
X_ROTATION 45, 1,1,0
X_ROTATION GETTIMERALL()/100, 0,1,.2
X_SETSHADER 13
X_DRAWOBJ 0, 0
SHOWSCREEN
WEND
That looks totally awesome!!! :good:
Keep us posted on your progress :)
Thanks guys for the nice words, but i couldnt have done it without the amazing support of you and all the examples here in the GL Basic community.
The track is generated procedurally. I learned a lot from the "Pseudo 3D" example from the Showroom and the S Zero example. The track is basically build of various segments (which can be straight, curve or looping). Each segment uses of course more inputs than just that, for example the lenght, the roadwidth, the height, and the exact amount of curveture as well as some looping paramenters can be adjusted for each segment. A segment consists of various subsegments, which are the actual triangles that get drawn. So if i need a track that goes forward, curve, forward, looping etc.. i can easly build it within seconds :)
For the orientation each vehicle has three perpendicular unity normal vectors that get rotated according to the normal of the collision surface via a rotation matrix. Smooth camera movement is a bit tricky, i still couldnt find the optimal solution.
At the weekend I will have more time to continue with the project, gonna try out X_Shader command.
Oh I see now and I will have to check out those showroom samples. The similar race track I had was segmented but only a flat road and any road segment can be added that would go on forever rather than in track loop, like a forever runner phone game. So I am guessing the segments, along with the textures, are imported files or constructed in real time? How is the mapping of the road done? Is it manual or auto seed generated map? :-[
get ready for cartoon racers =D
Quote from: matchy on 2015-Oct-23
Oh I see now and I will have to check out those showroom samples. The similar race track I had was segmented but only a flat road and any road segment can be added that would go on forever rather than in track loop, like a forever runner phone game. So I am guessing the segments, along with the textures, are imported files or constructed in real time? How is the mapping of the road done? Is it manual or auto seed generated map? :-[
get ready for cartoon racers =D
The track is one object (ok basically there are three, but not that important now) and gets build from lots of vertexes at the start of the program. Let me write some pseude code so you get the idea what happens before the mainloop:
Function BuildTrack:
LOCAL starttrack = 0
startobj track
addSegment(starttrack, straight,lenght = 200, newheight = 100, number of subsegments etc...)
addSegment(starttrack,curve,lenght = 200, newheight = 0, number of subsegments etc...)
addSegment(starttrack,looping,lenght = 200, newheight = 0, etc... getting the idea)
addmoreSegments ....
endobj
ENDFUNCTION
Function AddSegment: byref starttrack, all the other parameters...,
calculate all x, y,z and whatever needed for subsegments according to the input parameters
calculate the end of this segment to byref it for the next segment later
for i = 0 to number of subsegments
addvertexes x,y,z //just usal tex coordinates like when drawing a rectangular surface from 4x vertexes
objnewgroup
addmorevertexes etc....
next
return startrack (= end of this segment)
ENDFUNCTION
OK, now the three objects are: Road, Borders and Decorating things make the bottom and the outer sides. Since Road and Borders only are used for collision testing later and they have different collision formulas, i had to split up the track into more than one objects, so I could "talk" the the borders and the road independently.
I'm working on a pseudo 3D racing game at the moment - although its more or less exploring how to read in track, tile, static and border information efficiently.
So far, the track layout is just a list of codes, lengths and height changes.
Quote from: ProN3rd on 2015-Oct-23
The track is one object...
I appreciate your thorough respones champ. 8) I'm still wondering where's the layout data for the whole track to be mapped? Is there or will it have/need a track designer? ::)
the actual data for each segment that flows into the createtrack function is saved and loaded using a txt file. Because i dont like to code hard values in the program or type them into the textfile manually, i build a small editor, so you can actually build a track from any kind of segments in real time and save everything, back to the txt file if it needs to be adjusted later. however the editor is buggy at the moment and by no means any better than dealing with plain numbers, but shall be a part of the final programm so one can make custom tracks =D
here is a screenshot that highlights some features. the obj setting is the "world" editor, where i can include primitives and objects. The track editor is a different thing. As mentioned the track is made of three objects.
Ah well that's cool and hope to see a video of that. ;) This is something that I am trying to avoid and have been able to created maps and landscapes from automated algos, such as using mazes. Even a developer tool version for testing or a user end version. Like in my zombie games, there is an internal and editor online. 8) Then I moved on to racing, then you present this explains why I'm so interested in your method. :whistle:
i think such an algorythm can be easly modfied so the buildtrack function gets just random values and creates a new track every time
Gee! :O :O
That editor does look cool! :good:
i am still having troubles with shading. Its a bit difficult to explain: the scene is rendered nicely with shadows even... but if I step inside the shadow, the shadow dissapears.
i am really struggeling with this. To explain i have enclosed three screenshots, where you see me flying in a tunnel which casts a shadow on the road (example1 and example2), the light source is behind right in the scene. However as soon as I am completly in the tunnel the shadow of the tunnel dissapears (Example3) and doesnt get rendered any more. The tunnel itsself is still rendered but it doesnt block the light any more. the ball is still casting a shadow on the road, which should be impossible as the ball is now fully in the tunnel.
The tunnel constist basically of thin plates using the top and bottom surfaces of the create cube function. The plates are wrapped around the road. I used Cullmode 1.
for the rendering pipeline, its nothing fance with the very basic setup. I didnt include any spotlight (1 to7) or ambient light, neither a 2nd spotlight-3 call at the end (shadows get rendered with the Xmake2d call it sais in the help file).
Make 3d
Set Cam
draw skybox
X Spot Lt -1 at cam pos
draw objects
X spot lt -3 at light source
draw objects again
make 2d
Hi
Yes, you are right. Shadow disappears when you dive into the shadow or you are close to the shadowcasting object and turning camera. I've already posted that bug 4 or 5 years ago
but it hasn't been fixed. :whistle: =D
Cheers
I had some sort of problem like this where I'm guessing it's a zbuffering issue, which you can see in my video demo. Alternatively, I've experimenting with drawing the 3d objects from afar then inwards in a circle radar fashion. Otherwise, far objects with cover close object with no zbuffering.
My suggestion is remove the shading for now because really you don't need it. If you want to work on shading, produce smaller code samples to solve your problems rather than drag this awesome project down as we can't help due to a bug.
While I never did much on the 3d front as of yet but I have a few suspicious.
I take your tunnel object is one object only right?
If so, imagine a cube surrounding the object on its boundaries, if your camera goes into it, you may loose the shadow.
I have seen this happening on open gl for ages into other aplications.
Possible way to resolve it:
-have multiple objects on the tunnel curve composing the final tunnel.
-Another reason could be related to front face polygons, here you will want your objects fully 3d closed, never as a thin plan.
Your case seems to be related with the first case, as the camera hops into the cube boundaries, specially on the concave part, I think the shadow renderer skips it since it believes you are inside it or something like that.
Can you upload that tunnel object? I´m pretty sure this is not a bug but it is just the way you have to deal with open gl.
edit: ops, just read that you are creating your objects on runtime... ;P
So try to create your arc segment with 3 objects, each covering 60 degrees from the 180 degrees arc, this way you will reduce the bounding box and the concave area, notice they must precisely fit together, otherwise you may get some light bleeding through. Secondly, make sure your light source is not going into the object and make sure the object itself is fully closed. This should resolve your issues. Additionally, you may want to create the tunnel segment part standing straight and then you clone it and rotate it because on some applications, if you create the object diagonally, the bounding box is going to form around it respecting world coordinates 90 degrees style and you will end up with a mess.
Heck, this is horrible to explain with words only, let me try to show it.
On the ´box off' image you won´t notice any difference on your 3d game, you are probably constructing your model according to type A (ground is a different object).
Type B, I´m creating the left most piece first and cloning and rotating it 60 degrees 2 times, so to make the full arc.
Type C, I´m modeling the top part of the arc, cloning it twice and rotating a piece 60 degrees and the other -60 degrees.
Now check the ´box on´ image and you will see how the bounding box (red) behaves on the different types per objects.
Like I said, you don´t want your camera inside the red area or you will loose that object´s shadow.
So your best choice would be to use the type C.
The front 2 yellow blocks are just a visual guide so you see why when you model, it is important that the model is oriented towards the lowest bounding box area possible, the right yellow block is going to waste a good area while one could simply use the left one and rotate it.
I hope this helps. ( A,B,C, 1,2,3... :D)
Would it be possible to bake/fake the shadow? It won't fix the issue, but nobody will know...
I will give a wild guess here:
-bake shadows is impossible since he is generating objects in code.
-fake is possible, it will add up to the number of texture tiles (just like 2d tiling when it comes to corners) or he will have to process shadows into the texture by the way of a virtual buffer, Mentalthink once pulled a technic for that by using the bump map channel, it is worth looking into.
I´m confident there is no issue or bug into this, it is just about dealing with the open gl as it is.
I have tried to explain it for ages, but our 3d vocabulary differs too much, hopefully the visuals will help.
I´m confident our shadow system is a projection map (or polygon) by its looks and it takes into account the object´s bounding box to speed up things considerably and cue objects that don´t need it, otherwise you would be looking into raytrace, which is not the case. By having the camera inside that bounding box, you kill its shadow. You will notice the chaps that responded earlier experienced the same thing:
"get close to an object and its shadow disappear"
And no, it is not a z buffer thing Matchy.
You don´t just model the whole world into a single object and expect a projection shadow map to work when the camera is inside its bounds!
I could be wrong... would have to try it myself. I´ve been wrong before. :P :P :P
HI Pron3n you have tried the command X_CULLMODE , perhaps the light and the camera into the tunnel don't works well.
The problem of X_Cullmode it's you can force draw the external and internal faces of a 3D Mesh, but you draw the double of polys... perhaps only apply to the tunnel don't drop down too much the FPS...
Another way like said Erico is doing the sadow pre-computed... In blender you have a very cheaper plugin for done the lightmaps or complete maps very very eaasily... and the good point in blender uses Cycles is a read good photorealistic engine. (Works with internal blender engine too).
But Mental, the thing works, you just have to tile the objects considering its bounds and no camera inside it. :good:
There is no way our shadow system is a raytracer, it is a projection map!! :rant:
Double face polygons won´t fix it. (while it is good to know, I didn´t know about that...)
=D =D :nana: Sorry guys I don't read all the post and too much hours wake up... tomorrow I will back and will say another stupid idea =D =D =D
Thanks for clarify Erico :good:
Your ideas are great, problem is that what I said is theory based on ancient experience, but not experienced on GLBasic itself.
It would be best if ProN3rd or our friends that have similar problem could give it a try.
But heck, chaps stating this as a bug without trying it out first does bug me a bunch.
I can do some coding to try it out, but it will be a while, if some of you can code faster, I can provide the objects.
I have recreated an example that shows exactly my problem in a few lines. Use ArrowUp and ArrowDown to control the player into the shadow. As soon as the player is fully in the shadow of the wall (tunnel), the shadow dissapears, meanwhile I will further check on your responses. thanks again for all your help
//Utility Class
TYPE Txyz
x;y;z
ENDTYPE
//Create Coordinates
GLOBAL pl AS Txyz ; pl.x = -0; pl.y = 0; pl.z = 10 //Player
GLOBAL cam AS Txyz ; cam.x = -50; cam.y = 0; cam.z = 10 //Cam
GLOBAL li AS Txyz ; li.x = -100; li.y = -400; li.z = 500 //Light
GLOBAL pr AS Txyz ; pr.x = 0; pr.y = 0; pr.z = -250 //Road
GLOBAL po AS Txyz ; po.x = 100; po.y = -75; po.z = 0 //Obstacle (Wall)
//Create Objects
GLOBAL player = GENX_OBJ() ; CreateSphere(player,5,10,RGB(255,0,0))
GLOBAL skybox = GENX_OBJ() ; CreateCube(skybox,3000,RGB(40,40,100))
GLOBAL road = GENX_OBJ() ; CreateCube(road,500,RGB(100,100,100))
GLOBAL obstacle = GENX_OBJ(); CreateCube(obstacle,100,RGB(130,10,130))
//Mainloop
WHILE TRUE
X_MAKE3D 1,2000,90
X_CAMERAUP 0,0,1
X_CAMERA cam.x,cam.y,cam.z,pl.x,pl.y,pl.z
//Draw skybox
X_CULLMODE -1
X_DRAWOBJ skybox,0
X_CLEAR_Z
X_CULLMODE 1
//Draw scene
X_MOVEMENT pr.x,pr.y,pr.z ; X_DRAWOBJ road,0
X_MOVEMENT po.x,po.y,po.z ; X_DRAWOBJ obstacle,0
X_MOVEMENT pl.x,pl.y,pl.z ; X_DRAWOBJ player,0
//Shadow light
X_SPOT_LT -3,0,li.x,li.y,li.z,0,0,0,360
//Draw scene again
X_MOVEMENT pr.x,pr.y,pr.z ; X_DRAWOBJ road,0
X_MOVEMENT po.x,po.y,po.z ; X_DRAWOBJ obstacle,0
X_MOVEMENT pl.x,pl.y,pl.z ; X_DRAWOBJ player,0
X_MAKE2D
SHOWSCREEN
//Movement Player
IF KEY(200); INC pl.x; INC cam.x; ENDIF
IF KEY(208); DEC pl.x; DEC cam.x; ENDIF
WEND
//Utility Functions
FUNCTION CreateSphere: num, r, n, col
LOCAL i,j, theta1, theta2, theta3, pi
pi = ACOS(0)*2
IF r < 0 THEN r = -r
IF n < 4 THEN n = 4
X_AUTONORMALS 2 // smooth edges
X_OBJSTART num
FOR j=0 TO INTEGER(n/2) -1
theta1 = j * 2*pi / n - pi/2;
theta2 = (j + 1) * 2*pi / n - pi/2;
FOR i=0 TO n
theta3 = i * 2*pi / n;
X_OBJADDVERTEX r*COS(theta2) * COS(theta3), r*SIN(theta2), _
r*COS(theta2) * SIN(theta3), i/n, 2*(j+1)/n, col
X_OBJADDVERTEX r*COS(theta1) * COS(theta3), r*SIN(theta1), _
r*COS(theta1) * SIN(theta3), i/n, 2*j/n, col
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION // n
FUNCTION CreateCube: num, sz, col
// Diese Variablen sind als LOCAL definiert:
// num, sz,
X_AUTONORMALS 1 // For a cube, hard edges
sz=sz/2
X_OBJSTART num
// Front Face
X_OBJADDVERTEX sz, -sz, sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz, sz, 0, 0, col
X_OBJADDVERTEX sz, sz, sz, 1, 1, col
X_OBJADDVERTEX -sz, sz, sz, 0, 1, col
X_OBJNEWGROUP
// Back Face
X_OBJADDVERTEX -sz, sz, -sz, 1, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX sz, sz, -sz, 0, 1, col
X_OBJADDVERTEX sz, -sz, -sz, 0, 0, col
X_OBJNEWGROUP
// Top Face
X_OBJADDVERTEX -sz, sz, sz, 0, 0, col
X_OBJADDVERTEX -sz, sz, -sz, 0, 1, col
X_OBJADDVERTEX sz, sz, sz, 1, 0, col
X_OBJADDVERTEX sz, sz, -sz, 1, 1, col
X_OBJNEWGROUP
// Bottom Face
X_OBJADDVERTEX sz, -sz, -sz, 0, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 1, col
X_OBJADDVERTEX sz, -sz, sz, 0, 0, col
X_OBJADDVERTEX -sz, -sz, sz, 1, 0, col
X_OBJNEWGROUP
// Right face
X_OBJADDVERTEX sz, sz, -sz, 1, 1, col
X_OBJADDVERTEX sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX sz, sz, sz, 0, 1, col
X_OBJADDVERTEX sz, -sz, sz, 0, 0, col
X_OBJNEWGROUP
// Left Face
X_OBJADDVERTEX -sz, -sz, sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz, -sz, 0, 0, col
X_OBJADDVERTEX -sz, sz, sz, 1, 1, col
X_OBJADDVERTEX -sz, sz, -sz, 0, 1, col
X_OBJNEWGROUP
X_OBJEND
ENDFUNCTION // sz
Oh gee, I ran your code, and definently dosen´t seem like anything remotely close to what I was bragging about. :( :-[
It actually behaves really weird, I will try to find anything that helps the issue.
The obstacle is hitting the lens because the field of view is too wide. Here's my modified FOV and matching speed demonstration code:
GLOBAL fov = 90
GLOBAL cam_offset = 0
GLOBAL speed = 1
//Mainloop
WHILE TRUE
IF NOT KEY(57) // spacebar (new)
cam_offset = -200
fov = 15
speed = 4
ELSE // (old)
cam_offset = 0
fov = 90
speed = 1
ENDIF
X_MAKE3D 1, 2000, fov
X_CAMERAUP 0,0,1
X_CAMERA cam.x + cam_offset, cam.y, cam.z, pl.x, pl.y, pl.z
//Draw skybox
Quote from: erico on 2015-Nov-03
I hope this helps. ( A,B,C, 1,2,3... :D)
:coke: aine ?
No, that was a mention about that michael song, it came to my mind looking at the big ABC letters on pic.
Damn I spent some time attempting, but I can´t even seem to make any light work with imported objects on latest glb.
Will the FOV fix the tunnel? I will look at your code.
i tried fov 15, but the shadow still dissapears when the camera is fully in the shadow, it only took a bit longer since you moved the camera -200. at this point the player sphere is already out of the obstacle shadow.
oh dear I just removed the skybox and now i get very weired results: i dont get any shadow at all... ... until i step infront of the obstacle.
lol, its like the opposite effect, the shadow is illuminated and appears when i step with the camera "inside it". completly the opposite and weired. Maybe its not a bug after all, but still its not working and i would need a skybox in any case :D
but probably it has something to do with the skybox, why should i not see a shadow in the first place when it is removed?
//Draw skybox
// X_CULLMODE -1
// X_DRAWOBJ skybox,0
// X_CLEAR_Z
// X_CULLMODE 1
Shadow without skybox when:
X_CULLMODE 1
ah yes i see, but just brings it back to the usual problem :)
Quote from: ProN3rd on 2015-Nov-04
ah yes i see, but just brings it back to the usual problem :)
The original issue seems solved to me. Note the more polys, the less gets clipped. Another CPU intensive task. :sick: :whistle: Sync code:
//Utility Class
TYPE Txyz
x;y;z
ENDTYPE
GLOBAL pl AS Txyz ; pl.x = -0; pl.y = 0; pl.z = 10 //Player
GLOBAL cam AS Txyz ; cam.x = -50; cam.y = 0; cam.z = 10 //Cam
GLOBAL li AS Txyz ; li.x = -100; li.y = -400; li.z = 500 //Light
GLOBAL pr AS Txyz ; pr.x = 0; pr.y = 0; pr.z = -250 //Road
GLOBAL po AS Txyz ; po.x = 100; po.y = -75; po.z = 0 //Obstacle (Wall)
//Create Objects
GLOBAL player = GENX_OBJ() ; CreateSphere(player,5, 36, RGB(255,0,0)) // added more sides for shadow resolution
GLOBAL skybox = GENX_OBJ() ; CreateCube(skybox,3000,RGB(40,40,100))
GLOBAL road = GENX_OBJ() ; CreateCube(road,500,RGB(100,100,100))
GLOBAL obstacle = GENX_OBJ() ; CreateCube(obstacle,100,RGB(130,50,130))
GLOBAL fov = 90
GLOBAL cam_offset = 0
GLOBAL speed = 1
//Mainloop
WHILE TRUE
IF NOT KEY(57) // no clipping - good
cam_offset = -200
fov = 15
speed = 4
ELSE // clipping - no good
cam_offset = 0
fov = 90
speed = 1
ENDIF
X_MAKE3D 1, 2000, fov
X_CAMERAUP 0,0,1
X_CAMERA cam.x + cam_offset, cam.y, cam.z, pl.x, pl.y, pl.z
X_CULLMODE 1
// X_ENABLE_Z TRUE
//Draw skybox
// X_CULLMODE -1
// X_DRAWOBJ skybox, 0
// X_CLEAR_Z
// X_CULLMODE 1
//Draw scene
X_MOVEMENT pr.x,pr.y,pr.z ; X_DRAWOBJ road,0
X_MOVEMENT pl.x,pl.y,pl.z ; X_DRAWOBJ player,0
X_MOVEMENT po.x,po.y,po.z ; X_DRAWOBJ obstacle,0
//Shadow light
X_SPOT_LT -3,0,li.x,li.y,li.z,0,0,0,360
//Draw scene again
X_MOVEMENT pr.x,pr.y,pr.z ; X_DRAWOBJ road,0
X_MOVEMENT pl.x,pl.y,pl.z ; X_DRAWOBJ player,0
X_MOVEMENT po.x,po.y,po.z ; X_DRAWOBJ obstacle,0
X_MAKE2D
SHOWSCREEN
//Movement Player
IF KEY(200); INC pl.x, speed; INC cam.x, speed; ENDIF
IF KEY(208); DEC pl.x, speed; DEC cam.x, speed; ENDIF
WEND
//Utility Functions
Quote from: matchy on 2015-Nov-04
Quote from: ProN3rd on 2015-Nov-04
ah yes i see, but just brings it back to the usual problem :)
The original issue seems solved to me. Note also, the more polys on the boxes, the less gets clipped and more shadow resolution. Another CPU intensive task. :sick: :whistle: Sync code:
//Utility Class
TYPE Txyz
x;y;z
ENDTYPE
GLOBAL pl AS Txyz ; pl.x = -0; pl.y = 0; pl.z = 10 //Player
GLOBAL cam AS Txyz ; cam.x = -50; cam.y = 0; cam.z = 10 //Cam
GLOBAL li AS Txyz ; li.x = -100; li.y = -400; li.z = 500 //Light
GLOBAL pr AS Txyz ; pr.x = 0; pr.y = 0; pr.z = -250 //Road
GLOBAL po AS Txyz ; po.x = 100; po.y = -75; po.z = 0 //Obstacle (Wall)
//Create Objects
GLOBAL player = GENX_OBJ() ; CreateSphere(player,5, 36, RGB(255,0,0)) // added more sides for shadow resolution
GLOBAL skybox = GENX_OBJ() ; CreateCube(skybox,3000,RGB(40,40,100))
GLOBAL road = GENX_OBJ() ; CreateCube(road,500,RGB(100,100,100))
GLOBAL obstacle = GENX_OBJ() ; CreateCube(obstacle,100,RGB(130,50,130))
GLOBAL fov = 90
GLOBAL cam_offset = 0
GLOBAL speed = 1
//Mainloop
WHILE TRUE
IF NOT KEY(57) // no clipping - good
cam_offset = -200
fov = 15
speed = 4
ELSE // clipping - no good
cam_offset = 0
fov = 90
speed = 1
ENDIF
X_MAKE3D 1, 2000, fov
X_CAMERAUP 0,0,1
X_CAMERA cam.x + cam_offset, cam.y, cam.z, pl.x, pl.y, pl.z
X_CULLMODE 1
// X_ENABLE_Z TRUE
//Draw skybox
// X_CULLMODE -1
// X_DRAWOBJ skybox, 0
// X_CLEAR_Z
// X_CULLMODE 1
//Draw scene
X_MOVEMENT pr.x,pr.y,pr.z ; X_DRAWOBJ road,0
X_MOVEMENT pl.x,pl.y,pl.z ; X_DRAWOBJ player,0
X_MOVEMENT po.x,po.y,po.z ; X_DRAWOBJ obstacle,0
//Shadow light
X_SPOT_LT -3,0,li.x,li.y,li.z,0,0,0,360
//Draw scene again
X_MOVEMENT pr.x,pr.y,pr.z ; X_DRAWOBJ road,0
X_MOVEMENT pl.x,pl.y,pl.z ; X_DRAWOBJ player,0
X_MOVEMENT po.x,po.y,po.z ; X_DRAWOBJ obstacle,0
X_MAKE2D
SHOWSCREEN
//Movement Player
IF KEY(200); INC pl.x, speed; INC cam.x, speed; ENDIF
IF KEY(208); DEC pl.x, speed; DEC cam.x, speed; ENDIF
WEND
//Utility Functions
Oh well, I tried it myself, found no solution, but here the test code.
Damn shadows, works fine till you get into its path,
-WASD to move camera, Q and E up and down.
-Arrows to move ball.
-5123 numpads to move light, 4 and 5 up and down.
That is what I get for being sure of the unknown. :-[ :x
edit:also, I could not get the imported objects to shade or take light at all. :(
Nice code structure ProN3rd!
You're FOV is high but now I'll also have a go at the experimental challenge of a straight raceway road with some tunnel like objects with the aim of no shade clipping or missing. :bed:
nice example erico, this is exactly what i mean. Stepping with the cam in the shadow makes the shadow disspear
do you think its a bug, or what could it possibly mean?
for fov, i think you cant choose values that are so low like 15. The scene will be totally distorted. I guess usual values range from 60-100?
Truly now I think it may be a bug, but I would not know for sure. (still trying to glup my ego on the last posts :puke:)
Heck, what is theory without practice anyways, I would not believe without code? ;/
Well, I tried many naive solutions, like extra objects and so on and nothing worked,
so I guess the baking/faking could do...
...but if you really must use this shadow system, I got into a way of it working but it restricts a lot. In case of your game, these restriction might not be a problem.
-Assume a fixed light position behind the camera, so that the shadows are projected towards the back of the stage.
(preferably, parent it to camera position so to simulate a linear light)
-keep the light positioned way up so that the rear part of the shadow is not too distorted in comparison to the front.
(you may need to use key 4 to push it up more then what is hardcoded)
-slice your tunnel like a bread bin, each part an object.
-try working with low POV so that you are visually into the shadow before the actual camera is.
Now, when you hit the shadow and it disapears, it is already outside the player´s view and it works.
You will need to play a lot with the elements to get what you want,
here is appended code with it working, use it with my last project, just add that GARAGEslice.ddd to media.
But I believe you get the idea.
edit: You might also be aware that while this works, while you are under a shadow, the player is being shaded but it does not cast its own shadows unless you are out of the shadow area. ye, camera in tunnel, player outside it without its own shadow. Haven´t tried a fix for this yet but you could simply stop drawing the shadow of the object that you are under its shadow and things should work out... it is already out of the camera view anyways :good: ;)
// --------------------------------- //
// Project: GLB3D
// Start: Wednesday, November 04, 2015
// IDE Version: 14.006
SETCURRENTDIR("Media")
// --- BOOT
X_LOADOBJ "WORLD.ddd",0 ; LOADSPRITE "WORLD.png",0
X_LOADOBJ "FLOOR.ddd",1 ; LOADSPRITE "FLOOR.png",1
X_LOADOBJ "PLAYER.ddd",2 ; LOADSPRITE "PLAYER.png",2
X_LOADOBJ "GARAGE.ddd",3 ; LOADSPRITE "GARAGE.png",3
X_LOADOBJ "BLOCO.ddd",4
X_LOADOBJ "BLOCOT.ddd",5
X_LOADOBJ "BLOCOU.ddd",6
X_LOADOBJ "GARAGEmask.ddd",7
X_LOADOBJ "GARAGEslice.ddd",8
LOADFONT "smalfont.png", 1
GLOBAL x,y,z, camx, camy ; x=0 ; y=10 ; z=80
GLOBAL xo,yo,zo
GLOBAL lx,ly,lz ; lx=100 ; ly=150 ; lz=75
// --------------------------------------------------------------- LOOP START
WHILE TRUE
// --- set 3d and camera
X_MAKE3D 1,2000,60
X_CAMERA x,y,z, x+camx,y+camy,z-1000
// --- draw
X_CULLMODE 1 //WORLD
X_SETTEXTURE 0,-1
X_DRAWOBJ 0,0
X_CLEAR_Z
X_FOG RGB(182,141,99),FALSE,25, 125
X_SETTEXTURE 1, -1 //FLOOR
X_DRAWOBJ 1,0
X_SETTEXTURE 2, -1 //PLAYER
X_MOVEMENT xo,yo,zo
X_DRAWOBJ 2,0
X_MOVEMENT 0,0,0
X_SETTEXTURE 3, -1 //GARAGE
//X_DRAWOBJ 3,0
//X_DRAWOBJ 7,0
X_DRAWOBJ 8,0
X_MOVEMENT 0,0,-11
X_DRAWOBJ 8,0
X_MOVEMENT 0,0,-22
X_DRAWOBJ 8,0
X_MOVEMENT 0,0,-33
X_DRAWOBJ 8,0
X_MOVEMENT 0,0,0
//blocks
//X_DRAWOBJ 4,0
//X_DRAWOBJ 5,0
//X_DRAWOBJ 6,0
// --- light
//X_AUTONORMALS 2
//X_AMBIENT_LT 0, RGB(255,255,255)
// X_SPOT_LT 1,RGB(255,0,0), x,y,z,0,0,0,360
X_SPOT_LT -3,RGB(0,0,0),x+750,y+2500,z+750, 0,0,0,360
// --- shadows
X_MOVEMENT xo,yo,zo
X_DRAWOBJ 2,0 //PLAYER
X_MOVEMENT 0,0,0
// X_DRAWOBJ 3,0 //GARAGE
// X_DRAWOBJ 7,0
// X_DRAWOBJ 4,0
// X_DRAWOBJ 5,0
// X_DRAWOBJ 6,0
IF z>28 THEN X_DRAWOBJ 8,0
X_MOVEMENT 0,0,-11
IF z>17 THEN X_DRAWOBJ 8,0
X_MOVEMENT 0,0,-22
IF z>6 THEN X_DRAWOBJ 8,0
X_MOVEMENT 0,0,-33
IF z>-5 THEN X_DRAWOBJ 8,0
X_MOVEMENT 0,0,0
// --- set 2d and print info
X_MAKE2D
SETFONT 1
PRINT x,0,0
PRINT y,0,20
PRINT z,0,40
PRINT camx,0,60
PRINT camy,0,80
PRINT xo,0,120
PRINT yo,0,140
PRINT zo,0,160
PRINT lx,0,200
PRINT ly,0,220
PRINT lz,0,240
// --- controls camera
//INC camx, MOUSEAXIS(0)
//DEC camy, MOUSEAXIS(1)
IF KEY(30)=1 THEN x=x-.5 //left KEY
IF KEY(32)=1 THEN x=x+.5 //right KEY
IF KEY(31)=1 THEN z=z+.5 //up key
IF KEY(17)=1 THEN z=z-.5 //down key
IF KEY(16)=1 THEN y=y-.5 // q
IF KEY(18)=1 THEN y=y+.5 // e
// --- controls player
IF KEY(203)=1 THEN xo=xo-.5 //left KEY
IF KEY(205)=1 THEN xo=xo+.5 //right KEY
IF KEY(208)=1 THEN zo=zo+.5 //up key
IF KEY(200)=1 THEN zo=zo-.5 //down key
// --- controls LIGHTS!
IF KEY(79)=1 THEN lx=lx-.5 //left KEY
IF KEY(81)=1 THEN lx=lx+.5 //right KEY
IF KEY(80)=1 THEN lz=lz+.5 //up key
IF KEY(76)=1 THEN lz=lz-.5 //down key
IF KEY(75)=1 THEN ly=ly+.5 //up key
IF KEY(77)=1 THEN ly=ly-.5 //down key
SHOWSCREEN
WEND
// --------------------------------------------------------------- LOOP END
Edit extra: updates the code so the slices behind the camera are off so not to cause problem to shadows on objects outside the tunnel. Move camera with WASD and player with arrows. Light is now parented to the camera.
Another thing you could try, so to keep a FOV high and/or a better balance all around, is to check if X_CAMERAUP helps on this front.
Is the shifted position affected? If not but the original, then you could rotate the whole world so as to use it as a "X_CAMERABACK" and it would give you more freedom.
I really hope this all helps out, I have had my mind into 3d in GLB for a while, all these experiments also help me clear up the catches. :)
thanks erico, this helps a lot, glad to hear you also making progress
i was so busy the last days gonna check this all out in detail later.
yes cameraup, is quite shifted, i prefer to move the camera instead of objects, i heared this doenst make a difference and camera movement is more logical to me, but i guess the usual way is to move objects. Not sure about that
Quote from: ProN3rd on 2015-Nov-04
...
oh dear I just removed the skybox and now i get very weired results: i dont get any shadow at all... ... until i step infront of the obstacle.
lol, its like the opposite effect, the shadow is illuminated and appears when i step with the camera "inside it". completly the opposite and weired. Maybe its not a bug after all, but still its not working and i would need a skybox in any case :D
but probably it has something to do with the skybox, why should i not see a shadow in the first place when it is removed?
...
You need to set the cullmode for shadows to happen, so if the polygons are facing outwards, which is correct, you get the shadow casted, if it is inverted, you will get that effect you described. The only way I believe this could happen on your case regarding the sky box, is that its cullmode is wrong, but that should not be a problem because you shall not re-render the skybox under the shadow light at all. Remember what you re-render on your scene after the shadow light are only the objects which are casting shadow, no need for the ones receiving it.
Notice on my code that I´m not re-rendering the floor neither the skybox, they both need no shadow casted, you may also add the X_CLEAR_Z command after you draw the skybox so you guarantee that it dosen´t receive shadows either.
Also, the skybox should have its surfaces facing inside, otherwise use cullmode 2 to ´flip´ it.
In my example I already modeled the cube the former way, so cullmode 1 works as it should.
Messing with realtime 3d is always fun. :good:
It's a ooooooold Problem! It was never fixed i guess...
Try to render with OpenGL.
i had some problems with clipping of the skybox and i read somewhere that i need the following Open GL Command to include right after i set the texture of the skycube:
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
if i could just find a way to make it work. :giveup: I have some example from the 2d scaling system which makes GL_LineWidth work, but i cant derive from that how I would figure out how to make the above commands work. Any help is very appreciated :nw:
I don´t understand what is your problem with the skybox.
Like in my code, isen´t just a matter of appending it to camera movement?
Where is the clipping?
sure it is, i think there is a misunderstanding, i mean not clipping, but edgeclamping.
If i was to use skybox-graphics for the cube, i would have either have to draw 8 objects (all of them being surfaces with different textures), or draw 1 cube-objects that uses a huge textures where each face has differnt texture coordinates.
for the first approach, all edges of the cube dont go smoothly into each other. The 2nd approach has only some edges run smoothly into each other.
The texture is simply not "clamped" to the edge of the surface. As far as i read in the internet this seems to be a commond problem that occurs especially on skyboxes. OpenGL therefore provides to command "Clamp_to_edge". However i do not know how to include it in GLBasic.
This is exactly what i mean: http://gamedev.stackexchange.com/questions/11931/skybox-texture-artifact-on-edge (http://gamedev.stackexchange.com/questions/11931/skybox-texture-artifact-on-edge) It describes the problem along with the solution and a screenshot.
I see, but that dosen´t happen on my testings, I´m using the second approach, a huge uvmapped imported cube.
I´m drawing it before lights, so it is always fully lit.
Do you think this could help you out?
I haven´t got a problem with clamping, since I switched to a sky cylinder,
if you want the code, just answer here.
No need it´s fine, if you wish, you can put it on snippets, so future chaps can check it out.
Glad everything is fine. :good:
that would be awesome nabz
lol i crashed my graphics card with too much shading -_-
so that topic is out of the question at least for now
but i found some very nice open gl examples in the snippets section, INLINE here i come :)
by the way, i tried many things to make a texture of irregular size (like 237*183) fit on a billbord rectangle surface but I seems like only texture sizes with a multiple of n^2 work correctly. Can anyone confirm this?