move/add stereoscopic-3D shaders to match glsl repo

This commit is contained in:
hunterk 2020-09-08 15:35:43 -05:00
parent a54ff3fa22
commit 547e9671bd
8 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,3 @@
shaders = 1
shader0 = shaders/anaglyph-to-side-by-side.slang

View File

@ -0,0 +1,60 @@
#version 450
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float flip_eye_toggle;
float green;
float blue;
} params;
#pragma parameter flip_eye_toggle "Flip Left/Right" 0.0 0.0 1.0 1.0
bool flip_eye = bool(params.flip_eye_toggle);
#pragma parameter green "Green" 1.0 0.0 1.0 1.0
#pragma parameter blue "Blue" 1.0 0.0 1.0 1.0
const vec3 rec_709_luma = vec3(0.212, 0.701, 0.087);
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out float oscillator;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
oscillator = float(mod(params.FrameCount, 2.));
oscillator = (flip_eye) ? oscillator : 1. - oscillator;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float oscillator;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D OriginalHistory1;
void main()
{
// convert current and previous frames to luma to preserve details
vec3 curr = texture(Source, vTexCoord).rgb;
float curr_lum = dot(curr, rec_709_luma);
vec3 last = texture(OriginalHistory1, vTexCoord).rgb;
float last_lum = dot(last, rec_709_luma);
// image for left/right eyes alternate on each frame
float one_eye = last_lum * oscillator + (curr_lum * (1. - oscillator));
float other_eye = curr_lum * oscillator + (last_lum * (1. - oscillator));
// one eye gets the red channel, the other eye goes to green and/or blue, depending on glasses
vec3 combined = vec3(one_eye, other_eye * params.green, other_eye * params.blue);
FragColor = vec4(combined, 1.0);
}

View File

@ -0,0 +1,76 @@
#version 450
// Shutter 3D to side-by-side
// by hunterk
// license: public domain
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float ZOOM, vert_pos, horz_pos, separation, flicker, height_mod, swap_eye;
} params;
#pragma parameter ZOOM "Zoom" 1.0 0.0 2.0 0.01
#define ZOOM params.ZOOM
#pragma parameter vert_pos "Vertical Modifier" 0.0 -2.0 2.0 0.01
#define vert_pos params.vert_pos
#pragma parameter horz_pos "Horizontal Modifier" 0.0 -2.0 2.0 0.01
#define horz_pos params.horz_pos
#pragma parameter separation "Eye Separation" 0.0 -2.0 2.0 0.01
#define separation params.separation
#pragma parameter flicker "Hold Last Frame (reduce flicker)" 1.0 0.0 1.0 0.25
#define flicker params.flicker
#pragma parameter height_mod "Image Height" 1.0 0.0 2.0 0.01
#define height_mod params.height_mod
#pragma parameter swap_eye "Swap Eye Sequence" 0.0 0.0 1.0 1.0
#define swap_eye params.swap_eye
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 left_coord;
layout(location = 1) out vec2 right_coord;
layout(location = 2) out float timer;
void main()
{
gl_Position = global.MVP * Position;
vec2 temp_coord = TexCoord.xy - 0.5;
temp_coord *= ZOOM;
temp_coord *= vec2(2.,1. / height_mod);
temp_coord += vec2(horz_pos, vert_pos);
temp_coord += 0.5;
left_coord = temp_coord.xy - vec2(0.5 + separation,0.);
right_coord = temp_coord.xy + vec2(0.5 + separation,0.);
timer = abs(swap_eye - mod(float(params.FrameCount), 2.));
}
#pragma stage fragment
layout(location = 0) in vec2 left_coord;
layout(location = 1) in vec2 right_coord;
layout(location = 2) in float timer;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 2) uniform sampler2D OriginalHistory1;
#define PrevTexture OriginalHistory1
void main()
{
vec4 left_screen = texture(Source, left_coord);
vec4 left_hold = texture(PrevTexture, left_coord);
vec4 right_screen = texture(Source, right_coord);
vec4 right_hold = texture(PrevTexture, right_coord);
left_screen = left_screen * timer + (1. - timer) * left_hold * flicker;
right_screen = right_screen * (1. - timer) + right_hold * timer * flicker;
FragColor = left_screen + right_screen;
}

View File

@ -0,0 +1,71 @@
#version 450
// simple shader to view content on side-by-side 3D displays
// by hunterk
// license: public domain
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float eye_sep, y_loc, BOTH, ana_zoom, WIDTH, HEIGHT, warpX, warpY, pulfrich;
} params;
#pragma parameter eye_sep "Eye Separation" 0.30 -1.0 5.0 0.05
#define eye_sep params.eye_sep
#pragma parameter y_loc "Vertical Placement" 0.25 -1.0 1.0 0.01
#define y_loc params.y_loc
#pragma parameter BOTH "Horizontal Placement" 0.51 -2.0 2.0 0.005
#define BOTH params.BOTH
#pragma parameter ana_zoom "Zoom" 0.75 -2.0 2.0 0.05
#define ana_zoom params.ana_zoom
#pragma parameter WIDTH "Side-by-Side Image Width" 3.05 1.0 7.0 0.05
#define WIDTH params.WIDTH
#pragma parameter HEIGHT "Side-by-Side Image Height" 2.0 1.0 5.0 0.1
#define HEIGHT params.HEIGHT
#pragma parameter warpX "Lens Warp Correction X" 0.1 0.0 0.5 0.05
#define warpX params.warpX
#pragma parameter warpY "Lens Warp Correction Y" 0.1 0.0 0.5 0.05
#define warpY params.warpY
#pragma parameter pulfrich "Pulfrich Effect" 0.0 0.0 0.5 0.25
#define pulfrich params.pulfrich
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = ((TexCoord.xy - 0.5) * ana_zoom + 0.5) * vec2(WIDTH, HEIGHT) - vec2(BOTH, 0.0);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
//distortion
vec2 Warp(vec2 pos){
pos.xy = pos.xy * 2.0-1.0;
pos.xy *= vec2(1.0+(pos.y*pos.y)*warpX,1.0+(pos.x*pos.x)*warpY);
return pos*0.5+0.5;}
void main()
{
vec2 warpCoord1 = Warp(vTexCoord.xy - vec2(eye_sep, y_loc));
vec2 warpCoord2 = Warp(vTexCoord.xy + vec2(eye_sep, -y_loc));
vec4 frame1 = texture(Source, warpCoord1);
vec4 frame2 = texture(Source, warpCoord2) * (1.0 - pulfrich);
vec4 final = vec4(frame1 + frame2);
FragColor = final;
}

View File

@ -0,0 +1,3 @@
shaders = 1
shader0 = shaders/shutter-to-anaglyph.slang

View File

@ -0,0 +1,3 @@
shaders = 1
shader0 = shaders/shutter-to-side-by-side.slang

View File

@ -0,0 +1,3 @@
shaders = 1
shaders0 = shaders/side-by-side-simple.slang