Skip to content

Commit 353f98b

Browse files
[p01] Adds wind to the shader
1 parent ccb2d04 commit 353f98b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

project01/shader/cloth_cs.glsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ uniform float RestLengthVert;
1111
uniform float RestLengthDiag;
1212
uniform float DeltaT = 0.000005;
1313
uniform float DampingConst = 0.1;
14+
uniform bool HasWind = true;
15+
uniform float WindStrength = 2;
16+
uniform vec3 WindDir = vec3(4, 0, 2);
1417

1518
layout(std430, binding=0) buffer PosIn {
1619
vec4 PositionIn[];
@@ -24,6 +27,9 @@ layout(std430, binding=2) buffer VelIn {
2427
layout(std430, binding=3) buffer VelOut {
2528
vec4 VelocityOut[];
2629
};
30+
layout(std430, binding=4) buffer NormIn {
31+
vec4 Normal[];
32+
};
2733

2834
void main() {
2935
uvec3 nParticles = gl_NumWorkGroups * gl_WorkGroupSize;
@@ -81,6 +87,18 @@ void main() {
8187

8288
force += -DampingConst * v;
8389

90+
if (HasWind)
91+
{
92+
vec3 normalized_wind_dir;
93+
if (WindDir == vec3(0.0f, 0.0f, 0.0f))
94+
normalized_wind_dir = glm::vec3(0.0f, 0.0f, 0.0f);
95+
else
96+
normalized_wind_dir = normalize(WindDir);
97+
98+
vec3 f_wind = WindStrength * dot(Normal[idx].xyz, normalized_wind_dir) * Normal[idx].xyz;
99+
force += f_wind;
100+
}
101+
84102
// Apply simple Euler integrator
85103
vec3 a = force * ParticleInvMass;
86104
PositionOut[idx] = vec4(

0 commit comments

Comments
 (0)