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

change culling on a material basis

Discussion in 'Shaders' started by mgto, Sep 25, 2014.

  1. mgto

    mgto

    Joined:
    May 30, 2013
    Posts:
    22
    Hi there,

    I'm wondering if there is a way to reuse one cg shader for different materials? I'm looking for a solution like in ogre where you have your material and just link the shader you want to use. In unity the material and the shader is somewhat the same but maybe there is a trick to achieve the same?

    multi_compile goes into this direction but is bound to the cg code block. #include is also helpful but does not allow to include a complete shader with pixel and fragment part.

    Anyone knows something more in depth?
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    It sounds like you might mean something non-standard by "materials". In Unity, a Material asset is a reference to a shader, and a collection of different property settings. Generally, you have many Materials sharing each shader, since you want things to look similar but use different textures or colours or whatever.

    Is something preventing you from using different shaders for different Materials?
     
  3. mgto

    mgto

    Joined:
    May 30, 2013
    Posts:
    22
    By shader I'm talking about everything inside the CGPROGRAM section. Everything else is the "material" in my sense.

    And redundancy is preventing me from creating several copys of the same shader in different materials. The shader should be in one master file and just be linked into different materials OR writing a master shader/material which is compiled to all permutations by unity itself.
     
  4. mgto

    mgto

    Joined:
    May 30, 2013
    Posts:
    22