I am writing a shader to achieve a laser show effect example. For now I am just focusing on the lines. One line ist represented as one triangle. When I save my shadercode, unity gets inactive and I can see in the task manager that the shader compiler has 30% cpu -> is compiling. But this takes forever, and when I restart unity, it isn't able to load the shader from the assets. I found out that this doesn't happen when I comment the line:
const int TRI_STRIP[TAM] = tmpTriStrip;
Obviously I then get an error that TRI_STRIP is undefined, but the shadercompiler did its work and Unity is still running. Then I put the line back into the code and the above desribed behaviour appears. Thanks for any tipps and advices.
Here is the complete geometryshader code:
void myGeometryShader(point gIn vert[1], inout TriangleStream<v2f> triStream)
{
float f = _PointSize / 20.0f * sin(_Time * _Speed); //half size
float4 vctmp[TAM];
int i;
float y;
for (i = 0; i < TAM; i += 3) {
y = sin(_Time * _Speed + _SinValue) * _MovHeight + _HeightOffset;
vctmp[i] = float4(0.0f, 0.0f, 0.0f, 0.0f);
vctmp[i + 1] = float4(_Distance, y, i / _MarginFactor - _EndWidth / 2.0f, 0.0f);
vctmp[i + 2] = float4(_Distance, y, i / _MarginFactor + _EndWidth / 2.0f, 0.0f);
}
const float4 vc[TAM] = vctmp;
float2 UV1tmp[TAM];
for (i = 0; i < TAM; i += 3) {
UV1tmp[i] = float2(0.0f, 0.0f);
UV1tmp[i + 1] = float2(1.0f, 0.0f);
UV1tmp[i + 2] = float2(1.0f, 1.0f);
}
const float2 UV1[TAM] = UV1tmp;
int tmpTriStrip[TAM];
for (i = 0; i < TAM; i++) {
tmpTriStrip[i] = 1;
}
const int TRI_STRIP[TAM] = tmpTriStrip;
v2f v[TAM];
// Assign new vertices positions
for (i = 0; i < TAM; i++) { v[i].pos = vert[0].pos + vc[i]; v[i].col = vert[0].col; }
// Assign UV values
for (i = 0; i < TAM; i++) v[i].uv_MainTex = TRANSFORM_TEX(UV1[i],_MainTex);
// Position in view space
for (i = 0; i < TAM; i++) { v[i].pos = mul(UNITY_MATRIX_MVP, v[i].pos); }
// Build the cube tile by submitting triangle strip vertices
for (i = 0; i < TAM / 3; i++)
{
triStream.Append(v[TRI_STRIP[i * 3 + 0]]);
triStream.Append(v[TRI_STRIP[i * 3 + 1]]);
triStream.Append(v[TRI_STRIP[i * 3 + 2]]);
triStream.RestartStrip();
}
}