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

gpu_shader_fx_dof_hq_vert.glsl « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1dd5bf42b25be552450d469d4c58029202ffc224 (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
57
58
59
60
61
62

in vec2 pos;
in vec2 uvs;
/* initial uv coordinate */
out vec2 uvcoord;

/* coordinate used for calculating radius et al set in geometry shader */
out vec2 particlecoord;

/* downsampling coordinates */
out vec2 downsample1;
out vec2 downsample2;
out vec2 downsample3;
out vec2 downsample4;

uniform vec2 invrendertargetdim;
uniform ivec2 rendertargetdim;

void vert_dof_downsample()
{
	/* gather pixels from neighbors. half dimensions means we offset half a pixel to
	 * get this right though it's possible we may lose a pixel at some point */
	downsample1 = uvs.xy + vec2(-0.5, -0.5) * invrendertargetdim;
	downsample2 = uvs.xy + vec2(-0.5, 0.5) * invrendertargetdim;
	downsample3 = uvs.xy + vec2(0.5, 0.5) * invrendertargetdim;
	downsample4 = uvs.xy + vec2(0.5, -0.5) * invrendertargetdim;

	gl_Position = vec4(pos, 0.0, 1.0);
}

/* geometry shading pass, calculate a texture coordinate based on the indexed id */
void vert_dof_coc_scatter_pass()
{
	vec2 pixel = vec2(rendertargetdim.x, rendertargetdim.y);
	/* some math to get the target pixel */
	int row = gl_InstanceID / rendertargetdim.x;
	int column = gl_InstanceID % rendertargetdim.x;
	uvcoord = (vec2(column, row) + vec2(0.5)) / pixel;

	vec2 pos = uvcoord * 2.0 - vec2(1.0);
	gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);

//	uvcoord = vec2(0.5, 0.5);
//	gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
}

void vert_dof_final()
{
	uvcoord = uvs;
	gl_Position = vec4(pos, 0.0, 1.0);
}

void main()
{
#if defined(FIRST_PASS)
	vert_dof_downsample();
#elif defined(SECOND_PASS)
	vert_dof_coc_scatter_pass();
#else
	vert_dof_final();
#endif
}