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

How to add lightmap for this shader?

Discussion in 'Shaders' started by viosat, Nov 4, 2015.

  1. viosat

    viosat

    Joined:
    Jun 14, 2015
    Posts:
    10
    Hi,
    how do I add lightmap for this shader?


    // - Unlit

    Shader "atsGrass-Unlit-Wind" {
    Properties {
    _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    }

    SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "LightMode"="ForwardBase"}
    LOD 100
    Cull Off
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha


    CGINCLUDE
    #include "UnityCG.cginc"
    sampler2D _MainTex;
    half4 _MainTex_ST;

    float4 _GrassWind; //is not defined in terrainengine.cginc

    struct v2f {
    float4 pos : SV_POSITION;
    float2 uv : TEXCOORD0;
    };

    inline float4 AnimateGrass(float4 pos, float3 normal, float animParams)
    {
    // animParams stored in color
    // animParams = primary factor = blue
    // Primary bending
    // Displace position
    pos.xyz += animParams * _GrassWind.xyz * _GrassWind.w; // controlled by vertex color blue
    return pos;
    }



    v2f vert (appdata_full v)
    {
    v2f o;
    float4 windParams = float(v.color.b);
    // call vertex animation
    float4 mdlPos = AnimateGrass(v.vertex, v.normal, windParams);
    o.pos = mul(UNITY_MATRIX_MVP,mdlPos);
    o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    return o;
    }
    ENDCG

    Pass {
    CGPROGRAM
    #pragma debug
    #pragma vertex vert
    #pragma fragment frag
    #pragma fragmentoption ARB_precision_hint_fastest
    fixed4 frag (v2f i) : COLOR
    {
    fixed4 tex = tex2D (_MainTex, i.uv);

    fixed4 c;
    c.rgb = tex.rgb;
    c.a = tex.a;

    return c;
    }
    ENDCG
    }
    }
    }
     
  2. StevenGerrard

    StevenGerrard

    Joined:
    Jun 1, 2015
    Posts:
    97
    Insert unity build-in support light map shader into your "frag" function.
    Multiply sampled light map color with "tex.rgb" would be good.
     
  3. viosat

    viosat

    Joined:
    Jun 14, 2015
    Posts:
    10
    Thank you very much for your answer !