wind shader

程序化纸张飞行着色器

 
 
 

通过风相互作用、轨道旋转和动态颤振模拟逼真的纸质物理学。非常适合在 3D 场景中制作神奇效果、记录动画或环境故事。

核心功能

  • 风模拟

     
     

    使用基于纹理的顶点置换生成自然的纸张颤动

     

  • 轨道运动

     
     

    使对象围绕可自定义的中心点旋转

     

  • 动态旋转

     
     

    在自然纸张方向和面向目标的方向之间混合

     

  • 材料体系

     
     

    支持 PBR 纹理(反照率、粗糙度、法线贴图)

     

主要特点

  • 🌀 可调节的风速和风向

  • ⭕ 可定制的圆形飞行路径

  • 🎚️ 风/方向混合控制

  • 📜 逼真的纸张般的运动

  • ✅ 风效果的开/关切换

  • 🖼️ 视觉细节的纹理支持

适合:

 

  • 神奇的文档动画

  • 环保碎纸

  • 法术效果视觉对象

  • 讲故事的场景元素

  • 通过 GDScript,您可以访问着色器的参数以创建大量特殊效果和动画。这些可以引导玩家、增强角色能力,或者简单地模拟风的物理特性——就像角色走过时纸张爆炸一样。存在多种可能性。
Shader code
shader_type spatial;
render_mode cull_disabled;
uniform sampler2D normalmap_tex:repeat_enable,filter_linear;
uniform sampler2D  albedo_tex:repeat_enable,filter_linear;
uniform sampler2D  rough_tex:repeat_enable,filter_linear;
uniform vec2 dir_2;
uniform float speed2:hint_range(0.0, 2.0)=0.1;
uniform sampler2D normalmap_tex_2:repeat_enable,filter_linear;
uniform vec3 center;
uniform float radius;
uniform float rotation_speed;
uniform vec3 axis;
uniform float wind_up:hint_range(0.0, 1.0, 0.1)=0.5;
uniform float wind_target:hint_range(-1.0, 1.0, 1.0)=-1.0;
uniform bool Wind=false;

void vertex() {
	if (Wind){
	float wind_seed=0.0;
	vec2 new_uv=vec2(UV.y,UV.x);
	vec4 normal_color2 = texture(normalmap_tex_2,new_uv*0.5+TIME*dir_2*speed2);
	VERTEX.y+=normal_color2.r*0.2;
		 // 2. 计算模型在轨道上的位置(绕轴旋转)
    float angle = TIME * rotation_speed;
    vec3 orbit_pos = center + radius * vec3(
        sin(angle),  // X 坐标(绕Y轴旋转)
        0.0,         // Y 坐标(保持不变)
        cos(angle)   // Z 坐标
    );

    // 3. 计算指向中心的方向(新Z轴)
    vec3 new_z = normalize(mix(wind_target*MODEL_MATRIX[1].xyz,center - orbit_pos,wind_up));

    // 4. 构建正交坐标系(根据旋转轴调整基准方向)
    vec3 up = axis; // 使用旋转轴作为基准上方向
    vec3 new_x = normalize(cross(up, new_z));
    vec3 new_y = normalize(cross(new_z, new_x));

    // 5. 构造变换矩阵(旋转 + 位置)
    mat4 transform = mat4(
        vec4(new_x, 0.0),
        vec4(new_y, 0.0),
        vec4(new_z, 0.0),
        vec4(orbit_pos, 1.0)
    );

    // 6. 应用变换
    MODELVIEW_MATRIX = VIEW_MATRIX * transform;
    POSITION = PROJECTION_MATRIX * MODELVIEW_MATRIX * vec4(VERTEX, 1.0);
	}

}
void fragment(){
	ALBEDO=texture(albedo_tex,UV).rgb;
	ROUGHNESS=texture(rough_tex,UV).r;
	NORMAL_MAP=texture(normalmap_tex,UV).rgb;
}
Tags
3D Animation, Environmental FX, Stylized Effects, Vertex Physics, wind
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from baoding

FIsheye Shader

Related shaders

3D wind sway shader with wind mask texture controll

vertex paint controlled simple 3D wind sway shader

Tilemap Wind shader

guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
tomaaron
tomaaron
1 month ago

hey! thanks for the shader. do you mind sharing an example? I’m having troubles setting it up.