TLDW logo

How to make Minecraft Shaders (3): Lighting and vertex shaders

By timetravelbeard

Summary

## Key takeaways - **Vertex Shaders Transform Positions**: Vertex shaders take model vertexes, move them into the world, then into camera view to center on screen, and pass data like lighting values as varyings to fragment shader for per-pixel blending. [01:01], [02:34] - **GL_Color Encodes Biome Tints**: GL_color carries vertex color from Minecraft used for grass and leaves biome color changes; texture is black-and-white, multiplied by GL_color to tint green in forests or brown in deserts. [07:28], [11:53] - **Lightmap Splits Torch and Sky**: Minecraft lightmap texture uses X coordinate for torch brightness and Y for skylight; colors adjust dynamically to time of day, purplish at night, bright blue daytime. [16:18], [19:26] - **Custom Torch Color Override**: Replace default torch light by defining vec3 torch_color from user sliders (torch_R, torch_G, torch_B), multiply by lightmap.x while keeping dynamic sky from lightmap.y. [25:22], [27:53] - **Directional Lighting via Dot Product**: Compute sunlight by normalizing shadowLightPosition, dot with face normals passed as varying vec3 normalSpace, clamp 0-1; faces toward sun/moon brighten, away darken. [31:55], [39:01] - **Combine Torch, Sky, Sun Lights**: Final lighting multiplies texture by (torch_color * lm.x + lightmapSky * lm.y + clamp(dot(normal, light), 0., 1.)), blending vanilla torch/skylight with custom directional sun. [42:57], [43:40]

Topics Covered

  • Vertex Shaders Transform and Pass Data
  • Varyings Interpolate Per-Pixel Values
  • Lightmap Encodes Torch and Sky
  • Dot Product Simulates Directional Light

Full Transcript

hey everybody this is time Trav beard and this is episode three of how to make Minecraft shaders today we're going to do vertex shaders actual lighting and

shading and some fog and stuff like that um so first for some concept um vertex shaders come before the fragment Shader and they've pretty much got two main

purposes as we said before the fragment Shader draws every pixel on the screen um in the case of 3D objects it's

drawing each pixel of each polygon um for anyone who isn't really familiar with 3D Graphics if we've got a block um It's Made of polygons like it's

made of sides like this is a face this is a face this is a face on the graphics card they're probably split up into triangles that doesn't really matter it's just we've got these different

sides of uh shapes and if it's something with a circle which you don't really have in Minecraft it would still be broken up into like a lot of little squares

or triangles that make up that shape um what the vertex Shader does is the first thing it does is it

takes the vertexes which each face like this is actually made of uh triangles let's say

so the vertexes are the corners that connect the lines that are the pieces so if this was split like this the these three

vertexes would make this triangle and the vertex Shader takes our little model of everything like here's a little T posed guy like you might see if

again glitches and he's just off in his file whatever but we've got our camera over here like let's say this is looking

down on us here's us and here's our camera and it looks this way what we've got to do is we've got to get this guy in front of the camera and then Center it on the screen like let's say this is

what our view actually looks like down here and there's nothing there so we have to take him take all his vertexes move them into the world first to like where he's supposed to be and

then we move the whole world into the camera's view so let's say here's us on the world and he's right here so we've moved his vertexes there and then we

have to move those where they look on the screen so from our view here be here but let's say he's looking sideways a little so his arms are kind of diagonal

so the verx Shader moves everything onto stren that's the first purpose the second purpose is that it since it comes before the fragment Shader which is where we draw the pixels um it's kind of

the intermediary to get data from Minecraft and that data is stored in each vertex when it's pushed over so anything we want to do in the fragment Shader where we're drawing things we

need to have that data from the vertex Shader since that's where it gets it from Minecraft so from Minecraft through vertexes and then we get it into the

fragment Shader now when we have data in the vertexes and we saw these as varying the reason they're called varying is because

they vary over the face of the um the face like this face so the when we're sampling a pixel one pixel might

be here one might be here one might be here so if we have something like a torch light value like let's say here's a torch it's really bright here it's not

as bright here so if this is a value of three brightness and this is a value of two brightness then in the middle here would be two and a half brightness and this one over here might only be one

brightness so in between the two and the one would be like one and a half brightness and that's how torch blocks have a smooth look is it takes the value here the value here the value here and the vertex

and when it passes that as a varying to the fragment Shader it's blending it and varying the the value so anything that we want to have that we're getting from Minecraft which will also cover those to

