Skybox

Three.js and WebGL 3D Programming Crash Course Three.js & WebGL 3D Programming
10 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.24
List Price:  €93.20
You save:  €27.96
£55.93
List Price:  £79.91
You save:  £23.97
CA$95.58
List Price:  CA$136.56
You save:  CA$40.97
A$107.13
List Price:  A$153.05
You save:  A$45.92
S$95.25
List Price:  S$136.08
You save:  S$40.82
HK$547.90
List Price:  HK$782.75
You save:  HK$234.85
CHF 63.85
List Price:  CHF 91.21
You save:  CHF 27.36
NOK kr770.13
List Price:  NOK kr1,100.23
You save:  NOK kr330.10
DKK kr486.51
List Price:  DKK kr695.05
You save:  DKK kr208.53
NZ$117.65
List Price:  NZ$168.07
You save:  NZ$50.42
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,679.19
List Price:  ৳10,970.75
You save:  ৳3,291.55
₹5,834.32
List Price:  ₹8,335.10
You save:  ₹2,500.78
RM333.81
List Price:  RM476.90
You save:  RM143.08
₦91,422.33
List Price:  ₦130,608.93
You save:  ₦39,186.60
₨19,487.31
List Price:  ₨27,840.21
You save:  ₨8,352.89
฿2,585.90
List Price:  ฿3,694.31
You save:  ฿1,108.40
₺2,277.50
List Price:  ₺3,253.72
You save:  ₺976.21
B$361.10
List Price:  B$515.88
You save:  B$154.78
R1,320.17
List Price:  R1,886.05
You save:  R565.87
Лв127.48
List Price:  Лв182.13
You save:  Лв54.64
₩96,293.43
List Price:  ₩137,567.94
You save:  ₩41,274.51
₪266.53
List Price:  ₪380.78
You save:  ₪114.24
₱4,038.21
List Price:  ₱5,769.12
You save:  ₱1,730.90
¥10,975.59
List Price:  ¥15,680.08
You save:  ¥4,704.49
MX$1,206.90
List Price:  MX$1,724.22
You save:  MX$517.31
QR255.26
List Price:  QR364.68
You save:  QR109.41
P965.80
List Price:  P1,379.77
You save:  P413.97
KSh9,448.65
List Price:  KSh13,498.65
You save:  KSh4,050
E£3,352.63
List Price:  E£4,789.68
You save:  E£1,437.04
ብር3,985.10
List Price:  ብር5,693.24
You save:  ብር1,708.14
Kz58,489.70
List Price:  Kz83,560.30
You save:  Kz25,070.60
CLP$66,385.51
List Price:  CLP$94,840.51
You save:  CLP$28,455
CN¥507.19
List Price:  CN¥724.59
You save:  CN¥217.40
RD$4,111.01
List Price:  RD$5,873.12
You save:  RD$1,762.11
DA9,398.61
List Price:  DA13,427.17
You save:  DA4,028.55
FJ$158.17
List Price:  FJ$225.97
You save:  FJ$67.79
Q544.39
List Price:  Q777.73
You save:  Q233.34
GY$14,639.41
List Price:  GY$20,914.34
You save:  GY$6,274.92
ISK kr9,791.60
List Price:  ISK kr13,988.60
You save:  ISK kr4,197
DH708.11
List Price:  DH1,011.63
You save:  DH303.52
L1,243.72
List Price:  L1,776.81
You save:  L533.09
ден4,016.98
List Price:  ден5,738.79
You save:  ден1,721.81
MOP$563.94
List Price:  MOP$805.67
You save:  MOP$241.72
N$1,340.22
List Price:  N$1,914.68
You save:  N$574.46
C$2,575.16
List Price:  C$3,678.96
You save:  C$1,103.79
रु9,316.74
List Price:  रु13,310.19
You save:  रु3,993.45
S/261.07
List Price:  S/372.97
You save:  S/111.90
K269.52
List Price:  K385.04
You save:  K115.52
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,842.03
List Price:  ZK2,631.59
You save:  ZK789.55
L324.63
List Price:  L463.78
You save:  L139.14
Kč1,640.70
List Price:  Kč2,343.96
You save:  Kč703.26
Ft25,605.88
List Price:  Ft36,581.40
You save:  Ft10,975.51
SEK kr762.91
List Price:  SEK kr1,089.92
You save:  SEK kr327.01
ARS$61,153.48
List Price:  ARS$87,365.86
You save:  ARS$26,212.38
Bs484.56
List Price:  Bs692.26
You save:  Bs207.70
COP$275,828.59
List Price:  COP$394,057.74
You save:  COP$118,229.14
₡35,172.98
List Price:  ₡50,249.28
You save:  ₡15,076.29
L1,727.65
List Price:  L2,468.18
You save:  L740.53
₲519,796.34
List Price:  ₲742,598.03
You save:  ₲222,801.68
$U2,684.12
List Price:  $U3,834.62
You save:  $U1,150.50
zł281.95
List Price:  zł402.81
You save:  zł120.85
Already have an account? Log In

Transcript

Hello in this free j s video we're going to show you how to use and create or I should say create and use sky boxes. You've obviously played a game a lot of games you're here learning free j. s and learning games programming. So skyboxes, the principle is very simple and offset if paid any free D name really. Or if you play through the game, you most likely will have seen a skybox. But the thing is, you wouldn't have perceived it as what it is. So let me explain what skyboxes better yet.

Let me show you the layout come up using a skybox. This free the world's got building in the background got this? dodgy IP I can look around. But this is in a 3d world. This is literally did this is where the magic comes in. I'm going to zoom out.

It's literally a cube. That's all it is just a textured cube and the cube Camera noise in the center of this cube. So whenever we look around, it looks like we're in the 3d world. And you can't really see where the different edges line up. And that's what skybox is, it's literally a cube that's textured, to make it look like you're in a big open world where it's you're in the youth like open space, whether you're in a jungle, wherever you're at sea, whatever it is, it gives that illusion you might be thinking, why would you want to do that? Can you get better quality from actually creating the models yourself?

And having a real 3d world and Germany you can get a better result. But the trade off in terms of performance is huge, because you've got to render all those different objects. What does this look like I said, we're doing nothing but six images, one for the slow one for a stare like the one there. I've been there the auto know when the Your edges off. That's it's that good and this one for the sky. And I've got the sky boxes or off a website called custom mapmakers.org.

Check it out, they've got a bunch of sky boxes, or didn't notice, well, when you download one of these, I'll show you this. They're actually TGA files. And TGA isn't supported in PJs, but just opening up in any sort of immigrating to an estate related PNG, that's what I did, you'll be able to use it like, right, so let's actually go about coding. This man was thinking, Oh, this looks so complex. In terms of the output, it must be complex code block that is a cube to texturing. I will code both of those principles.

So let's just create a bar geometry equals new, free dots. You geometry and for this honest boy 10,000 by 10,000 journey you want a big toy box because when you're moving around the skybox, you generally don't want to be moving anywhere, you just don't get to literally the end of the skybox. Basically Don't be right up next to one of the faces because your look blurry. It won't look very good, the 3d effect will basically diminish. So that's something that you do not want to do before I actually continue with this. I'll show you I've already added image files, or pretty simple stuff like that down front left, right up.

This is a no skybox that I'll show you in a moment. This is the one that we just saw. So we created the geometry. Now we're going to create the materials of our cube materials equals And your semi colon and in here comes a new free dot mesh, basic material. And in here, we're gonna provide a few parameters and set it up. So we're going to do math, new, free dot texture, loader dot load.

And in here we're gonna specify image for slash skybox, forward slash skybox one, sorry, front dot png. And now we're going to specify the way we're going to render in terms of size. So this is going to be solid Ray, dot double sided. And now we're going to just comment this out. All right. So let's just copy and paste this in, we need a few more times.

I was no except for semi colon instead of a common mode. But easy fix though. For the final one, just remove the semicolon. Just change this to I just love this about a good Id like brackets. I can double click the image and provide the preview with some basic information like the dimensions that's just fantastic for getting a brief overview of what you're dealing with. So this is code, actually.

It's lowercase. I was just thinking I'm pretty sure it's lowercase. So changes to back. I've already worked all of this out in what order is should because if you don't put in the right order, the images won't align properly. Again, already sorted this all out for you. I worked it out.

You don't have to worry about that. Because when you actually download, I'll show you again, actually, it's already in the bin. When you download a skybox, like this one from the custom website, though they're not named back down front, whatnot, they have this postfix BK dn, f t. So back down front, left, right up. Once you've converted them to PNG, rename them, we can use this current name. It doesn't matter what naming system you use, as long as you know what you're using. And as long as you're consistent, that is what is important.

So let's change this to where are we on down, right and then finally, left. We're pretty much done the bulk of it. Now we just need to do VA to map to Rio equals news three dot ambient law And in here, we're going to hash zero x. Sorry, I don't know what the hell is going on there with my fingers. 0.2 real. Okay, what else have I done?

I was looking I was like, I've just literally are looking at this line of code here, so near and I've just copied and pasted it into my head. And then I just wrote that out. Right? embarrassing. So the actual code is three mesh face material. Thank you might get a specified color before Well, that's what I'm doing.

But the reason I'm doing this is below it. But let's specify the right one then two materials. As created keeps var tube equals new free. And I'll make sure I don't copy the line below like last time, specified, the geometry that we're drawing and any materials, which is cute material finally seem to say that nothing is okay. So let's go back refresh. Now something doesn't seem right.

So let's console. log fished. Yeah. Because obviously, the color is off to the syntax highlighting so something about this is not liking hmm you asked me to remove this. I don't like any of them. So I use curly braces instead square braces, my bad.

If you notice that and you've already updated fantastic, great. You deserve a cookie. Okay, I want some cookies. If not like it right now very simple stuff, and I can guarantee it's gonna work now. I can't guarantee I just hoped. So there you go in a few lines of code, we are now on some sort of beach cliff.

So in 19 area either way, very convinced. And once you've got loads of the objects in the world, you've got a player and you're moving around the scenery. That looks pretty decent, because you won't just even be staring at those hills or mountains in the background. They literally look realistic. They look like why would I keep walking towards it? Or you could actually reach it and climb those mountains but obviously, we know you can't do that one because again, and two because it's just a flat image.

So that's how to create a skybox. And that's what a skybox is very simple stuff, but very effective. So definitely consider using a skybox. In your game, if you have any questions, feel free to post them on our education platform. So no learning code at UK or feel free to contact us in any means possible to you. All the source code for this video and the source code from every other video in the series will be available on GitHub and the link to that will be in the description.

So check that out if you are having any issues. And as usual, thanks for watching, and stay frosty.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.