Sign in to follow this  
FMDGames

Space Environment

Recommended Posts

FMDGames    134
Hey there, I am using the DirectX 9 API in C++. I am working in a team to create a space based massively multiplayer online roll playing game. The problem i have is that i wish to create a space environment with stars etc. I was advised that a way to do this is by using a sphere, and map a texture on the sphere. My first question is if i texture the sphere, will the textures be visable from inside the sphere (which is where all the objects of the game will be located). The sphere will be huge. If this is a good way to do it, could someone explain how it can be achieved, as i have got some 3d models, and when the camera is placed inside, the model textures cannot be seen. If there is another way to do this, please explain this also. I am a relatively new directx developer, and this is my first project. Thank you for reading my post ;)

Share this post


Link to post
Share on other sites
HanSoL0    1210
Hi there FMD, welcome to GameDev. There's a special place in my heart for space games (check my sig for my game [smile]). The way we render outer space in my game is inside a cube. Take a cube and flip the normals so the polygons are actually facing in. Then place the camera in the center of cube, and texture the inside with six nice space backdrop textures. Then you have to make sure the camera never leaves the exact center of the cube so you can maintain the illusion that you're surrounded by space. If you do a search on here for "skyboxes", you'll find all kinds of info. I think the DirectX SDK even has a demo application explaining skyboxes. Check out the video of my game to see how this works.

Much luck to you on your project! Have a great day,

Share this post


Link to post
Share on other sites
FMDGames    134
Hmm, ive got a problem with lighting, before i flip the cube, i can see the textures, after tho, i cant. It seems to be a lighting problem. Would you be able to post some source code to help me as this is being un-cooperative. :( Oh and i did move the camera before anyone asks :P

Thanks :)

Share this post


Link to post
Share on other sites
rKallmeyer    396
I use the same technique as HanSoL0 so I might be able to help. There are a few things I can think of that might be your problem.

By "flipping textures" do you mean "flipping normals" because flipping normals is what you need to do. Try turning off backface culling to see if this is your problem.

You should turn off lighting when rendering your star skybox.

I might not be understanding what the problem is so you might want to post a screen shot.

Check the bottom of the Screenshots section for some examples

Share this post


Link to post
Share on other sites
HanSoL0    1210
Quote:
Original post by Nuget5555
Try turning off backface culling to see if this is your problem.

My money is on that one. I remember having that problem way back when I implimented my skybox, and all I had to do was either turn off backface culling, or reverse the order.

Share this post


Link to post
Share on other sites
rKallmeyer    396
Posting an example from my code probably wouldn't help you because the interfaces/data structions/general flow might be completely different.

However if you post what you are having problems with (setting states, textures, and rendering the skybox) it would be much easier to find problem and help you fix it.

Share this post


Link to post
Share on other sites
dhanji    192
Im partial to sprites myself, simulating a skybox with a repeating sprite is

a) faster on the FFP
b) uses TnL vertices by default
c) gives u better simulation of a background (9 faces vs. 6)
d) requires no normal/culling state change costs

Of course you can argue that all these are pretty insignificant on faster cards, and you'd be right...

as for your problem have you tried disabling lighting and setting the ambient light color to bright white? Also make sure your box is big enough and not z-fighting with some other mesh..

EDIT: to flip the normals on a mesh change the D3DRS_CULLMODE renderstate to CCW or CW (one is flipped, one is unflipped, depending on your face data..)

Share this post


Link to post
Share on other sites
FMDGames    134
I disabled culling, so this shouldnt make any difference :S but still cant see anything. It must be a lighting problem then. If i disable lighting, i can see the sphere but not the texture and i dont see anything when i move the camera inside the cube.

Share this post


Link to post
Share on other sites
FMDGames    134
bool Setup() //Setup SkyBox & Lights Etc
{
Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
HRESULT hr = 0;
hr = D3DXCreateSphere(
Device,
1.0f,
60,
60,
&Mesh,
0);
if(FAILED(hr))
{
::MessageBox(0, "D3DXCreateMesh() - FAILED", 0, 0);
return false;
}
hr = D3DXCreateTextureFromFile(
Device,
"texture.jpg",
&Tex);

if(FAILED(hr))
{
::MessageBox(0, "D3DXCreateTexture() - FAILED", 0, 0);
return false;
}


Device->SetTexture(0,Tex);

Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

//
// Set Lights.
//

D3DLIGHT9 light;
::ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Ambient = d3d::WHITE;
light.Diffuse = d3d::WHITE;
light.Specular = d3d::BLACK;
light.Direction = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
Device->SetLight(0, &light);
Device->LightEnable(0, true);

Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
Device->SetRenderState(D3DRS_SPECULARENABLE, true);
//
// Set camera.
//

D3DXVECTOR3 pos(0.0f, 0.0f, 0.1f);
D3DXVECTOR3 target(0.0f, 0.0f, 1.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

D3DXMATRIX V;
D3DXMatrixLookAtLH(
&V,
&pos,
&target,
&up);

Device->SetTransform(D3DTS_VIEW, &V);

//
// Set projection matrix.
//

D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)Width / (float)Height,
1.0f,
1000.0f);
Device->SetTransform(D3DTS_PROJECTION, &proj);

