Shader "Custom/SimpleWaterWithReflectiveEnvURP" {
Properties {
_Color("Color", Color) = (1,1,1,1)
_MainTex("Texture", 2D) = "white" {}
_WaveScale("Wave scale", Range(0.01, 0.3)) = 0.1
_Speed("Speed", Range(0.1, 2.0)) = 1.0
_ReflectionStrength("Reflection Strength", Range(0,1)) = 0.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
Pass {
Tags { "LightMode" = "UniversalForward" }
HLSLPROGRAM
// Required pragmas
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile_instancing
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float2 uv : TEXCOORD0;
float3 normal : TEXCOORD1;
float4 vertex : SV_POSITION;
UNITY_FOG_COORDS(1)
UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _WaveScale;
float _Speed;
float4 _Color;
float _ReflectionStrength;
v2f vert(appdata v) {
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.normal = UnityObjectToWorldNormal(v.normal);
o.uv = v.uv;
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
half4 frag(v2f i) : SV_Target {
half2 uv = i.uv;
uv.x += _Time.y * _Speed;
uv.y += sin(uv.x * _WaveScale) * _WaveScale;
half4 tex = tex2D(_MainTex, TRANSFORM_TEX(uv, _MainTex));
half3 viewDir = normalize(UnityWorldSpaceViewDir(i.vertex.xyz));
half3 reflectDir = reflect(-viewDir, i.normal);
half4 envColor = half4(UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, reflectDir).rgb, 1.0);
half4 color = lerp(tex * _Color, envColor, _ReflectionStrength);
UNITY_APPLY_FOG(i.fogCoord, color);
return color;
}
ENDHLSL
}
}
}
留言列表