SkySphere for TSE
by Chris Schletter · in Torque Game Engine Advanced · 10/20/2005 (2:04 pm) · 40 replies
Ok,
Let me preface this with the assertion that I am a novice at 3D programming; I've spent my entire career in the business software development world. That being said...
I have been looking at doing space environments in Torque, and originally started with TGE, but since I wasn't too far along I decided to go ahead and just do everything with TSE. Originally I wasn't too worried about the skybox as I was just going to use a black skybox and dynamically place stars based on known stars and deep space object positions; however that is a lot of stars that need to be accounted for based on where you are looking in the night sky and I felt for background it probably wasn't the ideal situation; at least to start with.
I decided that I needed some type of skybox, so I started to convert the www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3007 "space"box over to TSE. I was successful at this, as it wasn't too hard, however I did decide to go ahead and create a skysphere after reading as much stuff as I could (and could understand, since all my hard fought for math skills have evaporated in the years since college). I did find the www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6644 but attempts to convert it met with unsatisfactory results. I ended up creating a skysphere based on the alogrithm found at astronomy.swin.edu.au/~pbourke/opengl/sphere to produce the Space class as a sphere with . At this point it only uses a single texture that is, a power of 2 of course, 2x1 in dimensions. It of course has the issue with scrunching the texture at the poles.
To use the code, you'll need to do the following:
a) Install the starter.fps for TSE from www.garagegames.com/mg/forums/result.thread.php?qt=33640.
b) Unzip the space.zip to your root TSE folder. The zip can be gotten from www.thzero.com/programming/torque/TSESkySphere.zip
c) Add the space.cpp and space.h files to your TorqueShaderEngine project in the Source Files\terrain folder.
d) Recompile the TorqueShaderEngine project.
e) Start up TSE with starter.fps and open the mission editor and load the space.mis. It should successfully load the mission, without terrain, and a skysphere with the MilkyWay galaxy displayed in all its glory.
There are a couple issues:
a) the poles are not north/south oriented. I am not sure why, nor can I seemingly get it to rotate. Kinda frustrating, since I originally wrote this in a simple OpenGL app and it was oriented correctly. If anyone has any ideas on this....
b) The fore-mentioned scrunching of the texture around the poles.
If anyone knows of a solid algo for doing a textured geosphere, please let me know, as I have not found one in scouring the 'net. This would solve the issue with the textures as all the triangles that make up the sphere are the same size.
Also, if you have any comments or suggestions for alpha blending of variety of textures, performance enhancements, etc. let me know.

Let me preface this with the assertion that I am a novice at 3D programming; I've spent my entire career in the business software development world. That being said...
I have been looking at doing space environments in Torque, and originally started with TGE, but since I wasn't too far along I decided to go ahead and just do everything with TSE. Originally I wasn't too worried about the skybox as I was just going to use a black skybox and dynamically place stars based on known stars and deep space object positions; however that is a lot of stars that need to be accounted for based on where you are looking in the night sky and I felt for background it probably wasn't the ideal situation; at least to start with.
I decided that I needed some type of skybox, so I started to convert the www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3007 "space"box over to TSE. I was successful at this, as it wasn't too hard, however I did decide to go ahead and create a skysphere after reading as much stuff as I could (and could understand, since all my hard fought for math skills have evaporated in the years since college). I did find the www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6644 but attempts to convert it met with unsatisfactory results. I ended up creating a skysphere based on the alogrithm found at astronomy.swin.edu.au/~pbourke/opengl/sphere to produce the Space class as a sphere with . At this point it only uses a single texture that is, a power of 2 of course, 2x1 in dimensions. It of course has the issue with scrunching the texture at the poles.
To use the code, you'll need to do the following:
a) Install the starter.fps for TSE from www.garagegames.com/mg/forums/result.thread.php?qt=33640.
b) Unzip the space.zip to your root TSE folder. The zip can be gotten from www.thzero.com/programming/torque/TSESkySphere.zip
c) Add the space.cpp and space.h files to your TorqueShaderEngine project in the Source Files\terrain folder.
d) Recompile the TorqueShaderEngine project.
e) Start up TSE with starter.fps and open the mission editor and load the space.mis. It should successfully load the mission, without terrain, and a skysphere with the MilkyWay galaxy displayed in all its glory.
There are a couple issues:
a) the poles are not north/south oriented. I am not sure why, nor can I seemingly get it to rotate. Kinda frustrating, since I originally wrote this in a simple OpenGL app and it was oriented correctly. If anyone has any ideas on this....
b) The fore-mentioned scrunching of the texture around the poles.
If anyone knows of a solid algo for doing a textured geosphere, please let me know, as I have not found one in scouring the 'net. This would solve the issue with the textures as all the triangles that make up the sphere are the same size.
Also, if you have any comments or suggestions for alpha blending of variety of textures, performance enhancements, etc. let me know.

