4
\$\begingroup\$

I am a very experienced iOS Developer, but I am beginning my very first foray into 3D graphics (specifically with SceneKit). I'm trying to model a planet, and I have it working with a height map giving mountains and valleys to a simple sphere.

What I'm wondering now is, how might I have a variable sea level? As I understand it, a height map only affects how the image is rendered, but it doesn't actually change the geometry of the object, correct? So my first idea, to have a smaller sphere and scale it up or down relative to the planet so that it shows through in the lower-elevation areas, wouldn't work?

If that's the case, how else might I approach this? I'd love a code sample if it's simple or ready-made, but mostly I'm just looking for a conceptual answer that I can go off and implement. How might I take a height-mapped planet surface, and have an adjustable sea level that fills in the lower-elevation areas first? For simplicity, I'm treating sea level as purely altitude-based (i.e. I don't need to factor in dams or obstacles, and maintaining a consistent volume of water isn't important).

\$\endgroup\$
1
\$\begingroup\$

You should be able to animate the height using u_time in your shader. Example usage of u_time code in Xcode project download here - https://developer.apple.com/library/mac/samplecode/SceneKit_Slides_WWDC2013/Introduction/Intro.html (compiles to slide show, use -> key to goto slide 40-something)

Can you help me out? I've been trying to do a height map with SceneKit's SCNShaderModifierEntryPointGeometry and can't seem to get my (UIImage*)heightMap passed to a sampler2D variable in the shaderModifier. How are you passing your image? Thanks in advance.

\$\endgroup\$
1
\$\begingroup\$

What you explain sounds reasonable. Generate a smaller sphere with the radius set for an appropriate sea level.

Alternativly generate a sphere and alter its scale. This'd be quicker than regenerating a new one.

\$\endgroup\$
1
\$\begingroup\$

You need a 3d noise function (perlin,simplex,..). Call it f(x,y,z). Usualy this function returns a 0..1 float value. You simply decide your sea level float k in 0..1 and :

Foreach point of the sphere

If f(x,y,z) < k 

 k is your heigth in that point

Else

 f(x,y,z) is your heigth in that point
\$\endgroup\$
  • 1
    \$\begingroup\$ This is good info, but I'm looking for how to execute the sea level, rather than calculate it. As in, would it be a second image layer, like a normal map layer on the sphere? Should it be a second overlapping sphere, resizing in and out? Is there a way to adjust the height map dynamically to fit sea level? That sort of thing. What processes can can be used to create this effect? \$\endgroup\$ – Nerrolken Aug 12 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.