|
|
@@ -1,15 +1,15 @@ |
|
|
|
[vert.glsl] |
|
|
|
|
|
|
|
#version 120 |
|
|
|
#version 130 |
|
|
|
|
|
|
|
uniform mat4 u_ZoomSettings; |
|
|
|
uniform vec4 u_TexelSize; |
|
|
|
uniform vec4 u_ScreenSize; |
|
|
|
uniform mat4 u_zoom_settings; |
|
|
|
uniform vec4 u_texel_size; |
|
|
|
uniform vec4 u_screen_size; |
|
|
|
|
|
|
|
attribute vec2 in_TexCoord; |
|
|
|
attribute vec2 in_Position; |
|
|
|
|
|
|
|
varying vec4 v_CenterX, v_CenterY, v_IndexX, v_IndexY; |
|
|
|
out vec4 v_center_x, v_center_y, v_index_x, v_index_y; |
|
|
|
|
|
|
|
void main(void) |
|
|
|
{ |
|
|
@@ -21,55 +21,55 @@ void main(void) |
|
|
|
* size of a texel: the distance from this new point to |
|
|
|
* the final point will be our error. */ |
|
|
|
vec4 offsets = vec4(0.5, -0.5, 0.015625, -0.015625); |
|
|
|
vec4 zoomscale = vec4(u_ZoomSettings[0][2], |
|
|
|
u_ZoomSettings[1][2], |
|
|
|
u_ZoomSettings[2][2], |
|
|
|
u_ZoomSettings[3][2]); |
|
|
|
vec4 zoomtx = vec4(u_ZoomSettings[0][0], |
|
|
|
u_ZoomSettings[1][0], |
|
|
|
u_ZoomSettings[2][0], |
|
|
|
u_ZoomSettings[3][0]); |
|
|
|
vec4 zoomty = vec4(u_ZoomSettings[0][1], |
|
|
|
u_ZoomSettings[1][1], |
|
|
|
u_ZoomSettings[2][1], |
|
|
|
u_ZoomSettings[3][1]); |
|
|
|
v_CenterX = zoomscale * in_TexCoord.x + zoomtx |
|
|
|
+ offsets.xyxy * u_TexelSize.x; |
|
|
|
v_CenterY = zoomscale * in_TexCoord.y - zoomty |
|
|
|
+ offsets.xyyx * u_TexelSize.y; |
|
|
|
vec4 zoomscale = vec4(u_zoom_settings[0][2], |
|
|
|
u_zoom_settings[1][2], |
|
|
|
u_zoom_settings[2][2], |
|
|
|
u_zoom_settings[3][2]); |
|
|
|
vec4 zoomtx = vec4(u_zoom_settings[0][0], |
|
|
|
u_zoom_settings[1][0], |
|
|
|
u_zoom_settings[2][0], |
|
|
|
u_zoom_settings[3][0]); |
|
|
|
vec4 zoomty = vec4(u_zoom_settings[0][1], |
|
|
|
u_zoom_settings[1][1], |
|
|
|
u_zoom_settings[2][1], |
|
|
|
u_zoom_settings[3][1]); |
|
|
|
v_center_x = zoomscale * in_TexCoord.x + zoomtx |
|
|
|
+ offsets.xyxy * u_texel_size.x; |
|
|
|
v_center_y = zoomscale * in_TexCoord.y - zoomty |
|
|
|
+ offsets.xyyx * u_texel_size.y; |
|
|
|
/* Precompute the multiple of one texel where our ideal |
|
|
|
* point lies. The fragment shader will call floor() on |
|
|
|
* this value. We add or remove a slight offset to avoid |
|
|
|
* rounding issues at the image's edges. */ |
|
|
|
v_IndexX = v_CenterX * u_ScreenSize.z - offsets.zwzw; |
|
|
|
v_IndexY = v_CenterY * u_ScreenSize.w - offsets.zwwz; |
|
|
|
v_index_x = v_center_x * u_screen_size.z - offsets.zwzw; |
|
|
|
v_index_y = v_center_y * u_screen_size.w - offsets.zwwz; |
|
|
|
} |
|
|
|
|
|
|
|
[frag.glsl] |
|
|
|
|
|
|
|
#version 120 |
|
|
|
#version 130 |
|
|
|
|
|
|
|
#if defined GL_ES |
|
|
|
precision highp float; |
|
|
|
#endif |
|
|
|
|
|
|
|
uniform vec4 u_TexelSize; |
|
|
|
uniform sampler2D u_Texture; |
|
|
|
uniform vec4 u_texel_size; |
|
|
|
uniform sampler2D u_texture; |
|
|
|
|
|
|
|
varying vec4 v_CenterX, v_CenterY, v_IndexX, v_IndexY; |
|
|
|
in vec4 v_center_x, v_center_y, v_index_x, v_index_y; |
|
|
|
|
|
|
|
void main(void) |
|
|
|
{ |
|
|
|
vec4 v05 = vec4(0.5, 0.5, 0.5, 0.5); |
|
|
|
vec4 rx, ry, t0, dx, dy, dd; |
|
|
|
/* Get a pixel coordinate from each slice into rx & ry */ |
|
|
|
rx = u_TexelSize.x + u_TexelSize.z * floor(v_IndexX); |
|
|
|
ry = u_TexelSize.y + u_TexelSize.w * floor(v_IndexY); |
|
|
|
rx = u_texel_size.x + u_texel_size.z * floor(v_index_x); |
|
|
|
ry = u_texel_size.y + u_texel_size.w * floor(v_index_y); |
|
|
|
/* Compute inverse distance to expected pixel in dd, |
|
|
|
* and put zero if we fall outside the texture. */ |
|
|
|
t0 = step(abs(rx - v05), v05) * step(abs(ry - v05), v05); |
|
|
|
dx = rx - v_CenterX; |
|
|
|
dy = ry - v_CenterY; |
|
|
|
dx = rx - v_center_x; |
|
|
|
dy = ry - v_center_y; |
|
|
|
#if 0 |
|
|
|
vec4 dd = t0 * (abs(dx) + abs(dy)); |
|
|
|
vec4 dd = t0 / (0.001 + sqrt((dx * dx) + (dy * dy))); |
|
|
@@ -115,78 +115,15 @@ void main(void) |
|
|
|
ret.xy = ret.xz * t2.yy + ret.yw * t2.xx; |
|
|
|
# endif |
|
|
|
/* Nearest neighbour */ |
|
|
|
gl_FragColor = texture2D(u_Texture, ret.xy); |
|
|
|
gl_FragColor = texture2D(u_texture, ret.xy); |
|
|
|
#else |
|
|
|
/* Alternate version: some kind of linear interpolation */ |
|
|
|
vec4 p0 = texture2D(u_Texture, vec2(rx.x, ry.x)); |
|
|
|
vec4 p1 = texture2D(u_Texture, vec2(rx.y, ry.y)); |
|
|
|
vec4 p2 = texture2D(u_Texture, vec2(rx.z, ry.z)); |
|
|
|
vec4 p3 = texture2D(u_Texture, vec2(rx.w, ry.w)); |
|
|
|
vec4 p0 = texture2D(u_texture, vec2(rx.x, ry.x)); |
|
|
|
vec4 p1 = texture2D(u_texture, vec2(rx.y, ry.y)); |
|
|
|
vec4 p2 = texture2D(u_texture, vec2(rx.z, ry.z)); |
|
|
|
vec4 p3 = texture2D(u_texture, vec2(rx.w, ry.w)); |
|
|
|
gl_FragColor = 1.0 / (dd.x + dd.y + dd.z + dd.w) |
|
|
|
* (dd.x * p0 + dd.y * p1 + dd.z * p2 + dd.w * p3); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
[vert.hlsl] |
|
|
|
|
|
|
|
void main(float2 a_Vertex : POSITION, |
|
|
|
float2 a_TexCoord : TEXCOORD0, |
|
|
|
uniform float4x4 u_ZoomSettings, |
|
|
|
uniform float4 u_TexelSize, |
|
|
|
uniform float4 u_ScreenSize, |
|
|
|
out float4 out_Position : POSITION0, |
|
|
|
out float4 v_CenterX : TEXCOORD0, |
|
|
|
out float4 v_CenterY : TEXCOORD1, |
|
|
|
out float4 v_IndexX : TEXCOORD2, |
|
|
|
out float4 v_IndexY : TEXCOORD3) |
|
|
|
{ |
|
|
|
out_Position = float4(a_Vertex, 0.0, 1.0); |
|
|
|
float4 offsets = float4(0.5, -0.5, 0.015625, -0.015625); |
|
|
|
float4 zoomscale = float4(u_ZoomSettings[2][0], |
|
|
|
u_ZoomSettings[2][1], |
|
|
|
u_ZoomSettings[2][2], |
|
|
|
u_ZoomSettings[2][3]); |
|
|
|
float4 zoomtx = float4(u_ZoomSettings[0][0], |
|
|
|
u_ZoomSettings[0][1], |
|
|
|
u_ZoomSettings[0][2], |
|
|
|
u_ZoomSettings[0][3]); |
|
|
|
float4 zoomty = float4(u_ZoomSettings[1][0], |
|
|
|
u_ZoomSettings[1][1], |
|
|
|
u_ZoomSettings[1][2], |
|
|
|
u_ZoomSettings[1][3]); |
|
|
|
v_CenterX = zoomscale * a_TexCoord.x + zoomtx |
|
|
|
+ offsets.xyxy * u_TexelSize.x; |
|
|
|
v_CenterY = zoomscale * a_TexCoord.y - zoomty |
|
|
|
+ offsets.xyyx * u_TexelSize.y; |
|
|
|
v_IndexX = v_CenterX * u_ScreenSize.z - offsets.zwzw; |
|
|
|
v_IndexY = v_CenterY * u_ScreenSize.w - offsets.zwwz; |
|
|
|
} |
|
|
|
|
|
|
|
[frag.hlsl] |
|
|
|
|
|
|
|
void main(in float4 v_CenterX : TEXCOORD0, |
|
|
|
in float4 v_CenterY : TEXCOORD1, |
|
|
|
in float4 v_IndexX : TEXCOORD2, |
|
|
|
in float4 v_IndexY : TEXCOORD3, |
|
|
|
uniform float4 u_TexelSize, |
|
|
|
uniform sampler2D u_Texture, |
|
|
|
out float4 out_FragColor : COLOR) |
|
|
|
{ |
|
|
|
float4 v05 = float4(0.5, 0.5, 0.5, 0.5); |
|
|
|
float4 rx, ry, t0, dx, dy, dd; |
|
|
|
rx = u_TexelSize.x + u_TexelSize.z * floor(v_IndexX); |
|
|
|
ry = u_TexelSize.y + u_TexelSize.w * floor(v_IndexY); |
|
|
|
t0 = step(abs(rx - v05), v05) * step(abs(ry - v05), v05); |
|
|
|
dx = rx - v_CenterX; |
|
|
|
dy = ry - v_CenterY; |
|
|
|
dd = t0 / (0.000001 + (dx * dx) + (dy * dy)); |
|
|
|
ry = ry * 0.25 + float4(0.0, 0.25, 0.5, 0.75); |
|
|
|
float2 t1 = step(dd.xz, dd.yw); |
|
|
|
float4 ret = lerp(float4(rx.xz, ry.xz), |
|
|
|
float4(rx.yw, ry.yw), t1.xyxy); |
|
|
|
dd.xy = lerp(dd.xz, dd.yw, t1); |
|
|
|
float t2 = step(dd.x, dd.y); |
|
|
|
ret.xy = lerp(ret.xz, ret.yw, t2); |
|
|
|
out_FragColor = tex2D(u_Texture, ret.xy); |
|
|
|
} |
|
|
|
|