add weather and time

This commit is contained in:
XuGaoFeng
2026-05-09 09:10:52 +08:00
parent 48e0dea5e1
commit 0ca1b49fa7
639 changed files with 121558 additions and 102 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 425a53e3c722f0e4b8b7f940834edd2d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
Shader "Hidden/EnviroBlitThrough"
{
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
ZTest Always ZWrite Off Cull Off
Pass
{
Name "EnviroBlitThrough"
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionHCS : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
// Note: The pass is setup with a mesh already in CS
// Therefore, we can just output vertex position
// See RenderingUtils.fullscreenMesh
output.positionCS = float4(input.positionHCS.xyz, 1.0);
#if UNITY_UV_STARTS_AT_TOP
output.positionCS.y *= -1;
#endif
output.uv = input.uv;
return output;
}
TEXTURE2D_X(_MainTex);
SAMPLER(sampler_MainTex);
half4 frag (Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, input.uv);
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 0a8d97f800797f1428576cb225f06d70
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/Blit/EnviroBlitThroughURP.shader
uploadId: 660896

View File

@@ -0,0 +1,69 @@
Shader "Hidden/EnviroBlitThroughURP17"
{
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
ZTest Always ZWrite Off Cull Off
Pass
{
Name "EnviroBlitThrough"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
TEXTURE2D_X(_MainTex);
SAMPLER(sampler_MainTex);
half4 frag (Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, input.texcoord);
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f Vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 64485b71c5135ab4fa5535c8b6bb907b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
Shader "Hidden/Enviro/BlitTroughHDRP"
{
HLSLINCLUDE
#pragma target 4.5
#pragma multi_compile __ ENVIROHDRP
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
struct Attributes
{
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings Vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
return output;
}
// List of properties to control your post process effect
float _Intensity;
TEXTURE2D_X(_InputTexture);
float4 CustomPostProcess(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
uint2 positionSS = input.texcoord * _ScreenSize.xy;
float3 outColor = LOAD_TEXTURE2D_X(_InputTexture, positionSS).xyz;
return float4(outColor, 1);
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f Vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 CustomPostProcess (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline" }
Pass
{
Name "EnviroBlitTroughHDRP"
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
#pragma fragment CustomPostProcess
#pragma vertex Vert
ENDHLSL
}
}
Fallback Off
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 63a1fa02cae5fd54888169da9767c67a
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/Blit/EnviroBlitTroughHDRP.shader
uploadId: 660896

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c7df2cc26740c1f4ea77793e55cbf071
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,76 @@
Shader "Hidden/EnviroApplyShadows"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
//_CloudsTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.uv;
return o;
}
float _Intensity;
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
UNITY_DECLARE_SCREENSPACE_TEXTURE(_CloudsTex);
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 sceneColor = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex,i.uv);
float4 cloudTex = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CloudsTex,i.uv);
float shadowsClouds = saturate(1-(cloudTex.b * _Intensity));
// shadowsClouds = shadowsClouds * ;
float4 final = float4(sceneColor.rgb * shadowsClouds, sceneColor.a);
return final;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: aac3497da77f54d45be34e36e73cd078
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/Clouds/EnviroApplyShadows.shader
uploadId: 660896

View File

@@ -0,0 +1,108 @@
Shader "Hidden/EnviroApplyShadowsHDRP"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
//_CloudsTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROHDRP
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
struct appdata
{
uint vertexID : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
return o;
}
float _Intensity;
float4 _HandleScales;
TEXTURE2D_X(_MainTex);
TEXTURE2D_X(_CloudsTex);
SAMPLER(sampler_CloudsTex);
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 sceneColor = SAMPLE_TEXTURE2D_X_LOD(_MainTex,s_trilinear_clamp_sampler, i.uv, 0);
float4 cloudTex = SAMPLE_TEXTURE2D_X(_CloudsTex,sampler_CloudsTex, i.uv * _HandleScales.xy);
float shadowsClouds = saturate(1-(cloudTex.b * _Intensity));
float4 final = float4(sceneColor.rgb * shadowsClouds, sceneColor.a);
return final;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: cd43fb7dba71169479da866d0aae5fa1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroApplyShadowsHDRP.shader
uploadId: 660896

View File

@@ -0,0 +1,110 @@
Shader "Hidden/EnviroApplyShadowsURP"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
//_CloudsTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
struct appdata
{
uint vertex : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.vertex = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
return o;
}
float _Intensity;
TEXTURE2D_X(_MainTex);
SAMPLER (sampler_MainTex);
TEXTURE2D_X(_CloudsTex);
SAMPLER (sampler_CloudsTex);
// UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
// UNITY_DECLARE_SCREENSPACE_TEXTURE(_CloudsTex);
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 sceneColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,i.uv);
float4 cloudTex = SAMPLE_TEXTURE2D_X(_CloudsTex,sampler_CloudsTex,i.uv);
float shadowsClouds = saturate(1-(cloudTex.b * _Intensity));
// shadowsClouds = shadowsClouds * ;
float4 final = float4(sceneColor.rgb * shadowsClouds, sceneColor.a);
return final;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: dd723b2af3633bb409d9ba4fa82ef5c7
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,200 @@
Shader "Hidden/EnviroVolumetricCloudsBlend"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Cull Off ZWrite Off ZTest Always
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIRO_DEPTH_BLENDING
#pragma multi_compile __ ENVIROURP
#pragma multi_compile __ UNITY_COLORSPACE_GAMMA
#include "UnityCG.cginc"
#include_with_pragmas "../Includes/FogInclude.cginc"
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
#ifdef STEREO_INSTANCING_ON
UNITY_DECLARE_TEX2DARRAY (_CloudTex);
#else
UNITY_DECLARE_TEX2D (_CloudTex);
#endif
UNITY_DECLARE_SCREENSPACE_TEXTURE(_DownsampledDepth);
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float4 _CloudTex_TexelSize;
float4 _MainTex_TexelSize;
SamplerState Point_Clamp_Sampler;
float4 _ProjectionExtents;
float4 _ProjectionExtentsRight;
float4x4 _CamToWorld;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float4 screenPos : TEXCOORD1;
float2 vsray : TEXCOORD2;
half3 pos : TEXCOORD3;
//#ifdef ENVIRO_DEPTH_BLENDING
float2 uv00 : TEXCOORD4;
float2 uv10 : TEXCOORD5;
float2 uv01 : TEXCOORD6;
float2 uv11 : TEXCOORD7;
//#endif
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata_img v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.pos = -v.vertex;
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord;
if(unity_StereoEyeIndex == 0)
o.vsray = (2.0 * v.texcoord - 1.0) * _ProjectionExtents.xy + _ProjectionExtents.zw;
else
o.vsray = (2.0 * v.texcoord - 1.0) * _ProjectionExtentsRight.xy + _ProjectionExtentsRight.zw;
o.screenPos = ComputeScreenPos(o.vertex);
//#ifdef ENVIRO_DEPTH_BLENDING
o.uv00 = v.texcoord - 0.5 * _CloudTex_TexelSize.xy;
o.uv10 = o.uv00 + float2(_CloudTex_TexelSize.x, 0.0);
o.uv01 = o.uv00 + float2(0.0, _CloudTex_TexelSize.y);
o.uv11 = o.uv00 + _CloudTex_TexelSize.xy;
//#endif
return o;
}
//#ifdef ENVIRO_DEPTH_BLENDING
float4 Upsample(v2f i)
{
float4 lowResDepth = 0.0f;
float highResDepth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,UnityStereoTransformScreenSpaceTex(i.uv)));
lowResDepth.x = LinearEyeDepth(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DownsampledDepth,UnityStereoTransformScreenSpaceTex(i.uv00)).r);
lowResDepth.y = LinearEyeDepth(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DownsampledDepth,UnityStereoTransformScreenSpaceTex(i.uv10)).r);
lowResDepth.z = LinearEyeDepth(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DownsampledDepth,UnityStereoTransformScreenSpaceTex(i.uv01)).r);
lowResDepth.w = LinearEyeDepth(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DownsampledDepth,UnityStereoTransformScreenSpaceTex(i.uv11)).r);
float4 depthDiff = abs(lowResDepth - highResDepth);
float accumDiff = dot(depthDiff, float4(1, 1, 1, 1));
[branch]
if (accumDiff < 1.5f)
{
#ifdef STEREO_INSTANCING_ON
float3 uv = float3(UnityStereoTransformScreenSpaceTex(i.uv),unity_StereoEyeIndex);
return _CloudTex.Sample(sampler_CloudTex, uv);
#else
return _CloudTex.Sample(sampler_CloudTex, UnityStereoTransformScreenSpaceTex(i.uv));
#endif
}
else
{
float minDepthDiff = depthDiff[0];
float2 nearestUv = i.uv00;
if (depthDiff[1] < minDepthDiff)
{
nearestUv = i.uv10;
minDepthDiff = depthDiff[1];
}
if (depthDiff[2] < minDepthDiff)
{
nearestUv = i.uv01;
minDepthDiff = depthDiff[2];
}
if (depthDiff[3] < minDepthDiff)
{
nearestUv = i.uv11;
minDepthDiff = depthDiff[3];
}
#ifdef STEREO_INSTANCING_ON
float3 uv = float3(UnityStereoTransformScreenSpaceTex(nearestUv),unity_StereoEyeIndex);
return _CloudTex.Sample(Point_Clamp_Sampler, uv);
#else
return _CloudTex.Sample(Point_Clamp_Sampler, UnityStereoTransformScreenSpaceTex(nearestUv));
#endif
}
}
//#endif
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 vspos = float4(i.vsray, 1.0,1.0);
float4 worldPos = mul(_CamToWorld,vspos);
float3 viewDir = normalize(worldPos.xyz - _WorldSpaceCameraPos);
float4 sourceColor = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex,UnityStereoTransformScreenSpaceTex(i.uv));
float4 cloudsColor = Upsample(i);
float4 finalColor = GetCloudColor(cloudsColor,worldPos);
#if defined(UNITY_COLORSPACE_GAMMA)
finalColor.rgb = LinearToGammaSpace(finalColor.rgb);
#endif
#if ENVIRO_DEPTH_BLENDING
float4 final = float4(sourceColor.rgb * (1 - finalColor.a) + lerp(sourceColor.rgb, finalColor.rgb, finalColor.a) * finalColor.a, 1);
return final;
#else
float4 final = sourceColor;
float sceneDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(i.uv)));
if (sceneDepth >= 0.99f)
final = float4(sourceColor.rgb * saturate(1 - finalColor.a) + lerp(sourceColor.rgb, finalColor.rgb, finalColor.a) * finalColor.a, 1);
return final;
#endif
}
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: ff01f3ead5b250a4f8337a15b15442ac
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroVolumetricCloudsBlend.shader
uploadId: 660896

View File

@@ -0,0 +1,226 @@
Shader "Hidden/EnviroVolumetricCloudsBlendHDRP"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque"}
LOD 100
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma target 4.5
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIRO_DEPTH_BLENDING
#pragma multi_compile __ ENVIROHDRP
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
#include_with_pragmas "../Includes/FogIncludeHLSL.hlsl"
TEXTURE2D_X(_MainTex);
TEXTURE2D_X(_DownsampledDepth);
TEXTURE2D_X (_CloudTex);
SAMPLER(sampler_CloudTex);
SamplerState Point_Clamp_Sampler;
float4 _CloudTex_TexelSize;
float4 _MainTex_TexelSize;
float4 _HandleScales;
float4 _DepthHandleScale;
float4 _ProjectionExtents;
float4 _ProjectionExtentsRight;
float4x4 _CamToWorld;
float3 color;
float3 opacity;
float _EnviroSkyIntensity;
struct appdata
{
uint vertexID : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float2 vsray : TEXCOORD1;
#ifdef ENVIRO_DEPTH_BLENDING
float2 uv00 : TEXCOORD2;
float2 uv10 : TEXCOORD3;
float2 uv01 : TEXCOORD4;
float2 uv11 : TEXCOORD5;
#endif
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
if(unity_StereoEyeIndex == 0)
o.vsray = (2.0 * o.uv * (1/_RTHandleScale.xy) - 1.0) * _ProjectionExtents.xy + _ProjectionExtents.zw;
else
o.vsray = (2.0 * o.uv * (1/_RTHandleScale.xy) - 1.0) * _ProjectionExtentsRight.xy + _ProjectionExtentsRight.zw;
#ifdef ENVIRO_DEPTH_BLENDING
o.uv00 = o.uv - 0.5 * _CloudTex_TexelSize.xy;
o.uv10 = o.uv00 + float2(_CloudTex_TexelSize.x, 0.0);
o.uv01 = o.uv00 + float2(0.0, _CloudTex_TexelSize.y);
o.uv11 = o.uv00 + _CloudTex_TexelSize.xy;
#endif
return o;
}
#ifdef ENVIRO_DEPTH_BLENDING
float4 Upsample(v2f i)
{
float4 lowResDepth = 0.0f;
float highResDepth = Linear01Depth(LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, i.uv * _ScreenSize.xy * (1/_RTHandleScale.xy), 0), _ZBufferParams);
lowResDepth.x = Linear01Depth(LOAD_TEXTURE2D_X(_DownsampledDepth,i.uv00 * _DepthHandleScale.zw * _DepthHandleScale.xy).r, _ZBufferParams);
lowResDepth.y = Linear01Depth(LOAD_TEXTURE2D_X(_DownsampledDepth,i.uv10 * _DepthHandleScale.zw * _DepthHandleScale.xy).r, _ZBufferParams);
lowResDepth.z = Linear01Depth(LOAD_TEXTURE2D_X(_DownsampledDepth,i.uv01 * _DepthHandleScale.zw * _DepthHandleScale.xy).r, _ZBufferParams);
lowResDepth.w = Linear01Depth(LOAD_TEXTURE2D_X(_DownsampledDepth,i.uv11 * _DepthHandleScale.zw * _DepthHandleScale.xy).r, _ZBufferParams);
float4 depthDiff = abs(lowResDepth - highResDepth);
float accumDiff = dot(depthDiff, float4(1, 1, 1, 1));
[branch]
if (accumDiff < 1.5f)
{
//float3 uv = float3(i.uv * _HandleScales.xy,unity_StereoEyeIndex);
//return _CloudTex.Sample(sampler_CloudTex, uv);
return SAMPLE_TEXTURE2D_X_LOD(_CloudTex,sampler_CloudTex, i.uv * _HandleScales.xy, 0);
}
else
{
float minDepthDiff = depthDiff[0];
float2 nearestUv = i.uv00;
if (depthDiff[1] < minDepthDiff)
{
nearestUv = i.uv10;
minDepthDiff = depthDiff[1];
}
if (depthDiff[2] < minDepthDiff)
{
nearestUv = i.uv01;
minDepthDiff = depthDiff[2];
}
if (depthDiff[3] < minDepthDiff)
{
nearestUv = i.uv11;
minDepthDiff = depthDiff[3];
}
//float3 uv = float3(nearestUv * _HandleScales.xy,unity_StereoEyeIndex);
//return _CloudTex.Sample(Point_Clamp_Sampler, uv );
return SAMPLE_TEXTURE2D_X_LOD(_CloudTex,Point_Clamp_Sampler, nearestUv * _HandleScales.xy, 0);
}
}
#endif
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 vspos = float4(i.vsray, 1.0, 1.0);
float4 worldPos = mul(_CamToWorld,vspos);
float3 viewDir = normalize(worldPos.xyz - _WorldSpaceCameraPos);
float4 sourceColor = SAMPLE_TEXTURE2D_X_LOD(_MainTex,s_trilinear_clamp_sampler, i.uv, 0);
float4 cloudsColor = float4(0,0,0,0);
#ifdef ENVIRO_DEPTH_BLENDING
cloudsColor = Upsample(i);
#else
cloudsColor = SAMPLE_TEXTURE2D_X_LOD(_CloudTex,sampler_CloudTex, i.uv * _HandleScales.xy, 0);
#endif
float4 finalColor = GetCloudColor(cloudsColor,worldPos);
finalColor.rgb *= _EnviroSkyIntensity * GetCurrentExposureMultiplier();
float rawDepth = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, i.uv * _ScreenSize.xy * (1/_RTHandleScale.xy), 0);
float sceneDepth = Linear01Depth(rawDepth, _ZBufferParams);
#if ENVIRO_DEPTH_BLENDING
float4 final = float4(sourceColor.rgb * (1 - finalColor.a) + lerp(sourceColor.rgb, finalColor.rgb, finalColor.a) * finalColor.a, 1);
#else
float4 final = sourceColor;
if (sceneDepth == 1.0f)
final = half4(sourceColor.rgb * saturate(1 - finalColor.a) + lerp(sourceColor.rgb, finalColor.rgb, finalColor.a) * finalColor.a, 1);
#endif
// HDRP Fog
/*if (sceneDepth == 1.0f)
{
PositionInputs posInput = GetPositionInput(i.vertex.xy, _ScreenSize.zw, rawDepth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
float3 V = GetSkyViewDirWS(i.uv * _ScreenSize.xy * (1/_RTHandleScale.xy));
posInput.positionWS = GetCurrentViewPosition() - V * _MaxFogDistance;
EvaluateAtmosphericScattering(posInput, V, color, opacity);
final.rgb = color + (1 - opacity) * final.rgb;
}*/
return final;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 07d27ac305a52804f8e9a42bd1cb2dc1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.2.2
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Clouds/EnviroVolumetricCloudsBlendHDRP.shader
uploadId: 766468

View File

@@ -0,0 +1,246 @@
Shader "Hidden/EnviroVolumetricCloudsBlendURP"
{
Properties
{
_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIRO_DEPTH_BLENDING
#pragma multi_compile __ ENVIROURP
#pragma multi_compile __ UNITY_COLORSPACE_GAMMA
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include_with_pragmas "../Includes/FogIncludeHLSL.hlsl"
TEXTURE2D_X(_MainTex);
SAMPLER (sampler_MainTex);
TEXTURE2D_X(_CloudTex);
SAMPLER (sampler_CloudTex);
TEXTURE2D_X_FLOAT(_DownsampledDepth);
SAMPLER (sampler_DownsampledDepth);
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER (sampler_CameraDepthTexture);
float4 _CloudTex_TexelSize;
float4 _MainTex_TexelSize;
SamplerState Point_Clamp_Sampler;
float4 _ProjectionExtents;
float4 _ProjectionExtentsRight;
float4x4 _CamToWorld;
struct appdata
{
uint vertex : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
//float4 screenPos : TEXCOORD1;
float2 vsray : TEXCOORD1;
//half3 pos : TEXCOORD2;
//#ifdef ENVIRO_DEPTH_BLENDING
float2 uv00 : TEXCOORD2;
float2 uv10 : TEXCOORD3;
float2 uv01 : TEXCOORD4;
float2 uv11 : TEXCOORD5;
//#endif
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
//o.pos = -v.vertex;
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(GetFullScreenTriangleTexCoord(v.vertex));
o.vertex = pos;
o.uv = uv;
if(unity_StereoEyeIndex == 0)
o.vsray = (2.0 * o.uv - 1.0) * _ProjectionExtents.xy + _ProjectionExtents.zw;
else
o.vsray = (2.0 * o.uv - 1.0) * _ProjectionExtentsRight.xy + _ProjectionExtentsRight.zw;
// o.screenPos = ComputeScreenPos(o.vertex);
//#ifdef ENVIRO_DEPTH_BLENDING
o.uv00 = o.uv - 0.5 * _CloudTex_TexelSize.xy;
o.uv10 = o.uv00 + float2(_CloudTex_TexelSize.x, 0.0);
o.uv01 = o.uv00 + float2(0.0, _CloudTex_TexelSize.y);
o.uv11 = o.uv00 + _CloudTex_TexelSize.xy;
//#endif
return o;
}
//#ifdef ENVIRO_DEPTH_BLENDING
float4 Upsample(v2f i)
{
float4 lowResDepth = 0.0f;
float highResDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture,i.uv).r, _ZBufferParams);
lowResDepth.x = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth,i.uv00).r, _ZBufferParams );
lowResDepth.y = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth,i.uv10).r, _ZBufferParams);
lowResDepth.z = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth,i.uv01).r, _ZBufferParams);
lowResDepth.w = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth,i.uv11).r, _ZBufferParams);
float4 depthDiff = abs(lowResDepth - highResDepth);
float accumDiff = dot(depthDiff, float4(1, 1, 1, 1));
[branch]
if (accumDiff < 1.5f)
{
return SAMPLE_TEXTURE2D_X(_CloudTex,sampler_CloudTex,i.uv);
#ifdef STEREO_INSTANCING_ON
//float3 uv = float3(i.uv,unity_StereoEyeIndex);
//return _CloudTex.Sample(sampler_CloudTex, uv);
#else
//return _CloudTex.Sample(sampler_CloudTex, i.uv);
#endif
}
else
{
float minDepthDiff = depthDiff[0];
float2 nearestUv = i.uv00;
if (depthDiff[1] < minDepthDiff)
{
nearestUv = i.uv10;
minDepthDiff = depthDiff[1];
}
if (depthDiff[2] < minDepthDiff)
{
nearestUv = i.uv01;
minDepthDiff = depthDiff[2];
}
if (depthDiff[3] < minDepthDiff)
{
nearestUv = i.uv11;
minDepthDiff = depthDiff[3];
}
return SAMPLE_TEXTURE2D_X(_CloudTex,Point_Clamp_Sampler,nearestUv);
#ifdef STEREO_INSTANCING_ON
// float3 uv = float3(UnityStereoTransformScreenSpaceTex(nearestUv),unity_StereoEyeIndex);
// return _CloudTex.Sample(Point_Clamp_Sampler, uv);
#else
// return _CloudTex.Sample(Point_Clamp_Sampler, UnityStereoTransformScreenSpaceTex(nearestUv));
#endif
}
}
//#endif
half3 LinearToGammaSpace (half3 linRGB)
{
linRGB = max(linRGB, half3(0.h, 0.h, 0.h));
return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h);
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 vspos = float4(i.vsray, 1.0, 1.0);
float4 worldPos = mul(_CamToWorld,vspos);
float3 viewDir = normalize(worldPos.xyz - _WorldSpaceCameraPos);
float4 sourceColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,i.uv);
float4 cloudsColor = Upsample(i);
float4 finalColor = GetCloudColor(cloudsColor,worldPos);
#if defined(UNITY_COLORSPACE_GAMMA)
finalColor.rgb = LinearToGammaSpace(finalColor.rgb);
#endif
#if ENVIRO_DEPTH_BLENDING
float4 final = float4(sourceColor.rgb * (1 - finalColor.a) + lerp(sourceColor.rgb, finalColor.rgb, finalColor.a) * finalColor.a, 1);
return final;
#else
float4 final = sourceColor;
float sceneDepth = Linear01Depth(SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture, i.uv).r, _ZBufferParams);
if (sceneDepth >= 0.99f)
final = float4(sourceColor.rgb * saturate(1 - finalColor.a) + lerp(sourceColor.rgb, finalColor.rgb, finalColor.a) * finalColor.a, 1);
return final;
#endif
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: ab2d55893002046489fbd7b38e564fcb
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.2.0
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Clouds/EnviroVolumetricCloudsBlendURP.shader
uploadId: 721859

View File

@@ -0,0 +1,152 @@
Shader "Hidden/EnviroVolumetricCloudsDepth"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
//Pass 1 downsample
Pass
{
Cull Off ZWrite Off ZTest Always
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#include "UnityCG.cginc"
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float4 _CameraDepthTexture_TexelSize;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float2 uv00 : TEXCOORD1;
float2 uv10 : TEXCOORD2;
float2 uv01 : TEXCOORD3;
float2 uv11 : TEXCOORD4;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.uv;
o.uv00 = v.uv - 0.5 * _CameraDepthTexture_TexelSize.xy;
o.uv10 = o.uv00 + float2(_CameraDepthTexture_TexelSize.x, 0.0);
o.uv01 = o.uv00 + float2(0.0, _CameraDepthTexture_TexelSize.y);
o.uv11 = o.uv00 + _CameraDepthTexture_TexelSize.xy;
return o;
}
float frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 depth;
depth[0] = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,UnityStereoTransformScreenSpaceTex(i.uv00));
depth[1] = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,UnityStereoTransformScreenSpaceTex(i.uv10));
depth[2] = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,UnityStereoTransformScreenSpaceTex(i.uv01));
depth[3] = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,UnityStereoTransformScreenSpaceTex(i.uv11));
return min(depth[0], min(depth[1], min(depth[2], depth[3])));
//float minDepth = min(min(depth[0], depth[1]), min(depth[2], depth[3]));
//float maxDepth = max(max(depth[0], depth[1]), max(depth[2], depth[3]));
// chessboard pattern
//int2 position = i.vertex.xy % 2;
//int index = position.x + position.y;
//return index == 1 ? minDepth : maxDepth;
//return minDepth;
}
ENDCG
}
//Pass 2 Copy
Pass
{
Cull Off ZWrite Off ZTest Always
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#include "UnityCG.cginc"
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.uv;
return o;
}
float frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,UnityStereoTransformScreenSpaceTex(i.uv));
}
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 71e0f599e0918df47984cb778c0f336d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroVolumetricCloudsDepth.shader
uploadId: 660896

View File

@@ -0,0 +1,207 @@
Shader "Hidden/EnviroVolumetricCloudsDepthHDRP"
{
Properties
{
// _CameraDepthTexture ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
//Pass 1 downsample
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROHDRP
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
float4 _CameraDepthTexture_TexelSize;
struct appdata
{
uint vertexID : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float2 uv00 : TEXCOORD1;
float2 uv10 : TEXCOORD2;
float2 uv01 : TEXCOORD3;
float2 uv11 : TEXCOORD4;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
o.uv00 = o.uv - 0.5 * _CameraDepthTexture_TexelSize.xy; //v.uv
o.uv10 = o.uv00 + float2(_CameraDepthTexture_TexelSize.x, 0.0);
o.uv01 = o.uv00 + float2(0.0, _CameraDepthTexture_TexelSize.y);
o.uv11 = o.uv00 + _CameraDepthTexture_TexelSize.xy;
return o;
}
float frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
uint2 positionSS = i.uv * _ScreenSize.xy;
float4 depth;
depth[0] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv00 * _ScreenSize.xy,0);
depth[1] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv10 * _ScreenSize.xy,0);
depth[2] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv01 * _ScreenSize.xy,0);
depth[3] = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture,i.uv11 * _ScreenSize.xy,0);
return min(depth[0], min(depth[1], min(depth[2], depth[3])));
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
//Pass 2 Copy
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROHDRP
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
struct appdata
{
uint vertexID : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
return o;
}
float frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
return LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, i.uv * _ScreenSize.xy,0);
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: e6c0cbdf098c32c4180a97e54fb4e65f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroVolumetricCloudsDepthHDRP.shader
uploadId: 660896

View File

@@ -0,0 +1,206 @@
Shader "Hidden/EnviroVolumetricCloudsDepthURP"
{
Properties
{
_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
//Pass 1 downsample
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER (sampler_CameraDepthTexture);
float4 _CameraDepthTexture_TexelSize;
struct appdata
{
uint vertex : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float2 uv00 : TEXCOORD1;
float2 uv10 : TEXCOORD2;
float2 uv01 : TEXCOORD3;
float2 uv11 : TEXCOORD4;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.vertex = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
o.uv00 = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv) - 0.5 * _CameraDepthTexture_TexelSize.xy;
o.uv10 = o.uv00 + float2(_CameraDepthTexture_TexelSize.x, 0.0);
o.uv01 = o.uv00 + float2(0.0, _CameraDepthTexture_TexelSize.y);
o.uv11 = o.uv00 + _CameraDepthTexture_TexelSize.xy;
return o;
}
float frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 depth;
depth[0] = SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture,i.uv00).r;
depth[1] = SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture,i.uv10).r;
depth[2] = SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture,i.uv01).r;
depth[3] = SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture,i.uv11).r;
return min(depth[0], min(depth[1], min(depth[2], depth[3])));
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
//Pass 2 Copy
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER (sampler_CameraDepthTexture);
struct appdata
{
uint vertex : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.vertex = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
return o;
}
float frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
return SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture,i.uv).r;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1da04d3fc0c7564499831a8c8ad259ae
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,126 @@
Shader "Hidden/EnviroCloudsRaymarch"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local _ ENVIRO_DEPTH_BLENDING
#pragma multi_compile_local _ ENVIRO_CLOUD_SHADOWS
#pragma multi_compile_local _ ENVIRO_LIGHTNING
#pragma multi_compile_local _ ENVIRO_VARIABLE_BOTTOM
#pragma multi_compile _ ENVIROURP
#include "UnityCG.cginc"
#include_with_pragmas "../Includes/VolumetricCloudsInclude.cginc"
#include_with_pragmas "../Includes/VolumetricCloudsTexInclude.cginc"
int _Frame;
uniform float _BlueNoiseIntensity;
float4 _CameraDepthTexture_TexelSize;
struct v2f
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv00 : TEXCOORD1;
float2 uv10 : TEXCOORD2;
float2 uv01 : TEXCOORD3;
float2 uv11 : TEXCOORD4;
UNITY_VERTEX_OUTPUT_STEREO
};
struct appdata
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
v2f vert (appdata_img v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.position = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.position.y *= -1;
#endif
#else
o.position = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord;
o.uv00 = v.texcoord - 0.5 * _CameraDepthTexture_TexelSize.xy;
o.uv10 = o.uv00 + float2(_CameraDepthTexture_TexelSize.x, 0.0);
o.uv01 = o.uv00 + float2(0.0, _CameraDepthTexture_TexelSize.y);
o.uv11 = o.uv00 + _CameraDepthTexture_TexelSize.xy;
return o;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 cameraRay = float4(i.uv * 2.0 - 1.0, 1.0, 1.0);
float3 EyePosition = _CameraPosition;
float3 ray = 0;
if (unity_StereoEyeIndex == 0)
{
cameraRay = mul(_InverseProjection, cameraRay);
cameraRay = cameraRay / cameraRay.w;
ray = normalize(mul((float3x3)_InverseRotation, cameraRay.xyz));
}
else
{
cameraRay = mul(_InverseProjectionRight, cameraRay);
cameraRay = cameraRay / cameraRay.w;
ray = normalize(mul((float3x3)_InverseRotationRight, cameraRay.xyz));
}
float rayLength = length(ray);
float sceneDepth = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DownsampledDepth, UnityStereoTransformScreenSpaceTex(i.uv));
float3 cameraDirection = -1 * transpose(_InverseRotation)[2].xyz;
float fwdFactor = dot(ray, cameraDirection);
float raymarchEnd = GetRaymarchEndFromSceneDepth(Linear01Depth(sceneDepth) / fwdFactor, 1000000);
float offset = tex2D(_BlueNoise, squareUV(i.uv + _Randomness.xy)).x * _BlueNoiseIntensity;
float3 pCent = float3(EyePosition.x, -_CloudsParameter.w, EyePosition.z);
float intensity, distance, alpha, shadow = 0.0f;
RaymarchParameters parameters;
InitRaymarchParameters(parameters);
float2 hitDistance = ResolveRay(EyePosition,ray,pCent,raymarchEnd,parameters);
float3 result = Raymarch(EyePosition,ray,hitDistance,pCent,parameters,offset);
#if ENVIRO_CLOUD_SHADOWS
float3 wpos = CalculateWorldPosition(i.uv,sceneDepth) - _WorldOffset;
shadow = RaymarchShadows(EyePosition,wpos,ray,pCent,parameters,offset,sceneDepth);
#endif
intensity = result.r;
distance = result.g;
alpha = result.b;
return float4(max(intensity,0.0),max(distance,1.0f),clamp(shadow,0.0,0.25),saturate(alpha));
}
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 9fcc6e1c98c66ff4684678733f05a424
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroVolumetricCloudsRaymarch.shader
uploadId: 660896

View File