days uh like uniforms attributes and if there's another word form um most a lot of those we get in the vertexes if it's something that varies over the face of

the block and there's some that are just the same like a fog color isn't going to change the color just is what it is a time of day is the same that can kind of bypass the vertex Shader and go straight

to fragment um so that's the concepts of today it's we're going to look at vertex shaders and data from Minecraft like we're going to do

fog probably and we're going to do some lighting code which should be kind of fun so we'll both look at the default Minecraft lighting which is based on

torches and Skylight or and then we're going to uh do some fancy lighting okay so let's get in if we go to our notepad first thing

we're going to do is we're going to do close all so we have a blank slate and we're going to go to our Minecraft folder and we're going to go into Shader

PX take our tutorial two copy and paste it again so we have a working version and uh we don't lose our working version we're name this tutorial 3 and this is what we're going to work in

today so tutorial 3 shaders and let's start with G buffers terrain since that does the terrain and we're going to look at the vertex Shader and the fragment

Shader so let's start in the vertex Shader I don't want to use Visual Studio let's go back in notepad U so we're going to edit with notepad++ and

let's also while we're here we'll open and now it's got us in the right folder let's also open G buffers terrain fragment trador FSH

so FSH the fragment Shader is where we were doing all of our our stuff so far and we remember from last time it's got this Shadow stuff already from this tutorial we're going to get rid of that

in a minute and just do without it but first let's look at the vertex Shader and see what's here so attribute MC entity um attribute is data coming from

Minecraft that varies like it's not the same on every instance of this so it might be different for every block MC entity um we can see here if it's doing a certain

thing it's doing something to the light we'll get into that later that might be the next episode but we've got these uniforms that are data coming in from Minecraft

um map fors and all this this is uh space stuff we're not going to mess with that today you've got something that's the shadow light position that's valuable information for shading that

tells us where either the Sun or the Moon is whichever one is casting light and shadows and then here's varying these are the things that the vertex Shader is passing to the fragment Shader it's

something called LM chord text chord GL color and Shadow position so in this tutorial the Shadows data is calculated in the

vertex Shader and then passed forward through that GL color we can see here in void main is taking from something called GL color most things that start

with GL like this are coming from openg GL in this case this is the color of the vertex in Minecraft that's used mostly for grass uh the way that grass and

leaves change color based on biome um that's encoded in this and then the actual texture is just black and white and that's why we saw in here when um go

color comes into the fragment Shader we're taking the texture color and multiplying it by that because then if the grass is green the black and white texture will be green if the grass is brown and like a desert it's going to be

be brown um this is all shading stuff um LM cord is the Minecraft

lighting see we vertex Shader and you see it's taking GL texture Matrix one times g whatever this

this is just how we get the values of the uh Minecraft lighting is this little mess right here and then since that's turning into LM chord and that's under varying that's going to be

passed into the fragment Shader and into the fragment Shader we do stuff with it um that's enough kind of talking right now let's get into this and let's open up our settings too because we're going

to do some settings first thing we're going to do is we're going to do a Define and we're going to say call this lighting style because we're going to going to

use this to save the old lighting so we still have it and then work on some new versions so we'll do zero as a default since we're going to save the old lighting and let's put zero and one for now and we'll add more later and let's

copy the lighting style so we've got that save the settings we'll go into our Shader it up properties and we're going to add that there on

screen save that and then let's come back to the G buffers fragment Shader regardless of what we're doing we want to use the color and the LM chord which is the Minecraft lighting data so

we're going to leave those here and then below that we're going to do our little um hash sign if and we're going to say if lighting

style equals zero and then we're going to keep all this stuff there and then down here let's do our little end if and to make sure that we remember

where things are we're going to highlight all that stuff and hit tab so that it goes up inside of this if so we know how things work and remember how they

work um and then let's make another one and we'll do hash if lighting style equals one and we'll open this up and we'll do an end if to close it

and let's save this and make sure that it works in Minecraft before we do anything else so let's go to Shader pack list tutorial 3 apply

it and it seems like I'm here where I am um let's make sure the Shader still

works put up our train grount okay that works and our red entities let's turn those on and I'm going to go in here and grab

myself a cow EG the great mythical thing and uh now there's a

c Okay cool so our Shader still works so now let's go into um lighting style one and this is where we're going to make our new lighting now before this

we've got the the color already is loading and it's multiplying by GL color um if we get rid of that GL color let's do that and save and look at what it

does and to see this we're going to have to turn off our gray scale setting um you can see now this is what the grass textures look like is they're just black and white so when we multiply

