sunset box: sun angle and offset fix

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

View file

@ -370,7 +370,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1963847629}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.25, z: -0.8}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

View file

@ -7,7 +7,6 @@
_HorizonTint ("Horizon tint", Range(0, 1)) = 0.1
[Header(Sun)]
_SunCol ("Sun color", Color) = (1.0, 0.65, 0.05, 1.0)
_SunAngle ("Sun angle", Range(0, 6.28)) = 0
_SunRadius ("Sun radius", Range(0, 0.3)) = 0.06
_SunCutoff ("Sun cutoff", Range(0, 0.5)) = 0.08
[Header(Star Layout)]
@ -169,17 +168,16 @@
float4 frag(v2f i) : SV_Target
{
float3 sun_dir = float3(sin(_SunAngle), 0, cos(_SunAngle));
float water_mod = 0;
float3 sun_dir = normalize(mul(unity_ObjectToWorld, float4(0, 0, 1, 1)) * float3(1, 0, 1));
float3 dir = normalize(i.hit_pos - i.cam_pos);
float theta = atan2(dir.x, dir.z); // latitude
float phi = asin(dir.y); // longitude
if (phi < 0) {
float3 object_pos = mul(unity_ObjectToWorld, float4(0, _HeightOffset, 0, 1));
float3 camera_local_pos = i.cam_pos - object_pos;
float3 origin = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
origin.y += _HeightOffset;
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.
float3 surface_pos = float3 (
camera_local_pos.x - camera_local_pos.y / (dir.y / dir.x),
@ -190,12 +188,16 @@
dir = reflect(dir, water_normal);
phi = asin(dir.y);
water_mod = dot(dir, water_normal);
}
float hit_angle = dot(dir, water_normal);
float3 col = sky(dir, theta, phi, sun_dir);
col = lerp(col, _WaterCol, water_mod);
return float4(col, 1);
float3 col = sky(dir, theta, phi, sun_dir);
col = lerp(col, _WaterCol, hit_angle);
return float4(col, 1);
}
else {
float3 col = sky(dir, theta, phi, sun_dir);
return float4(col, 1);
}
}
ENDCG
}