Planetside Software Forums

General => Terragen Discussion => Topic started by: bigben on October 11, 2007, 07:28:08 PM

Title: Embedding multiple masks in an image
Post by: bigben on October 11, 2007, 07:28:08 PM
Following on from my Blue Marble experiment I couldn't help but think about using these images as masks. While the resolution is relatively low, the colours are reasonably realistic and there are no clouds, so they should be useful for defining broad environmental regions. Rather than generate additional images, it should be possible to compare the colour within the image to a reference colour using functions and set a deviation range on which to generate a mask. Should be technically possible, although the network might get a little complicated and performance will need to be tested.

So far so good, but what about the masks I painstakingly generate from landsat images... These are much higher resolution (10-15m after reprojecting to UTM), have unrealistic colours and do contain some clouds.  File size has always been an issue with greyscale image masks derived from these. Each project involved calculating a total image size (Mb) to be divided up amongst the masks. The criteria for selecting which resolution to make a mask got a little complex, with a particular mask often being made up of a combination of other masks of different resolutions.

Combining the two methods I'm going to test the following workflow:

In theory this should make it possible to add several high resolution masks to an image for the same cost as 3 greyscale images.  Something to play with over the weekend.  :)
Title: Re: Embedding multiple masks in an image
Post by: dhavalmistry on October 11, 2007, 09:44:23 PM
man...where the hell do u get all these ideas??....
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 11, 2007, 11:53:07 PM
Some people play brain training games on their Nintendo DS on the train... I play with TG2  ;D.  I have a varied and nerdy background (astronomy, geology, botany/zoology, scientific photography etc....) and with TG2 I get to draw on all of the stuff I've learnt and connect it together to solve problems (and occasionally make a cool pic). It's quite rewarding to actually use all this stuff I crammed into my head and that helps keep me on a roll  ;)
Title: Re: Embedding multiple masks in an image
Post by: Njen on October 12, 2007, 02:31:33 AM
At the very least, one can put 3 different masks into each of the individual colour channels of red, green and blue of any image format. While only limiting the number of masks per image to three, it's superior in a few ways:

* PSD is a proprietary format
* All image formats use RGB channels and can all be used in this method
* The technology to read the RGB colour channels separately is very simple
* Easier to manage than individual layers within a PSD
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 12, 2007, 08:53:52 PM
Quote from: njen on October 12, 2007, 02:31:33 AM
At the very least, one can put 3 different masks into each of the individual colour channels of red, green and blue of any image format. While only limiting the number of masks per image to three, it's superior in a few ways:

* PSD is a proprietary format
* All image formats use RGB channels and can all be used in this method
* The technology to read the RGB colour channels separately is very simple
* Easier to manage than individual layers within a PSD

I was referring to multi-layered PSD images mainly as my source for generating masks. I generate multiple layers for different components and then combine for a final mask output. This speeds the workflow as you don't have to be 100% accurate for each mask type. e.g. quick tree distribution - carefully drawn rivers and roads... or slope mask used to mask manually drawn rivers (preventing you from drawing rivers up the side of valleys as satellite images are not 100% accurate on terrain)... more in the blurb to follow... ;)
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 12, 2007, 09:08:50 PM
Well as usual I start with the most optimistic ideas and then work my way back to what is actually practical/feasible. The results so far:

Image size/format

Using RGB images was a bit of a silly idea as it's really trying to do too much. The main reason is that TG's limits with loading images seem to relate more to Mb than pixels.  You can therefore load a lager greyscale image than a RGB image i.e. higher resolution masks. Using different greyscale values within a single image for different masks is still a good idea though. The image I added to this project covers the south island and is 7500 x 8600 pixels. The equivalent blue marble texture is only 2700 x 3100 (full resolution).

[sidetrack] For those trying to push the limits of loading large RGB textures for planetary renders, you might try separating the channels to greyscale images and then reconstructing the colour in TG2 using a build colour node. It my be possible to get a 70% increase in image width unless you reach a memory limit before this. [/sidetrack]

Masking Regions

OK, so which masks to combine. Once again, I got too ambitious and tried to mask two non-adjacent areas. I was already concerned that it might not work as expected due to anti-aliasing creating a range of greyscale values at the border of two pixel values in the image. This concern was well founded as this render shows, but at this stage it's good to see when things don't work.

What did work, though is a substantial increase in resolution of the surfacing. You can see part of the lake from the blue marble texture protruding from the lake on the left... and of course you can make out portions of where a wide river bed would flow betweent the pink masked areas.The trick to using this successfully then is going to be in carefully choosing which adjacent features to include in a single mask. e.g. water, beach, rocks, all grass, green grass.  In my TG0.9 Grampians project I had these equivalent masks as separate images and didn't have enough RAM to have them all as high res. Some of the masks were at lower res, with careful surface order selection compensating for the lack of resolution (e.g. low resolution beach overlayed at edges by hig res lakes and grass)

