At the moment, the shader looks like this:

Shader "Map/RoadUV" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _NoiseTex ("Albedo noise (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 } SubShader { Tags { "RenderType"="Opaque" "Queue" = "Geometry+1" } LOD 200 Offset -1, -1 CGPROGRAM #pragma surface surf Standard fullforwardshadows decal:blend #pragma target 3.0 sampler2D _MainTex; sampler2D _NoiseTex; struct Input { float2 uv_MainTex; float3 worldPos; }; half _Glossiness; half _Metallic; fixed4 _Color; void surf (Input IN, inout SurfaceOutputStandard o) { float4 noise = tex2D(_NoiseTex, IN.worldPos.xz * 0.025); fixed4 c = tex2D(_MainTex, IN.worldPos.xz * 0.025); float blend = IN.uv_MainTex.x; blend *= noise.x + 0.5; blend = smoothstep(0.4, 0.7, blend); o.Albedo = c.rgb; o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = blend; } ENDCG } FallBack "Diffuse" } 

I need instead of worldPos to use the second UV

  • You are doing something completely different, or I did not understand why it is - Stranger in the Q
  • Why use the world coordinates as textural, I do not understand - Stranger in the Q
  • @StrangerintheQ for a flat object is pretty convenient, but now I just need to change it from worldPos to UV - WanSpi
  • it will only work for fixed objects, but oh well, it’s not clear what the problem is, what effect are you trying to achieve? You give the shader code that does something, without explanation ... - Stranger in the Q
  • @StrangerintheQ I perfectly understand that this example will only work with static objects, so I want to redo it, so that the coordinates would be taken from the UV, and not from the global coordinates, this is how to extract the UV coordinates of the second channel - WanSpi

1 answer 1

I managed to conjure up, in general, now the code looks like this:

  Shader "Map/RoadUV" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _NoiseTex ("Albedo noise (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 } SubShader { Tags { "RenderType"="Opaque" "Queue" = "Geometry+1" } LOD 200 Offset -1, -1 CGPROGRAM #pragma surface surf Standard fullforwardshadows decal:blend vertex:vert #pragma target 3.5 sampler2D _MainTex; sampler2D _NoiseTex; struct Input { float2 uv_MainTex : TEXCOORD0; float3 myUV2; }; half _Glossiness; half _Metallic; fixed4 _Color; void vert (inout appdata_full v, out Input data) { UNITY_INITIALIZE_OUTPUT(Input, data); data.myUV2 = v.texcoord2.xyz; } void surf (Input IN, inout SurfaceOutputStandard o) { float4 noise = tex2D(_NoiseTex, IN.myUV2.xy * 0.025); fixed4 c = tex2D(_MainTex, IN.myUV2.xy * 0.025); float blend = IN.uv_MainTex.x; blend *= noise.x + 0.5; blend = smoothstep(0.4, 0.7, blend); o.Albedo = c.rgb; o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = blend; } ENDCG } FallBack "Diffuse" }