有没有关于如何在GLSL或类似着色器中制造雨水的精彩教程?我可以很容易地为Maya找到那些,但不是这样,可悲的是。谢谢!
答案 0 :(得分: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;
很抱歉,如果那太简洁了。