|
フラグメントシェーダー 三項ブーリアン演算
ブーリアン演算を3項でやってみた。
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,1,0,0)
ELSE
CALL VEC3(C,0,0,0)
END IF
CALL SETCOLOR(C)
PLOT POINTS:X,Y
NEXT XX
NEXT YY
END
EXTERNAL FUNCTION MIN3(X,Y,Z)
LET MIN3=MIN(X,MIN(Y,Z))
END FUNCTION
EXTERNAL FUNCTION MIN4(X,Y,Z,W)
LET MIN4=MIN(MIN(X,Y),MIN(Z,W))
END FUNCTION
EXTERNAL FUNCTION MAX3(X,Y,Z)
LET MAX3=MAX(X,MAX(Y,Z))
END FUNCTION
EXTERNAL FUNCTION CIRCLE(P(),B(),R)
DIM PP(2)
MAT PP=P-B
LET CIRCLE=LENGTH(PP)-R
END FUNCTION
EXTERNAL FUNCTION DISTANCE(P())
DIM P1(2),P2(2),P3(2)
CALL VEC2(P1,.3*COS(0),.3*SIN(0))
CALL VEC2(P2,.3*COS(2*PI/3),.3*SIN(2*PI/3))
CALL VEC2(P3,.3*COS(4*PI/3),.3*SIN(4*PI/3))
LET A=CIRCLE(P,P1,.5)
LET B=CIRCLE(P,P2,.5)
LET C=CIRCLE(P,P3,.5)
LET DISTANCE=MIN3(A,B,C)
!LET DISTANCE=MAX3(A,B,C)
!LET DISTANCE=MAX3(-A,B,C)
!LET DISTANCE=MAX3(A,-B,C)
!LET DISTANCE=MAX3(A,B,-C)
!LET DISTANCE=MAX3(A,-B,-C)
!LET DISTANCE=MAX3(-A,B,-C)
!LET DISTANCE=MAX3(-A,-B,C)
!LET DISTANCE=MIN3(MIN(MAX(-A,B),MAX(A,-B)),MIN(MAX(-B,C),MAX(B,-C)),MIN(MAX(-A,C),MAX(A,-C)))
!LET DISTANCE=MAX3(MIN(A,B),MIN(B,C),MIN(A,C))
!LET DISTANCE=MIN3(MAX(A,B),MAX(B,C),MAX(A,C))
!LET DISTANCE=MIN3(MAX(-A,B),MAX(-B,C),MAX(A,-C))
!LET DISTANCE=MIN3(MAX3(-A,-B,C),MAX3(A,-B,-C),MAX3(-A,B,-C))
!LET DISTANCE=MIN3(MAX3(-A,B,C),MAX3(A,-B,C),MAX3(A,B,-C))
!LET DISTANCE=MIN(MAX3(-A,B,C),MAX3(A,-B,C))
!LET DISTANCE=MIN3(MAX3(-A,-B,C),MAX3(A,B,C),MAX3(A,B,-C))
!LET DISTANCE=MIN3(MAX3(-A,B,C),MAX3(-A,-B,C),MAX3(A,-B,-C))
!LET DISTANCE=MIN3(MAX3(A,B,C),MAX3(-A,B,C),MAX3(A,-B,C))
!LET DISTANCE=MAX(A,MIN(-B,C))
!LET DISTANCE=MIN3(MAX3(A,-B,-C),MAX3(-A,B,-C),MAX3(A,B,C))
!LET DISTANCE=MIN3(MAX3(A,-B,-C),MAX3(-A,B,C),MAX3(A,B,C))
!LET DISTANCE=MIN4(MAX3(A,-B,C),MAX3(-A,-B,C),MAX3(A,B,-C),MAX3(A,-B,-C))
!LET DISTANCE=MIN3(MAX3(A,B,-C),MAX3(A,-B,-C),MAX3(-A,-B,C))
END FUNCTION
EXTERNAL SUB SETCOLOR(COL())
SET COLOR COLORINDEX(CLAMP(COL(1),0,1),CLAMP(COL(2),0,1),CLAMP(COL(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
|
|