Cg Programming/Unity

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.

Preliminaries[edit]

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

  • 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.)
  • Second, this part assumes that readers are somewhat familiar with Unity. If this is not the case, readers should consult the first three sections of the Unity Manual (Unity BasicsAsset Workflow and The Main Windows).
  • Third, Unity doesn't distinguish between Cg (the shading language by Nvidia) and DirectX 9-style HLSL (the shading language in Direct3D 9) since the two languages are very similar; thus, most of these tutorials also apply to DirectX 9-style 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.

Tutorials[edit]

Note that the tutorials assume that you read them in the order in which they are presented here, i.e. each tutorial will assume that you are familiar with the concepts and techniques introduced by previous tutorials. If you are new to Cg or Unity you should at least read through the tutorials in the “Basics” section. (Now you are warned!)

Basics[edit]
Transparent Surfaces[edit]
Basic Lighting[edit]
Basic Texturing[edit]
Textures in 3D[edit]
Environment Mapping[edit]
Variations on Lighting[edit]
Non-Standard Vertex Transformations[edit]
Image Effects and Compute Shaders[edit]
Miscellaneous[edit]

Missing Tutorials[edit]

Basic Features of Unity[edit]
  • Fog
  • Lightmaps
  • Particles
  • Halos
  • Spherical Harmonic Lighting
  • Generate Cube Texture with ReadPixels
Optimizing Shaders[edit]
  • Per-Vertex vs. Per-Fragment Computations
  • Blending and discard (and Alpha Test)
  • Precision of Variables
  • Sampling of Textures
  • Other Recommendations
Other Topics[edit]
  • [stub:] Water Reflection and Refraction (about Water)
  • Shadow Maps
  • Z Priming
  • Chroma Keying
  • Illuminated Lines
  • Ambient Occlusion by Spheres (soft shadows of spheres from skylight)
  • Water Waves (procedural normal mapping)
  • Curved Mirrors (raytraced reflections)
  • Shadow Volumes without Stencil Buffer
  • Animated Sprites
  • Procedural Textures (noise)
  • Glitter Effect

Links[edit]


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值