Purpose of Practice

概要。项目瀑布波纹效果的要求。内容。
参考游戏 : RIM2

Shader 的实现。使用不同的两张波纹(Ripple)纹理,各自设置不同的速度使波纹效果更自然。
为了让Mesh的波纹呈现向外围渐渐消失的效果,使用Vertex Color。

瀑布的落水而产生的波纹效果使用以上Mesh。

为了在Shader使波纹的边缘自然地Fade-out,Vertex color 要用 mask。

  • 先用黑色填满整体后,在开着Soft-Selection的状态下选择里面的Vertex填满红色。
  • 用Vertex tool的Blur功能把整体修改得自然。
  • Mesh的内部也需要添加自然波纹效果的话,内部也设置成黑色便可。
编辑UV。
Dual ripple foam texture.
Channel R
Channel B

Shader Snippet

该着色器是使用“ Amplify Shader Editor”创建的。
This shader was created using the Amplify Shader Editor.

Shader "Water Ripple Shader"
{
	Properties
	{
		_Cutoff( "Mask Clip Value", Float ) = 0.5
		_RippleFoam("RippleFoam", 2D) = "white" {}
		_MainFoamSpeed("Main Foam Speed", Float) = 0.1
		_SecondFoamSpeed("Second Foam Speed", Float) = 0.1
		_MainFoamScale("Main Foam Scale", Float) = 2
		[HideInInspector] __dirty( "", Int ) = 1
	}

	SubShader
	{
		Tags{ "RenderType" = "TransparentCutout"  "Queue" = "AlphaTest+0" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True" "IsEmissive" = "true"  }
		Cull Back
		CGPROGRAM
		#include "UnityShaderVariables.cginc"
		#pragma target 3.5
		#pragma multi_compile_instancing
		#pragma only_renderers d3d11 glcore gles gles3 metal 
		#pragma surface surf Unlit keepalpha noshadow novertexlights nolightmap  nodynlightmap nodirlightmap nometa noforwardadd vertex:vertexDataFunc 
		struct Input
		{
			float2 vertexToFrag32;
			float2 vertexToFrag33;
			float4 vertexColor : COLOR;
		};

		uniform float _MainFoamSpeed;
		uniform float _MainFoamScale;
		uniform sampler2D _RippleFoam;
		uniform float _SecondFoamSpeed;
		uniform float _Cutoff = 0.5;

		void vertexDataFunc( inout appdata_full v, out Input o )
		{
			UNITY_INITIALIZE_OUTPUT( Input, o );
			float temp_output_30_0 = ( _MainFoamSpeed * 0.15 );
			float2 appendResult31 = (float2(temp_output_30_0 , temp_output_30_0));
			float2 panner8 = ( ( appendResult31 * _Time.y ).x * float2( 0,1 ) + v.texcoord.xy);
			float2 temp_output_22_0 = ( panner8 * _MainFoamScale );
			o.vertexToFrag32 = temp_output_22_0;
			float temp_output_15_0 = ( _SecondFoamSpeed * 0.15 );
			float2 appendResult18 = (float2(temp_output_15_0 , temp_output_15_0));
			o.vertexToFrag33 = ( temp_output_22_0 + ( appendResult18 * _Time.y ) );
		}

		inline fixed4 LightingUnlit( SurfaceOutput s, half3 lightDir, half atten )
		{
			return fixed4 ( 0, 0, 0, s.Alpha );
		}

		void surf( Input i , inout SurfaceOutput o )
		{
			o.Emission = float4(1,1,1,0).rgb;
			o.Alpha = 1;
			float lerpResult40 = lerp( 0.5 , ( tex2D( _RippleFoam, i.vertexToFrag32 ).g + tex2D( _RippleFoam, i.vertexToFrag33 ).r ) , i.vertexColor.r);
			clip( lerpResult40 - _Cutoff );
		}

		ENDCG
	}
	CustomEditor "ASEMaterialInspector"
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s