Page 1 of 5

Making a 3D (viewport-ish)/real-time renderer.. from skratch

Posted: Mon Apr 30, 2007 10:13 am
by arneoog
Intro, and stuff
I am really trying to programme a real-time renderer.
At the moment I'm just at still frames, and only drawing lines :P
And it's, at the moment, written in PHP :lol: because that's the language I know best..
But when I've got it working at a per pixel level, I will make it into C++

Now, it's this per pixel part I'm having problems with.. :? (If that's actually what I must do)
I can't find good enough info on Z-buffering or just perpixel drawing.
How to scan the image, set color where there is tris, find depth, ect..


The renderer, so far
It isn't all that much.. It decodes OBJ files, projects and transforms them,
then it just draw lines :)
(This is what I don't want it to do, eventually..)

>>Link to the "renderer"<<
(or what ever you want to call it, heh)


Url variables:
  • f - [file] - you can use all the files in the /obj directory (/?f=suzanne)
    s - [size] - this changes the size of the object (/?s=4)
    rx - [rotateX] - this changes the x rotation of the object, in degrees (/?rx=45)
    ry - [rotateY] - this changes the y rotation of the object, in degrees (/?ry=30)
Example using all the variables:
/?f=srr&s=50&rx=40&ry=-20
in action


Some questions
Okay.. How do you do the Z-Buffering or do anyone know an excellent tut on how to code a simple one?
And How to use this Z/pixel info for materials?
And so on.. :)

I don't need full anweres on everything, but tips and such would be nice :)
Probably after understanding the Z-Buffer and made it, I will know better how to do the rest.. :P


Cheers!

Oh, sh*t! This got long, hehe..

Posted: Mon Apr 30, 2007 7:00 pm
by daniel_nieto
it would be very interesting to see indigo's competition, (just kidding, or it will be?), wooow, man, i really want to do a render from scratch in the future too, maybe in java, like kerkythea, or some... well, at least it would be easy to emmigrate to C++ from php, since their sentences are very similar... i love php! unfortunately, i cant help you with any of your Q's, sorry, keep on the good work!!! Cheers!

Posted: Mon Apr 30, 2007 8:23 pm
by manitwo

Posted: Mon Apr 30, 2007 11:50 pm
by arneoog
daniel_nieto, Thank you! :)

manitwo, Yepp, I've seen them.. but they are way to advanced for me to
understand how it's made, but I'm not going to make a raytracer anyways :P
If I've understood the meaning of the words, biased and unbiased..
This will be a very biased renderer :D

...

Posted: Tue May 01, 2007 2:00 am
by zsouthboy
Z buffering is simply storing an extra buffer, then comparing your current pixel's "z" value with the corresponding spot in the buffer. If the current z value is closer to the camera than the current z buffer value, the pixel is written to the framebuffer, and the z buffer is updated with that just written pixel's z value.

It's a way of preventing yourself from rasterizing tris that are are going to end up being occluded in the final render. That's all. Nothing special.

:)

Posted: Tue May 01, 2007 2:29 am
by Kram1032
Raytracing = biased form of Pathtracing, as far as I know...
It's rays, that are shooten ONCE, and then get redirected with the camera.
Mirrored surfaces just are bouncing a limited time (very few, like between just once and maximally ten times...)
Diffuse mats wont have ANY effect of the "Neighbour" material. A simple white diffuse wont get redish, when there is a red diffuse next to it.

This can be done in realtime.

Realtime-fakeSSS is done a quite nice way, as far as I know:
It uses blurmaps, that define, how much the light gets blurred and it uses the same ray, that is reflected AND goes throught the surface, instead of beeing reflected hundrets of times...

_______
More or less guessed ;)

Posted: Tue May 01, 2007 2:43 am
by arneoog
heh...
I know how a Z-Buffer works, but not how to code it.. :S
Or how to get a script to understand that it's hitting a triangel..
This is the part I need help with..
Is it done on a par triangle level, or the whole scene/model at once?

Arg.. It's hard to find the info I need, have been searching for days now :(

Posted: Tue May 01, 2007 4:16 am
by zsouthboy
arne:

I don't understand the touble you are having with z-buffer:

*goes to check the link to your current version*


Oooooooooooooooh. Okay.

Right now, you're not really doing rasterization. You're simply drawing vector graphics (using a drawLine function or some sort probably?) with no care for occlusion or material color.

To make the move to rasterization, you have to do more work :)

http://en.wikipedia.org/wiki/Rasterisation

Posted: Tue May 01, 2007 4:24 am
by arneoog
I knew I had to do something like that! :D
Thanks for the link, I'll read my eyes out (almost) :P

I wrote that it's just drawing lines, hehe :)

Thanks!

Posted: Tue May 01, 2007 4:36 am
by zsouthboy
I didn't mention it, but you are doing a good job :) You've already figured out perspective and transformation.

If you need some more help feel free to ask.

Hell, I have to be honest, I entertained the idea of creating a renderer in ASP, just to play with. Never got around to it.

EDIT: I'm going to try to find the name of the book that finally made rendering "click" in my head. It goes, step by step, through how to make a software scanline renderer, explains lighting and how to implement it, etc. It's all in C or C++ IIRC.

Posted: Tue May 01, 2007 4:44 am
by arneoog
Sweet!
Thank you, zsouthboy! :D :D
(I doubt that's your real name, but whatever..)

I like images :)
Image
Hehe..

EDIT: But I still don't understand how to code it :P :lol:
I'll read and search more...

Posted: Tue May 01, 2007 7:03 am
by zsouthboy
Here you go, straight from SIGG:

http://www.siggraph.org/education/mater ... lygon1.htm

then

http://www.siggraph.org/education/mater ... lygon2.htm

That should be exactly where you're stuck.

EDIT: Real name is Chris, btw. "zsouthboy" is.. a long story. Don't ask :)

Posted: Tue May 01, 2007 7:25 am
by arneoog
Yay! :D
That's exactly what I needed! ..I think :P

Thanks, Chris! :D

Posted: Tue May 01, 2007 10:02 am
by arneoog
!!!WARNING: MAY CONTAIN BAD LANGUAGE!!!


SWEET FUCK, I MADE IT!!! :D
IT'S DRAWING TRIANGLES!!! :D :D :D


Okay, now I'm happy. :P


EDIT: it's alittle slow.. but here is a small model as a preview :P
http://roxworth.elqx.com/obj_viewer/?f=box2&s=10

Posted: Tue May 01, 2007 10:04 am
by Kram1032
:D