2021. 4. 17. 19:19
Unity/shader
#define _BoardSize 8.0
int2 GetPiecePos(float2 _pos)
{
return int2(min(_BoardSize-1, _pos.x * _BoardSize), min(_BoardSize-1, _pos.y * _BoardSize));
}
fixed2 GetUvPos(int2 _pos)
{
return fixed2((half)_pos.x / _BoardSize + (0.5 / _BoardSize), (half)_pos.y / _BoardSize + (0.5 / _BoardSize));
}
int2 piecePos = GetPiecePos(i.uv);
fixed2 uvPos = GetUvPos(piecePos);
col.r = uvPos.x * 0.1;
col.g = uvPos.y * 0.1;
col.a = 1;
return col;
결과
#define _BoardSize 8.0
int2 GetPiecePos(float2 _pos)
{
return int2(min(_BoardSize-1, _pos.x * _BoardSize), min(_BoardSize-1, _pos.y * _BoardSize));
}
int2 LenPos(int len, int angle)
{
int2 _pos = int2(0, 0);
switch (angle)
{
case 0:
_pos.x = len;
_pos.y = 0;
break;
case 45:
_pos.x = len;
_pos.y = len;
break;
case 90:
_pos.x = 0;
_pos.y = len;
break;
case 135:
_pos.x = -len;
_pos.y = len;
break;
case 180:
_pos.x = -len;
_pos.y = 0;
break;
case 225:
_pos.x = -len;
_pos.y = -len;
break;
case 270:
_pos.x = 0;
_pos.y = -len;
break;
case 315:
_pos.x = len;
_pos.y = -len;
break;
}
return _pos;
}
int2 piecePos = GetPiecePos(i.uv);
int angle = piecePos.y * 45;
col.r = 0.5+(float2)LenPos(piecePos.x, angle).x * 0.05;
col.g = 0.5 + (float2)LenPos(piecePos.x, angle).y * 0.05;
col.b = 0.5;
col.a = 1;
return col;
결과
아름다운 무지개가 나왔다
Hue가 어째서 360도의 각도를 지니는지 알수있는 부분
int2 LenPos(int len, int angle)
{
int2 _pos = int2(0, 0);
if (angle == 0)
{
_pos.x = len;
_pos.y = 0;
}
else if (angle == 45)
{
_pos.x = len;
_pos.y = len;
}
else if (angle == 90)
{
_pos.x = 0;
_pos.y = len;
}
else if (angle == 135)
{
_pos.x = -len;
_pos.y = len;
}
else if (angle == 180)
{
_pos.x = -len;
_pos.y = 0;
}
else if (angle == 225)
{
_pos.x = -len;
_pos.y = -len;
}
else if (angle == 270)
{
_pos.x = 0;
_pos.y = -len;
}
else if (angle == 315)
{
_pos.x = len;
_pos.y = -len;
}
return _pos;
}
if버전
'Unity > shader' 카테고리의 다른 글
유니티 쉐이더 기초 (0) | 2021.04.17 |
---|---|
모션블러 종류 (1) | 2021.03.02 |
유니티 쉐이더 인스펙터 (0) | 2021.02.21 |