Archived

This topic is now archived and is closed to further replies.

Ilici

Space simulation problems and more... (+screenshots)

Recommended Posts

Ilici    862
I'm working on a space simulation and i've ran into some troubles: 1. When texturing a spherical planet i get these seams: I'm generating the sphere like this:
	float polyAng = 2.0f * PI / sides;
	float ang;

	float vx, vy, vz;
	int i, j;

	for (j = 0; j <= slices; j++)
	{
		ang = j * PI / slices - PI / 2.0f;
		for (i = 0; i <= sides; i++)
		{						
			vx = cos(i * polyAng) * cos(ang);
			vy = sin(ang);
			vz = sin(i * polyAng) * cos(ang);

			Vertices[j * sides + i].x = vx;
			Vertices[j * sides + i].z = vz;
			Vertices[j * sides + i].y = vy;

			TexCoords[j * sides + i].x = atan2(vx, vz) / (2 * PI) + 0.5f ; // //(float) i / sides;

			if (TexCoords[j * sides + i].x >= 1.0f) TexCoords[j * sides + i].x = 0.999f;
			TexCoords[j * sides + i].y = asin(vy) / PI + 0.5f; ////(float) j / slices;


			Normals[j * sides + i] = Vertices[j * sides + j];
		}
	}
	
	int ind = 0;
	for (j = 1; j <= sides; j++)
	{
		for (i = 0; i <= sides; i++)
		{			
			Indices[ind++] = (j - 1) * sides + i;
			Indices[ind++] =  j      * sides + i;
		}
	}	
Any ideeas? 2. I'm trying to implement some LOD technique to the planets in the following way: Calculate the visual error using that formula, then if it is greater than some treshhold, change to a more tesseled model. How to calculate rp (the projected radius)? I have D and R and the two planes of the view frustum. 3. How do i determine the visibiliy of a sphere to know how much of it is occluded. I want to be able to make a nice fade for the flare as more and more of the sun is obscured ^^ WRONG ^^ 4. How would i go about adding some nebulas? A box would seem a good ideea but how to generate one? I'd appreciate any ideeas to improve the look of the scene ! [ My Site ] [A link to gamedev] [A Link to google] [A link to nowhere] [ /*ilici*/ ] [edited by - Ilici on March 20, 2004 6:10:40 PM]

Share this post


Link to post
Share on other sites
mattnewport    1038
I would guess your texturing problem is because you''ve got the wrong wrapping mode set. Don''t know if you''re using D3D or OpenGL but in D3D you need to set the wrapping render state:
d3dDevice->SetRenderState(D3DRS_WRAPn  , D3DWRAPCOORD_n  ); 
for the texture coordinate set you''re using and the direction you want to enable wrapping in. This tells D3D to interpolate texture coordinates such that the shortest distance from 0.99 to 0.01 is to wrap around 1.0 rather than to work backwards from .99 to .01 - what you''re seeing in your screenshot is the whole of the texture from near the right edge back to the left edge compressed across one band of triangles. Note that this is different from the wrap texture addressing mode which tells D3D how to handle coordinates outside the 0-1 range (by tiling, mirroring, clamping etc.)

Share this post


Link to post
Share on other sites
Ilici    862


this is how it looks now - added a skybox with the nebula textures and motion blur on the stars

I''m using OpenGL, mattnewpor and since i''m doing the tex coords manually i need another solution.

One question about lighting though:


float lp[4] = {0.0f, 0.0f, 0.0f, 1.0f };
float lc[4] = {1.0f, 1.0f, 1.0f, 1.0f };
float la[4] = {0.0f, 0.0f, 0.0f, 1.0f };

glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lp);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lc);
glLightfv(GL_LIGHT0, GL_AMBIENT, la);


This should create a point light right?

Where should i call glLightfv, right before rendering the sphere, before setting up the camera (gluLookAt), or somewhere else?




Share this post


Link to post
Share on other sites
mattnewport    1038
quote:
Original post by Ilici
I''m using OpenGL, mattnewpor and since i''m doing the tex coords manually i need another solution.


There must be some equivalent to the D3DRS_WRAP state that you can set in OpenGL, afraid I can''t help you with what it is though. Not sure what you mean when you say you need another solution because you''re doing the tex coords manually? This render state isn''t about D3D generating tex coords for you, it just sets up the render state so the card knows how it should handle interpolation of tex coords. It should work if you can find the equivalent state setting call for GL.

Share this post


Link to post
Share on other sites
CraZeE    217
cool effect. btw, how did u actually do the atmospheric glow? nice work so far. and the sun glare.. is it dynamic or just a texture effect for now?

Share this post


Link to post
Share on other sites
Ilici    862
quote:
Original post by CraZeE
cool effect. btw, how did u actually do the atmospheric glow? nice work so far. and the sun glare.. is it dynamic or just a texture effect for now?


The atmospheric glow is just a billboard with a texture gradient made in Photopaint.

The sun flare is another billboard with a texture i got off the net.

Thanx for the comments!

Share this post


Link to post
Share on other sites
Eelco    301
regarding the error calculations: i got something working, maybe its of use to you too.

it calculates the error projected on a sphere, not onto the camera plane, because that gave me the problem of a rotating camera potentionally producing a lot of huge errors. this also means there are no lod chances when rotating the camera, which is a good thing imho.


