Shader Introductory study Notes

Source: Internet
Author: User

Basic structure of shader program



Learn in the code and the notes are all written.


Shader "First Fantasy/water/water diffuse" {//define shader properties; Properties {/* Format: _name ("Display Name", type) = Defaultvalue[{options}]; {_name-Name of the property, variable name. Display Name-This string will be displayed in Unity's material editor as the user-readable content of shader-the type of this property, the possible type is represented by the following: color-a color, Defined by four quantities of rgba (red, green, and transparent); 2D-a map of 2 of the order size (256,512, and so on). This poster will be converted to the corresponding color of each pixel based on the model Uvs after sampling, which is eventually displayed; Rect-a map of a non-2-order size; cube-the cube map texture (cube texture), which is simply a combination of 6 linked 2D maps, It is mainly used for reflection effects (such as sky boxes and dynamic reflections) and is also converted to the corresponding point sampling; Range (min, max)-a floating-point number between the minimum and maximum values, Generally used as a parameter to adjust shader certain characteristics (such as the cutoff value of transparency rendering can be from 0 to 1, etc.); float-any one floating point; Vector-a four-dimensional number; DefaultValue-defines the default value for this property. Color-an RGBA color defined in 0~1, such as (1,1,1,1); 2d/rect/cube-For a map, the default value can be a string representing the default tint color, either an empty string or "white", "black", "gray", " A float,range in Bump "-a specified floating-point vector-a 4-dimensional number that is written as (x,y,z,w) {option}-it is only about 2d,rect or cube mapping, and at least we have to write a pair of blank blanks after the map when writing the input. {}, when we need to open a specific option, we can write it in the curly braces. If you need to open more than one option at the same time, you can use whitespace delimited. Possible choices are objectlinear, Eyelinear, SphereMap, Cubereflect, and Cubenormal, all of which are texgen patterns in OpenGL. } */_maintex ("Base (RGB)", 2D) = "White" {}_mainteXcolor ("Diffuse", Color) = (1,1,1,0.55) _maintexmultiply ("Multiply", Range (0,5)) = 1_maintexmovespeedu ("U Move speed", Range ( -6,6)) = 0.5_maintexmovespeedv ("V Move Speed", Range ( -6,6)) = 0.5}subshader{//The hardware will determine when to invoke the shader by determining these tags. ;/* "Queue" = "XXX"---Specify render order queue {Background (1000)-the first called Render, used to render the sky box or Background Geometry (2000)-This is the default value for rendering non-transparent objects (in general, The vast majority of objects in the scene should be opaque) alphatest (2450)-used to render alpha test pixels, setting a queue for alphatest alone for efficiency reasons transparent (3000)- To render a transparent object in a backward order overlay (4000)-The effect of rendering overlay, is the final stage of rendering (such as lens flare, etc.) (PS: We can also specify their own Queue value, written like this: "Queue" = "transparent+100" , which represents a call on a queue of 100 after transparent. By adjusting the queue value, we can make sure that some objects must be rendered before or after other objects, and this technique is sometimes useful. } "Rendertype" = "Opaque"-renders non-transparent object "rendertype" = "Transparent"-renders the object containing the transparent effect "ignoreprojector" = "True"-- Not affected by projectors "forcenoshadowcasting" = "true"--never produces a shadow */tags {"Queue" = "Transparent" "ignoreprojector" = "true" " Rendertype "=" Transparent "} zwrite offalphatest Greater 0Blend srcalpha oneminussrcalpha//level of detail of abbreviation;/* In Unity's quality settingsWe can set the maximum allowable Lod and the Subshader will not be available when the LOD is less than the LOD specified by Subshader. Unity built-in shader defines a set of LOD values that we can use as a reference to set our own LOD values when we implement our own shader, so that you can control it more precisely when you adjust the image according to the device's graphics performance. {Vertexlit and its series = 100Decal, reflective vertexlit = 150Diffuse = 200Diffuse Detail, reflective bumped unlit, reflective Bump ed Vertexlit = 250Bumped, specular = 300Bumped specular = 400Parallax = 500Parallax specular =--} */lod 200//A start tag that indicates from this In the beginning is a CG program; Cgprogram/* declares that we are going to write a surface shader and specify the lighting model; Format: #pragma surface surfacefunction Lightmodel [Optionalparams]{surface- The name of the method that declares a surface shader Surfacefunction-shader code-Lightmodel-uses the lighting model. } */#pragma surface surf lambert//!!! For this CG program, you must declare with the same name as the previous variable if you want to access the variables defined in the properties. //sampler2d is the type of 2D map in GLSL, corresponding, Sampler1d,sampler3d,samplercube and so on. sampler2d _maintex;fixed4 _maintexcolor; Fixed _maintexmultiply;fixed _maintexmovespeedu;fixed _maintexmovespeedv;struct Input {//declares a uv_ Maintex a variable containing two floating-point numbers. FLOAT2 uv_maintex;};/ * When calculating the output, shader calls the surf function multiple times, giving each point coordinate on a map to calculate the output. The second parameter is a writable Surfaceoutput,surfaceouTput is a predefined output structure, and the goal of our surf function is to fill in the output structure based on the input.     The SURFACEOUTPUT structure is defined as follows: struct surfaceoutput{half3 Albedo;     The color of the pixel half3 Normal;   The normal value of pixels is half3 emission;    The divergence color of pixels half specular;       Pixel specular highlight half Gloss;       The luminous intensity of the pixel half Alpha; transparency of Pixels}; Surfaceoutput O-This is the output */void surf (Input in, InOut surfaceoutput O) after the surface calculation function surf Processing {FIXED2 MAINTEXMOVESCROLLEDUV = in.u v_maintex;fixed maintexmoveu = _maintexmovespeedu * _time;fixed Maintexmovev = _maintexmovespeedv * _Time; Maintexmovescrolleduv + = Fixed2 (Maintexmoveu, Maintexmovev);//tex2d function, a CG program that uses a method of sampling a point in a poster to return a float4.; Half4 C = tex2d (_maintex, MAINTEXMOVESCROLLEDUV); O. Albedo = C.rgb * _maintexcolor * _maintexmultiply;o. Alpha = _MAINTEXCOLOR.A;} ENDCG} FallBack "Diffuse"}


Shader Introductory study Notes

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.