Transparent Sphere (does it look right?)

Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,453
Location
Detroit, Michigan
Website
Visit site



So ive been working on creating spheres on the fly, so basically the sphere is defined by slices and stacks. So for instance I would draw an 8 slice 8 stack sphere with 4 triangle strips in one go separated by degenerative indices.


Im just not sure if it looks right. Opinions?
 

Dimacus

Member
Joined
Jan 25, 2006
Messages
349
Age
33
Location
Land of the 'åäö'
Website
luminare.no-ip.org
It looks to me like there is something slightly off with the deep/dark red lighting, especially around the top left area.


I think it looks more 'jagged' in that area because you don't seem to have a lighting gradient, or it's not as strong as the lighter shade of red.
 

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
To me it looks like depth dependant drawing were some surfaces dont get drawn and dont add to the color. Transparent objects need to either be sorted or drawn with depth function "always".
 

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
I think I did transparency like this: First draw all normal objects normally, then turn off depth test, does that inable writing to depth buffer? You wouldnt wanna write to depth buffer thats the thing, then draw all transparent surfaces and they will all get drawn and overlap everything. Then to remove the parts of transparent surfaces that shouldnt be there, draw the normal surfaces again with depth test enabled again and function "lequal".
 

Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,453
Location
Detroit, Michigan
Website
Visit site
Im not sure if the depth testing is the problem, all of the faces are there thats what causes the darker areas. What i think is happening is that when the vertices for the strip cross the pole of the sphere the points swap which i think effects the winding which effects the normal. So i think for have of the sphere the normals may be inverted.


Does that makes sense?
 

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
What do you use the normals for then? I noticed if you look at the equater it forms a circle were half is dark and half is bright, if you only draw one side of a surface it would look like that, but then theres hmm, some surfaces definitly seem inverted somehow, how do you come up with the vertices? your own calculations?


What is it you want to achieve, a globe with slices of surfaces visible inside or a single color globe transparent and same color across?
 

Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,453
Location
Detroit, Michigan
Website
Visit site
Yeah if i dont use the normals i get basically the outline of the object, but it appears flat. So I dont think this is the right solution.


Yes im procedurally calculating the vertices. Im calculating the points in rings and then combining the rings into strips, but like i said before I think once the rings cross at the poles the winding of the faces inverts messing up the normals for that half. If i swap the points on the second half I think it will look right.


Im trying to make the sphere transparent and put it around another object. So it should still retain its depth, thus the normals.
 

skeezix

Internal Development
Joined
Mar 11, 2003
Messages
8,060
Website
www.codejedi.com
I've not had time to look ingo GL or GLES much so I'm a noob, but for sphere what I've been doing is calculating points on the sphere and using them to define triangle vertices, and normals pointing out from the planes, and good to go. I've no clue what strip and stacks are though in this context ;)


But just a simple tesselated sphere in triangles works fine and pretty easy .. but its a lot of triangles if you want it smooth looking! I need to look into this more, since sending thousanad of triangles for one sphere has got to be the worst brute force way to do it :)


jeff
 

j0n

Member
Joined
Nov 25, 2010
Messages
103
I've not had time to look ingo GL or GLES much so I'm a noob, but for sphere what I've been doing is calculating points on the sphere and using them to define triangle vertices, and normals pointing out from the planes, and good to go. I've no clue what strip and stacks are though in this context ;)


But just a simple tesselated sphere in triangles works fine and pretty easy .. but its a lot of triangles if you want it smooth looking! I need to look into this more, since sending thousanad of triangles for one sphere has got to be the worst brute force way to do it :)


jeff
Yep this is the way I have done it in the past and it has worked very well. If you parameterize the amount of slices you need on each axis you can get it down to quite an reasonable level while still looking good. I can't really think of a better way of approaching this problem.


This tutorial demos this approach to generating the vertex data : http://www.swiftless.com/tutorials/opengl/sphere.html


However he leaves out normal calculation.


Usually I would generate the normals after generating the vertices, by using a for loop over the vertices and a cross product calculation for every 3 vertices. This should give you the effect you want. If you would like more explanation let me know.
 

skeezix

Internal Development
Joined
Mar 11, 2003
Messages
8,060
Website
www.codejedi.com
Thats more or less how I do it; it just seems cumbersome. I mean sure, you could try to do backface removal to avoid sending all those triangles etc .. but for my little hack, I've been doing script based code for generating dynamic worlds, and its a _lot_ of triangles very quickly, and very quickly overwhelms movile device GPUs. So I'll have to optimize like mad to cut out all the extra triangles.. just seems a shame :) Theres probably a better way.... or else its a lot of optimization. I know at least in OpenGL on a desktop,m the drivers are quite smart about backface removal on their own.


jeff
 

Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,453
Location
Detroit, Michigan
Website
Visit site
Yeah i think im making it hard trying to do vertical strip rather than horizontal ones. I have all the vertices its just getting them into the correct order in the indices.


Also calculating normals can be quite simple with a sphere, the normal for the vertex is the same x,y,z values (just dont multiply by the radius or offset by the origin)
 

sixtyfifthbit

Member
Joined
Aug 24, 2007
Messages
168
How accurate must the "spheres" be? Will there be anything on the spheres, or do you just need apparent translucent discs? What I would do, unless you were going to put things on the surface of the sphere, is to merely make a billboarded circle - that is, make a flat polygon of n sides to approximate a circular disc and always rotate it to face the camera.


Why do you need "slices and stacks"?
 

Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,453
Location
Detroit, Michigan
Website
Visit site
Ok i think its a front to back problem all along. So here the sphere as is. What happens here is that when the sphere roatates that the faces become aligned. So each strip is drawn in middle front, around the top to the back middle and then back around to the front. So when that second have is drawn over it is adding to the exisiting red.





So i think the correct way to handle this is to enable culling, which makes the full red go away.


 
Last edited by a moderator:

skeezix

Internal Development
Joined
Mar 11, 2003
Messages
8,060
Website
www.codejedi.com
You do want to order the triangles in the right way too IIRC; I forget particulars, been a year since I looked, but I recall many drivers need to see front to back ordering, or clockwise, or other restrictions; if you fail to order properly, sometimes the driver assumptions get screwed up.


jeff
 
Top