Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How to paint on a 3D object without raycast in Unity (from shader)?

Discussion in 'Shaders' started by seltonnn, May 7, 2018.

  1. seltonnn

    seltonnn

    Joined:
    Aug 16, 2017
    Posts:
    3
    I have spent weeks to find a way to paint on a 3D Object with a brush in Unity. I have find solutions with raycasting and RenderTexrures, but it's not fast enough.

    Currently I am passing the cameras MVP matrix to my shader to create a circle on the 3D object's surface, but I am unable to "burn it" on the texture from the shader, since there is no way(?) to make actual changes from a shader.

    I have also tried to do something with ZBuffer, but it only works if nothing moves. As soon as I move something, the draw will "flow".

    I am not an expert in shader coding, but I see no option for drawing anything from there.

    Please if you have any suggestions, do not hesitate to share with me.
     
  2. bournifle

    bournifle

    Joined:
    Jan 13, 2010
    Posts:
    31
  3. seltonnn

    seltonnn

    Joined:
    Aug 16, 2017
    Posts:
    3
    It's not good. I have a bunch of little meshes with a bunch of (few hundred) mesh colliders because of the raycast, and it's too much. The result is around 2-3 FPS with my scene.

    Currently I am able to color the vertices at a given point (e.g. at the mouse position using the cameras view matrix in the shader), but I am unable to "save on vertex colors to the actual mesh" from shader. So the previous vertex coloring is gone at the next rendering iteration. :(
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,874
    Dont use mesh colliders then? is there a specific reason you cant do this with compounds of primitive colliders?

    EDIT: and you save the colors by putting that data into a buffer somewhere. Compute shader with structured buffers would be a nice way and you would have buffer as a render texture / texture.
     
    seltonnn likes this.
  5. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    314
    3D painting is easy and pleasant :)

     
    seltonnn likes this.
  6. seltonnn

    seltonnn

    Joined:
    Aug 16, 2017
    Posts:
    3
    Wow, that's cool. Can you share the code as well?