Research on Surface shader

Source: Internet
Author: User
Tags unity 5

Surface shaders must be affected by lights and shadows. Surface shaders is a shader that is easier to write light-it is an abstract encapsulation with unity.

The standard output structure of the surface coloring tool is as follows: struct surfaceoutput {fixed3 albedo; // diffuse color fixed3 normal; // tangent space normal, if written fixed3 emission; half specular; // specular power in 0 .. 1 range fixed gloss; // specular intensity fixed Alpha; // alpha for transparencies };
In unity 5, the surface coloring tool can also use a physical lighting model. The built-in standard and standard illumination models (see below) Use these output structures: struct surfaceoutputstandard {fixed3 albedo; // base (diffuse or specular) color fixed3 normal; // tangent space normal, if written half3 emission; half metallic; // 0 = non-metal, 1 = metal half smoothness; // 0 = rough, 1 = smooth half occlusion; // occlusion (default 1) fixed Alpha; // alpha for transparencies}; struct surfaceoutputstandardspecular {fixed3 albedo; // diffuse color fixed3 specular; // specular color fixed3 normal; // tangent space normal, if written half3 emission; half smoothness; // 0 = rough, 1 = smooth half occlusion; // occlusion (default 1) fixed Alpha; // alpha for transparencies };
Surface shader Input Structure
Float3 viewdir-contains the view direction for calculating the parallax effect and edge lighting. Float4 and color semantics-contain the color of each vertex to be interpolated. Float4 screenpos-the position of the screen space that contains the reflection or screen space effect. Please note that this is not suitable for grabpass; you need to use the computegrabscreenpos function to calculate the custom UV. Float3 worldpos-contains the location of the world space. Float3 worldrefl-World Reflection vector. Float3 worldnormal-world normal vector.

 

Surface shader compilation command

1. It must be placed in the subshader block instead of pass. The surface coloring tool itself will compile into multiple pass.
2. It uses the # pragma surface... command to indicate that it is a surface coloring tool.

Parameters required by surface shader

Surfacefunction-which CG function has the surface coloring code.
1. This function should take the following form:
Void SURF (input in, inout surfaceoutput O)
Input is the structure you define. The input should contain any texture coordinates and additional automatic variables required by the surface function.

2. lightmodel-lighting model used.

Built-in standard and standardspecular Based on physics, as well as simple non-physical Lambert (diffuse) and blinnphong (mirror ). See the custom Lighting Model page to learn how to compile your own.
The standard lighting model uses the surfaceoutputstandard output structure and matches the standard color in unity.
The standardspecular lighting model uses the surfaceoutputstandardspecular output structure and matches the standard shader in unity.
Lambert and blinnphong lighting models are not physical-based (Unity 4.x), but their pasters can be used for faster rendering on low-end hardware.

Simple surface shader example
Example: shader "example/diffuse simple" {subshader {tags {"rendertype" = "Opaque"} cgprogram # pragma surface surf lamstruct input {float4 color: color ;}; void SURF (input in, inout surfaceoutput O) {o. albedo = 1;} endcg} fallback "diffuse "}

 

Research on Surface shader

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.