@@ -0,0 +1,148 @@
Shader "Hidden/EnviroCloudsRaymarchHDRP"
{
Properties
{
}
SubShader
{
//Tags { "RenderType"="Opaque" }
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local _ ENVIRO_DEPTH_BLENDING
#pragma multi_compile_local _ ENVIRO_CLOUD_SHADOWS
#pragma multi_compile_local _ ENVIRO_LIGHTNING
#pragma multi_compile_local _ ENVIRO_VARIABLE_BOTTOM
#pragma multi_compile __ ENVIROHDRP
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
#include_with_pragmas "../Includes/VolumetricCloudsInclude.cginc"
#include_with_pragmas "../Includes/VolumetricCloudsTexHDRPInclude.cginc"
int _Frame;
uniform float _BlueNoiseIntensity;
uniform float4 _DepthHandleScale;
struct appdata
{
uint vertexID : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.position = GetFullScreenTriangleVertexPosition(v.vertexID);
o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
return o;
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
// uint2 positionSS = i.uv * _ScreenSize.xy;
float4 cameraRay = float4(i.uv * 2.0 - 1.0, 1.0, 1.0);
float3 EyePosition = _CameraPosition;
float3 ray = 0;
//if (unity_StereoEyeIndex == 0)
//{
cameraRay = mul(_InverseProjection, cameraRay);
cameraRay = cameraRay / cameraRay.w;
ray = normalize(mul((float3x3)_InverseRotation, cameraRay.xyz));
//}
//else
// {
// cameraRay = mul(_InverseProjectionRight, cameraRay);
// cameraRay = cameraRay / cameraRay.w;
// ray = normalize(mul((float3x3)_InverseRotationRight, cameraRay.xyz));
//}
float rayLength = length(ray);
float sceneDepth = LOAD_TEXTURE2D_X(_DownsampledDepth, i.uv * _DepthHandleScale.zw);
//float sceneDepth = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, i.uv * _ScreenSize.xy, 0);
float raymarchEnd = GetRaymarchEndFromSceneDepth(Linear01Depth(sceneDepth, _ZBufferParams), 1000000); //* rayLenght
float offset = tex2D(_BlueNoise, squareUV(i.uv + _Randomness.xy)).x * _BlueNoiseIntensity;
float3 pCent = float3(EyePosition.x, -_CloudsParameter.w, EyePosition.z);
float intensity, distance, alpha, shadow = 0.0f;
RaymarchParameters parameters;
InitRaymarchParameters(parameters);
float2 hitDistance = ResolveRay(EyePosition,ray,pCent,raymarchEnd,parameters);
float3 result = Raymarch(EyePosition,ray,hitDistance,pCent,parameters,offset);
#if ENVIRO_CLOUD_SHADOWS
float3 wpos = CalculateWorldPosition(i.uv,sceneDepth) - _WorldOffset;
shadow = RaymarchShadows(EyePosition,wpos,ray,pCent,parameters,offset,sceneDepth);
#endif
intensity = result.r;
distance = result.g;
alpha = result.b;
return float4(max(intensity,0.0),max(distance,1.0f),clamp(shadow,0.0,0.25),saturate(alpha));
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 83cb7b07c4a4dd24c91671effd1a1b09
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroVolumetricCloudsRaymarchHDRP.shader
uploadId: 660896

View File

@@ -0,0 +1,150 @@
Shader "Hidden/EnviroCloudsRaymarchURP"
{
Properties
{
_MainTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local _ ENVIRO_DEPTH_BLENDING
#pragma multi_compile_local _ ENVIRO_CLOUD_SHADOWS
#pragma multi_compile_local _ ENVIRO_LIGHTNING
#pragma multi_compile_local _ ENVIRO_VARIABLE_BOTTOM
#pragma multi_compile _ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include_with_pragmas "../Includes/VolumetricCloudsInclude.cginc"
#include_with_pragmas "../Includes/VolumetricCloudsTexURPInclude.cginc"
int _Frame;
uniform float _BlueNoiseIntensity;
struct v2f
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
struct appdata
{
uint vertex : SV_VertexID;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
// UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.position = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
return o;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float4 cameraRay = float4(i.uv * 2.0 - 1.0, 1.0, 1.0);
float3 EyePosition = _CameraPosition;
float3 ray = 0;
if (unity_StereoEyeIndex == 0)
{
cameraRay = mul(_InverseProjection, cameraRay);
cameraRay = cameraRay / cameraRay.w;
ray = normalize(mul((float3x3)_InverseRotation, cameraRay.xyz));
}
else
{
cameraRay = mul(_InverseProjectionRight, cameraRay);
cameraRay = cameraRay / cameraRay.w;
ray = normalize(mul((float3x3)_InverseRotationRight, cameraRay.xyz));
}
float rayLength = length(ray);
float sceneDepth = SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth, i.uv);
float3 cameraDirection = -1 * transpose(_InverseRotation)[2].xyz;
float fwdFactor = dot(ray, cameraDirection);
float raymarchEnd = GetRaymarchEndFromSceneDepth(Linear01Depth(sceneDepth, _ZBufferParams) / fwdFactor, 1000000); //* rayLenght
float offset = tex2D(_BlueNoise, squareUV(i.uv + _Randomness.xy)).x * _BlueNoiseIntensity;
float3 pCent = float3(EyePosition.x, -_CloudsParameter.w, EyePosition.z);
float intensity, distance, alpha, shadow = 0.0f;
RaymarchParameters parameters;
InitRaymarchParameters(parameters);
float2 hitDistance = ResolveRay(EyePosition,ray,pCent,raymarchEnd,parameters);
float3 result = Raymarch(EyePosition,ray,hitDistance,pCent,parameters,offset);
#if ENVIRO_CLOUD_SHADOWS
float3 wpos = CalculateWorldPosition(i.uv,sceneDepth) - _WorldOffset;
shadow = RaymarchShadows(EyePosition,wpos,ray,pCent,parameters,offset,sceneDepth);
#endif
intensity = result.r;
distance = result.g;
alpha = result.b;
return float4(max(intensity,0.0),max(distance,1.0f),clamp(shadow,0.0,0.25),saturate(alpha));
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a4455315341b379429a123aa5b2edd2a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,186 @@
Shader "Hidden/EnviroVolumetricCloudsReproject"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ ENVIRO_DEPTH_BLENDING
#pragma multi_compile _ ENVIROURP
#include "UnityCG.cginc"
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
float4 _MainTex_TexelSize;
UNITY_DECLARE_SCREENSPACE_TEXTURE(_UndersampleCloudTex);
float4 _UndersampleCloudTex_TexelSize;
UNITY_DECLARE_SCREENSPACE_TEXTURE(_DownsampledDepth);
float4x4 _PrevVP;
float4x4 _CamToWorld;
//float4x4 _CamProjection;
float4 _ProjectionExtents;
float4 _ProjectionExtentsRight;
float2 _TexelSize;
float _BlendTime;
float3 _WorldOffset;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float2 ray : TEXCOORD1;
// float4 screenPos : TEXCOORD2;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.uv;
if(unity_StereoEyeIndex == 0)
o.ray = (2.0 * v.uv - 1.0) * _ProjectionExtents.xy + _ProjectionExtents.zw;
else
o.ray = (2.0 * v.uv - 1.0) * _ProjectionExtentsRight.xy + _ProjectionExtentsRight.zw;
// o.screenPos = ComputeScreenPos(o.vertex);
return o;
}
float2 PrevUV(float4 wspos, out half outOfBound)
{
float4 prevClip = mul(_PrevVP, wspos);
prevClip.xy /= prevClip.w;
prevClip.xy = prevClip.xy * 0.5 + 0.5;
half oobmax = max(0.0 - prevClip.x, 0.0 - prevClip.y);
half oobmin = max(prevClip.x - 1.0, prevClip.y - 1.0);
outOfBound = step(0, max(oobmin, oobmax));
return prevClip.xy;
}
float4 ClipAABB(float4 aabbMin, float4 aabbMax, float4 prevSample)
{
float4 p_clip = 0.5 * (aabbMax + aabbMin);
float4 e_clip = 0.5 * (aabbMax - aabbMin);
float4 v_clip = prevSample - p_clip;
float4 v_unit = v_clip / e_clip;
float4 a_unit = abs(v_unit);
float ma_unit = max(max(a_unit.x, max(a_unit.y, a_unit.z)), a_unit.w);
if (ma_unit > 1.0)
return p_clip + v_clip / ma_unit;
else
return prevSample;
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float3 vspos = float3(i.ray, 1.0);
float4 raymarchResult = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_UndersampleCloudTex,UnityStereoTransformScreenSpaceTex(i.uv));
float distance = raymarchResult.y;
// float intensity = raymarchResult.x;
half outOfBound;
float4 worldPos = mul(_CamToWorld, float4(normalize(vspos) * distance, 1.0));
worldPos /= worldPos.w;
//worldPos.xyz -= _WorldOffset;
float2 prevUV = PrevUV(worldPos, outOfBound);
{
float4 prevSample = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoTransformScreenSpaceTex(prevUV));
float4 m1 = float4(0.0f,0.0f,0.0f,0.0f);
float4 m2 = float4(0.0f,0.0f,0.0f,0.0f);
float sampleCount = 1.0f;
float originalPointDepth = LinearEyeDepth(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DownsampledDepth, UnityStereoTransformScreenSpaceTex(i.uv)));
[unroll]
for (int x = -1; x <= 1; x ++)
{
[unroll]
for (int y = -1; y <= 1; y ++ )
{
float4 val;
if (x == 0 && y == 0)
{
val = raymarchResult;
m1 += val;
m2 += val * val;
}
else
{
float2 uv = i.uv + float2(x * _UndersampleCloudTex_TexelSize.x, y * _UndersampleCloudTex_TexelSize.y);
val = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_UndersampleCloudTex, UnityStereoTransformScreenSpaceTex(uv));
float depth = LinearEyeDepth(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DownsampledDepth,UnityStereoTransformScreenSpaceTex(uv)));
if (abs(originalPointDepth - depth) < (pow(max(1, depth), 1.5f) / 500.0f))
{
m1 += val;
m2 += val * val;
sampleCount += 1.0f;
}
}
}
}
float gamma = _BlendTime;
float4 mu = m1 / sampleCount;
float4 sigma = sqrt(abs(m2 / sampleCount - mu * mu));
float4 minc = mu - gamma * sigma;
float4 maxc = mu + gamma * sigma;
prevSample = ClipAABB(minc, maxc, prevSample);
//Blend.
raymarchResult = lerp(prevSample, raymarchResult, max(0.001f, outOfBound));
}
return raymarchResult;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 83e3f6f2f3eed864ebae27ea7987d19b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroVolumetricCloudsReproject.shader
uploadId: 660896

View File

@@ -0,0 +1,227 @@
Shader "Hidden/EnviroVolumetricCloudsReprojectHDRP"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ ENVIRO_DEPTH_BLENDING
#pragma multi_compile __ ENVIROHDRP
#pragma target 4.5
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
TEXTURE2D_X(_MainTex);
SAMPLER(sampler_MainTex);
float4 _MainTex_TexelSize;
TEXTURE2D_X(_UndersampleCloudTex);
SAMPLER(sampler_UndersampleCloudTex);
float4 _UndersampleCloudTex_TexelSize;
TEXTURE2D_X(_DownsampledDepth);
SAMPLER(sampler_DownsampledDepth);
float4x4 _PrevVP;
float4x4 _CamToWorld;
float4 _ProjectionExtents;
float4 _ProjectionExtentsRight;
float2 _TexelSize;
float _BlendTime;
float3 _WorldOffset;
uniform float4 _DepthHandleScale;
uniform float4 _UndersampleCloudTexScale;
uniform float4 _MainTexHandleScale;
struct appdata
{
uint vertexID : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float2 ray : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
if(unity_StereoEyeIndex == 0)
o.ray = (2.0 * o.uv * _RTHandleScale.xy - 1.0) * _ProjectionExtents.xy + _ProjectionExtents.zw;
else
o.ray = (2.0 * o.uv * _RTHandleScale.xy - 1.0) * _ProjectionExtentsRight.xy + _ProjectionExtentsRight.zw;
return o;
}
float2 PrevUV(float4 wspos, out half outOfBound)
{
float4 prevClip = mul(_PrevVP, wspos);
prevClip.xy /= prevClip.w;
prevClip.xy = prevClip.xy * 0.5 + 0.5;
half oobmax = max(0.0 - prevClip.x, 0.0 - prevClip.y);
half oobmin = max(prevClip.x - 1.0, prevClip.y - 1.0);
outOfBound = step(0, max(oobmin, oobmax));
return prevClip.xy;
}
float4 ClipAABB(float4 aabbMin, float4 aabbMax, float4 prevSample)
{
float4 p_clip = 0.5 * (aabbMax + aabbMin);
float4 e_clip = 0.5 * (aabbMax - aabbMin);
float4 v_clip = prevSample - p_clip;
float4 v_unit = v_clip / e_clip;
float4 a_unit = abs(v_unit);
float ma_unit = max(max(a_unit.x, max(a_unit.y, a_unit.z)), a_unit.w);
if (ma_unit > 1.0)
return p_clip + v_clip / ma_unit;
else
return prevSample;
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float3 vspos = float3(i.ray, 1.0);
float4 raymarchResult = SAMPLE_TEXTURE2D_X(_UndersampleCloudTex,sampler_UndersampleCloudTex, i.uv);
float distance = raymarchResult.y;
//float intensity = raymarchResult.x;
half outOfBound;
float4 worldPos = mul(_CamToWorld, float4(normalize(vspos) * distance, 1.0));
worldPos /= worldPos.w;
//worldPos.xyz -= _WorldOffset;
float2 prevUV = PrevUV(worldPos, outOfBound);
{
float4 prevSample = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex, prevUV * _MainTexHandleScale.xy );
float4 m1 = float4(0.0f,0.0f,0.0f,0.0f);
float4 m2 = float4(0.0f,0.0f,0.0f,0.0f);
float sampleCount = 1.0f;
float originalPointDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth, i.uv * _DepthHandleScale.xy).r, _ZBufferParams);
[unroll]
for (int x = -1; x <= 1; x ++)
{
[unroll]
for (int y = -1; y <= 1; y ++ )
{
float4 val;
if (x == 0 && y == 0)
{
val = raymarchResult;
m1 += val;
m2 += val * val;
}
else
{
float2 uv = i.uv + float2(x * _UndersampleCloudTex_TexelSize.x, y * _UndersampleCloudTex_TexelSize.y);
val = SAMPLE_TEXTURE2D_X(_UndersampleCloudTex,sampler_UndersampleCloudTex, uv);
float depth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth,uv * _DepthHandleScale.xy).r, _ZBufferParams);
if (abs(originalPointDepth - depth) < (pow(max(1, depth), 1.5f) / 500.0f))
{
m1 += val;
m2 += val * val;
sampleCount += 1.0f;
}
}
}
}
float gamma = _BlendTime;
float4 mu = m1 / sampleCount;
float4 sigma = sqrt(abs(m2 / sampleCount - mu * mu));
float4 minc = mu - gamma * sigma;
float4 maxc = mu + gamma * sigma;
prevSample = ClipAABB(minc, maxc, prevSample);
//Blend
raymarchResult = lerp(prevSample, raymarchResult, max(0.001f, outOfBound));
}
return raymarchResult;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 81afbae9e0be32648a45d6acd2db0f7b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Clouds/EnviroVolumetricCloudsReprojectHDRP.shader
uploadId: 660896

View File