There will still be some edge effects, so selecting features that will not look out of place when in close proximity in these areas will also help, as well as some additional mask adjustments to provide some extra breakup of the edges.

Tonal masking

While anti-aliasing creates some minor complications at the edges of these masks it also has many benefits. The first is that it greatly increases the apparent resolution of the mask (at the cost of some fine detail). It also increases the apparent tonal range, with an 8 bit greyscale image behaving more like a 16-bit image when you make adjustments to it in TG. It would therefore be reasonably practical to combine "hard" masks with tonal masks in the on image. e.g. all grass (hard mask, pixel value 128) and green grass (tonal mask, pixel value range 32-96). The base grass texture is for dead grass, overlayed with a texture for green grass blended by the green grass mask... Using conditional nodes and colour adjust nodes to extract the tonal range from the mask image and then adjusting it back to the full tonal range. The smoothing from anti-aliasing will add in the intermediate tones.

While this approach my not be as good as using full tonal images, it is all part of a balancing act. It's a compromise between resolution and the number of masks required. By reducing the number of masks required you can increase their resolution which in my experience is usually more beneficial than accurate tonal values.

Conditional nodes.

Had to have a play with htese  ;)  A few things didn't go quite to plan. To get the conditional node to work I had to convert the colour to a scalar first which wasn't expected. The output of the conditional node was somewhat pixellated but that was because of the way I had set it up (outputs of 1 or 0). To smooth it I could have set a colour adjusted image as the true output, but by the time you set that up for additional masks it would be easier to use colour adjust nodes in conjunction with add/sutract/multiply scalar nodes to construct the separate masks.

The Boolean conditional mask didn't seem to work at all???
Conditional: Image = 1, true = 1, else = 0 worked
Boolean conditional: Image > 0.9 didn't work

In situations where some pixellation is not an issue (distributions of large objects), using an image without anti-aliasing and conditional nodes could provide a quick method of setting up masks.

Very promising so far.... definitely worth some more experimentation.
Title: Re: Embedding multiple masks in an image
Post by: nvseal on October 12, 2007, 09:23:14 PM
All I can say is wow. :o
Title: Re: Embedding multiple masks in an image
Post by: dhavalmistry on October 12, 2007, 09:31:55 PM
speechless.....
Title: Re: Embedding multiple masks in an image
Post by: monks on October 13, 2007, 06:17:39 AM
This is great work BB. This is the kind of scales that ME-DEM will want to work at.

monks
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 13, 2007, 12:08:41 PM
Recovering from some odd system problems... had to download again and reinstall.

But prior to that, I had made some more progress and it's working reasonably well. 7 masks in one image. I've manually drawn some rivers in but the resolution is insufficient for them to actually show up (requires >1 pixel wide to account for anti-aliasing)  Other masks I've made at the full resolution of the landsat images were OK, but there's no way I'm going to get a 15m resolution image to cover this large an area.  (resolution of mask image here is only 90m)

I'll work on a closer view after I sort out a few more technical details. Already identified a few settings that need to be changed in the image map node to make the pixel values correlate better to the black and white levels in the colour adjust nodes. I'm a little surprised (pleasantly) that I haven't run into memory issues yet but I'm sure I'll be able to find that limit without too much trouble.

More results and details later.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 13, 2007, 07:34:34 PM
Back up and running. Here's a low res comparison showing the difference in resolution between the blue marble texture and my greyscale mask. I got the rivers back with a bit more tweaking of the colour adjust settings, although the main problem was a slope restriction.

The screengrab shows the links from the image map to the surface shaders.  This is a very basic setup to test the principle. To add a bit more variation I'd probably start by using the mask output as a blending shader for a fractal to use as the breakup for the surfaces.

