创建基本的表面着色器-iso_17356

时间:2024-06-28 11:40:49
【文件属性】:

文件名称:创建基本的表面着色器-iso_17356

文件大小:6.09MB

文件格式:PDF

更新时间:2024-06-28 11:40:49

Unity

1.2 创建基本的表面着色器 随着我们进一步学习本书,你已经知道如何在 Unity 当中设置工作区,从而提高你的工 作效率,而且这很容易实现。如果你已经熟悉了在 Unity 4 中创建着色器和设置材质,可以 跳过这个教程。这里,我们只是为了确保新的 Unity 4 开发者能够顺利学习有关表面着色器 的其他教程。 1.2.1 准备工作 开始学习本教程之前,你需要先打开 Unity 4,并且创建新的项目。在本书中有一个 Unity 项目,所以当你学习到相应的教程时,你可以使用这个项目并添加自定义的着色器。 当你完成了这些,现在就准备进入实时阴影的奇妙世界吧! 1.2.2 如何操作 在开始我们第一个着色器之前,我们需要创建一个小的场景(scene)供我们使用。这 可以通过 Unity 编辑器中的 GameObject | Create Other 菜单来完成。然后可以创建一个平面 作为地面,创建两个球体作为着色器的应用对象,以及一个定向光作为场景的灯光。场景 建立完毕,我们就可以开始编写着色器了: 1. 在 Unity 编辑器的 Project 面板上,右击 Assets 文件,选择 Create | Folder。 如果你使用的是本书提供的 Unity 项目文件,你可以直接跳到步骤 4。 Diffuse Shading 8 To achieve a basic diffuse lighting model, we will have to create a Shader that will include an emissive color, an ambient color, and the total light accumulated from all light sources. The following recipes show you how to build up a complete diffuse lighting model, and also show some various industry tricks that come in handy for creating more complicated diffuse models using only textures. By the end of this chapter you will have learned how to build basic Shaders that perform basic operations. Armed with this knowledge, you will be able to create just about any Surface Shader. Creating a basic Surface Shader As we progress further into the recipes in this book, it is important that you know how to set up your workspace in Unity, so that you can work ef ciently, and without any pain. If you are already quite familiar with creating Shaders and setting up Materials in Unity 4, you may skip this recipe. It is here to ensure that newcomers to surface shading in Unity 4 can work with the rest of the recipes. Getting ready To get started with this recipe, you will need to have Unity 4 running, and must have created a new project. There will also be a Unity project included with this cookbook, so you can use that one as well and simply add your own custom Shaders to it, as you step through each recipe. With that completed, you are now ready to step into the wonderful world of real-time shading! How to do it… Before getting into our  rst Shader, let's create a small scene for us to work with. This can be done by going to GameObject | Create Other in the Unity editor. From there you can create a plane, to act as a ground, a couple of spheres, to which we will apply our Shader, and a directional light to give the scene some light. With our scene generated, we can move onto the Shader writing steps: 1. In the Project tab in your Unity editor, right-click on the Assets folder and select Create | Folder. If you are using the Unity project that came with the cookbook, you can skip to step 4.


网友评论