sunset box: refraction
This commit is contained in:
parent
b4bf728285
commit
32d7e50e40
2 changed files with 43 additions and 18 deletions
|
@ -59,6 +59,10 @@ Material:
|
||||||
m_Texture: {fileID: 0}
|
m_Texture: {fileID: 0}
|
||||||
m_Scale: {x: 1, y: 1}
|
m_Scale: {x: 1, y: 1}
|
||||||
m_Offset: {x: 0, y: 0}
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _WaterNormal:
|
||||||
|
m_Texture: {fileID: 2800000, guid: cafeae09bbcef5a6cabeaac76bab5462, type: 3}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
- _WaterSurface:
|
- _WaterSurface:
|
||||||
m_Texture: {fileID: 2800000, guid: cafeae09bbcef5a6cabeaac76bab5462, type: 3}
|
m_Texture: {fileID: 2800000, guid: cafeae09bbcef5a6cabeaac76bab5462, type: 3}
|
||||||
m_Scale: {x: 1.6, y: 1}
|
m_Scale: {x: 1.6, y: 1}
|
||||||
|
@ -72,7 +76,7 @@ Material:
|
||||||
- _Glossiness: 0.5
|
- _Glossiness: 0.5
|
||||||
- _GlossyReflections: 1
|
- _GlossyReflections: 1
|
||||||
- _Grid: 0
|
- _Grid: 0
|
||||||
- _HeightOffset: -0.7
|
- _HeightOffset: -1
|
||||||
- _HorizonTint: 0.1
|
- _HorizonTint: 0.1
|
||||||
- _Metallic: 0
|
- _Metallic: 0
|
||||||
- _Mode: 0
|
- _Mode: 0
|
||||||
|
@ -92,12 +96,12 @@ Material:
|
||||||
- _SunRadius: 0.037
|
- _SunRadius: 0.037
|
||||||
- _Temp: 0.703
|
- _Temp: 0.703
|
||||||
- _UVSec: 0
|
- _UVSec: 0
|
||||||
- _WaveStrength: 0.5
|
- _WaveStrength: 1
|
||||||
- _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}
|
||||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
- _HorizonCol: {r: 0.43, g: 0.27, b: 0.49, a: 1}
|
- _HorizonCol: {r: 0.43, g: 0.27, b: 0.49, a: 1}
|
||||||
- _SkyCol: {r: 0.13841508, g: 0.08388217, b: 0.2735849, a: 1}
|
- _SkyCol: {r: 0.08235293, g: 0.09343877, b: 0.27450982, a: 1}
|
||||||
- _SunCol: {r: 1, g: 0.5988961, b: 0.05098039, a: 1}
|
- _SunCol: {r: 1, g: 0.5988961, b: 0.05098039, a: 1}
|
||||||
- _WaterCol: {r: 0.041651834, g: 0.0754717, b: 0.060873438, a: 1}
|
- _WaterCol: {r: 0.6556604, g: 1, b: 0.8435335, a: 1}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
_WaterCol ("Water color", Color) = (0.03, 0.08, 0.12, 1.0)
|
_WaterCol ("Water color", Color) = (0.03, 0.08, 0.12, 1.0)
|
||||||
_WaveStrength ("Wave scale", Range(0, 1)) = 1
|
_WaveStrength ("Wave scale", Range(0, 1)) = 1
|
||||||
[NoScaleOffset]
|
[NoScaleOffset]
|
||||||
_WaterSurface ("Surface Normal", 2D) = "white" {}
|
_WaterNormal ("Surface Normal", 2D) = "white" {}
|
||||||
[Header(Debug)]
|
[Header(Debug)]
|
||||||
_Grid ("Grid visibility", Range(0, 1)) = 0
|
_Grid ("Grid visibility", Range(0, 1)) = 0
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
float _SunRadius;
|
float _SunRadius;
|
||||||
float _SunCutoff;
|
float _SunCutoff;
|
||||||
|
|
||||||
sampler2D _WaterSurface;
|
sampler2D _WaterNormal;
|
||||||
float3 _WaterCol;
|
float3 _WaterCol;
|
||||||
float _HeightOffset;
|
float _HeightOffset;
|
||||||
float _WaveStrength;
|
float _WaveStrength;
|
||||||
|
@ -93,15 +93,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 get_water_normal(float2 pos) {
|
float3 get_water_normal(float2 pos) {
|
||||||
pos *= 0.03;
|
pos *= 0.3;
|
||||||
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(_WaterNormal, float2(1, -1) * pos + float2(t1, t1 * 0.5)) - 0.5).zxy;
|
||||||
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(_WaterNormal, pos * 0.276 + float2(t2 * 0.8, t2)) - 0.5).zxy;
|
||||||
// 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(_WaterNormal, pos * 0.07 + float2(t3 * 0.8, -t3)) - 0.5).zxy;
|
||||||
normal = normalize(normal.zxy);
|
// normal = normalize(normal.zxy);
|
||||||
|
|
||||||
|
// normal = UP;
|
||||||
|
// normal += (tex2D(_NoiseTex, pos).zxy - 0.5)*0.4;
|
||||||
|
normal = normalize(normal);
|
||||||
|
|
||||||
|
|
||||||
// return UP;
|
// return UP;
|
||||||
return lerp(UP, normal, _WaveStrength);
|
return lerp(UP, normal, _WaveStrength);
|
||||||
|
@ -157,14 +162,21 @@
|
||||||
|
|
||||||
col = lerp(col, star_col, star_strength);
|
col = lerp(col, star_col, star_strength);
|
||||||
|
|
||||||
/// debug grid
|
|
||||||
col = lerp(col, WHITE, _Grid * (frac(cellx) < 0.04 || frac(celly) < 0.04));
|
|
||||||
|
|
||||||
/// sun
|
/// sun
|
||||||
float alignment = min(acos(dot(dir, sun_dir)), 1);
|
float alignment = min(acos(dot(dir, sun_dir)), 1);
|
||||||
float sun_amount = smax(min(_SunRadius / alignment, 5) - _SunCutoff, 0, 0.15);
|
float sun_amount = smax(min(_SunRadius / alignment, 5) - _SunCutoff, 0, 0.15);
|
||||||
|
|
||||||
col = lerp(col, _SunCol, sun_amount);
|
col = lerp(col, _SunCol, sun_amount);
|
||||||
|
|
||||||
|
/// debug grid
|
||||||
|
// col = lerp(col, WHITE, _Grid * (frac(cellx) < 0.04 || frac(celly) < 0.04));
|
||||||
|
col = lerp(col, WHITE, _Grid * (
|
||||||
|
pow(frac( cellx), 20) +
|
||||||
|
pow(frac( celly), 20) +
|
||||||
|
pow(frac(-cellx), 20) +
|
||||||
|
pow(frac(-celly), 20)
|
||||||
|
));
|
||||||
|
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +184,9 @@
|
||||||
{
|
{
|
||||||
// float3 horizon_col = lerp(_SkyCol, _SunCol, _HorizonTint);
|
// float3 horizon_col = lerp(_SkyCol, _SunCol, _HorizonTint);
|
||||||
float3 origin = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
|
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 sun_dir = mul(unity_ObjectToWorld, float4(0, 0, 1, 1)) * float3(1, 0, 1) - origin;
|
||||||
|
// sun_dir.y = sin(_Time.x * 10) * 0.05;
|
||||||
|
sun_dir = normalize(sun_dir);
|
||||||
|
|
||||||
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
|
||||||
|
@ -191,12 +205,19 @@
|
||||||
);
|
);
|
||||||
float3 water_normal = get_water_normal(surface_pos.xz);
|
float3 water_normal = get_water_normal(surface_pos.xz);
|
||||||
|
|
||||||
|
float3 refracted_dir = normalize(refract(dir, water_normal, 1/1.333));
|
||||||
|
float subsurf = (refracted_dir.y + 1);
|
||||||
|
|
||||||
dir = reflect(dir, water_normal);
|
dir = reflect(dir, water_normal);
|
||||||
phi = asin(dir.y);
|
phi = asin(dir.y);
|
||||||
float hit_angle = dot(dir, water_normal);
|
float hit_angle = dot(dir, water_normal);
|
||||||
|
|
||||||
float3 sky_reflection = sky(dir, theta, phi, sun_dir) ;
|
float3 sky_reflection = sky(dir, theta, phi, sun_dir) ;
|
||||||
col = lerp(sky_reflection, _WaterCol, hit_angle);
|
|
||||||
|
float3 water_col = lerp(_SkyCol, _SunCol, 0.01) * _WaterCol;
|
||||||
|
col = water_col * subsurf * 12;
|
||||||
|
col = lerp(sky_reflection, col, hit_angle);
|
||||||
|
|
||||||
// float distance = length(surface_pos - camera_local_pos);
|
// float distance = length(surface_pos - camera_local_pos);
|
||||||
// float fog_factor = smoothstep(10, 70, distance) * 0.4;
|
// float fog_factor = smoothstep(10, 70, distance) * 0.4;
|
||||||
// col = lerp(col, horizon_col, fog_factor);
|
// col = lerp(col, horizon_col, fog_factor);
|
||||||
|
|
Loading…
Reference in a new issue