Unityshader Effect of Plush velvet

Source: Internet
Author: User
Tags diff mul

We're going to do a fur ball today.

The core of the algorithm through a plurality of passes, from the inside to the outside layer of the paste on a layer of transparent diffuse, the more on the outside of the local level less looks more sparse, the more blurred

Furhelper.cginc

struct V2F {float4 pos:sv_position;
	Half2 uv:texcoord0;
	Half2 Uv1:texcoord1;
Fixed4 Diff:color;

};
float _furlength;
Sampler2d _maintex;
FLOAT4 _maintex_st;
Sampler2d _furtex;
FLOAT4 _furtex_st;

float _blur;
	v2f Vert (Appdata_base v) {v2f o;
	V.VERTEX.XYZ + = V.normal * _furlength * FURSTEP;
	O.pos = Unityobjecttoclippos (V.vertex);
	O.UV = Transform_tex (V.texcoord, _maintex);
	O.uv1 = Transform_tex (V.texcoord, _furtex);
	FLOAT3 Worldnormal = Normalize (Mul (V.normal, (float3x3) unity_worldtoobject));
	O.diff = Lambertdiffuse (worldnormal);
	O.DIFF.A = 1-(Furstep * furstep);
	FLOAT4 Worldpos = Mul (Unity_objecttoworld, V.vertex);
	O.DIFF.A + = dot (normalize (_worldspacecamerapos.xyz-v.vertex), worldnormal)-_blur;
return o;
} float _cutoff;

float _thickness;
	Fixed4 Frag (v2f i): sv_target {fixed4 col = tex2d (_maintex, I.UV);
	Fixed alpha = tex2d (_furtex, i.uv1). R;
	Col *= I.diff;
	COL.A *= Step (Lerp (_cutoff, _cutoff + _thickness, furstep), Alpha);
return col; }
Furshader.shader

Shader "Custom/furshader" {Properties {_maintex ("Texture", 2D) = "White" {} _furtex ("Fur pattern", 2D) = "White" {} _diffuse ("Diffuse value", range (0, 3)) = 1 _furlength ("Fur Length", Range (0.0, 1)) = 0.5 _cutoff ("Alpha CutOff", Ra Nge (0, 1)) = 0.5 _blur ("Blur", range (0, 1)) = 0.5 _thickness ("Thickness", range (0, 0.5)) = 0} cginclude fixed
	_diffuse;
		Inline fixed4 lambertdiffuse (float3 worldnormal) {FLOAT3 Lightdir = normalize (_WORLDSPACELIGHTPOS0.XYZ);
		float NDOTL = max (0.2, Dot (worldnormal, lightdir));
	return ndotl* _diffuse;
		} ENDCG Subshader {tags{"rendertype" = "Transparent" "Queue" = "Transparent" "lightmode" = "Forwardbase"} Zwrite Off Blend srcalpha oneminussrcalpha Pass {cgprogram #pragma vertex vert #pragma fragment Frag #define FU RSTEP 0.05 #include "Furhelper.cginc" ENDCG} Pass {cgprogram #pragma vertex vert #pragma fragment Frag #define Furstep 0.10 #include "Furhelper.cginc" ENDCG} Pass {CGProgram #pragma vertex vert #pragma fragment frag #define Furstep 0.15 #include "furhelper.cginc" ENDCG} Pass {
		Cgprogram #pragma vertex vert #pragma fragment frag #define Furstep 0.20 #include "furhelper.cginc" ENDCG} Pass {
	Cgprogram #pragma vertex vert #pragma fragment Frag #define FURSTEP 0.25 #include "Furhelper.cginc" ENDCG} Pass

		{cgprogram #pragma vertex vert #pragma fragment Frag #define FURSTEP 0.30 #include "Furhelper.cginc" ENDCG}

		Pass {cgprogram #pragma vertex vert #pragma fragment Frag #define FURSTEP 0.35 #include "Furhelper.cginc" ENDCG} 

		Pass {cgprogram #pragma vertex vert #pragma fragment frag #define Furstep 0.40 #include "Furhelper.cginc" ENDCG}
	Pass {cgprogram #pragma vertex vert #pragma fragment frag #define FURSTEP 0.45 #include "furhelper.cginc" ENDCG } Pass {cgprogram #pragma vertex vert #pragma fragment Frag #define FURSTEP 0.50 #include "Furhelper.cginc" ENDC
G} Pass {Cgprogram#pragma vertex vert #pragma fragment Frag #define FURSTEP 0.55 #include "Furhelper.cginc" ENDCG} Pass {Cgprogra M #pragma vertex vert #pragma fragment frag #define FURSTEP 0.60 #include "furhelper.cginc" ENDCG} Pass {Cgprog RAM #pragma vertex vert #pragma fragment frag #define Furstep 0.65 #include "furhelper.cginc" ENDCG} Pass {CGPR Ogram #pragma vertex vert #pragma fragment Frag #define Furstep 0.70 #include "Furhelper.cginc" ENDCG} Pass {CG
		Program #pragma vertex vert #pragma fragment frag #define FURSTEP 0.75 #include "furhelper.cginc" ENDCG} Pass {
		Cgprogram #pragma vertex vert #pragma fragment Frag #define FURSTEP 0.80 #include "Furhelper.cginc" ENDCG} Pass {
	Cgprogram #pragma vertex vert #pragma fragment Frag #define FURSTEP 0.85 #include "furhelper.cginc" ENDCG} Pass

		{cgprogram #pragma vertex vert #pragma fragment frag #define FURSTEP 0.90 #include "Furhelper.cginc" ENDCG} Pass {Cgprogram #pragmaVertex vert #pragma fragment Frag #define FURSTEP 0.95 #include "Furhelper.cginc" ENDCG}} 




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.