代码如下:
Shader "World Shader"{属性{_MainTex ("Base (RGB)", 2D) = "white"{}_TextureScale ("Texture Scale", float) = 1
//[NoScaleOffset] _BumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 250
CGPROGRAM
#pragma surface surf Lambert noforwardadd
sampler2D _MainTex;
float _TextureScale;
//sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
float3 worldPos;
float3 worldNormal;
};
float myFmod(float a, float b)
{
float c = frac(abs(a / b)) * abs(b);
return c;
}
void surf (Input IN, inout SurfaceOutput o)
{
float x = IN.worldPos.x * _TextureScale;
float y = IN.worldPos.y * _TextureScale;
float z = IN.worldPos.z * _TextureScale;
float isUp = abs(IN.worldNormal.y);
float2 offset = float2(myFmod(z + x * (1 - isUp), 0.0625), myFmod(y + x * isUp, 0.0625));
fixed4 c = tex2D(_MainTex, IN.uv_MainTex + offset);
o.Albedo = c.rgb;
o.Alpha = 1;
//o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
}
ENDCG
}
FallBack "Mobile/Diffuse"
}
我把我的unity项目切换到URP,我的自定义着色器停止工作:(我如何使我的自定义着色器支持URP?我如何转换它?
在尝试将着色器代码转换为url之前,如果您的着色器足够简单,您可以尝试让Unity为您自己转换。
选择着色器应用的材质。编辑→呈现→材料→将选择的内置材料转换为URP。
将材料转换为URP