Post news RSS Devblog 5 - Using decals to break bricks

In the end I decided to do the breaking a block animation. If I'm not mistaken, the technique of superimposing textures on top of others is called decal.An example could be bullet holes on a scene.

Posted by on

In the end I decided to do the breaking a block animation. If I'm not mistaken, the technique of superimposing textures on top of others is called decal.
An example could be bullet holes on a scene.

They adapt to the shape of the surface and they can even give a perforation effect.

Unfortunately I don't control the whole graphics thing at all (decals are usually applied using Shaders and depend on the rendering pipeline you have chosen. I don't even know the differences between pipelines).
So I'm going to do something much simpler without details like depth or fit in to shape.
It will be a texture that I will put where the player is pointing.
We start looking for a break sprite:

We save it as a texture, assign the texture to a material, adjust the background transparency and offset on it so that only part of the texture is visible.
Now is the dodgy part, the code.
My idea is to create a class that manages its positioning and movement. At all times we will have 1 single animation that we will move to the corresponding brick.
The class should have the "frames" / offsets of the texture in which each image is seen. We will only put the animation in the scene if it is used, so there are no extra objects.
Every so often while you chop I am already playing a sound effect, we take advantage of that site to advance the animation:

To determine where to put it, we will use the raycasting that has been done previously to find out which block you want to chop. From it, we can extract the point of impact and the angle. We can't use the hit point directly, because this is exactly where the face of the brick model is. Which results in a problem known as "z fighting":

It cannot be appreciated very well, but it is the flickering shown the struggle to show the texture of the block or the break one.
As a fix we can use the location of the model, depending on where it is, we will move the animation forwards / backwards very little:

Much better.
With this there's only one detail reamining, the size of the texture:

See how it is bigger than block's height.

I can't think of any fixes. If we always show the animation in the center of the face, it would be a matter of using the height of the face, but the hit point can be at any point on the brick, so it will always end up sticking out if a decal is not used
We will have to get serious about the graphics issue and begin to understand what the subject is about, time to find out:

After this, it is clear that there are 2 paths to choose from in terms of pipelines:
- URP: Designed for mobile and 2d, with new tools and lights for 2d.
- HDRP: Designed for pc / consoles, with support for RTX, new types of lights, fabric shader, decals system included, etc ..
- BuiltIn: The system currently used by the project.

And at least to me, even clearer which one to choose -> HDRP.
The game is not 2d and the focus is that it works on my gamer laptop, not on my mobile. I won't be using all HDRP features, but decals is something I want.
I have migrated the project to HDRP. Things like the preview of the block got broken, but I think everything is fixed now.
We can now return to the original thread, the decal.
In HDRP there is a component called Decal Projector, thanks to it we can put our texture above the block without protruding strangely.
The class I had programmed to spawn the texture, position it, and animate it works almost perfectly with the Decal Projector. So luckily, we have not wasted any time.

It no longer stands out!
The drawing is ugly as fuck.
Something like this + depth would be more cool:

A pity that i'm not good at these things.

Mini improvement in construction

I have noticed another thing that made me mad a lot and that is that, every time you pointed to a different stud, the rotation of the object was lost, so it was a constant fight:

After a touch-up, the behavior is already more natural:

I have rebuilt the house to see if there was any graphical difference after switching to HDRP:

Old lighting / pipeline:

It looks more like a bit burnt, although I like the bright colors rather than the depressing ones from before.

LuisChaves - - 51 comments

Snap, didn't expect this to be so in depth. Good job dude!

Reply Good karma Bad karma+2 votes
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.