by GL color we get that GL color if we want to just see that GL color on its own we can have our color just equal GL color so let's try that for a second

we'll comment out where it loads the texture and have it just equal go color and we can have things come down to the next line um it doesn't care about that so that can actually be a convenient way to

kind of have options if we wanted to go like this and we can kind of comment out and jump between them so now our color will equal GL color let's save that go

back in Minecraft hit R to refresh and this is what the GL color data is so you could see that these leaves are green these Vines are green but when we do this we're not getting the

uh where things are see-through and everything you see the Shadows still are because we didn't change the shadow Shader so if we wanted to we could even

say um color equals GL color and then we could say just color do alpha let's put this on one

line Alpha equals the Alpha from the texture like this and then we should

get the color from the vertex and just the alpha value from the texture so now we're mixing data of what we get from Minecraft which is the the

vertex color and texture data to do something isn't that kind of cool it's a weird way the world can look but it's it's a good way to see what it

does okay let's see so we in G buffer fragment Shader I'm going to get rid of that line and put this

back to being what it was so our color equals the loaded texture times the vertex color now let's go to our settings in

the Shader and let's turn lighting style to one to be our new lighting that we're making now if we look at this right now all it's doing is loading the textures

and it's applying the LM cord I think let's go in here and get ourselves a torch so that we can play with lighting and see about lighting

if we put down a torch let's see does that does that do anything different let's get somewhere where it's dark we might not have any uh shading going on at all here actually I'll set

it to nighttime that should help okay now if we look at nighttime it's not dark there's no torches because our new lighting style doesn't do

anything all it does is load a texture value so let's see what we're doing we've got our color loaded times GL color and we've got our light map loaded

the Minecraft data into a v 2 that's call LM for light map but then if we come down to our lighting style we don't do anything with it we could look in this shadow tutorial

and see what it's doing um but we're going to do instead is we're going to play around with it and think how Minecraft might use the lighting value

um you see here it's taking the color and it's timesing it by the Light map let's look at that first and see what that does and then we'll break it down so copy that and paste it here and we're

going to take our color and multiply it by light map values the way that would work is if something is in a a room with no light like black lighting it would be black if it's white light it would be white if there's only red light it would

only be red um let's save that see what that looks like reload okay so now we've got Darkness where it's dark we've got brightness where there's torches so

we've got some basic lighting now the way this works in Minecraft is this texture 2D is loading um a thing it's loading a 2d

texture called light map and the way the light Map works is it's got two coordinates an X and A Y for where it is on the on the screen and in basically in One Direction is how bright the Torches

are and One Direction is how much how bright the Skylight is and then those colors change in Minecraft on the time of day so something that has high exposure to the sun would be maybe like

purplish at night but it's going to be a bright blue in the daytime um if we want to visualize this differently we can instead of loading that default texture we can do something

else with it so if we want to say VC 3

torch color equals VC 3 because this three components and let's make this yellow so that would be one red one green and zero

blue let's put our sumic colon and let's say VC 3 Sky color equals and we'll do VC 3 and this is going to be very ugly just for

testing we're going to make this just a dark blue so 0 0 one and instead of doing that let's say our

color equals color times and let's check if our color is a v three or a v 4 it's a

V4 so we'll do color.

RGB equals color. RGB because we don't want the alpha changing just the red green and blue let's do that times torch color and if we just do this our torch

color is just the same everywhere so we want to know what it is for each block so we're going to use the light map so let's say times torch color times light map and either the x or the Y is the

torch and the other one is the sky so let's see what this does let's go into Minecraft and reload it and it looks like yellow is where there's torches because where I put a torch it

makes yellow cool so X is our torch value but we want to also use the sky so we'll multiply it

by that torch Value Plus Sky color times LM

doy and let's look at this go back in Minecraft refresh it and there we go so now we have blue everywhere that there's sky and where

there's torches it also adds yellow and this isn't the best right here because we can see the sky actually isn't blue that's why using this light map can be

very valuable so let's bring that back and get rid of this and we'll do file save and look at that again let's load back into Minecraft and now since it's using the

light map texture the color of the skylighting is going to adjust dynamically to match whatever the Minecraft sky is when we do something fancy later we can calculate those

colors on our own and we can do something like have Sky color actually let's do it right now let's um bring back this new code comment out this old code and let's have

the sky color change based on the time of day a way we can do that is using these uniforms that come from Minecraft it's not only textures but we can do other things too that we can find on the

a documentation one of them is uniform let's say float let's see Sun angle I believe is one of them and

