Slope-dependent textures on a sphere

Hello everyone,

can you help me? I’ve got a problem for a small game project. I want to model spherical planets. Think Mario Galaxy :slight_smile: These planets will have mountains and so on. The model is just an icosphere, and I’ve used the sculpt tool for my mountain ranges - so far, so good.

I’d like to use blender to texture my planet based on the slope of my terrain. That texture should at least fade between grass and stone textures: Steep areas should get the rocky texture. To achieve this effect, I’ve followed David Miller’s instructions: http://vimeo.com/28922937 - and it works fine.

However, that only works on a plane. The technique described in that video uses the vertex normals to determine the texture color; however, as far as I can work it out, it only looks at the normal angle relative to world coordinates. That means it does not work on a sphere, as p.e. the equator will always be rocky.

Now, the obvious solution would be to use the normal angle relative to the object center. Is that possible somehow? If not, is there another technique I could use for the desired effect?

Another solution I’ve thought of: Can I use the length of the adjacent edges somehow as input values for the color mask? On an icosphere, the edges will be longer if I pull vertices upwards. Combined with the stencil stuff from the video, that would give me the desired effect.

I’m no expert with blender, but eager to learn. I’d be glad if anyone has a suggestion for me, thanks in advance!

I suppose this is possible with a bit of vector juggling and cross product in the most recent versions of blender. But if it’s for a game you are probably not using cycles as a renderer and my BI chops are a bit hmmm by now… so post back if you are using cycles and a sample planet would be nice so someone doesn’t have to spend the time to build one to test…

Well I had a few mins so here is something to try in cycles. You should probably wait until some of the experts like Kaluura or Ace show you how it really should be done, but this might be a stopgap bit of hackwork.


Anyway you should be able to plug your materials into the nodetree to get a better looking planet. In the Altitude factor group you can adjust the curve to increase or decrease the range of the greenery.
Note that this method puts veg on top of the peaks where you might expect to find snow so there’s more juggling to subtract the top end from that material but I should leave some fun for you!
WARNING: This will almost certainly not work with any version that is not quite quite fresh and new. I recommend you download a development build - they might have a few bugs but they are fairly stable and you will have a lot more functionality.

Edit: Okay I know the vegetation does not look realistic.

Attachments

Planetoid.zip (378 KB)

is it function of slope or height dependant ?

happy cycles

I have an old image here with slope dependent materials.


However, I don’t know of any easy methods to wrap this to a sphere as opposed to a single axis, to do what you might require some vector math to project this setup multiple ways without too much interference between them.

@ Ace dragon
i tried to replicate nodes set up but did not work!

do you have a sample file
can you also explain the math behind this
i see the normal node at top left but don’t see any texture going into it
so how does this one works?

thanks

@ Eppo do you mean the charcoal model
that one was not base on height or slope more on some distance

salut

I got a stupid idea… which just works. :smiley:


In the image, blue is flat, red is steep and green is in between. (Look at the tip of the mountain on the right!) :eyebrowlift2:

(Don’t ask where that angle calculation formula comes from. That’s something in between Google and the mathematician in my head. He’s on holidays for the moment. I simply re-use the node group.) :wink:

The stupid idea was to do some complicate math to calculate the angle in between the normal and the position of the point to consider and to do some more math to get a factor. It’s just much simpler than I thought. :eyebrowlift: The values just “fit”. :wink:

The blend file: Forum Spherical Slope.blend (184 KB)

Enjoy! :smiley:

i’v seen example in 2.5 bl but using composite nodes only!
will look for another method !

happy bl

ok slope means normal
i got an example here for showing colors function of normal
but don’t really control the specific color for different slope range
may be Kaluura can find some magic formula for this!


can be done with OLS or other nodes set up in cycls too

salut

I made a test with a less chaotic shape. Yep! I confirm it works really well. :smiley:


