Creating a Pixel Shader in Roblox Studio: A Step-by-Step Guide — Transcript
Full transcript
- 0:00This is how to make a pixel shader in
- 0:02Roblox Studios. This is the shader. And
- 0:05how it works is it creates um a bunch of
- 0:09frames that are pixels. And then for
- 0:12every frame, it creates a raycast at the
- 0:16location of the pixel. And then if it um
- 0:19hits something, it'll get the color of
- 0:21what it hits and set the pixel to that.
- 0:24If not, it'll set it to the default
- 0:26color. And this is just to limit how
- 0:30many times it um updates per second. And
- 0:34um I will also put a way for you to get
- 0:37this in the description. So you don't
- 0:40really have to make it yourself, but
- 0:41I'll show you how. First, we go into
- 0:43starter player. And then we go into
- 0:45starter player scripts. Then we're going
- 0:47to add a script. You're going to need
- 0:49these values to start. So we have the
- 0:51player that gets the player of the local
- 0:54script. We have the run surface. It
- 0:57basically runs every update of the game.
- 1:01We have uh we create a new screen GUI
- 1:05and then we get the player GUI and set
- 1:08the screen GUI's parent to the player
- 1:10GUI. Basically, just creating a place
- 1:13for the frames to like display. Next, we
- 1:16have the pixel size. That's how big the
- 1:19pixels will be. The max view distance.
- 1:22That's how far the raycasts will be able
- 1:24to go. The default color, the color that
- 1:28the pixels will be set if the raycast
- 1:31don't hit anything.
- 1:33Border pixel size, that's what that
- 1:36means. Um, I have it set to zero, but if
- 1:39we set that to like one and then this to
- 1:420.9,
- 1:44this is the difference in color between
- 1:46the border and the like pixel color.
- 1:48Okay. So, it basically like outlines
- 1:51every pixel with um like a difference
- 1:55with the of the main color. So, this is
- 1:580.9 difference and it like
- 2:02you can have it if you want. I'll just
- 2:04put it in there so you can mess around.
- 2:07Okay. Um there's the frames. Um obvious
- 2:12frames per second.
- 2:14Um offset. So offset is how many pixels
- 2:18like they'll compensate for the like
- 2:21movement of UI that happens at when the
- 2:25new UI is created or when the game
- 2:28starts and distance. This is like like
- 2:30change in brightness over the distance
- 2:33um of the raycast like how far away it
- 2:36like hit.
- 2:38Okay, now we're on to the setting up the
- 2:43pixels. So, first we're going to make a
- 2:45list of all the pixels. This is going to
- 2:47be just to make it easier to get them
- 2:50all. And we're going to create a
- 2:52function called you can have it whatever
- 2:54you want, but um this will set up the
- 2:57pixels. And we'll make a couple
- 3:00variables at the beginning because the
- 3:03size of the screen can change um when
- 3:06like initializing.
- 3:08We first will like destroy any of the
- 3:10pixels that or get rid of any of the
- 3:13pixels that are already in there. Um set
- 3:16up like an easier way to organize all
- 3:20the pixels.
- 3:22Um we check if the screen size has
- 3:25changed the same after like one up like
- 3:29after a little bit of time and if it
- 3:31hasn't we call the function again and
- 3:34then just return.
- 3:36But if the size is the same. We go
- 3:39through all the y pixels and x pixels in
- 3:42two functions or two for loops. Uh the
- 3:47first for loop we set it to zero for the
- 3:49y and have the end number being the y
- 3:54pixels and the x for the second for
- 3:56loop. The x is also zero and the end
- 4:00number is going to be the x pixels.
- 4:04And you can spawn
- 4:07um them in like this, but it doesn't
- 4:10really help.
- 4:13Um and for creating them, you create a
- 4:17frame, you don't have to set a name, but
- 4:20I just did. Uh you set the size. This is
- 4:24a U di
- 4:26I don't This is um offset. So it's like
- 4:29the actual pixel size like not um scaled
- 4:32to the screen. And for the position it's
- 4:35going to be a scale and you scales are
- 4:39like decimal points like a one to zero
- 4:42basically. So you divide the so this is
- 4:47ba this basically gets the location of
- 4:49where the pixel should be and you divide
- 4:52that by the entire screen size of the x
- 4:56and you do the same for y but instead
- 4:58you subtract the offset so it goes up
- 5:01and over here we do add the offset I
- 5:04forgot to mention that so it does count
- 5:07for the like difference and border pixel
- 5:10that equals the border pixel value
- 5:13The mode is I put it inset and the
- 5:18Z-index I put that as negative one so
- 5:21that other UI can be on top of it. And
- 5:25then the frames parent is just the
- 5:28screen UI. And then you add the frame to
- 5:32the list list of pixels by getting the X
- 5:35value and the Y-value. So it's really
- 5:37easy to find it. And that's why we did
- 5:40this over here and setting that to
- 5:43there. Now we'll have a function for the
- 5:45raycast. This is um not that necessary,
- 5:49but it just looks better. It has two
- 5:52inputs, the X and the Y. And I do
- 5:56recommend um excluding the player the
- 6:00character from the thing. So basically
- 6:03it won't display the character. rays
- 6:06don't really capture how the character
- 6:07looks in like the real game that well.
- 6:10So, I I basically made it so this like
- 6:14character lookalike thing follows your
- 6:16character and it just makes it so you
- 6:19can't see the actual player.
- 6:22Um, the animations don't play on it, but
- 6:25you could if you wanted to. You just
- 6:28have to do a little bit more work. And
- 6:31then you need to create a view which you
- 6:34get the current camera and you get the
- 6:37viewport to array um function and you
- 6:41just plug in the x and y values
- 6:44and then you create a way array by
- 6:46getting the workspace and then there's a
- 6:48function called raycast. You get the
- 6:51origin which is the like point of which
- 6:54the ray was cast, the view direction
- 6:57which is like where to point the ray and
- 7:01then the distance. It will basically you
- 7:03multiply the view direction by the
- 7:05distance. That basically um tells it how
- 7:08far the ray should go. And then you just
- 7:10give it the parameters and return the
- 7:13ray. And now to update all the pixels,
- 7:17we're going to create another function.
- 7:20And we just get the other values that we
- 7:22had up when we created the frames. And
- 7:25then I we have these values. They're
- 7:28just kind of um to optimize the code a
- 7:32bit I would say because it is quite
- 7:34laggy with um a pixel size of 10 and
- 7:39three frames. It is a little three
- 7:42frames a second. Still is pretty laggy.
- 7:46Well, and not that much, but you can
- 7:48notice like delay in the mouse. We got
- 7:51the color, which is just a new color. We
- 7:54have the max distance inverted. This
- 7:57basically calculates forehand, so we
- 7:59don't have to do it every time. And
- 8:02default color, default border color
- 8:04again. Then the X positions. This is
- 8:07basically so we can do the
- 8:08multiplication beforehand. Y position,
- 8:11we also did that beforehand over here.
- 8:14And we have basically the same thing as
- 8:17up up here. Two for four loops. Um, we
- 8:21get the pixel by doing basically the
- 8:24opposite of this. Well, we do the exact
- 8:27same thing. We just get it instead of
- 8:30setting it. Um, and then the ray results
- 8:33is just the calling the function of the
- 8:35raycast and putting the x pixel and the
- 8:37y pixel in. And then if there are ray
- 8:40results that is necessary because if
- 8:42there isn't and we do um the rest of
- 8:45this code it will not work but that's
- 8:48why there is a default color also create
- 8:51an instance color the like color of the
- 8:54part that it hit and then we will have
- 8:56the RGB values just separated for easy
- 9:00like use over here and then if there is
- 9:02a distance we get the distance and
- 9:04multiply it by the
- 9:07um opposite of the view distance over
- 9:10here. Change how bright it will be
- 9:13depending on the distance. And you just
- 9:15um new color and multiply all of it. RGB
- 9:18times the distance. And then for the
- 9:20border color, RGB, but we'll also add
- 9:24the BPB, border pixel brightness. And
- 9:29you just have an else and do um it
- 9:32without the distance if we don't have it
- 9:34um it enabled. And then if we don't have
- 9:37array cast, we just set it all the the
- 9:40colors to default color. Okay. And now
- 9:43we can call the setup function and that
- 9:46will just set up everything. And now for
- 9:48the frame rate stuff. So we'll have a
- 9:52function called frame. And the frame
- 9:54will be will add the elap elapse which
- 9:58is basically time since the last time it
- 10:00uh updated. And then if the frame is
- 10:03greater than or equal to um one divided
- 10:06by the frame rate we'll set the frame to
- 10:08zero the and we'll update it
- 10:11initializes. And you can see if we go to
- 10:16view and performance we can see in here
- 10:20the CPU is working a little over the
- 10:23max. It does kind of bump up to 50
- 10:27sometimes, but you can kind of change
- 10:31the
- 10:32pixel size and the FPS to
- 10:36fit your needs. And if you can, you try
- 10:39to optimize the updates. You can if you
- 10:42want, but I don't think you can do that
- 10:45much. I tried to find out how to run any
- 10:48code on the GPU because um let's go back
- 10:54to the performance.
- 10:56The we can see the GPU is not doing
- 11:01anything right now, but I don't think
- 11:03there's a good way. Don't mind that.
- 11:05That's because I like
- 11:07broke that. And that's how you make a
- 11:08pixel shader in Roblox Studios.
About this transcript
This page contains the full transcript of Creating a Pixel Shader in Roblox Studio: A Step-by-Step Guide by ACStudio, generated from the public captions YouTube serves with the video. The transcript has 1,698 words across 227 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.