How do I use PSIZE in a Unity 4.5.4 shader?

I’m told that Unity overhauled the shader compile system in version 4.5. I am unable to get any examples of a shader that sets the size of vertices to work in Unity 4.5.

I am trying to build a point cloud editor that will allow me to scale the visible point size as the user scales a model. I have seen several posts claiming this approach works but they are all a couple years old…

Here is the shader I have been trying:

Shader "Custom/VertexColor" {
    SubShader {
    Pass {
    	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
        LOD 200
              
                 
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #include "UnityCG.cginc"
  
        struct VertexInput {
            float4 v : POSITION;
            float4 color: COLOR;
        };
         
        struct VertexOutput {
            float4 pos : SV_POSITION;
            float4 col : COLOR;
            float4 size : PSIZE;
        };
         
        VertexOutput vert(VertexInput v) {
         
            VertexOutput o;
            o.pos = mul(UNITY_MATRIX_MVP, v.v);
            o.col = v.color;
            o.size = 10.0;
            return o;
        }
         
        float4 frag(VertexOutput o) : COLOR {
            return o.col;
        }
 
        ENDCG
        } 
    }
 
}

The only way I’ve been able to get PSIZE to work is by forcing OpenGL. There may be a workaround for Direct3D but this might get you started.

First, run Unity with OpenGL like so:

"C:\Program Files (x86)\Unity\Editor\Unity.exe" -force-opengl

Attach the following script to your main camera. This enables point size in OpenGL. ([Source][1])

#if UNITY_STANDALONE
#define IMPORT_GLENABLE
#endif
 
using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;
 
public class EnablePointSize : MonoBehaviour 
{
    const UInt32 GL_VERTEX_PROGRAM_POINT_SIZE = 0x8642;
    const UInt32 GL_POINT_SMOOTH = 0x0B10;
     
    const string LibGLPath =
        #if UNITY_STANDALONE_WIN
        "opengl32.dll";
    #elif UNITY_STANDALONE_OSX
    "/System/Library/Frameworks/OpenGL.framework/OpenGL";
    #elif UNITY_STANDALONE_LINUX
    "libGL";  // Untested on Linux, this may not be correct
    #else
    null;   // OpenGL ES platforms don't require this feature
    #endif
     
    #if IMPORT_GLENABLE
    [DllImport(LibGLPath)]
    public static extern void glEnable(UInt32 cap);
     
    private bool mIsOpenGL;
     
    void Start()
    {
        mIsOpenGL = SystemInfo.graphicsDeviceVersion.Contains("OpenGL");
    }
     
    void OnPreRender()
    {
        if (mIsOpenGL)
            glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
            glEnable(GL_POINT_SMOOTH);
    }
    #endif
}

Attach the following script to a GameObject to create a point mesh. ([Source][2])

using UnityEngine;
using System.Collections;
 
 
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class PointCloud : MonoBehaviour {
 
    private Mesh mesh;
    int numPoints = 60000;
 
    // Use this for initialization
    void Start () {
        mesh = new Mesh();
 
        GetComponent<MeshFilter>().mesh = mesh;
        CreateMesh();
    }
 
    void CreateMesh() {
        Vector3[] points = new Vector3[numPoints];
        int[] indecies = new int[numPoints];
        Color[] colors = new Color[numPoints];
        for(int i=0;i<points.Length;++i) {
            points *= new Vector3(Random.Range(-10,10), Random.Range (-10,10), Random.Range (-10,10));*

indecies = i;
colors = new Color(Random.Range(0.0f,1.0f),Random.Range (0.0f,1.0f),Random.Range(0.0f,1.0f),1.0f);
}

mesh.vertices = points;
mesh.colors = colors;
mesh.SetIndices(indecies, MeshTopology.Points,0);

}
}
Attach your shader using PSIZE to that game object as a Material.
Now you should have a point cloud.
*[1]: http://answers.unity3d.com/questions/519670/shader-inconsistency-between-opengl-and-directx.html*_
*[2]: KaMend.com is for sale | HugeDomains