Untiy 3d Shaderlab_ 7th _ forward Render path _1_forwardbase and Forwardadd

Source: Internet
Author: User
Tags mul

7th Chapter Forward Render Path
The main purpose of this chapter is to make it possible to customize the shader of your forward render path by allowing you to correctly access Unity's light source data while not using unity's surface shader. If the reader does not have this requirement, or if it has been understood how unity holds the source data for the forward render path, then this chapter can be skipped.
7.1ForwardBase and Forwardadd
Forwardbase and Forwardadd are two passes designed specifically for rendering objects under the forward rendering path, whichThe forwardbase will be executed prior to Forwardadd. These two types of passes have different forward rendering paths.Lighting processing functions. Before we explain the forward pass, let's first check out these two different forward passperformance under different render paths.
7.1.1 Design and inspection of the scene and materials

Open the scene under the Lab_0. There are 3 renderingpath in this scene, Vertexlit,forward and deferred, respectively, and there are plenty of parallel lights, point light sources, pixel light sources and vertex light sources in the scene.

The first row of balls is applied to the material under Lab 0/shader. Fwdbase.shader, just output a blue in the pass of Lightmode= forwardbase (0, 0.5, 1.0, 1.0), The third row of small ball is used fwdaddx.shader, in lightmode = Forwardadd pass within the output of a (1.0,0,0,1.0) Red, the third row of ball application is Fwdadd.shader, the orange color of a (1.0, 0.5, 0,1.0) is only output in the pass of Lightmode = Forwardadd.


The main code for Fwdbase.shader is as follows:
Shader "Tut/lighting/forward/lab_0/fwdbase" {subshader {pass{//This pass is only used to count a certain color to check the performance of this type of pass under different rendering paths tags{ "Lightmode" = "forwardbase"}cgprogram#pragma vertex vert#pragma fragment Frag#pragma multi_compile_fwdbase#include " Unitycg.cginc "#include" lighting.cginc "struct vertout{float4 pos:sv_position;float4 color:color;}; Vertout Vert (Appdata_base v) {vertout o;o.pos=mul (Unity_matrix_mvp,v.vertex); O.color=float4 (0,0.5,1,1);// Enter a fixed blue return o; FLOAT4 Frag (vertout i): Color{return I.color;} Endcg}//end Pass}}

The main code for Fwdadd.shader is as follows:
Shader " Tut/lighting/forward/lab_0/fwdadd "{subshader {pass{tags{" lightmode "=" Forwardbase "}cgprogram#pragma multi_compile _fwdbase#pragma vertex vert#pragma fragment frag#include "Unitycg.cginc" #include "lighting.cginc" struct vertout{ Float4 pos:sv_position;float4 Color:color;}; Vertout Vert (Appdata_base v) {vertout o;o.pos=mul (Unity_matrix_mvp,v.vertex); O.color=float4 (0,0.5,1,1);//Blue return O ;} FLOAT4 Frag (vertout i): Color{return I.color;} Endcg}//end passpass{tags{"Lightmode" = "Forwardadd"}blend one zero//to eliminate the effects of forwardbase by this hybrid cgprogram#pragma vertex Vert#pragma fragment Frag#include "Unitycg.cginc" #include "lighting.cginc" struct VERTOUT{FLOAT4 pos:sv_position; Float4 Color:color;}; Vertout Vert (Appdata_base v) {vertout o;o.pos=mul (Unity_matrix_mvp,v.vertex); O.color=float4 (1,0.5,0,1);// Output a fixed orange return o; FLOAT4 Frag (vertout i): Color{return I.color;} Endcg}//end Pass}} 
The main code for Fwdaddx.shader is as follows:
Subshader {pass{tags{"lightmode" = "Forwardadd"}cgprogram#pragma vertex vert#pragma fragment frag//#pragma multi_ Compile_fwdadd#include "Unitycg.cginc" #include "lighting.cginc" struct VERTOUT{FLOAT4 pos:sv_position;float4 color: COLOR;}; Vertout Vert (Appdata_base v) {vertout o;o.pos=mul (Unity_matrix_mvp,v.vertex); O.color=float4 (1,0,0,1);// Output a fixed red return o; FLOAT4 Frag (vertout i): Color{return I.color;} Endcg}//end Pass}}
the performance of 7.1.2 Forwardbase and Forwardadd
we compile and run it, according to the results shown in the figure above, in vertexlit rendering mode, forwardbase and Fowardadd's lightmode are not supported . In addition, the Fwdaddx.shader has no output under 3 render paths, which Note Forwardadd This pass needs to be used with forwardbase, or it will be ignored by unity. Under the forward and deferred render paths, the forward pass can be rendered normally .

Untiy 3d Shaderlab_ 7th _ forward Render path _1_forwardbase and Forwardadd

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.