hi everyone,
I create this shader a long time ago. I need to use it in another project, but in the new project I work with URP, but when I try to import, shows me some troubles. I saw that the code changed in the URP. so how can I change the code?
I guess the only difference is to change the CGPROGRAM to HLSLPROGRAM, but when I change it the following error appears
“Shader error in ‘labxsp/Piso’: Unexpected identifier “fixed4”. Expected one of: typedef const void inline uniform nointerpolation extern shared static volatile row_major column_major struct sampler or a user-defined type at UnityLightingCommon.cginc(4)”
i change the fixed4 to float4. but it doesn’t work.
i share the code
this is the old code
Shader "labxsp/Piso"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_tamanoCuadricula ("Tamaño de cuadricula", float) = 4
_GrosorLinea ("Grosor de Linea", Range (0.0,1.0)) = .1
_ColorLinea ("Color de Linea", Color) = (1,0,0,1)
_ColorPiso ("Color del piso", Color) = (0,0,0,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Unlit alpha
sampler2D _MainTex;
float _tamanoCuadricula, _GrosorLinea;
float4 _ColorLinea, _ColorPiso;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
float4 c = _ColorPiso;
float2 uv = IN.uv_MainTex;
float2 cuadricula = frac(uv * _tamanoCuadricula);
if (cuadricula.x > _GrosorLinea || cuadricula.y > _GrosorLinea)
{
//o.Emission = _ColorLinea * cos(_Time.y)*.5+.5;
o.Emission = _ColorLinea* sin(_Time.y /3);
}
o.Albedo = c.rgb;
o.Alpha = c.a;
}
half4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten)
{
fixed4 c;
c.rgb = s.Albedo.rgb;
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
}
This is the new code
Shader "labxsp/Piso"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_tamanoCuadricula ("Tamaño de cuadricula", float) = 4
_GrosorLinea ("Grosor de Linea", Range (0.0,1.0)) = .1
_ColorLinea ("Color de Linea", Color) = (1,0,0,1)
_ColorPiso ("Color del piso", Color) = (0,0,0,1)
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
HLSLPROGRAM
#pragma surface surf Unlit alpha
sampler2D _MainTex;
float _tamanoCuadricula, _GrosorLinea;
float4 _ColorLinea, _ColorPiso;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
float4 c = _ColorPiso;
float2 uv = IN.uv_MainTex;
float2 cuadricula = frac(uv * _tamanoCuadricula);
if (cuadricula.x > _GrosorLinea || cuadricula.y > _GrosorLinea)
{
//o.Emission = _ColorLinea * cos(_Time.y)*.5+.5;
o.Emission = _ColorLinea* sin(_Time.y /3);
}
o.Albedo = c.rgb;
o.Alpha = c.a;
}
half4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten)
{
float4 c;
c.rgb = s.Albedo.rgb;
c.a = s.Alpha;
return c;
}
ENDHLSL
}
FallBack "Diffuse"
}
Thanks a lot.