Unity Shader Example 15 (Gerstner Wave)

本文介绍了使用Unity进行3D水波模拟的Gerstner波方法,详细解析了公式和代码实现,包括波浪方向、振幅、陡峭度等因素对水面效果的影响,并提到了批处理静态设置对游戏运行的影响。
摘要由CSDN通过智能技术生成
Shader "Unlit/GerstnerWave"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "black" {}

		// example 1(1个波的高度y)
		/*
		_GAmplitude ("Wave Amplitude", float) = 0.3
		_GFrequency ("Wave Frequency", float) = 1.3
		_GSteepness ("Wave Steepness", float) = 1.0
		_GSpeed ("Wave Speed", float) = 1.2
		_GDirection ("Wave Direction", Vector) = (0.3 ,0.85, 0.85, 0.25)
		*/

		// example 2 (4个波合成的高度y)
		/*
		_GAmplitude ("Wave Amplitude", Vector) = (0.3 ,0.35, 0.25, 0.25)
		_GFrequency ("Wave Frequency", Vector) = (1.3, 1.35, 1.25, 1.25)
		_GSteepness ("Wave Steepness", Vector) = (1.0, 1.0, 1.0, 1.0)
		_GSpeed ("Wave Speed", Vector) = (1.2, 1.375, 1.1, 1.5)
		_GDirectionAB ("Wave Direction", Vector) = (0.3 ,0.85, 0.85, 0.25)
		_GDirectionCD ("Wave Direction", Vector) = (0.1 ,0.9, 0.5, 0.5)
		*/

		_GAmplitude ("Wave Amplitude", Vector) = (0.3 ,0.35, 0.25, 0.25)
		_GFrequency ("Wave Frequency", Vector) = (1.3, 1.35, 1.25, 1.25)
		_GSteepness ("Wave Steepness", Vector) = (1.0, 1.0, 1.0, 1.0)
		_GSpeed ("Wave Speed", Vector) = (1.2, 1.375, 1.1, 1.5)
		_GDirectionAB ("Wave Direction", Vector) = (0.3 ,0.85, 0.85, 0.25)
		_GDirectionCD ("Wave Direction", Vector) = (0.1 ,0.9, 0.5, 0.5)
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;

			// example 1 (1个波的高度y)
			/*
			float _GAmplitude;
			float _GFrequency;
			float _GSteepness;
			float _GSpeed;
			Vector _GDirection;
			*/

			// example 2 (4个波合成的高度y)
			/*
			floa
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值