|
フラグメントシェーダー 星
星型を定義しています。
DIM ST(2),C(3)
ASK BITMAP SIZE XSIZE,YSIZE
SET COLOR MODE "NATIVE"
SET POINT STYLE 1
SET WINDOW -XSIZE/MIN(XSIZE,YSIZE),XSIZE/MIN(XSIZE,YSIZE),-YSIZE/MIN(XSIZE,YSIZE),YSIZE/MIN(XSIZE,YSIZE)
FOR YY=0 TO YSIZE-1
FOR XX=0 TO XSIZE-1
LET X=(XX*2-XSIZE)/MIN(XSIZE,YSIZE)
LET Y=(YY*2-YSIZE)/MIN(XSIZE,YSIZE)
CALL VEC2(ST,X,Y)
IF DISTANCE(ST)>0 THEN
CALL VEC3(C,0,0,0)
ELSE
CALL VEC3(C,1,0,0)
END IF
CALL SETCOLOR(C(1),C(2),C(3))
PLOT POINTS:X,Y
NEXT XX
NEXT YY
END
EXTERNAL FUNCTION STAR5(P(),R,RF) !距離関数 星型
DIM K1(2),K2(2),BA(2),P1(2),PP(2)
CALL VEC2(K1,.809016994375,-.587785252292)
CALL VEC2(K2,-K1(1),K1(2))
LET P(1)=ABS(P(1))
MAT PP=P
FOR I=1 TO 2
LET P(I)=P(I)-2*MAX(DOT(K1,PP),0)*K1(I)
NEXT I
MAT PP=P
FOR I=1 TO 2
LET P(I)=P(I)-2*MAX(DOT(K2,PP),0)*K2(I)
NEXT I
LET P(1)=ABS(P(1))
LET P(2)=P(2)-R
CALL VEC2(K2,-K1(2),K1(1))
MAT BA=RF*K2
CALL VEC2(K2,0,1)
MAT BA=BA-K2
LET H=CLAMP(DOT(P,BA)/DOT(BA,BA),0,R)
MAT P1=H*BA
MAT P1=P-P1
LET STAR5=LENGTH(P1)*SIGN(P(2)*BA(1)-P(1)*BA(2))
END FUNCTION
EXTERNAL FUNCTION DISTANCE(P())
LET DISTANCE=STAR5(P,.5,.381966011250105)
END FUNCTION
EXTERNAL SUB SETCOLOR(R,G,B)
SET COLOR COLORINDEX(CLAMP(R,0,1),CLAMP(G,0,1),CLAMP(B,0,1))
END SUB
EXTERNAL SUB VEC2(A(),X,Y)
LET A(1)=X
LET A(2)=Y
END SUB
EXTERNAL SUB VEC3(A(),X,Y,Z)
LET A(1)=X
LET A(2)=Y
LET A(3)=Z
END SUB
EXTERNAL FUNCTION CLAMP(X,A,B)
LET CLAMP=MIN(B,MAX(X,A))
END FUNCTION
EXTERNAL FUNCTION LENGTH(A())
LET LENGTH=SQR(A(1)^2+A(2)^2)
END FUNCTION
EXTERNAL FUNCTION SIGN(X)
IF X<0 THEN
LET SIGN=-1
ELSEIF X>0 THEN
LET SIGN=1
ELSE
LET SIGN=0
END IF
END FUNCTION
|
|