(McNopper / OpenGL 阅读笔记)1 GPU 粒子系统

主要思想是,创建GL_RGBA32F 纹理两个,用来储存粒子的位置;通过乒乓方法更新纹理的内容。

优点: 比cpu 计算更快;

缺点:对硬件有要求,需要OpenGL3.2点两个特征: 浮点纹理和顶点着色器纹理采用。 

主要代码如下:

 

顶点着色器

#version 150

uniform sampler2D u_positionTexture;

uniform float u_positionTextureWidth;

uniform float u_time;

in vec2 a_vertex;

out vec4 v_particle;

// Pseudo random function
float rand(vec2 seed)
{
	return fract(sin(dot(seed.xy, vec2(12.9898, 78.233))) * 43758.5453);
}

void main(void)
{
	float position_speed = 0.2*u_time;
	float lifetime_speed = 0.04*u_time;

	// Get particle data from last texture
	v_particle = texture(u_positionTexture, a_vertex);

	// Each particle has the same translation vector. Pseudo random function is used to randomly distribute the particles over the screen
	v_particle.x += (rand(a_vertex*123.456)*2.0-1.0)*position_speed;
	v_particle.y += (rand(a_vertex*234.567)*2.0-1.0)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值