I’m rendering points (not triangles or quads) and would like to use texture coordinates automatically generated by the hardware after the vertex shader. In OpenGL/GLSL one would simply use the build-in fragment shader input gl_PointCoord. What is the Unity/Cg equivalent of that?
(Note: There is already a discussion in the Scripting forum about this topic, but I think it is more likely to get an answer in the Shaders forum
)
Point rendering seems to be badly documented, so for anyone interested:
Set your Mesh to MeshTopology.Points mode using the SetIndices method. Then use a shader like this which writes the point size:
Shader "Custom/Starfield" {
Properties {
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
CGPROGRAM
#pragma exclude_renderers flash
#pragma vertex vert
#pragma fragment frag
struct appdata {
float4 pos : POSITION;
};
struct v2f {
float4 pos : SV_POSITION;
float size : PSIZE;
};
v2f vert(appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.pos);
o.size = 10.0;
return o;
}
half4 frag(v2f i) : COLOR
{
return half4(1,0,0,1);
}
ENDCG
}
}
}