Forum archive
3d object formula + rendering
- Hello Everybody ! ;D
I have a question about general 3d programming :
Imagine we have a object defined by a 3d formula ex : x^2 + y^2 - r = 0 (a cylinder)
Once i have this equation, what is the simpliest way to render it directly on screen (i mean without too much code, brutforce approch no mather the time it will take)
Currently i know two techniques:
- raytracing (who need to solve equation between a ray and object equation) (but give best result) ::)
- voxels (wich need lot of code but faster enough for realtime) (quite blocky, not what i'm searching)
i know its possible to generate a random x,y,z point and check if its in the equation (with some error level eg : >-0.1 - <0.1 ) but its really TOO much brutforcing and will took years to have a decent result
Also for lighting :
From the equation itself, is it possible to determine (i mean to compute) directly a equation that will give the normals???
eg for the cylinder ( x*x + y*y - r = 0 ) => normals (x,y,0)
the idea it to take the normal of the object and the normal of the light (which will also be defined by a 3d formula) compute them and then make current object point brighter or darker which the result Re: 3d object formula + rendering
I think voxels would really work for this. It wouldn't be much code (you can probably do something like that within a 100 lines of code).
Also, voxels don't need to be blocky. It's an issue between data size and resolution. In theory you could render each voxel at a size of 1 pixel.
I think it should be doable to render a voxel block between 2 and 4 pixels, that would look really decent (at least for a realtime).
please note: when I say 'rendered voxel' I mean a square to represent the voxel. Not a 3d cube like in Ken's demos. I don't know the preformance of
real 3d cubes.- If you don't care about speed (or memory), then the voxel approach is certainly the easiest. What isn't so easy is optimizing the voxel approach. Fortunately for you, you don't have to - I've already done it for you .. that is, if you're satisfied with Evaldraw's voxel mode. Here's a simple cylinder script to get you started:
(x,y,z,&r,&g,&b)
{
r = 128; g = 128; b = 128;
return(x^2 + y^2 < 1^2);
}