Placeholder Image

字幕列表 影片播放

  • All right, Welcome to lecture nine of G D 50.

  • Today's topic is dread halls.

  • So last week we ventured into Unity, our first foray into three D and not only three D, but also just getting our hands around, um, our heads and hands around the Unity Game engine, which is among unreal and others sort of the most popular game engines and use for to D and three d games.

  • Um, and last week we did sort of, ah, 2.5 d style helicopter game whereby everything wasn't three D, but we were still aligning things based on just two axes.

  • The X and A y, I believe possible dizzy and why I don't remember.

  • But two axes versus three axes today will actually be diving into using all three axes available, twisting 93 d in the context of a game called dread halls.

  • And so a dread halls is is a V.

  • It was a PR game, actually, the first of the our game that I ever played on the Oculus.

  • The Gear v.

  • R.

  • Simpson giv e r.

  • And it puts you in sort of this dark and eerie three D maze where you don't really know what's going on, and you can go around and get collectibles and encounter creatures and stuff as you can see in the bottom.

  • Right?

  • Screenshot there.

  • Um, today's examples gonna be a little simpler, but it allows us to explore things like procedural maze generation and, um, first person camera controls.

  • So last week, recall we were using sort of a 3 1/3 person camera whereby we were sort of far back on the scene today will actually be using a first person camera where the camera is effectively our eyes as if you were walking around in the maze ourselves.

  • Unfortunately, we won't be using a V R demonstration this week, but next week I hope to put together sort of a V R sampling.

  • Using this projects, we can see how this works in V R.

  • And how Unity's Toolkit works in V.

  • R.

  • So some of the topics will be covering today.

  • We'll be talking about texture ring.

  • So recall last week the helicopter and all of the items in our game where just sort of flat colors they didn't really have any texture associated with them.

  • We'll talk about how to assign textures to materials and how to apply those materials to objects.

  • In our scene, we'll talk about materials and lighting.

  • So not only materials, but also the different kinds of lights that unity supports and a few details about those we'll talk about again three d mais generations So we'll have a simple but effective algorithm for creating.

  • Um, a three D data structure trip is in our level, as opposed to previously where we had just a, you know, a tile map that we could generate to give us the appearance of walking around in some sort of two d world.

  • Now well, actually perform a similar operation on data to de Array.

  • But we'll take that arraign well, actually create three D blocks and create a maze that we can walk through in three D space.

  • Um, which is kind of fun and interesting.

  • Last week we only had one scene in our game.

  • So which was just a place seen.

  • And even though we had sort of like a game over state within that scene, we didn't transition between scenes.

  • We just sort of reloaded the same scene.

  • Today we'll have a title screen and a place scene.

  • Which sort of, um, is an evolution of the idea that we had in love to D, where we had a state machine that was governing our entire game in terms of the different states that we could be in, whether it was the title of the game over the place, state and so forth.

  • Unity does the same thing with seen objects, which are effectively a snapshot of ah Siri's of game objects aligned in a particular way.

  • In the editor, we'll talk about fog and also global lighting and certain other things that allow us to create a atmosphere conducive to the sort of feel that we want to get in our game today, which is sort of creepy and eerie.

  • And lastly, when we talk about how to create you y elements in the game, we'll talk about unity to D.

  • It's canvas object and text labels and some other things and how those are operating Um, which is sort of two sides of the same coin.

  • Unity three D also comes bundled with unity to D, a set of tools used to make not only to two games, but also to d interfaces that you can apply to your three D games.

  • So first a demo.

  • Now, I've been sick for the last week, so I'm not going to, uh, ask for anybody to come up in demo just because I don't want anybody else sick.

  • So I'm going to just go ahead and show, um, just this lecture, the game that I put together for you.

  • So here I have two scenes noticed here.

  • I have a title scene and a place seen him in the unity editor.

  • Right now, I'm gonna load up the title scene here, which I've done, and then notice that it has sort of a game to you in a scene view.

  • I'm gonna hit play, gonna make sure that it's set to maximize which it is.

  • And so we have sound here.

  • So we should hear audio and hit play and notice that we have sort of like this and being creepy music track playing.

  • Um, we have a very we could have easily done this in love to D.

  • This is just a black screen with two, uh, text labels on it.

  • And this is done with Unity's two d.

  • U.

  • I.

  • Tool kit.

  • And so it says it tells us to press, enter.

  • So if I press enter, we instantly get teleported into kind of like this maze, this creepy looking maize, and so I can walk around in this maze and there are a few things going on.

  • So, anybody can anybody tell me some of the things they notice about the scene, But what jumps out of them, what are some of the elements?

  • If you were to put this together yourself, where would you start?

  • What are the pieces that we can put together here?

  • Yes.

  • Yep.

  • There has to be a ground that you can stand on.

  • And there is So we're generating, uh, not only walls in our scene, of course, but we need a ground to sit in an office.

  • And also, if you look up top, it's kind of difficult to tell, but we also have a ceiling so ground in the ceiling and walls.

  • Some kind of lighting.

  • Yes.

  • Um, And so in this case, we're actually using ambient world lighting as opposed to having a light source.

  • So we'll take a look at that.

  • Last in last week's lecture we used for two weeks Prior is lecture we used a directional light object, but in this case we have no lights in the scene.

  • We're actually using Unity's World lighting, which will take a look at soon.

  • Um, when we walk around knows that I can move my where my camera's looking with my mouse.

  • So we're actually controlling the camera with a first person controller in F PS controller, which is actually a component that unity provides to you and then notice eventually.

  • If we keep exploring the maze, we come across this little thing here, which is a sort of a pickup, and when we pick this up, we get sort of like this piano weird, creepy piano sound and in the scene reloads, um, anybody noticed anything about what we see in the distance, like how that's how that's effective.

  • I think if I'm looking at this wall right here, for example, it's kind of hard to tell.

  • But as opposed to like down this hallway, what's what's the difference there?

  • The light sources for the ladies.

  • The light source is further away, kind of.

  • So we're we're experiencing here we're seeing is a It's a a graphics sort of concept called fog and So what fog lets you do is effectively adds color to the scene based upon how far away the objects are in the scene and multiplies color onto them.

  • And it gives you the illusion of looking in to look as if think you're surrounded by fog.

  • Basically, and it's been around for a very long time, back even as far as the N 64 days, and we'll talk about that later today.

  • It's actually incredibly easy to add that into a game with unity and its world lighting system.

  • Any idea as to how fog not only in terms of aesthetics, but how you could maybe help with performance?

  • Yeah, that's much you need as much pixel clarity kind of the the big thing about fog and the way that it was used a long time ago.

  • Is that because eventually things are completely opaque beyond a certain point, you don't need far draw distance in your game so you can actually like dynamically you can you can omit rendering things that are a certain distance away because you wouldn't be able to see them anyway, as this was an optimization technique.

  • Used a lot back when draw distance was a huge bottleneck on computers and gave video game consoles back in the nineties.

  • For example, like Silent Hill, the game for PS one was almost exclusively fog, and you could see very little in front of you, and we'll see a screen show that later.

  • Um, and they use that for to boost their performance and also to provide a certain aesthetic.

  • And then one other thing you might be being attention to is there's a sound on loop, just sort of this creepy sort of whispering sound.

  • And that's to, um, just at atmosphere, right?

  • Just because without it, we would.

  • You know, it's little things like that, especially in horror games like this.

  • The atmosphere can be everything.

  • So with very simple ideas, fog, some whispers, first person controller, sort of tight hallways.

  • Um, you been producing?

  • That's pretty scary.

  • Now there are a few things missing from this.

  • Namely, there's nothing that's going to come at you and attack you.

  • Um, but it would be not terribly difficult to add, but because we're using procedural generation, you would need what's called a knave mesh, and you would need to generate that procedure, least, that things could follow you in three D space.

  • Um, might have some time to talk about how to do that a little bit later today.

  • Um, but that's not implemented in this particular lecture, but it would be not to infeasible to accomplish, but those are some of the pieces that will take a look at today.

  • Um, so that was this is the title seen.

  • Notice that there's not a whole lot here, actually.

  • So raise him back out.

  • We can see, you know, canvases are huge and unity just because it's more optimized for the engine to render them that way.

  • But we can see even though it's a two d sort of, um, you I it's very visible in three D space.

  • And if you click this button here, we end up getting uh oh, no, that's just brings us into Sorry.

  • Click this button here.

  • That brings us into sort of the two D unity to demotes an hour interacting with things in two D, and I can actually click on this label and move it around in two D, as if we were using a to D game engine, as opposed to a three d game mentioned, so we'll look at that a little bit later.

  • This is the just the title scene.

  • So the placing itself, I'm not going to save that.

  • The play scene itself gonna go from two D back to 32 here is pretty much empty.

  • So we have a first person controller here.

  • This is the F PS controller.

  • Object, Same buddy.

  • Anybody tell what basically constitutes an FBS controller just by looking at the scene here?

  • What are some of the pieces that jump out at you?

  • I just put the camera right where the player is exactly.

  • But the camera right where the player is effectively where their head should be relative to where their body is and their body What's constituting their body here, Can you tell you could just be a cute looks like a Cuban.

  • It's this.

  • It's actually this capsule right here if you can see it.

  • Uh, there's this capsule here, this green capsule.

  • It's a little bit more organic feeling than a cube, necessarily.

  • But you could use a Cubas Well, um, but a capsule is how, uh, character controllers and unity are represented and character controllers sort of come for free in unity, which is really nice.

  • They're part of the standard assets.

  • So if you go to import package immunity, if you're going to assets import package, there's a lot of packages that come for free.

  • The sort of bootstrap you, um, noticed.

  • There's activity packages, cameras, characters.

  • The characters package has three D characters are third person characters, first person characters, some that are physics based on that are not physics based.

  • This particular controller is not physics based, meaning that we don't apply forces to it.

  • We move it around.

  • It's Kinnah Matic.

  • Um, it can't It is affected by gravity.

  • So, in a sense, that kind of his physics based.

  • But it's not strictly physics based like a rigid body and a rigid body would.

  • And the collisions that occur between this and other rigid body aren't the same as they would be if we were to make this a purely rigid, body based character controller.

  • There is a purely rigid, body based character controller that you can import having experimented with it a lot, but you could probably figure out a good use for that in terms of the game remade, you want toe move precisely on surfaces that have different materials, like icy surfaces or what not and have it apply it in a very physically realistic way.

  • Um, I have a few things that we have here in our place.

  • Seen.

  • We have a dungeon generator object.

  • So this dungeon generator object is just empty.

  • Object with a level generator script here.

  • And then we have a few other objects a floor parent, a walls parent and a whisper source.

  • So we'll get into the details of what all of those mean our goal today.

  • We'll be talking about a few things, so we'll be talking about.

  • Here's a picture of the storm maze.

  • So we talked about some of those things at a high level, will actually explore how to implement them immunity today.

  • So making a maze, making the fog effect, walking through it with our character controller.

  • We want to be able to have some kind of game play here.

  • So we have collectibles in the form of this red coin is actually part of another standard assets pack a prototype assets packed.

  • It comes with a prototype little coin object that you can throw in.

  • Um, anybody noticed anything about this coin beyond the fact that it's, you know, just a sort of red coin.

  • What it will.

  • Do you notice about this scene here committing a glow?

  • Any ideas as to how it's emitting a glow light source inside of it?

  • Exactly.

  • So we'll talk about that will show you how that's implemented.

  • Very easy doing unity.

  • And then we'll also talk about towards the end r.

  • Two d seen our title scene and how to construct it, which is actually very easy and unity, as opposed to doing something by code.

  • You very rarely actually for interfaces need to touch code, at least in terms of how to lay them out.

  • Immunity.

  • You can do everything very visually and with the mouse since, actually it's a It's a pleasure to making interfaces if you're used to just making them in in code, so text a ring.

  • So last week or two weeks ago, we did nothing with textures.

  • It was, well, that's not true.

  • We had one texture on the background, which was the sort of scrolling background, but we didn't really look at that too much in today's example that you know, the helicopter and the coin and the, um the buildings and all that stuff.

  • Those were all just polygons with flat colors associated with them.

  • Today we'll be talking about how to actually texture things with materials.

  • And so this is very easy to do in unity.

  • So I'm gonna go over to a to my title seen here just because it's fairly ITT's lit in a fairly normal way, as opposed to the place in which is not lit in a normal way.

  • Because we're using environment lighting, we don't have a skybox.

  • The title scene has a fairly normal light.

  • Ah, lighting setup.

  • So if I add a cube here to the scene so you can see right off the bat by default, we do get a material here, which has an Albert's calling Al Beato component.

  • Albedo just means, like, what's its surface color look like?

  • It has a much more technical definition.

  • Um, and you can look up on Wikipedia what albedo means.

  • It has something to do with the way that light interacts with surfaces.

  • There's a lot of other elements here.

  • You could make something look metallic.

  • You could make it look smoother rough, and you can also add normal maps, height maps and a few other things, which gives it more of like a bumpy texture and so forth.

  • And you can also make things emit light this way, which the coin actually not only emits light but also is a light source.

  • So it does both, Um, and there's a few other things here.

  • For example, let's say you have a very large cube and a small texture.

  • If you put a very small texture on a large cube, what's it gonna look like?

  • What's your instinct if we if we have a very large Cuban Avery, let's say we have a 64 by 64 pixel texture.

  • But Cuba's humongous was that What effect is that gonna have on the Cube?

  • It's gonna look kind of like an end 64 Cuba.

  • It's going thio.

  • What basically happens is going to interpret between the texture pixels, that textiles when you apply a texture to your cube, and so when you play a small texture to a large surface, it's gonna look stretched.

  • It's gonna be it's gonna look stretched and, like, um, it's gonna look also filtered.

  • Is it like you sort of see in some YouTube videos if you watch them and they recorded a very small resolution, but you blow them up, they look filtered.

  • Or if you've ever stretched a picture in the right software and it's looked, looks interpreted and filtered, it's gonna have that look.

  • So you can do is you can apply tiling.

  • So here we can see there's a tiling element X and Y so of one in the X and Y direction because it only applies on a flat surface.

  • So the effect of tiling would be such that if you have a 64 by 64 texture, you could just tile that texture several times to get the desired look that you want on whatever surface that you're trying to look at in your game world.

  • Maybe it's a very small object, but maybe it's a very large object that you're looking at as a character, and you want a tile bricks, for example, or, you know, Stone.

  • So to apply a texture to a, um, to a three d object in the scene, I'm gonna go into here so you need a material first.

  • These are all unity material objects you can tell because they have a circular, that little eyes if they've been wrapped around a sphere.

  • These are all unity materials, as opposed to textures, textures or just two d Object to d, you know, textures to the images.

  • So this is part of a an asset pact that I downloaded for this lecture called Dungeon Modules.

  • Low Polly Dungeon modules, which is in the asset store.

  • Um and so what I'm going to do is I'm just gonna apply.

  • Let's say I want to just apply this rock material to this object, right?

  • I go over to that going to first, uh, at a I think because I went into the material, uh, I had a incorrect appearance.

  • So do that.

  • That's strange.

  • I'm gonna create a new scene, and then I'm gonna add a cube and then a not pop, maybe the beam.

  • I wonder why it is not.

  • That's very strange.

  • For some reason, it might be a setting that I have enabled.

  • That's not allowing it to, um, correctly render.

  • But the effect of that should be that we apply normally.

  • If you apply a, um ah, a texture to a material.

  • It'll have the effect of creating it'll it'll instantly texture it.

  • But what I can do is I can go to textures here, and this should work to go to that, and then it will play it that way.

  • So normally, if you're in a fresh project and you add a new three D object and just click and drag a material onto a three D object, it will texture it for you.

  • In this case, I think, because it's automatically assigning a material to these objects based on some project setting that I'm off off the cuff, just unable to, um, I don't know for sure you can instead just go to the albedo component here.

  • So albedo functions not only as a color but also as a texture for your object.

  • And so you can apply a texture just a to D image to your albedo component of a material, right, And then we'll have the same effect.

  • Is texture.

  • Ring it, um, immediately.

  • So normally, what if this is supposed to do is create a, um, albedo creating new material with that texture as the El Beato?

  • When you said the material to the um three D object now, I wonder if I Yeah, I'm not sure.

  • I'm not sure exactly why it didn't work as, uh, like, right off the bat like it's normally supposed to in a fresh project.

  • It will.

  • I'll try to investigate.

  • But if it ever happens like that, where for some reason you're I think it has to do with the way the Shakers are set on here.

  • Maybe there's a setting I'm just not sure about.

  • But you can just set the alb Edo component here manually.

  • It'll have the same effect.

  • So the albedo component of your material setting that with a texture, textures, objects.

  • And so that's effectively how we get from, uh, this sort of look of a flat shaded or flat color shaded object to a texture shaded object just like that and texture mapping sort of in itself is a very wide field and fairly complicated.

  • But, um, ultimately, it looks something like this.

  • Does anybody Can anybody tell me what this looks like here?

  • So we see here, obviously, we have a fully textured model.

  • But if we're looking at this, what does it look like we've done here?

  • So what does it look like?

  • Ignore all the lines But what does it sort of looks like we have on this surface?

  • Just a texture, right?

  • We can see what we can Sort of see the colors here, for example, maybe the his belt here, or or actually, that looks like the top of his head here, this being the top of his head.

  • And we have, like, his belt and other things.

  • Um, this right here we could pretty clearly see that's like, sort of its face mask.

  • Right?

  • But it's just on a two d surface like this is a just a regular texture.

  • And so what we've done here is basically taken all of the polygons that comprise the model.

  • It's sort of laid them out flat, right?

  • Wait him out flat, as if on a table where texture is.

  • And that's what you ve mapping is.

  • And this is usually something that you do in whatever three d modeling software that you're using immunity.

  • When you apply a texture to a material or a material with a texture to an object, it will use its standard.

  • Um, it has its own built in like mapping algorithm that'll apply material to a model, and so it does it differently for different objects.

  • We can We can create a, um, like a sphere.

  • For example.

  • Move this fear over here and we'll try again.

  • And just to see if Thea applying the material works on that.

  • No, it doesn't.

  • So applying a So if you go into this, um, material here, which is for some reason great out.

  • Um, you see it again, create a new three D sphere, and then, um oh, this time it looks like it.

  • So I can tell.

  • No, I don't think that's working.

  • Um oh, now it's now it allows us to accept a texture.

  • Okay.

  • So we can apply a texture.

  • Whips apply texture to that.

  • And so now we can see our sphere has been mapped as well, and it looks fairly convincing.

  • It's been wrapped around it in a way that doesn't look too distorted or too weird.

  • And so unity has its own ways of mapping for its primitive objects.

  • Um, whether it's spheres cubes, we have a few other ones capsule cylinders, planes, and it'll depend, obviously where your texture is.

  • If your texture is fairly ornate, it might end up looking distorted.

  • But for most purposes.

  • Um, for simple, primitive objects for most textures, it should work pretty well.

  • Now, if you imported a model that was like a table or character and he just applied a texture to it, it's not going to look good.

  • It's gonna look messed up.

  • And so your three D software will export a material with the model.

  • Assuming that you've modeled in that software with a texture, it'll actually give you material that you can then reference that will properly apply a texture to your character.

  • But the same sort of apply a texture.

  • Just a regular texture to a complicated model just isn't gonna work because it hasn't been UV mapped.

  • In a smart way, unity is not gonna know.

  • I have a table I want to map.

  • I want to map the texture too.

  • The table in a you know, in a way that looks convincing.

  • You can see this kind of if we create a cube, and then if we go ahead and been making apparent for some reason, uh, if we appear gonna first a sign, uh, okay, for some reason that worked instantly, Um, but you can see we've applied a sort of wall texture to it.

  • And then if we scale it down So this is this scale button up here.

  • So we have, um you can move, rotate things if unfamiliar.

  • Thea sort of these top buttons up here are transform operators so you can move things.

  • Scale are rotate things and scale things.

  • So if you scale this along the you know this, why access a bit and then you zoom in.

  • The texture looks pretty compressed and distorted because it's just doing the same algorithm and assuming it's the same kind of surface without taking into consideration how it's been warped, right?

  • So it ideally, you wouldn't have these sort of, like flattening thing.

  • This this flattening happening.

  • And so in your 30 software, you would unwrap your model and then, um, apply a texture to each separate polygon of your model in a way that looks convincing.

  • And so this isn't anything that you necessarily have to do, um, for the lectures for the demonstration for your project.

  • But if you are creating your own treaty assets for importing three D assets on, if you want to use textures in a way that we're doing today, you will need to probably become familiar with you.

  • The wrapping you the unwrapping UV mapping and whatever suffer that you're using.

  • And if you're just unfamiliar with it in general.

  • And I've wanted to know sort of what goes on in turning a, you know, flat white polygon character into something that has a texture.

  • This is effectively what happens.

  • You unwrap it, make it flat, sort of like stamp the material onto it effectively and that be.

  • They know that maps the U.

  • V's of the texture, sort of the textures virtual coordinates to your three D model.

  • So any questions as to how this works at all, or about unity and applying textures?

  • No.

  • With you, you make the textures right.

  • Words world.

  • How do you make the textures on the right that I mean, that's kind of an art form in itself.

  • You you do have to do it by hand, Um and sort of No.

  • I mean, there's a good amount of trial and error that will go into it, too, as you're making your model and sort of unwrapping it and noticing.

  • Oh, this looks weird.

  • As I'm applying this polygon to the surface to go and change the texture.

  • But you could use any you could use Gamper photo shop or any standard, um, texture creation software and kind of just, um, at something.

  • I don't do a lot of it, but it's something that I imagine that you just get better at with time and artists, texture, artists and modeling artists probably developed, sort of like in attuned sense of what makes a good texture versus what doesn't.

  • Um, generally, you'll make the model, um, first, and then you'll make the texture.

  • So, um okay, so we already talked a little bit about models.

  • Sorry about materials.

  • We'll go back over it really briefly again.

  • There.

  • Uh, there is a resource that I really like and I think doesn't really wonderful job of teaching beyond far beyond the basics of unity.

  • And that's Kat like coding dot com and its holy free.

  • They just have a bunch of free articles on there which are very in depth.

  • And this is a screen shot taken from one of the articles where they talk about how to make really interesting materials.

  • So you can see here, this one, the left, it looks a very you know, it looks like a fireball like it's made out of magma.

  • Um, and it's got bumps on it has contour.

  • You can see that.

  • They're sort of like a glow to the fire on it.

  • On the right, you can see that this model has, um, sort of conditional shine on certain parts of it.

  • Like the metal part of it is shiny, but the rest of it isn't.

  • And sort of like, how do we make certain parts of material shiny?

  • How do we make certain parts of it flat?

  • Um, the article goes in the depth on that.

  • Effectively, what they do is they use several layers of maps like a shiny nous map, which is the texture that tells, um, that you reference in a unity custom shader that you write which the article teaches you how to write, which will make certain parts of the texture glossy and certain parts of it not glossy.

  • So, Matt, and so you can do a lot of really cool, very interesting things.

  • Immunities, shading system is very, um so the sky's the limit.

  • I mean, because it's effectively a standard shader, um language like you would.

  • It's effectively the same thing as H L S L.

  • I believe, which is high level shading language, which is a if I'm not misremembering.

  • Microsoft originally came up with it.

  • It's very similar to G l s L, which is the open geo shading language.

  • And so what these are effectively is just a little programs that run on your graphics card.

  • We talked about this before, but they tell you're seeing how to process lighting for the objects that air within it.

  • And everything in unity has a shader associated with it, even if it's just the standard shader, which by default, is just a white color.

  • But you can write your own shakers and you're capable of virtually unlimited possibility.

  • And, uh, the this is effectively is all a shader, and it's all a shader that's been written in code.

  • But we have a lot of these variables that are exposed to us, and albedo is one of them, and albedo is sort of conditional if it if it gets a texture applied to it, it will just render that texture.

  • But if you apply color to it, it will apply that color to your material.

  • And so that's how you can get, you know, textured things versus non texture things.

  • Metallic just computes shyness and reflectivity off of surfaces.

  • And that's just something that's written into the Shader and produces the lighting responsible to make that happen.

  • And all of these different things was part of a single shader, and material is effectively a shader.

  • They're kind of one of the same.

  • Material is a little bit different in that you can also specify how its surface should interact with other things.

  • So, for example, if you're in an ice level, material can not only be like the sort of glossy I see look of something, but also how slippery is it when I walk over it and should I slide?

  • And how should other things interact with it that have physics, So like, those two sort of hand in hand are so what material is.

  • But, um, likely as you're starting out, the only real things that you'll need to consider um, and you sort of bound only by your curiosity are albedo and maybe metallic and maybe a mission.

  • And then, depending on how much you how bigger thing is and how small your texture is, maybe tiling and then recall last week we manipulated offset.

  • So offset is how much the texture is shifted and recall it loops around back to the other side.

  • And so, by manipulating offset on the X axis, we were able to get a scrolling, infinitely scrolling texture, right.

  • And so all these things have their uses, and pretty much everything in unity has its uses.

  • Its a very vast tool kit to use.

  • Um, but those were probably the important things that you'll see.

  • And this article and many others on this website, which I highly recommend if you're looking to get really deep into unity will give you a lot of insight into how things work far beyond just the surface level there.

  • So any questions on materials?

  • All right, so we're gonna take a look now at lighting, so materials materials are one part of the equation.

  • So that's sort of defines how things should look when light hits them.

  • But we also need light itself in our scene to illuminate things.

  • And so this is taken from another article on cat like coding on rendering.

  • And so this is a scene with a lot of lights, a lot of glowing lights and missive lights, and there's a lot more going on here.

  • Um, but this is, Ah, another great series of articles on how to understand the lighting model in unity.

  • And it teaches you a lot, teaches you almost, you know, down to the very bare ingredients of the sort of the software in the rendering.

  • If you want to go that deep, I certainly have been gone through every article because there's just a tremendous amount of content.

  • It's very deep.

  • But if you're looking to really looking to really get a sense of how it works, I would I would encourage you to explore that, Um, so we look at a few different types of lighting.

  • Beyond the more complicated things that this article talks about.

  • We'll look at the different styles of lights, which you'll probably use more often as you're starting out.

  • So point lights, anybody have an idea?

  • So what a point light might be based on this picture?

  • Wow.

  • Uh, it's not pointing in a very specific direction.

  • That's actually a spotlight.

  • Okay, so a point light is a source of light that actually, uh, shoots out in all directions around it, so it emits light in all directions.

  • But within a confined area and a specific intensity, a spotlight shines light in a specific direction.

  • So only one direction.

  • And what's interesting about spotlights is you can actually apply what's called a cookie to them and what a cookie does, very similar to what the bat like the Batman Lite does.

  • It allows you to apply a texture to a light and therefore cast shadows specific shadows on the light.

  • So if you wanted to make like something like the bat signal, you could put the bat man icon cookie on your spotlight, and that'll shine the light.

  • But the bat, uh, the Batman logo will be in the middle of it.

  • It's effectively the same thing as taking a literal spotlight and putting a object onto it.

  • It produces a shadow Emmanuel show.

  • It's called cookie Um, a directional light so anybody know what a directional light is.

  • So despite its name, it's actually not us.

  • Not the same thing as a spotlight.

  • So directional light.

  • We used a directional light last week, actually, last lecture Directional light casts light in a single direction, but throughout the entire scene as if it's the sun, so this allows us to illuminate globally the entire scene.

  • But all light gets cast from one direction.

  • So if you want a toe, produce the appearance of daylight in your scene.

  • Just a single directional light will illuminate everything, and then the last thing which is used less is called an area light.

  • Does anybody know anybody gets when area light is based on this picture here?

  • Yes, it's like that's only on the surface light.

  • That's only on the surface.

  • Um, kind of Yes.

  • So it's light that will emit from the surface of a, um, specifically designated, uh, rectangle effectively in one direction.

  • So you can define a large area, for example, maybe like maybe you want, like a wall strip in your game or something along the wall to emit light specifically to the left or something like that.

  • That's what an area light is capable of.

  • Now.

  • Area lights are computational e expensive, and so you can only use them when you bake your lighting seem to remember what baking means.

  • We're in a frank the lighting, so baked lighting just means that instead of real time lighting, calculating things dynamically.

  • The light gets calculated, UM, one time and saved and almost like freezed onto all of the objects in the scene.

  • And so there are pros and cons to this.

  • What's a pro to make the lighting?

  • Do we think less competition?

  • The intensive?

  • What's the downside to baked lighting can be very effective, can be dynamically affected.

  • So if you're walking through a baked lighting scene and you're expecting to cast a shadow on something, or for something to cast a shadow on to you, it's not gonna happen because the environments already been the lighting.

  • For that, Sean's been pre baked.

  • It's almost as if we've just re colored the world in a specific way, But we're not actually doing any lighting calculations.

  • But this is how lighting worked in like the N 64 era, and it's how it still works now for certain situations, you know nothing's gonna cast a shadow on something.

  • You can make really nice looking lighting for a scene without um needing to do it in real time.

  • You just bake it right so those are the different types of lights so we can see that in unity.

  • So if we go here, I'm going to s O right now.

  • We have a directional light.

  • So this directional light is this object here by default all, um, and you can zoom in as much as you want, but it's sort of like, um, there we go.

  • Um, this directional light is Onley shining in one direction so I can move it here.

  • So currently I'm in.

  • Um, it's a little bit weird to navigate just because it's been rotated a little bit, given that it's a directional light, its rotation, um so notice how it changes.

  • So if I shine it upwards, knows everything comes black because the lighting is just shining upwards.

  • Writes as if it's coming from below.

  • And if I shine it towards there knows that the lighting on the the sphere and the little cube there sort of change a bit, right, because they're getting affected by the direction of the light a little bit.

  • But they both get affected the exact same because the directional light is omnipresent, its throughout the entire scene.

  • It's a global object.

  • Now find elite the directional light.

  • Yes, we have no light now, so these things just look kind of, like, statically shaded.

  • You can add a new light through Ah, if you right click in your sort of game object of you and then you go over here, you can see we have all the different lights we talked about.

  • There's all these things called reflection probes and light probe groups and those air a little bit more complicated.

  • But those allow you to effectively get pseudo real time lighting and reflection with baked lighting and reflection.

  • Um, we won't talk about those in today's lecture, but there's a point, like, for example, So let's see, Where is it?

  • That's right over here.

  • So I'm gonna move it over here so you can see it's not global, like the, um, directional light was right.

  • It's just affecting this very limited.

  • I'm gonna zoom in a little bit so you can see a little bit better, but it's affecting just sort of these two objects relative to where its position is right, and so this works perfectly for things like lamps and your scene.

  • If you wanna have a street light or whether you want to have to be like a fire going on in the house, or if you want the, You know, like the power up that we had in the, uh, the pickup that we had in the ah, unity.

  • Seen right.

  • We have just the It's just a meeting.

  • A purple light that, um, is within a very small radius.

  • Notice here we can change the color of the light.

  • So if I make it like that, um, for some reason Oh, here you go.

  • So do that.

  • So notice Now it's emitting a purple light so you can color alight.

  • However you want to produce whatever affects you want.

  • So fire is not gonna admit white lights probably admit, like an orange red light.

  • Um, streetlights probably gonna admit, kind of like a yellow orangey light.

  • Um, So depending on what you're seeing, looks like and what you're trying to emulate, you can accomplish pretty much anything with just the you know, these very simple objects.

  • So I'm gonna get rid of the point light, and then we're going to create a spotlight.

  • I'm not gonna create a area light just because we need to Bay actually baked the lighting into the scene.

  • But I will create a spotlight.

  • Just we can see what it looks like Get in the right position.

  • So I was gonna be a little tough to, uh, for exactly where you are.

  • Okay?

  • Getting close.

  • Here we go.

  • Perfect.

  • So there's little spotlight right here is being produced by our objects.

  • We could see we can move it around, and then we can apply a cookie to it if we want to.

  • A cz.

  • Well, um, it's right here.

  • So in your if you're in a spotlight and you won't apply a texture to it, just this little cookie and just expect the texture.

  • So whatever whatever image you want.

  • And if you're creating a cookie texture, white means full lights in black means full shadow, and so you could make it a grayscale image.

  • You can make it anywhere in between white and black, which allow you to produce some interesting effects.

  • Thea, for example, the manual in, um, it's not here, So I didn't include a picture here, but the manual shows like there are some kind of like the lights that you put on the stand and they have a bunch of L E.

  • D's right, and they're serving a grid and they shoot out.

  • Spotlight you can create a cookie.

  • That's kind of a gray scale with those greeted lines, and it will shoot light onto the scene as if it's being broadcast from a sort of grid of L E.

  • D's.

  • So there's a lot you can do with just some very simple ideas.

  • Those are the kinds of lighting that we can use.

  • And in today's lecture, we only really use the point light.

  • And in last lecture, we use the directional light.

  • Come on, um, and spotlights you can.

  • You could, for example, uh, programmatically change.

  • For example, the rotation of a spotlight.

  • If you wanna have, like, a swinging spotlight on your scene toe, illuminate some wall or some surface, there's a lot of cool things you could do with it.

  • So those are the core types of lights in unity.

  • Does anybody have any questions as to how they're used or probably work eyes?

  • No matter.

  • So for the directional light, it does not matter where it's placed.

  • You could place it anywhere you're seeing 00 or some far distance away.

  • You'll have the exact same effect on the entire scene.

  • Yeah, any more questions?

  • Okay, cool, cool.

  • So those air lights, um, bump, mapping, talk about very briefly.

  • So bump mapping is we actually do use this in the game.

  • Um, the above map effectively is So what you see here on the left is a an actual three d seen these are actual models being shaded in real time in real time.

  • But they're actually real models being illuminated in the middle.

  • We can see what's called a bump map, and on the right, we can see a district a flat, um, like a flat plane with a bump map with the same bump map, apply to it and then illuminated.

  • So what a bump map allows us to do is to take a flat wall or flat surface or whatever you want and then simulate like an actual three dimensional contour, three dimensional bumps or whatever you want on that surface, um, without needing to create the actual geometry to make it possible.

  • And so, um, there are different tools that will aid to create bump mapping, um, objects off our but mapping textures.

  • Often, three packages will have these so you can create them or other software.

  • Um, but they are effectively just the encoding of what are called surface normals.

  • So just a vector going from outside of the, um, uh outside of the polygon at that given point.

  • And they tell the lighting system in unity.

  • Pretend as if there's actually, um, geometry pointed in that direction when you calculate it.

  • And so even though it doesn't distort the geometry in a way that's like this is still completely flat.

  • The lighting thinks that the geometry is kind of, you know, contoured, and so it allows us to create.

  • Um, this is kind of a toy example, but it's actually relevant in the in the case of walls that have and we covered this last week just not as much detail but walls that you want to be flat and you don't want to have a lot of polygons, for you can create a bump map for and apply that bump map.

  • And then when you're rendering it when you walk past a wall, it's gonna look as if the wall actually has cracks and bumps in it, Um, for a realistic effect, and this is used in the game too.

  • Slight degree.

  • You can crank it up if you want to.

  • I didn't on my computer because my settings are My specs aren't sufficient, but every texture in today's example has a bump map associated with it.

  • Um, so you can actually see where what the, um um you can actually see the effect of bum mapping at various degrees of, um of use the materials here, So I'm gonna go.

  • I'm gonna load up the scene that has the actual stuff I'm going to, actually, I don't need to look to see.

  • And all you need to do is go to the materials and the floor, for example.

  • Where is the floor?

  • Right here.

  • So knows that before we talked about albedo and then also mentioned normal map, so right here all you really need to do in order to get unity to detect normal maps.

  • And this is just part of the standard shader.

  • Normal maps and bump maps, by the way, are effectively synonymous.

  • Um, you can just drag your normal map texture into this field here, this little square, and then give it a degree.

  • I wish to apply that normal map.

  • And so if you look at this here, um, appeal to see I don't recall.

  • Yeah, we can sort of see how it changes the texture, right?

  • So at zero, there's no normal mapping taking place at all.

  • That texture is just completely flat, as if we had done just the regular apply texture to a sphere.

  • But the degree at which we apply a normal mapping.

  • So notice that degree one.

  • It kind of looks pretty realistic, as if we've got kind of a stony texture.

  • And the more we go right, the more exaggerated starts to look right.

  • And you could just keep doing that.

  • Um, and it'll eventually just looked really distorted.

  • But that allows you in depending on how strong our computer is.

  • You can go higher or lower to, ah effect just how bumpy, just how strong the bump map.

  • The normal map affects the lighting rendering.

  • So it's that easy to get just a, um, fairly sort of extra sense of realism in your scene, so you'll notice if you're walking through the scene.

  • If you turn off lighting, it's even easier to see all of the surfaces.

  • The floors, the ceilings and the walls have a bump map as well as a texture map, so that's in case you're wondering what these weird colored textures are.

  • Um, are G B R X y Z for the surface normals and how and their permutations thereof.

  • And that's how it gets encoded into this.

  • And so often you can see if you're looking at a bump map and a texture map, you can kind of see together like Okay, this makes sense.

  • The parts that I would expect to be bumpier do have, um, a correlation to how they look on the actual bump map texture.

  • You can see it here.

  • Everything that is bumpy or contoured is very visible in the bump map.

  • That's just by nature of the way the data's encoded.

  • So any questions is toe how bump maps work or what they are or how to use them in unity.

  • All right, cool.

  • So now we're gonna start getting into ah, little bit more into how this all comes together in our maze on our game, and we'll talk about May's generation.

  • So I'm going to just start up the game the scene here.

  • So I'm in the actual place, seen so in scenes I loaded up Playas before I'm going to hit play.

  • Um, I'm gonna turn off my sounds because the creepy sounds a little disorienting after a while, um, and then going thio Um, actually, I'm going to go to a two by three of you and then hit play so we have the regular game view down here below, and then also, if I zoom out, you can see that are seen was empty before.

  • But now we've got a maze, and currently it's not very visible at all because one were playing fog.

  • Right and recall fog allows us to effectively add color to objects that are farther away from us.

  • And two, there's a ceiling on top of our, um, a roof on top of our maze.

  • So it's actually blocking out the actual what the maze looks like.

  • So we can fairly easily make a couple of changes here in order to see our amaze a little bit better.

  • I'm gonna goto window gonna goto lighting settings.

  • And so if you go to a window lighting settings those you're sort of global unity lighting settings, right?

  • You can say you're skybox, you consent environment lighting.

  • You can set things like fog.

  • Y

All right, Welcome to lecture nine of G D 50.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

Dreadhalls | Unity 3D教程--CS50的遊戲開發介紹。 (Dreadhalls | Unity 3D Tutorial - CS50's Intro to Game Development)

  • 0 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字