- Home /
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!
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
Your answer
![](https://koobas.hobune.stream/wayback/20220612130138im_/https://answers.unity.com/themes/thub/images/avi.jpg)