[attachthumb=#3]

The main glitches in a method like this are where adjacent masked areas do not contain sequential greyscale values. In the worst case scenario of white pixels next to black, anti-aliasing will smooth the border to potentially create a full greyscale range.  The various colour adjustments will then result in narrow bands of every surface layer along this border.  How much of a problem this is depends on how close you want to get with the camera and the resolution of the mask.  This should be taken into consideration when choosing greyscale values for the mask regions, so that in some cases the banding will appear natural.  In this scene the progression from white to black is : Water > Rock > Sand > Dark dead grass/scrub > Light dead grass > Green Grass > Trees.  Layer order will also come into play but this will vary from scene to scene.

The other thing to remember is that creating masks is a very laborious process, particularly rivers, which require extensive checking and usually require a lot of manual drawing. 

[attachthumb=#4]

Lakes are a breeze now. I use a slope map from GM to select the lakes (magic wand with a tolerance of 1, not antialiased... lakes are white and the banks are not.), and the landsat image is used to locate them. This method was particularly useful for this mask image because there were some clouds over some of the larger lakes at the south end.

Still a few technical issues to sort out. Need to check Data is Linear in the Colour tab of the Image map node to start with or it's very hard getting the right colour adjust settings.

Backing the camera up a bit and running a larger, high quality render.  8)
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 14, 2007, 04:48:31 PM
Stopped the render as it displays enought for demonstration purposes. Bear in mind that the surfacing was left deliberately basic to clearly show the distributions.  From here I have to go back to a basic test image to produce a clip to extract masks from 10% increments in greyscale values.... and then make a full resolution mask of this area.

This result is definitely good enough for me to continue developing it.
Title: Re: Embedding multiple masks in an image
Post by: nvseal on October 14, 2007, 04:55:37 PM
This is looking fantastic. When can we see one from higher up?
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 14, 2007, 06:50:52 PM
Running a smaller version of frame 1 (the original orbital render). There were some clouds in the lower right of the south island so it will be interesting to see how these glitches in the mask appear from this distance.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 14, 2007, 07:15:57 PM
Just had a quick look in Google Earth to check my interpretation of the landsat image...  Looks like I was reasonably correct in choosing areas of green vegetation. Landsat images can be hard to interpret on their own as bare rock, areas burnt out by bush fires and lush grass can all be bright pink.

The larger lake is also lighter in all of the satellite imagery which could be easily handled by using white for dark lakes and 90% for light lakes in the mask image. Any edge effects on the dark lakes would just look like shallow water, and in those cases where there is some detail in the satellite imagery from different water depths, these could be added in to the mask as intermediate tones using a third colour adjust shader to create a tonal mask...
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 15, 2007, 12:21:21 AM
Here's a 500 pixel render from orbit. South island contains masked surfaces, north island contains blue marble texture.  Even though the render's a bit small, you can still pick out several lakes over the island and a long riverbed running across the island to the coast (cyan arrow).

The yellow arrow indicates the position and direction of the camera for the previous render.

Running a cropped 1000 pixel render now to show a bit more detail.  I got errors attempting 2000 and 3000 pixels renders. I'll have to track down which image is causing it, although I suspect it may be the mask image.

Just remember that the mask creation was only a quick one based only on the area for the render above. This mask only took about an hour to make including manually drawing some rivers. Taking that into consideration I'd say it's worked fairly well, which is probably more luck than anything. The next render is looking very cool  :)


[edit] here 'tis. You can see the riverbeds I was talking about at the top right.  Running a 1500 pixel render of the whole scene with better AA overnight (+). Compare this to the blue marble texture in http://forums.planetside.co.uk/index.php?topic=2512.msg24788#msg24788 (http://forums.planetside.co.uk/index.php?topic=2512.msg24788#msg24788)

Now for the long process of creating a proper mask... [/edit]
Title: Re: Embedding multiple masks in an image
Post by: monks on October 15, 2007, 04:40:51 AM
Won-der-ful.

monks
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 15, 2007, 07:41:37 AM
Thanks.

Now that the initial enthusiasm has slowed down a bit I can get back to being a bit more methodical  ::)

Attached a zip file with a test image and the node setup for these tests.  Colouring by numbers using a single greyscale image.
[attachthumb=#3]

As mentioned previously there are edge effects if image smoothing is turned on, but whether this is detrimental to the final image will depend on a number of factors.
[attachthumb=#2]
This demo shows a worst case scenario where masked areas are surrounded by black. If you zoom in really close on the edges you can see the banding resulting from image smoothing.

Turn image smoothing off and there are no edge effects.
[attachthumb=#1]

The best bit is, with "Data is linear" set in the image map's colour section the numbers matched the greyscale % set in Photoshop. You could potentially set even more masks per image, but that would depend on your uses for them.

Now to add some tonal masks to the mix....
Title: Re: Embedding multiple masks in an image
Post by: cyphyr on October 15, 2007, 08:05:18 AM
Is that a clamp function (I'm guessing clamp colour?) in there?
Richard
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 15, 2007, 08:24:08 AM
The colour adjust shader includes a 0,1 clamp. Black and white levels are placed close together just below the greyscale value of the region to be masked. You could set them just above the previous greyscale used, which would give you a slightly wider masked area. I've used this to create "beaches" for rivers by simply using colour adjust shaders with different limits.

You could also use 2 colour adjust nodes for each limit, using the "wide" mask for one mask, and subtracting the "narrow" mask from the adjacent tonal value. This would reduce edge effects on smoothed mask images but may have a detrimental impact on render time.  The performance of this kind of thing is one thing that has improved with the latest update. Some of the things I tried previously would simply crash TG in under a second, but now they render nicely.

So many ideas still spinning around... I'm definitely glad to have found a way around the limitations of my earlier masking projects in TG0.9 and TG2, but it will also mean many more hours creating the masks.  My Grampians project in TG0.9 was something of a personal milestone, but that benchmark has been moved a very long way with TG2... even taking objects out of the equation. Having almost as much fun as the guys working on displacement spires  ;)

Attached another test, this time of a best case scenario where tonal regions of the mask are in sequential order. Image is smoothed and there's only one edge with edge effects (left hand edge where white is adjacent to black)
Title: Re: Embedding multiple masks in an image
Post by: nvseal on October 15, 2007, 08:40:52 AM
This is looking so good! Can't wait for the next render.
Title: Re: Embedding multiple masks in an image
Post by: cyphyr on October 15, 2007, 09:04:56 AM
In you "best case" scenario could you use a "junk" colour that would have the edge effects occur on it but since your not using that colour it would not render, sort of like having a padding colour. Bit out of my depth but hey sometimes (read a lot) I just cant keep my trap shut :)
Richard
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 15, 2007, 10:14:11 AM
Quote from: nvseal on October 15, 2007, 08:40:52 AM
This is looking so good! Can't wait for the next render.

Alas, we're at the "waiting" render size  ;) ... although there's just the one cloud layer left in so it's progressing reasonable well.  Thanks for the clip.  I'll have a spare machine at work in a couple of weeks. I think it might have to render an orbital cloud animation test. Animating a single cloud fractal works really well in TG2. Animating multiple clouds with multiple fractals controlling blending and warping could produce some very interesting results.

Quote from: cyphyr on October 15, 2007, 09:04:56 AM
In you "best case" scenario could you use a "junk" colour that would have the edge effects occur on it but since your not using that colour it would not render, sort of like having a padding colour. Bit out of my depth but hey sometimes (read a lot) I just cant keep my trap shut :)
Richard

The colours in this case are simply to illustrate the distributions of the masks. I needed exaggerated colours so that I could easily see whether distriubtions were correct, and to highlight any potential glitches. 

There are several factors that would influence the final result and if/how much these edge effects would be noticeable so I wouldn't worry too much about them here. I've just mentioned them because they should be taken into consideration when selecting which greyscale value in the mask to assign to which surface. e.g. reflective water would really destroy a render if it shows up in odd places, so water surfaces should always be assigned to black or white so that there is no overlap on boundaries between other surfaces.

I have a couple more tests to do and then I'll show a real example, which will help put this into perspective. It's not necessarily ideal for all image-based masking but it certainly has a lot of potential for saving memorey usage by reducing the number of masks required, thus allowing higher resolution masks to be used ... which in turn results in more realistic renders.

Keep the trap open... explaining things helps me sort things out more clearly for myself, which is partly why this post is so verbose... thinking out loud  ;)
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 15, 2007, 07:35:39 PM
Spent the night working on the technical processes to correct the mistakes I made in the intial masks for NZ and I now have a clear idea of how to fix it.... then I got to work this morning and saw the "buggy" render about 2/3 complete. Looking very cool  :)

I've nutted out a process for using a range of mask greyscale values to create tonal variation within a masked area... or a gradated blending of the surface. I'll post a demo tonight and then start some serious work on the real masks for this project.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 16, 2007, 03:58:00 PM
Here's the next proof of concept... using TG's image anti-aliasing to create intermediate tones in an image with a limited pixel value range.

3 blocks of the step wedge image were filled with a gradation covering the same pixel value range as the blocks.  Using the previous method, the total distribution of the masked area is defined by  creating a "binary" image of mask using the high and low pixel values of the range and then subtracting them to get the difference.

An additional colour adjust shader is then used to increase the contrast of the gradation to whatever range is required... e.g. nomralised to 0 - 1 for use as a fractal breakup, or a smaller range for use as a colour function (as in this example) This provides extra flexibility for blending shaders using the same portion of a mask as well as creating extra variation within a surface.

Once again, the choice of mask subjects and their order is critical to dealing with any possible edge effects, but it is quite feasible to get 2-3 tonal masks and 2-6 binary masks out of a single mask image.

The sample render shows the original mask image showing the gradation in the middle, the effect of the step wedge surface shaders on this gradation, and a masked portion of just the gradation, with a contrast adjusted version used as a colour shader. The transform shaders are simply to avoid loading the image multiple times.

Used carefully this technique could be used to greatly extend the detail in masked renders using real life data in a reatively efficient manner, leaving extra resources for better surfacing and large populations.

I also did some testing to see why I got errors attempting to render the NZ scene at 2000+ pixels output. I removed the images 1 by 1 to no avail and then started on the terrains. Removing the largest TER file got a 3000 pixel render started so I may have to split this terrain into two parts. Posting a 1500 pixel orbital render in the image sharing section soon...
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 17, 2007, 09:17:12 AM
OK enough of the pretty coloured squares. "What's the point?" you may ask. The example in the first post shows multiple "binary" masks using a single mask image. This in itself is pretty cool. Now let's take the lakes as an example.  In my render they are all the same colour. In all satellite images, there are two large lakes in the centre of the south island that show up as being much lighter (shallower). In higher resolution imagery, you can also see some subsurface detail in many lakes giving you a sense of the depth of the water.

