This commit is contained in:
2026-11-24 15:51:02 +01:00
parent cca4d73e41
commit f4aa17114a
22092 changed files with 5042406 additions and 0 deletions
@@ -0,0 +1,108 @@
fileFormatVersion: 2
guid: 20be25aac4e22ee49a7db76fb3df6de2
ModelImporter:
serializedVersion: 22200
internalIDToNameTable: []
externalObjects: {}
materials:
materialImportMode: 2
materialName: 0
materialSearch: 1
materialLocation: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleCurves: 1
optimizeGameObjects: 0
removeConstantScaleCurves: 0
motionNodeName:
rigImportErrors:
rigImportWarnings:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
importAnimatedCustomProperties: 0
importConstraints: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
extraUserProperties: []
clipAnimations: []
isReadable: 0
meshes:
lODScreenPercentages: []
globalScale: 1
meshCompression: 0
addColliders: 0
useSRGBMaterialColor: 1
sortHierarchyByName: 1
importVisibility: 1
importBlendShapes: 1
importCameras: 1
importLights: 1
nodeNameCollisionStrategy: 1
fileIdsGeneration: 2
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
keepQuads: 0
weldVertices: 1
bakeAxisConversion: 0
preserveHierarchy: 0
skinWeightsMode: 0
maxBonesPerVertex: 4
minBoneWeight: 0.001
optimizeBones: 1
meshOptimizationFlags: -1
indexFormat: 0
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVMarginMethod: 1
secondaryUVMinLightmapResolution: 40
secondaryUVMinObjectScale: 1
secondaryUVPackMargin: 4
useFileScale: 1
strictVertexDataChecks: 0
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
tangentImportMode: 3
normalCalculationMode: 4
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
blendShapeNormalImportMode: 1
normalSmoothingSource: 0
referencedClips: []
importAnimation: 1
humanDescription:
serializedVersion: 3
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
globalScale: 1
rootMotionBoneName:
hasTranslationDoF: 0
hasExtraRoot: 0
skeletonHasParents: 1
lastHumanDescriptionAvatarSource: {instanceID: 0}
autoGenerateAvatarMappingIfUnspecified: 1
animationType: 2
humanoidOversampling: 1
avatarSetup: 0
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
importBlendShapeDeformPercent: 1
remapMaterialsIfMaterialImportModeIsNone: 0
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,37 @@
Shader "Hidden/Core/ProbeVolumeDebug"
{
SubShader
{
Tags{ "RenderType" = "Opaque" }
LOD 100
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch switch2
#pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
// Central render pipeline specific includes
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugBase.hlsl"
#define PROBE_VOLUME_DEBUG_FUNCTION_MAIN
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugFunctions.hlsl"
ENDHLSL
Pass
{
Name "ForwardOnly"
ZTest LEqual
ZWrite On
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
ENDHLSL
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 3b21275fd12d65f49babb5286f040f2d
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,413 @@
#ifndef PROBEVOLUMEDEBUG_BASE_HLSL
#define PROBEVOLUMEDEBUG_BASE_HLSL
// TEMPORARY WORKAROUND
// Unfortunately we don't have a cross pipeline way to pass per frame constant.
// One of the reason is that we don't want to force a certain Constant Buffer layout on users (read: SRP writer) for shared data.
// This means that usually SRP Core functions (see SpaceTransforms.hlsl for example) use common names that are NOT declared in the Core package but rather in each pipelines.
// The consequence is that when writing core shaders that need those variables, we currently have to copy their declaration and set them manually from core C# code to the relevant shaders.
// Here is current the subset of variables and functions required by APV debug.
// Copying them here means that these shaders don't support either XR or Camera Relative rendering (at least until those concept become fully cross pipeline)
CBUFFER_START(ShaderVariablesProbeVolumeDebug)
float4x4 unity_MatrixVP; // Sent by builtin
float4x4 unity_MatrixInvV; // Sent by builtin
float4x4 unity_ObjectToWorld; // Sent by builtin
float4x4 unity_MatrixV; // Sent by builtin
float4 _ScreenSize;
float3 _WorldSpaceCameraPos; // Sent by builtin
CBUFFER_END
TEXTURE2D(_ExposureTexture);
#define UNITY_MATRIX_VP unity_MatrixVP
#define UNITY_MATRIX_V unity_MatrixV
#define UNITY_MATRIX_I_V unity_MatrixInvV
#define UNITY_MATRIX_M unity_ObjectToWorld
float3 GetCurrentViewPosition()
{
return UNITY_MATRIX_I_V._14_24_34;
}
float GetCurrentExposureMultiplier()
{
return LOAD_TEXTURE2D(_ExposureTexture, int2(0, 0)).x;
}
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureXR.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/DecodeSH.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolume.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Debug.cs.hlsl"
uniform int _ShadingMode;
uniform float _ExposureCompensation;
uniform float _ProbeSize;
uniform float4 _Color;
uniform int _SubdivLevel;
uniform float _CullDistance;
uniform int _MaxAllowedSubdiv;
uniform int _MinAllowedSubdiv;
uniform float _ValidityThreshold;
uniform uint _RenderingLayerMask;
uniform float _OffsetSize;
// Sampling Position Debug
uniform bool _DebugProbeVolumeSampling = false;
StructuredBuffer<float4> _positionNormalBuffer;
uniform float4 _DebugArrowColor; // arrow color for position and normal debug
uniform float4 _DebugLocator01Color; // locator color for final sampling position debug
uniform float4 _DebugLocator02Color; // locator color for normal and view bias sampling position debug
uniform float4 _DebugEmptyProbeData; // probe color for missing data
uniform bool _ForceDebugNormalViewBias; // additional locator to debug Normal Bias and View Bias without AntiLeak Reduction Mode
uniform bool _DebugSamplingNoise = false;
uniform sampler2D _NumbersTex;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float, _Validity)
UNITY_DEFINE_INSTANCED_PROP(float, _RenderingLayer)
UNITY_DEFINE_INSTANCED_PROP(float, _DilationThreshold)
UNITY_DEFINE_INSTANCED_PROP(float, _TouchupedByVolume)
UNITY_DEFINE_INSTANCED_PROP(float4, _IndexInAtlas)
UNITY_DEFINE_INSTANCED_PROP(float4, _Offset)
UNITY_DEFINE_INSTANCED_PROP(float, _RelativeSize)
UNITY_INSTANCING_BUFFER_END(Props)
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 color : COLOR0;
float2 texCoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 normal : TEXCOORD1;
float4 color : COLOR0;
float2 texCoord : TEXCOORD0;
float2 samplingFactor_ValidityWeight : TEXCOORD2; // stores sampling factor (for Probe Sampling Debug view) and validity weight
float2 centerCoordSS : TEXCOORD3;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void DoCull(inout v2f o)
{
ZERO_INITIALIZE(v2f, o);
o.samplingFactor_ValidityWeight = float2(0.0f, 1.0f);
}
// snappedProbePosition_WS : worldspace position of main probe (a corner of the 8 probes cube)
// samplingPosition_WS : worldspace sampling position after applying 'NormalBias' and 'ViewBias' and 'ValidityAndNormalBased Leak Reduction'
// normalizedOffset : normalized offset between sampling position and snappedProbePosition
void FindSamplingData(float3 posWS, float3 normalWS, uint renderingLayer, out float3 snappedProbePosition_WS, out float3 samplingPositionNoAntiLeak_WS, out float probeDistance, out float3 normalizedOffset, out float validityWeights[8])
{
float3 cameraPosition_WS = _WorldSpaceCameraPos;
float3 viewDir_WS = normalize(cameraPosition_WS - posWS);
if (_DebugSamplingNoise)
{
float2 posNDC = ComputeNormalizedDeviceCoordinates(posWS, UNITY_MATRIX_VP);
float2 posSS = floor(posNDC.xy * _ScreenSize.xy);
posWS = AddNoiseToSamplingPosition(posWS, posSS, viewDir_WS);
}
posWS -= _APVWorldOffset;
// uvw
APVResources apvRes = FillAPVResources();
float3 uvw;
uint subdiv;
float3 biasedPosWS;
bool valid = TryToGetPoolUVWAndSubdiv(apvRes, posWS, normalWS, viewDir_WS, uvw, subdiv, biasedPosWS);
// Validity mask
float3 texCoord = uvw * _APVPoolDim - .5f;
float3 texFrac = frac(texCoord);
uint validityMask = LoadValidityMask(apvRes, renderingLayer, texCoord);
for (uint i = 0; i < 8; i++)
{
int3 probeCoord = GetSampleOffset(i);
float validityWeight = ((probeCoord.x == 1) ? texFrac.x : 1.0f - texFrac.x) *
((probeCoord.y == 1) ? texFrac.y : 1.0f - texFrac.y) *
((probeCoord.z == 1) ? texFrac.z : 1.0f - texFrac.z);
validityWeights[i] = validityWeight * GetValidityWeight(i, validityMask);
}
// Sample position
normalizedOffset = texFrac;
if (_APVLeakReductionMode == APVLEAKREDUCTIONMODE_PERFORMANCE)
{
float3 warped = uvw;
WarpUVWLeakReduction(apvRes, renderingLayer, warped);
normalizedOffset += (warped - uvw) * _APVPoolDim;
}
// stuff
probeDistance = ProbeDistance(subdiv);
snappedProbePosition_WS = GetSnappedProbePosition(biasedPosWS, subdiv) + _APVWorldOffset;
samplingPositionNoAntiLeak_WS = biasedPosWS + _APVWorldOffset;
}
// Return probe sampling weight
float ComputeSamplingFactor(float3 probePosition_WS, float3 snappedProbePosition_WS, float3 normalizedOffset, float probeDistance)
{
float samplingFactor = -1.0f;
if (distance(snappedProbePosition_WS, probePosition_WS) < 0.0001f)
{
samplingFactor = (1.0f-normalizedOffset.x) * (1.0f-normalizedOffset.y) * (1.0f-normalizedOffset.z);
}
else if (distance(snappedProbePosition_WS, probePosition_WS + float3(-1.0f, 0.0f, 0.0f)*probeDistance) < 0.0001f)
{
samplingFactor = (normalizedOffset.x) * (1.0f-normalizedOffset.y) * (1.0f-normalizedOffset.z);
}
else if (distance(snappedProbePosition_WS, probePosition_WS + float3(-1.0f, -1.0f, 0.0f)*probeDistance) < 0.0001f)
{
samplingFactor = (normalizedOffset.x) * (normalizedOffset.y) * (1.0f-normalizedOffset.z);
}
else if (distance(snappedProbePosition_WS, probePosition_WS + float3(0.0f, -1.0f, 0.0f)*probeDistance) < 0.0001f)
{
samplingFactor = (1.0f-normalizedOffset.x) * (normalizedOffset.y) * (1.0f-normalizedOffset.z);
}
else if (distance(snappedProbePosition_WS, probePosition_WS + float3(-1.0f, 0.0f, -1.0f)*probeDistance) < 0.0001f)
{
samplingFactor = (normalizedOffset.x) * (1.0f-normalizedOffset.y) * (normalizedOffset.z);
}
else if (distance(snappedProbePosition_WS, probePosition_WS + float3(0.0f, 0.0f, -1.0f)*probeDistance) < 0.0001f)
{
samplingFactor = (1.0f-normalizedOffset.x) * (1.0f-normalizedOffset.y) * (normalizedOffset.z);
}
else if (distance(snappedProbePosition_WS, probePosition_WS + float3(-1.0f, -1.0f, -1.0f)*probeDistance) < 0.0001f)
{
samplingFactor = (normalizedOffset.x) * (normalizedOffset.y) * (normalizedOffset.z);
}
else if (distance(snappedProbePosition_WS, probePosition_WS + float3(0.0f, -1.0f, -1.0f)*probeDistance) < 0.0001f)
{
samplingFactor = (1.0f-normalizedOffset.x) * (normalizedOffset.y) * (normalizedOffset.z);
}
return samplingFactor;
}
// Sample a texture with numbers at the right place depending on a number input
half4 SampleCharacter(int input, float2 texCoord) // Samples _NumbersTex to get given character
{
// texture is divided in 16 parts and contains following characters : '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.' (+ empty space)
float2 uv = float2((texCoord.x + input) / 16.0f, texCoord.y);
half4 color = tex2D(_NumbersTex, uv);
return color;
}
// Writes a floating number with two decimals using a texture with numbers.
// Use to debug probe sampling weights with text
half4 WriteFractNumber(float input, float2 texCoord)
{
// using 4 characters
float i = 4.0f;
// 0.00X
int n3_value = floor(frac(input * 100.0f) * 10.0f);
int n2_add = 0;
if (n3_value >= 5) {n2_add = 1;}
// 0.0X
int n2_value = floor(frac(input * 10.0f) * 10.0f);
n2_value += n2_add;
int n1_add = 0;
if (n2_value >= 10) {n2_value -= 10; n1_add = 1;}
// 0.X
int n1_value = floor(frac(input) * 10.0f);
n1_value += n1_add;
int n0_add = 0;
if (n1_value >= 10) {n1_value -= 10; n0_add = 1;}
// X
int n0_value = floor(input);
n0_value += n0_add;
float2 n0_uv = float2(clamp(texCoord.x*i - 0.0f, 0.0f, 1.0f), texCoord.y);
float2 dot_uv = float2(clamp(texCoord.x*i - 1.0f, 0.0f, 1.0f), texCoord.y);
float2 n1_uv = float2(clamp(texCoord.x*i - 2.0f, 0.0f, 1.0f), texCoord.y);
float2 n2_uv = float2(clamp(texCoord.x*i - 3.0f, 0.0f, 1.0f), texCoord.y);
half4 outVal = 0;
if (texCoord.x <= 0.25)
outVal = SampleCharacter(n0_value, n0_uv);
else if (texCoord.x <= 0.50)
outVal = SampleCharacter(10, dot_uv);
else if (texCoord.x <= 0.75)
outVal = SampleCharacter(n1_value, n1_uv);
else
outVal = SampleCharacter(n2_value, n2_uv);
return outVal;
}
// Finer culling, degenerate the vertices of the debug element if it lies over the max distance.
// Coarser culling has already happened on CPU.
bool ShouldCull(inout v2f o)
{
float4 position = float4(UNITY_MATRIX_M._m03_m13_m23, 1);
int brickSize = UNITY_ACCESS_INSTANCED_PROP(Props, _IndexInAtlas).w;
bool shouldCull = false;
if (distance(position.xyz + _APVWorldOffset, GetCurrentViewPosition()) > _CullDistance || brickSize > _MaxAllowedSubdiv || brickSize < _MinAllowedSubdiv)
{
ZERO_INITIALIZE(v2f, o);
DoCull(o);
shouldCull = true;
}
return shouldCull;
}
float3 EvalL1(float3 L0, float3 L1_R, float3 L1_G, float3 L1_B, float3 N)
{
float3 outLighting = 0;
L1_R = DecodeSH(L0.r, L1_R);
L1_G = DecodeSH(L0.g, L1_G);
L1_B = DecodeSH(L0.b, L1_B);
outLighting += SHEvalLinearL1(N, L1_R, L1_G, L1_B);
return outLighting;
}
float3 EvalL2(inout float3 L0, float4 L2_R, float4 L2_G, float4 L2_B, float4 L2_C, float3 N)
{
DecodeSH_L2(L0, L2_R, L2_G, L2_B, L2_C);
return SHEvalLinearL2(N, L2_R, L2_G, L2_B, L2_C);
}
float3 CalculateDiffuseLighting(v2f i)
{
APVResources apvRes = FillAPVResources();
int3 texLoc = UNITY_ACCESS_INSTANCED_PROP(Props, _IndexInAtlas).xyz;
float3 normal = normalize(i.normal);
float3 skyShadingDirection = normal;
if (_ShadingMode == DEBUGPROBESHADINGMODE_PROBE_OCCLUSION)
{
float4 shadowmask = apvRes.ProbeOcclusion[texLoc];
return shadowmask.rgb * 0.5 + (shadowmask.aaa * 0.5);
}
else if (_ShadingMode == DEBUGPROBESHADINGMODE_SKY_DIRECTION)
{
if (_APVSkyDirectionWeight > 0)
{
float value = 1.0f / GetCurrentExposureMultiplier();
uint index = apvRes.SkyShadingDirectionIndices[texLoc].r * 255;
if (index != 255)
skyShadingDirection = apvRes.SkyPrecomputedDirections[index].rgb;
else
return float3(value, 0.0f, 0.0f);
if (dot(normal, skyShadingDirection) > 0.95)
return float3(0.0f, value, 0.0f);
return float3(0.0f, 0.0f, 0.0f);
}
else
{
return _DebugEmptyProbeData.xyz / GetCurrentExposureMultiplier();
}
}
else
{
float3 skyOcclusion = _DebugEmptyProbeData.xyz;
if (_APVSkyOcclusionWeight > 0)
{
// L0 L1
float4 temp = float4(kSHBasis0, kSHBasis1 * normal.x, kSHBasis1 * normal.y, kSHBasis1 * normal.z);
skyOcclusion = dot(temp, apvRes.SkyOcclusionL0L1[texLoc].rgba);
}
if (_ShadingMode == DEBUGPROBESHADINGMODE_SKY_OCCLUSION_SH)
{
return skyOcclusion / GetCurrentExposureMultiplier();
}
else
{
float4 L0_L1Rx = apvRes.L0_L1Rx[texLoc].rgba;
float3 L0 = L0_L1Rx.xyz;
if (_ShadingMode == DEBUGPROBESHADINGMODE_SHL0)
return L0;
float L1Rx = L0_L1Rx.w;
float4 L1G_L1Ry = apvRes.L1G_L1Ry[texLoc].rgba;
float4 L1B_L1Rz = apvRes.L1B_L1Rz[texLoc].rgba;
float3 bakeDiffuseLighting = EvalL1(L0, float3(L1Rx, L1G_L1Ry.w, L1B_L1Rz.w), L1G_L1Ry.xyz, L1B_L1Rz.xyz, normal);
bakeDiffuseLighting += L0;
if (_ShadingMode == DEBUGPROBESHADINGMODE_SHL0L1)
return bakeDiffuseLighting;
#ifdef PROBE_VOLUMES_L2
float4 L2_R = apvRes.L2_0[texLoc].rgba;
float4 L2_G = apvRes.L2_1[texLoc].rgba;
float4 L2_B = apvRes.L2_2[texLoc].rgba;
float4 L2_C = apvRes.L2_3[texLoc].rgba;
bakeDiffuseLighting += EvalL2(L0, L2_R, L2_G, L2_B, L2_C, normal);
#endif
if (_APVSkyOcclusionWeight > 0)
bakeDiffuseLighting += skyOcclusion * EvaluateAmbientProbe(skyShadingDirection);
return bakeDiffuseLighting;
}
}
}
CBUFFER_START(TouchupVolumeBounds)
float4 _TouchupVolumeBounds[16 * 3]; // A BBox is 3 float4
uint _AdjustmentVolumeCount;
CBUFFER_END
bool IsInSelection(float3 position)
{
for (uint i = 0; i < _AdjustmentVolumeCount; i++)
{
float3 center = _TouchupVolumeBounds[i * 3 + 0].xyz;
bool isSphere = _TouchupVolumeBounds[i * 3 + 0].w >= FLT_MAX;
if (isSphere)
{
float radius = _TouchupVolumeBounds[i * 3 + 1].x;
if (dot(position - center, position - center) < radius * radius)
return true;
}
else
{
float3 X = _TouchupVolumeBounds[i * 3 + 1].xyz;
float3 Y = _TouchupVolumeBounds[i * 3 + 2].xyz;
float3 Z = float3(_TouchupVolumeBounds[i * 3 + 0].w,
_TouchupVolumeBounds[i * 3 + 1].w,
_TouchupVolumeBounds[i * 3 + 2].w);
if (abs(dot(position - center, normalize(X))) < length(X) &&
abs(dot(position - center, normalize(Y))) < length(Y) &&
abs(dot(position - center, normalize(Z))) < length(Z))
return true;
}
}
return false;
}
#endif //PROBEVOLUMEDEBUG_BASE_HLSL
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0c0fc89bf58dc6d4590d0db55a62679e
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,418 @@
#ifndef PROBEVOLUMEDEBUG_FUNCTIONS_HLSL
#define PROBEVOLUMEDEBUG_FUNCTIONS_HLSL
float4 TransformPosition(float3 posOS)
{
return mul(UNITY_MATRIX_M, float4(posOS, 1.0f)) + float4(_APVWorldOffset, 0.0f);
}
#ifdef PROBE_VOLUME_DEBUG_FUNCTION_MAIN
v2f vert(appdata v)
{
v2f o;
ZERO_INITIALIZE(v2f, o);
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
if (!ShouldCull(o))
{
float3 probePosition_WS = TransformPosition(0.0f).xyz;
if (_AdjustmentVolumeCount > 0 && !IsInSelection(probePosition_WS))
{
DoCull(o);
}
else if (_DebugProbeVolumeSampling) // Only sampled probes (8 of them) should be shown, the other should be culled
{
float4 debugPosition = _positionNormalBuffer[0];
float4 debugNormal = _positionNormalBuffer[1];
float3 snappedProbePosition_WS; // worldspace position of main probe (a corner of the 8 probes cube)
float3 samplingPositionNoAntiLeak_WS; // // worldspace sampling position after applying 'NormalBias', 'ViewBias'
float probeDistance;
float3 normalizedOffset; // normalized offset between sampling position and snappedProbePosition
float validityWeight[8];
FindSamplingData(debugPosition.xyz, debugNormal.xyz, _RenderingLayerMask, snappedProbePosition_WS, samplingPositionNoAntiLeak_WS, probeDistance, normalizedOffset, validityWeight);
float samplingFactor = ComputeSamplingFactor(probePosition_WS, snappedProbePosition_WS, normalizedOffset, probeDistance);
// Let's cull probes that are not sampled
if (samplingFactor == -1.0f)
{
DoCull(o);
return o;
}
float4 wsPos = float4(probePosition_WS, 1.0);
wsPos += normalize(mul(UNITY_MATRIX_M, float4(v.vertex.xyz, 0.0f))) * _ProbeSize * 0.3f; // avoid scale from transformation matrix to be effective (otherwise some probes are bigger than others)
float4 pos = mul(UNITY_MATRIX_VP, wsPos);
float remappedDepth = Remap(-1.0f, 1.0f, 0.6f, 1.0f, pos.z); // remapped depth to draw gizmo on top of most other objects
o.vertex = float4(pos.x, pos.y, remappedDepth * pos.w, pos.w);
o.normal = normalize(mul(v.normal, (float3x3)UNITY_MATRIX_M));
o.color = v.color;
o.texCoord = v.texCoord;
o.samplingFactor_ValidityWeight = float2(samplingFactor, 1.0f);
}
else
{
float4 wsPos = TransformPosition(v.vertex.xyz * _ProbeSize);
o.vertex = mul(UNITY_MATRIX_VP, wsPos);
o.normal = normalize(mul(v.normal, (float3x3)UNITY_MATRIX_M));
if (_ShadingMode == DEBUGPROBESHADINGMODE_RENDERING_LAYER_MASKS)
{
o.centerCoordSS = _ScreenSize.xy * ComputeNormalizedDeviceCoordinatesWithZ(probePosition_WS, UNITY_MATRIX_VP).xy;
if (_APVLayerCount != 1 & (asuint(UNITY_ACCESS_INSTANCED_PROP(Props, _RenderingLayer)) & _RenderingLayerMask) == 0)
DoCull(o);
}
}
}
return o;
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
if (_ShadingMode >= DEBUGPROBESHADINGMODE_SH && _ShadingMode <= DEBUGPROBESHADINGMODE_SHL0L1
|| _ShadingMode == DEBUGPROBESHADINGMODE_SKY_OCCLUSION_SH || _ShadingMode == DEBUGPROBESHADINGMODE_SKY_DIRECTION || _ShadingMode == DEBUGPROBESHADINGMODE_PROBE_OCCLUSION)
{
return float4(CalculateDiffuseLighting(i) * exp2(_ExposureCompensation) * GetCurrentExposureMultiplier(), 1);
}
else if (_ShadingMode == DEBUGPROBESHADINGMODE_INVALIDATED_BY_ADJUSTMENT_VOLUMES)
{
float4 defaultCol = float4(CalculateDiffuseLighting(i) * exp2(_ExposureCompensation) * GetCurrentExposureMultiplier(), 1);
float touchupAction = UNITY_ACCESS_INSTANCED_PROP(Props, _TouchupedByVolume);
if (touchupAction > 0 && touchupAction < 1)
{
return float4(1, 0, 0, 1);
}
return defaultCol;
}
else if (_ShadingMode == DEBUGPROBESHADINGMODE_VALIDITY)
{
float validity = UNITY_ACCESS_INSTANCED_PROP(Props, _Validity);
float threshold = PROBE_VALIDITY_THRESHOLD;
return lerp(float4(0, 1, 0, 1), float4(1, 0, 0, 1), validity > threshold);
}
else if (_ShadingMode == DEBUGPROBESHADINGMODE_VALIDITY_OVER_DILATION_THRESHOLD)
{
float validity = UNITY_ACCESS_INSTANCED_PROP(Props, _Validity);
float threshold = UNITY_ACCESS_INSTANCED_PROP(Props, _DilationThreshold);
if (validity > threshold)
{
return float4(1, 0, 0, 1);
}
else
{
return float4(0, 1, 0, 1);
}
}
else if (_ShadingMode == DEBUGPROBESHADINGMODE_RENDERING_LAYER_MASKS)
{
float3 colors[4] = {
float3(230, 159, 0) / 255.0f,
float3(0, 158, 115) / 255.0f,
float3(0, 114, 178) / 255.0f,
float3(204, 121, 167) / 255.0f,
};
if (_APVLayerCount == 1) return _DebugEmptyProbeData; // Rendering layers are not baked
uint renderingLayer = asuint(UNITY_ACCESS_INSTANCED_PROP(Props, _RenderingLayer)) & _RenderingLayerMask;
uint stripeSize = 8;
float3 result = float3(0, 0, 0);
int2 positionSS = i.vertex.xy;
uint layerId = 0, layerCount = countbits(renderingLayer);
int colorIndex = 0;
if (layerCount >= 2 && positionSS.y < i.centerCoordSS.y)
colorIndex = 1;
if (layerCount >= 3 && colorIndex == 1 && positionSS.x < i.centerCoordSS.x)
colorIndex = 2;
if (layerCount >= 4 && colorIndex == 0 && positionSS.x < i.centerCoordSS.x)
colorIndex = 3;
for (uint l = 0; (l < _APVLayerCount) && (layerId < layerCount); l++)
{
[branch]
if (renderingLayer & (1U << l))
{
if (colorIndex == 0)
result = colors[l];
colorIndex--;
}
}
// NdotV to make the debug view easier to understand
float3 N = normalize(i.normal);
float3 V = UNITY_MATRIX_V[2].xyz;
return float4(result * max(0, dot(N, V)), 1);
}
else if (_ShadingMode == DEBUGPROBESHADINGMODE_SIZE)
{
float4 col = lerp(float4(0, 1, 0, 1), float4(1, 0, 0, 1), UNITY_ACCESS_INSTANCED_PROP(Props, _RelativeSize));
return col;
}
return _Color;
}
#endif
#ifdef PROBE_VOLUME_DEBUG_FUNCTION_FRAGMENTATION
int _ChunkCount;
StructuredBuffer<int> _DebugFragmentation;
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
return output;
}
float4 Frag(Varyings input) : SV_Target
{
int lineSize = (int)ceil(sqrt(_ChunkCount));
int2 coord = (int2)(input.texcoord * lineSize);
int index = coord.y * lineSize + coord.x;
float4 color = 0.0;
if (index < _ChunkCount && _DebugFragmentation[index] != -1)
color = float4(0.0, 1.0, 0.0, 1.0);
return color;
}
#endif
#ifdef PROBE_VOLUME_DEBUG_FUNCTION_OFFSET
v2f vert(appdata v)
{
v2f o;
ZERO_INITIALIZE(v2f, o);
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
o.vertex = 0;
o.normal = 0;
float3 probePosition_WS = TransformPosition(0.0f).xyz;
float3 offset = UNITY_ACCESS_INSTANCED_PROP(Props, _Offset).xyz;
float offsetLenSqr = dot(offset, offset);
if (offsetLenSqr <= 1e-6f)
{
DoCull(o);
}
else if (_AdjustmentVolumeCount > 0 && !IsInSelection(probePosition_WS))
{
DoCull(o);
}
else if (!ShouldCull(o))
{
float4 wsPos = TransformPosition(v.vertex.xyz * float3(_OffsetSize, _OffsetSize, 1.0f));
o.vertex = mul(UNITY_MATRIX_VP, wsPos);
o.normal = normalize(mul(v.normal, (float3x3)UNITY_MATRIX_M));
}
return o;
}
float4 frag(v2f i) : SV_Target
{
return float4(0, 0, 1, 1);
}
#endif
#ifdef PROBE_VOLUME_DEBUG_FUNCTION_SAMPLING
v2f vert(appdata v)
{
v2f o;
ZERO_INITIALIZE(v2f, o);
float4 debugPosition = _positionNormalBuffer[0];
float4 debugNormal = _positionNormalBuffer[1];
float4 wsPos = float4(0.0f, 0.0f, 0.0f, 1.0f);
float samplingFactor = 0.0f; // probe sampling weight (when needed) is compute in vertex shader. Usefull for drawing 8 debug quads showing weights
float3 snappedProbePosition_WS; // worldspace position of main probe (a corner of the 8 probes cube)
float3 samplingPositionNoAntiLeak_WS; // worldspace sampling position after applying 'NormalBias', 'ViewBias'
float probeDistance;
float3 normalizedOffset; // normalized offset between sampling position and snappedProbePosition
float validityWeights[8];
float validityWeight = 1.0f;
FindSamplingData(debugPosition.xyz, debugNormal.xyz, _RenderingLayerMask, snappedProbePosition_WS, samplingPositionNoAntiLeak_WS, probeDistance, normalizedOffset, validityWeights);
// QUADS to write the sampling factor of each probe
// each QUAD has an individual ID in vertex color blue channel
if (v.color.z)
{
// QUAD 01
float3 quadPosition = snappedProbePosition_WS;
validityWeight = validityWeights[0];
// QUAD 02
if (abs(v.color.z - 0.2f) < 0.02f)
{
quadPosition = snappedProbePosition_WS + float3(0.0f, 1.0f, 0.0f) * probeDistance;
validityWeight = validityWeights[2];
}
// QUAD 03
if (abs(v.color.z - 0.3f) < 0.02f)
{
quadPosition = snappedProbePosition_WS + float3(1.0f, 1.0f, 0.0f) * probeDistance;
validityWeight = validityWeights[3];
}
// QUAD 04
if (abs(v.color.z - 0.4f) < 0.02f)
{
quadPosition = snappedProbePosition_WS + float3(1.0f, 0.0f, 0.0f) * probeDistance;
validityWeight = validityWeights[1];
}
// QUAD 05
if (abs(v.color.z - 0.5f) < 0.02f)
{
quadPosition = snappedProbePosition_WS + float3(0.0f, 0.0f, 1.0f) * probeDistance;
validityWeight = validityWeights[4];
}
// QUAD 06
if (abs(v.color.z - 0.6f) < 0.02f)
{
quadPosition = snappedProbePosition_WS + float3(0.0f, 1.0f, 1.0f) * probeDistance;
validityWeight = validityWeights[6];
}
// QUAD 07
if (abs(v.color.z - 0.7f) < 0.02f)
{
quadPosition = snappedProbePosition_WS + float3(1.0f, 1.0f, 1.0f) * probeDistance;
validityWeight = validityWeights[7];
}
// QUAD 08
if (abs(v.color.z - 0.8f) < 0.02f)
{
quadPosition = snappedProbePosition_WS + float3(1.0f, 0.0f, 1.0f) * probeDistance;
validityWeight = validityWeights[5];
}
if (_APVLeakReductionMode == APVLEAKREDUCTIONMODE_QUALITY)
samplingFactor = validityWeight; // this is not 100% accurate in some cases (cause we do max 3 samples)
else
samplingFactor = ComputeSamplingFactor(quadPosition, snappedProbePosition_WS, normalizedOffset, probeDistance);
float4 cameraUp = mul(UNITY_MATRIX_I_V, float4(0.0f, 1.0f, 0.0f, 0.0f));
float4 cameraRight = -mul(UNITY_MATRIX_I_V, float4(1.0f, 0.0f, 0.0f, 0.0f));
wsPos = mul(UNITY_MATRIX_M, float4(0.0f, 0.0f, 0.0f, 1.0f));
wsPos += float4(quadPosition + cameraUp.xyz * _ProbeSize / 1.5f, 0.0f);
wsPos += float4((v.vertex.x * cameraRight.xyz + v.vertex.y * cameraUp.xyz * 0.5f) * 20.0f * _ProbeSize, 0.0f);
}
// ARROW to show the position and normal of the debugged fragment
else if (v.color.y)
{
float3 forward = normalize(debugNormal.xyz);
float3 up = float3(0.0f, 1.0f, 0.0f); if (dot(up, forward) > 0.9f) { up = float3(1.0f, 0.0f, 0.0f); }
float3 right = normalize(cross(forward, up));
up = cross(right, forward);
float3x3 orientation = float3x3(
right.x, up.x, forward.x,
right.y, up.y, forward.y,
right.z, up.z, forward.z);
wsPos = float4(mul(orientation, (v.vertex.xyz * _ProbeSize * 5.0f)), 1.0f);
wsPos = mul(UNITY_MATRIX_M, wsPos);
wsPos.xyz += debugPosition.xyz;
}
// LOCATOR to debug sampling position
else
{
if (v.color.x) // DEBUG NORMAL + VIEW BIAS
{
if (_ForceDebugNormalViewBias)
{
wsPos = mul(UNITY_MATRIX_M, float4(v.vertex.xyz * _ProbeSize * 1.5f, 1.0f));
wsPos += float4(samplingPositionNoAntiLeak_WS, 0.0f);
}
else
{
DoCull(o);
return o;
}
}
else // DEBUG NORMAL + VIEW BIAS + ANTI LEAK
{
wsPos = mul(UNITY_MATRIX_M, float4(v.vertex.xyz * _ProbeSize * 3.0f, 1.0f));
wsPos += float4(snappedProbePosition_WS + normalizedOffset * probeDistance, 0.0f);
}
}
float4 pos = mul(UNITY_MATRIX_VP, wsPos);
float remappedDepth = Remap(-1.0f, 1.0f, 0.6f, 1.0f, pos.z); // remapped depth to draw gizmo on top of most other objects
o.vertex = float4(pos.x, pos.y, remappedDepth * pos.w, pos.w);
o.normal = normalize(mul(v.normal, (float3x3)UNITY_MATRIX_M));
o.color = v.color;
o.texCoord = v.texCoord;
o.samplingFactor_ValidityWeight = float2(samplingFactor, validityWeight);
return o;
}
float4 frag(v2f i) : SV_Target
{
// QUADS to write the sampling factor of each probe
if (i.color.z)
{
float samplingFactor = i.samplingFactor_ValidityWeight.x;
float validityWeight = i.samplingFactor_ValidityWeight.y;
half4 color = WriteFractNumber(samplingFactor, i.texCoord);
if (validityWeight > 0.0f)
color = lerp(half4(0.0f, 0.0f, 0.0f, 1.0f), half4(0.0f, 1.0f, 0.0f, 1.0f), color.x);
else
color = lerp(half4(1.0f, 1.0f, 1.0f, 1.0f), half4(1.0f, 0.0f, 0.0f, 1.0f), color.x);
return color;
}
// ARROW to show debugging position and normal
else if (i.color.y)
{
return _DebugArrowColor;
}
// LOCATOR to debug sampling position
else
{
if (i.color.x) // DEBUG NORMAL + VIEW BIAS
return _DebugLocator02Color;
else // DEBUG NORMAL + VIEW BIAS + ANTILEAK MODE
return _DebugLocator01Color;
}
}
#endif
#endif // PROBEVOLUMEDEBUG_FUNCTIONS_HLSL
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7b7fb68bec939a04791463e4b8734f38
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,35 @@
Shader "Hidden/Core/ProbeVolumeFragmentationDebug"
{
SubShader
{
Tags{ }
Pass
{
ZWrite On
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
#pragma editor_sync_compilation
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch switch2
// #pragma enable_debug_symbols
#pragma vertex Vert
#pragma fragment Frag
// Central render pipeline specific includes
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugBase.hlsl"
#define PROBE_VOLUME_DEBUG_FUNCTION_FRAGMENTATION
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugFunctions.hlsl"
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 3a80877c579b9144ebdcc6d923bca303
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,98 @@
fileFormatVersion: 2
guid: 73fe53b428c5b3440b7e87ee830b608a
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
Shader "Hidden/Core/ProbeVolumeOffsetDebug"
{
SubShader
{
Tags{ "RenderType" = "Opaque" }
LOD 100
HLSLINCLUDE
#pragma editor_sync_compilation
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch switch2
#pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
// Central render pipeline specific includes
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugBase.hlsl"
#define PROBE_VOLUME_DEBUG_FUNCTION_OFFSET
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugFunctions.hlsl"
ENDHLSL
Pass
{
Name "ForwardOnly"
ZTest LEqual
ZWrite On
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
ENDHLSL
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: db8bd7436dc2c5f4c92655307d198381
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,37 @@
Shader "Hidden/Core/ProbeVolumeSamplingDebug"
{
SubShader
{
Tags{ "RenderType" = "Opaque" }
LOD 100
HLSLINCLUDE
#pragma editor_sync_compilation
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch switch2
#pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
//#pragma enable_debug_symbols
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugBase.hlsl"
#define PROBE_VOLUME_DEBUG_FUNCTION_SAMPLING
#include "Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugFunctions.hlsl"
ENDHLSL
Pass
{
Name "ForwardOnly"
ZTest LEqual
ZWrite On
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
ENDHLSL
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: bf54e6528c79a224e96346799064c393
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: