forked from vesa-org/DisplayHDRTest
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBackgroundNoiseEffect.hlsl
More file actions
73 lines (61 loc) · 2.53 KB
/
BackgroundNoiseEffect.hlsl
File metadata and controls
73 lines (61 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
//
//
// Custom effects using pixel shaders should use HLSL helper functions defined in
// d2d1effecthelpers.hlsli to make use of effect shader linking.
#define D2D_INPUT_COUNT 0 // The pixel shader is a source and does not take inputs.
#define D2D_REQUIRES_SCENE_POSITION // The pixel shader requires the SCENE_POSITION input.
// Note that the custom build step must provide the correct path to find d2d1effecthelpers.hlsli when calling fxc.exe.
#include "d2d1effecthelpers.hlsli"
cbuffer constants : register(b0)
{
float dpi : packoffset(c0.x);
float APL : packoffset(c0.y); // APL -Average Picture Level
float Clamp : packoffset(c0.z); // No pixel values above this limit (nits)
float iTime : packoffset (c0.w); // time since app start in seconds
};
// https://www.pcg-random.org/
uint pcg(uint v)
{
uint state = v * 747796405u + 2891336453u;
uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
return (word >> 22u) ^ word;
}
// https://www.shadertoy.com/view/XlGcRh
// Uniform value in range [0..1)
float hash( int2 u )
{
return float(pcg(pcg(u.x) + u.y)) / float(0xFFFFFFFFU); // normalize to 1.0
}
/*
a = 1; G = (a - 1)! = 1; // exponential distribution
a = 2; G = (a - 1)! = 1; // gamma distribution
*/
D2D_PS_ENTRY(main)
{
float x;
float c = 10000; // output color init to out of range
float2 pos = D2DGetScenePosition().xy; // units of pixels
pos.x -= iTime * 60.0; // animate
pos.y += iTime * 60.0;
// pos /= 4; // derez into tiles
int i = 0;
while (c > Clamp) // check vs Clamp
{
x = hash(pos + x * i); // uniform from [0 to 1.)
c = -log(1.0 - x) * APL;
i++;
}
c = c/80.f; // scale from nits to CCCS brightness units
// c = pow(c, 2.2); // required in SDR mode
return float4( c, c, c, 1.0 );
}