Painting materials onto meshes at runtime?

So I’m creating a map editor for my game (kinda plays like an xcom dungeon crawler)
And for indoor environments it currently works pretty well, but I’ve been trying to add outdoor environments to it, but it just looks way too blocky with the way I’m spawning the map and I was wondering if anyone knew how I could paint my materials onto the cubes I spawn for the map.

alt text
ignore the WoW tiles :stuck_out_tongue: easy to grab for testing

I have different shaped tiles to fill out the edge of holes like in the image for stuff like water, lava, slime, tar or just plain darkness.

I wouldn’t mind if I could just have two materials to paint with per cube (I know a lot of terrains engines only have 4 layers and I don’t wanna do some mad blending between a textures, just a smooth transition between two would be enough)

So if anyone has any ideas on how I could achieve this that’d be awesome

Hi @Systemfre1

I’m unsure what you are aiming for.

Do you want to have tiles that form a smooth border between two adjacent tilesets, or do you want to “physically” paint your texture onto the tiles, for example like Splatoon, but with a mouse? The former is easy, the latter hard.

If you mean the “physically” painting one, you would have to raycast from your current mouse position, which can be done via Physics.Raycast, using this example as your ray origin/direction.

You then get a gameobject you collided with, as well as the target UV coordinates.

The next step would be t o create a shader that interpolates between X textures according to the uv value. You can set the UV value at the ray collision point from earlier to your currently selecting texture. The problem starts when you dont simply want to texture a single pixel, but a pixel area. The CPU is really bad at setting that, you would be better off using your GPU for that, so even more shaders. There are things like that at the AssetStore (eg this one), but they arent cheap.

Overall I’d advise you to create a split gameobject, that you can put in between 2 tilesets. You can either physically divide the rectangle into two triangles, or use a simple 2 texture shader for it.

Hope this helps, I’m happy to answer more questions or point you towards shader resources (they are fun!)