Search Unity

Question Shader should change prefab color based on height but it doesnt

Discussion in 'Shaders' started by Jinngineer, Oct 12, 2021.

  1. Jinngineer

    Jinngineer

    Joined:
    Apr 22, 2020
    Posts:
    41
    Hello,

    Ive been following CatLike Codings tutorials about the basics of Unity and on the 2nd one he started discussing shaders.

    The code is supposed to cause the colors of the instantiated prefab to change with its position on the y axis, but the color always remains black.

    The shader is attatched to the matieral, and the material is attached to the prefab.

    This is my first foray into using shaders, any constructive criticism is welcome :)

    Code (csharp):
    1.  
    2. Shader "Graph/Point Surface"
    3. {
    4.    Properties
    5.        {
    6.        _Smoothness ("Smoothness", Range(0,1)) = 0.5
    7.        }
    8.        SubShader
    9.        {
    10.        CGPROGRAM
    11.    #pragma surface ConfigureSurface Standard fullforwardshadows
    12.    #pragma target 3.0
    13.        struct Input
    14.            {
    15.                float3 worldPos;
    16.            };
    17.        float _Smoothness;
    18.        void ConfigureSurface(Input input, inout SurfaceOutputStandard surface)
    19.            {
    20.            surface.Albedo = input.worldPos * 0.5 + 0.5;
    21.            surface.Smoothness = _Smoothness;
    22.            }
    23.        ENDCG
    24.  
    25.        }
    26.  
    27.        FallBack "Diffuse"
    28. }
    29.  
    30.