we'll find out if this is right in a minute so this is pulling the uniform from Minecraft and the way this uniform works is it's 0 to 0.5 like halfway for day and the other half is

night if I remember it correctly we'll find out so let's say we'll do an if here

if Sun angle is greater than or equal 2.5 close that bracket because we want this to happen if that's true we'll open and close our bracket so if Sun angle is greater than

that which would mean it's nighttime we want our Sky color to equal zero and then we're going to do our

color here let's save this get back in Minecraft reload it and we messed up somewhere that's copy your error I probably have that's probably not a

right uniform file new paste here's our error um I don't know what that is but we didn't change much so we know

where our problem is let's see if Sun angle is greater than 0.5 do this wanted Sun angle it's time to look

online let's go to the OptiFine docs shaders of txt and we're going to find and page and

let's type Sun angle okay uniform FL Sun angle so that looks like that was right and that wasn't our problem so let's see

if we did something wrong here I'm going to delete this new part that we made

save try to load back in okay so that line that part is our problem let's paste paste it we can comment out this line and see if that's the

problem go back in here refresh and it's fine without that line so that line is the problem so what did we do well Sky color is a v 3 and here we're just setting it to a float so if

we want it black it has to be a VC three of zero not just zero so let's try that we'll save it reload

okay now it reloaded so let's see we've got blue sky let's set our time to Something in the middle of the night and now we have a black Sky cool

so that worked um if we wanted to do a custom Sky color like this we would probably want this to blend and do better um that's math and stuff that

we'll let's do it right now actually um no well I'm going to focus on so we're going to delete that um we'll keep this stuff here in

case you want to use it later in another part actually I'm going to control the z a few times bringing that all back put these together as one

option um but comment them out for now because we're not going to use them maybe we'll use them later when we do something fancy and we can take this new stuff and put it inside of

this comment and just like we can comment with um these two lines and that does a line if we comment with a slash and then a star everything after that is a comment until you do a star and a

slash so all of this is inactivated right here so in our new lighting style we're just doing color times the light map since the light map gives us um that stuff but maybe we want to

change our torch color so let's actually mix some of the code together of taking the light map and that we're going to do color times equal let's see the torch

color was which it was the LM dox the sky color is what changes dynamically so let's keep our torch color first we'll Define

that and we'll keep this formula let's copy that and paste it out here and we want to keep the torch cover but we want to change the sky color so let's put that down a line and we'll tab

it in so we know it's a part of that and we want this part to be the texture from the light map so let's take

that and put that where Sky color is and we're going to take just the Y component and we don't need this anymore and then now we've got our custom torch

color which is yellow and then we're multiplying the color which is already the texture with the vertex color and we're going to multiply that

by let's see make this let's make this a little easier to read the torch color times the torch value and the light uh the light map Sky color times that value

and let's see what that looks like cool so now we have our custom torch color and the Minecraft sky color now if we want we can make this torch color be something that the user can control

so let's go into our settings and we'll Define these we'll take uh 0 to one values here like we did for this other stuff we'll copy that and we'll paste it

and if you want you can make this have more values like 0.1 0.2 um and let's name these torch

red just an R for red because we we're lazy we don't want to type too much and we'll do G for green and B for blue and we'll say the default would be one red

and one green and zero blue then we're going to copy these we're going to save our settings go into shaders of properties and we're going to make these the

sliders so we'll put them here and then we also want these to be on screen so we'll put them here and we may organize this screen a little bit and now we want want to do something

with these so we're going to take these values and in our G buffers terrain we're going to say this torch color let's expand that so what we can do is

we can put this down like this if this helps us think and we're going to have that instead be a VC three oh wait never

mind we we'll keep it torch color and then here where we Define torch color we'll have this VC three be these three values we just made and we will separate those by

commas save this get back in Minecraft reload it and right now it looks the same that's yellow but let's go into our Shader

settings and let's say that we want our torches to be blue or just white if we mix all three they'll be white if we want our torch to be blue there we've got blue

torches if we want purple torches that's full red and blue with a zero green there we go we got purple torches nice I'm G to reset everything so we're back

to normal and now we have custom torch light and if we go back to the daytime oops I've got caps lock on we can see that the sky color is

adjusting so now we just learned about Skylight and torch light and the Skylight the way it works is like when you're in a cave or something um that light kind of Fades off the further you

get away from the Sun so like here it's dark darker um and it kind of just comes straight down and then kind of Fades off to the side and that's the the default

