1 | [vert.glsl] |
---|
2 | |
---|
3 | #version 130 |
---|
4 | |
---|
5 | attribute vec3 in_Vertex; |
---|
6 | attribute vec4 in_Color; |
---|
7 | varying vec4 pass_Color; |
---|
8 | |
---|
9 | uniform mat4 proj_matrix; |
---|
10 | uniform mat4 view_matrix; |
---|
11 | uniform mat4 model_matrix; |
---|
12 | |
---|
13 | void main() |
---|
14 | { |
---|
15 | gl_Position = proj_matrix * view_matrix * model_matrix |
---|
16 | * vec4(in_Vertex, 1.0); |
---|
17 | pass_Color = in_Color; |
---|
18 | } |
---|
19 | |
---|
20 | [frag.glsl] |
---|
21 | |
---|
22 | #version 130 |
---|
23 | |
---|
24 | #if defined GL_ES |
---|
25 | precision highp float; |
---|
26 | #endif |
---|
27 | |
---|
28 | varying vec4 pass_Color; |
---|
29 | |
---|
30 | mat4 bayer = mat4( 0.0, 12.0, 3.0, 15.0, |
---|
31 | 8.0, 4.0, 11.0, 7.0, |
---|
32 | 2.0, 14.0, 1.0, 13.0, |
---|
33 | 10.0, 6.0, 9.0, 5.0); |
---|
34 | |
---|
35 | mat4 cluster = mat4(12.0, 5.0, 6.0, 13.0, |
---|
36 | 4.0, 0.0, 1.0, 7.0, |
---|
37 | 11.0, 3.0, 2.0, 8.0, |
---|
38 | 15.0, 10.0, 9.0, 14.0); |
---|
39 | |
---|
40 | float rand(vec2 p) |
---|
41 | { |
---|
42 | return fract(sin(dot(p, vec2(12.9898, 78.2333))) * 123.4567); |
---|
43 | } |
---|
44 | |
---|
45 | void main() |
---|
46 | { |
---|
47 | vec4 col = pass_Color; |
---|
48 | #if defined GL_ES |
---|
49 | int dx = int(mod(gl_FragCoord.x, 4.0)); |
---|
50 | int dy = int(mod(gl_FragCoord.y, 4.0)); |
---|
51 | float t; |
---|
52 | if (dx == 0) |
---|
53 | { |
---|
54 | if (dy == 0) t = cluster[0][0]; else if (dy == 1) t = cluster[0][1]; else if (dy == 2) t = cluster[0][2]; else t = cluster[0][3]; |
---|
55 | } |
---|
56 | else if (dx == 1) |
---|
57 | { |
---|
58 | if (dy == 0) t = cluster[1][0]; else if (dy == 1) t = cluster[1][1]; else if (dy == 2) t = cluster[1][2]; else t = cluster[1][3]; |
---|
59 | } |
---|
60 | else if (dx == 2) |
---|
61 | { |
---|
62 | if (dy == 0) t = cluster[2][0]; else if (dy == 1) t = cluster[2][1]; else if (dy == 2) t = cluster[2][2]; else t = cluster[2][3]; |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | if (dy == 0) t = cluster[3][0]; else if (dy == 1) t = cluster[3][1]; else if (dy == 2) t = cluster[3][2]; else t = cluster[3][3]; |
---|
67 | } |
---|
68 | #else |
---|
69 | float t = cluster[int(mod(gl_FragCoord.x, 4.0))] |
---|
70 | [int(mod(gl_FragCoord.y, 4.0))]; |
---|
71 | #endif |
---|
72 | t += rand(gl_FragCoord.xy) - 0.5; |
---|
73 | t = (t + 0.5) / 17.0; |
---|
74 | col.x += fract(t - col.x) - t; |
---|
75 | col.y += fract(t - col.y) - t; |
---|
76 | col.z += fract(t - col.z) - t; |
---|
77 | gl_FragColor = col; |
---|
78 | } |
---|
79 | |
---|
80 | [vert.hlsl] |
---|
81 | |
---|
82 | void main(float4 in_Vertex : POSITION, |
---|
83 | float4 in_Color : COLOR, |
---|
84 | uniform float4x4 proj_matrix, |
---|
85 | uniform float4x4 view_matrix, |
---|
86 | uniform float4x4 model_matrix, |
---|
87 | out float4 out_Color : COLOR, |
---|
88 | out float4 out_Position : POSITION) |
---|
89 | { |
---|
90 | out_Position = mul(proj_matrix, mul(view_matrix, mul(model_matrix, in_Vertex))); |
---|
91 | out_Color = in_Color; |
---|
92 | } |
---|
93 | |
---|
94 | [frag.hlsl] |
---|
95 | |
---|
96 | float4x4 bayer = float4x4( 0.0, 12.0, 3.0, 15.0, |
---|
97 | 8.0, 4.0, 11.0, 7.0, |
---|
98 | 2.0, 14.0, 1.0, 13.0, |
---|
99 | 10.0, 6.0, 9.0, 5.0); |
---|
100 | |
---|
101 | #if 1 |
---|
102 | float4x4 cluster = float4x4(12.0, 5.0, 6.0, 13.0, |
---|
103 | 4.0, 0.0, 1.0, 7.0, |
---|
104 | 11.0, 3.0, 2.0, 8.0, |
---|
105 | 15.0, 10.0, 9.0, 14.0); |
---|
106 | #endif |
---|
107 | |
---|
108 | void main(float4 in_Color : COLOR, |
---|
109 | float4 in_FragCoord : WPOS, |
---|
110 | out float4 out_FragColor : COLOR) |
---|
111 | { |
---|
112 | float4 col = in_Color; |
---|
113 | #if 1 |
---|
114 | int x = (int)in_FragCoord.x; |
---|
115 | int y = (int)in_FragCoord.y; |
---|
116 | |
---|
117 | // FIXME: we cannot address this matrix directly on the PS3 |
---|
118 | float t = bayer[int(frac(x * 0.25) * 4.0)] |
---|
119 | [int(frac(y * 0.25) * 4.0)]; |
---|
120 | |
---|
121 | t = (t + 0.5) / 17.0; |
---|
122 | col.x += frac(t - col.x) - t; |
---|
123 | col.y += frac(t - col.y) - t; |
---|
124 | col.z += frac(t - col.z) - t; |
---|
125 | #endif |
---|
126 | out_FragColor = col; |
---|
127 | } |
---|
128 | |
---|