{"id":1535,"date":"2016-07-11T13:33:07","date_gmt":"2016-07-11T05:33:07","guid":{"rendered":"http:\/\/www.clonefactor.com\/wordpress\/?p=1535"},"modified":"2016-07-27T19:45:04","modified_gmt":"2016-07-27T11:45:04","slug":"record-smeareffect","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/program\/unity3d\/1535\/","title":{"rendered":"[Record] SmearEffect"},"content":{"rendered":"<p>\u5728 Twitter \u4e0a\u4e00\u540d\u53eb Chris Wade \u7684\u7a0b\u5e8f\u54e1\u91cd\u5236 Unreal \u7684\u4e00\u500b effect.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1536\" src=\"http:\/\/www.clonefactor.com\/wordpress\/wp-content\/uploads\/2016\/07\/smear_effect.gif\" alt=\"smear_effect\" width=\"392\" height=\"219\" \/><\/p>\n<p>\u4eba\u5bb6\u653e\u4e86 source code \u5728 Git<br \/>\n<a href=\"https:\/\/github.com\/cjacobwade\/HelpfulScripts\/tree\/master\/SmearEffect\">https:\/\/github.com\/cjacobwade\/HelpfulScripts\/tree\/master\/SmearEffect<\/a><\/p>\n<pre class=\"brush:ruby\">Shader \"Custom\/Smear\"\r\n{\r\n\tProperties\r\n\t{\r\n\t\t_Color(\"Color\", Color) = (1,1,1,1)\r\n\t\t_MainTex(\"Albedo (RGB)\", 2D) = \"white\" {}\r\n\t\t_Glossiness(\"Smoothness\", Range(0,1)) = 0.5\r\n\t\t_Metallic(\"Metallic\", Range(0,1)) = 0.0\r\n\r\n\t\t_Position(\"Position\", Vector) = (0, 0, 0, 0)\r\n\t\t_PrevPosition(\"Prev Position\", Vector) = (0, 0, 0, 0)\r\n\r\n\t\t_NoiseScale(\"Noise Scale\", Float) = 15\r\n\t\t_NoiseHeight(\"Noise Height\", Float) = 1.3\r\n\t}\r\n\r\n\tSubShader\r\n\t{\r\n\t\tTags{ \"RenderType\" = \"Opaque\" }\r\n\t\tLOD 200\r\n\r\n\t\tCGPROGRAM\r\n\t\t#pragma surface surf Standard vertex:vert addshadow\r\n\t\t#pragma target 3.0\r\n\r\n\t\tsampler2D _MainTex;\r\n\r\n\t\tstruct Input\r\n\t\t{\r\n\t\t\tfloat2 uv_MainTex;\r\n\t\t};\r\n\t\r\n\t\thalf _Glossiness;\r\n\t\thalf _Metallic;\r\n\t\tfixed4 _Color;\r\n\t\tfixed4 _PrevPosition;\r\n\t\tfixed4 _Position;\r\n\t\r\n\t\thalf _NoiseScale;\r\n\t\thalf _NoiseHeight;\r\n\t\r\n\t\tfloat hash(float n)\r\n\t\t{\r\n\t\t\treturn frac(sin(n)*43758.5453);\r\n\t\t}\r\n\t\r\n\t\tfloat noise(float3 x)\r\n\t\t{\r\n\t\t\t\/\/ The noise function returns a value in the range -1.0f -&gt; 1.0f\r\n\t\r\n\t\t\tfloat3 p = floor(x);\r\n\t\t\tfloat3 f = frac(x);\r\n\t\r\n\t\t\tf = f*f*(3.0 - 2.0*f);\r\n\t\t\tfloat n = p.x + p.y*57.0 + 113.0*p.z;\r\n\t\r\n\t\t\treturn lerp(lerp(lerp(hash(n + 0.0), hash(n + 1.0), f.x),\r\n\t\t\t\tlerp(hash(n + 57.0), hash(n + 58.0), f.x), f.y),\r\n\t\t\t\tlerp(lerp(hash(n + 113.0), hash(n + 114.0), f.x),\r\n\t\t\t\t\tlerp(hash(n + 170.0), hash(n + 171.0), f.x), f.y), f.z);\r\n\t\t}\r\n\t\r\n\t\tvoid vert(inout appdata_full v, out Input o)\r\n\t\t{\r\n\t\t\tUNITY_INITIALIZE_OUTPUT(Input, o);\r\n\t\t\tfixed4 worldPos = mul(_Object2World, v.vertex);\r\n\t\r\n\t\t\tfixed3 worldOffset = _Position.xyz - _PrevPosition.xyz; \/\/ -5\r\n\t\t\tfixed3 localOffset = worldPos.xyz - _Position.xyz; \/\/ -5\r\n\t\r\n\t\t\t\/\/ World offset should only be behind swing\r\n\t\t\tfloat dirDot = dot(normalize(worldOffset), normalize(localOffset));\r\n\t\t\tfixed3 unitVec = fixed3(1, 1, 1) * _NoiseHeight;\r\n\t\t\tworldOffset = clamp(worldOffset, unitVec * -1, unitVec);\r\n\t\t\tworldOffset *= -clamp(dirDot, -1, 0) * lerp(1, 0, step(length(worldOffset), 0));\r\n\t\r\n\t\t\tfixed3 smearOffset = -worldOffset.xyz * lerp(1, noise(worldPos * _NoiseScale), step(0, _NoiseScale));\r\n\t\t\tworldPos.xyz += smearOffset;\r\n\t\t\tv.vertex = mul(_World2Object, worldPos);\r\n\t\t}\r\n\t\r\n\t\tvoid surf(Input IN, inout SurfaceOutputStandard o)\r\n\t\t{\r\n\t\t\t\/\/ Albedo comes from a texture tinted by color\r\n\t\t\tfixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;\r\n\t\t\to.Albedo = c.rgb;\r\n\t\r\n\t\t\t\/\/ Metallic and smoothness come from slider variables\r\n\t\t\to.Metallic = _Metallic;\r\n\t\t\to.Smoothness = _Glossiness;\r\n\t\t\to.Alpha = c.a;\r\n\t\t}\r\n\t\tENDCG\r\n\t}\r\n\r\n\tFallBack \"Diffuse\"\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Twitter \u4e0a\u4e00\u540d\u53eb Chris Wade \u7684\u7a0b\u5e8f\u54e1\u91cd\u5236 Unreal \u7684\u4e00\u500b effect &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,11],"tags":[],"class_list":["post-1535","post","type-post","status-publish","format-standard","hentry","category-shader","category-unity3d"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/1535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1535"}],"version-history":[{"count":0,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/1535\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}