Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by wooolly · Aug 19, 2020 at 11:27 AM · shaderfog of warfog-of-war

Fog of War Shader help - prevent light changes

Hello,

I followed this old tutorial on implementing a fog of war shader... (https://www.youtube.com/watch?v=PNAvNeOTnSE) In essence, it's implemented by putting a plane over the entire game world, applying a raw texture to that plane which has circles at each units position, and using a custom shader to make those circles transparent. The circles are bright green and the background is bright blue so it knows where to apply transparency.

I have got it mostly working, the only problem is it seems to effect the lighting. I don't know enough about shaders to know why this is.

FOW plane disabled FOW plane enabled I've attached two screenshots, one is with the FOW plane disabled, the other is with it enabled. The game becomes a lot brighter with the FOW plane enabled. This screenshot is taken at midday (when the sun is at it's highest intensity), so the opposite effect happens when at midnight (night time), it becomes REALLY dark.

I don't want the light to be affected at all, the ONLY thing I want is for the circles to be fully transparent, and for the remaining plane to be semi-transparent with a black colouring like it currently is. Please assist me if possible and thanks for reading.

Code:

 Shader "Custom/FogOfWar" {
     Properties {
         _Color("Main Color", Color) = (1,1,1,1)
         _MainTex("Base (RGB)", 2D) = "white" {}
     }
 
     SubShader {
         Tags {"RenderType"="Transparent" "LightMode"="ForwardBase"}
         Blend SrcAlpha OneMinusSrcAlpha
         Lighting Off
         LOD 200
 
         CGPROGRAM
         #pragma surface surf NoLighting noambient alpha
 
         fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, float aten)
         {
                 fixed4 color;
                 color.rgb = s.Albedo;
                 color.a = s.Alpha;
                 return color;
         }
         
         sampler2D _MainTex;
         fixed4     _Color;
 
         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; // Green - colour of aperture mask
         }
         ENDCG
     }
 }


lightshaderhelp1.png (501.3 kB)
lightshaderhelp2.png (341.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Namey5 · Aug 20, 2020 at 04:40 AM

A few things;

1. The 'LightMode; tag should only go inside a pass and isn't necessary in surface shaders. For transparent shaders however, you should set the 'Queue' tag to transparent;


 Tags {"RenderType"="Transparent" "Queue"="Transparent"}


2. This is a surface shader, so you don't need to manually handle blending;


 //Remove this
 Blend SrcAlpha OneMinusSrcAlpha
 
 ...
 
 //Change 'alpha' to 'alpha:fade'
 CGPROGRAM
 #pragma surface surf NoLighting noambient alpha:fade


3. Make sure your alpha is only in a range of [0,1], otherwise you can end up with unexpected behaviour if you aren't careful;


 o.Alpha = saturate (_Color.a - baseColor.g);
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wooolly · Aug 20, 2020 at 09:41 AM 0
Share

You, sir, are a god. Thanks for the assistance.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

201 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RTS fog of war texture remapping shader,Fog of war plane texture remapping shader HDRP 0 Answers

Change shader properties during rungtime 1 Answer

Fog of War Effect Help 0 Answers

How to hide a texture partially without rendering to it? 0 Answers

How to show render texture in a 2D game (Fog of War). 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges