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

Question Is adding Stencil-Test to Non-Custom Shaders possible?

Discussion in 'Shaders' started by DaneielG, Feb 10, 2023.

  1. DaneielG

    DaneielG

    Joined:
    Jan 24, 2022
    Posts:
    6
    Hi, I'd like to use the stencil functionality to discard fragments. But I only know during runtimeI what materials I'm working with. So I can't modify them before.
    Is there any way for example to replace the original shader inside a material and to call the original shader with all it's properties from the replacement shader in case the replacement passes the stencil test?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,255
    Sadly, no, there is no way of doing this. Unity has this functionality internally and use it for sprite and deferred rendering, but it’s not exposed to c# outside of custom SRP rendering, and URP render features.
     
  3. DaneielG

    DaneielG

    Joined:
    Jan 24, 2022
    Posts:
    6
    Thanks a lot for the quick answer :) And there isn't somehow a way to put code into cginc that is automatically called by any shader?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,255