Author Topic: Freebasic 3d renderer using tinyptc  (Read 26514 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Freebasic 3d renderer using tinyptc
« Reply #60 on: November 13, 2006 »
ok, a bit more detail.

The objects I've done it with in that demo are the pawns, the sphere uses a similar method for reflections but the camera points the other way. The sphere can be pointed towards the camera but the pawn is pointed towards a pivot placed at the same height as the pawn but with the cameras x and z coords. That means i only have to set the texture coords once and don't have to recalculate each frame, with more complex objects you'd need to.
I then place a camera somewhere inside the object with the same orientation as the main camera (maybe back the camera up a bit and hide the object) and render with quite a wide angle which changes a little with the distance from the object to the main camera.
For the uv values I think (can't find the source atm and don't think i worked out the refraction) I just used the reflection formula (from some point along -z), normalised the vector then multiplied the x and y components by .5 and added .5 to bring them into the range 0.0->1.0 and used them for u and v.

EDIT:
I've used this a few times but always had to mess around with values with a bit of trial and error until i'm happy with it.
« Last Edit: November 13, 2006 by Stonemonkey »

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Freebasic 3d renderer using tinyptc
« Reply #61 on: November 13, 2006 »
Stonemonkey . . . I am not worthy - that is absolutely fantastic - I was gobsmacked - cool cool beans dude!

Have some karma for that!

Regards and appreciation

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Freebasic 3d renderer using tinyptc
« Reply #62 on: November 14, 2006 »
We had started to put a project together with this engine and it was looking promising, it's really nice to use it and behaves a lot like the BB3D command set, I hope that in the future that we can pick this up again and finish something with it. I'll give SM some karma for this too as he's been developing the techniques to do this since the Yabasic days a few years ago and it represents a lot of hard work.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Freebasic 3d renderer using tinyptc
« Reply #63 on: April 24, 2007 »
how exaclty does this line work?

Code: [Select]
#define alpha(s,d) ((((s and &hff00ff)*(s shr 24)+(d and &hff00ff)*(256-(s shr 24)))and &hff00ff00)or(((s and &hff00)*(s shr 24)+(d and &hff00)*(256-(s shr 24)))and &hff0000))shr 8

ive been trying to get a nice alpha in my softrender using it but it doesnt work the way im trying to do it is something like this *buckbuffer=alpha(rgb(r,g,b), *backbuffer) on every pixel transfer but my object turns black so im guessing im doing it wrong.
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Freebasic 3d renderer using tinyptc
« Reply #64 on: April 24, 2007 »
You need an alpha value in the source:

*backbuffer=alpha((alpha_value shl 24) or rgb(r,g,b), *backbuffer)

in this case, alpha_value should be a value 0-255.

When you multiply 2 8 bit numbers you can't have more than a 16 bit result so it's able to do the multiply on the red and blue bytes together without them interfering with each other which means you only have to separate out the green byte.

EDIT: the same idea can be used for shading.

Fryer.
« Last Edit: April 24, 2007 by Stonemonkey »

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Freebasic 3d renderer using tinyptc
« Reply #65 on: April 25, 2007 »
cool it works!

i have a bit of a problem though the white inmy object turns red and red gets filtered out?
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Freebasic 3d renderer using tinyptc
« Reply #66 on: April 25, 2007 »

oh.., really noce work man.  :)

I suggest that , you add a skelta animation to your 3D Engine.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Freebasic 3d renderer using tinyptc
« Reply #67 on: April 25, 2007 »
I'm not sure why that's happening nino but i just thought that there must be a better method you could use as the idea behind my code is to take 2 32 bit colour values to do the calculations whereas you already have them as individual r,g,b values and you're combining them with rgb(r,g,b) only to take them apart again to do the alpha.

Is your buffer 24 or 32 bit?  and what order are the bytes(colours) in?

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Freebasic 3d renderer using tinyptc
« Reply #68 on: April 25, 2007 »
its r shr 16 or g shr 8 or blue in that order i coded up something that works quite nicely today because like you said i wasnt using your macro to its full potential.

cheers anyway mate :cheers:.
Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Freebasic 3d renderer using tinyptc
« Reply #69 on: April 26, 2007 »
wow cant beleive I havent seen this sooner, really nice work Fryer, top quality rendering there as per usual ;D
Challenge Trophies Won: