diff options
Diffstat (limited to 'assets')
| -rwxr-xr-x | assets/fragment.glsl | 2 | ||||
| -rwxr-xr-x | assets/vertex.glsl | 106 |
2 files changed, 96 insertions, 12 deletions
diff --git a/assets/fragment.glsl b/assets/fragment.glsl index 5ce136e..bb1eab2 100755 --- a/assets/fragment.glsl +++ b/assets/fragment.glsl @@ -1,6 +1,7 @@ #version 330 core
flat in uvec2 pass_data;
+in float pass_ao;
out vec4 color;
@@ -18,5 +19,6 @@ void main(void) uint block = (pass_data.x >> 28) & 15u;
uint face = (pass_data.x >> 25) & 7u;
float tint = TINT[face];
+ tint *= 1.0 - pow(pass_ao / 3.0, 1.2) * 0.65;
color = vec4(vec3(tint), 1);
}
diff --git a/assets/vertex.glsl b/assets/vertex.glsl index f4c3fde..78a479c 100755 --- a/assets/vertex.glsl +++ b/assets/vertex.glsl @@ -1,6 +1,6 @@ #version 330 core
-layout (location = 0) in vec3 quad;
+layout (location = 0) in vec3 in_quad;
layout (std140) uniform Matrices {
mat4 proj;
@@ -19,6 +19,13 @@ layout (std140) uniform Face { };
flat out uvec2 pass_data;
+out float pass_ao;
+
+const mat3 ROT90 = mat3(
+ 0.0, 0.0, 1.0,
+ 0.0, 1.0, 0.0,
+ -1.0, 0.0, 0.0
+);
uint get_half(int index)
{
@@ -34,28 +41,98 @@ uvec2 get_data(int index) return uvec2(lower, upper);
}
+bool get_ao_rotate(uint data)
+{
+ vec4 ao;
+
+ ao.x = (data >> 0) & 3u;
+ ao.y = (data >> 2) & 3u;
+ ao.z = (data >> 4) & 3u;
+ ao.w = (data >> 6) & 3u;
+
+ float a = abs(ao.x - ao.w);
+ float b = abs(ao.y - ao.z);
+
+ return a > b;
+}
+
+float get_ao(uint data, uint face)
+{
+ vec4 ao;
+
+ ao.x = (data >> 0) & 3u;
+ ao.y = (data >> 2) & 3u;
+ ao.z = (data >> 4) & 3u;
+ ao.w = (data >> 6) & 3u;
+
+ switch (face) {
+ case 0u: // PX
+ case 2u: // PY
+ case 4u: // PZ
+ ao = ao.xywz;
+ if (get_ao_rotate(data))
+ ao = ao.wxyz;
+ break;
+ case 1u: // NX
+ case 3u: // NY
+ case 5u: // NZ
+ if (get_ao_rotate(data))
+ ao = ao.ywxz;
+ ao = ao.wzxy;
+ break;
+ }
+
+ return ao[gl_VertexID];
+}
+
+vec3 rotate(vec3 v, uint face)
+{
+ switch(face) {
+ case 0u: // PX
+ case 1u: // NX
+ v = vec3(v.x, v.z, -v.y + 1);
+ break;
+ case 2u: // PY
+ case 3u: // NY
+ v = vec3(-v.z + 1, v.y, v.x);
+ break;
+ case 4u: // PZ
+ case 5u: // NZ
+ v = vec3(v.y, -v.x + 1, v.z);
+ break;
+ }
+
+ return v;
+}
+
vec3 get_quad(uint face, uint width, uint height)
{
- vec3 squad = quad;
- squad.x *= width;
- squad.y *= height;
+ vec3 quad = in_quad;
+ quad.x *= width;
+ quad.y *= height;
switch(face) {
case 0u: // PX
- return squad.yzx + vec3(1, 0, 0);
+ quad = quad.yzx + vec3(1, 0, 0);
+ break;
case 1u: // NX
- return squad.yxz;
+ quad = quad.yxz;
+ break;
case 2u: // PY
- return squad.xyz + vec3(0, 1, 0);
+ quad = quad.xyz + vec3(0, 1, 0);
+ break;
case 3u: // NY
- return squad.zyx;
+ quad = quad.zyx;
+ break;
case 4u: // PZ
- return squad.zxy + vec3(0, 0, 1);
+ quad = quad.zxy + vec3(0, 0, 1);
+ break;
case 5u: // NZ
- return squad.xzy;
+ quad = quad.xzy;
+ break;
}
- // should not happen
- return vec3(0);
+
+ return quad;
}
void main(void)
@@ -71,6 +148,8 @@ void main(void) // get quad verts
vec3 quad = get_quad(face, width, height);
+ if (get_ao_rotate(data.y))
+ quad = rotate(quad, face);
// get position
vec3 position = vec3(x, y, z);
@@ -79,5 +158,8 @@ void main(void) // draw
gl_Position = proj * view * vec4(position, 1.0);
+
+ // fragment input
pass_data = data;
+ pass_ao = get_ao(data.y, face);
}
|