文件名称:创建自定义漫反射光照模型-iso_17356
文件大小:6.09MB
文件格式:PDF
更新时间:2024-06-28 11:40:50
Unity
1.5 创建自定义漫反射光照模型 Unity 自带的光照函数已经很强大了,不过你需要的不仅仅是这些,你可能希望学到更 多并且想要创建大量的自定义光照模型。从实际的经验来看,我们永远不会认为一个只使 用自带光照模型的项目是个好项目。我们希望创建自定义光照模型来实现各种效果,比如 实现边缘高亮的效果,或者实现更多基于立方贴图的光照,甚至你还想控制你的着色器对 游戏过程进行反馈(它可以将所有它能控制的领域反馈给你)。 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.