Minecraft lighting is that Skylight and that torch light and then if we want to do fancier lighting like shadows and lighting from the Sun what we're going to do and I'll draw

a picture about this um is the way that standard lighting Works in computer Graphics because it's how it works in the world is if here we

have our Cube my great Picasso Cube and here we have a circle and this is basic computer Graphics like Theory and stuff here's our

sun um the way we calculate lighting is that if something me get a a blue here for this is that stuff that's facing the sun

is brighter and stuff that's facing away from the Sun is darker we probably all know that um if you don't that's how that works so like with a

circle it's like this it kind of gets darker as it's starts getting further away um so this end is all like really

dark this end is kind of light same with the square if this end is facing the surface of it it'll be bright if this is kind of facing it it's going to be kind of dark and then and then the one on the

opposite side is going to be like pitch black and the way we compute that in computer Graphics is with something called

normals um since each of these faces is 3D and it's called vertexes those vertexes are V3 which is

a point XYZ in space but also this surface points in a direction like it this one is facing up this one is facing this way this one is coming towards us

and on a circle each each one is going to just look away from the center um it's like a table the top would look up anything on the side looks certain ways so what we do to do

lighting is We compare this angle to the angle of the sun because if it's looking right at the sun it should be fully white if it's looking away from the Sun it would be fully black and actually if

it's even just looking perpendicular that would also be black so to calculate computer Graphics like Li in what we're going to do is we're going to take the

normal which is this from the surface and we're going to take the direction from the Sun and we're going to compare the two and the smaller this distance is

between them The Wider it should be and the bigger that distance the darker it should be so this one again would be very bright this would be black because it's perpendicular and this one would be more than black if it's possible because

looking away so to do that we're going to take this direction this direction this one's longer because the sun is really far away this one is always a length of one so we're going to

normalize this which means we'll take the same angle but make it only one and then we can compare this Angle now you could do that with like the Pythagorean theorem or you could do that with like

distance but there's a very fast way computers do it called Dot and it's probably in here already I think it did it in the vertex shade but we'll do it

here um we're going to use another uniform we've got these here we're going to use one

called um Shadow light angle I think it is let's check our OptiFine documentation and make sure that it exists how I think it is we'll look for

shadow light and here we have a uniform VC three Shadow light position which is the shadow light sunent and moon position and ey space so let's copy that

we want that information from Minecraft so we'll paste that here we'll copy the name of it and what we're going to do here is we're going to compare the face

normal to the sun normal to get sunlighting but we'll do that in let's say lighting style two because lighting style one here is kind

of just default Minecraft lighting so we'll paste that down here and let's grab our little thing

here paste it here and we'll make if lighting style equals two close that with an end if and this has to

have all of our shading stuff in it so what we need to do is we would still take our torch color because let's say we still want torch

color so we'll put that in here and then we want our color to be multiplied by torch color and instead of the light map let's take

the um something with the shadow light position so let's see this line was our torch lighting this line was our

skylighting what we'll do is we'll comment that out right now and we'll instead take the uh the dot product which is

comparing the two angles and we're going to compare the shadow light position like I said we need to normalize that because when we do dot product we want things to be only one long and the Sun

is probably further away than one so we're going to compare that so we're inside of dot the first thing is the sunlight position let's say the second

one is going to be the um the normal of the texture that might just be GL normal or GL normals if this isn't we're going to

get an error and I'm going to look it up in another Shader um and we want to make sure that this value is a zero to one range since light is only going to be zero black to white being one so we're

going to take this whole thing and put it inside of a clamp clamp is an open GL function that limits something it clamps the value between two things so we're going to clamp this between 0 and one

otherwise we'll get Negative values of brightness when something's facing away from the Sun and let's save this and see if this works and this should give us lighting

towards the Sun and towards the moon oh wait we didn't make lighting style to be an option so let's go back to our

settings and of lighting style 0 and one we'll add a two in there and save it and then now if we get back in Minecraft reload our

Shader Shader pack settings let's put lighting style to two unexpected token so we've got something going wrong so let's look at our code and see

what we did okay so it's times that and it needs to be plus this so let's do a plus see if that does it if that does it I might have remembered things correctly

if not we'll need to look stuff up you always need to look stuff up so says we got an error let's go to our new and paste

it and it's just it's not giving us information that we can really use that's um oh I type out here I wanted that to

be GL normals let's see if that does anything it does not so I'm going to let's see look somewhere else let's

see what we've got in here if this does anything got GL GL here we go GL normals like that let's see if that exists in the fragment

