Skip to content

Commit deb8ce2

Browse files
committed
Adjusted shader parameters and switched to higher quality anaglyph filter.
1 parent 58709bc commit deb8ce2

8 files changed

+64
-62
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Andres Hernandez
3+
Copyright (c) 2022 Andres Hernandez
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Godot Stereo 3D : Add-On For Godot Engine
2-
Godot Stereo 3D adds stereoscopic 3D support to Godot Engine (red/cyan anaglyph 3D glasses) in game and in editor. Works as a screen-space shader based on the depth buffer (2D to 3D conversion) so is very fast. Requires GLES3. The best 3D glasses to use with this add-on are called Pro-Ana (red/cyan). They make plastic and paper versions and are very affordable.
2+
Godot Stereo 3D adds stereoscopic 3D support to Godot Engine (red/cyan anaglyph 3D glasses) in game and in editor. Works as a screen-space shader based on the depth buffer (2D to 3D conversion) so is very fast. Requires GLES3. The best 3D glasses to use with this add-on are called Pro-Ana (red/cyan). They make plastic and paper versions and are very affordable. Proview and Anachrome glasses also work well (red/cyan).
33

44
![Screenshot](ScreenShots/Godot_Stereo_3D_Game.jpg)
55

@@ -14,16 +14,15 @@ For manual install, download the `Stereo3D` folder from this repository and copy
1414
## CONFIGURATION
1515

1616
* Place the `Stereo3D.tscn` scene inside your main game tree.
17-
* If used in combination with `Godot Super Scaling`, the `Stereo3D` node should be inside your game world.
1817
* In the `Stereo3D` inspector settings, check the `Enable` box to turn stereo on or off in game or in editor.
1918
* Set `Z Near` to the z_near of your camera.
2019
* Set `Z Far` to the z_far of your camera.
21-
* The `Separation` controls the distance between the eyes. `0` is no distance and `100` is the maximum.
22-
* Setting `Separation` too high may cause discomfort, so leaving it around the default of `50` is recommended.
23-
* The `Convergence` controls the distance to the parallax plane the eyes are focused on (on the z axis).
24-
* Higher values for `Convergence` will result in a greater 3D effect, but setting it too high may cause discomfort.
25-
* The `Pop Out` setting controls the overlap between the left/right images. This makes the image more 3D or more comfortable.
26-
* Typically lower `Pop Out` settings are easier to focus on. However, if you use transparent surfaces or reflections (e.g. glass windows) then it is better to set `Pop Out` to the maximum so that the transparent pass closer matches the 3D render.
20+
* The `Stereo Strength` controls the distance between the eyes. `0` is no distance and `100` is the maximum.
21+
* Setting `Stereo Strength` too high may cause discomfort, so leaving it around the default of `50` is recommended.
22+
* The `Parallax Depth` controls the distance to the parallax plane the eyes are focused on (on the z axis).
23+
* Higher values for `Parallax Depth` will result in a greater 3D effect, but setting it too high may cause discomfort.
24+
* The `Parallax Offset` setting controls the overlap between the left/right images. This makes the image more 3D or more comfortable.
25+
* Typically higher `Parallax Offset` settings are easier to focus on. However, it can depend on the content.
2726
* If you have overlapping transparent surfaces in your game, you need to set the `Render Priority` of the transparent material to `1` or above (for example, in a racing game, viewed from the 3rd person, the front window could have `Render Priority` of `0` and the back `1`).
2827
* For cut-out textures (like decals or grass) the `Render Priority` should be above `0`, the `Depth Draw Mode` set to `Opaque Pre-Pass`, `Transparent` set to false, and enable `Use Alpha Scissor` on the material. If the decal texture is on top of a transparent material (e.g. a sticker on a window) then the `Depth Draw Mode` must be set to `Never`.
2928
* If you use reflection probes, the reflections will be captured with the results of the post-process and will be incorrect. In these cases, you should leave the `Stereo3D` disabled in game, then on _ready() in your game, wait a certain amount of time (enough for the captures to take place) before enabling `Stereo3D`.
@@ -34,7 +33,7 @@ For manual install, download the `Stereo3D` folder from this repository and copy
3433

3534
MIT License
3635

37-
Copyright (c) 2021 Andres Hernandez
36+
Copyright (c) 2022 Andres Hernandez
3837

3938
Permission is hereby granted, free of charge, to any person obtaining a copy
4039
of this software and associated documentation files (the "Software"), to deal

ScreenShots/Godot_Stereo_3D_Game.jpg

21 KB
Loading
87.2 KB
Loading

Stereo3D/LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Andres Hernandez
3+
Copyright (c) 2022 Andres Hernandez
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Stereo3D/Stereo3D.gd

+25-25
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
tool
44
extends Spatial
55

6-
# separation controls the distance between the eyes
7-
export(float, 0.0, 100.0) var separation = 50.0 setget change_separation
8-
# convergence controls the focus plane (distance on z axis where the eyes focus)
9-
export(float, 0.0, 100.0) var convergence = 50.0 setget change_convergence
10-
# pop out adjusts the overlap to be more comfortable or for more depth
11-
export(float, 0.0, 100.0) var pop_out = 50.0 setget change_pop_out
6+
# stereo strength controls the distance between the eyes
7+
export(float, 0.0, 100.0) var stereo_strength = 50.0 setget change_strength
8+
# parallax depth controls the zero plane (distance on z axis where the eyes focus)
9+
export(float, 0.0, 100.0) var parallax_depth = 50.0 setget change_parallax_depth
10+
# parallax offset adjusts the overlap to be more comfortable or for more depth
11+
export(float, 0.0, 100.0) var parallax_offset = 50.0 setget change_parallax_offset
1212
# z near should match your camera node
13-
export var z_near = 0.05 setget change_near
13+
export var z_near = 0.1 setget change_near
1414
# z far should match your camera node
1515
export var z_far = 100.0 setget change_far
1616
# enables stereo 3D in game or editor or both, must be controlled here
@@ -22,9 +22,9 @@ var shader_material
2222
func _ready():
2323
#warning-ignore:RETURN_VALUE_DISCARDED
2424
self.connect("visibility_changed", self, "on_visible_change")
25-
change_separation(separation)
26-
change_convergence(convergence)
27-
change_pop_out(pop_out)
25+
change_strength(stereo_strength)
26+
change_parallax_depth(parallax_depth)
27+
change_parallax_offset(parallax_offset)
2828
change_near(z_near)
2929
change_far(z_far)
3030
change_enable(enable)
@@ -35,23 +35,23 @@ func get_shader():
3535
shader_material = get_node("Overlay").get_surface_material(0)
3636
return shader_material
3737

38-
# changes the separation
39-
func change_separation(val):
40-
separation = val
41-
var eye_separation = separation / 40000.0
42-
get_shader().set_shader_param("eye_separation", eye_separation)
38+
# changes the eye separation
39+
func change_strength(val):
40+
stereo_strength = val
41+
var eye_separation = stereo_strength / 250000.0
42+
get_shader().set_shader_param("stereo_strength", eye_separation)
4343

44-
# changes the convergence
45-
func change_convergence(val):
46-
convergence = val
47-
var convergence_plane = convergence / 1000.0;
48-
get_shader().set_shader_param("convergence_plane", convergence_plane)
44+
# changes the zero parallax plane
45+
func change_parallax_depth(val):
46+
parallax_depth = val
47+
var zero_plane = parallax_depth / 100.0;
48+
get_shader().set_shader_param("parallax_depth", zero_plane)
4949

50-
# changes the pop out
51-
func change_pop_out(val):
52-
pop_out = val
53-
var parallax_offset = (100.0 - pop_out) / 10000.0;
54-
get_shader().set_shader_param("parallax_offset", parallax_offset)
50+
# changes the offset
51+
func change_parallax_offset(val):
52+
parallax_offset = val
53+
var offset_amount = (100.0 - parallax_offset) / 5000.0;
54+
get_shader().set_shader_param("parallax_offset", offset_amount)
5555

5656
# changes if stereo 3D is enabled in game or editor
5757
func change_enable(val):

Stereo3D/Stereo3D.tres

+25-22
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ render_mode skip_vertex_transform, depth_test_disable,
88
unshaded, shadows_disabled, ambient_light_disabled;
99

1010
// separation between the eyes
11-
uniform float eye_separation = 0.00125;
11+
uniform float stereo_strength = 0.0002;
1212
// focus plane on z axis
13-
uniform float convergence_plane = 0.05;
13+
uniform float parallax_depth = 0.5;
1414
// overlap of left/right images
15-
uniform float parallax_offset = 0.005;
15+
uniform float parallax_offset = 0.01;
1616
// z near of the camera
17-
uniform float z_near = 0.05;
17+
uniform float z_near = 0.1;
1818
// z far of the camera
1919
uniform float z_far = 100.0;
2020
// x offset for sample coordinates
2121
const float samples[3] = {0.5, 0.66, 1.0};
2222
// count for above samples
2323
const int sample_count = 3;
24-
// left color filter to reduce ghosting
25-
const mat3 left_optimize = mat3(
26-
vec3(0.437, 0.449, 0.164),
27-
vec3(-0.062, -0.062, -0.024),
28-
vec3(-0.048, -0.050, -0.017));
29-
// right color filter to reduce ghosting
30-
const mat3 right_optimize = mat3(
31-
vec3(-0.011, -0.032, -0.007),
32-
vec3(0.377, 0.761, 0.009),
33-
vec3(-0.026, -0.093, 1.234));
24+
// left color filter
25+
const mat3 left_filter = mat3(
26+
vec3(0.4561, 0.500484, 0.176381),
27+
vec3(-0.400822, -0.0378246, -0.0157589),
28+
vec3(-0.0152161, -0.0205971, -0.00546856));
29+
// right color filter
30+
const mat3 right_filter = mat3(
31+
vec3(-0.0434706, -0.0879388, -0.00155529),
32+
vec3(0.378476, 0.73364, -0.0184503),
33+
vec3(-0.0721527, -0.112961, 1.2264));
3434

3535
// scales the overlay to full screen
3636
void vertex() {
@@ -45,15 +45,16 @@ vec3 getColor(sampler2D tex, vec2 uv) {
4545

4646
// samples the depth from depth buffer in linear space
4747
float getDepth(sampler2D tex, vec2 uv) {
48-
float depth_map = textureLod(tex, uv, 0.0).r * 2.0 - 1.0;
49-
float linear_depth = 2.0 * z_near * z_far / (z_far + z_near - depth_map * (z_far - z_near));
48+
float depth_sample = textureLod(tex, uv, 0.0).r;
49+
float ndc = depth_sample * 2.0 - 1.0;
50+
float linear_depth = (2.0 * z_near * z_far) / (z_far + z_near - ndc * (z_far - z_near));
5051
linear_depth /= z_far;
5152
return linear_depth;
5253
}
5354

5455
// get the parallax offset
5556
float getParallax(float depth) {
56-
depth = 1.0 - convergence_plane / depth;
57+
depth = 1.0 - parallax_depth / depth;
5758
return depth;
5859
}
5960

@@ -64,17 +65,19 @@ void fragment() {
6465
vec2 uv = vec2(0.0);
6566

6667
for (int i = 0; i < sample_count; ++i) {
67-
uv.x = samples[i] * eye_separation + parallax_offset;
68+
uv.x = samples[i] * stereo_strength + parallax_offset;
6869
min_depth_left = min(min_depth_left, getDepth(DEPTH_TEXTURE, SCREEN_UV + uv));
6970
min_depth_right = min(min_depth_right, getDepth(DEPTH_TEXTURE, SCREEN_UV - uv));
7071
}
7172

72-
float parallax_left = eye_separation * getParallax(min_depth_left) + parallax_offset;
73-
float parallax_right = eye_separation * getParallax(min_depth_right) + parallax_offset;
73+
float parallax_left = stereo_strength * getParallax(min_depth_left) + parallax_offset;
74+
float parallax_right = stereo_strength * getParallax(min_depth_right) + parallax_offset;
7475

7576
vec3 color_left = getColor(SCREEN_TEXTURE, SCREEN_UV + vec2(parallax_left, 0.0));
7677
vec3 color_right = getColor(SCREEN_TEXTURE, SCREEN_UV - vec2(parallax_right, 0.0));
77-
78-
ALBEDO = clamp(color_left * left_optimize, vec3(0.0), vec3(1.0)) + clamp(color_right * right_optimize, vec3(0.0), vec3(1.0));
78+
79+
vec3 color_final = clamp(color_left * left_filter, vec3(0.0), vec3(1.0)) + clamp(color_right * right_filter, vec3(0.0), vec3(1.0));
80+
81+
ALBEDO = color_final;
7982
}
8083
"

Stereo3D/Stereo3D.tscn

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ size = Vector2( 2, 2 )
99
[sub_resource type="ShaderMaterial" id=3]
1010
render_priority = -128
1111
shader = ExtResource( 2 )
12-
shader_param/eye_separation = 0.00125
13-
shader_param/convergence_plane = 0.05
14-
shader_param/parallax_offset = 0.005
15-
shader_param/z_near = 0.05
12+
shader_param/stereo_strength = 0.0002
13+
shader_param/parallax_depth = 1.0
14+
shader_param/parallax_offset = 0.01
15+
shader_param/z_near = 0.1
1616
shader_param/z_far = 100.0
1717

1818
[node name="Stereo3D" type="Spatial"]

0 commit comments

Comments
 (0)