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 inkclear · Jul 17, 2017 at 04:36 AM · shadersfogmergeunlit

Is merging this two shaders possible?

Hello! Im trying to merge this two shaders with out luck, what I am trying to accomplish is having an Unlit Texture as my base color and on top have this fog that reacts to Height and Distance from the 0 point on the scene... It can be merging the shader codes or having the two materials layered with the fog multiplied over the other unlit texture, what maters to me is the result more than doing it one way or another...

So the fisrt one is a simple unlit texture shader:

 Properties
 {
     _MainTex ("Texture", 2D) = "white" {}
 }
 SubShader
 {
     Tags { "RenderType"="Opaque" }
     LOD 100

     Pass
     {
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         // make fog work
         #pragma multi_compile_fog
         
         #include "UnityCG.cginc"

         struct appdata
         {
             float4 vertex : POSITION;
             float2 uv : TEXCOORD0;
         };

         struct v2f
         {
             float2 uv : TEXCOORD0;
             UNITY_FOG_COORDS(1)
             float4 vertex : SV_POSITION;
         };

         sampler2D _MainTex;
         float4 _MainTex_ST;
         
         v2f vert (appdata v)
         {
             v2f o;
             o.vertex = UnityObjectToClipPos(v.vertex);
             o.uv = TRANSFORM_TEX(v.uv, _MainTex);
             UNITY_TRANSFER_FOG(o,o.vertex);
             return o;
         }
         
         fixed4 frag (v2f i) : SV_Target
         {
             // sample the texture
             fixed4 col = tex2D(_MainTex, i.uv);
             // apply fog
             UNITY_APPLY_FOG(i.fogCoord, col);
             return col;
         }
         ENDCG
     }
 }

}

and the second one is this one (the one with the fog), it has a lot of controls for some lights, which I don't need, just need that fog to emulate a shadow over height and depth:

 Properties {
     _MainTex ("Texture", 2D) = "white" {}
     _LayoutTexture ("Layout Texture", 2D) = "white" {}
     _LayoutTexturePower ("Layout Texture Power", Float) = 1
      _MainColor ("Main Color", Color) = (1,0.73,0.117,0)
      _TopLight ("Top Light", Float) = 1
      _RightLight ("Right Light", Float) = 1
      _FrontLight ("Front Light", Float) = 1
     _RimColor ("Rim Color", Color) = (0,0,0,0)
     _RimPower ("Rim Power", Float) = 0.0
     
      _LightTint ("Light Tint", Color) = (1,1,1,0)
      _AmbientColor ("Ambient Color", Color) = (0.5,0.1,0.2,0.0)
      _AmbientPower ("Ambient Power", Float) = 0.0
     _LightmapColor ("Lightmap Tint", Color) = (0,0,0,0)
     _LightmapPower ("Lightmap Power", Float) = 1
     _ShadowPower ("Shadow Light", Float) = 0
     [Toggle(USE_LIGHTMAP)]_UseLightMap ("Lightmap Enabled", Float) = 0
     
     _FogColor ("Fog color", Color) = (1,1,1,1)
     _FogYStartPos ("Fog Y-start pos", Float) = 0.1
     _FogHeight ("Fog Height", Float) = 0.1
     _FogAnimationHeight ("Fog Animation Height", Float) = 0.1
     _FogAnimationFreq ("Fog Animation Frequency", Float) = 0.1
     [Toggle(USE_DIST_FOG)]_UseFogDistance ("Distance Fog", Float) = 0
     _FogStart ("Distance Start", Float) = 0
      _FogEnd ("Distance End", Float) = 50
      _FogDensity ("Distance Density", Float) = 1

      [HideInInspector]_LightDirF ("Front Light Direction", Vector) = (0,0,-1)
     [HideInInspector]_LightDirT ("Top Light Direction", Vector) = (0,1,0)
     [HideInInspector]_LightDirR ("Right Light Direction", Vector) = (1,0,0)
     [Toggle(USE_DIR_LIGHT)] _UseDirLight ("Directional Light", Float) = 0
 }
 SubShader {
     Tags { "QUEUE"="Geometry" "RenderType"="Opaque" }
     LOD 200
     
     Pass {
     Tags { "LIGHTMODE"="ForwardBase" "QUEUE"="Geometry" "RenderType"="Opaque" }
         CGPROGRAM
             #pragma shader_feature USE_LIGHTMAP
             #pragma shader_feature USE_DIST_FOG
             #pragma shader_feature USE_DIR_LIGHT
             #pragma fragmentoption ARB_precision_hint_fastest
             
             #define USE_LAYOUT_TEXTURE;
             #define USE_MAIN_TEX;
             #define USE_FOG
             #pragma vertex vert
             #pragma fragment frag

             uniform half3 _MainColor;
             uniform half _TopLight;
             uniform half _RightLight;
             uniform half _FrontLight;
             uniform half3 _RimColor;
             uniform half _RimPower;
             
             uniform half3 _AmbientColor;
             uniform half _AmbientPower;
             uniform half _UseLightMap;
             
             uniform half _LightmapPower;
             uniform half3 _LightTint;
             uniform half3 _LightmapColor;
             uniform half _ShadowPower;
             
             uniform float _LayoutTexturePower;
             
             uniform half3 _FogColor;
             uniform half _FogYStartPos;
             uniform half _FogHeight;
             uniform half _FogAnimationHeight;
             uniform half _FogAnimationFreq;    
             
             uniform half _FogStart;
             uniform half _FogEnd;
             uniform half _FogDensity;
             
             #include "Marvelous.cginc"
             
 
             CL_OUT_WPOS vert(CL_IN v) {
             #ifndef USE_DIST_FOG
                 return customLightingSimpleSoftFogVert(v, _MainColor, _RimColor, _RimPower, _RightLight, _FrontLight, _TopLight, _AmbientColor, _AmbientPower,_FogYStartPos, _FogAnimationHeight, _FogAnimationFreq);
             #else
                 CL_OUT_WPOS o=customLightingSimpleSoftFogVert(v, _MainColor, _RimColor, _RimPower, _RightLight, _FrontLight, _TopLight, _AmbientColor, _AmbientPower,_FogYStartPos, 1, 1);
                 float cameraVertDist = length(_WorldSpaceCameraPos - o.wpos)*_FogDensity; 
                 o.color.w = saturate((_FogEnd - cameraVertDist) / (_FogEnd - _FogStart));    
                 return o;        
             #endif
             }
             
             fixed4 frag(CL_OUT_WPOS v) : COLOR {
             #ifndef USE_DIST_FOG
                 return customLightingSoftFogFrag(v, _FogColor, _FogHeight, _LightTint, _UseLightMap, _LightmapPower, _LightmapColor, _ShadowPower);
             #else
                 fixed4 c = customLightingSoftFogFrag(v, _FogColor, _FogHeight, _LightTint, _UseLightMap, _LightmapPower, _LightmapColor, _ShadowPower);
                 return lerp(half4(_FogColor,1),c,v.color.w);
             #endif
             }
             
         ENDCG
     }
 }
 FallBack "Diffuse"

}

Hope some one has an idea, Thanks in advance!

Comment
Add comment · Show 1
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 Cornelis-de-Jager · Jul 17, 2017 at 04:39 AM 0
Share

Not sure why you want to merge the a fog texture with your buildings? Is there anything the in-game Fog can't handle? Also if you just want to make a fog effect around a certain point maybe check this out:

http://answers.unity3d.com/questions/52486/how-to-make-a-good-fog-effect.html

0 Replies

· Add your reply
  • Sort: 

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

73 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

Related Questions

Shader graph place small image/texture at specific location on object,Shader graph place texture at specific place on object 0 Answers

Lighting support in Unlit shader 0 Answers

Unlit Terrain Foliage, is it possible? 1 Answer

Global fog doesn't work? 0 Answers

Default-Sprite with fog 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