I'm developing a shader in unity. The shader must contain vertex, fragment and geometry shaders, and while the first two work fine, I have problems with geometry shader.
When I use the code below, the shaded object the shader just gets painted pink, but I see no shader compilation errors. If I just remove geometry shader, everything works as expected.
The current implementation should just copy input data to output, i.e. do nothing.
Another interesting thing is that Unity is likely to ignoring the content of the geometry shader - if I remove everything from it, the object is still pink. In my understanding nothing should be rendered in this case.
The code I'm using:
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Custom/VoidCircle"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Progress ("Progress", float) = 0.4
}
SubShader
{
Tags { "RenderType"="Opaque" }
Blend SrcAlpha OneMinusSrcAlpha
LOD 100
Pass
{
CGPROGRAM
#pragma geometry geom
#pragma vertex vert
#pragma fragment frag
struct appdata
{
float4 vertex : POSITION; // vertex position
float2 uv : TEXCOORD0; // texture coordinate
};
struct v2f
{
float2 uv : TEXCOORD0; // texture coordinate
float4 vertex : SV_POSITION; // clip space position
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
// ALL THE PROBLEMS ARE HERE
[maxvertexcount(3)]
void geom(triangle v2f input[3], inout TriangleStream<v2f> OutputStream)
{
for (int i = 0; i < 3; i++) {
OutputStream.Append(input[i]);
}
}
sampler2D _MainTex;
float4 _MainTex_TexelSize;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
float besta = 0;
int d = 1;
for (int x = -d; x <= d; x++) {
for (int y = -d; y <= d; y++) {
float4 col1 = tex2D(_MainTex, i.uv + fixed2(_MainTex_TexelSize.x * x, _MainTex_TexelSize.y * y));
if (col1.a > besta) {
besta = col1.a;
}
}
}
if (col.a > 0) {
return float4(col.a, col.a, col.a, 1);
} else {
return float4(0, 0, 0, besta);
}
}
ENDCG
}
}
}