openGL es2.0 粒子系统方式之球体爆炸
一、Java代码:
package com.gzdxid.particles;
import java.nio.FloatBuffer;
import com.gzdxid.utils.BufferUtil;
import com.gzdxid.utils.MatrixState;
import android.opengl.GLES20;
public class GrainShooter { int mProgram;
int muMVPMatrixHandle;
int uPointSizeHandle;
int uColorHandle;
int uTimeHandle;
int maVelocityHandle;
private FloatBuffer mVelocityBuffer;
private int vCount;
private float pointSize;
private float timeLive = 0;
private long timeStamp = 0;
public GrainShooter(float pointSize, int pointCount, int mProgram) {
// TODO Auto-generated constructor stub
this.vCount = pointCount;
this.pointSize = pointSize;
initVertex();
initShader(mProgram);
} private void initVertex() {
float []velocity=new float[vCount*3];
for(int i=0;
i=5){
timeLive+=0.02f;
timeStamp=currTimeStamp;
}
GLES20.glUseProgram(mProgram);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);
GLES20.glUniform1f(uPointSizeHandle, pointSize);
GLES20.glUniform1f(uTimeHandle, timeLive);
GLES20.glUniform3fv(uColorHandle, 1, new float[]{1,0,0}, 0);
GLES20.glVertexAttribPointer(maVelocityHandle, 3, GLES20.GL_FLOAT, false, 3*4, mVelocityBuffer);
GLES20.glEnableVertexAttribArray(maVelocityHandle);
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, vCount);
}
}
二、定点着色器:
uniform mat4 uMVPMatrix;
uniform float uPointSize;
uniform float uTime;
attribute vec3 aVelocity;
void main()
{
float currTime=mod(uTime,5);
float px=aVelocity.x*currTime;
float py=aVelocity.y*currTime-0.5*1.0*currTime*currTime;
float pz=aVelocity.z*currTime;
gl_Position=uMVPMatrix*vec4(px,py,pz,1);
gl_PointSize=uPointSize;
}
三、片源着色器: 【openGL es2.0 粒子系统方式之球体爆炸】
precision mediump float;
uniform vec3 uColor;
void main()
{
gl_FragColor=vec4(uColor,1.0);
}
推荐阅读
- 一粒饥饿不堪的米
- 了解自然大气粒子对气候的影响
- Cesium|Cesium 粒子系统学习
- 2.关于OpenGL|2.关于OpenGL 坐标系以及渲染流程
- 一粒米的夙愿
- OpenGL|OpenGL ES之LUT(滤镜基准图)
- OpenGL|OpenGL 绘制甜甜圈深度测试、多边形偏移、裁剪、 混合
- FFmpeg|FFmpeg 开发(07)(FFmpeg + OpenGLES 实现 3D 全景播放器)
- 《播一粒种子在春天》后感
- open基础笔记