sunset box: fixed normals and other thingsTM

This commit is contained in:
Crispy 2023-02-19 18:50:50 +01:00
parent 32d7e50e40
commit 3f06e84552
9 changed files with 408 additions and 42 deletions

View file

@ -59,8 +59,20 @@ Material:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TempTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _WaterAO:
m_Texture: {fileID: 2800000, guid: dd4d5ec12dc0480c4844ce7523f236de, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _WaterHeight:
m_Texture: {fileID: 2800000, guid: f7d421fd3d8201f31938dea0107230ef, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _WaterNormal:
m_Texture: {fileID: 2800000, guid: cafeae09bbcef5a6cabeaac76bab5462, type: 3}
m_Texture: {fileID: 2800000, guid: 5da9476453fb6074bb8baeb93d8c9513, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _WaterSurface:
@ -76,7 +88,7 @@ Material:
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Grid: 0
- _HeightOffset: -1
- _HeightOffset: -0.7
- _HorizonTint: 0.1
- _Metallic: 0
- _Mode: 0
@ -89,14 +101,15 @@ Material:
- _StarRandom: 0.85
- _StarSize: 0.06
- _StarSizeRandom: 0.5
- _StarTint: 0.5
- _StarTint: 0.2
- _StarsMissing: 0.75
- _SunAngle: 0
- _SunCutoff: 0.121
- _SunRadius: 0.037
- _Temp: 0.703
- _UVSec: 0
- _WaveStrength: 1
- _WaveSpeed: 0.5
- _WaveStrength: 0.5
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
@ -104,4 +117,4 @@ Material:
- _HorizonCol: {r: 0.43, g: 0.27, b: 0.49, 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}
- _WaterCol: {r: 0.6556604, g: 1, b: 0.8435335, a: 1}
- _WaterCol: {r: 0.6035511, g: 0.9339623, b: 0.63756216, a: 1}

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

View file

@ -0,0 +1,104 @@
fileFormatVersion: 2
guid: dd4d5ec12dc0480c4844ce7523f236de
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 1
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

View file

@ -0,0 +1,104 @@
fileFormatVersion: 2
guid: f7d421fd3d8201f31938dea0107230ef
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 KiB

View file

@ -0,0 +1,104 @@
fileFormatVersion: 2
guid: 5da9476453fb6074bb8baeb93d8c9513
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -234,7 +234,7 @@ GameObject:
- component: {fileID: 1702728168}
- component: {fileID: 1702728167}
m_Layer: 0
m_Name: UnlockButton
m_Name: handle_mesh
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -369,13 +369,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1963847629}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!114 &1963847633
MonoBehaviour:
m_ObjectHideFlags: 0
@ -426,7 +426,7 @@ PrefabInstance:
- target: {fileID: -8679921383154817045, guid: 5009e49fafd33ed0e980b53b1f9e954d,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
value: 0.9982502
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5009e49fafd33ed0e980b53b1f9e954d,
type: 3}
@ -436,7 +436,7 @@ PrefabInstance:
- target: {fileID: -8679921383154817045, guid: 5009e49fafd33ed0e980b53b1f9e954d,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
value: -0.059132166
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5009e49fafd33ed0e980b53b1f9e954d,
type: 3}
@ -451,7 +451,7 @@ PrefabInstance:
- target: {fileID: -8679921383154817045, guid: 5009e49fafd33ed0e980b53b1f9e954d,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
value: -6.78
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 5009e49fafd33ed0e980b53b1f9e954d,
type: 3}

View file

@ -23,9 +23,15 @@
_HeightOffset ("Height offset", Range(-10, 10)) = -0.5
_WaterCol ("Water color", Color) = (0.03, 0.08, 0.12, 1.0)
_WaveStrength ("Wave scale", Range(0, 1)) = 1
_WaveSpeed ("Wave speed", Range(0, 5)) = 1
[NoScaleOffset]
_WaterNormal ("Surface Normal", 2D) = "white" {}
// [NoScaleOffset]
// _WaterHeight ("Height", 2D) = "white" {}
// [NoScaleOffset]
// _WaterAO ("AO", 2D) = "white" {}
[Header(Debug)]
// _TempTex ("Temp", 2D) = "white" {}
_Grid ("Grid visibility", Range(0, 1)) = 0
}
@ -45,6 +51,9 @@
#define PI 3.1416f
#define WHITE 1
#define RED float3(1, 0, 0)
#define GREEN float3(0, 1, 0)
#define BLUE float3(0, 1, 1)
#define UP float3(0, 1, 0)
struct appdata
@ -77,9 +86,12 @@
float _SunCutoff;
sampler2D _WaterNormal;
// sampler2D _WaterHeight;
// sampler2D _WaterAO;
float3 _WaterCol;
float _HeightOffset;
float _WaveStrength;
float _WaveSpeed;
float _Grid;
@ -93,25 +105,36 @@
}
float3 get_water_normal(float2 pos) {
pos *= 0.3;
float3 normal = 0;
float t1 = _Time.x * 0.18;
normal += (tex2D(_WaterNormal, float2(1, -1) * pos + float2(t1, t1 * 0.5)) - 0.5).zxy;
float t2 = _Time.x * 0.37;
normal += (tex2D(_WaterNormal, pos * 0.276 + float2(t2 * 0.8, t2)) - 0.5).zxy;
float t3 = _Time.x * 0.08;
normal += (tex2D(_WaterNormal, pos * 0.07 + float2(t3 * 0.8, -t3)) - 0.5).zxy;
// normal = normalize(normal.zxy);
// normal = UP;
// normal += (tex2D(_NoiseTex, pos).zxy - 0.5)*0.4;
normal = normalize(normal);
pos *= 0.05;
float time = _Time.x * _WaveSpeed + 5; // offset is to make it look better at frame 0
float t1 = time * 0.18;
float3 normal = (tex2D(_WaterNormal, pos + float2(t1, -t1 * 0.5)) - 0.5) * 0.5;
float t2 = time * 0.37;
normal += (tex2D(_WaterNormal, pos * 0.276 + float2(t2 * 0.8, t2)) - 0.5);
float t3 = time * 0.08;
normal += (tex2D(_WaterNormal, pos * 0.07 + float2(t3 * 0.8, -t3)) - 0.5);
// normal = normalize(normal.zxy); // normal map import settings
normal = normalize(normal.rbg) * float3(-1, 1, -1); // standard import settings
// normal = normalize(normal);
// return UP;
return lerp(UP, normal, _WaveStrength);
}
// float3 get_ao(float2 pos) {
// pos *= 0.1;
// float3 ao = 0;
// float t1 = _Time.x * 0.18;
// ao += (tex2D(_WaterAO, float2(1, -1) * pos + float2(t1, t1 * 0.5)));
// float t2 = _Time.x * 0.37;
// ao += (tex2D(_WaterAO, pos * 0.276 + float2(t2 * 0.8, t2)));
// float t3 = _Time.x * 0.08;
// ao += (tex2D(_WaterAO, pos * 0.07 + float2(t3 * 0.8, -t3)));
// return ao/3;
// }
inline float smin(float a, float b, float k)
{
float h = max(k - abs(a - b), 0) / k;
@ -124,7 +147,17 @@
return max(a, b) + h * h * h * k * 1/6;
}
float3 sky(float3 dir, float theta, float phi, float3 sun_dir) {
float3 sun(float3 base_col, float3 dir, float3 sun_dir)
{
float alignment = min(acos(dot(dir, sun_dir)), 1);
float sun_amount = smax(min(_SunRadius / alignment, 5) - _SunCutoff, 0, 0.15);
return lerp(base_col, _SunCol, sun_amount);
}
float3 sky(float3 dir, float3 sun_dir)
{
float theta = atan2(dir.x, dir.z); // latitude
float phi = asin(dir.y); // longitude
/// background
float factor = smoothstep(0, 0.5, dir.y + 0.2);
float3 horizon_col = lerp(_SkyCol, _SunCol, _HorizonTint);
@ -162,14 +195,17 @@
col = lerp(col, star_col, star_strength);
/// sun
float alignment = min(acos(dot(dir, sun_dir)), 1);
float sun_amount = smax(min(_SunRadius / alignment, 5) - _SunCutoff, 0, 0.15);
col = lerp(col, _SunCol, sun_amount);
col = sun(col, dir, sun_dir);
// col = sun(col, dir, float3(1,0,0));
// col = sun(col, dir, float3(-1,0,0));
// col = sun(col, dir, float3(0,0,1));
// col = sun(col, dir, float3(0,0,-1));
// col = sun(col, dir, normalize(float3(-1,0,-1)));
// col = sun(col, dir, normalize(float3(1,0,-1)));
// col = sun(col, dir, normalize(float3(-1,0,1)));
// col = sun(col, dir, normalize(float3(1,0,1)));
/// 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) +
@ -184,17 +220,15 @@
{
// float3 horizon_col = lerp(_SkyCol, _SunCol, _HorizonTint);
float3 origin = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
float3 sun_dir = mul(unity_ObjectToWorld, float4(0, 0, 1, 1)) * float3(1, 0, 1) - origin;
float3 sun_dir = (mul(unity_ObjectToWorld, float4(0, 0, -1, 1)) - origin) * float3(1, 0, 1);
// sun_dir.y = sin(_Time.x * 10) * 0.05;
sun_dir = normalize(sun_dir);
float3 dir = normalize(i.hit_pos - i.cam_pos);
float theta = atan2(dir.x, dir.z); // latitude
float phi = asin(dir.y); // longitude
float3 col;
if (phi < 0) {
if (dir.y < 0) {
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.
@ -205,25 +239,32 @@
);
float3 water_normal = get_water_normal(surface_pos.xz);
float3 reflected_dir = reflect(dir, water_normal);
float3 sky_reflection = sky(reflected_dir, sun_dir) ;
float3 water_col = lerp(_SkyCol, _SunCol, 0.01) * _WaterCol;
float3 refracted_dir = normalize(refract(dir, water_normal, 1/1.333));
float subsurf = (refracted_dir.y + 1);
dir = reflect(dir, water_normal);
phi = asin(dir.y);
float hit_angle = dot(dir, water_normal);
col = water_col * max(subsurf * 12 - 2, 0.7);
float3 sky_reflection = sky(dir, theta, phi, sun_dir) ;
// float3 water_ao = get_ao(surface_pos.xz);
// col = water_col * lerp(0.1, water_ao, _WaveStrength) * 7;
float3 water_col = lerp(_SkyCol, _SunCol, 0.01) * _WaterCol;
col = water_col * subsurf * 12;
float hit_angle = dot(dir, -water_normal);
col = lerp(sky_reflection, col, hit_angle);
// col = sky_reflection;
// col *= pow(dot(UP, water_normal), 512); // EVIL in the water
// col = pow((tex2D(_WaterNormal, surface_pos.xz).zxy), 2);
// col = tex2D(_WaterAO, surface_pos.xz);
// 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 {
col = sky(dir, theta, phi, sun_dir);
col = sky(dir, sun_dir);
}
return float4(col, 1);
}