About the author
#22
JS
03/11/2006 (10:18 am)
There is no reference to a "SpaceTexture" in the material.h that you supplied in the .rar file. (I get the same error as Wayne)JS
#23
Looks really realistic Chris, thanks a lot. This is critical to my project.
JS
03/11/2006 (12:17 pm)
Ah! I got it. Fairly simple fix, just put "SpaceTexture," into the "enum TextureHandleType function in materialList.h, not in material.h. Looks really realistic Chris, thanks a lot. This is critical to my project.
JS
#24
03/11/2006 (4:51 pm)
Jack, that did it thanks. and great resorce Chris Thanks
#25
I'll correct that ASAP. Must have pulled it in my hurry out of the wrong source.
And thanks, can't really take that much credit from it. It also has issues, because of the triangles near the north/south poles are much smaller than those around the equator where it smooshes the textures and can cause issues.
I'm trying to get a texture mapped geosphere to work instead for it. If anyone has ideas or code snippets (or Mike you have a handy resource for Milkshape's SimpleMeshFormat)....
03/11/2006 (6:21 pm)
Mms, ok.I'll correct that ASAP. Must have pulled it in my hurry out of the wrong source.
And thanks, can't really take that much credit from it. It also has issues, because of the triangles near the north/south poles are much smaller than those around the equator where it smooshes the textures and can cause issues.
I'm trying to get a texture mapped geosphere to work instead for it. If anyone has ideas or code snippets (or Mike you have a handy resource for Milkshape's SimpleMeshFormat)....
#26
I remember stock TGE/TSE has a problem whereby descending down below a certain point causes the skybox to dissapear, it just goes grey, and I was testing to see if this would happen with the skysphere as well, and got this crash. Just wondering if its my copy of the engine, or a some other bug.
Thanks,
JS
03/11/2006 (8:56 pm)
I wonder can either of you confirm an error Im getting. When you descend below a certain distance in the skysphere, It crashes the engine, and mentions an error in PrimBuilder.cpp? I remember stock TGE/TSE has a problem whereby descending down below a certain point causes the skybox to dissapear, it just goes grey, and I was testing to see if this would happen with the skysphere as well, and got this crash. Just wondering if its my copy of the engine, or a some other bug.
Thanks,
JS
#27
I would really like to know where you got the galaxy.jpg... Is there a way to create that stretching effect on the picture with Photoshop or a tutorial. Me == Programmer != Artist
01/18/2007 (3:30 am)
Has anyone done more work on this? I implemented this into my TSE too. Works nifty! I would really like to know where you got the galaxy.jpg... Is there a way to create that stretching effect on the picture with Photoshop or a tutorial. Me == Programmer != Artist
#28
Anyone interested in this? I would really like to know how to get my own pictures in now.
Pllleaaaase... im begging here!
01/23/2007 (8:39 am)
Okay.. I've ported this to TSE Milestone 4. Was very simple actually. Anyone interested in this? I would really like to know how to get my own pictures in now.
Pllleaaaase... im begging here!
#29
01/23/2007 (8:19 pm)
I wouldn't mind taking a look at it. =)
#30
It's really getting to me.
Anyway here the files (for TSE MS4):
space.h
space.cpp
I'm adding the stars in now using this resource. I looks alot better that way. Have a look at Mike Kuklinski's plan of Kuiper.
01/24/2007 (12:10 am)
This is the second resource that offers no support with the Images... It's really getting to me.
Anyway here the files (for TSE MS4):
space.h
space.cpp
I'm adding the stars in now using this resource. I looks alot better that way. Have a look at Mike Kuklinski's plan of Kuiper.
#31
This was not a resource. It was a post that shows the basics on how to do something. In this case it was a port of Mike's original resource to TSE from TGE but it dynamically generates the coords of the sphere. Both suffer from a problem though and if you view the sphere in wireframe you'll see what it is. It'd be better to generate the sphere as a tesselated icosahedron.
As for the image, um, its pretty easy to find the galaxy.jpg thats in the zip file. Put a different image in its place will change the background of the sphere.
01/24/2007 (5:16 am)
James,This was not a resource. It was a post that shows the basics on how to do something. In this case it was a port of Mike's original resource to TSE from TGE but it dynamically generates the coords of the sphere. Both suffer from a problem though and if you view the sphere in wireframe you'll see what it is. It'd be better to generate the sphere as a tesselated icosahedron.
As for the image, um, its pretty easy to find the galaxy.jpg thats in the zip file. Put a different image in its place will change the background of the sphere.
#32
I'll have a look at the problem as you describe in using a tesselated icosahedron.
My problem with the images is not that I cant find one. I have created a bunch of backgrounds.
When I look at this image I notice that it get stretched towards the north a south. It totally makes sense as to why it should do it. I just would like to know how to create that effect on a normal picture. im sure it's simple. But I have no solid Photoshop experience.
01/24/2007 (9:37 pm)
For something that was not a "resource" it is still pretty resourceful :-PI'll have a look at the problem as you describe in using a tesselated icosahedron.
My problem with the images is not that I cant find one. I have created a bunch of backgrounds.
When I look at this image I notice that it get stretched towards the north a south. It totally makes sense as to why it should do it. I just would like to know how to create that effect on a normal picture. im sure it's simple. But I have no solid Photoshop experience.
#33
Anyways, tesselated icosahedron would solve that issue. As a quicky here is a simple OpenGL implementation outline (http://www.glprogramming.com/red/chapter02.html) for it.
Personally I haven't had any time to invest into all of this... and have been holding off to see what they do with Torque X and 3D because frankly for a space sim I don't need the terrain, etc. :)
01/24/2007 (9:42 pm)
Uncomment the area in the skysphere.cpp so that it renders as a wireframe and you'll see exactly what the problem is with the north-south stretching. Actually, both this code and Mike's original, have the north/south axis of the sphere going east/west in when actually rendered.Anyways, tesselated icosahedron would solve that issue. As a quicky here is a simple OpenGL implementation outline (http://www.glprogramming.com/red/chapter02.html) for it.
Personally I haven't had any time to invest into all of this... and have been holding off to see what they do with Torque X and 3D because frankly for a space sim I don't need the terrain, etc. :)
#34
Once again my problem would be into taking my textures and making them that format (Tesselated). Gonna give it a shot anyway.
01/25/2007 (12:26 am)
Dunno if you've noticed... But there is an createIcosahedron function in "engine/game/sphere.cpp". I see what you mean by the stretching, and how an icosahedron would fix that. Once again my problem would be into taking my textures and making them that format (Tesselated). Gonna give it a shot anyway.
#35
Has to do with checking the vertex bounds. Any help would be greatly appreciated. I was planning on writing up an article about it in TDN to help others once I figured it out.
02/20/2007 (8:48 pm)
Anyone get the resources here working correctly on TGEA 1.0? I'm reporting the same error as Jack was with the PrimBuilder error.Has to do with checking the vertex bounds. Any help would be greatly appreciated. I was planning on writing up an article about it in TDN to help others once I figured it out.
#36
08/24/2007 (9:43 am)
Hi, I'm running TGEA 1.0.1 and I've pulled the latest versions of starter.fps and this zip file, but I'm still getting an entirely pink environment on load. I read through the thread and checked to make sure the aforementioned fixes were in and everything looked fine, is anyone else still having this issue?
#37
08/26/2007 (3:12 am)
Try making your visibledistance (variable) less something like 25000. Remember that there are other places in the engine the visible distance is get from, eg. tsEditctrl.cpp (if i remember correctly).
#38
netGhost.cpp, sceneObject.cpp, and sky.cpp, but everything is still coming in pink - is there anything in the console output that would help me figure out what could possibly be going wrong? There are only a few warning messages coming in:
in the Loading Mods section:
Missing file: common/defaults.cs!
Initializing MOD: FPS Starter Kit
Warning, overwriting material properties for: grass
Warning, overwriting material properties for: patchy
Initializing MOD: Torque Demo Client
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainV.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainP.hlsl'?
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS20V.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS20P.hlsl'?
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11AV.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11AP.hlsl'?
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11BV.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11BP.hlsl'?
Warning, overwriting material properties for: foliage
Warning, overwriting material properties for: stone
08/27/2007 (7:06 am)
I've changed what distance variables I've found (except the mods) to 25000 in editTSCtrl.cpp, sceneGraph.cpp,netGhost.cpp, sceneObject.cpp, and sky.cpp, but everything is still coming in pink - is there anything in the console output that would help me figure out what could possibly be going wrong? There are only a few warning messages coming in:
in the Loading Mods section:
Missing file: common/defaults.cs!
Initializing MOD: FPS Starter Kit
Warning, overwriting material properties for: grass
Warning, overwriting material properties for: patchy
Initializing MOD: Torque Demo Client
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainV.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainP.hlsl'?
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS20V.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS20P.hlsl'?
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11AV.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11AP.hlsl'?
GFXD3DShader::initVertShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11BV.hlsl'?
GFXD3DShader::initVertShader - unable to compile shader!
GFXD3DShader::initPixShader - no compiled code produced; possibly missing file 'shaders/terrainBlenderPS11BP.hlsl'?
Warning, overwriting material properties for: foliage
Warning, overwriting material properties for: stone
#39
08/27/2007 (8:21 am)
Do you have the April 2007 DirectX SDK installed?
#40
08/27/2007 (8:41 am)
I downloaded the latest DirectX a few weeks ago which I believe was a June release.
Torque Owner Chris Schletter