Dark Bit Factory & Gravity

GENERAL => Projects => Topic started by: Shockwave on March 26, 2011

Title: Very quickly made effect.
Post by: Shockwave on March 26, 2011
This is just a little experiment, it's something I might develop into an intro.

Please ignore the coder colours, this is just a test to see how quick this runs on various systems - I think it should be quite quick because it's all pointers. If it's too slow I'll have to ditch the pixel pushing and switch to the hardware for this.

Code is included in case anyone wants to use any of it.

Code: [Select]
'*******************************************************************************
'*
'*            Quickly made Metablob thingy by Shockwave 2011..
'*            ================================================
'*                  Greetings to gun owners everywhere.
'*
'*   Fuckings to pretentious twats who fart too high for thier own assholes.
'*   If the cap fits....
'*
'*   Credit to shockwave/dbfinteractive.com if used!
'*******************************************************************************

'-------------------------------------------------------------------------------
'   LIBS;
'-------------------------------------------------------------------------------
   
    #INCLUDE "TINYPTC_EXT.BI"
    #INCLUDE "WINDOWS.BI"
   
    OPTION STATIC
    OPTION EXPLICIT

'-------------------------------------------------------------------------------
'   800 * 600 SCREEN AND SCREEN BUFFER.
'-------------------------------------------------------------------------------
   
    CONST   XRES    =    800
    CONST   YRES    =    600
   
    DIM SHARED AS UINTEGER BUFFER2( XRES * YRES )
    DIM SHARED AS UINTEGER BUFFER ( XRES * YRES )

'-------------------------------------------------------------------------------
'   OTHER DEFINITIONS.
'-------------------------------------------------------------------------------

    CONST   CIRCX    =    320
    CONST   CIRCY    =    320

    DIM SHARED AS UINTEGER CIRCBUFF ( CIRCX * CIRCY )   
   
    DECLARE SUB PREP_CIRCLE()
    DECLARE SUB CIRC(BYVAL CX AS INTEGER , BYVAL CY AS INTEGER , BYVAL R AS INTEGER , BYVAL TC AS UINTEGER)
    DECLARE SUB DRAW_METABLOB(BYVAL XX AS INTEGER,BYVAL YY AS INTEGER)
    PREP_CIRCLE()

    CONST STARNUM = 30
       
    DIM SHARED AS DOUBLE STX (STARNUM)
    DIM SHARED AS DOUBLE STY (STARNUM)
    DIM SHARED AS DOUBLE STS (STARNUM)
   
    DECLARE SUB SET_STAR()
    DECLARE SUB DRAW_STAR()
   
    SET_STAR()

    DIM SHARED R2D AS DOUBLE
    R2D=(4 * ATN ( 1 ))/180

'-------------------------------------------------------------------------------
'   OPEN THE SCREEN;
'-------------------------------------------------------------------------------
   
    PTC_ALLOWCLOSE(0)
    PTC_SETDIALOG(1,"QUICK INTRO"+CHR$(13)+"FULL SCREEN?",0,1)               
    IF (PTC_OPEN("BY SHOCKWAVE",XRES,YRES)=0) THEN
        END-1
    END IF   
   
'*******************************************************************************
'*  MAIN LOOP;
'*******************************************************************************

    DIM SHARED AS DOUBLE GADD,DV,OLD

WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE) 

    OLD=TIMER

        DRAW_STAR()
        PTC_UPDATE@BUFFER(0)
        ERASE BUFFER   
        SLEEP 1
       
    DV=TIMER-OLD
    IF DV>2 THEN DV=2
    GADD=GADD+DV
   
WEND

'*******************************************************************************
'*  EXIT.
'*******************************************************************************

EXITPROCESS(0)
 
'-------------------------------------------------------------------------------
'   SUBROUTINES.
'-------------------------------------------------------------------------------

SUB SET_STAR()

    DIM LP AS INTEGER
   
    FOR LP=1 TO STARNUM
       
        STX(LP)=(RND(1)*(XRES+CIRCX))-CIRCX
        STY(LP)=(RND(1)*(YRES+CIRCY))-CIRCY
        STS(LP)=(RND(1)*3)*100
       
    NEXT
   

END SUB

SUB DRAW_STAR()

    DIM LP AS INTEGER
   
    FOR LP=1 TO STARNUM
       
        DRAW_METABLOB(INT(STX(LP)),INT(STY(LP)+140*SIN((STX(LP)+GADD)*R2D)))

        STX(LP)=STX(LP)-(STS(LP)*DV)
        IF STX(LP)< -CIRCX THEN STX(LP)=STX(LP)+(XRES+CIRCX)

    NEXT
   

END SUB



SUB DRAW_METABLOB(BYVAL XX AS INTEGER,BYVAL YY AS INTEGER)

'-------------------------------------------------------------------------
'
' DRAW A METABOB AT XX,YY
'
' CLIP TO SCREEN LIMITS.
'
'-------------------------------------------------------------------------

    DIM PP  AS UINTEGER PTR
    DIM PP2 AS UINTEGER PTR
    DIM AS INTEGER CLIPL , CLIPR , Y , LP, SLICE
   
    '------------------------------------------------------------------------
    ' CLIP X TO SCREEN;
    '------------------------------------------------------------------------
   
    CLIPL=0
    CLIPR=CIRCX
   
    IF XX<0 THEN CLIPL = -XX
   
    IF XX > (XRES-CIRCX) THEN CLIPR = CIRCX-(XX-(XRES-CIRCX))
   
    IF CLIPL>CIRCX THEN CLIPL=0 : CLIPR=0
    IF CLIPR<1 THEN CLIPL=0 : CLIPR = 0
   
    SLICE = CLIPR-CLIPL
   
    XX=XX+CLIPL
   
    '------------------------------------------------------------------------
    ' DRAW LOOP
    '------------------------------------------------------------------------
   
    FOR Y=0 TO CIRCY-1
       
        IF YY>=0 AND YY<YRES THEN
           
            PP =@BUFFER  (XX+(YY*XRES))
            PP2=@CIRCBUFF(CLIPL+(Y*CIRCX))
           
            FOR LP=1 TO SLICE           
                *PP += *PP2               
                PP2+=1
                PP+=1
               
            NEXT
       
        END IF
        YY+=1
       
    NEXT
   


END SUB


SUB PREP_CIRCLE()

'-------------------------------------------------------------------------
'
' PRECALCULATE THE METABALL
'
' SUB IS CALLED ONCE AT THE START OF THE PROGRAM.
'
'-------------------------------------------------------------------------

    DIM TC AS INTEGER
    DIM LP AS INTEGER
   
    FOR LP=150 TO 1 STEP-1
       
       
        CIRC(CIRCX SHR 1,CIRCY SHR 1,LP,TC)
       
        IF TC<255 THEN TC+=1
       
    NEXT
   
END SUB



SUB CIRC(BYVAL CX AS INTEGER , BYVAL CY AS INTEGER , BYVAL R AS INTEGER , BYVAL TC AS UINTEGER)

'-------------------------------------------------------------------------
'
' FILLED CIRCLE ROUTINE
' USAGE  CIRC ( CX , CY , RADIUS , R , G , B )
'
' CLIPS TO SCREEN BOUNDARIES - BY SHOCKWAVE.
' CUSTOMISED HERE TO DRAW INTO A BUFFER FOR THE METABLOBS.
'
'-------------------------------------------------------------------------

DIM AS INTEGER R2,CC,LOOPY,WW,L,CLIPL ,CLIPR,SLICE
DIM PP AS INTEGER PTR
R2=R*R
CC=-R
FOR LOOPY = CC TO R     
        WW = SQR(R2-LOOPY*LOOPY)
       
        IF LOOPY+CY>=0 AND LOOPY+CY<CIRCY THEN
            CLIPL = CX-WW
            CLIPR = (CX+WW)-1
            IF CLIPL<0 THEN CLIPL=0
            IF CLIPR>CIRCX-1 THEN CLIPR = CIRCX-1
            PP=@CIRCBUFF((CIRCX*(LOOPY+CY))+CLIPL)
            SLICE = CLIPR - CLIPL
            IF SLICE>0 THEN
                    ASM
                    MOV EAX,DWORD PTR[TC]
                    MOV ECX, [SLICE]
                    MOV EDI, [PP]
                    REP STOSD
                    END ASM   
            END IF   
   
        END IF
NEXT

END SUB

The thing I am going to develop this into will be quite Melon Dezign looking, all I am interested to know at this stage is if it runs smooth (especially on older systems).

Cheers folks!
Title: Re: Very quickly made effect.
Post by: Hotshot on March 26, 2011
Fast as Fuck....on Full Screen and Window.....No Slowdown whatever...

I love the Bluey colour  ;D

My spec are

2GHZ
3GB RAM
GEFORCE 9600
Title: Re: Very quickly made effect.
Post by: Rbz on March 26, 2011
Works fine on windowed mode, on fullscreen sometimes the screen flashes in black, not sure but could be my new 1080p monitor not liking this resolution.
Title: Re: Very quickly made effect.
Post by: Kirl on March 26, 2011
Quite old, slower then usual laptop (probably software issues), runs very smooth at full screen.

Good stuff! :)
Title: Re: Very quickly made effect.
Post by: LittleWhite on March 27, 2011
Nice ... it has a look of plasma in blobs :)
Title: Re: Very quickly made effect.
Post by: rain_storm on March 27, 2011
Fast and smooth,
Celeron D 3GHz
256MB RAM
Title: Re: Very quickly made effect.
Post by: mind on March 27, 2011
personally, i'd say that the particles are too linear.. go for an exponential approximation of a sphere instead.. and for gods sake, SATURATE! if col>255; col=255; PLEASE!! haha :)

want some advice on how to take it further? render the background at 127,127,127 instead of 0,0,0, and draw a bunch of particles, some beeing additive and some beeing subtractive.. it doesnt make sense when in typing, but once you see it you'll know what i mean :P
Title: Re: Very quickly made effect.
Post by: Shockwave on March 27, 2011
Thanks for the benchmarks and your advice too

@Mind - I was planning something similar to what you suggested but I hadn't considered having subtractive pixels, that would indeed be interesting. Thank you!
Title: Re: Very quickly made effect.
Post by: Shockwave on March 27, 2011
Here it is now.

It looks a lot different :)
Title: Re: Very quickly made effect.
Post by: rain_storm on March 27, 2011
Much nicer, This has to be an order of magnitude faster then the meathod I use for similar effects, which is a simple random noise + smooth. And this is dynamic. Worthy of some Karma I think now that I can see it in a better light.
Title: Re: Very quickly made effect.
Post by: Shockwave on March 27, 2011
Thanks mate.

The good thing is that I don't have to do any bounds checking for the pixels because I've just used a huge colour palette buffer so it's pretty quick :)

I'll release the source when it's finished.
Title: Re: Very quickly made effect.
Post by: Rbz on March 27, 2011
Much better now, it now looks like clouds and it didn't flashes in black anymore for full screen mode.
Title: Re: Very quickly made effect.
Post by: Shockwave on March 27, 2011
it didn't flashes in black anymore for full screen mode.

The res is now 640 * 480, before it was 800 * 600 so maybe it's a problem with 800*600 in tinyptc?
Title: Re: Very quickly made effect.
Post by: Rbz on March 27, 2011
It's probably my new monitor mate, I never had this problem before. And having a windowed mode is always nice.

[edited] baah, just tested old version and it works fine without flashing, nothing like a reboot to fix things :)
Title: Re: Very quickly made effect.
Post by: Dr.Death on March 27, 2011
I like the newer version better now mate it would make a wicked intro now..

Any more ideas for it ??
Title: Re: Very quickly made effect.
Post by: Xetick on March 27, 2011
Nice new version. Looks quite a lot like a perlin noise effect now and it's very fast too!
Title: Re: Very quickly made effect.
Post by: padman on March 27, 2011
Works fine on my Celeron D 2,66GHz, Geforce FX5200, 1280MB RAM. And it's looking cool too. (Would have been a nice effect for the Liquid Challenge ;))
Title: Re: Very quickly made effect.
Post by: Shockwave on March 27, 2011
Thanks, I'm going to make it look more like clouds now and see what I can add to it without making it look too silly.
Title: Re: Very quickly made effect.
Post by: va!n on March 27, 2011
Wow! Very nice work and esp impressive fast for software rendering! The new version looks much better.
Btw, how many objects are you drawing in the latest version? What about a test version where the user can change some values and report you his results? For example a version with following options:

- Select 640x480 and 800x600
- Show number of used Objects/Balls ( change by +/- or cursor keys)
- Showing FPS

Just an idea... so you would get a overview what is possible without slowing down the FPS to much ;)
Still looking forward to your nice work!
Title: Re: Very quickly made effect.
Post by: StatMat on March 27, 2011
Nice effect that. Definitely worthy of fleshing out. Always good to see pure software renderingtoo, just the way it should be. :p
Title: Re: Very quickly made effect.
Post by: Hotshot on March 27, 2011
It is the most Realtic clouds I have seen for while  :)
Title: Re: Very quickly made effect.
Post by: Raizor on April 02, 2011
The thing I am going to develop this into will be quite Melon Dezign looking...

Shockwave, you have no idea how much of a Melon fan I am :)

I used to watch their crack intros for Crystal over and over again on the Amiga. I'm really looking forward to seeing the finished intro.

I like the effect, it's cool. Kinda like that bastard child of a shadebobs, plasma and metaballs gangbang :)  Would look even nicer if the objects were different colours or the colours changed in some way. Is that possible?