Untitled

 avatar
unknown
csharp
a year ago
2.8 kB
6
No Index
Shader "Custom/Waves_URP" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_Glossiness ("Smoothness", Range(0,1)) = 0.5
		_Metallic ("Metallic", Range(0,1)) = 0.0
		_WaveA ("Wave A (dir, steepness, wavelength)", Vector) = (1,0,0.5,10)
		_WaveB ("Wave B", Vector) = (0,1,0.25,20)
		_WaveC ("Wave C", Vector) = (1,1,0.15,10)
	}
	SubShader {
		Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline" }
		Pass
        {
		LOD 200

		HLSLPROGRAM
		#pragma fragment frag 
		#pragma vertex vert 
		#pragma target 3.0

		#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"


		CBUFFER_START(UnityPerMaterial)

			sampler2D _MainTex;
			half _Glossiness;
			half _Metallic;
			half4 _Color;
			float4 _WaveA, _WaveB, _WaveC;
		CBUFFER_END

		struct Attributes
		{
		    float4 positionOS   : POSITION;
		    float2 uv : TEXCOORD0;
		};
		struct Varyings
		{
		    // The positions in this struct must have the SV_POSITION semantic.
		    float4 positionHCS  : SV_POSITION;
		    float2 uv : TEXCOORD0;
		};

		float3 GerstnerWave (
			float4 wave, float3 p, inout float3 tangent, inout float3 binormal
		) {
		    float steepness = wave.z;
		    float wavelength = wave.w;
		    float k = 2 * 3.14159265 / wavelength;
			float c = sqrt(9.8 / k);
			float2 d = normalize(wave.xy);
			float f = k * (dot(d, p.xz) - c * _Time.y);
			float a = steepness / k;

			tangent += float3(
				-d.x * d.x * (steepness * sin(f)),
				d.x * (steepness * cos(f)),
				-d.x * d.y * (steepness * sin(f))
			);
			binormal += float3(
				-d.x * d.y * (steepness * sin(f)),
				d.y * (steepness * cos(f)),
				-d.y * d.y * (steepness * sin(f))
			);
			return float3(
				d.x * (a * cos(f)),
				a * sin(f),
				d.y * (a * cos(f))
			);
		}

		Varyings vert(Attributes IN) {
			/*float3 gridPoint = vertexData.vertex.xyz;
			float3 tangent = float3(1, 0, 0);
			float3 binormal = float3(0, 0, 1);
			float3 p = gridPoint;
			p += GerstnerWave(_WaveA, gridPoint, tangent, binormal);
			p += GerstnerWave(_WaveB, gridPoint, tangent, binormal);
			p += GerstnerWave(_WaveC, gridPoint, tangent, binormal);
			float3 normal = normalize(cross(binormal, tangent));
			vertexData.vertex.xyz = p;
			vertexData.normal = normal;*/
			Varyings OUT;

		    OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
		    OUT.uv = IN.uv;

		    return OUT;
		}

		half4 frag(Varyings IN) : SV_Target {
			float4 color = float4(1,1,1,1);
			return color;
			/*fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
			o.Albedo = c.rgb;
			o.Metallic = _Metallic;
			o.Smoothness = _Glossiness;
			o.Alpha = c.a;*/
		}
		ENDHLSL
		}
	}

}
Editor is loading...