I am working on a geometry shader that draws quads based on a supplied set of points. This is working on Windows, but as soon as I change my build target to Android it stops working (Both in Editor and on device).
Everything I am reading is telling me that if my android device supports OpenGL ES3.1 + Android Expansion Pack that it should work.
Any ideas on what I am doing wrong?
Here is my Shader:
Shader "PORT/PointCloudGeometry"
{
Properties
{
_Sprite ("Sprite", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
_Size("Size", Vector) = (1,1,0,0)
}
SubShader
{
Tags { "Queue" = "Overlay+100" "RenderType"="Transparent" }
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
Cull off
Zwrite off
Pass
{
CGPROGRAM
//Pragmas
#pragma target 50
#pragma vertex vert
#pragma geometry geom
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
//User defined variables
uniform sampler2D _Sprite;
uniform float4 _Color;
uniform float2 _Size;
uniform float3 _worldPos;
int _StaticCylinderSpherical = 0;
struct data{
float3 pos;
};
StructuredBuffer<data> buf_Points;
//Base input structs
struct vertexOutput{
float4 pos: SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
};
//Vertex function
vertexOutput vert(uint id: SV_VertexID){
vertexOutput o;
o.pos = float4(buf_Points[id].pos + _worldPos, 1.0f);
return o;
}
//Geometry function
[maxvertexcount(4)]
void geom(point vertexOutput p[1], inout TriangleStream<vertexOutput> triStream){
float2 halfS = _Size;
float4 v[4];
//if(_StaticCylinderSpherical == 0){
v[0] = p[0].pos.xyzw + float4(-halfS.x, -halfS.y,0,0);
v[1] = p[0].pos.xyzw + float4(-halfS.x, halfS.y,0,0);
v[2] = p[0].pos.xyzw + float4(halfS.x, -halfS.y,0,0);
v[3] = p[0].pos.xyzw + float4(halfS.x, halfS.y,0,0);
//}
vertexOutput pIn;
pIn.pos = mul(UNITY_MATRIX_VP, v[0]);
pIn.uv = float2(0.0f,0.0f);
UNITY_TRANSFER_FOG(pIn, pIn.pos);
triStream.Append(pIn);
pIn.pos = mul(UNITY_MATRIX_VP, v[1]);
pIn.uv = float2(0.0f,1.0f);
UNITY_TRANSFER_FOG(pIn, pIn.pos);
triStream.Append(pIn);
pIn.pos = mul(UNITY_MATRIX_VP, v[2]);
pIn.uv = float2(1.0f,0.0f);
UNITY_TRANSFER_FOG(pIn, pIn.pos);
triStream.Append(pIn);
pIn.pos = mul(UNITY_MATRIX_VP, v[3]);
pIn.uv = float2(1.0f,1.0f);
UNITY_TRANSFER_FOG(pIn, pIn.pos);
triStream.Append(pIn);
}
//fragment function
float4 frag(vertexOutput i) : COLOR {
fixed4 col = tex2D(_Sprite, i.uv) * _Color;
UNITY_APPLY_FOG(i.fogCoord, col); // Apply Fog
return col;
}
ENDCG
}
}
}
Here is where I am setting the Shaders values:
using UnityEngine;
using System.Collections;
public class PORT_PointCloud_Geometry : PORT_PointCloud {
public Shader geomShader;
Material mat;
public Texture2D sprite;
public Vector2 size = Vector2.one;
public Color color = new Color(.75f,.5f,0,1);
private ComputeBuffer outputBuffer;
private PointData[] points;
struct PointData{
public Vector3 pos;
};
void Start(){
mat = new Material (geomShader);
points = new PointData[] {new PointData (){ pos = Vector3.zero }};
outputBuffer = new ComputeBuffer (points.Length, 12);
outputBuffer.SetData (points);
}
void OnRenderObject(){
mat.SetPass (0);
mat.SetColor ("_Color", color);
mat.SetBuffer ("buf_points", outputBuffer);
mat.SetTexture ("_Sprite", sprite);
mat.SetVector ("_Size", size);
mat.SetVector ("_worldPos", transform.position);
Graphics.DrawProcedural (MeshTopology.Points, outputBuffer.count);
}
void OnDestroy(){
outputBuffer.Release ();
}
}