I am browsing Unity3D forum and I can see only geometry shader examples in Cg (HLSL).
So, I have written GLSL minimal version. Later I will include GLSL hull and domain shaders for tessellation.
Enable OpenGL in Unity3D → set -force-glcore parameter to editor executable, for instance: “C:\Program Files\Unity\Editor\Unity.exe” -force-glcore
Source:
//reference: http://www.geeks3d.com/20111111/simple-introduction-to-geometry-shaders-glsl-opengl-tutorial-part1/
//Minimal exercise. You should see blue color.
//Pass-through geometry shader sends the input primitives (a triangle) to the rasterizer without transformation.
Shader "Geometry Shader #01"
{
SubShader
{
Pass
{
GLSLPROGRAM
#ifdef VERTEX
void main()
{
gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
}
#endif
#ifdef GEOMETRY
layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;
void main()
{
for(int i=0; i<3; i++)
{
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}
#endif
#ifdef FRAGMENT
out vec4 color;
void main()
{
color = vec4(0.0, 0.0, 1.0, 1.0);
}
#endif
ENDGLSL
}
}
}
Given that Metal does not support geometry shaders, and that geometry shaders should almost never be used because they are unbelievably slow, no, not really…
Now I am trying to make basic tessellation in GLSL. No errors, but shader looks bad.
I discovered that Unity3D GLSL shaders work properly with gl_Vertex but with tessellation I have to set minimum version 400. In this option, gl_Vertex is deprecated. Also trick with layout (location = 0) doesn’t work.