点精灵 几种形状的Shader脚本

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值