• Create Account

Banner advertising on our site currently available from just \$5!

# Making holes on a heightmap based terrain

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1GeneralMeliante  Members   -  Reputation: 149

Like
0Likes
Like

Posted 09 October 2012 - 01:50 PM

I'm currently working on a cylinder shaped terrain produced by a height map. What happens in the program is simple, there is a texture for the colors of the terrain that has the alpha value of regions in with i want it to be invisible and another texture ARGB with the A being the gray scale for the heights and RGB is the normal for the light. The texture is such that the A value goes from 1 to 255 and I'm reserving the 0 for the regions with holes, meaning i don't want then to exist. So in theory no problem, I'm making those regions invisible based on the first texture but on practice what's happening is that the program is considering the 0 as the minimum height and, even with the texture on top, is creating some lines towards this regions of 0, like trying to make its triangle but not getting there because i cut the next vertex by making it invisible.

The image below is with a clip() function making the region invisible

This next image is without the clip function:

Notice the lines going to the center of the cylinder This is how it gets when i stop making those vertex invisible
So, just to say, i used the function Clip() on the pixel shader to make it invisible.

My questions are: Is it possible, the same way i used clip() on the pixel shader i do something like that on the vertex shader and get rid of the unwanted vertex? Basically, is possible to just say to ignore value 0? Any ideas to fix this? Another thing is that we can see that the program is interpolating the values from one vertex to the next, that is why i cuts on halfway through to the invisible vertex.

On a more technical point of view the domain shader is the one picking the heights from the texture and plotting it.

I managed to fix this somehow by modifying the texture, through the program, by changing the 0 values of the heights to a more proper one, but i'd like to know if there's a possibility through the HLSL.

I'm working with Directx11 API with C++ and the program uses Tessellation.
Thank you for your time and will be very glad with any input on this!

### #2PhillipHamlyn  Members   -  Reputation: 458

Like
3Likes
Like

Posted 09 October 2012 - 02:07 PM

I dont think that is possible. The heightmap texture will be sampled in the Vertex Shader based on the geometry and interpolated for the triangle inners. To have a hole you'd have to have a hole in your geometry, such that the Vertex Shader would not get passed the triangles that describe the hole. I've never thought about that possibility - so I could be way out of line, but I've got a height map based terrain and I also would struggle to punch a hole in the geometry without doing it explicitly.

Alternatively you could just paint the Zero height region transparent - after all it only needs to look like a hole doesn't it ?

### #3phil_t  Crossbones+   -  Reputation: 5288

Like
0Likes
Like

Posted 09 October 2012 - 02:24 PM

To have a hole you'd have to have a hole in your geometry, such that the Vertex Shader would not get passed the triangles that describe the hole.

Well, you can certainly "reject" triangles in the vertex shader by setting each of the 3 vertices to the same position. But that's going to be difficult/impossible if you're sharing vertices between triangles in your terrain, since the same vertex will be used for triangles you don't want to reject.

### #4Krohm  Crossbones+   -  Reputation: 3658

Like
1Likes
Like

Posted 10 October 2012 - 12:56 AM

I strongly advice to not do so at vertex level.
It's worth noticing it is not possible, in a VS to set "each of the 3 vertices to the same position". This is Geometry/Primitive shader capability, for which you could just avoid emitting a primitive to rasterize.
Also note that moving vertices has a consequence on shading and rasterization on all primitives using it.

In the past, I've been moderately successful using height map parametrization to encode hole points. It required some uniforms and I didn't consider it good enough for general use so I didn't invest on it. However, this technique has re-surfaced in L4D2.
I'm currently inclined to use precomputed low-res distance fields instead. But given the availability of large (for my purpose) uniform storage in SM4 and beyound, I guess I won't spend more effort on it.

edit: typo

Edited by Krohm, 10 October 2012 - 12:57 AM.

### #5phil_t  Crossbones+   -  Reputation: 5288

Like
0Likes
Like

Posted 10 October 2012 - 11:29 AM

It's worth noticing it is not possible, in a VS to set "each of the 3 vertices to the same position".

Sure you can do this, I do it all the time. Maybe I phrased it incorrectly - if each of the 3 vertices outputs the same position from the vertex shader, the primitive is essentially rejected.

### #6Krohm  Crossbones+   -  Reputation: 3658

Like
0Likes
Like

Posted 12 October 2012 - 01:10 AM

Yes, I understand what you mean.
But as you wrote "that's going to be difficult/impossible if you're sharing vertices between triangles".
Anyway, no matter how we phrase that thing, VS cannot natively do that. It needs to be instructed in doing that using a texcoord. It is just better to use a GS.
The primitive is not rejected. It is degenerated, a 0-fragments triangle. That's not the same as rejecting a primitive, nor the same as rejecting the rasterized fragments. I notice you have used quotes to de-emphatize the word but I find that idea dangerous to let go.

Because of the limitations of this system and the lack of flexibility, I advice against this method. If it works for you, good (implies independent vertices for terrain?). But I'm having difficulties thinking at it as a best practice.

edit: more elaborations on what "reject" means here.

Edited by Krohm, 12 October 2012 - 01:12 AM.

### #7GeneralMeliante  Members   -  Reputation: 149

Like
0Likes
Like

Posted 15 October 2012 - 10:47 AM

Well guys, first thank you very much for your input.

Based on the overall answer it looks like this "move" on the VS is a very tricky one and not recommended if it is possible.

And yes what i was doing is using a diffuse texture to get those holes transparent and what i was trying to fix was this weird lines trying to reach the regions of zero because from one vertex to the zero one there is a direct line connecting then and when i clip the zero vertex it keeps half the line.

As sad on my first post i managed to fix this quite well by changing the zeros of the texture to a better suited value. In a way that the zero region would now have a value equal to its non-zero neighbor and the lines wouldn't go weirdly to the center so when i passed the diffuse texture the lines would, in theory, be pointing along the the cylinder terrain.
What did happen is that i can hardly see the lines now, so great.

Thanks very much, it was very informative (btw i loved the L4D2 thing)

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS