Hello Guest

Author Topic: Fog not displaying on sprites  (Read 4368 times)

rajmehta2509

  • Newbie
  • *
  • Posts: 3
    • View Profile
Fog not displaying on sprites
« on: February 10, 2016, 11:56:30 pm »
Hi i am developing a 3d game and i using tk2dsprite for grass but the problem is fog is not effecting the sprites.

after searching the forum what i did was -

Shader "tk2d/BlendVertexColor"
{
   Properties
   {
      _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
   }
   
   SubShader
   {
      Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
      ZWrite Off Lighting Off Cull Off Fog { Mode Linear Range 0,50 Color (1,1,1,1) } Blend SrcAlpha OneMinusSrcAlpha
      LOD 110
      
      Pass
      {
         CGPROGRAM
         #pragma vertex vert_vct
         #pragma fragment frag_mult
         #pragma fragmentoption ARB_precision_hint_fastest
         #include "UnityCG.cginc"

         sampler2D _MainTex;
         float4 _MainTex_ST;

         struct vin_vct
         {
            float4 vertex : POSITION;
            float4 color : COLOR;
            float2 texcoord : TEXCOORD0;
         };

         struct v2f_vct
         {
            float4 vertex : POSITION;
            fixed4 color : COLOR;
            float2 texcoord : TEXCOORD0;
         };

         v2f_vct vert_vct(vin_vct v)
         {
            v2f_vct o;
            o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
            o.color = v.color;
            o.texcoord = v.texcoord;
            return o;
         }

         fixed4 frag_mult(v2f_vct i) : COLOR
         {
            fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
            return col;
         }
         
         ENDCG
      }
   }
 
   SubShader
   {
      Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
      ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off Fog { Mode Linear Range 0,50 }
      LOD 100

      BindChannels
      {
         Bind "Vertex", vertex
         Bind "TexCoord", texcoord
         Bind "Color", color
      }

      Pass
      {
         Lighting Off
         SetTexture [_MainTex] { combine texture * primary }
      }
   }
}

But still there is no fog on sprites.I want my sprites to remain unlit but i do want the fog effect.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Fog not displaying on sprites
« Reply #1 on: February 23, 2016, 09:33:24 pm »
I would highly recommend not using tk2d for grass in a 3d game - it wasn't built for that and performance won't be particularly great. You're better off buildign the grass meshes a 3d package.

Having said that - you should probably write a surface shader that writes to Emission instead of Albedo, that will give you what you need without having to work out what the fog system in unity does.