U3d Shader Forward Path Light storage information

Source: Internet
Author: User
Tags diff
1.Forward add to be used with Forward base. tags{"Lightmode" = "forwardbase"} tags{"Lightmode" = "Forwardadd"} Otherwise forward add is not rendered under any rendering path. 2.Vertex list rendering path, forward shader, will not be rendered out. In the forward or deferred rendering path, the Forward shader is rendered (although it is a custom vertex/fragment Forward shader, the deferred render path should be used in deferred rendering, otherwise the forward/ Vertex light shader). Because the rendering path is like the Path State Highway expressway, the shader lighting rendering mode is similar to the motorcycle trolley, the main road can accommodate all kinds of cars, the path can only accommodate the car. 3.FORWARDADD is the forward rendering path, more than one pixel light will execute the pass, that is, n pixel light source, Forwardadd will be executed n-1 times. 4. Lighting has pixel type, vertex type, corresponding to render Mode important and non-important settings.
A description of the response in the editor\data\cgincludes\unitycg.cginc. First, the light source float4 _worldspacelightpos0; Indicates the position of the light source, _WORLDSPACELIGHTPOS0.W = 0 is a parallel light. Otherwise it is a point light source. FLOAT4 _lightcolor0; Represents the color of a light source. Camera forward and deferred mode: Under Forward path rendering path, only the important and _worldspacelightpos0 with pixel parallel light (_LIGHTCOLOR0) have data. There is no pixel parallel light, but there are pixel point light source WorldSpaceLightPos0 data, _lightcolor0 no data.
Second, the point of light storage, three float4 vector, representing 4 point light source of x,y,z coordinates. FLOAT4 unity_4lightposx0; Storage (x0, x1, x2, x3) float4 unity_4lightposy0; Storage (y0, y1, y2, y3) float4 unity_4lightposz0; Storage (z0, Z1, Z2, Z3) Response: Float4 Unity_4lightatten0 represents the attenuation coefficients of the 4-point light source. FLOAT4 Unity_4lightcolor[4] Represents the color of the 4-point light source. Camera forward and deferred mode: In the case of only forwardbase, unity_4lightpos[xyz]0 and unity_ within Forwardbasepass 4LightColor contains only point light source information (can be pixel point light source and ranking will be more forward).
In the case of Forwardadd, the unity_4lightpos[xyz]0 and Unity_4lightcolor in Forwardbasepass only contain vertex point light source information (no pixel point light source). And within the unity_4lightpos[xyz]0 are the positions in the world coordinate system. In Forwardaddpass, only more than two pixel light sources (important) are performed, and no data is available in unity_4lightpos[xyz]0.
General light source information storage FLOAT4 Unity_4lightposition[4] represents the position of the 4-point light source or the directional vector of the parallel light (w = 0 is a parallel light). FLOAT4 Unity_4lightcolor[4] Represents the color of these 4 light sources. FLOAT4 Unity_4lightatten[4] Represents the attenuation of these 4 light sources. No valid data is included in Forwardbasepass and Forwardaddpass.
Iv. Summary: In the forward rendering path, for the vertex light source, you can simply use the shade4pointlights function to compute the illumination in forwardbase (use unity_4lightpos[xyz]0 and unity_, of course). 4LightColor is OK, just does not contain parallel light). For pixel light sources, _worldspacelightpos0 and _lightcolor0 are used in both Basepass and forwardpass to compute the illumination. FLOAT3 shade4pointlights (float4 lightposx, Float4 lightposy, Float4 Lightposz, Float3 lightColor0, Float3 LightColor1, F LOAT3 LightColor2, Float3 LightColor3, Float4 lightattensq, float3 pos, Float3 Normal) {//to light vectors float4 TX = lightposx-pos.x; FLOAT4 tolighty = Lightposy-pos.y; FLOAT4 tolightz = lightposz-pos.z; Squared lengths Float4 lengthsq = 0; LENGTHSQ + = tolightx * TOLIGHTX; LENGTHSQ + = Tolighty * tolighty; LENGTHSQ + = Tolightz * TOLIGHTZ; Ndotl float4 ndotl = 0; Ndotl + = tolightx * normal.x; Ndotl + = Tolighty * NORMAL.Y; Ndotl + = Tolightz * NORMAL.Z; Correct ndotl float4 corr = rsqrt (LENGTHSQ); Ndotl = Max (FLOAT4 (0,0,0,0), Ndotl * corr); Attenuation FLOAT4 Atten = 1.0/(1.0 + lengthsq * lightattensq); FLOAT4 diff = ndotl * atten;Final color Float3 col = 0; Col + = LightColor0 * diff.x; Col + = LightColor1 * DIFF.Y; Col + = LightColor2 * DIFF.Z; Col + = LightColor3 * DIFF.W; return col; }

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.