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

Worldspace canvas backface culling

Discussion in 'UGUI & TextMesh Pro' started by fueldown, Mar 15, 2015.

  1. fueldown

    fueldown

    Joined:
    Aug 21, 2012
    Posts:
    15
    Hello guys,
    I have a bunch of worldspace canvases and when i move around my world, I can see the backfaces of my UI. I am using a separate camera for UI in forward rendering as my main cam is in deferred and UI has a bug with deferred rendering.

    Screen Shot 2015-03-15 at 11.10.19 am.png
    Because of the separate camera, I need to have all worldspace canvases to be backface culled so that I won't see it (as you can see in above image, flat numbers on the other side of the building should be culled). Is there anyway to cull the backfaces of a canvas?
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    That is a curious one, I was sure there was a way but can't think of it off the top of my head

    @phil-Unity @Aras Is this something built in or would you need to apply a custom shader to do it.
     
  3. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    Yeah. Same Problem. I totally think that there was something like that during the beta. I believe in the Canvas Render. Can't find it now.
     
  4. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    I just built a quick shader to solve the issue. It's basically just the UIDefault shader from 4.6.3 but with backface culling enabled. You can get it from here:

    http://pastebin.com/YLiAieh8
     
    ceitel likes this.
  5. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    yone-haru likes this.
  6. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    yea it needs a different shader. we have backface culling turned off by default
     
    SimonDarksideJ likes this.
  7. fueldown

    fueldown

    Joined:
    Aug 21, 2012
    Posts:
    15
    That's what I ended up doing. Just went into the built-in shader and set the cull to back.
     
  8. Graham-B

    Graham-B

    Joined:
    Feb 27, 2013
    Posts:
    321
    Thanks for this solution Martin. Any idea how to add this to the UI-DefaultFont shader in 5.3.6? If doesn't have a culling attribute that I can see. I've resorted to using the same default shader for both text and images and it seems to work fine, however I'm not sure if this is optimal performance-wise.
     
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    Sorry to necro, but this is the relevant thread... I want to do exactly this, but I can't figure out how to actually use a custom shader with UI elements. Can somebody clue me in?

    EDIT: Never mind, you just make a Material and apply it to each UI element in the Inspector. Duh. :)
     
    Last edited: Mar 29, 2018
  10. yone-haru

    yone-haru

    Joined:
    Aug 30, 2021
    Posts:
    8
    This shader works in URP! thanks a lot!