freebasic.net Forum Index
FreeBASIC's Official Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in

3D engine
Goto page 1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    freebasic.net Forum Index -> Projects
View previous topic :: View next topic  
Author Message
Stonemonkey

PostPosted: Jun 28, 2005 22:58    Post subject: 3D engine Reply with quote

A small demo/test of a software engine i've started re writing in freebasic, got a fair bit of work to do. Sorry no source atm.

http://freespace.virgin.net/r.fryer/soft3d_7.exe
 
Back to top
View user's profile
SotSvart

PostPosted: Jun 29, 2005 0:57    Post subject: Reply with quote

Looks nize! Got abit dizzy there for a second
 
Back to top
View user's profile Visit poster's website
v1ctor
Site Admin
PostPosted: Jun 29, 2005 6:16    Post subject: Reply with quote

Great, the textures seem perspective-correct, it runs fast enough here, a 1.8 Athlon.. i guess you used 90% of inline asm anyway. Btw, why not hardware accel, because the challenge? ;)
 
Back to top
View user's profile Visit poster's website MSN Messenger
D.J.Peters
Guru
PostPosted: Jun 29, 2005 18:11    Post subject: Reply with quote

(sorry bad english!)


Hi Stonemonkey,
i write an software shader too i was intersting how you make the h-line loop i have tryed read your code with an disambler (from nasm) and it seams that you are use th single data type in the loop. You can speed it up if you are use an fixed point data type. the result can be an power of 2.

80 fps > 160 fps

currently i'm writing the color spotlight part. will your shader support color lightning too?

Good work Joshy
 
Back to top
View user's profile Visit poster's website
Hexadecimal Dude!
Sr. Member
PostPosted: Jun 29, 2005 18:27    Post subject: Reply with quote

well, it completely froze my (rubbish) computer, had to cold boot it!
ah well, it was worth it for the first frame ;-).....
 
Back to top
View user's profile Send e-mail AIM Address Yahoo Messenger MSN Messenger
Stonemonkey

PostPosted: Jun 30, 2005 16:47    Post subject: Reply with quote

HI,

Sorry about the freeze hexadecimal dude, i've not really got any explanation for that.

D.J.Peters, I use singles for interpolating U/Z,V/Z and 1/Z. I've tried using fixed point for those but 32 bits doesn't quite give enough accuracy with the way I do the perspective correction although i have played around with using an extra integer for the z buffer instead of the single which has improved things a bit.

v1ctor, been asked that a few times and tbh don't really know, probably the challenge and the satisfaction when it's all finally working. The vertex/shading calculations and some of the tri drawing routine are done in asm but i think i need to learn more about optimising asm.

btw, what's the best way to clear an area of memory in freebasic?

Sorry about the dizzyness Sotvart.

EDIT:
Hexadecimal dude, i think i can explain the freeze. I use a method of keeping the control of programs at a constant rate independant of the framerate but it can sometimes get stuck in a never ending loop if there's too much for it to do or if it's run on a slow pc, sorry about that.


Last edited by Stonemonkey on Jun 30, 2005 18:03; edited 1 time in total
 
Back to top
View user's profile
DrV
Site Admin
PostPosted: Jun 30, 2005 18:00    Post subject: Reply with quote

To clear an area of memory, you can use the built-in CLEAR, or libc's memset(), or write your own (faster :) routine. For example, if you know that your memory area is always a multiple of 4 bytes in length, you can do a very fast rep stosd:
Code:
Sub memset_dword(Byval addr As Any Ptr, Byval fill_with As Byte, Byval num_bytes As Integer)
asm
  Xor eax, eax
  mov al, [fill_with]
  mov ah, al
  mov bx, ax
  Shl ebx, 16
  Or eax, ebx
  mov ecx, [num_bytes]
  Shr ecx, 2
  mov edi, [addr]
  cld
  rep stosd
End asm
End Sub

'' example usage

Dim mem As Any Ptr
Const mem_size As Integer = 1024

mem = allocate(mem_size)

memset_dword(mem, 255, mem_size)

deallocate mem
 
Back to top
View user's profile Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Stonemonkey

PostPosted: Jun 30, 2005 18:32    Post subject: Reply with quote

Thanks DrV.
 
Back to top
View user's profile
SotSvart

PostPosted: Jun 30, 2005 19:45    Post subject: Reply with quote

Quote:
Sorry about the dizzyness Sotvart.

Hehe no need to say sorry, good demos should make you dizzy =)
 
Back to top
View user's profile Visit poster's website
jupiter3888

PostPosted: Jul 01, 2005 1:43    Post subject: Reply with quote

hey nice work there. i felt the need to duck on several occasions when a block was heading straight for me! and thats a hard feeling to replicate in software.
it runs very well on my intel celeron 2.8 GHz, just to let you know. nice smooth animation and movement.
 
Back to top
View user's profile Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Stonemonkey

PostPosted: Jul 01, 2005 9:11    Post subject: Reply with quote

Thanks jupiter.

v1ctor and D.J.Peters, thought you might be interested so here's the source with only the buffer clearing written in asm, it still runs pretty well. I've also removed the delta timing so it wont have problems on slower comps other than just running slow

http://freespace.virgin.net/r.fryer/soft3d.bas
 
Back to top
View user's profile
relsoft
Master
PostPosted: Jul 02, 2005 3:51    Post subject: Reply with quote

Nice!!!!!
 
Back to top
View user's profile Visit poster's website Yahoo Messenger
v1ctor
Site Admin
PostPosted: Jul 02, 2005 22:41    Post subject: Reply with quote

Cool, not bad for an almost "pure" FB implementation, i thought you were using fixed-point and interpolation inside the inner-loop every n-texels, what could make it way more complex and look not too great, but at least twice as fast.

I changed it to 320x240 and got dizzy after 3 secs ;). Btw, to compile with the latest FB changes, the pointer operations must be changed.. "p += expr" is now like in C to make type-casting supported.
 
Back to top
View user's profile Visit poster's website MSN Messenger
D.J.Peters
Guru
PostPosted: Jul 04, 2005 7:07    Post subject: Reply with quote

(Sorry bad english!)

Yes and without fixedpoint math you can speed up the 3 add parts too.
Code:
uc+=ustep:vc+=vstep:zc+=zstep

in assembler
Code:
fld [uc] '1
fadd [ustep] '3
fstp [uc] '2+1!!! broken pipeline
fld [vc]  '1
fadd [vstep] '3
fstp [vc] '2+1!!! broken pipeline
fld [zc] '1
fadd [zstep] '3
fstp [zc] '2+1
 

This will use 20-21 cycles
Code:
fld [uc] '1
fadd [ustep] '1
fld [vc] '1
fadd [vstep] '1
fld [zc] '1
fadd [zstep] '1
fxch st(2) ' 0
fstp [uc] '2
fstp [vc] '2
fstp [zc] '2
 

and now it use only 12 cycles.

I must test it with AMD and Intel too

Joshy
 
Back to top
View user's profile Visit poster's website
Stonemonkey

PostPosted: Jul 04, 2005 9:30    Post subject: Reply with quote

Ah, thanks D.J.Peters. As i said before i need to look into how to optimise asm and that's a start.
 
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    freebasic.net Forum Index -> Projects All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7  Next
Page 1 of 7

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



sf.net phatcode