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,80 @@
using UnityEngine.Serialization;
namespace UnityEngine.Rendering
{
/// <summary>
/// The available options for range reduction/tonemapping when outputting to an HDR device.
/// </summary>
[GenerateHLSL]
public enum HDRRangeReduction
{
/// <summary>
/// No range reduction.
/// </summary>
None,
/// <summary>
/// Reinhard tonemapping.
/// </summary>
Reinhard,
/// <summary>
/// BT2390 Hermite spline EETF range reduction.
/// </summary>
BT2390,
/// <summary>
/// ACES tonemapping preset for 1000 nits displays.
/// </summary>
ACES1000Nits,
/// <summary>
/// ACES tonemapping preset for 2000 nits displays.
/// </summary>
ACES2000Nits,
/// <summary>
/// ACES tonemapping preset for 4000 nits displays.
/// </summary>
ACES4000Nits
}
/// <summary>
/// The available options for colorspace when outputting to an HDR device.
/// </summary>
[GenerateHLSL]
public enum HDRColorspace
{
/// <summary>
/// Rec709 color primaries with D65 white point.
/// </summary>
Rec709,
/// <summary>
/// Rec2020 color primaries with D65 white point.
/// </summary>
Rec2020,
/// <summary>
/// P3 color primaries with D65 white point.
/// </summary>
P3D65
}
/// <summary>
/// The available options for color encoding when outputting to an HDR device.
/// </summary>
[GenerateHLSL]
public enum HDREncoding
{
/// <summary>
/// Linear OETF.
/// </summary>
Linear = TransferFunction.Linear,
/// <summary>
/// ST 2084 PQ OETF
/// </summary>
PQ = TransferFunction.PQ,
/// <summary>
/// Gamma 2.2 OETF.
/// </summary>
Gamma22 = TransferFunction.Gamma22,
/// <summary>
/// sRGB curve OETF.
/// </summary>
sRGB = TransferFunction.sRGB
}
}
@@ -0,0 +1,33 @@
//
// This file was automatically generated. Please don't edit by hand. Execute Editor command [ Edit > Rendering > Generate Shader Includes ] instead
//
#ifndef HDROUTPUTDEFINES_CS_HLSL
#define HDROUTPUTDEFINES_CS_HLSL
//
// UnityEngine.Rendering.HDRColorspace: static fields
//
#define HDRCOLORSPACE_REC709 (0)
#define HDRCOLORSPACE_REC2020 (1)
#define HDRCOLORSPACE_P3D65 (2)
//
// UnityEngine.Rendering.HDREncoding: static fields
//
#define HDRENCODING_LINEAR (3)
#define HDRENCODING_PQ (2)
#define HDRENCODING_GAMMA22 (4)
#define HDRENCODING_S_RGB (0)
//
// UnityEngine.Rendering.HDRRangeReduction: static fields
//
#define HDRRANGEREDUCTION_NONE (0)
#define HDRRANGEREDUCTION_REINHARD (1)
#define HDRRANGEREDUCTION_BT2390 (2)
#define HDRRANGEREDUCTION_ACES1000NITS (3)
#define HDRRANGEREDUCTION_ACES2000NITS (4)
#define HDRRANGEREDUCTION_ACES4000NITS (5)
#endif
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 413c288ef05043d4285cf0407f8188b9
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d568fc1905aef314a9f36afd557bc4f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,23 @@
using System;
namespace UnityEngine.Rendering
{
/// <summary>
/// Implement this interface on every post process volumes
/// </summary>
public interface IPostProcessComponent
{
/// <summary>
/// Tells if the post process needs to be rendered or not.
/// </summary>
/// <returns><c>true</c> if the effect should be rendered, <c>false</c> otherwise.</returns>
bool IsActive();
/// <summary>
/// Tells if the post process can run the effect on-tile or if it needs a full pass.
/// </summary>
/// <returns><c>true</c> if it can run on-tile, <c>false</c> otherwise.</returns>
[Obsolete("Unused #from(2023.1)")]
bool IsTileCompatible() => false;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 412b3ba463224f2cb2e0e70f93677f3c
timeCreated: 1661170665
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d87e57545548474c86d357b2d08ee30
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,238 @@
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using System.Dynamic;
using UnityEngine.Serialization;
namespace UnityEngine.Rendering
{
/// <summary>
/// Data-Driven Lens Flare can be added on any gameobject
/// </summary>
[ExecuteAlways]
[AddComponentMenu("Rendering/Lens Flare (SRP)")]
[PipelineHelpURL("UniversalRenderPipelineAsset", "urp/shared/lens-flare/lens-flare-component")]
[PipelineHelpURL("HDRenderPipelineAsset", "shared/lens-flare/lens-flare-component")]
public sealed class LensFlareComponentSRP : MonoBehaviour
{
[SerializeField]
private LensFlareDataSRP m_LensFlareData = null;
enum Version
{
Initial,
}
#pragma warning disable 414
[SerializeField]
Version version = Version.Initial;
#pragma warning restore 414
/// <summary>
/// Lens flare asset used on this component
/// </summary>
public LensFlareDataSRP lensFlareData
{
get => m_LensFlareData;
set
{
m_LensFlareData = value;
OnValidate();
}
}
/// <summary>
/// Intensity
/// </summary>
[Min(0.0f)]
public float intensity = 1.0f;
/// <summary>
/// Distance used to scale the Distance Attenuation Curve
/// </summary>
[Min(1e-5f)]
public float maxAttenuationDistance = 100.0f;
/// <summary>
/// Distance used to scale the Scale Attenuation Curve
/// </summary>
[Min(1e-5f)]
public float maxAttenuationScale = 100.0f;
/// <summary>
/// Attenuation by distance
/// </summary>
public AnimationCurve distanceAttenuationCurve = new AnimationCurve(new Keyframe(0.0f, 1.0f), new Keyframe(1.0f, 0.0f));
/// <summary>
/// Scale by distance, use the same distance as distanceAttenuationCurve
/// </summary>
public AnimationCurve scaleByDistanceCurve = new AnimationCurve(new Keyframe(0.0f, 1.0f), new Keyframe(1.0f, 0.0f));
/// <summary>
/// If component attached to a light, attenuation the lens flare per light type
/// </summary>
public bool attenuationByLightShape = true;
/// <summary>
/// Attenuation used radially, which allow for instance to enable flare only on the edge of the screen
/// </summary>
public AnimationCurve radialScreenAttenuationCurve = new AnimationCurve(new Keyframe(0.0f, 1.0f), new Keyframe(1.0f, 1.0f));
/// <summary>
/// Enable Occlusion feature
/// </summary>
public bool useOcclusion = false;
/// <summary>
/// Enable Occlusion using Background Cloud (for instance: CloudLayer)
/// Please use useFogOpacityOcclusion instead.
/// </summary>
[Obsolete("Replaced by environmentOcclusion. #from(6000.0)")]
[NonSerialized]
public bool useBackgroundCloudOcclusion = false;
/// <summary>Enable occlusion from environment effects supported by the render pipeline. This may include opacity from volumetric clouds, background clouds, fog and water.</summary>
[FormerlySerializedAs("volumetricCloudOcclusion")]
[FormerlySerializedAs("useFogOpacityOcclusion")]
public bool environmentOcclusion = false;
/// <summary>
/// Enable Occlusion with Water
/// </summary>
[Obsolete("Replaced by environmentOcclusion. #from(6000.0)")]
[NonSerialized]
public bool useWaterOcclusion = false;
/// <summary>
/// Radius around the light used to occlude the flare (value in world space)
/// </summary>
[Min(0.0f)]
public float occlusionRadius = 0.1f;
/// <summary>
/// Random Samples Count used inside the disk with 'occlusionRadius'
/// </summary>
[Range(1, 64)]
public uint sampleCount = 32;
/// <summary>
/// Z Occlusion Offset allow us to offset the plane where the disc of occlusion is place (closer to camera), value on world space.
/// Useful for instance to sample occlusion outside a light bulb if we place a flare inside the light bulb
/// </summary>
public float occlusionOffset = 0.05f;
/// <summary>
/// Global Scale
/// </summary>
[Min(0.0f)]
public float scale = 1.0f;
/// <summary>
/// If allowOffScreen is true then If the lens flare is outside the screen we still emit the flare on screen
/// </summary>
public bool allowOffScreen = false;
/// <summary>
/// If volumetricCloudOcclusion is true then use the volumetric cloud (on HDRP only) for the occlusion
/// Please use useFogOpacityOcclusion instead.
/// </summary>
[Obsolete("Please use environmentOcclusion instead. #from(6000.0)")]
[NonSerialized]
public bool volumetricCloudOcclusion = false;
/// Our default celestial body will have an angular radius of 3.3 degrees. This is an arbitrary number, but must be kept constant
/// so the occlusion radius for direct lights is consistent regardless of near / far clip plane configuration.
const float sCelestialAngularRadius = 3.3f * Mathf.PI / 180.0f;
/// <summary>
/// OcclusionRemapCurve allow the occlusion [from 0 to 1] to be remap with any desired shape.
/// </summary>
public TextureCurve occlusionRemapCurve = new TextureCurve(AnimationCurve.Linear(0.0f, 0.0f, 1.0f, 1.0f), 1.0f, false, new Vector2(0.0f, 1.0f));
/// <summary>
/// Light override, change the light which influences the flares including "modulate by light color" and "Attenuation By Light Shape" but not the position.
/// </summary>
public Light lightOverride = null;
/// <summary>
/// Retrieves the projected occlusion radius from a particular celestial in the infinity plane with an angular radius.
/// This is used for directional lights which require to have consistent occlusion radius regardless of the near/farplane configuration.
/// </summary>
/// <param name="mainCam">The camera utilized to calculate the occlusion radius</param>
/// <returns>The value, in world units, of the occlusion angular radius.</returns>
public float celestialProjectedOcclusionRadius(Camera mainCam)
{
float projectedRadius = (float)Math.Tan(sCelestialAngularRadius) * mainCam.farClipPlane;
return occlusionRadius * projectedRadius;
}
#if UNITY_EDITOR
void Awake()
{
if (!lensFlareData)
lensFlareData = AssetDatabase.LoadAssetAtPath<LensFlareDataSRP>("Packages/com.unity.render-pipelines.core/Runtime/RenderPipelineResources/Default Lens Flare (SRP).asset");
}
#endif
/// <summary>
/// Add or remove the lens flare to the queue of PostProcess
/// </summary>
void OnEnable()
{
if (lensFlareData)
LensFlareCommonSRP.Instance.AddData(this);
else
LensFlareCommonSRP.Instance.RemoveData(this);
}
/// <summary>
/// Remove the lens flare from the queue of PostProcess
/// </summary>
void OnDisable()
{
LensFlareCommonSRP.Instance.RemoveData(this);
}
/// <summary>
/// Add or remove the lens flare from the queue of PostProcess
/// </summary>
void OnValidate()
{
if (isActiveAndEnabled && lensFlareData != null)
{
LensFlareCommonSRP.Instance.AddData(this);
}
else
{
LensFlareCommonSRP.Instance.RemoveData(this);
}
}
private void OnDestroy()
{
occlusionRemapCurve.Release();
}
#if UNITY_EDITOR
private const float k_DebugClippingSafePercentage = 0.9f; //for debug gizmo, only push 90% further so we avoid clipping of debug lines.
void OnDrawGizmosSelected()
{
Camera mainCam = Camera.current;
if (mainCam != null && useOcclusion)
{
Vector3 positionWS;
float adjustedOcclusionRadius = occlusionRadius;
Light light = GetComponent<Light>();
if (light != null && light.type == LightType.Directional)
{
positionWS = -transform.forward * (mainCam.farClipPlane * k_DebugClippingSafePercentage) + mainCam.transform.position;
adjustedOcclusionRadius = celestialProjectedOcclusionRadius(mainCam);
}
else
{
positionWS = transform.position;
}
Color previousH = Handles.color;
Color previousG = Gizmos.color;
Handles.color = Color.red;
Gizmos.color = Color.red;
Vector3 dir = (mainCam.transform.position - positionWS).normalized;
Handles.DrawWireDisc(positionWS + dir * occlusionOffset, dir, adjustedOcclusionRadius, 1.0f);
Gizmos.DrawWireSphere(positionWS, occlusionOffset);
Gizmos.color = previousG;
Handles.color = previousH;
}
}
#endif
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc4d76f733087744991913c9d19d5274
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: d7b90718ad2a7af4aab8546a0897d5db, type: 3}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,501 @@
using UnityEngine.Serialization;
namespace UnityEngine.Rendering
{
/// <summary>
/// SRPLensFlareBlendMode defined the available blend mode for each LensFlareElement
/// </summary>
[System.Serializable]
public enum SRPLensFlareBlendMode
{
/// <summary>
/// Additive: Blend One One
/// </summary>
Additive,
/// <summary>
/// Screen:
/// Blend One OneMinusSrcColor
/// </summary>
Screen,
/// <summary>
/// Premultiply:
/// Blend One OneMinusSrcAlpha
/// ColorMask RGB
/// </summary>
Premultiply,
/// <summary>
/// Lerp: Blend SrcAlpha OneMinusSrcAlpha
/// </summary>
Lerp
}
/// <summary>
/// SRPLensFlareDistribution defined how we spread the flare element when count > 1
/// </summary>
[System.Serializable]
public enum SRPLensFlareDistribution
{
/// <summary>
/// Uniformly spread
/// </summary>
Uniform,
/// <summary>
/// Controlled with curved
/// </summary>
Curve,
/// <summary>
/// Random distribution
/// </summary>
Random
}
/// <summary>
/// SRPLensFlareType which can be an image of a procedural shape
/// If change order or add new member, need to update preview
/// shader: LensFlareDataDrivenPreview.shader
/// </summary>
[System.Serializable]
[GenerateHLSL]
public enum SRPLensFlareType
{
/// <summary>
/// Image from a file or a RenderTexture
/// </summary>
Image,
/// <summary>
/// Procedural Circle
/// </summary>
Circle,
/// <summary>
/// Polygon
/// </summary>
Polygon,
/// <summary>
/// shape as a ring
/// </summary>
Ring,
/// <summary>
/// Hoop
/// </summary>
LensFlareDataSRP
}
/// <summary>
/// SRPLensFlareColorType describe how to colorize LensFlare
/// </summary>
[System.Serializable]
[GenerateHLSL]
public enum SRPLensFlareColorType
{
/// <summary>
/// Constant Color
/// </summary>
Constant = 0,
/// <summary>
/// Radial Gradient
/// </summary>
RadialGradient,
/// <summary>
/// Angular Gradient
/// </summary>
AngularGradient
}
/// <summary>
/// LensFlareDataElementSRP defines collection of parameters describing the behavior a Lens Flare Element.
/// </summary>
[System.Serializable]
public sealed class LensFlareDataElementSRP
{
/// <summary> Initialize default values </summary>
public LensFlareDataElementSRP()
{
lensFlareDataSRP = null;
visible = true;
localIntensity = 1.0f;
position = 0.0f;
positionOffset = new Vector2(0.0f, 0.0f);
angularOffset = 0.0f;
translationScale = new Vector2(1.0f, 1.0f);
lensFlareTexture = null;
uniformScale = 1.0f;
sizeXY = Vector2.one;
allowMultipleElement = false;
count = 5;
rotation = 0.0f;
preserveAspectRatio = false;
// Ring
ringThickness = 0.25f;
// Hoop
hoopFactor = 1.0f;
// Shimmer
noiseAmplitude = 1.0f;
noiseFrequency = 1;
noiseSpeed = 0;
shapeCutOffSpeed = 0.0f;
shapeCutOffRadius = 10.0f;
tintColorType = SRPLensFlareColorType.Constant;
tint = new Color(1.0f, 1.0f, 1.0f, 0.5f);
tintGradient = new TextureGradient(
new GradientColorKey[] { new GradientColorKey(Color.black, 0.0f), new GradientColorKey(Color.white, 1.0f) },
new GradientAlphaKey[] { new GradientAlphaKey(0.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) });
blendMode = SRPLensFlareBlendMode.Additive;
autoRotate = false;
isFoldOpened = true;
flareType = SRPLensFlareType.Circle;
distribution = SRPLensFlareDistribution.Uniform;
lengthSpread = 1f;
colorGradient = new Gradient();
colorGradient.SetKeys(new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.white, 1.0f) },
new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) });
positionCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f, 1.0f, 1.0f), new Keyframe(1.0f, 1.0f, 1.0f, -1.0f));
scaleCurve = new AnimationCurve(new Keyframe(0.0f, 1.0f), new Keyframe(1.0f, 1.0f));
uniformAngle = 0.0f;
uniformAngleCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 0.0f));
// Random
seed = 0;
intensityVariation = 0.75f;
positionVariation = new Vector2(1.0f, 0.0f);
scaleVariation = 1.0f;
rotationVariation = 180.0f;
// Distortion
enableRadialDistortion = false;
targetSizeDistortion = Vector2.one;
distortionCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f, 1.0f, 1.0f), new Keyframe(1.0f, 1.0f, 1.0f, -1.0f));
distortionRelativeToCenter = false;
// Parameters for Procedural
fallOff = 1.0f;
edgeOffset = 0.1f;
sdfRoundness = 0.0f;
sideCount = 6;
inverseSDF = false;
}
/// <summary>
/// Clone the current LensFlareDataElementSRP.
/// </summary>
/// <returns>Cloned LensFlareDataElementSRP.</returns>
public LensFlareDataElementSRP Clone()
{
LensFlareDataElementSRP clone = new LensFlareDataElementSRP();
clone.lensFlareDataSRP = lensFlareDataSRP;
clone.visible = visible;
clone.localIntensity = localIntensity;
clone.position = position;
clone.positionOffset = positionOffset;
clone.angularOffset = angularOffset;
clone.translationScale = translationScale;
clone.lensFlareTexture = lensFlareTexture;
clone.uniformScale = uniformScale;
clone.sizeXY = sizeXY;
clone.allowMultipleElement = allowMultipleElement;
clone.count = count;
clone.rotation = rotation;
clone.preserveAspectRatio = preserveAspectRatio;
clone.ringThickness = ringThickness;
clone.hoopFactor = hoopFactor;
clone.noiseAmplitude = noiseAmplitude;
clone.noiseFrequency = noiseFrequency;
clone.noiseSpeed = noiseSpeed;
clone.shapeCutOffSpeed = shapeCutOffSpeed;
clone.shapeCutOffRadius = shapeCutOffRadius;
clone.tintColorType = tintColorType;
clone.tint = tint;
clone.tintGradient = new TextureGradient(tintGradient.colorKeys, tintGradient.alphaKeys, tintGradient.mode, tintGradient.colorSpace, tintGradient.textureSize);
clone.tintGradient = new TextureGradient(tintGradient.colorKeys, tintGradient.alphaKeys);
clone.blendMode = blendMode;
clone.autoRotate = autoRotate;
clone.isFoldOpened = isFoldOpened;
clone.flareType = flareType;
clone.distribution = distribution;
clone.lengthSpread = lengthSpread;
clone.colorGradient = new Gradient();
clone.colorGradient.SetKeys(colorGradient.colorKeys, colorGradient.alphaKeys);
clone.colorGradient.mode = colorGradient.mode;
clone.colorGradient.colorSpace = colorGradient.colorSpace;
clone.positionCurve = new AnimationCurve(positionCurve.keys);
clone.scaleCurve = new AnimationCurve(scaleCurve.keys);
clone.uniformAngle = uniformAngle;
clone.uniformAngleCurve = new AnimationCurve(uniformAngleCurve.keys);
clone.seed = seed;
clone.intensityVariation = intensityVariation;
clone.positionVariation = positionVariation;
clone.scaleVariation = scaleVariation;
clone.rotationVariation = rotationVariation;
clone.enableRadialDistortion = enableRadialDistortion;
clone.targetSizeDistortion = targetSizeDistortion;
clone.distortionCurve = new AnimationCurve(distortionCurve.keys);
clone.distortionRelativeToCenter = distortionRelativeToCenter;
clone.fallOff = fallOff;
clone.edgeOffset = edgeOffset;
clone.sdfRoundness = sdfRoundness;
clone.sideCount = sideCount;
clone.inverseSDF = inverseSDF;
return clone;
}
/// <summary> Current Element is himselft another LensFlareDataSRP </summary>
public LensFlareDataSRP lensFlareDataSRP;
/// <summary> Visibility checker for current element </summary>
public bool visible;
/// <summary> Position </summary>
public float position;
/// <summary> Position offset </summary>
public Vector2 positionOffset;
/// <summary> Angular offset </summary>
public float angularOffset;
/// <summary> Translation Scale </summary>
public Vector2 translationScale;
// For Hoop
/// <summary>Ring thickness</summary>
[Range(0.0f, 1.0f)]
public float ringThickness;
/// <summary>Hoop thickness</summary>
[Range(-1.0f, 1.0f)]
public float hoopFactor;
// For Ring
/// <summary>Noise parameter amplitude</summary>
public float noiseAmplitude;
/// <summary>Noise parameter frequency</summary>
public int noiseFrequency;
/// <summary>Noise parameter Speed</summary>
public float noiseSpeed;
/// <summary>To simulate the cutoff of the flare by the circular shape of the lens. How quickly this cutoff happen.</summary>
public float shapeCutOffSpeed;
/// <summary>To simulate the cutoff of the flare by the circular shape of the lens.</summary>
public float shapeCutOffRadius;
[Min(0), SerializeField, FormerlySerializedAs("localIntensity")]
float m_LocalIntensity;
/// <summary> Intensity of this element </summary>
public float localIntensity
{
get => m_LocalIntensity;
set => m_LocalIntensity = Mathf.Max(0, value);
}
/// <summary> Texture used to for this Lens Flare Element </summary>
public Texture lensFlareTexture;
/// <summary> Uniform scale applied </summary>
public float uniformScale;
/// <summary> Scale size on each dimension </summary>
public Vector2 sizeXY;
/// <summary> Enable multiple elements </summary>
public bool allowMultipleElement;
[Min(1), SerializeField, FormerlySerializedAs("count")]
int m_Count;
/// <summary> Element can be repeated 'count' times </summary>
public int count
{
get => m_Count;
set => m_Count = Mathf.Max(1, value);
}
/// <summary> Preserve Aspect Ratio </summary>
public bool preserveAspectRatio;
/// <summary> Local rotation of the texture </summary>
public float rotation;
/// <summary>Specify how to tint flare.</summary>
public SRPLensFlareColorType tintColorType;
/// <summary> Tint of the texture can be modulated by the light we are attached to</summary>
public Color tint;
/// <summary> Tint radially of the texture can be modulated by the light we are attached to . </summary>
public TextureGradient tintGradient;
/// <summary> Blend mode used </summary>
public SRPLensFlareBlendMode blendMode;
/// <summary> Rotate the texture relative to the angle on the screen (the rotation will be added to the parameter 'rotation') </summary>
public bool autoRotate;
/// <summary> FlareType used </summary>
public SRPLensFlareType flareType;
/// <summary> Modulate by light color if the asset is used in a 'SRP Lens Flare Source Override' </summary>
public bool modulateByLightColor;
#pragma warning disable 0414 // never used (editor state)
/// <summary> Internal value use to store the state of minimized or maximized LensFlareElement </summary>
[SerializeField]
bool isFoldOpened;
#pragma warning restore 0414
/// <summary> SRPLensFlareDistribution defined how we spread the flare element when count > 1 </summary>
public SRPLensFlareDistribution distribution;
/// <summary> Length to spread the distribution of flares, spread start at 'starting position' </summary>
public float lengthSpread;
/// <summary> Curve describing how to place flares distribution (Used only for Uniform and Curve 'distribution') </summary>
public AnimationCurve positionCurve;
/// <summary> Curve describing how to scale flares distribution (Used only for Uniform and Curve 'distribution') </summary>
public AnimationCurve scaleCurve;
/// <summary> Seed used to seed randomness </summary>
public int seed;
/// <summary> Colors used uniformly for Uniform or Curve Distribution and Random when the distribution is 'Random'. </summary>
public Gradient colorGradient;
[Range(0, 1), SerializeField, FormerlySerializedAs("intensityVariation")]
float m_IntensityVariation;
/// <summary> Scale factor applied on the variation of the intensities. </summary>
public float intensityVariation
{
get => m_IntensityVariation;
set => m_IntensityVariation = Mathf.Max(0, value);
}
/// <summary> Scale factor applied on the variation of the positions. </summary>
public Vector2 positionVariation;
/// <summary> Coefficient applied on the variation of the scale (relative to the current scale). </summary>
public float scaleVariation;
/// <summary> Scale factor applied on the variation of the rotation (relative to the current rotation or auto-rotate). </summary>
public float rotationVariation;
/// <summary> True to use or not the radial distortion. </summary>
public bool enableRadialDistortion;
/// <summary> Target size used on the edge of the screen. </summary>
public Vector2 targetSizeDistortion;
/// <summary> Curve blending from screen center to the edges of the screen. </summary>
public AnimationCurve distortionCurve;
/// <summary> If true the distortion is relative to center of the screen otherwise relative to lensFlare source screen position. </summary>
public bool distortionRelativeToCenter;
[Range(0, 1), SerializeField, FormerlySerializedAs("fallOff")]
float m_FallOff;
/// <summary> Fall of the gradient used for the Procedural Flare. </summary>
public float fallOff
{
get => m_FallOff;
set => m_FallOff = Mathf.Clamp01(value);
}
[Range(0, 1), SerializeField, FormerlySerializedAs("edgeOffset")]
float m_EdgeOffset;
/// <summary> Gradient Offset used for the Procedural Flare. </summary>
public float edgeOffset
{
get => m_EdgeOffset;
set => m_EdgeOffset = Mathf.Clamp01(value);
}
[Min(3), SerializeField, FormerlySerializedAs("sideCount")]
int m_SideCount;
/// <summary> Side count of the regular polygon generated. </summary>
public int sideCount
{
get => m_SideCount;
set => m_SideCount = Mathf.Max(3, value);
}
[Range(0, 1), SerializeField, FormerlySerializedAs("sdfRoundness")]
float m_SdfRoundness;
/// <summary> Roundness of the polygon flare (0: Sharp Polygon, 1: Circle). </summary>
public float sdfRoundness
{
get => m_SdfRoundness;
set => m_SdfRoundness = Mathf.Clamp01(value);
}
/// <summary> Inverse the gradient direction. </summary>
public bool inverseSDF;
/// <summary> Uniform angle (in degrees) used with multiple element enabled with Uniform distribution. </summary>
public float uniformAngle;
/// <summary> Uniform angle (remap from -180.0f to 180.0f) used with multiple element enabled with Curve distribution. </summary>
public AnimationCurve uniformAngleCurve;
}
/// <summary> LensFlareDataSRP defines a Lens Flare with a set of LensFlareDataElementSRP </summary>
[PipelineHelpURL("UniversalRenderPipelineAsset", "urp/shared/lens-flare/lens-flare-asset")]
[PipelineHelpURL("HDRenderPipelineAsset", "shared/lens-flare/lens-flare-asset")]
[System.Serializable]
public sealed class LensFlareDataSRP : ScriptableObject
{
/// <summary> Initialize default value </summary>
public LensFlareDataSRP()
{
elements = null;
}
/// <summary>
/// Check if we have at last one 'modulatedByLightColor' enabled.
/// </summary>
/// <returns>true if we have at least one 'modulatedByLightColor' on the asset.</returns>
public bool HasAModulateByLightColorElement()
{
if (elements != null)
{
foreach (LensFlareDataElementSRP e in elements)
{
if (e.modulateByLightColor)
return true;
}
}
return false;
}
/// <summary> List of LensFlareDataElementSRP </summary>
public LensFlareDataElementSRP[] elements;
}
}
@@ -0,0 +1,24 @@
//
// This file was automatically generated. Please don't edit by hand. Execute Editor command [ Edit > Rendering > Generate Shader Includes ] instead
//
#ifndef LENSFLAREDATASRP_CS_HLSL
#define LENSFLAREDATASRP_CS_HLSL
//
// UnityEngine.Rendering.SRPLensFlareColorType: static fields
//
#define SRPLENSFLARECOLORTYPE_CONSTANT (0)
#define SRPLENSFLARECOLORTYPE_RADIAL_GRADIENT (1)
#define SRPLENSFLARECOLORTYPE_ANGULAR_GRADIENT (2)
//
// UnityEngine.Rendering.SRPLensFlareType: static fields
//
#define SRPLENSFLARETYPE_IMAGE (0)
#define SRPLENSFLARETYPE_CIRCLE (1)
#define SRPLENSFLARETYPE_POLYGON (2)
#define SRPLENSFLARETYPE_RING (3)
#define SRPLENSFLARETYPE_LENS_FLARE_DATA_SRP (4)
#endif
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9ee7f7178a92d554fa636bc513594ded
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 877e1507ae8d81c40bf1b94c1a86036f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: d7b90718ad2a7af4aab8546a0897d5db, type: 3}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
namespace UnityEngine.Rendering
{
[GenerateHLSL]
internal enum LensFlareOcclusionPermutation
{
Depth = (1 << 0),
FogOpacity = (1 << 2),
}
}
@@ -0,0 +1,14 @@
//
// This file was automatically generated. Please don't edit by hand. Execute Editor command [ Edit > Rendering > Generate Shader Includes ] instead
//
#ifndef LENSFLAREOCCLUSIONPERMUTATION_CS_HLSL
#define LENSFLAREOCCLUSIONPERMUTATION_CS_HLSL
//
// UnityEngine.Rendering.LensFlareOcclusionPermutation: static fields
//
#define LENSFLAREOCCLUSIONPERMUTATION_DEPTH (1)
#define LENSFLAREOCCLUSIONPERMUTATION_FOG_OPACITY (4)
#endif
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 81fe9e8731660404b8d68e384d6c03a9
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96120271267b5eb42bfbd64422b10352
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 86304ecf756376e4b8ecb6f9d6111b89
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,257 @@
///
/// FidelityFX Super Resolution (FSR) Common Shader Code
///
/// This file provides shader helper functions which are intended to be used with the C# helper functions in
/// FSRUtils.cs. The main purpose of this file is to simplify the usage of the external FSR shader functions within
/// the Unity shader environment.
///
/// Usage:
/// - Call SetXConstants function on a command buffer in C#
/// - Launch shader (via draw or dispatch)
/// - Call associated ApplyX function provided by this file
///
/// The following preprocessor parameters MUST be defined before including this file:
/// - FSR_INPUT_TEXTURE
/// - The texture to use as input for the FSR passes
/// - FSR_INPUT_SAMPLER
/// - The sample to use for FSR_INPUT_TEXTURE
///
/// The following preprocessor parameters are optional and MAY be defined before including this file:
/// - FSR_ENABLE_ALPHA
/// - Enables alpha pass-through functionality for the RCAS pass
///
// Ensure that the shader including this file is targeting an adequate shader level
#if SHADER_TARGET < 45
#error FidelityFX Super Resolution requires a shader target of 4.5 or greater
#endif
// Indicate that we'll be using the HLSL implementation of FSR
#define A_GPU 1
#define A_HLSL 1
// Enable either the 16-bit or the 32-bit implementation of FSR depending on platform support
// Note: There are known issues relating to the math approximation functions on some DX11 drivers when FP16 is used.
// Due to this issue, we currently prevent the 16-bit implementation from being used when DX11 is detected.
#if REAL_IS_HALF && !defined(SHADER_API_D3D11)
#define A_HALF
#define FSR_EASU_H 1
#define FSR_RCAS_H 1
#else
#define FSR_EASU_F 1
#define FSR_RCAS_F 1
#endif
// Enable the RCAS passthrough alpha feature when the alpha channel is in use
#if FSR_ENABLE_ALPHA
#define FSR_RCAS_PASSTHROUGH_ALPHA 1
#endif
// Include the external FSR HLSL files
#include "Packages/com.unity.render-pipelines.core/Runtime/PostProcessing/Shaders/ffx/ffx_a.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/PostProcessing/Shaders/ffx/ffx_fsr1.hlsl"
/// Bindings for FSR EASU constants provided by the CPU
///
/// Helper functions that set these constants can be found in FSRUtils
float4 _FsrEasuConstants0;
float4 _FsrEasuConstants1;
float4 _FsrEasuConstants2;
float4 _FsrEasuConstants3;
// Unity doesn't currently have a way to bind uint4 types so we reinterpret float4 as uint4 using macros below
#define FSR_EASU_CONSTANTS_0 asuint(_FsrEasuConstants0)
#define FSR_EASU_CONSTANTS_1 asuint(_FsrEasuConstants1)
#define FSR_EASU_CONSTANTS_2 asuint(_FsrEasuConstants2)
#define FSR_EASU_CONSTANTS_3 asuint(_FsrEasuConstants3)
/// EASU glue functions
///
/// These are used by the EASU implementation to access texture data
#if FSR_EASU_H
AH4 FsrEasuRH(AF2 p)
{
#ifdef FSR_CLAMP_COORD
p = FSR_CLAMP_COORD(p);
#endif
return (AH4)GATHER_RED_TEXTURE2D_X(FSR_INPUT_TEXTURE, FSR_INPUT_SAMPLER, p);
}
AH4 FsrEasuGH(AF2 p)
{
#ifdef FSR_CLAMP_COORD
p = FSR_CLAMP_COORD(p);
#endif
return (AH4)GATHER_GREEN_TEXTURE2D_X(FSR_INPUT_TEXTURE, FSR_INPUT_SAMPLER, p);
}
AH4 FsrEasuBH(AF2 p)
{
#ifdef FSR_CLAMP_COORD
p = FSR_CLAMP_COORD(p);
#endif
return (AH4)GATHER_BLUE_TEXTURE2D_X(FSR_INPUT_TEXTURE, FSR_INPUT_SAMPLER, p);
}
void FsrEasuProcessInput(inout AH4 r, inout AH4 g, inout AH4 b)
{
// HDRP only. URP use an upscaling pass before EASU pass where this operation can be done.
#ifdef HDR_INPUT
AH3 s0 = FastTonemap(AH3(r.x, g.x, b.x) * FSR_EASU_ONE_OVER_PAPER_WHITE);
AH3 s1 = FastTonemap(AH3(r.y, g.y, b.y) * FSR_EASU_ONE_OVER_PAPER_WHITE);
AH3 s2 = FastTonemap(AH3(r.z, g.z, b.z) * FSR_EASU_ONE_OVER_PAPER_WHITE);
AH3 s3 = FastTonemap(AH3(r.w, g.w, b.w) * FSR_EASU_ONE_OVER_PAPER_WHITE);
r = AH4(s0.r, s1.r, s2.r, s3.r);
g = AH4(s0.g, s1.g, s2.g, s3.g);
b = AH4(s0.b, s1.b, s2.b, s3.b);
#endif
}
#else
AF4 FsrEasuRF(AF2 p)
{
#ifdef FSR_CLAMP_COORD
p = FSR_CLAMP_COORD(p);
#endif
return GATHER_RED_TEXTURE2D_X(FSR_INPUT_TEXTURE, FSR_INPUT_SAMPLER, p);
}
AF4 FsrEasuGF(AF2 p)
{
#ifdef FSR_CLAMP_COORD
p = FSR_CLAMP_COORD(p);
#endif
return GATHER_GREEN_TEXTURE2D_X(FSR_INPUT_TEXTURE, FSR_INPUT_SAMPLER, p);
}
AF4 FsrEasuBF(AF2 p)
{
#ifdef FSR_CLAMP_COORD
p = FSR_CLAMP_COORD(p);
#endif
return GATHER_BLUE_TEXTURE2D_X(FSR_INPUT_TEXTURE, FSR_INPUT_SAMPLER, p);
}
void FsrEasuProcessInput(inout AF4 r, inout AF4 g, inout AF4 b)
{
// HDRP only. URP use an upscaling pass before EASU pass where this operation can be done.
#ifdef HDR_INPUT
#ifndef FSR_EASU_ONE_OVER_PAPER_WHITE
#error missing definition of FSR_EASU_ONE_OVER_PAPER_WHITE
#endif
float3 s0 = FastTonemap(float3(r.x, g.x, b.x) * FSR_EASU_ONE_OVER_PAPER_WHITE);
float3 s1 = FastTonemap(float3(r.y, g.y, b.y) * FSR_EASU_ONE_OVER_PAPER_WHITE);
float3 s2 = FastTonemap(float3(r.z, g.z, b.z) * FSR_EASU_ONE_OVER_PAPER_WHITE);
float3 s3 = FastTonemap(float3(r.w, g.w, b.w) * FSR_EASU_ONE_OVER_PAPER_WHITE);
r = float4(s0.r, s1.r, s2.r, s3.r);
g = float4(s0.g, s1.g, s2.g, s3.g);
b = float4(s0.b, s1.b, s2.b, s3.b);
#endif
}
#endif
/// Applies FidelityFX Super Resolution Edge Adaptive Spatial Upsampling at the provided pixel position
///
/// The source texture must be provided before this file is included via the FSR_INPUT_TEXTURE preprocessor symbol
/// Ex: #define FSR_INPUT_TEXTURE _SourceTex
///
/// A valid sampler must also be provided via the FSR_INPUT_SAMPLER preprocessor symbol
/// Ex: #define FSR_INPUT_SAMPLER sampler_LinearClamp
///
/// The color data stored in the source texture should be in gamma 2.0 color space
real3 ApplyEASU(uint2 positionSS)
{
#if FSR_EASU_H
// Execute 16-bit EASU
AH3 color;
FsrEasuH(
#else
// Execute 32-bit EASU
AF3 color;
FsrEasuF(
#endif
color, positionSS, FSR_EASU_CONSTANTS_0, FSR_EASU_CONSTANTS_1, FSR_EASU_CONSTANTS_2, FSR_EASU_CONSTANTS_3
);
return color;
}
/// Bindings for FSR RCAS constants provided by the CPU
///
/// Helper functions that set these constants can be found in FSRUtils
float4 _FsrRcasConstants;
// Unity doesn't currently have a way to bind uint4 types so we reinterpret float4 as uint4 using macros below
#define FSR_RCAS_CONSTANTS asuint(_FsrRcasConstants)
/// RCAS glue functions
///
/// These are used by the RCAS implementation to access texture data and perform color space conversion if necessary
#if FSR_RCAS_H
AH4 FsrRcasLoadH(ASW2 p)
{
return (AH4)LOAD_TEXTURE2D_X(FSR_INPUT_TEXTURE, p);
}
void FsrRcasInputH(inout AH1 r, inout AH1 g, inout AH1 b)
{
// No conversion to linear necessary since it's always performed during EASU output
}
#else
AF4 FsrRcasLoadF(ASU2 p)
{
return LOAD_TEXTURE2D_X(FSR_INPUT_TEXTURE, p);
}
void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b)
{
// No conversion to linear necessary since it's always performed during EASU output
}
#endif
/// Applies FidelityFX Super Resolution Robust Contrast Adaptive Sharpening at the provided pixel position
///
/// The source texture must be provided before this file is included via the FSR_INPUT_TEXTURE preprocessor symbol
/// Ex: #define FSR_INPUT_TEXTURE _SourceTex
///
/// A valid sampler must also be provided via the FSR_INPUT_SAMPLER preprocessor symbol
/// Ex: #define FSR_INPUT_SAMPLER sampler_LinearClamp
///
/// RCAS supports an optional alpha passthrough that can be enabled via the FSR_ENABLE_ALPHA preprocessor symbol
/// When passthrough is enabled, this function will return the input texture's alpha channel unmodified
///
/// The color data stored in the source texture should be in linear color space
#if FSR_ENABLE_ALPHA
real4 ApplyRCAS(uint2 positionSS)
#else
real3 ApplyRCAS(uint2 positionSS)
#endif
{
#if FSR_RCAS_H
// Execute 16-bit RCAS
#if FSR_ENABLE_ALPHA
AH4 color;
#else
AH3 color;
#endif
FsrRcasH(
#else
// Execute 32-bit RCAS
#if FSR_ENABLE_ALPHA
AF4 color;
#else
AF3 color;
#endif
FsrRcasF(
#endif
color.r,
color.g,
color.b,
#if FSR_ENABLE_ALPHA
color.a,
#endif
positionSS,
FSR_RCAS_CONSTANTS
);
return color;
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ee30e890854422d4c85fb895d34e2a53
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,621 @@
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Random.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/Sampling.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/PostProcessing/LensFlareDataSRP.cs.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/PostProcessing/LensFlareOcclusionPermutation.cs.hlsl"
struct AttributesLensFlare
{
uint vertexID : SV_VertexID;
#ifndef FLARE_PREVIEW
UNITY_VERTEX_INPUT_INSTANCE_ID
#endif
};
struct VaryingsLensFlare
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
float2 screenPos : TEXCOORD1;
#if defined(FLARE_HAS_OCCLUSION) || defined(FLARE_COMPUTE_OCCLUSION)
float occlusion : TEXCOORD2;
#endif
#ifndef FLARE_PREVIEW
UNITY_VERTEX_OUTPUT_STEREO
#endif
};
TEXTURE2D(_FlareTex);
SAMPLER(sampler_FlareTex);
TEXTURE2D(_FlareOcclusionRemapTex);
SAMPLER(sampler_FlareOcclusionRemapTex);
#if defined(FLARE_HAS_OCCLUSION)
TEXTURE2D_ARRAY(_FlareOcclusionTex);
SAMPLER(sampler_FlareOcclusionTex);
#endif
#ifdef HDRP_FLARE
uint _FlareOcclusionPermutation;
TEXTURE2D_X(_FlareSunOcclusionTex);
SAMPLER(sampler_FlareSunOcclusionTex);
#endif
float4 _FlareColorValue;
float4 _FlareData0; // x: localCos0, y: localSin0, zw: PositionOffsetXY
float4 _FlareData1; // x: OcclusionRadius, y: OcclusionSampleCount, z: ScreenPosZ, w: ScreenRatio
float4 _FlareData2; // xy: ScreenPos, zw: FlareSize
float4 _FlareData3; // x: Allow Offscreen, y: Edge Offset, z: Falloff, w: invSideCount
// For Ring:
// w: RingThickness
float4 _FlareData4; // x: SDF Roundness, y: Poly Radius, z: PolyParam0, w: PolyParam1
// For Ring:
// x: noiseAmplitude, y: noiseFrequency, z: noiseSparsity, w: noiseSpeed
float4 _FlareData5; // x: ConstantColor, y: Intensity, z: shapeCutOffSpeed, w: cutoffRadius
float4 _FlareData6; // x: LensFlareType, y: ElementIndex
TEXTURE2D(_FlareRadialTint);
SAMPLER(sampler_FlareRadialTint);
int _ViewId; // Used for XR index, for SinglePass and Multipass
#ifdef FLARE_PREVIEW
float4 _FlarePreviewData;
#define _ScreenSize _FlarePreviewData.xy;
#define _FlareScreenRatio _FlarePreviewData.z;
#endif
float4 _FlareOcclusionIndex;
#define _LocalCos0 _FlareData0.x
#define _LocalSin0 _FlareData0.y
#define _PositionTranslate _FlareData0.zw
// Vertex _FlareData1
#define _OcclusionRadius _FlareData1.x
#define _OcclusionSampleCount _FlareData1.y
#define _ScreenPosZ _FlareData1.z
#ifndef _FlareScreenRatio
#define _FlareScreenRatio _FlareData1.w
#endif
// Fragment _FlareData1
#define _FlareType ((int)_FlareData6.x)
#define _FlareElementIndex ((int)_FlareData6.y)
#define _ScreenPos _FlareData2.xy
#define _FlareSize _FlareData2.zw
#define _OcclusionOffscreen _FlareData3.x
#define _FlareEdgeOffset _FlareData3.y
#define _FlareFalloff _FlareData3.z
#define _FlareShapeInvSide _FlareData3.w
#define _FlareRingThickness _FlareData3.w
#define _FlareSDFRoundness _FlareData4.x
#define _FlareSDFPolyRadius _FlareData4.y
#define _FlareSDFPolyParam0 _FlareData4.z
#define _FlareSDFPolyParam1 _FlareData4.w
// For Ring only
#define _FlareNoiseAmplitude _FlareData4.x
#define _FlareNoiseFrequency _FlareData4.y
#define _FlareNoiseSpeed _FlareData4.z
#define _IsFlareColorRadial (_FlareData5.x == 1.0f)
#define _IsFlareColorAngular (_FlareData5.x == 2.0f)
#define _FlareIntensity _FlareData5.y
#define _FlareCutoffSpeed _FlareData5.z
#define _FlareCutoffRadius _FlareData5.w
void Rotate(out float2 rot, float2 v, float cos0, float sin0)
{
rot = float2(v.x * cos0 - v.y * sin0,
v.x * sin0 + v.y * cos0);
}
// Disables LOAD_TEXTURE2D_ARRAY_LOD-related implicit vector-truncation warnings.
#pragma warning (disable : 3206)
#if defined(FLARE_COMPUTE_OCCLUSION) || defined(FLARE_OPENGL3_OR_OPENGLCORE)
float GetLinearDepthValue(float2 uv)
{
float depth;
#if defined(HDRP_FLARE) || defined(FLARE_PREVIEW)
if (_ViewId >= 0)
{
depth = LOAD_TEXTURE2D_ARRAY_LOD(_CameraDepthTexture, uint2(uv * _ScreenSize.xy), _ViewId, 0).x;
}
else
{
depth = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, uint2(uv * _ScreenSize.xy), 0).x;
}
#else
depth = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, uint2(uv * GetScaledScreenParams().xy), 0).x;
if (_ViewId >= 0)
{
#if defined(DISABLE_TEXTURE2D_X_ARRAY)
// This should never happen in theory since _ViewId can only be >= 0 IF xr is enabled and so DISABLE_TEXTURE2D_X_ARRAY is disabled.
// We just have to manage the DISABLE_TEXTURE2D_X_ARRAY variant here for avoiding warnings.
// HDRP does not need this because it never uses DISABLE_TEXTURE2D_X_ARRAY.
depth = LOAD_TEXTURE2D_LOD(_CameraDepthTexture, int2(uv * GetScaledScreenParams().xy), 0).x;
#else
depth = LOAD_TEXTURE2D_ARRAY_LOD(_CameraDepthTexture, int2(uv * GetScaledScreenParams().xy), _ViewId, 0).x;
#endif
}
else
depth = LOAD_TEXTURE2D_X_LOD(_CameraDepthTexture, uint2(uv * GetScaledScreenParams().xy), 0).x;
#endif
if (unity_OrthoParams.w != 0.0)
return LinearEyeDepthOrtho(depth, _ProjectionParams.y, _ProjectionParams.z);
return LinearEyeDepth(depth, _ZBufferParams);
}
float GetOcclusion(float ratio)
{
if (_OcclusionSampleCount == 0.0f)
return 1.0f;
float contrib = 0.0f;
float sample_Contrib = 1.0f / _OcclusionSampleCount;
float2 ratioScale = float2(1.0f / ratio, 1.0);
for (uint i = 0; i < (uint)_OcclusionSampleCount; i++)
{
float2 dir = _OcclusionRadius * SampleDiskUniform(Hash(2 * i + 0), Hash(2 * i + 1));
float2 pos0 = _ScreenPos.xy + dir;
float2 pos = pos0 * 0.5f + 0.5f;
#ifdef UNITY_UV_STARTS_AT_TOP
pos.y = 1.0f - pos.y;
#endif
if (all(pos >= 0) && all(pos <= 1))
{
float depth0 = GetLinearDepthValue(pos);
if (depth0 > _ScreenPosZ)
{
float occlusionValue = 1.0f;
#ifdef HDRP_FLARE
if ((_FlareOcclusionPermutation & LENSFLAREOCCLUSIONPERMUTATION_FOG_OPACITY) != 0)
{
float fogOcclusion;
if (_ViewId >= 0)
fogOcclusion = SAMPLE_TEXTURE2D_ARRAY_LOD(_FlareSunOcclusionTex, sampler_FlareSunOcclusionTex, pos * _RTHandleScale.xy, _ViewId, 0).x;
else
fogOcclusion = SAMPLE_TEXTURE2D_X_LOD(_FlareSunOcclusionTex, sampler_FlareSunOcclusionTex, pos * _RTHandleScale.xy, 0).x;
occlusionValue *= saturate(fogOcclusion);
}
#endif
contrib += sample_Contrib * occlusionValue;
}
}
else if (_OcclusionOffscreen > 0.0f)
{
contrib += sample_Contrib;
}
}
contrib = SAMPLE_TEXTURE2D_LOD(_FlareOcclusionRemapTex, sampler_FlareOcclusionRemapTex, float2(saturate(contrib), 0.0f), 0).x;
contrib = saturate(contrib);
return contrib;
}
#endif
#if defined(FLARE_COMPUTE_OCCLUSION)
VaryingsLensFlare vertOcclusion(AttributesLensFlare input, uint instanceID : SV_InstanceID)
{
VaryingsLensFlare output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
#if defined(HDRP_FLARE) || defined(FLARE_PREVIEW)
float screenRatio = _FlareScreenRatio;
#else
float2 screenParam = GetScaledScreenParams().xy;
float screenRatio = screenParam.y / screenParam.x;
#endif
float2 quadPos = 2.0f * GetQuadVertexPosition(input.vertexID).xy - 1.0f;
float2 uv = GetQuadTexCoord(input.vertexID);
uv.x = 1.0f - uv.x;
output.positionCS.xy = quadPos;
output.texcoord.xy = uv;
output.positionCS.z = 1.0f;
output.positionCS.w = 1.0f;
float occlusion = GetOcclusion(screenRatio);
if (_OcclusionOffscreen < 0.0f && // No lens flare off screen
(any(_ScreenPos.xy < -1) || any(_ScreenPos.xy >= 1)))
occlusion = 0.0f;
output.occlusion = occlusion;
output.screenPos = output.positionCS.xy;
return output;
}
float4 fragOcclusion(VaryingsLensFlare input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return float4(input.occlusion.xxx, 1.0f);
}
#else
VaryingsLensFlare vert(AttributesLensFlare input, uint instanceID : SV_InstanceID)
{
VaryingsLensFlare output;
#ifndef FLARE_PREVIEW
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
#endif
#if defined(HDRP_FLARE) || defined(FLARE_PREVIEW)
float screenRatio = _FlareScreenRatio;
#else
float2 screenParam = GetScaledScreenParams().xy;
float screenRatio = screenParam.y / screenParam.x;
#endif
float4 posPreScale = float4(2.0f, 2.0f, 1.0f, 1.0f) * GetQuadVertexPosition(input.vertexID) - float4(1.0f, 1.0f, 0.0f, 0.0);
float2 uv = GetQuadTexCoord(input.vertexID);
uv.x = 1.0f - uv.x;
output.texcoord.xy = uv;
posPreScale.xy *= _FlareSize;
float2 local;
Rotate(local, posPreScale.xy, _LocalCos0, _LocalSin0);
local.x *= screenRatio;
output.positionCS.xy = local + _ScreenPos + _PositionTranslate;
output.positionCS.z = 1.0f;
output.positionCS.w = 1.0f;
#if defined(FLARE_HAS_OCCLUSION)
float occlusion;
if (_OcclusionOffscreen < 0.0f && // No lens flare off screen
(any(_ScreenPos.xy < -1.0f) || any(_ScreenPos.xy > 1.0f)))
{
occlusion = 0.0f;
}
else
{
#if defined(FLARE_OPENGL3_OR_OPENGLCORE)
#if defined(HDRP_FLARE) || defined(FLARE_PREVIEW)
float screenRatio = _FlareScreenRatio;
#else
float2 screenParam = GetScaledScreenParams().xy;
float screenRatio = screenParam.y / screenParam.x;
#endif
occlusion = GetOcclusion(screenRatio);
#else // defined(FLARE_OPENGL3_OR_OPENGLCORE)
if (_ViewId >= 0)
occlusion = LOAD_TEXTURE2D_ARRAY_LOD(_FlareOcclusionTex, uint2(_FlareOcclusionIndex.x, 0), _ViewId, 0).x;
else
occlusion = LOAD_TEXTURE2D_ARRAY_LOD(_FlareOcclusionTex, uint2(_FlareOcclusionIndex.x, 0), 0, 0).x;
#endif // defined(FLARE_OPENGL3_OR_OPENGLCORE)
}
output.occlusion = occlusion;
#endif
output.screenPos = output.positionCS.xy;
return output;
}
#endif
// Resets LOAD_TEXTURE2D_ARRAY_LOD-related implicit vector-truncation warnings.
#pragma warning (default : 3206)
// Constrains: x in [0.0f, 1.0f]
float InverseGradient(float x)
{
// Before:
// Do *not* simplify as 1.0f - x
//return x * (1.0f - x) / (x + eps);
// Kind of equivalent of (without the edge smoothness control):
//if (0.0f < x && x < 1.0f)
// return 1.0f - x;
//else
// return 0.0f;
// After:
// Larger eps give smoother boundary-edges
const float eps = 1e-3f;
// cf. https://www.desmos.com/calculator/0hprry9l90
// Rescale to always have the max at 1.0f;
//
// The max of 'x * (1.0f - x) / (x + eps)'
// Is when x == sqrt(eps (1 + eps)) - eps
// which is => 1 + 2*eps - 2*sqrt(eps*(1 + eps))
// We can rescale by scaling with 1/maxValue
// => x*(1 - x)/(x + eps)*(1/(1 + 2*eps - 2*sqrt(eps*(1 + eps))))
// Simplifed as:
// Compile-time variables:
const float eps2 = 2.0f * eps;
const float scale = 2.0f * sqrt(eps * (1.0f + eps));
const float a = scale - eps2 - 1.0f;
const float b = a * eps;
//return x * (x - 1.0f) / (a * x + b);
// to:
return mad(x, x, -x) * rcp(mad(a, x, b));
}
float CircleSDF(float2 center, float2 pos, float r)
{
return length(pos - center) - r;
}
float SDFBlocker(float2 pos, float2 screenPos, float ar, float r)
{
float2 localPos = _ScreenPos - screenPos;
localPos.y = -localPos.y;
float2 offset = localPos * _FlareCutoffSpeed;
float2 rot;
Rotate(rot, offset, _LocalCos0, _LocalSin0);
pos.y *= ar;
return CircleSDF(pos, rot, _FlareCutoffRadius * r);
}
float ComputeCircle(float2 uv, float2 screenPos)
{
float2 v = 2.0f * uv - 1.0f;
float radius = 1.0f;
float sdfBlocker = SDFBlocker(v, screenPos, _FlareSize.y / _FlareSize.x, radius);
float sdfSrc = CircleSDF(v, float2(0.0f, 0.0f), radius);
float sdf = max(sdfSrc, sdfBlocker);
sdf = saturate(sdf / ((_FlareEdgeOffset - radius)));
#if defined(FLARE_INVERSE_SDF)
sdf = saturate(sdf);
sdf = InverseGradient(sdf);
#endif
sdf = pow(saturate(sdf), _FlareFalloff);
return sdf;
}
// Modfied from ref: https://www.shadertoy.com/view/MtKcWW
// https://www.shadertoy.com/view/3tGBDt
float ComputePolygon(float2 uv_, float2 screenPos)
{
float2 v = 2.0f * uv_ - 1.0f;
float r = _FlareSDFPolyRadius;
float an = _FlareSDFPolyParam0;
float he = _FlareSDFPolyParam1;
float bn = an * floor((atan2(v.y, v.x) + 0.5f * an) / an);
float cos0 = cos(bn);
float sin0 = sin(bn);
float2 p = float2( cos0 * v.x + sin0 * v.y,
-sin0 * v.x + cos0 * v.y);
// side of polygon
float sdf = length(p - float2(r, clamp(p.y, -he, he))) * sign(p.x - r) - _FlareSDFRoundness;
float sdfBlocker = SDFBlocker(v, screenPos, _FlareSize.y / _FlareSize.x, r);
sdf = max(sdf, sdfBlocker);
sdf *= _FlareEdgeOffset;
#if defined(FLARE_INVERSE_SDF)
sdf = saturate(-sdf);
sdf = InverseGradient(sdf);
#else
sdf = saturate(-sdf);
#endif
sdf = pow(saturate(sdf), _FlareFalloff);
return sdf;
}
float4 Interpolation_C2_InterpAndDeriv(float2 x)
{
return x.xyxy * x.xyxy * (x.xyxy * (x.xyxy * (x.xyxy * float2(6.0f, 0.0f).xxyy + float2(-15.0f, 30.0f).xxyy) + float2(10.0f, -60.0f).xxyy) + float2(0.0f, 30.0f).xxyy);
}
// Generates a random number for each of the 4 cell corners
float4 NoiseHash2D(float2 gridcell)
{
float2 kOffset = float2(26.0f, 161.0f);
float kDomain = 71.0f;
float kLargeFloat = 1.0f / 951.135664f;
float4 P = float4(gridcell.xy, gridcell.xy + 1.0f);
P = P - floor(P * (1.0f / kDomain)) * kDomain; // truncate the domain
P += kOffset.xyxy; // offset to interesting part of the noise
P *= P; // calculate and return the hash
return frac(P.xzxz * P.yyww * kLargeFloat);
}
float GenerateValueNoise2D(float2 coordinate)
{
float2 i = floor(coordinate);
float2 f = coordinate - i;
float4 hash = NoiseHash2D(i);
float4 blend = Interpolation_C2_InterpAndDeriv(f);
float4 res0 = lerp(hash.xyxz, hash.zwyw, blend.yyxx);
float2 resDelta = res0.yw - res0.xz;
float noise = res0.x + resDelta.x * blend.x;
return noise;
}
float ComputeRing(float2 uv_, float2 screenPos)
{
float2 pos = 2.0f * uv_ - 1.0f;
#ifndef FLARE_PREVIEW
float iTime = _Time.y;
#else
float iTime = 0;
#endif
float r = 1.0f;
float ang = FastAtan2(pos.y, pos.x);
float2 sc;
float noiseAng = ang * _FlareNoiseFrequency;
sincos(noiseAng, sc.x, sc.y);
float noise = abs(abs(GenerateValueNoise2D(_FlareNoiseAmplitude * sc + _FlareElementIndex.xx + _FlareNoiseSpeed * iTime)));
float sdfBlocker = CircleSDF(pos, float2(0.0f, 0.0f), r);
float sdf;
sdf = abs(CircleSDF(pos, 0.0f.xx, (1.0f - _FlareRingThickness))) - _FlareRingThickness;
sdf = max(noise * sdf, sdfBlocker);
sdf = saturate(sdf / ((_FlareEdgeOffset - r)));
#if defined(FLARE_INVERSE_SDF)
sdf = saturate(sdf);
sdf = InverseGradient(sdf);
#endif
sdf = pow(saturate(sdf), _FlareFalloff);
float sdfBlockerCutoff = SDFBlocker(pos, screenPos, _FlareSize.y / _FlareSize.x, 1.0f);
sdf *= saturate(-sdfBlockerCutoff > 0.0f);
return sdf;
}
float4 GetFlareShape(float2 uv, float2 screenPos)
{
float4 flareColor = 1.0f;
float shape;
if (_FlareType == SRPLENSFLARETYPE_CIRCLE)
shape = ComputeCircle(uv, screenPos);
else if (_FlareType == SRPLENSFLARETYPE_POLYGON)
shape = ComputePolygon(uv, screenPos);
else if (_FlareType == SRPLENSFLARETYPE_RING)
shape = ComputeRing(uv, screenPos);
else if (_FlareType == SRPLENSFLARETYPE_IMAGE)
{
shape = 1.0f;
flareColor = SAMPLE_TEXTURE2D(_FlareTex, sampler_FlareTex, uv);
float sdfBlocker = SDFBlocker(2.0f * uv - 1.0f, screenPos, _FlareSize.y / _FlareSize.x, 1.0f);
flareColor *= saturate(-sdfBlocker > 0.0f);
}
else
{
// Not possible, if the code execute this lines, we have a bug on the code
// SRPLENSFLARETYPE_LENS_FLARE_DATA_SRP should never be executed
shape = -1.0f;
}
#if defined(HDRP_FLARE) || defined(FLARE_PREVIEW)
float screenRatio = _FlareScreenRatio;
#else
float2 screenParam = GetScaledScreenParams().xy;
float screenRatio = screenParam.y / screenParam.x;
#endif
float2 pos = 2.0f * uv - 1.0f;
if (_IsFlareColorRadial)
{
float radius = length(pos);
if (_FlareType == SRPLENSFLARETYPE_RING)
{
float offset = 1.0f - _FlareRingThickness;
float a = (1.0f / clamp(2.0f * _FlareRingThickness, _FlareRingThickness, 1.0f));
float b = 1.0f - a;
radius = saturate(a * radius + b);
}
float4 grad = SAMPLE_TEXTURE2D_LOD(_FlareRadialTint, sampler_FlareRadialTint, float2(saturate(radius), 0.0f), 0);
flareColor *= grad;
}
else if (_IsFlareColorAngular)
{
float angle01 = (atan2(pos.y, pos.x) + PI) / TWO_PI;
float4 grad = SAMPLE_TEXTURE2D_LOD(_FlareRadialTint, sampler_FlareRadialTint, float2(saturate(angle01), 0.0f), 0);
flareColor *= grad;
}
flareColor *= _FlareColorValue;
flareColor.rgb *= _FlareIntensity;
#ifdef FLARE_ADDITIVE_BLEND
float4 finalValue = float4(flareColor.rgb * shape, shape * flareColor.a);
#elif defined(FLARE_SCREEN_BLEND)
float4 finalValue = float4(flareColor.rgb * shape, shape * flareColor.a);
#elif defined(FLARE_PREMULTIPLIED_BLEND)
float4 finalValue = float4(flareColor.rgb * shape, shape * flareColor.a);
#elif defined(FLARE_LERP_BLEND)
float4 finalValue = float4(flareColor.rgb, shape * flareColor.a);
#else
float4 finalValue = flareColor * shape;
#endif
return finalValue;
}
float4 frag(VaryingsLensFlare input) : SV_Target
{
#ifndef FLARE_PREVIEW
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
#endif
#if defined(FLARE_HAS_OCCLUSION)
if (input.occlusion > 0.0f)
{
float4 col = GetFlareShape(input.texcoord, input.screenPos.xy);
return col * input.occlusion;
}
else
{
return float4(0.0f, 0.0f, 0.0f, 0.0f);
}
#else
float4 col = GetFlareShape(input.texcoord, input.screenPos.xy);
return col;
#endif
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a279154a65cb87e46a9922aeaf9b7bc4
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,438 @@
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Random.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Sampling/Sampling.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ScreenCoordOverride.hlsl"
TEXTURE2D(_LensFlareScreenSpaceSpectralLut);
TEXTURE2D_X(_LensFlareScreenSpaceStreakTex);
TEXTURE2D_X(_LensFlareScreenSpaceBloomMipTexture);
TEXTURE2D_X(_LensFlareScreenSpaceResultTexture);
float4 _LensFlareScreenSpaceBloomMipTexture_TexelSize;
float4 _LensFlareScreenSpaceStreakTex_TexelSize;
float4 _LensFlareScreenSpaceParams1;
float4 _LensFlareScreenSpaceParams2;
float4 _LensFlareScreenSpaceParams3;
float4 _LensFlareScreenSpaceParams4;
float4 _LensFlareScreenSpaceParams5;
int _LensFlareScreenSpaceMipLevel;
float3 _LensFlareScreenSpaceTintColor;
#define LensFlareScreenSpaceIntensity _LensFlareScreenSpaceParams1.x
#define LensFlareScreenSpaceFirstIntensity _LensFlareScreenSpaceParams1.y
#define LensFlareScreenSpaceSecondaryIntensity _LensFlareScreenSpaceParams1.z
#define LensFlareScreenSpacePolarIntensity _LensFlareScreenSpaceParams1.w
#define LensFlareScreenSpaceVignetteIntensity _LensFlareScreenSpaceParams2.x
#define LensFlareScreenSpaceStartingPosition _LensFlareScreenSpaceParams2.y
#define LensFlareScreenSpaceScale _LensFlareScreenSpaceParams2.z
#define LensFlareScreenSpaceCount _LensFlareScreenSpaceParams3.x
#define LensFlareScreenSpaceCountDimmer _LensFlareScreenSpaceParams3.y
#define LensFlareScreenSpaceChromaIntensity _LensFlareScreenSpaceParams3.z
#define LensFlareScreenSpaceChromaSample _LensFlareScreenSpaceParams3.w
#define LensFlareScreenSpaceStreakIntensity _LensFlareScreenSpaceParams4.x
#define LensFlareScreenSpaceStreakLength _LensFlareScreenSpaceParams4.y
#define LensFlareScreenSpaceStreakOrientation _LensFlareScreenSpaceParams4.z
#define LensFlareScreenSpaceStreakThreshold _LensFlareScreenSpaceParams4.w
#define LensFlareScreenSpaceRatio _LensFlareScreenSpaceParams5.x
#define LensFlareScreenSpaceWarpedScaleX _LensFlareScreenSpaceParams5.y
#define LensFlareScreenSpaceWarpedScaleY _LensFlareScreenSpaceParams5.z
#define REGULAR_FLARE_MULTIPLIER 0.1
#define STREAK_FLARE_MULTIPLIER 1
struct AttributesSSLF
{
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VaryingsSSLF
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
float2 GetAnamorphism()
{
float f = frac(LensFlareScreenSpaceStreakOrientation);
bool even = ((floor(LensFlareScreenSpaceStreakOrientation) % 2) == 0);
float x = even ? -(1.0 - f) : -(1.0 - (1.0 - f));
float y = even ? f : -(1.0 - f);
return float2(x, y);
}
float map01To(float value, float min, float max)
{
return (max - min) * (value - 0.5);
}
float map01(float value, float min, float max)
{
float r = rcp(max - min);
return Remap01(value, r, min * r);
}
float2 scaleUV(float2 uv, float2 center, float scale, bool invert, bool polar)
{
if (polar)
{
scale = rcp(scale);
// Correctly map the UV before doing polar conversion
uv = float2(LensFlareScreenSpaceWarpedScaleX * map01To(uv.x, -scale, scale), LensFlareScreenSpaceWarpedScaleY * map01To(uv.y, -scale, scale));
// Polar coordinate conversion
float x = SafeSqrt(SafePositivePow(uv.x, 2) + SafePositivePow(uv.y, 2));
float x1 = map01(x, 0.0, sqrt(2.0));
float y = FastAtan2(uv.x, uv.y);
float y1 = 1.0 - map01(y, -PI, PI);
uv = float2(y1, invert ? (1.0 - x1) : x1);
}
else
{
// First, we substract the center before scaling
uv -= center;
uv *= 1.0 / scale;
// Then, we add center back
uv += center;
if (invert)
{
uv = 1.0 - uv;
}
}
return uv;
}
float3 GetFlareTexture(float2 uv, float scale, float intensity, bool polar, bool regularFlarePass)
{
bool invert = scale < 0.0;
bool distortUV = (scale != 1 || polar);
float signScale = sign(scale);
bool chromaticAberration = (LensFlareScreenSpaceChromaIntensity > 0);
//Chromatic
float2 coords = 2.0 * uv - 1.0;
float2 end = uv - coords * dot(coords, coords) * LensFlareScreenSpaceChromaIntensity;
float2 diff = end - uv;
if (distortUV)
uv = scaleUV(uv, float2(0.5, 0.5), abs(scale), invert, polar);
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
// HDRP Implementation taken from UberPost shader
int samples = 1;
if (chromaticAberration)
{
samples = int(length(_PostProcessScreenSize.xy * diff / 2.0));
samples = clamp(samples, 3, (int)LensFlareScreenSpaceChromaSample);
}
float2 delta = diff / samples;
float3 sum = 0.0;
float3 filterSum = 0.0;
float3 filter = 0.0;
for (int i = 0; i < samples; i++)
{
float3 s = 0.0;
// Depending on if we are computing regular flares or streaks, we sample a different texture.
if (regularFlarePass)
{
s = SAMPLE_TEXTURE2D_X_LOD(_LensFlareScreenSpaceBloomMipTexture, s_linear_clamp_sampler, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(uv)), 0.0).xyz;
}
else
{
s = SAMPLE_TEXTURE2D_X_LOD(_LensFlareScreenSpaceStreakTex, s_linear_clamp_sampler, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(uv)), 0.0).xyz;
}
s *= _LensFlareScreenSpaceTintColor;
UNITY_BRANCH
if (chromaticAberration)
{
float t = (i + 0.5) / samples;
filter = SAMPLE_TEXTURE2D_LOD(_LensFlareScreenSpaceSpectralLut, s_linear_clamp_sampler, saturate(float2(t, 0.0)), 0.0).xyz;
}
else
{
filter = 1.0;
}
sum += s * filter;
filterSum += filter;
uv += signScale * delta;
}
float3 result = sum / filterSum;
#endif
#if defined (URP_LENS_FLARE_SCREEN_SPACE)
// Taken from URP UberPost Implementation
float3 result = 0.0;
// If chromaticAberration Intenisty is zero, we do only one sample.
if (chromaticAberration)
{
diff = diff / 3.0;
float r, g, b;
if (regularFlarePass)
{
r = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceBloomMipTexture, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uv), _LensFlareScreenSpaceBloomMipTexture_TexelSize.xy) ).x;
g = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceBloomMipTexture, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS((diff + uv)), _LensFlareScreenSpaceBloomMipTexture_TexelSize.xy) ).y;
b = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceBloomMipTexture, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS((diff * 2.0 + uv)), _LensFlareScreenSpaceBloomMipTexture_TexelSize.xy)).z;
}
else
{
r = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceStreakTex, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uv)) ).x;
g = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceStreakTex, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS((diff + uv)) )).y;
b = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceStreakTex, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS((diff * 2.0 + uv)))).z;
}
result = float3(r, g, b);
}
else
{
if (regularFlarePass)
{
result = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceBloomMipTexture, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uv))).xyz;
}
else
{
result = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceStreakTex, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uv))).xyz;
}
}
result *= _LensFlareScreenSpaceTintColor;
#endif
return result * intensity;
}
VaryingsSSLF vert(AttributesSSLF input)
{
VaryingsSSLF output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float4 positionCS = float4(2.0, 2.0, 1.0, 1.0) * GetQuadVertexPosition(input.vertexID) - float4(1.0, 1.0, 0.0, 0.0);
float2 uv = GetQuadTexCoord(input.vertexID);
uv.y = 1.0 - uv.y;
output.positionCS = positionCS;
output.texcoord = uv;
return output;
}
// Prefilter: Shrink horizontally and apply threshold.
float4 FragmentPrefilter(VaryingsSSLF input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
uv /= _RTHandlePostProcessScale.xy;
#endif
float dy = GetAnamorphism().x * _LensFlareScreenSpaceBloomMipTexture_TexelSize.y;
float dx = GetAnamorphism().y * _LensFlareScreenSpaceBloomMipTexture_TexelSize.x;
float2 u0 = saturate(float2(uv.x - dx, uv.y - dy));
float2 u1 = saturate(float2(uv.x + dx, uv.y + dy));
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
float3 c0 = SAMPLE_TEXTURE2D_X_LOD(_LensFlareScreenSpaceBloomMipTexture, s_linear_clamp_sampler, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(u0)), 0.0).xyz;
float3 c1 = SAMPLE_TEXTURE2D_X_LOD(_LensFlareScreenSpaceBloomMipTexture, s_linear_clamp_sampler, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(u1)), 0.0).xyz;
#endif
#if defined (URP_LENS_FLARE_SCREEN_SPACE)
float3 c0 = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceBloomMipTexture, sampler_LinearClamp, ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(u0), _LensFlareScreenSpaceBloomMipTexture_TexelSize.xy)).xyz;
float3 c1 = SAMPLE_TEXTURE2D_X(_LensFlareScreenSpaceBloomMipTexture, sampler_LinearClamp, ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(u1), _LensFlareScreenSpaceBloomMipTexture_TexelSize.xy)).xyz;
#endif
float3 c = (c0 + c1) / 2.0;
float br = max(c.r, max(c.g, c.b));
c *= max(br - LensFlareScreenSpaceStreakThreshold, 0.0) / max(br, 1e-4);
return float4(c, 1.0);
}
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
float3 SampleScaled(TEXTURE2D_X(tex), float2 uv)
{
return SAMPLE_TEXTURE2D_X(tex, s_linear_clamp_sampler, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(uv))).xyz;
}
#endif
#if defined (URP_LENS_FLARE_SCREEN_SPACE)
float3 SampleScaled(TEXTURE2D_X(tex), float2 uv)
{
return SAMPLE_TEXTURE2D_X(tex, sampler_LinearClamp, ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uv))).xyz;
}
#endif
//Downsampler Pass
float4 FragmentDownsample(VaryingsSSLF input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord.xy;
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
uv /= _RTHandlePostProcessScale.xy;
#endif
float dy = GetAnamorphism().y * _LensFlareScreenSpaceStreakTex_TexelSize.y * LensFlareScreenSpaceStreakLength * ((float)_LensFlareScreenSpaceMipLevel + 1.0) / LensFlareScreenSpaceRatio;
float dx = GetAnamorphism().x * _LensFlareScreenSpaceStreakTex_TexelSize.x * LensFlareScreenSpaceStreakLength * ((float)_LensFlareScreenSpaceMipLevel + 1.0) / LensFlareScreenSpaceRatio;
float2 u0 = saturate(float2(uv.x - dx * 5.0, uv.y - dy * 5.0));
float2 u1 = saturate(float2(uv.x - dx * 3.0, uv.y - dy * 3.0));
float2 u2 = saturate(float2(uv.x - dx * 1.0, uv.y - dy * 1.0));
float2 u3 = saturate(float2(uv.x + dx * 1.0, uv.y + dy * 1.0));
float2 u4 = saturate(float2(uv.x + dx * 3.0, uv.y + dy * 3.0));
float2 u5 = saturate(float2(uv.x + dx * 5.0, uv.y + dy * 5.0));
float3 c0 = 1.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u0) / 12.0;
float3 c1 = 2.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u1) / 12.0;
float3 c2 = 3.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u2) / 12.0;
float3 c3 = 3.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u3) / 12.0;
float3 c4 = 2.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u4) / 12.0;
float3 c5 = 1.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u5) / 12.0;
return float4((c0 + c1 + c2 + c3 + c4 + c5), 1.0);
}
//Upsampler Pass
float4 FragmentUpsample(VaryingsSSLF input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
uv /= _RTHandlePostProcessScale.xy;
#endif
float dy = GetAnamorphism().y * _LensFlareScreenSpaceStreakTex_TexelSize.y * LensFlareScreenSpaceStreakLength * 1.5 * ((float)_LensFlareScreenSpaceMipLevel + 1.0) / LensFlareScreenSpaceRatio;
float dx = GetAnamorphism().x * _LensFlareScreenSpaceStreakTex_TexelSize.x * LensFlareScreenSpaceStreakLength * 1.5 * ((float)_LensFlareScreenSpaceMipLevel + 1.0) / LensFlareScreenSpaceRatio;
float2 u0 = saturate(float2(uv.x - dx, uv.y - dy));
float2 u1 = saturate(float2(uv.x, uv.y));
float2 u2 = saturate(float2(uv.x + dx, uv.y + dy));
float3 c0 = 1.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u0) / 4.0;
float3 c1 = 2.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u1) / 4.0;
float3 c2 = 1.0 * SampleScaled(_LensFlareScreenSpaceStreakTex, u2) / 4.0;
return float4(c0 + c1 + c2, 1.0);
}
// Final composition
float4 FragmentComposition(VaryingsSSLF input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
float3 streakFlare = 0.0;
float3 regularFlare = 0.0;
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
uv /= _RTHandlePostProcessScale.xy;
#endif
// Streaks
if (LensFlareScreenSpaceStreakIntensity > 0.0)
{
streakFlare = GetFlareTexture(uv, 1, LensFlareScreenSpaceStreakIntensity * STREAK_FLARE_MULTIPLIER, false, false);
}
// Vignette Parameters
float vignettePow = 2.0;
float vignetteScale = 1.0;
float vignetteSquaredness = 2.0; // 1.0 and lower means more star shaped, 2.0 ellipsis, above more squared
// Vignette textures
float2 uvVignette = scaleUV(uv, float2(0.5, 0.5), vignetteScale, false, false);
float vignetteX = saturate(SafePositivePow(abs(2.0 * uvVignette.x - 1.0), (vignetteSquaredness)));
float vignetteY = saturate(SafePositivePow(abs(2.0 * uvVignette.y - 1.0), (vignetteSquaredness)));
float vignetteRound = saturate(SafePositivePow((vignetteX + vignetteY), (vignettePow)));
// Texture to have flares only on the edges of the screen
vignetteRound = lerp(1, vignetteRound, LensFlareScreenSpaceVignetteIntensity);
// Regular Flare
if (LensFlareScreenSpaceIntensity > 0.0)
{
float3 classic = 0.0;
float3 classicInv = 0.0;
float3 polarInv = 0.0;
// The scale of the texture scales with (index + start)^scale
for (int i = 0; i < LensFlareScreenSpaceCount; ++i)
{
float scale = SafePositivePow(abs((i + LensFlareScreenSpaceStartingPosition)), LensFlareScreenSpaceScale);
float currentSampleDimmer = SafePositivePow(LensFlareScreenSpaceCountDimmer, i);
if (LensFlareScreenSpaceSecondaryIntensity > 0.0)
{
classic += GetFlareTexture(uv, -scale, LensFlareScreenSpaceSecondaryIntensity * REGULAR_FLARE_MULTIPLIER * currentSampleDimmer, false, true);
}
if (LensFlareScreenSpaceFirstIntensity > 0.0)
{
classicInv += GetFlareTexture(uv, scale, LensFlareScreenSpaceFirstIntensity * REGULAR_FLARE_MULTIPLIER * currentSampleDimmer, false, true);
}
if (LensFlareScreenSpacePolarIntensity > 0.0)
{
polarInv += GetFlareTexture(uv, -scale, LensFlareScreenSpacePolarIntensity * REGULAR_FLARE_MULTIPLIER * currentSampleDimmer, true, true);
}
}
// Compositing
regularFlare += (classicInv + classic) * vignetteRound; // VignetteRound is to avoid having flare in the middle of the screen.
regularFlare += polarInv * vignetteX; // VignetteX is to prevent discontinuities because polar doesn't tile properly.
}
float4 final = float4(regularFlare + streakFlare, 1.0);
final *= LensFlareScreenSpaceIntensity;
return final;
}
// Write Result to Bloom
real4 FragmentWrite(VaryingsSSLF input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
#if defined (HDRP_LENS_FLARE_SCREEN_SPACE)
uv /= _RTHandlePostProcessScale.xy;
#endif
return float4(SampleScaled(_LensFlareScreenSpaceResultTexture, uv), 1.0);
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: afe55daff42455e4eb6a40e34678a418
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: badda61a05436ff46bc63d5e3182a197
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e3711cae0eaec834eb4ae197be7dd569
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2a9d148fab2695346824a766e925a31f
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2a92c8c54bb0f63458be93b670c77c3b
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,854 @@
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
//
// [LPM] LUMA PRESERVING MAPPER 1.20190521
//
//==============================================================================================================================
// LICENSE
// =======
// Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved.
// -------
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// -------
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
// -------
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//------------------------------------------------------------------------------------------------------------------------------
// ABOUT
// =====
// For questions and comments, feel free to contact the author directly: timothy.lottes@amd.com
// LPM is an evoluation of the concepts in "A Blend of GCN Optimisation and Colour Processing" from GDC 2019.
// This presentation can be found here: https://gpuopen.com/gdc-2019-presentation-links/
// Changes from the GDC 2019 presentation,
// (a.) Switched from using LUTs to doing the full mapping in ALU.
// This was made possible by changing the algorithm used to "walk back in gamut".
// There is no longer any need for "Fast" vs "Quality" modes.
// While the prior "Quality" mode had good precision for luma, chroma precision was relatively poor.
// Specifically having only 32 steps in the LUT wasn't enough to do a great job on the overexposure color shaping.
// The ALU version has great precision, while being much easier to integrate and tune.
// Likewise as most GPU workloads are not ALU-bound, this ALU version should be better for async integration.
// (b.) Moved to only one step of "walk back in gamut" done towards the end of the mapper (not necessary to do twice).
// (c.) Introduced a secondary optional matrix multiply conversion at the end (better for small to large gamut cases, etc).
//------------------------------------------------------------------------------------------------------------------------------
// FP16 PRECISION LIMITS
// =====================
// LPM supports a packed FP16 fast path.
// The lowest normal FP16 value is 2^-14 (or roughly 0.000061035).
// Converting this linear value to sRGB with input range {0 to 1} scaled {0 to 255} on output produces roughly 0.2.
// Maybe enough precision to convert for 8-bit, but not enough working precision for accumulating lighting.
// Converting 2^-14 to Gamma 2.2 with input range {0 to 1} scaled to {0 to 255} on output produces roughly 3.1.
// Not enough precision in normals values, depending on denormals for near zero precision.
//------------------------------------------------------------------------------------------------------------------------------
// TUNING THE CROSSTALK VALUE
// ==========================
// The crosstalk value shapes how color over-exposes.
// Suggest tuning the crosstalk value to get the look and feel desired by the content author.
// Here is the intuition on how to tune the crosstalk value passed into LpmSetup().
// Start with {1.0,1.0,1.0} -> this will fully desaturate on over-exposure (not good).
// Start reducing the blue {1.0,1.0,1.0/8.0} -> tint towards yellow on over-exposure (medium maintaining saturation).
// Reduce blue until the red->yellow->white transition is good {1.0,1.0,1.0/16.0} -> maintaining good saturation.
// It is possible to go extreme to {1.0,1.0,1.0/128.0} -> very high saturation on over-exposure (yellow tint).
// Then reduce red a little {1.0/2.0,1.0,1.0/32.0} -> to tint blues towards cyan on over-exposure.
// Or reduce green a little {1.0,1.0/2.0,1.0/32.0} -> to tint blues towards purple on over-exposure.
// If wanting a stronger blue->purple, drop both green and blue {1.0,1.0/4.0,1.0/128.0}.
// Note that crosstalk value should be tuned differently based on the color space.
// Suggest tuning crosstalk separately for Rec.2020 and Rec.709 primaries for example.
//------------------------------------------------------------------------------------------------------------------------------
// SETUP THE MAPPER
// ================
// This would typically be done on the CPU, but showing the GPU code here.
// ...
// // Setup the control block.
// AU4 map0,map1,map2,map3,map4,map5,map6,map7,map8,map9,mapA,mapB,
// AU4 mapC,mapD,mapE,mapF,mapG,mapH,mapI,mapJ,mapK,mapL,mapM,mapN;
// LpmSetup(
// map0,map1,map2,map3,map4,map5,map6,map7,map8,map9,mapA,mapB,
// mapC,mapD,mapE,mapF,mapG,mapH,mapI,mapJ,mapK,mapL,mapM,mapN,
// false,LPM_CONFIG_709_709,LPM_COLORS_709_709, // <-- Using the LPM_ prefabs to make inputs easier.
// 0.0, // softGap
// 256.0, // hdrMax
// 8.0, // exposure
// 0.25, // contrast
// 1.0, // shoulder contrast
// AF3_(0.0), // saturation
// AF3(1.0,1.0/2.0,1.0/32.0)); // crosstalk
// ...
// // Store the control block to ubo/ssbo buffer (this requires 0 through N to be stored).
// constants.map0=map0;
// constants.map1=map1;
// constants.map2=map2;
// ...
// constants.mapM=mapM;
// constants.mapN=mapN;
//------------------------------------------------------------------------------------------------------------------------------
// RUNNING THE MAPPER ON COLOR
// ===========================
// This part would be running per-pixel on the GPU.
// This is showing the no 'shoulder' adjustment fast path.
// ...
// #include "ffx_a.h"
// #include "ffx_lpm.h"
// ...
// // Fetch the control block (this requires 0 through N to be loaded, some of this will get dead-code removed).
// AU4 map0,map1,map2,map3,map4,map5,map6,map7,map8,map9,mapA,mapB,
// AU4 mapC,mapD,mapE,mapF,mapG,mapH,mapI,mapJ,mapK,mapL,mapM,mapN;
// map0=constants.map0;
// map1=constants.map1;
// map2=constants.map2;
// ...
// mapM=constants.mapM;
// mapN=constants.mapN;
// ...
// // Run the tone/gamut-mapper.
// // The 'c.rgb' is the color to map, using the no-shoulder tuning option.
// LpmFilter(c.r,c.g,c.b,false,LPM_CONFIG_709_709, // <-- Using the LPM_CONFIG_ prefab to make inputs easier.
// map0,map1,map2,map3,map4,map5,map6,map7,map8,map9,mapA,mapB,
// mapC,mapD,mapE,mapF,mapG,mapH,mapI,mapJ,mapK,mapL,mapM,mapN);
// ...
// // Do the final linear to non-linear transform.
// c.r=AToSrgbF1(c.r);
// c.g=AToSrgbF1(c.g);
// c.b=AToSrgbF1(c.b);
//------------------------------------------------------------------------------------------------------------------------------
// CHANGE LOG
// ==========
// 20190521 - Updated file naming.
// 20190425 - Initial GPU-only ALU-only prototype code drop (working 32-bit and 16-bit paths).
//==============================================================================================================================
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
//
// CPU
//
//==============================================================================================================================
#ifdef A_CPU
// TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
//
// GPU
//
//==============================================================================================================================
#ifdef A_GPU
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// HELPER CODE
//------------------------------------------------------------------------------------------------------------------------------
// Used by LpmSetup() to build constants for the GPU setup path.
//------------------------------------------------------------------------------------------------------------------------------
// Color math references,
// - http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
// - https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_.28.22gamma.22.29
// - http://www.ryanjuckett.com/programming/rgb-color-space-conversion/
//==============================================================================================================================
// Low-precision solution.
void LpmMatInv3x3(out AF3 ox,out AF3 oy,out AF3 oz,in AF3 ix,in AF3 iy,in AF3 iz){
AF1 i=1.0/(ix.x*(iy.y*iz.z-iz.y*iy.z)-ix.y*(iy.x*iz.z-iy.z*iz.x)+ix.z*(iy.x*iz.y-iy.y*iz.x));
ox=AF3((iy.y*iz.z-iz.y*iy.z)*i,(ix.z*iz.y-ix.y*iz.z)*i,(ix.y*iy.z-ix.z*iy.y)*i);
oy=AF3((iy.z*iz.x-iy.x*iz.z)*i,(ix.x*iz.z-ix.z*iz.x)*i,(iy.x*ix.z-ix.x*iy.z)*i);
oz=AF3((iy.x*iz.y-iz.x*iy.y)*i,(iz.x*ix.y-ix.x*iz.y)*i,(ix.x*iy.y-iy.x*ix.y)*i);}
//------------------------------------------------------------------------------------------------------------------------------
// Transpose.
void LpmMatTrn3x3(out AF3 ox,out AF3 oy,out AF3 oz,in AF3 ix,in AF3 iy,in AF3 iz){
ox=AF3(ix.x,iy.x,iz.x);oy=AF3(ix.y,iy.y,iz.y);oz=AF3(ix.z,iy.z,iz.z);}
//------------------------------------------------------------------------------------------------------------------------------
void LpmMatMul3x3(out AF3 ox,out AF3 oy,out AF3 oz,in AF3 ax,in AF3 ay,in AF3 az,in AF3 bx,in AF3 by,in AF3 bz){
AF3 bx2,by2,bz2;LpmMatTrn3x3(bx2,by2,bz2,bx,by,bz);
ox=AF3(dot(ax,bx2),dot(ax,by2),dot(ax,bz2));
oy=AF3(dot(ay,bx2),dot(ay,by2),dot(ay,bz2));
oz=AF3(dot(az,bx2),dot(az,by2),dot(az,bz2));}
//------------------------------------------------------------------------------------------------------------------------------
// D65 xy coordinates.
AF2 lpmColD65=AF2(0.3127,0.3290);
//------------------------------------------------------------------------------------------------------------------------------
// Rec709 xy coordinates, (D65 white point).
AF2 lpmCol709R=AF2(0.64,0.33);
AF2 lpmCol709G=AF2(0.30,0.60);
AF2 lpmCol709B=AF2(0.15,0.06);
//------------------------------------------------------------------------------------------------------------------------------
// DCI-P3 xy coordinates, (D65 white point).
AF2 lpmColP3R=AF2(0.680,0.320);
AF2 lpmColP3G=AF2(0.265,0.690);
AF2 lpmColP3B=AF2(0.150,0.060);
//------------------------------------------------------------------------------------------------------------------------------
// Rec2020 xy coordinates, (D65 white point).
AF2 lpmCol2020R=AF2(0.708,0.292);
AF2 lpmCol2020G=AF2(0.170,0.797);
AF2 lpmCol2020B=AF2(0.131,0.046);
//------------------------------------------------------------------------------------------------------------------------------
// Computes z from xy, returns xyz.
AF3 LpmColXyToZ(AF2 a){return AF3(a.x,a.y,1.0-(a.x+a.y));}
//------------------------------------------------------------------------------------------------------------------------------
// Returns conversion matrix, rgbw inputs are xy chroma coordinates.
void LpmColRgbToXyz(out AF3 ox,out AF3 oy,out AF3 oz,AF2 r,AF2 g,AF2 b,AF2 w){
// Expand from xy to xyz.
AF3 r3,g3,b3;LpmMatTrn3x3(r3,g3,b3,LpmColXyToZ(r),LpmColXyToZ(g),LpmColXyToZ(b));
// Convert white xyz to XYZ.
AF3 w3=LpmColXyToZ(w)*(1.0/w.y);
// Compute xyz to XYZ scalars for primaries.
AF3 rv,gv,bv;LpmMatInv3x3(rv,gv,bv,r3,g3,b3);
AF3 s=AF3(dot(rv,w3),dot(gv,w3),dot(bv,w3));
// Scale.
ox=r3*s;oy=g3*s;oz=b3*s;}
//==============================================================================================================================
// Visualize difference between two values, by bits of precision.
// This is useful when doing approximation to reference comparisons.
AP1 LpmD(AF1 a,AF1 b){return abs(a-b)<1.0;}
//------------------------------------------------------------------------------------------------------------------------------
AF1 LpmC(AF1 a,AF1 b){AF1 c=1.0; // 6-bits or less (the color)
if(LpmD(a* 127.0,b* 127.0))c=0.875; // 7-bits
if(LpmD(a* 255.0,b* 255.0))c=0.5; // 8-bits
if(LpmD(a* 512.0,b* 512.0))c=0.125; // 9-bits
if(LpmD(a*1024.0,b*1024.0))c=0.0; // 10-bits or better (black)
return c;}
//------------------------------------------------------------------------------------------------------------------------------
AF3 LpmViewDiff(AF3 a,AF3 b){return AF3(LpmC(a.r,b.r),LpmC(a.g,b.g),LpmC(a.b,b.b));}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// HDR10 RANGE LIMITING SCALAR
//------------------------------------------------------------------------------------------------------------------------------
// As of 2019, HDR10 supporting TVs typically have PQ tonal curves with near clipping long before getting to the peak 10K nits.
// Unfortunately this clipping point changes per TV (requires some amount of user calibration).
// Some examples,
// https://youtu.be/M7OsbpU4oCQ?t=875
// https://youtu.be/8mlTElC2z2A?t=1159
// https://youtu.be/B5V5hCVXBAI?t=975
// For this reason it can be useful to manually limit peak HDR10 output to some point before the clipping point.
// The following functions are useful to compute the scaling factor 'hdr10S' to use with LpmSetup() to manually limit peak.
//==============================================================================================================================
// Compute 'hdr10S' for raw HDR10 output, pass in peak nits (typically somewhere around 1000.0 to 2000.0).
AF1 LpmHdr10RawScalar(AF1 peakNits){return peakNits*(1.0/10000.0);}
//------------------------------------------------------------------------------------------------------------------------------
// Compute 'hdr10S' for scRGB based HDR10 output, pass in peak nits (typically somewhere around 1000.0 to 2000.0).
AF1 LpmHdr10ScrgbScalar(AF1 peakNits){return peakNits*(1.0/10000.0)*(10000.0/80.0);}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// FREESYNC2 SCRGB SCALAR
//------------------------------------------------------------------------------------------------------------------------------
// The more expensive scRGB mode for FreeSync2 requires a complex scale factor based on display properties.
//==============================================================================================================================
// TODO: Validate this is correct!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// This computes the 'fs2S' factor used in LpmSetup().
AF1 LpmFs2ScrgbScalar(
bool localDimming, // Is local dimming on?
AF1 minLuma,AF1 medLuma){ // Queried display properties.
if(localDimming)return 0.0; // TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return ((medLuma-minLuma)+minLuma)*(1.0/80.0);}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// CONFIGURATION PREFABS
//------------------------------------------------------------------------------------------------------------------------------
// Use these to simplify some of the input(s) to the LpmSetup() and LpmFilter() functions.
// The 'LPM_CONFIG_<destination>_<source>' defines are used for the path control.
// The 'LPM_COLORS_<destination>_<source>' defines are used for the gamut control.
// This contains expected common configurations, anything else will need to be made by the user.
//------------------------------------------------------------------------------------------------------------------------------
// WORKING COLOR SPACE
// ===================
// 2020 ......... Rec.2020
// 709 .......... Rec.709
// P3 ........... DCI-P3 with D65 white-point
// --------------
// OUTPUT COLOR SPACE
// ==================
// FS2RAW ....... Faster 32-bit/pixel FreeSync2 raw gamma 2.2 output (native display primaries)
// FS2SCRGB ..... Slower 64-bit/pixel FreeSync2 via the scRGB option (Rec.709 primaries with possible negative color)
// HDR10RAW ..... Faster 32-bit/pixel HDR10 raw (10:10:10:2 PQ output with Rec.2020 primaries)
// HDR10SCRGB ... Slower 64-bit/pixel scRGB (linear FP16, Rec.709 primaries with possible negative color)
// 709 .......... Rec.709, sRGB, Gamma 2.2, or traditional displays with Rec.709-like primaries
//------------------------------------------------------------------------------------------------------------------------------
// FREESYNC2 VARIABLES
// ===================
// fs2R ..... Queried xy coordinates for display red
// fs2G ..... Queried xy coordinates for display green
// fs2B ..... Queried xy coordinates for display blue
// fs2W ..... Queried xy coordinates for display white point
// fs2S ..... Computed by LpmFs2ScrgbScalar()
//------------------------------------------------------------------------------------------------------------------------------
// HDR10 VARIABLES
// ===============
// hdr10S ... Use LpmHdr10<Raw|Scrgb>Scalar() to compute this value
//==============================================================================================================================
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_FS2RAW_709 false,false,true, true, false
#define LPM_COLORS_FS2RAW_709 lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
fs2R,fs2G,fs2B,fs2W,\
fs2R,fs2G,fs2B,fs2W,1.0
//------------------------------------------------------------------------------------------------------------------------------
// FreeSync2 min-spec is larger than sRGB, so using 709 primaries all the way through as an optimization.
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_FS2SCRGB_709 false,false,false,false,true
#define LPM_COLORS_FS2SCRGB_709 lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,fs2S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_HDR10RAW_709 false,false,true, true, false
#define LPM_COLORS_HDR10RAW_709 lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,hdr10S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_HDR10SCRGB_709 false,false,false,false,true
#define LPM_COLORS_HDR10SCRGB_709 lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,hdr10S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_709_709 false,false,false,false,false
#define LPM_COLORS_709_709 lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,1.0
//==============================================================================================================================
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_FS2RAW_P3 true, true, false,false,false
#define LPM_COLORS_FS2RAW_P3 lpmColP3R,lpmColP3G,lpmColP3B,lpmColD65,\
fs2R,fs2G,fs2B,fs2W,\
fs2R,fs2G,fs2B,fs2W,1.0
//------------------------------------------------------------------------------------------------------------------------------
// FreeSync2 gamut can be smaller than P3.
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_FS2SCRGB_P3 true, true, true, false,false
#define LPM_COLORS_FS2SCRGB_P3 lpmColP3R,lpmColP3G,lpmColP3B,lpmColD65,\
fs2R,fs2G,fs2B,fs2W,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,fs2S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_HDR10RAW_P3 false,false,true, true, false
#define LPM_COLORS_HDR10RAW_P3 lpmColP3R,lpmColP3G,lpmColP3B,lpmColD65,\
lpmColP3R,lpmColP3G,lpmColP3B,lpmColD65,\
lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,hdr10S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_HDR10SCRGB_P3 false,false,true, false,false
#define LPM_COLORS_HDR10SCRGB_P3 lpmColP3R,lpmColP3G,lpmColP3B,lpmColD65,\
lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,hdr10S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_709_P3 true, true, false,false,false
#define LPM_COLORS_709_P3 lpmColP3R,lpmColP3G,lpmColP3B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,1.0
//==============================================================================================================================
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_FS2RAW_2020 true, true, false,false,false
#define LPM_COLORS_FS2RAW_2020 lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
fs2R,fs2G,fs2B,fs2W,\
fs2R,fs2G,fs2B,fs2W,1.0
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_FS2SCRGB_2020 true, true, true, false,false
#define LPM_COLORS_FS2SCRGB_2020 lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
fs2R,fs2G,fs2B,fs2W,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,fs2S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_HDR10RAW_2020 false,false,false,false,false
#define LPM_COLORS_HDR10RAW_2020 lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,hdr10S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_HDR10SCRGB_2020 false,false,true, false,false
#define LPM_COLORS_HDR10SCRGB_2020 lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,hdr10S
//------------------------------------------------------------------------------------------------------------------------------
// CON SOFT CON2 CLIP SCALEONLY
#define LPM_CONFIG_709_2020 true, true, false,false,false
#define LPM_COLORS_709_2020 lpmCol2020R,lpmCol2020G,lpmCol2020B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,\
lpmCol709R,lpmCol709G,lpmCol709B,lpmColD65,1.0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// SETUP CONTROL BLOCK
//------------------------------------------------------------------------------------------------------------------------------
// This is used to control LpmFilter*() functions.
//------------------------------------------------------------------------------------------------------------------------------
// CONTROL BLOCK
// =============
// LPM has an optimized constant|literal control block of 384 bytes.
// This control block should be 128-byte aligned (future-proof in case constant cache lines end up at 128-bytes/line).
// Much of this block is reserved for future usage, and to establish good alignment.
// Compile will dead-code remove things not used (no extra overhead).
// Content ordered and grouped for best performance in the common cases.
// Control block has both 32-bit and 16-bit values so that optimizations are possible on platforms supporting faster 16-bit.
//------------------------------------------------------------------------------------------------------------------------------
// 32-BIT PART
// _______R________ _______G________ _______B________ _______A________
// map0 saturation.r saturation.g saturation.b contrast
// map1 toneScaleBias.x toneScaleBias.y lumaT.r lumaT.g
// map2 lumaT.b crosstalk.r crosstalk.g crosstalk.b
// map3 rcpLumaT.r rcpLumaT.g rcpLumaT.b con2R.r
// --
// map4 con2R.g con2R.b con2G.r con2G.g
// map5 con2G.b con2B.r con2B.g con2B.b
// map6 shoulderContrast lumaW.r lumaW.g lumaW.b
// map7 softGap.x softGap.y conR.r conR.g
// --
// map8 conR.b conG.r conG.g conG.b
// map9 conB.r conB.g conB.b (reserved)
// mapA (reserved) (reserved) (reserved) (reserved)
// mapB (reserved) (reserved) (reserved) (reserved)
// --
// mapC (reserved) (reserved) (reserved) (reserved)
// mapD (reserved) (reserved) (reserved) (reserved)
// mapE (reserved) (reserved) (reserved) (reserved)
// mapF (reserved) (reserved) (reserved) (reserved)
// --
// PACKED 16-BIT PART
// _______X________ _______Y________ _______X________ _______Y________
// mapG.rg saturation.r saturation.g saturation.b contrast
// mapG.ba toneScaleBias.x toneScaleBias.y lumaT.r lumaT.g
// mapH.rg lumaT.b crosstalk.r crosstalk.g crosstalk.b
// mapH.ba rcpLumaT.r rcpLumaT.g rcpLumaT.b con2R.r
// mapI.rg con2R.g con2R.b con2G.r con2G.g
// mapI.ba con2G.b con2B.r con2B.g con2B.b
// mapJ.rg shoulderContrast lumaW.r lumaW.g lumaW.b
// mapJ.ba softGap.x softGap.y conR.r conR.g
// --
// mapK.rg conR.b conG.r conG.g conG.b
// mapK.ba conB.r conB.g conB.b (reserved)
// mapL.rb (reserved) (reserved) (reserved) (reserved)
// mapL.ba (reserved) (reserved) (reserved) (reserved)
// mapM.rb (reserved) (reserved) (reserved) (reserved)
// mapM.ba (reserved) (reserved) (reserved) (reserved)
// mapN.rb (reserved) (reserved) (reserved) (reserved)
// mapN.ba (reserved) (reserved) (reserved) (reserved)
//------------------------------------------------------------------------------------------------------------------------------
// IDEAS
// =====
// - Some of this might benefit from double precision on the GPU.
// - Can scaling factor in con2 be used to improve FP16 precision?
// - Verify lumaW stuff!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//==============================================================================================================================
void LpmSetup(
// Control block output.
out AU4 map0,out AU4 map1,out AU4 map2,out AU4 map3,out AU4 map4,out AU4 map5,out AU4 map6,out AU4 map7,
out AU4 map8,out AU4 map9,out AU4 mapA,out AU4 mapB,out AU4 mapC,out AU4 mapD,out AU4 mapE,out AU4 mapF,
out AU4 mapG,out AU4 mapH,out AU4 mapI,out AU4 mapJ,out AU4 mapK,out AU4 mapL,out AU4 mapM,out AU4 mapN,
// Path control.
AP1 shoulder, // Use optional extra shoulderContrast tuning (set to false if shoulderContrast is 1.0).
// Prefab start, "LPM_CONFIG_".
AP1 con, // Use first RGB conversion matrix, if 'soft' then 'con' must be true also.
AP1 soft, // Use soft gamut mapping.
AP1 con2, // Use last RGB conversion matrix.
AP1 clip, // Use clipping in last conversion matrix.
AP1 scaleOnly, // Scale only for last conversion matrix (used for 709 HDR to scRGB).
// Gamut control, "LPM_COLORS_".
AF2 xyRedW,AF2 xyGreenW,AF2 xyBlueW,AF2 xyWhiteW, // Chroma coordinates for working color space.
AF2 xyRedO,AF2 xyGreenO,AF2 xyBlueO,AF2 xyWhiteO, // For the output color space.
AF2 xyRedC,AF2 xyGreenC,AF2 xyBlueC,AF2 xyWhiteC,AF1 scaleC, // For the output container color space (if con2).
// Prefab end.
AF1 softGap, // Range of 0 to a little over zero, controls how much feather region in out-of-gamut mapping, 0=clip.
// Tonemapping control.
AF1 hdrMax, // Maximum input value.
AF1 exposure, // Number of stops between 'hdrMax' and 18% mid-level on input.
AF1 contrast, // Input range {0.0 (no extra contrast) to 1.0 (maximum contrast)}.
AF1 shoulderContrast, // Shoulder shaping, 1.0 = no change (fast path).
AF3 saturation, // A per channel adjustment, use <0 decrease, 0=no change, >0 increase.
AF3 crosstalk){ // One channel must be 1.0, the rest can be <= 1.0 but not zero.
//-----------------------------------------------------------------------------------------------------------------------------
// Contrast needs to be 1.0 based for no contrast.
contrast+=1.0;
// Saturation is based on contrast.
saturation+=contrast;
//-----------------------------------------------------------------------------------------------------------------------------
AF1 midIn=hdrMax*0.18/exp2(exposure);
AF1 midOut=0.18;
//-----------------------------------------------------------------------------------------------------------------------------
AF2 toneScaleBias;
AF1 cs=contrast*shoulderContrast;
AF1 z0=-pow(midIn,contrast);
AF1 z1=pow(hdrMax,cs)*pow(midIn,contrast);
AF1 z2=pow(hdrMax,contrast)*pow(midIn,cs)*midOut;
AF1 z3=pow(hdrMax,cs)*midOut;
AF1 z4=pow(midIn,cs)*midOut;
toneScaleBias.x=-((z0+(midOut*(z1-z2))/(z3-z4))/z4);
//-----------------------------------------------------------------------------------------------------------------------------
AF1 w0=pow(hdrMax,cs)*pow(midIn,contrast);
AF1 w1=pow(hdrMax,contrast)*pow(midIn,cs)*midOut;
AF1 w2=pow(hdrMax,cs)*midOut;
AF1 w3=pow(midIn,cs)*midOut;
toneScaleBias.y=(w0-w1)/(w2-w3);
//-----------------------------------------------------------------------------------------------------------------------------
AF3 lumaW;AF3 rgbToXyzXW;AF3 rgbToXyzYW;AF3 rgbToXyzZW;
LpmColRgbToXyz(rgbToXyzXW,rgbToXyzYW,rgbToXyzZW,xyRedW,xyGreenW,xyBlueW,xyWhiteW);
// Use the Y vector of the matrix for the associated luma coef.
// For safety, make sure the vector sums to 1.0.
lumaW=rgbToXyzYW;
lumaW*=ARcpF1(lumaW.r+lumaW.g+lumaW.b);
//-----------------------------------------------------------------------------------------------------------------------------
// The 'lumaT' for crosstalk mapping is always based on the output color space, unless soft conversion is not used.
AF3 lumaT;AF3 rgbToXyzXO;AF3 rgbToXyzYO;AF3 rgbToXyzZO;
LpmColRgbToXyz(rgbToXyzXO,rgbToXyzYO,rgbToXyzZO,xyRedO,xyGreenO,xyBlueO,xyWhiteO);
if(soft)lumaT=rgbToXyzYO;else lumaT=rgbToXyzYW;
lumaT*=ARcpF1(lumaT.r+lumaT.g+lumaT.b);
AF3 rcpLumaT=ARcpF3(lumaT);
//-----------------------------------------------------------------------------------------------------------------------------
AF2 softGap2;
if(soft)softGap2=AF2(softGap,(1.0-softGap)/(softGap*0.693147180559));
#ifdef A_HLSL
else softGap2=AF2_(0.0);
#endif
//-----------------------------------------------------------------------------------------------------------------------------
// First conversion is always working to output.
AF3 conR,conG,conB;
if(con){AF3 xyzToRgbRO;AF3 xyzToRgbGO;AF3 xyzToRgbBO;
LpmMatInv3x3(xyzToRgbRO,xyzToRgbGO,xyzToRgbBO,rgbToXyzXO,rgbToXyzYO,rgbToXyzZO);
LpmMatMul3x3(conR,conG,conB,xyzToRgbRO,xyzToRgbGO,xyzToRgbBO,rgbToXyzXW,rgbToXyzYW,rgbToXyzZW);}
#ifdef A_HLSL
else{conR=conG=conB=AF3_(0.0);}
#endif
//-----------------------------------------------------------------------------------------------------------------------------
// The last conversion is always output to container.
AF3 con2R,con2G,con2B;
if(con2){AF3 rgbToXyzXC;AF3 rgbToXyzYC;AF3 rgbToXyzZC;
LpmColRgbToXyz(rgbToXyzXC,rgbToXyzYC,rgbToXyzZC,xyRedC,xyGreenC,xyBlueC,xyWhiteC);
AF3 xyzToRgbRC;AF3 xyzToRgbGC;AF3 xyzToRgbBC;
LpmMatInv3x3(xyzToRgbRC,xyzToRgbGC,xyzToRgbBC,rgbToXyzXC,rgbToXyzYC,rgbToXyzZC);
LpmMatMul3x3(con2R,con2G,con2B,xyzToRgbRC,xyzToRgbGC,xyzToRgbBC,rgbToXyzXO,rgbToXyzYO,rgbToXyzZO);
con2R*=scaleC;con2G*=scaleC;con2B*=scaleC;}
#ifdef A_HLSL
else{con2R=con2G=con2B=AF3_(0.0);}
#endif
if(scaleOnly)con2R.r=scaleC;
//-----------------------------------------------------------------------------------------------------------------------------
// Debug force 16-bit precision for the 32-bit inputs.
#ifdef LPM_DEBUG_FORCE_16BIT_PRECISION
saturation=AF3(AH3(saturation));
contrast=AF1(AH1(contrast));
toneScaleBias=AF2(AH2(toneScaleBias));
lumaT=AF3(AH3(lumaT));
crosstalk=AF3(AH3(crosstalk));
rcpLumaT=AF3(AH3(rcpLumaT));
con2R=AF3(AH3(con2R));
con2G=AF3(AH3(con2G));
con2B=AF3(AH3(con2B));
shoulderContrast=AF1(AH1(shoulderContrast));
lumaW=AF3(AH3(lumaW));
softGap2=AF2(AH2(softGap2));
conR=AF3(AH3(conR));
conG=AF3(AH3(conG));
conB=AF3(AH3(conB));
#endif
//-----------------------------------------------------------------------------------------------------------------------------
// Pack into control block.
map0.rgb=AU3_AF3(saturation);map0.a=AU1_AF1(contrast);
map1.rg=AU2_AF2(toneScaleBias);map1.ba=AU2_AF2(lumaT.rg);
map2.r=AU1_AF1(lumaT.b);map2.gba=AU3_AF3(crosstalk);
map3.rgb=AU3_AF3(rcpLumaT);map3.a=AU1_AF1(con2R.r);
map4.rg=AU2_AF2(con2R.gb);map4.ba=AU2_AF2(con2G.rg);
map5.r=AU1_AF1(con2R.b);map5.gba=AU3_AF3(con2B);
map6.r=AU1_AF1(shoulderContrast);map6.gba=AU3_AF3(lumaW);
map7.rg=AU2_AF2(softGap2);map7.ba=AU2_AF2(conR.rg);
map8.r=AU1_AF1(conR.b);map8.gba=AU3_AF3(conG);
map9.rgb=AU3_AF3(conB);
#ifdef A_HLSL
map9.a=0.0;mapA=mapB=mapC=mapD=mapE=mapF=AU4_(0);
#endif
//-----------------------------------------------------------------------------------------------------------------------------
#ifdef A_HALF
// Packed 16-bit part of control block.
mapG.rg=AU2_AH4(AH4(AH1(saturation.r),AH1(saturation.g),AH1(saturation.b),AH1(contrast)));
mapG.ba=AU2_AH4(AH4(AH1(toneScaleBias.x),AH1(toneScaleBias.y),AH1(lumaT.r),AH1(lumaT.g)));
mapH.rg=AU2_AH4(AH4(AH1(lumaT.b),AH1(crosstalk.r),AH1(crosstalk.g),AH1(crosstalk.b)));
mapH.ba=AU2_AH4(AH4(AH1(rcpLumaT.r),AH1(rcpLumaT.g),AH1(rcpLumaT.b),AH1(con2R.r)));
mapI.rg=AU2_AH4(AH4(AH1(con2R.g),AH1(con2R.b),AH1(con2G.r),AH1(con2G.g)));
mapI.ba=AU2_AH4(AH4(AH1(con2G.b),AH1(con2B.r),AH1(con2B.g),AH1(con2B.b)));
mapJ.rg=AU2_AH4(AH4(AH1(shoulderContrast),AH1(lumaW.r),AH1(lumaW.g),AH1(lumaW.b)));
mapJ.ba=AU2_AH4(AH4(AH1(softGap2.x),AH1(softGap2.y),AH1(conR.r),AH1(conR.g)));
mapK.rg=AU2_AH4(AH4(AH1(conR.b),AH1(conG.r),AH1(conG.g),AH1(conG.b)));
mapK.ba=AU2_AH4(AH4(AH1(conB.r),AH1(conB.g),AH1(conB.b),AH1(0.0)));
#ifdef A_HLSL
mapL=mapM=mapN=AU4_(0);
#endif
#endif
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// MAPPER
//------------------------------------------------------------------------------------------------------------------------------
// Do not call this directly, instead call the LpmFilter*() functions.
// This gets reconfigured based on inputs for all the various usage cases.
// Some of this has been explicitly ordered to increase precision.
//------------------------------------------------------------------------------------------------------------------------------
// IDEAS
// =====
// - Use med3() for soft falloff and for [A] color conversions.
// - Retry FP16 PQ conversion with different input range.
// - Possibly skip some work if entire wave is in gamut.
//==============================================================================================================================
// Use LpmFilter() instead of this.
void LpmMap(inout AF1 colorR,inout AF1 colorG,inout AF1 colorB,// Input and output color.
AF3 lumaW, // Luma coef for RGB working space.
AF3 lumaT, // Luma coef for crosstalk mapping (can be working or output color-space depending on usage case).
AF3 rcpLumaT, // 1/lumaT.
AF3 saturation, // Saturation powers.
AF1 contrast, // Contrast power.
AP1 shoulder, // Using shoulder tuning (should be a compile-time immediate).
AF1 shoulderContrast, // Shoulder power.
AF2 toneScaleBias, // Other tonemapping parameters.
AF3 crosstalk, // Crosstalk scaling for over-exposure color shaping.
AP1 con, // Use first RGB conversion matrix (should be a compile-time immediate), if 'soft' then 'con' must be true also.
AF3 conR,AF3 conG,AF3 conB, // RGB conversion matrix (working to output space conversion).
AP1 soft, // Use soft gamut mapping (should be a compile-time immediate).
AF2 softGap, // {x,(1-x)/(x*0.693147180559)}, where 'x' is gamut mapping soft fall-off amount.
AP1 con2, // Use last RGB conversion matrix (should be a compile-time immediate).
AP1 clip, // Use clipping on last conversion matrix.
AP1 scaleOnly, // Do scaling only (special case for 709 HDR to scRGB).
AF3 con2R,AF3 con2G,AF3 con2B){ // Secondary RGB conversion matrix.
//------------------------------------------------------------------------------------------------------------------------------
// Grab original RGB ratio (RCP, 3x MUL, MAX3).
AF1 rcpMax=ARcpF1(AMax3F1(colorR,colorG,colorB));AF1 ratioR=colorR*rcpMax;AF1 ratioG=colorG*rcpMax;AF1 ratioB=colorB*rcpMax;
// Apply saturation, ratio must be max 1.0 for this to work right (3x EXP2, 3x LOG2, 3x MUL).
ratioR=pow(ratioR,AF1_(saturation.r));ratioG=pow(ratioG,AF1_(saturation.g));ratioB=pow(ratioB,AF1_(saturation.b));
//------------------------------------------------------------------------------------------------------------------------------
// Tonemap luma, note this uses the original color, so saturation is luma preserving.
// If not using 'con' this uses the output space luma directly to avoid needing extra constants.
// Note 'soft' should be a compile-time immediate (so no branch) (3x MAD).
AF1 luma;if(soft)luma=colorG*AF1_(lumaW.g)+(colorR*AF1_(lumaW.r)+(colorB*AF1_(lumaW.b)));
else luma=colorG*AF1_(lumaT.g)+(colorR*AF1_(lumaT.r)+(colorB*AF1_(lumaT.b)));
luma=pow(luma,AF1_(contrast)); // (EXP2, LOG2, MUL).
AF1 lumaShoulder=shoulder?pow(luma,AF1_(shoulderContrast)):luma; // Optional (EXP2, LOG2, MUL).
luma=luma*ARcpF1(lumaShoulder*AF1_(toneScaleBias.x)+AF1_(toneScaleBias.y)); // (MAD, MUL, RCP).
//------------------------------------------------------------------------------------------------------------------------------
// If running soft clipping (this should be a compile-time immediate so branch will not exist).
if(soft){
// The 'con' should be a compile-time immediate so branch will not exist.
// Use of 'con' is implied if soft-falloff is enabled, but using the check here to make finding bugs easy.
if(con){
// Converting ratio instead of color. Change of primaries (9x MAD).
colorR=ratioR;colorG=ratioG;colorB=ratioB;
ratioR=colorR*AF1_(conR.r)+(colorG*AF1_(conR.g)+(colorB*AF1_(conR.b)));
ratioG=colorG*AF1_(conG.g)+(colorR*AF1_(conG.r)+(colorB*AF1_(conG.b)));
ratioB=colorB*AF1_(conB.b)+(colorG*AF1_(conB.g)+(colorR*AF1_(conB.r)));
// Convert ratio to max 1 again (RCP, 3x MUL, MAX3).
rcpMax=ARcpF1(AMax3F1(ratioR,ratioG,ratioB));ratioR*=rcpMax;ratioG*=rcpMax;ratioB*=rcpMax;}
//------------------------------------------------------------------------------------------------------------------------------
// Absolute gamut mapping converted to soft falloff (maintains max 1 property).
// g = gap {0 to g} used for {-inf to 0} input range
// {g to 1} used for {0 to 1} input range
// x >= 0 := y = x * (1-g) + g
// x < 0 := g * 2^(x*h)
// Where h=(1-g)/(g*log(2)) --- where log() is the natural log
// The {g,h} above is passed in as softGap.
// Soft falloff (3x MIN, 3x MAX, 9x MAD, 3x EXP2).
ratioR=min(max(AF1_(softGap.x),ASatF1(ratioR*AF1_(-softGap.x)+ratioR)),
ASatF1(AF1_(softGap.x)*exp2(ratioR*AF1_(softGap.y))));
ratioG=min(max(AF1_(softGap.x),ASatF1(ratioG*AF1_(-softGap.x)+ratioG)),
ASatF1(AF1_(softGap.x)*exp2(ratioG*AF1_(softGap.y))));
ratioB=min(max(AF1_(softGap.x),ASatF1(ratioB*AF1_(-softGap.x)+ratioB)),
ASatF1(AF1_(softGap.x)*exp2(ratioB*AF1_(softGap.y))));}
//------------------------------------------------------------------------------------------------------------------------------
// Compute ratio scaler required to hit target luma (4x MAD, 1 RCP).
AF1 lumaRatio=ratioR*AF1_(lumaT.r)+ratioG*AF1_(lumaT.g)+ratioB*AF1_(lumaT.b);
// This is limited to not clip.
AF1 ratioScale=ASatF1(luma*ARcpF1(lumaRatio));
// Assume in gamut, compute output color (3x MAD).
colorR=ASatF1(ratioR*ratioScale);colorG=ASatF1(ratioG*ratioScale);colorB=ASatF1(ratioB*ratioScale);
// Capability per channel to increase value (3x MAD).
// This factors in crosstalk factor to avoid multiplies later.
// '(1.0-ratio)*crosstalk' optimized to '-crosstalk*ratio+crosstalk'
AF1 capR=AF1_(-crosstalk.r)*colorR+AF1_(crosstalk.r);
AF1 capG=AF1_(-crosstalk.g)*colorG+AF1_(crosstalk.g);
AF1 capB=AF1_(-crosstalk.b)*colorB+AF1_(crosstalk.b);
// Compute amount of luma needed to add to non-clipped channels to make up for clipping (3x MAD).
AF1 lumaAdd=ASatF1((-colorB)*AF1_(lumaT.b)+((-colorR)*AF1_(lumaT.r)+((-colorG)*AF1_(lumaT.g)+luma)));
// Amount to increase keeping over-exposure ratios constant and possibly exceeding clipping point (4x MAD, 1 RCP).
AF1 t=lumaAdd*ARcpF1(capG*AF1_(lumaT.g)+(capR*AF1_(lumaT.r)+(capB*AF1_(lumaT.b))));
// Add amounts to base color but clip (3x MAD).
colorR=ASatF1(t*capR+colorR);colorG=ASatF1(t*capG+colorG);colorB=ASatF1(t*capB+colorB);
// Compute amount of luma needed to add to non-clipped channel to make up for clipping (3x MAD).
lumaAdd=ASatF1((-colorB)*AF1_(lumaT.b)+((-colorR)*AF1_(lumaT.r)+((-colorG)*AF1_(lumaT.g)+luma)));
// Add to last channel (3x MAD).
colorR=ASatF1(lumaAdd*AF1_(rcpLumaT.r)+colorR);
colorG=ASatF1(lumaAdd*AF1_(rcpLumaT.g)+colorG);
colorB=ASatF1(lumaAdd*AF1_(rcpLumaT.b)+colorB);
//------------------------------------------------------------------------------------------------------------------------------
// The 'con2' should be a compile-time immediate so branch will not exist.
// Last optional place to convert from smaller to larger gamut (or do clipped conversion).
// For the non-soft-falloff case, doing this after all other mapping saves intermediate re-scaling ratio to max 1.0.
if(con2){
// Change of primaries (9x MAD).
ratioR=colorR;ratioG=colorG;ratioB=colorB;
if(clip){
colorR=ASatF1(ratioR*AF1_(con2R.r)+(ratioG*AF1_(con2R.g)+(ratioB*AF1_(con2R.b))));
colorG=ASatF1(ratioG*AF1_(con2G.g)+(ratioR*AF1_(con2G.r)+(ratioB*AF1_(con2G.b))));
colorB=ASatF1(ratioB*AF1_(con2B.b)+(ratioG*AF1_(con2B.g)+(ratioR*AF1_(con2B.r))));}
else{
colorR=ratioR*AF1_(con2R.r)+(ratioG*AF1_(con2R.g)+(ratioB*AF1_(con2R.b)));
colorG=ratioG*AF1_(con2G.g)+(ratioR*AF1_(con2G.r)+(ratioB*AF1_(con2G.b)));
colorB=ratioB*AF1_(con2B.b)+(ratioG*AF1_(con2B.g)+(ratioR*AF1_(con2B.r)));}}
//------------------------------------------------------------------------------------------------------------------------------
if(scaleOnly){colorR*=AF1_(con2R.r);colorG*=AF1_(con2R.r);colorB*=AF1_(con2R.r);}}
//==============================================================================================================================
// Packed FP16 version, see non-packed version above for all comments.
// Use LpmFilterH() instead of this.
void LpmMapH(inout AH2 colorR,inout AH2 colorG,inout AH2 colorB,AH3 lumaW,AH3 lumaT,AH3 rcpLumaT,AH3 saturation,AH1 contrast,
AP1 shoulder,AH1 shoulderContrast,AH2 toneScaleBias,AH3 crosstalk,AP1 con,AH3 conR,AH3 conG,AH3 conB,AP1 soft,AH2 softGap,
AP1 con2,AP1 clip,AP1 scaleOnly,AH3 con2R,AH3 con2G,AH3 con2B){
//------------------------------------------------------------------------------------------------------------------------------
AH2 rcpMax=ARcpH2(AMax3H2(colorR,colorG,colorB));AH2 ratioR=colorR*rcpMax;AH2 ratioG=colorG*rcpMax;AH2 ratioB=colorB*rcpMax;
ratioR=pow(ratioR,AH2_(saturation.r));ratioG=pow(ratioG,AH2_(saturation.g));ratioB=pow(ratioB,AH2_(saturation.b));
//------------------------------------------------------------------------------------------------------------------------------
AH2 luma;if(soft)luma=colorG*AH2_(lumaW.g)+(colorR*AH2_(lumaW.r)+(colorB*AH2_(lumaW.b)));
else luma=colorG*AH2_(lumaT.g)+(colorR*AH2_(lumaT.r)+(colorB*AH2_(lumaT.b)));
luma=pow(luma,AH2_(contrast));
AH2 lumaShoulder=shoulder?pow(luma,AH2_(shoulderContrast)):luma;
luma=luma*ARcpH2(lumaShoulder*AH2_(toneScaleBias.x)+AH2_(toneScaleBias.y));
//------------------------------------------------------------------------------------------------------------------------------
if(soft){
if(con){
colorR=ratioR;colorG=ratioG;colorB=ratioB;
ratioR=colorR*AH2_(conR.r)+(colorG*AH2_(conR.g)+(colorB*AH2_(conR.b)));
ratioG=colorG*AH2_(conG.g)+(colorR*AH2_(conG.r)+(colorB*AH2_(conG.b)));
ratioB=colorB*AH2_(conB.b)+(colorG*AH2_(conB.g)+(colorR*AH2_(conB.r)));
rcpMax=ARcpH2(AMax3H2(ratioR,ratioG,ratioB));ratioR*=rcpMax;ratioG*=rcpMax;ratioB*=rcpMax;}
//------------------------------------------------------------------------------------------------------------------------------
ratioR=min(max(AH2_(softGap.x),ASatH2(ratioR*AH2_(-softGap.x)+ratioR)),
ASatH2(AH2_(softGap.x)*exp2(ratioR*AH2_(softGap.y))));
ratioG=min(max(AH2_(softGap.x),ASatH2(ratioG*AH2_(-softGap.x)+ratioG)),
ASatH2(AH2_(softGap.x)*exp2(ratioG*AH2_(softGap.y))));
ratioB=min(max(AH2_(softGap.x),ASatH2(ratioB*AH2_(-softGap.x)+ratioB)),
ASatH2(AH2_(softGap.x)*exp2(ratioB*AH2_(softGap.y))));}
//------------------------------------------------------------------------------------------------------------------------------
AH2 lumaRatio=ratioR*AH2_(lumaT.r)+ratioG*AH2_(lumaT.g)+ratioB*AH2_(lumaT.b);
AH2 ratioScale=ASatH2(luma*ARcpH2(lumaRatio));
colorR=ASatH2(ratioR*ratioScale);colorG=ASatH2(ratioG*ratioScale);colorB=ASatH2(ratioB*ratioScale);
AH2 capR=AH2_(-crosstalk.r)*colorR+AH2_(crosstalk.r);
AH2 capG=AH2_(-crosstalk.g)*colorG+AH2_(crosstalk.g);
AH2 capB=AH2_(-crosstalk.b)*colorB+AH2_(crosstalk.b);
AH2 lumaAdd=ASatH2((-colorB)*AH2_(lumaT.b)+((-colorR)*AH2_(lumaT.r)+((-colorG)*AH2_(lumaT.g)+luma)));
AH2 t=lumaAdd*ARcpH2(capG*AH2_(lumaT.g)+(capR*AH2_(lumaT.r)+(capB*AH2_(lumaT.b))));
colorR=ASatH2(t*capR+colorR);colorG=ASatH2(t*capG+colorG);colorB=ASatH2(t*capB+colorB);
lumaAdd=ASatH2((-colorB)*AH2_(lumaT.b)+((-colorR)*AH2_(lumaT.r)+((-colorG)*AH2_(lumaT.g)+luma)));
colorR=ASatH2(lumaAdd*AH2_(rcpLumaT.r)+colorR);
colorG=ASatH2(lumaAdd*AH2_(rcpLumaT.g)+colorG);
colorB=ASatH2(lumaAdd*AH2_(rcpLumaT.b)+colorB);
//------------------------------------------------------------------------------------------------------------------------------
if(con2){
ratioR=colorR;ratioG=colorG;ratioB=colorB;
if(clip){
colorR=ASatH2(ratioR*AH2_(con2R.r)+(ratioG*AH2_(con2R.g)+(ratioB*AH2_(con2R.b))));
colorG=ASatH2(ratioG*AH2_(con2G.g)+(ratioR*AH2_(con2G.r)+(ratioB*AH2_(con2G.b))));
colorB=ASatH2(ratioB*AH2_(con2B.b)+(ratioG*AH2_(con2B.g)+(ratioR*AH2_(con2B.r))));}
else{
colorR=ratioR*AH2_(con2R.r)+(ratioG*AH2_(con2R.g)+(ratioB*AH2_(con2R.b)));
colorG=ratioG*AH2_(con2G.g)+(ratioR*AH2_(con2G.r)+(ratioB*AH2_(con2G.b)));
colorB=ratioB*AH2_(con2B.b)+(ratioG*AH2_(con2B.g)+(ratioR*AH2_(con2B.r)));}}
//------------------------------------------------------------------------------------------------------------------------------
if(scaleOnly){colorR*=AH2_(con2R.r);colorG*=AH2_(con2R.r);colorB*=AH2_(con2R.r);}}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// FILTER
//------------------------------------------------------------------------------------------------------------------------------
// Entry point for per-pixel color tone+gamut mapping.
// Input is linear color {0 to hdrMax} ranged.
// Output is linear color {0 to 1} ranged, except for scRGB where outputs can end up negative and larger than one.
//==============================================================================================================================
// 32-bit entry point.
void LpmFilter(
// Input and output color.
inout AF1 colorR,inout AF1 colorG,inout AF1 colorB,
// Path control should all be compile-time immediates.
AP1 shoulder, // Using shoulder tuning.
// Prefab "LPM_CONFIG_" start, use the same as used for LpmSetup().
AP1 con, // Use first RGB conversion matrix, if 'soft' then 'con' must be true also.
AP1 soft, // Use soft gamut mapping.
AP1 con2, // Use last RGB conversion matrix.
AP1 clip, // Use clipping in last conversion matrix.
AP1 scaleOnly, // Scale only for last conversion matrix (used for 709 HDR to scRGB).
// Prefab end.
// Control block.
AU4 map0,AU4 map1,AU4 map2,AU4 map3,AU4 map4,AU4 map5,AU4 map6,AU4 map7,
AU4 map8,AU4 map9,AU4 mapA,AU4 mapB,AU4 mapC,AU4 mapD,AU4 mapE,AU4 mapF,
AU4 mapG,AU4 mapH,AU4 mapI,AU4 mapJ,AU4 mapK,AU4 mapL,AU4 mapM,AU4 mapN){
LpmMap(colorR,colorG,colorB,
AF3(AF4_AU4(map6).g,AF4_AU4(map6).b,AF4_AU4(map6).a), // lumaW
AF3(AF4_AU4(map1).b,AF4_AU4(map1).a,AF4_AU4(map2).r), // lumaT
AF3(AF4_AU4(map3).r,AF4_AU4(map3).g,AF4_AU4(map3).b), // rcpLumaT
AF3(AF4_AU4(map0).r,AF4_AU4(map0).g,AF4_AU4(map0).b), // saturation
AF4_AU4(map0).a, // contrast
shoulder,
AF4_AU4(map6).r, // shoulderContrast
AF2(AF4_AU4(map1).r,AF4_AU4(map1).g), // toneScaleBias
AF3(AF4_AU4(map2).g,AF4_AU4(map2).b,AF4_AU4(map2).a),// crosstalk
con,
AF3(AF4_AU4(map7).b,AF4_AU4(map7).a,AF4_AU4(map8).r), // conR
AF3(AF4_AU4(map8).g,AF4_AU4(map8).b,AF4_AU4(map8).a), // conG
AF3(AF4_AU4(map9).r,AF4_AU4(map9).g,AF4_AU4(map9).b), // conB
soft,
AF2(AF4_AU4(map7).r,AF4_AU4(map7).g), // softGap
con2,clip,scaleOnly,
AF3(AF4_AU4(map3).a,AF4_AU4(map4).r,AF4_AU4(map4).g), // con2R
AF3(AF4_AU4(map4).b,AF4_AU4(map4).a,AF4_AU4(map5).r), // con2G
AF3(AF4_AU4(map5).g,AF4_AU4(map5).b,AF4_AU4(map5).a));} // con2B
//------------------------------------------------------------------------------------------------------------------------------
#if A_HALF
// Packed 16-bit entry point (maps 2 colors at the same time).
void LpmFilterH(
inout AH2 colorR,inout AH2 colorG,inout AH2 colorB,
AP1 shoulder,AP1 con,AP1 soft,AP1 con2,AP1 clip,AP1 scaleOnly,
AU4 map0,AU4 map1,AU4 map2,AU4 map3,AU4 map4,AU4 map5,AU4 map6,AU4 map7,
AU4 map8,AU4 map9,AU4 mapA,AU4 mapB,AU4 mapC,AU4 mapD,AU4 mapE,AU4 mapF,
AU4 mapG,AU4 mapH,AU4 mapI,AU4 mapJ,AU4 mapK,AU4 mapL,AU4 mapM,AU4 mapN){
LpmMapH(colorR,colorG,colorB,
AH3(AH2_AU1(mapJ.r).y,AH2_AU1(mapJ.g).x,AH2_AU1(mapJ.g).y), // lumaW
AH3(AH2_AU1(mapG.a).x,AH2_AU1(mapG.a).y,AH2_AU1(mapH.r).x), // lumaT
AH3(AH2_AU1(mapH.b).x,AH2_AU1(mapH.b).y,AH2_AU1(mapH.a).x), // rcpLumaT
AH3(AH2_AU1(mapG.r).x,AH2_AU1(mapG.r).y,AH2_AU1(mapG.g).x), // saturation
AH2_AU1(mapG.g).y, // contrast
shoulder,
AH2_AU1(mapJ.r).x, // shoulderContrast
AH2_AU1(mapG.b), // toneScaleBias
AH3(AH2_AU1(mapH.r).y,AH2_AU1(mapH.g).x,AH2_AU1(mapH.g).y), // crosstalk
con,
AH3(AH2_AU1(mapJ.a).x,AH2_AU1(mapJ.a).y,AH2_AU1(mapK.r).x), // conR
AH3(AH2_AU1(mapK.r).y,AH2_AU1(mapK.g).x,AH2_AU1(mapK.g).y), // conG
AH3(AH2_AU1(mapK.b).x,AH2_AU1(mapK.b).y,AH2_AU1(mapK.a).x), // conB
soft,
AH2_AU1(mapJ.b), // softGap
con2,clip,scaleOnly,
AH3(AH2_AU1(mapH.a).y,AH2_AU1(mapI.r).x,AH2_AU1(mapI.r).y), // con2R
AH3(AH2_AU1(mapI.g).x,AH2_AU1(mapI.g).y,AH2_AU1(mapI.b).x), // con2G
AH3(AH2_AU1(mapI.b).y,AH2_AU1(mapI.a).x,AH2_AU1(mapI.a).y));} // con2B
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________________________/\_______________________________________________________________
//==============================================================================================================================
// END OF GPU CODE
//==============================================================================================================================
#endif
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8b2264ffe26ac3e42b4077bfbc35941b
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: