[Xiao Ming learns shader] 4. Custom Lighting----Ramptexture

Source: Internet
Author: User
Tags ming

The previous article, which halflambert the custom illumination, is similar to this one, but when it is calculated, it is no longer multiplied by the direction and Atten.

The Halflam of the light incident direction and the point product of the method are used as coordinates, and the RGB values of the Ramptexture (Halflam,halflam) points are found as the mixed values multiplied by the albedo and incident light colors of S.

The code is as follows:

Shader"CUSTOM/11.26/2"{properties{_ramptex ("Ramp Texture", 2D) =" White"{} _maintex ("Ramp Texture", 2D) =" White"{}}subshader{tags{"Rendertype"="Opaque"} LOD $Cgprogram#pragmaSurface Surf Rampsampler2d _ramptex;        Sampler2d _maintex; structinput{FLOAT2 Uv_maintex;        }; voidSurf (Input in,inout surfaceoutput o) {half4 c=tex2d (_maintex,in.uv_maintex); O.albedo=C.rgb; O.alpha=C.A; } inline Float4 Lightingramp (surfaceoutput s,fixed3 lightdir,fixedatten) {        floatlightdif=dot (s.normal,lightdir); floathalflam=0.5*lightdif+0.5; FLOAT3 Ramp=tex2d (_RAMPTEX,FLOAT2 (Halflam,halflam)). RGB;        Float4 Col; Col.rgb=s.albedo*_lightcolor0.rgb*ramp; COL.A=S.alpha; returnCol; } endcg}fallback"Diffuse"}

:

[Xiao Ming learns shader] 4. Custom Lighting----Ramptexture

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.