ovr_sdk

annotate LibOVR/Src/CAPI/GL/CAPI_GL_DistortionShaders.h @ 3:f12a8f74fe1f

added the Xcode project
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 21 Jan 2015 11:37:50 +0200
parents
children
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 Filename : CAPI_GL_Shaders.h
nuclear@0 4 Content : Distortion shader header for GL
nuclear@0 5 Created : November 11, 2013
nuclear@0 6 Authors : David Borel, Volga Aksoy
nuclear@0 7
nuclear@0 8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 9
nuclear@0 10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 11 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 12 which is provided at the time of installation or download, or which
nuclear@0 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 14
nuclear@0 15 You may obtain a copy of the License at
nuclear@0 16
nuclear@0 17 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 18
nuclear@0 19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 20 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 22 See the License for the specific language governing permissions and
nuclear@0 23 limitations under the License.
nuclear@0 24
nuclear@0 25 ************************************************************************************/
nuclear@0 26
nuclear@0 27
nuclear@0 28 #ifndef OVR_CAPI_GL_Shaders_h
nuclear@0 29 #define OVR_CAPI_GL_Shaders_h
nuclear@0 30
nuclear@0 31
nuclear@0 32 #include "CAPI_GL_Util.h"
nuclear@0 33
nuclear@0 34 namespace OVR { namespace CAPI { namespace GL {
nuclear@0 35
nuclear@0 36 static const char glsl2Prefix[] =
nuclear@0 37 "#version 110\n"
nuclear@0 38 "#extension GL_ARB_shader_texture_lod : enable\n"
nuclear@0 39 "#extension GL_ARB_draw_buffers : enable\n"
nuclear@0 40 "#extension GL_EXT_gpu_shader4 : enable\n"
nuclear@0 41 "#define _FRAGCOLOR_DECLARATION\n"
nuclear@0 42 "#define _MRTFRAGCOLOR0_DECLARATION\n"
nuclear@0 43 "#define _MRTFRAGCOLOR1_DECLARATION\n"
nuclear@0 44 "#define _GLFRAGCOORD_DECLARATION\n"
nuclear@0 45 "#define _VS_IN attribute\n"
nuclear@0 46 "#define _VS_OUT varying\n"
nuclear@0 47 "#define _FS_IN varying\n"
nuclear@0 48 "#define _TEXTURELOD texture2DLod\n"
nuclear@0 49 "#define _TEXTURE texture2D\n"
nuclear@0 50 "#define _FRAGCOLOR gl_FragColor\n"
nuclear@0 51 "#define _MRTFRAGCOLOR0 gl_FragData[0]\n"
nuclear@0 52 "#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
nuclear@0 53 "#ifdef GL_EXT_gpu_shader4\n"
nuclear@0 54 " #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"
nuclear@0 55 "#endif\n";
nuclear@0 56
nuclear@0 57 static const char glsl3Prefix[] =
nuclear@0 58 "#version 150\n"
nuclear@0 59 "#define _FRAGCOLOR_DECLARATION out vec4 FragColor;\n"
nuclear@0 60 "#define _MRTFRAGCOLOR0_DECLARATION out vec4 FragData0;\n"
nuclear@0 61 "#define _MRTFRAGCOLOR1_DECLARATION out vec4 FragData1;\n"
nuclear@0 62 "#define _GLFRAGCOORD_DECLARATION in vec4 gl_FragCoord;\n"
nuclear@0 63 "#define _VS_IN in\n"
nuclear@0 64 "#define _VS_OUT out\n"
nuclear@0 65 "#define _FS_IN in\n"
nuclear@0 66 "#define _TEXTURELOD textureLod\n"
nuclear@0 67 "#define _TEXTURE texture\n"
nuclear@0 68 "#define _FRAGCOLOR FragColor\n"
nuclear@0 69 "#define _MRTFRAGCOLOR0 FragData0\n"
nuclear@0 70 "#define _MRTFRAGCOLOR1 FragData1\n"
nuclear@0 71 "#define _TEXELFETCHDECL\n";
nuclear@0 72
nuclear@0 73 static const char SimpleQuad_vs[] =
nuclear@0 74 "uniform vec2 PositionOffset;\n"
nuclear@0 75 "uniform vec2 Scale;\n"
nuclear@0 76
nuclear@0 77 "_VS_IN vec3 Position;\n"
nuclear@0 78
nuclear@0 79 "void main()\n"
nuclear@0 80 "{\n"
nuclear@0 81 " gl_Position = vec4(Position.xy * Scale + PositionOffset, 0.5, 1.0);\n"
nuclear@0 82 "}\n";
nuclear@0 83
nuclear@0 84 const OVR::CAPI::GL::ShaderBase::Uniform SimpleQuad_vs_refl[] =
nuclear@0 85 {
nuclear@0 86 { "PositionOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 },
nuclear@0 87 { "Scale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 },
nuclear@0 88 };
nuclear@0 89
nuclear@0 90 static const char SimpleQuad_fs[] =
nuclear@0 91 "uniform vec4 Color;\n"
nuclear@0 92
nuclear@0 93 "_FRAGCOLOR_DECLARATION\n"
nuclear@0 94
nuclear@0 95 "void main()\n"
nuclear@0 96 "{\n"
nuclear@0 97 " _FRAGCOLOR = Color;\n"
nuclear@0 98 "}\n";
nuclear@0 99
nuclear@0 100 const OVR::CAPI::GL::ShaderBase::Uniform SimpleQuad_fs_refl[] =
nuclear@0 101 {
nuclear@0 102 { "Color", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 16 },
nuclear@0 103 };
nuclear@0 104
nuclear@0 105 static const char SimpleQuadGamma_fs[] =
nuclear@0 106 "uniform vec4 Color;\n"
nuclear@0 107
nuclear@0 108 "_FRAGCOLOR_DECLARATION\n"
nuclear@0 109
nuclear@0 110 "void main()\n"
nuclear@0 111 "{\n"
nuclear@0 112 " _FRAGCOLOR.rgb = pow(Color.rgb, vec3(2.2));\n"
nuclear@0 113 " _FRAGCOLOR.a = Color.a;\n"
nuclear@0 114 "}\n";
nuclear@0 115
nuclear@0 116 const OVR::CAPI::GL::ShaderBase::Uniform SimpleQuadGamma_fs_refl[] =
nuclear@0 117 {
nuclear@0 118 { "Color", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 16 },
nuclear@0 119 };
nuclear@0 120
nuclear@0 121 // This must be prefixed with glsl2Prefix or glsl3Prefix before being compiled.
nuclear@0 122 static const char SimpleTexturedQuad_vs[] =
nuclear@0 123 "uniform vec2 PositionOffset;\n"
nuclear@0 124 "uniform vec2 Scale;\n"
nuclear@0 125
nuclear@0 126 "_VS_IN vec3 Position;\n"
nuclear@0 127 "_VS_IN vec4 Color;\n"
nuclear@0 128 "_VS_IN vec2 TexCoord;\n"
nuclear@0 129
nuclear@0 130 "_VS_OUT vec4 oColor;\n"
nuclear@0 131 "_VS_OUT vec2 oTexCoord;\n"
nuclear@0 132
nuclear@0 133 "void main()\n"
nuclear@0 134 "{\n"
nuclear@0 135 " gl_Position = vec4(Position.xy * Scale + PositionOffset, 0.5, 1.0);\n"
nuclear@0 136 " oColor = Color;\n"
nuclear@0 137 " oTexCoord = TexCoord;\n"
nuclear@0 138 "}\n";
nuclear@0 139
nuclear@0 140 // The following declaration is copied from the generated D3D SimpleTexturedQuad_vs_refl.h file, with D3D_NS renamed to GL.
nuclear@0 141 const OVR::CAPI::GL::ShaderBase::Uniform SimpleTexturedQuad_vs_refl[] =
nuclear@0 142 {
nuclear@0 143 { "PositionOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 },
nuclear@0 144 { "Scale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 },
nuclear@0 145 };
nuclear@0 146
nuclear@0 147
nuclear@0 148 // This must be prefixed with glsl2Prefix or glsl3Prefix before being compiled.
nuclear@0 149 static const char SimpleTexturedQuad_ps[] =
nuclear@0 150 "uniform sampler2D Texture0;\n"
nuclear@0 151
nuclear@0 152 "_FS_IN vec4 oColor;\n"
nuclear@0 153 "_FS_IN vec2 oTexCoord;\n"
nuclear@0 154
nuclear@0 155 "_FRAGCOLOR_DECLARATION\n"
nuclear@0 156
nuclear@0 157 "void main()\n"
nuclear@0 158 "{\n"
nuclear@0 159 " _FRAGCOLOR = oColor * _TEXTURE(Texture0, oTexCoord);\n"
nuclear@0 160 "}\n";
nuclear@0 161
nuclear@0 162 // The following is copied from the generated D3D SimpleTexturedQuad_ps_refl.h file, with D3D_NS renamed to GL.
nuclear@0 163 const OVR::CAPI::GL::ShaderBase::Uniform SimpleTexturedQuad_ps_refl[] =
nuclear@0 164 {
nuclear@0 165 { "Color", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 16 },
nuclear@0 166 };
nuclear@0 167
nuclear@0 168
nuclear@0 169 static const char Distortion_vs[] =
nuclear@0 170 "uniform vec2 EyeToSourceUVScale;\n"
nuclear@0 171 "uniform vec2 EyeToSourceUVOffset;\n"
nuclear@0 172
nuclear@0 173 "_VS_IN vec2 Position;\n"
nuclear@0 174 "_VS_IN vec4 Color;\n"
nuclear@0 175 "_VS_IN vec2 TexCoord0;\n"
nuclear@0 176
nuclear@0 177 "_VS_OUT vec4 oColor;\n"
nuclear@0 178 "_VS_OUT vec2 oTexCoord0;\n"
nuclear@0 179
nuclear@0 180 "void main()\n"
nuclear@0 181 "{\n"
nuclear@0 182 " gl_Position.x = Position.x;\n"
nuclear@0 183 " gl_Position.y = Position.y;\n"
nuclear@0 184 " gl_Position.z = 0.5;\n"
nuclear@0 185 " gl_Position.w = 1.0;\n"
nuclear@0 186 // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion).
nuclear@0 187 // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye)
nuclear@0 188 " oTexCoord0 = TexCoord0 * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 189 " oColor = Color;\n" // Used for vignette fade.
nuclear@0 190 "}\n";
nuclear@0 191
nuclear@0 192 const OVR::CAPI::GL::ShaderBase::Uniform Distortion_vs_refl[] =
nuclear@0 193 {
nuclear@0 194 { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 },
nuclear@0 195 { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 },
nuclear@0 196 };
nuclear@0 197
nuclear@0 198 static const char Distortion_fs[] =
nuclear@0 199 "uniform sampler2D Texture0;\n"
nuclear@0 200
nuclear@0 201 "_FS_IN vec4 oColor;\n"
nuclear@0 202 "_FS_IN vec2 oTexCoord0;\n"
nuclear@0 203
nuclear@0 204 "_FRAGCOLOR_DECLARATION\n"
nuclear@0 205
nuclear@0 206 "void main()\n"
nuclear@0 207 "{\n"
nuclear@0 208 " _FRAGCOLOR = _TEXTURE(Texture0, oTexCoord0, 0.0);\n"
nuclear@0 209 " _FRAGCOLOR.a = 1.0;\n"
nuclear@0 210 "}\n";
nuclear@0 211
nuclear@0 212
nuclear@0 213 static const char DistortionTimewarp_vs[] =
nuclear@0 214 "uniform vec2 EyeToSourceUVScale;\n"
nuclear@0 215 "uniform vec2 EyeToSourceUVOffset;\n"
nuclear@0 216 "uniform mat4 EyeRotationStart;\n"
nuclear@0 217 "uniform mat4 EyeRotationEnd;\n"
nuclear@0 218
nuclear@0 219 "_VS_IN vec2 Position;\n"
nuclear@0 220 "_VS_IN vec4 Color;\n"
nuclear@0 221 "_VS_IN vec2 TexCoord0;\n"
nuclear@0 222
nuclear@0 223 "_VS_OUT vec4 oColor;\n"
nuclear@0 224 "_VS_OUT vec2 oTexCoord0;\n"
nuclear@0 225
nuclear@0 226 "void main()\n"
nuclear@0 227 "{\n"
nuclear@0 228 " gl_Position.x = Position.x;\n"
nuclear@0 229 " gl_Position.y = Position.y;\n"
nuclear@0 230 " gl_Position.z = 0.0;\n"
nuclear@0 231 " gl_Position.w = 1.0;\n"
nuclear@0 232
nuclear@0 233 // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion).
nuclear@0 234 // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD.
nuclear@0 235 " vec3 TanEyeAngle = vec3 ( TexCoord0.x, TexCoord0.y, 1.0 );\n"
nuclear@0 236
nuclear@0 237 // Accurate time warp lerp vs. faster
nuclear@0 238 #if 1
nuclear@0 239 // Apply the two 3x3 timewarp rotations to these vectors.
nuclear@0 240 " vec3 TransformedStart = (EyeRotationStart * vec4(TanEyeAngle, 0)).xyz;\n"
nuclear@0 241 " vec3 TransformedEnd = (EyeRotationEnd * vec4(TanEyeAngle, 0)).xyz;\n"
nuclear@0 242 // And blend between them.
nuclear@0 243 " vec3 Transformed = mix ( TransformedStart, TransformedEnd, Color.a );\n"
nuclear@0 244 #else
nuclear@0 245 " mat4 EyeRotation = mix ( EyeRotationStart, EyeRotationEnd, Color.a );\n"
nuclear@0 246 " vec3 Transformed = EyeRotation * TanEyeAngle;\n"
nuclear@0 247 #endif
nuclear@0 248
nuclear@0 249 // Project them back onto the Z=1 plane of the rendered images.
nuclear@0 250 " float RecipZ = 1.0 / Transformed.z;\n"
nuclear@0 251 " vec2 Flattened = vec2 ( Transformed.x * RecipZ, Transformed.y * RecipZ );\n"
nuclear@0 252
nuclear@0 253 // These are now still in TanEyeAngle space.
nuclear@0 254 // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye)
nuclear@0 255 " vec2 SrcCoord = Flattened * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 256 " oTexCoord0 = SrcCoord;\n"
nuclear@0 257 " oColor = vec4(Color.r, Color.r, Color.r, Color.r);\n" // Used for vignette fade.
nuclear@0 258 "}\n";
nuclear@0 259
nuclear@0 260
nuclear@0 261 const OVR::CAPI::GL::ShaderBase::Uniform DistortionTimewarp_vs_refl[] =
nuclear@0 262 {
nuclear@0 263 { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 },
nuclear@0 264 { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 },
nuclear@0 265 };
nuclear@0 266
nuclear@0 267 static const char DistortionChroma_vs[] =
nuclear@0 268 "uniform vec2 EyeToSourceUVScale;\n"
nuclear@0 269 "uniform vec2 EyeToSourceUVOffset;\n"
nuclear@0 270
nuclear@0 271 "_VS_IN vec2 Position;\n"
nuclear@0 272 "_VS_IN vec4 Color;\n"
nuclear@0 273 "_VS_IN vec2 TexCoord0;\n"
nuclear@0 274 "_VS_IN vec2 TexCoord1;\n"
nuclear@0 275 "_VS_IN vec2 TexCoord2;\n"
nuclear@0 276
nuclear@0 277 "_VS_OUT vec4 oColor;\n"
nuclear@0 278 "_VS_OUT vec2 oTexCoord0;\n"
nuclear@0 279 "_VS_OUT vec2 oTexCoord1;\n"
nuclear@0 280 "_VS_OUT vec2 oTexCoord2;\n"
nuclear@0 281
nuclear@0 282 "void main()\n"
nuclear@0 283 "{\n"
nuclear@0 284 " gl_Position.x = Position.x;\n"
nuclear@0 285 " gl_Position.y = Position.y;\n"
nuclear@0 286 " gl_Position.z = 0.5;\n"
nuclear@0 287 " gl_Position.w = 1.0;\n"
nuclear@0 288
nuclear@0 289 // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion).
nuclear@0 290 // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye)
nuclear@0 291 " oTexCoord0 = TexCoord0 * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 292 " oTexCoord1 = TexCoord1 * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 293 " oTexCoord2 = TexCoord2 * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 294
nuclear@0 295 " oColor = Color;\n" // Used for vignette fade.
nuclear@0 296 "}\n";
nuclear@0 297
nuclear@0 298 const OVR::CAPI::GL::ShaderBase::Uniform DistortionChroma_vs_refl[] =
nuclear@0 299 {
nuclear@0 300 { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 },
nuclear@0 301 { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 },
nuclear@0 302 };
nuclear@0 303
nuclear@0 304 static const char DistortionChroma_fs[] =
nuclear@0 305 "uniform sampler2D Texture0;\n"
nuclear@0 306 "uniform sampler2D Texture1;\n"
nuclear@0 307 "uniform vec3 OverdriveScales_IsSrgb;\n"
nuclear@0 308
nuclear@0 309 "_FS_IN vec4 oColor;\n"
nuclear@0 310 "_FS_IN vec2 oTexCoord0;\n"
nuclear@0 311 "_FS_IN vec2 oTexCoord1;\n"
nuclear@0 312 "_FS_IN vec2 oTexCoord2;\n"
nuclear@0 313
nuclear@0 314 "_MRTFRAGCOLOR0_DECLARATION\n" // Desired color (next frame's "PrevTexture")
nuclear@0 315 "_MRTFRAGCOLOR1_DECLARATION\n" // Overdriven color (Back-buffer)
nuclear@0 316 "_GLFRAGCOORD_DECLARATION\n"
nuclear@0 317
nuclear@0 318 "#ifdef _TEXELFETCHDECL\n"
nuclear@0 319 "_TEXELFETCHDECL\n"
nuclear@0 320 "#endif\n"
nuclear@0 321
nuclear@0 322 "void main()\n"
nuclear@0 323 "{\n"
nuclear@0 324 " float ResultR = _TEXTURE(Texture0, oTexCoord0, 0.0).r;\n"
nuclear@0 325 " float ResultG = _TEXTURE(Texture0, oTexCoord1, 0.0).g;\n"
nuclear@0 326 " float ResultB = _TEXTURE(Texture0, oTexCoord2, 0.0).b;\n"
nuclear@0 327 " vec3 newColor = vec3(ResultR * oColor.r, ResultG * oColor.g, ResultB * oColor.b);\n"
nuclear@0 328
nuclear@0 329 " _MRTFRAGCOLOR0 = vec4(newColor, 1);\n"
nuclear@0 330 " _MRTFRAGCOLOR1 = _MRTFRAGCOLOR0;\n"
nuclear@0 331
nuclear@0 332 " #ifdef _TEXELFETCHDECL\n"
nuclear@0 333 // pixel luminance overdrive
nuclear@0 334 " if(OverdriveScales_IsSrgb.x > 0.0)\n"
nuclear@0 335 " {\n"
nuclear@0 336 " ivec2 pixelCoord = ivec2(gl_FragCoord.x, gl_FragCoord.y);\n"
nuclear@0 337 " vec3 oldColor = texelFetch(Texture1, pixelCoord, 0).rgb;\n"
nuclear@0 338
nuclear@0 339 " vec3 adjustedScales;\n"
nuclear@0 340 " adjustedScales.x = newColor.x > oldColor.x ? OverdriveScales_IsSrgb.x : OverdriveScales_IsSrgb.y;\n"
nuclear@0 341 " adjustedScales.y = newColor.y > oldColor.y ? OverdriveScales_IsSrgb.x : OverdriveScales_IsSrgb.y;\n"
nuclear@0 342 " adjustedScales.z = newColor.z > oldColor.z ? OverdriveScales_IsSrgb.x : OverdriveScales_IsSrgb.y;\n"
nuclear@0 343
nuclear@0 344 // overdrive is tuned for gamma space so if we're in linear space fix gamma before doing the calculation
nuclear@0 345 " vec3 overdriveColor;\n"
nuclear@0 346 " if(OverdriveScales_IsSrgb.z > 0.0)\n"
nuclear@0 347 " {\n"
nuclear@0 348 " oldColor = pow(oldColor, vec3(1.0/2.2, 1.0/2.2, 1.0/2.2));\n"
nuclear@0 349 " newColor = pow(newColor, vec3(1.0/2.2, 1.0/2.2, 1.0/2.2));\n"
nuclear@0 350 " overdriveColor = clamp(newColor + (newColor - oldColor) * adjustedScales, 0.0, 1.0);\n"
nuclear@0 351 " overdriveColor = pow(overdriveColor, vec3(2.2, 2.2, 2.2));\n"
nuclear@0 352 " }\n"
nuclear@0 353 " else\n"
nuclear@0 354 " overdriveColor = clamp(newColor + (newColor - oldColor) * adjustedScales, 0.0, 1.0);\n"
nuclear@0 355
nuclear@0 356 " _MRTFRAGCOLOR1 = vec4(overdriveColor, 1.0);\n"
nuclear@0 357 " }\n"
nuclear@0 358 " #else\n"
nuclear@0 359 // If statement to keep OverdriveScales_IsSrgb from being optimized out.
nuclear@0 360 " if(OverdriveScales_IsSrgb.x > 0.0)\n"
nuclear@0 361 " _MRTFRAGCOLOR1 = vec4(newColor, 1);\n"
nuclear@0 362 " #endif\n"
nuclear@0 363 "}\n";
nuclear@0 364
nuclear@0 365 const OVR::CAPI::GL::ShaderBase::Uniform DistortionChroma_ps_refl[] =
nuclear@0 366 {
nuclear@0 367 { "OverdriveScales_IsSrgb", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 12 },
nuclear@0 368 };
nuclear@0 369
nuclear@0 370 static const char DistortionTimewarpChroma_vs[] =
nuclear@0 371 "uniform vec2 EyeToSourceUVScale;\n"
nuclear@0 372 "uniform vec2 EyeToSourceUVOffset;\n"
nuclear@0 373 "uniform mat4 EyeRotationStart;\n"
nuclear@0 374 "uniform mat4 EyeRotationEnd;\n"
nuclear@0 375
nuclear@0 376 "_VS_IN vec2 Position;\n"
nuclear@0 377 "_VS_IN vec4 Color;\n"
nuclear@0 378 "_VS_IN vec2 TexCoord0;\n"
nuclear@0 379 "_VS_IN vec2 TexCoord1;\n"
nuclear@0 380 "_VS_IN vec2 TexCoord2;\n"
nuclear@0 381
nuclear@0 382 "_VS_OUT vec4 oColor;\n"
nuclear@0 383 "_VS_OUT vec2 oTexCoord0;\n"
nuclear@0 384 "_VS_OUT vec2 oTexCoord1;\n"
nuclear@0 385 "_VS_OUT vec2 oTexCoord2;\n"
nuclear@0 386
nuclear@0 387 "void main()\n"
nuclear@0 388 "{\n"
nuclear@0 389 " gl_Position.x = Position.x;\n"
nuclear@0 390 " gl_Position.y = Position.y;\n"
nuclear@0 391 " gl_Position.z = 0.0;\n"
nuclear@0 392 " gl_Position.w = 1.0;\n"
nuclear@0 393
nuclear@0 394 // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion).
nuclear@0 395 // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD.
nuclear@0 396 " vec3 TanEyeAngleR = vec3 ( TexCoord0.x, TexCoord0.y, 1.0 );\n"
nuclear@0 397 " vec3 TanEyeAngleG = vec3 ( TexCoord1.x, TexCoord1.y, 1.0 );\n"
nuclear@0 398 " vec3 TanEyeAngleB = vec3 ( TexCoord2.x, TexCoord2.y, 1.0 );\n"
nuclear@0 399
nuclear@0 400 // Accurate time warp lerp vs. faster
nuclear@0 401 #if 1
nuclear@0 402 // Apply the two 3x3 timewarp rotations to these vectors.
nuclear@0 403 " vec3 TransformedRStart = (EyeRotationStart * vec4(TanEyeAngleR, 0)).xyz;\n"
nuclear@0 404 " vec3 TransformedGStart = (EyeRotationStart * vec4(TanEyeAngleG, 0)).xyz;\n"
nuclear@0 405 " vec3 TransformedBStart = (EyeRotationStart * vec4(TanEyeAngleB, 0)).xyz;\n"
nuclear@0 406 " vec3 TransformedREnd = (EyeRotationEnd * vec4(TanEyeAngleR, 0)).xyz;\n"
nuclear@0 407 " vec3 TransformedGEnd = (EyeRotationEnd * vec4(TanEyeAngleG, 0)).xyz;\n"
nuclear@0 408 " vec3 TransformedBEnd = (EyeRotationEnd * vec4(TanEyeAngleB, 0)).xyz;\n"
nuclear@0 409
nuclear@0 410 // And blend between them.
nuclear@0 411 " vec3 TransformedR = mix ( TransformedRStart, TransformedREnd, Color.a );\n"
nuclear@0 412 " vec3 TransformedG = mix ( TransformedGStart, TransformedGEnd, Color.a );\n"
nuclear@0 413 " vec3 TransformedB = mix ( TransformedBStart, TransformedBEnd, Color.a );\n"
nuclear@0 414 #else
nuclear@0 415 " mat3 EyeRotation;\n"
nuclear@0 416 " EyeRotation[0] = mix ( EyeRotationStart[0], EyeRotationEnd[0], Color.a ).xyz;\n"
nuclear@0 417 " EyeRotation[1] = mix ( EyeRotationStart[1], EyeRotationEnd[1], Color.a ).xyz;\n"
nuclear@0 418 " EyeRotation[2] = mix ( EyeRotationStart[2], EyeRotationEnd[2], Color.a ).xyz;\n"
nuclear@0 419 " vec3 TransformedR = EyeRotation * TanEyeAngleR;\n"
nuclear@0 420 " vec3 TransformedG = EyeRotation * TanEyeAngleG;\n"
nuclear@0 421 " vec3 TransformedB = EyeRotation * TanEyeAngleB;\n"
nuclear@0 422 #endif
nuclear@0 423
nuclear@0 424 // Project them back onto the Z=1 plane of the rendered images.
nuclear@0 425 " float RecipZR = 1.0 / TransformedR.z;\n"
nuclear@0 426 " float RecipZG = 1.0 / TransformedG.z;\n"
nuclear@0 427 " float RecipZB = 1.0 / TransformedB.z;\n"
nuclear@0 428 " vec2 FlattenedR = vec2 ( TransformedR.x * RecipZR, TransformedR.y * RecipZR );\n"
nuclear@0 429 " vec2 FlattenedG = vec2 ( TransformedG.x * RecipZG, TransformedG.y * RecipZG );\n"
nuclear@0 430 " vec2 FlattenedB = vec2 ( TransformedB.x * RecipZB, TransformedB.y * RecipZB );\n"
nuclear@0 431
nuclear@0 432 // These are now still in TanEyeAngle space.
nuclear@0 433 // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye)
nuclear@0 434 " vec2 SrcCoordR = FlattenedR * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 435 " vec2 SrcCoordG = FlattenedG * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 436 " vec2 SrcCoordB = FlattenedB * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
nuclear@0 437
nuclear@0 438 " oTexCoord0 = SrcCoordR;\n"
nuclear@0 439 " oTexCoord1 = SrcCoordG;\n"
nuclear@0 440 " oTexCoord2 = SrcCoordB;\n"
nuclear@0 441
nuclear@0 442 " oColor = vec4(Color.r, Color.r, Color.r, Color.r);\n" // Used for vignette fade.
nuclear@0 443 "}\n";
nuclear@0 444
nuclear@0 445
nuclear@0 446 const OVR::CAPI::GL::ShaderBase::Uniform DistortionTimewarpChroma_vs_refl[] =
nuclear@0 447 {
nuclear@0 448 { "EyeToSourceUVScale", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 0, 8 },
nuclear@0 449 { "EyeToSourceUVOffset", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 8, 8 },
nuclear@0 450 { "EyeRotationStart", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 16, 64 },
nuclear@0 451 { "EyeRotationEnd", OVR::CAPI::GL::ShaderBase::VARTYPE_FLOAT, 80, 64 },
nuclear@0 452 };
nuclear@0 453
nuclear@0 454 }}} // OVR::CAPI::GL
nuclear@0 455
nuclear@0 456 #endif // OVR_CAPI_GL_Shaders_h