Divide by depth for instant 3D

24 days ago by cm0002 to c/programming

When I first started working on games, I used high level frameworks that would give you a Camera that just kind of worked. But as I learned more and wanted t...
panda_abyss 16 points 24 days ago

This is a nice simple blog post, really enjoyed it

Despite knowing a lot of algebra it was nice to walk through a clear application in such a clean way

path: 0 25950623, hotness: undefined, score: 16, children: 0
Unpigged 9 points 24 days ago

Recommended read for everyone into computer graphics: David F. Rogers, Mathematical elements for computer graphics.

path: 0 25951878, hotness: undefined, score: 9, children: 0
Ad4mWayn3 8 points 24 days ago

Perspective projection formulas are a walk in the park until you need to rotate things and compose rigid transformations, you better know how to build those quaternions and matrices ;)

path: 0 25955199, hotness: undefined, score: 8, children: 3
Unpigged 2 points 23 days ago

You don't need quaternions for affine transformations.

path: 0 25955199 25969659, hotness: undefined, score: 2, children: 2
offspec 4 points 23 days ago

Does rotation not result in gimball lock without quaternions?

path: 0 25955199 25969659 25969945, hotness: undefined, score: 4, children: 1
Unpigged 2 points 23 days ago

It sure does but quake1 and quake 2 happened on matrices and Euler angles so there's a long way you can go before even thinking the letter q.

path: 0 25955199 25969659 25969945 25978668, hotness: undefined, score: 2, children: 0
Scrath 4 points 24 days ago

This is great and I wished I found it a week ago.

I have spent the last week building a basic 3D rendering engine in C, though I restricted myself to isometric rendering which I considered the simplest form to implement. Especially since trying to talk shop with ChatGPT on the topic usually lead to very complicated design recommendations that far exceeded the amount of features I actually cared about in my proof of concept (e.g. variable camera position, adjustable field of view and more)

Now I only need to figure out how to cull unwanted triangles from my loaded .obj files

path: 0 25952214, hotness: undefined, score: 4, children: 7
Valmond 6 points 24 days ago

Check out cross product & dot product, basic stepping stones for 3D rendering (and culling). Then quaternions & lerp for rotations (you don't want gimbal lock).

Good luck, it's loads of fun (IMO)!

path: 0 25952214 25953523, hotness: undefined, score: 6, children: 0
AngryPancake 1 point 24 days ago

Do you render with GPU or CPU? In any case, sort the vertices by distance and it should come together for you.

path: 0 25952214 25952689, hotness: undefined, score: 1, children: 3
Scrath 3 points 24 days ago

Just simple CPU calculations. I'm basically just mapping my points from 3D space to my 2D screen and drawing lines between them. Not sure if rendering engine is actually the correct term for what I am doing. The word engine kind of implies a larger scope than I am going for.

Of course, I had to massively complicate this for myself by setting out to use this for displaying basic wireframe graphics on embedded systems... Basically I currently need to figure out how to reduce my triangle based objects to ones that only have the silhouette lines or that only show triangles which are actually visible, except my line drawing setup does not allow for partially obscured faces as is.

path: 0 25952214 25952689 25953347, hotness: undefined, score: 3, children: 2
AngryPancake 1 point 24 days ago

Sounds great! I would still call it a rendering engine, I don't think it matters how large the scope is. It looks like you're on a good path forward, I'm sure you'll get it soon! Don't go too crazy on the optimizations is my only recommendation.

path: 0 25952214 25952689 25953347 25955012, hotness: undefined, score: 1, children: 0
KeenFlame 1 point 22 days ago

It's called projection, and culling, in that order if you want to search for help. But I would have built a ray marcher instead as that is more fun and useful if you are doing it to learn

path: 0 25952214 25952689 25953347 25995900, hotness: undefined, score: 1, children: 0
Unpigged 1 point 23 days ago

Writing rasterizer by hand is an incredible fun exercise. Get some basic reading on the graphics, don't do gpt first. You will never see games as you had before.

Culling faces is simple: you have geometry in camera space. Take a dot product between a surface normal and view direction vector and if it's negative then the normal is pointing away from you and the face is invisible.

Proper techniques with occlusion and stuff are more complicated, such as painter algorithm or z-budgeting or others

path: 0 25952214 25969680, hotness: undefined, score: 1, children: 1
Scrath 1 point 23 days ago

Thanks for the tip. I'll have to try that out later when I have time.

After noticing that ChatGPT had quite a different vision than I did, I've mostly been brute forcing the projection math by drawing a cube on paper and seeing how the 3D coordinates are transformed to 2D space. The only useful thing it actually helped me with was figuring out which 3D file format was most compatible for parsing into my objects. It tried writing a parser for that format, which I looked at and then decided to do it myself with less lines of code ;D

path: 0 25952214 25969680 25971328, hotness: undefined, score: 1, children: 0
FishFace 4 points 24 days ago

I learnt this myself making visualisations in Winamp :)

path: 0 25953225, hotness: undefined, score: 4, children: 0
super_user_do 1 point 24 days ago

this thing looks so cool!

path: 0 25961963, hotness: undefined, score: 1, children: 0
programming
programming

@programming.dev

login for more options
28830
3724
3332

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev


go to feed...