- Home /
Question by
Flaming_burrito · Mar 17, 2021 at 06:41 AM ·
shader programmingshader writing
Shader Programming Missing Texture
Hello. I am trying to write an outline shader for my 3D game but the problem is that my material only works for projects not using URP. For projects that use URP, the only thing I can see is the outline. The object itself is pink indicating a missing texture. How would I make this shader work for URP?
Shader "Unlit/Outline"
{
Properties
{
_Color("Main Color", Color) = (0.5,0.5,0.5,1)
_MainTex ("Texture", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (0,0,0,1)
_OutlineWidth("Outline width", Range(1.0,5.0)) = 1.01 // width of 1.01
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float4 pos : POSITION;
float3 normal : NORMAL;
};
float _OutlineWidth;
float4 _OutlineColor;
v2f vert(appdata v)
{
v.vertex.xyz *= _OutlineWidth; // outline
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
ENDCG
SubShader
{
Tags { "RenderPipeline" = "UniversalRenderPipeline" }
Pass // rendering the outline
{
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag(v2f i): COLOR{
return _OutlineColor;
}
ENDCG
}
Pass // Rendering the object on top
{
ZWRITE On
Material{
Diffuse[_Color]
Ambient[_Color]
}
Lighting On
SetTexture[_MainTex]
{
ConstantColor[_Color]
}
SetTexture[_MainTex]{
Combine previous * primary DOUBLE
}
}
}
}
Comment