Point Sprite automatic texture coords

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 :wink: )

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
		}
	} 
}

I’ve been looking into this outside of Unity. In OpenGL and Cg, I’m doing this:

            glEnable(GL_POINT_SPRITE_ARB);
            glEnable(GL_PROGRAM_POINT_SIZE_EXT);
            CgGL.SetStateMatrixParameter(mParticleModelViewProj, cgGLModelviewProjectionMatrix, cgGLMatrixIdentity);
            mParticleShader.Activate();
            cgGLSetTextureParameter(mParticleTexture, TextureId);
            cgGLEnableTextureParameter(mParticleTexture);
            glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            mParticleFragShader.Activate();
            mParticles.Render(true);

(I have shader classes etc that handle some things but the gl and cggl calls are what’s important here)

vertex shader

struct output{
	float4 position : POSITION;
	float4 color : COLOR;
	float  size      : PSIZE;
};
struct input {
	float4 position: POSITION;
	float4 color : COLOR;
};


output main(input IN, uniform float4x4 ModelViewProj)
{
	
	output OUT;

	OUT.position = mul(ModelViewProj, IN.position);
	OUT.size = 500.0f / OUT.position.w;
	OUT.color = IN.color;

	return OUT;
}

fragment shader

struct output
{
	float4 color : COLOR;
};

struct input
{
	float4 color : COLOR;
	float2 texCoord : TEXCOORD0;
};

output main(input IN, uniform sampler2D tex)
{

  output OUT;

  OUT.color = IN.color * tex2D(tex, IN.texCoord.xy);

  return OUT;

}

Hope that helps.

Thanks for your effort, but as I would like to do this inside Unity it’s not helping :expressionless: