Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Surface shader with lightmap

Discussion in 'Shaders' started by kabur, Aug 1, 2019.

  1. kabur

    kabur

    Joined:
    Jan 23, 2016
    Posts:
    12
    I am totally a new to shaders.I got a shader from the Infinite Runner Package that bends world. Now the problem is, it doesnt support lightmaps. So, can anyone please tell me, what do i have to add in this shader if i want it to support lightmap ? (I tried adding code from a Lightmap shader to this one, i dont know what i did wrong.)

    Code (CSharp):
    1.  
    2. Shader "Custom/Curved" {
    3.      
    4.     Properties {
    5.         _MainTex ("Base (RGB)", 2D) = "white" {}
    6.         _QOffset ("Offset", Vector) = (0,0,0,0)
    7.         _Dist ("Distance", Float) = 100.0
    8.     }
    9.     SubShader {
    10.         Tags { "RenderType"="Opaque" }
    11.         LOD 200
    12.         Fog { Color [_AddFog] }
    13.        
    14.         CGPROGRAM
    15.         #pragma surface surf Lambert vertex:myvert finalcolor:mycolor
    16.  
    17.         sampler2D _MainTex;
    18.     uniform float4 _QOffset;
    19.         uniform float _Dist;
    20.         float4 color : COLOR;
    21.  
    22.         struct Input
    23.         {
    24.             float2 uv_MainTex;
    25.             half Myfog;
    26.         };
    27.  
    28.         void myvert (inout appdata_full v, out Input data)
    29.         {
    30.             float4 vv = mul( unity_ObjectToWorld, v.vertex );
    31.                 [URL='http://vv.xyz/']vv.xyz[/URL] -= _WorldSpaceCameraPos.xyz;
    32.         float zOff = vv.z/_Dist;
    33.         vv = _QOffset*zOff*zOff;
    34.                 v.vertex += mul(unity_WorldToObject, vv);
    35.                 UNITY_INITIALIZE_OUTPUT(Input,data);
    36.         }
    37.         void mycolor (Input IN, SurfaceOutput o, inout fixed4 color)
    38.         {
    39.         }
    40.  
    41.         void surf (Input IN, inout SurfaceOutput o) {
    42.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    43.             o.Albedo = c.rgb;
    44.             o.Alpha = c.a;
    45.         }
    46.         ENDCG
    47.        
    48.     }    
    49.      FallBack "Diffuse"
    50.  }
    51.  
    52.  
    53.  
     
unityunity