; calculate error
mx# = (e\v1\wx + e\v2\wx) / 2
my# = (e\v1\wy + e\v2\wy) / 2
mz# = (e\v1\wz + e\v2\wz) / 2

cx# = mx - camerax
cy# = my - cameray
cz# = mz - cameraz

dx# = mx * (1-e\mul)
dy# = my * (1-e\mul)
dz# = mz * (1-e\mul)

m2# = (cx^2 + cy^2 + cz^2)

cx# = cy*dz - cz*dy
cy# = cz*dx - cx*dz
cz# = cx*dy - cy*dx

e\error = Sqr(cx*cx + cy*cy + cz*cz) / m2 ;actual error


the vector m is the midpoint of an edge, c is the vector from the camera to this midpoint, d is the errorvector in worldspace, and the rest should be not too hard too understand.

Share this post


Link to post
Share on other sites
fractoid    703
erm... try this?

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


Damn, why is the source box so big when it''s only two lines?

Share this post


Link to post
Share on other sites
Rattlehead    122
I can''t really help out with the original question, but I wanted to say that those screenies are sweet!

If the planet had a night side (maybe with lighted cities?) it would be just about perfect...

Rattlehead

Share this post


Link to post
Share on other sites
Ilici    862
quote:
Original post by Rattlehead

If the planet had a night side (maybe with lighted cities?) it would be just about perfect...




There will be lighting (maybe even bumpmapping), but first i have to make the lighting work...

fractoid, yes, my tex parameters are exactly that


Eelco, thanks, that's a good ideea, but i don't understant what "e" is and what "\" represents:

"e\v1\wx"

What language is it? at first i thought Visual Basic but the "\" in VB is integer division..


Oh, i've also thought of using 2 skyboxes to get some parallax effect going on.

[edited by - Ilici on March 22, 2004 10:40:34 AM]

Share this post


Link to post
Share on other sites
Eelco    301
e is an edge struct, and the \ is a dereference operator, like . or -> in c++. this method works just fine for me.

Share this post


Link to post
Share on other sites
Ilici    862
quote:
Original post by CodeMunkie
What language is that, Pascal?

[edited by - CodeMunkie on March 22, 2004 12:18:11 PM]


Certainly not Pascal, i think it''s C#..


Anyway, fixed the seams!
here''s the correct code for making and redering the sphere:


NumVertices = ((slices + 1) * (sides + 1)) * 2;

Vertices = new CVector3[NumVertices];
TexCoords = new CVector2[NumVertices];
Normals = new CVector3[NumVertices];

float polyAng = 2.0f * PI / sides;
float ang;

float vx, vy, vz;
int i, j;

int ind = 0;
for (j = 0; j <= slices; j++)
{
ang = j * PI / slices - PI / 2.0f;
for (i = 0; i <= sides; i++)
{
vx = cos(i * polyAng) * cos(ang);
vy = sin(ang);
vz = sin(i * polyAng) * cos(ang);

Vertices[ind].x = vx;
Vertices[ind].y = vy;
Vertices[ind].z = vz;

TexCoords[ind].x = 1.0f - (float)i / (float)sides;
TexCoords[ind].y = (float)j / (float)slices;

Normals[ind] = Normalize(Vertices[ind]);

ind++;
}
}

ind = 0;

NumIndices = (slices) * (sides + 1) * 2;
Indices = new unsigned short [NumIndices];

for (j = 1; j <= slices; j++)
{
for (i = 0; i <= sides; i++)
{
Indices[ind++] = (j - 1) * (sides + 1) + i;
Indices[ind++] = j * (sides + 1) + i;
}
}


////// render now


GL.EnableClientState(GL_VERTEX_ARRAY);
GL.EnableClientState(GL_NORMAL_ARRAY);
GL.EnableClientState(GL_TEXTURE_COORD_ARRAY);

GL.SetVertexPointer(3, GL_FLOAT, 0, Vertices);
GL.SetNormalPointer(GL_FLOAT, 0, Normals);
GL.SetTexCoordPointer(2, GL_FLOAT, 0, TexCoords);

int i;
for (i = 0; i < Slices; i++)
{
GL.DrawIndexedArrays(GL_TRIANGLE_STRIP, (Sides + 1) * 2, GL_UNSIGNED_SHORT, &Indices[i * (Sides + 1) * 2]);
}

GL.DisableClientState(GL_VERTEX_ARRAY);
GL.DisableClientState(GL_NORMAL_ARRAY);
GL.DisableClientState(GL_TEXTURE_COORD_ARRAY);

Share this post


Link to post
Share on other sites
chronos    100
I don't know whether OpenGL has something like mattnewport described, but the only solution I'm aware of is to split the vertices at the boundary where texture coordinates jump from 1.0 immediately back to 0.0. This is because the vertices at the boundary really describe two different pairs of UV coordinates: the incoming coordinates (ending with U coordinate 1.0 at the polygon preceding the boundary) and the outgoing coordinates (starting with U coordinate 0.0 at the polygon following the boundary).

[edited by - chronos on March 22, 2004 1:07:23 PM]

Share this post


Link to post
Share on other sites
teamonkey    200
quote:
Original post by CodeMunkie
What language is that, Pascal?

[edited by - CodeMunkie on March 22, 2004 12:18:11 PM]


At a guess, Blitz3D. www.blitzbasic.com

Share this post


Link to post
Share on other sites