Shader as well looks like I was missing a capital and I put an S where it shouldn't be okay it doesn't want to do that now that

means the Geon normal is probably only available in the vertex Shader so we're going to take it and pass it forward to the fragment

Shader so what we're going to do is we're going to create our own varing and we'll call this normals for the face

and then here we're going to have that equal the GL normal I mess it up this needs to be what is it it's a VC three let's say and then we have normal

SP do XYZ equals g normal doxyz okay I took a break cuz I messed something up um let's get back into

this okay so in gb's vertex Shader we've got our varying VC 3 normal space that we're going to take this information of the normal map I mean the information of

which direction each face is pointing and we're going to have that equal the gormal which is the way it's facing just in its model wherever it is rotate it

and everything in the right way normalize it so it's 0 to one and that's what we're doing in the vertex Shader and we're passing it with the varying and like I said in the newer ones that

should been out in our fragment Shader we are taking it in as a varying and then what we're going to do is we're going to say that the dis the distance

or the the dot product between the light and the the thing would be again a 0 to1 range of the Shadow light position which is the Sun or the moon the dot product

Compares that to our normal space and then we're going to take that and we're going to add that in right here so that our color is our color

times the torch light plus this sun Direction which is the the dot product of that we can also just take this and

put it in there if we wanted to just kind of put that there and do this here um but we'll keep it separate so

that we can maybe make adjustments to how right we want a torch color and and this and that see that line is where I had it inside of there so we have our color is

the color times torch light plus the light dot let's save that go in Minecraft we'll refresh it and we see if the Sun is over there we have

light and things that are facing it if we do time set to like around noon where the sun is facing up and things are lit when they're facing the sun over

there and if we do time set this then when the sun's over there only things facing it are lit and that's your

basic shading is just comparing the angle of the face to where the sun is but with this this didn't have shadows so down here there's Shadow there's light coming where it shouldn't be

whereas if we go back to fighting style zero which had the Shadows built in already um sunlight probably isn't getting down in there but you see this

is much less dramatic it's got light in the shadows and everything it had some configurations for that um so let's go back to our lighting

stock 2 that we just made and in our code let's add back in the Skylight where things have light

exposed to the sky and then we've got a light for where the sun is let's see what that looks like okay so now we still have

this dramatic lighting but we also have some uh some brightness on these ends that are are looking towards the sky it looks

like these things pointing in the opposite direction are still kind of kind of black so maybe we didn't clamp this

right we did not so let's let's clamp this between a 0 to one 0 comma 1 and what that does is it makes it so that the lowest it can be zero and the brightest can can be in is

one um because otherwise if we compare these angles all these ones pointed away are negative values and that would make things darker than they

should be so we come back in here and load now we can see that these parts pointing away from the Sun aren't Negative black but they're just the the

sun exposure or the sky exposure to them so cool now we just made uh torch light and skylight and we have sunlight and we did this on

our own um but we didn't do the Shadows yet we've already got that code in the other thing and we'll go over that in another episode

um let's look at fog real quick I scratch that so to review the what we're doing in lighting in our

new lighting style too is all that the Shader is doing is first it's loading the texture and it's multiplying it by the vertex color we're

taking the light map cords and we got these all of these things from the uh vertex Shader uh we're also taking the normals of our

face which we got from the vertex Shader and what we did is we took the vertex data by its Matrix which put it into the camera view put that in a 0 to1

range and then we took that 0 to1 range and we compared it to the position of the sun which was also in a 0 to one range did the dot product which does

that comparison clamped it between 0 to one to give us that that light Dot and then that gives us our sunlighting so here we have torch

light here we have skylight here we have sunlight and as we saw um by taking the texture value we get a dynamic Sky color

but we also if we wanted to could do our own Sky color um and make it up and then change it based on different things like like sun

angle and that and there's a lot of other things we can do with information like that which is why you want to be familiar with these these documentation um CU a lot of them kind

of are multiple similar things so if we did just the sun position we wouldn't also get the moon position when it switches this gives us both at the same time we can also have an up position so

something we could do with that is we could say maybe we want the Skylight to only be um on things facing up um and there's all kinds of other

stuff we can do in here so you can just search and look for things and find stuff uh next episode I think we'll do fog and then that might get us to more

of a regular Shader um there's also things like World Time moon phase there's all kinds of things that we can do cool effects with when we want to

um held items like all of this stuff is information we can get from Minecraft that we can do things with so we can make night vision effects blindness

effects um all kinds of stuff

Loading...

Loading video analysis...