首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在GLSL或类似版本中创建rain?

如何在GLSL或类似版本中创建rain?
EN

Stack Overflow用户
提问于 2012-06-18 15:29:33
回答 1查看 3.7K关注 0票数 0

有没有关于如何在GLSL或类似的着色器中创建rain的很好的教程?我可以很容易地为Maya找到一个,但不幸的是,不是这个。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-19 00:42:59

你说的“雨”是什么意思。表示雨的方式有很多种。

此样本具有雨效应和涟漪效应。

https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/demos/google/particles/index.html

不过没有教程。它的工作原理是创建一堆单位正方形,为每个正方形赋予一个随机值,将该随机值与时间值相加,并计算着色器中的位置,如下所示

代码语言:javascript
复制
uniform float u_time;          // a time value passed in by JavaScript
uniform mat4 u_view_inverse;   // view inverse (camera world matrix)
uniform mat4 u_view_projection;// view projection matrix

attribute vec4 a_vertex;       // the unit quad values
attribute vec4 a_position;     // the base position of this particle repeated for
                               // each vertex
attribute vec4 a_velocity;     // velocity for this quad, repeated for each vertex
attribute float a_time_offset; // a time offset for this particle 
                               // repeated for each vertex

// compute a position
float localTime = u_time + a_time_offset;
vec4 base_position = a_position + a_velocity * localTime;

// rotate quad so it's perpendicular to the view
vec4 quadX = viewInverse[0] * a_vertex.x;
vec4 quadZ = viewInverse[1] * a_vertex.y;

// compute the real world position for this vertex
vec4 position = base_position + quadX + quadZ;

// at this point position is the same as any other 'standard' 3d shader
// do with it whatever. Example:
gl_Position = viewProjectionMatrix * position;

抱歉,如果这太简短了。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11078539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档