From cead5081bef78ee2b9fe0e948c7fc05977b2629c Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 5 Jun 2014 02:56:25 +0200 Subject: [PATCH] Fix MLAA --- data/shaders/mlaa_blend2.frag | 16 ++++++++++++---- data/shaders/mlaa_offset.vert | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/data/shaders/mlaa_blend2.frag b/data/shaders/mlaa_blend2.frag index ccce69602..d227dfc83 100644 --- a/data/shaders/mlaa_blend2.frag +++ b/data/shaders/mlaa_blend2.frag @@ -1,7 +1,15 @@ uniform sampler2D edgesMap; uniform sampler2D areaMap; -uniform vec2 PIXEL_SIZE; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; + vec2 screen; +}; #define MAX_SEARCH_STEPS 8.0 #define MAX_DISTANCE 33.0 @@ -16,7 +24,7 @@ out vec4 FragColor; * bit. */ vec4 tex2Doffset(sampler2D map, vec2 texcoord, vec2 offset) { - return textureLod(map, texcoord + PIXEL_SIZE * offset, 0.0); + return textureLod(map, texcoord + offset / screen, 0.0); } float SearchXLeft(vec2 texcoord) { @@ -87,7 +95,7 @@ void main() { // Now fetch the crossing edges. Instead of sampling between edgels, we // sample at 0.25, to be able to discern what value has each edgel: - vec4 coords = vec4(d.x, 0.25, d.y + 1.0, 0.25) * PIXEL_SIZE.xyxy + uv.xyxy; + vec4 coords = vec4(d.x, 0.25, d.y + 1.0, 0.25) / screen.xyxy + uv.xyxy; float e1 = textureLod(edgesMap, coords.xy, 0.0).r; float e2 = textureLod(edgesMap, coords.zw, 0.0).r; @@ -102,7 +110,7 @@ void main() { vec2 d = vec2(SearchYUp(uv), SearchYDown(uv)); // Now fetch the crossing edges (yet again): - vec4 coords = vec4(-0.25, d.x, -0.25, d.y - 1.0) * PIXEL_SIZE.xyxy + uv.xyxy; + vec4 coords = vec4(-0.25, d.x, -0.25, d.y - 1.0) / screen.xyxy + uv.xyxy; float e1 = textureLod(edgesMap, coords.xy, 0.0).g; float e2 = textureLod(edgesMap, coords.zw, 0.0).g; diff --git a/data/shaders/mlaa_offset.vert b/data/shaders/mlaa_offset.vert index 111ca2a55..88aa272ba 100644 --- a/data/shaders/mlaa_offset.vert +++ b/data/shaders/mlaa_offset.vert @@ -20,6 +20,6 @@ void main() { // invy.y = 1.0 - invy.y; uv = invy.st; - offset[0] = invy.xyxy + screen.xyxy * vec4(-1.0, 0.0, 0.0, 1.0); - offset[1] = invy.xyxy + screen.xyxy * vec4( 1.0, 0.0, 0.0, -1.0); + offset[0] = invy.xyxy + vec4(-1.0, 0.0, 0.0, 1.0) / screen.xyxy; + offset[1] = invy.xyxy + vec4( 1.0, 0.0, 0.0, -1.0) / screen.xyxy; }