- Home /
Random Tiling Textures
I have a small pool of textures that i want to adjust randomly to a surface of an object. Similar to how it was in half life. (demonstrated in this video) I'm sorry i'm new to unity and maybe this is a simple task but I didn't find any useful info on how to do it. Any advise would be helpful, thank you in advance.
               Comment
              
 
               
              After superficially learning about hlsl syntax i tried to create shader to solve this:
 Shader "Custom/RandomTilingShader"
 {
     Properties
     {
         _Tex1 ("Texture", 2D) = "white" {}
     _Tex2 ("Texture", 2D) = "white" {}
     _Tex3 ("Texture", 2D) = "white" {}
     _Tex4 ("Texture", 2D) = "white" {}
     }
     SubShader
         {
             Tags { "RenderType" = "Opaque" }
             LOD 200
             CGPROGRA$$anonymous$$
             #pragma surface surf Lambert
             sampler2D _Tex1;
             sampler2D _Tex2;
             sampler2D _Tex3;
             sampler2D _Tex4;
             struct Input 
             {
                 half2 uv_Tex1;
             };
             // generic pseudo-random function
             half rand2(half2 coords) 
             {
                 return frac(sin(dot(coords, half2(12.9898, 78.233))) * 43758.5453);
             }
             void surf(Input IN, inout SurfaceOutput o)
             {
                 const sampler2D TexArr[4] = { _Tex1, _Tex2, _Tex3, _Tex4 };
                 int x = rand2(floor(IN.uv_Tex1)) * 4;
                 half2 uvTex1 = IN.uv_Tex1;
                 sampler2D curTex = TexArr[x];
                 half4 tex1 = tex2D(curTex, uvTex1);
                 o.Albedo = tex1.rgb;
                 o.Alpha = tex1.a;
             }
         ENDCG
     }
             FallBack "Diffuse"
     }
but it doesn't work and I don't know what am i doing wrong.
Your answer
 
 
             Follow this Question
Related Questions
How do you properly let unity resize texture tiling? 0 Answers
Texture tiling for any object? 2 Answers
How do I fix repeating tiles ? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                