ovr_sdk
diff LibOVR/Src/CAPI/GL/CAPI_GL_DistortionShaders.h @ 0:1b39a1b46319
initial 0.4.4
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 14 Jan 2015 06:51:16 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/CAPI/GL/CAPI_GL_DistortionShaders.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,456 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 + Filename : CAPI_GL_Shaders.h 1.7 + Content : Distortion shader header for GL 1.8 + Created : November 11, 2013 1.9 + Authors : David Borel, Volga Aksoy 1.10 + 1.11 + Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.12 + 1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.15 +which is provided at the time of installation or download, or which 1.16 +otherwise accompanies this software in either electronic or hard copy form. 1.17 + 1.18 +You may obtain a copy of the License at 1.19 + 1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.21 + 1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.23 +distributed under the License is distributed on an "AS IS" BASIS, 1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.25 +See the License for the specific language governing permissions and 1.26 +limitations under the License. 1.27 + 1.28 + ************************************************************************************/ 1.29 + 1.30 + 1.31 +#ifndef OVR_CAPI_GL_Shaders_h 1.32 +#define OVR_CAPI_GL_Shaders_h 1.33 + 1.34 + 1.35 +#include "CAPI_GL_Util.h" 1.36 + 1.37 +namespace OVR { namespace CAPI { namespace GL { 1.38 + 1.39 + static const char glsl2Prefix[] = 1.40 + "#version 110\n" 1.41 + "#extension GL_ARB_shader_texture_lod : enable\n" 1.42 + "#extension GL_ARB_draw_buffers : enable\n" 1.43 + "#extension GL_EXT_gpu_shader4 : enable\n" 1.44 + "#define _FRAGCOLOR_DECLARATION\n" 1.45 + "#define _MRTFRAGCOLOR0_DECLARATION\n" 1.46 + "#define _MRTFRAGCOLOR1_DECLARATION\n" 1.47 + "#define _GLFRAGCOORD_DECLARATION\n" 1.48 + "#define _VS_IN attribute\n" 1.49 + "#define _VS_OUT varying\n" 1.50 + "#define _FS_IN varying\n" 1.51 + "#define _TEXTURELOD texture2DLod\n" 1.52 + "#define _TEXTURE texture2D\n" 1.53 + "#define _FRAGCOLOR gl_FragColor\n" 1.54 + "#define _MRTFRAGCOLOR0 gl_FragData[0]\n" 1.55 + "#define _MRTFRAGCOLOR1 gl_FragData[1]\n" // The texture coordinate [0.0,1.0] for texel i of a texture of size N is: (2i + 1)/2N 1.56 + "#ifdef GL_EXT_gpu_shader4\n" 1.57 + " #define _TEXELFETCHDECL vec4 texelFetch(sampler2D tex, ivec2 coord, int lod){ ivec2 size = textureSize2D(tex, lod); return texture2D(tex, vec2(float((coord.x * 2) + 1) / float(size.x * 2), float((coord.y * 2) + 1) / float(size.y * 2))); }\n" 1.58 + "#endif\n"; 1.59 + 1.60 + static const char glsl3Prefix[] = 1.61 + "#version 150\n" 1.62 + "#define _FRAGCOLOR_DECLARATION out vec4 FragColor;\n" 1.63 + "#define _MRTFRAGCOLOR0_DECLARATION out vec4 FragData0;\n" 1.64 + "#define _MRTFRAGCOLOR1_DECLARATION out vec4 FragData1;\n" 1.65 + "#define _GLFRAGCOORD_DECLARATION in vec4 gl_FragCoord;\n" 1.66 + "#define _VS_IN in\n" 1.67 + "#define _VS_OUT out\n" 1.68 + "#define _FS_IN in\n" 1.69 + "#define _TEXTURELOD textureLod\n" 1.70 + "#define _TEXTURE texture\n" 1.71 + "#define _FRAGCOLOR FragColor\n" 1.72 + "#define _MRTFRAGCOLOR0 FragData0\n" 1.73 + "#define _MRTFRAGCOLOR1 FragData1\n" 1.74 + "#define _TEXELFETCHDECL\n"; 1.75 + 1.76 + static const char SimpleQuad_vs[] = 1.77 + "uniform vec2 PositionOffset;\n" 1.78 + "uniform vec2 Scale;\n" 1.79 + 1.80 + "_VS_IN vec3 Position;\n" 1.81 + 1.82 + "void main()\n" 1.83 + "{\n" 1.84 + " gl_Position = vec4(Position.xy * Scale + PositionOffset, 0.5, 1.0);\n" 1.85 + "}\n"; 1.86 + 1.87 + const OVR::CAPI::GL::ShaderBase::Uniform SimpleQuad_vs_refl[] = 1.88 + { 1.89 + { "PositionOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 }, 1.90 + { "Scale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 }, 1.91 + }; 1.92 + 1.93 + static const char SimpleQuad_fs[] = 1.94 + "uniform vec4 Color;\n" 1.95 + 1.96 + "_FRAGCOLOR_DECLARATION\n" 1.97 + 1.98 + "void main()\n" 1.99 + "{\n" 1.100 + " _FRAGCOLOR = Color;\n" 1.101 + "}\n"; 1.102 + 1.103 + const OVR::CAPI::GL::ShaderBase::Uniform SimpleQuad_fs_refl[] = 1.104 + { 1.105 + { "Color", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 16 }, 1.106 + }; 1.107 + 1.108 + static const char SimpleQuadGamma_fs[] = 1.109 + "uniform vec4 Color;\n" 1.110 + 1.111 + "_FRAGCOLOR_DECLARATION\n" 1.112 + 1.113 + "void main()\n" 1.114 + "{\n" 1.115 + " _FRAGCOLOR.rgb = pow(Color.rgb, vec3(2.2));\n" 1.116 + " _FRAGCOLOR.a = Color.a;\n" 1.117 + "}\n"; 1.118 + 1.119 + const OVR::CAPI::GL::ShaderBase::Uniform SimpleQuadGamma_fs_refl[] = 1.120 + { 1.121 + { "Color", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 16 }, 1.122 + }; 1.123 + 1.124 + // This must be prefixed with glsl2Prefix or glsl3Prefix before being compiled. 1.125 + static const char SimpleTexturedQuad_vs[] = 1.126 + "uniform vec2 PositionOffset;\n" 1.127 + "uniform vec2 Scale;\n" 1.128 + 1.129 + "_VS_IN vec3 Position;\n" 1.130 + "_VS_IN vec4 Color;\n" 1.131 + "_VS_IN vec2 TexCoord;\n" 1.132 + 1.133 + "_VS_OUT vec4 oColor;\n" 1.134 + "_VS_OUT vec2 oTexCoord;\n" 1.135 + 1.136 + "void main()\n" 1.137 + "{\n" 1.138 + " gl_Position = vec4(Position.xy * Scale + PositionOffset, 0.5, 1.0);\n" 1.139 + " oColor = Color;\n" 1.140 + " oTexCoord = TexCoord;\n" 1.141 + "}\n"; 1.142 + 1.143 + // The following declaration is copied from the generated D3D SimpleTexturedQuad_vs_refl.h file, with D3D_NS renamed to GL. 1.144 + const OVR::CAPI::GL::ShaderBase::Uniform SimpleTexturedQuad_vs_refl[] = 1.145 + { 1.146 + { "PositionOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 }, 1.147 + { "Scale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 }, 1.148 + }; 1.149 + 1.150 + 1.151 + // This must be prefixed with glsl2Prefix or glsl3Prefix before being compiled. 1.152 + static const char SimpleTexturedQuad_ps[] = 1.153 + "uniform sampler2D Texture0;\n" 1.154 + 1.155 + "_FS_IN vec4 oColor;\n" 1.156 + "_FS_IN vec2 oTexCoord;\n" 1.157 + 1.158 + "_FRAGCOLOR_DECLARATION\n" 1.159 + 1.160 + "void main()\n" 1.161 + "{\n" 1.162 + " _FRAGCOLOR = oColor * _TEXTURE(Texture0, oTexCoord);\n" 1.163 + "}\n"; 1.164 + 1.165 + // The following is copied from the generated D3D SimpleTexturedQuad_ps_refl.h file, with D3D_NS renamed to GL. 1.166 + const OVR::CAPI::GL::ShaderBase::Uniform SimpleTexturedQuad_ps_refl[] = 1.167 + { 1.168 + { "Color", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 16 }, 1.169 + }; 1.170 + 1.171 + 1.172 + static const char Distortion_vs[] = 1.173 + "uniform vec2 EyeToSourceUVScale;\n" 1.174 + "uniform vec2 EyeToSourceUVOffset;\n" 1.175 + 1.176 + "_VS_IN vec2 Position;\n" 1.177 + "_VS_IN vec4 Color;\n" 1.178 + "_VS_IN vec2 TexCoord0;\n" 1.179 + 1.180 + "_VS_OUT vec4 oColor;\n" 1.181 + "_VS_OUT vec2 oTexCoord0;\n" 1.182 + 1.183 + "void main()\n" 1.184 + "{\n" 1.185 + " gl_Position.x = Position.x;\n" 1.186 + " gl_Position.y = Position.y;\n" 1.187 + " gl_Position.z = 0.5;\n" 1.188 + " gl_Position.w = 1.0;\n" 1.189 + // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion). 1.190 + // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye) 1.191 + " oTexCoord0 = TexCoord0 * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.192 + " oColor = Color;\n" // Used for vignette fade. 1.193 + "}\n"; 1.194 + 1.195 + const OVR::CAPI::GL::ShaderBase::Uniform Distortion_vs_refl[] = 1.196 + { 1.197 + { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 }, 1.198 + { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 }, 1.199 + }; 1.200 + 1.201 + static const char Distortion_fs[] = 1.202 + "uniform sampler2D Texture0;\n" 1.203 + 1.204 + "_FS_IN vec4 oColor;\n" 1.205 + "_FS_IN vec2 oTexCoord0;\n" 1.206 + 1.207 + "_FRAGCOLOR_DECLARATION\n" 1.208 + 1.209 + "void main()\n" 1.210 + "{\n" 1.211 + " _FRAGCOLOR = _TEXTURE(Texture0, oTexCoord0, 0.0);\n" 1.212 + " _FRAGCOLOR.a = 1.0;\n" 1.213 + "}\n"; 1.214 + 1.215 + 1.216 + static const char DistortionTimewarp_vs[] = 1.217 + "uniform vec2 EyeToSourceUVScale;\n" 1.218 + "uniform vec2 EyeToSourceUVOffset;\n" 1.219 + "uniform mat4 EyeRotationStart;\n" 1.220 + "uniform mat4 EyeRotationEnd;\n" 1.221 + 1.222 + "_VS_IN vec2 Position;\n" 1.223 + "_VS_IN vec4 Color;\n" 1.224 + "_VS_IN vec2 TexCoord0;\n" 1.225 + 1.226 + "_VS_OUT vec4 oColor;\n" 1.227 + "_VS_OUT vec2 oTexCoord0;\n" 1.228 + 1.229 + "void main()\n" 1.230 + "{\n" 1.231 + " gl_Position.x = Position.x;\n" 1.232 + " gl_Position.y = Position.y;\n" 1.233 + " gl_Position.z = 0.0;\n" 1.234 + " gl_Position.w = 1.0;\n" 1.235 + 1.236 + // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion). 1.237 + // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD. 1.238 + " vec3 TanEyeAngle = vec3 ( TexCoord0.x, TexCoord0.y, 1.0 );\n" 1.239 + 1.240 + // Accurate time warp lerp vs. faster 1.241 +#if 1 1.242 + // Apply the two 3x3 timewarp rotations to these vectors. 1.243 + " vec3 TransformedStart = (EyeRotationStart * vec4(TanEyeAngle, 0)).xyz;\n" 1.244 + " vec3 TransformedEnd = (EyeRotationEnd * vec4(TanEyeAngle, 0)).xyz;\n" 1.245 + // And blend between them. 1.246 + " vec3 Transformed = mix ( TransformedStart, TransformedEnd, Color.a );\n" 1.247 +#else 1.248 + " mat4 EyeRotation = mix ( EyeRotationStart, EyeRotationEnd, Color.a );\n" 1.249 + " vec3 Transformed = EyeRotation * TanEyeAngle;\n" 1.250 +#endif 1.251 + 1.252 + // Project them back onto the Z=1 plane of the rendered images. 1.253 + " float RecipZ = 1.0 / Transformed.z;\n" 1.254 + " vec2 Flattened = vec2 ( Transformed.x * RecipZ, Transformed.y * RecipZ );\n" 1.255 + 1.256 + // These are now still in TanEyeAngle space. 1.257 + // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye) 1.258 + " vec2 SrcCoord = Flattened * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.259 + " oTexCoord0 = SrcCoord;\n" 1.260 + " oColor = vec4(Color.r, Color.r, Color.r, Color.r);\n" // Used for vignette fade. 1.261 + "}\n"; 1.262 + 1.263 + 1.264 + const OVR::CAPI::GL::ShaderBase::Uniform DistortionTimewarp_vs_refl[] = 1.265 + { 1.266 + { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 }, 1.267 + { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 }, 1.268 + }; 1.269 + 1.270 + static const char DistortionChroma_vs[] = 1.271 + "uniform vec2 EyeToSourceUVScale;\n" 1.272 + "uniform vec2 EyeToSourceUVOffset;\n" 1.273 + 1.274 + "_VS_IN vec2 Position;\n" 1.275 + "_VS_IN vec4 Color;\n" 1.276 + "_VS_IN vec2 TexCoord0;\n" 1.277 + "_VS_IN vec2 TexCoord1;\n" 1.278 + "_VS_IN vec2 TexCoord2;\n" 1.279 + 1.280 + "_VS_OUT vec4 oColor;\n" 1.281 + "_VS_OUT vec2 oTexCoord0;\n" 1.282 + "_VS_OUT vec2 oTexCoord1;\n" 1.283 + "_VS_OUT vec2 oTexCoord2;\n" 1.284 + 1.285 + "void main()\n" 1.286 + "{\n" 1.287 + " gl_Position.x = Position.x;\n" 1.288 + " gl_Position.y = Position.y;\n" 1.289 + " gl_Position.z = 0.5;\n" 1.290 + " gl_Position.w = 1.0;\n" 1.291 + 1.292 + // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion). 1.293 + // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye) 1.294 + " oTexCoord0 = TexCoord0 * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.295 + " oTexCoord1 = TexCoord1 * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.296 + " oTexCoord2 = TexCoord2 * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.297 + 1.298 + " oColor = Color;\n" // Used for vignette fade. 1.299 + "}\n"; 1.300 + 1.301 + const OVR::CAPI::GL::ShaderBase::Uniform DistortionChroma_vs_refl[] = 1.302 + { 1.303 + { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 }, 1.304 + { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 }, 1.305 + }; 1.306 + 1.307 + static const char DistortionChroma_fs[] = 1.308 + "uniform sampler2D Texture0;\n" 1.309 + "uniform sampler2D Texture1;\n" 1.310 + "uniform vec3 OverdriveScales_IsSrgb;\n" 1.311 + 1.312 + "_FS_IN vec4 oColor;\n" 1.313 + "_FS_IN vec2 oTexCoord0;\n" 1.314 + "_FS_IN vec2 oTexCoord1;\n" 1.315 + "_FS_IN vec2 oTexCoord2;\n" 1.316 + 1.317 + "_MRTFRAGCOLOR0_DECLARATION\n" // Desired color (next frame's "PrevTexture") 1.318 + "_MRTFRAGCOLOR1_DECLARATION\n" // Overdriven color (Back-buffer) 1.319 + "_GLFRAGCOORD_DECLARATION\n" 1.320 + 1.321 + "#ifdef _TEXELFETCHDECL\n" 1.322 + "_TEXELFETCHDECL\n" 1.323 + "#endif\n" 1.324 + 1.325 + "void main()\n" 1.326 + "{\n" 1.327 + " float ResultR = _TEXTURE(Texture0, oTexCoord0, 0.0).r;\n" 1.328 + " float ResultG = _TEXTURE(Texture0, oTexCoord1, 0.0).g;\n" 1.329 + " float ResultB = _TEXTURE(Texture0, oTexCoord2, 0.0).b;\n" 1.330 + " vec3 newColor = vec3(ResultR * oColor.r, ResultG * oColor.g, ResultB * oColor.b);\n" 1.331 + 1.332 + " _MRTFRAGCOLOR0 = vec4(newColor, 1);\n" 1.333 + " _MRTFRAGCOLOR1 = _MRTFRAGCOLOR0;\n" 1.334 + 1.335 + " #ifdef _TEXELFETCHDECL\n" 1.336 + // pixel luminance overdrive 1.337 + " if(OverdriveScales_IsSrgb.x > 0.0)\n" 1.338 + " {\n" 1.339 + " ivec2 pixelCoord = ivec2(gl_FragCoord.x, gl_FragCoord.y);\n" 1.340 + " vec3 oldColor = texelFetch(Texture1, pixelCoord, 0).rgb;\n" 1.341 + 1.342 + " vec3 adjustedScales;\n" 1.343 + " adjustedScales.x = newColor.x > oldColor.x ? OverdriveScales_IsSrgb.x : OverdriveScales_IsSrgb.y;\n" 1.344 + " adjustedScales.y = newColor.y > oldColor.y ? OverdriveScales_IsSrgb.x : OverdriveScales_IsSrgb.y;\n" 1.345 + " adjustedScales.z = newColor.z > oldColor.z ? OverdriveScales_IsSrgb.x : OverdriveScales_IsSrgb.y;\n" 1.346 + 1.347 + // overdrive is tuned for gamma space so if we're in linear space fix gamma before doing the calculation 1.348 + " vec3 overdriveColor;\n" 1.349 + " if(OverdriveScales_IsSrgb.z > 0.0)\n" 1.350 + " {\n" 1.351 + " oldColor = pow(oldColor, vec3(1.0/2.2, 1.0/2.2, 1.0/2.2));\n" 1.352 + " newColor = pow(newColor, vec3(1.0/2.2, 1.0/2.2, 1.0/2.2));\n" 1.353 + " overdriveColor = clamp(newColor + (newColor - oldColor) * adjustedScales, 0.0, 1.0);\n" 1.354 + " overdriveColor = pow(overdriveColor, vec3(2.2, 2.2, 2.2));\n" 1.355 + " }\n" 1.356 + " else\n" 1.357 + " overdriveColor = clamp(newColor + (newColor - oldColor) * adjustedScales, 0.0, 1.0);\n" 1.358 + 1.359 + " _MRTFRAGCOLOR1 = vec4(overdriveColor, 1.0);\n" 1.360 + " }\n" 1.361 + " #else\n" 1.362 + // If statement to keep OverdriveScales_IsSrgb from being optimized out. 1.363 + " if(OverdriveScales_IsSrgb.x > 0.0)\n" 1.364 + " _MRTFRAGCOLOR1 = vec4(newColor, 1);\n" 1.365 + " #endif\n" 1.366 + "}\n"; 1.367 + 1.368 + const OVR::CAPI::GL::ShaderBase::Uniform DistortionChroma_ps_refl[] = 1.369 + { 1.370 + { "OverdriveScales_IsSrgb", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 12 }, 1.371 + }; 1.372 + 1.373 + static const char DistortionTimewarpChroma_vs[] = 1.374 + "uniform vec2 EyeToSourceUVScale;\n" 1.375 + "uniform vec2 EyeToSourceUVOffset;\n" 1.376 + "uniform mat4 EyeRotationStart;\n" 1.377 + "uniform mat4 EyeRotationEnd;\n" 1.378 + 1.379 + "_VS_IN vec2 Position;\n" 1.380 + "_VS_IN vec4 Color;\n" 1.381 + "_VS_IN vec2 TexCoord0;\n" 1.382 + "_VS_IN vec2 TexCoord1;\n" 1.383 + "_VS_IN vec2 TexCoord2;\n" 1.384 + 1.385 + "_VS_OUT vec4 oColor;\n" 1.386 + "_VS_OUT vec2 oTexCoord0;\n" 1.387 + "_VS_OUT vec2 oTexCoord1;\n" 1.388 + "_VS_OUT vec2 oTexCoord2;\n" 1.389 + 1.390 + "void main()\n" 1.391 + "{\n" 1.392 + " gl_Position.x = Position.x;\n" 1.393 + " gl_Position.y = Position.y;\n" 1.394 + " gl_Position.z = 0.0;\n" 1.395 + " gl_Position.w = 1.0;\n" 1.396 + 1.397 + // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion). 1.398 + // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD. 1.399 + " vec3 TanEyeAngleR = vec3 ( TexCoord0.x, TexCoord0.y, 1.0 );\n" 1.400 + " vec3 TanEyeAngleG = vec3 ( TexCoord1.x, TexCoord1.y, 1.0 );\n" 1.401 + " vec3 TanEyeAngleB = vec3 ( TexCoord2.x, TexCoord2.y, 1.0 );\n" 1.402 + 1.403 + // Accurate time warp lerp vs. faster 1.404 +#if 1 1.405 + // Apply the two 3x3 timewarp rotations to these vectors. 1.406 + " vec3 TransformedRStart = (EyeRotationStart * vec4(TanEyeAngleR, 0)).xyz;\n" 1.407 + " vec3 TransformedGStart = (EyeRotationStart * vec4(TanEyeAngleG, 0)).xyz;\n" 1.408 + " vec3 TransformedBStart = (EyeRotationStart * vec4(TanEyeAngleB, 0)).xyz;\n" 1.409 + " vec3 TransformedREnd = (EyeRotationEnd * vec4(TanEyeAngleR, 0)).xyz;\n" 1.410 + " vec3 TransformedGEnd = (EyeRotationEnd * vec4(TanEyeAngleG, 0)).xyz;\n" 1.411 + " vec3 TransformedBEnd = (EyeRotationEnd * vec4(TanEyeAngleB, 0)).xyz;\n" 1.412 + 1.413 + // And blend between them. 1.414 + " vec3 TransformedR = mix ( TransformedRStart, TransformedREnd, Color.a );\n" 1.415 + " vec3 TransformedG = mix ( TransformedGStart, TransformedGEnd, Color.a );\n" 1.416 + " vec3 TransformedB = mix ( TransformedBStart, TransformedBEnd, Color.a );\n" 1.417 +#else 1.418 + " mat3 EyeRotation;\n" 1.419 + " EyeRotation[0] = mix ( EyeRotationStart[0], EyeRotationEnd[0], Color.a ).xyz;\n" 1.420 + " EyeRotation[1] = mix ( EyeRotationStart[1], EyeRotationEnd[1], Color.a ).xyz;\n" 1.421 + " EyeRotation[2] = mix ( EyeRotationStart[2], EyeRotationEnd[2], Color.a ).xyz;\n" 1.422 + " vec3 TransformedR = EyeRotation * TanEyeAngleR;\n" 1.423 + " vec3 TransformedG = EyeRotation * TanEyeAngleG;\n" 1.424 + " vec3 TransformedB = EyeRotation * TanEyeAngleB;\n" 1.425 +#endif 1.426 + 1.427 + // Project them back onto the Z=1 plane of the rendered images. 1.428 + " float RecipZR = 1.0 / TransformedR.z;\n" 1.429 + " float RecipZG = 1.0 / TransformedG.z;\n" 1.430 + " float RecipZB = 1.0 / TransformedB.z;\n" 1.431 + " vec2 FlattenedR = vec2 ( TransformedR.x * RecipZR, TransformedR.y * RecipZR );\n" 1.432 + " vec2 FlattenedG = vec2 ( TransformedG.x * RecipZG, TransformedG.y * RecipZG );\n" 1.433 + " vec2 FlattenedB = vec2 ( TransformedB.x * RecipZB, TransformedB.y * RecipZB );\n" 1.434 + 1.435 + // These are now still in TanEyeAngle space. 1.436 + // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye) 1.437 + " vec2 SrcCoordR = FlattenedR * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.438 + " vec2 SrcCoordG = FlattenedG * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.439 + " vec2 SrcCoordB = FlattenedB * EyeToSourceUVScale + EyeToSourceUVOffset;\n" 1.440 + 1.441 + " oTexCoord0 = SrcCoordR;\n" 1.442 + " oTexCoord1 = SrcCoordG;\n" 1.443 + " oTexCoord2 = SrcCoordB;\n" 1.444 + 1.445 + " oColor = vec4(Color.r, Color.r, Color.r, Color.r);\n" // Used for vignette fade. 1.446 + "}\n"; 1.447 + 1.448 + 1.449 + const OVR::CAPI::GL::ShaderBase::Uniform DistortionTimewarpChroma_vs_refl[] = 1.450 + { 1.451 + { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 }, 1.452 + { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 }, 1.453 + { "EyeRotationStart", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 16, 64 }, 1.454 + { "EyeRotationEnd", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 80, 64 }, 1.455 + }; 1.456 + 1.457 +}}} // OVR::CAPI::GL 1.458 + 1.459 +#endif // OVR_CAPI_GL_Shaders_h