add weather and time
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
#include_with_pragmas "FogInclude.cginc"
|
||||
|
||||
float3 ApplyFog(float3 sceneColor, float2 uv, float3 wPos, float linearDepth)
|
||||
{
|
||||
return ApplyFogAndVolumetricLights(sceneColor,uv,wPos,linearDepth);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a1642594534635429ca94e74de65d26
|
||||
timeCreated: 1452690568
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
#include_with_pragmas "FogIncludeHLSL.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
|
||||
float _EnviroSkyIntensity;
|
||||
|
||||
float3 ApplyFog(float3 sceneColor, float2 uv, float3 wPos, float linearDepth)
|
||||
{
|
||||
float4 fog = GetExponentialHeightFog(wPos,linearDepth);
|
||||
fog.rgb *= _EnviroSkyIntensity * GetCurrentExposureMultiplier();
|
||||
return ApplyVolumetricLights(fog,sceneColor,uv);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3082087955cba844a717ad38fde3a0d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
#include_with_pragmas "FogIncludeHLSL.hlsl"
|
||||
|
||||
float3 ApplyFog(float3 sceneColor, float2 uv, float3 wPos, float linearDepth)
|
||||
{
|
||||
return ApplyFogAndVolumetricLights(sceneColor,uv,wPos,linearDepth);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65b7a748fa7b55b48b3001df25bcf1da
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,211 @@
|
||||
#include "SkyInclude.cginc"
|
||||
#include "VolumetricCloudsBlendInclude.cginc"
|
||||
|
||||
#ifndef ENVIRO_VOLUMELIGHT_KEYWORD
|
||||
#define ENVIRO_VOLUMELIGHT_KEYWORD
|
||||
#pragma multi_compile __ ENVIRO_VOLUMELIGHT
|
||||
#endif
|
||||
|
||||
#ifndef ENVIRO_SIMPLEFOG_KEYWORD
|
||||
#define ENVIRO_SIMPLEFOG_KEYWORD
|
||||
#pragma multi_compile __ ENVIRO_SIMPLEFOG
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
UNITY_DECLARE_TEX2DARRAY(_EnviroVolumetricFogTex);
|
||||
#else
|
||||
sampler2D _EnviroVolumetricFogTex;
|
||||
#endif
|
||||
|
||||
float4 _EnviroVolumetricFogTex_TexelSize;
|
||||
float4 _Screen_TexelSize;
|
||||
|
||||
uniform float4 _EnviroFogParameters; //x = rayorigin1, y = falloff1, z = density1, w = height1
|
||||
uniform float4 _EnviroFogParameters2; //x = rayorigin2, y = falloff2, z = density2, w = height2
|
||||
uniform float4 _EnviroFogParameters3; //x = maxDensity, y = startDistance, z = , w = sky blend
|
||||
uniform float4 _EnviroFogColor; //Fog color
|
||||
uniform float4 _EnviroDirLightColor;
|
||||
uniform float3 _EnviroCameraPos;
|
||||
uniform float3 _EnviroWorldOffset;
|
||||
|
||||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN)
|
||||
struct EnviroRemovalZones
|
||||
{
|
||||
float type;
|
||||
float3 pos;
|
||||
float radius;
|
||||
float3 size;
|
||||
float3 axis;
|
||||
float stretch;
|
||||
float density;
|
||||
float feather;
|
||||
float4x4 transform;
|
||||
float pad0;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
StructuredBuffer<EnviroRemovalZones> _EnviroRemovalZones : register(t1);
|
||||
float _EnviroRemovalZonesCount;
|
||||
#endif
|
||||
|
||||
int ihash(int n)
|
||||
{
|
||||
n = (n<<13)^n;
|
||||
return (n*(n*n*15731+789221)+1376312589) & 2147483647;
|
||||
}
|
||||
|
||||
float frand(int n)
|
||||
{
|
||||
return ihash(n) / 2147483647.0;
|
||||
}
|
||||
|
||||
float2 cellNoise(int2 p)
|
||||
{
|
||||
int i = p.y*256 + p.x;
|
||||
return float2(frand(i), frand(i + 57)) - 0.5;//*2.0-1.0;
|
||||
}
|
||||
|
||||
float Pow2(float x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
float CalculateLineIntegral(float FogHeightFalloff, float RayDirectionY, float RayOriginTerms)
|
||||
{
|
||||
float Falloff = FogHeightFalloff * RayDirectionY;
|
||||
|
||||
float LineIntegral = ((1.0f - exp2(-Falloff)) / Falloff);
|
||||
float LineIntegralTaylor = log(2.0) - (0.5 * Pow2(log(2.0))) * Falloff;
|
||||
|
||||
return RayOriginTerms * (abs(Falloff) > 0.01f ? LineIntegral : LineIntegralTaylor);
|
||||
}
|
||||
|
||||
float3 InverseLerp(float lowThreshold, float hiThreshold, float value)
|
||||
{
|
||||
return (value - lowThreshold) / (hiThreshold - lowThreshold);
|
||||
}
|
||||
float ClampedInverseLerp(float lowThreshold, float hiThreshold, float value)
|
||||
{
|
||||
return saturate(InverseLerp(lowThreshold, hiThreshold, value));
|
||||
}
|
||||
|
||||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN)
|
||||
|
||||
void FogZones(float3 pos, inout float density)
|
||||
{
|
||||
for (int i = 0; i < _EnviroRemovalZonesCount; i++)
|
||||
{
|
||||
if(_EnviroRemovalZones[i].type == 0)
|
||||
{
|
||||
float3 dir = _EnviroRemovalZones[i].pos - pos;
|
||||
float3 axis = _EnviroRemovalZones[i].axis;
|
||||
float3 dirAlongAxis = dot(dir, axis) * axis;
|
||||
|
||||
dir = dir + dirAlongAxis * _EnviroRemovalZones[i].stretch;
|
||||
float distsq = dot(dir, dir);
|
||||
float radius = _EnviroRemovalZones[i].radius;
|
||||
float feather = _EnviroRemovalZones[i].feather;
|
||||
|
||||
feather = (1.0 - smoothstep (radius * feather, radius, distsq));
|
||||
|
||||
float contribution = feather * _EnviroRemovalZones[i].density;
|
||||
density = density + contribution;
|
||||
density = max(density,0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
float influence = 1;
|
||||
float3 position = mul(_EnviroRemovalZones[i].transform, float4(pos, 1)).xyz;
|
||||
|
||||
float x = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.x) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.x);
|
||||
float y = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.y) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.y);
|
||||
float z = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.z) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.z);
|
||||
|
||||
influence = x * y * z;
|
||||
|
||||
density += _EnviroRemovalZones[i].density * influence;
|
||||
density = max(density,0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
float4 GetExponentialHeightFog(float3 wPos, float linearDepth)
|
||||
{
|
||||
wPos = wPos - _EnviroWorldOffset;
|
||||
const half MinFogOpacity = _EnviroFogParameters3.x;
|
||||
|
||||
float3 CameraToReceiver = wPos - _EnviroCameraPos.xyz;
|
||||
float camHeightLimiter = min(2000.0f,_EnviroCameraPos.y - _EnviroWorldOffset.y);
|
||||
float CameraToReceiverHeight = wPos.y - camHeightLimiter;
|
||||
float3 viewDirection = CameraToReceiver;
|
||||
float viewLength = length(viewDirection);
|
||||
viewDirection /= viewLength;
|
||||
|
||||
float fogAmount = 0;
|
||||
|
||||
float RayDirectionY = CameraToReceiverHeight;
|
||||
|
||||
float Exponent = _EnviroFogParameters.y * (camHeightLimiter - _EnviroFogParameters.w);
|
||||
float RayOriginTerms = _EnviroFogParameters.z * exp2(-Exponent);
|
||||
float ExponentSecond = _EnviroFogParameters2.y * (camHeightLimiter - _EnviroFogParameters2.w);
|
||||
float RayOriginTermsSecond = _EnviroFogParameters2.z * exp2(-ExponentSecond);
|
||||
|
||||
#if ENVIRO_SIMPLEFOG
|
||||
fogAmount = CalculateLineIntegral(_EnviroFogParameters.y, RayDirectionY, RayOriginTerms) * viewLength;
|
||||
#else
|
||||
fogAmount = (CalculateLineIntegral(_EnviroFogParameters.y, RayDirectionY, RayOriginTerms) + CalculateLineIntegral(_EnviroFogParameters2.y, RayDirectionY, RayOriginTermsSecond)) * viewLength;
|
||||
#endif
|
||||
|
||||
//Start Distance
|
||||
if(viewLength <= _EnviroFogParameters3.y)
|
||||
{
|
||||
float fallOff = ClampedInverseLerp(0.0f,_EnviroFogParameters3.y, viewLength);
|
||||
fogAmount = fogAmount * pow(fallOff,6);
|
||||
}
|
||||
|
||||
//Fog Zones
|
||||
fogAmount = clamp(fogAmount,0,10);
|
||||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN)
|
||||
FogZones(wPos,fogAmount);
|
||||
#endif
|
||||
|
||||
float fogfactor = max(exp2(-fogAmount), MinFogOpacity);
|
||||
float scatteringFactor = saturate(linearDepth + _EnviroFogParameters3.z);
|
||||
|
||||
// Color
|
||||
#if ENVIRO_SIMPLESKY
|
||||
float4 sky = GetSkyColorSimple(viewDirection,0.005f,scatteringFactor);
|
||||
#else
|
||||
float4 sky = GetSkyColor(viewDirection,0.005f,scatteringFactor);
|
||||
#endif
|
||||
float3 inscatterColor = lerp(_EnviroFogColor.rgb,sky.rgb,_EnviroFogParameters3.w);
|
||||
float3 fogColor = inscatterColor * saturate(1 - fogfactor);
|
||||
|
||||
return float4(fogColor, fogfactor);
|
||||
}
|
||||
|
||||
float3 ApplyVolumetricLights(float4 fogColor, float3 sceneColor, float2 uv)
|
||||
{
|
||||
#if ENVIRO_VOLUMELIGHT
|
||||
float4 volumeLightsSample = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_EnviroVolumetricFogTex, uv);
|
||||
//uvs += cellNoise(uvs.xy * _Screen_TexelSize.zw) * _VolumeScatter_TexelSize.xy * 0.8;
|
||||
float3 volumeLightsDirectional = volumeLightsSample.a * _EnviroDirLightColor.rgb;
|
||||
float3 volumeLights = volumeLightsSample.rgb;
|
||||
return (sceneColor.rgb * fogColor.a + fogColor.rgb * max(volumeLightsDirectional,0.75)) + volumeLights;
|
||||
//return (sceneColor.rgb * fogColor.a + fogColor.rgb) + volumeLightsDirectional + volumeLights;
|
||||
#else
|
||||
return sceneColor.rgb * fogColor.a + fogColor.rgb;
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 ApplyFogAndVolumetricLights(float3 sceneColor, float2 uv, float3 wPos, float linearDepth)
|
||||
{
|
||||
float4 fog = GetExponentialHeightFog(wPos,linearDepth);
|
||||
return ApplyVolumetricLights(fog,sceneColor,uv);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa261f31cac9cc643a5ab48737979f2f
|
||||
timeCreated: 1452690568
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/FogInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,205 @@
|
||||
#include "SkyIncludeHLSL.hlsl"
|
||||
#include "VolumetricCloudsBlendIncludeHLSL.hlsl"
|
||||
|
||||
|
||||
#ifndef ENVIRO_VOLUMELIGHT_KEYWORD
|
||||
#define ENVIRO_VOLUMELIGHT_KEYWORD
|
||||
#pragma multi_compile __ ENVIRO_VOLUMELIGHT
|
||||
#endif
|
||||
|
||||
#ifndef ENVIRO_SIMPLEFOG_KEYWORD
|
||||
#define ENVIRO_SIMPLEFOG_KEYWORD
|
||||
#pragma multi_compile __ ENVIRO_SIMPLEFOG
|
||||
#endif
|
||||
|
||||
|
||||
TEXTURE2D_X(_EnviroVolumetricFogTex);
|
||||
SAMPLER(sampler_EnviroVolumetricFogTex);
|
||||
float4 _EnviroVolumetricFogTex_TexelSize;
|
||||
float4 _Screen_TexelSize;
|
||||
|
||||
uniform float4 _EnviroFogParameters; //x = rayorigin1, y = falloff1, z = density1, w = height1
|
||||
uniform float4 _EnviroFogParameters2; //x = rayorigin2, y = falloff2, z = density2, w = height2
|
||||
uniform float4 _EnviroFogParameters3; //x = maxDensity, y = startDistance, z = , w = sky blend
|
||||
uniform float4 _EnviroFogColor; //Fog color
|
||||
uniform float4 _EnviroDirLightColor;
|
||||
uniform float3 _EnviroCameraPos;
|
||||
uniform float3 _EnviroWorldOffset;
|
||||
|
||||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN)
|
||||
struct EnviroRemovalZones
|
||||
{
|
||||
float type;
|
||||
float3 pos;
|
||||
float radius;
|
||||
float3 size;
|
||||
float3 axis;
|
||||
float stretch;
|
||||
float density;
|
||||
float feather;
|
||||
float4x4 transform;
|
||||
float pad0;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
StructuredBuffer<EnviroRemovalZones> _EnviroRemovalZones : register(t1);
|
||||
float _EnviroRemovalZonesCount;
|
||||
#endif
|
||||
|
||||
int ihash(int n)
|
||||
{
|
||||
n = (n<<13)^n;
|
||||
return (n*(n*n*15731+789221)+1376312589) & 2147483647;
|
||||
}
|
||||
|
||||
float frand(int n)
|
||||
{
|
||||
return ihash(n) / 2147483647.0;
|
||||
}
|
||||
|
||||
float2 cellNoise(int2 p)
|
||||
{
|
||||
int i = p.y*256 + p.x;
|
||||
return float2(frand(i), frand(i + 57)) - 0.5;//*2.0-1.0;
|
||||
}
|
||||
|
||||
float Pow2(float x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
float CalculateLineIntegral(float FogHeightFalloff, float RayDirectionY, float RayOriginTerms)
|
||||
{
|
||||
float Falloff = FogHeightFalloff * RayDirectionY;
|
||||
|
||||
float LineIntegral = ((1.0f - exp2(-Falloff)) / Falloff);
|
||||
float LineIntegralTaylor = log(2.0) - (0.5 * Pow2(log(2.0))) * Falloff;
|
||||
|
||||
return RayOriginTerms * (abs(Falloff) > 0.01f ? LineIntegral : LineIntegralTaylor);
|
||||
}
|
||||
|
||||
float3 InverseLerp(float lowThreshold, float hiThreshold, float value)
|
||||
{
|
||||
return (value - lowThreshold) / (hiThreshold - lowThreshold);
|
||||
}
|
||||
float ClampedInverseLerp(float lowThreshold, float hiThreshold, float value)
|
||||
{
|
||||
return saturate(InverseLerp(lowThreshold, hiThreshold, value));
|
||||
}
|
||||
|
||||
|
||||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN)
|
||||
|
||||
void FogZones(float3 pos, inout float density)
|
||||
{
|
||||
for (int i = 0; i < _EnviroRemovalZonesCount; i++)
|
||||
{
|
||||
if(_EnviroRemovalZones[i].type == 0)
|
||||
{
|
||||
float3 dir = _EnviroRemovalZones[i].pos - pos;
|
||||
float3 axis = _EnviroRemovalZones[i].axis;
|
||||
float3 dirAlongAxis = dot(dir, axis) * axis;
|
||||
|
||||
dir = dir + dirAlongAxis * _EnviroRemovalZones[i].stretch;
|
||||
float distsq = dot(dir, dir);
|
||||
float radius = _EnviroRemovalZones[i].radius;
|
||||
float feather = _EnviroRemovalZones[i].feather;
|
||||
|
||||
feather = (1.0 - smoothstep (radius * feather, radius, distsq));
|
||||
|
||||
float contribution = feather * _EnviroRemovalZones[i].density;
|
||||
density = density + contribution;
|
||||
density = max(density,0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
float influence = 1;
|
||||
float3 position = mul(_EnviroRemovalZones[i].transform, float4(pos, 1)).xyz;
|
||||
|
||||
float x = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.x) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.x);
|
||||
float y = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.y) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.y);
|
||||
float z = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.z) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.z);
|
||||
|
||||
influence = x * y * z;
|
||||
|
||||
density += _EnviroRemovalZones[i].density * influence;
|
||||
density = max(density,0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 GetExponentialHeightFog(float3 wPos, float linearDepth)
|
||||
{
|
||||
wPos = wPos - _EnviroWorldOffset;
|
||||
|
||||
const half MinFogOpacity = _EnviroFogParameters3.x;
|
||||
|
||||
float3 CameraToReceiver = wPos - _EnviroCameraPos.xyz;
|
||||
float camHeightLimiter = min(2000.0f,_EnviroCameraPos.y - _EnviroWorldOffset.y);
|
||||
float CameraToReceiverHeight = wPos.y - camHeightLimiter;
|
||||
float3 viewDirection = CameraToReceiver;
|
||||
float viewLength = length(viewDirection);
|
||||
viewDirection /= viewLength;
|
||||
|
||||
float fogAmount = 0;
|
||||
float RayDirectionY = CameraToReceiverHeight;
|
||||
|
||||
float Exponent = _EnviroFogParameters.y * (camHeightLimiter - _EnviroFogParameters.w);
|
||||
float RayOriginTerms = _EnviroFogParameters.z * exp2(-Exponent);
|
||||
float ExponentSecond = _EnviroFogParameters2.y * (camHeightLimiter - _EnviroFogParameters2.w);
|
||||
float RayOriginTermsSecond = _EnviroFogParameters2.z * exp2(-ExponentSecond);
|
||||
|
||||
#if ENVIRO_SIMPLEFOG
|
||||
fogAmount = CalculateLineIntegral(_EnviroFogParameters.y, RayDirectionY, RayOriginTerms) * viewLength;
|
||||
#else
|
||||
fogAmount = (CalculateLineIntegral(_EnviroFogParameters.y, RayDirectionY, RayOriginTerms) + CalculateLineIntegral(_EnviroFogParameters2.y, RayDirectionY, RayOriginTermsSecond)) * viewLength;
|
||||
#endif
|
||||
|
||||
//Start Distance
|
||||
if(viewLength <= _EnviroFogParameters3.y)
|
||||
{
|
||||
float fallOff = ClampedInverseLerp(0.0f,_EnviroFogParameters3.y, viewLength);
|
||||
fogAmount = fogAmount * pow(fallOff,6);
|
||||
}
|
||||
|
||||
//Fog Zones
|
||||
fogAmount = clamp(fogAmount,0,10);
|
||||
#if defined(SHADER_API_D3D11) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN)
|
||||
FogZones(wPos,fogAmount);
|
||||
#endif
|
||||
|
||||
float fogfactor = max(exp2(-fogAmount), MinFogOpacity);
|
||||
float scatteringFactor = saturate(linearDepth + _EnviroFogParameters3.z);
|
||||
|
||||
// Color
|
||||
#if ENVIRO_SIMPLESKY
|
||||
float4 sky = GetSkyColorSimple(viewDirection,0.005f,scatteringFactor);
|
||||
#else
|
||||
float4 sky = GetSkyColor(viewDirection,0.005f,scatteringFactor);
|
||||
#endif
|
||||
float3 inscatterColor = lerp(_EnviroFogColor.rgb,sky.rgb,_EnviroFogParameters3.w);
|
||||
float3 fogColor = inscatterColor * saturate(1 - fogfactor);
|
||||
|
||||
return float4(fogColor, fogfactor);
|
||||
}
|
||||
|
||||
float3 ApplyVolumetricLights(float4 fogColor, float3 sceneColor, float2 uv)
|
||||
{
|
||||
#if defined(ENVIRO_VOLUMELIGHT)
|
||||
float4 volumeLightsSample = SAMPLE_TEXTURE2D_X(_EnviroVolumetricFogTex, sampler_EnviroVolumetricFogTex, uv);
|
||||
//uvs += cellNoise(uvs.xy * _Screen_TexelSize.zw) * _VolumeScatter_TexelSize.xy * 0.8;
|
||||
float3 volumeLightsDirectional = volumeLightsSample.a * _EnviroDirLightColor.rgb;
|
||||
float3 volumeLights = volumeLightsSample.rgb;
|
||||
return (sceneColor.rgb * fogColor.a + fogColor.rgb * max(volumeLightsDirectional,0.75)) + volumeLights;
|
||||
#else
|
||||
return sceneColor.rgb * fogColor.a + fogColor.rgb;
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 ApplyFogAndVolumetricLights(float3 sceneColor, float2 uv, float3 wPos, float linearDepth)
|
||||
{
|
||||
float4 fog = GetExponentialHeightFog(wPos,linearDepth);
|
||||
return ApplyVolumetricLights(fog,sceneColor,uv);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8db9bd7b531f93d46ae2cb21180a00a8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/FogIncludeHLSL.hlsl
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,151 @@
|
||||
///////////PERLIN NOISE////////////////
|
||||
//////// NOT USED ANYMORE ////////////
|
||||
|
||||
// Hash to get pseudo-random gradient direction
|
||||
float2 hash2(float2 p)
|
||||
{
|
||||
// A simple 2D hash
|
||||
p = frac(p * float2(127.1, 311.7));
|
||||
p += dot(p, p + 74.7);
|
||||
return normalize(frac(float2(p.x * p.y, p.x + p.y)) * 2.0 - 1.0);
|
||||
}
|
||||
|
||||
// Quintic fade curve for smooth interpolation
|
||||
float fade(float t)
|
||||
{
|
||||
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
|
||||
}
|
||||
|
||||
float penoise(float2 uv, float scale)
|
||||
{
|
||||
// Scale and wrap UVs to create tileable domain
|
||||
float2 p = uv * scale;
|
||||
|
||||
// Integer cell coordinates
|
||||
float2 i0 = floor(p);
|
||||
float2 f = frac(p);
|
||||
|
||||
// Wrap to ensure seamless tiling
|
||||
float2 i1 = fmod(i0 + 1.0, scale);
|
||||
|
||||
// Gradient vectors for the four cell corners
|
||||
float2 g00 = hash2(fmod(i0, scale));
|
||||
float2 g10 = hash2(float2(i1.x, i0.y));
|
||||
float2 g01 = hash2(float2(i0.x, i1.y));
|
||||
float2 g11 = hash2(i1);
|
||||
|
||||
// Distance vectors to corners
|
||||
float2 d00 = f - float2(0.0, 0.0);
|
||||
float2 d10 = f - float2(1.0, 0.0);
|
||||
float2 d01 = f - float2(0.0, 1.0);
|
||||
float2 d11 = f - float2(1.0, 1.0);
|
||||
|
||||
// Dot products
|
||||
float n00 = dot(g00, d00);
|
||||
float n10 = dot(g10, d10);
|
||||
float n01 = dot(g01, d01);
|
||||
float n11 = dot(g11, d11);
|
||||
|
||||
// Smooth interpolation
|
||||
float2 u = fade(f);
|
||||
float nx0 = lerp(n00, n10, u.x);
|
||||
float nx1 = lerp(n01, n11, u.x);
|
||||
float nxy = lerp(nx0, nx1, u.y);
|
||||
|
||||
// Normalize to [0,1]
|
||||
return 0.5 + 0.5 * nxy;
|
||||
}
|
||||
|
||||
float perlinFBM(float2 uv, float baseScale, int octaves, float gain, float lacun)
|
||||
{
|
||||
float total = 0.0;
|
||||
float amp = 0.5; // starting amplitude
|
||||
float freq = 1.0; // starting frequency
|
||||
float weight = 0.0;
|
||||
|
||||
// Always wrap UV first to avoid precision drift
|
||||
uv = frac(uv);
|
||||
|
||||
[unroll]
|
||||
for (int i = 0; i < octaves; i++)
|
||||
{
|
||||
// Sample tileable perlin at increasing frequency
|
||||
// Keep tiling domain proportional to frequency for seamless wrap
|
||||
total += amp * penoise(uv * freq, baseScale * freq);
|
||||
weight += amp;
|
||||
|
||||
freq *= lacun; // e.g. 2.0
|
||||
amp *= gain; // e.g. 0.5
|
||||
}
|
||||
|
||||
// Normalize to 0..1
|
||||
return saturate(total / weight);
|
||||
}
|
||||
//////////////////////////////////////////
|
||||
///////////WORLEY NOISE///////////////////
|
||||
//////////////////////////////////////////
|
||||
|
||||
// Hash to generate a repeatable 0..1 value for integer coords
|
||||
float hash21_stable(int2 p, int period)
|
||||
{
|
||||
uint2 pu = (uint2)(p + period * 4096); // shift into positive domain
|
||||
pu = pu % (uint)period;
|
||||
|
||||
uint n = pu.x * 73856093u ^ pu.y * 19349663u;
|
||||
return frac((float)n * 0.000000119f);
|
||||
}
|
||||
|
||||
float2 hash22_stable(int2 p, int period)
|
||||
{
|
||||
float h1 = hash21_stable(p, period);
|
||||
float h2 = hash21_stable(p + int2(17, 37), period);
|
||||
return float2(h1, h2);
|
||||
}
|
||||
|
||||
float Worley2D_Stable(float2 uv, int tileCount)
|
||||
{
|
||||
// Tile domain
|
||||
float2 p = uv * tileCount;
|
||||
int2 baseCell = int2(floor(p));
|
||||
float2 f = frac(p);
|
||||
|
||||
float minDist = 1.0;
|
||||
|
||||
// Search 3x3 neighborhood
|
||||
[unroll]
|
||||
for (int y = -1; y <= 1; y++)
|
||||
{
|
||||
[unroll]
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
int2 neighbor = baseCell + int2(x, y);
|
||||
float2 rand = hash22_stable(neighbor, tileCount);
|
||||
float2 feature = float2(x, y) + rand;
|
||||
|
||||
float d = length(f - feature);
|
||||
minDist = min(minDist, d);
|
||||
}
|
||||
}
|
||||
return saturate(minDist);
|
||||
}
|
||||
|
||||
float WorleyFBM2D(float2 uv, int baseTiles, float bias)
|
||||
{
|
||||
uv = frac(uv); // ensure [0,1] input
|
||||
|
||||
float n = 0.0;
|
||||
float amp = 0.5;
|
||||
int tiles = baseTiles;
|
||||
|
||||
[unroll]
|
||||
for (int octave = 0; octave < 3; octave++)
|
||||
{
|
||||
n += amp * Worley2D_Stable(uv, tiles);
|
||||
tiles *= 2; // double tiles per octave
|
||||
amp *= 0.5; // halve amplitude
|
||||
}
|
||||
|
||||
// Invert + bias for cloud-like coverage
|
||||
n = pow(1.0 - n, bias);
|
||||
return saturate(n);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4be7489fb7dbf78499fe38c68a7529c0
|
||||
timeCreated: 1505167667
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/NoiseInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
struct EnviroRemovalZones
|
||||
{
|
||||
float type;
|
||||
float3 pos;
|
||||
float radius;
|
||||
float3 size;
|
||||
float3 axis;
|
||||
float stretch;
|
||||
float density;
|
||||
float feather;
|
||||
float4x4 transform;
|
||||
float pad0;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
|
||||
StructuredBuffer<EnviroRemovalZones> _EnviroRemovalZones : register(t1);
|
||||
float _EnviroRemovalZonesCount;
|
||||
|
||||
float3 InverseLerp(float lowThreshold, float hiThreshold, float3 value)
|
||||
{
|
||||
return (value - lowThreshold) / (hiThreshold - lowThreshold);
|
||||
}
|
||||
float ClampedInverseLerp(float lowThreshold, float hiThreshold, float value)
|
||||
{
|
||||
return saturate(InverseLerp(lowThreshold, hiThreshold, value));
|
||||
}
|
||||
|
||||
|
||||
void ParticleZones(float3 pos, inout float density)
|
||||
{
|
||||
for (int i = 0; i < _EnviroRemovalZonesCount; i++)
|
||||
{
|
||||
if(_EnviroRemovalZones[i].type == 0)
|
||||
{
|
||||
float3 dir = _EnviroRemovalZones[i].pos - pos;
|
||||
float3 axis = _EnviroRemovalZones[i].axis;
|
||||
float3 dirAlongAxis = dot(dir, axis) * axis;
|
||||
|
||||
dir = dir + dirAlongAxis * _EnviroRemovalZones[i].stretch;
|
||||
float distsq = dot(dir, dir);
|
||||
|
||||
float feather = 1.0;
|
||||
feather = (1.0 - smoothstep (_EnviroRemovalZones[i].radius * feather, _EnviroRemovalZones[i].radius, distsq));
|
||||
|
||||
float contribution = feather * _EnviroRemovalZones[i].density;
|
||||
density = clamp(density + contribution,0,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
float influence = 1;
|
||||
float3 position = mul(_EnviroRemovalZones[i].transform, float4(pos, 1)).xyz;
|
||||
|
||||
float x = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.x) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.x);
|
||||
float y = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.y) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.y);
|
||||
float z = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.z) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.z);
|
||||
|
||||
influence = x * y * z;
|
||||
|
||||
density += _EnviroRemovalZones[i].density * influence;
|
||||
density = clamp(density,0,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6dc5023c0e5ec3499e40a42405af18f
|
||||
timeCreated: 1452690568
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/ParticlesInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,70 @@
|
||||
|
||||
struct EnviroRemovalZones
|
||||
{
|
||||
float type;
|
||||
float3 pos;
|
||||
float radius;
|
||||
float3 size;
|
||||
float3 axis;
|
||||
float stretch;
|
||||
float density;
|
||||
float feather;
|
||||
float4x4 transform;
|
||||
float pad0;
|
||||
float pad1;
|
||||
};
|
||||
|
||||
|
||||
StructuredBuffer<EnviroRemovalZones> _EnviroRemovalZones : register(t1);
|
||||
float _EnviroRemovalZonesCount;
|
||||
|
||||
float3 InverseLerp(float lowThreshold, float hiThreshold, float3 value)
|
||||
{
|
||||
return (value - lowThreshold) / (hiThreshold - lowThreshold);
|
||||
}
|
||||
float ClampedInverseLerp(float lowThreshold, float hiThreshold, float value)
|
||||
{
|
||||
return saturate(InverseLerp(lowThreshold, hiThreshold, value));
|
||||
}
|
||||
|
||||
|
||||
void ParticleZones_float(float3 pos, float density, out float alpha)
|
||||
{
|
||||
alpha = 1;
|
||||
|
||||
for (int i = 0; i < _EnviroRemovalZonesCount; i++)
|
||||
{
|
||||
if(_EnviroRemovalZones[i].type == 0)
|
||||
{
|
||||
float3 dir = _EnviroRemovalZones[i].pos - pos;
|
||||
float3 axis = _EnviroRemovalZones[i].axis;
|
||||
float3 dirAlongAxis = dot(dir, axis) * axis;
|
||||
|
||||
dir = dir + dirAlongAxis * _EnviroRemovalZones[i].stretch;
|
||||
float distsq = dot(dir, dir);
|
||||
|
||||
float feather = 1.0;
|
||||
feather = (1.0 - smoothstep (_EnviroRemovalZones[i].radius * feather, _EnviroRemovalZones[i].radius, distsq));
|
||||
|
||||
float contribution = feather * _EnviroRemovalZones[i].density;
|
||||
density = clamp(density + contribution,0,1);
|
||||
alpha = density;
|
||||
}
|
||||
else
|
||||
{
|
||||
float influence = 1;
|
||||
float3 position = mul(_EnviroRemovalZones[i].transform, float4(pos, 1)).xyz;
|
||||
|
||||
float x = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.x) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.x);
|
||||
float y = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.y) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.y);
|
||||
float z = ClampedInverseLerp(-0.5f, -0.5f + _EnviroRemovalZones[i].feather, position.z) - ClampedInverseLerp(0.5f - _EnviroRemovalZones[i].feather, 0.5f, position.z);
|
||||
|
||||
influence = x * y * z;
|
||||
|
||||
density += _EnviroRemovalZones[i].density * influence;
|
||||
density = clamp(density,0,1);
|
||||
alpha = density;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecec9f641f2ccff4f805f886baa5f349
|
||||
timeCreated: 1452690568
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/ParticlesInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,362 @@
|
||||
uniform float4 _SunDir;
|
||||
uniform float4 _MoonDir;
|
||||
|
||||
uniform float4 _SunColor;
|
||||
|
||||
uniform half4 _FrontColor0;
|
||||
uniform half4 _FrontColor1;
|
||||
uniform half4 _FrontColor2;
|
||||
uniform half4 _FrontColor3;
|
||||
uniform half4 _FrontColor4;
|
||||
uniform half4 _FrontColor5;
|
||||
uniform half4 _FrontColor6;
|
||||
|
||||
uniform half4 _BackColor0;
|
||||
uniform half4 _BackColor1;
|
||||
uniform half4 _BackColor2;
|
||||
uniform half4 _BackColor3;
|
||||
uniform half4 _BackColor4;
|
||||
uniform half4 _BackColor5;
|
||||
uniform half4 _BackColor6;
|
||||
|
||||
uniform float4 _SkyColorTint;
|
||||
|
||||
uniform float _frontBackDistribution0;
|
||||
uniform float _frontBackDistribution1;
|
||||
uniform float _frontBackDistribution2;
|
||||
uniform float _frontBackDistribution3;
|
||||
uniform float _frontBackDistribution4;
|
||||
|
||||
uniform float _Intensity;
|
||||
uniform float _SkyColorExponent;
|
||||
uniform float _MieScatteringIntensity;
|
||||
|
||||
|
||||
float Mie(float costh, float g)
|
||||
{
|
||||
g = min(g, 0.9381);
|
||||
float k = 1.55 * g - 0.55 * g * g * g;
|
||||
|
||||
float kcosth = k * costh;
|
||||
|
||||
return (1 - k * k) / ((4 * 3.14159265f) * (1 - kcosth) * (1 - kcosth));
|
||||
}
|
||||
|
||||
float RemapEnviro(float org_val, float org_min, float org_max, float new_min, float new_max)
|
||||
{
|
||||
return new_min + saturate(((org_val - org_min) / (org_max - org_min))*(new_max - new_min));
|
||||
}
|
||||
|
||||
|
||||
//Cirrus Clouds
|
||||
uniform sampler2D _CirrusCloudMap;
|
||||
uniform float _CirrusCloudAlpha;
|
||||
uniform float _CirrusCloudCoverage;
|
||||
uniform float _CirrusCloudAltitude;
|
||||
uniform float4 _CirrusCloudColor;
|
||||
uniform float _CirrusCloudColorPower;
|
||||
uniform float2 _CirrusCloudAnimation;
|
||||
|
||||
float4 CirrusClouds(float3 uvs)
|
||||
{
|
||||
uvs = normalize(uvs);
|
||||
|
||||
float4 uv1;
|
||||
float4 uv2;
|
||||
|
||||
uv1.xy = (uvs.xz * 0.2) + _CirrusCloudAnimation;
|
||||
uv2.xy = (uvs.xz * 0.6) + _CirrusCloudAnimation;
|
||||
|
||||
float4 clouds1 = tex2D(_CirrusCloudMap, uv1.xy);
|
||||
float4 clouds2 = tex2D(_CirrusCloudMap, uv2.xy);
|
||||
|
||||
float color1 = pow(clouds1.g + clouds2.g, 0.1);
|
||||
float color2 = pow(clouds2.b * clouds1.r, 0.2);
|
||||
|
||||
float4 finalClouds = lerp(clouds1, clouds2, color1 * color2);
|
||||
float cloudExtinction = pow(uvs.y , 2);
|
||||
|
||||
finalClouds.a *= _CirrusCloudAlpha;
|
||||
finalClouds.a *= cloudExtinction;
|
||||
|
||||
if (uvs.y < 0)
|
||||
finalClouds.a = 0;
|
||||
|
||||
finalClouds.rgb = finalClouds.a * pow(_CirrusCloudColor.rgb,max(_CirrusCloudColorPower,0.0001));
|
||||
finalClouds.rgb = pow(finalClouds.rgb, saturate(1 - _CirrusCloudCoverage));
|
||||
|
||||
return finalClouds;
|
||||
}
|
||||
|
||||
half3 tonemapACES(half3 color, float Exposure)
|
||||
{
|
||||
color *= Exposure;
|
||||
|
||||
// See https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
|
||||
const half a = 2.51;
|
||||
const half b = 0.03;
|
||||
const half c = 2.43;
|
||||
const half d = 0.59;
|
||||
const half e = 0.14;
|
||||
return saturate((color * (a * color + b)) / (color * (c * color + d) + e));
|
||||
}
|
||||
|
||||
|
||||
//2D Clouds
|
||||
uniform sampler2D _FlatCloudsBaseTexture;
|
||||
uniform sampler2D _FlatCloudsDetailTexture;
|
||||
uniform float4 _FlatCloudsAnimation;
|
||||
uniform float3 _FlatCloudsLightDirection;
|
||||
uniform float3 _FlatCloudsLightColor;
|
||||
uniform float3 _FlatCloudsAmbientColor;
|
||||
uniform float4 _FlatCloudsLightingParams; // x = LightIntensity, y = AmbientIntensity, z = Absorbtion, w = HgPhase
|
||||
uniform float4 _FlatCloudsParams; // x = Coverage, y = Density, z = Altitude, w = shadowSteps
|
||||
uniform float4 _FlatCloudsTiling; // x = Base, y = Detail
|
||||
|
||||
float HenryGreenstein(float cosTheta, float g)
|
||||
{
|
||||
float k = 3.0 / (8.0 * 3.1415926f) * (1.0 - g * g) / (2.0 + g * g);
|
||||
return k * (1.0 + cosTheta * cosTheta) / pow(abs(1.0 + g * g - 2.0 * g * cosTheta), 1.5);
|
||||
}
|
||||
|
||||
|
||||
float CalculateCloudDensity(float2 posBase, float2 posDetail,float3 worldPos, float coverage)
|
||||
{
|
||||
float4 baseNoise = tex2D(_FlatCloudsBaseTexture, posBase);
|
||||
float low_freq_fBm = (baseNoise.g * 0.625) + (baseNoise.b * 0.25) + (baseNoise.a * 0.125);
|
||||
float base_cloud = RemapEnviro(baseNoise.r, -(1.0 - low_freq_fBm), 1.0, 0.0, 1.0) * coverage;
|
||||
|
||||
float4 detailNoise = tex2D(_FlatCloudsDetailTexture, posDetail * 2);
|
||||
float high_freq_fBm = (detailNoise.r * 0.625) + (detailNoise.g * 0.25) + (detailNoise.b * 0.125);
|
||||
float density = RemapEnviro(base_cloud, 1-high_freq_fBm * 0.5, 1.0, 0.0, 1.0);
|
||||
|
||||
density *= pow(high_freq_fBm, 0.4);
|
||||
density *= _FlatCloudsParams.y;
|
||||
|
||||
|
||||
return density;
|
||||
}
|
||||
|
||||
|
||||
float SampleShadowUV(float2 baseUV, float2 detailUV)
|
||||
{
|
||||
// Direction in UV space, scaled by some small factor
|
||||
// Direction in UV space
|
||||
float2 dirUV = normalize(_FlatCloudsLightDirection.xz);
|
||||
|
||||
// Total shadow length in UV space (constant)
|
||||
float totalShadowLength = 0.01;
|
||||
|
||||
// Per-step offset so total distance remains the same
|
||||
float2 stepUV = dirUV * (totalShadowLength / _FlatCloudsParams.w);
|
||||
|
||||
float shadow = 1.0;
|
||||
float stepFactor = _FlatCloudsLightingParams.z * 1 / _FlatCloudsParams.w;
|
||||
|
||||
for (int i = 1; i <= _FlatCloudsParams.w; i++)
|
||||
{
|
||||
float2 uvOffsetBase = baseUV - stepUV * i;
|
||||
float2 uvOffsetDetail = detailUV - stepUV * i * (_FlatCloudsTiling.y/_FlatCloudsTiling.x);
|
||||
|
||||
float d = CalculateCloudDensity(uvOffsetBase, uvOffsetDetail, float3(0,0,0), _FlatCloudsParams.x);
|
||||
shadow *= exp(-d * stepFactor);
|
||||
}
|
||||
|
||||
return saturate(shadow);
|
||||
}
|
||||
|
||||
float4 Clouds2D (float3 uvs, float3 worldPos)
|
||||
{
|
||||
half4 col = 0;
|
||||
uvs = normalize(uvs);
|
||||
|
||||
float4 uv1;
|
||||
uv1.xy = (uvs.xz * _FlatCloudsTiling.x) + _FlatCloudsAnimation.xy;
|
||||
uv1.zw = (uvs.xz * _FlatCloudsTiling.y) + _FlatCloudsAnimation.zw;
|
||||
|
||||
float cloudExtinction = pow(uvs.y, 2);
|
||||
float density = CalculateCloudDensity(uv1.xy, uv1.zw, uvs, _FlatCloudsParams.x);
|
||||
|
||||
// --- Shadows ---
|
||||
float shadowTerm = SampleShadowUV(uv1.xy, uv1.zw);
|
||||
//float absorbtion = exp2(-1 * (density * _FlatCloudsLightingParams.z));
|
||||
float shadows = shadowTerm;
|
||||
|
||||
float3 viewDir = normalize(worldPos - _WorldSpaceCameraPos);
|
||||
float inscatterAngle = dot(normalize(_FlatCloudsLightDirection), -viewDir);
|
||||
float hg = HenryGreenstein(inscatterAngle, _FlatCloudsLightingParams.w) * 2 * shadows;
|
||||
|
||||
// apply shadow to the direct light only
|
||||
float lighting = density * (shadows + hg) * shadowTerm;
|
||||
|
||||
float3 lightColor = pow(_FlatCloudsLightColor, 2) * _FlatCloudsLightingParams.x;
|
||||
col.rgb = lightColor * lighting;
|
||||
col.rgb += _FlatCloudsAmbientColor * _FlatCloudsLightingParams.y;
|
||||
|
||||
|
||||
col.a = saturate(density * cloudExtinction);
|
||||
|
||||
if (uvs.y < 0)
|
||||
col.a = 0;
|
||||
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
|
||||
float4 GetSkyColorSimple (float3 viewDir, float mieSize, float depth = 1.0)
|
||||
{
|
||||
float cosTheta = smoothstep(0.0,2.0,saturate(dot(-_SunDir.xyz, viewDir)));
|
||||
// float cosTheta = smoothstep(-0.25,1.15,saturate(dot(-_SunDir.xyz, viewDir)));
|
||||
half y = -viewDir.y / 0.02;
|
||||
|
||||
float3 frontBack1 = lerp(_FrontColor1.rgb,_BackColor1.rgb,cosTheta);
|
||||
float3 frontBack2 = lerp(_FrontColor2.rgb,_BackColor2.rgb,cosTheta);
|
||||
float3 frontBack5 = lerp(_FrontColor5.rgb,_BackColor5.rgb,cosTheta);
|
||||
|
||||
float heightS1 = RemapEnviro(viewDir.y,-0.75,_frontBackDistribution0,0,1);
|
||||
float heightS2 = RemapEnviro(viewDir.y,_frontBackDistribution0,_frontBackDistribution1,0,1);
|
||||
float heightS5 = RemapEnviro(viewDir.y,_frontBackDistribution1,1,0,1);
|
||||
|
||||
float3 sky1 = lerp(float3(0,0,0),frontBack1.rgb,heightS1);
|
||||
float3 sky2 = lerp(sky1.rgb,frontBack2.rgb,heightS2);
|
||||
float3 sky5 = lerp(sky2.rgb,frontBack5.rgb,heightS5);
|
||||
|
||||
float3 skyColor = sky5 * _Intensity;
|
||||
|
||||
float eyeCos = dot(_SunDir.xyz, viewDir);
|
||||
float eyeCos2 = eyeCos * eyeCos;
|
||||
float fade = saturate(dot(_SunDir.xyz, viewDir));
|
||||
|
||||
float mie = Mie(eyeCos, 0.7) * _MieScatteringIntensity * fade * depth;
|
||||
skyColor.rgb += (mie * skyColor) * _SunColor.rgb;
|
||||
|
||||
return float4(pow(skyColor * _SkyColorTint.rgb,_SkyColorExponent),1);
|
||||
}
|
||||
|
||||
float4 GetSkyColor (float3 viewDir, float mieSize,float depth = 1.0)
|
||||
{
|
||||
float cosTheta = smoothstep(0.0,2.0,saturate(dot(-_SunDir.xyz, viewDir)));
|
||||
half y = -viewDir.y / 0.02;
|
||||
|
||||
float3 frontBack0 = lerp(_FrontColor0.rgb,_BackColor0.rgb,cosTheta);
|
||||
float3 frontBack1 = lerp(_FrontColor1.rgb,_BackColor1.rgb,cosTheta);
|
||||
float3 frontBack2 = lerp(_FrontColor2.rgb,_BackColor2.rgb,cosTheta);
|
||||
float3 frontBack3 = lerp(_FrontColor3.rgb,_BackColor3.rgb,cosTheta);
|
||||
float3 frontBack4 = lerp(_FrontColor4.rgb,_BackColor4.rgb,cosTheta);
|
||||
float3 frontBack5 = lerp(_FrontColor5.rgb,_BackColor5.rgb,cosTheta);
|
||||
|
||||
float heightS1 = RemapEnviro(viewDir.y,-0.75,_frontBackDistribution0,0,1);
|
||||
float heightS2 = RemapEnviro(viewDir.y,_frontBackDistribution0,_frontBackDistribution1,0,1);
|
||||
float heightS3 = RemapEnviro(viewDir.y,_frontBackDistribution1,_frontBackDistribution2,0,1);
|
||||
float heightS4 = RemapEnviro(viewDir.y,_frontBackDistribution2,_frontBackDistribution3,0,1);
|
||||
float heightS5 = RemapEnviro(viewDir.y,_frontBackDistribution3,1,0,1);
|
||||
|
||||
float3 sky1 = lerp(frontBack0.rgb,frontBack1.rgb,heightS1);
|
||||
float3 sky2 = lerp(sky1.rgb,frontBack2.rgb,heightS2);
|
||||
float3 sky3 = lerp(sky2.rgb,frontBack3.rgb,heightS3);
|
||||
float3 sky4 = lerp(sky3.rgb,frontBack4.rgb,heightS4);
|
||||
float3 sky5 = lerp(sky4.rgb,frontBack5.rgb,heightS5);
|
||||
|
||||
float3 skyColor = sky5 * _Intensity;
|
||||
|
||||
float eyeCos = dot(_SunDir.xyz, viewDir);
|
||||
float eyeCos2 = eyeCos * eyeCos;
|
||||
float fade = saturate(dot(_SunDir.xyz, viewDir));
|
||||
|
||||
float mie = Mie(eyeCos, 0.7) * _MieScatteringIntensity * fade * depth;
|
||||
skyColor.rgb += (mie * skyColor) * _SunColor.rgb;
|
||||
|
||||
return float4(pow(skyColor * _SkyColorTint.rgb,_SkyColorExponent),1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
///Aurora
|
||||
sampler2D _Aurora_Layer_1;
|
||||
sampler2D _Aurora_Layer_2;
|
||||
sampler2D _Aurora_Colorshift;
|
||||
|
||||
float4 _AuroraColor;
|
||||
float _AuroraIntensity;
|
||||
float _AuroraBrightness;
|
||||
float _AuroraContrast;
|
||||
float _AuroraHeight;
|
||||
float _AuroraScale;
|
||||
float _AuroraSpeed;
|
||||
float _AuroraSteps;
|
||||
|
||||
float4 _Aurora_Tiling_Layer1;
|
||||
float4 _Aurora_Tiling_Layer2;
|
||||
float4 _Aurora_Tiling_ColorShift;
|
||||
|
||||
float randomNoise(float3 co)
|
||||
{
|
||||
return frac(sin(dot(co.xyz ,float3(17.2486,32.76149, 368.71564))) * 32168.47512);
|
||||
}
|
||||
|
||||
float4 SampleAurora(float3 uv)
|
||||
{
|
||||
|
||||
float2 uv_1 = uv.xy * _Aurora_Tiling_Layer1.xy + (_Aurora_Tiling_Layer1.zw * _AuroraSpeed * _Time.y);
|
||||
|
||||
float4 aurora = tex2Dlod(_Aurora_Layer_1, float4(uv_1.xy,0,0));
|
||||
|
||||
float2 uv_2 = uv_1 * _Aurora_Tiling_Layer2.xy + (_Aurora_Tiling_Layer2.zw * _AuroraSpeed * _Time.y);
|
||||
float4 aurora2 = tex2Dlod(_Aurora_Layer_2, float4(uv_2.xy,0,0));
|
||||
aurora += (aurora2 - 0.5) * 0.5;
|
||||
|
||||
aurora.w = aurora.w * 0.8 + 0.05;
|
||||
|
||||
float3 uv_3 = float3(uv.xy * _Aurora_Tiling_ColorShift.xy + (_Aurora_Tiling_ColorShift.zw * _AuroraSpeed * _Time.y), 0.0);
|
||||
float4 cloudColor = tex2Dlod(_Aurora_Colorshift, float4(uv_3.xy,0,0));
|
||||
|
||||
float contrastMask = 1.0 - saturate(aurora.a);
|
||||
contrastMask = pow(contrastMask, _AuroraContrast);
|
||||
aurora.rgb *= lerp(float3(0,0,0), _AuroraColor.rgb * cloudColor.rgb * _AuroraBrightness, contrastMask);
|
||||
|
||||
float cloudSub = 1.0 - uv.z;
|
||||
aurora.a = aurora.a - cloudSub * cloudSub;
|
||||
aurora.a = saturate(aurora.a * _AuroraIntensity);
|
||||
aurora.rgb *= aurora.a;
|
||||
|
||||
return aurora;
|
||||
}
|
||||
|
||||
float4 Aurora (float3 wpos)
|
||||
{
|
||||
if (_AuroraIntensity < 0.05)
|
||||
return float4(0,0,0,0);
|
||||
|
||||
float3 viewDir = normalize(wpos - _WorldSpaceCameraPos);
|
||||
|
||||
float viewFalloff = 1.0 - saturate(dot(viewDir, float3(0,1,0)));
|
||||
|
||||
if (viewDir.y < 0 || viewDir.y > 1)
|
||||
return half4(0, 0, 0, 0);
|
||||
|
||||
float3 traceDir = normalize(viewDir + float3(0, viewFalloff * 0.2 ,0));
|
||||
|
||||
float3 worldPos = _WorldSpaceCameraPos + traceDir * ((_AuroraHeight - _WorldSpaceCameraPos.y) / max(traceDir.y, 0.01));
|
||||
float3 uv = float3(worldPos.xz * 0.01 * _AuroraScale, 0);
|
||||
|
||||
half3 uvStep = half3(traceDir.xz * -1.0 * (1.0 / traceDir.y), 1.0) * (1.0 / _AuroraSteps);
|
||||
uv += uvStep * randomNoise(wpos + _SinTime.w);
|
||||
|
||||
half4 finalColor = half4(0,0,0,0);
|
||||
|
||||
[loop]
|
||||
for (int iCount = 0; iCount < _AuroraSteps; iCount++)
|
||||
{
|
||||
if (finalColor.a > 1)
|
||||
break;
|
||||
|
||||
uv += uvStep;
|
||||
finalColor += SampleAurora(uv) * (1.0 - finalColor.a);
|
||||
}
|
||||
|
||||
finalColor *= viewDir.y;
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9881aff4c014a874fadfa837748f2ae9
|
||||
timeCreated: 1452690568
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/SkyInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,346 @@
|
||||
uniform float4 _SunDir;
|
||||
uniform float4 _MoonDir;
|
||||
|
||||
uniform float4 _SunColor;
|
||||
|
||||
uniform half4 _FrontColor0;
|
||||
uniform half4 _FrontColor1;
|
||||
uniform half4 _FrontColor2;
|
||||
uniform half4 _FrontColor3;
|
||||
uniform half4 _FrontColor4;
|
||||
uniform half4 _FrontColor5;
|
||||
uniform half4 _FrontColor6;
|
||||
|
||||
uniform half4 _BackColor0;
|
||||
uniform half4 _BackColor1;
|
||||
uniform half4 _BackColor2;
|
||||
uniform half4 _BackColor3;
|
||||
uniform half4 _BackColor4;
|
||||
uniform half4 _BackColor5;
|
||||
uniform half4 _BackColor6;
|
||||
|
||||
uniform float4 _SkyColorTint;
|
||||
|
||||
uniform float _frontBackDistribution0;
|
||||
uniform float _frontBackDistribution1;
|
||||
uniform float _frontBackDistribution2;
|
||||
uniform float _frontBackDistribution3;
|
||||
uniform float _frontBackDistribution4;
|
||||
|
||||
uniform float _Intensity;
|
||||
uniform float _SkyColorExponent;
|
||||
uniform float _MieScatteringIntensity;
|
||||
|
||||
|
||||
float Mie(float costh, float g)
|
||||
{
|
||||
g = min(g, 0.9381);
|
||||
float k = 1.55 * g - 0.55 * g * g * g;
|
||||
|
||||
float kcosth = k * costh;
|
||||
|
||||
return (1 - k * k) / ((4 * 3.14159265f) * (1 - kcosth) * (1 - kcosth));
|
||||
}
|
||||
|
||||
float RemapEnviro(float org_val, float org_min, float org_max, float new_min, float new_max)
|
||||
{
|
||||
return new_min + saturate(((org_val - org_min) / (org_max - org_min))*(new_max - new_min));
|
||||
}
|
||||
|
||||
|
||||
//Cirrus Clouds
|
||||
uniform sampler2D _CirrusCloudMap;
|
||||
uniform float _CirrusCloudAlpha;
|
||||
uniform float _CirrusCloudCoverage;
|
||||
uniform float _CirrusCloudAltitude;
|
||||
uniform float4 _CirrusCloudColor;
|
||||
uniform float _CirrusCloudColorPower;
|
||||
uniform float2 _CirrusCloudAnimation;
|
||||
|
||||
float4 CirrusClouds(float3 uvs)
|
||||
{
|
||||
uvs = normalize(uvs);
|
||||
|
||||
float4 uv1;
|
||||
float4 uv2;
|
||||
|
||||
uv1.xy = (uvs.xz * 0.2) + _CirrusCloudAnimation;
|
||||
uv2.xy = (uvs.xz * 0.6) + _CirrusCloudAnimation;
|
||||
|
||||
float4 clouds1 = tex2D(_CirrusCloudMap, uv1.xy);
|
||||
float4 clouds2 = tex2D(_CirrusCloudMap, uv2.xy);
|
||||
|
||||
float color1 = pow(clouds1.g + clouds2.g, 0.1);
|
||||
float color2 = pow(clouds2.b * clouds1.r, 0.2);
|
||||
|
||||
float4 finalClouds = lerp(clouds1, clouds2, color1 * color2);
|
||||
float cloudExtinction = pow(uvs.y , 2);
|
||||
|
||||
finalClouds.a *= _CirrusCloudAlpha;
|
||||
finalClouds.a *= cloudExtinction;
|
||||
|
||||
if (uvs.y < 0)
|
||||
finalClouds.a = 0;
|
||||
|
||||
finalClouds.rgb = finalClouds.a * pow(_CirrusCloudColor.rgb,max(_CirrusCloudColorPower,0.0001));
|
||||
finalClouds.rgb = pow(finalClouds.rgb,1 - _CirrusCloudCoverage);
|
||||
|
||||
return finalClouds;
|
||||
}
|
||||
|
||||
|
||||
//2D Clouds
|
||||
uniform sampler2D _FlatCloudsBaseTexture;
|
||||
uniform sampler2D _FlatCloudsDetailTexture;
|
||||
uniform float4 _FlatCloudsAnimation;
|
||||
uniform float3 _FlatCloudsLightDirection;
|
||||
uniform float3 _FlatCloudsLightColor;
|
||||
uniform float3 _FlatCloudsAmbientColor;
|
||||
uniform float4 _FlatCloudsLightingParams; // x = LightIntensity, y = AmbientIntensity, z = Absorbtion, w = HgPhase
|
||||
uniform float4 _FlatCloudsParams; // x = Coverage, y = Density, z = Altitude, w = shadowSteps
|
||||
uniform float4 _FlatCloudsTiling; // x = Base, y = Detail
|
||||
|
||||
|
||||
float HenryGreenstein(float cosTheta, float g)
|
||||
{
|
||||
float k = 3.0 / (8.0 * 3.1415926f) * (1.0 - g * g) / (2.0 + g * g);
|
||||
return k * (1.0 + cosTheta * cosTheta) / pow(abs(1.0 + g * g - 2.0 * g * cosTheta), 1.5);
|
||||
}
|
||||
|
||||
|
||||
float CalculateCloudDensity(float2 posBase, float2 posDetail,float3 worldPos, float coverage)
|
||||
{
|
||||
float4 baseNoise = tex2D(_FlatCloudsBaseTexture, posBase);
|
||||
float low_freq_fBm = (baseNoise.g * 0.625) + (baseNoise.b * 0.25) + (baseNoise.a * 0.125);
|
||||
float base_cloud = RemapEnviro(baseNoise.r, -(1.0 - low_freq_fBm), 1.0, 0.0, 1.0) * coverage;
|
||||
|
||||
float4 detailNoise = tex2D(_FlatCloudsDetailTexture, posDetail * 2);
|
||||
float high_freq_fBm = (detailNoise.r * 0.625) + (detailNoise.g * 0.25) + (detailNoise.b * 0.125);
|
||||
float density = RemapEnviro(base_cloud, 1-high_freq_fBm * 0.5, 1.0, 0.0, 1.0);
|
||||
|
||||
density *= pow(high_freq_fBm, 0.4);
|
||||
density *= _FlatCloudsParams.y;
|
||||
|
||||
|
||||
return density;
|
||||
}
|
||||
float SampleShadowUV(float2 baseUV, float2 detailUV)
|
||||
{
|
||||
// Direction in UV space, scaled by some small factor
|
||||
// Direction in UV space
|
||||
float2 dirUV = normalize(_FlatCloudsLightDirection.xz);
|
||||
|
||||
// Total shadow length in UV space (constant)
|
||||
float totalShadowLength = 0.01;
|
||||
|
||||
// Per-step offset so total distance remains the same
|
||||
float2 stepUV = dirUV * (totalShadowLength / _FlatCloudsParams.w);
|
||||
|
||||
float shadow = 1.0;
|
||||
float stepFactor = _FlatCloudsLightingParams.z * 1 / _FlatCloudsParams.w;
|
||||
|
||||
for (int i = 1; i <= _FlatCloudsParams.w; i++)
|
||||
{
|
||||
float2 uvOffsetBase = baseUV - stepUV * i;
|
||||
float2 uvOffsetDetail = detailUV - stepUV * i * (_FlatCloudsTiling.y/_FlatCloudsTiling.x);
|
||||
|
||||
float d = CalculateCloudDensity(uvOffsetBase, uvOffsetDetail, float3(0,0,0), _FlatCloudsParams.x);
|
||||
shadow *= exp(-d * stepFactor);
|
||||
}
|
||||
|
||||
return saturate(shadow);
|
||||
}
|
||||
|
||||
float4 Clouds2D (float3 uvs, float3 worldPos)
|
||||
{
|
||||
half4 col = 0;
|
||||
uvs = normalize(uvs);
|
||||
|
||||
float4 uv1;
|
||||
uv1.xy = (uvs.xz * _FlatCloudsTiling.x) + _FlatCloudsAnimation.xy;
|
||||
uv1.zw = (uvs.xz * _FlatCloudsTiling.y) + _FlatCloudsAnimation.zw;
|
||||
|
||||
float cloudExtinction = pow(uvs.y, 2);
|
||||
float density = CalculateCloudDensity(uv1.xy, uv1.zw, uvs, _FlatCloudsParams.x);
|
||||
|
||||
// --- Shadows ---
|
||||
float shadowTerm = SampleShadowUV(uv1.xy, uv1.zw);
|
||||
//float absorbtion = exp2(-1 * (density * _FlatCloudsLightingParams.z));
|
||||
float shadows = shadowTerm;
|
||||
|
||||
float3 viewDir = normalize(worldPos - _WorldSpaceCameraPos);
|
||||
float inscatterAngle = dot(normalize(_FlatCloudsLightDirection), -viewDir);
|
||||
float hg = HenryGreenstein(inscatterAngle, _FlatCloudsLightingParams.w) * 2 * shadows;
|
||||
|
||||
// apply shadow to the direct light only
|
||||
float lighting = density * (shadows + hg) * shadowTerm;
|
||||
|
||||
float3 lightColor = pow(_FlatCloudsLightColor, 2) * _FlatCloudsLightingParams.x;
|
||||
col.rgb = lightColor * lighting;
|
||||
col.rgb += _FlatCloudsAmbientColor * _FlatCloudsLightingParams.y;
|
||||
|
||||
|
||||
col.a = saturate(density * cloudExtinction);
|
||||
|
||||
if (uvs.y < 0)
|
||||
col.a = 0;
|
||||
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
float4 GetSkyColorSimple (float3 viewDir, float mieSize, float depth = 1.0)
|
||||
{
|
||||
float cosTheta = smoothstep(-0.25,1.15,saturate(dot(-_SunDir.xyz, viewDir)));
|
||||
half y = -viewDir.y / 0.02;
|
||||
|
||||
float3 frontBack1 = lerp(_FrontColor1.rgb,_BackColor1.rgb,cosTheta);
|
||||
float3 frontBack2 = lerp(_FrontColor2.rgb,_BackColor2.rgb,cosTheta);
|
||||
float3 frontBack5 = lerp(_FrontColor5.rgb,_BackColor5.rgb,cosTheta);
|
||||
|
||||
float heightS1 = RemapEnviro(viewDir.y,-0.75,_frontBackDistribution0,0,1);
|
||||
float heightS2 = RemapEnviro(viewDir.y,_frontBackDistribution0,_frontBackDistribution1,0,1);
|
||||
float heightS5 = RemapEnviro(viewDir.y,_frontBackDistribution1,1,0,1);
|
||||
|
||||
float3 sky1 = lerp(float3(0,0,0),frontBack1.rgb,heightS1);
|
||||
float3 sky2 = lerp(sky1.rgb,frontBack2.rgb,heightS2);
|
||||
float3 sky5 = lerp(sky2.rgb,frontBack5.rgb,heightS5);
|
||||
|
||||
float3 skyColor = sky5 * _Intensity;
|
||||
|
||||
float eyeCos = dot(_SunDir.xyz, viewDir);
|
||||
float eyeCos2 = eyeCos * eyeCos;
|
||||
float fade = saturate(dot(_SunDir.xyz, viewDir));
|
||||
|
||||
float mie = Mie(eyeCos, 0.7) * _MieScatteringIntensity * fade * depth;
|
||||
skyColor.rgb += (mie * skyColor) * _SunColor.rgb;
|
||||
|
||||
return float4(skyColor * _SkyColorTint.rgb,1);
|
||||
}
|
||||
|
||||
float4 GetSkyColor (float3 viewDir, float mieSize, float depth = 1.0)
|
||||
{
|
||||
float cosTheta = smoothstep(-0.25,1.15,saturate(dot(-_SunDir.xyz, viewDir)));
|
||||
half y = -viewDir.y / 0.02;
|
||||
|
||||
float3 frontBack0 = lerp(_FrontColor0.rgb,_BackColor0.rgb,cosTheta);
|
||||
float3 frontBack1 = lerp(_FrontColor1.rgb,_BackColor1.rgb,cosTheta);
|
||||
float3 frontBack2 = lerp(_FrontColor2.rgb,_BackColor2.rgb,cosTheta);
|
||||
float3 frontBack3 = lerp(_FrontColor3.rgb,_BackColor3.rgb,cosTheta);
|
||||
float3 frontBack4 = lerp(_FrontColor4.rgb,_BackColor4.rgb,cosTheta);
|
||||
float3 frontBack5 = lerp(_FrontColor5.rgb,_BackColor5.rgb,cosTheta);
|
||||
|
||||
float heightS1 = RemapEnviro(viewDir.y,-0.75,_frontBackDistribution0,0,1);
|
||||
float heightS2 = RemapEnviro(viewDir.y,_frontBackDistribution0,_frontBackDistribution1,0,1);
|
||||
float heightS3 = RemapEnviro(viewDir.y,_frontBackDistribution1,_frontBackDistribution2,0,1);
|
||||
float heightS4 = RemapEnviro(viewDir.y,_frontBackDistribution2,_frontBackDistribution3,0,1);
|
||||
float heightS5 = RemapEnviro(viewDir.y,_frontBackDistribution3,1,0,1);
|
||||
|
||||
float3 sky1 = lerp(frontBack0.rgb,frontBack1.rgb,heightS1);
|
||||
float3 sky2 = lerp(sky1.rgb,frontBack2.rgb,heightS2);
|
||||
float3 sky3 = lerp(sky2.rgb,frontBack3.rgb,heightS3);
|
||||
float3 sky4 = lerp(sky3.rgb,frontBack4.rgb,heightS4);
|
||||
float3 sky5 = lerp(sky4.rgb,frontBack5.rgb,heightS5);
|
||||
|
||||
float3 skyColor = sky5 * _Intensity;
|
||||
|
||||
float eyeCos = dot(_SunDir.xyz, viewDir);
|
||||
float eyeCos2 = eyeCos * eyeCos;
|
||||
float fade = saturate(dot(_SunDir.xyz, viewDir));
|
||||
|
||||
float mie = Mie(eyeCos, 0.7) * _MieScatteringIntensity * fade * depth;
|
||||
|
||||
skyColor.rgb += (mie * skyColor) * _SunColor.rgb;
|
||||
|
||||
return float4(skyColor * _SkyColorTint.rgb,1);
|
||||
}
|
||||
|
||||
|
||||
///Aurora
|
||||
sampler2D _Aurora_Layer_1;
|
||||
sampler2D _Aurora_Layer_2;
|
||||
sampler2D _Aurora_Colorshift;
|
||||
|
||||
float4 _AuroraColor;
|
||||
float _AuroraIntensity;
|
||||
float _AuroraBrightness;
|
||||
float _AuroraContrast;
|
||||
float _AuroraHeight;
|
||||
float _AuroraScale;
|
||||
float _AuroraSpeed;
|
||||
float _AuroraSteps;
|
||||
|
||||
float4 _Aurora_Tiling_Layer1;
|
||||
float4 _Aurora_Tiling_Layer2;
|
||||
float4 _Aurora_Tiling_ColorShift;
|
||||
|
||||
float randomNoise(float3 co)
|
||||
{
|
||||
return frac(sin(dot(co.xyz ,float3(17.2486,32.76149, 368.71564))) * 32168.47512);
|
||||
}
|
||||
|
||||
float4 SampleAurora(float3 uv)
|
||||
{
|
||||
|
||||
float2 uv_1 = uv.xy * _Aurora_Tiling_Layer1.xy + (_Aurora_Tiling_Layer1.zw * _AuroraSpeed * _Time.y);
|
||||
|
||||
float4 aurora = tex2Dlod(_Aurora_Layer_1, float4(uv_1.xy,0,0));
|
||||
|
||||
float2 uv_2 = uv_1 * _Aurora_Tiling_Layer2.xy + (_Aurora_Tiling_Layer2.zw * _AuroraSpeed * _Time.y);
|
||||
float4 aurora2 = tex2Dlod(_Aurora_Layer_2, float4(uv_2.xy,0,0));
|
||||
aurora += (aurora2 - 0.5) * 0.5;
|
||||
|
||||
aurora.w = aurora.w * 0.8 + 0.05;
|
||||
|
||||
float3 uv_3 = float3(uv.xy * _Aurora_Tiling_ColorShift.xy + (_Aurora_Tiling_ColorShift.zw * _AuroraSpeed * _Time.y), 0.0);
|
||||
float4 cloudColor = tex2Dlod(_Aurora_Colorshift, float4(uv_3.xy,0,0));
|
||||
|
||||
float contrastMask = 1.0 - saturate(aurora.a);
|
||||
contrastMask = pow(contrastMask, _AuroraContrast);
|
||||
aurora.rgb *= lerp(float3(0,0,0), _AuroraColor.rgb * cloudColor.rgb * _AuroraBrightness, contrastMask);
|
||||
|
||||
float cloudSub = 1.0 - uv.z;
|
||||
aurora.a = aurora.a - cloudSub * cloudSub;
|
||||
aurora.a = saturate(aurora.a * _AuroraIntensity);
|
||||
aurora.rgb *= aurora.a;
|
||||
|
||||
return aurora;
|
||||
}
|
||||
|
||||
float4 Aurora (float3 wpos)
|
||||
{
|
||||
if (_AuroraIntensity < 0.05)
|
||||
return float4(0,0,0,0);
|
||||
|
||||
float3 viewDir = normalize(wpos);
|
||||
|
||||
float viewFalloff = 1.0 - saturate(dot(viewDir, float3(0,1,0)));
|
||||
|
||||
if (viewDir.y < 0 || viewDir.y > 1)
|
||||
return half4(0, 0, 0, 0);
|
||||
|
||||
float3 traceDir = normalize(viewDir + float3(0, viewFalloff * 0.2 ,0));
|
||||
|
||||
float3 worldPos = _WorldSpaceCameraPos + traceDir * ((_AuroraHeight - _WorldSpaceCameraPos.y) / max(traceDir.y, 0.01));
|
||||
float3 uv = float3(worldPos.xz * 0.01 * _AuroraScale, 0);
|
||||
|
||||
half3 uvStep = half3(traceDir.xz * -1.0 * (1.0 / traceDir.y), 1.0) * (1.0 / _AuroraSteps);
|
||||
uv += uvStep * randomNoise(wpos + _SinTime.w);
|
||||
|
||||
half4 finalColor = half4(0,0,0,0);
|
||||
|
||||
[loop]
|
||||
for (int iCount = 0; iCount < _AuroraSteps; iCount++)
|
||||
{
|
||||
if (finalColor.a > 1)
|
||||
break;
|
||||
|
||||
uv += uvStep;
|
||||
finalColor += SampleAurora(uv) * (1.0 - finalColor.a);
|
||||
}
|
||||
|
||||
finalColor *= viewDir.y;
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e19f793cfb7e04a4c86d39861dc19630
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/SkyIncludeHLSL.hlsl
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,85 @@
|
||||
#pragma multi_compile __ ENVIRO_SIMPLESKY
|
||||
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
UNITY_DECLARE_TEX2DARRAY(_EnviroClouds);
|
||||
#else
|
||||
sampler2D _EnviroClouds;
|
||||
#endif
|
||||
|
||||
float3 _AmbientColor;
|
||||
float3 _DirectLightColor;
|
||||
float _AtmosphereColorSaturateDistance;
|
||||
float4 _CloudsParameter;
|
||||
float _SolarTime;
|
||||
//float _AmbientDistanceScale;
|
||||
|
||||
float ComputeAmbient(float4 cloudsColor, float normalizedHeight)
|
||||
{
|
||||
float _AmbientDistanceScale = 0.25;
|
||||
// Height influence: higher clouds receive more ambient sky light
|
||||
// 0.7 base → 1.3 peak (keep within a modest range for realism)
|
||||
float heightFactor = lerp(0.7, 1.3, normalizedHeight);
|
||||
|
||||
// Distance influence: nearby clouds look brighter, far clouds fade
|
||||
// _AmbientDistanceScale lets you control falloff distance
|
||||
float distFalloff = exp(-cloudsColor.g * _AmbientDistanceScale);
|
||||
|
||||
// Combine
|
||||
float ambient = cloudsColor.a * heightFactor * distFalloff;
|
||||
return saturate(ambient);
|
||||
}
|
||||
|
||||
|
||||
float4 GetCloudColor(float4 cloudsColor, float3 worldPos)
|
||||
{
|
||||
float3 viewDir = normalize(worldPos.xyz - _WorldSpaceCameraPos.xyz);
|
||||
|
||||
float3 sunColor = pow(_DirectLightColor.rgb,2) * 2;
|
||||
float3 skyColor = float3(1,1,1);
|
||||
|
||||
#if ENVIRO_SIMPLESKY
|
||||
skyColor = GetSkyColorSimple(viewDir, 0.005f);
|
||||
#else
|
||||
skyColor = GetSkyColor(viewDir, 0.005f);
|
||||
#endif
|
||||
|
||||
float3 cloudsPos = _WorldSpaceCameraPos + viewDir * cloudsColor.g;
|
||||
float normalizedHeight = saturate((cloudsPos.y - _CloudsParameter.x) / (_CloudsParameter.y - _CloudsParameter.x));
|
||||
float ambient = ComputeAmbient(cloudsColor.a, normalizedHeight);
|
||||
float4 finalColor = float4(cloudsColor.r * sunColor + _AmbientColor * ambient, cloudsColor.a);
|
||||
|
||||
float p = smoothstep(0.55, 0.60, _SolarTime);
|
||||
float dayNightModifier = lerp(1.5, 0.1, p);
|
||||
|
||||
float baseDist = _AtmosphereColorSaturateDistance;
|
||||
|
||||
float kShadowRatio = dayNightModifier;
|
||||
static const float kMidRatio = 1.0;
|
||||
static const float kHighlightRatio = 2.0;
|
||||
|
||||
float3 brightness = saturate(finalColor.rgb);
|
||||
float luminance = dot(brightness, float3(0.299,0.587,0.114));
|
||||
|
||||
// Blend distance mapping with dynamic base
|
||||
float distLow = lerp(baseDist * kShadowRatio, baseDist * kMidRatio,saturate(luminance * 2.0));
|
||||
float blendDist = lerp(distLow, baseDist * kHighlightRatio,saturate((luminance - 0.5) * 2.0));
|
||||
// Final factor
|
||||
// float atmosphericBlendFactor = saturate(exp(-cloudsColor.g / _AtmosphereColorSaturateDistance));
|
||||
float atmosphericBlendFactor = saturate(exp(-cloudsColor.g / blendDist));
|
||||
finalColor.rgb = lerp(skyColor, finalColor.rgb, atmosphericBlendFactor);
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float3 ApplyClouds(float3 sceneColor, float2 uv, float3 worldPos)
|
||||
{
|
||||
float4 cloudsColor = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_EnviroClouds, uv);
|
||||
float4 finalColor = GetCloudColor(cloudsColor,worldPos);
|
||||
//return sceneColor.rgb * saturate(1 - finalColor.a) + finalColor.rgb * finalColor.a;
|
||||
|
||||
float a = saturate(finalColor.a);
|
||||
float3 c = lerp(sceneColor.rgb, finalColor.rgb, a);
|
||||
return sceneColor.rgb * (1 - a) + c * a;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbb571eced02b1941aa10421b8e7e2a8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/VolumetricCloudsBlendInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,80 @@
|
||||
#ifndef ENVIRO_SIMPLESKY_KEYWORD
|
||||
#define ENVIRO_SIMPLESKY_KEYWORD
|
||||
#pragma multi_compile __ ENVIRO_SIMPLESKY
|
||||
#endif
|
||||
|
||||
TEXTURE2D_X(_EnviroClouds);
|
||||
SAMPLER(sampler_EnviroClouds);
|
||||
|
||||
float3 _AmbientColor;
|
||||
float3 _DirectLightColor;
|
||||
float _AtmosphereColorSaturateDistance;
|
||||
float4 _CloudsParameter;
|
||||
float _SolarTime;
|
||||
|
||||
float ComputeAmbient(float4 cloudsColor, float normalizedHeight)
|
||||
{
|
||||
float _AmbientDistanceScale = 0.25;
|
||||
// Height influence: higher clouds receive more ambient sky light
|
||||
// 0.7 base → 1.3 peak (keep within a modest range for realism)
|
||||
float heightFactor = lerp(0.7, 1.3, normalizedHeight);
|
||||
|
||||
// Distance influence: nearby clouds look brighter, far clouds fade
|
||||
// _AmbientDistanceScale lets you control falloff distance
|
||||
float distFalloff = exp(-cloudsColor.g * _AmbientDistanceScale);
|
||||
|
||||
// Combine
|
||||
float ambient = cloudsColor.a * heightFactor * distFalloff;
|
||||
return saturate(ambient);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float4 GetCloudColor(float4 cloudsColor, float3 worldPos)
|
||||
{
|
||||
float3 viewDir = normalize(worldPos.xyz - _WorldSpaceCameraPos.xyz);
|
||||
|
||||
float3 sunColor = pow(_DirectLightColor.rgb,2) * 2;
|
||||
float3 skyColor = float3(1,1,1);
|
||||
|
||||
#if ENVIRO_SIMPLESKY
|
||||
skyColor = GetSkyColorSimple(viewDir, 0.005f);
|
||||
#else
|
||||
skyColor = GetSkyColor(viewDir, 0.005f);
|
||||
#endif
|
||||
|
||||
float3 cloudsPos = _WorldSpaceCameraPos + viewDir * cloudsColor.g;
|
||||
float normalizedHeight = saturate((cloudsPos.y - _CloudsParameter.x) / (_CloudsParameter.y - _CloudsParameter.x));
|
||||
float ambient = ComputeAmbient(cloudsColor.a, normalizedHeight);
|
||||
float4 finalColor = float4(cloudsColor.r * sunColor + _AmbientColor * ambient, cloudsColor.a);
|
||||
|
||||
float p = smoothstep(0.55, 0.60, _SolarTime);
|
||||
float dayNightModifier = lerp(1.5, 0.1, p);
|
||||
|
||||
float baseDist = _AtmosphereColorSaturateDistance;
|
||||
|
||||
float kShadowRatio = dayNightModifier;
|
||||
static const float kMidRatio = 1.0;
|
||||
static const float kHighlightRatio = 2.0;
|
||||
|
||||
float3 brightness = saturate(finalColor.rgb);
|
||||
float luminance = dot(brightness, float3(0.299,0.587,0.114));
|
||||
|
||||
// Blend distance mapping with dynamic base
|
||||
float distLow = lerp(baseDist * kShadowRatio, baseDist * kMidRatio,saturate(luminance * 2.0));
|
||||
float blendDist = lerp(distLow, baseDist * kHighlightRatio,saturate((luminance - 0.5) * 2.0));
|
||||
// Final factor
|
||||
float atmosphericBlendFactor = saturate(exp(-cloudsColor.g / blendDist));
|
||||
finalColor.rgb = lerp(skyColor, finalColor.rgb, atmosphericBlendFactor);
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float3 ApplyClouds(float3 sceneColor, float2 uv, float3 worldPos)
|
||||
{
|
||||
float4 cloudsColor = SAMPLE_TEXTURE2D_X(_EnviroClouds,sampler_EnviroClouds, uv);
|
||||
float4 finalColor = GetCloudColor(cloudsColor,worldPos);
|
||||
return sceneColor.rgb * saturate(1 - finalColor.a) + finalColor.rgb * finalColor.a;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 624bc9c7f1dfe0c4fb9653a27c24a913
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/VolumetricCloudsBlendIncludeHLSL.hlsl
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,883 @@
|
||||
#ifndef PI
|
||||
#define PI 3.14159265
|
||||
#endif
|
||||
|
||||
#ifndef TWO_PI
|
||||
#define TWO_PI 6.28318530
|
||||
#endif
|
||||
|
||||
#ifndef INV_PI
|
||||
#define INV_PI 0.31830989
|
||||
#endif
|
||||
|
||||
uniform Texture3D _Noise;
|
||||
SamplerState sampler_Noise;
|
||||
uniform Texture3D _DetailNoise;
|
||||
SamplerState sampler_DetailNoise;
|
||||
uniform Texture2D _WeatherMap;
|
||||
SamplerState sampler_WeatherMap;
|
||||
uniform Texture2D _CurlNoise;
|
||||
SamplerState sampler_CurlNoise;
|
||||
|
||||
uniform sampler2D _BottomsOffsetNoise;
|
||||
uniform sampler2D _BlueNoise;
|
||||
|
||||
float4 _BlueNoise_TexelSize;
|
||||
float3 _WorldOffset;
|
||||
|
||||
uniform float4x4 _InverseProjection;
|
||||
uniform float4x4 _InverseRotation;
|
||||
uniform float4x4 _InverseProjectionRight;
|
||||
uniform float4x4 _InverseRotationRight;
|
||||
|
||||
float4x4 _LeftWorldFromView;
|
||||
float4x4 _RightWorldFromView;
|
||||
float4x4 _LeftViewFromScreen;
|
||||
float4x4 _RightViewFromScreen;
|
||||
|
||||
uniform float4 _CloudsParameter;
|
||||
uniform float4 _CloudsParameter2;
|
||||
|
||||
uniform float4 _Steps;
|
||||
uniform float4 _CloudsLighting;
|
||||
uniform float4 _CloudsLighting2;
|
||||
uniform float4 _CloudsLightingExtended;
|
||||
uniform float4 _CloudsLightingExtended2;
|
||||
|
||||
uniform float4 _CloudsMultiScattering;
|
||||
uniform float4 _CloudsMultiScattering2;
|
||||
|
||||
uniform float4 _CloudsErosionIntensity; //x = Base, y = Detail
|
||||
uniform float4 _CloudsNoiseSettings; //x = Base, y = Detail
|
||||
|
||||
uniform float4 _CloudsShape1;
|
||||
uniform float4 _CloudsShape2;
|
||||
|
||||
uniform float4 _CloudDensityScale;
|
||||
uniform float4 _CloudsCoverageSettings; //x = _GlobalCoverage, y = Bottom Coverage Mod, z = Top coverage mod, w = Clouds Up Morph Intensity
|
||||
uniform float _GlobalCoverage;
|
||||
uniform float4 _CloudsAnimation;
|
||||
uniform float4 _CloudsWindDirection;
|
||||
|
||||
uniform float3 _LightDir;
|
||||
uniform float _stepsInDepth;
|
||||
uniform float _LODDistance;
|
||||
uniform float3 _CameraPosition;
|
||||
uniform float4 _Resolution;
|
||||
uniform float4 _Randomness;
|
||||
uniform float _EnviroDepthTest;
|
||||
uniform float _SolarTime;
|
||||
////
|
||||
const float env_inf = 1e10;
|
||||
|
||||
struct RaymarchParameters
|
||||
{
|
||||
//Lighting
|
||||
float scatteringCoef;
|
||||
float silverLiningIntensity;
|
||||
float silverLiningSpread;
|
||||
float edgeHighlightStrength;
|
||||
float directIndirectBalance;
|
||||
float exposure;
|
||||
float attenuation;
|
||||
float lightStep;
|
||||
float lightAbsorb;
|
||||
float multiScatterStrength;
|
||||
float multiScatterFalloff;
|
||||
float ambientFloor;
|
||||
|
||||
//Height
|
||||
float4 cloudsParameter;
|
||||
|
||||
//Density
|
||||
float density;
|
||||
float densitySmoothness;
|
||||
|
||||
//Erosion
|
||||
float baseErosion;
|
||||
float detailErosion;
|
||||
|
||||
int minSteps, maxSteps;
|
||||
|
||||
float baseNoiseUV;
|
||||
float detailNoiseUV;
|
||||
|
||||
float baseErosionIntensity;
|
||||
float detailErosionIntensity;
|
||||
|
||||
float baseNoiseMultiplier;
|
||||
float detailNoiseMultiplier;
|
||||
|
||||
float bottomShape;
|
||||
float midShape;
|
||||
float topShape;
|
||||
float topLayer;
|
||||
float rampShape;
|
||||
float cloudTypeShaping;
|
||||
};
|
||||
|
||||
void InitRaymarchParameters(inout RaymarchParameters parameters)
|
||||
{
|
||||
parameters.scatteringCoef = _CloudsLighting.x;
|
||||
parameters.silverLiningIntensity = _CloudsLighting.y;
|
||||
parameters.silverLiningSpread = _CloudsLighting.w;
|
||||
|
||||
parameters.multiScatterStrength = _CloudsMultiScattering.x;
|
||||
parameters.multiScatterFalloff = _CloudsMultiScattering.y;
|
||||
parameters.ambientFloor = _CloudsMultiScattering.z;
|
||||
parameters.exposure = _CloudsMultiScattering.w;
|
||||
|
||||
parameters.directIndirectBalance = _CloudsLightingExtended.x;
|
||||
parameters.attenuation = _CloudsLightingExtended.y;
|
||||
parameters.lightStep = _CloudsLightingExtended.z;
|
||||
parameters.lightAbsorb = _CloudsLightingExtended.w;
|
||||
|
||||
parameters.edgeHighlightStrength = _CloudsLighting.z;
|
||||
|
||||
parameters.cloudsParameter = _CloudsParameter;
|
||||
|
||||
parameters.density = _CloudDensityScale.x;
|
||||
parameters.densitySmoothness = _CloudDensityScale.z;
|
||||
|
||||
parameters.baseErosion = _CloudsErosionIntensity.x;
|
||||
parameters.detailErosion = _CloudsErosionIntensity.y;
|
||||
|
||||
parameters.baseNoiseMultiplier = _CloudsNoiseSettings.z;
|
||||
parameters.detailNoiseMultiplier = _CloudsNoiseSettings.w;
|
||||
|
||||
parameters.minSteps = _Steps.x;
|
||||
parameters.maxSteps = _Steps.y;
|
||||
|
||||
parameters.baseNoiseUV = _CloudsNoiseSettings.x;
|
||||
parameters.detailNoiseUV = _CloudsNoiseSettings.y;
|
||||
|
||||
parameters.baseErosionIntensity = _CloudsErosionIntensity.x;
|
||||
parameters.detailErosionIntensity = _CloudsErosionIntensity.y;
|
||||
|
||||
parameters.bottomShape = _CloudsShape1.x;
|
||||
parameters.midShape = _CloudsShape1.y;
|
||||
parameters.topShape = _CloudsShape1.z;
|
||||
parameters.topLayer = _CloudsShape1.w;
|
||||
|
||||
parameters.rampShape = _CloudsCoverageSettings.w;
|
||||
|
||||
parameters.cloudTypeShaping = _CloudsCoverageSettings.z;
|
||||
}
|
||||
|
||||
float HenryGreensteinNorm(float cosTheta, float g)
|
||||
{
|
||||
float g2 = g * g;
|
||||
return (1.0 - g2) / (4.0 * PI * pow(1.0 + g2 - 2.0 * g * cosTheta, 1.5));
|
||||
}
|
||||
|
||||
float RemapEnviro(float org_val, float org_min, float org_max, float new_min, float new_max)
|
||||
{
|
||||
return new_min + saturate(((org_val - org_min) / (org_max - org_min))*(new_max - new_min));
|
||||
}
|
||||
|
||||
float4 GetWeather(float3 pos)
|
||||
{
|
||||
float2 uv = pos.xz * 0.0000025;
|
||||
return _WeatherMap.SampleLevel(sampler_WeatherMap,uv, 0);
|
||||
}
|
||||
|
||||
float GetSamplingHeight(float3 pos, float3 center, float4 parameters)
|
||||
{
|
||||
return (length(pos - center) - (parameters.w + parameters.x)) * parameters.z;
|
||||
}
|
||||
|
||||
float3 ScreenSpaceDither(float2 vScreenPos, float lum)
|
||||
{
|
||||
float d = dot(float2(131.0, 312.0), vScreenPos.xy); //+ _Time TODO
|
||||
float3 vDither = float3(d, d, d);
|
||||
vDither.rgb = frac(vDither.rgb / float3(103.0, 71.0, 97.0)) - float3(0.5, 0.5, 0.5);
|
||||
return (vDither.rgb / 15.0) * 1.0 * lum;
|
||||
}
|
||||
|
||||
float GetRaymarchEndFromSceneDepth(float sceneDepth, float maxRange)
|
||||
{
|
||||
float raymarchEnd = 0.0f;
|
||||
#if ENVIRO_DEPTH_BLENDING
|
||||
if (sceneDepth >= 0.99f)
|
||||
{
|
||||
raymarchEnd = maxRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
raymarchEnd = sceneDepth * _ProjectionParams.z;
|
||||
}
|
||||
#else
|
||||
if(_EnviroDepthTest > 0 )
|
||||
{
|
||||
if (sceneDepth >= 0.99f)
|
||||
{
|
||||
raymarchEnd = maxRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
raymarchEnd = sceneDepth * _ProjectionParams.z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
raymarchEnd = maxRange;
|
||||
}
|
||||
#endif
|
||||
return raymarchEnd;
|
||||
}
|
||||
|
||||
float4 GetHeightGradient(float cloudType)
|
||||
{
|
||||
// x,y = bottom smoothstep, z,w = top smoothstep
|
||||
const float4 CloudGradient1 = float4(0.0, 0.07, 0.08, 0.15); // Strato
|
||||
const float4 CloudGradient2 = float4(0.0, 0.20, 0.42, 0.60); // Cumulus
|
||||
const float4 CloudGradient3 = float4(0.0, 0.08, 0.75, 0.98); // Nimbus
|
||||
|
||||
float a = 1.0 - saturate(cloudType * 2.0); // 0→0.5 strato
|
||||
float b = 1.0 - abs(cloudType - 0.5) * 2.0; // around 0.5 cumulus
|
||||
float c = saturate(cloudType - 0.5) * 2.0; // 0.5→1 nimbus
|
||||
|
||||
return CloudGradient1 * a + CloudGradient2 * b + CloudGradient3 * c;
|
||||
}
|
||||
|
||||
float GradientStep(float a, float4 g)
|
||||
{
|
||||
return smoothstep(g.x, g.y, a) - smoothstep(g.z, g.w, a);
|
||||
}
|
||||
|
||||
// ---------- Final profile with varying bottom ----------
|
||||
float CloudTypeShaping(float3 worldPos, float cloudType, RaymarchParameters p)
|
||||
{
|
||||
float _BottomVariation = 1000; // e.g. 500.0 m of random variation
|
||||
float _NoiseScale = 0.000025; // e.g. 0.001 for slow world-scale noise
|
||||
|
||||
// noise-based base variation
|
||||
float baseOffset = 0;
|
||||
#if ENVIRO_VARIABLE_BOTTOM
|
||||
baseOffset = tex2Dlod(_BottomsOffsetNoise, float4(worldPos.xz * _NoiseScale,0,0)).r * _BottomVariation;
|
||||
#endif
|
||||
float bottom = p.cloudsParameter.x + baseOffset;
|
||||
float top = bottom + (p.cloudsParameter.y - p.cloudsParameter.x);
|
||||
|
||||
// normalized height
|
||||
float h = saturate((worldPos.y - bottom) / (top - bottom));
|
||||
|
||||
// choose gradient band based on type
|
||||
float4 gradient = GetHeightGradient(cloudType);
|
||||
|
||||
// final vertical profile
|
||||
return GradientStep(h, gradient);
|
||||
}
|
||||
|
||||
|
||||
float CloudVerticalShaping(float heightNorm,
|
||||
float bottomCtrl,
|
||||
float midCtrl,
|
||||
float topCtrl,
|
||||
float ramp)
|
||||
{
|
||||
// --- Define segments ---
|
||||
float2 bottomRange = float2(-0.1, 0.25);
|
||||
float2 midRange = float2(0.20, 0.45);
|
||||
float2 topRange = float2(0.40, 0.8); // top segment fades before 1.0
|
||||
|
||||
// --- Compute smooth ramps ---
|
||||
float bottom = smoothstep(bottomRange.x, bottomRange.y, heightNorm) *
|
||||
(1.0 - smoothstep(bottomRange.x + ramp, bottomRange.y + ramp, heightNorm));
|
||||
|
||||
float mid = smoothstep(midRange.x, midRange.y, heightNorm) *
|
||||
(1.0 - smoothstep(midRange.x + ramp, midRange.y + ramp, heightNorm));
|
||||
|
||||
float top = smoothstep(topRange.x, topRange.y, heightNorm) *
|
||||
(1.0 - smoothstep(topRange.x + ramp, topRange.y + ramp, heightNorm));
|
||||
|
||||
// --- Fade top influence out at absolute top ---
|
||||
//top *= 1.0 - smoothstep(0.95, 1.0, heightNorm);
|
||||
|
||||
// --- Normalize weights so controls are balanced ---
|
||||
float sum = bottom + mid + top + 1e-5;
|
||||
bottom /= sum;
|
||||
mid /= sum;
|
||||
top /= sum;
|
||||
|
||||
// --- Apply coverage controls ---
|
||||
float bias = bottomCtrl * bottom + midCtrl * mid + topCtrl * top;
|
||||
|
||||
// --- Map to envelope multiplier ---
|
||||
// center at 1.0 = no change, limit to avoid full fill
|
||||
float envelope = 1.0 + bias * 0.5; // adjust scale as needed
|
||||
//envelope = envelope;
|
||||
|
||||
//Bottom Round
|
||||
float edgeRound = 1.0 - exp(-heightNorm * 8.0);
|
||||
envelope *= lerp(1.0, edgeRound, 0.9 * bottom);
|
||||
|
||||
|
||||
|
||||
// --- Subtle round-top modifier ---
|
||||
float edgeRoundTop = 1.0 - exp(-(1.0 - heightNorm) * 8.0); // only affects highest ~0.8–1.0
|
||||
envelope *= lerp(1.0, edgeRoundTop, 1.5 * top);
|
||||
|
||||
if(heightNorm > 0.90)
|
||||
envelope = 0;
|
||||
|
||||
return envelope;
|
||||
}
|
||||
|
||||
float CloudTopLayer(float heightNorm, float baseNoise, float topLayerAdd)
|
||||
{
|
||||
const float topMin = 0.90;
|
||||
const float topMax = 0.94;
|
||||
float verticalFalloff = smoothstep(topMin, topMax, heightNorm) - smoothstep(topMax, 1.0, heightNorm);
|
||||
|
||||
float coverage = baseNoise;
|
||||
return verticalFalloff * coverage * topLayerAdd;
|
||||
}
|
||||
|
||||
// Sample Cloud Density
|
||||
float CalculateCloudDensity(float3 pos, float3 PlanetCenter, RaymarchParameters parameters, float4 weather, float mip, float lod, bool details)
|
||||
{
|
||||
const float baseFreq = 1e-5;
|
||||
|
||||
// Get Height fraction
|
||||
float height = GetSamplingHeight(pos, PlanetCenter, parameters.cloudsParameter);
|
||||
|
||||
// wind settings
|
||||
float cloud_top_offset = 2000.0;
|
||||
float3 wind_direction = float3(_CloudsWindDirection.x, 0.0, _CloudsWindDirection.y);
|
||||
|
||||
// skew in wind direction
|
||||
pos += height * wind_direction * cloud_top_offset;
|
||||
|
||||
float mip1 = mip + lod;
|
||||
float4 coord = float4(pos * baseFreq * parameters.baseNoiseUV, mip1);
|
||||
|
||||
// Animate Wind
|
||||
coord.xyz += float3(_CloudsWindDirection.z, 0.0f, _CloudsWindDirection.w) * 14;
|
||||
|
||||
float4 baseNoise = _Noise.SampleLevel(sampler_Noise, coord.xyz,coord.w) * parameters.baseNoiseMultiplier;
|
||||
float low_freq_fBm = (baseNoise.g * 0.625) + (baseNoise.b * 0.25) + (baseNoise.a * 0.125);
|
||||
float base_cloud = RemapEnviro(baseNoise.r, -(1.0 - low_freq_fBm) * (parameters.baseErosionIntensity), 1.0, 0.0, 1.0) ;
|
||||
|
||||
float targetShape = CloudVerticalShaping(height,parameters.bottomShape,parameters.midShape,parameters.topShape,parameters.rampShape);
|
||||
float heightGradient = CloudTypeShaping(pos,saturate(weather.g + 0.1), parameters);
|
||||
float shapedCloud = base_cloud * targetShape;
|
||||
|
||||
shapedCloud *= lerp(1.0, heightGradient, parameters.cloudTypeShaping);
|
||||
shapedCloud += CloudTopLayer(height, base_cloud, parameters.topLayer);
|
||||
|
||||
|
||||
float cloud_coverage = saturate(1-weather.r);
|
||||
|
||||
if(height > 0.90)
|
||||
cloud_coverage = saturate(1-weather.b);
|
||||
|
||||
float cloudDensity = RemapEnviro(shapedCloud, cloud_coverage, 1.0, 0.0, 1.0);
|
||||
|
||||
//DETAIL
|
||||
[branch]
|
||||
if (details)
|
||||
{
|
||||
float mip2 = mip + lod;
|
||||
coord = float4(pos * baseFreq * parameters.detailNoiseUV, mip2);
|
||||
|
||||
//Curl
|
||||
float distToCam = distance(pos, _WorldSpaceCameraPos);
|
||||
float curlFade = saturate(1.0 - distToCam / 20000.0f);
|
||||
|
||||
float2 curlA = _CurlNoise.SampleLevel(sampler_CurlNoise, coord.xz * 2, 0).rg * 2 - 1;
|
||||
float2 curlB = _CurlNoise.SampleLevel(sampler_CurlNoise, coord.xy * 3, 0).rg * 2 - 1;
|
||||
float2 curl = lerp(curlA, curlB, 0.5);
|
||||
|
||||
float curlAmp = 0.5 * parameters.attenuation * curlFade;
|
||||
curl *= curlAmp * saturate(height * 2);
|
||||
|
||||
coord.xy += curl;
|
||||
coord.xz += curl * 0.5;
|
||||
|
||||
coord.xyz += float3(_CloudsWindDirection.z * 14, _CloudsAnimation.z, _CloudsWindDirection.w * 14);
|
||||
|
||||
float3 detailNoise = _DetailNoise.SampleLevel(sampler_DetailNoise, coord.xyz, coord.w).rgb * parameters.detailNoiseMultiplier;
|
||||
float high_freq_fBm = (detailNoise.r * 0.625) + (detailNoise.g * 0.25) + (detailNoise.b * 0.125);
|
||||
float high_freq_noise_modifier = lerp(high_freq_fBm, 1.0f - high_freq_fBm, saturate(height * 8));
|
||||
cloudDensity = RemapEnviro(cloudDensity, saturate(high_freq_noise_modifier * parameters.detailErosionIntensity), 1.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
if(height > 0.9)
|
||||
cloudDensity *= 0.2;
|
||||
|
||||
return cloudDensity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const float shadowSampleDistance[5] = {0.5, 2, 8, 12, 32};
|
||||
static const float LightingInfluence[5] = {5, 4, 3, 2, 1};
|
||||
|
||||
float GetDensityAlongRay(float3 pos,float3 PlanetCenter,RaymarchParameters parameters,float3 LightDirection,float4 weather,float lod)
|
||||
{
|
||||
float mipBiasScale = 0.1;
|
||||
float opticalDepth = 0.0;
|
||||
float mipOffset = 0.0;
|
||||
float distanceTraveled = 0.0;
|
||||
|
||||
[loop]
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
// Base step size from shadowSampleDistance
|
||||
float baseStep = shadowSampleDistance[i] * (512.0 * _CloudsLightingExtended.z);
|
||||
|
||||
distanceTraveled += baseStep;
|
||||
|
||||
// Sample cloud density
|
||||
float3 samplePos = pos + LightDirection * distanceTraveled;
|
||||
float density = 0;
|
||||
if(i < 4)
|
||||
density = CalculateCloudDensity(samplePos, PlanetCenter, parameters, weather, mipOffset, lod, true) * 0.75;
|
||||
else
|
||||
density = CalculateCloudDensity(samplePos, PlanetCenter, parameters, weather, mipOffset, lod, false) * 0.75;
|
||||
|
||||
|
||||
|
||||
opticalDepth += LightingInfluence[i] * density * baseStep;
|
||||
|
||||
// Update mip offset proportionally
|
||||
mipOffset += saturate(baseStep * mipBiasScale);
|
||||
}
|
||||
|
||||
return opticalDepth;
|
||||
}
|
||||
|
||||
|
||||
float3 _LightningCenter;
|
||||
float _LightningRadius;
|
||||
float _LightningStart;
|
||||
float _LightningDuration;
|
||||
float _GlobalTime;
|
||||
|
||||
float LightningIntensity(float t)
|
||||
{
|
||||
if (t < 0 || t > _LightningDuration) return 0;
|
||||
|
||||
// ---- Parameters ----
|
||||
float flickerStrength = 0.25; // 0..1 amplitude of flicker
|
||||
float flickerCycles = 3; // number of flickers across duration
|
||||
float endBoost = 2; // 1 = none, 2 = double brightness at end
|
||||
|
||||
// ---- Duration-based scaling ----
|
||||
float riseRate = 1.0 / max(0.15 * _LightningDuration, 0.001);
|
||||
float decayRate = 1.0 / max(_LightningDuration, 0.001);
|
||||
|
||||
float rise = saturate(t * riseRate);
|
||||
float decay = exp(-t * decayRate * _LightningDuration);
|
||||
float envelope = rise * decay;
|
||||
|
||||
// ---- Flicker ----
|
||||
float flickerFreq = flickerCycles / max(_LightningDuration, 0.001);
|
||||
float flicker = 1.0 + flickerStrength * sin(t * flickerFreq * 6.2831853);
|
||||
|
||||
// ---- Late-time boost ----
|
||||
// Progress through flash (0 → 1)
|
||||
float progress = saturate(t / _LightningDuration);
|
||||
// Stronger near the end (ease-in curve)
|
||||
float lateBoost = 1.0 + (endBoost - 1.0) * pow(progress, 3.0);
|
||||
|
||||
return envelope * flicker * lateBoost;
|
||||
}
|
||||
|
||||
|
||||
float SampleEnergy(
|
||||
float3 pos, float cosTheta, float3 center,
|
||||
RaymarchParameters p, float3 LightDirection,
|
||||
float height, float ds_lod, float step_size,
|
||||
float4 weather, float lod, float gradApprox)
|
||||
{
|
||||
//--------------------------------
|
||||
// 1. Optical depth along light
|
||||
//--------------------------------
|
||||
float tau = GetDensityAlongRay(pos, center, p, LightDirection, weather, lod);
|
||||
float sigma_t = max(p.lightAbsorb, 0.0005);
|
||||
float opticalD = sigma_t * tau;
|
||||
|
||||
//--------------------------------
|
||||
// 2. Direct scattering (HG + edge highlight coupled)
|
||||
//--------------------------------
|
||||
float T = exp(-opticalD);
|
||||
float g = 0.85 - p.silverLiningSpread;
|
||||
float hgForward = HenryGreensteinNorm(cosTheta, g);
|
||||
float hgIso = 0.25 * INV_PI * p.edgeHighlightStrength;
|
||||
float phase = hgIso + hgForward;
|
||||
float direct = T * phase * p.scatteringCoef * 20.0 * max(_SolarTime,0.25) * p.silverLiningIntensity;
|
||||
|
||||
//--------------------------------
|
||||
// 3. Multi-scattering (indirect)
|
||||
//--------------------------------
|
||||
float msEnergy = p.multiScatterStrength * (1.0 - T) * exp(-opticalD * p.multiScatterFalloff);
|
||||
float phaseMS = 0.25 * INV_PI;
|
||||
float indirect = msEnergy * phaseMS * p.scatteringCoef * 20.0;
|
||||
|
||||
//--------------------------------
|
||||
// 3a Distance Clouds Tweaks
|
||||
//--------------------------------
|
||||
float distToCam = length(pos - _WorldSpaceCameraPos);
|
||||
float distFactor = saturate(distToCam / 7000);
|
||||
|
||||
// Push balance toward indirect at distance
|
||||
float indirectBoost = lerp(1.0, 1.5, distFactor); // 1.0 near, 1.5 far
|
||||
float directFade = lerp(1.0, 0.7, distFactor); // keep direct a bit weaker far
|
||||
|
||||
direct *= directFade;
|
||||
indirect *= indirectBoost;
|
||||
|
||||
//--------------------------------
|
||||
// 4. Ambient floor
|
||||
//--------------------------------
|
||||
float ambientFloor = p.ambientFloor * (1.0 - exp(-opticalD * 0.1));
|
||||
|
||||
//--------------------------------
|
||||
// 5. Lightning
|
||||
//--------------------------------
|
||||
float lightning = 0.0;
|
||||
#if ENVIRO_LIGHTNING
|
||||
float dist = length(pos - _LightningCenter);
|
||||
float softness = 0.5;
|
||||
float falloff = exp(-pow(dist / _LightningRadius, 2.0) * softness);
|
||||
float flash = LightningIntensity(_Time.y - _LightningStart);
|
||||
float densityAtten = exp(-tau * 0.004);
|
||||
lightning = flash * falloff * densityAtten * 100.0 * (10 * saturate(1 - _SolarTime));
|
||||
#endif
|
||||
|
||||
//--------------------------------
|
||||
// 6. Combine total energy
|
||||
//--------------------------------
|
||||
float energy = direct + indirect + ambientFloor + lightning;
|
||||
|
||||
return max(energy * p.exposure, 0.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
float2 squareUV(float2 uv)
|
||||
{
|
||||
float width = _Resolution.x;
|
||||
float height = _Resolution.y;
|
||||
float scale = 400;
|
||||
float x = uv.x * width;
|
||||
float y = uv.y * height;
|
||||
return float2 (x/scale, y/scale);
|
||||
}
|
||||
|
||||
|
||||
bool ray_trace_sphere(float3 center, float3 rd, float3 offset, float radius, out float t1, out float t2) {
|
||||
float3 p = center - offset;
|
||||
float b = dot(p, rd);
|
||||
float c = dot(p, p) - (radius * radius);
|
||||
|
||||
float f = b * b - c;
|
||||
if (f >= 0.0) {
|
||||
float dem = sqrt(f);
|
||||
t1 = -b - dem;
|
||||
t2 = -b + dem;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool resolve_ray_start_end(float3 ws_origin, float3 ws_ray, float3 center, RaymarchParameters parameter, out float start, out float end)
|
||||
{
|
||||
start = 0;
|
||||
end = 0;
|
||||
//case includes on ground, inside atm, above atm.
|
||||
float ot1, ot2, it1, it2;
|
||||
bool outIntersected = ray_trace_sphere(ws_origin, ws_ray, center, parameter.cloudsParameter.w + parameter.cloudsParameter.y, ot1, ot2);
|
||||
if (!outIntersected || ot2 < 0.0f)
|
||||
return false; //you see nothing.
|
||||
|
||||
bool inIntersected = ray_trace_sphere(ws_origin, ws_ray, center, parameter.cloudsParameter.w + parameter.cloudsParameter.x, it1, it2);
|
||||
|
||||
if (inIntersected)
|
||||
{
|
||||
if (it1 * it2 < 0)
|
||||
{
|
||||
//we're on ground.
|
||||
start = max(it2, 0);
|
||||
end = ot2;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = 0.0f;
|
||||
//we're inside atm, or above atm.
|
||||
if (ot1 * ot2 < 0.0)
|
||||
{
|
||||
//Inside atm.
|
||||
if (it2 > 0.0)
|
||||
{
|
||||
//Look down.
|
||||
end = it1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Look up.
|
||||
end = ot2;
|
||||
}
|
||||
|
||||
start = 0.0f;
|
||||
}
|
||||
else
|
||||
{ //Outside atm
|
||||
if (ot1 < 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = ot1;
|
||||
end = it1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
end = ot2;
|
||||
start = max(ot1, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int inside = 0;
|
||||
|
||||
float2 ResolveRay(float3 pos, float3 ray, float3 center, float raymarchEnd, RaymarchParameters parameter)
|
||||
{
|
||||
float sampleStart = 0;
|
||||
float sampleEnd = 0;
|
||||
|
||||
if (!resolve_ray_start_end(pos, ray,center, parameter, sampleStart, sampleEnd))
|
||||
{
|
||||
return float2(0,0);
|
||||
}
|
||||
|
||||
float3 sampleStartPos = pos + (ray * sampleStart);
|
||||
if (sampleEnd <= sampleStart)
|
||||
{
|
||||
return float2(0,0);
|
||||
}
|
||||
|
||||
float ch = length(pos - center) - parameter.cloudsParameter.w;
|
||||
//float height = RemapEnviro(pos.y, parameter.cloudsParameter.x, parameter.cloudsParameter.y * 0.75, 0, 1);
|
||||
//float end = lerp(_CloudsCoverageSettings.y * 0.85,_CloudsCoverageSettings.y * 1.25,height);
|
||||
|
||||
raymarchEnd = min(raymarchEnd, _CloudsCoverageSettings.y);
|
||||
|
||||
if (ch < parameter.cloudsParameter.x)
|
||||
{
|
||||
sampleEnd = min(raymarchEnd, sampleEnd);
|
||||
inside = 0;
|
||||
|
||||
if(ray.y < 0)
|
||||
return float2(0,0);
|
||||
}
|
||||
else if (ch > parameter.cloudsParameter.y)
|
||||
{
|
||||
sampleEnd = min(raymarchEnd, sampleEnd);
|
||||
inside = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sampleEnd = min(raymarchEnd, sampleEnd);
|
||||
inside = 0;
|
||||
}
|
||||
|
||||
return float2(max(0.0f,sampleStart), min(raymarchEnd, sampleEnd));
|
||||
}
|
||||
|
||||
float CalculateLodMips(float distanceToCamera)
|
||||
{
|
||||
return lerp(0.0, lerp(5.0,0.0,_LODDistance), saturate((distanceToCamera - 3000.0) / (100000.0 - 3000.0)));
|
||||
}
|
||||
|
||||
|
||||
float3 Raymarch (float3 cameraPos, float3 ray, float2 hitDistance, float3 center, RaymarchParameters parameters, float offset)
|
||||
{
|
||||
float cloud_test = 0.0;
|
||||
int zero_density_sample_count = 0;
|
||||
float sampled_density_previous = -1.0;
|
||||
|
||||
float alpha = 1.0;
|
||||
float intensity = 0.0;
|
||||
float depth = 0.0;
|
||||
float depthWeightSum = 0.000001;
|
||||
float trans = 1.0f;
|
||||
|
||||
int steps = (int)lerp(parameters.minSteps, parameters.maxSteps, ray.y);
|
||||
|
||||
//int steps = parameters.maxSteps;
|
||||
float rayStepLength = (hitDistance.y - hitDistance.x) / steps;
|
||||
float3 rayStep = ray * rayStepLength;
|
||||
|
||||
float3 pos = (cameraPos + (hitDistance.x) * ray);
|
||||
pos += (offset * rayStepLength) * ray;
|
||||
//pos += rayStep;
|
||||
pos += rayStep;
|
||||
float3 sampleEndPos = cameraPos + ray * hitDistance.y;
|
||||
float eyeToEnd = distance(cameraPos, sampleEndPos);
|
||||
float cosTheta = dot(ray, normalize(_LightDir));
|
||||
|
||||
[loop]
|
||||
for (int i = 0; i < steps; i++)
|
||||
{
|
||||
|
||||
//Calculate projection height
|
||||
float height = GetSamplingHeight(pos, center, parameters.cloudsParameter);
|
||||
|
||||
//Get out of expensive raymarching
|
||||
if (alpha <= 0.01 || height > 1.0 || height < 0.0 || _CloudsCoverageSettings.x <= -0.9)
|
||||
break;
|
||||
|
||||
// Get Weather Data
|
||||
float4 weather = GetWeather(pos);
|
||||
|
||||
float distanceToCamera = length(pos - cameraPos);
|
||||
float lod = CalculateLodMips(distanceToCamera);
|
||||
|
||||
if (cloud_test > 0.0)
|
||||
{
|
||||
float sampled_density = CalculateCloudDensity(pos, center, parameters, weather, 0, lod, true);
|
||||
|
||||
if (sampled_density == 0.0 && sampled_density_previous == 0.0)
|
||||
{
|
||||
zero_density_sample_count++;
|
||||
}
|
||||
|
||||
if (zero_density_sample_count < 8 && sampled_density != 0.0)
|
||||
{
|
||||
float extinction = pow(max(parameters.density * sampled_density,0.001),parameters.densitySmoothness);
|
||||
float clampedExtinction = max(extinction, 1e-7);
|
||||
|
||||
float transmittance = exp(-extinction * rayStepLength);
|
||||
|
||||
float gradApprox = abs(sampled_density - sampled_density_previous);
|
||||
|
||||
// edge-sensitive ds_lod
|
||||
float ds_lod_local = sampled_density * (1.0 + lod * 0.8);
|
||||
|
||||
float luminance = SampleEnergy(pos, cosTheta, center, parameters, _LightDir, height, sampled_density, rayStepLength,weather,lod,gradApprox);
|
||||
|
||||
float integScatt = (luminance - luminance * transmittance);
|
||||
|
||||
float depthWeight = trans;
|
||||
depth += depthWeight * distanceToCamera;
|
||||
depthWeightSum += depthWeight;
|
||||
|
||||
intensity += trans * integScatt;
|
||||
|
||||
trans *= transmittance;
|
||||
alpha *= max(transmittance, 0.0);
|
||||
|
||||
if (alpha <= 0.01)
|
||||
alpha = 0.0;
|
||||
}
|
||||
// if not, then set cloud_test to zero so that we go back to the cheap sample case
|
||||
else if(zero_density_sample_count >= 8)
|
||||
{
|
||||
cloud_test = 0.0;
|
||||
zero_density_sample_count = 0;
|
||||
}
|
||||
|
||||
sampled_density_previous = sampled_density;
|
||||
pos += rayStep;
|
||||
}
|
||||
else
|
||||
{
|
||||
// sample density the cheap way, only using the low frequency noise
|
||||
cloud_test = CalculateCloudDensity(pos, center, parameters, weather, 0, lod, (bool)inside);
|
||||
|
||||
if (cloud_test == 0.0)
|
||||
{
|
||||
pos += rayStep * 2;
|
||||
}
|
||||
else //take a step back and capture area we skipped.
|
||||
{
|
||||
pos -= rayStep;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
float distance = depth / depthWeightSum;
|
||||
|
||||
if (distance <= 0.0)
|
||||
{
|
||||
distance = length(sampleEndPos - cameraPos);
|
||||
}
|
||||
|
||||
alpha = saturate(1.0f - alpha);
|
||||
|
||||
return float3(intensity,distance,alpha);
|
||||
|
||||
}
|
||||
|
||||
float3 CalculateWorldPosition (float2 uv, float depth)
|
||||
{
|
||||
float4x4 proj, eyeToWorld;
|
||||
|
||||
if (unity_StereoEyeIndex == 0)
|
||||
{
|
||||
proj = _LeftViewFromScreen;
|
||||
eyeToWorld = _LeftWorldFromView;
|
||||
}
|
||||
else
|
||||
{
|
||||
proj = _RightViewFromScreen;
|
||||
eyeToWorld = _RightWorldFromView;
|
||||
}
|
||||
|
||||
//bit of matrix math to take the screen space coord (u,v,depth) and transform to world space
|
||||
float2 uvClip = uv * 2.0 - 1.0;
|
||||
float clipDepth = depth; // Fix for OpenGl Core thanks to Lars Bertram
|
||||
clipDepth = (UNITY_NEAR_CLIP_VALUE < 0) ? clipDepth * 2 - 1 : clipDepth;
|
||||
float4 clipPos = float4(uvClip, clipDepth, 1.0);
|
||||
float4 viewPos = mul(proj, clipPos); // inverse projection by clip position
|
||||
viewPos /= viewPos.w; // perspective division
|
||||
return float3(mul(eyeToWorld, viewPos).xyz);
|
||||
}
|
||||
|
||||
float RaymarchShadows (float3 cameraPos, float3 worldPos,float3 ray,float3 center, RaymarchParameters parameters, float offset,float depth)
|
||||
{
|
||||
if(depth == 0.0f)
|
||||
return 0.0;
|
||||
|
||||
int steps = 16;
|
||||
float worldDotLight = saturate(dot(float3(0, 1, 0), _LightDir));
|
||||
float bottomDist = max(0, parameters.cloudsParameter.x ) / worldDotLight;
|
||||
float topDist = max(0, parameters.cloudsParameter.y ) / worldDotLight;
|
||||
|
||||
float rayStepLength = (topDist - bottomDist) / steps;
|
||||
float3 rayStep = _LightDir * rayStepLength;
|
||||
|
||||
float3 pos = worldPos + bottomDist * _LightDir;
|
||||
|
||||
float4 weather = GetWeather(pos);
|
||||
float intensity = 0.05;
|
||||
|
||||
float shadowIntensity = 0.0;
|
||||
|
||||
float _Softness = 2.0f;
|
||||
|
||||
[unroll]
|
||||
for (int i = 0; i < steps; i++)
|
||||
{
|
||||
float3 samplePos = rayStepLength * i * _LightDir + pos;
|
||||
float sampleResult = CalculateCloudDensity(samplePos, center, parameters, weather, 0, 0, true) * intensity;
|
||||
float result = sampleResult * (rayStepLength / (i + 1));
|
||||
shadowIntensity += result;
|
||||
|
||||
// if (shadowIntensity > 0.99)
|
||||
// break;
|
||||
}
|
||||
return (shadowIntensity);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38c16a4885560c54fbc0504cd5019da4
|
||||
timeCreated: 1505167667
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/VolumetricCloudsInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,2 @@
|
||||
TEXTURE2D_X(_MainTex);
|
||||
TEXTURE2D_X(_DownsampledDepth);
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec298c7f5f5d1a64196a764bdf40289f
|
||||
timeCreated: 1505167667
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/VolumetricCloudsTexHDRPInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,3 @@
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_DownsampledDepth);
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthTexture);
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c8fae82a28dfc44b85ece5a9ed7f747
|
||||
timeCreated: 1505167667
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Includes/VolumetricCloudsTexInclude.cginc
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,6 @@
|
||||
TEXTURE2D_X(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
TEXTURE2D_X_FLOAT(_DownsampledDepth);
|
||||
SAMPLER (sampler_DownsampledDepth);
|
||||
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
|
||||
SAMPLER (sampler_CameraDepthTexture);
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78ef83094a6b4b147988c1b2c3208de0
|
||||
timeCreated: 1505167667
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user