Hi everyone
Based on the post http://forum.unity3d.com/threads/158891-Unity4-point-sprite-texture-coordinates.
I just started with shader programming and I’m trying to create a small particle system using cg. I want to use this to place the particles randomly.
Now I’m dealing with the same question as in the post above. The problem seems to be that every point gets just one color. What it does is to look on the texture with the coords of the point. When I create a mesh like in the post with the double size of the texture ( 64x64 = 128 ) i get something like that:

My Shader
Shader "Custom/SamplePointShader" {
Properties {
_MainTex ("Texture Image", 2D) = "" {}
_SpriteSize("SpriteSize", Float) = 10
}
SubShader {
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
fixed4 _TintColor;
float _SpriteSize;
struct vertexInput {
float4 pos : POSITION;
fixed4 col : COLOR;
float2 UV : TEXCOORD0;
};
struct fragmentInput {
float4 pos : SV_POSITION;
float size : PSIZE;
fixed4 col : COLOR;
float2 UV: TEXCOORD0;
};
fragmentInput vert(vertexInput input) {
fragmentInput output = (fragmentInput)0;
output.pos = mul(UNITY_MATRIX_MVP, input.pos);
output.col = input.col;
output.size = _SpriteSize;
output.UV = input.UV;
return output;
}
float4 frag(fragmentInput input) : COLOR
{
return tex2D(_MainTex, float2(input.UV.x / _SpriteSize,input.UV.y / _SpriteSize));
}
ENDCG
}
}
}
How is it possible to show the whole texture on one point? Is it possible?
I also tried to create particles based on the billboard technique (http://en.wikibooks.org/wiki/Cg_Programming/Unity/Billboards).
It really looks like a nice particle:
My Billboard Shader
Shader "Custom/SampleBillboard" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Texture Image", 2D) = "" {}
_SpriteSize("SpriteSize", Float) = 10
}
SubShader {
Pass{
Cull Off
Lighting Off
ZWrite Off
Blend SrcAlpha One
AlphaTest Greater .01
ColorMask RGB
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
fixed4 _TintColor;
float _SpriteSize;
struct vertexInput {
float4 pos : POSITION;
fixed4 col : COLOR;
float2 UV : TEXCOORD0;
};
struct fragmentInput {
float4 pos : SV_POSITION;
fixed4 col : COLOR;
float2 UV: TEXCOORD1;
};
fragmentInput vert(vertexInput input) {
fragmentInput output = (fragmentInput)0;
output.pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1))+ float4(input.pos.x, input.pos.y, 0.0, 0.0));
output.col = input.col;
output.UV = input.UV;
return output;
}
float4 frag(fragmentInput input) : COLOR
{
return 2.0f * input.col * _TintColor * tex2D(_MainTex, float2(input.UV));
}
ENDCG
}
}
}
But now I got some basic problems. Objects that are behind the particle hides the particle.
Beyond this projection matrix problem when I would use the billboard solution I have to create for every particle an object and attach the shader to it. Is it achievable to create those in the shader?
Or am I totally wrong and do I have to use something like a geometry shader to achieve all this?
Sorry for the bunch of questions, and my bad english ;).

