aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shaders/earth_fallback.fp36
-rw-r--r--sons_of_sol/private_db/ApplicationInit.cpp13
2 files changed, 48 insertions, 1 deletions
diff --git a/shaders/earth_fallback.fp b/shaders/earth_fallback.fp
new file mode 100644
index 0000000..c8d6d2a
--- /dev/null
+++ b/shaders/earth_fallback.fp
@@ -0,0 +1,36 @@
+// Set the fragment color
+
+uniform sampler2D tex;
+
+varying vec3 fragmentNormal ;
+varying vec3 lightVector ;
+varying vec3 cameraVector ;
+
+void main()
+{
+ vec3 fragNormal = normalize( fragmentNormal ) ;
+
+ float f = dot( fragNormal, normalize( lightVector ) );
+ float c = dot( fragNormal, normalize( cameraVector ) );
+ c = (c - 0.5) * 2.0 ;
+
+ vec4 color = texture2D(tex,gl_TexCoord[0].xy + vec2( 0.5, -0.2 ));
+
+ float bluef = (1.0f / (1.0f + exp(-f * 150.0f)));
+
+ float bluef2 = (1.0f / (1.0f + exp(c * 20.0f))) * f;
+ float redf2 = (1.0f / (1.0f + exp(c * 20.0f))) * pow(f,2) * f;
+ float greenf2 = redf2;
+
+ float alpha = (1.0f / (1.0f + exp(c * 30.0f))) * f;
+
+ /* Each color has its own drop off rate */
+ float greenf = (1.0f / (1.0f + exp(-f * 60.0f)));
+ float redf = (1.0f / (1.0f + exp(-f * 30.0f)));
+
+ gl_FragColor = vec4(
+ redf*color[0] + 1000.0*redf2,
+ greenf*color[1] + 1000.0*greenf2,
+ bluef*color[2] + 1000.0*bluef2,
+ 1.0-1000.0*alpha );
+}
diff --git a/sons_of_sol/private_db/ApplicationInit.cpp b/sons_of_sol/private_db/ApplicationInit.cpp
index 1794fd5..ea409ed 100644
--- a/sons_of_sol/private_db/ApplicationInit.cpp
+++ b/sons_of_sol/private_db/ApplicationInit.cpp
@@ -180,8 +180,19 @@ bool SonsOfSolApplication::initialize( int argc, char** argv ) {
}
m_earth_prog = new GloxProgram() ;
+
+
+ printf( "Using GLSL version %s\n", glGetString( GL_SHADING_LANGUAGE_VERSION ) );
+
+ const char* earth_frag_shader = "shaders/earth.fp";
+ float version = atof( (const char*) glGetString( GL_SHADING_LANGUAGE_VERSION ) );
+ if( version < 1.29 ) {
+ fprintf( stderr, "Using version %02f, unfortunately, I must use the fallback shader\n", version );
+ earth_frag_shader = "shaders/earth_fallback.fp";
+ }
+
if( m_earth_prog->attachShaderFromFile( "shaders/earth.vp", GL_VERTEX_SHADER ) ||
- m_earth_prog->attachShaderFromFile( "shaders/earth.fp", GL_FRAGMENT_SHADER ) ||
+ m_earth_prog->attachShaderFromFile( earth_frag_shader, GL_FRAGMENT_SHADER ) ||
m_earth_prog->link() ) {
cerr << "Warning Unable to load shaders: " <<
GloxShader::getMessage() << endl;