<p>Deferred decals are a common way to achieve this without re-rendering the same geometry. It also allows you to change the appearance, i.e. add some gap or smooth out the details.</p>

<p>The algorithm:</p>

<ol>
<li>Draw a box around your height field, the size should be as tight as possible to avoid over draw. </li>
<li>sample the depth buffer to get the world-space position of the current pixel (the height field / other geo)</li>
<li>Project your box down in world space</li>
<li>Use the projected box coordinate to sample from your overlay texture.</li>
</ol>

CC BY-SA 4.0
2018-12-02T04:22:03.387Z
2018-12-02T04:22:03.387Z
Calvin
<p>What is the method used in overlaying a grid (agonostic of the grid type) on to a height map? It seems it's some sort of projection, but what are the technical details in how to implement it?</p>

<p>An example here is a hexagon grid overlayed onto the map in Civ5 that nicely handles spatial distance regardless of how high the height map is at a position - 
<a href="https://i.sstatic.net/yN0HQ.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yN0HQ.jpg" alt="enter image description here"></a></p>

CC BY-SA 4.0
2018-11-27T03:13:42.460Z
Maybe I misunderstood the question. You can just create 3d lines in the xz plane of that hexagonal pattern and set the y value of the points on the lines to the height map value at that location. The more points in the lines the better approximated it will be.
Andrew Wilson
CC BY-SA 4.0
2018-11-27T18:51:12.007Z
Maybe, my question was incorrect. I'm also interesting highlighting the height map area (different diffuse color or similar), based on user interaction. I'm not sure how to do all of this cleanly.
dev_nut
CC BY-SA 4.0
2018-11-27T22:00:37.970Z
You want a transparent filling for each cell? You can do this with a second pass. Just rerender the same terrain geometry but this time without texture/shading. Just a transparent color. Alpha blend the two rendered images together. For efficiency you can construct geometry with much less detail than the terrain that achieves the same effect by sampling the height map values at the edges.
Andrew Wilson
CC BY-SA 4.0
2018-11-28T00:21:35.973Z
This is close, but the main point was getting transparent filling (or at least a different color) for a specific cell, similar to the highlight cell above. The highlighted cell has a slightly different shading than the rest of the cells (in addition to the god rays).
dev_nut
<3d><projections>
Overlaying a grid on to a height map
dev_nut
# Overlaying a grid on to a height map

(Asked by: username_0 on 2018-11-26)

What is the method used in overlaying a grid (agonostic of the grid type) on to a height map? It seems it's some sort of projection, but what are the technical details in how to implement it?

An example here is a hexagon grid overlayed onto the map in Civ5 that nicely handles spatial distance regardless of how high the height map is at a position -
[![enter image description here](https://i.sstatic.net/yN0HQ.jpg)](https://i.sstatic.net/yN0HQ.jpg)

**Tags:** 3d, projections

> **Comments:**
> **username_1**: Maybe I misunderstood the question. You can just create 3d lines in the xz plane of that hexagonal pattern and set the y value of the points on the lines to the height map value at that location. The more points in the lines the better approximated it will be.  
> **username_0**: Maybe, my question was incorrect. I'm also interesting highlighting the height map area (different diffuse color or similar), based on user interaction. I'm not sure how to do all of this cleanly.  
> **username_1**: You want a transparent filling for each cell? You can do this with a second pass. Just rerender the same terrain geometry but this time without texture/shading. Just a transparent color. Alpha blend the two rendered images together. For efficiency you can construct geometry with much less detail than the terrain that achieves the same effect by sampling the height map values at the edges.  
> **username_0**: This is close, but the main point was getting transparent filling (or at least a different color) for a specific cell, similar to the highlight cell above. The highlighted cell has a slightly different shading than the rest of the cells (in addition to the god rays).  

---

## 1 answers

### Answer by username_2 on 2018-12-02. Score: 1 | Accepted answer

Deferred decals are a common way to achieve this without re-rendering the same geometry. It also allows you to change the appearance, i.e. add some gap or smooth out the details.

The algorithm:

1. Draw a box around your height field, the size should be as tight as possible to avoid over draw.
2. sample the depth buffer to get the world-space position of the current pixel (the height field / other geo)
3. Project your box down in world space
4. Use the projected box coordinate to sample from your overlay texture.


---