return true;
} //End of Setup

bool Display(float timeDelta)
{
if( Device ) // Only use Device methods if we have a valid device.
{

//
// Render
//

Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xfffffff, 1.0f, 0);
Device->BeginScene();

Device->SetMaterial(&d3d::WHITE_MTRL);
Device->SetTexture(0, Tex);
Mesh->DrawSubset(0);


Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}



[The Display method is called from the WinMain function]

This is a small bit of code. Not all references are declared.

Edited by Coder: source tags

[Edited by - FMDGames on August 4, 2004 4:17:12 PM]

Share this post


Link to post
Share on other sites
HanSoL0    1210
The reason you can't see the inside of the sphere is because polygons are one-sided. They're only solid on one side. If you look at a polygon from the rear, it's invisible.

I can't see where you're loading or rendering your cube. Did you leave that part out?

To turn off backface culling, use this:
Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

Share this post


Link to post
Share on other sites
FMDGames    134
Its most likey the fact im using D3DXCreateSphere()... I couldnt get it to work on the cube either... I tried it on a sphere my 3d artist created and it textured it, but only on the outside and not on the inside. Only thing changed was the mesh was loaded instead of created.

Share this post


Link to post
Share on other sites
HanSoL0    1210
The reason your generated sphere isn't textured is because the D3DXCreateSphere() function creates a mesh using the D3DFVF_XYZ | D3DFVF_NORMAL FVF - there are no texture coordinates generated, so a texture won't be used on these vertices.

Again, your artist is going to need to flip the normals on the cube or sphere or whatever, or else you will not be able to see the object from the inside.

Share this post


Link to post
Share on other sites
FMDGames    134
He did try, but he cant seem to work it out. Two of the spheres he sent me i could see outside, two of the spheres i couldnt see outside. But i cant see any on the inside :S. My guess is it must be a lighting problem.

Share this post


Link to post
Share on other sites
HanSoL0    1210
More than likely, if it was a lighting problem, you wouldn't be able to see any meshes ever. What program are you using to create your meshes? What format are you loading them into your application in?

Share this post


Link to post
Share on other sites
helix    301
Quote:
Original post by HanSoL0
Check out the video of my game to see how this works.


Nice trailer. That's very similar to what my little space game was supposed to be like (but mine is way more stripped down) but I just can't seem to get my spaceship and camera to behave nicely together like yours. :(

Share this post


Link to post
Share on other sites
rKallmeyer    396
maya has a very simple command to flip normals. I can't remember it exactly but heres the jist of it.

[space menu] > polygons > texturing > reverse-normals

Try loading your meshes into MeshView that comes with the SDK. If you get the same problem as you do in your program then you can be sure your meshes are to blame.

Share this post


Link to post
Share on other sites
FMDGames    134
I finnaly got it to work after a combination of some new spheres, playing with lighting, and playing with the camera. It looks good, but the texture isnt that good so ill get a new texture soon.

Thanks to all that helped!

Share this post


Link to post
Share on other sites
Mushu    1396
This code works and renders a whole mesh?

Device->SetMaterial(&d3d::WHITE_MTRL);
Device->SetTexture(0, Tex);
Mesh->DrawSubset(0);

That will only render one polygon. Maybe I'm wrong. But you got it to work anyway, so good job! When I used a cube to display space I ended up seeing the edges, no matter how detailed the texture or size of the cube. So I ended up using a sphere (which it seems you're using too). Good luck with the rest of your project.

Share this post


Link to post
Share on other sites
Pinzmon    127
Quote:
...This code works and renders a whole mesh?


Device->SetMaterial(&d3d::WHITE_MTRL);
Device->SetTexture(0, Tex);
Mesh->DrawSubset(0);

That will only render one polygon. Maybe I'm wrong. ...




Yep, you are wrong :)

My tips for rendering skyboxes/spheres, in semi-pseudocode:

skySphere.Location = Camera.Location //BUT! skySphere.Rotation != Camera.Rotation

//Always render the skysphere first, with zbuffer writes disabled, so it is always behind everything else.

renderstates.lighting = false;
renderstates.zbufferwriteenable = false;
skySphere.Render()
renderstates.zbufferwriteenable = true;
renderstates.lighting = true;

Share this post


Link to post
Share on other sites
FMDGames    134
The only problem i have with that is that i if i disable lighting, the texture cannot be seen, and all you do see is a black screen, of inside the sphere :S.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this