티스토리 뷰

아래는 ShaderED에서 사용하기 위한 함수
float2 random2(float2 p)
{
return frac(sin(float2(dot(p, float2(127.1f, 311.7f)), dot(p, float2(269.5f, 183.3f))))*43758.5453f);
}
float3 voronoiNoise(float2 uv, float scale, float2 resolution, float animateOffset)
{
float3 color;
float2 st = uv * (resolution.x/resolution.y) * scale;
float2 i_st = floor(st);
float2 f_st = frac(st);
float m_dist = 1;
for (int y=-1;y<=1;y++)
{
for(int x=-1;x<=1;x++)
{
float2 neighbor = float2(float(x),float(y));
// random position from current + neighbor
float2 p = random2(i_st + neighbor);
// animate point
p = .5f + .5f * sin(animateOffset + 6.2381f * p);
// vector between pixel and the pixel
float2 diff = neighbor + p - f_st;
float dist = length(diff);
m_dist = min(m_dist, dist);
}
}
// draw the min distance
color += m_dist;
// draw cell center
return color;
}
아래는 언리얼엔진에서 사용하기 위해 묶어놓은 코드다.
struct AnimateVoronoi
{
float2 random2(float2 p)
{
return frac(sin(float2(dot(p, float2(127.1f, 311.7f)), dot(p, float2(269.5f, 183.3f))))*43758.5453f);
}
float3 voronoiNoise(float2 uv, float scale, float2 resolution, float animateOffset)
{
float3 color = float3(0,0,0);
float2 st = uv * (resolution.x/resolution.y) * scale;
float2 i_st = floor(st);
float2 f_st = frac(st);
float m_dist = 1;
for (int y=-1;y<=1;y++)
{
for(int x=-1;x<=1;x++)
{
float2 neighbor = float2(float(x),float(y));
// random position from current + neighbor
float2 p = random2(i_st + neighbor);
// animate point
p = .5f + .5f * sin(animateOffset + 6.2381f * p);
// vector between pixel and the pixel
float2 diff = neighbor + p - f_st;
float dist = length(diff);
m_dist = min(m_dist, dist);
}
}
// draw the min distance
color += m_dist;
// draw cell center
return color;
}
};
AnimateVoronoi voronoi;
return voronoi.voronoiNoise(uv, scale, resolution, animateOffset);
원본 출처 : https://thebookofshaders.com/12/
'개발 > Shader' 카테고리의 다른 글
| [HLSL] Edge Detection - Sobel (0) | 2021.09.16 |
|---|---|
| [HLSL] Simple Texture Normal (0) | 2021.09.16 |
| [Color Blending] 컬러 블랜딩 공식 (0) | 2021.06.22 |
| [Unity/URP] Built-in Shader 작업물을 URP로 포팅하기 위한 도큐먼트 (0) | 2021.06.13 |
| [Unity/URP] URP에서 Built-in Function이나 Variable에 접근하기 (0) | 2021.06.13 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- #Shader #셰이더 #Tessellator #눈발자국 #발자국
- shader
- unity
- 이미지 효과
- ImageEffect
- 컴퓨터네트워크
- 네트워크
- 소공
- Substance Designer
- 법선
- 컴네
- normal
- Noise
- 이종식
- Unreal
- designer
- HLSL
- 이미지이펙트
- 블러효과
- 정리
- 컴퓨터구조론
- 소프트웨어공학
- 노영태
- 모션블러
- MotionBlur
- 유니티 셰이더
- 인하대
- Substance
- 유니티
- ue4
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
글 보관함