This commit is contained in:
2025-05-16 23:31:59 +08:00
parent 9e4fef3f1e
commit d891e3f0ee
1198 changed files with 274242 additions and 1558 deletions

View File

@@ -0,0 +1,81 @@
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_DEFINES_INCLUDED_
#define _VLB_SHADER_DEFINES_INCLUDED_
/// ****************************************
/// GLOBAL DEFINES
/// ****************************************
#if UNITY_VERSION < 201810 // SRP support introduced in Unity 2018.1.0
#undef VLB_SRP_API
#endif
#if UNITY_VERSION >= 560 // Instancing API introduced in Unity 5.6
#define VLB_INSTANCING_API_AVAILABLE 1
#if defined(INSTANCING_ON)
#define VLB_GPU_INSTANCING 1
#endif
#endif
#if UNITY_VERSION >= 550 // Single Pass Instanced rendering introduced in Unity 5.5
#define VLB_STEREO_INSTANCING 1
#endif
#if VLB_SRP_API && VLB_INSTANCING_API_AVAILABLE && VLB_GPU_INSTANCING
// When using SRP API and GPU Instancing, the unity_WorldToObject and unity_ObjectToWorld matrices are not sent, so we have to manually send them
#define VLB_CUSTOM_INSTANCED_OBJECT_MATRICES 1
#endif
#if VLB_COLOR_GRADIENT_MATRIX_HIGH || VLB_COLOR_GRADIENT_MATRIX_LOW
#define VLB_COLOR_GRADIENT 1
#else
#define VLB_COLOR_FLAT 1
#endif
/// ****************************************
/// ****************************************
/// DEBUG
/// ****************************************
#define DEBUG_VALUE_DEPTHBUFFER_FROMEYE 1
#define DEBUG_VALUE_DEPTHBUFFER_FROMNEARPLANE 2
#define DEBUG_VALUE_DEPTHBLEND 3
#define DEBUG_VALUE_DEPTHSTEREOEYE 4
#define DEBUG_VALUE_LINEAR_OVERFLOW 5
#define DEBUG_VALUE_SHADOW_DEPTH 6
#define DEBUG_VALUE_DYNOCC_DEPTH 7
//#define DEBUG_DEPTH_MODE DEBUG_VALUE_DYNOCC_DEPTH
//#define DEBUG_SHOW_NOISE3D 1
//#define DEBUG_BLEND_INSIDE_OUTSIDE 1
#if DEBUG_DEPTH_MODE && !VLB_DEPTH_BLEND
#define VLB_DEPTH_BLEND 1
#endif
#if DEBUG_SHOW_NOISE3D && !VLB_NOISE_3D
#define VLB_NOISE_3D 1
#endif
/// ****************************************
/// ****************************************
/// OPTIM
/// ****************************************
/// compute most of the intensity in VS => huge perf improvements
#if !VLB_SHADER_ACCURACY_HIGH
#define OPTIM_VS 1
#endif
/// when OPTIM_VS is enabled, also compute fresnel in VS => better perf,
/// but require too much tessellation for the same quality
//#define OPTIM_VS_FRESNEL_VS 1
/// ****************************************
/// ****************************************
/// FIXES
/// ****************************************
#define FIX_DISABLE_DEPTH_BLEND_WITH_OBLIQUE_PROJ 1
/// ****************************************
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 49653fbebfba49948a7dd9821fc64690
timeCreated: 1578601843
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5a0074f2031380c488da5e38151a7a47, type: 3}
m_Name: ShaderGenerator
m_EditorClassIdentifier:
m_Base: {fileID: 4900000, guid: 08ac1efda1d05b44287ea2dd367f9d5e, type: 3}
m_Pass: {fileID: 4900000, guid: b6eb5846ef7ddc640b6a24b36de75bda, type: 3}
m_IncludesBuiltin: {fileID: 4900000, guid: ee8814b2cee7fd144a04d6a24551c48b, type: 3}
m_IncludesURP: {fileID: 4900000, guid: 63a637fa650f3444d93ad1bcb6b45d28, type: 3}
m_IncludesHDRP: {fileID: 4900000, guid: 30c63e832e947354e8a77d5e829fffeb, type: 3}
outputLocation: {fileID: 4900000, guid: 4ee4a786af721354884879633db96691, type: 3}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 41a72982cc42d7c47a12a3e40591b5f7
timeCreated: 1592827303
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
// The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility.
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_MATHS_INCLUDED_
#define _VLB_SHADER_MATHS_INCLUDED_
inline float lengthSqr(float2 v) { return dot(v, v); }
inline float dot2(float3 v) { return dot(v.xy,v.xy); }
inline float lerpClamped(float a, float b, float t) { return lerp(a, b, saturate(t)); }
inline float invLerp(float a, float b, float t) { return (t - a) / (b - a); }
inline float invLerpClamped(float a, float b, float t) { return saturate(invLerp(a, b, t)); }
inline float fromABtoCD_Clamped(float valueAB, float A, float B, float C, float D) { return lerpClamped(C, D, invLerpClamped(A, B, valueAB)); }
// Returns 1.0 if a >= b, 0.0 otherwise
inline float isEqualOrGreater(float a, float b) { return step(b, a); }
// Returns 1.0 if a < b, 0.0 otherwise
inline float isLower(float a, float b) { return 1.0 - step(b, a); }
// Returns 1.0 if all arguments equal 1.0, 0.0 otherwise
inline float ifAnd(float a, float b) { return isEqualOrGreater(a + b, 1.5); }
inline float ifAnd(float a, float b, float c) { return isEqualOrGreater(a + b + c, 2.5); }
// Get signed distance of pos from the plane (normal ; d).
// Normal should be normalized.
// If we want to disable this feature, we could set normal and d to 0 (no discard in this case).
inline float DistanceToPlane(float3 pos, float3 normal, float d) { return dot(normal, pos) + d; }
// https://www.iquilezles.org/www/articles/functions/functions.htm
// A nice choice to remap the 0..1 interval into 0..1, such that the corners are mapped to 0 and the center to 1.
// In other words, parabola(0) = parabola(1) = 0, and parabola(1/2) = 1.
inline float parabola( float x, float k )
{
return pow( 4.0*x*(1.0-x), k );
}
// https://en.wikipedia.org/wiki/Smoothstep
inline float smootherstep(float edge0, float edge1, float x)
{
// Scale, and clamp x to 0..1 range
x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
// Evaluate polynomial
return x*x*x*(x*(x * 6 - 15) + 10);
}
inline float flipUV(float uv, float shouldFlip)
{
// returns uv or 1-uv
return max(-shouldFlip, 0) + shouldFlip * uv;
}
inline float GetLODFadeFactor()
{
float fadeFactor = unity_LODFade.x;
if (fadeFactor <= 0)
{
fadeFactor = 1 - abs(fadeFactor);
}
return fadeFactor;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8e2291ef6ea68d34da2e1a28422a7fdc
timeCreated: 1504539309
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,109 @@
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_PROPERTIES_INCLUDED_
#define _VLB_SHADER_PROPERTIES_INCLUDED_
#include "ShaderPropertySystem.cginc"
/// ****************************************
/// PROPERTIES DECLARATION
/// ****************************************
VLB_DEFINE_PROP_START
#if VLB_CUSTOM_INSTANCED_OBJECT_MATRICES
VLB_DEFINE_PROP(float4x4, _LocalToWorldMatrix)
VLB_DEFINE_PROP(float4x4, _WorldToLocalMatrix)
#endif
// if VLB_COLOR_GRADIENT_MATRIX_HIGH || VLB_COLOR_GRADIENT_MATRIX_LOW
VLB_DEFINE_PROP(float4x4, _ColorGradientMatrix)
// else
VLB_DEFINE_PROP(float4, _ColorFlat)
// endif
VLB_DEFINE_PROP(half, _AlphaInside)
VLB_DEFINE_PROP(half, _AlphaOutside)
VLB_DEFINE_PROP(half, _HDRPExposureWeight)
VLB_DEFINE_PROP(float2, _ConeSlopeCosSin) // between -1 and +1
VLB_DEFINE_PROP(float2, _ConeRadius) // x = start radius ; y = end radius
VLB_DEFINE_PROP(float2, _ConeGeomProps) // x = apex offset z > 0 ; y = mesh sides
VLB_DEFINE_PROP(float, _AttenuationLerpLinearQuad)
VLB_DEFINE_PROP(float3, _DistanceFallOff) // fallOffStart, fallOffEnd, maxGeometryDistance
VLB_DEFINE_PROP(float, _DistanceCamClipping)
VLB_DEFINE_PROP(float, _FadeOutFactor)
VLB_DEFINE_PROP(float, _FresnelPow) // must be != 0 to avoid infinite fresnel
VLB_DEFINE_PROP(float, _GlareFrontal)
VLB_DEFINE_PROP(float, _GlareBehind)
VLB_DEFINE_PROP(float, _DrawCap)
VLB_DEFINE_PROP(float4, _CameraParams) // xyz: object space forward vector ; w: cameraIsInsideBeamFactor (-1 : +1)
// if VLB_OCCLUSION_CLIPPING_PLANE
VLB_DEFINE_PROP(float4, _DynamicOcclusionClippingPlaneWS)
VLB_DEFINE_PROP(float, _DynamicOcclusionClippingPlaneProps)
// elif VLB_OCCLUSION_DEPTH_TEXTURE
VLB_DEFINE_PROP(float4, _DynamicOcclusionDepthProps) // x = should flip x? ; y = should flip y? ; z = fade distance ; w = perspective cam ?
// endif
// VLB_NOISE_3D
VLB_DEFINE_PROP(float4, _NoiseVelocityAndScale)
VLB_DEFINE_PROP(float2, _NoiseParam)
/////////////////
/// SD
/////////////////
VLB_DEFINE_PROP(float, _DepthBlendDistance)
VLB_DEFINE_PROP(float2, _TiltVector)
VLB_DEFINE_PROP(float4, _AdditionalClippingPlaneWS)
VLB_DEFINE_PROP(float3, _LocalForwardDirection) // VLB_MESH_SKEWING
/////////////////
/// HD
/////////////////
VLB_DEFINE_PROP(half, _Intensity)
VLB_DEFINE_PROP(float, _SideSoftness)
VLB_DEFINE_PROP(float4, _Jittering)
VLB_DEFINE_PROP(float3, _CameraForwardOS) // xyz: object space forward vector
VLB_DEFINE_PROP(float3, _CameraForwardWS) // xyz: world space forward vector
VLB_DEFINE_PROP(float3, _TransformScale)
// VLB_COOKIE_1CHANNEL || VLB_COOKIE_RGBA
VLB_DEFINE_PROP(float4, _CookieProperties)
VLB_DEFINE_PROP(float4, _CookiePosAndScale)
VLB_DEFINE_PROP(float4, _ShadowProps) // VLB_SHADOW
VLB_DEFINE_PROP_END
// UNITY_REVERSED_Z define is broken for WebGL and URP
uniform float _VLB_UsesReversedZBuffer; // not reversed in OpenGL on WebGL
#if VLB_DITHERING
uniform float _VLB_DitheringFactor;
uniform sampler2D _VLB_DitheringNoiseTex;
uniform float4 _VLB_DitheringNoiseTex_TexelSize;
#endif
/////////////////
/// SD
/////////////////
#if VLB_OCCLUSION_DEPTH_TEXTURE
// Setting a Texture property to a GPU instanced material is not supported, so keep it as regular property
uniform sampler2D _DynamicOcclusionDepthTexture;
#endif
/////////////////
/// HD
/////////////////
uniform float _VLB_CameraBlendingDistance;
// Setting a Texture property to a GPU instanced material is not supported, so keep it as regular property
uniform sampler2D _ShadowDepthTexture; // VLB_SHADOW
uniform sampler2D _CookieTexture; // VLB_COOKIE_1CHANNEL || VLB_COOKIE_RGBA
uniform sampler2D _VLB_JitteringNoiseTex;
uniform float4 _VLB_JitteringNoiseTex_TexelSize;
/// ****************************************
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 27b50b866731025428ef37b38a364a98
timeCreated: 1578601843
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_PROPERTY_SYSTEM_INCLUDED_
#define _VLB_SHADER_PROPERTY_SYSTEM_INCLUDED_
/// ****************************************
/// PROPERTIES MACROS
/// ****************************************
#if VLB_INSTANCING_API_AVAILABLE && VLB_GPU_INSTANCING
#if UNITY_VERSION < 201730 // https://unity3d.com/fr/unity/beta/unity2017.3.0b1
// PRE UNITY 2017.3
// for some reason, letting the default UNITY_MAX_INSTANCE_COUNT value generates the following error:
// "Internal error communicating with the shader compiler process"
#define UNITY_MAX_INSTANCE_COUNT 150
#define VLB_DEFINE_PROP_START UNITY_INSTANCING_CBUFFER_START(Props)
#define VLB_DEFINE_PROP_END UNITY_INSTANCING_CBUFFER_END
#define VLB_GET_PROP(name) UNITY_ACCESS_INSTANCED_PROP(name)
#else
// POST UNITY 2017.3
#define VLB_DEFINE_PROP_START UNITY_INSTANCING_BUFFER_START(Props)
#define VLB_DEFINE_PROP_END UNITY_INSTANCING_BUFFER_END(Props)
#define VLB_GET_PROP(name) UNITY_ACCESS_INSTANCED_PROP(Props, name)
#endif
#define VLB_DEFINE_PROP(type, name) UNITY_DEFINE_INSTANCED_PROP(type, name)
#elif VLB_SRP_API && VLB_SRP_BATCHER
#define VLB_DEFINE_PROP_START CBUFFER_START(UnityPerMaterial)
#define VLB_DEFINE_PROP_END CBUFFER_END
#define VLB_DEFINE_PROP(type, name) type name;
#define VLB_GET_PROP(name) name
#else
#define VLB_DEFINE_PROP_START
#define VLB_DEFINE_PROP_END
#define VLB_DEFINE_PROP(type, name) uniform type name;
#define VLB_GET_PROP(name) name
#endif
/// ****************************************
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4db26b55566f95a47adcaf8ca699bf3b
timeCreated: 1578601843
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
// The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility.
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_SPECIFIC_INCLUDED_
#define _VLB_SHADER_SPECIFIC_INCLUDED_
// POSITION TRANSFORM
#if UNITY_VERSION < 540
#define __VLBMatrixWorldToObject _World2Object
#define __VLBMatrixObjectToWorld _Object2World
#define __VLBMatrixV UNITY_MATRIX_V
inline float4 VLBObjectToClipPos(in float3 pos) { return mul(UNITY_MATRIX_MVP, float4(pos, 1.0)); }
#else
#if VLB_CUSTOM_INSTANCED_OBJECT_MATRICES
#define __VLBMatrixWorldToObject UNITY_ACCESS_INSTANCED_PROP(Props, _WorldToLocalMatrix)
#define __VLBMatrixObjectToWorld UNITY_ACCESS_INSTANCED_PROP(Props, _LocalToWorldMatrix)
#define __VLBMatrixV unity_MatrixV
inline float4 VLBObjectToClipPos(in float3 pos) { return mul(mul(unity_MatrixVP, __VLBMatrixObjectToWorld), float4(pos, 1.0)); }
#else
#define __VLBMatrixWorldToObject unity_WorldToObject
#define __VLBMatrixObjectToWorld unity_ObjectToWorld
#define __VLBMatrixV UNITY_MATRIX_V
#define VLBObjectToClipPos UnityObjectToClipPos
#endif
#endif
inline float4 VLBObjectToWorldPos(in float4 pos) { return mul(__VLBMatrixObjectToWorld, pos); }
#define VLBWorldToViewPos(pos) (mul(__VLBMatrixV, float4(pos.xyz, 1.0)).xyz)
// FRUSTUM PLANES
#define VLBFrustumPlanes unity_CameraWorldClipPlanes
// CAMERA
inline float3 __VLBWorldToObjectPos(in float3 pos) { return mul(__VLBMatrixWorldToObject, float4(pos, 1.0)).xyz; }
inline float3 VLBGetCameraPositionObjectSpace(float3 scaleObjectSpace)
{
return __VLBWorldToObjectPos(_WorldSpaceCameraPos).xyz * scaleObjectSpace;
}
// DEPTH
#ifndef UNITY_DECLARE_DEPTH_TEXTURE // handle Unity pre 5.6.0
#define UNITY_DECLARE_DEPTH_TEXTURE(tex) sampler2D_float tex
#endif
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
#define VLBSampleDepthTexture(/*float4*/uv) (SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, (uv)/(uv.w)))
#define VLBLinearEyeDepth(depth) (LinearEyeDepth(depth))
// FOG
#define VLB_FOG_UNITY_BUILTIN_COORDS
#if VLB_ALPHA_AS_BLACK
#define VLB_FOG_APPLY(color) \
float4 fogColor = unity_FogColor; \
fogColor.rgb *= color.a; \
UNITY_APPLY_FOG_COLOR(i.fogCoord, color, fogColor);
// since we use this shader with Additive blending, fog color should be modulated by general alpha
#else
#define VLB_FOG_APPLY(color) UNITY_APPLY_FOG(i.fogCoord, color);
#endif
inline void ApplyPipelineSpecificIntensityModifier(inout float intensity) {}
#endif // _VLB_SHADER_SPECIFIC_INCLUDED_

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0f65a880b7990834b8700ebf9f9a53fa
timeCreated: 1578601843
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
// The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility.
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_SPECIFIC_INCLUDED_
#define _VLB_SHADER_SPECIFIC_INCLUDED_
/////////////////////////////////////////////////////
// Redefine missing functions from legacy pipeline
/////////////////////////////////////////////////////
inline float4 ComputeNonStereoScreenPos(float4 pos)
{
float4 o = pos * 0.5f;
o.xy = float2(o.x, o.y * _ProjectionParams.x) + o.w;
o.zw = pos.zw;
return o;
}
#define TransformStereoScreenSpaceTex(uv, w) uv
inline float4 ComputeScreenPos(float4 pos)
{
float4 o = ComputeNonStereoScreenPos(pos);
#if defined(UNITY_SINGLE_PASS_STEREO)
o.xy = TransformStereoScreenSpaceTex(o.xy, pos.w);
#endif
return o;
}
/////////////////////////////////////////////////////
// POSITION TRANSFORM
inline float4 VLBObjectToClipPos(in float3 pos) { return mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, float4(pos.xyz, 1.0))); }
// Don't use UNITY_MATRIX_M directly here, because ApplyCameraTranslationToMatrix has been applied to it to substract the camera position.
// But we can't use GetRawUnityObjectToWorld neither, since it doesn't work on Unity 2018.4.19 and HDRP 4.10.0 with GPUInstancing.
// So we counter the effect of ApplyCameraTranslationToMatrix by adding the _WorldSpaceCameraPos back.
inline float4 VLBObjectToWorldPos(in float4 pos)
{
float4x4 modelMatrix = UNITY_MATRIX_M;
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
modelMatrix._m03_m13_m23 += _WorldSpaceCameraPos;
#endif
return mul(modelMatrix, pos);
}
#define VLBObjectToViewPos(pos) (mul(UNITY_MATRIX_V, mul(UNITY_MATRIX_M, float4(pos.xyz, 1.0))).xyz)
// FRUSTUM PLANES
#define VLBFrustumPlanes _FrustumPlanes
// CAMERA
inline float3 __VLBWorldToObjectPos(in float3 pos) { return mul(UNITY_MATRIX_I_M, float4(pos, 1.0)).xyz; }
inline float3 VLBGetCameraPositionObjectSpace(float3 scaleObjectSpace)
{
// getting access directly to _WorldSpaceCameraPos gives wrong values
return __VLBWorldToObjectPos(GetCurrentViewPosition()) * scaleObjectSpace;
}
// DEPTH
#define VLBSampleDepthTexture(/*float4*/uv) (SampleCameraDepth((uv.xy) / (uv.w)))
#define VLBLinearEyeDepth(depth) LinearEyeDepth((depth), _ZBufferParams)
inline void ApplyPipelineSpecificIntensityModifier(inout float intensity)
{
#if defined(UNITY_SHADER_VARIABLES_INCLUDED) && UNITY_VERSION >= 202110
intensity *= lerp(1.0, GetCurrentExposureMultiplier(), VLB_GET_PROP(_HDRPExposureWeight));
#endif
}
#endif // _VLB_SHADER_SPECIFIC_INCLUDED_

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8895ab27688df164283e6aa7391ecabd
timeCreated: 1578601839
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
// The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility.
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_SPECIFIC_INCLUDED_
#define _VLB_SHADER_SPECIFIC_INCLUDED_
// POSITION TRANSFORM
#if VLB_CUSTOM_INSTANCED_OBJECT_MATRICES
#define __VLBMatrixWorldToObject UNITY_ACCESS_INSTANCED_PROP(Props, _WorldToLocalMatrix)
#define __VLBMatrixObjectToWorld UNITY_ACCESS_INSTANCED_PROP(Props, _LocalToWorldMatrix)
#define __VLBMatrixV unity_MatrixV
inline float4 VLBObjectToClipPos(in float3 pos) { return mul(mul(unity_MatrixVP, __VLBMatrixObjectToWorld), float4(pos, 1.0)); }
#else
#define __VLBMatrixWorldToObject unity_WorldToObject
#define __VLBMatrixObjectToWorld unity_ObjectToWorld
#define __VLBMatrixV UNITY_MATRIX_V
inline float4 VLBObjectToClipPos(in float3 pos) { return mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, float4(pos.xyz, 1.0))); }
#endif
inline float4 VLBObjectToWorldPos(in float4 pos) { return mul(__VLBMatrixObjectToWorld, pos); }
#define VLBWorldToViewPos(pos) (mul(__VLBMatrixV, float4(pos.xyz, 1.0)).xyz)
// FRUSTUM PLANES
#define VLBFrustumPlanes unity_CameraWorldClipPlanes
// CAMERA
inline float3 __VLBWorldToObjectPos(in float3 pos) { return mul(__VLBMatrixWorldToObject, float4(pos, 1.0)).xyz; }
inline float3 VLBGetCameraPositionObjectSpace(float3 scaleObjectSpace)
{
return __VLBWorldToObjectPos(_WorldSpaceCameraPos).xyz * scaleObjectSpace;
}
// DEPTH
#define VLBSampleDepthTexture(/*float4*/uv) (SampleSceneDepth((uv.xy) / (uv.w)))
#define VLBLinearEyeDepth(depth) LinearEyeDepth((depth), _ZBufferParams)
// FOG
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#define VLB_FOG_MIX(color, fogColor, posClipSpace) color.rgb = MixFogColor(color.rgb, fogColor.rgb, ComputeFogFactor(posClipSpace.z * posClipSpace.w))
#if VLB_ALPHA_AS_BLACK
#define VLB_FOG_APPLY(color) \
float4 fogColor = unity_FogColor; \
fogColor.rgb *= color.a; \
VLB_FOG_MIX(color, fogColor, i.posClipSpace);
#else
#define VLB_FOG_APPLY(color) VLB_FOG_MIX(color, unity_FogColor, i.posClipSpace);
#endif
#endif
inline void ApplyPipelineSpecificIntensityModifier(inout float intensity) {}
#endif // _VLB_SHADER_SPECIFIC_INCLUDED_

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5506b213335ebb24f91756ab209e7915
timeCreated: 1578601843
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,230 @@
// The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility.
// UNITY_SHADER_NO_UPGRADE
#ifndef _VLB_SHADER_UTILS_INCLUDED_
#define _VLB_SHADER_UTILS_INCLUDED_
#include "ShaderMaths.cginc"
// https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html
#define VLB_CAMERA_NEAR_PLANE _ProjectionParams.y
#define VLB_CAMERA_FAR_PLANE _ProjectionParams.z
#define VLB_CAMERA_ORTHO unity_OrthoParams.w // w is 1.0 when camera is orthographic, 0.0 when perspective
// Z buffer to 0..1 depth (0 at eye, 1 at far plane)
float VLB_ZBufferTo01(float depth, float near, float far)
{
float x = 1 - far / near;
float y = far / near;
return 1.0 / (x * depth + y);
}
// Z buffer to linear depth
float VLB_ZBufferToLinear(float depth, float near, float far)
{
float x = 1 - far / near;
float y = far / near;
float z = x / far;
float w = y / far;
return 1.0 / (z * depth + w);
}
inline float4 Depth_VS_ComputeProjPos(float3 vertexViewSpace, float4 vertexClipSpace)
{
float4 projPos = ComputeScreenPos(vertexClipSpace);
projPos.z = -vertexViewSpace.z; // = COMPUTE_EYEDEPTH
return projPos;
}
inline float Depth_PS_GetLinearDepthOrtho(float rawDepth)
{
rawDepth = lerp(rawDepth, 1.0f - rawDepth, _VLB_UsesReversedZBuffer);
return (VLB_CAMERA_FAR_PLANE - VLB_CAMERA_NEAR_PLANE) * rawDepth + VLB_CAMERA_NEAR_PLANE;
}
inline float Depth_PS_GetSceneDepthFromNearPlane(float4 uv)
{
float rawDepth = VLBSampleDepthTexture(uv);
float linearDepthPersp = VLBLinearEyeDepth(rawDepth);
float linearDepthOrtho = Depth_PS_GetLinearDepthOrtho(rawDepth);
return lerp(linearDepthPersp, linearDepthOrtho, VLB_CAMERA_ORTHO);
}
inline float Depth_PS_GetSceneDepthFromEye(float4 uv, float3 posViewSpace)
{
float rawDepth = VLBSampleDepthTexture(uv);
float linearDepthPersp = VLBLinearEyeDepth(rawDepth);
// transform perspective depth from near plane to distance based on the eye
float acosViewDirZ = abs(normalize(posViewSpace.xyz).z); // TODO precompute that in VS?
linearDepthPersp /= acosViewDirZ;
float linearDepthOrtho = Depth_PS_GetLinearDepthOrtho(rawDepth);
return lerp(linearDepthPersp, linearDepthOrtho, VLB_CAMERA_ORTHO);
}
#if VLB_DEPTH_BLEND || VLB_DITHERING
inline float DepthFade_PS_BlendDistance(float4 projPos, float3 posViewSpace, float distance)
{
// Use FromNearPlane instead of FromEye for SD beams, it looks better specially in QA tests 'BlendWithGeom' and 'BlendWithGeomDisableAtSrc'
float sceneDepth = Depth_PS_GetSceneDepthFromNearPlane(projPos);
float sceneZ = max(0, sceneDepth - VLB_CAMERA_NEAR_PLANE);
float partZ = max(0, projPos.z - VLB_CAMERA_NEAR_PLANE);
return saturate((sceneZ - partZ) / distance);
}
#endif // VLB_DEPTH_BLEND || VLB_DITHERING
#if VLB_NOISE_3D
uniform sampler3D _VLB_NoiseTex3D;
uniform float _VLB_NoiseCustomTime;
float3 Noise3D_GetUVW(float3 posWorldSpace, float3 posLocalSpace)
{
float4 noiseVelocityAndScale = VLB_GET_PROP(_NoiseVelocityAndScale);
float2 noiseParam = VLB_GET_PROP(_NoiseParam);
float3 velocity = noiseVelocityAndScale.xyz;
float scale = noiseVelocityAndScale.w;
float3 posRef = lerp(posWorldSpace, posLocalSpace, noiseParam.y); // 0 -> World Space ; 1 -> Local Space
// use _VLB_NoiseCustomTime if it's equal or higher than 0.0
float currentTime = lerp(_Time.y, _VLB_NoiseCustomTime, isEqualOrGreater(_VLB_NoiseCustomTime, 0.0f));
//return frac(posRef.xyz * scale + (currentTime * velocity)); // frac doesn't give good results on VS
return (posRef.xyz * scale + (currentTime * velocity));
}
float Noise3D_GetFactorFromUVW(float3 uvw)
{
float2 noiseParam = VLB_GET_PROP(_NoiseParam);
float intensity = noiseParam.x;
float noise = tex3D(_VLB_NoiseTex3D, uvw).a;
return lerp(1, noise, intensity);
}
#endif // VLB_NOISE_3D
inline float ComputeAttenuationSD(float pixDistZ, float fallOffStart, float fallOffEnd, float lerpLinearQuad)
{
float distFromSourceNormalized = invLerpClamped(fallOffStart, fallOffEnd, pixDistZ);
// Almost simple linear attenuation between Fade Start and Fade End: Use smoothstep for a better fall to zero rendering
float attLinear = smoothstep(0, 1, 1 - distFromSourceNormalized);
// Unity's custom quadratic attenuation https://forum.unity.com/threads/light-attentuation-equation.16006/
float attQuad = 1.0 / (1.0 + 25.0 * distFromSourceNormalized * distFromSourceNormalized);
const float kAttQuadStartToFallToZero = 0.8;
attQuad *= saturate(smoothstep(1.0, kAttQuadStartToFallToZero, distFromSourceNormalized)); // Near the light's range (fade end) we fade to 0 (because quadratic formula never falls to 0)
return lerp(attLinear, attQuad, lerpLinearQuad);
}
inline float ComputeAttenuationHD(float pixDistZ, float fallOffStart, float fallOffEnd)
{
float distFromSourceNormalized = invLerpClamped(fallOffStart, fallOffEnd, pixDistZ);
float att = -1.0f;
#if VLB_ATTENUATION_LINEAR
// Simple linear attenuation
att = (1 - distFromSourceNormalized);
#elif VLB_ATTENUATION_QUAD
// Unity's custom quadratic attenuation
// https://forum.unity.com/threads/light-attentuation-equation.16006/
// https://forum.unity.com/threads/light-distance-in-shader.509306/#post-3326818
att = saturate(1.0 / (1.0 + 25.0 * distFromSourceNormalized * distFromSourceNormalized) * saturate((1 - distFromSourceNormalized) * 5.0));
#endif
return att;
}
#if VLB_COLOR_GRADIENT
#if VLB_COLOR_GRADIENT_MATRIX_HIGH || VLB_COLOR_GRADIENT_MATRIX_LOW
#if VLB_COLOR_GRADIENT_MATRIX_HIGH
#define FLOAT_PACKING_PRECISION 64
#else
#define FLOAT_PACKING_PRECISION 8
#endif
inline float4 UnpackToColor(float packedFloat)
{
float4 color;
color.a = packedFloat % FLOAT_PACKING_PRECISION;
packedFloat = floor(packedFloat / FLOAT_PACKING_PRECISION);
color.b = packedFloat % FLOAT_PACKING_PRECISION;
packedFloat = floor(packedFloat / FLOAT_PACKING_PRECISION);
color.g = packedFloat % FLOAT_PACKING_PRECISION;
packedFloat = floor(packedFloat / FLOAT_PACKING_PRECISION);
color.r = packedFloat;
return color / (FLOAT_PACKING_PRECISION - 1);
}
inline float GetAtMatrixIndex(float4x4 mat, uint idx) { return mat[idx % 4][floor(idx / 4)]; }
inline float4 DecodeGradient(float t, float4x4 colorMatrix)
{
#define kColorGradientMatrixSize 16
float sampleIndexFloat = t * (kColorGradientMatrixSize - 1);
float ratioPerSample = sampleIndexFloat - (int)sampleIndexFloat;
uint sampleIndexInt = min((uint)sampleIndexFloat, kColorGradientMatrixSize - 2);
float4 colorA = UnpackToColor(GetAtMatrixIndex(colorMatrix, sampleIndexInt + 0));
float4 colorB = UnpackToColor(GetAtMatrixIndex(colorMatrix, sampleIndexInt + 1));
return lerp(colorA, colorB, ratioPerSample);
}
#elif VLB_COLOR_GRADIENT_ARRAY
inline half4 DecodeGradient(float t, float4 colorArray[kColorGradientArraySize])
{
uint arraySize = kColorGradientArraySize;
float sampleIndexFloat = t * (arraySize - 1);
float ratioPerSample = sampleIndexFloat - (int)sampleIndexFloat;
uint sampleIndexInt = min((uint)sampleIndexFloat, arraySize - 2);
float4 colorA = colorArray[sampleIndexInt + 0];
float4 colorB = colorArray[sampleIndexInt + 1];
return lerp(colorA, colorB, ratioPerSample);
}
#endif // VLB_COLOR_GRADIENT_*
inline float4 ComputeColorGradient(float pixDistFromSource)
{
float distanceFadeEnd = VLB_GET_PROP(_DistanceFallOff).y;
float4x4 colorGradientMatrix = VLB_GET_PROP(_ColorGradientMatrix);
float distFromSourceNormalized = invLerpClamped(0, distanceFadeEnd, pixDistFromSource);
return DecodeGradient(distFromSourceNormalized, colorGradientMatrix);
}
#elif VLB_COLOR_FLAT
inline float4 ComputeColorFlat()
{
return VLB_GET_PROP(_ColorFlat);
}
#endif // VLB_COLOR_GRADIENT / VLB_COLOR_FLAT
inline float4 ApplyAlphaToColor(float4 color)
{
#if VLB_ALPHA_AS_BLACK
color.rgb *= color.a;
#endif
return color;
}
inline float4 ApplyAlphaToColor(float4 color, float additionalAlpha)
{
#if VLB_ALPHA_AS_BLACK
color.rgb *= color.a;
color.rgb *= additionalAlpha;
#else
color.a *= additionalAlpha;
#endif
return color;
}
#endif // _VLB_SHADER_UTILS_INCLUDED_

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 05361e63ec7797d4cac0db54e579335c
timeCreated: 1504539309
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,79 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: VLBDummyMaterialHD
m_Shader: {fileID: 4800000, guid: 4528e9cdcb41bf94cad437d30c795bac, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _CookieTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DynamicOcclusionDepthTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ShadowDepthTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AlphaInside: 1
- _AlphaOutside: 1
- _AttenuationLerpLinearQuad: 0.5
- _BlendDstFactor: 1
- _BlendSrcFactor: 1
- _DepthBlendDistance: 2
- _DistanceCamClipping: 0.5
- _DrawCap: 1
- _DynamicOcclusionClippingPlaneProps: 0.25
- _FadeOutFactor: 1
- _FresnelPow: 1
- _GlareBehind: 0.5
- _GlareFrontal: 0.5
- _HDRPExposureWeight: 0
- _Intensity: 1
- _SideSoftness: 1
- _ZTest: 4
m_Colors:
- _AdditionalClippingPlaneWS: {r: 0, g: 0, b: 0, a: 0}
- _CameraForwardOS: {r: 0, g: 0, b: 0, a: 1}
- _CameraForwardWS: {r: 0, g: 0, b: 0, a: 1}
- _CameraParams: {r: 0, g: 0, b: 0, a: 0}
- _ColorFlat: {r: 1, g: 1, b: 1, a: 1}
- _ConeGeomProps: {r: 0, g: 0, b: 0, a: 0}
- _ConeRadius: {r: 0, g: 0, b: 0, a: 0}
- _ConeSlopeCosSin: {r: 0, g: 0, b: 0, a: 0}
- _CookiePosAndScale: {r: 0, g: 0, b: 1, a: 1}
- _CookieProperties: {r: 0, g: 0, b: 0, a: 0}
- _DistanceFallOff: {r: 0, g: 1, b: 1, a: 0}
- _DynamicOcclusionClippingPlaneWS: {r: 0, g: 0, b: 0, a: 0}
- _DynamicOcclusionDepthProps: {r: 1, g: 1, b: 0.25, a: 1}
- _Jittering: {r: 0, g: 0, b: 0, a: 0}
- _LocalForwardDirection: {r: 0, g: 0, b: 1, a: 1}
- _NoiseParam: {r: 0, g: 0, b: 0, a: 0}
- _NoiseVelocityAndScale: {r: 0, g: 0, b: 0, a: 0}
- _ShadowProps: {r: 1, g: 1, b: 1, a: 1}
- _TiltVector: {r: 0, g: 0, b: 0, a: 0}
- _TransformScale: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ad45c2cd047f4a74888d5f05073768cc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,79 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: VLBDummyMaterialSD
m_Shader: {fileID: 4800000, guid: 99ebbc59c087a40419472ad7eabe81e9, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _CookieTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DynamicOcclusionDepthTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ShadowDepthTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AlphaInside: 1
- _AlphaOutside: 1
- _AttenuationLerpLinearQuad: 0.5
- _BlendDstFactor: 1
- _BlendSrcFactor: 1
- _DepthBlendDistance: 2
- _DistanceCamClipping: 0.5
- _DrawCap: 1
- _DynamicOcclusionClippingPlaneProps: 0.25
- _FadeOutFactor: 1
- _FresnelPow: 1
- _GlareBehind: 0.5
- _GlareFrontal: 0.5
- _HDRPExposureWeight: 0
- _Intensity: 1
- _SideSoftness: 1
- _ZTest: 4
m_Colors:
- _AdditionalClippingPlaneWS: {r: 0, g: 0, b: 0, a: 0}
- _CameraForwardOS: {r: 0, g: 0, b: 0, a: 1}
- _CameraForwardWS: {r: 0, g: 0, b: 0, a: 1}
- _CameraParams: {r: 0, g: 0, b: 0, a: 0}
- _ColorFlat: {r: 1, g: 1, b: 1, a: 1}
- _ConeGeomProps: {r: 0, g: 0, b: 0, a: 0}
- _ConeRadius: {r: 0, g: 0, b: 0, a: 0}
- _ConeSlopeCosSin: {r: 0, g: 0, b: 0, a: 0}
- _CookiePosAndScale: {r: 0, g: 0, b: 1, a: 1}
- _CookieProperties: {r: 0, g: 0, b: 0, a: 0}
- _DistanceFallOff: {r: 0, g: 1, b: 1, a: 0}
- _DynamicOcclusionClippingPlaneWS: {r: 0, g: 0, b: 0, a: 0}
- _DynamicOcclusionDepthProps: {r: 1, g: 1, b: 0.25, a: 1}
- _Jittering: {r: 0, g: 0, b: 0, a: 0}
- _LocalForwardDirection: {r: 0, g: 0, b: 1, a: 1}
- _NoiseParam: {r: 0, g: 0, b: 0, a: 0}
- _NoiseVelocityAndScale: {r: 0, g: 0, b: 0, a: 0}
- _ShadowProps: {r: 1, g: 1, b: 1, a: 1}
- _TiltVector: {r: 0, g: 0, b: 0, a: 0}
- _TransformScale: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d177b67705c3fa042ac63cc2d388dbb7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,138 @@
Shader "Hidden/VLB_HD_URP_Default"
{
Properties
{
_ConeRadius("Cone Radius", Vector) = (0,0,0,0)
_ConeGeomProps("Cone Geom Props", Vector) = (0,0,0,0)
_ColorFlat("Color", Color) = (1,1,1,1)
_HDRPExposureWeight("HDRP Exposure Weight", Range(0,1)) = 0
_DistanceFallOff("Distance Fall Off", Vector) = (0,1,1,0)
_NoiseVelocityAndScale("Noise Velocity And Scale", Vector) = (0,0,0,0)
_NoiseParam("Noise Param", Vector) = (0,0,0,0)
_BlendSrcFactor("BlendSrcFactor", Int) = 1 // One
_BlendDstFactor("BlendDstFactor", Int) = 1 // One
_ZTest("ZTest", Int) = 4 // LEqual
// SD
_ConeSlopeCosSin("Cone Slope Cos Sin", Vector) = (0,0,0,0)
_AlphaInside("Alpha Inside", Range(0,1)) = 1
_AlphaOutside("Alpha Outside", Range(0,1)) = 1
_DistanceCamClipping("Camera Clipping Distance", Float) = 0.5
_FadeOutFactor("FadeOutFactor", Float) = 1
_AttenuationLerpLinearQuad("Lerp between attenuation linear and quad", Float) = 0.5
_DepthBlendDistance("Depth Blend Distance", Float) = 2
_FresnelPow("Fresnel Pow", Range(0,15)) = 1
_GlareFrontal("Glare Frontal", Range(0,1)) = 0.5
_GlareBehind("Glare from Behind", Range(0,1)) = 0.5
_DrawCap("Draw Cap", Float) = 1
_CameraParams("Camera Params", Vector) = (0,0,0,0)
_DynamicOcclusionClippingPlaneWS("Dynamic Occlusion Clipping Plane WS", Vector) = (0,0,0,0)
_DynamicOcclusionClippingPlaneProps("Dynamic Occlusion Clipping Plane Props", Float) = 0.25
_DynamicOcclusionDepthTexture("DynamicOcclusionDepthTexture", 2D) = "white" {}
_DynamicOcclusionDepthProps("DynamicOcclusionDepthProps", Vector) = (1, 1, 0.25, 1)
_LocalForwardDirection("LocalForwardDirection", Vector) = (0,0,1)
_TiltVector("TiltVector", Vector) = (0,0,0,0)
_AdditionalClippingPlaneWS("AdditionalClippingPlaneWS", Vector) = (0,0,0,0)
// HD
_Intensity("Intensity", Range(0,8)) = 1
_SideSoftness("SideSoftness", Range(0,15)) = 1
_Jittering("Jittering", Vector) = (0,0,0,0)
_CameraForwardOS("Camera Forward OS", Vector) = (0,0,0)
_CameraForwardWS("Camera Forward WS", Vector) = (0,0,0)
_TransformScale("Transform Scale", Vector) = (0,0,0)
_CookieTexture("CookieTexture", 2D) = "white" {}
_CookieProperties("CookieProperties", Vector) = (0,0,0,0)
_CookiePosAndScale("CookiePosAndScale", Vector) = (0,0,1,1)
_ShadowDepthTexture("ShadowDepthTexture", 2D) = "white" {}
_ShadowProps("ShadowProps", Vector) = (1,1,1,1)
}
Category
{
Tags
{
"Queue" = "Transparent"
"RenderType" = "Transparent"
"IgnoreProjector" = "True"
"DisableBatching" = "True" // disable dynamic batching which doesn't work neither with multiple materials nor material property blocks
}
Blend[_BlendSrcFactor][_BlendDstFactor]
ZWrite Off
ZTest[_ZTest]
SubShader
{
Pass
{
Cull Front
HLSLPROGRAM
#if !defined(SHADER_API_METAL) // Removed shader model spec for Metal support https://github.com/keijiro/Cloner/commit/1120493ca2df265d450de3ec1b38a1d388468964
#pragma target 3.0
#endif
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile_local __ VLB_ALPHA_AS_BLACK
#pragma multi_compile_local __ VLB_NOISE_3D
#pragma multi_compile_local __ VLB_COLOR_GRADIENT_MATRIX_HIGH
#pragma multi_compile_local VLB_ATTENUATION_LINEAR VLB_ATTENUATION_QUAD
#pragma multi_compile_local __ VLB_SHADOW
#pragma multi_compile_local __ VLB_COOKIE_1CHANNEL VLB_COOKIE_RGBA
#pragma multi_compile_local VLB_RAYMARCHING_QUALITY_0 VLB_RAYMARCHING_QUALITY_1 VLB_RAYMARCHING_QUALITY_2
#define VLB_SHADER_HD 1
#define VLB_SRP_API 1
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
#if VLB_RAYMARCHING_QUALITY_0
#define VLB_RAYMARCHING_STEP_COUNT 5
#endif
#if VLB_RAYMARCHING_QUALITY_1
#define VLB_RAYMARCHING_STEP_COUNT 10
#endif
#if VLB_RAYMARCHING_QUALITY_2
#define VLB_RAYMARCHING_STEP_COUNT 20
#endif
#include "ShaderDefines.cginc"
#include "ShaderProperties.cginc"
#include "ShaderSpecificURP.cginc"
#include "VolumetricLightBeamSharedHD.cginc"
v2f vert(vlb_appdata v) { return vertShared(v ); }
half4 frag(v2f i) : SV_Target { return fragShared(i ); }
ENDHLSL
}
}
}
}

View File

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

View File

@@ -0,0 +1,128 @@
Shader "Hidden/VLB_SD_URP_Default"
{
Properties
{
_ConeRadius("Cone Radius", Vector) = (0,0,0,0)
_ConeGeomProps("Cone Geom Props", Vector) = (0,0,0,0)
_ColorFlat("Color", Color) = (1,1,1,1)
_HDRPExposureWeight("HDRP Exposure Weight", Range(0,1)) = 0
_DistanceFallOff("Distance Fall Off", Vector) = (0,1,1,0)
_NoiseVelocityAndScale("Noise Velocity And Scale", Vector) = (0,0,0,0)
_NoiseParam("Noise Param", Vector) = (0,0,0,0)
_BlendSrcFactor("BlendSrcFactor", Int) = 1 // One
_BlendDstFactor("BlendDstFactor", Int) = 1 // One
_ZTest("ZTest", Int) = 4 // LEqual
// SD
_ConeSlopeCosSin("Cone Slope Cos Sin", Vector) = (0,0,0,0)
_AlphaInside("Alpha Inside", Range(0,1)) = 1
_AlphaOutside("Alpha Outside", Range(0,1)) = 1
_DistanceCamClipping("Camera Clipping Distance", Float) = 0.5
_FadeOutFactor("FadeOutFactor", Float) = 1
_AttenuationLerpLinearQuad("Lerp between attenuation linear and quad", Float) = 0.5
_DepthBlendDistance("Depth Blend Distance", Float) = 2
_FresnelPow("Fresnel Pow", Range(0,15)) = 1
_GlareFrontal("Glare Frontal", Range(0,1)) = 0.5
_GlareBehind("Glare from Behind", Range(0,1)) = 0.5
_DrawCap("Draw Cap", Float) = 1
_CameraParams("Camera Params", Vector) = (0,0,0,0)
_DynamicOcclusionClippingPlaneWS("Dynamic Occlusion Clipping Plane WS", Vector) = (0,0,0,0)
_DynamicOcclusionClippingPlaneProps("Dynamic Occlusion Clipping Plane Props", Float) = 0.25
_DynamicOcclusionDepthTexture("DynamicOcclusionDepthTexture", 2D) = "white" {}
_DynamicOcclusionDepthProps("DynamicOcclusionDepthProps", Vector) = (1, 1, 0.25, 1)
_LocalForwardDirection("LocalForwardDirection", Vector) = (0,0,1)
_TiltVector("TiltVector", Vector) = (0,0,0,0)
_AdditionalClippingPlaneWS("AdditionalClippingPlaneWS", Vector) = (0,0,0,0)
// HD
_Intensity("Intensity", Range(0,8)) = 1
_SideSoftness("SideSoftness", Range(0,15)) = 1
_Jittering("Jittering", Vector) = (0,0,0,0)
_CameraForwardOS("Camera Forward OS", Vector) = (0,0,0)
_CameraForwardWS("Camera Forward WS", Vector) = (0,0,0)
_TransformScale("Transform Scale", Vector) = (0,0,0)
_CookieTexture("CookieTexture", 2D) = "white" {}
_CookieProperties("CookieProperties", Vector) = (0,0,0,0)
_CookiePosAndScale("CookiePosAndScale", Vector) = (0,0,1,1)
_ShadowDepthTexture("ShadowDepthTexture", 2D) = "white" {}
_ShadowProps("ShadowProps", Vector) = (1,1,1,1)
}
Category
{
Tags
{
"Queue" = "Transparent"
"RenderType" = "Transparent"
"IgnoreProjector" = "True"
"DisableBatching" = "True" // disable dynamic batching which doesn't work neither with multiple materials nor material property blocks
}
Blend[_BlendSrcFactor][_BlendDstFactor]
ZWrite Off
ZTest[_ZTest]
SubShader
{
Pass
{
Cull Front
HLSLPROGRAM
#if !defined(SHADER_API_METAL) // Removed shader model spec for Metal support https://github.com/keijiro/Cloner/commit/1120493ca2df265d450de3ec1b38a1d388468964
#pragma target 3.0
#endif
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile_local __ VLB_ALPHA_AS_BLACK
#pragma multi_compile_local __ VLB_NOISE_3D
#pragma multi_compile_local __ VLB_COLOR_GRADIENT_MATRIX_HIGH
#pragma multi_compile_local __ VLB_DEPTH_BLEND
#pragma multi_compile_local __ VLB_OCCLUSION_CLIPPING_PLANE VLB_OCCLUSION_DEPTH_TEXTURE
#pragma multi_compile_local __ VLB_MESH_SKEWING
#pragma multi_compile_local __ VLB_SHADER_ACCURACY_HIGH
#define VLB_SRP_API 1
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
#include "ShaderDefines.cginc"
#include "ShaderProperties.cginc"
#include "ShaderSpecificURP.cginc"
#include "VolumetricLightBeamSharedSD.cginc"
v2f vert(vlb_appdata v) { return vertShared(v , v.texcoord.y); }
half4 frag(v2f i) : SV_Target { return fragShared(i , i.cameraPosObjectSpace_outsideBeam.w); }
ENDHLSL
}
}
}
}

View File

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

View File

@@ -0,0 +1,531 @@
// The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility
// UNITY_SHADER_NO_UPGRADE
#ifndef _VOLUMETRIC_LIGHT_BEAM_SHARED_INCLUDED_
#define _VOLUMETRIC_LIGHT_BEAM_SHARED_INCLUDED_
/// ****************************************
/// SHADER INPUT / OUTPUT STRUCT
/// ****************************************
struct vlb_appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
#if VLB_INSTANCING_API_AVAILABLE && (VLB_STEREO_INSTANCING || VLB_GPU_INSTANCING)
UNITY_VERTEX_INPUT_INSTANCE_ID // for GPU Instancing and Single Pass Instanced rendering
#endif
};
struct v2f
{
float4 posClipSpace : SV_POSITION;
float3 posObjectSpace : TEXCOORD0;
float4 posWorldSpace : TEXCOORD1;
float3 posViewSpace : TEXCOORD2;
float3 cameraPosObjectSpace : TEXCOORD3;
float4 projPos : TEXCOORD6;
#ifdef VLB_FOG_UNITY_BUILTIN_COORDS
UNITY_FOG_COORDS(7)
#endif
#if VLB_INSTANCING_API_AVAILABLE
#if VLB_GPU_INSTANCING
UNITY_VERTEX_INPUT_INSTANCE_ID // not sure this one is useful
#endif
#if VLB_STEREO_INSTANCING
UNITY_VERTEX_OUTPUT_STEREO // for Single Pass Instanced rendering
#endif
#endif // VLB_INSTANCING_API_AVAILABLE
};
#include "ShaderUtils.cginc"
inline float ComputeFadeWithCamera(float3 posViewSpace, float enabled)
{
float distCamToPixWS = abs(posViewSpace.z); // only check Z axis (instead of length(posViewSpace.xyz)) to have smoother transition with near plane (which is not curved)
float camFadeDistStart = _ProjectionParams.y; // cam near place
float camFadeDistEnd = camFadeDistStart + _VLB_CameraBlendingDistance;
float fadeWhenTooClose = smoothstep(0, 1, invLerpClamped(camFadeDistStart, camFadeDistEnd, distCamToPixWS));
// fade out according to camera's near plane
return lerp(1, fadeWhenTooClose, enabled);
}
// Vector Camera to current Pixel, in object space and normalized
inline float3 ComputeVectorCamToPixOSN(float3 pixPosOS, float3 cameraPosOS)
{
float3 vecCamToPixOSN = normalize(pixPosOS - cameraPosOS);
// Deal with ortho camera:
// With ortho camera, we don't want to change the fresnel according to camera position.
// So instead of computing the proper vector "Camera to Pixel", we take account of the "Camera Forward" vector (which is not dependant on the pixel position)
float3 vecCamForwardOSN = VLB_GET_PROP(_CameraForwardOS);
return lerp(vecCamToPixOSN, vecCamForwardOSN, VLB_CAMERA_ORTHO);
}
v2f vertShared(vlb_appdata v)
{
v2f o;
#if VLB_INSTANCING_API_AVAILABLE && (VLB_STEREO_INSTANCING || VLB_GPU_INSTANCING)
UNITY_SETUP_INSTANCE_ID(v);
#if VLB_STEREO_INSTANCING
#ifndef VLB_SRP_API // TODO CHECK THAT WE DON'T NEED THIS WITH SRP
UNITY_INITIALIZE_OUTPUT(v2f, o);
#endif
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#endif
#if VLB_GPU_INSTANCING
UNITY_TRANSFER_INSTANCE_ID(v, o);
#endif
#endif
// compute the proper cone shape, so the whole beam fits into a 2x2x1 box
// The model matrix (computed via the localScale from BeamGeometry.)
float4 vertexOS = v.vertex;
float2 coneRadius = VLB_GET_PROP(_ConeRadius);
float maxRadius = max(coneRadius.x, coneRadius.y);
float normalizedRadiusStart = coneRadius.x / maxRadius;
float normalizedRadiusEnd = coneRadius.y / maxRadius;
vertexOS.xy *= lerp(normalizedRadiusStart, normalizedRadiusEnd, vertexOS.z);
float3 scaleObjectSpace = float3(maxRadius, maxRadius, VLB_GET_PROP(_DistanceFallOff).z); // maxGeometryDistance
o.posWorldSpace = VLBObjectToWorldPos(vertexOS);
o.posClipSpace = VLBObjectToClipPos(vertexOS.xyz);
// TODO Should create and use VLBWorldToClipPos instead
//o.posClipSpace = VLBWorldToClipPos(o.posWorldSpace.xyz);
#if defined(VLBWorldToViewPos)
float3 posViewSpace = VLBWorldToViewPos(o.posWorldSpace.xyz);
#elif defined(VLBObjectToViewPos)
float3 posViewSpace = VLBObjectToViewPos(vertexOS);
#else
You_should_define_either_VLBWorldToViewPos_or_VLBObjectToViewPos
#endif
// apply the same scaling than we do through the localScale in BeamGeometry.ComputeLocalMatrix
// to get the proper transformed vertex position in object space
o.posObjectSpace = vertexOS.xyz * scaleObjectSpace;
o.projPos = Depth_VS_ComputeProjPos(posViewSpace, o.posClipSpace);
o.cameraPosObjectSpace = VLBGetCameraPositionObjectSpace(scaleObjectSpace);
o.posViewSpace = posViewSpace;
#ifdef VLB_FOG_UNITY_BUILTIN_COORDS
UNITY_TRANSFER_FOG(o, o.posClipSpace);
#endif
return o;
}
// original code from Inigo Quilez: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm
float coneIntersect(float3 rayOrigin, float3 rayDir, float3 conePosEnd, float radiusStart, float radiusEnd)
{
float3 ba = conePosEnd;
float3 oa = rayOrigin;
float3 ob = rayOrigin - conePosEnd;
float m0 = dot(ba, ba);
float m1 = dot(oa, ba);
float m2 = dot(rayDir, ba);
float m3 = dot(rayDir, oa);
float m5 = dot(oa, oa);
float m9 = dot(ob, ba);
// caps
if (m1 < 0.0)
{
if (dot2(oa*m2 - rayDir * m1) < (radiusStart*radiusStart*m2*m2)) // delayed division
return -m1 / m2;
}
else if (m9 > 0.0)
{
float t = -m9 / m2; // NOT delayed division
if (dot2(ob + rayDir * t) < (radiusEnd*radiusEnd))
return t;
}
// body
float rr = radiusStart - radiusEnd;
float hy = m0 + rr * rr;
float k2 = m0 * m0 - m2 * m2*hy;
float k1 = m0 * m0*m3 - m1 * m2*hy + m0 * radiusStart*(rr*m2*1.0);
float k0 = m0 * m0*m5 - m1 * m1*hy + m0 * radiusStart*(rr*m1*2.0 - m0 * radiusStart);
float h = k1 * k1 - k2 * k0;
if (h < 0.0) return -1.0; // no intersection
float t = (-k1 - sqrt(h)) / k2;
float y = m1 + t * m2;
if (y<0.0 || y>m0) return -1.0; //no intersection
return t;
}
half4 fragShared(v2f i)
{
#if VLB_INSTANCING_API_AVAILABLE && VLB_GPU_INSTANCING
UNITY_SETUP_INSTANCE_ID(i);
#endif
#if VLB_INSTANCING_API_AVAILABLE && VLB_STEREO_INSTANCING
// This fix access to depth map on the right eye when using single pass (aka Stereo Rendering Mode Multiview) on Gear VR or Oculus Go/Quest
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); // https://docs.unity3d.com/Manual/SinglePassInstancing.html
#endif
float3 transformScale = VLB_GET_PROP(_TransformScale);
float3 intersectOutOS = i.posObjectSpace * transformScale;
// compute proper ray start and dir
float3 realCamPosOS = i.cameraPosObjectSpace.xyz * transformScale;
float3 rayDirOS = ComputeVectorCamToPixOSN(intersectOutOS, realCamPosOS); // deal with ortho cam here
float3 realVecCamToPix = intersectOutOS - realCamPosOS;
float rayLength = dot(rayDirOS, realVecCamToPix);
float3 rayStartOS = intersectOutOS - rayLength * rayDirOS;
#if VLB_NOISE_3D
// only useful for noise world space
float3 intersectOutWS = i.posWorldSpace.xyz;
float3 rayDirWS, rayStartWS;
{
float3 perspRayStartWS = _WorldSpaceCameraPos.xyz;
float3 perspRayDirWS = normalize(intersectOutWS - perspRayStartWS);
float3 orthoRayDirWS = VLB_GET_PROP(_CameraForwardWS);
float3 orthoRayStartWS = intersectOutWS - rayLength * orthoRayDirWS;
rayStartWS = lerp(perspRayStartWS, orthoRayStartWS, VLB_CAMERA_ORTHO);
rayDirWS = lerp(perspRayDirWS, orthoRayDirWS, VLB_CAMERA_ORTHO);
}
#endif // VLB_NOISE_3D
float distanceFadeEnd = VLB_GET_PROP(_DistanceFallOff).y * transformScale.z;
float2 coneRadius = VLB_GET_PROP(_ConeRadius) * min(transformScale.x, transformScale.y);
float tIn = coneIntersect(rayStartOS, rayDirOS, float3(0, 0, distanceFadeEnd), coneRadius.x, coneRadius.y);
// fix artifact in VR on geometry edges when no intersection is found
float intensity = 1.0 - ifAnd(
isLower(tIn, 0.0),
isLower(realCamPosOS.z, 0.0) // is it ok to apply transformScale here?
);
tIn = max(tIn, 0); // when camera is inside the beam, tIn = -1: set tIn at 0
float tOut = length(rayStartOS - intersectOutOS);
float sceneZ = Depth_PS_GetSceneDepthFromEye(i.projPos, i.posViewSpace);
{ // DEBUG
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHBUFFER_FROMEYE
return Depth_PS_GetSceneDepthFromEye(i.projPos, i.posViewSpace) * _ProjectionParams.w;
#elif DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHBUFFER_FROMNEARPLANE
return Depth_PS_GetSceneDepthFromNearPlane(i.projPos) * _ProjectionParams.w;
#elif DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHSTEREOEYE
float depthValue = Depth_PS_GetSceneDepthFromEye(i.projPos, i.posViewSpace) * _ProjectionParams.w;
#if defined(USING_STEREO_MATRICES) && defined(UNITY_STEREO_MULTIVIEW_ENABLED) // used with single pass / multiview on android VR (Oculus Go/Quest, Gear VR)
return depthValue * lerp(float4(1, 0, 0, 1), float4(0, 1, 0, 1), unity_StereoEyeIndex);
#elif defined(UNITY_SINGLE_PASS_STEREO)
return depthValue * lerp(float4(1, 0, 0, 1), float4(0, 0, 1, 1), unity_StereoEyeIndex);
#elif defined(UNITY_STEREO_INSTANCING_ENABLED)
return depthValue * lerp(float4(0, 1, 0, 1), float4(0, 0, 1, 1), unity_StereoEyeIndex);
#elif defined(UNITY_STEREO_MULTIVIEW_ENABLED)
return depthValue * lerp(float4(1, 1, 0, 1), float4(0, 1, 1, 1), unity_StereoEyeIndex);
#else
return depthValue;
#endif
#elif DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHBLEND
return float4(1 - saturate(abs(tIn - sceneZ)), 1 - saturate(abs(tOut - sceneZ)), 0, 1);
#endif
} // DEBUG
tOut = min(tOut, sceneZ);
float tInJittered = tIn;
// add jittering
{
float2 screenPos = i.projPos.xy / i.projPos.w;
float2 jitterCoord = screenPos * _ScreenParams.xy * _VLB_JitteringNoiseTex_TexelSize.xy;
float jitterNoise = tex2D(_VLB_JitteringNoiseTex, jitterCoord).r;
float4 jitterProps = VLB_GET_PROP(_Jittering);
// Golden Ratio Animated Noise https://blog.demofox.org/2017/10/31/animating-noise-for-integration-over-time/
float frameRate = jitterProps.y;
const float kGoldenRatio = 1.61803398875f; // (1.0f + sqrt(5.0f)) * 0.5f;
const float kGoldenRatioFrac = 0.61803398875f;
uint frame = uint(floor(_Time.y * frameRate));
jitterNoise = frac(jitterNoise + float(frame) * kGoldenRatio);
float3 intersectInOS = rayStartOS + rayDirOS * tIn;
float currentPosZNorm = max(intersectInOS.z, intersectOutOS.z) / distanceFadeEnd;
float jitterRatio = invLerpClamped(jitterProps.z /* range start */, jitterProps.w /* range end */, currentPosZNorm);
tInJittered += jitterNoise * jitterRatio * jitterProps.x;
}
#if VLB_COLOR_GRADIENT
float4 colorGradient = 0.0;
#endif // VLB_COLOR_GRADIENT
#if VLB_COOKIE_RGBA
float4 colorCookieSum = 0;
#endif // VLB_COOKIE_RGBA
{
float distanceFadeStart = VLB_GET_PROP(_DistanceFallOff).x * transformScale.z;
float sumLerp = 0.0;
float sumLinear = 0.0;
float sideSoftness = VLB_GET_PROP(_SideSoftness);
const int raymarchSteps = VLB_RAYMARCHING_STEP_COUNT;
int stepCountLinear = 0;
float stepLinear = 1.1 * distanceFadeEnd / raymarchSteps;
float tLinear = tIn; // using the non jittered version of tIn for linear sampling helps a bit smoothing the noise
#if VLB_SHADOW
// cache some values useful for shadow computing
float4 shw_props = VLB_GET_PROP(_ShadowProps);
const float shw_isPersp = shw_props.w;
const float shw_apexDist = VLB_GET_PROP(_ConeGeomProps).x * shw_isPersp;
const float kMinNearClipPlane = 0.1f * shw_isPersp; // should be the same than in VolumetricShadowHD.cs
const float shw_nearUnscaled = max(shw_apexDist, kMinNearClipPlane / transformScale.z);
const float shw_nearScaled = max(shw_apexDist, kMinNearClipPlane);
const float shw_farUnscaled = shw_nearUnscaled + distanceFadeEnd / transformScale.z;
const float shw_farScaled = shw_nearScaled + distanceFadeEnd;
// handle scale X & Y
float2 shw_ratioScale;
{
float ratioScale = transformScale.x / transformScale.y;
if (ratioScale >= 1) shw_ratioScale = float2(1.0 / ratioScale, 1.0);
else shw_ratioScale = float2(1.0, ratioScale);
}
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_SHADOW_DEPTH
{
float shadowDepthRaw = tex2D(_ShadowDepthTexture, i.projPos.xy / i.projPos.w).r;
float shadowDepthLinearPersp = VLB_ZBufferToLinear(shadowDepthRaw, shw_nearUnscaled, shw_farUnscaled);
shadowDepthLinearPersp = fromABtoCD_Clamped(shadowDepthLinearPersp, shw_nearUnscaled, shw_farUnscaled, shw_nearScaled, shw_farScaled);
const float shadowDepthLinearOrtho = shadowDepthRaw * (shw_farScaled - shw_nearScaled);
float shadowDepthLinear = lerp(shadowDepthLinearOrtho, shadowDepthLinearPersp, shw_isPersp) - shw_apexDist;
return shadowDepthLinear;
}
#endif // DEBUG_DEPTH_MODE
#endif // VLB_SHADOW
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_LINEAR_OVERFLOW
bool linearStepsOverflow = false;
#endif // DEBUG_VALUE_LINEAR_OVERFLOW
for (int i = 0; i < raymarchSteps; i++)
{
float t = saturate(float(i+1) / (raymarchSteps + 1));
float tLerp = lerp(tInJittered, tOut, t); // use the jittered version of tIn to apply noise on raymarching
float3 posOSLinear = rayStartOS + rayDirOS * tLinear;
float3 posOSLerp = rayStartOS + rayDirOS * tLerp;
//if (length(posOSLerp - rayStartOS) > tOut) { break; } // Fix cookie sampling artifacts when a geometry is placed between the camera and the beam. Useless when disabling mipmaps on cookie texture
float att = ComputeAttenuationHD(posOSLerp.z, distanceFadeStart, distanceFadeEnd);
float widthAtThisZ = fromABtoCD_Clamped(posOSLerp.z, 0.0, distanceFadeEnd, coneRadius.x, coneRadius.y);
float fresnel = (widthAtThisZ - length(posOSLerp.xy)) / (widthAtThisZ * sideSoftness);
fresnel = saturate(fresnel);
float powerAtThisStepLerp = att * fresnel;
float powerAtThisStepLinear = 1.0;
#if VLB_COLOR_GRADIENT
colorGradient += ApplyAlphaToColor(ComputeColorGradient(posOSLerp.z / transformScale.z));
#endif // VLB_COLOR_GRADIENT
#if VLB_NOISE_3D
{
//#define VLB_NOISE_3D_LINEAR 1
#if VLB_NOISE_3D_LINEAR
float3 posWSLinear = rayStartWS + rayDirWS * tLinear;
float3 noiseUVWLinear = Noise3D_GetUVW(posWSLinear, posOSLinear);
float noiseFactorLinear = Noise3D_GetFactorFromUVW(noiseUVWLinear);
powerAtThisStepLinear *= noiseFactorLinear;
#else
float3 posWSLerp = rayStartWS + rayDirWS * tLerp;
float3 noiseUVWLerp = Noise3D_GetUVW(posWSLerp, posOSLerp);
float noiseFactorLerp = Noise3D_GetFactorFromUVW(noiseUVWLerp);
powerAtThisStepLerp *= noiseFactorLerp;
#endif
}
#endif // VLB_NOISE_3D
#if VLB_COOKIE_1CHANNEL || VLB_COOKIE_RGBA
{
float4 posAndScale = VLB_GET_PROP(_CookiePosAndScale);
float4 props = VLB_GET_PROP(_CookieProperties); // contrib + negative, texture channel, cos(rot), sin(rot)
float2x2 rotMatrix = float2x2(props.z, -props.w, props.w, props.z);
float2 posOSXY = posOSLerp.xy / widthAtThisZ; // [-0.5 ; 0.5]
posOSXY += posAndScale.xy; // translate
posOSXY = mul(posOSXY, rotMatrix); // rotate
posOSXY *= posAndScale.zw; // scale
posOSXY = posOSXY * 0.5 + 0.5; // transform coord to [0.0 ; 1.0]
#if VLB_COOKIE_1CHANNEL
float cookie = tex2D(_CookieTexture, posOSXY)[(int)props.y];
float negative = max(props.x, 0); // props.x also store contribution as negative value if negative
float contrib = abs(props.x);
powerAtThisStepLerp *= lerp(1.0, lerp(cookie, 1.0 - cookie, negative), contrib);
#endif
#if VLB_COOKIE_RGBA
colorCookieSum += tex2D(_CookieTexture, posOSXY);
#endif
}
#endif // VLB_COOKIE_1CHANNEL || VLB_COOKIE_RGBA
#if VLB_SHADOW
{
float3 posOSRef = posOSLerp;
float width = lerp(coneRadius.x, widthAtThisZ, shw_isPersp);
float2 posOSXYNormalized = posOSRef.xy / width;
// handle scale X & Y
posOSXYNormalized *= shw_ratioScale;
posOSXYNormalized = posOSXYNormalized * 0.5 + 0.5;
posOSXYNormalized.x = flipUV(posOSXYNormalized.x, shw_props.x);
posOSXYNormalized.y = flipUV(posOSXYNormalized.y, shw_props.y);
float shadowDepthRaw = tex2D(_ShadowDepthTexture, posOSXYNormalized).r;
shadowDepthRaw = lerp(shadowDepthRaw, 1.0f - shadowDepthRaw, _VLB_UsesReversedZBuffer);
// Compte perspective linear depth and handle Z scaling
float shadowDepthLinearPersp = VLB_ZBufferToLinear(shadowDepthRaw, shw_nearUnscaled, shw_farUnscaled); // decode depth value using unscaled near/far distance
shadowDepthLinearPersp = fromABtoCD_Clamped(shadowDepthLinearPersp, shw_nearUnscaled, shw_farUnscaled, shw_nearScaled, shw_farScaled); // scale the linear depth value according to the scaled near/far distance
// Compute ortho linear depth
const float shadowDepthLinearOrtho = shadowDepthRaw * (shw_farScaled - shw_nearScaled);
// get either the perspective or ortho depth
float shadowDepthLinear = lerp(shadowDepthLinearOrtho, shadowDepthLinearPersp, shw_isPersp) - shw_apexDist;
float factor = isEqualOrGreater(shadowDepthLinear, posOSRef.z);
float dimmer = shw_props.z;
factor = (1 - dimmer) + factor * dimmer; // lerp(1 - dimmer, 1, factor)
powerAtThisStepLerp *= factor;
}
#endif // VLB_SHADOW
sumLerp += powerAtThisStepLerp;
if (tLinear < tOut)
{
tLinear += stepLinear;
sumLinear += powerAtThisStepLinear;
stepCountLinear++;
}
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_LINEAR_OVERFLOW
else
{
linearStepsOverflow = true;
}
#endif // DEBUG_VALUE_LINEAR_OVERFLOW
}
// for loop end
#if VLB_COLOR_GRADIENT
colorGradient /= raymarchSteps;
#endif // VLB_COLOR_GRADIENT
#if VLB_COOKIE_RGBA
colorCookieSum /= raymarchSteps;
#endif // VLB_COOKIE_RGBA
intensity *= (sumLerp / raymarchSteps);
if (stepCountLinear > 0)
{
float meanLinear = (sumLinear / stepCountLinear);
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_LINEAR_OVERFLOW
{
if (!linearStepsOverflow)
return float4(0, 0, 1, 1);
}
#endif // DEBUG_VALUE_LINEAR_OVERFLOW
intensity *= meanLinear;
}
intensity *= (tOut - tIn); // prevent from having a darker circle at end cap
intensity *= VLB_GET_PROP(_Intensity);
}
{
float fadeWithCameraEnabled = 1 - VLB_CAMERA_ORTHO; // fading according to camera eye position doesn't make sense with ortho camera
intensity *= ComputeFadeWithCamera(i.posViewSpace, fadeWithCameraEnabled);
}
{
float factorInsideGeom = isEqualOrGreater(tOut, tIn);
intensity *= factorInsideGeom;
}
#if VLB_COLOR_GRADIENT
float4 color = colorGradient;
#elif VLB_COLOR_FLAT
float4 color = ApplyAlphaToColor(ComputeColorFlat());
#endif // VLB_COLOR_GRADIENT / VLB_COLOR_FLAT
#if VLB_COOKIE_RGBA
{
float4 props = VLB_GET_PROP(_CookieProperties); // contrib + negative, texture channel, cos(rot), sin(rot)
float contrib = abs(props.x);
color *= lerp(1, colorCookieSum, contrib);
}
#endif // VLB_COOKIE_RGBA
#if VLB_DITHERING
{
float2 screenPos = i.projPos.xy / i.projPos.w;
float2 ditherCoord = screenPos * _ScreenParams.xy * _VLB_DitheringNoiseTex_TexelSize.xy;
float dither = tex2D(_VLB_DitheringNoiseTex, ditherCoord).r - 0.5;
color += (1 - saturate(intensity)) * _VLB_DitheringFactor * dither;
}
#endif
ApplyPipelineSpecificIntensityModifier(/* inout */ intensity);
intensity *= GetLODFadeFactor();
#if VLB_ALPHA_AS_BLACK
color *= intensity;
#else
color.a *= intensity;
#endif
#ifdef VLB_FOG_APPLY
VLB_FOG_APPLY(color);
#endif
color.a = clamp(color.a, 0, 1); // clamp alpha to avoid color artifacts on URP with HDR and high intensity
return color;
}
#endif

