Advertisement

"3D Decals" for roads on terrain.

Started by July 30, 2017 03:02 AM
24 comments, last by 3ddominator 6 years, 11 months ago

Hi, in both situations, the spline will go over the mountain.  But in:

in forward rendering:

- render decals to backbuffer, no z depth test against the landscape (as its not rendered at this point).  Ideally you should employ a z buffer just to enforce correct draw order in decal buffer.  If you dont z test the decal buffer then draw order will dictate the scene (ie possible overwrites).

- Render the terrain, for each pixel consult the decal buffer and blend the pixel in that buffer in.

This method is good from a fixed perspective 

For deferred.

- Render terrain data to various buffers.  including gbuffer.

- Render decal terrain, test z depth against terrain zbuffer, and decal zbuffer.  cull pixel where z test fails.

- Combine all buffers include decal buffer.

Better from an all round perspective.

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

1 hour ago, ErnieDingo said:

- render decals to backbuffer, no z depth test against the landscape (as its not rendered at this point).  Ideally you should employ a z buffer just to enforce correct draw order in decal buffer.  If you dont z test the decal buffer then draw order will dictate the scene (ie possible overwrites).

This is what i don't understand, rendering the decals to backbuffer. I assume that by rendering the decals you mean rendering them from a 3D perspective, and then when rendering the terrain blend the pixels with the corresponding ones from the decal buffer, so that they don't look like they are floating when you look closely, right?

Advertisement
6 minutes ago, LazyDuke said:

This is what i don't understand, rendering the decals to backbuffer. I assume that by rendering the decals you mean rendering them from a 3D perspective, and then when rendering the terrain blend the pixels with the corresponding ones from the decal buffer, so that they don't look like they are floating when you look closely, right?

yep, exactly.

 

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

56 minutes ago, ErnieDingo said:

yep, exactly.

 

Before doing that, first i need to snap the road geometry to the ground. If i tried to do what you say right now, there would be z-fighting and clipping between the road decal and the terrain because the road is not a real decal since it hasn't been flattened to the terrain yet. That's what i need to know, how to turn the curved road mesh into a decal and after that blend it with the terrain. Sorry for not being very clear. If only Unity had built-in spline decals... I know you already told me a way how to do this, but i need a more accurate one since the player will be able to place roads wherever they want.

Easier if I show you how i've done it via pics.

Terrain rendering with decals.  I render the decals to a seperate buffer, no z, then when I render the terrain, you can see it blend in.

http://insanesoftware.com.au/terraindecal.png

For water, I use a normal map rendered to the scene, then blend when I render the water layer.

http://insanesoftware.com.au/waterdecal.png

@LazyDuke

Also, here is the a picture of the splines as they look geometrically.http://insanesoftware.com.au/splines.png

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

10 hours ago, LazyDuke said:

there would be z-fighting and clipping between the road decal

To prevent any Z-fighting you need to make the road more like they would be in real live, with a bit of a exaggeration on height.

Road.png.16cf0d02b8db6b345c1000a5963c55f4.png

The one on the left is for sandy roads and the one on the right for regular roads.

Advertisement
On 8/1/2017 at 1:18 AM, Scouting Ninja said:

To prevent any Z-fighting you need to make the road more like they would be in real live, with a bit of a exaggeration on height.

The one on the left is for sandy roads and the one on the right for regular roads.

In my piece, there is no z fighting as the backbuffer is separated from the terrain component.  So, I dont need to raise it in my function.  With my splines, the outer sections are actually for alpha blending :)   I really should just zip up my editor for you to play with.

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

On 8/3/2017 at 7:02 PM, ErnieDingo said:

In my piece, there is no z fighting as the backbuffer is separated from the terrain component.  So, I dont need to raise it in my function.  With my splines, the outer sections are actually for alpha blending :)   I really should just zip up my editor for you to play with.

That would be pretty cool!

3 minutes ago, LazyDuke said:

That would be pretty cool!

Will try and pull together the editor and relevant files.   Will post a link though the internal mail. 

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

On 7/31/2017 at 3:23 AM, ErnieDingo said:

OK, so I've implemented the exact problem you are facing into, and I used splines also.  There are 2 problem spaces, you have identified both.

1 - Splines for roads.

2 - Decals in geometry.  

My solutions.

1. For spines on roads, you are on the right path.  I did something slightly different with splines.  Using a spline SPINE, I generate my geometry.  So the spine is only a guide, I create parallel splines based upon the perpendicular vectors.  I actually end up with 4 guide lines and I create 3 rows of triangles.  This gives you a decent resolution on most terrain, you can up this more if you have more detailed terrain.   That only solves part of the problem, gives you a decent approximation.  NOW...for the more interesting part, blending to your varying terrain.  The extra "rails" also allow for alpha blending per point to smooth off edges also.

2.  I actually render my spline roads to a separate back buffer texture, there is reason for this.  This is to deal with mapping to the terrain in a close approximate way.    When rendering my terrain, I sample from this buffer (as a texture) and apply to it per pixel.

This works well for forward rendering, but the limitation is that because the terrain depth hasn't been rendered before generating so z depth wont be tested.  Deferred works better as you will have access to the z depth.

I know you are using unity, so I cant offer a solution in that space, only the technique I used for decals.

My game is on the page below, its downloadable.   You will find spline decals on the waters edges, roads, decals used also burn marks.  Decals are also used for boat wakes on water as well.

https://www.facebook.com/InsaneSoftware.com.au/

Gl with this!

Hi

I was looking for something like this for a while now and magically found your post here today!

So i wanted to ask is it possible to implement something like this in Unreal Engine 4? There is a whole thread on their forum and people are bumping it night and day without any answers from epic and everyone (including me) will be psyched if someone can do something about it. This is their forum thread about this feature request:

https://forums.unrealengine.com/unreal-engine/feedback-for-epic/108081-spline-decals

UE4 got both differed and forward and you can choose which one you like but it would be great if it can be used with differed as you already mentioned.

  

This topic is closed to new replies.

Advertisement