Starting with the satellite image and a slope map I first created a mask for the boundaries of the lakes. Using this mask as a selection, I copied the RGB image of the lakes to a new layer in Photoshop, extracted the blue channel, normalised it's pixel values and then set the black output level to 225 so that the lakes' pixel values ranged from 225-255. The rest of the image was filled with black, but would normally contain the other masks.

Now into TG2.
Load the image and use a colour adjust shader to set the black and white levels to 0.8, and feed this into the fractal breakup of a surface layer, creating the boundary of the lakes.

Link the image to a second colour adjust node, this time setting just the black level to 0.8, giving you a full greyscale image of the greyscale values from the RGB image. While you might expect stretching 30 pixels values out to a 255 pixel value range would contain significant banding, you have to remember than anti-aliasing was applied prior to the colour adjust, smoothing the pixel boundaries with intermediate tones. The result is instead incredibly smooth.

Apply this to the fractal breakup of a surface layer to act as a blending shader between a light and dark water colour, tweaking the gamma in the colour adjust node to get the desired effect. The end result is a hack of inland water bathymetry.  There is an edge effect in the render below, and I need to invert the mask greyscale values to reverse the effect so that the edges appear as shallow water. The edge effect will still be there, but it will be cunningly disguised  ;)

I'm always impressed by just how flexible the colour adjustments are in TG2. Given that I've started with an 8 bit image and applied some pretty severe adjsutments to a very small tonal range, the results are *very* smooth. This "feature" helps to make this technique more flexible by allowing more tonal masks to be squeezed in to a single image.
Title: Re: Embedding multiple masks in an image
Post by: Oshyan on October 17, 2007, 01:38:54 PM
Very nice results and cool in-depth manipulations of the masks. But are you sure those lighter lakes are just shallower? I rather suspect it's some kind of area-specific sediment or bottom coloration, like the bright blue or green alpine lakes you see sometimes: http://www.myroyaltyfreehd.com/assets/images/bright_blue_lake_in_alberta.jpg As you can see it does not appear to be a function of depth.

- Oshyan
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 17, 2007, 04:27:11 PM
They did seem to be unnaturally light... variations like this could be a combination of several things such as this or the colour of the material forming the lake bed. We have the reverse situation here in some places where the lakes are on very light sand but tannins released from leaves falling into the water make the water look almost black.  The cool thing is that it doesn't matter what the cause of variation is, it gets picked up by using a mask based on the actual colour of the lake.  An extra bonus   ;D
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 18, 2007, 09:05:11 AM
This is sort of becoming a diary for me for this project... more thinking out loud and a bit of progress...

The new mask is coming along nicely. The landsat images for NZ are fairly consistent which is making things easier. The first mask I made was an extrememly simplified technique. One of the biggest weaknesses of was that there was no allowance made for shadows. You can't notice it much in the render because the lighting is similar to the angle of the sun in the satellite images. 

This time, however, I went back to my more accurate hack to remove shadows...  Convert the satellite image to lab colour, fill the lightness channel with 50% grey and normalise the other two channels. Convert back to RGB and then run a curves adjustment to put some contrast back into the image. Add some adjustment layers to tweak the contrast/hues temporarily for highlighting certain regions, and then use colour slection to select the area.

Then it's a case of copying and pasting the relevant channel to a new layer and adjusting the levels to fit the range in the final mask image... simple really... kind of. Selecting the right colours to generate each mask can be very tricky.  [edit] Just had a look at the images you linked Oshyan and it seems I was a lot closer than I thought.  There are some minor adjustments to be made but it's going to be easier rather than harder. Those images were very helpful. [/edit]

The sample of mask image attached also shows some coastal subsurface detail. I'm going to try to include this around the north east corner of the north island. As the mask will be in a shader separated from all of the other regions by an altitude restriction, I can leave it as a full range greyscale image.This will be used to further lighten the subsurface detail "hacked" from 1km bathymetry data and should look really cool.

From my other resolution tests it looks like I'll be drawing a lot of rivers. Things have changed somewhat frommy original ideas, but the more I toy around with this the better it's looking, and it's a lot simpler than my previous masking efforts from satellite images. My last renders are starting to look pretty ordinary :)
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 21, 2007, 08:07:47 AM
Did a bit more work on the masks and applied it to my project.  I started with the coastal subsurface detail which worked pretty well but required some careful finetuning of several shaders to remove edge effects along the beach/water edge. There were essentially two main issues.

1. Antialiasing produced reduced pixel values along the beach/water edge over the water. This in turn resulted in the lake surface (darker, more saturated blue)  appearing in the shallowest water. This was fixed by adding an altitude restriction to the lake surface *and* reducing the white point to spread the amount of white across the margin.

