void main(void)
{
vec2 temp = gl_PointCoord * 2.0 - vec2(1.0);
if(dot(temp,temp) > sin(atan(temp.y, temp.x) * 5.0))
discard;
gl_FragColor = oColor;
}
点 花型
void main(void)\
{\
vec2 temp = gl_PointCoord * 2.0 - vec2(1.0);\
float x = temp.x;\
float y = temp.y;\
float pt = x / y;\
float vt = y / x;\
if( pt < vt )\
discard;\
gl_FragColor = oColor;\
}";
void main(void0
{
vec2 temp = gl_PointCoord * 2.0 - vec2(1.0);
if (dot(temp, temp) > sin(atan(temp.y, temp.x) * 5.0))
{
discard;
}
}
点 风车型
precision mediump float;\
uniform vec4 oColor; \
void main(void)\
{\
vec2 temp = gl_PointCoord ;\
float x = temp.x;\
float y = gl_PointCoord.y;\
if( x < y || ( 1.0 - x) < y )\
discard;\
gl_FragColor = oColor;\
}";
点 三角
precision mediump float;\
uniform vec4 oColor; \
void main(void)\
{\
vec2 temp = gl_PointCoord * 2.0 - vec2(1.0) ;\
if( dot(temp,temp) > 1.0)
discard;\
gl_FragColor = oColor;\
}";
点 圆点
^ 形状箭头
attribute vec4 inVertex;
attribute vec4 inColor;
uniform mat4 uWorldMatrix;
uniform float uPointSize;
varying vec4 oColor;
varying mat2 rotation;
void main(void)
{
float cosa = cos(inColor.a);
float sina = sin(inColor.a);
vec4 pos = vec4(inVertex.xy,0.0,inVertex.w);
rotation = mat2(cosa,sina,-sina,cosa);
gl_Position = uWorldMatrix * pos;
gl_PointSize = uPointSize;
oColor = vec4(inColor.rgb,0.0);
}
precision mediump float;
varying vec4 oColor;
varying mat2 rotation;
void main(void)
{
vec2 p = gl_PointCoord- vec2(0.5);
p = rotation*p;
if(p.x+p.y*0.577 + 0.2887 < 0.0 || p.x - p.y*0.577 - 0.2887 > 0.0 || (p.x - p.y*1.732< 0.0 && p.x + p.y*1.732 > 0.0))
discard;
gl_FragColor = vec4(oColor.rgb,1.0);
}
------------------------------------------------------华丽分界线------------------------------------------------------
用点精灵实现BatchDraw (纹理并不是单张图,而是大纹理的一部分)
vert:
attribute vec4 inVertex;
attribute vec2 ratexy;//长宽对比大纹理比例
attribute vec2 texPos;//小纹理在大纹理中位置比例
uniform mat4 uWorldMatrix;
uniform mat4 uTextureMatrix;
uniform float uPointSize;
varying mat4 oTexMatrix; //仅用于相机旋转后,保持纹理图相对方位不变,若永远正面相机 可以不需要
varying vec2 oRatexy;
varying vec2 oTex;
void main(void)
{
gl_Position = uWorldMatrix * inVertex;
gl_PointSize = uPointSize;
oRatexy = ratexy;
oTex = texPos;
}
frag:
precision highp float;
uniform sampler2D uTextureCrood0;
varying vec2 oTex;
varying vec2 oRatexy;
varying mat4 oTexMatrix;
void main(void)
{
vec2 tex = (gl_PointCoord + oTex) * oRatexy; //计算小纹理在大纹理中的纹理坐标[0,1]之间
gl_FragColor = texture2D(uTextureCrood0 , oTexMatrix * vec4(tex , 0.0, 1.0).xy); //计算旋转 如果纹理永远正对相机,可以不需要texmatrix转换 直接用tex即可
}