# View-aligned voronoi islands (for infinite forests, Eevee and Cycles)

**URL:** <https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131>\
**Category:** Tutorials, Tips and Tricks\
**Created:** [March 7, 2022, 5:44pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131 "2022-03-07T17:44:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThomasKole](https://blenderartists.org/user_avatar/blenderartists.org/thomaskole/32/1388979_2.png) [@ThomasKole](https://blenderartists.org/u/ThomasKole)\
**Post date:** [March 7, 2022, 5:44pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/1 "2022-03-07T17:44:16Z")

</div>

A while back I posted an update about my Tenochtitlan project:  
 ![tmp](https://blenderartists.org/uploads/default/original/4X/9/0/6/9060fd376ca4440afd3926c12454d2beddf9b90c.gif)

> [@Tenochtitlan (wip)](https://blenderartists.org/t/tenochtitlan-wip/1360197/7):
>
> For the longest time I was struggling with the trees on the terrain. The scale of the scene is much to big for individual trees, even with tricks like imposters and cards. But just slapping on a color with some noise is also not good enough. I think I’ve found something? Here’s the first attempt: [tmp] Essentially, I generate little view-space oriented planes on a mesh in a shader, to which I can apply a tiling tree texture: [tmp] I hope what I’ve done makes an…

I’m showing the way I am generating a procedural infinite forest in a shader.  
The underlying concept is what I’m calling view-aligned islands. Essentially,  
I’m generating little UV islands which always look at the camera, but also stay anchored in their centers.

![tmp](https://blenderartists.org/uploads/default/original/4X/1/9/2/19231c466d960765df34818c90c2e00fe24b95b8.gif)

# Let’s Begin

It starts with a voronoi node. This creates the cells as a basis for the islands.  
A vector pointing towards the center of each island is created using this Vector Transform trick:

 ![image](https://blenderartists.org/uploads/default/original/4X/8/7/9/8791d08eff0be1989f086dc37073e971c4201b8c.png)

The node transforms (0,0,0) from _camera space_ into _world space_, which gives me the position of the camera in the world.

Using a couple of cross products, I can create two important vectors:

- One pointing to the right as seen from the camera
- One pointing up, but along the camera’s plane

Note the first cross product with (0,0,1); this determines the up direction of the trees.

 ![image](https://blenderartists.org/uploads/default/original/4X/3/e/2/3e2cbc4199d87873235ff6d0e4d293709a1aeaa9.png)

Next, we can use dot products to create two UV coordinates: One based on the actual world position, the other on the center of each voronoi island:

 ![image](https://blenderartists.org/uploads/default/original/4X/4/c/c/4cc55f81ade9a7ebef91e38ca9735027856997c5.jpeg)

This is ok as is, but we need to correct a perspective mistake.  
First, we divide both UV coordinates based on the original camera vector lengths:

 ![image](https://blenderartists.org/uploads/default/original/4X/3/1/7/317ce72ccd83f3851eb80dd290af3b258741aed9.jpeg)

Then, we scale it back up based just on the voronoi island camera vector length:

 ![image](https://blenderartists.org/uploads/default/original/4X/9/b/1/9b1662e1a58e437b2271159d7408091b167075ff.jpeg)

# Result of step 1:

**And we’re done here! Now we have little UV islands that face the camera:**

 ![image](https://blenderartists.org/uploads/default/original/4X/c/6/f/c6f84d3345cf11228bdbec2b2512726db3ce1e71.jpeg)  
 ![image](https://blenderartists.org/uploads/default/original/4X/9/7/6/9763291aaa3467a47e3e58ebca5ad733188252ac.jpeg)

We can use this coordinate to sample a texture:

 ![image](https://blenderartists.org/uploads/default/original/4X/6/1/5/61556165cb65a0541b23ca2063b4101050570d49.jpeg)

# Blending the borders:

If you find the harsh island borders off-putting, we can use a white noise texture to “blur” the borders.

 ![image](https://blenderartists.org/uploads/default/original/4X/8/7/1/871c37fb82496292e529d4626c00cd2a35ff0e97.png)

This jitters each sample by a little bit, and when multiple render samples, the result should be a blur:

 ![image](https://blenderartists.org/uploads/default/original/4X/c/0/1/c0127259abd7adf812bcaad57c827060cb71b82e.jpeg)

Looks great in Cycles, not so much in Eevee:

 ![image](https://blenderartists.org/uploads/default/original/4X/4/3/9/439e71bdd3e51e94d6e6ca150828a9c037f682e2.jpeg)

The borders are all mushy and grey. This is the result of mip-mapping. The noisy offsets trick Eevee into thinking the texture is very far away. Choose “smart” texture filtering, and the problem goes away:

 ![image](https://blenderartists.org/uploads/default/original/4X/4/7/7/47748d83bee7cd9570e5f248a1a4ce5f683438c8.jpeg)

# Wrapping up:

So, these are view-aligned voronoi islands.

For my trees, I generated one big texture with trees, in various passes, like this:

 ![image](https://blenderartists.org/uploads/default/original/4X/c/2/1/c21713afe34453121af45dac8a059e6e2c139ad4.jpeg)  
 ![image](https://blenderartists.org/uploads/default/original/4X/b/a/5/ba555eaecd906664bf57f38ffceaff0d11a5ac72.jpeg)

Based on the desired tree density at any point I shift the UV a bit to the right.  
I also have a random-per-tree texture, which I use to randomly colour my trees.

# Additional tips:

The voronoi node has a “color” output, which returns a random color per island.  
This is in turn 3 random values, in R G B.  
You can use these values to randomly rotate, shift, and scale each island.

Combine this random color with a random color per tree to break up the tiling of the tree texture.

If you generate a normalmap from your trees, you can use the generated vector to construct a worldspace normal map. This helps with lighting.

# Pro’s and Con’s

The cool thing about this is that the render cost is flat - the same for every pixel, not matter the size of your forest. This also means that iteration is super fast, much faster than using something like individual trees or even billboards.

The downside of course is that it is a hack; There’s no acutal volume, no correct shadows, no silhouetting.

# .BLEND

Have fun and try for yourself:  
[ViewAlignedVoronoiIslands.blend](https://blenderartists.org/uploads/short-url/6ePVyoTEZIHrCszEbwj9XRTv5UO.blend) (1.1 MB)

---

<div class="post-metadata">

**Author:** ![Artproject](https://blenderartists.org/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@Artproject](https://blenderartists.org/u/Artproject)\
**Post date:** [March 7, 2022, 6:54pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/2 "2022-03-07T18:54:32Z")

</div>

absolutely brilliant and much appreciated! 🙂 - I’ve been struggling to populate some vast Oregon forest scenes with infinite forests and this will help me immensely - your explanation has also clarified my understanding of vectors - thanks! - you are hereby added to the Thanks To list in the movie’s credits - movie’s called The Migrant, possibly released in late 2023 - all the best, Stephen Norrington

---

<div class="post-metadata">

**Author:** ![Hoverkraft](https://blenderartists.org/user_avatar/blenderartists.org/hoverkraft/32/10549_2.png) [@Hoverkraft](https://blenderartists.org/u/Hoverkraft)\
**Post date:** [March 7, 2022, 10:17pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/3 "2022-03-07T22:17:29Z")

</div>

You really went above and beyond, this is better than some paid tutorials. Thank you!

---

<div class="post-metadata">

**Author:** ![Mark06GT](https://blenderartists.org/user_avatar/blenderartists.org/mark06gt/32/495950_2.png) [@Mark06GT](https://blenderartists.org/u/Mark06GT)\
**Post date:** [June 28, 2022, 11:23am UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/4 "2022-06-28T11:23:12Z")

</div>

Thank you so much for sharing and developing this technique. I’ve been struggling with ways to create large-scale environments. This will be a huge help!

---

<div class="post-metadata">

**Author:** ![Modron](https://blenderartists.org/user_avatar/blenderartists.org/modron/32/672_2.png) [@Modron](https://blenderartists.org/u/Modron)\
**Post date:** [June 28, 2022, 3:46pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/5 "2022-06-28T15:46:19Z")

</div>

This is very interesting. Thank you for posting.

---

<div class="post-metadata">

**Author:** ![SterlingRoth](https://blenderartists.org/user_avatar/blenderartists.org/sterlingroth/32/3107_2.png) [@SterlingRoth](https://blenderartists.org/u/SterlingRoth)\
**Post date:** [June 28, 2022, 6:00pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/6 "2022-06-28T18:00:00Z")

</div>

This is a very cool technique. Thank you for sharing this.

While playing around, I added in some angle based effects, so forests seen at a glancing angle are more vertical, and looking down on them from above look more like an aerial view:

 ![image](https://blenderartists.org/uploads/default/original/4X/a/8/1/a813aa70a2c8db8011f19e37c7b702859cd6364b.jpeg)

Thanks again @ThomasKole , there’s some powerful vector magic in there that is really cool.

---

<div class="post-metadata">

**Author:** ![ThomasKole](https://blenderartists.org/user_avatar/blenderartists.org/thomaskole/32/1388979_2.png) [@ThomasKole](https://blenderartists.org/u/ThomasKole)\
**Post date:** [June 29, 2022, 6:09pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/7 "2022-06-29T18:09:09Z")

</div>

Wow, looks great!

---

<div class="post-metadata">

**Author:** ![joseph](https://blenderartists.org/user_avatar/blenderartists.org/joseph/32/1433056_2.png) [@joseph](https://blenderartists.org/u/joseph)\
**Post date:** [June 29, 2022, 6:25pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/8 "2022-06-29T18:25:58Z")

</div>

I’d love to see the details on how you did this 🙂

---

<div class="post-metadata">

**Author:** ![SterlingRoth](https://blenderartists.org/user_avatar/blenderartists.org/sterlingroth/32/3107_2.png) [@SterlingRoth](https://blenderartists.org/u/SterlingRoth)\
**Post date:** [June 29, 2022, 6:57pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/9 "2022-06-29T18:57:52Z")

</div>

For my source image, I used the same density gradient effect that @ThomasKole was showing along the x axis, but I added an “angle” gradient on the y axis:

 ![image](https://blenderartists.org/uploads/default/original/4X/5/9/6/596dd0b4db3e9984b75b7705ff3388e547f78ece.jpeg)

so the trees at the top of the image are seen from the side, and the ones at the bottom are seen from the top

Then I used the incoming normal to get the apparent angle of the surface as viewed from the camera:

 ![image](https://blenderartists.org/uploads/default/original/4X/6/e/c/6ec3ee4fa6afc931c8b1a76efc1d30044faeb3c2.jpeg)  
I then used that as a factor to displace the uvmapping per voronoi cell on the Y axis, plus some randomness from the voronoi color

I used a noise node to generate density variations, and did the same displacement with some randomness on the X axis.

Since I rendered my scattered tree image as a transparent .png, I composited in a couple ground textures, influenced by the density noise texture

Here is my file, with textures reduced for upload:  
[ViewAlignedVoronoiIslands - aerial terrain rendering - CC-NC.blend](https://blenderartists.org/uploads/short-url/iFV2bDURGcmxsNRK9IjFbaq7eTA.blend) (3.3 MB) (CC-NC license)

---

<div class="post-metadata">

**Author:** ![UnCommonGrafx](https://blenderartists.org/letter_avatar_proxy/v4/letter/u/b5a626/32.png) [@UnCommonGrafx](https://blenderartists.org/u/UnCommonGrafx)\
**Post date:** [July 1, 2022, 10:47am UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/10 "2022-07-01T10:47:44Z")

</div>

That is most informative. Ha, well over me head!  
This is brilliant material to study. Thank you for your efforts.

---

<div class="post-metadata">

**Author:** ![ThomasKole](https://blenderartists.org/user_avatar/blenderartists.org/thomaskole/32/1388979_2.png) [@ThomasKole](https://blenderartists.org/u/ThomasKole)\
**Post date:** [December 4, 2022, 7:08pm UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/11 "2022-12-04T19:08:48Z")

</div>

I’ve been trying to break up the contours a bit with Geometry Nodes. I have this weird thing working…

> [@Request: Geometry Nodes Camera Outline](https://blenderartists.org/t/request-geometry-nodes-camera-outline/1420290/5):
>
> Huh, instead of shading the fins, I use refraction. That seams to work a lot better thinking Very nice fluffy contours Those little green bits are slanting slightly backwards, causing them to refract what’s behind on the hill

 ![](https://blenderartists.org/uploads/default/original/4X/3/c/2/3c266c18e26e93d1690fa2440ca3185c73211172.jpeg)

---

<div class="post-metadata">

**Author:** ![skuax](https://blenderartists.org/user_avatar/blenderartists.org/skuax/32/640868_2.png) [@skuax](https://blenderartists.org/u/skuax)\
**Post date:** [September 12, 2023, 8:49am UTC](https://blenderartists.org/t/view-aligned-voronoi-islands-for-infinite-forests-eevee-and-cycles/1366131/12 "2023-09-12T08:49:22Z")

</div>

Congratulations, really smart. Thanks for the deep explanation.
