Unity3d Shader by percentage realistic model

Source: Internet
Author: User

Shader

Shader"Unlit/disappear"{Properties {_maintex ("Texture", 2D) =" White"{} _color ("Flow Color", Color) = (1,1,1,1) _percent ("Percent", Range (0,1)) =0.5_range ("Range", Float) =1_offset ("Offset", Float) =0.5} subshader {Tags {"Rendertype"="Opaque"} LOD -Pass {Cgprogram#pragmaVertex vert#pragmaFragment Frag//Make fog work            #pragmaMulti_compile_fog#include"Unitycg.cginc"            structAppData {float4 vertex:position;            FLOAT2 uv:texcoord0;            }; structv2f {float2 uv:texcoord0; Unity_fog_coords (1) Float4 vertex:sv_position; floatHeight:color;            };            Sampler2d _maintex;            FLOAT4 _maintex_st;            FLOAT4 _color; float_range; float_offset; float_percent;                v2f Vert (AppData v) {v2f o; O.vertex=Mul (UNITY_MATRIX_MVP, V.vertex); O.uv=Transform_tex (V.UV, _maintex);                Unity_transfer_fog (O,o.vertex); O.height= (V.vertex.y-_offset)/_range; returno; } fixed4 Frag (v2f i): sv_target {//Sample The textureFixed4 col =tex2d (_maintex, I.UV); //Apply FogUnity_apply_fog (I.fogcoord, col); if(i.height>_percent)                {Discard; }                returnCol; } ENDCG} }}

Code

usingUnityengine;usingSystem.Collections; [Requirecomponent (typeof(Meshrenderer))] Public classDisappear:monobehaviour {PrivateMaterial MMat; [Range (0,1)]     Public floatPercent =1; voidAwake () {varRenderer = gameobject.getcomponent<meshrenderer> (); MMat=renderer.material; varMF = gameobject.getcomponent<meshfilter> (); Mmat.setfloat ("_offset", MF.MESH.BOUNDS.MIN.Y); Mmat.setfloat ("_range", MF.MESH.BOUNDS.SIZE.Y); }    //Use this for initialization    voidStart () {}//Update is called once per frame    voidUpdate () {mmat.setfloat ("_percent", Percent); }}

Unity3d Shader by percentage realistic model

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.