sabresaurus / SabreCSG

Level design tools for Unity
MIT License
1.36k stars 137 forks source link

Decals #153

Open Henry00IS opened 6 years ago

Henry00IS commented 6 years ago

The ability to place decals similar to Source Engine would break up the repetitive tiling textures that are generally a problem with these types of levels. I am still working out the details on how it should work... will probably have to some research and see just how other level editors implement this type of feature into a coherent workflow. If you know some good level editors that provide placing decals please let me know in the comments below.

vertxxyz commented 6 years ago

Decals are present in the HD Render pipeline, and are often implemented in deferred with the use of Command Buffers a-la https://docs.unity3d.com/Manual/GraphicsCommandBuffers.html But yeah, it'd be good to have a decal-placer. The HD Pipe sucks, and needs a general placement tool.

On Fri, 15 Jun 2018 at 19:35, Henry de Jongh notifications@github.com wrote:

The ability to place decals similar to Source Engine would break up the repetitive tiling textures that are generally a problem with these types of levels. I am still working out the details on how it should work... will probably have to some research and see just how other level editors implement this type of feature into a coherent workflow. If you know some good level editors that provide placing decals please let me know in the comments below.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sabresaurus/SabreCSG/issues/153, or mute the thread https://github.com/notifications/unsubscribe-auth/AU8jxQj6u_7lu0Z9tYKTFMdR3bmPAc_sks5t83_vgaJpZM4UpSCC .

Henry00IS commented 6 years ago

Some Discord Curiosities

I was thinking that it should be part of the geometry. Didn't actually consider making it another game object that tries to attach itself onto nearby polygons, that's an interesting concept...

Generally how decals work, is that it's just quads (or a couple other shapes) with a texture on it that's 0.0001x or so distance from the polygon it lies on so that there is no depth-fighting. Unless you move really far away and your depth buffer starts to have accuracy problems and it starts fighting, but it could be possible to have a global value for this in the CSG Model settings.

My current theory would be implemented it like this: As you know CSG never creates any new brush faces, you always manipulate the existing faces of the brushes (sure it splits them up later and triangulates etc. but you don't care for that while designing the levels).

I can keep a list of decals on every brush face that act similar to UV coordinates. They do not have any location information nor do they know the shape of the brush face. They just know their material, offset, rotation and scale. So if you decide to change the brush around it wouldn't affect the decals nor would they distort...

But then what if the decals no longer fit on the brush and are like 20m to the right of what was once a wall and is now a brick in a wall, how will you be able to tell and possibly clean up all this garbage data?

Unless it does this by itself, anything invisible doesn't get saved or alike, but that may feel wrong to the level designer that may have only done that as a quick test and loses their work.

I will be talking to Robin-Yann Storm on Wednesday to discuss UX things so I can bring up this concern on how to clearly bring this to the level designer's attention without taking you out of the flow with a lot of convoluted menus or lists of decals that you'd have to edit manually.

I am kind of thinking we take the face and consider it a 2D polygon and from there it's simple 2D position, rotation and scale. So changing the polygon around wouldn't matter except for the (whatever is the) upper-left corner of the polygon defining the position. So:

+--------------+
|              |
|  +--------+  |
|  | DECAL  |  |
|  +--------+  |
|              |
+--------------+

+-----------------------------+
|                             |
|  +--------+                 |
|  | DECAL  |                 |
|  +--------+                 |
|                             |
|                             |
|                             |
|                             |
|                             |
+-----------------------------+

They are local coordinates, so even this would continue to work:

+----X
|     X
|  +---X
|  | DECX
|  +-----X
|         X
|          X
|           X
|            X
|             X
+--------------X

According to Baxayaun: "And speaking about Hammer, one of the cool things about decals in Hammer was that you could "shoot" decals anywhere. You didn't need to select a brush and apply a decal, you could just point where you wanted the decal and click. That made it super easy to use."

I imagine that's easy to implement once we have a system like this in place. The only problem is when you have a decal on a border of two polygons:

+-----------------------------+
|             ||              |
|             ||              |
|         +--------+          |
|         | DECAL  |          |
|         +--------+          |
|             ||              |
|             ||              |
+-----------------------------+

Although that may be quite solvable with enough time and patience on my part as this would be a question of math, but if the level designers wants to move or rotate it around afterwards it will get a lot of more complicated if not nearly impossible. You'd be dealing with two decals that technically aren't linked together. It could be possible to have the placement tool show a preview as well as have options for the initial rotation and scale so the level designer can trial&error a couple times until it's just right. But then he can't edit the brushes without ruining the decal work.

And this is where I stand today pretty much, nearly there but not quite! :grin:

Henry00IS commented 6 years ago

@vertxxyz nice find! It should be a generic approach that works in all Unity versions though. It would be nice if SabreCSG can provide decals out of the box that work with any shader under any condition.

notPelf commented 6 years ago

There's a free and open source decal system that I found a while back that does what you're describing. It works on any mesh of any complexity but I think it requires a specific shader type. I don't know what the license is for any of it but you can peak through the code here:

https://bitbucket.org/Deni35-team/unity-simple-decal-system/overview

Some workflow improvements on that system would be great.

Also if I could make a request, it would be nice to make the decal system separated from the existing brush tools. The reason is that from my experience in hammer back in the day, placing decals is done after the level geometry has already been mostly finished and everything is just being detailed with props, etc. The issue is that when the SabreCSG UI is open for editing brushes and whatnot, you can't click on props to move them around, only brushes. Since decals and prop placement go hand-in-hand and decals and brush editing tend to not be done at the same time, it wouldn't make sense to only be able to select brushes and not props while placing decals. Also if it's separated then decals and brush editing can be done at the same time, but you can also edit props and such too while placing decals.

Henry00IS commented 6 years ago

Thanks for the link I will check it out soon!

The current idea was to integrate it into SabreCSG's face editor (or likely an additional mode) and the decals will be generated as part of the final mesh... not this extra tool that's not directly part of SabreCSG which would probably be very confusing. I also didn't want to have a game object for every decal if possible unlike how Hammer does it. It should just keep you in the flow, you texture a wall, you put some stains on it and continue in a non-destructive manner so you could continue editing the level without losing your decal work...

Henry00IS commented 6 years ago

@notPelf I have to agree, that decal system is quite amazing. I will reconsider.