Krolyxon
Commit d5eb2c5

Branches

Refs →

aurora.confighyprshaders15_anaglyph_3d.glsl

35 lines · 1.1 KB · GLSL

1#version 300 es
2// Anaglyph 3D Shader - OPTIMIZED
3// Fixes: Edge clamping, alpha preservation, depth-aware separation
4
5precision highp float;
6
7in vec2 v_texcoord;
8uniform sampler2D tex;
9out vec4 fragColor;
10
11// --- CONFIGURATION ---
12const float SEPARATION = 0.003;
13// Make separation stronger at edges (simulates depth from screen curvature)
14const bool DEPTH_AWARE = true;
15
16void main() {
17 vec2 offset = vec2(SEPARATION, 0.0);
18
19 // Optional: Increase separation toward screen edges for more depth
20 if (DEPTH_AWARE) {
21 float edgeFactor = abs(v_texcoord.x - 0.5) * 2.0; // 0 at center, 1 at edges
22 offset.x *= 1.0 + edgeFactor * 0.5;
23 }
24
25 // Clamp coordinates to prevent edge sampling artifacts
26 vec2 leftCoord = clamp(v_texcoord - offset, 0.0, 1.0);
27 vec2 rightCoord = clamp(v_texcoord + offset, 0.0, 1.0);
28
29 vec4 leftEye = texture(tex, leftCoord);
30 vec4 rightEye = texture(tex, rightCoord);
31 vec4 center = texture(tex, v_texcoord);
32
33 // Combine: Red from left, Cyan (GB) from right
34 fragColor = vec4(leftEye.r, rightEye.g, rightEye.b, center.a);
35}