1 Preliminaries

Cg programming in the game engine Unity is considerably easier than Cg programming for an OpenGL or Direct3D application. Import of meshes and images (i.e. textures) is supported by a graphical user interface; mipmaps and normal maps can be computed automatically; the most common vertex attributes and uniforms are predefined; OpenGL and Direct3D states can be set by very simple commands; etc.


在 Unity 引擎中使用 Cg 进行图形编程比为 OpenGL 或是 Direct3D 应用程序编程更容易。导入的模型和图片(也就是贴图)通过一个图形化用户界面被支持;mipmaps 和法线贴图可以被自动计算;最常用的顶点属性和特定参数都被预定义了;OpenGL 和 Direct3D 的状态可以用非常简单的命令来设置;等等。


1 Preliminaries 前言

A free version of Unity can be downloaded for Windows and MacOS atUnity's download page. All of the included tutorials work with the free version. Three points should be noted:


可以在 Unity's download page页面下载到 Windows 平台和 MacOS 平台的Unity 免费版本。所有教程都运行于免费版本。要注意以下三点:

  • First, this part is about vertex and fragment shaders in Unity. This kind of shader programming is particularly flexible and allows you to program very efficient shaders, which is often important when rendering performance is limited, e.g., on mobile devices. It's also very useful for image effects and to understand how GPUs work in general. Programming vertex and fragment shaders is less useful if the standard lighting of Unity should be taken into account. (In that case, Surface Shaders are preferable in Unity.)


    首先,这部分内容是关于 Unity 中的 vertex 和 fragment shaders。这类的shader编程非常灵活,且允许你编写非常高效的 shader,这对于渲染性能有限的设备,比如移动设备,通常是非常重要的。它对于影像效果和理解 GPUs 大体上是如何工作也非常有用。如果引入 Unity 的 standard lighting 的话,编写vertex 和 fragment shaders 就不那么有用了(如果那样的话,使用 Unity 中的 Surface Shaders更可取)。


  • Second, this part assumes that readers are somewhat familiar with Unity. If this is not the case, readers should consult the first two sections of the Unity Manual (Unity Basics and Building Scenes).


    其次,这部分内容假定读者熟悉Unity。否则,读者应该查阅 Unity 手册的前两章。


  • Third, Unity doesn't distinguish between Cg (the shading language by Nvidia) and HLSL (the shading language in Direct3D) since the two languages are very similar; thus, most of these tutorials also apply to HLSL.


    第三,Unity 并没有把 Cg(Nvidia 的着色语言)和 HLSL(Direct3D 的着色语言)区别开来,因为两种语言非常相似;因此,大多数这些教程也适用于 HLSL。


  • Furthermore, Cg is documented by Nvidia's Cg Tutorial and Nvidia's Cg Language Specification. However, these descriptions are missing the details specific to Unity. On the other hand,Unity's shader documentation focuses on Unity's ShaderLab syntax and assumes that readers are familiar with Cg. Thus, learning Cg programming in Unity without prior knowledge of Cg can be rather difficult. This wikibook tries to close this gap by providing an introduction to Cg programming in Unity without requiring prior knowledge of Cg.


    此外,Cg 在《 Nvidia 的 Cg 教程 》和《 Nvidia 的 Cg 语言规范 》中都有讲解。然而,这些描述缺少针对于 Unity 的细节。另一方面,Unity 的着色器文档着重于 Unity 的 ShaderLab 语法并且假定读者熟悉 Cg。因此,在没有 Cg 基础之前在 Unity 中学习使用 Cg 进行编程是相当困难的。这本维基教科书试图提供一个在没有 Cg 基础的情况下在 Unity 中使用 Cg 编程的介绍,以填补这个空白。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值