Search Unity

How to lighting object by self shader?

Discussion in 'General Graphics' started by liuyu, Jan 29, 2015.

  1. liuyu

    liuyu

    Joined:
    Oct 14, 2014
    Posts:
    28
    Hi,
    There is a devil(left) by shader "Diffuse" (the unity default shader), and a swordman(right) by shader "MyShader"(the shader that I wrote).
    I use pix of directx to find how to render lighting:
    1. draw devil (no lighting)
    2. draw swordman (no lighting)
    3. draw devil (lighting, alpha is add (one one)
    4. there is not draw swordman(lighting)
    Why the swordman isn't draw lighting like devil? Thanks.


    Code (CSharp):
    1. Shader "MyShader" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.     }
    5.     SubShader {
    6.         Tags { "RenderType"="Opaque" }
    7.         LOD 200
    8.         Pass
    9.         {
    10.             Tags {"LightMode" = "ForwardBase"}
    11.             Cull back
    12.             Lighting off
    13.             Blend off          
    14.             CGPROGRAM
    15.             #pragma multi_compile_fwdbase
    16.             #pragma vertex Vert_T
    17.             #pragma fragment Frag_T
    18.             #pragma fragmentoption ARB_precision_hint_fastest
    19.                      
    20.             PX_T_outvs Vert_T(PX_T_invs i)
    21.            {
    22.             PX_T_outvs o;
    23.             o.pos = mul (UNITY_MATRIX_MVP, i.vertex);  
    24.             o.texcoord = i.texcoord;
    25.             return o;
    26.            }
    27.            fixed4 Frag_T( PX_T_outvs i ) : COLOR
    28.            {
    29.               fixed4 colorTex = tex2D(_MainTex, i.texcoord);
    30.               return colorTex;
    31.             }
    32.            ENDCG
    33.           }
    34.       }
    35.       FallBack "Diffuse"
    36.     }