
[ad_1]
I’ve a shader that applies a texture to a sphere with lighting, making it seem like a properly lit planet:
The code for my shader is right here:
Shader "Custom/CloudedSurface"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Clouds ("Clouds", 2D) = "white" {}
}
SubShader
{
Pass {
Tags { "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#embody "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 regular : NORMAL;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float3 regular : NORMAL;
float3 worldPos : TEXCOORD1;
};
sampler2D _MainTex;
sampler2D _Clouds;
float4 _MainTex_ST;
float4 _Clouds_ST;
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.regular = normalize(mul(v.regular, unity_WorldToObject).xyz);
return o;
}
fixed4 _LightColor0;
fixed4 frag(v2f i) : SV_Target
{
float dif = max(0.05, dot(i.regular, normalize(_WorldSpaceLightPos0.xyz)));
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 end result = fixed4(col.rgb * dif * _LightColor0.rgb, 1);
return end result;
}
ENDCG
}
}
}
It is sort of easy because it simply applies a texture to a sphere with some fundamental lighting. It must run on a cellular so I need to maintain it easy for top efficiency. No want for advanced results or particulars and so forth.
The subject is that I would like to use a second texture (referred to as “Clouds” above) and transfer this across the sphere, while preserving it underneath the affect of lighting. This will make it seem like clouds are transferring across the planet. Please can somebody assist me to do that?
I do not assume it ought to be onerous, however at any time when I strive it combines the 2 textures collectively and strikes them concurrently. I do not know the way to transfer the clouds independently and “on high” of the principle texture to create the phantasm. Maybe I would like a second cross? I’ve tried to no luck.
Any assist can be actually appreciated.
[ad_2]