Search Unity

Built-in shader replacement

Discussion in 'Shaders' started by olegfnew, Oct 31, 2011.

  1. olegfnew

    olegfnew

    Joined:
    Oct 31, 2011
    Posts:
    2
    I import a tree prefab and add it to a terrain, terrain starts to spam about "Tree Soft Occlusion" shader. I have my own shader for a tree and I would like to replace built-in Tree Soft Occlusion shader with it. Is it possible and is yes - how to do it? When I simply rename my shader to Nature/Tree Soft Occlusion Bark, Unity won't get it and still uses built-in shader.
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You can download the build in shader score code here: built-in-shaders

    Simply change the shader as you like and include the new / edited shader into the project to overwrite the build in.

    (Shader name and "folder" are determine inside the shader code , so its no wonder that renaming does not help)
     
  3. olegfnew

    olegfnew

    Joined:
    Oct 31, 2011
    Posts:
    2
    That is what I was trying to do. I take my shader (with the normalmap, glossmap and with the actual file name my_shader.shader) and rename it inside like this:
    Shader "Nature/Tree Soft Occlusion Bark" { /* shader code here */ }
    Then i go to my prefab, choosing Nature/Tree Soft Occlusion Bark for a material and there is still Unity's built-in shader with only diffuse map etc. What am i doing wrong?
     
  4. artician

    artician

    Joined:
    Nov 27, 2009
    Posts:
    345
    I would like to know this as well. I have trees in my environment which already have two-sided leaf planes (because one side is covered in snow, and the other is not). I need to turn off 2-sided textures in this shader, and then replace the default shader with my own. Can someone please give some advice? (For both locating the 2-sided texture portion and for replacing the shader itself).

    Alternatively - I'd love to not be forced to use the Soft Occlusion shaders at all!

    Many thanks!
     
    Last edited: Dec 15, 2011
  5. Emptiness

    Emptiness

    Joined:
    Jul 14, 2012
    Posts:
    33
    Has anybody found a solution yet?
     
  6. Emptiness

    Emptiness

    Joined:
    Jul 14, 2012
    Posts:
    33
    I've found kinda solution:

    1. When your tree is on the scene it has a "Mesh Renderer" component and it has material(s).

    2. Those are the materials you need to change to see any changes. Even if you don't change them just for example the lighting in a different file, you have to have those materials replaced.

    I hope it helps somebody :)
     
  7. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    I would like to do this in Unity 2021 LTS and have not yet found a solution.
    general questions:

    1. is it true that placing identically named shaders "manually" in my assets folder overwrites unity default shaders?
    2. does this work for built-in render pipeline?
    3. do i need to do something like put it in Resources folder or any other speciality?
    4. what about shader filename? or only internal of shader naming?

    the shaders i would like to replace are all terrain shaders:
    A) detail gras shader (to get it write into z/normal in a deferred way)
    B) nature tree soft occlusion bark and leaves (to get them properly lit and write into z/normal in a deferred way)

    are there any other ways to get these shaders to render properly or "hacky" defered?

    the reason why i dont want to use any other system like vegetation studio but stay with units default terrain detail + tree rendering is that the billboarding done there is MUCH faster than all other bill board systems on the market. my guess is that all other systems need to go through LodGroup component per gameobject (tree) but without it, it's specialized code that is much simpler.

    rendering 100.000s of soft occlusion billboards is on a modern i7-9000 cpu half a millisecond main thread and multiple milliseconds for other billboard renderers :-(