2. Antialiasing also offsets the texture slightly as was apparent when I tried to combine a smoothed and unsmoothed image in the same mask setup. With some more experimentation I may be able to find an offset amount to realign the smoothed image. Such an offset is typical of image processing routines, and is usually too small to be noticed, but in this application it is critical.

The extra coastal subsurface detail looks pretty cool :)  Terrain surfacing was only partially reconstructed in this render.

[attachthumb=#1]

Reworking the surfaces to the new mask it's starting to look a little sexier than the original version.

Some aspects of this have improved, others have been degraded...although these only appear at closer camera angles.  Some more experimentation is needed to see if I can work around these problems, but even if I can't it's still a nifty method if used within its limitations. There are still a couple of gaps in the mask image I have to fill after I interpret what the colours are referring to.  There are no rivers drawn in the mask yet, so that will be another improvement to come.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 21, 2007, 10:16:48 AM
The rock layer in the last image above has too great a coverage.  This is due to me setting too big a gap between two ranges of pixel values and a discrete pixel value for the rock layer. I originally did this to ensure that I could easily separate the masks from the tonal range, but this has caused additional problems.  In practise, I'm using two decimal places to specify black and white levels to extract masks from the full range of tones, and since TG does this properly (now that I've been setting the colour to linear) I should be using greyscale values to reflect this.... i.e. individual masks should have gaps in pixel values of no more than 2. In this case it is 10.  I've re-adjusted (extended) the limits on the masks adjacent to the rock mask to create a more discrete rock mask. This looks better in the preview with a dry grass distribution closer to what I expected.

Rendering an oblique view to show the range of accuracy over different distances, (hopefully getting too close to show the detail degrading too much)
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 21, 2007, 04:34:24 PM
OK. Here's the oblique view clearly showing the banding and edge effects resulting from this masking method. The foreground lake has used this to advantage, creating the appearance of a band of shallow water around the lake.  From a distance, the banding also creates the impression of sharpening the textures but up close it's going to require some extra blending with fractals to disguise the edges, although this will still have limited success.
Title: Re: Embedding multiple masks in an image
Post by: Arandil on October 21, 2007, 04:42:54 PM
Y'know, I'm gonna have to name the scuff mark forming on my jaw, from it hitting the floor, 'littleben' ...
Title: Re: Embedding multiple masks in an image
Post by: Oshyan on October 21, 2007, 04:43:23 PM
The banding is definitely an issue from up-close, but the results still look very good. So are you working up toward an animation here or what? From orbit to ground? ;D

- Oshyan
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 21, 2007, 08:20:53 PM
Quote from: Oshyan on October 21, 2007, 04:43:23 PM
The banding is definitely an issue from up-close, but the results still look very good. So are you working up toward an animation here or what? From orbit to ground? ;D

- Oshyan

That pretty much entered my head with the first version (I've been itching to do one for ages), although it doesn't necessarily have to be using this method.  These tests have largely been looking at an alternative approach to that vexing compromise between mask resolution and RAM usage. Mixing different methods would probably complement each other, but I'd want to output something before I start exploring different combinations/permutations.

I'm still exploring the limitations of this method and still have some room for optimising the mask image. For testing purposes I've only used 30 greyscale values for each tonal mask. As I only have a few masks I could reallocate the remaining pixel values to get 50 values per mask.... and I haven't attempted to "disguise" the borders yet. 

I also haven't found a limit for the size of mask I can use. While I can't make the mask image much bigger, there's nothing stoppping me from tiling the mask in the same way that I have tiled the terrain. The limiting factor there would be the size of image I can work on in Photoshop, as the processing involved wouldn't work with separate images.

If I can figure out using matching smoothed and unsmoothed images in the same TGD then this opens up a few more possibilities, although not necessarily for this scale of work.  I'm almost at the end  ;)

I have a couple of ideas for "cheating" on the animation.... zoom down to some water and then move across to a forested/grassy terrain.... or fly into a conveniently placed low cloud and have trees appear as the camera comes out the other side.
Title: Re: Embedding multiple masks in an image
Post by: Oshyan on October 21, 2007, 08:38:11 PM
The whole "switch scenes when you go through a cloud" thing is a very common approach. I'd actually hoped, with TG2's planet-to-ground scale capabilities, that future such scenes could eliminate that cliche. ;)

- Oshyan
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 21, 2007, 09:01:19 PM
Then I guess I'll be trying it without the cloud. No guts, no glory  ;) 

I'll be using multiple versions of populations/ surface substitutes masked by distance shaders to provide additional LOD fading with distance anyway... I'm just not too sure at the moment how well it will work so I was thinking of a fallback position.  That will be another set of tests again, although I have previously mocked up the masks for the proof of concept and now understand the quality settings in populations better. 

