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

very easy problem...help me

Discussion in 'Scripting' started by JohnSonLi, Sep 5, 2012.

  1. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    Shader "Example/Diffuse Texture" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}//.....................................Declaration once
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    };
    sampler2D _MainTex;//.......................................Declared again,why? Declare the same thing twice ,is it a must????
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    .........................................................................
     
  2. Marrrk

    Marrrk

    Joined:
    Mar 21, 2011
    Posts:
    1,032
    Those two are not equal, the first one declares a property, which is visible when you assign the shader to a material, you can change these values and see the description in the material inspector.

    The second declaration is for the shader, so that inside the shader code you can use the previousely declared property. When your shader does not need to access this property you can leave it out and keep the shader smaller and the performance higher.
     
  3. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    thank you