Author Topic: Very quickly made effect.  (Read 8111 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Very quickly made effect.
« 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!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Very quickly made effect.
« Reply #1 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

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
Re: Very quickly made effect.
« Reply #2 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.
Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
Re: Very quickly made effect.
« Reply #3 on: March 26, 2011 »
Quite old, slower then usual laptop (probably software issues), runs very smooth at full screen.

Good stuff! :)
www.kirl.nl
Challenge Trophies Won:

Offline LittleWhite

  • Senior Member
  • Amiga 1200
  • ********
  • Posts: 418
  • Karma: 31
  • It's me!
    • View Profile
Re: Very quickly made effect.
« Reply #4 on: March 27, 2011 »
Nice ... it has a look of plasma in blobs :)
The demoscene will never die, never!

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Very quickly made effect.
« Reply #5 on: March 27, 2011 »
Fast and smooth,
Celeron D 3GHz
256MB RAM

Challenge Trophies Won:

Offline mind

  • Texture-San
  • DBF Aficionado
  • ******
  • Posts: 2324
  • Karma: 85
    • View Profile
    • boredom is a beatiful thing.
Re: Very quickly made effect.
« Reply #6 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
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Very quickly made effect.
« Reply #7 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!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Very quickly made effect.
« Reply #8 on: March 27, 2011 »
Here it is now.

It looks a lot different :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Very quickly made effect.
« Reply #9 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.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Very quickly made effect.
« Reply #10 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.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
Re: Very quickly made effect.
« Reply #11 on: March 27, 2011 »
Much better now, it now looks like clouds and it didn't flashes in black anymore for full screen mode.
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Very quickly made effect.
« Reply #12 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?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2750
  • Karma: 493
    • View Profile
    • http://www.rbraz.com/
Re: Very quickly made effect.
« Reply #13 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 :)
« Last Edit: March 27, 2011 by rbz »
Challenge Trophies Won:

Offline Dr.Death

  • Senior Member
  • Amiga 1200
  • ********
  • Posts: 445
  • Karma: 9
    • View Profile
Re: Very quickly made effect.
« Reply #14 on: March 27, 2011 »
I like the newer version better now mate it would make a wicked intro now..

Any more ideas for it ??
Proud member of DAWN

Offline Xetick

  • Atari ST
  • ***
  • Posts: 132
  • Karma: 80
    • View Profile
    • Plane9
Re: Very quickly made effect.
« Reply #15 on: March 27, 2011 »
Nice new version. Looks quite a lot like a perlin noise effect now and it's very fast too!
Plane9 - Home of the Plane9 3d screensaver/music visualizer
Challenge Trophies Won:

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 990
  • Karma: 260
    • View Profile
Re: Very quickly made effect.
« Reply #16 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 ;))
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17394
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Very quickly made effect.
« Reply #17 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.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1431
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Very quickly made effect.
« Reply #18 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!
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline StatMat

  • C= 64
  • **
  • Posts: 43
  • Karma: 14
    • View Profile
Re: Very quickly made effect.
« Reply #19 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
"When the only tool you own is a hammer, every problem begins to resemble a nail."