Shaders: vertex and fragment programs - Unity Shader Reference 番外2

这篇博客介绍了如何在Unity中编写顶点和片段着色器程序,包括ShaderLab的基础知识和使用Cg/HLSL编写自定义着色器。通过实例展示了如何使用顶点和片段程序,以及如何利用UnityCG.cginc文件和属性。着重强调了在图形硬件上关闭固定功能并使用可编程管线的能力。
摘要由CSDN通过智能技术生成

Shaders: vertex and fragment programs

着色器:顶点与片断程序

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.2版本
参考链接:https://docs.unity3d.com/Manual/ShaderTut2.html

This tutorial will teach you the basics of how to write vertex and fragment programs in Unity shaders. For a basic introduction to ShaderLab see the Getting Started tutorial. If you want to write shaders that interact with lighting, read about Surface Shaders instead.
本教程将向您介绍如何在Unity着色器中编写顶点和片段程序的基础知识。对于ShaderLab的基本介绍,请参阅入门教程。如果你想要写与灯光交互的着色器,那就去阅读表面着色器吧。

Lets start with a small recap of the general structure of a shader:

Shader "MyShaderName"
{
    Properties
    {
        // material properties here
    }
    SubShader // subshader for graphics hardware A
    {
        Pass
        {
            // pass commands ...
        }
        // more passes if needed
    }
    // more subshaders if needed
    FallBack "VertexLit" // optional fallback
}

Here at the end we introduce a new command: FallBack “VertexLit”. The Fallback command can be used at the end of the shader; it tells which shader should be used if no SubShaders from the current shader can run on user’s graphics hardware. The effect is the same as including all SubShaders from the fallback shader at the end. For example, if you were to write a fancy normal-mapped shader, then instead of writing a very basic non-normal-mapped subshader for old graphics cards you can just fallback to built-in VertexLit shader.
在这里,我们引入了一个新的命令:回退(FallBack) “VertexLit”。回退命令可以在着色器的末端使用;它告诉我们,如果当前着色器中没有子材质可以在用户的图形硬件上运行,那么应该使用哪个着色器。其效果在所有子着色器是一样的被包含在最后的回退着色器中。例如,如果您要编写一个漂亮的法线映射着色器,而不是为旧的图形卡编写一个非常基本的无法线映射的子着色器,您可以直接回退到内置的VertexLit着色器。

The basic building blocks of the shader are introduced in the first shader tutorial while the full documentation of Properties, SubShaders and Passes are also available.
着色器的基本构建块是在第一个着色器教程中引入的,而属性、SubShaders和Passes的完整文档也是可用的。

A quick way of building SubShaders is to use passes defined in other shaders. The command UsePass does just that, so you can reuse shader code in a neat fashion. As an example the following command uses the pass with the name “FORWARD” from the built-in Specular shader: UsePass “Specular/FORWARD”.
构建子着色器的一种快速方法是使用在其他着色器中定义的passes。UsePass的命令就是这样做的,所以您可以以一种整洁的方式重用着色器代码。作为一个例子,下面的命令使用来自内置的高光着色器的“FORWARD”这个名称

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值