|
フラグメントシェーダーによるプログラムです。
ネット上のサンプルを基にアンパンマン?を描画しています。
PUBLIC NUMERIC LIGHTCOLOR(3),BACKCOLOR(3),FACECOLOR(3),NOSECOLOR(3),CHEEKCOLOR(3),EYESCOLOR(3),HIGHLIGHT(3),LINECOLOR(3),T
DIM P(2),M(2,2),V(2),W(2),Q(2),QQ(2),DESTCOLOR(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)
CALL VEC3(LIGHTCOLOR,0.95, 0.95, 0.5)!' // 背景の後光の色
CALL VEC3(BACKCOLOR,0.95, 0.25, 0.25)!' // 背景の下地の色
CALL VEC3(FACECOLOR,0.95, 0.75, 0.5)!' // 顔の色
CALL VEC3(NOSECOLOR,0.95, 0.25, 0.25)!' // 鼻の色
CALL VEC3(CHEEKCOLOR,1.0, 0.55, 0.25)!' // 頬の色
CALL VEC3(EYESCOLOR,0.15, 0.05, 0.05)!' // 目の色
CALL VEC3(HIGHLIGHT,0.95, 0.95, 0.95)!' // ハイライトの色
CALL VEC3(LINECOLOR,0.3, 0.2, 0.2)!' // ラインの色
LET T=INT(TIME)
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(P,X,Y)
CALL SUNRISE(P,DESTCOLOR)
LET S=SIN(SIN(T*2)*.75)
LET C=COS(SIN(T*2))
CALL MAT2(M,C,-S,S,C)
MAT Q=P*M
! circle(q, vec2(0.0), 0.5, faceColor, destColor);
CALL VEC2(V,0,0)
CALL CIRCLE(Q,V,.5,FACECOLOR,DESTCOLOR)
! circle(q, vec2(0.0, -0.05), 0.15, noseColor, destColor);
CALL VEC2(V,0,-.05)
CALL CIRCLE(Q,V,.15,NOSECOLOR,DESTCOLOR)
! circle(q, vec2(0.325, -0.05), 0.15, cheekColor, destColor);
CALL VEC2(V,.325,-.05)
CALL CIRCLE(Q,V,.15,CHEEKCOLOR,DESTCOLOR)
! circle(q, vec2(-0.325, -0.05), 0.15, cheekColor, destColor);
CALL VEC2(V,-.325,-.05)
CALL CIRCLE(Q,V,.15,CHEEKCOLOR,DESTCOLOR)
! ellipse(q, vec2(0.15, 0.135), vec2(0.75, 1.0), 0.075, eyesColor, destColor);
CALL VEC2(V,.15,.135)
CALL VEC2(W,.75,1)
CALL ELLIPSE(Q,V,W,.075,EYESCOLOR,DESTCOLOR)
! ellipse(q, vec2(-0.15, 0.135), vec2(0.75, 1.0), 0.075, eyesColor, destColor);
CALL VEC2(V,-.15,.135)
CALL ELLIPSE(Q,V,W,.075,EYESCOLOR,DESTCOLOR)
! circleLine(q, vec2(0.0), 0.5, 0.525, lineColor, destColor);
CALL VEC2(V,0,0)
CALL CIRCLELINE(Q,V,.5,.525,LINECOLOR,DESTCOLOR)
! circleLine(q, vec2(0.0, -0.05), 0.15, 0.17, lineColor, destColor);
CALL VEC2(V,0,-.05)
CALL CIRCLELINE(Q,V,.15,.17,LINECOLOR,DESTCOLOR)
! arcLine(q, vec2(0.325, -0.05), 0.15, 0.17, PI * 1.5, 0.0, lineColor, destColor);
CALL VEC2(V,.325,-.05)
CALL ARCLINE(Q,V,.15,.17,PI*.5,0,LINECOLOR,DESTCOLOR)
! arcLine(q, vec2(-0.325, -0.05), 0.15, 0.17, PI * 0.5, 0.0, lineColor, destColor);
CALL VEC2(V,-.325,-.05)
CALL ARCLINE(Q,V,.15,.17,PI*1.5,0,LINECOLOR,DESTCOLOR)
! arcLine(q * vec2(1.2, 1.0), vec2(0.19, 0.2), 0.125, 0.145, 0.0, 0.02, lineColor, destColor);
CALL VEC2(V,1.2,1)
CALL VEC2(W,.19,.2)
FOR I=1 TO 2
LET QQ(I)=Q(I)*V(I)
NEXT I
CALL ARCLINE(QQ,W,.125,.145,0,.02,LINECOLOR,DESTCOLOR)
! arcLine(q * vec2(1.2, 1.0), vec2(-0.19, 0.2), 0.125, 0.145, 0.0, 0.02, lineColor, destColor);
CALL VEC2(V,1.2,1)
CALL VEC2(W,-.19,.2)
FOR I=1 TO 2
LET QQ(I)=Q(I)*V(I)
NEXT I
CALL ARCLINE(QQ,W,.125,.145,0,.02,LINECOLOR,DESTCOLOR)
! arcLine(q * vec2(0.9, 1.0), vec2(0.0, -0.15), 0.2, 0.22, PI, 0.055, lineColor, destColor);
CALL VEC2(V,.9,1)
CALL VEC2(W,0,-.15)
FOR I=1 TO 2
LET QQ(I)=Q(I)*V(I)
NEXT I
CALL ARCLINE(QQ,W,0.2, 0.22, PI, 0.055,LINECOLOR,DESTCOLOR)
! rect(q, vec2(-0.025, 0.0), 0.035, highlight, destColor);
CALL VEC2(V,-.025,0)
CALL RECT(Q,V,.035,HIGHLIGHT,DESTCOLOR)
! rect(q, vec2(-0.35, 0.0), 0.035, highlight, destColor);
CALL VEC2(V,-.35,0)
CALL RECT(Q,V,.035,HIGHLIGHT,DESTCOLOR)
! rect(q, vec2(0.3, 0.0), 0.035, highlight, destColor);
CALL VEC2(V,.3,0)
CALL RECT(Q,V,.035,HIGHLIGHT,DESTCOLOR)
CALL SETCOLOR(DESTCOLOR)
PLOT POINTS:X,Y
NEXT XX
NEXT YY
END
EXTERNAL SUB CIRCLE(P(),OFFSET(),SIZE,COL(),I())
DIM PP(2)
MAT PP=P-OFFSET
LET L=LENGTH(PP)
IF L<SIZE THEN MAT I=COL
END SUB
EXTERNAL SUB ELLIPSE(P(),OFFSET(),PROP(),SIZE,COL(),I())
DIM PP(2),Q(2)
MAT PP=P-OFFSET
FOR J=1 TO 2
LET Q(J)=PP(J)/PROP(J)
NEXT J
IF LENGTH(Q)<SIZE THEN MAT I=COL
END SUB
EXTERNAL SUB CIRCLELINE(P(),OFFSET(),ISIZE,OSIZE,COL(),I())
DIM Q(2)
MAT Q=P-OFFSET
LET L=LENGTH(Q)
IF L>ISIZE AND L<OSIZE THEN MAT I=COL
END SUB
EXTERNAL SUB ARCLINE(P(),OFFSET(),ISIZE,OSIZE,RAD,HEIGHT,COL(),I())
DIM ROT(2,2),Q(2)
LET S=SIN(RAD)
LET C=COS(RAD)
CALL MAT2(ROT,C,-S,S,C)
MAT Q=P-OFFSET
MAT Q=Q*ROT
LET L=LENGTH(Q)
IF L>ISIZE AND L<OSIZE AND Q(2)>HEIGHT THEN MAT I=COL
END SUB
EXTERNAL SUB RECT(P(),OFFSET(),SIZE,COL(),I())
DIM Q(2)
MAT Q=P-OFFSET
MAT Q=(1/SIZE)*Q
IF ABS(Q(1))<1 AND ABS(Q(2))<1 THEN MAT I=COL
END SUB
EXTERNAL SUB SUNRISE(P(),I())
LET F=ATAN(P(1),P(2))+T
LET FS=SIN(F*10)
FOR J=1 TO 2
LET I(J)=MIX(LIGHTCOLOR(J),BACKCOLOR(J),FS)
NEXT J
END SUB
EXTERNAL SUB SETCOLOR(A())
SET COLOR COLORINDEX(CLAMP(A(1),0,1),CLAMP(A(2),0,1),CLAMP(A(3),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 MIX(X,Y,A)
LET MIX=X*(1-A)+Y*A
END FUNCTION
EXTERNAL SUB MAT2(X(,),A,B,C,D)
LET X(1,1)=A
LET X(1,2)=B
LET X(2,1)=C
LET X(2,2)=D
END SUB
EXTERNAL FUNCTION ATAN(X,Y)
IF ABS(X)>1E-4 THEN
LET TH=ATN(Y/X)
IF Y<>0 THEN
IF X>0 AND Y<0 THEN LET TH=TH+PI*2
IF X<0 THEN LET TH=TH+PI
ELSE !' Y=0
IF X<0 THEN LET TH=PI ELSE LET TH=0
END IF
ELSE !' X=0
LET TH=PI/2
IF Y<0 THEN LET TH=TH+PI
END IF
LET ATAN=TH
END FUNCTION
|
|