Hey there fellow Unity users!
I’ve been working on this baby for a while now, and I cannot seem to figure it out.
What I want to do is paint on my model within my app ZBrush/Mudbox style. Currently that is working by
casting a ray from the camera to my mouseposition (camera.ScreenPointToRay(Input.mousePosition))
getting the texture coordinate from RaycastHit.textureCoord
However, this returns one x/y, which is quite useless. I want to create a radius (brushsize) around my mousepointer, and get back all affected pixels within that radius. I’ve tried casting a whole lot or rays, but that doesn’t work for several reasons (one being speed).
I’ve tried searching the forums and Google, and came close. But I could not find the solution to my problem. Anyone who knows? It’s very much appreciated
If you’ve taken some time to look around the internet for a solution I imagine that by now you realize that what you’re trying to achieve is actually quit difficult. Have you looked into using Unity’s projector?
To give you an example, I believe how Unity has implemented it’s projector is by rendering the meshes being projected on from the projector’s point of view to create a second set of ‘projector’ UVs. The UV’s are then used on the meshes (together with the projection texture) when rendering normally in the main camera.
Of course, the projector won’t help you if you actually want to recreate the same functionality that ZBrush/Mudbox has but there are a whole lot of very complex issues you’ll need to deal with mainly involving the mapping from screen space into UV space on each of the models.
If you’re serious about implementing the feature I’d probably start by recreating Unity’s projection script but instead of rendering the meshes using both the original UVs and the projector UVs, you resolve the mapping and bake the two together. Of course you’ll have texture resolution issues because the projection resolution will be dependent on the original texture resolution on the mesh but it might just be enough for your purposes.
It sounds like a great tool to have though and I imagine a lot of people would be very interested in getting their hands on it so let us know how it goes!