Nodes: colour according to z position

Hi,

So I’m making a game in Unity 3d, which uses heightmap terrain. I’m trying to make myself some terrain in Blender and export it as a heightmap. I’m trying to do this by rendering my blendered terrain from above with an orthographic projection camera, with some clever nodesy stuff. To make this work, I need a material for my terrain which is a certain colour according to it’s height so I can make the heightmap. So basically, the heighest points need to be near white and the lowest points need to be very dark, and it should interpolate linearly between. I did some nodes stuff, and it’s nearly working - there’s just one problem - it’s not linear!

So here’s the nodes thing I made (I’m using blender render, not cycles):


So that gradient you can see on the sphere in the thumbnail should be linear. It’s difficult to tell if a gradient is linear or not, so I did a test. I tested out this shader on a perfectly flat plane that I tilted at an angle. I did the render thing and all that and imported it into unity. If this gradient was linear, the terrain i’d have imported would be the same as what i’d made in blender - a flat, tilted plane.

Instead I got this:


Definitely not linear… I don’t know why this would be, but it looks sort of like a square root graph… Or some sort of root anyway, I don’t know…

I’ve just realised I haven’t explained what the dot product thing is doing - that is multiplying the global position by (0.0, 0.0, 1.0). This was my slightly weird attempt of separating the z element of the global position vector. Strangely, there doesn’t seem to be any kind of “separate vector” node. Maybe I’ve misunderstood what dot product does - I thought it multiplied the vectors together component for component…

Ok, since writing the rest of that I thought about it looking like some sort of root graph, so I put in a math node just after the dot product and tried squaring and cubing the value. It sort of helped, it didn’t fix it completely. I still kinda want to know what the actual problem is here…

Well, if anyone knows of anything about this, I’d be very grateful.

Thanks, and happy blendering!

can this help may be

happy bl

Are you sure gamma correction isn’t sneaking its way into this and messing everything up? Make sure you’re either saving/loading everything as linear data, or make sure you correct back to linear when loading.

Could be the viewport working in sRGB space instead of linear…

Can confirm everything is fine example blend is here – http://www.pasteall.org/blend/34448

As you increase the greater than’s with whole numbers it aligns fine with the resultant objects.


try this

Hi,

Why not simply use the ‘Separate XYZ’ node? In ‘Converter’
Though this number will vary depending on the coordinate system, e.g. it could be negative so use some math to rescale from 0 to 1

Sorry, just noticed you are using BI not Cycles


Best of luck

Martin