View File

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

View File

@@ -0,0 +1,590 @@
// The following comment prevents Unity from auto upgrading the shader. Please keep it to keep backward compatibility
// UNITY_SHADER_NO_UPGRADE
#ifndef _VOLUMETRIC_LIGHT_BEAM_SHARED_INCLUDED_
#define _VOLUMETRIC_LIGHT_BEAM_SHARED_INCLUDED_
/// ****************************************
/// SHADER INPUT / OUTPUT STRUCT
/// ****************************************
struct vlb_appdata
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
#if VLB_INSTANCING_API_AVAILABLE && (VLB_STEREO_INSTANCING || VLB_GPU_INSTANCING)
UNITY_VERTEX_INPUT_INSTANCE_ID // for GPU Instancing and Single Pass Instanced rendering
#endif
};
struct v2f
{
float4 posClipSpace : SV_POSITION;
float3 posObjectSpace : TEXCOORD0;
float3 posObjectSpaceNonSkewed : TEXCOORD8;
float4 posWorldSpace : TEXCOORD1;
float4 posViewSpace_extraData : TEXCOORD2;
float4 cameraPosObjectSpace_outsideBeam : TEXCOORD3;
#if OPTIM_VS
half4 color : TEXCOORD4;
#endif
#if VLB_NOISE_3D || OPTIM_VS
float4 uvwNoise_intensity : TEXCOORD5;
#endif
#if VLB_DEPTH_BLEND || VLB_DITHERING
float4 projPos : TEXCOORD6;
#endif
#ifdef VLB_FOG_UNITY_BUILTIN_COORDS
UNITY_FOG_COORDS(7)
#endif
#if VLB_INSTANCING_API_AVAILABLE
#if VLB_GPU_INSTANCING
UNITY_VERTEX_INPUT_INSTANCE_ID // not sure this one is useful
#endif
#if VLB_STEREO_INSTANCING
UNITY_VERTEX_OUTPUT_STEREO // for Single Pass Instanced rendering
#endif
#endif // VLB_INSTANCING_API_AVAILABLE
};
#include "ShaderUtils.cginc"
inline float ComputeBoostFactor(float pixDistFromSource, float outsideBeam, float isCap)
{
pixDistFromSource = max(pixDistFromSource, 0.001); // prevent 1st segment from being boosted when boostFactor is 0
float glareFrontal = VLB_GET_PROP(_GlareFrontal);
float insideBoostDistance = glareFrontal * VLB_GET_PROP(_DistanceFallOff).y;
float boostFactor = 1 - smoothstep(0, 0 + insideBoostDistance + 0.001, pixDistFromSource); // 0 = no boost ; 1 = max boost
boostFactor = lerp(boostFactor, 0, outsideBeam); // no boost for outside pass
float4 cameraParams = VLB_GET_PROP(_CameraParams);
float cameraIsInsideBeamFactor = saturate(cameraParams.w); // _CameraParams.w is (-1 ; 1)
boostFactor = cameraIsInsideBeamFactor * boostFactor; // no boost for outside pass
boostFactor = lerp(boostFactor, 1, isCap); // cap is always at max boost
return boostFactor;
}
// boostFactor is normalized
float ComputeFresnel(float3 posObjectSpace, float3 vecCamToPixOSN, float outsideBeam, float boostFactor)
{
// Compute normal
float2 cosSinFlat = normalize(posObjectSpace.xy);
float2 coneSlopeCosSin = VLB_GET_PROP(_ConeSlopeCosSin);
float3 normalObjectSpace = (float3(cosSinFlat.x * coneSlopeCosSin.x, cosSinFlat.y * coneSlopeCosSin.x, -coneSlopeCosSin.y));
normalObjectSpace *= (outsideBeam * 2 - 1); // = outsideBeam ? 1 : -1;
// real fresnel factor
float fresnelReal = dot(normalObjectSpace, -vecCamToPixOSN);
// compute a fresnel factor to support long beams by projecting the viewDir vector
// on the virtual plane formed by the normal and tangent
float coneApexOffsetZ = VLB_GET_PROP(_ConeGeomProps).x;
float3 tangentPlaneNormal = normalize(posObjectSpace.xyz + float3(0, 0, coneApexOffsetZ));
float distToPlane = dot(-vecCamToPixOSN, tangentPlaneNormal);
float3 vec2D = normalize(-vecCamToPixOSN - distToPlane * tangentPlaneNormal);
float fresnelProjOnTangentPlane = dot(normalObjectSpace, vec2D);
// blend between the 2 fresnels
float3 localForwardDirN = VLB_GET_PROP(_LocalForwardDirection);
float vecCamToPixDotZ = dot(vecCamToPixOSN, localForwardDirN);
float factorNearAxisZ = abs(vecCamToPixDotZ); // factorNearAxisZ is normalized
float fresnel = lerp(fresnelProjOnTangentPlane, fresnelReal, factorNearAxisZ);
float fresnelPow = VLB_GET_PROP(_FresnelPow);
// Lerp the fresnel pow to the glare factor according to how far we are from the axis Z
const float kMaxGlarePow = 1.5;
float glareFrontal = VLB_GET_PROP(_GlareFrontal);
float glareBehind = VLB_GET_PROP(_GlareBehind);
float glareFactor = kMaxGlarePow * (1 - lerp(glareFrontal, glareBehind, outsideBeam));
fresnelPow = lerp(fresnelPow, min(fresnelPow, glareFactor), factorNearAxisZ);
// Pow the fresnel
fresnel = smoothstep(0, 1, fresnel);
fresnel = (1 - isEqualOrGreater(-fresnel, 0)) * // fix edges artefacts on android ES2
(pow(fresnel, fresnelPow));
// Boost distance inside
float boostFresnel = lerp(fresnel, 1 + 0.001, boostFactor);
fresnel = lerp(boostFresnel, fresnel, outsideBeam); // no boosted fresnel if outside
// We do not have to treat cap a special way, since boostFactor is already set to 1 for cap via ComputeBoostFactor
return fresnel;
}
inline float ComputeFadeWithCamera(float3 posViewSpace, float enabled)
{
float distCamToPixWS = abs(posViewSpace.z); // only check Z axis (instead of length(posViewSpace.xyz)) to have smoother transition with near plane (which is not curved)
float camFadeDistStart = _ProjectionParams.y; // cam near place
float camFadeDistEnd = camFadeDistStart + VLB_GET_PROP(_DistanceCamClipping);
float fadeWhenTooClose = smoothstep(0, 1, invLerpClamped(camFadeDistStart, camFadeDistEnd, distCamToPixWS));
// fade out according to camera's near plane
return lerp(1, fadeWhenTooClose, enabled);
}
float4 ComputeColor(float pixDistFromSource, float outsideBeam)
{
#if VLB_COLOR_GRADIENT
float4 color = ComputeColorGradient(pixDistFromSource);
#elif VLB_COLOR_FLAT
float4 color = ComputeColorFlat();
#endif
float alphaInside = VLB_GET_PROP(_AlphaInside);
float alphaOutside = VLB_GET_PROP(_AlphaOutside);
float alpha = lerp(alphaInside, alphaOutside, outsideBeam);
return ApplyAlphaToColor(color, alpha);
}
inline float ComputeInOutBlending(float vecCamToPixDotZ, float outsideBeam)
{
// smooth blend between inside and outside geometry depending of View Direction
const float kFaceLightSmoothingLimit = 1;
float factorFaceLightSourcePerPixN = saturate(smoothstep(kFaceLightSmoothingLimit, -kFaceLightSmoothingLimit, vecCamToPixDotZ)); // smoother transition
return lerp(factorFaceLightSourcePerPixN, 1 - factorFaceLightSourcePerPixN, outsideBeam);
}
#if VLB_MESH_SKEWING
inline float4 SkewVectorOS(float4 vec, float3 scaleObjectSpace)
{
float3 localForwardDirN = VLB_GET_PROP(_LocalForwardDirection);
vec.xy += vec.z * localForwardDirN.xy * scaleObjectSpace.z / (scaleObjectSpace.xy * localForwardDirN.z);
return vec;
}
inline float3 UnskewVectorOS(float3 vec)
{
float3 localForwardDirN = VLB_GET_PROP(_LocalForwardDirection);
vec.xy -= localForwardDirN.xy * (vec.z / localForwardDirN.z);
return vec;
}
#endif // VLB_MESH_SKEWING
// Vector Camera to current Pixel, in object space and normalized
inline float3 ComputeVectorCamToPixOSN(float3 pixPosOS, float3 cameraPosOS)
{
float3 vecCamToPixOSN = normalize(pixPosOS - cameraPosOS);
// Deal with ortho camera:
// With ortho camera, we don't want to change the fresnel according to camera position.
// So instead of computing the proper vector "Camera to Pixel", we take account of the "Camera Forward" vector (which is not dependant on the pixel position)
float4 cameraParams = VLB_GET_PROP(_CameraParams);
float3 vecCamForwardOSN = cameraParams.xyz;
#if VLB_MESH_SKEWING
vecCamForwardOSN = normalize(UnskewVectorOS(vecCamForwardOSN));
#endif // VLB_MESH_SKEWING
return lerp(vecCamToPixOSN, vecCamForwardOSN, VLB_CAMERA_ORTHO);
}
inline float GetTiltDistanceFactor(float3 posObjectSpace)
{
float2 tiltVector = VLB_GET_PROP(_TiltVector);
float pixDistFromSource = abs(posObjectSpace.z);
return pixDistFromSource + posObjectSpace.x * tiltVector.x + posObjectSpace.y * tiltVector.y;
}
v2f vertShared(vlb_appdata v, float outsideBeam)
{
v2f o;
#if VLB_INSTANCING_API_AVAILABLE && (VLB_STEREO_INSTANCING || VLB_GPU_INSTANCING)
UNITY_SETUP_INSTANCE_ID(v);
#if VLB_STEREO_INSTANCING
#ifndef VLB_SRP_API // TODO CHECK THAT WE DON'T NEED THIS WITH SRP
UNITY_INITIALIZE_OUTPUT(v2f, o);
#endif
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#endif
#if VLB_GPU_INSTANCING
UNITY_TRANSFER_INSTANCE_ID(v, o);
#endif
#endif
#if VLB_NOISE_3D || OPTIM_VS
o.uvwNoise_intensity = 1;
#endif
// compute the proper cone shape, so the whole beam fits into a 2x2x1 box
// The model matrix (computed via the localScale from BeamGeometry.)
float4 vertexOS = v.vertex;
vertexOS.z *= vertexOS.z; // make segment tessellation denser near the source, since beam is usually more visible at start
float2 coneRadius = VLB_GET_PROP(_ConeRadius);
float maxRadius = max(coneRadius.x, coneRadius.y);
float normalizedRadiusStart = coneRadius.x / maxRadius;
float normalizedRadiusEnd = coneRadius.y / maxRadius;
vertexOS.xy *= lerp(normalizedRadiusStart, normalizedRadiusEnd, vertexOS.z);
float3 scaleObjectSpace = float3(maxRadius, maxRadius, VLB_GET_PROP(_DistanceFallOff).z); // maxGeometryDistance
o.posObjectSpaceNonSkewed = vertexOS.xyz * scaleObjectSpace;
#if VLB_MESH_SKEWING
// skew the real vertex position
vertexOS = SkewVectorOS(vertexOS, scaleObjectSpace);
#endif
o.posWorldSpace = VLBObjectToWorldPos(vertexOS);
o.posClipSpace = VLBObjectToClipPos(vertexOS.xyz);
// TODO Should create and use VLBWorldToClipPos instead
//o.posClipSpace = VLBWorldToClipPos(o.posWorldSpace.xyz);
#if defined(VLBWorldToViewPos)
float3 posViewSpace = VLBWorldToViewPos(o.posWorldSpace.xyz);
#elif defined(VLBObjectToViewPos)
float3 posViewSpace = VLBObjectToViewPos(vertexOS);
#else
You_should_define_either_VLBWorldToViewPos_or_VLBObjectToViewPos
#endif
// apply the same scaling than we do through the localScale in BeamGeometry.ComputeLocalMatrix
// to get the proper transformed vertex position in object space
o.posObjectSpace = vertexOS.xyz * scaleObjectSpace;
#if VLB_DEPTH_BLEND || VLB_DITHERING
o.projPos = Depth_VS_ComputeProjPos(posViewSpace, o.posClipSpace);
#endif
float isCap = v.texcoord.x;
#if VLB_NOISE_3D
o.uvwNoise_intensity.rgb = Noise3D_GetUVW(o.posWorldSpace.xyz, o.posObjectSpace);
#endif
float3 cameraPosObjectSpace = VLBGetCameraPositionObjectSpace(scaleObjectSpace);
#if VLB_MESH_SKEWING
cameraPosObjectSpace = UnskewVectorOS(cameraPosObjectSpace); // unskew the camera position of object space
#endif // VLB_MESH_SKEWING
o.cameraPosObjectSpace_outsideBeam = float4(
cameraPosObjectSpace,
outsideBeam);
#if OPTIM_VS
// Treat Cap a special way: cap is only visible from inside
float intensity = 1 - outsideBeam * isCap; // AKA if (outsideBeam == 1 && isCap == 1) intensity = 0
float pixDistFromSource = length(o.posObjectSpace.z);
float pixDistFromSourceTilted = GetTiltDistanceFactor(o.posObjectSpace);
float3 distancesFallOff = VLB_GET_PROP(_DistanceFallOff);
float attenuationLerpLinearQuad = VLB_GET_PROP(_AttenuationLerpLinearQuad);
intensity *= ComputeAttenuationSD(pixDistFromSourceTilted, distancesFallOff.x, distancesFallOff.y, attenuationLerpLinearQuad);
float boostFactor = ComputeBoostFactor(pixDistFromSource, outsideBeam, isCap);
// Vector Camera to current Pixel, in object space and normalized
float3 vecCamToPixOSN = ComputeVectorCamToPixOSN(o.posObjectSpaceNonSkewed.xyz, cameraPosObjectSpace);
float vecCamToPixDotZ = dot(vecCamToPixOSN, float3(0, 0, 1));
#if OPTIM_VS_FRESNEL_VS
// Pass data needed to compute fresnel in fragment shader
// Computing fresnel on vertex shader give imprecise results
intensity *= ComputeFresnel(o.posObjectSpaceNonSkewed, vecCamToPixOSN, outsideBeam, boostFactor);
#endif
// fade out
intensity *= VLB_GET_PROP(_FadeOutFactor);
// smooth blend between inside and outside geometry depending of View Direction
intensity *= ComputeInOutBlending(vecCamToPixDotZ, outsideBeam);
// no intensity for cap if _DrawCap = 0
float drawCap = VLB_GET_PROP(_DrawCap);
intensity *= isEqualOrGreater(drawCap, isCap);
o.uvwNoise_intensity.a = intensity;
o.color = ComputeColor(pixDistFromSourceTilted, outsideBeam);
float extraData = boostFactor;
#else
float extraData = isCap;
#endif // OPTIM_VS
o.posViewSpace_extraData = float4(posViewSpace, extraData);
#ifdef VLB_FOG_UNITY_BUILTIN_COORDS
UNITY_TRANSFER_FOG(o, o.posClipSpace);
#endif
return o;
}
half4 fragShared(v2f i, float outsideBeam)
{
#if VLB_INSTANCING_API_AVAILABLE && VLB_GPU_INSTANCING
UNITY_SETUP_INSTANCE_ID(i);
#endif
#if VLB_INSTANCING_API_AVAILABLE && VLB_STEREO_INSTANCING
// This fix access to depth map on the right eye when using single pass (aka Stereo Rendering Mode Multiview) on Gear VR or Oculus Go/Quest
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); // https://docs.unity3d.com/Manual/SinglePassInstancing.html
#endif
{
float4 cameraParams = VLB_GET_PROP(_CameraParams);
float cameraIsInsideBeamFactor = saturate(cameraParams.w); // _CameraParams.w is (-1 ; 1)
}
#if OPTIM_VS
float intensity = i.uvwNoise_intensity.a;
#else
float intensity = 1;
#endif
float pixDistFromSource = length(i.posObjectSpace.z);
// additional clipping plane
{
float4 addClippingPlaneWS = VLB_GET_PROP(_AdditionalClippingPlaneWS);
clip(DistanceToPlane(i.posWorldSpace.xyz, addClippingPlaneWS.xyz, addClippingPlaneWS.w));
}
// DYNAMIC OCCLUSION
#if VLB_OCCLUSION_CLIPPING_PLANE
{
float4 clippingPlaneWS = VLB_GET_PROP(_DynamicOcclusionClippingPlaneWS);
float distToClipPlane = DistanceToPlane(i.posWorldSpace.xyz, clippingPlaneWS.xyz, clippingPlaneWS.w);
clip(distToClipPlane);
float fadeDistance = VLB_GET_PROP(_DynamicOcclusionClippingPlaneProps);
intensity *= smoothstep(0, fadeDistance, distToClipPlane);
}
#elif VLB_OCCLUSION_DEPTH_TEXTURE
{
#if VLB_GPU_INSTANCING
// Dynamic Occlusion Depth Texture is not supported with GPU Instancing because instanced cbuffers cannot hold samplers
return float4(1, 0, 0, 1);
#endif
const float kMinNearClipPlane = 0.1f; // should be the same than in DynamicOcclusion.cs
float4 depthProps = VLB_GET_PROP(_DynamicOcclusionDepthProps);
const float isPersp = depthProps.w;
float2 coneMeshProps = VLB_GET_PROP(_ConeGeomProps);
float2 coneRadius = VLB_GET_PROP(_ConeRadius);
float widthAtThisZ = fromABtoCD_Clamped(pixDistFromSource, 0.0, VLB_GET_PROP(_DistanceFallOff).z, coneRadius.x, coneRadius.y);
float width = lerp(coneRadius.x, widthAtThisZ, isPersp);
float2 srcUvCentered = (i.posObjectSpace.xy) / width;
int coneMeshSides = (int)coneMeshProps.y;
if (coneMeshSides == 4)
{
// with 4 sides, make the UV matches a square instead of a cone to match with depth buffer camera frustum
float maxCenteredUV = max(abs(srcUvCentered.x), abs(srcUvCentered.y));
srcUvCentered /= maxCenteredUV;
}
float2 uv = srcUvCentered * 0.5 + 0.5;
uv.x = flipUV(uv.x, depthProps.x);
uv.y = flipUV(uv.y, depthProps.y);
float dynamicOcclusionDepthRaw = tex2D(_DynamicOcclusionDepthTexture, uv).r;
dynamicOcclusionDepthRaw = lerp(dynamicOcclusionDepthRaw, 1.0f - dynamicOcclusionDepthRaw, _VLB_UsesReversedZBuffer);
float fallOffEnd = VLB_GET_PROP(_DistanceFallOff).z; // maxGeometryDistance
float apexDist = coneMeshProps.x * isPersp;
float near = max(apexDist, kMinNearClipPlane);
float far = near + fallOffEnd;
const float dynamicOcclusionDepthLinearPersp = VLB_ZBufferToLinear(dynamicOcclusionDepthRaw, near, far);
// Compute ortho linear depth
const float dynamicOcclusionDepthLinearOrtho = dynamicOcclusionDepthRaw * (far - near);
// get either the perspective or ortho depth
float dynamicOcclusionDepthLinear = lerp(dynamicOcclusionDepthLinearOrtho, dynamicOcclusionDepthLinearPersp, isPersp) - apexDist;
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_DYNOCC_DEPTH
return dynamicOcclusionDepthLinear / far;
#endif
float fadeDistance = depthProps.z;
float factor = smoothstep(0, fadeDistance, dynamicOcclusionDepthLinear - pixDistFromSource);
intensity *= lerp(factor, 1, isEqualOrGreater(dynamicOcclusionDepthRaw, 1)); // only apply factor if(dynamicOcclusionDepthRaw < 1), meaning there is an occlusion
}
#endif
#if DEBUG_SHOW_NOISE3D
return Noise3D_GetFactorFromUVW(i.uvwNoise_intensity.xyz);
#endif
float3 cameraPosObjectSpace = i.cameraPosObjectSpace_outsideBeam.xyz;
// Vector Camera to current Pixel, in object space and normalized
float3 vecCamToPixOSN = ComputeVectorCamToPixOSN(i.posObjectSpaceNonSkewed.xyz, cameraPosObjectSpace);
#if VLB_NOISE_3D || !OPTIM_VS
// Blend inside and outside
float vecCamToPixDotZ = dot(vecCamToPixOSN, float3(0, 0, 1));
float factorNearAxisZ = abs(vecCamToPixDotZ);
#endif
// 3D NOISE
#if VLB_NOISE_3D
{
float noise3DFactor = Noise3D_GetFactorFromUVW(i.uvwNoise_intensity.rgb);
// disable noise 3D when looking from behind or from inside because it makes the cone shape too much visible
noise3DFactor = lerp(noise3DFactor, 1, pow(factorNearAxisZ, 10));
intensity *= noise3DFactor;
}
#endif // VLB_NOISE_3D
float3 posViewSpace = i.posViewSpace_extraData.xyz;
// DEPTH BLEND
#if VLB_DEPTH_BLEND
{
float depthBlendDistance = VLB_GET_PROP(_DepthBlendDistance);
#if FIX_DISABLE_DEPTH_BLEND_WITH_OBLIQUE_PROJ
// disable depth sampling with oblique projection
float3 nearPlaneWS = VLBFrustumPlanes[4].xyz;
float3 farPlaneWS = VLBFrustumPlanes[5].xyz;
float dotNearFar = abs(dot(nearPlaneWS, farPlaneWS)); // abs needed on 5.2, but not needed on 2018
depthBlendDistance *= isEqualOrGreater(dotNearFar, 0.99);
#endif // FIX_DISABLE_DEPTH_BLEND_WITH_OBLIQUE_PROJ
// we disable blend factor when the pixel is near the light source,
// to prevent from blending with the light source model geometry (like the flashlight model).
float depthBlendStartDistFromSource = depthBlendDistance;
float pixDistFromSourceNormalized = invLerpClamped(0, depthBlendStartDistFromSource, pixDistFromSource);
float depthBlendDist = depthBlendDistance * pixDistFromSourceNormalized;
float depthBlendFactor = DepthFade_PS_BlendDistance(i.projPos, posViewSpace, depthBlendDist);
depthBlendFactor = lerp(depthBlendFactor, 1, isEqualOrGreater(0, depthBlendDistance));
depthBlendFactor = lerpClamped(1, depthBlendFactor, pixDistFromSourceNormalized * 100); // prevent artifacts when cap geometry is too close from some geometry
intensity *= depthBlendFactor;
{ // DEBUG
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHBUFFER_FROMEYE
return Depth_PS_GetSceneDepthFromEye(i.projPos, posViewSpace) * _ProjectionParams.w;
#elif DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHBUFFER_FROMNEARPLANE
return Depth_PS_GetSceneDepthFromNearPlane(i.projPos) * _ProjectionParams.w;
#elif DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHSTEREOEYE
float depthValue = Depth_PS_GetSceneDepthFromEye(i.projPos, posViewSpace) * _ProjectionParams.w;
#if defined(USING_STEREO_MATRICES) && defined(UNITY_STEREO_MULTIVIEW_ENABLED) // used with single pass / multiview on android VR (Oculus Go/Quest, Gear VR)
return depthValue * lerp(float4(1, 0, 0, 1), float4(0, 1, 0, 1), unity_StereoEyeIndex);
#elif defined(UNITY_SINGLE_PASS_STEREO)
return depthValue * lerp(float4(1, 0, 0, 1), float4(0, 0, 1, 1), unity_StereoEyeIndex);
#elif defined(UNITY_STEREO_INSTANCING_ENABLED)
return depthValue * lerp(float4(0, 1, 0, 1), float4(0, 0, 1, 1), unity_StereoEyeIndex);
#elif defined(UNITY_STEREO_MULTIVIEW_ENABLED)
return depthValue * lerp(float4(1, 1, 0, 1), float4(0, 1, 1, 1), unity_StereoEyeIndex);
#else
return depthValue;
#endif
#elif DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHBLEND
return depthBlendFactor;
#endif
} // DEBUG
}
#endif // VLB_DEPTH_BLEND
#if !OPTIM_VS
float pixDistFromSourceTilted = GetTiltDistanceFactor(i.posObjectSpace);
{
float isCap = i.posViewSpace_extraData.w;
// no intensity for cap if _DrawCap = 0
intensity *= isEqualOrGreater(VLB_GET_PROP(_DrawCap), isCap - 0.00001);
// Treat Cap a special way: cap is only visible from inside
intensity *= 1 - outsideBeam * isCap; // AKA if (outsideBeam == 1 && isCap == 1) intensity = 0
// boost factor
float boostFactor = ComputeBoostFactor(pixDistFromSource, outsideBeam, isCap);
// fresnel
intensity *= ComputeFresnel(i.posObjectSpaceNonSkewed, vecCamToPixOSN, outsideBeam, boostFactor);
// fade out
intensity *= VLB_GET_PROP(_FadeOutFactor);
// attenuation
float3 distancesFallOff = VLB_GET_PROP(_DistanceFallOff);
intensity *= ComputeAttenuationSD(pixDistFromSourceTilted, distancesFallOff.x, distancesFallOff.y, VLB_GET_PROP(_AttenuationLerpLinearQuad));
// smooth blend between inside and outside geometry depending of View Direction
intensity *= ComputeInOutBlending(vecCamToPixDotZ, outsideBeam);
}
#elif !OPTIM_VS_FRESNEL_VS // && OPTIM_VS
{
float boostFactor = i.posViewSpace_extraData.w;
// compute fresnel in fragment shader to keep good quality even with low tessellation
intensity *= ComputeFresnel(i.posObjectSpaceNonSkewed, vecCamToPixOSN, outsideBeam, boostFactor);
}
#endif // !OPTIM_VS_FRESNEL_VS && OPTIM_VS
// fade when too close to camera factor
{
float fadeWithCameraEnabled = 1 - VLB_CAMERA_ORTHO; // fading according to camera eye position doesn't make sense with ortho camera
intensity *= ComputeFadeWithCamera(posViewSpace, fadeWithCameraEnabled);
}
#if DEBUG_BLEND_INSIDE_OUTSIDE
float DBGvecCamToPixDotZ = dot(vecCamToPixOSN, float3(0, 0, 1));
return lerp(float4(1, 0, 0, 1), float4(0, 1, 0, 1), ComputeInOutBlending(DBGvecCamToPixDotZ, outsideBeam));
#endif // DEBUG_BLEND_INSIDE_OUTSIDE
// Do not fill color.rgb only, because of performance drops on android
#if !OPTIM_VS
float4 color = ComputeColor(pixDistFromSourceTilted, outsideBeam);
#else
float4 color = i.color;
#endif
#if VLB_DITHERING
float2 screenPos = i.projPos.xy / i.projPos.w;
float2 ditherCoord = screenPos * _ScreenParams.xy * _VLB_DitheringNoiseTex_TexelSize.xy;
float dither = tex2D(_VLB_DitheringNoiseTex, ditherCoord).r - 0.5;
color += (1 - saturate(intensity)) * _VLB_DitheringFactor * dither;
#endif
ApplyPipelineSpecificIntensityModifier(/* inout */ intensity);
intensity *= GetLODFadeFactor();
#if VLB_ALPHA_AS_BLACK
color *= intensity;
#else
color.a *= intensity;
#endif
#ifdef VLB_FOG_APPLY
VLB_FOG_APPLY(color);
#endif
color.a = clamp(color.a, 0, 1); // clamp alpha to avoid color artifacts on URP with HDR and high intensity
return color;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 025a6043ec7e0b449bb360c35c0bcb20
timeCreated: 1504539309
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
Shader "{VLB_GEN_SHADERNAME}"
{
Properties
{
_ConeRadius("Cone Radius", Vector) = (0,0,0,0)
_ConeGeomProps("Cone Geom Props", Vector) = (0,0,0,0)
_ColorFlat("Color", Color) = (1,1,1,1)
_HDRPExposureWeight("HDRP Exposure Weight", Range(0,1)) = 0
_DistanceFallOff("Distance Fall Off", Vector) = (0,1,1,0)
_NoiseVelocityAndScale("Noise Velocity And Scale", Vector) = (0,0,0,0)
_NoiseParam("Noise Param", Vector) = (0,0,0,0)
_BlendSrcFactor("BlendSrcFactor", Int) = 1 // One
_BlendDstFactor("BlendDstFactor", Int) = 1 // One
_ZTest("ZTest", Int) = 4 // LEqual
// SD
_ConeSlopeCosSin("Cone Slope Cos Sin", Vector) = (0,0,0,0)
_AlphaInside("Alpha Inside", Range(0,1)) = 1
_AlphaOutside("Alpha Outside", Range(0,1)) = 1
_DistanceCamClipping("Camera Clipping Distance", Float) = 0.5
_FadeOutFactor("FadeOutFactor", Float) = 1
_AttenuationLerpLinearQuad("Lerp between attenuation linear and quad", Float) = 0.5
_DepthBlendDistance("Depth Blend Distance", Float) = 2
_FresnelPow("Fresnel Pow", Range(0,15)) = 1
_GlareFrontal("Glare Frontal", Range(0,1)) = 0.5
_GlareBehind("Glare from Behind", Range(0,1)) = 0.5
_DrawCap("Draw Cap", Float) = 1
_CameraParams("Camera Params", Vector) = (0,0,0,0)
_DynamicOcclusionClippingPlaneWS("Dynamic Occlusion Clipping Plane WS", Vector) = (0,0,0,0)
_DynamicOcclusionClippingPlaneProps("Dynamic Occlusion Clipping Plane Props", Float) = 0.25
_DynamicOcclusionDepthTexture("DynamicOcclusionDepthTexture", 2D) = "white" {}
_DynamicOcclusionDepthProps("DynamicOcclusionDepthProps", Vector) = (1, 1, 0.25, 1)
_LocalForwardDirection("LocalForwardDirection", Vector) = (0,0,1)
_TiltVector("TiltVector", Vector) = (0,0,0,0)
_AdditionalClippingPlaneWS("AdditionalClippingPlaneWS", Vector) = (0,0,0,0)
// HD
_Intensity("Intensity", Range(0,8)) = 1
_SideSoftness("SideSoftness", Range(0,15)) = 1
_Jittering("Jittering", Vector) = (0,0,0,0)
_CameraForwardOS("Camera Forward OS", Vector) = (0,0,0)
_CameraForwardWS("Camera Forward WS", Vector) = (0,0,0)
_TransformScale("Transform Scale", Vector) = (0,0,0)
_CookieTexture("CookieTexture", 2D) = "white" {}
_CookieProperties("CookieProperties", Vector) = (0,0,0,0)
_CookiePosAndScale("CookiePosAndScale", Vector) = (0,0,1,1)
_ShadowDepthTexture("ShadowDepthTexture", 2D) = "white" {}
_ShadowProps("ShadowProps", Vector) = (1,1,1,1)
}
Category
{
Tags
{
"Queue" = "Transparent"
"RenderType" = "Transparent"
"IgnoreProjector" = "True"
"DisableBatching" = "True" // disable dynamic batching which doesn't work neither with multiple materials nor material property blocks
}
Blend[_BlendSrcFactor][_BlendDstFactor]
ZWrite Off
ZTest[_ZTest]
SubShader
{
{VLB_GEN_PASSES}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 08ac1efda1d05b44287ea2dd367f9d5e
timeCreated: 1592812249
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1 @@
#include "UnityCG.cginc"

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee8814b2cee7fd144a04d6a24551c48b
timeCreated: 1592841392
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,2 @@
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 30c63e832e947354e8a77d5e829fffeb
timeCreated: 1592841465
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 63a637fa650f3444d93ad1bcb6b45d28
timeCreated: 1592841460
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
Pass
{
Cull {VLB_GEN_CULLING}
{VLB_GEN_PROGRAM_PRE}
#if !defined(SHADER_API_METAL) // Removed shader model spec for Metal support https://github.com/keijiro/Cloner/commit/1120493ca2df265d450de3ec1b38a1d388468964
#pragma target 3.0
#endif
#pragma vertex vert
#pragma fragment frag
{VLB_GEN_PRAGMA_FOG}
{VLB_GEN_PRAGMA_INSTANCING}
{VLB_GEN_PRAGMA_MULTI_COMPILE_VARIANTS}
{VLB_GEN_PRE}
{VLB_GEN_RAYMARCHING_QUALITIES}
#include "ShaderDefines.cginc"
#include "ShaderProperties.cginc"
{VLB_GEN_SPECIFIC_INCLUDE}
v2f vert(vlb_appdata v) { return vertShared(v {VLB_GEN_INPUT_VS}); }
half4 frag(v2f i) : SV_Target { return fragShared(i {VLB_GEN_INPUT_FS}); }
{VLB_GEN_PROGRAM_POST}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b6eb5846ef7ddc640b6a24b36de75bda
timeCreated: 1592812249
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant: