Update leenkx/Shaders/std/tonemap.glsl
This commit is contained in:
		| @ -89,3 +89,52 @@ vec3 tonemapAgXFull(vec3 x) { | ||||
|     x = clamp(x, 0.0, 1.0); | ||||
|     return pow(x, vec3(1.0/2.2));  | ||||
| } | ||||
|  | ||||
|  | ||||
| // Interleaved Gradient Noise (Pseudo-random, AKA Blue Noise style) | ||||
| // Based on http://momentsingraphics.de/BlueNoise.html | ||||
| float ditherBlueNoiseStyle(vec2 p) { | ||||
|     return fract(sin(dot(p.xy, vec2(12.9898, 78.233))) * 43758.5453123); | ||||
| } | ||||
|  | ||||
| // White Noise Dithering | ||||
| float ditherWhiteNoise(vec2 p) { | ||||
|     return fract(sin(dot(p, vec2(12.9898, 4.1414))) * 43758.5453); | ||||
| } | ||||
|  | ||||
| // Ordered Dithering (4x4 Bayer Matrix) | ||||
| float ditherOrderedBayer4x4(ivec2 p) { | ||||
|     const float bayer[16] = float[16]( | ||||
|          0.0,  8.0,  2.0, 10.0, | ||||
|         12.0,  4.0, 14.0,  6.0, | ||||
|          3.0, 11.0,  1.0,  9.0, | ||||
|         15.0,  7.0, 13.0,  5.0 | ||||
|     ); | ||||
|     int index = (p.x % 4) * 4 + (p.y % 4); | ||||
|     return bayer[index] / 16.0; | ||||
| } | ||||
|  | ||||
| // Ordered Dithering (8x8 Bayer Matrix) | ||||
| float ditherOrderedBayer8x8(ivec2 p) { | ||||
|     const float bayer8x8[64] = float[64]( | ||||
|          0.0, 32.0,  8.0, 40.0,  2.0, 34.0, 10.0, 42.0, | ||||
|         48.0, 16.0, 56.0, 24.0, 50.0, 18.0, 58.0, 26.0, | ||||
|         12.0, 44.0,  4.0, 36.0, 14.0, 46.0,  6.0, 38.0, | ||||
|         60.0, 28.0, 52.0, 20.0, 62.0, 30.0, 54.0, 22.0, | ||||
|          3.0, 35.0, 11.0, 43.0,  1.0, 33.0,  9.0, 41.0, | ||||
|         51.0, 19.0, 59.0, 27.0, 49.0, 17.0, 57.0, 25.0, | ||||
|         15.0, 47.0,  7.0, 39.0, 13.0, 45.0,  5.0, 37.0, | ||||
|         63.0, 31.0, 55.0, 23.0, 61.0, 29.0, 53.0, 21.0 | ||||
|     ); | ||||
|     int index = (p.x % 8) * 8 + (p.y % 8); | ||||
|     return bayer8x8[index] / 64.0; | ||||
| } | ||||
|  | ||||
|  | ||||
| //vec3 applyDither(vec3 color, vec2 screenCoord) { | ||||
| //    float quantizationLevels = 255.0; | ||||
| //    float noise = randomDither(screenCoord); | ||||
| //    float noiseOffset = (noise - 0.5) / quantizationLevels; | ||||
| //    vec3 ditheredColor = color + noiseOffset; | ||||
| //    return clamp(ditheredColor, 0.0, 1.0); | ||||
| //} | ||||
|  | ||||
		Reference in New Issue
	
	Block a user