0

有没有关于如何在 GLSL 或类似着色器中创建雨的很棒的教程?我可以很容易地为 Maya 找到那些,但遗憾的是,这不是。谢谢!

4

1 回答 1

3

“雨”是什么意思。有很多方式来表示雨

这个样本有下雨效果和涟漪效果

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

虽然没有教程。它的工作原理是创建一堆单位方块,给每个单位一个随机值,将该随机值添加到一个时间值,然后计算着色器中的一个位置,如下所示

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;

对不起,如果这太简洁了。

于 2012-06-18T16:42:59.447 回答