Rendering a car with my own ray-tracer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
writing a ray tracer is not that hard i mean here's one written in c in under a hundred lines the thing is the simple ray tracers usually only support spheres and basic materials what if you wanted to render something more complicated like a phone or a car yeah how about a car see that's definitely not a sphere today we're not writing a raytracer okay that's easy we're creating art all right we need a car hold on hold on see we don't we don't do things the intelligent way around here i i should have specified that my apologies see everyone knows you can't flex by using other people's work disgusting obviously i'm gonna make my own see this is this is very personal for me um i was i was hurt before when i was when i was just a young bro in my early teens i downloaded blender and the first thing the first thing i tried to do was model a car i was a little bit ambitious apparently i was stupid i thought it would be easy and i failed but then i grew up i got knowledge and here we are doing it again [Music] but in the end i i failed again i don't know what to say i mean i i think i'm i think i'm just gonna give up wrong we don't give up around here okay i forced myself to do it again i threw out my old model because it was garbage like it took i just want to make it clear it took a long time took a long time to make this but it's just it's bad it looks like a deflated fish i was like no i am not releasing this we're going to do this all over again i learned from my mistakes and i came up with this foolproof method of modeling cars alright so the the first step you block out the basic shape it's sort of like sketching but in 3d don't overthink it just do it slowly refine this shape by adding more geometry and as you add geometry make sure to keep the topology nice and clean not like this once you have a pretty decent shape apply a subdivision surface modifier now we have a bunch of separate parts that need to be merged use these parts as guides and then draw a better mesh on top this is called retopologizing it's pretty common in character design and kind of just 3d modeling in general throughout this process also make sure to mark the lines of the car's body panels this helps both with lining things up with the reference but now we can use them to actually draw the body panels fill in this geometry adding smaller details and remember that all of this new geometry sticks to this base mesh that we designed earlier so everything stays perfectly smooth even as we add more complex geometry once all the body panels are done fill in the smaller components of the car which is basically just a bunch of modeling none of the parts on their own are particularly difficult and about five and a half years later something like that you will have this car model for those that are wondering this is a 1962 maserati tipo151 i chose it because it looks unusual and i like unusual things it has character to it only a few were made for racing back in the day and i thought it would be cool to modify this design slightly to make it into a road car i also couldn't find any models of this car online and that means that this is the best model of this car ever made so obviously congratulations to me you know you know how it is all right so we have a car model now that's that's cute and everything but we need to render it i did write a new beretracer back in 2019 and i did get some good results from it but it's missing some parts we have no ui so how am i gonna flex my insane programming skills with a command line program everyone knows this is not possible and also from a technical perspective we're missing important things like direct light sampling bump mapping and procedurally generated noise i pretty much need all of these things for this particular scene we do need to have priorities though flexing always comes first so we do need a ui in all seriousness though a ui is pretty useful because otherwise i can't see the progress of a render and i can only see it when it's done which is pretty annoying there are some pretty good c plus plus ui libraries on github though and this time i was going to do things the intelligent way i was i was there i went to github i was just about to clone the repository and i don't know what happened like my internet just stopped working my router was reduced to atoms in front of my eyes it was really it was quite something and clearly the only thing that can be done in this case is i just had to make one from scratch so that's that's what i ended up doing luckily anyone who isn't new to my channel knows that i am working on reinventing a different wheel the game engine i have my own game engine and i thought this would be a good time to test it out so i use it to make a simple ui first i cloned the template project i made then i did some coding off-camera and i made this programming language it's it's really not that important oh oh i didn't mention that okay so basically i wrote this programming language slash specification language thing and i call it piranha it actually works okay to be fair it's it's basically it's a node-based programming language and it's very confusing but it makes sense to me and and it has syntax highlighting so you know yeah exactly exactly the purpose of it is to specify node-based materials and systems similar to a compositor but in text form in many ways i find this easier than dragging and dropping nodes in blender anyway i set this up to recompile automatically when it finds that my source file has been changed as you can see here's a simple hello world program this is not a sequential programming language though you can do some really cursed stuff like this where the variable comes after its usage it's not really a variable but anyway i'll spare you the details it's a weird programming language i integrated all this with my path tracer and got it to display the output of the path tracer in real time now as you can see it looks pretty ugly but i spent some time and i made it look good you know for flexing purposes now this preview window is totally generic you can set it up to display anything you can preview colors images path tracer outputs the results of image transformations etc these also all update in real time and just as an example i set up this basic piranha program to process an image basically it removes the blue background behind this frozen dairy product and displays the result it's groundbreaking i know i actually find this more intuitive than working with other visual image editing tools so adobe please dm me on linkedin or something and we can talk about licensing after this video of course all right we need a few more things we need procedural noise which is useful because you can apply a texture to an object without going to the effort of generating texture coordinates so the value of the noise map is entirely determined by position another very important thing that we need is direct light sampling now i won't talk too much about this but basically it just makes things fast the general idea is as your path tracer is generating a path through your scene at each vertex you can directly sample every light source instead of relying only on the end of your path this dramatically improves performance by essentially reducing noise as you can see without direct light sampling it would take a few minutes just to see if your materials look decent which is pretty pathetic the final thing that we need in order to get that blender look is something called tone mapping if you were to directly map the output of a path tracer to rgb so for example let's say your path tracer outputs a light intensity values between 0 and infinity technically and you clip that range between 0 and 1 and then map that to between 0 and 255 like you would find in a 24 bit image it's gonna look pretty bad trust me okay it looks very 2005 and we've come a long way since then the trick here is that most cameras and your eye can cram a lot more dynamic range without clipping and they can do that because their response is not perfectly linear so this has the effect of compressing a much wider array of intensities into a smaller range i implemented two tone mapping functions one is aces which is commonly used in cinema and the other is hable tone mapping which is commonly used at video games anyway alright we're done now all we have to do is translate these blender materials into piranha nodes for the most part this is a fairly straightforward process i made sure to implement all the nodes that i needed in piranha so i don't have to take any shortcuts just copy them right over from blender the first renderer was it was okay but i didn't really like the glass because it looked a little bit too perfect this was because the entire scene was kind of unrealistic in the sense that the studio was basically floating in the vacuum of space any real studio would have some light leaks or background reflections and this background light would reflect off of the glass giving our eye a clue that something is actually there so i hacked a basic environment map in to deal with that and here you go here's the final image it's basically the same one that was in my thumbnail i did about 16 000 samples per pixel and the reason why it had to be so high is mainly because of the interior rendering anything behind glass complicates things a little bit and there's still some noise on the inside but for a uni-directional path tracer it's actually not that bad just as a comparison here is the output from blender now they're not exactly the same because the geometry is a bit different but the quality is comparable i prefer the tone mapping in my ray tracing over the one in blender because it doesn't over saturate bright areas and that was one thing that i actually didn't like very much in the initial blender render that i did maybe i was doing something wrong i don't know blender's path tracer which is called cycles by the way for anyone who doesn't know is also quite a bit more efficient it's about 30 to 40 percent faster depending on the scene and based on some profiling that i did and digging around in blender's code it's probably because it uses intel's embry library for spatial partitioning i might look into using this in the future but i didn't really need it for this project so i didn't bother just as a final flex i wanted to show what can be done with these procedural materials i rendered an alternate version with racing stripes and these racing stripes were actually generated totally procedurally so they're not textures the code to generate them is pretty simple it's basically just two rectangle functions and the input parameter is the z-axis and that's basically what mixed the red and white colors now i know that some people out there don't really get the point of this you may be thinking it's cool and all but aren't there more efficient ways of rendering an image well yes obviously there are but i don't do this to be efficient i do it because i enjoy it and it really is that simple i also learned a lot from this project and i'm definitely not an expert in case that wasn't obvious a developer who specializes in graphics might watch this and think i'm a total noob but that's fine everyone starts somewhere and for me the easy way to learn something is to just do it the hard way alright that's pretty much all i have for today thanks for watching everyone all of the code for this project is open source obviously and it's on my github the link is in the description i should note that it isn't really ready for public release but after this video is released i'll focus on polishing the code and getting a version out that you guys can try alright bye for now and have a great day
Info
Channel: AngeTheGreat
Views: 263,668
Rating: undefined out of 5
Keywords: 3d, blender, c++, coding, coding adventure, dev log, devlog, game engine, game level design, gaming, programming, software development, ray-tracing, ray-tracer, path-tracing, path-tracer, from scratch, car modeling, car modelling, blender model, blender modelling, blender modeling
Id: 8liHiCNM4iU
Channel Id: undefined
Length: 13min 52sec (832 seconds)
Published: Fri May 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.