aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Rahm <joshua.rahm@colorado.edu>2013-12-11 02:39:59 -0700
committerJoshua Rahm <joshua.rahm@colorado.edu>2013-12-11 02:39:59 -0700
commit678a0d1e4c97349ae2d29b4bdda8d670ce2490cf (patch)
treef5b8b21b2f1baf803c03a8e247e18c918af5d0cd
parent2e297229c65eeb6ec899a6f77bd333c7abc331e4 (diff)
downloadSonsOfSol-678a0d1e4c97349ae2d29b4bdda8d670ce2490cf.tar.gz
SonsOfSol-678a0d1e4c97349ae2d29b4bdda8d670ce2490cf.tar.bz2
SonsOfSol-678a0d1e4c97349ae2d29b4bdda8d670ce2490cf.zip
Made shader look awesome, added readme, ready for final commit
-rw-r--r--README.md134
m---------glox0
-rw-r--r--objects/textures/earth.jpgbin2266862 -> 2574625 bytes
-rw-r--r--screenshots/primary_shader.jpgbin0 -> 202058 bytes
-rw-r--r--shaders/earth.fp22
-rw-r--r--shaders/earth.vp1
m---------slox0
-rw-r--r--sons_of_sol/SonsOfSolApplication.hpp1
-rw-r--r--sons_of_sol/private_db/ApplicationDisplay.cpp63
-rw-r--r--sons_of_sol/private_db/ApplicationInit.cpp1
10 files changed, 145 insertions, 77 deletions
diff --git a/README.md b/README.md
index fac4240..457cb9f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,132 @@
-GraphicsFinal
+Sons Of Sol
=============
-Moving away from Glut and beginning to learn SDL. I'm uising Glox as my
-main library for OpenGL, which is the first time I have ever used sub-modules
-in Git.
+Build Instructions
+==================
+
+Most of the time just run
+$ make
+
+The makefiles should be updated and working, but
+in case they are not, you can run:
+
+$ ./genmake.sh # generate bootstrap Makefile
+$ make genmake # recursively generate other makefiles
+$ make
+
+(To use genmake, you must have gawk installed)
+
+Defaultly, the project compiles with all debugging flags enabled
+and no optimizations. To compile with optimizations run
+
+$ OPTFLAGS=-O<Level> make
+
+NOTES
+====
+
+This code has been verified to work on the CSEL machines
+with the fallback shader (see below)
+
+libglox and libslox are both projects written by me this year
+for the purpose of aiding me with OpenGL and SDL
+
+Story
+============
+
+The year is 2183 and the rebel cause is all but extinguished and an Imperial
+victory seems almost all but inevitable. One lingering
+hope remains with the frigate Industrial and its X25B fighter
+escorts if they can destroy the Death Star. You are
+a part of a quick fighter response team known as the Sons of Sol who have
+been enlisted to protect the frigate from the Death Star and its fighter
+as it makes a close approach to fire its main weapon and save the rebel cause
+and ensuring the survival of liberty for years to come.
+
+You are due for engagement now.
+
+Controls
+========
+
+Movement
+
+W/S - Forward/Back
+Mouse - Pitch/Yaw
+Q/E - Roll
+A/D - Strafe Left/Right
+Z/X - Strafe Up/Down
+Shift or Spacebar - Shoot
+
+What to look for
+================
+
+Once you leave the initial launch tube, you will
+have control of your ship. There are other ships that
+orbit around the death star and they look like little
+moving stars when far away.
+
+Near the starting point, there are 5 moving ships that follow
+ellipses around the starting point. To get there, just turn
+around after leaving the acceleration tube and find your way back.
+
+Likewise, there are ships around the frigate you can find much like
+around the death star.
+
+In addition, the Death Star has a few openings that you can fly into and
+try to make your way to the Death Star's reactor core.
+
+
+Cool graphics things
+====================
+
+There are 2 shaders, one for the moon and
+one for the Earth. The earth shader is implemented
+two different ways because I found that they work
+differently depending on the version of glsl
+
+If using the primary shader for the earth (glsl >= 1.3)
+then the earth rotates as a small, but noticable speed.
+
+The ships dynamically change the resolution of
+the model the closer you get. That is how I am able
+to have literaly a hundred of the little ships.
+
+All 6 degrees of freedom actually work, although
+strafing is intentionally slow.
+
+The controls use a smooth averaging algorithm to produce
+the smooth control effects.
+
+The initial starting light is a directional light that
+changes from red to green when it is time to accelerate.
+
+The spaceship jitter is described as a function of the
+acceleration and if the gun is firing
+
+Lighting actually comes from the sun, and a secondary, smaller
+light is emitted from the Earth.
+
+The small ships employ complex alorithms to yaw, pitch and roll
+with the line they follow to make it look more realistic (Follow one, it's quite cool)
+
+The bullets from the gun are lines drawn along the vector of motion
+that have an alpha gradient and their color decays over time.
+
+Some Caveats
+============
+
+The Earth, Moon and Sun move with you, so don't
+try to get to them because you can't.
+
+If you go too far past the death star or the frigate
+and look back, there will be some Z fighting because there
+is no limit on how far you can go.
+
+There is no collision or hit detection :-( but it is still
+fun to pretend.
+
+Textures could be better but this isn't for a photoshop class
+so, I think they are good enough.
+
+If you are using glsl < 1.3 (like the CSEL machines) then you
+can't use the primary shader, but never fear! I included a screenshot
+of it in the 'screenshots' directory. I'm proud of that shader.
diff --git a/glox b/glox
-Subproject 06b216d01ebcf4fb5aa3d4540ef084d6a0a8595
+Subproject b7ef0f362685c7d2f46e7be421570c62d4eab11
diff --git a/objects/textures/earth.jpg b/objects/textures/earth.jpg
index 0f1840d..a52729f 100644
--- a/objects/textures/earth.jpg
+++ b/objects/textures/earth.jpg
Binary files differ
diff --git a/screenshots/primary_shader.jpg b/screenshots/primary_shader.jpg
new file mode 100644
index 0000000..1ebe84a
--- /dev/null
+++ b/screenshots/primary_shader.jpg
Binary files differ
diff --git a/shaders/earth.fp b/shaders/earth.fp
index c8d6d2a..3ca8ae9 100644
--- a/shaders/earth.fp
+++ b/shaders/earth.fp
@@ -5,6 +5,7 @@ uniform sampler2D tex;
varying vec3 fragmentNormal ;
varying vec3 lightVector ;
varying vec3 cameraVector ;
+uniform float time ;
void main()
{
@@ -14,23 +15,22 @@ void main()
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)));
+ vec4 color = texture2D(tex,gl_TexCoord[0].xy + vec2( -time, -0.2 ));
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 redf2 = 200.0 * (1.0f / (1.0f + exp(c * 20.0f))) * pow(f,10.0) * f;
+ float greenf2 = 200.0 * (1.0f / (1.0f + exp(c * 20.0f))) * pow(f,15.0) * f;
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)));
+ float bluef = (0.8f / (1.0f + exp(-f * 100.0f)));
+ float greenf = (0.8f / (1.0f + exp(-f * 40.0f))) ;
+ float redf = (0.8f / (1.0f + exp(-f * 20.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 );
+ min(1.0,(redf*color[0] + 1000.0*redf2)),
+ min(1.0,(greenf*color[1] + 1000.0*greenf2)),
+ min(1.0,(bluef*color[2] + 1000.0*bluef2)),
+ min(1.0,1.0-1000.0*alpha) );
}
diff --git a/shaders/earth.vp b/shaders/earth.vp
index 502a970..31fc84b 100644
--- a/shaders/earth.vp
+++ b/shaders/earth.vp
@@ -3,6 +3,7 @@ uniform vec3 lightPos ;
/* Position of the -x axis */
uniform vec3 cameraPos ;
+uniform float time ;
varying vec3 fragmentNormal;
varying vec3 lightVector;
diff --git a/slox b/slox
-Subproject 6a40f5305d038001c750c4b8a623bd16d735556
+Subproject 852b3b4da896817d2161f7345ef4b16c0f6240c
diff --git a/sons_of_sol/SonsOfSolApplication.hpp b/sons_of_sol/SonsOfSolApplication.hpp
index 27187c9..ea56614 100644
--- a/sons_of_sol/SonsOfSolApplication.hpp
+++ b/sons_of_sol/SonsOfSolApplication.hpp
@@ -175,6 +175,7 @@ private:
glox::GloxProgram* m_moon_prog ;
int m_earth_shader_light_pos ;
int m_earth_shader_camera_pos ;
+ int m_earth_shader_time ;
int m_moon_shader_light_pos ;
int m_moon_shader_camera_pos ;
};
diff --git a/sons_of_sol/private_db/ApplicationDisplay.cpp b/sons_of_sol/private_db/ApplicationDisplay.cpp
index e4a2a78..c1a8d87 100644
--- a/sons_of_sol/private_db/ApplicationDisplay.cpp
+++ b/sons_of_sol/private_db/ApplicationDisplay.cpp
@@ -13,68 +13,6 @@ using namespace std;
float randJitter() {
return ((rand() & 0xFF) - 128.0) / (256.0 * 10) ;
}
-void Cockpit()
-{
- // Screen edge
-// float w = 1.8;
- // Save transform attributes (Matrix Mode and Enabled Modes)
- glPushAttrib(GL_TRANSFORM_BIT|GL_ENABLE_BIT);
- // Save projection matrix and set unit transform
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(-1.8,+1.8,-1,1,-1,1);
- // Save model view matrix and set to indentity
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- // Draw instrument panel with texture
- // glColor3f(1,1,1);
- // glEnable(GL_TEXTURE_2D);
- // glBegin(GL_QUADS);
- // glTexCoord2d(0,0);glVertex2f(-2,-1);
- // glTexCoord2d(1,0);glVertex2f(+2,-1);
- // glTexCoord2d(1,1);glVertex2f(+2, 0);
- // glTexCoord2d(0,1);glVertex2f(-2, 0);
- // glEnd();
- // glDisable(GL_TEXTURE_2D);
- // Draw the inside of the cockpit in grey
-// glColor3f(0.6,0.6,0.6);
-// glBegin(GL_QUADS);
-// // Port
-// glVertex2f(-2,-1);
-// glVertex2f(-2,+1);
-// glVertex2f(-w,+1);
-// glVertex2f(-w,-1);
-// // Starboard
-// glVertex2f(+2,-1);
-// glVertex2f(+2,+1);
-// glVertex2f(+w,+1);
-// glVertex2f(+w,-1);
-// // Port overhead
-// glVertex2f(-2.00,+0.8);
-// glVertex2f(-2.00,+1);
-// glVertex2f(-0.03,+1);
-// glVertex2f(-0.03,+0.9);
-// // Starboard overhead
-// glVertex2f(+2.00,+0.8);
-// glVertex2f(+2.00,+1);
-// glVertex2f(+0.03,+1);
-// glVertex2f(+0.03,+0.9);
-// // Windshield divide
-// glVertex2f(-0.03,+1);
-// glVertex2f(+0.03,+1);
-// glVertex2f(+0.03,+0);
-// glVertex2f(-0.03,+0);
-// glEnd();
- // Reset model view matrix
- glPopMatrix();
- // Reset projection matrix
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- // Pop transform attributes (Matrix Mode and Enabled Modes)
- glPopAttrib();
-}
void SonsOfSolApplication::display() {
if ( m_script_ttl >= 0 ) {
@@ -136,6 +74,7 @@ void SonsOfSolApplication::display() {
m_earth_prog->render() ;
m_earth_prog->setUniformVector3( m_earth_shader_light_pos,
m_light_manager.getLightSource(0)->getPosition() ) ;
+ m_earth_prog->setUniformFloat( m_earth_shader_time, SDL_GetTicks() / 300000.0 ) ;
//GloxPoint<> pos( GloxCos( ticks ) * FAR_DISTANCE_END/4.0, 0, GloxSin( ticks ) * FAR_DISTANCE_END/4.0 );
GloxPoint<> pos( -250000, 0, 0 );
diff --git a/sons_of_sol/private_db/ApplicationInit.cpp b/sons_of_sol/private_db/ApplicationInit.cpp
index ea409ed..30b4b10 100644
--- a/sons_of_sol/private_db/ApplicationInit.cpp
+++ b/sons_of_sol/private_db/ApplicationInit.cpp
@@ -199,6 +199,7 @@ bool SonsOfSolApplication::initialize( int argc, char** argv ) {
}
m_earth_shader_light_pos = m_earth_prog->getUniformLocation( "lightPos" );
m_earth_shader_camera_pos = m_earth_prog->getUniformLocation( "cameraPos" );
+ m_earth_shader_time = m_earth_prog->getUniformLocation( "time" ) ;
cout << "Earth light " << m_earth_shader_light_pos << endl;
cout << "Earth camera " << m_earth_shader_camera_pos << endl;