2 minutes reading time
(306 words)
star.vfl
/* Name : star.vfl
* Modifed By : 정현준
* Shader 소개 : 별모양 패턴 shader 입니다.
*/
#include <math.h>
#pragma label starNum NumberStarPoints
#pragma label transX TransformU
#pragma label transY TransformV
#pragma label min InnterSize
#pragma label max OuterSize
#pragma label rotAngle RotateStar
#pragma label RepeatS RepeatU
#pragma label RepeatT RepeatV
#pragma label bgColor BackGroundColor
#pragma label starColor StarColor
#pragma hint bgColor color
#pragma hint starColor color
surface hjcStar(
int starNum = 5; // star 꼭지점 갯수
float transX = 0.5, // star U(s) 위치
transY = 0.5, // star (v) 위치
min = 0.145, // star의 안쪽부분 시작점
max = 0.341, // star의 바깥부분 시작점
rotAngle = 37.0, // star 회전
RepeatS = 0.2, // star U(s) 패턴반복
RepeatT = 0.2; // star U(t) 패턴반복
vector bgColor = {0, 0, 0.5}, // background 색상
starColor = {1, 1, 1}; // star 색상
)
{
float ss, tt, xPos = P.x, yPos = P.y;
float angle, rad, tempAngle, bias, starAngle;
vector tempP1, tempP2, resVec1, resVec2, crossTemp;
starAngle = 2 * PI / starNum; // 2*PI = 360 / 꼭지점 갯수 -> 별 shape
tempP1 = {1, 0, 0};
tempP2 = set( cos(starAngle / 2), sin( starAngle / 2),0);
tempP1 *= max;
tempP2 *= min;
resVec1 = tempP2 - tempP1;
ss = (xPos * RepeatS)%1 - transX;
tt = (yPos * RepeatT)%1 - transY;
angle = atan2(ss, tt) + PI/180 * (-rotAngle);
rad = sqrt(pow(ss, 2) + pow(tt, 2));
tempAngle = angle% starAngle/starAngle;
if (tempAngle >= 0.5)
{
tempAngle = 1 - tempAngle ;
}
resVec2 = set(cos(tempAngle), sin(tempAngle), 0);
resVec2 *= rad;
resVec2 -= tempP1;
crossTemp = cross(resVec1, resVec2);
if(crossTemp.z < 0)
{
bias = 0.0;
}
else
{
bias = 1.0;
}
Cf = lerp(bgColor, starColor, bias);
}
Comments 2
와 대단하십니다. 별 소스는 직접 만드신거예요?? 저는 책에서 보고 만들어봤었습니다. ㅎㅎ
감사합니다 ㅎㅎ