You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
309 lines
15 KiB
309 lines
15 KiB
using UnityEngine.Experimental.Rendering;
|
|
|
|
namespace UnityEngine.Rendering.HighDefinition
|
|
{
|
|
// Global Constant Buffers - b registers. Unity supports a maximum of 16 global constant buffers.
|
|
enum ConstantRegister
|
|
{
|
|
Global = 0,
|
|
XR = 1,
|
|
PBRSky = 2,
|
|
RayTracing = 3,
|
|
RayTracingLightLoop = 4,
|
|
WorldEnvLightReflectionData = 5,
|
|
APV = APVConstantBufferRegister.GlobalRegister,
|
|
}
|
|
|
|
// We need to keep the number of different constant buffers low.
|
|
// Indeed, those are bound for every single drawcall so if we split things in various CB (lightloop, SSS, Fog, etc)
|
|
// We multiply the number of CB we have to bind per drawcall.
|
|
// This is why this CB is big.
|
|
// It should only contain 2 sorts of things:
|
|
// - Global data for a camera (view matrices, RTHandle stuff, etc)
|
|
// - Things that are needed per draw call (like fog or lighting info for forward rendering)
|
|
// Anything else (such as engine passes) can have their own constant buffers (and still use this one as well).
|
|
|
|
// PARAMETERS DECLARATION GUIDELINES:
|
|
// All data is aligned on Vector4 size, arrays elements included.
|
|
// - Shader side structure will be padded for anything not aligned to Vector4. Add padding accordingly.
|
|
// - Base element size for array should be 4 components of 4 bytes (Vector4 or Vector4Int basically) otherwise the array will be interlaced with padding on shader side.
|
|
// - In Metal the float3 and float4 are both actually sized and aligned to 16 bytes, whereas for Vulkan/SPIR-V, the alignment is the same. Do not use Vector3!
|
|
// Try to keep data grouped by access and rendering system as much as possible (fog params or light params together for example).
|
|
// => Don't move a float parameter away from where it belongs for filling a hole. Add padding in this case.
|
|
[GenerateHLSL(needAccessors = false, generateCBuffer = true, constantRegister = (int)ConstantRegister.Global)]
|
|
unsafe struct ShaderVariablesGlobal
|
|
{
|
|
public const int RenderingLayersMask = (int)RenderingLayerMask.Everything;
|
|
|
|
// TODO: put commonly used vars together (below), and then sort them by the frequency of use (descending).
|
|
// Note: a matrix is 4 * 4 * 4 = 64 bytes (1x cache line), so no need to sort those.
|
|
|
|
// ================================
|
|
// PER VIEW CONSTANTS
|
|
// ================================
|
|
// TODO: all affine matrices should be 3x4.
|
|
public Matrix4x4 _ViewMatrix;
|
|
public Matrix4x4 _CameraViewMatrix;
|
|
public Matrix4x4 _InvViewMatrix;
|
|
public Matrix4x4 _ProjMatrix;
|
|
public Matrix4x4 _InvProjMatrix;
|
|
public Matrix4x4 _ViewProjMatrix;
|
|
public Matrix4x4 _CameraViewProjMatrix;
|
|
public Matrix4x4 _InvViewProjMatrix;
|
|
public Matrix4x4 _NonJitteredViewProjMatrix;
|
|
public Matrix4x4 _NonJitteredInvViewProjMatrix;
|
|
public Matrix4x4 _PrevViewProjMatrix; // non-jittered
|
|
public Matrix4x4 _PrevInvViewProjMatrix; // non-jittered
|
|
|
|
#if !USING_STEREO_MATRICES
|
|
public Vector4 _WorldSpaceCameraPos_Internal;
|
|
public Vector4 _PrevCamPosRWS_Internal;
|
|
#endif
|
|
public Vector4 _ScreenSize; // { w, h, 1 / w, 1 / h }
|
|
public Vector4 _PostProcessScreenSize; // { w, h, 1.0 / w, 1.0 / h }
|
|
|
|
// Those four uniforms are specific to the RTHandle system
|
|
public Vector4 _RTHandleScale; // { w / RTHandle.maxWidth, h / RTHandle.maxHeight } : xy = currFrame, zw = prevFrame
|
|
public Vector4 _RTHandleScaleHistory; // Same as above but the RTHandle handle size is that of the history buffer
|
|
public Vector4 _RTHandlePostProcessScale; // { postProcessWidth / RTHandle.maxWidth, postProcessWidth / RTHandle.maxHeight } : xy = currFrame, zw = prevFrame
|
|
public Vector4 _RTHandlePostProcessScaleHistory; // Same as above but the RTHandle handle size for post process is that of the history buffer
|
|
|
|
public Vector4 _DynamicResolutionFullscreenScale; // Represent the scale between dynamic resolution and the final camera viewport resolution
|
|
|
|
// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
|
|
// x = 1 - f/n
|
|
// y = f/n
|
|
// z = 1/f - 1/n
|
|
// w = 1/n
|
|
// or in case of a reversed depth buffer (UNITY_REVERSED_Z is 1)
|
|
// x = -1 + f/n
|
|
// y = 1
|
|
// z = -1/n + -1/f
|
|
// w = 1/f
|
|
public Vector4 _ZBufferParams;
|
|
|
|
// x = 1 or -1 (-1 if projection is flipped)
|
|
// y = near plane
|
|
// z = far plane
|
|
// w = 1/far plane
|
|
public Vector4 _ProjectionParams;
|
|
|
|
// Parameters used to linearize the Z buffer
|
|
// Correctly handles oblique projection matrices
|
|
// https://jcgt.org/published/0005/04/03/paper.pdf
|
|
public Vector4 _InvProjParams;
|
|
|
|
// x = orthographic camera's width
|
|
// y = orthographic camera's height
|
|
// z = unused
|
|
// w = 1.0 if camera is ortho, 0.0 if perspective
|
|
public Vector4 unity_OrthoParams;
|
|
|
|
// x = width
|
|
// y = height
|
|
// z = 1 + 1.0/width
|
|
// w = 1 + 1.0/height
|
|
public Vector4 _ScreenParams;
|
|
|
|
[HLSLArray(6, typeof(Vector4))]
|
|
public fixed float _FrustumPlanes[6 * 4]; // { (a, b, c) = N, d = -dot(N, P) } [L, R, T, B, N, F]
|
|
|
|
[HLSLArray(6, typeof(Vector4))]
|
|
public fixed float _ShadowFrustumPlanes[6 * 4]; // { (a, b, c) = N, d = -dot(N, P) } [L, R, T, B, N, F]
|
|
|
|
// TAA Frame Index ranges from 0 to 1023.
|
|
public Vector4 _TaaFrameInfo; // { taaSharpenStrength, unused, taaFrameIndex, taaEnabled ? 1 : 0 }
|
|
|
|
// Current jitter strength (0 if TAA is disabled)
|
|
public Vector4 _TaaJitterStrength; // { x, y, x/width, y/height }
|
|
|
|
// t = animateMaterials ? Time.realtimeSinceStartup : 0.
|
|
// We keep all those time value for compatibility with legacy unity but prefer _TimeParameters instead.
|
|
public Vector4 _Time; // { t/20, t, t*2, t*3 }
|
|
public Vector4 _SinTime; // { sin(t/8), sin(t/4), sin(t/2), sin(t) }
|
|
public Vector4 _CosTime; // { cos(t/8), cos(t/4), cos(t/2), cos(t) }
|
|
public Vector4 unity_DeltaTime; // { dt, 1/dt, smoothdt, 1/smoothdt }
|
|
public Vector4 _TimeParameters; // { t, sin(t), cos(t) }
|
|
public Vector4 _LastTimeParameters; // { t, sin(t), cos(t) }
|
|
|
|
// Volumetric lighting / Fog.
|
|
public Vector4 _PlanetCenterRadius;
|
|
public Vector4 _PlanetUpAltitude;
|
|
public int _FogEnabled;
|
|
public int _PBRFogEnabled;
|
|
public int _EnableVolumetricFog;
|
|
public float _MaxFogDistance;
|
|
public Vector4 _FogColor; // color in rgb
|
|
public float _FogColorMode;
|
|
public float _GlobalMipBias;
|
|
public float _GlobalMipBiasPow2;
|
|
public uint _RayTracingCheckerIndex;
|
|
public Vector4 _MipFogParameters;
|
|
public Vector4 _HeightFogBaseScattering;
|
|
public float _HeightFogBaseExtinction;
|
|
public float _HeightFogBaseHeight;
|
|
public float _GlobalFogAnisotropy;
|
|
public int _VolumetricFilteringEnabled;
|
|
public Vector2 _HeightFogExponents; // { 1/H, H }
|
|
public int _FogDirectionalOnly;
|
|
public float _FogGIDimmer;
|
|
|
|
// VBuffer
|
|
public Vector4 _VBufferViewportSize; // { w, h, 1/w, 1/h }
|
|
public Vector4 _VBufferLightingViewportScale; // Necessary us to work with sub-allocation (resource aliasing) in the RTHandle system
|
|
public Vector4 _VBufferLightingViewportLimit; // Necessary us to work with sub-allocation (resource aliasing) in the RTHandle system
|
|
public Vector4 _VBufferDistanceEncodingParams; // See the call site for description
|
|
public Vector4 _VBufferDistanceDecodingParams; // See the call site for description
|
|
public uint _VBufferSliceCount;
|
|
public float _VBufferRcpSliceCount;
|
|
public float _VBufferRcpInstancedViewCount; // Used to remap VBuffer coordinates for XR
|
|
public float _VBufferLastSliceDist; // The distance to the middle of the last slice
|
|
|
|
public Vector4 _ShadowAtlasSize;
|
|
public Vector4 _CascadeShadowAtlasSize;
|
|
public Vector4 _AreaShadowAtlasSize;
|
|
public Vector4 _CachedShadowAtlasSize;
|
|
public Vector4 _CachedAreaShadowAtlasSize;
|
|
|
|
// Water
|
|
public Vector4 _BoundsSS;
|
|
public float _UpDirectionX;
|
|
public float _UpDirectionY;
|
|
public float _BufferStride;
|
|
public int _EnableWater;
|
|
|
|
public Vector4 _WaterAmbientProbe;
|
|
public Vector4 _UnderWaterScatteringExtinction;
|
|
public Vector4 _UnderWaterUpHeight;
|
|
public int _UnderWaterSurfaceIndex;
|
|
public float _UnderWaterCausticsIntensity;
|
|
public float _UnderWaterCausticsPlaneBlendDistance;
|
|
public float _UnderWaterCausticsTilingFactor;
|
|
public Matrix4x4 _UnderWaterSurfaceTransform_Inverse;
|
|
public float _UnderWaterCausticsMaxLOD;
|
|
public float _UnderWaterCausticsShadowIntensity;
|
|
public float _UnderWaterCausticsRegionSize;
|
|
public int _CustomOutputForCustomPass;
|
|
|
|
public int _PreRefractionPass;
|
|
public int _SpecularFade;
|
|
public uint _EnableRenderingLayers;
|
|
public int _ReflectionsMode;
|
|
|
|
public uint _DirectionalLightCount;
|
|
public uint _PunctualLightCount;
|
|
public uint _AreaLightCount;
|
|
public uint _EnvLightCount;
|
|
|
|
public uint _WorldDirectionalLightCount;
|
|
public uint _WorldPunctualLightCount;
|
|
public uint _WorldAreaLightCount;
|
|
public uint _WorldEnvLightCount;
|
|
|
|
public int _EnvLightSkyEnabled;
|
|
public uint _CascadeShadowCount;
|
|
public int _DirectionalShadowIndex;
|
|
public uint _EnableLightLayers;
|
|
|
|
public uint _EnableSkyReflection;
|
|
public uint _EnableSSRefraction;
|
|
public float _SSRefractionInvScreenWeightDistance; // Distance for screen space smoothstep with fallback
|
|
public float _ColorPyramidLodCount;
|
|
|
|
public float _DirectionalTransmissionMultiplier;
|
|
public float _ProbeExposureScale;
|
|
public float _ContactShadowOpacity;
|
|
public float _ReplaceDiffuseForIndirect;
|
|
|
|
public Vector4 _AmbientOcclusionParam; // xyz occlusion color, w directLightStrenght
|
|
|
|
public float _IndirectDiffuseLightingMultiplier;
|
|
public uint _IndirectDiffuseLightingLayers;
|
|
public float _ReflectionLightingMultiplier;
|
|
public uint _ReflectionLightingLayers;
|
|
|
|
public float _MicroShadowOpacity;
|
|
public uint _EnableProbeVolumes;
|
|
public uint _ProbeVolumeCount;
|
|
public float _SlopeScaleDepthBias;
|
|
|
|
public Vector4 _CookieAtlasSize;
|
|
public Vector4 _CookieAtlasData;
|
|
public Vector4 _ReflectionAtlasCubeData;
|
|
public Vector4 _ReflectionAtlasPlanarData;
|
|
|
|
// Tile/Cluster
|
|
public uint _NumTileFtplX;
|
|
public uint _NumTileFtplY;
|
|
public float g_fClustScale;
|
|
public float g_fClustBase;
|
|
|
|
public float g_fNearPlane;
|
|
public float g_fFarPlane;
|
|
public int g_iLog2NumClusters; // We need to always define these to keep constant buffer layouts compatible
|
|
public uint g_isLogBaseBufferEnabled;
|
|
|
|
public uint _NumTileClusteredX;
|
|
public uint _NumTileClusteredY;
|
|
public int _EnvSliceSize;
|
|
public uint _EnableDecalLayers;
|
|
|
|
// Subsurface scattering
|
|
// Use float4 to avoid any packing issue between compute and pixel shaders
|
|
[HLSLArray(DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT, typeof(Vector4))]
|
|
public fixed float _ShapeParamsAndMaxScatterDists[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * 4]; // RGB = S = 1 / D, A = d = RgbMax(D)
|
|
[HLSLArray(DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT, typeof(Vector4))]
|
|
public fixed float _TransmissionTintsAndFresnel0[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * 4]; // RGB = 1/4 * color, A = fresnel0
|
|
[HLSLArray(DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT, typeof(Vector4))]
|
|
public fixed float _WorldScalesAndFilterRadiiAndThicknessRemaps[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * 4]; // X = meters per world unit, Y = filter radius (in mm), Z = remap start, W = end - start
|
|
[HLSLArray(DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT, typeof(Vector4))]
|
|
public fixed float _DualLobeAndDiffusePower[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * 4]; // RGB = dual lobe, A = diffuse power
|
|
[HLSLArray(DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT, typeof(Vector4))]
|
|
public fixed float _BorderAttenuationColor[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * 4]; // RGB = dual lobe, A = diffuse power
|
|
// Because of constant buffer limitation, arrays can only hold 4 components elements (otherwise we get alignment issues)
|
|
// We could pack the 16 values inside 4 uint4 but then the generated code is inefficient and generates a lots of swizzle operations instead of a single load.
|
|
// That's why we have 16 uint and only use the first component of each element.
|
|
[HLSLArray(DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT, typeof(ShaderGenUInt4))]
|
|
public fixed uint _DiffusionProfileHashTable[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * 4]; // TODO: constant
|
|
|
|
public uint _EnableSubsurfaceScattering; // Globally toggles subsurface and transmission scattering on/off
|
|
public uint _TexturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
|
|
public uint _TransmissionFlags; // 1 bit/profile; 0 = regular, 1 = thin
|
|
public uint _DiffusionProfileCount;
|
|
|
|
// Decals
|
|
public Vector2 _DecalAtlasResolution;
|
|
public uint _EnableDecals;
|
|
public uint _DecalCount;
|
|
|
|
public float _OffScreenDownsampleFactor;
|
|
public uint _OffScreenRendering;
|
|
public uint _XRViewCount;
|
|
public int _FrameCount;
|
|
|
|
public Vector4 _CoarseStencilBufferSize;
|
|
|
|
public int _IndirectDiffuseMode;
|
|
public int _EnableRayTracedReflections;
|
|
public int _RaytracingFrameIndex; // Index of the current frame [0, 7]
|
|
public uint _EnableRecursiveRayTracing;
|
|
|
|
public int _TransparentCameraOnlyMotionVectors;
|
|
// Can be set to 0 to globally "disable" tessellation
|
|
// Because the DepthPrepass doesn't have a DEBUG_DISPLAY variant, it is the only way to disable it for debug modes
|
|
public float _GlobalTessellationFactorMultiplier;
|
|
public float _SpecularOcclusionBlend;
|
|
public float _DeExposureMultiplier;
|
|
|
|
// See ScreenCoordOverride.hlsl for details.
|
|
public Vector4 _ScreenSizeOverride;
|
|
public Vector4 _ScreenCoordScaleBias;
|
|
|
|
public Vector2 _VolumetricCloudsShadowScale;
|
|
public uint _EnableComputeThickness;
|
|
public float _VolumetricCloudsFallBackValue;
|
|
public Vector4 _VolumetricCloudsShadowOriginToggle;
|
|
public Vector4 _ColorPyramidUvScaleAndLimitCurrentFrame;
|
|
public Vector4 _ColorPyramidUvScaleAndLimitPrevFrame;
|
|
}
|
|
}
|