News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

UW3D Returns

Started by kevin, January 13, 2005, 09:54:51 AM

Previous topic - Next topic

stef

Hi!

Yes that sounds really cool!

When is the release of PB 1.64 ?

What is "virtually free alpha blending"?


Greetings
stef

Draco9898

#16
does this mean we can do hard-core alpha-blending effects on virtually everything/anything? I smell a revision of my flame particles  ;D Oh and I could fiddle with my game more, I guess...What about filling the screen with semi-transparent water without making everything scream to a halt (3-4 FPS at best.)?

@stef:
I Suppose this means a lot of things will be very fast considering it's not all in software anymore and utilizes your graphics card more. It's all done in your graphics card rather then having the CPU do most and sending it's work to the drawing surface. That's what I'm guessing, but I guess Kevin will have to fill us in.
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

#17
QuoteWhat is "virtually free alpha blending"?

  You can blend at much the same speed as opaque rendering.    Obviously this will vary dramatically between video cards. 

Quotedoes this mean we can do hard-core alpha-blending effects on virtually everything/anything?

  To a degree, or more accurately, pretty much anything polygon based.  Some things aren't ie. shapes

QuoteWhat about filling the screen with semi-transparent water without making everything scream to a halt (3-4 FPS at best.)?

   erm,  This  approach runs quite nicely without 3D.

   A similar approach was also used in the Rugby tech demos. Rugby Thread

   The screen is split into two cameras.  All the polygons are batched to the scene, then we draw camera 1.  Camera 1 is attached to the video frame buffer.  Then camera 2. Which is attach to an fx frame buffer.  Once render we blit the bottom section to the screen.  Which allows this section of the screen to be blended with minimal impact.. 



QuoteI Suppose this means a lot of things will be very fast considering it's not all in software anymore and utilizes your graphics card more. It's all done in your graphics card rather then having the CPU do most and sending it's work to the drawing surface.

   In terms of opaque rendering, using polygons tends to be slower than the GPU's blitter.  PB has always been hardware accelerated for 2d blits, but the direct draw Blitter only has limited functionality.   For any functionality that can't be uniformally provided in hardware, software solutions have to be used.   

  If you use software and in particular blending (which require reading from both buffers source & destination) then you have to use off card surfaces like FX buffers.  Because you can't read video memory at speed on the PC.  Even over the PCX bus it's still 20 or worse times slower than system memory.     The bottle neck is mainly copying the frame buffer from system to video.

   Rendering images as 3D quads avoid the cpu reading the back buffer issue, since the memory is local to the gpu,  you've now limited to the hardware supported sizes, blend states and more importantly the number of texture state changes per each draw call.     Meaning, calling it too often slows it down dramatically!   

* Pro's

   - Generally Faster combination effects (filtering, rotation, alpha based blending) while rendering to the screen.

   - Avoids copying the frame buffer.


* Con's

  - Texture size/ Texture format/ Blend mode issues across different hardware.
  - Will chokes on too many state changes / draw calls.   
  - Can't render to off screen surfaces across the board..

   Anyway, the point is,  It's not merely an set and forget situation.

Draco9898

