Add shaders
This commit is contained in:
-181
@@ -1,181 +0,0 @@
|
||||
|
||||
Shader "Enviro/Lite/EnviroFogRendering"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("Base (RGB)", Any) = "white" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 3.0
|
||||
|
||||
// Start: LuxWater
|
||||
#pragma multi_compile __ LUXWATER_DEFERREDFOG
|
||||
|
||||
#if defined(LUXWATER_DEFERREDFOG)
|
||||
sampler2D _UnderWaterMask;
|
||||
float4 _LuxUnderWaterDeferredFogParams; // x: IsInsideWatervolume?, y: BelowWaterSurface shift, z: EdgeBlend
|
||||
#endif
|
||||
// End: LuxWater
|
||||
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "../../../Core/Resources/Shaders/Core/EnviroFogCore.cginc"
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
|
||||
uniform float4x4 _LeftWorldFromView;
|
||||
uniform float4x4 _RightWorldFromView;
|
||||
uniform float4x4 _LeftViewFromScreen;
|
||||
uniform float4x4 _RightViewFromScreen;
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
float3 sky : TEXCOORD1;
|
||||
float2 uv : TEXCOORD2;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
|
||||
v2f vert(appdata_img v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v); //Insert
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Insert
|
||||
o.pos = v.vertex * float4(2, 2, 1, 1) + float4(-1, -1, 0, 0);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y > 0)
|
||||
o.uv.y = 1 - o.uv.y;
|
||||
#endif
|
||||
o.sky.x = saturate(_SunDir.y + 0.25);
|
||||
o.sky.y = saturate(clamp(1.0 - _SunDir.y, 0.0, 0.5));
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
|
||||
float rawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
float dpth = Linear01Depth(rawDepth);
|
||||
|
||||
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 = rawDepth; // 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
|
||||
|
||||
float4 wsPos = float4(mul(eyeToWorld, viewPos).xyz, 1);
|
||||
float4 wsDir = wsPos - float4(_WorldSpaceCameraPos, 0);
|
||||
|
||||
float3 viewDir = normalize(wsDir);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
half fogFac = 0;
|
||||
float4 finalFog = 0;
|
||||
float g = _DistanceParams.x;
|
||||
half gAdd = 0;
|
||||
|
||||
if (_EnviroParams.z > 0)
|
||||
{
|
||||
gAdd = ComputeHalfSpace (wsDir);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Scene
|
||||
if (dpth < 0.99999)
|
||||
{
|
||||
// Calculate Distance Fog
|
||||
if (_EnviroParams.y > 0)
|
||||
{
|
||||
g += ComputeDistance(wsDir, dpth);
|
||||
g *= _distanceFogIntensity;
|
||||
}
|
||||
|
||||
// AAdd Height Fog
|
||||
g += gAdd;
|
||||
|
||||
// Compute fog amount
|
||||
fogFac = ComputeFogFactor(max(0.0, g));
|
||||
fogFac = lerp(_maximumFogDensity, 1.0f, fogFac);
|
||||
|
||||
finalFog = ComputeScatteringScene(viewDir, i.sky.xy);
|
||||
|
||||
}
|
||||
else //SKY
|
||||
{
|
||||
float f = saturate(_EnviroSkyFog.x * (viewDir.y + _EnviroSkyFog.z));
|
||||
f = pow(f, _EnviroSkyFog.y);
|
||||
fogFac = (clamp(f, 0, 1));
|
||||
finalFog = ComputeScatteringScene(viewDir, i.sky.xy);
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// Start: LuxWater
|
||||
#if defined(LUXWATER_DEFERREDFOG)
|
||||
half4 fogMask = tex2D(_UnderWaterMask, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
float watersurfacefrombelow = DecodeFloatRG(fogMask.ba);
|
||||
|
||||
// Get distance and lower it a bit in order to handle edge blending artifacts (edge blended parts would not get ANY fog)
|
||||
float dist = (watersurfacefrombelow - dpth) + _LuxUnderWaterDeferredFogParams.y * _ProjectionParams.w;
|
||||
// Fade fog from above water to below water
|
||||
float fogFactor = saturate(1.0 + _ProjectionParams.z * _LuxUnderWaterDeferredFogParams.z * dist);
|
||||
// Clamp above result to where water is actually rendered
|
||||
fogFactor = (fogMask.r == 1) ? fogFactor : 1.0;
|
||||
// Mask fog on underwarter parts - only if we are inside a volume (bool... :( )
|
||||
if (_LuxUnderWaterDeferredFogParams.x) {
|
||||
fogFactor *= saturate(1.0 - fogMask.g * 8.0);
|
||||
if (dist < -_ProjectionParams.w * 4 && fogMask.r == 0 && fogMask.g < 1.0) {
|
||||
fogFactor = 1.0;
|
||||
}
|
||||
}
|
||||
// Tweak fog factor
|
||||
fogFac = lerp(1.0, fogFac, fogFactor);
|
||||
#endif
|
||||
// End: LuxWater
|
||||
|
||||
float4 source = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
return lerp (finalFog, source, fogFac);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
Fallback Off
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b0160f40adf130428015ffb5bfdb8a5
|
||||
timeCreated: 1459178236
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
-161
@@ -1,161 +0,0 @@
|
||||
|
||||
Shader "Enviro/Lite/EnviroFogRenderingSimple"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("Base (RGB)", Any) = "white" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
|
||||
|
||||
uniform float4x4 _LeftWorldFromView;
|
||||
uniform float4x4 _RightWorldFromView;
|
||||
uniform float4x4 _LeftViewFromScreen;
|
||||
uniform float4x4 _RightViewFromScreen;
|
||||
uniform float4 _EnviroParams;
|
||||
uniform float4 _DistanceParams;
|
||||
uniform int4 _SceneFogMode;
|
||||
uniform float4 _SceneFogParams;
|
||||
uniform half _distanceFogIntensity;
|
||||
uniform float4 _EnviroSkyFog; // x = _SkyFogHeight, y = _SkyFogIntensity, z = _SkyFogStart, w = _HeightFogIntensity
|
||||
uniform float _maximumFogDensity;
|
||||
uniform float _lightning;
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
float2 uv : TEXCOORD1;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
|
||||
v2f vert(appdata_img v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v); //Insert
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Insert
|
||||
o.pos = v.vertex * float4(2, 2, 1, 1) + float4(-1, -1, 0, 0);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y > 0)
|
||||
o.uv.y = 1 - o.uv.y;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
half ComputeFogFactor(float coord)
|
||||
{
|
||||
float fogFac = 0.0;
|
||||
|
||||
if (_SceneFogMode.x == 1) // linear
|
||||
{
|
||||
fogFac = coord * _SceneFogParams.z + _SceneFogParams.w;
|
||||
}
|
||||
|
||||
if (_SceneFogMode.x >= 2) // exp
|
||||
{
|
||||
fogFac = _SceneFogParams.y * coord; fogFac = exp2(-fogFac);
|
||||
}
|
||||
|
||||
return saturate(fogFac);
|
||||
}
|
||||
|
||||
// Distance fog
|
||||
float ComputeDistance(float3 camDir, float zdepth)
|
||||
{
|
||||
float dist;
|
||||
dist = length(camDir);
|
||||
dist -= _ProjectionParams.y;
|
||||
return dist;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
|
||||
float rawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
float dpth = Linear01Depth(rawDepth);
|
||||
|
||||
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 = rawDepth; // 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
|
||||
|
||||
float4 wsPos = float4(mul(eyeToWorld, viewPos).xyz, 1);
|
||||
float4 wsDir = wsPos - float4(_WorldSpaceCameraPos, 0);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
half fogFac = 0;
|
||||
float4 finalFog = unity_FogColor;
|
||||
float g = _DistanceParams.x;
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Scene
|
||||
if (dpth < 0.99999)
|
||||
{
|
||||
// Calculate Distance Fog
|
||||
if (_EnviroParams.y > 0)
|
||||
{
|
||||
g += ComputeDistance(wsDir,dpth);
|
||||
g *= _distanceFogIntensity;
|
||||
}
|
||||
|
||||
// Compute fog amount
|
||||
fogFac = ComputeFogFactor(max(0.0, g));
|
||||
fogFac = lerp(_maximumFogDensity, 1.0f, fogFac);
|
||||
}
|
||||
else //SKY
|
||||
{
|
||||
float3 viewDir = normalize(wsDir);
|
||||
float f = saturate(_EnviroSkyFog.x * (viewDir.y + _EnviroSkyFog.z));
|
||||
f = pow(f, _EnviroSkyFog.y);
|
||||
fogFac = clamp(f, 0, 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
float4 source = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
return lerp (finalFog, source, fogFac);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
Fallback Off
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52f9d6fdd8d48b54d9e1538255a22e9a
|
||||
timeCreated: 1459178236
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
Shader "Enviro/Lite/MoonShader"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("Texture (RGB)", 2D) = "black" {}
|
||||
_Color("Color", Color) = (0.8, 0.8, 0.8, 1)
|
||||
_Brightness("Brightness", Float) = 5
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"RenderType"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
}
|
||||
Pass
|
||||
{
|
||||
Cull Back
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
uniform float4 _SunPosition;
|
||||
uniform float4 _MoonPosition;
|
||||
uniform sampler2D _MainTex;
|
||||
uniform float4 _MainTex_ST;
|
||||
uniform float4 _Color;
|
||||
uniform float _Brightness;
|
||||
uniform float _moonFogIntensity;
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float3 normal : TEXCOORD0;
|
||||
float3 worldvertpos : TEXCOORD1;
|
||||
float2 texcoord : TEXCOORD2;
|
||||
};
|
||||
|
||||
v2f vert(appdata_base v)
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.normal = mul((float3x3)unity_ObjectToWorld, v.normal);
|
||||
o.worldvertpos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(v2f i) : COLOR
|
||||
{
|
||||
|
||||
float3 sunPos = _SunPosition;
|
||||
float3 moonPos = _MoonPosition;
|
||||
|
||||
float3 lightVector = normalize(_SunPosition - moonPos);
|
||||
|
||||
i.normal = normalize(i.normal);
|
||||
|
||||
float3 clr = tex2D(_MainTex, i.texcoord) * _Color;
|
||||
clr = pow(clr, 0.3);
|
||||
float d = saturate(max(0.0,dot(i.normal,lightVector)) * 2);
|
||||
clr = (clr * d) * _Brightness;
|
||||
|
||||
return float4(clr * _moonFogIntensity,1);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a73bcd29e414e34fb7b2b7eb7f75155
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Enviro/Lite/MoonShaderPhased"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Moon Texture", 2D) = "white" {}
|
||||
_Phase ("Moon Phase", float) = 0
|
||||
_Brightness ("Moon Brightness", Range(0.1,5)) = 0.5
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{"Queue"="Transparent"
|
||||
"RenderType"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
}
|
||||
|
||||
Fog
|
||||
{
|
||||
Mode Off
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Cull Back
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
#pragma target 2.0
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
uniform float4 _MainTex_ST;
|
||||
uniform float _Phase;
|
||||
uniform float _Brightness;
|
||||
uniform float _moonFogIntensity;
|
||||
|
||||
struct v2f {
|
||||
float4 position : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 uv_MainTex : TEXCOORD0;
|
||||
float3 normal : TEXCOORD1;
|
||||
float3 viewdir : TEXCOORD2;
|
||||
};
|
||||
|
||||
float MoonPhaseFactor(float2 uv, float phase)
|
||||
{
|
||||
float alpha = 1.0;
|
||||
|
||||
float srefx = uv.x - 0.5;
|
||||
float refx = abs(uv.x - 0.5);
|
||||
float refy = abs(uv.y - 0.5);
|
||||
float refxfory = sqrt(0.25 - refy * refy);
|
||||
float xmin = -refxfory;
|
||||
float xmax = refxfory;
|
||||
float xmin1 = (xmax - xmin) * (phase / 2) + xmin;
|
||||
float xmin2 = (xmax - xmin) * phase + xmin;
|
||||
if (srefx < xmin1) {
|
||||
alpha = 0;
|
||||
} else if (srefx < xmin2 && xmin1 != xmin2) {
|
||||
alpha = (srefx - xmin1) / (xmin2 - xmin1);
|
||||
}
|
||||
return alpha;
|
||||
}
|
||||
|
||||
v2f vert(appdata_base v) {
|
||||
v2f o;
|
||||
|
||||
float phaseabs = abs(_Phase);
|
||||
float3 offset = 10 * float3(_Phase, -phaseabs, -phaseabs);
|
||||
|
||||
float3 normal = v.normal;
|
||||
float3 viewdir = normalize(ObjSpaceViewDir(v.vertex));
|
||||
|
||||
o.position = UnityObjectToClipPos(v.vertex);
|
||||
o.color.rgb = 1 - phaseabs;
|
||||
o.color.a = 1;
|
||||
o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
o.normal = v.normal;
|
||||
o.viewdir = normalize(viewdir + offset);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : COLOR {
|
||||
fixed4 color = i.color;
|
||||
|
||||
float alpha = MoonPhaseFactor(i.uv_MainTex, abs(_Phase));
|
||||
fixed shading = max(0, dot(i.normal, i.viewdir));
|
||||
color.rgb *= pow(shading, 0.5);
|
||||
|
||||
// Moon texture
|
||||
fixed3 moontex = tex2D(_MainTex, i.uv_MainTex);
|
||||
color.rgb *= moontex.rgb * 2.5;
|
||||
|
||||
float lum = dot(color.rgb, float3(0.8, 0.8, 0.8));
|
||||
color.a = min(color.a, lum * alpha);
|
||||
color.rgb = saturate(1.0 - exp(-_Brightness * color.rgb));
|
||||
return float4(color.rgb, color.a * _moonFogIntensity);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1b5f57aa0d6ff9438d0e14cc18c4506
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
Reference in New Issue
Block a user