Monday, April 28, 2025
HomeGame DevelopmentLearn how to make tiling properties work with extra texture slots in...

Learn how to make tiling properties work with extra texture slots in a Unity Floor Shader?


I’ve created a customized shader based mostly on Unity’s commonplace floor shader,
however tiling and offset properties do not work in any respect.
Solely the albedo texture slot’s tiling works.
How do you make tiling work for particular person texture slots?

Material properties with tiling and offset section circled

My customized shader code simply in case:

Shader "Customized/customized shader" {
    Properties {
        _Color ("Coloration", Coloration) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _NormalTex ("Regular map", 2D) = "bump" {}
        _BumpScale ("Bump scale", Vary(0,1)) = 1.0
        _Glossiness ("Smoothness", Vary(0,1)) = 0.5
        _Metallic ("Metallic", Vary(0,1)) = 0.0
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
        
        CGPROGRAM
        // Bodily based mostly Normal lighting mannequin, and allow shadows on all gentle sorts
        #pragma floor surf Normal fullforwardshadows

        // Use shader mannequin 3.0 goal, to get nicer trying lighting
        #pragma goal 3.0

        sampler2D _MainTex;
        sampler2D _NormalTex;

        struct Enter {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        half _BumpScale;
        fixed4 _Color;

        void surf (Enter IN, inout SurfaceOutputStandard o) {
            // Albedo comes from a texture tinted by shade
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;

            fixed3 n = UnpackScaleNormal(tex2D(_NormalTex, IN.uv_MainTex), _BumpScale);
            o.Regular = n;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments