Introduction to Unity3d Shader shader programming (i)

Source: Internet
Author: User

Self-study Unity3d also has a big six months, to shader has been afraid into the pit, recently read some information, and through their own practice, to shader still have a little understanding, share under only for reference.

Since shader is a rendering of image images, it is possible to understand the knowledge of graphics and GPU programming before learning. The spring snow lowbrow of GPU programming and CG language is highly recommended, and the book is electronically available online.

There is also a book on the development of unity shaders and screen effects for Unity3d's shader, which was translated by Unity Shaders and effects Cookbook.

First look at the effect of the shader implementation:

1. Create a new sphere sphere, and then build a material ball material in project.

2. Assign the new material ball to the materials of the mesh renderer component of the Sphere object

Choose different shader, and adjust the parameters, you can see different effects.

3. Create a new shader in project, and a shader will be written by default when opened.

Shader"Custom/testshader"{//Shader "keyword start" "Custom/testshader" "Shader name, divided well used to group"Properties {//It contains attributes that are assigned in Unity_maintex ("Base (RGB)", 2D) =" White"{}//_maintex The property name "Base (RGB)" Property description, the "2D" property Type "White" "Default" will appear in the Unity panel_alpha ("Transparency", Range (0,1))=0} subshader {//child shader, can write multiple to adapt to different hardware or platformTags {"Rendertype"="Opaque"}//shader Tags "The hardware will decide when to call the shader by determining these tags"Lod $//Level of DetailCgprogram//CG Language started//affirm that the program uses surface shader processing for the following surf, using the Lambert illumination model        #pragmaSurface Surf Lambertsampler2d _maintex;//variables of type sampler2d, names consistent with names in attributes, used to receive unity-passed argumentshalf _alpha; structInput {//struct, for entering dataFLOAT2 Uv_maintex;//uv_ the Uvs used to fetch the incoming map        }; voidSurf (Input in, InOut surfaceoutput o) {//method of surface shaderHalf4 C = tex2d (_maintex, In.uv_maintex);//tex2d method to sample a point in a mapO.albedo = C.rgb;//assigning an RGB color to an outputO.alpha = C.A;//Transparency Assignment} ENDCG//end of CG language} FallBack"Diffuse"//rolling back}

Related information:

Candycat's Blog: http://blog.csdn.net/candycat1992/article/category/1782159

Introduction to Unity3d Shader shader programming (i)

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.