sunset box: sun angle and offset fix
This commit is contained in:
parent
e84947d3fc
commit
11640b59b0
2 changed files with 14 additions and 12 deletions
|
@ -370,7 +370,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1963847629}
|
m_GameObject: {fileID: 1963847629}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
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_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
_HorizonTint ("Horizon tint", Range(0, 1)) = 0.1
|
_HorizonTint ("Horizon tint", Range(0, 1)) = 0.1
|
||||||
[Header(Sun)]
|
[Header(Sun)]
|
||||||
_SunCol ("Sun color", Color) = (1.0, 0.65, 0.05, 1.0)
|
_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
|
_SunRadius ("Sun radius", Range(0, 0.3)) = 0.06
|
||||||
_SunCutoff ("Sun cutoff", Range(0, 0.5)) = 0.08
|
_SunCutoff ("Sun cutoff", Range(0, 0.5)) = 0.08
|
||||||
[Header(Star Layout)]
|
[Header(Star Layout)]
|
||||||
|
@ -169,17 +168,16 @@
|
||||||
|
|
||||||
float4 frag(v2f i) : SV_Target
|
float4 frag(v2f i) : SV_Target
|
||||||
{
|
{
|
||||||
float3 sun_dir = float3(sin(_SunAngle), 0, cos(_SunAngle));
|
float3 sun_dir = normalize(mul(unity_ObjectToWorld, float4(0, 0, 1, 1)) * float3(1, 0, 1));
|
||||||
|
|
||||||
float water_mod = 0;
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
if (phi < 0) {
|
if (phi < 0) {
|
||||||
float3 object_pos = mul(unity_ObjectToWorld, float4(0, _HeightOffset, 0, 1));
|
float3 origin = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
|
||||||
float3 camera_local_pos = i.cam_pos - object_pos;
|
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.
|
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 (
|
float3 surface_pos = float3 (
|
||||||
camera_local_pos.x - camera_local_pos.y / (dir.y / dir.x),
|
camera_local_pos.x - camera_local_pos.y / (dir.y / dir.x),
|
||||||
|
@ -190,13 +188,17 @@
|
||||||
|
|
||||||
dir = reflect(dir, water_normal);
|
dir = reflect(dir, water_normal);
|
||||||
phi = asin(dir.y);
|
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);
|
float3 col = sky(dir, theta, phi, sun_dir);
|
||||||
col = lerp(col, _WaterCol, water_mod);
|
col = lerp(col, _WaterCol, hit_angle);
|
||||||
return float4(col, 1);
|
return float4(col, 1);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
float3 col = sky(dir, theta, phi, sun_dir);
|
||||||
|
return float4(col, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
ENDCG
|
ENDCG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue