diff --git a/Assets/sunset_box/sunset_box.unity b/Assets/sunset_box/sunset_box.unity index c666e97..791bdc1 100644 --- a/Assets/sunset_box/sunset_box.unity +++ b/Assets/sunset_box/sunset_box.unity @@ -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} diff --git a/Assets/sunset_box/sunset_env_dynamic.shader b/Assets/sunset_box/sunset_env_dynamic.shader index e97f758..4688023 100644 --- a/Assets/sunset_box/sunset_env_dynamic.shader +++ b/Assets/sunset_box/sunset_env_dynamic.shader @@ -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 }