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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

block silhouette: easy with one mesh, how to do with submeshes?

Discussion in 'General Graphics' started by jctz, Dec 10, 2015.

  1. jctz

    jctz

    Joined:
    Aug 14, 2013
    Posts:
    47
    Hi,

    I implemented a silhouette effect so that objects behind an obstruction gets rendered with a solid silhouette in the parts that are obstructed:

    http://screencast.com/t/awfeytnK
    (White silhouette = friendly unit, Yellow silhouette = enemy unit)

    This was simple for single-mesh objects because I could just add passes to my MeshRenderer:
    0 - pass 1 (stencil set)
    1 - pass 2 (diffuse, clear stencil)
    2 - pass 3 (opaque postpass, stencil test)
    (each have their render queues set explicitly either in the shader or material)

    However, we're starting to add units with more than one mesh. By default they're showing up like this:
    0 - submesh1
    1 - submesh2

    And I need to make all submeshes be able to silhouette against obstructions. If I arrange my materials like this:
    0 - submesh1 - stencil set
    1 - submesh1 - diffuse
    2 - submesh1 - opaque post pass
    3 - submesh2 - stencil set
    4 - submesh2 - diffuse
    5 - submesh2 - opaque post pass

    Would this even work? How would I tell Unity which prepass or postpass is associated with which submesh?

    Would this work?

    0 - submesh 0 - diffuse
    1 - submesh 1 - diffuse
    2 - submesh 0 - stencil set
    3 - submesh 1 - stencil set
    4 - submesh 0 - opaque post pass
    5 - submesh 1 - opaque post pass

    Thanks in advance,
    Jeff
     
  2. jctz

    jctz

    Joined:
    Aug 14, 2013
    Posts:
    47