Vertex deformation of Shader

Source: Internet
Author: User
Tags mul

The 3D object can be bent through vertex deformation, which is common in the runway of parkour game. Can be bent left, right, up, and down.

Shader"custom/vertexcolorcurved"{Properties {//6 parameters required by shader_maintex ("Base (RGB)", 2D) =" White"{} _qoffset ("Offset", Vector) = (0,0,0,0) _dist ("Distance", Float) =100.0_brightnessamount ("Brightness Amount", Float) =1.0_saturationamount ("saturation Amount", Float) =1.0_contrastamount ("contrast Amount", Float) =1.0} subshader {Tags {"Queue"="Transparent"} Pass {Blend srcalpha oneminussrcalpha cgprogram#pragmaVertex vert#pragmaFragment Frag#include"Unitycg.cginc"sampler2d _maintex;            FLOAT4 _qoffset; float_dist; fixed_brightnessamount; fixed_saturationamount; fixed_contrastamount; float_opacityamount; structv2f {float4 pos:sv_position;                FLOAT4 uv:texcoord0;                FLOAT3 Viewdir:texcoord1;            Fixed4 Color:color;            };                                  v2f Vert (Appdata_full v) {v2f o; FLOAT4 vPOS=Mul (UNITY_MATRIX_MV, V.vertex); floatZoff = vpos.z/_dist; vPOS+ = _qoffset*zoff*Zoff; O.pos=Mul (unity_matrix_p, vPOS); O.uv=V.texcoord; //O.color.rgb = V.color.rgb; //take vertex color                                  returno; } float3 contrastsaturationbrightness (float3 color,floatBrtfloatSatfloatcon) {                  //increase or decrease these values to//adjust R, G and B color channels separately                floatAVGLUMR =0.5; floatAVGLUMG =0.5; floatAvglumb =0.5; //luminance coefficients for getting luminance from the imageFLOAT3 Luminancecoeff = FLOAT3 (0.2125,0.7154,0.0721); //Operation for BrightmessFLOAT3 Avglumin =float3 (AVGLUMR, AVGLUMG, Avglumb); FLOAT3 Brtcolor= Color *BRT; floatINTENSITYF =dot (Brtcolor, Luminancecoeff); FLOAT3 intensity=float3 (INTENSITYF, INTENSITYF, INTENSITYF); //operation for SaturationFLOAT3 Satcolor =lerp (intensity, brtcolor, Sat); //Operation for contrastFLOAT3 concolor =lerp (avglumin, Satcolor, con); returnconcolor; } Half4 Frag (v2f i): COLOR0 {fixed4 Rendertex=tex2d (_maintex, I.UV); //                  //Apply vertex Color//Rendertex.rgb *= I.color.rgb; //vertex color and map blending//Apply The brightness, saturation, contrast operationsRendertex.rgb =contrastsaturationbrightness (Rendertex.rgb, _brightnessamount, _saturationamount, _ContrastAmount); returnRendertex; } ENDCG}} FallBack"Diffuse"}

Vertex deformation of 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.