0

I created fog by raw image and material with custom shader.

Now I want to darken some gameobjects(sprites) which cross fog border.

But I'm noob in shaders. How I can do this? Write any links on manuals/tutorials or some ideas.

Picture for clarity: picture picture

Fog shader:

Shader "Custom/Fog" {
Properties{
    _Color("Main Color", Color) = (1,1,1,1)
    _MainTex("Base (RGB)", 2D) = "white" {} // Base (RGB)
}
    SubShader{
        Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" "LightMode" = "ForwardBase" "IgnoreProjector" = "True" }
        Blend SrcAlpha  OneMinusSrcAlpha
        Lighting Off
        LOD 200

        CGPROGRAM

            #pragma surface surf NoLighting noambient alpha:blend

            fixed4 _Color;
            sampler2D _MainTex;

            struct Input {
                float2 uv_MainTex;
            };


            void surf(Input IN, inout SurfaceOutput o) {

                half4 baseColor = tex2D(_MainTex, IN.uv_MainTex);
                o.Albedo = _Color.rgb * baseColor.b;
                o.Alpha = _Color.a - baseColor.g;
            }
        ENDCG
   }
      FallBack "Diffuse"
}
Slimper
  • 23
  • 2
  • 6
  • Oh this looks tricky. Is the gray box (the fog) an object in the scene? Rendered overlay? Distance from camera? Something else? The answer to your question would depend heavily on which one of those it is. – Draco18s no longer trusts SE Apr 18 '17 at 15:42
  • Fog is raw image in separate canvas (Screen Space - Camera). raw image texture is rendertexture. active masks (fog camera looks on mask layer) control open/closed areas. [picture](http://prnt.sc/ey5avf) Camera: orthographic. Distance: -25 – Slimper Apr 19 '17 at 06:33
  • Example result image: [picture](https://image.ibb.co/gtC5BQ/Screenshot_7.png) – Slimper Apr 19 '17 at 08:39
  • Ok, so that result isn't achieved by doing things the way you're doing it. It's achieved by using completely different sprites on tiles the game knows are supposed to be fogged. – Draco18s no longer trusts SE Apr 19 '17 at 12:18
  • If you want to darken whatever is behind, a good start is to switch to multiplicative blending, i.e. replace Blend SrcAlpha OneMinusSrcAlpha with Blend DstColor Zero. – Kalle Halvarsson Jan 04 '19 at 13:48

0 Answers0