Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 HappyGoLucky · Oct 19, 2017 at 05:33 PM · uishadershader programmingshader-replacement

Fog of War overlay for overhead map.

Having used the tutorial by Sergey Taraban I have manage to create a working overlay for an overhead map. What I have achieved is as the player explores the world, the area on the map is revealed. I am hoping to refine the shader but lack the understanding for pragma. What I intend to have happen is instead of applying a color to the "Fog of War area" (black portion) apply a texture instead. The current shader code is as follows, the Tutorial can be found at https://www.youtube.com/watch?v=PNAvNeOTnSE. Any help would be appreciated.

Shader "Custom/FogOfWarMask" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _BlurPower("BlurPower", float) = 0.002 } SubShader{ Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha //Lighting off //LOD 200 CGPROGRAM #pragma surface surf Lambert alpha:fade #pragma target 3.0 fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, float aten) { fixed4 color; color.rgb = s.Albedo; color.a = s.Alpha; return color; }

fixed4 _Color; sampler2D _MainTex; float _BlurPower;

struct Input { float2 uv_MainTex; };

void surf(Input IN, inout SurfaceOutput o) { half4 baseColor1 = tex2D(_MainTex, IN.uv_MainTex + float2(-_BlurPower, 0)); half4 baseColor2 = tex2D(_MainTex, IN.uv_MainTex + float2(0, -_BlurPower)); half4 baseColor3 = tex2D(_MainTex, IN.uv_MainTex + float2(_BlurPower, 0)); half4 baseColor4 = tex2D(_MainTex, IN.uv_MainTex + float2(0, _BlurPower)); half4 baseColor = 0.25 (baseColor1 + baseColor2 + baseColor3 + baseColor4); //o.Albedo = baseColor.rgb; o.Albedo = _Color.rgb baseColor.b; o.Alpha = _Color.a - baseColor.g; } ENDCG } }

screenshot-20.jpg (145.9 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 HappyGoLucky · Oct 20, 2017 at 08:52 PM

Figured it out by combining two shaders together. The end result is as follows.

Shader "Custom/FogOfWarMask" { Properties{ _Color("Color", Color) = (1,1,1,1) _MainTex("Albedo (RGB)", 2D) = "white" {} _BlurPower("BlurPower", float) = 0.002 _PaintTex("Paint Texture (RGBA)", 2D) = "white" {} _BlendAmount("Blend Amount", Range(0.0, 1.0)) = 1.0 } SubShader{ Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha //Lighting off //LOD 200

     CGPROGRAM

pragma surface surf Lambert alpha:fade

pragma target 3.0

     fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, float aten) {
     fixed4 color;
     color.rgb = s.Albedo;
     color.a = s.Alpha;
     return color;
 }

 float _BlurPower;
 fixed4 _Color;
 sampler2D _MainTex;    
 sampler2D _PaintTex;
 fixed _BlendAmount;

 struct Input 
 {
     float2 uv_MainTex;
     float2 uv_PaintTex;
 };

 void surf(Input IN, inout SurfaceOutput o) 
 {    
     half4 baseColor1 = tex2D(_MainTex, IN.uv_MainTex + float2(-_BlurPower, 0));
     half4 baseColor2 = tex2D(_MainTex, IN.uv_MainTex + float2(0, -_BlurPower));
     half4 baseColor3 = tex2D(_MainTex, IN.uv_MainTex + float2(_BlurPower, 0));
     half4 baseColor4 = tex2D(_MainTex, IN.uv_MainTex + float2(0, _BlurPower));
     half4 baseColor = 0.25 * (baseColor1 + baseColor2 + baseColor3 + baseColor4);

     fixed4 paint = tex2D(_PaintTex, IN.uv_MainTex);

     o.Albedo = baseColor.rgb; 
     o.Albedo = lerp((_Color.rgb * baseColor.b), paint, _Color.a * _BlendAmount);
     o.Alpha = _Color.a - baseColor.g;        
 }
 ENDCG
 }

}

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 Brogan89 · Dec 11, 2017 at 09:33 AM 0
Share

Hey thanks so much, I'm so glad I stumbled across this. Spent the last 4.5 hours trying to work out why $$anonymous$$e was working after trying the same tutorial. Ended up just needing to add alpha:fade to the end of the`#pragma` line.

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

156 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

Related Questions

shadertoy to unity,Shadertoy to unity 0 Answers

How can i combine shaders? 0 Answers

3 Color linear gradient shader 1 Answer

Prevent overlapping UI image 0 Answers

Get shadowmap in HDRP with commandBuffer 0 Answers


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