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

Rendering with Replaced Shaders ignores default value in Properties block?

Discussion in 'Shaders' started by EthanP, Jun 17, 2013.

  1. EthanP

    EthanP

    Joined:
    Jun 16, 2013
    Posts:
    16
    using the shader "Tutorial/Textured Colored" provided in the unity manual:
    http://docs.unity3d.com/Documentation/Manual/ShaderTut2.html

    modify the default color to some none white value
    Code (csharp):
    1.  
    2. _Color ("Main Color", Color) = (0.2,0,0,1)
    3.  
    then render with replaced shader by setting replacement shader for the camera
    Code (csharp):
    1.  
    2. camera.SetReplacementShader( Shader.Find( "Tutorial/Textured Colored" ), "" );
    3.  
    the result indicates _Color is white but not (0.2,0,0,1).

    It's correct on a material.
     
    Last edited: Jun 17, 2013
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    The replacement camera will copy any values with the same name from the normal shader of the object to the replacement shader. If you do not want that behavior, simply rename the _Color variable in the replacement shader to something that does not occur in any of the shaders you use for normal shading.
     
  3. EthanP

    EthanP

    Joined:
    Jun 16, 2013
    Posts:
    16
    changed the name, now the color is black..
     
  4. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    You can also hard-code the color into the shader if you want. There is no need to use a color variable if you know it has to become white.
     
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,864
    replacement shader will copy whatever the values are in the original material of your object and use it IF there is/are any unless they are already overwriten in the replacement shader itself.