summaryrefslogtreecommitdiff
path: root/tests/glsl/sascha-willems/deferredmultisampling/debug.frag
blob: f404711dd189f4026f9b6e04d13eb891bba7cef7 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#version 450
//TEST:COMPARE_GLSL:

#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable

layout (binding = 1) uniform sampler2DMS samplerPosition;
layout (binding = 2) uniform sampler2DMS samplerNormal;
layout (binding = 3) uniform sampler2DMS samplerAlbedo;

layout (location = 0) in vec3 inUV;

layout (location = 0) out vec4 outFragColor;

#define NUM_SAMPLES 8

vec4 resolve(sampler2DMS tex, ivec2 uv)
{
	vec4 result = vec4(0.0);	   
	int count = 0;
	for (int i = 0; i < NUM_SAMPLES; i++)
	{
		vec4 val = texelFetch(tex, uv, i); 
		result += val;
		count++;
	}    
	return result / float(NUM_SAMPLES);
}

void main() 
{
	ivec2 attDim = textureSize(samplerPosition);
	ivec2 UV = ivec2(inUV.st * attDim * 2.0);

	highp int index = 0;
	if (inUV.s > 0.5)
	{
		index = 1;
		UV.s -= attDim.x;
	}
	if (inUV.t > 0.5)
	{
		index = 2;
		UV.t -= attDim.y;
	}

	vec3 components[3];
	components[0] = resolve(samplerPosition, UV).rgb;  
	components[1] = resolve(samplerNormal, UV).rgb;  
	components[2] = resolve(samplerAlbedo, UV).rgb;  
	// Uncomment to display specular component
	//components[2] = vec3(texture(samplerAlbedo, inUV.st).a);  
	
	// Select component depending on UV
	outFragColor.rgb = components[index];
}