如何在GLSL或类似系统中创建雨水?

如何在GLSL或类似系统中创建雨水?,glsl,webgl,hlsl,Glsl,Webgl,Hlsl,有没有关于如何在GLSL或类似着色器中创建雨水的优秀教程?我可以很容易地为玛雅找到一个,但不幸的是,不是这个。谢谢 你说的“雨”是什么意思。有很多方法来表示雨 此示例具有雨效应和涟漪效应 不过没有教程。它的工作原理是创建一组单位正方形,给每个正方形一个随机值,将该随机值添加到时间值中,然后计算着色器中的位置,如中所示 uniform float u_time; // a time value passed in by JavaScript uniform mat4 u_vie

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

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

此示例具有雨效应和涟漪效应

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

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;
对不起,太简单了。

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

此示例具有雨效应和涟漪效应

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

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;

抱歉,这太简单了。

这些Maya教程是什么?我真的怀疑这和着色器有什么关系,而是关于粒子效果。是的,我相信这更多的是关于粒子效果,我想只是在应用程序中使用类似雨的外观。这些Maya教程是什么?我真的怀疑这和着色器有什么关系,而是关于粒子效果。是的,我相信这更多的是关于粒子效果,我想只是在应用中有一个像雨一样的外观。哇,这太棒了,gman!!非常感谢!这是你自己创建的吗?哦,对不起,传入的随机值在哪里?或者我只是忽略了一些明显的东西?在链接到的演示中,是的,有几个半随机值作为每个粒子的其他属性传入。它们是在初始化时选择的,因此每个粒子效果都在一次又一次地播放相同的粒子“循环”,但效果看起来不错。如果你需要在一个世界上放置多个相同效果的物体,而你又不想让它们看起来都是同步的,那么最简单的方法就是(a)给每个物体一个单独的时钟,(b)给每个物体一个随机旋转哇,这太棒了,gman!!非常感谢!这是你自己创建的吗?哦,对不起,传入的随机值在哪里?或者我只是忽略了一些明显的东西?在链接到的演示中,是的,有几个半随机值作为每个粒子的其他属性传入。它们是在初始化时选择的,因此每个粒子效果都在一次又一次地播放相同的粒子“循环”,但效果看起来不错。如果你需要在一个世界上放置相同效果的倍数,而你又不想让它们看起来都是同步的,那么最简单的方法就是(a)给每一个单独的时钟,(b)给每一个随机旋转