From 149a90e01c429186603fbc6976d5cf91252a401e Mon Sep 17 00:00:00 2001 From: Reinier Vens Date: Tue, 1 Jun 2021 08:16:36 +0100 Subject: [PATCH] Realistic Volumetrics Tweaked the density function for the clouds - fill density now fades smoothly to zero over safety radius Changed the way density is mapped to luminosity in volume color sampling Added directional lighting to clouds Changed raymarching accumulation logic Fixed step artifacts (reverted to simple blue noise sampling) --- Assets/Materials/Fog Marching Main Menu.mat | 32 ++++----- Assets/Materials/Fog Marching.mat | 28 ++++---- Assets/Materials/UI/Map Gravity Lines.mat | 2 +- Assets/Scenes/ARPG.unity | 67 +----------------- Assets/Scenes/Main Menu.unity | 70 ++++--------------- Assets/Shaders/Compute/Stardust/Stardust.mat | 2 +- .../Shaders/Raymarching/VolumeRender.shader | 21 +++--- Assets/Shaders/Terrain/My Lighting.cginc | 14 ---- GameData/PlayerSettings.msgpack | 4 +- 9 files changed, 58 insertions(+), 182 deletions(-) diff --git a/Assets/Materials/Fog Marching Main Menu.mat b/Assets/Materials/Fog Marching Main Menu.mat index 49fd25a36..7eb5ac30e 100644 --- a/Assets/Materials/Fog Marching Main Menu.mat +++ b/Assets/Materials/Fog Marching Main Menu.mat @@ -42,32 +42,32 @@ Material: m_Floats: - _AlphaFloor: 0 - _DepthBlend: 512 - - _DepthCeiling: 4096 - - _FlowSpeed: 1 - - _Gamma: 0.25 + - _DepthCeiling: 1024 + - _FlowSpeed: 5 + - _Gamma: 0.5 - _GridCeilingBlend: -300 - _GridCeilingDensity: 0.01 - _GridCeilingFollow: 0 - _GridCeilingOffset: 0 - - _GridFillDensity: 0.00001 - - _GridFloorBlend: 39.6 + - _GridFillDensity: 0.001 + - _GridFloorBlend: 50 - _GridFloorDensity: 1 - - _GridFloorOffset: 27.55 - - _GridPatchBlend: 200 - - _GridPatchDensity: 3 + - _GridFloorOffset: 104.91 + - _GridPatchBlend: 50 + - _GridPatchDensity: 1 - _NoiseExponent: 2 - - _NoiseFrequency: 0.01 - - _NoiseSpeed: 0.01 - - _NoiseStrength: 150 + - _NoiseFrequency: 0.02 + - _NoiseSpeed: 0.00001 + - _NoiseStrength: 200 - _SafetyDistance: 50 - - _Scattering: 50 + - _Scattering: 0 - _ScatteringDensityExponent: 8 - _ScatteringDistExponent: 0.5 - _ScatteringMinDist: 1 - _StepExponent: 2 - - _TintExponent: 12 - - _TurbulenceAmplitude: 1 - - _TurbulenceScale: 1 + - _TintExponent: 0.2 + - _TurbulenceAmplitude: 50 + - _TurbulenceScale: 100 m_Colors: - - _Tint: {r: 0.39215687, g: 0.39215687, b: 0.39215687, a: 1} + - _Tint: {r: 0.09803921, g: 0.09803921, b: 0.09803921, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Materials/Fog Marching.mat b/Assets/Materials/Fog Marching.mat index 6a62d9c3e..35c068f74 100644 --- a/Assets/Materials/Fog Marching.mat +++ b/Assets/Materials/Fog Marching.mat @@ -43,31 +43,31 @@ Material: - _AlphaFloor: 0.01 - _DepthBlend: 512 - _DepthCeiling: 4096 - - _FlowSpeed: 2.5 + - _FlowSpeed: 2 - _Gamma: 0.5 - _GridCeilingBlend: -300 - _GridCeilingDensity: 0.01 - _GridCeilingFollow: 0 - _GridCeilingOffset: 0 - - _GridFillDensity: 0.00002 - - _GridFloorBlend: 50 - - _GridFloorDensity: 3 - - _GridFloorOffset: 0 - - _GridPatchBlend: 50 - - _GridPatchDensity: 0.5 + - _GridFillDensity: 0.0025 + - _GridFloorBlend: 100 + - _GridFloorDensity: 2 + - _GridFloorOffset: 22.8 + - _GridPatchBlend: 30 + - _GridPatchDensity: 0.25 - _NoiseExponent: 1 - - _NoiseFrequency: 0.02 + - _NoiseFrequency: 0.01 - _NoiseSpeed: 0 - - _NoiseStrength: 250 - - _SafetyDistance: 53.73 - - _Scattering: 1.25 + - _NoiseStrength: 100 + - _SafetyDistance: 40 + - _Scattering: 0 - _ScatteringDensityExponent: 0.5 - _ScatteringDistExponent: 0.5 - _ScatteringMinDist: 500 - _StepExponent: 2 - - _TintExponent: 9 - - _TurbulenceAmplitude: 25 + - _TintExponent: 1.5 + - _TurbulenceAmplitude: 100 - _TurbulenceScale: 100 m_Colors: - - _Tint: {r: 6.525489, g: 6.525489, b: 6.525489, a: 1} + - _Tint: {r: 0.0014705883, g: 0.0014705883, b: 0.0014705883, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Materials/UI/Map Gravity Lines.mat b/Assets/Materials/UI/Map Gravity Lines.mat index 1841af6a4..2d44e5cc2 100644 --- a/Assets/Materials/UI/Map Gravity Lines.mat +++ b/Assets/Materials/UI/Map Gravity Lines.mat @@ -86,7 +86,7 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 - - _Scale: 4.091124 + - _Scale: 5.0237036 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 diff --git a/Assets/Scenes/ARPG.unity b/Assets/Scenes/ARPG.unity index 129b7e116..25bd7cb5c 100644 --- a/Assets/Scenes/ARPG.unity +++ b/Assets/Scenes/ARPG.unity @@ -30670,15 +30670,12 @@ GameObject: m_Component: - component: {fileID: 2115559090} - component: {fileID: 2115559089} - - component: {fileID: 2115559098} - component: {fileID: 2115559091} - component: {fileID: 2115559092} - component: {fileID: 2115559093} - component: {fileID: 2115559094} - component: {fileID: 2115559095} - component: {fileID: 2115559088} - - component: {fileID: 2115559097} - - component: {fileID: 2115559096} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -30778,9 +30775,9 @@ MonoBehaviour: antialiasingMode: 3 temporalAntialiasing: jitterSpread: 1 - sharpness: 0 + sharpness: 0.5 stationaryBlending: 0.98 - motionBlending: 0.98 + motionBlending: 0.95 subpixelMorphologicalAntialiasing: quality: 2 fastApproximateAntialiasing: @@ -30904,66 +30901,6 @@ MonoBehaviour: positionOffset: {x: 0, y: 0, z: 0} m_posOffsetData: {fileID: 0} listenerMask: 1 ---- !u!114 &2115559096 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2115559087} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b642ff60407fe724bafa6602199213c0, type: 3} - m_Name: - m_EditorClassIdentifier: - velocityShader: {fileID: 4800000, guid: 0d7f09e63dd99504ca6e04212a21ec72, type: 3} - neighborMaxGen: 0 - neighborMaxSupport: 1 - numResident: 0 - numRendered: 0 - numDrawCalls: 0 ---- !u!114 &2115559097 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2115559087} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 899f97884c6d96b4ca20648ec109a37f, type: 3} - m_Name: - m_EditorClassIdentifier: - pattern: 9 - patternScale: 1 - activeSample: {x: 0, y: 0, z: 0, w: 0} - activeIndex: -2 ---- !u!114 &2115559098 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2115559087} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 65f5677aa325c184f801528d78a73827, type: 3} - m_Name: - m_EditorClassIdentifier: - ditherTex: {fileID: 2800000, guid: 859f329ee8606864ea19dbf373a5ec56, type: 3} - reprojectionShader: {fileID: 4800000, guid: 7ca93c1a56ee0154b8c714591d6d211a, type: 3} - colorspace: 1 - useHigherOrderFilteringMainColor: 1 - useHigherOrderFilteringHistory: 1 - historyRectification: 0 - useVarianceClipping: 1 - useAABBRounding: 1 - dilation: 2 - useMotionBlur: 0 - feedbackMin: 0.99 - feedbackMax: 0.999 - motionBlurStrength: 1 - motionBlurIgnoreFF: 0 --- !u!1 &2117796865 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Main Menu.unity b/Assets/Scenes/Main Menu.unity index be67a23de..8f40743eb 100644 --- a/Assets/Scenes/Main Menu.unity +++ b/Assets/Scenes/Main Menu.unity @@ -233,7 +233,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 47e64413aeb5ae740b410d70fb05d20c, type: 3} m_Name: m_EditorClassIdentifier: - rotSpeed: {x: 0, y: 5, z: 0} + rotSpeed: {x: 0, y: 2, z: 0} --- !u!4 &335549372 Transform: m_ObjectHideFlags: 0 @@ -802,8 +802,8 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 741153267} - m_LocalRotation: {x: 0.015506903, y: 0.9502416, z: -0.30741313, w: 0.04793323} - m_LocalPosition: {x: -117.51999, y: -77.08743, z: 149.09026} + m_LocalRotation: {x: 0.015506901, y: 0.9502416, z: -0.30741307, w: 0.047933236} + m_LocalPosition: {x: -117.51998, y: -77.08744, z: 149.09026} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 412917866} @@ -1207,12 +1207,10 @@ GameObject: - component: {fileID: 965376323} - component: {fileID: 965376327} - component: {fileID: 965376326} - - component: {fileID: 965376331} - component: {fileID: 965376325} - component: {fileID: 965376322} - component: {fileID: 965376328} - component: {fileID: 965376330} - - component: {fileID: 965376329} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -1265,7 +1263,7 @@ Camera: serializedVersion: 2 m_ClearFlags: 1 m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0} - m_projectionMatrixMode: 0 + m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 m_SensorSize: {x: 36, y: 24} @@ -1304,8 +1302,8 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 965376321} - m_LocalRotation: {x: 0.015506903, y: 0.9502416, z: -0.30741313, w: 0.04793323} - m_LocalPosition: {x: -117.51999, y: -77.08743, z: 149.09026} + m_LocalRotation: {x: 0.015506901, y: 0.9502416, z: -0.30741307, w: 0.047933236} + m_LocalPosition: {x: -117.51998, y: -77.08744, z: 149.09026} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -1329,12 +1327,12 @@ MonoBehaviour: m_Bits: 256 stopNaNPropagation: 1 finalBlitToCameraTarget: 0 - antialiasingMode: 0 + antialiasingMode: 3 temporalAntialiasing: jitterSpread: 1 - sharpness: 0.25 - stationaryBlending: 0.99 - motionBlending: 0.85 + sharpness: 0.5 + stationaryBlending: 0.975 + motionBlending: 0.95 subpixelMorphologicalAntialiasing: quality: 2 fastApproximateAntialiasing: @@ -1423,24 +1421,6 @@ MonoBehaviour: m_EditorClassIdentifier: _volMaterial: {fileID: 2100000, guid: e21702a5e6e98b7409d6913663ceab7e, type: 2} GridTransform: {fileID: 1172538221} ---- !u!114 &965376329 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 965376321} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b642ff60407fe724bafa6602199213c0, type: 3} - m_Name: - m_EditorClassIdentifier: - velocityShader: {fileID: 4800000, guid: 0d7f09e63dd99504ca6e04212a21ec72, type: 3} - neighborMaxGen: 0 - neighborMaxSupport: 1 - numResident: 0 - numRendered: 0 - numDrawCalls: 0 --- !u!114 &965376330 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1455,34 +1435,8 @@ MonoBehaviour: m_EditorClassIdentifier: pattern: 12 patternScale: 1 - activeSample: {x: -0.375, y: -0.055555552, z: 0.25, w: -0.3888889} - activeIndex: 3 ---- !u!114 &965376331 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 965376321} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 65f5677aa325c184f801528d78a73827, type: 3} - m_Name: - m_EditorClassIdentifier: - ditherTex: {fileID: 2800000, guid: 859f329ee8606864ea19dbf373a5ec56, type: 3} - reprojectionShader: {fileID: 4800000, guid: 7ca93c1a56ee0154b8c714591d6d211a, type: 3} - colorspace: 0 - useHigherOrderFilteringMainColor: 0 - useHigherOrderFilteringHistory: 1 - historyRectification: 0 - useVarianceClipping: 1 - useAABBRounding: 1 - dilation: 2 - useMotionBlur: 1 - feedbackMin: 0.88 - feedbackMax: 0.97 - motionBlurStrength: 1 - motionBlurIgnoreFF: 0 + activeSample: {x: 0.4375, y: -0.24074075, z: -0.0625, w: 0.3148148} + activeIndex: 14 --- !u!4 &971662241 stripped Transform: m_CorrespondingSourceObject: {fileID: 7852221720971737233, guid: 046dde0f4600bce41ad33c476f99b309, diff --git a/Assets/Shaders/Compute/Stardust/Stardust.mat b/Assets/Shaders/Compute/Stardust/Stardust.mat index 9d6902952..bc9da2381 100644 --- a/Assets/Shaders/Compute/Stardust/Stardust.mat +++ b/Assets/Shaders/Compute/Stardust/Stardust.mat @@ -61,7 +61,7 @@ Material: - _Cutoff: 0.5 - _DetailNormalMapScale: 1 - _DstBlend: 0 - - _EmissionGain: 0.438 + - _EmissionGain: 0.716 - _GlossMapScale: 1 - _Glossiness: 0.5 - _GlossyReflections: 1 diff --git a/Assets/Shaders/Raymarching/VolumeRender.shader b/Assets/Shaders/Raymarching/VolumeRender.shader index 60af55114..6cdbb1fd7 100644 --- a/Assets/Shaders/Raymarching/VolumeRender.shader +++ b/Assets/Shaders/Raymarching/VolumeRender.shader @@ -41,7 +41,7 @@ #include "Assets/Shaders/Volumetric.cginc" // the number of volume samples to take - #define SAMPLE_COUNT 128 + #define SAMPLE_COUNT 96 // Shared shader code for pixel view rays, given screen pos and camera frame vectors. // Camera vectors are passed in as this shader is run from a post proc camera, so the unity built-in values are not useful. @@ -57,6 +57,7 @@ uniform half _Gamma, _DepthCeiling, + _DepthBlend, _Scattering, _ScatteringDensityExponent, _ScatteringDistExponent, @@ -74,31 +75,31 @@ void RaymarchStep( in float3 pos, in float stepSize, in float weight, inout float4 sum, in float scatter, inout float scatterSum) { float4 col = VolumeSampleColor( pos ); - col.rgb *= weight * (1.0 - sum.a); - - sum += stepSize * col * col.a; + col.a *= stepSize * weight; + sum.rgb += col.rgb * col.a * (1.0 - sum.a); + sum.a += col.a; scatterSum += pow(col.a, _ScatteringDensityExponent) * scatter; } float4 RayMarch( in float3 origin, in float3 direction, in float zbuf, in float2 screenUV, out float scatterSum ) { scatterSum = 0; - float blue = tex2D(_DitheringTex, screenUV * _DitheringCoords.xy).r; - float rand = frac(blue + _FrameNumber * 1.61803398875); + float blue = tex2D(_DitheringTex, screenUV * _DitheringCoords.xy + _DitheringCoords.zw).r; + //float rand = frac(blue + _FrameNumber * 1.61803398875); //return float4(rand, rand, rand, 1); //half rand = frac(nrand(screenUV) + _FrameNumber * 1.61803398875); - //half rand = nrand(screenUV + frac(_Time.x)) * 2; + //half rand = nrand(screenUV + frac(_Time.x)); + half rand = blue; float4 sum = (float4)0.; scatterSum = 0.; // setup sampling - float offset = rand/SAMPLE_COUNT; float rayDist = 0; for( int i = 0; i < SAMPLE_COUNT; i++ ) { float prevRayDist = rayDist; - rayDist = pow((float)i/SAMPLE_COUNT + offset,_StepExponent) * _DepthCeiling; + rayDist = pow((i+rand)/SAMPLE_COUNT,_StepExponent) * _DepthCeiling + 1; float distToSurf = zbuf - rayDist; if( distToSurf <= 0.001 || sum.a > .99) break; @@ -106,8 +107,6 @@ //float wt = (distToSurf >= step) ? 1. : distToSurf / step; RaymarchStep( origin + rayDist * direction, step, 1-rayDist/_DepthCeiling, sum, _Scattering/pow(max(rayDist,_ScatteringMinDist),_ScatteringDistExponent), scatterSum); - - rayDist += step; } sum.rgb = pow( sum.rgb, 1 / _Gamma ); diff --git a/Assets/Shaders/Terrain/My Lighting.cginc b/Assets/Shaders/Terrain/My Lighting.cginc index b68c6eb9e..4dcdb1f1b 100644 --- a/Assets/Shaders/Terrain/My Lighting.cginc +++ b/Assets/Shaders/Terrain/My Lighting.cginc @@ -257,19 +257,6 @@ UnityIndirect CreateIndirectLight (Interpolators i, float3 viewDir) { float3 calcNormal (float3 pos, float2 uv) { - /*float3 n = float3(pos.x, - tex2D(_DisplacementMap, float2(uv.x, uv.y + _DisplacementMap_TexelSize.y * _DisplacementStep)).x * -_DisplacementStrength, - pos.z + _DisplacementMap_TexelSize.y * unity_ObjectToWorld._m00 * _DisplacementStep); - float3 s = float3(pos.x, - tex2D(_DisplacementMap, float2(uv.x, uv.y - _DisplacementMap_TexelSize.y * _DisplacementStep)).x * -_DisplacementStrength, - pos.z - _DisplacementMap_TexelSize.y * unity_ObjectToWorld._m00 * _DisplacementStep); - float3 e = float3(pos.x + _DisplacementMap_TexelSize.x * unity_ObjectToWorld._m00 * _DisplacementStep, - tex2D(_DisplacementMap, float2(uv.x + _DisplacementMap_TexelSize.x * _DisplacementStep, uv.y)).x * -_DisplacementStrength, - pos.z); - float3 w = float3(pos.x - _DisplacementMap_TexelSize.x * unity_ObjectToWorld._m00 * _DisplacementStep, - tex2D(_DisplacementMap, float2(uv.x - _DisplacementMap_TexelSize.x * _DisplacementStep, uv.y)).x * -_DisplacementStrength, - pos.z); - float3 norm = cross(normalize(n-s),normalize(e-w));*/ float3 n = float3(pos.x, tex2D(_DisplacementMap, float2(uv.x, uv.y + _DisplacementMap_TexelSize.y * _DisplacementStep)).x * -_DisplacementStrength, pos.z + _DisplacementMap_TexelSize.y * unity_ObjectToWorld._m00 * _DisplacementStep); @@ -279,7 +266,6 @@ float3 calcNormal (float3 pos, float2 uv) float3 e = float3(pos.x + _DisplacementMap_TexelSize.x * unity_ObjectToWorld._m00 * _DisplacementStep, tex2D(_DisplacementMap, float2(uv.x + _DisplacementMap_TexelSize.x * _DisplacementStep, uv.y)).x * -_DisplacementStrength, pos.z); - //float3 norm = cross(normalize(n-s),normalize(e-w)); float3 norm = cross(normalize(n-me),normalize(e-me)); return norm; } diff --git a/GameData/PlayerSettings.msgpack b/GameData/PlayerSettings.msgpack index 7e6d92003..c88f04d85 100644 --- a/GameData/PlayerSettings.msgpack +++ b/GameData/PlayerSettings.msgpack @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1478a630cae13020cca64ce4d079128be00d6b0183b453ee928841f6ca9747ce -size 46017 +oid sha256:2ee3ed112ccfb79f6913ce95c044e443db527051a39daa9c5850f049eed7eab9 +size 42803