Cg Programming/Unity
2017-04-18 09:30
495 查看
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
Basics, Asset 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 shouldat least read through the tutorials in the “Basics” section. (Now you are warned!)
Basics[edit]
Minimal Shader (aboutshaders, materials, and game objects)
RGB Cube (about vertex output
parameters)
Debugging
of Shaders (about vertex input parameters)
Shading
in World Space (about uniforms)
Transparent Surfaces[edit]
Cutaways (about discarding fragmentsand triangle-face culling)
Transparency (about blending)
Order-Independent
Transparency (about order-independent blending)
Silhouette
Enhancement (about transforming normal vectors)
Basic Lighting[edit]
Diffuse Reflection (aboutper-vertex diffuse lighting and multiple light sources of different kinds)
Specular Highlights (about
per-vertex lighting)
Two-Sided Surfaces (about
two-sided per-vertex lighting)
Smooth
Specular Highlights (about per-pixel lighting)
Two-Sided
Smooth Surfaces (about two-sided per-pixel lighting)
Multiple Lights (about
for-loops for handling multiple light sources in one shader pass)
Basic Texturing[edit]
Textured Spheres (abouttexturing a sphere)
Lighting
Textured Surfaces (about textures for diffuse lighting)
Glossy Textures (about
gloss mapping)
Transparent
Textures (about using alpha textures for discarding fragments, alpha testing, and blending)
Layers of Textures (about
multitexturing)
Textures in 3D[edit]
Lightingof Bumpy Surfaces (about normal mapping)
Projection
of Bumpy Surfaces (about parallax mapping)
Cookies (about projective texture
mapping for shaping light)
Projectors (about projective
texture mapping for projectors)
Environment Mapping[edit]
Reflecting Surfaces (aboutreflection mapping)
Curved Glass (about refraction
mapping)
Skyboxes (about rendering of environment
maps as background)
Many Light Sources (about
image-based lighting)
Variations on Lighting[edit]
Brushed Metal (aboutanisotropic specular reflection)
Specular
Highlights at Silhouettes (about the Fresnel factor for specular reflection)
Diffuse
Reflection of Skylight (about hemisphere lighting)
Translucent
Surfaces (about diffuse and forward-scattered transmission of backlight)
Translucent Bodies (about
diffuse lighting with reduced contrast and transmission of diffuse backlight at silhouettes)
Soft
Shadows of Spheres (about rendering the umbra and penumbra of spheres)
Toon Shading (about non-photorealistic
rendering)
Non-Standard Vertex Transformations[edit]
Screen Overlays (abouta direct transformation from object space to screen space)
Billboards (about view-aligned
projection of objects)
Nonlinear
Deformations (about vertex blending)
Shadows on Planes (about
projecting shadows onto planes)
Image Effects and Compute Shaders[edit]
Minimal ImageEffect (about basic image post-processing with fragment shaders)
Computing
Image Effects (about using compute shaders for image effects)
Computing
Color Histograms (about computing a color histogram with a compute shader)
Computing
the Brightest Pixel (about finding the brightest pixel with a compute shader)
Miscellaneous[edit]
Bézier Curves (aboutquadratic Bézier curves and splines)
Hermite Curves (about
cubic Hermite curves and splines)
Rotations (about Euler angles
and quaternions)
Projection
for Virtual Reality (about off-axis perspective projection)
Mirrors (about rendering plane mirrors
with render textures)
Missing Tutorials[edit]
Basic Features of Unity[edit]
FogLightmaps
Particles
Halos
Spherical Harmonic Lighting
Generate Cube Texture with ReadPixels
Optimizing Shaders[edit]
Per-Vertex vs. Per-Fragment ComputationsBlending and discard (and Alpha Test)
Precision of Variables
Sampling of Textures
Other Recommendations
Other Topics[edit]
[stub:] WaterReflection 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]
Unity shader reference: http://docs.unity3d.com/Manual/SL-Reference.htmlShaders in the Unity Community Wiki: http://wiki.unity3d.com/index.php/Shaders
Unity user forum about shaders: http://forum.unity3d.com/forums/16-ShaderLab
Video tutorials on graphics: http://unity3d.com/learn/tutorials/topics/graphics
Blog entry about a SIGGRAPH presentation on shader optimization: http://blogs.unity3d.com/2011/08/18/fast-mobile-shaders-talk-at-siggraph/
相关文章推荐
- Cg Programming/Unity/Screen Overlays屏幕叠加
- wiki/Cg Programming/Unity/shder_理解准备
- wiki/Cg Programming/Unity_shder/Minimal Shader
- Cg Programming/Unity/Shading in World Space世界空间中的着色器
- Cg Programming/Unity/Shadows on Planes平面上的阴影
- Cg Programming/Unity/Minimal Image Effect最小的图像效果
- Cg Programming/Unity/Two-Sided Smooth Surfaces双面平滑曲面
- Cg Programming/Unity/Billboards广告牌
- wiki/Cg Programming/Unity_shder/RGB Cube
- Cg Programming/Unity/Two-Sided Surfaces双面表面
- wiki/Cg Programming/Unity/Cutaways
- Cg Programming/Unity/Order-Independent Transparency
- Cg Programming/Unity/Specular Highlights镜面高光
- Cg Programming/Unity/Smooth Specular Highlights平滑镜面高光
- Cg Programming/Unity/Transparent Textures透明纹理
- Cg Programming/Unity/Many Light Sources多光源
- Cg Programming/Unity/Cutaways
- Cg Programming/Unity/Transparency透明度
- Cg Programming/Unity/Cookies
- Cg Programming/Unity/Layers of Textures纹理的层级