Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Texture and Sphere Height-feild don't match up right...

Author
Message
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 14th Jul 2012 23:11
Here's the code that converts a 128x64 grayscale image to a height field on a 128x64 segmented sphere. I run the code and it works but not properly. The texture seems to be in the right place on the sphere, but the changed vertices don't match up with where the texture height-colors are. Maybe I shifted the code wrong somehow.

I hope I explained this well enough.



Home is where my souped-up computer is...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2012 00:09
I think you'll find the x coordinates for the bitmap go from 0 to 127 and from 0 to 63 for y. That could be one reason.
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 15th Jul 2012 00:29
Green, I am "pasting" the image at 1, 1 - not 0, 0. Just for a try I adjusted for that. No change...

Home is where my souped-up computer is...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2012 00:49
Quote: "Green, I am "pasting" the image at 1, 1 - not 0, 0."


So you did. Sorry.

Are your colours supposed to align with the vertices or the polys between them?

How did you create your sphere? Is it a DBPro sphere? If it is then it will have (128+1)*(64+1) = 8385 vertices if you used something like



Think fences and fence posts.
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 15th Jul 2012 03:31
Yea, I'm shooting for the colors to be on the vertices for height purposes, I plan on using a higher-res map for actually texturing the sphere. It is a DBPro sphere I have used. I'll post the project/images in a little bit so you can see the code in full.

Home is where my souped-up computer is...
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 15th Jul 2012 19:38
Here's the project as it is so far in it's entirety. This heightmap-onto-a-sphere has really got me stumped. If anyone can see where I did wrong, it'd be you all.

Thanks again!

Home is where my souped-up computer is...
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Jul 2012 18:09
I had to comment out the loading of two of the images as they were missing from the project but it ran and I looked quickly through the code. At the moment I can't tell exactly what you're after

I don't see you using SET VERTEX DIFFUSE anywhere in your code to set the vertex colours.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 16th Jul 2012 18:45
Hi JoeOH,have you considered making the sphere yourself with the vertex commands and matrix1 "make object new" command.
I find it a lot easier for working with spheres,and you can set up the UV to what ever you like quite simply.
The way i do it is to position a dummy object at the 0,0,0 then rotate it on the x and y angles separately to match with how many sections i want to make the sphere out of,then move the object by the radius i need to match with the height map.The objects position is the vertex for that point.You can set the UV for it as well because you know how many sections your using and which one your on.After you have set all the vertex positions its a simple matter to write a loop that sets all the index data to produce the polyies.
The only problems i get doing it this way are trying to remember that square height maps dont quite wrap smoothly around spheres,but unless its a real heightmap like a model of the earth that someone will recognise its not that big a problem.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jul 2012 19:16 Edited at: 16th Jul 2012 19:17
Quote: "If anyone can see where I did wrong,"


I've tested your demo and apart from one minor error in the code I don't know what the problem is that you are talking about. What should the modified sphere look like?

The minor error is that vertices should be numbered from 0 to n-1 when n is the number of vertices. I tried that correction but couldn't see what the problem was supposed to be.

Also, have you taken note of my earlier comment about fences and fence posts? In other words, for "vertices" read fence posts and for "segments" read fence sections.

Have you allowed for the fact that DBPro spheres have lots of duplicated vertices? For example, run the following code, press "w" and ask yourself where are the other 8 vertices?



Edit Added the missing code.
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 17th Jul 2012 00:47
WLGfx, I didn't know about the set vertex diffuse command. I will give it a go..

Home is where my souped-up computer is...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Jul 2012 12:32
Quote: "WLGfx, I didn't know about the set vertex diffuse command. I will give it a go.."


You'll still need to address the issues I mentioned. Have you tried yet?
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Jul 2012 12:47
Yeah, although I got the bumpy surface I wasn't exactly sure what it was meant to achieve, especially without the extra images.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 17th Jul 2012 20:08
WLGfx, what I would like to do is have a 128x64 greyscale heightmap image to be used to create the hills and valley's on the sphere. the darker the spot, the lower the terrain will be at that spot on the sphere and vice versa.

The extra images weren't really used so far. I thought I took those lines out before uploading.

And Gandalf, I now understand that each poly "square" on a sphere is really 2 triangles that each have 4 vertexes of their own. I'll try to implement what you have stated and get back with you all on it.

Home is where my souped-up computer is...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Jul 2012 20:29
OK. Let us know how you get on.

Just one elaboration of my earlier points: you can think of the sphere as a plain which is wrapped around so the left and right hand edges coincide and the top and bottom edges all map to the North and South poles respectively. That's where the "missing" vertices have gone. One consequence of that is that in your application the lefthand edge vertices need to use the same heightmap pixels as those on the right hand edge. So if your sphere has 128 vertical slices there will be 129 vertices in each row and the 129th one should use the same heightmap value as the first. Similar arguments apply to the horizontal slices.

I hope that makes things a bit clearer. You will have to check the details but something along the above lines should work.
JoeOh
17
Years of Service
User Offline
Joined: 25th Feb 2009
Location:
Posted: 17th Jul 2012 23:58
ok, I got it to work as I wanted it to. The texture and height-field match up quite nicely. All I did was change the HeightMap(128, 64) to HeightMap(129, 65) and reversed how the HeightMap() x-value Array was loaded.

Here's the code:



it should work and you'll see what I mean. Use the camera controls to move around the planet. Use the Middle Mouse button to pan around the camera, the mouse wheel to zoom in and out. Use the ControlKey+mouse buttom to skew the camera around.

If you get disorientated use the space bar to straighten you out. The current camera controls are not perfect, but that can be remedied soon enough.

Home is where my souped-up computer is...
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Jul 2012 16:20
The bumpy surfaces were coming up fine, but each time you alter the vertices within a mesh you will also need to alter the normals of it too so that it reacts to a light source properly. Calculating the normals is time consuming depending on how many triangles are in the mesh and then it's whether you're also going to need to average out the normals (which is better) for each vertex.

Using the vertex diffuse colour can save on using a texture as can add a detail map over the surface. If two colour are different between two vertices then the gpu with use a linear interpolate to smooth out the colour change which is no overhead. The gpu also does this when blending textures over triangle faces anyway.

I can't yet test out the new source code but I will come back later and see what you have done with it.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-08 01:54:55
Your offset time is: 2026-07-08 01:54:55