Sign in to follow this  

Decal Projection - Quick Question on Direction of implementation

This topic is 381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI Guys,

 

I've decided to tackle Decal's.  I previously posted about this on Tyre trails (static decals).  

 

After implementing shadow maps successfully, i'm thinking of using a deferred rendering process which uses a similar technique.  Obviously, this time its to a frame buffer, rather than a z-buffer like shadow maps.  I believe this technique will give an approximate, not a accurate result.

 

A few notes/goals/issues.

 

- Projection of the texturing only to the terrain.  I don't believe this technique will be useable in more complex scenarios such as assets (trees etc).

- It's quick.

- This may not be able to handle very complex terrain geometry, so its use cases will be severely limited.  (this is my first full game engine I am building so im not trying to have everything completely there for gen 1).

 

Method

 

1 - Decal geometry is overlaid onto my terrain geometry in a close contouring (basically hover above) - this is done in my editor,using splines etc to model the path, vertices/geometry is generated in there.

2 - Render all decals into a separate backbuffer/shader buffer using the scene camera projection. (with a Z buffer also to ensure depth order is correct (or I could presort this)). Render this with no lighting, just flat rendering.  This produces a texture that I will use to sample when rendering my terrain.

3 - While rendering the terrain, not only sample the shadow buffer, but also the decal buffer (using projection to find the right reference pixel).  No Z comparison needed.  If a pixelcolour > 0 exists in the decal buffer then sample that and combine with terrain texture and shadow map sample.

 

The question - Will this work at all?

 

I've attached a screenshot of my game.  At the moment, the roads are just alpha blended texture (this does not use the technique above).  So you can see the terrain is flat (mostly).  There are craters so I fear this technique fails on that front.

 

So the solution is simple for now, but what else should I read up on or consider for paths forward.  This is a starting point for me, seeing I've never done anything like this before.  Shadow maps was a challenge to just do something new.   Feel more comfortable with some of the possibilities in DirectX 11.   Any feedback is appreciated.  Thanks in advance.

 

sample.png

 

 

Share this post


Link to post
Share on other sites

This would work and its an approach i've taken in the past. You will need to render the terrain's depth into the Z-buffer first otherise decals that should be hidden behind mountains would be visible through the mountain - unless your terrain is flat enough that the camera can never get to that point.

edit: If you move to deferred shading, decals become trivial as you just render their geometry into the g-buffer prior to lighting. Tiled forward+ style approaches involve splitting your scene into a 3d screenspace grid and storing the decal projection information per cell.

Edited by Digitalfragment

Share this post


Link to post
Share on other sites

This would work and its an approach i've taken in the past. You will need to render the terrain's depth into the Z-buffer first otherise decals that should be hidden behind mountains would be visible through the mountain - unless your terrain is flat enough that the camera can never get to that point.

edit: If you move to deferred shading, decals become trivial as you just render their geometry into the g-buffer prior to lighting. Tiled forward+ style approaches involve splitting your scene into a 3d screenspace grid and storing the decal projection information per cell.

Hi,

 

Sort of rendering the terrain to the frame buffer first, yes.  But really, the decals will be rendered into a separate buffer first though and then that buffer sampled as I render the terrain. That way I can merge it with my lighting for the final pass.

 

The issue, my decals are hovering above the surface and currently not sampling from the terrain depth buffer.  Its a bit hacky, but basically at my merge I could get some perspective distortion on the terrain as the camera moves over it.  I will post some screenshots once I've done my first tech test. I hope it will be suitable enough for my game (fixed camera perspective).

 

This is my first version of my game engine, in future, I will revise and improve the pipeline (Gbuffer/Normals/lighting buffers) 

 

Thanks though!

Share this post


Link to post
Share on other sites

HI, just an update on my progress.  Im working through it in my editor.  Screenshot of where the texture is on the screen, and the rendertargettexture I actually rendered to.  I will have a final version merging both together in the next few hours.

 

wip.jpg

Share this post


Link to post
Share on other sites

Final update.  It works..but only as a rather basic implementation with severe limitations.

 

1 - my implementation samples a texture based on pixel location ,so it doesn't respect Z depth.  Therefore it doesn't overlay well on contours.  But its fine for what I want as A) its from a distance, B) the areas i'm overlaying are flat.

2 - I found that if I use a method similar to shadow mapping, I get a better result (from simple tests).  But it has some limitations too around detail on textures, but it respects the contours of the landscape better.

3 - I'm not catering for aspect ratio of the frame buffer vs the decal buffer, so its not perfectly static.  This is an easy fix.  Ensure the decal buffer has the same aspect ratio. 

4 - I think i need to revisit this at some point, but for now it will do all I need for this game.

 

- removed pic to save bandwidth.

Edited by ErnieDingo

Share this post


Link to post
Share on other sites

Update: improved the whole thing.  Now respects Z depth, texture clarity is good and detail close up is excellent.

 

- Use perspective projection rather than a otho projection.  

- Uses a smaller texture which means pixel draw is less (substantially).

- Nearly 0 impact now on frame rate.

 

wip3.jpg

Share this post


Link to post
Share on other sites

Thought I would update on where I am with tyre trails and decals.  Modeling splines across my map and I have the framework for the triangle generation ready  (marked in pink).

 

- can vary the width the splines at the control points.  

 

To generate the triangles, its fairly straight forward.

 

tri 1 - left side n, n1 + 1, right n

tri 2 - left side n+1, right n, n +1 

 

repeat until end of spline vertex list.

 

Will post update once I have decal roads working.

 

wip4.jpg

Share this post


Link to post
Share on other sites

HI all, 2nd last post I will do here.   Seeing I have a only a couple of things left.  I thought to share the remaining stages.

 

Blending is just right now (using right blendstate).  

 

- Articulate alpha drop off on edges for smooth transitions.

- base blend value so you can manipulate how much the whole thing is blended.  

 

Todo:

 

Just allow control points to adjust width so road doesn't look uniform.  (basically there, not turned on)

Colour adjustments per control point maybe

Alpha blending control per control point maybe.

 

 

 

wip6.jpg

Share this post


Link to post
Share on other sites

This topic is 381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this