March 28, 2024, 09:32:03 PM

Username
Password

Pages: [1]   Go Down
Print
Author Topic: Heightmaps  (Read 31711 times)
0 Members and 1 Guest are viewing this topic.
aqrit
Developer
*
Offline Offline

Posts: 85



View Profile WWW
« on: February 23, 2014, 08:47:58 AM »

Exporting a heightmap from Blender...
A 256 color bitmap is not good enough to use.
According to http://blenderartists.org/forum/archive/index.php/t-96874.html
the heightmap must be rendered and saved as a *.EXR file
then using http://www.imagemagick.org/ the *.EXR file can be converted to a format that is easier to work with, while still retaining important color info.

I *think* I've got a pretty good understanding of the TERR chunk from looking at Mikademus, and Ghabry's projects.
edit: update structure defininations


   heightmap data is stored in some form of Block Truncation Coding

   The grayscale image is divided into 8x8 sub-blocks
   each block is represented by two "layers"
   Layer_1 is a 32-bit value that is used as the base level for all 64 pixels in the block
   Layer_2 is 64 8-bit values ( one 8-bit value for each pixel in the block )
   To determine the height of a pixel the corresponding Layer_2 value is multiplied by 128
   then added to the corresponding Layer_1 value

   The Layer_2 entries can be re-used by different blocks to save space ( dictionary compression )

   // note: LAYER1 contains two heightmaps ( of the same dimensions )
   // one for line of sight and one for movement? http://forum.dark-omen.org/tools/general-modding-questions-t1210.0.html
   // however, TERR_HEADER's size, width, height, and num_blocks_layer1 members are all missing the second heightmap

   struct TERR_HEADER
   {
      char id[4]; // 'TERR'
      DWORD size;
      DWORD width;
      DWORD height;
      DWORD num_blocks_layer2;
      DWORD num_blocks_layer1;
   };
   struct LAYER1
   {
      DWORD size;
      struct BLOCK
      {
         DWORD base_height;
         DWORD layer2_offset; // bytes from &layer2.blocks[0]
      } blocks[1];
   };
   struct LAYER2
   {
      DWORD size;
      struct BLOCK
      {
         BYTE delta[8][8];
      } blocks[1];
   };


« Last Edit: March 04, 2014, 01:03:18 AM by aqrit » Logged
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #1 on: February 23, 2014, 10:14:30 PM »

All looks great! Using Blender 2.47 I've flattened the original Black Pyramids map B5_01B and included it along with another version with Hills (press B in Blender to group select a region and then raise them up and then smooth them (Alt and Smooth several times) then press F12 to render scene and F3 to save as OpenEXR. Then Save the new modified map as SmoothHill.blend and Export using Dark Omen script as SmoothHill.M3D.

Includes finished SmoothHills .EXR, .M3d, .Blend and original Flat Map.
http://www.mediafire.com/download/jxrc48rr33a7fiz/SmoothHillBASE.zip

(having trouble opening .EXR in ImageMagik -> http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=23380

do I need plugin ?

http://www.openexr.com/index.html

I can open .EXR in Photoshop 7.0 using Plugin


Will be so cool to finally make custom new maps!
*1st Height Map is Line of Sight and Single Player Camera and 2nd Height Map is troop movement and Multiplayer Camera so just make identical.*

Smiley
« Last Edit: February 24, 2014, 12:09:55 AM by olly » Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
aqrit
Developer
*
Offline Offline

Posts: 85



View Profile WWW
« Reply #2 on: February 24, 2014, 06:08:54 PM »

Quote
trouble opening .EXR in ImageMagik
doh, nothing is ever easy :-(
Logged
Ghabry
Developer
*
Offline Offline

Posts: 1020



View Profile
« Reply #3 on: February 25, 2014, 01:48:04 AM »

Is PNG with 16bit (grey) color channel good enough?
Logged

aqrit
Developer
*
Offline Offline

Posts: 85



View Profile WWW
« Reply #4 on: February 25, 2014, 09:37:41 AM »

Is PNG with 16bit (grey) color channel good enough?
Yes.
I finally installed Blender today, and now see that option... ( so it is easy Cheesy )

some of the maps like B1_04 have some small negative ( I assume ) elevations...
I don't really know what to do with those...
but everything else is under the 65,535 maximum for 16-bit

Logged
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #5 on: February 25, 2014, 11:19:55 PM »

Forgive me if I'm wrong but we found that exporting PNG was only 8bit in Blender but does allow 16bit TIFF which we then had to convert to 16bit PNG (if required) using imagemagik ->

(Old instructions and downloads I found with my converted 16bit TIFF and PNG maps)

http://www.mediafire.com/download/mgjidv3d47ka9es/HeightMap+Conversion+Tiff+to+PNG+all+16bits.zip

http://www.mediafire.com/download/9prf7hkv1k4s17t/16bitTiffto+16BitPNG+HM+Examples.zip

->

Paste infile.TIFF (16bit height map produced from Blender)into

C:\Program Files (x86)\ImageMagick-6.8.2-Q16

Run from command prompt and use DIR to get to 
C:\Program Files (x86)\ImageMagick-6.8.2-Q16\

then type

convert infile.tif -depth 16 -type Grayscale outfile.png

and the newly produced outfile.png will appear in C:\Program Files (x86)\ImageMagick-6.8.2-Q16\

and should be 16bit .png and can be verified using same console

Run from command prompt and use DIR to get to 
C:\Program Files (x86)\ImageMagick-6.8.2-Q16\

convert infile.tif -verbose info:

and

convert outfile.png -verbose info:



http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=11082&p=35415#p35407




*****ACTUALLY YOU HAVE TO USE OPTIMIZE INSTEAD OF GREYSCALE TO GET 16BIT GREYSCALE*****

Run from command prompt and use DIR to get to 
C:\Program Files (x86)\ImageMagick-6.8.2-Q16\

then type

convert infile.tif -depth 16 -type Optimise outfile.png
Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
aqrit
Developer
*
Offline Offline

Posts: 85



View Profile WWW
« Reply #6 on: February 26, 2014, 08:52:15 AM »


* blender.png (8.99 KB. 174x175 - viewed 1098 times.)


seems to work

Logged
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #7 on: February 26, 2014, 06:25:47 PM »

Cool, looks like they've included it in the latest Blender version (does our DO import/Export scripts still work) as I'm still on old 2.47 for using our scripts but can jump between versions if necessary.

Smiley

« Last Edit: February 27, 2014, 07:54:52 AM by olly » Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
aqrit
Developer
*
Offline Offline

Posts: 85



View Profile WWW
« Reply #8 on: March 08, 2014, 07:19:50 AM »

I've re-invented the wheel  Sad

Dark Omen heightmaps to/from 16-bit grayscale PNG image files
http://bitpatch.com/downloads/do_terr.zip

completely untested.
correctness and/or usefulness is unknown.
Logged
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #9 on: March 08, 2014, 11:35:42 AM »

Sounds promising, I will start testing -many thanks.

Smiley
Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #10 on: March 08, 2014, 09:56:02 PM »

Works really well! Troops don't appear to Step down slopes as the gradients are much more smooth using 16bit PNG.

Smiley Smiley Smiley


However, just like the earlier height map generator, we need to adjust colour levels down from 255 whiteness to 60 as Blender's white is too high in Dark Omen.


1) Open B5_01B Flat map in blender and create some smooth hills

2) F12 to Render and F3 to Export as 16bit PNG and export as BASE.M3D and convert to BASE.M3X with Map Gridder tool and save as SmoothHills.blend

3)Open new 16bit PNG in Photoshop 7 and lower Colour levels down from 255 whiteness to 60 and flip vertically. Then export as 16bit TIFF and rename to infile. Then using imagemagick to convert back to 16bit PNG using CMD convert infile.tif -depth 16 -type Optimise outfile.png
  
4)Using command prompt cd and cd choose B5_01B folder to run terr.exe and have the flat map B5_01B.PRJ renamed as in.prj and run the first command terr -x in.prj out1.png out2.png which will extract the existing height maps into 16bit PNG files

5)With the new smooth hills 16bit heightmap, rename it in1.png and copy and paste it again and rename as in2.png . Then run the 2nd command terr.exe  terr -i in.prj out.prj in1.png in2.png which will transfer the heightmap data from 16bit png into Dark Omen out.prj

6)Check new out.prj heightmaps but renaming to in.prj and running the first command again to produce 2 new Out.png files

7)Also copy new B5_01B.prj and rename to B5_01.prj to open with BTB editor that also displays heightmap.


http://www.mediafire.com/download/9ju36u5naaebuvq/AqritHeightMap.zip





Will post more updates and vids, using custom Gradient maps for finer tuning and perhaps we could automate reducing the White height levels within your code, rather than in Adobe Photoshop, one day.
« Last Edit: March 09, 2014, 12:17:39 AM by olly » Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
aqrit
Developer
*
Offline Offline

Posts: 85



View Profile WWW
« Reply #11 on: March 09, 2014, 08:51:27 AM »

I don't trust photoshop to not to screw up the 16-bit color images.... ( and gIMP will screw them up )
you should try adjusting the gamma/exposure in blender
... but I would think that somehow blender could be setup to make white a certain elevation and black a certain elevation, instead of high is white and low is black.
Quote
You can put a Blend Texture on your mesh, with the ColorBand white on one side and black on the other. In the MapInput tab (on the XYZ blocks) map everything to Z.
maybe?

things don't have to be renamed... in.prj out.png etc. are just descriptions aka this file is PRJ and is INPUT Smiley
terr -x B5_01B.PRJ weee.png splat.png would work just as well.
« Last Edit: March 09, 2014, 09:00:45 AM by aqrit » Logged
olly
Global Spokesperson
*
Offline Offline

Posts: 2268



View Profile
« Reply #12 on: March 09, 2014, 11:56:29 PM »

Unfortunately all my Mod terrains already have a Blend Texture on mesh, with the ColorBand white on one side and black on the other. In the MapInput tab (on the XYZ blocks) map everything to Z. (Fans only need raise some terrain and then can press F12 to produce height map, as all set up ready to go).

However, I found the solution was to make one terrain tile (or the edges in this test) to be 660 Blender Blocks high which then meant full White = 660 and therefore made 1 Blender Block = 1 Dark Omen block high. Using a modified BTB editor from Ghabry, which displays the heights, it can be used to check values match up. I also rotated the camera 180 so I don't have to flip the height map map vertically before importing.

http://www.mediafire.com/download/7cirdgw51hbrdw2/AqritHeightMapv2.zip


Using my old Gradient test map that gently slopes up to 10 Blender blocks high in the middle, now works perfectly - Eternal thanks!



Old Gradient 10 vid - shows troops "stepping up each block"

https://www.youtube.com/watch?v=xjIQAGAJ55o

New Video showing troops walking much more smoothly

https://www.youtube.com/watch?v=2igdS47qf0A


*More tests to follow and probably my blender settings at fault for 660 to be the work around solution will investigate further as have things like Orthographic Camera Scale set to 313 to fit in whole map etc. but the future is looking awesome*
« Last Edit: March 10, 2014, 12:40:20 AM by olly » Logged

and back in Nuln, the ageing Graf Berhardt smiled his secret smile of pride whenever he heard the latest tales of his eldest son's ever growing chain of glorious victories -(sothr manual)
Pages: [1]   Go Up
Print
Jump to: