UE5 -HLSL- 깃발 펄럭펄럭

 애니메이션에 사용할 버텍스 컬러를 적절히 칠해준다.




그리고 살랑 살랑 움직이게 만들어 준다.




뭔가 아쉬우니,파동을 여러개 만들어 섞어 준다.

float Wave1 = sin(Position.x + NewTime * Speed)*Strength *0.1;

float Wave2 = cos(Position.y + NewTime * Speed)*Strength*0.05;

float Wave3 = sin(Position.z + NewTime * Speed)*Strength*0.01;

float combinedWave =(Wave1 + Wave2 * Wave3) *Strength* mask;


방향별 파동을 만들고 강도를 적당히 봐가며 설정 해 주고 합쳐준다.


마지막으로 바람의 세기를 표현 해 보자.

바람이 불때 흔들리다 바람이 멎으면 서서히 멈추고 다시 바람이 불면 움직이게 만들어 보자.



float cycleIndex = floor(Time / 30);

float randomValue = frac(sin(cycleIndex * 12.345) * 67654.3212);

float threshold = lerp(1.0, 13.0, randomValue); 

float WindAmplitude = (NewTime < threshold)?(1.0 - saturate(NewTime / threshold)) 

    : saturate((NewTime - threshold) / (30 - threshold));


NewTime이 threshold 보다 작으면 연산자의 참값1.0 - saturate(NewTime / threshold) 반환 한다. 이 값은 0에서 1사이의 값을 가진다.  해당값을 1에서 빼면 1에서 0으로 내려가는 값을 가진다. 움직임이 서서히 멈춘다.

saturate((NewTime - threshold) / (30 - threshold)); newtime이 threshold 보다 큰 값일때(최대 30) 0에서 1까지 증가 하는 값이 나온다.

마지막으로 WindAmplitude 값을 리턴값에 곱해준다.






댓글