And the explanations I forgot earlier: The material assumes the object is a sphere (or something close) with bumps and holes. (It produces strange results with anything else.) The Angle factor coming out of the Angle Calculator is (seems to be) in the range [0, pi/2] so a color ramp clamps only the extreme values. That’s all I can think of for the moment.

@RickyBlender: My magic wand is a bit limp tonight… Too much work earlier. :wink: Can you point me in the direction of the OSL shader used on Suzanne. I couldn’t find it. BA falls flat on its face when you search for “normal”. And Google is starting to propose me kitchen appliances… :smiley:

the OSL was from breatch i think
#include “stdosl.h”

shader Camera_normals(
output color Camera_Normals = color(0.8)
)

{

color C = color(transform(“world”, “camera”, N));
Camera_Normals = 0.5*color(C[0], C[1], -C[2]) + color(0.5);
}

now this may not be the easiest way to work with

here is another easier way in cycles but no control of levels


but there are other ways to add colors function of normal
you could use the Fresnel or layerweight which are function of the face’s normals
there you could add a color ramp or something to establish some levels for colors!

happy cycles

I tried it out with an ANT Landscape in spherical mode and it seems to work. Color by slope. But a nice addition would be Color by height mixed in as well. Then you could use the slope for bump/displace and the height for diffuse.

Attachments


that is another problem
do you add this on a relatively flat surface like a landscape so function of Z values only

or on an object which might require to think in terms of spherical coordinates!

happy bl

Well, here’s another one. http://www.pasteall.org/blend/24408
Mapping Z makes poles white, if needed. Make it base colors or grayscale and mix materials, roughness, whatever.

@Atom: Hungry people… You give them a finger and they want the whole arm. :wink:


Here, I cut the landscape into 3 levels (sea-sand-vegetation, dirt-rock, snowy caps) depending on the altitude, each one with its own slope-dependent color map, with color ramps to control the transition in between the levels.

If you want a leg too… errr… snow on the poles, that’s possible too. :wink:

The updated blend file: Forum Spherical Slope.blend (796 KB)

@RickyBlender: Now I see… This is a matcap. At least, because of the way the normals are converted, the material changes depending on the camera view. And that can be done in pure Cycles now that we have that “Vector Transform” node.


On the left, Brecht’s material with Cycles nodes only. On the right, my “matcap”. If anything else, it could be used for a quick clay style render. Very interesting in fact. :eyebrowlift:

What I do in here is to convert the normals from “World” to “Camera” (whatever that means), then into greyscale and that result is converted to fit in the range (0, 1). Easy as pie! :wink:

The blend file, of course: Forum Matcap.blend (129 KB)

Enjoy! :smiley:

did you figure out how the new mapping node wroks
like this new vector and normal mode are
i open a new thread and no one seems to know how it works!

i’ll try to test your examples

thanks

@Kaluura: Thanks for the updated file, I guess I was feeling a bit peckish yesterday.

“Gromit, have you been eating my cheese?”:cool:

@RickyBlender: I haven’t looked into the new Mapping node features… much… until now. It’s just weird and probably bugged.

http://www.miikahweb.com/en/blender/svn-logs/commit/60507

The feature was introduced there:

http://www.miikahweb.com/en/blender/svn-logs/commit/60371

So… That’s what the buttons are supposed to do: To allow you to use the Mapping node in the circumstances set by these buttons. It makes sense. (The sentence is in modern English.) :wink: …But I fail to see in what other circumstances than to scale/rotate/shift/crop a texture we would use that (huge monster of a) node.

From my experience, I can say that there’s a difference in the way the textures are scaled wether you choose “Texture” or “Point”/“Vector” (look the same to the naked eye)… and “Normal” makes really weird stuff. That’s all I can say. Right now, I’ll stick with “Point” which is the same behavior as before (and the one I prefer… in my version).

And I’m going to download a newer version. Mine is already obsolete… A few days old! :smiley:

@Atom: Don’t worry. Nobody forces me to do anything I don’t want to. It interests me too… I foresee plenty of little cartoon planets orbiting in the viewport soon. :smiley: