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 / Grayscale memblock image?

Author
Message
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 4th Aug 2014 12:56
Is it possible to create a grayscale only image, using memblocks?

I would really need more steps than what one single byte can provide in my heightmap generator, that's what it would be for.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Aug 2014 14:23 Edited at: 4th Aug 2014 14:24
Just tried it and no, doesn't seem to work unfortunately.
If you just need extra heightmap resolution you can combine the red and green channels (and the blue and alpha as well if needed). For example height = (red << 8) || green.


"Why do programmers get Halloween and Christmas mixed up?"
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Aug 2014 15:27 Edited at: 4th Aug 2014 15:30
One good option is .RAW - this is supported in a few programs for heightmaps, like Cryengine3 for example, it's a raw image format that supports 16-bit greyscale, which is perfect for heightmaps - with 16-bit grey, you go from 0-255 resolution, to 0-65535 resolution.

Really, it's just raw data, you need to know the image dimensions to load it back in. It is supported in PhotoShopCS4 and Corel Paint Shop Pro.

To convert a float to a 16-bit raw WORD, I do it the wrong, long, horrible way because it works and I never bothered to work out the right way...

a=int(h#/256)
b=(h#-(a*256.0))*256

Then write out byte B then byte A for each pixel. Writing out pure WORD values from DBPro didn't work, so I did it that way.

A while ago someone was on the forum talking about a nice trick they'd found. What they do is take the heightmap, say a 256x256 greyscale heightmap, and make that the red channel. Then 2 tileable heightmaps, maybe even just a tileable texture made grey - those become the blue and green channels. So you end up with the main heightmap in red, and 2 tiled heightmaps in green and blue. Then the cool bit, the red heightmap is scaled by 4 times, so that 256x256 becomes 1024x1024 - a fairly decent heightmap size in any engine. The green heightmap is scaled by 2 and repeated 4 times, and the blue heightmap isn't scaled and repeats 16 times (4x4). All 3 heightmaps then work together, to provide 1 big 1024x1024 heightmap with good variance, and you only really have to make a 256x256 heightmap to make it. You'd work out each points heightmap value for red green and blue, then do something like this: h#=r+(g*0.01)+(b*0.0001)

So that's one option if you prefer to edit smaller heightmaps, big 1024x1024 heightmaps can be a right pain to design. If you go with the above method, probably best to consider procedural vegetation and decent tolerances on models - like you won't necessarily have any perfectly flat areas, so adding things like foundations or stilts to buildings is an idea.

I am the one who knocks...
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 4th Aug 2014 16:20 Edited at: 4th Aug 2014 17:11
To be honest, what i'm working on is not a simple heightmap generator, rather an erosion tool for my game's level editor. So achieving certain heightmap tricks is kinda out of the question, but thank you for sharing that, really appretiated.

Here's a picture of what i can currently turn a very primitive minute-heightmap into.



I was just hoping to get faster mid-render previews of the process how the erosion is going, i'm already calculating with extended values during the erosion simulation.

I didn't think this was such a... he-he... grey area...
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Aug 2014 17:28
I see. I've been messing with Cryengine3 recently, trying to make better heightmaps, which is why I ended up using .raw, as that's the only way to get higher than 8-bit detail - so for that, outputting raw 16-bit is ideal.

What I do have though, is an isometric render of the terrain, using just the line command. It's not blindingly quick, but it might be useful if you'd like to preview a heightmap array without having to generate meshes or mess with the camera settings. Just let me know if you'd like to see the code for it, I know how dull it can be to sit and wait on terrain generation... I'm guessing erosion can take a long time, and having anything showing progress would be better than nothing, even if it does take a few seconds to render. I'm guessing that the problem with 8-bit heightmaps is they are only 8-bit, its too tricky to try and work out how the terrain will look based on a heightmap.

I am the one who knocks...
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Aug 2014 01:46 Edited at: 8th Aug 2014 03:02
I can give you 512 values to display heights like a real topographical map:

I just have to work it out first...

It actually seems surprisingly complicated to produce a linear gradient from incremental values. 0 (white) to 512 (red). I need the brain workout though.

hmm it's not even 512 values, this doesn't seem very good. Maybe I should try the thermal imaging colours instead (black to blue to green to yellow to red to magenta to white). That should hopefully get at least 65536 colours.

Formerly OBese87.
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 11th Aug 2014 13:37
There's a lot of ways to store and work with incredible amount of height steps... the point would have been to simply work with a memblock and so MAKE IMAGE FROM MEMBLOCK could have been used for quick preview without any need for workarounds.

Also saving the final heightmap AS AN IMAGE would have been nice.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Aug 2014 14:28
Quote: "the point would have been to simply work with a memblock "


What's the problem exactly? All you have to do is code your desired height values as a 24 bit integer, i.e. in the range 0 to 16777215. Then take the first 8 as your red byte, next 8 as your green byte and the final 8 as your blue byte. That should give you enough height values to play with. You then just reverse the steps when you use the image.

As soon as you've created the memblock, simply create the image and display it. Since you already seem to know how to do this I'm a bit puzzled as to the true nature of your problem.



Powered by Free Banners
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Aug 2014 20:10
@Quel @Green Gandalf
This is what I was trying to solve. Yes you can use all RGB colours for heights and get 16777... whatever it is heights (lots!) but the way colours are calculated gives you cycles of blue in cycles of green in a cycle of red, which would be impossible for a human to interpret correctly. I want to convert these colour values to a linear gradient so that a human eye could analyse the heights.

Formerly OBese87.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 11th Aug 2014 20:55
Quote: "I want to convert these colour values to a linear gradient so that a human eye could analyse the heights."

If you just want to downsample your 24-bit values to 8-bit values that you can display as an image it's as easy as c = int(255 * value / 16777215.0)


"Why do programmers get Halloween and Christmas mixed up?"
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Aug 2014 21:55
@Rudolpho - but then this loses data in the final image and quel would like to store the heightmaps as images.

Formerly OBese87.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Aug 2014 00:13
Yes, but then you can store it in the other colour channels as well. I thought the issue was displaying (an approximation) that was easier to interpret for human eyes.


"Why do programmers get Halloween and Christmas mixed up?"
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Aug 2014 00:22
You mean to store the image as a mess of colours and then scale them to one band of rgb when viewing? That's a solution of sorts but it would be nicer to have an image that is human readable and then convert it to something the computer can make sense of rather than the other way around.

Formerly OBese87.
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Aug 2014 01:30
True.
It is possible you could achieve the desired results by using a large colour lookup table; for example it would be feasible to have a 64kb lookup where 2^16 values will map to 2^8 actual colour values, thus making the image appear as grayscale when viewed even though it has 16-bit colour index values per pixel.
Of course this wouldn't work well with much higher bit depths since the colour table would become enormous.


"Why do programmers get Halloween and Christmas mixed up?"
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Aug 2014 01:39
Or if you are generating these images yourself you could manually export them to a format that supports additional data chunks, such as PNG.
In this case you can store a 8-bit grayscale image as the actual image data and then store your higher resolution height map data in an ancillary chunk that you write your own importing routine to read. Of course the actual image data is irrelevant, but it will provide an actual approximation to view in an arbitrary image viewing application.


"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2026-07-05 18:24:58
Your offset time is: 2026-07-05 18:24:58