Added Dohya

This commit is contained in:
2026-08-29 13:34:57 +03:00
parent f6a7547e84
commit 9f87122a34
1478 changed files with 963649 additions and 35753 deletions
@@ -0,0 +1,71 @@
// 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
/// ****************************************
/// ****************************************
/// DEBUG
/// ****************************************
#define DEBUG_VALUE_DEPTHBUFFER 1
#define DEBUG_VALUE_DEPTHBLEND 2
#define DEBUG_VALUE_DEPTHSTEREOEYE 3
//#define DEBUG_DEPTH_MODE DEBUG_VALUE_DEPTHBUFFER
//#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
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 49653fbebfba49948a7dd9821fc64690
timeCreated: 1578601843
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -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}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 41a72982cc42d7c47a12a3e40591b5f7
timeCreated: 1592827303
licenseType: Store
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
// 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 dot2(float2 v) { return dot(v,v); }
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); }
// 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);
}
#endif
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8e2291ef6ea68d34da2e1a28422a7fdc
timeCreated: 1504539309
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,80 @@
// 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(float2, _ConeSlopeCosSin) // between -1 and +1
VLB_DEFINE_PROP(float2, _ConeRadius) // x = start radius ; y = end radius
VLB_DEFINE_PROP(float, _ConeApexOffsetZ) // > 0
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(float, _DynamicOcclusionDepthProps)
// endif
// if VLB_DEPTH_BLEND
VLB_DEFINE_PROP(float, _DepthBlendDistance)
// endif
// if VLB_NOISE_3D
VLB_DEFINE_PROP(float4, _NoiseVelocityAndScale)
VLB_DEFINE_PROP(float2, _NoiseParam)
// endif
// if VLB_MESH_SKEWING
VLB_DEFINE_PROP(float3, _LocalForwardDirection)
// endif
VLB_DEFINE_PROP(float2, _TiltVector)
VLB_DEFINE_PROP(float4, _AdditionalClippingPlaneWS)
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_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
#if VLB_DITHERING
uniform float _VLB_DitheringFactor;
uniform sampler2D _VLB_DitheringNoiseTex;
uniform float4 _VLB_DitheringNoiseTex_TexelSize;
#endif
/// ****************************************
#endif
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 27b50b866731025428ef37b38a364a98
timeCreated: 1578601843
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -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
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4db26b55566f95a47adcaf8ca699bf3b
timeCreated: 1578601843
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -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_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
#endif // _VLB_SHADER_SPECIFIC_INCLUDED_
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0f65a880b7990834b8700ebf9f9a53fa
timeCreated: 1578601843
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -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_
/////////////////////////////////////////////////////
// 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)
#endif // _VLB_SHADER_SPECIFIC_INCLUDED_
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8895ab27688df164283e6aa7391ecabd
timeCreated: 1578601839
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
// 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
#endif // _VLB_SHADER_SPECIFIC_INCLUDED_
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5506b213335ebb24f91756ab209e7915
timeCreated: 1578601843
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,152 @@
// 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 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);
}
#if VLB_DEPTH_BLEND || VLB_DITHERING
inline float SampleSceneZ_Eye(float4 uv)
{
float rawDepth = VLBSampleDepthTexture(uv);
float linearDepthPersp = VLBLinearEyeDepth(rawDepth);
rawDepth = lerp(rawDepth, 1.0f - rawDepth, _VLB_UsesReversedZBuffer);
float linearDepthOrtho = (VLB_CAMERA_FAR_PLANE - VLB_CAMERA_NEAR_PLANE) * rawDepth + VLB_CAMERA_NEAR_PLANE;
return lerp(linearDepthPersp, linearDepthOrtho, VLB_CAMERA_ORTHO);
}
inline float4 DepthFade_VS_ComputeProjPos(float3 vertexViewSpace, float4 vertexClipSpace)
{
float4 projPos = ComputeScreenPos(vertexClipSpace);
projPos.z = -vertexViewSpace.z; // = COMPUTE_EYEDEPTH
return projPos;
}
inline float DepthFade_PS_BlendDistance(float4 projPos, float distance)
{
float sceneZ = max(0, SampleSceneZ_Eye(projPos) - 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 ComputeAttenuation(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);
}
#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 half4 UnpackToColor(float packedFloat)
{
half4 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 half4 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);
half4 colorA = UnpackToColor(GetAtMatrixIndex(colorMatrix, sampleIndexInt + 0));
half4 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);
half4 colorA = colorArray[sampleIndexInt + 0];
half4 colorB = colorArray[sampleIndexInt + 1];
return lerp(colorA, colorB, ratioPerSample);
}
#endif // VLB_COLOR_GRADIENT_*
#endif // _VLB_SHADER_UTILS_INCLUDED_
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 05361e63ec7797d4cac0db54e579335c
timeCreated: 1504539309
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,60 @@
%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: VLBDummyMaterial
m_Shader: {fileID: 4800000, guid: 4a4068e88a2c1cd4bbd3f74707431d5a, 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:
- _DynamicOcclusionDepthTexture:
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
- _ConeApexOffsetZ: 0
- _DepthBlendDistance: 2
- _DistanceCamClipping: 0.5
- _DrawCap: 1
- _DynamicOcclusionClippingPlaneProps: 0.25
- _DynamicOcclusionDepthProps: 0.25
- _FadeOutFactor: 1
- _FresnelPow: 1
- _GlareBehind: 0.5
- _GlareFrontal: 0.5
m_Colors:
- _AdditionalClippingPlaneWS: {r: 0, g: 0, b: 0, a: 0}
- _CameraParams: {r: 0, g: 0, b: 0, a: 0}
- _ColorFlat: {r: 1, g: 1, b: 1, a: 1}
- _ConeRadius: {r: 0, g: 0, b: 0, a: 0}
- _ConeSlopeCosSin: {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}
- _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}
- _TiltVector: {r: 0, g: 0, b: 0, a: 0}
m_BuildTextureStacks: []
m_AllowLocking: 1
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dd3045adcfbe9f443a2a928086c79010
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,102 @@
Shader "Hidden/VLB_URP_SinglePass"
{
Properties
{
_ConeSlopeCosSin("Cone Slope Cos Sin", Vector) = (0,0,0,0)
_ConeRadius("Cone Radius", Vector) = (0,0,0,0)
_ConeApexOffsetZ("Cone Apex Offset Z", Float) = 0
_ColorFlat("Color", Color) = (1,1,1,1)
_AlphaInside("Alpha Inside", Range(0,1)) = 1
_AlphaOutside("Alpha Outside", Range(0,1)) = 1
_DistanceFallOff("Distance Fall Off", Vector) = (0,1,1,0)
_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
_NoiseVelocityAndScale("Noise Velocity And Scale", Vector) = (0,0,0,0)
_NoiseParam("Noise Param", Vector) = (0,0,0,0)
_CameraParams("Camera Params", Vector) = (0,0,0,0)
_BlendSrcFactor("BlendSrcFactor", Int) = 1 // One
_BlendDstFactor("BlendDstFactor", Int) = 1 // One
_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", Float) = 0.25
_LocalForwardDirection("LocalForwardDirection", Vector) = (0,0,1)
_TiltVector("TiltVector", Vector) = (0,0,0,0)
_AdditionalClippingPlaneWS("AdditionalClippingPlaneWS", Vector) = (0,0,0,0)
}
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
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_DEPTH_BLEND
#pragma multi_compile_local __ VLB_COLOR_GRADIENT_MATRIX_HIGH
#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_PASS_OUTSIDEBEAM_FROM_VS_TO_FS 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"
#include "ShaderDefines.cginc"
#include "ShaderProperties.cginc"
#include "ShaderSpecificURP.cginc"
#include "VolumetricLightBeamShared.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
}
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4a4068e88a2c1cd4bbd3f74707431d5a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,556 @@
// 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(_ConeApexOffsetZ);
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);
}
half4 ComputeColor(float pixDistFromSource, float outsideBeam)
{
#if VLB_COLOR_GRADIENT_MATRIX_HIGH || VLB_COLOR_GRADIENT_MATRIX_LOW
float distanceFadeEnd = VLB_GET_PROP(_DistanceFallOff).y;
float4x4 colorGradientMatrix = VLB_GET_PROP(_ColorGradientMatrix);
float distFromSourceNormalized = invLerpClamped(0, distanceFadeEnd, pixDistFromSource);
half4 color = DecodeGradient(distFromSourceNormalized, colorGradientMatrix);
#else
half4 color = VLB_GET_PROP(_ColorFlat);
#endif
half alphaInside = VLB_GET_PROP(_AlphaInside);
half alphaOutside = VLB_GET_PROP(_AlphaOutside);
half alpha = lerp(alphaInside, alphaOutside, outsideBeam);
#if VLB_ALPHA_AS_BLACK
color.rgb *= color.a;
color.rgb *= alpha;
#else
color.a *= alpha;
#endif
return color;
}
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 = DepthFade_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 *= ComputeAttenuation(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
float apexDist = VLB_GET_PROP(_ConeApexOffsetZ);
float2 uv = normalize(i.posObjectSpace.xy) * 0.5 + 0.5;
float dynamicOcclusionDepthRaw = tex2D(_DynamicOcclusionDepthTexture, uv).r;
dynamicOcclusionDepthRaw = lerp(dynamicOcclusionDepthRaw, 1.0f - dynamicOcclusionDepthRaw, _VLB_UsesReversedZBuffer);
float fallOffEnd = VLB_GET_PROP(_DistanceFallOff).z; // maxGeometryDistance
float near = max(apexDist, kMinNearClipPlane);
float far = near + fallOffEnd;
float dynamicOcclusionDepthLinear = VLB_ZBufferToLinear(dynamicOcclusionDepthRaw, near, far);
dynamicOcclusionDepthLinear -= apexDist;
float fadeDistance = VLB_GET_PROP(_DynamicOcclusionDepthProps);
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
// 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, 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;
#if DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHBUFFER
return SampleSceneZ_Eye(i.projPos) * _ProjectionParams.w;
#elif DEBUG_DEPTH_MODE == DEBUG_VALUE_DEPTHSTEREOEYE
float depthValue = SampleSceneZ_Eye(i.projPos) * _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
}
#endif // VLB_DEPTH_BLEND
float3 posViewSpace = i.posViewSpace_extraData.xyz;
#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 *= ComputeAttenuation(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
half4 color = ComputeColor(pixDistFromSourceTilted, outsideBeam);
#else
half4 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
#if VLB_ALPHA_AS_BLACK
color *= intensity;
#else
color.a *= intensity;
#endif
#ifdef VLB_FOG_APPLY
VLB_FOG_APPLY(color);
#endif
return color;
}
#endif
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 025a6043ec7e0b449bb360c35c0bcb20
timeCreated: 1504539309
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
Shader "{VLB_GEN_SHADERNAME}"
{
Properties
{
_ConeSlopeCosSin("Cone Slope Cos Sin", Vector) = (0,0,0,0)
_ConeRadius("Cone Radius", Vector) = (0,0,0,0)
_ConeApexOffsetZ("Cone Apex Offset Z", Float) = 0
_ColorFlat("Color", Color) = (1,1,1,1)
_AlphaInside("Alpha Inside", Range(0,1)) = 1
_AlphaOutside("Alpha Outside", Range(0,1)) = 1
_DistanceFallOff("Distance Fall Off", Vector) = (0,1,1,0)
_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
_NoiseVelocityAndScale("Noise Velocity And Scale", Vector) = (0,0,0,0)
_NoiseParam("Noise Param", Vector) = (0,0,0,0)
_CameraParams("Camera Params", Vector) = (0,0,0,0)
_BlendSrcFactor("BlendSrcFactor", Int) = 1 // One
_BlendDstFactor("BlendDstFactor", Int) = 1 // One
_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", Float) = 0.25
_LocalForwardDirection("LocalForwardDirection", Vector) = (0,0,1)
_TiltVector("TiltVector", Vector) = (0,0,0,0)
_AdditionalClippingPlaneWS("AdditionalClippingPlaneWS", Vector) = (0,0,0,0)
}
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
SubShader
{
{VLB_GEN_PASSES}
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 08ac1efda1d05b44287ea2dd367f9d5e
timeCreated: 1592812249
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1 @@
#include "UnityCG.cginc"
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee8814b2cee7fd144a04d6a24551c48b
timeCreated: 1592841392
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -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"
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 30c63e832e947354e8a77d5e829fffeb
timeCreated: 1592841465
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -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"
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 63a637fa650f3444d93ad1bcb6b45d28
timeCreated: 1592841460
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
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}
#include "ShaderDefines.cginc"
#include "ShaderProperties.cginc"
#include "{VLB_GEN_SPECIFIC_INCLUDE}"
#include "VolumetricLightBeamShared.cginc"
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}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b6eb5846ef7ddc640b6a24b36de75bda
timeCreated: 1592812249
licenseType: Store
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant: