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. Dismiss Notice

Shader for Mesh Segmentation

Discussion in 'Shaders' started by rmottaghi, Jul 17, 2016.

  1. rmottaghi

    rmottaghi

    Joined:
    Jun 14, 2016
    Posts:
    6
    Hi folks, I am working on a project where I would like to get object segmentation masks using a shader. For example, imagine the two buses below are two models in a scene. We want to assign the same solid color to every pixel of one object, but different colors for different objects in the scene. I assume we can achieve this by changing the materials of these models to plain colors; however, this will affect the original RGB rendering. In our case, we would like to render the RGB image as well as its corresponding segmentation mask at the same time (by two different cameras with their corresponding shaders). Is there a solution for this scenario?

    Captura de pantalla 2015-02-13 a las 17.25.18.png

    Thanks! I appreciate your helps!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
  3. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,460
    More like
    - make a script that put all objects of your scene into a list
    - go through the list and assign a unique colors to each objects (color contrast base on list.count)
    - render it to render texture
    - save the texture
     
  4. rmottaghi

    rmottaghi

    Joined:
    Jun 14, 2016
    Posts:
    6
    Will this affect rendering the original RGB images? The reason I want to use shaders instead of modifying objects is that I would like to have the RGB images and the segmentation masks side-by-side. Could you provide more details about how I can render both of them at the same time? Thanks!