![]() ![]() Our Input we set up as uv_Maintex this allows for us to input a texture object. I want to draw your attention to this section of the code:įirst, we define the data types for our inputs and outputs and create a function for us to serve the outputs into unity. Within our block, you can see some code for assigning tags, assigning levels of detail (LOD), and the CGPROGRAM block. For example, depending on the graphics hardware you want to support, you can make shaders for the various graphics APIs. You can define multiple sub shaders for many different uses. The second block is our SubShader this is where our shader logic goes. There’s a bit to these values but suffice it to say, both values are default white. We also defined the default values for these properties. Using square brackets, I outlined which property was the default color and default texture. We defined two properties, the MainColor and the MainTexture. This allows for different configurations within Unity by creating things like sliders and inputs within the Inspector window for us to play around with. A material property is what Unity stores along with our materials. The properties box is where we define the properties for our materials. Within the Shader block curly brackets, we have our other sections. Here you can see the name of our shader and that it is in the “Custom” directory. You can use this to define your properties, create many shaders using the SubShader blocks, assign custom options, and assign a fallback shader object. ![]() This is used to define our Shader Object. The first thing at the top, starting with “Shader,” is the Shader Block. It looks a bit much to anyone new to this, including myself, so let’s take it a section at a time. Here is the complete, minimal shader code: I created some basic shader code you can use. Open the Shader file, and let’s check out the code. You can configure your choice of IDE I have VSCode configured. Unity will launch an IDE for use to check out the code. Now go back to the Project window and double click our new Shader file. ![]() You should see this in the Inspector Window. We have just applied our shader to the materials. Finally, drag the shader file over to the inspector window with our sphere covered in our new material. Click the sphere in the Scene window to bring up the Inspector Window. Now right-click our Shaders folder scroll to Create -> Shader -> Standard Surface Shader. After that, drag our new material into the Scene Window where our sphere is and onto the sphere we made. We will use this new material to add our new shader to the 3D Mesh. Materials are similar to skins we can apply to 3D objects. Double click into the Materials folder, right-click and Create is right at the top -> click Material. In the Project Window, right-click on the word Assets and create two new folders, Materials and Shaders. Now we have a 3D Mesh on the screen that we can begin adding things to it. In the Hierarchy Window, right-click and scroll to 3D Object and click whichever object grabs your fancy. I won’t give a full rundown of Unity and the stuff you can do. So download it, and create a new project. The first thing to set yourself up making shaders in Unity is Unity. We’ll be focusing on using ShaderLab to create shaders. What we’ll focus on is adding some basic functionality to a shader. Creating these in Unity allows for a great deal of freedom in what we make. A shader object exists in a shader asset which is just the script we are writing. In Unity, we create shader objects which act as wrappers for our shader program. For the context of Unity, a shader is a small script containing logic and calculations for determining the colors of a pixel. There are other ways to tackle this, but Unity gives an easy setup to get started quickly. We’re going to focus primarily on shaders in Unity. However, I’m writing what I’m learning, so don’t come for me if I’m off on anything.Ī shader is a program that runs on the GPU as part of the graphics pipeline. Like anything else in programming, you pick up momentum with each new thing you build, so I found a tutorial and started making shaders. There’s always some new thing to learn, there’s a bunch of different new languages and toolsets to know, and on top of all that, there’s math. For those of you who love rabbit holes, learning graphics programming is a pretty deep one. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |