Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4b3224a
initial iridescent fresnel, only single channel ior
keptsecret Aug 26, 2025
9c71906
iridescent fresnel does rgb IOR, use in brdf
keptsecret Aug 26, 2025
0f51306
some bug fixes
keptsecret Aug 27, 2025
f205d4e
replace loop for vector operations in fresnel
keptsecret Aug 27, 2025
f6daa6f
added iridescent btdf
keptsecret Aug 27, 2025
09402ea
added unit tests
keptsecret Aug 27, 2025
a77c337
merge bxdfs, fix conflicts
keptsecret Aug 28, 2025
aa0f6e8
latest example
keptsecret Aug 28, 2025
d2cb193
moved colorspace transform mats into struct functions
keptsecret Aug 28, 2025
33fc955
some more colorspace utility
keptsecret Aug 28, 2025
0f6c7a2
merge latest bxdf_fixes, fix conflicts
keptsecret Nov 3, 2025
d8b6773
restore encode/decode matrices
keptsecret Nov 3, 2025
65239d9
colorspace specific dominant wavelengths (still missing ACES), use gl…
keptsecret Nov 3, 2025
9a8b77e
update iridescent fresnel to match fresnel concept
keptsecret Nov 3, 2025
702ec8d
Merge branch 'master' into iridescence_bxdf
keptsecret Nov 4, 2025
76ad0ed
minor typo fixes
keptsecret Nov 4, 2025
53c930f
minor fixes to cook torrance, ndf infinity, move util functions into …
keptsecret Nov 4, 2025
23de8ed
changes to angle adding usage
keptsecret Nov 4, 2025
ff9e03f
better orthonormality for H
keptsecret Nov 4, 2025
18b3922
minor change to ggx clamp
keptsecret Nov 4, 2025
a5d8f5c
Merge branch 'master' into iridescence_bxdf
keptsecret Nov 5, 2025
f3dd05c
minor changes to create complex_t in angle_adding
keptsecret Nov 5, 2025
68d3614
refactor out common section of cook torrance generate
keptsecret Nov 5, 2025
aebfecf
added luma contribution hint, getPrefixThroughputWeights to interacti…
keptsecret Nov 6, 2025
b53fa1b
cook torrance bsdf can use spectral fresnel, uses interaction.getPref…
keptsecret Nov 6, 2025
946b050
thin smooth dielectric use luma coeff from interaction
keptsecret Nov 6, 2025
1a2f561
split iridescent fresnel by SupportsTransmission, adjusted fresnel co…
keptsecret Nov 7, 2025
4b8a06b
fix edge cases for iridescent fresnel
keptsecret Nov 7, 2025
5782a49
removed redundant weight in interaction
keptsecret Nov 7, 2025
55471ca
removed duplicate fresnel code, added creation params for iridescent
keptsecret Nov 10, 2025
64be771
split out iridescent fresnel vars into base struct
keptsecret Nov 10, 2025
8f9a114
renamed private funcs, replace enable_if usage with NBL_FUNC_REQUIRES
keptsecret Nov 10, 2025
8a71f40
avoid promoting 1d fresnel to 3d just to dot product, added private f…
keptsecret Nov 10, 2025
dee1b61
init ndf quants, minor cook torrance fixes
keptsecret Nov 11, 2025
cd9b18b
primaries wavelengths for aces colorspaces (not sure they're correct)
keptsecret Nov 11, 2025
0984c7e
fixes to angle adder, handle some edge cases
keptsecret Nov 11, 2025
3d7ded6
Merge branch 'master' into iridescence_bxdf
keptsecret Nov 12, 2025
1908749
Bugfix `sincos_accumulator::create`
devshgraphicsprogramming Nov 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 54 additions & 87 deletions include/nbl/builtin/hlsl/colorspace.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define _NBL_BUILTIN_HLSL_COLOR_SPACE_COLORSPACE_INCLUDED_

#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include <nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl>
#include <nbl/builtin/hlsl/colorspace/decodeCIEXYZ.hlsl>

namespace nbl
{
Expand All @@ -16,104 +18,89 @@ namespace colorspace

struct colorspace_base
{
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_R = 580.0f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_G = 550.0f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_B = 450.0f;
// default CIE RGB primaries wavelengths
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_R = 700.0f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_G = 546.1f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_B = 435.8f;
};

struct scRGB : colorspace_base
{
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_R = 611.4f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_G = 549.1f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_B = 464.2f;

static float32_t3x3 FromXYZ()
{
return float32_t3x3(
float32_t3( 3.240970f, -1.537383f, -0.498611f),
float32_t3(-0.969244f, 1.875968f, 0.041555f),
float32_t3( 0.055630f, -0.203977f, 1.056972f)
);
return XYZtoscRGB;
}
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(FromXYZ(), val); }
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(XYZtoscRGB, val); }

static float32_t3x3 ToXYZ()
{
return float32_t3x3(
float32_t3(0.412391f, 0.357584f, 0.180481f),
float32_t3(0.212639f, 0.715169f, 0.072192f),
float32_t3(0.019331f, 0.119195f, 0.950532f)
);
return scRGBtoXYZ;
}
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ToXYZ(), val); }
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(scRGBtoXYZ, val); }
};

struct sRGB : scRGB {};
struct BT709 : scRGB {};

struct Display_P3 : colorspace_base
{
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_R = 614.9f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_G = 544.2f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_B = 464.2f;

static float32_t3x3 FromXYZ()
{
return float32_t3x3(
float32_t3( 2.4934969119f, -0.9313836179f, -0.4027107845f),
float32_t3(-0.8294889696f, 1.7626640603f, 0.0236246858f),
float32_t3( 0.0358458302f, -0.0761723893f, 0.9568845240f)
);
return XYZtoDisplay_P3;
}
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(FromXYZ(), val); }
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(XYZtoDisplay_P3, val); }