@@ -0,0 +1,222 @@
Shader "Hidden/EnviroVolumetricCloudsReprojectURP"
{
Properties
{
_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Cull Off ZWrite Off ZTest Always
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ ENVIRO_DEPTH_BLENDING
#pragma multi_compile _ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
float4 _MainTex_TexelSize;
float4 _UndersampleCloudTex_TexelSize;
TEXTURE2D_X(_MainTex);
SAMPLER (sampler_MainTex);
TEXTURE2D_X(_UndersampleCloudTex);
SAMPLER (sampler_UndersampleCloudTex);
TEXTURE2D_X_FLOAT(_DownsampledDepth);
SAMPLER (sampler_DownsampledDepth);
float4x4 _PrevVP;
float4x4 _CamToWorld;
float4 _ProjectionExtents;
float4 _ProjectionExtentsRight;
float2 _TexelSize;
float _BlendTime;
float3 _WorldOffset;
struct appdata
{
uint vertex : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float2 ray : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.vertex = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
if(unity_StereoEyeIndex == 0)
o.ray = (2.0 * o.uv - 1.0) * _ProjectionExtents.xy + _ProjectionExtents.zw;
else
o.ray = (2.0 * o.uv - 1.0) * _ProjectionExtentsRight.xy + _ProjectionExtentsRight.zw;
return o;
}
float2 PrevUV(float4 wspos, out half outOfBound)
{
float4 prevClip = mul(_PrevVP, wspos);
prevClip.xy /= prevClip.w;
prevClip.xy = prevClip.xy * 0.5 + 0.5;
half oobmax = max(0.0 - prevClip.x, 0.0 - prevClip.y);
half oobmin = max(prevClip.x - 1.0, prevClip.y - 1.0);
outOfBound = step(0, max(oobmin, oobmax));
return prevClip.xy;
}
float4 ClipAABB(float4 aabbMin, float4 aabbMax, float4 prevSample)
{
float4 p_clip = 0.5 * (aabbMax + aabbMin);
float4 e_clip = 0.5 * (aabbMax - aabbMin);
float4 v_clip = prevSample - p_clip;
float4 v_unit = v_clip / e_clip;
float4 a_unit = abs(v_unit);
float ma_unit = max(max(a_unit.x, max(a_unit.y, a_unit.z)), a_unit.w);
if (ma_unit > 1.0)
return p_clip + v_clip / ma_unit;
else
return prevSample;
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float3 vspos = float3(i.ray, 1.0);
float4 raymarchResult = SAMPLE_TEXTURE2D_X(_UndersampleCloudTex, sampler_UndersampleCloudTex, i.uv);
float distance = raymarchResult.y;
// float intensity = raymarchResult.x;
half outOfBound;
float4 worldPos = mul(_CamToWorld, float4(normalize(vspos) * distance, 1.0));
worldPos /= worldPos.w;
//worldPos.xyz -= _WorldOffset;
float2 prevUV = PrevUV(worldPos, outOfBound);
{
float4 prevSample = SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, prevUV);
float4 m1 = float4(0.0f,0.0f,0.0f,0.0f);
float4 m2 = float4(0.0f,0.0f,0.0f,0.0f);
float sampleCount = 1.0f;
float originalPointDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth, sampler_DownsampledDepth,i.uv).r, _ZBufferParams);
[unroll]
for (int x = -1; x <= 1; x ++)
{
[unroll]
for (int y = -1; y <= 1; y ++ )
{
float4 val;
if (x == 0 && y == 0)
{
val = raymarchResult;
m1 += val;
m2 += val * val;
}
else
{
float2 uv = i.uv + float2(x * _UndersampleCloudTex_TexelSize.x, y * _UndersampleCloudTex_TexelSize.y);
val = SAMPLE_TEXTURE2D_X(_UndersampleCloudTex,sampler_UndersampleCloudTex, uv);
float depth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(_DownsampledDepth,sampler_DownsampledDepth,uv).r, _ZBufferParams);
if (abs(originalPointDepth - depth) < (pow(max(1, depth), 1.5f) / 500.0f))
{
m1 += val;
m2 += val * val;
sampleCount += 1.0f;
}
}
}
}
float gamma = _BlendTime;
float4 mu = m1 / sampleCount;
float4 sigma = sqrt(abs(m2 / sampleCount - mu * mu));
float4 minc = mu - gamma * sigma;
float4 maxc = mu + gamma * sigma;
prevSample = ClipAABB(minc, maxc, prevSample);
//Blend.
raymarchResult = lerp(prevSample, raymarchResult, max(0.001f, outOfBound));
}
return raymarchResult;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: c02e7540e49837249960828b7291a14e
ShaderImporter:
externalObjects: {}
defaultTextures:
- _MainTex: {instanceID: 0}
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
Shader "Enviro3/Standard/WeatherTexture"
{
Properties
{
_Coverage ("Coverage", Range(0,1)) = 0.5
_Tiling ("Tiling", Range(1,100)) = 10
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "../Includes/NoiseInclude.cginc"
#pragma target 3.0
#pragma exclude_renderers gles
sampler2D _MainTex;
struct VertexInput
{
half4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct VertexOutput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
VertexOutput vert (appdata_img v)
{
VertexOutput o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord;
return o;
}
float4x4 world_view_proj;
float _CoverageLayer1;
float _CloudsTypeLayer1;
float _WorleyFreq1Layer1;
float _WorleyFreq2Layer1;
float _DilateCoverageLayer1;
float _DilateTypeLayer1;
float _CloudsTypeModifierLayer1;
float4 _LocationOffset;
float3 _WindDirectionLayer1;
float4 frag(VertexInput input) : SV_Target
{
float2 uv = input.uv;
float2 windOffsetLayer1 = _WindDirectionLayer1.xy;
//float2 fillerUV = uv.xy + windOffsetLayer1 + _LocationOffset.xy;
//float covFiller = WorleyFBM2D(fillerUV,2,0.75) * 0.8;
int freq1 = _WorleyFreq1Layer1;
int freq2 = _WorleyFreq2Layer1;
//Worley Noise
float worley1Layer1 = WorleyFBM2D((windOffsetLayer1 + _LocationOffset.xy + uv.xy), freq1, 1.4);
float worley2Layer1 = WorleyFBM2D((windOffsetLayer1 + _LocationOffset.xy + uv.xy), freq2, 2.2);
float dilateCoverageLayer1 = lerp(worley1Layer1,worley2Layer1,_DilateCoverageLayer1);
//Coverage Layer
float coverageLayer1 = saturate(dilateCoverageLayer1 + ((1-dilateCoverageLayer1) * _CoverageLayer1));
float dilateTypeLayer1 = (pow(lerp(worley1Layer1,worley2Layer1,_DilateTypeLayer1),0.5) - 0.1) * 0.65;
float typeLayer1 = saturate(dilateTypeLayer1 * _CloudsTypeModifierLayer1);
float topClouds = saturate(pow((worley2Layer1) * worley1Layer1,1.5) + pow(worley1Layer1,_CoverageLayer1 * 2));
return float4(coverageLayer1,typeLayer1,topClouds,pow(topClouds,0.5));
}
ENDCG
}
}
FallBack "Diffuse"
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 934edb0dc23e1614da34f81363ce736c
timeCreated: 1507124107
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/Clouds/EnviroWeatherMap.shader
uploadId: 660896

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2bf24deacf03eb844ac04aa9defc32fd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,812 @@
// Copyright(c) 2016, Michal Skalsky
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Shader "Hidden/EnviroBlur"
{
Properties
{
//_MainTex("Texture", any) = "" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
CGINCLUDE
//--------------------------------------------------------------------------------------------
// Downsample, bilateral blur and upsample config
//--------------------------------------------------------------------------------------------
// method used to downsample depth buffer: 0 = min; 1 = max; 2 = min/max in chessboard pattern
#define DOWNSAMPLE_DEPTH_MODE 2
#define UPSAMPLE_DEPTH_THRESHOLD 1.5f
#define BLUR_DEPTH_FACTOR 0.5
#define GAUSS_BLUR_DEVIATION 1.5
#define FULL_RES_BLUR_KERNEL_SIZE 7
#define HALF_RES_BLUR_KERNEL_SIZE 5
#define QUARTER_RES_BLUR_KERNEL_SIZE 6
//--------------------------------------------------------------------------------------------
#define PI 3.1415927f
#include "UnityCG.cginc"
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
UNITY_DECLARE_TEX2DARRAY(_CameraDepthTexture);
UNITY_DECLARE_TEX2DARRAY(_HalfResDepthBuffer);
UNITY_DECLARE_TEX2DARRAY(_QuarterResDepthBuffer);
UNITY_DECLARE_TEX2DARRAY(_HalfResColor);
UNITY_DECLARE_TEX2DARRAY(_QuarterResColor);
UNITY_DECLARE_TEX2DARRAY(_MainTex);
#else
UNITY_DECLARE_TEX2D(_CameraDepthTexture);
UNITY_DECLARE_TEX2D(_HalfResDepthBuffer);
UNITY_DECLARE_TEX2D(_QuarterResDepthBuffer);
UNITY_DECLARE_TEX2D(_HalfResColor);
UNITY_DECLARE_TEX2D(_QuarterResColor);
UNITY_DECLARE_TEX2D(_MainTex);
#endif
float4 _MainTex_TexelSize;
float4 _CameraDepthTexture_TexelSize;
float4 _HalfResDepthBuffer_TexelSize;
float4 _QuarterResDepthBuffer_TexelSize;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
struct v2fDownsample
{
#if SHADER_TARGET > 40
float2 uv : TEXCOORD0;
#else
float2 uv00 : TEXCOORD0;
float2 uv01 : TEXCOORD1;
float2 uv10 : TEXCOORD2;
float2 uv11 : TEXCOORD3;
#endif
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
struct v2fUpsample
{
float2 uv : TEXCOORD0;
float2 uv00 : TEXCOORD1;
float2 uv01 : TEXCOORD2;
float2 uv10 : TEXCOORD3;
float2 uv11 : TEXCOORD4;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.uv;
return o;
}
//-----------------------------------------------------------------------------------------
// vertDownsampleDepth
//-----------------------------------------------------------------------------------------
v2fDownsample vertDownsampleDepth(appdata v, float2 texelSize)
{
v2fDownsample o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2fDownsample, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
#if SHADER_TARGET > 40
o.uv = v.uv;
#else
o.uv00 = v.uv - 0.5 * texelSize.xy;
o.uv10 = o.uv00 + float2(texelSize.x, 0);
o.uv01 = o.uv00 + float2(0, texelSize.y);
o.uv11 = o.uv00 + texelSize.xy;
#endif
return o;
}
//-----------------------------------------------------------------------------------------
// vertUpsample
//-----------------------------------------------------------------------------------------
v2fUpsample vertUpsample(appdata v, float2 texelSize)
{
v2fUpsample o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2fUpsample, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.vertex = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.vertex.y *= -1;
#endif
#else
o.vertex = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.uv;
o.uv00 = v.uv - 0.5 * texelSize.xy;
o.uv10 = o.uv00 + float2(texelSize.x, 0);
o.uv01 = o.uv00 + float2(0, texelSize.y);
o.uv11 = o.uv00 + texelSize.xy;
return o;
}
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
float4 SampleTexture(Texture2DArray tex, SamplerState samplerState, float2 uv)
{
//return UNITY_SAMPLE_TEX2DARRAY(tex, float3((uv).xy, (float)unity_StereoEyeIndex));
//return UNITY_SAMPLE_TEX2DARRAY_SAMPLER(tex,samplerState,uv);
return tex.Sample(samplerState, float3((uv).xy, (float)unity_StereoEyeIndex));
}
//-----------------------------------------------------------------------------------------
// BilateralUpsample
//-----------------------------------------------------------------------------------------
float4 BilateralUpsample(v2fUpsample input, Texture2DArray hiDepth, Texture2DArray loDepth, Texture2DArray loColor, SamplerState linearSampler, SamplerState pointSampler)
{
const float threshold = UPSAMPLE_DEPTH_THRESHOLD;
// float4 highResDepth = LinearEyeDepth(hiDepth.Sample(pointSampler, input.uv)).xxxx;
float4 highResDepth = LinearEyeDepth(SampleTexture(hiDepth, pointSampler, input.uv)).xxxx;
float4 lowResDepth;
lowResDepth[0] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv00));
lowResDepth[1] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv10));
lowResDepth[2] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv01));
lowResDepth[3] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv11));
float4 depthDiff = abs(lowResDepth - highResDepth);
float accumDiff = dot(depthDiff, float4(1, 1, 1, 1));
[branch]
if (accumDiff < threshold) // small error, not an edge -> use bilinear filter
{
return SampleTexture(loColor,linearSampler,input.uv);
}
// find nearest sample
float minDepthDiff = depthDiff[0];
float2 nearestUv = input.uv00;
if (depthDiff[1] < minDepthDiff)
{
nearestUv = input.uv10;
minDepthDiff = depthDiff[1];
}
if (depthDiff[2] < minDepthDiff)
{
nearestUv = input.uv01;
minDepthDiff = depthDiff[2];
}
if (depthDiff[3] < minDepthDiff)
{
nearestUv = input.uv11;
minDepthDiff = depthDiff[3];
}
return SampleTexture(loColor,pointSampler,nearestUv);
}
//-----------------------------------------------------------------------------------------
// DownsampleDepth
//-----------------------------------------------------------------------------------------
float DownsampleDepth(v2fDownsample input, Texture2DArray depthTexture, SamplerState depthSampler)
{
#if SHADER_TARGET > 40
float4 depth = depthTexture.Gather(depthSampler, input.uv);
#else
float4 depth;
depth.x = SampleTexture(depthTexture,depthSampler,input.uv00).x;
depth.y = SampleTexture(depthTexture,depthSampler,input.uv01).x;
depth.z = SampleTexture(depthTexture,depthSampler,input.uv10).x;
depth.w = SampleTexture(depthTexture,depthSampler,input.uv11).x;
#endif
#if DOWNSAMPLE_DEPTH_MODE == 0 // min depth
return min(min(depth.x, depth.y), min(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 1 // max depth
return max(max(depth.x, depth.y), max(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 2 // min/max depth in chessboard pattern
float minDepth = min(min(depth.x, depth.y), min(depth.z, depth.w));
float maxDepth = max(max(depth.x, depth.y), max(depth.z, depth.w));
// chessboard pattern
int2 position = input.vertex.xy % 2;
int index = position.x + position.y;
return index == 1 ? minDepth : maxDepth;
#endif
}
//-----------------------------------------------------------------------------------------
// GaussianWeight
//-----------------------------------------------------------------------------------------
float GaussianWeight(float offset, float deviation)
{
float weight = 1.0f / sqrt(2.0f * PI * deviation * deviation);
weight *= exp(-(offset * offset) / (2.0f * deviation * deviation));
return weight;
}
//-----------------------------------------------------------------------------------------
// BilateralBlur
//-----------------------------------------------------------------------------------------
float4 BilateralBlur(v2f input, int2 direction, Texture2DArray depth, SamplerState depthSampler, const int kernelRadius, float2 pixelSize)
{
//const float deviation = kernelRadius / 2.5;
const float deviation = kernelRadius / GAUSS_BLUR_DEVIATION; // make it really strong
float2 uv = input.uv;
float4 centerColor = SampleTexture(_MainTex,sampler_MainTex,uv);
float3 color = centerColor.xyz;
//return float4(color, 1);
float centerDepth = LinearEyeDepth(SampleTexture(depth,depthSampler,uv));
float weightSum = 0;
// gaussian weight is computed from constants only -> will be computed in compile time
float weight = GaussianWeight(0, deviation);
color *= weight;
weightSum += weight;
[unroll] for (int i = -kernelRadius; i < 0; i += 1)
{
float2 offset = (direction * i);
float3 sampleColor = SampleTexture(_MainTex,sampler_MainTex,input.uv + offset * _MainTex_TexelSize.xy).rgb;
float sampleDepth = LinearEyeDepth(SampleTexture(depth,depthSampler, input.uv + offset * _MainTex_TexelSize.xy));
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(i, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
[unroll] for (int k = 1; k <= kernelRadius; k += 1)
{
float2 offset = (direction * k);
float3 sampleColor = SampleTexture(_MainTex,sampler_MainTex,input.uv + offset * _MainTex_TexelSize.xy).rgb;
float sampleDepth = LinearEyeDepth(SampleTexture(depth,depthSampler, input.uv + offset * _MainTex_TexelSize.xy));
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(k, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
color /= weightSum;
return float4(color, centerColor.w);
}
#else
float4 SampleTexture(Texture2D tex, SamplerState samplerState, float2 uv)
{
return tex.Sample(samplerState,uv);
}
float4 SampleTexture(Texture2D tex, SamplerState samplerState, float2 uv, float2 offset)
{
return tex.Sample(samplerState,uv,offset);
}
//-----------------------------------------------------------------------------------------
// BilateralUpsample
//-----------------------------------------------------------------------------------------
float4 BilateralUpsample(v2fUpsample input, Texture2D hiDepth, Texture2D loDepth, Texture2D loColor, SamplerState linearSampler, SamplerState pointSampler)
{
float4 result = float4(0,0,0,0);
const float threshold = UPSAMPLE_DEPTH_THRESHOLD;
// float4 highResDepth = LinearEyeDepth(hiDepth.Sample(pointSampler, input.uv)).xxxx;
float4 highResDepth = LinearEyeDepth(SampleTexture(hiDepth, pointSampler, input.uv)).xxxx;
float4 lowResDepth;
lowResDepth[0] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv00));
lowResDepth[1] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv10));
lowResDepth[2] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv01));
lowResDepth[3] = LinearEyeDepth(SampleTexture(loDepth, pointSampler, input.uv11));
float4 depthDiff = abs(lowResDepth - highResDepth);
float accumDiff = dot(depthDiff, float4(1, 1, 1, 1));
[branch]
if (accumDiff < threshold) // small error, not an edge -> use bilinear filter
{
result = SampleTexture(loColor,linearSampler,input.uv);
}
// find nearest sample
float minDepthDiff = depthDiff[0];
float2 nearestUv = input.uv00;
if (depthDiff[1] < minDepthDiff)
{
nearestUv = input.uv10;
minDepthDiff = depthDiff[1];
}
if (depthDiff[2] < minDepthDiff)
{
nearestUv = input.uv01;
minDepthDiff = depthDiff[2];
}
if (depthDiff[3] < minDepthDiff)
{
nearestUv = input.uv11;
minDepthDiff = depthDiff[3];
}
result = SampleTexture(loColor,pointSampler,nearestUv);
return result;
}
//-----------------------------------------------------------------------------------------
// DownsampleDepth
//-----------------------------------------------------------------------------------------
float DownsampleDepth(v2fDownsample input, Texture2D depthTexture, SamplerState depthSampler)
{
#if SHADER_TARGET > 40
float4 depth = depthTexture.Gather(depthSampler, input.uv);
#else
float4 depth;
depth.x = SampleTexture(depthTexture,depthSampler,input.uv00).x;
depth.y = SampleTexture(depthTexture,depthSampler,input.uv01).x;
depth.z = SampleTexture(depthTexture,depthSampler,input.uv10).x;
depth.w = SampleTexture(depthTexture,depthSampler,input.uv11).x;
#endif
#if DOWNSAMPLE_DEPTH_MODE == 0 // min depth
return min(min(depth.x, depth.y), min(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 1 // max depth
return max(max(depth.x, depth.y), max(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 2 // min/max depth in chessboard pattern
float minDepth = min(min(depth.x, depth.y), min(depth.z, depth.w));
float maxDepth = max(max(depth.x, depth.y), max(depth.z, depth.w));
// chessboard pattern
int2 position = input.vertex.xy % 2;
int index = position.x + position.y;
return index == 1 ? minDepth : maxDepth;
#endif
}
//-----------------------------------------------------------------------------------------
// GaussianWeight
//-----------------------------------------------------------------------------------------
float GaussianWeight(float offset, float deviation)
{
float weight = 1.0f / sqrt(2.0f * PI * deviation * deviation);
weight *= exp(-(offset * offset) / (2.0f * deviation * deviation));
return weight;
}
//-----------------------------------------------------------------------------------------
// BilateralBlur
//-----------------------------------------------------------------------------------------
float4 BilateralBlur(v2f input, int2 direction, Texture2D depth, SamplerState depthSampler, const int kernelRadius, float2 pixelSize)
{
//const float deviation = kernelRadius / 2.5;
const float deviation = kernelRadius / GAUSS_BLUR_DEVIATION; // make it really strong
float2 uv = input.uv;
float4 centerColor = SampleTexture(_MainTex,sampler_MainTex,uv);
float4 color = centerColor;
//return float4(color, 1);
float centerDepth = LinearEyeDepth(SampleTexture(depth,depthSampler,uv));
float weightSum = 0;
// gaussian weight is computed from constants only -> will be computed in compile time
float weight = GaussianWeight(0, deviation);
color *= weight;
weightSum += weight;
[unroll] for (int i = -kernelRadius; i < 0; i += 1)
{
float2 offset = (direction * i);
float4 sampleColor = SampleTexture(_MainTex,sampler_MainTex,input.uv,offset);
float sampleDepth = LinearEyeDepth(SampleTexture(depth,depthSampler, input.uv, offset).x);
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(i, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
[unroll] for (int k = 1; k <= kernelRadius; k += 1)
{
float2 offset = (direction * k);
float4 sampleColor = SampleTexture(_MainTex,sampler_MainTex,input.uv,offset);
float sampleDepth = LinearEyeDepth(SampleTexture(depth,depthSampler,input.uv,offset).x);
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(k, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
color /= weightSum;
return float4(color);
}
#endif
ENDCG
// pass 0 - horizontal blur (hires)
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment horizontalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
fixed4 horizontalFrag(v2f input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(1, 0), _CameraDepthTexture, sampler_CameraDepthTexture, FULL_RES_BLUR_KERNEL_SIZE, _CameraDepthTexture_TexelSize.xy);
}
ENDCG
}
// pass 1 - vertical blur (hires)
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment verticalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
fixed4 verticalFrag(v2f input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(0, 1), _CameraDepthTexture, sampler_CameraDepthTexture, FULL_RES_BLUR_KERNEL_SIZE, _CameraDepthTexture_TexelSize);
}
ENDCG
}
// pass 2 - horizontal blur (lores)
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment horizontalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
fixed4 horizontalFrag(v2f input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(1, 0), _HalfResDepthBuffer, sampler_HalfResDepthBuffer, HALF_RES_BLUR_KERNEL_SIZE, _HalfResDepthBuffer_TexelSize);
}
ENDCG
}
// pass 3 - vertical blur (lores)
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment verticalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
fixed4 verticalFrag(v2f input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(0, 1), _HalfResDepthBuffer, sampler_HalfResDepthBuffer, HALF_RES_BLUR_KERNEL_SIZE, _HalfResDepthBuffer_TexelSize);
}
ENDCG
}
// pass 4 - downsample depth to half
Pass
{
CGPROGRAM
#pragma vertex vertHalfDepth
#pragma fragment frag
// #pragma target gl4.1
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
v2fDownsample vertHalfDepth(appdata v)
{
return vertDownsampleDepth(v, _CameraDepthTexture_TexelSize);
}
float4 frag(v2fDownsample input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _CameraDepthTexture, sampler_CameraDepthTexture);
return float4(depth,depth,depth,depth);
}
ENDCG
}
// pass 5 - bilateral upsample
Pass
{
Blend One Zero
CGPROGRAM
#pragma vertex vertUpsampleToFull
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
v2fUpsample vertUpsampleToFull(appdata v)
{
return vertUpsample(v, _HalfResDepthBuffer_TexelSize);
}
float4 frag(v2fUpsample input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralUpsample(input, _CameraDepthTexture, _HalfResDepthBuffer, _HalfResColor, sampler_HalfResColor, sampler_HalfResDepthBuffer);
}
ENDCG
}
// pass 6 - downsample depth to quarter
Pass
{
CGPROGRAM
#pragma vertex vertQuarterDepth
#pragma fragment frag
//#pragma target gl4.1
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
v2fDownsample vertQuarterDepth(appdata v)
{
return vertDownsampleDepth(v, _HalfResDepthBuffer_TexelSize);
}
float4 frag(v2fDownsample input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _HalfResDepthBuffer, sampler_HalfResDepthBuffer);
return float4(depth,depth,depth,depth);
}
ENDCG
}
// pass 7 - bilateral upsample quarter to full
Pass
{
Blend One Zero
CGPROGRAM
#pragma vertex vertUpsampleToFull
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
v2fUpsample vertUpsampleToFull(appdata v)
{
return vertUpsample(v, _QuarterResDepthBuffer_TexelSize);
}
float4 frag(v2fUpsample input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralUpsample(input, _CameraDepthTexture, _QuarterResDepthBuffer, _QuarterResColor, sampler_QuarterResColor, sampler_QuarterResDepthBuffer);
}
ENDCG
}
// pass 8 - horizontal blur (quarter res)
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment horizontalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
fixed4 horizontalFrag(v2f input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(1, 0), _QuarterResDepthBuffer, sampler_QuarterResDepthBuffer, QUARTER_RES_BLUR_KERNEL_SIZE, _QuarterResDepthBuffer_TexelSize.xy);
}
ENDCG
}
// pass 9 - vertical blur (quarter res)
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment verticalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
fixed4 verticalFrag(v2f input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(0, 1), _QuarterResDepthBuffer, sampler_QuarterResDepthBuffer, QUARTER_RES_BLUR_KERNEL_SIZE, _QuarterResDepthBuffer_TexelSize.xy);
}
ENDCG
}
// pass 10 - downsample depth to half (fallback for DX10)
Pass
{
CGPROGRAM
#pragma vertex vertHalfDepth
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
v2fDownsample vertHalfDepth(appdata v)
{
return vertDownsampleDepth(v, _CameraDepthTexture_TexelSize);
}
float4 frag(v2fDownsample input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _CameraDepthTexture, sampler_CameraDepthTexture);
return float4(depth,depth,depth,depth);
}
ENDCG
}
// pass 11 - downsample depth to quarter (fallback for DX10)
Pass
{
CGPROGRAM
#pragma vertex vertQuarterDepth
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP
v2fDownsample vertQuarterDepth(appdata v)
{
return vertDownsampleDepth(v, _HalfResDepthBuffer_TexelSize);
}
float4 frag(v2fDownsample input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _HalfResDepthBuffer, sampler_HalfResDepthBuffer);
return float4(depth,depth,depth,depth);
}
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 1575a50566010d44dab58feb9714c69a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Fog/EnviroBilateralBlur.shader
uploadId: 660896

View File

@@ -0,0 +1,917 @@
// Copyright(c) 2016, Michal Skalsky
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Shader "Hidden/EnviroBlurURP"
{
Properties
{
_MainTex("Texture", any) = "" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
HLSLINCLUDE
//--------------------------------------------------------------------------------------------
// Downsample, bilateral blur and upsample config
//--------------------------------------------------------------------------------------------
// method used to downsample depth buffer: 0 = min; 1 = max; 2 = min/max in chessboard pattern
#define DOWNSAMPLE_DEPTH_MODE 2
#define UPSAMPLE_DEPTH_THRESHOLD 1.5f
#define BLUR_DEPTH_FACTOR 0.5
#define GAUSS_BLUR_DEVIATION 1.5
#define FULL_RES_BLUR_KERNEL_SIZE 7
#define HALF_RES_BLUR_KERNEL_SIZE 5
#define QUARTER_RES_BLUR_KERNEL_SIZE 6
//--------------------------------------------------------------------------------------------
//#define PI 3.1415927f
#if ENVIROURP17
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
TEXTURE2D_X_FLOAT(_HalfResDepthBuffer);
SAMPLER(sampler_HalfResDepthBuffer);
TEXTURE2D_X_FLOAT(_QuarterResDepthBuffer);
SAMPLER(sampler_QuarterResDepthBuffer);
TEXTURE2D_X(_HalfResColor);
SAMPLER(sampler_HalfResColor);
TEXTURE2D_X(_QuarterResColor);
SAMPLER(sampler_QuarterResColor);
TEXTURE2D_X(_MainTex);
SAMPLER(sampler_MainTex);
float4 _MainTex_TexelSize;
float4 _CameraDepthTexture_TexelSize;
float4 _HalfResDepthBuffer_TexelSize;
float4 _QuarterResDepthBuffer_TexelSize;
struct appdata
{
uint vertex : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
struct v2fDownsample
{
#if SHADER_TARGET > 40
float2 uv : TEXCOORD0;
#else
float2 uv00 : TEXCOORD0;
float2 uv01 : TEXCOORD1;
float2 uv10 : TEXCOORD2;
float2 uv11 : TEXCOORD3;
#endif
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
struct v2fUpsample
{
float2 uv : TEXCOORD0;
float2 uv00 : TEXCOORD1;
float2 uv01 : TEXCOORD2;
float2 uv10 : TEXCOORD3;
float2 uv11 : TEXCOORD4;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.vertex = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
return o;
}
//-----------------------------------------------------------------------------------------
// vertDownsampleDepth
//-----------------------------------------------------------------------------------------
v2fDownsample vertDownsampleDepth(appdata v, float2 texelSize)
{
v2fDownsample o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.vertex = pos;
#if SHADER_TARGET > 40
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
#else
o.uv00 = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv); - 0.5 * texelSize.xy;
o.uv10 = o.uv00 + float2(texelSize.x, 0);
o.uv01 = o.uv00 + float2(0, texelSize.y);
o.uv11 = o.uv00 + texelSize.xy;
#endif
return o;
}
//-----------------------------------------------------------------------------------------
// vertUpsample
//-----------------------------------------------------------------------------------------
v2fUpsample vertUpsample(appdata v, float2 texelSize)
{
v2fUpsample o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.vertex = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
o.uv00 = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv) - 0.5 * texelSize.xy;
o.uv10 = o.uv00 + float2(texelSize.x, 0);
o.uv01 = o.uv00 + float2(0, texelSize.y);
o.uv11 = o.uv00 + texelSize.xy;
return o;
}
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
//-----------------------------------------------------------------------------------------
// BilateralUpsample
//-----------------------------------------------------------------------------------------
float4 BilateralUpsample(v2fUpsample input, Texture2DArray hiDepth, Texture2DArray loDepth, Texture2DArray loColor, SamplerState linearSampler, SamplerState pointSampler)
{
float4 result = float4(0,0,0,0);
const float threshold = UPSAMPLE_DEPTH_THRESHOLD;
float4 highResDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(hiDepth, pointSampler, input.uv), _ZBufferParams).xxxx;
float4 lowResDepth;
lowResDepth[0] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv00), _ZBufferParams);
lowResDepth[1] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv10), _ZBufferParams);
lowResDepth[2] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv01), _ZBufferParams);
lowResDepth[3] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv11), _ZBufferParams);
float4 depthDiff = abs(lowResDepth - highResDepth);
float accumDiff = dot(depthDiff, float4(1, 1, 1, 1));
[branch]
if (accumDiff < threshold) // small error, not an edge -> use bilinear filter
{
result = SAMPLE_TEXTURE2D_X(loColor,linearSampler,input.uv);
}
// find nearest sample
float minDepthDiff = depthDiff[0];
float2 nearestUv = input.uv00;
if (depthDiff[1] < minDepthDiff)
{
nearestUv = input.uv10;
minDepthDiff = depthDiff[1];
}
if (depthDiff[2] < minDepthDiff)
{
nearestUv = input.uv01;
minDepthDiff = depthDiff[2];
}
if (depthDiff[3] < minDepthDiff)
{
nearestUv = input.uv11;
minDepthDiff = depthDiff[3];
}
result = SAMPLE_TEXTURE2D_X(loColor,pointSampler,nearestUv);
return result;
}
//-----------------------------------------------------------------------------------------
// DownsampleDepth
//-----------------------------------------------------------------------------------------
float DownsampleDepth(v2fDownsample input, Texture2DArray depthTexture, SamplerState depthSampler)
{
#if SHADER_TARGET > 40
float4 depth = depthTexture.Gather(depthSampler, input.uv);
#else
float4 depth;
depth.x = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv00).x;
depth.y = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv01).x;
depth.z = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv10).x;
depth.w = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv11).x;
#endif
#if DOWNSAMPLE_DEPTH_MODE == 0 // min depth
return min(min(depth.x, depth.y), min(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 1 // max depth
return max(max(depth.x, depth.y), max(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 2 // min/max depth in chessboard pattern
float minDepth = min(min(depth.x, depth.y), min(depth.z, depth.w));
float maxDepth = max(max(depth.x, depth.y), max(depth.z, depth.w));
// chessboard pattern
int2 position = input.vertex.xy % 2;
int index = position.x + position.y;
return index == 1 ? minDepth : maxDepth;
#endif
}
//-----------------------------------------------------------------------------------------
// GaussianWeight
//-----------------------------------------------------------------------------------------
float GaussianWeight(float offset, float deviation)
{
float weight = 1.0f / sqrt(2.0f * PI * deviation * deviation);
weight *= exp(-(offset * offset) / (2.0f * deviation * deviation));
return weight;
}
//-----------------------------------------------------------------------------------------
// BilateralBlur
//-----------------------------------------------------------------------------------------
float4 BilateralBlur(v2f input, int2 direction, Texture2DArray depth, SamplerState depthSampler, const int kernelRadius, float2 pixelSize)
{
//const float deviation = kernelRadius / 2.5;
const float deviation = kernelRadius / GAUSS_BLUR_DEVIATION; // make it really strong
float2 uv = input.uv;
float4 centerColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,uv );
float4 color = centerColor;
//return float4(color, 1);
float centerDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(depth,depthSampler,uv), _ZBufferParams);
float weightSum = 0;
// gaussian weight is computed from constants only -> will be computed in compile time
float weight = GaussianWeight(0, deviation);
color *= weight;
weightSum += weight;
[unroll] for (int i = -kernelRadius; i < 0; i += 1)
{
float2 offset = (direction * i);
float4 sampleColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,input.uv + offset * _MainTex_TexelSize.xy);
float sampleDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(depth,depthSampler, input.uv + offset * _MainTex_TexelSize.xy).x, _ZBufferParams);
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(i, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
[unroll] for (int k = 1; k <= kernelRadius; k += 1)
{
float2 offset = (direction * k);
float4 sampleColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,input.uv + offset * _MainTex_TexelSize.xy );
float sampleDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(depth,depthSampler,input.uv + offset * _MainTex_TexelSize.xy ).x , _ZBufferParams);
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(k, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
color /= weightSum;
return float4(color);
}
#else
//-----------------------------------------------------------------------------------------
// BilateralUpsample
//-----------------------------------------------------------------------------------------
float4 BilateralUpsample(v2fUpsample input, Texture2D hiDepth, Texture2D loDepth, Texture2D loColor, SamplerState linearSampler, SamplerState pointSampler)
{
const float threshold = UPSAMPLE_DEPTH_THRESHOLD;
float4 highResDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(hiDepth, pointSampler, input.uv), _ZBufferParams).xxxx;
float4 lowResDepth;
lowResDepth[0] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv00), _ZBufferParams);
lowResDepth[1] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv10), _ZBufferParams);
lowResDepth[2] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv01), _ZBufferParams);
lowResDepth[3] = LinearEyeDepth(SAMPLE_TEXTURE2D_X(loDepth, pointSampler, input.uv11), _ZBufferParams);
float4 depthDiff = abs(lowResDepth - highResDepth);
float accumDiff = dot(depthDiff, float4(1, 1, 1, 1));
[branch]
if (accumDiff < threshold) // small error, not an edge -> use bilinear filter
{
return SAMPLE_TEXTURE2D_X(loColor,linearSampler,input.uv);
}
// find nearest sample
float minDepthDiff = depthDiff[0];
float2 nearestUv = input.uv00;
if (depthDiff[1] < minDepthDiff)
{
nearestUv = input.uv10;
minDepthDiff = depthDiff[1];
}
if (depthDiff[2] < minDepthDiff)
{
nearestUv = input.uv01;
minDepthDiff = depthDiff[2];
}
if (depthDiff[3] < minDepthDiff)
{
nearestUv = input.uv11;
minDepthDiff = depthDiff[3];
}
return SAMPLE_TEXTURE2D_X(loColor,pointSampler,nearestUv);
}
//-----------------------------------------------------------------------------------------
// DownsampleDepth
//-----------------------------------------------------------------------------------------
float DownsampleDepth(v2fDownsample input, Texture2D depthTexture, SamplerState depthSampler)
{
#if SHADER_TARGET > 40
float4 depth = depthTexture.Gather(depthSampler, input.uv);
#else
float4 depth;
depth.x = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv00).x;
depth.y = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv01).x;
depth.z = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv10).x;
depth.w = SAMPLE_TEXTURE2D_X(depthTexture,depthSampler,input.uv11).x;
#endif
#if DOWNSAMPLE_DEPTH_MODE == 0 // min depth
return min(min(depth.x, depth.y), min(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 1 // max depth
return max(max(depth.x, depth.y), max(depth.z, depth.w));
#elif DOWNSAMPLE_DEPTH_MODE == 2 // min/max depth in chessboard pattern
float minDepth = min(min(depth.x, depth.y), min(depth.z, depth.w));
float maxDepth = max(max(depth.x, depth.y), max(depth.z, depth.w));
// chessboard pattern
int2 position = input.vertex.xy % 2;
int index = position.x + position.y;
return index == 1 ? minDepth : maxDepth;
#endif
}
//-----------------------------------------------------------------------------------------
// GaussianWeight
//-----------------------------------------------------------------------------------------
float GaussianWeight(float offset, float deviation)
{
float weight = 1.0f / sqrt(2.0f * PI * deviation * deviation);
weight *= exp(-(offset * offset) / (2.0f * deviation * deviation));
return weight;
}
//-----------------------------------------------------------------------------------------
// BilateralBlur
//-----------------------------------------------------------------------------------------
float4 BilateralBlur(v2f input, int2 direction, Texture2D depth, SamplerState depthSampler, const int kernelRadius, float2 pixelSize)
{
//const float deviation = kernelRadius / 2.5;
const float deviation = kernelRadius / GAUSS_BLUR_DEVIATION; // make it really strong
float2 uv = input.uv;
float4 centerColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,uv );
float4 color = centerColor;
//return float4(color, 1);
float centerDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(depth,depthSampler,uv), _ZBufferParams);
float weightSum = 0;
// gaussian weight is computed from constants only -> will be computed in compile time
float weight = GaussianWeight(0, deviation);
color *= weight;
weightSum += weight;
[unroll] for (int i = -kernelRadius; i < 0; i += 1)
{
float2 offset = (direction * i);
float4 sampleColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,input.uv + offset * _MainTex_TexelSize.xy);
float sampleDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(depth,depthSampler, input.uv + offset * _MainTex_TexelSize.xy).x, _ZBufferParams);
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(i, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
[unroll] for (int k = 1; k <= kernelRadius; k += 1)
{
float2 offset = (direction * k);
float4 sampleColor = SAMPLE_TEXTURE2D_X(_MainTex,sampler_MainTex,input.uv + offset * _MainTex_TexelSize.xy );
float sampleDepth = LinearEyeDepth(SAMPLE_TEXTURE2D_X(depth,depthSampler,input.uv + offset * _MainTex_TexelSize.xy ).x , _ZBufferParams);
float depthDiff = abs(centerDepth - sampleDepth);
float dFactor = depthDiff * BLUR_DEPTH_FACTOR;
float w = exp(-(dFactor * dFactor));
// gaussian weight is computed from constants only -> will be computed in compile time
weight = GaussianWeight(k, deviation) * w;
color += weight * sampleColor;
weightSum += weight;
}
color /= weightSum;
return float4(color);
}
#endif
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
struct v2fDownsample
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
struct v2fUpsample
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
v2fUpsample vertUpsample(appdata v, float2 texelSize)
{
v2fUpsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
v2fDownsample vertDownsampleDepth(appdata v, float2 texelSize)
{
v2fDownsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
#endif
ENDHLSL
// pass 0 - horizontal blur (hires)
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment horizontalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
float4 horizontalFrag(v2f input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(1, 0), _CameraDepthTexture, sampler_CameraDepthTexture, FULL_RES_BLUR_KERNEL_SIZE, _CameraDepthTexture_TexelSize.xy);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 1 - vertical blur (hires)
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment verticalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
float4 verticalFrag(v2f input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(0, 1), _CameraDepthTexture, sampler_CameraDepthTexture, FULL_RES_BLUR_KERNEL_SIZE, _CameraDepthTexture_TexelSize);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 2 - horizontal blur (lores)
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment horizontalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
float4 horizontalFrag(v2f input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(1, 0), _HalfResDepthBuffer, sampler_HalfResDepthBuffer, HALF_RES_BLUR_KERNEL_SIZE, _HalfResDepthBuffer_TexelSize);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 3 - vertical blur (lores)
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment verticalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
float4 verticalFrag(v2f input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(0, 1), _HalfResDepthBuffer, sampler_HalfResDepthBuffer, HALF_RES_BLUR_KERNEL_SIZE, _HalfResDepthBuffer_TexelSize);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 4 - downsample depth to half
Pass
{
HLSLPROGRAM
#pragma vertex vertHalfDepth
#pragma fragment frag
// #pragma target gl4.1
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
v2fDownsample vertHalfDepth(appdata v)
{
#if ENVIROURP17
return vertDownsampleDepth(v, _CameraDepthTexture_TexelSize);
#else
v2fDownsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
#endif
}
float4 frag(v2fDownsample input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _CameraDepthTexture, sampler_CameraDepthTexture);
return float4(depth,depth,depth,depth);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 5 - bilateral upsample
Pass
{
Blend One Zero
HLSLPROGRAM
#pragma vertex vertUpsampleToFull
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
v2fUpsample vertUpsampleToFull(appdata v)
{
#if ENVIROURP17
return vertUpsample(v, _HalfResDepthBuffer_TexelSize);
#else
v2fUpsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
#endif
}
float4 frag(v2fUpsample input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralUpsample(input, _CameraDepthTexture, _HalfResDepthBuffer, _HalfResColor, sampler_HalfResColor, sampler_HalfResDepthBuffer);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 6 - downsample depth to quarter
Pass
{
HLSLPROGRAM
#pragma vertex vertQuarterDepth
#pragma fragment frag
//#pragma target gl4.1
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
v2fDownsample vertQuarterDepth(appdata v)
{
#if ENVIROURP17
return vertDownsampleDepth(v, _HalfResDepthBuffer_TexelSize);
#else
v2fDownsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
#endif
}
float4 frag(v2fDownsample input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _HalfResDepthBuffer, sampler_HalfResDepthBuffer);
return float4(depth,depth,depth,depth);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 7 - bilateral upsample quarter to full
Pass
{
Blend One Zero
HLSLPROGRAM
#pragma vertex vertUpsampleToFull
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
v2fUpsample vertUpsampleToFull(appdata v)
{
#if ENVIROURP17
return vertUpsample(v, _QuarterResDepthBuffer_TexelSize);
#else
v2fUpsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
#endif
}
float4 frag(v2fUpsample input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralUpsample(input, _CameraDepthTexture, _QuarterResDepthBuffer, _QuarterResColor, sampler_QuarterResColor, sampler_QuarterResDepthBuffer);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 8 - horizontal blur (quarter res)
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment horizontalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
float4 horizontalFrag(v2f input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(1, 0), _QuarterResDepthBuffer, sampler_QuarterResDepthBuffer, QUARTER_RES_BLUR_KERNEL_SIZE, _QuarterResDepthBuffer_TexelSize.xy);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 9 - vertical blur (quarter res)
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment verticalFrag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
float4 verticalFrag(v2f input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return BilateralBlur(input, int2(0, 1), _QuarterResDepthBuffer, sampler_QuarterResDepthBuffer, QUARTER_RES_BLUR_KERNEL_SIZE, _QuarterResDepthBuffer_TexelSize.xy);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 10 - downsample depth to half (fallback for DX10)
Pass
{
HLSLPROGRAM
#pragma vertex vertHalfDepth
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
v2fDownsample vertHalfDepth(appdata v)
{
#if ENVIROURP17
return vertDownsampleDepth(v, _CameraDepthTexture_TexelSize);
#else
v2fDownsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
#endif
}
float4 frag(v2fDownsample input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _CameraDepthTexture, sampler_CameraDepthTexture);
return float4(depth,depth,depth,depth);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
// pass 11 - downsample depth to quarter (fallback for DX10)
Pass
{
HLSLPROGRAM
#pragma vertex vertQuarterDepth
#pragma fragment frag
#pragma target 3.5
#pragma exclude_renderers gles
#pragma multi_compile __ ENVIROURP17
v2fDownsample vertQuarterDepth(appdata v)
{
#if ENVIROURP17
return vertDownsampleDepth(v, _HalfResDepthBuffer_TexelSize);
#else
v2fDownsample o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
#endif
}
float4 frag(v2fDownsample input) : SV_Target
{
#if ENVIROURP17
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float depth = DownsampleDepth(input, _HalfResDepthBuffer, sampler_HalfResDepthBuffer);
return float4(depth,depth,depth,depth);
#else
return float4(0,0,0,0);
#endif
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 32fd70cd087662643831919acaa533c2
ShaderImporter:
externalObjects: {}
defaultTextures:
- _MainTex: {instanceID: 0}
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.1.4
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Fog/EnviroBilateralBlurURP.shader
uploadId: 673787

View File

@@ -0,0 +1,111 @@
Shader "Hidden/EnviroHeightFog"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#pragma multi_compile __ UNITY_COLORSPACE_GAMMA
#include "UnityCG.cginc"
#include_with_pragmas "../Includes/FogInclude.cginc"
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
float3 ray : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata_img v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined(ENVIROURP)
o.position = float4(v.vertex.xyz,1.0);
#if UNITY_UV_STARTS_AT_TOP
o.position.y *= -1;
#endif
#else
o.position = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord;
return o;
}
float4x4 _LeftWorldFromView;
float4x4 _RightWorldFromView;
float4x4 _LeftViewFromScreen;
float4x4 _RightViewFromScreen;
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
void InverseProjectDepth (float depth, float2 texcoord, out float3 worldPos)
{
float4x4 proj, eyeToWorld;
if (unity_StereoEyeIndex == 0)
{
proj = _LeftViewFromScreen;
eyeToWorld = _LeftWorldFromView;
}
else
{
proj = _RightViewFromScreen;
eyeToWorld = _RightWorldFromView;
}
#if !UNITY_UV_STARTS_AT_TOP
//texcoord.y = 1 - texcoord.y;
#endif
float2 uvClip = texcoord * 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
worldPos = mul(eyeToWorld, viewPos).xyz;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv);
float linearDepth = Linear01Depth(depth);
float3 worldPos;
InverseProjectDepth(depth, i.uv.xy, worldPos);
float4 col = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.uv);
float4 fog = GetExponentialHeightFog(worldPos,linearDepth);
//this is not correct but LinearToGamma does produce even worse results..
#if defined(UNITY_COLORSPACE_GAMMA)
fog.rgb *= 1.5;
#endif
float3 final = ApplyVolumetricLights(fog,col.rgb, i.uv);
return float4(final.rgb,col.a);
}
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 5f1a7a03afe5374439810ec3993fb6ac
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Fog/EnviroHeightFog.shader
uploadId: 660896

View File

@@ -0,0 +1,163 @@
Shader "Hidden/EnviroHeightFogHDRP"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 4.5
#pragma multi_compile __ ENVIROHDRP
#if defined (ENVIROHDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl"
#include_with_pragmas "../Includes/FogIncludeHLSL.hlsl"
struct appdata
{
uint vertexID : SV_VertexID;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
float3 ray : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.position = GetFullScreenTriangleVertexPosition(v.vertexID);
o.uv = GetFullScreenTriangleTexCoord(v.vertexID);
return o;
}
float4x4 _LeftWorldFromView;
float4x4 _RightWorldFromView;
float4x4 _LeftViewFromScreen;
float4x4 _RightViewFromScreen;
float3 color, opacity;
float _EnviroSkyIntensity;
TEXTURE2D_X(_MainTex);
void InverseProjectDepth (float depth, float2 texcoord, out float3 worldPos)
{
float4x4 proj, eyeToWorld;
if (unity_StereoEyeIndex == 0)
{
proj = _LeftViewFromScreen;
eyeToWorld = _LeftWorldFromView;
}
else
{
proj = _RightViewFromScreen;
eyeToWorld = _RightWorldFromView;
}
#if !UNITY_UV_STARTS_AT_TOP
texcoord.y = 1 - texcoord.y;
#endif
float2 uvClip = texcoord * 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
worldPos = mul(eyeToWorld, viewPos).xyz;
//viewDir = worldPos - _CameraPosition.xyz;
//dist = length(viewDir);
//viewDir /= dist;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float depth = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, i.uv * _ScreenSize.xy * (1/_RTHandleScale.xy), 0).r;
float linearDepth = Linear01Depth(depth, _ZBufferParams);
float3 worldPos;
InverseProjectDepth(depth, i.uv.xy * (1/_RTHandleScale.xy), worldPos);
float4 fog = GetExponentialHeightFog(worldPos,linearDepth);
fog.rgb *= _EnviroSkyIntensity * GetCurrentExposureMultiplier();
//HDRP Fog
//float3 V = GetSkyViewDirWS(i.uv.xy * _ScreenSize.xy * (1/_RTHandleScale.xy));
//PositionInputs posInput = GetPositionInput(i.position.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
//posInput.positionWS = GetCurrentViewPosition() - V * _MaxFogDistance;
//EvaluateAtmosphericScattering(posInput, V, color, opacity);
//fog.rgb = color + (1 - opacity) * fog.rgb;
float4 col = SAMPLE_TEXTURE2D_X_LOD(_MainTex,s_trilinear_clamp_sampler, i.uv, 0);
//float4 volumetrics = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_EnviroVolumetricFogTex, i.uv);
//col.rgb = col.rgb * fog.a + fog.rgb * max(volumetrics.rgb,0.75);
col.rgb = col.rgb * fog.a + fog.rgb;
return col;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 05a94bc890a932e4c96dc05c6427e9d9
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/Fog/EnviroHeightFogHDRP.shader
uploadId: 660896

View File

@@ -0,0 +1,148 @@
Shader "Hidden/EnviroHeightFogURP"
{
Properties
{
_MainTex ("Texture", any) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ UNITY_COLORSPACE_GAMMA
#pragma multi_compile __ ENVIROURP
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include_with_pragmas "../Includes/FogIncludeHLSL.hlsl"
struct appdata
{
uint vertex : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.position = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
return o;
}
float4x4 _LeftWorldFromView;
float4x4 _RightWorldFromView;
float4x4 _LeftViewFromScreen;
float4x4 _RightViewFromScreen;
TEXTURE2D_X(_MainTex);
SAMPLER(sampler_MainTex);
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER (sampler_CameraDepthTexture);
void InverseProjectDepth (float depth, float2 texcoord, out float3 worldPos)
{
float4x4 proj, eyeToWorld;
if (unity_StereoEyeIndex == 0)
{
proj = _LeftViewFromScreen;
eyeToWorld = _LeftWorldFromView;
}
else
{
proj = _RightViewFromScreen;
eyeToWorld = _RightWorldFromView;
}
#if !UNITY_UV_STARTS_AT_TOP
//texcoord.y = 1 - texcoord.y;
#endif
float2 uvClip = texcoord * 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
worldPos = mul(eyeToWorld, viewPos).xyz;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float depth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture,sampler_CameraDepthTexture, i.uv);
float linearDepth = Linear01Depth(depth, _ZBufferParams);
float3 worldPos;
InverseProjectDepth(depth, i.uv.xy, worldPos);
float4 col = SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, i.uv);
float4 fog = GetExponentialHeightFog(worldPos,linearDepth);
//this is not correct but LinearToGamma does produce even worse results..
#if defined(UNITY_COLORSPACE_GAMMA)
fog.rgb *= 1.5;
#endif
float3 final = ApplyVolumetricLights(fog,col.rgb, i.uv);
return float4(final.rgb,col.a);
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 29134b07a9b3ff847890a42914b2a6f4
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,395 @@
Shader "Hidden/Volumetrics"
{
Properties
{
_MainTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
float4x4 _LeftWorldFromView;
float4x4 _RightWorldFromView;
float4x4 _LeftViewFromScreen;
float4x4 _RightViewFromScreen;
sampler2D _DitherTexture;
UNITY_DECLARE_SHADOWMAP(_CascadeShadowMapTexture);
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
/* #if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
UNITY_DECLARE_TEX2DARRAY(_EnviroCloudsTex);
#else
sampler2D _EnviroCloudsTex;
#endif*/
uniform sampler3D _NoiseTexture;
uniform int _Steps;
uniform float3 _CameraPosition;
uniform float4 _VolumetricLight;
uniform float4 _HeightFog;
uniform float4 _HeightParams;
uniform float4 _NoiseData;
uniform float3 _WindDirection;
uniform float4 _MieG;
uniform float _MaxRayLength;
uniform float _MaxRayLengthLights;
uniform float4 _AmbientColor;
uniform float3 _DirLightDir;
//uniform float4 _DirLightColor;
uniform float4 _Randomness;
#if !SHADER_API_GLES3
struct PointLight
{
float3 pos;
float range;
float3 color;
float padding;
};
StructuredBuffer<PointLight> _PointLights;
float _PointLightsCount;
struct SpotLight
{
float3 pos;
float range;
float3 color;
float3 lightDirection;
float lightCosHalfAngle;
//float2 angularFalloffParameters;
//float2 distanceFalloffParameters;
float padding;
};
StructuredBuffer<SpotLight> _SpotLights;
float _SpotLightsCount;
#endif
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata_img v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.position = UnityObjectToClipPos(v.vertex);
//o.position = v.vertex * float4(2,2,1,1) + float4(-1,-1,0,0);
o.uv = v.texcoord;
return o;
}
float4 GetCascadeWeights_SplitSpheres(float3 wpos)
{
float3 fromCenter0 = wpos - unity_ShadowSplitSpheres[0].xyz;
float3 fromCenter1 = wpos - unity_ShadowSplitSpheres[1].xyz;
float3 fromCenter2 = wpos - unity_ShadowSplitSpheres[2].xyz;
float3 fromCenter3 = wpos - unity_ShadowSplitSpheres[3].xyz;
float4 distances2 = float4(dot(fromCenter0,fromCenter0), dot(fromCenter1,fromCenter1), dot(fromCenter2,fromCenter2), dot(fromCenter3,fromCenter3));
float4 weights = float4(distances2 >= unity_ShadowSplitSqRadii);
return weights;
}
float4 GetCascadeShadowCoord(float4 pos, float4 cascadeWeights)
{
return mul(unity_WorldToShadow[(int)dot(cascadeWeights, float4(1,1,1,1))], pos);
}
/*
float GetCascadeWeights_SplitSpheres(float3 positionWS)
{
float3 fromCenter0 = positionWS - unity_ShadowSplitSpheres[0].xyz;
float3 fromCenter1 = positionWS - unity_ShadowSplitSpheres[1].xyz;
float3 fromCenter2 = positionWS - unity_ShadowSplitSpheres[2].xyz;
float3 fromCenter3 = positionWS - unity_ShadowSplitSpheres[3].xyz;
float4 distances2 = float4(dot(fromCenter0, fromCenter0), dot(fromCenter1, fromCenter1), dot(fromCenter2, fromCenter2), dot(fromCenter3, fromCenter3));
float4 weights = float4(distances2 >= unity_ShadowSplitSqRadii);
weights.yzw = saturate(weights.yzw - weights.xyz);
return float(4.0) - dot(weights, float4(4, 3, 2, 1));
}
float4 GetCascadeShadowCoord(float3 positionWS, half cascadeIndex)
{
float4 shadowCoord = mul(unity_WorldToShadow[cascadeIndex], float4(positionWS, 1.0));
return float4(shadowCoord.xyz, 0);
}
*/
float anisotropy(float costheta)
{
float g = _MieG.x;
float gsq = g*g;
float denom = 1 + gsq - 2.0 * g * costheta;
denom = denom * denom * denom;
denom = sqrt(max(0, denom));
return (1 - gsq) / denom;
}
float anisotropyPointSpot(float costheta)
{
float g = 0.8;
float gsq = g*g;
float denom = 1 + gsq - 2.0 * g * costheta;
denom = denom * denom * denom;
denom = sqrt(max(0, denom));
return (1 - gsq) / denom;
}
float Attenuation(float distNorm)
{
return 1.0 / (1.0 + 25.0 * distNorm);
}
float DirectionalLight(float3 wpos)
{
float atten = 1.0f;
float4 cascadeWeights = GetCascadeWeights_SplitSpheres(wpos);
bool inside = dot(cascadeWeights, float4(1, 1, 1, 1)) < 4;
float4 samplePos = GetCascadeShadowCoord(float4(wpos, 1), cascadeWeights);
float shadows = UNITY_SAMPLE_SHADOW(_CascadeShadowMapTexture, samplePos.xyz).r;
atten = inside ? shadows : 1.0f;
if(shadows > 0.0f)
atten = 1.0f;
return atten;
}
#if !SHADER_API_GLES3
float3 PointLights(float3 pos)
{
float3 color = 0;
for (int i = 0; i < _PointLightsCount; i++)
{
float3 posToLight = _PointLights[i].pos - pos;
float distNorm = dot(posToLight, posToLight) * _PointLights[i].range;
float att = Attenuation(distNorm);
//#if ANISOTROPY
float3 cameraToPos = normalize(pos - _WorldSpaceCameraPos.xyz);
float costheta = dot(cameraToPos, normalize(posToLight));
att *= anisotropyPointSpot(costheta);
//#endif
color += _PointLights[i].color * att;
}
return color;
}
float3 SpotLights(float3 pos)
{
float3 color = 0;
for (int i = 0; i < _SpotLightsCount; i++)
{
float3 posToLight = _SpotLights[i].pos - pos;
float distNorm = dot(posToLight, posToLight) * _SpotLights[i].range;
float att = Attenuation(distNorm);
half3 lightVector = normalize(pos - _SpotLights[i].pos);
half cosAngle = dot(_SpotLights[i].lightDirection.xyz, lightVector);
half angleAttenuation = 1;
angleAttenuation = smoothstep(_SpotLights[i].lightCosHalfAngle, lerp(1, _SpotLights[i].lightCosHalfAngle, 0.8f), cosAngle);
angleAttenuation = pow(angleAttenuation, 2.0f);
att *= angleAttenuation;
#if ANISOTROPY
float3 cameraToPos = normalize(pos - _CameraPos.xyz);
float costheta = dot(cameraToPos, normalize(posToLight));
att *= anisotropyPointSpot(costheta);
#endif
color += _SpotLights[i].color * att;
}
return color;
}
#endif
//-----------------------------------------------------------------------------------------
// GetDensity
//-----------------------------------------------------------------------------------------
float GetDensity(float3 wpos, inout float density, float depth, float3 rayDir)
{
density = 1.0f;
// #ifdef NOISE
// float4 noise = tex3D(_NoiseTexture, frac(wpos * _NoiseData.x + float3(_Time.y * _WindDirection.x, 0, _Time.y * _WindDirection.y)));
// float noiseFbm = (noise.g * 0.625) + (noise.b * 0.25) + (noise.a * 0.125);
// noiseFbm = saturate(noiseFbm - _NoiseData.y);
// density *= saturate(noiseFbm);
// #endif
return density;
}
float2 squareUV(float2 uv)
{
float width = _ScreenParams.x;
float height = _ScreenParams.y;
float scale = 1000;
float x = uv.x * width;
float y = uv.y * height;
return float2 (x/scale, y/scale);
}
float2 WorldToScreenUV(float3 worldPos)
{
// Project world position into clip space
float4 clipPos = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0));
// Perspective divide
clipPos.xyz /= clipPos.w;
// Convert from clip space (-1..1) to UV space (0..1)
float2 uv = clipPos.xy * 0.5 + 0.5;
return uv;
}
float4 RayMarch(float2 uv,float2 screenPos, float3 rayStart, float3 rayDir, float rayLength, float rayLengthLights, float linearDepth)
{
if (rayLength <= 0.01 || !all(isfinite(rayDir)))
return float4(0, 0, 0, 0);
float2 interleavedPos = fmod(floor(saturate(screenPos.xy)), 8.0);
interleavedPos = clamp(interleavedPos, 0.0, 7.999);
#if UNITY_SINGLE_PASS_STEREO
float4 scaleOffset = unity_StereoScaleOffset[unity_StereoEyeIndex];
interleavedPos = (interleavedPos - scaleOffset.zw) / scaleOffset.xy;
#endif
float4 ditherUV = saturate(float4(interleavedPos / 8.0 + float2(0.5 / 8.0, 0.5 / 8.0),0,0));
float offset = tex2Dlod(_DitherTexture, ditherUV).w; //+ _Randomness.xy
int stepCount = _Steps;
float stepSize = rayLength / stepCount;
float3 step = rayDir * stepSize;
float stepSizeLights = rayLengthLights / stepCount;
float3 stepLights = rayDir * stepSizeLights;
float3 currentPositionDithered = rayStart + step * offset;
float3 currentPositionLightsDithered = rayStart + stepLights * offset;
float3 currentPosition = rayStart + step;
float4 color = float4(0.0,0.0,0.0,0);
float cosAngle;
float extinction = 0;
float transmitance = 0;
float ambient = 0;
cosAngle = dot(_DirLightDir.xyz, -rayDir);
float ani = anisotropy(cosAngle);
float4 lightsColor = float4(0,0,0,0);
[loop]
for (int i = 0; i < stepCount; i++)
{
float density = GetDensity(currentPosition, density, linearDepth, rayDir);
float2 shadowUV = WorldToScreenUV(currentPositionDithered);
//float cloudsShadows = pow(UNITY_SAMPLE_SCREENSPACE_TEXTURE(_EnviroCloudsTex, shadowUV).b,0.25);
float atten = DirectionalLight(currentPositionDithered) * 0.1 ;//* (1-cloudsShadows);
float scattering = _VolumetricLight.x * density;
extinction += _VolumetricLight.y * density;
transmitance += atten * scattering * exp(-extinction);
#if !SHADER_API_GLES3
lightsColor.rgb += PointLights(currentPositionLightsDithered) * stepSizeLights * density;
lightsColor.rgb += SpotLights(currentPositionLightsDithered) * stepSizeLights * density;
#endif
currentPosition += step;
currentPositionDithered += step;
currentPositionLightsDithered += stepLights;
}
//color.rgb = _DirLightColor.rgb * transmitance * ani;
color.a = transmitance * ani;
color.rgb += lightsColor.rgb * 0.1;
color = max(0, color);
return color;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float2 uv = i.uv.xy;
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
float linearDepth = Linear01Depth(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 = i.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
float3 wpos = mul(eyeToWorld, viewPos).xyz;
float3 rayStart = _WorldSpaceCameraPos;
float3 rayDir = wpos - _WorldSpaceCameraPos;
//rayDir *= linearDepth;
float rayLength = length(rayDir);
rayDir /= rayLength;
float rayLengthLights = min(rayLength, _MaxRayLengthLights);
rayLength = min(rayLength, _MaxRayLength);
float4 color = RayMarch(uv, i.position.xy, rayStart, rayDir, rayLength, rayLengthLights, linearDepth);
return color;
}
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 1104191b0e8adc746b7bb747e1ea1a87
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.2.2
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Fog/EnviroVolumetrics.shader
uploadId: 766468

View File

@@ -0,0 +1,406 @@
Shader "Hidden/VolumetricsURP"
{
Properties
{
//_MainTex ("Texture", any) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile __ ENVIROURP
#pragma shader_feature_local __ ENVIROURP17
#if defined (ENVIROURP)
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#if defined (ENVIROURP17)
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#endif
float4x4 _LeftWorldFromView;
float4x4 _RightWorldFromView;
float4x4 _LeftViewFromScreen;
float4x4 _RightViewFromScreen;
sampler2D _DitherTexture;
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
uniform sampler3D _NoiseTexture;
uniform int _Steps;
uniform float3 _CameraPosition;
uniform float4 _VolumetricLight;
uniform float4 _HeightFog;
uniform float4 _HeightParams;
uniform float4 _NoiseData;
uniform float3 _WindDirection;
uniform float4 _MieG;
uniform float _MaxRayLength;
uniform float _MaxRayLengthLights;
uniform float4 _AmbientColor;
uniform float3 _DirLightDir;
uniform float4 _Randomness;
#if !SHADER_API_GLES3
struct PointLight
{
float3 pos;
float range;
float3 color;
float padding;
};
StructuredBuffer<PointLight> _PointLights;
float _PointLightsCount;
struct SpotLight
{
float3 pos;
float range;
float3 color;
float3 lightDirection;
float lightCosHalfAngle;
float padding;
};
StructuredBuffer<SpotLight> _SpotLights;
float _SpotLightsCount;
#endif
struct v2f
{
float2 uv : TEXCOORD0;
float4 position : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
struct appdata
{
#if defined (ENVIROURP17)
uint vertex : SV_VertexID;
#else
float4 vertex : POSITION;
#endif
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
v2f vert (appdata v)
{
v2f o = (v2f)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#if defined (ENVIROURP17)
float4 pos = GetFullScreenTriangleVertexPosition(v.vertex);
float2 uv = GetFullScreenTriangleTexCoord(v.vertex);
o.position = pos;
o.uv = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
#else
o.position = float4(v.vertex.xyz,1);
#if UNITY_UV_STARTS_AT_TOP
o.position.y *= -1;
#endif
o.uv = v.texcoord;
#endif
return o;
}
float anisotropy(float costheta)
{
float g = _MieG.x;
float gsq = g*g;
float denom = 1 + gsq - 2.0 * g * costheta;
denom = denom * denom * denom;
denom = sqrt(max(0, denom));
return (1 - gsq) / denom;
}
float anisotropyPointSpot(float costheta)
{
float g = 0.8;
float gsq = g*g;
float denom = 1 + gsq - 2.0 * g * costheta;
denom = denom * denom * denom;
denom = sqrt(max(0, denom));
return (1 - gsq) / denom;
}
float Attenuation(float distNorm)
{
return 1.0 / (1.0 + 25.0 * distNorm);
}
float DirectionalLight(float3 wpos)
{
float atten = 1.0f;
half cascadeIndex = ComputeCascadeIndex(wpos);
bool inside = dot(cascadeIndex, 1) < 4;
float4 coords = mul(_MainLightWorldToShadow[cascadeIndex], float4(wpos, 1.0));
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
half4 shadowParams = GetMainLightShadowParams();
#if UNITY_VERSION >= 202220
float shadows = SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_LinearClampCompare), coords, shadowSamplingData, shadowParams, false).r;
#else
float shadows = SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), coords, shadowSamplingData, shadowParams, false).r;
#endif
atten = inside ? shadows : 1.0f;
// if(shadows > 0.0f)
// atten = 1.0f;
return atten;
}
#if !SHADER_API_GLES3
float3 PointLights(float3 pos)
{
float3 color = 0;
for (int i = 0; i < _PointLightsCount; i++)
{
float3 posToLight = _PointLights[i].pos - pos;
float distNorm = dot(posToLight, posToLight) * _PointLights[i].range;
float att = Attenuation(distNorm);
//#if ANISOTROPY
float3 cameraToPos = normalize(pos - _WorldSpaceCameraPos.xyz);
float costheta = dot(cameraToPos, normalize(posToLight));
att *= anisotropyPointSpot(costheta);
//#endif
color += _PointLights[i].color * att;
}
return color;
}
float3 SpotLights(float3 pos)
{
float3 color = 0;
for (int i = 0; i < _SpotLightsCount; i++)
{
float3 posToLight = _SpotLights[i].pos - pos;
float distNorm = dot(posToLight, posToLight) * _SpotLights[i].range;
float att = Attenuation(distNorm);
half3 lightVector = normalize(pos - _SpotLights[i].pos);
half cosAngle = dot(_SpotLights[i].lightDirection.xyz, lightVector);
half angleAttenuation = 1;
angleAttenuation = smoothstep(_SpotLights[i].lightCosHalfAngle, lerp(1, _SpotLights[i].lightCosHalfAngle, 0.8f), cosAngle);
angleAttenuation = pow(angleAttenuation, 2.0f);
att *= angleAttenuation;
#if ANISOTROPY
float3 cameraToPos = normalize(pos - _CameraPos.xyz);
float costheta = dot(cameraToPos, normalize(posToLight));
att *= anisotropyPointSpot(costheta);
#endif
color += _SpotLights[i].color * att;
}
return color;
}
#endif
//-----------------------------------------------------------------------------------------
// GetDensity
//-----------------------------------------------------------------------------------------
float GetDensity(float3 wpos, inout float density, float depth, float3 rayDir)
{
density = 1.0f;
// #ifdef NOISE
// float4 noise = tex3D(_NoiseTexture, frac(wpos * _NoiseData.x + float3(_Time.y * _WindDirection.x, 0, _Time.y * _WindDirection.y)));
// float noiseFbm = (noise.g * 0.625) + (noise.b * 0.25) + (noise.a * 0.125);
// noiseFbm = saturate(noiseFbm - _NoiseData.y);
// density *= saturate(noiseFbm);
// #endif
return density;
}
float2 squareUV(float2 uv)
{
float width = _ScreenParams.x;
float height =_ScreenParams.y;
float scale = 1000;
float x = uv.x * width;
float y = uv.y * height;
return float2 (x/scale, y/scale);
}
float4 RayMarch(float2 uv,float2 screenPos, float3 rayStart, float3 rayDir, float rayLength, float rayLengthLights, float linearDepth)
{
if (rayLength <= 0.01 || !all(isfinite(rayDir)))
return float4(0, 0, 0, 0);
float2 interleavedPos = fmod(floor(saturate(screenPos.xy)), 8.0);
interleavedPos = clamp(interleavedPos, 0.0, 7.999);
#if UNITY_SINGLE_PASS_STEREO
float4 scaleOffset = unity_StereoScaleOffset[unity_StereoEyeIndex];
interleavedPos = (interleavedPos - scaleOffset.zw) / scaleOffset.xy;
#endif
float4 ditherUV = saturate(float4(interleavedPos / 8.0 + float2(0.5 / 8.0, 0.5 / 8.0),0,0));
float offset = tex2Dlod(_DitherTexture, ditherUV).w; //+ _Randomness.xy
int stepCount = _Steps;
float stepSize = rayLength / stepCount;
float3 step = rayDir * stepSize;
float stepSizeLights = rayLengthLights / stepCount;
float3 stepLights = rayDir * stepSizeLights;
float3 currentPositionDithered = rayStart + step * offset;
float3 currentPositionLightsDithered = rayStart + stepLights * offset;
float3 currentPosition = rayStart + step;
float4 color = float4(0.0,0.0,0.0,0);
float cosAngle;
float extinction = 0;
float transmitance = 0;
float ambient = 0;
cosAngle = dot(_DirLightDir.xyz, -rayDir);
float ani = anisotropy(cosAngle);
float4 lightsColor = float4(0,0,0,0);
[loop]
for (int i = 0; i < stepCount; i++)
{
float density = GetDensity(currentPosition, density, linearDepth, rayDir);
float atten = DirectionalLight(currentPositionDithered) * 0.1;
//Cloud Shadows
//float cloudShadows = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CloudsTex,uv).b;
//atten *= (1-cloudShadows);
float scattering = _VolumetricLight.x * density;
extinction += _VolumetricLight.y * density;
transmitance += atten * scattering * exp(-extinction);
#if !SHADER_API_GLES3
lightsColor.rgb += PointLights(currentPositionLightsDithered) * stepSizeLights * density;
lightsColor.rgb += SpotLights(currentPositionLightsDithered) * stepSizeLights * density;
#endif
currentPosition += step;
currentPositionDithered += step;
currentPositionLightsDithered += stepLights;
}
//color.rgb = _DirLightColor.rgb * transmitance * ani;
color.a = transmitance * ani;
color.rgb += lightsColor.rgb * 0.1;
color = max(0, color);
return color;
}
float4 frag (v2f i) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
float2 uv = i.uv.xy;
float depth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(uv)).r;
float linearDepth = Linear01Depth(depth,_ZBufferParams);
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 = i.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
float3 wpos = mul(eyeToWorld, viewPos).xyz;
float3 rayStart = _WorldSpaceCameraPos;
float3 rayDir = wpos - _WorldSpaceCameraPos;
//rayDir *= linearDepth;
float rayLength = length(rayDir);
rayDir /= rayLength;
float rayLengthLights = min(rayLength, _MaxRayLengthLights);
rayLength = min(rayLength, _MaxRayLength);
float4 color = RayMarch(uv, i.position.xy, rayStart, rayDir, rayLength, rayLengthLights, linearDepth);
return color;
}
#else
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
// just invert the colors
col.rgb = 1 - col.rgb;
return col;
}
#endif
ENDHLSL
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 48155ce484c07e140a82661968a2c303
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.2.2
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Fog/EnviroVolumetricsURP.shader
uploadId: 766468

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f5f639f1135f5a84994c6e7ed5060724
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7a1642594534635429ca94e74de65d26
timeCreated: 1452690568
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: c3082087955cba844a717ad38fde3a0d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 65b7a748fa7b55b48b3001df25bcf1da
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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.81.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);
}

View File

@@ -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

View File

@@ -0,0 +1,2 @@
TEXTURE2D_X(_MainTex);
TEXTURE2D_X(_DownsampledDepth);

View File

@@ -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

View File

@@ -0,0 +1,3 @@
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
UNITY_DECLARE_SCREENSPACE_TEXTURE(_DownsampledDepth);
UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthTexture);

View File

@@ -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

View File

@@ -0,0 +1,6 @@
TEXTURE2D_X(_MainTex);
SAMPLER(sampler_MainTex);
TEXTURE2D_X_FLOAT(_DownsampledDepth);
SAMPLER (sampler_DownsampledDepth);
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER (sampler_CameraDepthTexture);

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 78ef83094a6b4b147988c1b2c3208de0
timeCreated: 1505167667
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 063ea7192fc37c046b8fb48f56df9c36
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,86 @@
Shader "Enviro3/Lightning" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_BrightnessMod("Brightness Mod ", float) = 250
_Brightness("Brightness ", float) = 250
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Blend One One
ColorMask RGBA
Cull Off Lighting Off ZWrite Off
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#pragma exclude_renderers gles
#include "UnityCG.cginc"
#include "../Includes/FogInclude.cginc"
sampler2D _MainTex;
float4 _TintColor;
float _Brightness = 1;
float _BrightnessMod = 1;
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
float4 wpos : TEXCOORD1;
float4 screenPos : TEXCOORD2;
UNITY_VERTEX_OUTPUT_STEREO
};
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
float3 viewVector = mul(unity_CameraInvProjection, float4(v.texcoord.xy * 5 - 1, 0, 1));
o.wpos = mul(unity_CameraToWorld, float4(viewVector, 0));
o.screenPos = ComputeScreenPos(v.vertex);
return o;
}
float4 frag (v2f i) : SV_Target
{
float3 worldPos = i.wpos.xyz;
float2 screenPos = (i.screenPos.xy/i.screenPos.w);
float depth = i.screenPos.w;
float4 col = tex2D(_MainTex, i.texcoord) * _TintColor;
col.rgb *= _Brightness * _BrightnessMod;
//col.rgb = ApplyFogAndVolumetricLights(col.rgb,screenPos,worldPos,depth);
col.rgb *= col.a;
return col;
}
ENDCG
}
}
}
Fallback "Legacy Shaders/Transparent/Diffuse"
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: c4e70ee8d55671543812ab0b45569cac
timeCreated: 1506252156
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/Particles/EnviroLightning.shader
uploadId: 660896

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 31631703daf9c884794d258836be1414
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.2.0
assetPath: Assets/Enviro 3 - Sky and Weather/Resources/Shader/Particles/EnviroParticles.shadergraph
uploadId: 721859

View File

@@ -0,0 +1,100 @@
Shader "Enviro3/Particles/WeatherParticles"
{
Properties
{
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Particle Texture", 2D) = "white" {}
//_EnviroLightIntensity ("Light Intensity", Range(0.0,1.0)) = 1.0
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGBA
Cull Off Lighting Off ZWrite Off
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma multi_compile_particles
#pragma multi_compile_fog
#pragma exclude_renderers gles
#include "UnityCG.cginc"
#if !SHADER_API_GLES3
#include "../Includes/ParticlesInclude.cginc"
#endif
sampler2D _MainTex;
fixed4 _TintColor;
float4 _EnviroLighting;
float _EnviroLightIntensity;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 projPos : TEXCOORD2;
float3 posWorld : TEXCOORD3;
UNITY_VERTEX_OUTPUT_STEREO
};
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
o.projPos = ComputeScreenPos (o.vertex);
COMPUTE_EYEDEPTH(o.projPos.z);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
fixed4 frag (v2f i) : SV_Target
{
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
#ifdef SOFTPARTICLES_ON
float partZ = i.projPos.z;
float fade = saturate (0.5 * (sceneZ-partZ));
i.color.a *= fade;
#endif
float4 tex = tex2D(_MainTex, i.texcoord);
float4 col = 2.0f * i.color * _TintColor * tex;
col.a = i.color.a * _TintColor.a * tex.a;
UNITY_APPLY_FOG(i.fogCoord, col);
//float4 fog = TransparentFog(col,i.posWorld,i.projPos.xy,sceneZ);
float blend = 1.0;
#if !SHADER_API_GLES3
ParticleZones(i.posWorld, blend);
#endif
return float4(col.rgb * max(_EnviroLightIntensity,0.1) ,col.a * blend);
}
ENDCG
}
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 597c4df509f19284bb7be42cdbb56996
timeCreated: 1472601408
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/Particles/EnviroWeatherParticles.shader
uploadId: 660896

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d16122c82e783fc409e683db24b66aed
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,256 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Hidden/EnviroCubemapBlur" {
Properties {
_MainTex ("Main", CUBE) = "" {}
_Texel ("Texel", Float) = 0.0078125
_Level ("Level", Float) = 0.
}
CGINCLUDE
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "HLSLSupport.cginc"
struct v2f {
half4 pos : SV_POSITION;
half4 uvw : TEXCOORD0;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uvw = v.texcoord;
return o;
}
UNITY_DECLARE_TEXCUBE(_MainTex);
half _Level; // Workaround for Metal driver bug: please keep this uniform aligned to 4 bytes (case 899153)
half _Texel;
#define zero half3(0., 0., 0.)
#define one half3(1., 1., 1.)
#define two half3(2., 2., 2.)
half3 fold(half3 st, half3 face)
{
half3 c = min(max(st, -one), one);
half3 f = abs(st - c);
half m = max(max(f.x, f.y), f.z);
return c - m*face;
}
half3 gauss(half d)
{
// compute coefficients for positions 0., 1.*d/.5 and 2.*d/.5
// this assumes a sigma of .5 for a density of 1.
half3 v = half3(0., 1.*d, 2.*d);
return exp(-v*v);
}
half4 frag(v2f i) : SV_Target
{
#if (SHADER_TARGET < 30)
return UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, i.uvw.xyz, _Level);
#else
half3 st;
half3 face = abs(i.uvw.xyz)==one ? i.uvw.xyz : zero;
half3 u = face.zxy*_Texel;
half3 v = face.yzx*_Texel;
half4 s = float4(i.uvw.xyz*(one - abs(face)), 0.);
// modulate coefficients based on position (texel density on projected sphere)
half w = 1. / sqrt(1. + dot(s.xyz, s.xyz));
half3 C = gauss(w*w*w);
half4 s1, s2, s3;
half3 c;
s = 0.;
w = 0.;
// first row
c = C.xyz*C.zzz;
st = i.uvw.xyz - 2.*u - 2.*v;
st = fold(st, face);
s3 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 1.*u - 2.*v;
st = fold(st, face);
s2 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 2.*v;
st = fold(st, face);
s1 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 1.*u - 2.*v;
st = fold(st, face);
s2 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 2.*u - 2.*v;
st = fold(st, face);
s3 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
w += c.x + dot(c.yz, two.yz);
s1 = c.x*s1 + c.y*s2;
s += c.z*s3;
s += s1;
// second row
c = C.xyz*C.yyy;
st = i.uvw.xyz + 2.*u - 1.*v;
st = fold(st, face);
s3 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 1.*u - 1.*v;
st = fold(st, face);
s2 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 1.*v;
st = fold(st, face);
s1 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 1.*u - 1.*v;
st = fold(st, face);
s2 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 2.*u - 1.*v;
st = fold(st, face);
s3 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
w += c.x + dot(c.yz, two.yz);
s1 = c.x*s1 + c.y*s2;
s += c.z*s3;
s += s1;
// third row
c = C.xyz*C.xxx;
st = i.uvw.xyz - 2.*u;
st = fold(st, face);
s3 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 1.*u;
st = fold(st, face);
s2 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz;
s1 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 1.*u;
s2 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 2.*u;
st = fold(st, face);
s3 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
w += c.x + dot(c.yz, two.yz);
s1 = c.x*s1 + c.y*s2;
s += c.z*s3;
s += s1;
// fourth row
c = C.xyz*C.yyy;
st = i.uvw.xyz + 2.*u + 1.*v;
st = fold(st, face);
s3 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 1.*u + 1.*v;
st = fold(st, face);
s2 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 1.*v;
st = fold(st, face);
s1 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 1.*u + 1.*v;
st = fold(st, face);
s2 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 2.*u + 1.*v;
st = fold(st, face);
s3 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
w += c.x + dot(c.yz, two.yz);
s1 = c.x*s1 + c.y*s2;
s += c.z*s3;
s += s1;
// fifth row
c = C.xyz*C.zzz;
st = i.uvw.xyz - 2.*u + 2.*v;
st = fold(st, face);
s3 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz - 1.*u + 2.*v;
st = fold(st, face);
s2 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 2.*v;
st = fold(st, face);
s1 = UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 1.*u + 2.*v;
st = fold(st, face);
s2 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
st = i.uvw.xyz + 2.*u + 2.*v;
st = fold(st, face);
s3 += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, st, _Level);
w += c.x + dot(c.yz, two.yz);
s1 = c.x*s1 + c.y*s2;
s += c.z*s3;
s += s1;
//return half4(C.zzz, 1.);
return s/w;
#endif
}
ENDCG
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
ZTest Always
Blend Off
AlphaTest off
Cull Off
ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma target 3.0
ENDCG
}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass {
ZTest Always
Blend Off
AlphaTest off
Cull Off
ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma target 2.0
ENDCG
}
}
}

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: a8dc759a3008f9e4d93036801febc85b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
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/ReflectionProbe/EnviroCubemapBlur.shader
uploadId: 660896

View File

@@ -0,0 +1,55 @@
Shader "Hidden/Enviro/ReflectionProbe"
{
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Pass
{
ZTest Always
Cull Off
ZWrite Off
Blend Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 pos : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.uv.x = 1 - o.uv.x;
return o;
}
float4 frag(v2f IN) : COLOR
{
return tex2D(_MainTex, IN.uv);
}
ENDCG
}
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 707d8faf84657f04a9c425ceb1e54b2e
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/ReflectionProbe/EnviroReflectionProbe.shader
uploadId: 660896

Some files were not shown because too many files have changed in this diff Show More