Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Default maps properties are not applying for custom Deferred shader

Discussion in 'Shaders' started by zipsted, Sep 7, 2017.

  1. zipsted

    zipsted

    Joined:
    Sep 14, 2015
    Posts:
    4
    Hello!

    What I'm doing
    I choose shader file in Project window, then add texture for one of the properties.


    I'm using that shader as custom deferred shader here:


    What I'm expecting
    Texture should be applied in builds for Editor and Standalone both.
    Or should not be, but defenitely in both builds.

    What is happening
    Shader uses default texture fine in Editor build, but in Standalone texture disappears.

    What's wrong, how to fix it, is there a correct way to add texture to shader without materia?

    Thank you!
     
  2. zipsted

    zipsted

    Joined:
    Sep 14, 2015
    Posts:
    4
    And I found the solution.

    We should remove all useless properties in shader.
    Then somewhere in the C# code we should write the following:
    Code (CSharp):
    1. var texture = Resources.Load ("<name-of-texture>") as Texture;
    2. Shader.SetGlobalTexture(Shader.PropertyToID("<name-of-parameter-in-shader>"), texture);
    Make sure we've got line
    Code (ShaderLab):
    1. sampler2D <name-of-parameter-in-shader>;
    in our shader.

    Hope, this discussion with myself will help someone.
     
    R0man and andrewpey like this.
  3. R0man

    R0man

    Joined:
    Jul 10, 2011
    Posts:
    90
    I can't get this to work at all. You would think setting the texture in the inspector would be enough.

    EDIT: Ok It works but nothing is happening when I render with a replacement shader.