But I'll run an animation without objects prior to that 'cos I won't be able to wait that long to see it (just after I render a mega composite).
Title: Re: Embedding multiple masks in an image
Post by: Oshyan on October 21, 2007, 09:10:33 PM
Sounds good, I can't wait! Depending on where I'm at with my own animation I may be able to help with rendering too, although I know you have some good horsepower at your disposal. ;)

- Oshyan
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 22, 2007, 04:52:26 AM
There was one step I forgot to include, and it fits in with the animation and my terrain tiling method...  I can get a lot closer to a small part of the terrain by using a full resolution mask for that area.  The mask above is the same resolution as the terrain (90m). Here's a small section out of the image I'm going to create a high res mask of.  15m per pixel  At this resolution the terrain detail will be the limiting factor requiring extra detail to be added. The extra mask will cover 90x90km.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 24, 2007, 07:25:09 PM
Creating the masks takes a long time, so in the meantime I'm doing some stress testing and minor tweaking in preparation for an animation. The first stress test of course is memory usage for the up close renders, so I added a preliminary version of the high resolution mask (just contains lakes and rivers) and added a 30km square of billboard trees. My home PC died several months back and I'm using a decapitated laptop with only 1Gb of RAM. I expected a crash but I managed to squeeze this out... only 530,000 trees, billboard image about 420 pixels square.

After making a minor adjustment to the mask image I tried again but this time it crashed so I must have been close to the memory limit. So before I go too much further it's time for some slashing.

The first place is the terrains. All of the terrain here are at 90m resolution, done intentionally for producing a very large render from orbit. Shifting to an animation has changed the requirements so I'll go back to a concentric set of terrains of decreasing resolution. This will cut the terrain sizes down from 300Mb to 96 - 120Mb... which is exactly why I worked on the technique. I'll probably have to do the same thing with the mask images, although it may be possible to leave them as they currently are. Removing the Blue Marble images will get me a bit more room although they weren't excessively big. This will hopefully give me enough memeory to whack in another million billboard trees and 1-2km of full poly trees.  (and of course, this whole topic is geared at minimising the memory usage of image masks)

I still haven't broken up the edges of the mask regions or tried any extra blending, but I have a couple of approaches to try for this. I also have a "cunning plan" to remove fractal detail from the rivers, although the impact on memory usage is yet to be determined.

The other thing to note is that using the paint brush in PSD to draw rivers is definitely not suitable for these low resolutions. Use a pencil and let TGs antialiasing do the smoothing. Having said that, it is possible to create even narrower rivers using the paint brush and multiple colour adjust nodes to repeatedly increase the contrast of the mask but that's not compatible with this multiple-mask image. The left hand river was wide enough to use the magic wand to select it (the gap was a glitch in the image), while the narrower river to the right was hand drawn with a 3pixel brush and has been reduced to a string of pools after smoothing. At this resolution a 1 pixel stroke around the water mask would produce a reasonable river bank of rocks.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 25, 2007, 03:02:33 AM
Removed fractal detail from water without reloading terrains. Seethe post above, where you can see extra terrain detail in the water. The image in this post just has waves and the noise that coours in the elevation data. The banks are steep but this could be smoothed by using a separate colour adjust node to create a more appropriate blending mask.

* River/lake mask subtracted from terrain blending mask.
* Normal terrain blending mask applied to terrains without fratcal detail
* Terrain mask - water mask applied to terrains with fractal detail
* Both sets of terrains are then merged using the water mask as the merge function

This should be particularly helpful for manually drawn rivers on steeper slopes where fractal detail tends to be more pronounced.

Render times were longer, but that was to be expected.  Also note the round green patches which are antialiased square pixels from the low res mask image
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 28, 2007, 07:03:27 PM
Created a new terrain set and tracked down the displacement that was screwing up my water surface. It would seem that the most practical way of having smooth masked rivers is to remove fractal detail from the terrains and then add the detail manually as there is no practical way of masking the fractal detail (merging terrains is too costly from a performance point of view)

Some quick test renders to test memory usage. the first two contain just surfaces (blue marble texture and masked surfaces) and the third has a population of billboard trees added.  The billboard tree image is only 400x400 pixels, and the 500,000 odd trees didn't add much to the overall memory usage :) (about 1.4Gb (RAM+VM))

Running a full size render (1600x900) now to check, but so far it's looking like rationalising the terrains has got me another 600Mb of memory to play with.  There are now two mask images, one covering the entire south island, and the other covering the highest resolution terrain at 15m resolution.  I may split the number of masks in the last image into two separate images so that banding is not as much of a problem. 1: Water, sand and rock 2: Dry and green grass, trees. 

These are more likely to work nicely together (e.g. water and rocks will always be surrounded by a small amount of sand) and will let me do my normal displacements for lakes and rivers to give them a bit more of a noticeable bank.

