SceneRefract: Make the refractive index of the medium a command line option.
The default is 1.2, but could be anything ("believable" effects are probably in
the lower values).
diff --git a/data/shaders/light-refract.frag b/data/shaders/light-refract.frag
index bcc5096..d1f1397 100644
--- a/data/shaders/light-refract.frag
+++ b/data/shaders/light-refract.frag
@@ -16,7 +16,7 @@
// compute the transmitted vector through the "front" surface of the object.
vec3 eye_direction = normalize(-vertex_position.xyz);
vec3 normalized_normal = normalize(vertex_normal);
- vec3 front_refraction = refract(eye_direction, normalized_normal, 1.45);
+ vec3 front_refraction = refract(eye_direction, normalized_normal, RefractiveIndex);
// Find our best distance approximation through the object so we can
// project the transmitted vector to the back of the object to find
// the exit point.
diff --git a/src/scene-refract.cpp b/src/scene-refract.cpp
index f4188e0..b936362 100644
--- a/src/scene-refract.cpp
+++ b/src/scene-refract.cpp
@@ -77,6 +77,8 @@
}
options_["texture"] = Scene::Option("texture", "nasa1", "Which texture to use",
optionValues);
+ options_["index"] = Scene::Option("index", "1.2",
+ "Index of refraction of the medium to simulate");
options_["use-vbo"] = Scene::Option("use-vbo", "true",
"Whether to use VBOs for rendering",
"false,true");
@@ -277,6 +279,8 @@
frg_source.add_const("LightColor", lightColor);
frg_source.add_const("LightSourcePosition", lightPosition);
+ float refractive_index(Util::fromString<float>(options["index"].value));
+ frg_source.add_const("RefractiveIndex", refractive_index);
if (!Scene::load_shaders_from_strings(program_, vtx_source.str(), frg_source.str())) {
return false;