C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Unity - Materials and ShadersEvery beautiful looking game contains a different variety of surfaces. Like metal, plastics, holograms, alien artifacts, and so on. Specifically, physical based Rendering. Rendering in Unity uses Shaders, Materials, and Textures. And three of them have a close relationship. MaterialsIn Unity 3D, a Material is a file that contains information about the lighting of an object with that material. A material has nothing to do with collisions, mass, or even physics in general. It is simply used to define how lighting affects an object with that material. In unity, Materials are not much more than a container for shaders and textures that can be applied to models. Most of the customization of Materials depends on which shader is selected for it, although all shaders have some common functionality. Let's create our new material, for that, first of all, create a new 3D project in Unity. Then right-click on the Assets, and go to Create -> Materials and give a name like 'My Material.' See the properties of Material. These properties are not that we have studied so far. That is because these are the properties that are programmed in the shader, not in the material. Materials are what make our objects visible in the first place. In fact, even in 2D, we use a unique material that does not require lighting as well. ShadersA shader is a program that defines how every single pixel is drawn on the screen. Shaders are not programmed in a C# or even in an object oriented programming language at all. Shaders are programmed in a C-like language called GLSL. This language can give direct instructions to the GPU for fast processing. Shader's scripts have mathematical calculations and algorithms for calculating the color of each pixel rendered, based on the lighting input and the material configuration. If the texture of a model specifies what is drawn on its surface, the shader is what determines how it is drawn. In other words, we can say that a material contains properties and textures, and shaders dictate what properties and textures a material can have. TexturesTextures are flat images that can be applied to 3D objects. Textures are responsible for models being colorful and interesting instead of blank and boring. It looks strange to think that a 2D image can be applied to a 3D model, but it is a very simple and straight forward process once you are familiar with it. Let's see one simple example: think about a water bottle, if you have taken off the label of a water bottle, you would see that it is a flat piece of paper. That label is like a texture. After the label is printed, it is then wrapped around the 3D bottle to provide a more pleasing look. Just all other assets, adding texture to a Unity is very easy. To create texture in Unity, simply create a folder for your textures; a good name would be Textures. Then download and drag any texture you want in your project into the Textures folder you just created. That's it. To create a folder, right click on the Assets and go to Create -> Folder. Rename it to 'Textures.' Now download any texture and drag it to that folder.
Next TopicUnity Coroutines
|