sunset box: sun angle fix, less noisy waves

This commit is contained in:
Crispy 2023-02-18 20:19:16 +01:00
parent 11640b59b0
commit b4bf728285
2 changed files with 19 additions and 12 deletions

View file

@ -90,9 +90,9 @@ Material:
- _SunAngle: 0 - _SunAngle: 0
- _SunCutoff: 0.121 - _SunCutoff: 0.121
- _SunRadius: 0.037 - _SunRadius: 0.037
- _Temp: 0.5 - _Temp: 0.703
- _UVSec: 0 - _UVSec: 0
- _WaveStrength: 0.6 - _WaveStrength: 0.5
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}

View file

@ -93,16 +93,18 @@
} }
float3 get_water_normal(float2 pos) { float3 get_water_normal(float2 pos) {
pos *= 0.03;
float3 normal = 0; float3 normal = 0;
float t1 = _Time.x * 0.18; float t1 = _Time.x * 0.18;
normal += (tex2D(_WaterSurface, pos * 1.04 + float2(t1, t1 * 0.5)) - 0.5); normal += (tex2D(_WaterSurface, pos * 1.04 + float2(t1, t1 * 0.5)) - 0.5);
float t2 = _Time.x * 0.37; float t2 = _Time.x * 0.37;
normal += (tex2D(_WaterSurface, pos * 0.276 + float2(t2 * 0.8, t2)) - 0.5); normal += (tex2D(_WaterSurface, pos * 0.276 + float2(t2 * 0.8, t2)) - 0.5);
float t3 = _Time.x * 0.08; // float t3 = _Time.x * 0.08;
normal += (tex2D(_WaterSurface, pos * 0.07 + float2(t3 * 0.8, -t3)) - 0.5); // normal += (tex2D(_WaterSurface, pos * 0.07 + float2(t3 * 0.8, -t3)) - 0.5);
normal = normalize(normal.zxy);
// return UP; // return UP;
return lerp(UP, normalize(normal.zxy), _WaveStrength); return lerp(UP, normal, _WaveStrength);
} }
inline float smin(float a, float b, float k) inline float smin(float a, float b, float k)
@ -168,14 +170,17 @@
float4 frag(v2f i) : SV_Target float4 frag(v2f i) : SV_Target
{ {
float3 sun_dir = normalize(mul(unity_ObjectToWorld, float4(0, 0, 1, 1)) * float3(1, 0, 1)); // float3 horizon_col = lerp(_SkyCol, _SunCol, _HorizonTint);
float3 origin = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
float3 sun_dir = normalize(mul(unity_ObjectToWorld, float4(0, 0, 1, 1)) * float3(1, 0, 1) - origin);
float3 dir = normalize(i.hit_pos - i.cam_pos); float3 dir = normalize(i.hit_pos - i.cam_pos);
float theta = atan2(dir.x, dir.z); // latitude float theta = atan2(dir.x, dir.z); // latitude
float phi = asin(dir.y); // longitude float phi = asin(dir.y); // longitude
float3 col;
if (phi < 0) { if (phi < 0) {
float3 origin = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
origin.y += _HeightOffset; origin.y += _HeightOffset;
float3 camera_local_pos = i.cam_pos - origin; float3 camera_local_pos = i.cam_pos - origin;
camera_local_pos.y = max(camera_local_pos.y, 0.01); // don't allow looking under water surface; it renders backwards. camera_local_pos.y = max(camera_local_pos.y, 0.01); // don't allow looking under water surface; it renders backwards.
@ -190,14 +195,16 @@
phi = asin(dir.y); phi = asin(dir.y);
float hit_angle = dot(dir, water_normal); float hit_angle = dot(dir, water_normal);
float3 col = sky(dir, theta, phi, sun_dir); float3 sky_reflection = sky(dir, theta, phi, sun_dir);
col = lerp(col, _WaterCol, hit_angle); col = lerp(sky_reflection, _WaterCol, hit_angle);
return float4(col, 1); // float distance = length(surface_pos - camera_local_pos);
// float fog_factor = smoothstep(10, 70, distance) * 0.4;
// col = lerp(col, horizon_col, fog_factor);
} }
else { else {
float3 col = sky(dir, theta, phi, sun_dir); col = sky(dir, theta, phi, sun_dir);
return float4(col, 1);
} }
return float4(col, 1);
} }
ENDCG ENDCG
} }