Skip to content

Instantly share code, notes, and snippets.

@NSTCG
Last active October 7, 2024 10:06
Show Gist options
  • Save NSTCG/8a3321189b571df4bc27495cff9fdbd9 to your computer and use it in GitHub Desktop.
Save NSTCG/8a3321189b571df4bc27495cff9fdbd9 to your computer and use it in GitHub Desktop.
A fragment shader for stereo image/video rendering in wonderland engine
/**
Copyright © 2024 Nithin Steven F <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "lib/Compatibility.frag"
#define FEATURE_TEXTURED
#define FEATURE_ALPHA_MASKED
#define FEATURE_VERTEX_COLORS
#ifdef TEXTURED
#define USE_TEXTURE_COORDS
#endif
#ifdef VERTEX_COLORS
#define USE_COLOR
#endif
#define USE_MATERIAL_ID
#include "lib/Uniforms.glsl"
#include "lib/Inputs.frag"
#ifdef TEXTURED
#include "lib/Textures.frag"
#endif
#include "lib/Packing.frag"
#include "lib/Materials.frag"
struct Material {
lowp vec4 color;
mediump uint flatTextureLeft;
mediump uint flatTextureRight;
};
Material decodeMaterial(uint matIndex) {
{{decoder}}
return mat;
}
void main() {
#ifdef TEXTURED
alphaMask(fragMaterialId, fragTextureCoords);
#endif
Material mat = decodeMaterial(fragMaterialId);
// Select texture based on view index (left or right eye)
mediump uint selectedTexture = (int(viewIndex) == 0) ? mat.flatTextureLeft : mat.flatTextureRight;
outColor =
#ifdef VERTEX_COLORS
fragColor *
#endif
#ifdef TEXTURED
textureAtlas(selectedTexture, fragTextureCoords) *
#endif
mat.color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment