• Welcome to Dark Bit Factory & Gravity.
 

Freebasic 3d renderer using tinyptc

Started by Stonemonkey, May 13, 2006

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stonemonkey

#60
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.

DrewPee

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

Shockwave

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:

ninogenio

how exaclty does this line work?


#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:

Stonemonkey

#64
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.

ninogenio

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:

Emil_halim


oh.., really noce work man.  :)

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

Stonemonkey

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?

ninogenio

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:

Tetra

wow cant beleive I havent seen this sooner, really nice work Fryer, top quality rendering there as per usual ;D
Challenge Trophies Won: