Erase parts of a texture with a raycast?

I’m not even sure what this would be called or think of any examples.

What I’m basically trying to figure out, is the floor has a texture, but also a secondary “dirt” texture on top. I want to be able to mop up the dirt texture but only the parts the mop touches.

I’ve tried to search for examples of this, but I can’t seem to find anything. I’m sure there is a solution somewhere, I’m just not sure what somthing like this would be called.

My apologies if this is not the correct forum.

Many techniques, depending on the quality of what you want. Such as

  • A shader that supports secondary textures

  • Decals

  • Microsplat - replaces your shaders with a generative shader

I suppose option 2 is what you want. I suggest searching google/youtube for how to implement decals in the specific rendering pipeline you’re using, the technique will vary based on that.

Thank you for the reply, I have searched for different ways to do this. I was thinking through a shader would be best.
But I not able to find anything on this, as I am really not sure what the technique to accomplish this is called.

Searching for “erase parts of texture with a raycast URP” gives me no results unfortunately

You want decals. Check the projector component. Unity - Manual: Projector component

And go to Asset Store and search for “decals”. You’ll find a lot of things.

I am familiar with decals. But this will allow me to remove part of the “dirt texture” the brush touches?

If you compose your dirt out of several decals, then you can remove them one by one. Otherwise your decal solution would need some kind of masking.

In my own game I’m using Microsplat. It uses control textures to mask which part of a texture to render, and you can have several layers of these materials. But Microsplat is a product family and possibly overkill if you need a simple solution.

Full package:

1 Like

Nice. I was expecting he needs 3D as it was supposed to be a floor, not screen space.

1 Like

It is 3D! :slight_smile:

Lay it on the floor, mop away.

9124129--1266220--Screen Shot 2023-07-04 at 11.19.32 AM.png

1 Like

This is great, but it doesn’t seem to work with custom meshes that have a tiled UV.

I couldn’t think of an example when I asked for help. But the perfect example would be Power Wash simulator. I assume that’s a shader they are using.

I found 2 examples online, one was with shader graph that is massively outdated and no longer works, another is from code monkeys, but does not divulge into it much at all. I’m really not sure what this is called to do any searches for any tutorials.

Here’s a Mask on a tiled Image. Obviously, it’s not a Mesh but a world space Canvas.

9138616--1269415--upload_2023-7-11_9-4-27.png
9138616--1269433--upload_2023-7-11_9-7-25.png


Here’s the same where the “exposed floor tiles” are rendered on top of a dirt image.

Obviously, the mask image can be a RenderTexture that you connect to your “mop” in such a way that mopping will draw white on this RenderTexture.

9138679--1269457--upload_2023-7-11_9-35-22.png

This is the setup for the last one
9138697--1269469--upload_2023-7-11_9-42-21.png