Sky Issues

Blitz3D Forums/Blitz3D Programming/Sky Issues

LKFX(Posted 2006) [#1]
Graphics3D 800,600,32,1
SetBuffer BackBuffer()
Global cam = CreateCamera()
PositionEntity cam,0,0,100
SkyBoxID = CreateCube() ;(camera)
ScaleMesh SkyBoxID,1000,1000,1000
FlipMesh SkyBoxID
EntityOrder SkyBoxID,1000
t=LoadTexture("sky02.bmp")
EntityTexture SkyBoxID,t
EntityFX SkyBoxID,1
PositionEntity SkyBoxID,0,0,0,-1000
ShowEntity SkyBoxID
CameraClsMode cam,0,1
While Not KeyHit(1)
TurnEntity SkyBoxid,0,.1,0
UpdateWorld
RenderWorld
Flip
Wend
End

The code makes a sky box and turns it, but my texture goes all mental and you can see the visble lines of the skybox, sky boxs are new to me any help would be appreciated....

LKFX
"if we were ment to go to war, we would have been born with green baggy skin"


Ross C(Posted 2006) [#2]
Firstly, i wouldn't use a blitz cube as a skybox. Mainly because your going to have problems texturing it.

Try this function. I can't remember where it came from, but i used it one of my projects. You call the function and it will create a skybox, based on the textures you pass.

Function create_skybox(f$,r$, b$,l$, t$, bt$, sx, sy, sz);front right back left top bottom scalex,y,z
    mesh = CreateMesh()

    ;front face
    brush = LoadBrush(f$,49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,-1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,-1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;right face
    brush = LoadBrush(r$,49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,-1,0,0
    AddVertex surface,+1,+1,+1,1,0
    AddVertex surface,+1,-1,+1,1,1
    AddVertex surface,+1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;back face
    brush = LoadBrush(b$,49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,-1,+1,+1,1,0
    AddVertex surface,-1,-1,+1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
 
    ;left face
    brush = LoadBrush(l$,49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,0
    AddVertex surface,-1,+1,-1,1,0
    AddVertex surface,-1,-1,-1,1,1
    AddVertex surface,-1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;top face
    brush = LoadBrush(t$,49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,1
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,-1,+1,-1,1,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
   
    ;bottom face 
    brush = LoadBrush(bt$,49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,-1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddVertex surface,-1,-1,+1,0,0
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
    
    ScaleMesh mesh,sx,sy,sz
    FlipMesh mesh
    EntityFX mesh,1+4+8; make fullbright
    Return mesh
End Function


You would do this to use this function. Just as you would to load a texture, include the file name of the texture for the TOP, BOTTOM, LEFT, RIGHT, FRONT and BACK sides, followed by an X Y and Z scale. The function does the rest. In the below example, the skybox would now by assigned the the variable "skybox"

Global skybox = create_skyBox("level1\sky_front.png","level1\sky_right.png","level1\sky_back.png","level1\sky_left.png", "level1\sky_top.png", "level1\sky_bottom.png",350,150,350)



Mustang(Posted 2006) [#3]
Also your skybox can be sized 1*1*1 if you use EntityOrder to draw it first, before any other 3D content. That way you might save some CameraRange. Also be sure to position the box EXACTLY where your active camera is... skybox only works correctly like that.


LKFX(Posted 2006) [#4]
thanks guys it looks much better lol.

i can just see the join lines where the textures are though is there away to avoid this?

I done EntityOrder skybox,1 is this right so it gets drawn first?

My sky box is in the same postion as my camera, not sure what you ment Mustang about your skybox can be sized 1*1*1, my textures are 512x512 so thats what i have scaled my mesh to.

It all looks better apart from the texture seams.


Mustang(Posted 2006) [#5]
loadbrush with 1+16+32(49) should clamp the UVs and prevent half pixel texture bleed... above code also makes it fullright ie disabling lighting. Only thing left I can think of is that your skybox textures are not correctly rendered - you need to render the with 90 deg FoV (field of vision) so that they would look correct when mapped to a box... you're effectively "baking" a 360 sphere (map) to a cube. And you can't handdraw those textures because of the needed distortion.

You can always use a cylinder or hemisphere with cylinderical mapping too if the camera doesn't look up. Both these sky types use maps that you can handdraw because they are like panorama images, more or less.

1*1*1 just meant that the cube can be really tiny, even 1cm * 1cm *1cm because it's drawn first - scale is irrelevant then.


LKFX(Posted 2006) [#6]
thanks mustang, i will have a play with it.


LKFX(Posted 2006) [#7]
Im using the load brush routine from ross which is

brush = LoadBrush(f$,49)

where would i put 1+16+32 ?


LKFX(Posted 2006) [#8]
also is there any good software for baking textures..


John J.(Posted 2006) [#9]
LKFX: I get visible seams frequently when a skybox uses a coordinate system different than Blitz's. The way to fix this is usually to apply the faces to the skybox differently. Try this:

Apply right.jpg (or whatever) to you forward (+z) cube face.
Apply left.jpg to your rear (-z) cube face
Apply front.jpg to your left (-x) cube face
Apply rear.jpg to your right (+x) cube face

... and leave the up and down cube facce as they are.

Im using the load brush routine from ross which is

brush = LoadBrush(f$,49)

where would i put 1+16+32 ?

The 1+16+32 goes in place of the "49"


LKFX(Posted 2006) [#10]
im going to try unwrap3d program see what that does....


Mustang(Posted 2006) [#11]
1+16+32 = 49, doesn't matter which one you use... the x+x+x-- way is just more clear to me.

http://www.blitzbasic.com/b3ddocs/command.php?name=LoadBrush&ref=3d_cat