Friday, May 13, 2011
2-D meets 3-D
i think it would be safe to suggest that my favorite class was my digital compositing class, although a more accurate answer is probably whatever class's deadline wasn't looming over my head like the sword of damocles at any given moment (which effectively rules out my undergrad 271: programming for dummies class, but more on that later.)
digital compositing, which i signed up for at the very last minute because i didn't know it existed, was really interesting nonetheless. the class revolved around inserting ("compositing") images/objects into a 2-D image. this is essentially beginning off that path that culminates in computer-generated monsters and alien invasions in every movie coming out between now and the end of october (after which time the remainder of the year is filled with so-called "oscar fare", movies that involved no apparent c.g. and instead have to rely on things like being "critically acclaimed.") in january, i had no clue at all how to do anything like that. now i have a bit of a clue, but don't expect to see my name in the credits of the next michael bay movie anytime soon (or at all, for at least two reasons.)
much of the first half of the semester was taken up with lectures consisting of our turkish professor explaining how computers read color information and writing equations that soon left me a little baffled. but i miraculously drew in photoshop a box on a pile of other boxes. i was so seriously dang proud of myself.
the rest of the assignments just got cooler.
there were four variations on assignments for our second and third project. mine was to take this picture
and have an object fly through it. it had to cast shadows correctly and the lighting had to match.
ok...... so, where do you start?
ima tell you.
along with this picture we were given a few more helpful things. we were given measurements, such as the dimensions of the box, the various distances of the camera from the box, how high off the ground it was, it's angle of declination, and this other photograph:
well, yeah that is pretty great, actually. that little peg is a pretty good indicator of how the light is, based on the shadows it casts. well come back to this in a bit.
so, if we're going to have an object fly through here, we need to build a 3-dimensional scene to put over this.
after an hour or two of frustrations and discovering, it looks kind of like this:
there are the basic objects that will need to receive the shadows: a plane for the ground, another for the wall, and a simple cube for the box. and i've set up some distance locators to ensure that my camera is the same height as the real camera was, so that the perspective will be the same, too.
since the real wooden box has many different sides and faces that will all receive shadows differently, i needed to model a box that looked just the same. and so i did. you can see the wire frame of my box against the background image of the real deal.
if you were able to move around and look at it, you'd see that it's not a perfect shape. i got it looking pretty close but after a point just had to start grabbing edges and corners and pulling them to where the looked right. as my professor at byu said, "in computer graphics, if it looks right, it is right." and if you could change your viewing angle a bit here, you'd see some definite skewing going on. but you can't, so we're good.
i should note here that this was not the method my teacher intended for us to use on this. he expected to do it in a way that didn't involved modeling the whole complex box, which he felt was much simpler. i didn't realize this until later on in the semester; i was just doing what seemed the easiest to me.
so, we've got a big fake box. great. here's where it gets kind of sneaky. in cg, the look/texture of an object is called its "shader." and you can apply a seemingly limitless variety of shaders using all manner of voodoo that i really don't understand very well yet (hopefully that will change in the coming summer months.) but one of the sneakiest is the "use background" shader. i'll let you figure out what that does.
"ideally", and that's a very unpredictable term around these parts, the box will render essentially invisible, since it looks like whatever is behind. but you can still tell it to receive shadows (as well as a myriad of other options, the joys of which i will expound upon in coming posts.)
at any rate, i'm off to a good start here.
next up is getting the lighting right.
remember that picture of the little pink peg casting a nice shadow on the white matte? well, now that i know kind of how to place objects in the scene, it's time to make my own peg and try to get it to cast an identical shadow.
ok.... let's look at the positive here: my peg's shadow is similar-ish to the real shadow. definitely needs some fill light so that the shadow isn't pure black. but we're getting there.
the problem with this scene, in case you didn't notice, is that half it is a jagged black mess.
i spent a few hours pouring over every setting, trying to find what 0 had been changed to a 1.
i tried using a different renderer and got this:
i guess that's better.....? now it just looks like a beam of dark matter from some super villain cut through my scene.
eventually i found the (embarrassingly blatant) problem and everything was peachy.
good. great. i got an image that looks like i stuck something into a real scene. never mind the still-very-too-dark shadows. i'm celebrating my accomplishments, not my faults.
i think it's time for a dress rehearsal, to see how it all looks together, magic green box and object and all.
heh. whoops. yeah, i need to take out my peg and, more importantly, turn off "reflections" on all of my crafted green objects. this is very encouraging, even if it does look like it just rained out here.
whomever was closest to me got a high five.
i mean, that's pretty cool.
yeah, pretty slick.
put it all together with its simple animation and it looks like this:
excitedly grab your nearest friend, pull them over to see your little slice of awesomeness, and catch the next bus home, telling yourself that you've done enough good work for today that programming can wait until tomorrow.