Saturday, October 1, 2022
HomeGame DevelopmentUnity Shader - Transferring one texture round and on prime of one...

Unity Shader – Transferring one texture round and on prime of one other texture


I’ve a shader that applies a texture to a sphere with lighting, making it appear like a properly lit planet:

enter image description here

The code for my shader is right here:

Shader "Customized/CloudedSurface"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Clouds ("Clouds", 2D) = "white" {}
    }
    SubShader
    {
        Go {
            Tags { "LightMode" = "ForwardBase" }
            CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #embrace "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 consequence = fixed4(col.rgb * dif * _LightColor0.rgb, 1);
                    return consequence;
                }
            ENDCG
        }
    }
}

It’s fairly easy because it simply applies a texture to a sphere with some primary lighting. It must run on a cellular so I need to hold it easy for prime efficiency. No want for advanced results or particulars and many others.

The problem is that I would like to use a second texture (referred to as “Clouds” above) and transfer this across the sphere, while holding it below the affect of lighting. It will make it appear like clouds are shifting across the planet. Please can somebody assist me to do that?

I do not suppose it ought to be arduous, however at any time when I strive it combines the 2 textures collectively and strikes them concurrently. I do not know easy methods to transfer the clouds independently and “on prime” of the principle texture to create the phantasm. Perhaps I would like a second move? I’ve tried to no luck.

Any assist can be actually appreciated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments