Index: branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc
===================================================================
--- branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc	(revision 8663)
+++ branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc	(revision 8668)
@@ -53,4 +53,6 @@
 {
   this->deactivate();
+  
+  delete shader;
 }
 
@@ -62,6 +64,11 @@
   this->offsetZ = 0;
   this->animationSpeed = 2;
-
-  noise3DTexSize = 64;
+  this->lightPos = Vector(0,0,0);
+  this->scale = 0.01f;
+  this->atmosphericRadius = 120;
+  this->planetRadius = 90;
+  this->divs = 100;
+
+  noise3DTexSize = 128;
   noise3DTexName = 0;
 
@@ -89,6 +96,4 @@
   Shader::Uniform(shader, "SkyColor").set(0.0f, 0.0f, 0.8f);
   Shader::Uniform(shader, "CloudColor").set(0.8f, 0.8f, 0.8f);
-  Shader::Uniform(shader, "LightPos").set(5.0f, 0.0f, 5.0f);
-  Shader::Uniform(shader, "Scale").set(0.1f);
   
   offset = new Shader::Uniform(shader, "Offset");
@@ -103,4 +108,10 @@
 
   LoadParam(root, "speed", this, CloudEffect, setAnimationSpeed);
+  LoadParam(root, "lightPos", this, CloudEffect, setLightPosition);
+  LoadParam(root, "scale", this, CloudEffect, setCloudScale);
+  
+  LoadParam(root, "planetRadius", this, CloudEffect, setPlanetRadius);
+  LoadParam(root, "atmosphericRadius", this, CloudEffect, setAtmosphericRadius);
+  LoadParam(root, "divisions", this, CloudEffect, setDivisions);
   
   LOAD_PARAM_START_CYCLE(root, element);
@@ -115,4 +126,12 @@
 {
   PRINTF(0)( "Activating\n");
+  
+  // Can only be set after the loadParams call
+  this->shader->activateShader();
+  Shader::Uniform(shader, "Scale").set(this->scale);
+  Shader::Uniform(shader, "LightPos").set(lightPos.x, lightPos.y, lightPos.z);
+  this->shader->deactivateShader();
+  
+  this->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1);
 
   this->cloudActivate = true;
@@ -139,5 +158,5 @@
   glBindTexture(GL_TEXTURE_3D, noise3DTexName);
 
-  glPushMatrix();
+  //glPushMatrix();
 
   this->shader->activateShader();
@@ -145,5 +164,5 @@
 
 
-  glColor3f(1.0, 1.0, 1.0);
+  /*glColor3f(1.0, 1.0, 1.0);
   glBegin(GL_QUADS);
 
@@ -153,9 +172,28 @@
   glTexCoord2f(1.0f, 0.0f); glVertex3f(10.0f, 0.0f,  0.0f);
 
+  glEnd();*/
+
+  glPushMatrix();
+  glTranslatef(0.0f,pRadius,0.0f);
+  //glRotatef(timeGetTime()/2000.0f,0.0f, 1.0f, 0.0f);
+  //glTranslatef(0.0f,0.0f,0.0f);
+
+  glBegin(GL_TRIANGLES);
+
+  for (int i=0; i < numIndices; i++)
+  {
+    glColor3f(1.0f, 1.0f, 1.0f);
+
+    glTexCoord2f(planeVertices[indices[i]].u, planeVertices[indices[i]].v);
+    glVertex3f(planeVertices[indices[i]].x, planeVertices[indices[i]].y, planeVertices[indices[i]].z);
+  }
+
   glEnd();
 
+  glPopMatrix();
+
   this->shader->deactivateShader();
 
-  glPopMatrix();
+  //glPopMatrix();
   glPopAttrib();
 
@@ -167,4 +205,98 @@
     return;
   this->offsetZ += 0.05 * dt * this->animationSpeed;
+}
+
+void CloudEffect::generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, float hTile, float vTile)
+{
+  // Make sure our vertex array is clear
+  if (planeVertices) 
+  {
+    delete planeVertices;
+    planeVertices = NULL;
+  }
+
+  // Make sure our index array is clear
+  if (indices)
+  {
+    delete indices;
+    indices = NULL;
+  }
+
+  // Set the number of divisions into a valid range
+  int divs = divisions;
+  if (divisions < 1) 
+    divs = 1;
+
+  if (divisions > 256) 
+    divs = 256; 
+
+  pRadius = planetRadius;
+
+  // Initialize the Vertex and indices arrays
+  numPlaneVertices = (divs + 1) * (divs + 1);   // 1 division would give 4 verts
+  numIndices  = divs * divs * 2 * 3;       // 1 division would give 6 indices for 2 tris
+
+  planeVertices = new VERTEX[numPlaneVertices];
+  memset(planeVertices, 0, sizeof(VERTEX));
+
+  indices = new int[numIndices];
+  memset(indices, 0, sizeof(int)*numIndices);
+
+  // Calculate some values we will need
+  float plane_size = 2.0f * (float)sqrt((SQR(atmosphereRadius)-SQR(planetRadius)));
+  float delta = plane_size/(float)divs;
+  float tex_delta = 2.0f/(float)divs;
+  
+  // Variables we'll use during the dome's generation
+  float x_dist   = 0.0f;
+  float z_dist   = 0.0f;
+  float x_height = 0.0f;
+  float z_height = 0.0f;
+  float height = 0.0f;
+
+  VERTEX SV; // temporary vertex
+
+  for (int i=0;i <= divs;i++)
+  {
+    for (int j=0; j <= divs; j++)
+    {
+      x_dist = (-0.5f * plane_size) + ((float)j*delta);
+      z_dist = (-0.5f * plane_size) + ((float)i*delta);
+
+      x_height = (x_dist*x_dist) / atmosphereRadius;
+      z_height = (z_dist*z_dist) / atmosphereRadius;
+      height = x_height + z_height;
+
+      SV.x = x_dist;
+      SV.y = 0.0f - height;
+      SV.z = z_dist;
+
+      // Calculate the texture coordinates
+      SV.u = hTile*((float)j * tex_delta*0.5f);
+      SV.v = vTile*(1.0f - (float)i * tex_delta*0.5f);
+
+      planeVertices[i*(divs+1)+j] = SV;
+    }
+  }
+
+  // Calculate the indices
+  int index = 0;
+  for (int i=0; i < divs;i++)
+  {
+    for (int j=0; j < divs; j++)
+    {
+      int startvert = (i*(divs+1) + j);
+
+        // tri 1
+      indices[index++] = startvert;
+      indices[index++] = startvert+1;
+      indices[index++] = startvert+divs+1;
+
+      // tri 2
+      indices[index++] = startvert+1;
+      indices[index++] = startvert+divs+2;
+      indices[index++] = startvert+divs+1;
+    }
+  }  
 }
 
Index: branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h
===================================================================
--- branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h	(revision 8663)
+++ branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h	(revision 8668)
@@ -31,4 +31,15 @@
 #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
 
+
+#define DTOR (PI/180.0f)
+#define SQR(x) (x*x)
+
+typedef struct {
+  float x,y,z;
+  unsigned int color;
+  float u, v;
+} VERTEX;
+
+
 class CloudEffect : public WeatherEffect
 {
@@ -45,11 +56,9 @@
 
   inline void activateCloud()
-  {
-    this->activate();
-  }
+  { this->activate(); }
+  
   inline void deactivateCloud()
-  {
-    this->deactivate();
-  }
+  { this->deactivate(); }
+  
   inline void setCloudOption(const std::string& option)
   {
@@ -57,9 +66,23 @@
       this->cloudActivate = true;
   }
+  
   inline void setAnimationSpeed(float speed)
-  {
-    this->animationSpeed = speed;
-  }
+  { this->animationSpeed = speed; }
+  
+  inline void setLightPosition(float x, float y, float z)
+  { this->lightPos = Vector(x,y,z); }
 
+  inline void setCloudScale(float scale)
+  { this->scale = scale; }
+  
+  inline void setPlanetRadius(float planetRadius)
+  { this->planetRadius = planetRadius; }
+  
+  inline void setAtmosphericRadius(float atmosphericRadius)
+  { this->atmosphericRadius = atmosphericRadius; }
+  
+  inline void setDivisions(int divs)
+  { this->divs = divs; }
+  
   virtual void draw() const;
   virtual void tick(float dt);
@@ -72,27 +95,48 @@
   void normalize3(double v[3]);
 
+  void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius,
+                        float hTile, float vTile);
 private:
 
-  bool        cloudActivate;
-  float       animationSpeed;
+  bool             cloudActivate;
+  float            animationSpeed;
 
   // Material                 cloudMaterial;
-  Shader*                 shader;
-  Shader::Uniform*        offset;
+  
+  // SHADER STUFF
+  Shader*          shader;
+  Shader::Uniform* offset;
+  float            offsetZ;
+  Vector           lightPos;
+  float            scale;
+  float            planetRadius;
+  float            atmosphericRadius;
+  int              divs;
 
-  float offsetZ;
+  // NOISE STUFF
+  int              noise3DTexSize;
+  GLuint           noise3DTexName;
+  GLubyte          *noise3DTexPtr;
 
-  int noise3DTexSize;
-  GLuint noise3DTexName;
-  GLubyte *noise3DTexPtr;
+  int              p[MAXB + MAXB + 2];
+  double           g3[MAXB + MAXB + 2][3];
+  double           g2[MAXB + MAXB + 2][2];
+  double           g1[MAXB + MAXB + 2];
 
-  int p[MAXB + MAXB + 2];
-  double g3[MAXB + MAXB + 2][3];
-  double g2[MAXB + MAXB + 2][2];
-  double g1[MAXB + MAXB + 2];
+  int              start;
+  int              B;
+  int              BM;
+  
+  // SKYPLANE STUFF
+  VERTEX *planeVertices;
+  int numPlaneVertices;
 
-  int start;
-  int B;
-  int BM;
+  int *indices;
+  int numIndices;
+
+  float pRadius;
+  
+  VERTEX *vertices;
+  int numVertices;
 };
 
