MixedReality-GraphicsTools-Unity
MixedReality-GraphicsTools-Unity copied to clipboard
Add programmatic iridescence support
Describe the problem
Banding is present in our texture based iridescence feature:

Switching to programmatic iridescence gradient look ups would alleviate this issue.
Describe the solution you'd like
Add a new gradient mode to this list which is maybe called "Iridescence Procedural"?

Implemented like so from @maluoi -
The sharp edges on the gradient were kinda bothering me, and I finally realized smoothstep was the answer! 😄
Anyhow, I thought I'd share the HLSL shader code I use for the iridescence gradient in StereoKit, in case it's helpful.
Another note here, using an array of float3s for the gradient color is how I'm avoiding banding, that's the ir_gradient variable here.
static const int ir_gradient_count = 5; static const float3 ir_gradient[] = { float3(0,0,0), float3(0,0,0), float3(0.065,0.018,0.429), float3(0,0,0), float3(0.013, 0.117, 0.597), float3(0,0,0) }; float3 GetIridescence(uint view_id, float3 world_pos, float3 surface_normal) { float3 dir = normalize(sk_camera_pos[view_id].xyz - world_pos); float ir = saturate(dot(dir, surface_normal)); float pct = ir * ir_gradient_count; int g = pct; pct = smoothstep(0, 1, frac(pct)); float3 curr = ir_gradient[g]; float3 next = ir_gradient[g+1]; return lerp(curr, next, pct); }
Describe alternatives you've considered
Live with the banding or use HDR textures for iridescence.
Additional context
Related to: https://github.com/microsoft/MixedReality-GraphicsTools-Unity/issues/22
