Readd missing import files
This commit is contained in:
+565
@@ -0,0 +1,565 @@
|
||||
// Upgrade NOTE: replaced 'defined UNITY2017_2_SP' with 'defined (UNITY2017_2_SP)'
|
||||
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
// 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/EnviroBilateralBlur"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("Texture", any) = "" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
// No culling or depth
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#pragma shader_feature UNITY2017_2_SP
|
||||
//--------------------------------------------------------------------------------------------
|
||||
// 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"
|
||||
|
||||
UNITY_DECLARE_TEX2D(_CameraDepthTexture);
|
||||
UNITY_DECLARE_TEX2D(_HalfResDepthBuffer);
|
||||
UNITY_DECLARE_TEX2D(_QuarterResDepthBuffer);
|
||||
UNITY_DECLARE_TEX2D(_HalfResColor);
|
||||
UNITY_DECLARE_TEX2D(_QuarterResColor);
|
||||
UNITY_DECLARE_TEX2D(_MainTex);
|
||||
|
||||
float4 _CameraDepthTexture_TexelSize;
|
||||
float4 _HalfResDepthBuffer_TexelSize;
|
||||
float4 _QuarterResDepthBuffer_TexelSize;
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
struct v2fUpsample
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv00 : TEXCOORD1;
|
||||
float2 uv01 : TEXCOORD2;
|
||||
float2 uv10 : TEXCOORD3;
|
||||
float2 uv11 : TEXCOORD4;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.uv;
|
||||
return o;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
// vertDownsampleDepth
|
||||
//-----------------------------------------------------------------------------------------
|
||||
v2fDownsample vertDownsampleDepth(appdata v, float2 texelSize)
|
||||
{
|
||||
v2fDownsample o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
#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;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
// BilateralUpsample
|
||||
//-----------------------------------------------------------------------------------------
|
||||
float4 BilateralUpsample(v2fUpsample input, Texture2D hiDepth, Texture2D loDepth, Texture2D loColor, SamplerState linearSampler, SamplerState pointSampler)
|
||||
{
|
||||
const float threshold = UPSAMPLE_DEPTH_THRESHOLD;
|
||||
float4 highResDepth = LinearEyeDepth(hiDepth.Sample(pointSampler, input.uv)).xxxx;
|
||||
float4 lowResDepth;
|
||||
|
||||
lowResDepth[0] = LinearEyeDepth(loDepth.Sample(pointSampler, input.uv00));
|
||||
lowResDepth[1] = LinearEyeDepth(loDepth.Sample(pointSampler, input.uv10));
|
||||
lowResDepth[2] = LinearEyeDepth(loDepth.Sample(pointSampler, input.uv01));
|
||||
lowResDepth[3] = LinearEyeDepth(loDepth.Sample(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
|
||||
{
|
||||
#if defined (UNITY2017_2_SP)
|
||||
return loColor.Sample(linearSampler, UnityStereoTransformScreenSpaceTex(input.uv));
|
||||
#else
|
||||
return loColor.Sample(linearSampler, input.uv);
|
||||
#endif
|
||||
}
|
||||
|
||||
// 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];
|
||||
}
|
||||
|
||||
#if defined (UNITY2017_2_SP)
|
||||
return loColor.Sample(pointSampler, UnityStereoTransformScreenSpaceTex(nearestUv));
|
||||
#else
|
||||
return loColor.Sample(pointSampler, nearestUv);
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
// 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 = depthTexture.Sample(depthSampler, input.uv00).x;
|
||||
depth.y = depthTexture.Sample(depthSampler, input.uv01).x;
|
||||
depth.z = depthTexture.Sample(depthSampler, input.uv10).x;
|
||||
depth.w = depthTexture.Sample(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 = _MainTex.Sample(sampler_MainTex, UnityStereoTransformScreenSpaceTex(uv));
|
||||
float3 color = centerColor.xyz;
|
||||
//return float4(color, 1);
|
||||
float centerDepth = (LinearEyeDepth(depth.Sample(depthSampler, UnityStereoTransformScreenSpaceTex(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 = _MainTex.Sample(sampler_MainTex, UnityStereoTransformScreenSpaceTex(input.uv), offset);
|
||||
float sampleDepth = (LinearEyeDepth(depth.Sample(depthSampler, UnityStereoTransformScreenSpaceTex(input.uv), offset)));
|
||||
|
||||
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 = _MainTex.Sample(sampler_MainTex, UnityStereoTransformScreenSpaceTex(input.uv), offset);
|
||||
float sampleDepth = (LinearEyeDepth(depth.Sample(depthSampler, UnityStereoTransformScreenSpaceTex(input.uv), offset)));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
// pass 0 - horizontal blur (hires)
|
||||
Pass
|
||||
{
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment horizontalFrag
|
||||
#pragma target 3.5
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
|
||||
fixed4 horizontalFrag(v2f input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
fixed4 verticalFrag(v2f input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
fixed4 horizontalFrag(v2f input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
fixed4 verticalFrag(v2f input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
v2fDownsample vertHalfDepth(appdata v)
|
||||
{
|
||||
return vertDownsampleDepth(v, _CameraDepthTexture_TexelSize);
|
||||
}
|
||||
|
||||
float4 frag(v2fDownsample input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
v2fUpsample vertUpsampleToFull(appdata v)
|
||||
{
|
||||
return vertUpsample(v, _HalfResDepthBuffer_TexelSize);
|
||||
}
|
||||
float4 frag(v2fUpsample input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
v2fDownsample vertQuarterDepth(appdata v)
|
||||
{
|
||||
return vertDownsampleDepth(v, _HalfResDepthBuffer_TexelSize);
|
||||
}
|
||||
|
||||
float4 frag(v2fDownsample input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
v2fUpsample vertUpsampleToFull(appdata v)
|
||||
{
|
||||
return vertUpsample(v, _QuarterResDepthBuffer_TexelSize);
|
||||
}
|
||||
float4 frag(v2fUpsample input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
fixed4 horizontalFrag(v2f input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
fixed4 verticalFrag(v2f input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
v2fDownsample vertHalfDepth(appdata v)
|
||||
{
|
||||
return vertDownsampleDepth(v, _CameraDepthTexture_TexelSize);
|
||||
}
|
||||
|
||||
float4 frag(v2fDownsample input) : SV_Target
|
||||
{
|
||||
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
|
||||
|
||||
v2fDownsample vertQuarterDepth(appdata v)
|
||||
{
|
||||
return vertDownsampleDepth(v, _HalfResDepthBuffer_TexelSize);
|
||||
}
|
||||
|
||||
float4 frag(v2fDownsample input) : SV_Target
|
||||
{
|
||||
float depth = DownsampleDepth(input, _HalfResDepthBuffer, sampler_HalfResDepthBuffer);
|
||||
|
||||
return float4(depth,depth,depth,depth);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 307338a0d8294f440853ba6b3a56cf54
|
||||
timeCreated: 1459178236
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
// MODIFIED FOR ENVIRO POST PROCESSING
|
||||
//
|
||||
// Kino/Bloom v2 - Bloom filter for Unity
|
||||
//
|
||||
// Copyright (C) 2015, 2016 Keijiro Takahashi
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
Shader "Hidden/EnviroDistanceBlur"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("", any) = "" {}
|
||||
_BaseTex("", any) = "" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
// 0: Prefilter
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_prefilter
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 1: Prefilter with anti-flicker
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define ANTI_FLICKER 1
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_prefilter
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 2: First level downsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_downsample1
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 3: First level downsampler with anti-flicker
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define ANTI_FLICKER 1
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_downsample1
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 4: Second level downsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag_downsample2
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 5: Upsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 6: High quality upsampler
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define HIGH_QUALITY 1
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 7: Combiner
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample_final
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
// 8: High quality combiner
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
CGPROGRAM
|
||||
#define HIGH_QUALITY 1
|
||||
#pragma multi_compile _ UNITY_COLORSPACE_GAMMA
|
||||
#include "../Core/EnviroBlurCore.cginc"
|
||||
#pragma vertex vert_multitex
|
||||
#pragma fragment frag_upsample_final
|
||||
#pragma target 3.0
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e01d888ba8d52d4283fc169b2717e27
|
||||
timeCreated: 1540850786
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+292
@@ -0,0 +1,292 @@
|
||||
|
||||
Shader "Enviro/Standard/EnviroFogRendering"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_EnviroVolumeLightingTex("Volume Lighting Tex", Any) = ""{}
|
||||
_MainTex("Source", Any) = "black"{}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 3.0
|
||||
#pragma multi_compile __ ENVIROVOLUMELIGHT
|
||||
#pragma multi_compile __ ENVIRO_DEPTHBLENDING
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
// 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/EnviroVolumeLightCore.cginc"
|
||||
#include "../../../../Core/Resources/Shaders/Core/EnviroFogCore.cginc"
|
||||
|
||||
//uniform sampler2D _MainTex;
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
uniform sampler3D _FogNoiseTexture;
|
||||
uniform float _DitheringIntensity;
|
||||
|
||||
#ifdef ENVIRO_DEPTHBLENDING
|
||||
uniform sampler2D _EnviroCloudsTex;
|
||||
#endif
|
||||
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;
|
||||
float4 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;
|
||||
}
|
||||
|
||||
float3 ScreenSpaceDither(float2 vScreenPos, float3 clr)
|
||||
{
|
||||
float d = dot(float2(131.0, 312.0), vScreenPos.xy + _Time.y);
|
||||
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) * _DitheringIntensity;
|
||||
}
|
||||
|
||||
// Linear height fog function
|
||||
float ComputeHalfSpaceWithNoise(float3 wsDir)
|
||||
{
|
||||
float3 wpos = _WorldSpaceCameraPos + wsDir;
|
||||
float FH = _HeightParams.x;
|
||||
float3 C = _WorldSpaceCameraPos;
|
||||
float3 V = wsDir;
|
||||
float3 P = wpos;
|
||||
float3 aV = (_HeightParams.w * _EnviroSkyFog.w) * V;
|
||||
float noise = tex3D(_FogNoiseTexture, frac(wpos * _FogNoiseData.x + float3(_Time.y * _FogNoiseVelocity.x, 0, _Time.y * _FogNoiseVelocity.y)));
|
||||
// float noise = tex3D(_FogNoiseTexture, wpos * 0.01);
|
||||
noise = saturate(noise - _FogNoiseData.z) * _FogNoiseData.y;
|
||||
aV *= noise;
|
||||
float FdotC = _HeightParams.y;
|
||||
float k = _HeightParams.z;
|
||||
float FdotP = P.y - FH;
|
||||
float FdotV = wsDir.y;
|
||||
float c1 = k * (FdotP + FdotC);
|
||||
float c2 = (1 - 2 * k) * FdotP;
|
||||
float g = min(c2, 0.0);
|
||||
g = -length(aV) * (c1 - g * g / abs(FdotV + 1.0e-5f));
|
||||
return g;
|
||||
}
|
||||
|
||||
float Remap(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));
|
||||
}
|
||||
|
||||
/// Main Fragment Shader
|
||||
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 gHeight = 0;
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Scene
|
||||
if (dpth < 0.99)
|
||||
{
|
||||
// Calculate Distance Fog
|
||||
if (_EnviroParams.y > 0)
|
||||
{
|
||||
g += ComputeDistance(wsDir, dpth);
|
||||
g *= _distanceFogIntensity;
|
||||
}
|
||||
|
||||
if (_EnviroParams.z > 0)
|
||||
{
|
||||
gHeight = ComputeHalfSpaceWithNoise(wsDir) * (1 - dpth);
|
||||
}
|
||||
//gHeight = lerp(0.75, 1.0, dpth);
|
||||
|
||||
|
||||
// Add Height Fog
|
||||
g += gHeight;
|
||||
|
||||
// Compute fog amount
|
||||
fogFac = ComputeFogFactor(max(0.0, g));
|
||||
|
||||
|
||||
#ifdef ENVIRO_DEPTHBLENDING
|
||||
float4 clouds = tex2D(_EnviroCloudsTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
|
||||
if (clouds.a > 0.9)
|
||||
{
|
||||
|
||||
if (_EnviroParams.z > 0 && _SceneFogMode.w == 1)
|
||||
{
|
||||
gHeight = ComputeHalfSpace(wsDir);
|
||||
}
|
||||
|
||||
half fogFacSky = ComputeFogFactor(max(0.0, gHeight));
|
||||
float f = saturate(_EnviroSkyFog.x * (viewDir.y + _EnviroSkyFog.z));
|
||||
f = pow(f, _EnviroSkyFog.y);
|
||||
|
||||
fogFac = (clamp(f, 0, 1));
|
||||
|
||||
float skyLerp = Remap(_WorldSpaceCameraPos.y, 0, _SunParameters.w, 0, 1);
|
||||
fogFac = lerp(fogFac, 1, skyLerp);
|
||||
}
|
||||
//fogFac = 1;
|
||||
#endif
|
||||
|
||||
|
||||
fogFac = lerp(_maximumFogDensity, 1.0f, fogFac);
|
||||
finalFog = ComputeScatteringScene(viewDir, i.sky.xy);
|
||||
|
||||
}
|
||||
else //SKY
|
||||
{
|
||||
if (_EnviroParams.z > 0 && _SceneFogMode.w == 1)
|
||||
{
|
||||
gHeight = ComputeHalfSpace(wsDir);
|
||||
}
|
||||
|
||||
half fogFacSky = ComputeFogFactor(max(0.0, gHeight));
|
||||
float f = saturate(_EnviroSkyFog.x * (viewDir.y + _EnviroSkyFog.z));
|
||||
f = pow(f, _EnviroSkyFog.y);
|
||||
|
||||
fogFac = (clamp(f, 0, 1));
|
||||
|
||||
if (fogFac > fogFacSky)
|
||||
fogFac = fogFacSky;
|
||||
|
||||
float skyLerp = Remap(_WorldSpaceCameraPos.y, 0, _SunParameters.w, 0, 1);
|
||||
fogFac = lerp(fogFac, 1, skyLerp);
|
||||
float4 skyFog = ComputeScatteringScene(viewDir, i.sky.xy);
|
||||
|
||||
finalFog = skyFog;
|
||||
}
|
||||
|
||||
//Dithering
|
||||
finalFog.rgb = finalFog.rgb + ScreenSpaceDither(i.pos.xy, finalFog.rgb);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Composing
|
||||
|
||||
// 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 final;
|
||||
float4 source = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
|
||||
#if defined (ENVIROVOLUMELIGHT)
|
||||
float4 volumeLighting = tex2D(_EnviroVolumeLightingTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
volumeLighting *= _EnviroParams.x;
|
||||
|
||||
if (_EnviroParams.w == 1)
|
||||
{
|
||||
volumeLighting.rgb = tonemapACES(volumeLighting.rgb, 1.0);
|
||||
}
|
||||
|
||||
// Start: LuxWater
|
||||
#if defined(LUXWATER_DEFERREDFOG)
|
||||
volumeLighting *= fogFactor;
|
||||
#endif
|
||||
// End: LuxWater
|
||||
final *= volumeLighting.w;
|
||||
|
||||
final = lerp (lerp(finalFog, finalFog + volumeLighting, _EnviroVolumeDensity), lerp(source, source + volumeLighting, _EnviroVolumeDensity), fogFac);
|
||||
#else
|
||||
final = lerp (finalFog, source, fogFac);
|
||||
#endif
|
||||
|
||||
return final;
|
||||
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback Off
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78aa7501e8e951446b1be533c73e8de6
|
||||
timeCreated: 1459178236
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
|
||||
Shader "Enviro/Standard/EnviroFogRenderingDisabled"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_EnviroVolumeLightingTex("Volume Lighting Tex", Any) = ""{}
|
||||
_MainTex("Source", Any) = "black"{}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 3.0
|
||||
#pragma multi_compile ENVIROVOLUMELIGHT
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
uniform sampler2D _EnviroVolumeLightingTex;
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
uniform float4 _EnviroParams;
|
||||
uniform float _EnviroVolumeDensity;
|
||||
|
||||
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); //Ins
|
||||
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;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
float4 source = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
|
||||
#if defined (ENVIROVOLUMELIGHT)
|
||||
float4 volumeLighting = tex2D(_EnviroVolumeLightingTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
volumeLighting *= _EnviroParams.x;
|
||||
if (_EnviroParams.w == 1)
|
||||
{
|
||||
volumeLighting.rgb = tonemapACES(volumeLighting.rgb, 1.0);
|
||||
}
|
||||
return lerp(source, source + volumeLighting, _EnviroVolumeDensity);
|
||||
#else
|
||||
return source;
|
||||
#endif
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
Fallback Off
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5dbacd27b280d345a34f2ecef4d76fb
|
||||
timeCreated: 1459178236
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
|
||||
Shader "Enviro/Standard/EnviroFogRenderingSimple"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_EnviroVolumeLightingTex("Volume Lighting Tex", Any) = ""{}
|
||||
_MainTex("Source", Any) = "black"{}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off Fog { Mode Off }
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 3.0
|
||||
#pragma multi_compile ENVIROVOLUMELIGHT
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
// 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/EnviroVolumeLightCore.cginc"
|
||||
#include "../../../../Core/Resources/Shaders/Core/EnviroFogCore.cginc"
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
|
||||
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
|
||||
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 = unity_FogColor;
|
||||
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);
|
||||
}
|
||||
else //SKY
|
||||
{
|
||||
half fogFacSky = ComputeFogFactor(max(0.0, gAdd));
|
||||
float f = saturate(_EnviroSkyFog.x * (viewDir.y + _EnviroSkyFog.z));
|
||||
f = pow(f, _EnviroSkyFog.y);
|
||||
fogFac = (clamp(f, 0, 1));
|
||||
|
||||
if (fogFac > fogFacSky)
|
||||
fogFac = fogFacSky;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 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 final;
|
||||
float4 source = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
|
||||
#if defined (ENVIROVOLUMELIGHT)
|
||||
float4 volumeLighting = tex2D(_EnviroVolumeLightingTex, UnityStereoTransformScreenSpaceTex(i.uv));
|
||||
volumeLighting *= _EnviroParams.x;
|
||||
if (_EnviroParams.w == 1)
|
||||
{
|
||||
volumeLighting.rgb = tonemapACES(volumeLighting.rgb, 1.0);
|
||||
}
|
||||
// Start: LuxWater
|
||||
#if defined(LUXWATER_DEFERREDFOG)
|
||||
volumeLighting *= fogFactor;
|
||||
#endif
|
||||
// End: LuxWater
|
||||
final = lerp (lerp(finalFog, finalFog + volumeLighting, _EnviroVolumeDensity), lerp(source, source + volumeLighting, _EnviroVolumeDensity), fogFac);
|
||||
#else
|
||||
final = lerp (finalFog, source, fogFac);
|
||||
#endif
|
||||
|
||||
return final;
|
||||
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
Fallback Off
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 899fe52a053808b40b4f6517d18538bd
|
||||
timeCreated: 1459178236
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+454
@@ -0,0 +1,454 @@
|
||||
// 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.
|
||||
|
||||
//Modified for use with Enviro - Sky and Weather
|
||||
|
||||
|
||||
|
||||
Shader "Enviro/Standard/VolumeLight"
|
||||
{
|
||||
Properties
|
||||
{ _MainTex("Texture", any) = "" {}
|
||||
[HideInInspector]_ZTest ("ZTest", Float) = 0
|
||||
[HideInInspector]_LightColor("_LightColor", Color) = (1,1,1,1)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
CGINCLUDE
|
||||
#if defined(SHADOWS_DEPTH) || defined(SHADOWS_CUBE)
|
||||
#define SHADOWS_NATIVE
|
||||
#endif
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityDeferredLibrary.cginc"
|
||||
#include "../Core/EnviroVolumeLightCore.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float4 uv : TEXCOORD0;
|
||||
float3 wpos : TEXCOORD1;
|
||||
float4 interpolatedRay : TEXCOORD2;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v); //Insert
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Ins
|
||||
if (unity_StereoEyeIndex == 0)
|
||||
o.pos = mul(_WorldViewProj, v.vertex);
|
||||
else
|
||||
o.pos = mul(_WorldViewProj_SP, v.vertex);
|
||||
|
||||
o.uv = ComputeScreenPos(o.pos);
|
||||
o.wpos = mul(unity_ObjectToWorld, v.vertex);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
// pass 0 - point light, camera inside
|
||||
Pass
|
||||
{
|
||||
ZTest Off
|
||||
Cull Front
|
||||
ZWrite Off
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragPointInside
|
||||
#pragma target 3.5
|
||||
#pragma exclude_renderers d3d9 gles
|
||||
|
||||
#define UNITY_HDR_ON
|
||||
|
||||
#pragma shader_feature HEIGHT_FOG
|
||||
#pragma shader_feature NOISE
|
||||
#pragma shader_feature SHADOWS_CUBE
|
||||
#pragma shader_feature POINT_COOKIE
|
||||
#pragma shader_feature POINT
|
||||
|
||||
#ifdef SHADOWS_DEPTH
|
||||
#define SHADOWS_NATIVE
|
||||
#endif
|
||||
|
||||
|
||||
fixed4 fragPointInside(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
float2 uv = i.uv.xy / i.uv.w;
|
||||
|
||||
// read depth and reconstruct world position
|
||||
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(uv,_CameraDepthTexture_ST));
|
||||
|
||||
float3 rayStart = _WorldSpaceCameraPos;
|
||||
float3 rayEnd = i.wpos;
|
||||
|
||||
float3 rayDir = (rayEnd - rayStart);
|
||||
float rayLength = length(rayDir);
|
||||
|
||||
rayDir /= rayLength;
|
||||
|
||||
float linearDepth = LinearEyeDepth(depth);
|
||||
float projectedDepth = linearDepth / dot(_CameraForward, rayDir);
|
||||
rayLength = min(rayLength, projectedDepth);
|
||||
|
||||
return RayMarch(i.pos.xy, rayStart, rayDir, rayLength);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 1 - spot light, camera inside
|
||||
Pass
|
||||
{
|
||||
ZTest Off
|
||||
Cull Front
|
||||
ZWrite Off
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragPointInside
|
||||
#pragma target 3.5
|
||||
#pragma exclude_renderers d3d9 gles
|
||||
|
||||
#define UNITY_HDR_ON
|
||||
|
||||
#pragma shader_feature HEIGHT_FOG
|
||||
#pragma shader_feature NOISE
|
||||
#pragma shader_feature SHADOWS_DEPTH
|
||||
#pragma shader_feature SPOT
|
||||
|
||||
#ifdef SHADOWS_DEPTH
|
||||
#define SHADOWS_NATIVE
|
||||
#endif
|
||||
|
||||
fixed4 fragPointInside(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
float2 uv = i.uv.xy / i.uv.w;
|
||||
|
||||
// read depth and reconstruct world position
|
||||
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(uv,_CameraDepthTexture_ST));
|
||||
|
||||
float3 rayStart = _WorldSpaceCameraPos;
|
||||
float3 rayEnd = i.wpos;
|
||||
|
||||
float3 rayDir = (rayEnd - rayStart);
|
||||
float rayLength = length(rayDir);
|
||||
|
||||
rayDir /= rayLength;
|
||||
|
||||
float linearDepth = LinearEyeDepth(depth);
|
||||
float projectedDepth = linearDepth / dot(_CameraForward, rayDir);
|
||||
rayLength = min(rayLength, projectedDepth);
|
||||
|
||||
return RayMarch(i.pos.xy, rayStart, rayDir, rayLength);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 2 - point light, camera outside
|
||||
Pass
|
||||
{
|
||||
//ZTest Off
|
||||
ZTest [_ZTest]
|
||||
Cull Back
|
||||
ZWrite Off
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragPointOutside
|
||||
#pragma target 3.5
|
||||
#pragma exclude_renderers d3d9 gles
|
||||
|
||||
#define UNITY_HDR_ON
|
||||
|
||||
#pragma shader_feature HEIGHT_FOG
|
||||
#pragma shader_feature SHADOWS_CUBE
|
||||
#pragma shader_feature NOISE
|
||||
#pragma shader_feature POINT_COOKIE
|
||||
#pragma shader_feature POINT
|
||||
|
||||
fixed4 fragPointOutside(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
float2 uv = i.uv.xy / i.uv.w;
|
||||
|
||||
// read depth and reconstruct world position
|
||||
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(uv,_CameraDepthTexture_ST));
|
||||
|
||||
float3 rayStart = _WorldSpaceCameraPos;
|
||||
float3 rayEnd = i.wpos;
|
||||
|
||||
float3 rayDir = (rayEnd - rayStart);
|
||||
float rayLength = length(rayDir);
|
||||
|
||||
rayDir /= rayLength;
|
||||
|
||||
float3 lightToCamera = _WorldSpaceCameraPos - _LightPos;
|
||||
|
||||
float b = dot(rayDir, lightToCamera);
|
||||
float c = dot(lightToCamera, lightToCamera) - (_VolumetricLight.z * _VolumetricLight.z);
|
||||
|
||||
float d = sqrt((b*b) - c);
|
||||
float start = -b - d;
|
||||
float end = -b + d;
|
||||
|
||||
float linearDepth = LinearEyeDepth(depth);
|
||||
float projectedDepth = linearDepth / dot(_CameraForward, rayDir);
|
||||
end = min(end, projectedDepth);
|
||||
|
||||
rayStart = rayStart + rayDir * start;
|
||||
rayLength = end - start;
|
||||
|
||||
return RayMarch(i.pos.xy, rayStart, rayDir, rayLength);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 3 - spot light, camera outside
|
||||
Pass
|
||||
{
|
||||
//ZTest Off
|
||||
ZTest[_ZTest]
|
||||
Cull Back
|
||||
ZWrite Off
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragSpotOutside
|
||||
#pragma target 3.5
|
||||
#pragma exclude_renderers d3d9 gles
|
||||
|
||||
#define UNITY_HDR_ON
|
||||
|
||||
#pragma shader_feature HEIGHT_FOG
|
||||
#pragma shader_feature SHADOWS_DEPTH
|
||||
#pragma shader_feature NOISE
|
||||
#pragma shader_feature SPOT
|
||||
|
||||
#ifdef SHADOWS_DEPTH
|
||||
#define SHADOWS_NATIVE
|
||||
#endif
|
||||
|
||||
float _CosAngle;
|
||||
float4 _ConeAxis;
|
||||
float4 _ConeApex;
|
||||
float _PlaneD;
|
||||
|
||||
fixed4 fragSpotOutside(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
float2 uv = i.uv.xy / i.uv.w;
|
||||
|
||||
// read depth and reconstruct world position
|
||||
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(uv,_CameraDepthTexture_ST));
|
||||
|
||||
float3 rayStart = _WorldSpaceCameraPos;
|
||||
float3 rayEnd = i.wpos;
|
||||
|
||||
float3 rayDir = (rayEnd - rayStart);
|
||||
float rayLength = length(rayDir);
|
||||
|
||||
rayDir /= rayLength;
|
||||
|
||||
|
||||
// inside cone
|
||||
float3 r1 = rayEnd + rayDir * 0.001;
|
||||
|
||||
// plane intersection
|
||||
float planeCoord = RayPlaneIntersect(_ConeAxis, _PlaneD, r1, rayDir);
|
||||
// ray cone intersection
|
||||
float2 lineCoords = RayConeIntersect(_ConeApex, _ConeAxis, _CosAngle, r1, rayDir);
|
||||
|
||||
float linearDepth = LinearEyeDepth(depth);
|
||||
float projectedDepth = linearDepth / dot(_CameraForward, rayDir);
|
||||
|
||||
float z = (projectedDepth - rayLength);
|
||||
rayLength = min(planeCoord, min(lineCoords.x, lineCoords.y));
|
||||
rayLength = min(rayLength, z);
|
||||
|
||||
return RayMarch(i.pos.xy, rayEnd, rayDir, rayLength);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 4 - directional light
|
||||
Pass
|
||||
{
|
||||
ZTest Off
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
Blend One One, One Zero
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vertDir
|
||||
#pragma fragment fragDir
|
||||
#pragma target 3.5
|
||||
#pragma exclude_renderers d3d9 gles
|
||||
|
||||
#define UNITY_HDR_ON
|
||||
|
||||
#pragma shader_feature HEIGHT_FOG
|
||||
#pragma shader_feature NOISE
|
||||
#pragma shader_feature SHADOWS_DEPTH
|
||||
#pragma shader_feature DIRECTIONAL_COOKIE
|
||||
#pragma shader_feature DIRECTIONAL
|
||||
|
||||
#ifdef SHADOWS_DEPTH
|
||||
#define SHADOWS_NATIVE
|
||||
#endif
|
||||
|
||||
v2f vertDir(appdata_img v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v); //Insert
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Ins
|
||||
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
|
||||
o.uv.y = 1.0f - o.uv.y; //blit flips the uv for some reason
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 fragDir(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
float2 uv = i.uv.xy;
|
||||
|
||||
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(uv, _CameraDepthTexture_ST));
|
||||
|
||||
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 wpos = i.interpolatedRay + _WorldSpaceCameraPos;
|
||||
|
||||
float linearDepth = Linear01Depth(depth);
|
||||
|
||||
float3 rayStart = _WorldSpaceCameraPos;
|
||||
float3 rayDir = wpos - _WorldSpaceCameraPos;
|
||||
|
||||
//Problem with VR?! Need more tests
|
||||
//rayDir *= linearDepth;
|
||||
|
||||
float rayLength = length(rayDir);
|
||||
rayDir /= rayLength;
|
||||
|
||||
rayLength = min(rayLength, _MaxRayLength);
|
||||
|
||||
float4 color = RayMarch(i.pos.xy, rayStart, rayDir, rayLength);
|
||||
|
||||
|
||||
if (linearDepth > 0.999999)
|
||||
{
|
||||
color.w = lerp(color.w, 1, _VolumetricLight.w);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 5 - black
|
||||
Pass
|
||||
{
|
||||
ZTest Off
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
Blend One One, One Zero
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vertW
|
||||
#pragma fragment fragW
|
||||
#pragma target 3.5
|
||||
#pragma exclude_renderers d3d9 gles
|
||||
|
||||
#ifdef SHADOWS_DEPTH
|
||||
#define SHADOWS_NATIVE
|
||||
#endif
|
||||
|
||||
|
||||
v2f vertW(appdata_img i)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(i); //Insert
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Ins
|
||||
half index = i.vertex.z;
|
||||
i.vertex.z = 0.1;
|
||||
o.pos = UnityObjectToClipPos(i.vertex);
|
||||
o.uv.xy = i.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 fragW(v2f i) : SV_Target
|
||||
{
|
||||
return float4(0,0,0,0);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9f3d22da4b08c84eb26827873f2a233
|
||||
timeCreated: 1459178237
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user