Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lightprobe_planar_downsample_frag.glsl « shaders « eevee « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3b3abdef00cd0e89e6329974f478fda7b5cc7b28 (plain)
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
/**
 * Simple downsample shader. Takes the average of the 4 texels of lower mip.
 **/

uniform sampler2DArray source;
uniform float fireflyFactor;

in vec2 uvs;
flat in float layer;

out vec4 FragColor;

float brightness(vec3 c)
{
	return max(max(c.r, c.g), c.b);
}

void main()
{
#if 0
	/* Reconstructing Target uvs like this avoid missing pixels if NPO2 */
	vec2 uvs = gl_FragCoord.xy * 2.0 / vec2(textureSize(source, 0));

	FragColor = textureLod(source, vec3(uvs, layer), 0.0);
#else
	vec2 texel_size = 1.0 / vec2(textureSize(source, 0));
	vec2 uvs = gl_FragCoord.xy * 2.0 * texel_size;
	vec4 ofs = texel_size.xyxy * vec4(0.75, 0.75, -0.75, -0.75);

	FragColor  = textureLod(source, vec3(uvs + ofs.xy, layer), 0.0);
	FragColor += textureLod(source, vec3(uvs + ofs.xw, layer), 0.0);
	FragColor += textureLod(source, vec3(uvs + ofs.zy, layer), 0.0);
	FragColor += textureLod(source, vec3(uvs + ofs.zw, layer), 0.0);
	FragColor *= 0.25;

	/* Clamped brightness. */
	float luma = max(1e-8, brightness(FragColor.rgb));
	FragColor *= 1.0 - max(0.0, luma - fireflyFactor) / luma;
#endif
}