Loading space_view3d_virtual_reality/oculus_dk2.glsl +25 −46 Changes for space_view3d_virtual_reality/oculus_dk2.glsl: 25 added lines, 46 removed lines. Original line number Diff line number Diff line // Oculus DK2 lens distortion shader for single eye // shader is adapted from Oculus DK1 distortion shader by // Lubosz Sarnecki(lubosz.wordpress.com/)a uniform sampler2D bgl_RenderedTexture; uniform float bgl_RenderedTextureWidth; uniform float bgl_RenderedTextureHeight; uniform float bgl_RenderedStereoEye; const vec4 kappa = vec4(1.0,0.7,1.0,1.0); const vec4 kappa = vec4(1.0,0.9,1.0,2.0); float screen_width = bgl_RenderedTextureWidth; float screen_height = bgl_RenderedTextureHeight; const float scaleFactor = 0.85; const vec2 leftCenter = vec2(0.25, 0.5); const vec2 rightCenter = vec2(0.75, 0.5); const float scaleFactor = 0.83; const float separation = -0.00; const vec2 lensCenter = vec2(0.5, 0.5); // Scales input texture coordinates for distortion. vec2 hmdWarp(vec2 LensCenter, vec2 texCoord, vec2 Scale, vec2 ScaleIn, float eta) { vec2 theta = (texCoord - LensCenter) * ScaleIn; vec2 hmdWarp(vec2 texCoord, vec2 Scale, vec2 ScaleIn, float eta) { vec2 theta = (texCoord - lensCenter) * ScaleIn; float rSq = theta.x * theta.x + theta.y * theta.y; vec2 rvector = theta * (kappa.x + kappa.y * rSq + kappa.z * rSq * rSq + kappa.w * rSq * rSq * rSq); vec2 tc = LensCenter + Scale * eta * rvector; vec2 tc = lensCenter + Scale * eta * rvector; return tc; } bool validate(vec2 tc, int left_eye) float edges(vec2 tc) { //keep within bounds of texture if ((left_eye == 1 && (tc.x < 0.0 || tc.x > 0.5)) || (left_eye == 0 && (tc.x < 0.5 || tc.x > 1.0)) || tc.y < 0.0 || tc.y > 1.0) { return false; } return true; float vertL = smoothstep(0.0,0.05,tc.x); float vertR = smoothstep(1.0,0.95,tc.x); float horizL = smoothstep(0.0,0.05,tc.y); float horizR = smoothstep(1.0,0.95,tc.y); return vertL*vertR*horizL*horizR; } void main() { vec2 screen = vec2(screen_width, screen_height); vec3 eta = vec3(1.00,1.018,1.042); //refraction indices float as = float(screen.x / 2.0) / float(screen.y); vec2 Scale = vec2(0.47, as); vec2 ScaleIn = vec2(2.0 * scaleFactor, 1.0 / as * scaleFactor); vec2 texCoord = (gl_TexCoord[0].st); texCoord.x *= 0.5; float as = float(screen.x) / float(screen.y); vec2 Scale = vec2(1.0, 1.0); vec2 ScaleIn = vec2(scaleFactor, scaleFactor); if (bgl_RenderedStereoEye > 0.1) texCoord.x += 0.5; vec2 texCoordSeparated = texCoord; vec2 texCoord = gl_TexCoord[0].st; vec2 tcR = vec2(0.0); vec2 tcG = vec2(0.0); Loading @@ -58,27 +51,13 @@ void main() vec4 color = vec4(0.0); if (texCoord.x < 0.5) { texCoordSeparated.x += separation; tcR = hmdWarp(leftCenter, texCoordSeparated, Scale, ScaleIn, eta.r ); tcG = hmdWarp(leftCenter, texCoordSeparated, Scale, ScaleIn, eta.g ); tcB = hmdWarp(leftCenter, texCoordSeparated, Scale, ScaleIn, eta.b ); tcR = hmdWarp(texCoord, Scale, ScaleIn, eta.r ); tcG = hmdWarp(texCoord, Scale, ScaleIn, eta.g ); tcB = hmdWarp(texCoord, Scale, ScaleIn, eta.b ); color.r = texture2D(bgl_RenderedTexture, tcR).r; color.g = texture2D(bgl_RenderedTexture, tcG).g; color.b = texture2D(bgl_RenderedTexture, tcB).b; color = color * edges(tcR); if (!validate(tcR, 1)) color = vec4(0.0); } else { texCoordSeparated.x -= separation; tcR = hmdWarp(rightCenter, texCoordSeparated, Scale, ScaleIn, eta.r ); tcG = hmdWarp(rightCenter, texCoordSeparated, Scale, ScaleIn, eta.g ); tcB = hmdWarp(rightCenter, texCoordSeparated, Scale, ScaleIn, eta.b ); color.r = texture2D(bgl_RenderedTexture, tcR).r; color.g = texture2D(bgl_RenderedTexture, tcG).g; color.b = texture2D(bgl_RenderedTexture, tcB).b; if (!validate(tcR, 0)) color = vec4(0.0); } gl_FragColor = color; } Loading
space_view3d_virtual_reality/oculus_dk2.glsl +25 −46 Changes for space_view3d_virtual_reality/oculus_dk2.glsl: 25 added lines, 46 removed lines. Original line number Diff line number Diff line // Oculus DK2 lens distortion shader for single eye // shader is adapted from Oculus DK1 distortion shader by // Lubosz Sarnecki(lubosz.wordpress.com/)a uniform sampler2D bgl_RenderedTexture; uniform float bgl_RenderedTextureWidth; uniform float bgl_RenderedTextureHeight; uniform float bgl_RenderedStereoEye; const vec4 kappa = vec4(1.0,0.7,1.0,1.0); const vec4 kappa = vec4(1.0,0.9,1.0,2.0); float screen_width = bgl_RenderedTextureWidth; float screen_height = bgl_RenderedTextureHeight; const float scaleFactor = 0.85; const vec2 leftCenter = vec2(0.25, 0.5); const vec2 rightCenter = vec2(0.75, 0.5); const float scaleFactor = 0.83; const float separation = -0.00; const vec2 lensCenter = vec2(0.5, 0.5); // Scales input texture coordinates for distortion. vec2 hmdWarp(vec2 LensCenter, vec2 texCoord, vec2 Scale, vec2 ScaleIn, float eta) { vec2 theta = (texCoord - LensCenter) * ScaleIn; vec2 hmdWarp(vec2 texCoord, vec2 Scale, vec2 ScaleIn, float eta) { vec2 theta = (texCoord - lensCenter) * ScaleIn; float rSq = theta.x * theta.x + theta.y * theta.y; vec2 rvector = theta * (kappa.x + kappa.y * rSq + kappa.z * rSq * rSq + kappa.w * rSq * rSq * rSq); vec2 tc = LensCenter + Scale * eta * rvector; vec2 tc = lensCenter + Scale * eta * rvector; return tc; } bool validate(vec2 tc, int left_eye) float edges(vec2 tc) { //keep within bounds of texture if ((left_eye == 1 && (tc.x < 0.0 || tc.x > 0.5)) || (left_eye == 0 && (tc.x < 0.5 || tc.x > 1.0)) || tc.y < 0.0 || tc.y > 1.0) { return false; } return true; float vertL = smoothstep(0.0,0.05,tc.x); float vertR = smoothstep(1.0,0.95,tc.x); float horizL = smoothstep(0.0,0.05,tc.y); float horizR = smoothstep(1.0,0.95,tc.y); return vertL*vertR*horizL*horizR; } void main() { vec2 screen = vec2(screen_width, screen_height); vec3 eta = vec3(1.00,1.018,1.042); //refraction indices float as = float(screen.x / 2.0) / float(screen.y); vec2 Scale = vec2(0.47, as); vec2 ScaleIn = vec2(2.0 * scaleFactor, 1.0 / as * scaleFactor); vec2 texCoord = (gl_TexCoord[0].st); texCoord.x *= 0.5; float as = float(screen.x) / float(screen.y); vec2 Scale = vec2(1.0, 1.0); vec2 ScaleIn = vec2(scaleFactor, scaleFactor); if (bgl_RenderedStereoEye > 0.1) texCoord.x += 0.5; vec2 texCoordSeparated = texCoord; vec2 texCoord = gl_TexCoord[0].st; vec2 tcR = vec2(0.0); vec2 tcG = vec2(0.0); Loading @@ -58,27 +51,13 @@ void main() vec4 color = vec4(0.0); if (texCoord.x < 0.5) { texCoordSeparated.x += separation; tcR = hmdWarp(leftCenter, texCoordSeparated, Scale, ScaleIn, eta.r ); tcG = hmdWarp(leftCenter, texCoordSeparated, Scale, ScaleIn, eta.g ); tcB = hmdWarp(leftCenter, texCoordSeparated, Scale, ScaleIn, eta.b ); tcR = hmdWarp(texCoord, Scale, ScaleIn, eta.r ); tcG = hmdWarp(texCoord, Scale, ScaleIn, eta.g ); tcB = hmdWarp(texCoord, Scale, ScaleIn, eta.b ); color.r = texture2D(bgl_RenderedTexture, tcR).r; color.g = texture2D(bgl_RenderedTexture, tcG).g; color.b = texture2D(bgl_RenderedTexture, tcB).b; color = color * edges(tcR); if (!validate(tcR, 1)) color = vec4(0.0); } else { texCoordSeparated.x -= separation; tcR = hmdWarp(rightCenter, texCoordSeparated, Scale, ScaleIn, eta.r ); tcG = hmdWarp(rightCenter, texCoordSeparated, Scale, ScaleIn, eta.g ); tcB = hmdWarp(rightCenter, texCoordSeparated, Scale, ScaleIn, eta.b ); color.r = texture2D(bgl_RenderedTexture, tcR).r; color.g = texture2D(bgl_RenderedTexture, tcG).g; color.b = texture2D(bgl_RenderedTexture, tcB).b; if (!validate(tcR, 0)) color = vec4(0.0); } gl_FragColor = color; }