• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
    11
  • comments
    51
  • views
    31772

Decals, finally!

Sign in to follow this  
Followers 0
Radikalizm

3230 views

I finally have a decal implementation working in the graphics component of my engine project. This really was a simple implementation and I've had this on my to-do list for a while, but it just got buried by a ton of other things I wanted to get out of the way first. Anyway, here's a screenshot using some art I made some time ago (click to enlarge):

render2-260713.png

Decals have access to all the features of the engine's material system and are completely managed on the GPU, so there's no need to involve the physics engine to calculate decal positions for example.

Both 2D decals and volume decals are supported.

The scene in the screenshot I posted is still a work in progress, hence the absence of shadows, indirect/ambient lighting, anti-aliasing and the crude texturing. I'll probably post a journal entry when it's completed.

3
Sign in to follow this  
Followers 0


20 Comments


This is great work man! Love to see what you are doing and how you do it. Do you mind sharing where you found out how to get this to work? We attempted it but got stuck. Thanks again

1

Share this comment


Link to comment

I based my decal rendering technique on the "Volume Decals" article by Emil Persson in GPU Pro 2, although I had to make some tweaks to get texture lookups for 2D decals to work correctly.

 

For each decal volume you render it comes down to retrieving the world position of your scene geometry at the fragment which is currently being shaded (you can use your depth buffer to reconstruct this position) and using this position to do a texture lookup in your decal texture(s).

 

If you're using deferred shading you can just overwrite (or even blend) the attributes stored in your g-buffer where your decal is rendered, which means your decals can have their own material properties, and that they can have normal maps and other cool effects.

 

If you don't own GPU Pro 2 I could give you a more detailed overview of the implementation if you'd like.

1

Share this comment


Link to comment

I've read through the thread you posted, and our techniques differ quite a bit.

In my implementation I don't actually do any projective texturing by setting up a projection camera. What I am doing is setting up a 'decal volume' which in my case is a simple cube. I basically look for an intersection plane between my decal volume and the scene geometry. Afterwards I do an orthogonal projection of my decal texture onto this plane within the bounds of the decal volume. The projection direction is determined by the rotation of the decal volume.

 

The extents of your decal volume can be used to cut off your projected texture in all directions, that way your decal won't project onto surfaces it shouldn't be applied to.

 

To get your coordinates for sampling your decal texture you can use a reconstructed world position as I mentioned before. Of course you need to transform this position to be local to your decal before it's any useful for texture sampling.

For volume decals I just use the decal-local position for texture sampling. For 2D decals I just ignore the z-component of the sample position, which would be the same as sampling from a volume texture where each depth slice would be identical.

 

I hope this helps :)

1

Share this comment


Link to comment

Again thanks, Ill pass this on to telanor and see what he thinks. Your method may be better, i dont know! all that hoopla is beyond me!

0

Share this comment


Link to comment
I didn't realize you could use the volume decal technique for 2d decals. Humus' tutorial seems to be the only one describing the technique on the internet, but how he gets the texcoords to sample the decal don't make much sense to me. His ScreenToLocal matrix seems to be more than just an inverse View*Projection matrix.

Could you explain the transforms you used to convert the screen position + sampled depth into the texcoords? My understanding is that if you multiply the screen position by the inverse viewprojection matrix, you get a world space position, which doesn't seem particularly useful for sampling a texture.
1

Share this comment


Link to comment

You do indeed get a world position, but you need to transform this to a position local to your decal volume. I just use my decal volume's inverse world transformation to get this local position.

1

Share this comment


Link to comment

Ok that got me closer, I think I just need to scale/offset the resulting coordinates so they're proper texture space coordinates. The usual 0.5 * float2(pos.x, -pos.y) + 0.5 doesn't quite seem to be right. What's the correct way to do this?

Also, if you're using a deferred renderer, how are you handling the transparency in the decal? My GBuffer's alpha channel is used for the specular component, so writing the alpha ends up making the decal shiny.  Figured it out, disabling alpha writes solves it.

1

Share this comment


Link to comment

The range conversion from [-1, 1] to [0, 1] works fine for me, it's just a standard (pos.xy + 1.0) * 0.5.

 

About disabling alpha writes, you might want to keep it enabled and let your decal write out its own material properties, like specular albedo, roughness, normals, etc. For decal alpha I just use an alpha map, but since I'm using deferred shading it is of course limited to either being completely opaque, or completely transparent (ie. I just discard the pixel). Maybe I should try experimenting with additive blending for some material properties, could give some interesting results.

1

Share this comment


Link to comment

With your system, have you noticed that when you get a certain distance away the decal offsets? We have this odd thing where if you move past a certain distance the decal changes and offsets by almost half. Thanks for the help with this and thank you for the updates! I owe you one!

1

Share this comment


Link to comment

Can't say I have this problem. Could you maybe provide some screenshots?

 

Could this be related to depth buffer precision? I had some nasty issues with this in the past, so I'm keeping a separate buffer with depth stored linearly from which I reconstruct my positions. It's not an optimal solution IMO, but it does solve a lot of headache inducing issues.

0

Share this comment


Link to comment

For anyone interested, here's another render of multiple decals with varying orientations (click to enlarge):

render3-290713.png

1

Share this comment


Link to comment
I'm surprised you're decals look that good with alpha clipping.  This is what ours looks like with alpha clipping and alpha blending.  This is the weird wrapping in the distance.

We're using a log depth buffer, so there shouldn't be any precision problems. This is an output of the sampling coordinates close up and far away. As you can see they don't change, so its a rather weird problem.
 
Edit:  I found out the distance thing is because of mipmapping.  If I disable mipmap generation when loading the image, the issue goes away.  Of course then the decal looks bad in the distance... any thoughts on why DX is sampling the mipmaps weirdly?
1

Share this comment


Link to comment

Wow, that is rather weird indeed. Since the sampling coordinates remain unchanged, could it be a problem with your decal texture's mipmaps?

1

Share this comment


Link to comment

Indeed, that is what is causing it. Any idea on what could be done to solve that?

0

Share this comment


Link to comment

How are you generating your mips right now? Are you letting your graphics library generate them for you, or do you generate them as a pre-processing step?

0

Share this comment


Link to comment
They're generated when calling D3DX11CreateShaderResourceViewFromFile
1

Share this comment


Link to comment

I've never used the D3DX library so I couldn't say whether you need to take any precautions with said function related to mipmap generation.

 

Are the texture's dimensions both powers of two? Normally seeing this shouldn't cause major problems anymore these days, but you never know.

 

For what it's worth, I can really recommend doing mipmap generation and other texture-processing jobs in a small custom off-line tool. You get a lot more control over the visual quality of your textures, and you reduce your game's loading time. If you'd be interested in developing something like this, a library like nvidia texture tools is a good start.

1

Share this comment


Link to comment
Interestingly enough, making it a power of 2 size fixed it, which is strange since DX10+ supports non-power-of-two sizes. Thanks for the help

Edit: If I change the MipFilter from Box to Triangle, it works with non-power-of-two sizes.
1

Share this comment


Link to comment

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