diff options
author | Sven Gothel <[email protected]> | 2014-07-07 23:46:19 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-07-07 23:46:19 +0200 |
commit | 38e51e4a5f6f35c658df10f6d48a33e3ffaea2f3 (patch) | |
tree | 259024b16429986ab48fd49a9bd2667dad2b85eb /src/jogl/classes/jogamp/opengl/util/stereo/shader | |
parent | 06fc570f70dc5ccfad7399d8426bdf224c239a5a (diff) |
Bug 1021: Add GenericStereoDevice* Supporting custom configurations; Hook-in oculusvr-sdk java distortion-mesh calculation if available
StereoDeviceFactory support new GenericStereoDeviceFactory, with it's GenericStereoDevice and GenericStereoDeviceRenderer.
GenericStereoDevice maintains different configurations, triggered either by passing a GenericStereoDevice.Config
instance directly or by the device-index parameter:
- 0: monoscopi device: No post-processing
- 1: stereoscopic device SBS: No post-processing
- 2: stereoscopic device SBS + Lenses: Distortion post-processing
(only available w/ oculusvr-sdk sub-module)
Producing a 'GenericStereoDevice.Config' instance is self containing
and may extend if supporting more device types like top-bottom, interlaced etc.
StereoDemo01 handles all use-cases and may be used as a test-bed
to add and experiment with stereoscopy, devices and settings.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/util/stereo/shader')
6 files changed, 217 insertions, 0 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_chroma.fp b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_chroma.fp new file mode 100644 index 000000000..4ac404729 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_chroma.fp @@ -0,0 +1,26 @@ +//Copyright 2014 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define varying in + out vec4 svr_FragColor; + #define texture2D texture +#else + #define svr_FragColor gl_FragColor +#endif + +uniform sampler2D svr_Texture0; + +varying vec3 svv_Fade; +varying vec2 svv_TexCoordR; +varying vec2 svv_TexCoordG; +varying vec2 svv_TexCoordB; + +void main (void) +{ + // 3 samples for fixing chromatic aberrations + vec3 color = vec3(texture2D(svr_Texture0, svv_TexCoordR).r, + texture2D(svr_Texture0, svv_TexCoordG).g, + texture2D(svr_Texture0, svv_TexCoordB).b); + svr_FragColor = vec4(svv_Fade * color, 1.0); // include vignetteFade +} + diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_chroma.vp b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_chroma.vp new file mode 100644 index 000000000..d4ab585d5 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_chroma.vp @@ -0,0 +1,33 @@ +//Copyright 2014 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +uniform vec2 svr_EyeToSourceUVScale; +uniform vec2 svr_EyeToSourceUVOffset; + +attribute vec2 svr_Position; +attribute vec2 svr_Params; +attribute vec2 svr_TexCoordR; +attribute vec2 svr_TexCoordG; +attribute vec2 svr_TexCoordB; + +varying vec3 svv_Fade; +varying vec2 svv_TexCoordR; +varying vec2 svv_TexCoordG; +varying vec2 svv_TexCoordB; + +void main(void) +{ + gl_Position = vec4(svr_Position.xy, 0.5, 1.0); + svv_Fade = vec3(svr_Params.r); // vignetteFade + + svv_TexCoordR = svr_TexCoordR * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordR.y = 1.0-svv_TexCoordR.y; + svv_TexCoordG = svr_TexCoordG * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordG.y = 1.0-svv_TexCoordG.y; + svv_TexCoordB = svr_TexCoordB * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordB.y = 1.0-svv_TexCoordB.y; +} diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_plain.fp b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_plain.fp new file mode 100644 index 000000000..2df890648 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_plain.fp @@ -0,0 +1,22 @@ +//Copyright 2014 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define varying in + out vec4 svr_FragColor; + #define texture2D texture +#else + #define svr_FragColor gl_FragColor +#endif + +uniform sampler2D svr_Texture0; + +varying vec3 svv_Fade; +varying vec2 svv_TexCoordR; + +void main (void) +{ + // 3 samples for fixing chromatic aberrations + vec3 color = texture2D(svr_Texture0, svv_TexCoordR).rgb; + svr_FragColor = vec4(svv_Fade * color, 1.0); // include vignetteFade +} + diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_plain.vp b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_plain.vp new file mode 100644 index 000000000..335d3f0f6 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_plain.vp @@ -0,0 +1,27 @@ +//Copyright 2014 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +uniform vec2 svr_EyeToSourceUVScale; +uniform vec2 svr_EyeToSourceUVOffset; + +attribute vec2 svr_Position; +attribute vec2 svr_Params; +attribute vec2 svr_TexCoordR; + +varying vec3 svv_Fade; +varying vec2 svv_TexCoordR; + +void main(void) +{ + gl_Position = vec4(svr_Position.xy, 0.5, 1.0); + svv_Fade = vec3(svr_Params.r); // vignetteFade + + // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion). + // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye) + svv_TexCoordR = svr_TexCoordR * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordR.y = 1.0-svv_TexCoordR.y; +} diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_timewarp.vp b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_timewarp.vp new file mode 100644 index 000000000..c4461ec3e --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_timewarp.vp @@ -0,0 +1,44 @@ +//Copyright 2014 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +uniform vec2 svr_EyeToSourceUVScale; +uniform vec2 svr_EyeToSourceUVOffset; +uniform mat4 svr_EyeRotationStart; +uniform mat4 svr_EyeRotationEnd; + +attribute vec2 svr_Position; +attribute vec2 svr_Params; +attribute vec2 svr_TexCoordR; + +varying vec3 svv_Fade; +varying vec2 svv_TexCoordR; + +void main(void) +{ + gl_Position = vec4(svr_Position.xy, 0.0, 1.0); + svv_Fade = vec3(svr_Params.r); // vignetteFade + + // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion). + // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD. + vec3 TanEyeAngle = vec3 ( svr_TexCoordR, 1.0 ); + + // Accurate time warp lerp vs. faster + // Apply the two 3x3 timewarp rotations to these vectors. + vec3 TransformedStart = (svr_EyeRotationStart * vec4(TanEyeAngle, 0)).xyz; + vec3 TransformedEnd = (svr_EyeRotationEnd * vec4(TanEyeAngle, 0)).xyz; + // And blend between them. + vec3 Transformed = mix ( TransformedStart, TransformedEnd, svr_Params.g /* timewarpLerpFactor */ ); + + // Project them back onto the Z=1 plane of the rendered images. + float RecipZ = 1.0 / Transformed.z; + vec2 Flattened = vec2 ( Transformed.x * RecipZ, Transformed.y * RecipZ ); + + // These are now still in TanEyeAngle space. + // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye) + svv_TexCoordR = Flattened * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordR.y = 1.0-svv_TexCoordR.y; +} diff --git a/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_timewarp_chroma.vp b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_timewarp_chroma.vp new file mode 100644 index 000000000..c08ed3113 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/stereo/shader/dist01_timewarp_chroma.vp @@ -0,0 +1,65 @@ +//Copyright 2014 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +uniform vec2 svr_EyeToSourceUVScale; +uniform vec2 svr_EyeToSourceUVOffset; +uniform mat4 svr_EyeRotationStart; +uniform mat4 svr_EyeRotationEnd; + +attribute vec2 svr_Position; +attribute vec2 svr_Params; +attribute vec2 svr_TexCoordR; +attribute vec2 svr_TexCoordG; +attribute vec2 svr_TexCoordB; + +varying vec3 svv_Fade; +varying vec2 svv_TexCoordR; +varying vec2 svv_TexCoordG; +varying vec2 svv_TexCoordB; + +void main(void) +{ + gl_Position = vec4(svr_Position.xy, 0.0, 1.0); + svv_Fade = vec3(svr_Params.r); // vignetteFade + + // Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion). + // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD. + vec3 TanEyeAngleR = vec3 ( svr_TexCoordR, 1.0 ); + vec3 TanEyeAngleG = vec3 ( svr_TexCoordG, 1.0 ); + vec3 TanEyeAngleB = vec3 ( svr_TexCoordB, 1.0 ); + + // Accurate time warp lerp vs. faster + // Apply the two 3x3 timewarp rotations to these vectors. + vec3 TransformedRStart = (svr_EyeRotationStart * vec4(TanEyeAngleR, 0)).xyz; + vec3 TransformedGStart = (svr_EyeRotationStart * vec4(TanEyeAngleG, 0)).xyz; + vec3 TransformedBStart = (svr_EyeRotationStart * vec4(TanEyeAngleB, 0)).xyz; + vec3 TransformedREnd = (svr_EyeRotationEnd * vec4(TanEyeAngleR, 0)).xyz; + vec3 TransformedGEnd = (svr_EyeRotationEnd * vec4(TanEyeAngleG, 0)).xyz; + vec3 TransformedBEnd = (svr_EyeRotationEnd * vec4(TanEyeAngleB, 0)).xyz; + + // And blend between them. + vec3 TransformedR = mix ( TransformedRStart, TransformedREnd, svr_Params.g /* timewarpLerpFactor */ ); + vec3 TransformedG = mix ( TransformedGStart, TransformedGEnd, svr_Params.g /* timewarpLerpFactor */ ); + vec3 TransformedB = mix ( TransformedBStart, TransformedBEnd, svr_Params.g /* timewarpLerpFactor */ ); + + // Project them back onto the Z=1 plane of the rendered images. + float RecipZR = 1.0 / TransformedR.z; + float RecipZG = 1.0 / TransformedG.z; + float RecipZB = 1.0 / TransformedB.z; + vec2 FlattenedR = vec2 ( TransformedR.x * RecipZR, TransformedR.y * RecipZR ); + vec2 FlattenedG = vec2 ( TransformedG.x * RecipZG, TransformedG.y * RecipZG ); + vec2 FlattenedB = vec2 ( TransformedB.x * RecipZB, TransformedB.y * RecipZB ); + + // These are now still in TanEyeAngle space. + // Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye) + svv_TexCoordR = FlattenedR * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordR.y = 1.0-svv_TexCoordR.y; + svv_TexCoordG = FlattenedG * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordG.y = 1.0-svv_TexCoordG.y; + svv_TexCoordB = FlattenedB * svr_EyeToSourceUVScale + svr_EyeToSourceUVOffset; + svv_TexCoordB.y = 1.0-svv_TexCoordB.y; +} |