Search Unity

How make a standard surface shader which use ambient light?

Discussion in 'Shaders' started by dienat, May 24, 2017.

  1. dienat

    dienat

    Joined:
    May 27, 2016
    Posts:
    417
    I am using a surface shader with standard illumination and it just ignore ambient light, it doesnt happen when i use the Standard shader unity provides

    Code (CSharp):
    1. Shader "Custom/CustomShader" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _BumpMap("Bumpmap", 2D) = "bump" {}
    6.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    7.         _Metallic ("Metallic", Range(0,1)) = 0.0
    8.     }
    9.     SubShader {
    10.         Tags { "RenderType"="Opaque" }
    11.         LOD 200
    12.  
    13.         CGPROGRAM
    14.         // Physically based Standard lighting model, and enable shadows on all light types
    15.         #pragma surface surf Standard fullforwardshadows
    16.  
    17.         // Use shader model 3.0 target, to get nicer looking lighting
    18.         #pragma target 3.0
    19.  
    20.         sampler2D _MainTex;
    21.         sampler2D _BumpMap;
    22.  
    23.         struct Input {
    24.             float2 uv_MainTex;
    25.             float2 uv_BumpMap;
    26.         };
    27.  
    28.         half _Glossiness;
    29.         half _Metallic;
    30.         fixed4 _Color;
    31.  
    32.         void surf (Input IN, inout SurfaceOutputStandard o) {
    33.             // Albedo comes from a texture tinted by color
    34.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    35.             o.Albedo = c.rgb;
    36.             // Metallic and smoothness come from slider variables
    37.             o.Metallic = _Metallic;
    38.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    39.             o.Smoothness = _Glossiness;
    40.             o.Alpha = c.a;
    41.         }
    42.         ENDCG
    43.     }
    44.     FallBack "Diffuse"
    45. }
    46.  
     
  2. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    try this pragma...
    #pragma surface surf Lambert
     
  3. dienat

    dienat

    Joined:
    May 27, 2016
    Posts:
    417
    It doesnt work, needs to be Standard to get the metallic and smoothness
     
  4. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    you asked about ambient light. that pragma does work with ambient light... at least it does in my shaders, but I'm making shaders for mobile, So I'm not using metallic and smoothness.

    Can you start from the shader unity provides, and modify that ? or look at the differences in tags, pragma or and included files.
     
  5. dienat

    dienat

    Joined:
    May 27, 2016
    Posts:
    417
    yes i could try with the unity standard and modify but dont know how difficult it will be and i wanted to know why with the standard lighting model it doesnt have ambient light