Large render is almost 1/3 done and is looking quite promising from a memory usage perspective. Currently oscillating between 1.2 - 1.4Gb despite increased render size, detail and AA.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 30, 2007, 05:45:52 PM
OK, so by now you're probably thinking that this is still looking a bit too chunky to be real... and it is... but as I said, the high res masks take a lot of work to prepare. This next test is another memory test to see what happens when I add a second high res mask to the project (and removing the south island blue marble image)... The render consists of just the terrain (no fractal detail), two masked surfaces for water and dry grass and because the snow was at the bottom of the node network I left it in as well.  The grey bits are to be filled with sand, rock, green grass and forest.

The start of the render was promising, with memory usage still around the 1.4Gb mark, but this gradually crept up to 1.8Gb 1/3 of the way through at which point I went to bed. That's not going to leave me enough RAM for billboard and poly trees so I'll either have to try and make do with a single high res mask or split the tgd into two components at the end, one for the approach from orbit (minus objects), and one for camera angles within the central terrain (minus bathymetry image, outer terrain, island terrains etc....). I'm leaning towards the latter mainly because I want to have some overlap between some of the masked regions

The water surface in this contains no fractal breakup to keep it looking relatively blurred, although it needs an additional colour to shift the shallowest water closer towards a sand colour (easily done).  The dry grass layer consists of a surface layer using a boolean style BW mask (only black and white) for the fractal breakup to control the surface distribution, a power fractal for the light colour as the input and another power fractal for the dark tone using a tonal version of the distribution mask as a blending shader. If further disguising of the last mask is required at closer camera positions I'll multipy it by a power fractal with high/low values of 1, 0.7 respectively

This is getting back towards looking very cool again ;)

Running a render at the border between the high and low res masks  of the same view from the tgd used for the orbital render to demonstrate the difference in resolution.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 30, 2007, 09:22:45 PM
Got impatient and stopped half way.  Here's a side by side comparison of the initial orbital render and the new  high res masks. Camera altitude is about 18km. There is some difference in the distribution as I have gone deliberately broader with the second mask to provide some overlap with green grass for extra variation. The tones in the mask are based on the original image, not the colourised version used for selecting the distribution, so this is greatly improved. Some gamma adjustment of the tonal mask is required to bring out the contrast a bit more, but the shading is there if you look closely.
Title: Re: Embedding multiple masks in an image
Post by: bigben on October 31, 2007, 09:04:41 PM
Added an extra test surface and an updated 1 mask with more rivers. Camera height dropped to around 500m (too low :( )  Antialiasing killed off the 1 pixel wide rivers, so a 2 pixel pencil is definitely the minimum for making TG2 masks. To get finer detail after that you need to increase the resolution of the mask.

Using a wider brush than the detail you're tracing is a bit scary, but you have to rememebr that antialiasing will bring it back in line.

Still screwed up the subsurface masking order... will have to look at my ocean setup and copy it rather than build from scratch  ;).  The third colour is giving better variation but the colours need adjusting.

At least now I'm reaching the limits for the current data I have and can start some serious building of the final masks.
Title: Re: Embedding multiple masks in an image
Post by: Volker Harun on November 03, 2007, 07:49:29 PM
I must admit that your explorations were far off what I had in mind. Though I was trying to get a realistic touch to my images, I was far away from reproducing, rebuilding - in an artistic matter.

Now I have a project - I need to get some Jamaican beaches copied for a real estate 3D environment ...

Ben, I really (I do) appreciate your forthgoing work! Thanks, Dude!
Title: Re: Embedding multiple masks in an image
Post by: bigben on November 04, 2007, 01:01:38 AM
You're welcome.  If you have any questions about what I've done, just ask.  Most of it is basic masking and the rest is just using the features of TG2 to cram more resolution into the maximum memory allocation. I have no doubt that you can manage the extra blending to disguise the mask borders.  ;)
Title: Re: Embedding multiple masks in an image
Post by: Mandrake on November 04, 2007, 08:21:45 AM
Ben, at the risk of entering this thread with my head up my ass, because this discussion is a bit advanced for what I'm doing now.
I'm wondering if you've been following the World Machine program?
It may be that the new outputs may help you with masking future work.
This masking work for populating obj's is very kewl..
http://world-machine.com/wm2/upgradetour.html#RGB
http://world-machine.com/blog/
Title: Re: Embedding multiple masks in an image
Post by: bigben on November 04, 2007, 02:14:06 PM
I've had a bit of a look at the new WM, but haven't played much as this data is only 90m res which isn't that useful when run through WM. I've found 30m resolution to be a minimum for getting really useful stuff out of WM, and there are some interesting new features that would be useful... although I'm trying to reduce the number of mask images at the moment ;)

There are still some features of TG2 that I have yet to fully explore for terrain-based masking purposes.