static float32_t3x3 ToXYZ()
{
return float32_t3x3(
float32_t3(0.4865709486f, 0.2656676932f, 0.1982172852f),
float32_t3(0.2289745641f, 0.6917385218f, 0.0792869141f),
float32_t3(0.0000000000f, 0.0451133819f, 1.0439443689f)
);
return Display_P3toXYZ;
}
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ToXYZ(), val); }
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(Display_P3toXYZ, val); }
};

struct DCI_P3 : colorspace_base
{
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_R = 614.9f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_G = 544.2f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_B = 464.2f;

static float32_t3x3 FromXYZ()
{
return float32_t3x3(
float32_t3(1.0f, 0.0f, 0.0f),
float32_t3(0.0f, 1.0f, 0.0f),
float32_t3(0.0f, 0.0f, 1.0f)
);
return XYZtoDCI_P3;
}
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(FromXYZ(), val); }
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(XYZtoDCI_P3, val); }

static float32_t3x3 ToXYZ()
{
return float32_t3x3(
float32_t3(1.0f, 0.0f, 0.0f),
float32_t3(0.0f, 1.0f, 0.0f),
float32_t3(0.0f, 0.0f, 1.0f)
);
return DCI_P3toXYZ;
}
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ToXYZ(), val); }
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(DCI_P3toXYZ, val); }
};

struct BT2020 : colorspace_base
{
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_R = 630.0f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_G = 532.0f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_B = 467.0f;

static float32_t3x3 FromXYZ()
{
return float32_t3x3(
float32_t3( 1.716651f, -0.355671f, -0.253366f),
float32_t3(-0.666684f, 1.616481f, 0.015769f),
float32_t3( 0.017640f, -0.042771f, 0.942103f)
);
return XYZtoBT2020;
}
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(FromXYZ(), val); }
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(XYZtoBT2020, val); }

static float32_t3x3 ToXYZ()
{
return float32_t3x3(
float32_t3(0.636958f, 0.144617f, 0.168881f),
float32_t3(0.262700f, 0.677998f, 0.059302f),
float32_t3(0.000000f, 0.028073f, 1.060985f)
);
return BT2020toXYZ;
}
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ToXYZ(), val); }
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(BT2020toXYZ, val); }
};

struct HDR10_ST2084 : BT2020 {};
Expand All @@ -122,71 +109,51 @@ struct HDR10_HLG : BT2020 {};

struct AdobeRGB : colorspace_base
{
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_R = 611.4f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_G = 534.7f;
NBL_CONSTEXPR_STATIC_INLINE float32_t wavelength_B = 464.2f;

static float32_t3x3 FromXYZ()
{
return float32_t3x3(
float32_t3( 2.0415879038f, -0.5650069743f, -0.3447313508f),
float32_t3(-0.9692436363f, 1.8759675015f, 0.0415550574f),
float32_t3( 0.0134442806f, -0.1183623922f, 1.0151749944f)
);
return XYZtoAdobeRGB;
}
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(FromXYZ(), val); }
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(XYZtoAdobeRGB, val); }

static float32_t3x3 ToXYZ()
{
return float32_t3x3(
float32_t3(0.5766690429f, 0.1855582379f, 0.1882286462f),
float32_t3(0.2973449753f, 0.6273635663f, 0.0752914585f),
float32_t3(0.0270313614f, 0.0706888525f, 0.9913375368f)
);
return AdobeRGBtoXYZ;
}
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ToXYZ(), val); }
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(AdobeRGBtoXYZ, val); }
};

struct ACES2065_1 : colorspace_base
{
static float32_t3x3 FromXYZ()
{
return float32_t3x3(
float32_t3( 1.0498110175f, 0.0000000000f, -0.0000974845f),
float32_t3(-0.4959030231f, 1.3733130458f, 0.0982400361f),
float32_t3( 0.0000000000f, 0.0000000000f, 0.9912520182f)
);
return XYZtoACES2065_1;
}
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(FromXYZ(), val); }
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(XYZtoACES2065_1, val); }

static float32_t3x3 ToXYZ()
{
return float32_t3x3(
float32_t3(0.9525523959f, 0.0000000000f, 0.0000936786f),
float32_t3(0.3439664498f, 0.7281660966f, -0.0721325464f),
float32_t3(0.0000000000f, 0.0000000000f, 1.0088251844f)
);
return ACES2065_1toXYZ;
}
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ToXYZ(), val); }
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ACES2065_1toXYZ, val); }
};

struct ACEScc : colorspace_base
{
static float32_t3x3 FromXYZ()
{
return float32_t3x3(
float32_t3( 1.6410233797f, -0.3248032942f, -0.2364246952f),
float32_t3(-0.6636628587f, 1.6153315917f, 0.0167563477f),
float32_t3( 0.0117218943f, -0.0082844420f, 0.9883948585f)
);
return XYZtoACEScc;
}
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(FromXYZ(), val); }
static float32_t3 FromXYZ(float32_t3 val) { return hlsl::mul(XYZtoACEScc, val); }

static float32_t3x3 ToXYZ()
{
return float32_t3x3(
float32_t3( 0.6624541811f, 0.1340042065f, 0.1561876870f),
float32_t3( 0.2722287168f, 0.6740817658f, 0.0536895174f),
float32_t3(-0.0055746495f, 0.0040607335f, 1.0103391003f)
);
return ACEScctoXYZ;
}
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ToXYZ(), val); }
static float32_t3 ToXYZ(float32_t3 val) { return hlsl::mul(ACEScctoXYZ, val); }
};

struct ACEScct : ACEScc {};
Expand Down
Loading