#18
Card: NVidia Geforce FX 5600XT(128mb) (Wow, this is so old that no one sells it anymore  :'( )
My Pc is probably a good Low-grade benchmark, it's getting crusty.

Played with it some, I get an amazing 60-70 FPS for FOUR HUNDRED 64,128 alpha-blended images @ 640, 480, Obviously 32 bit, full-screen exclusive mode. I also get 4-5 FPS using Fx images in the same example in compiler 1.47.

Similar results or a bit lower for rotating and scaling the same amount of images.

Ink 1+32 -Dots, a 200 x 200 Box, or Circles seem to crawl to a halt though (15-20 Fps), of course, I'm probably doing something terribly/horrifically wrong as I just tried locking the buffer, drawing batches of them and unlocking. Tring a full screen primitive just results in FPs 1 (IF that).

There is a strange bug though, but of course you probably already know about it. Don't want to be your captain obvious, but I try loading a 3d image in when I first start playbasic and it goes into the buffer stretched out, cropped off and has it's colors inverted. (It seems to fix itself if I draw the image twice)


Is there anyway to manipulate/renderTO a 3d image without having to re-send it to the 3d card?
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

stef

Hi!

That's really not bad :)

code below is just experimentally ( for BOTS )
but a slly question:
how can I limit the 'sun-particles' ( let's say a maximum of 200 on screen)

needs PB1.65 or above!


OpenScreen 800,600,32,2

Type particle
x#,y#
dx#,dy#
angle#
speed#
Radius
Colour
EndType


Dim Object As particle List

global sun
global ground

drawstuff()


Do
rendertoscreen
Cls RGB(0,0,255)
Print FPS()

Addpart()

LockBuffer

For Each Object()

Object.x#=Object.x#+Object.dx#
Object.y#=Object.y#+Object.dy#


If PointInBox(Object.x#,Object.y#,10,10,790,590)=False

Object = NULL
Continue  

EndIf

CircleC Object.x#,Object.y#,Object.Radius,True,Object.Colour

Next

UnLockBuffer


drawalphaimage sun,600-40+rnd(2),100-40+rnd(2),alpha#,1
drawalphaimage ground,0,300,1.0-alpha#,1

alpha#=sin(angle#)
alpha#=abs(alpha#)
angle#=angle#+0.2


Sync
Loop
function drawstuff()

sun=getfreeimage()
create3dimage sun,80,80
rendertoimage sun
CircleC 40,40,40,1,RGB(255,255,0)

ground=getfreeimage()
create3dimage ground,800,300
rendertoimage ground
cls RGB(0,140,200)


endfunction



Function Addpart()

For x= 0 To 6


Object = New particle
Object.X# =600
Object.y# =100
Object.Angle# =Rnd(360)
Object.Speed# =3
Object.dx# =Cos(Object.angle)*object.speed
Object.dy# =Sin(Object.angle)*object.speed

Object.Radius =2
Object.Colour  =RGB(255,255,0)

Next

EndFunction



Draco9898

#20
Well, you just keep creating new particles instead of recycling old ones. Infact, if you ran this for a long time I bet you'd just crash the proggie- because you just keep eating up RAM. You have to manage your memory better or it will overflow.
Try making a typed array of 200 particles and give them a number 'life'. check each loop if any of the particles 'lifes' have expired and assign them new default values via a function if they have.
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

stef

Hi!

Thx for reply
That's a 'type list' example; the particles are 'killed' when leaving screen.
'Object = NULL'
   
I normally prefer simple arrays or types, but wanted to try out lists (maybe more elegant)
but as said above I have a problem with limiting particlenumber

should be something like
Size = GetArrayElements(ThisArray(), DimensionIndex)


Greetings
stef


kevin

QuotePlayed with it some, I get an amazing 60-70 FPS for FOUR HUNDRED 64,128 alpha-blended images @ 640, 480, Obviously 32 bit, full-screen exclusive mode. I also get 4-5 FPS using Fx images in the same example in compiler 1.47.

See Image Draw Modes


Quote
Ink 1+32 -Dots, a 200 x 200 Box, or Circles seem to crawl to a halt though (15-20 Fps), of course, I'm probably doing something terribly/horrifically wrong as I just tried locking the buffer, drawing batches of them and unlocking. Tring a full screen primitive just results in FPs 1 (IF that).


See Image Draw Modes



Quote
There is a strange bug though, but of course you probably already know about it. Don't want to be your captain obvious, but I try loading a 3d image in when I first start playbasic and it goes into the buffer stretched out, cropped off and has it's colors inverted. (It seems to fix itself if I draw the image twice)

There are bugs ?.. gezzz  thanks caption obvious


QuoteIs there anyway to manipulate/renderTO a 3d image without having to re-send it to the 3d card?

  Render what


Quotehow can I limit the 'sun-particles' ( let's say a maximum of 200 on screen)

You could,

  * use a some globals to keep track of the number of created/deleted items in the list.  . 

  * Make a function to count  through the list

   or adding a drawn counter to the render loop..


NumbOfParticles=0
For Each Object()

Object.x#=Object.x#+Object.dx#
Object.y#=Object.y#+Object.dy#


If PointInBox(Object.x#,Object.y#,10,10,790,590)=False

Object = NULL
Continue  

EndIf

CircleC Object.x#,Object.y#,Object.Radius,True,Object.Colour
inc NumbOfParticles
Next



Quoteshould be something like
Size = GetArrayElements(ThisArray(), DimensionIndex)

   Yeah, none of the array commands are aware that it's a list, so that'd return the container size atm.

  Add any ideas to this feature request



stef

#23
Yes, with your code it's working

Use LMB and RMB for increase/decrease maxparticles (= number of particles)

needs PB1.65 or above


OpenScreen 800,600,32,2

Type particle
x#,y#
dx#,dy#
angle#
speed#
Radius
Colour
EndType


Dim Object As particle List

Global sun
Global ground
Global NumbOfParticles
Global MaxParticles=20

drawstuff()


Do
RenderToScreen
Cls RGB(0,0,255)
Print FPS()
Print MaxParticles
Print NumbOfParticles
Print GetArrayElements(object(),0)


If LeftMouseButton()=1
FlushMouse
MaxParticles=MaxParticles-5
EndIf
If RightMouseButton()=1
FlushMouse
MaxParticles=MaxParticles+5
EndIf

If MaxParticles<0 Then MaxParticles=0


If NumbOfParticles<MaxParticles
Addpart()
EndIf

LockBuffer

NumbOfParticles=0

For Each Object()

Object.x#=Object.x#+Object.dx#
Object.y#=Object.y#+Object.dy#


If PointInBox(Object.x#,Object.y#,10,10,790,590)=False

Object = NULL
Continue  

EndIf

CircleC Object.x#,Object.y#,Object.Radius,True,Object.Colour

Inc NumbOfParticles

Next

UnLockBuffer


DrawAlphaImage sun,600-40+Rnd(2),100-40+Rnd(2),alpha#,1
DrawAlphaImage ground,0,300,1.0-alpha#,1

alpha#=Sin(angle#)
alpha#=Abs(alpha#)
angle#=angle#+0.5


Sync
Loop
Function drawstuff()

sun=GetFreeImage()
Create3DImage sun,80,80
RenderToImage sun
CircleC 40,40,40,1,RGB(255,255,0)

ground=GetFreeImage()
Create3DImage ground,800,300
RenderToImage ground
Cls RGB(0,140,200)


EndFunction



Function Addpart()

For x= 0 To 6


Object = New particle
Object.X# =600
Object.y# =100
Object.Angle# =Rnd(360)
Object.Speed# =1
Object.dx# =Cos(Object.angle#)*object.speed#
Object.dy# =Sin(Object.angle#)*object.speed#

Object.Radius =4
Object.Colour  =RGB(255,255,0)

Next

EndFunction


Draco9898

thanks kevin. Yea Stef, I haven't played with lists yet so I wasn't 100% sure what was happening.
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

Kman1011

Truly an awsome feat to have a 3d engine in PB. Hope it comes out in time for my next project starting in October 2007. ;D
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

kevin


  While the method this actually uses, is fairly difficult I guess (ie. all of the geometry is rotated/clipped/sorted & draw in PB code).   building your own mini 3D engine in PB1.69 and above,  is actually rather trivial now using Sprite Entities a perspective sprite drawing.   

  Perspective Sprite Drawing

  At some point i'll be releasing an trimmed downversion of the UW3D engine as a Slib for PB1.70.  Effectively this will give you a basic 3d engine (pretty similar to Dark Basic Classic) to play with.   

RavenVegetable

I know it's been a while since I looked over PB, but...software 3D. Jeez.

That's fairly awesome.

kevin

#28
Software 3D Render Engine Tech Demo V0.22 Update

  While picking through a list of old demos during a recent updating frenzy, this seemed like one of the most logical demos to rebuild in PlayBASIC V1.63h.   Since this type of demo puts great deal of strain on the PB runtime.  Each frame it has a mountain of vectex rotation / projection / clipping calculations to get through, not to mention drawing the scene at the end of it.   The while rendering uses built in features like  Tri / GouraudTri combined with the scene buffer for depth sorting,  everything else is just good old fashion PlayBASIC code.    

   The original port of this demo was to PlayBasic V1.05/V1.06  (two years ago),  the original code was written in DB about 2 years prior to that.   So it's old code and it shows.  While it's tempting to try and clean it up for users,  that seems like a lot of work for nothing (since PBFX 1.70 supports Direct3D!),  so rather i'm cleaning up the appearance.  Performance wise PlayBASIC V1.63h has enough code execution improvement to be able to do things like add  backdrop,   run it in higher resolution and increase  Z clipping plane distance.     Other cosmetics has have been smoothing the height map,  which removes the jiggered terrain appearance.  

   Anyway here's a few new pictures of this prehistoric demo :)...

kevin

#29
 Update V0.24

    Cleaned up the demo a little more and have added menu's (title/screen mode/world settings) and update some terrain tidbits. So it's faster again. Added a second mode to the terrain to check if brute force meshing is quicker (Ie. See Terrain Demo in your example pack), turns out it's not.. Since the original version picks the section of the terrain it projects. So size doesn't really affect it.