First, three basic types of shader in unity

Source: Internet
Author: User

Fixed function shader (Shader)

Fixed function shader renders the specific performance of the pipeline for fixed functions. More simple and compatible with older machines

second, surface shader

A technology that exists in Unity3d by U3d. Untiy3d for us to wrap up the complexity of shader, reduce the writing threshold of shader, and create a surface shader

third, vertex shader and fragment shader

The GPU contains two components: a programmable vertex processor and a programmable fragment processor, a vertex and fragment processor separated into a programmable unit, a programmable vertex processor is a hardware unit that can run a vertex program, and a programmable fragment processor is a unit that can run a fragment program. Vertex shader: The vertex shader extracts the entity information (vertex position, normal vector, texture coordinate) from the front end of the GPU, and completes the operation of vertex coordinate space transformation, normal vector space transformation, illumination calculation, and finally transfers the computed data to the specified register. The fragment shader fragment program obtains the required data from the above registers: texture coordinates and illumination information, and the color calculation (texture query) of each fragment based on this information and the texture information passed from the application, and finally the processed data is transferred to the raster Operation module.

three kinds of shaders in common:

prooerties parameter section, the function and syntax are exactly the same.
The specific functions are in Subshader.
can be labeled
Three shaders different points
surface shader has no channel pass{}, add error, the shader has packed the specific content in the light model.
fixed rendering pipeline after each sentence code does not have ";"
core structure is different:

the core of a fixed rendering pipeline is:material{} and settexture[_maintex]{}the core of the vertex and fragment shader is:cgprogram
#pragma vertex vert
< span data-filtered= "Filtered" >#pragma fragment Frag
#include " Unitycg.cginc "
ENDCG The core of the surface shader is: 1. The surface shader uses the Unity3d self-illuminated model Lambert, and does not do vertex processing, Only one surface treatment function surf is required.
cgprogram
#pragma surface surf lambert
ENDCF
2. This set represents the use of their own written lighting model Lsylightmodel, and used the vertex handler function vert
cgprogram
#pragma surface surf Lsylightmodel vertex:vert
ENDCG Ii. The overall framework of shader

1, from this picture can be seen, unity in the shader can be divided into the following three modules:properties are generally defined as the starting part of the shader. The property module can define properties that specify what input that code has. You can edit these properties directly in the material panel when using shader. The syntax within a properties block is a single line. The definition format for the property is as follows:

Attributes can be categorized into the following categories:

1), number and slide bar
name ("Display Name", Range (Min, max)) = number//sliding bar adjustment
name ("Display Name", Float) = number//Digital Adjustment
name ("Display Name", Int) = number//Digital Adjustment
Color and vector (note four-dollar number)
name ("Display Name", Color) = (number,number,number,number)
name ("Display Name", Vector) = (number,number,number,number)
2), stickers
name ("Display Name", 2D) = "Defaulttexture" {}
name ("Display name", cube) = "Defaulttexture" {}//cube map
name ("Display Name", 3D) = "Defaulttexture" {}
3), details
the properties of range and float can only be single-precision values.
in the subsequent shader program, the property value is accessed through [name]. Display name is displayed in the material viewer.
You can use the equals sign in the property definition to provide a default value for each property.
The default value for a texture (for a single, Rect, Cube) can be either an empty string or a built-in default texture: "White", "black", "gray" or "bump"
using the example
Properties for a water shader
Properties
{
_wavescale ("Wave scale", Range (0.02,0.15)) = 0.07//Sliders
_refldistort ("Reflection Distort", Range (0,1.5)) = 0.5
_refrdistort ("Refraction Distort", Range (0,1.5)) = 0.4
_refrcolor ("Refraction color", color) = (..,. 1)//color
_reflectiontex ("Environment Reflection", 2D) = "" "{}//Textures
_refractiontex ("Environment refraction", 2D) = "" "{}
_fresnel ("Fresnel (A)", 2D) = "" "{}
_bumpmap ("BumpMap (RGB)", 2D) = "" {}
}

2, child shader Subshader

I'll elaborate on this in the next article.

3, Roll back fallback
The end of the shader basic framework is to specify a rollback function fallback that is used when all child shaders are not running (when the target device is too old, all devices have an unsupported feature when used fallback) and can be considered a defult.

First, three basic types of shader in unity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.