Commits

Anonymous committed dce7b53

Implemented improved water. Tweaks to the environment system.

  • Participants
  • Parent commits f54cb91

Comments (0)

Files changed (7)

 #include "text.h"
 #include "texture.h"
 
-#define MAX_DISTANCE        400
+#define MAX_DISTANCE        300
 #define ENV_TRANSITION      0.05f
 #define UPDATE_INTERVAL     200 //milliseconds
 
 
   Region*   r;
   bool      day;
+  int       i;
+  GLrgba    average;
 
   r = (Region*)CameraRegion ();
   day = (hours >= 6 && hours < 21);
       desired.color[ENV_COLOR_NORTH] = glRgba (0.5f, 0.9f, 1.0f);
       desired.color[ENV_COLOR_SOUTH] = glRgba (0.5f, 0.9f, 1.0f);
       desired.color[ENV_COLOR_EAST] = glRgba (0.5f, 0.9f, 1.0f);
-      desired.color[ENV_COLOR_WEST] = glRgba (0.5f, 0.7f, 1.0f);
-      desired.color[ENV_COLOR_TOP] = glRgba (0.0f, 0.0f, 1.0f);
       desired.color[ENV_COLOR_FOG] = glRgba (0.5f, 0.9f, 1.0f);
-      desired.color[ENV_COLOR_LIGHT] = glRgba (1.0f, 1.0f, 0.5f);
+      desired.color[ENV_COLOR_WEST] = glRgba (0.5f, 0.9f, 1.0f);
+      desired.color[ENV_COLOR_TOP] = glRgba (0.0f, 0.0f, 0.6f);
+      desired.color[ENV_COLOR_LIGHT] = glRgba (1.0f, 1.0f, 1.0f);
       desired.color[ENV_COLOR_AMBIENT] = glRgba (0.3f, 0.3f, 1.0f);
       desired.light = glVector (-0.5f, 0.0f, -0.5f);
       desired.star_fade = 0.0f;
       desired.fog_max = MAX_DISTANCE;
-      desired.fog_min = MAX_DISTANCE -  MAX_DISTANCE * r->moisture;
+      desired.fog_min = MAX_DISTANCE - MAX_DISTANCE * r->moisture;
+      //desired.fog_min = MAX_DISTANCE / 2;
+      /*
       if (r->has_flowers) {
         desired.color[ENV_COLOR_NORTH] = glRgba (1.0f, 1.0f, 0.8f);
         desired.color[ENV_COLOR_SOUTH] = glRgba (1.0f, 1.0f, 0.8f);
         desired.color[ENV_COLOR_AMBIENT] = glRgba (0.0f, 0.0f, 1.0f);
         desired.fog_min = 1;
       }
+      */
+      for (i = 0; i < ENV_COLOR_COUNT; i++) {
+        //if (i == ENV_COLOR_TOP)
+          //continue;
+        //if (i == ENV_COLOR_LIGHT)
+         // continue;
+        average = desired.color[i] + r->color_atmosphere;
+        desired.color[i] = average / 2;
+        //desired.color[i] = r->color_atmosphere;
+      }
+      //desired.color[ENV_COLOR_TOP] = r->color_atmosphere;
+
       break;
     case 19:
       desired.color[ENV_COLOR_NORTH] = glRgba (0.1f, 0.5f, 0.5f);

Terrain/Region.cpp

 #define BLEND_DISTANCE    (REGION_SIZE / 4)
 //#define BLEND_DISTANCE    1
 #define DITHER_SIZE       (REGION_SIZE / 2)
-#define OCEAN_BUFFER      20 //The number of regions around the edge which must be ocean
+#define OCEAN_BUFFER      2 //The number of regions around the edge which must be ocean
 #define COAST_DEPTH       2 // how many blocks inward do we find sand
 #define FLOWER_PALETTE    (sizeof (flower_palette) / sizeof (GLrgba))
 
       //If everthing around us is above us, we can't flow downhill
       if (!selected.x && !selected.y) //Let's just head for the edge of the map
         selected = to_coast;
-      //selected.x = 0;
-      //selected.y = -1;
       neighbor = &continent[x + selected.x][y + selected.y];
       if (selected.y == -1) {//we're moving north
         neighbor->flags_shape |= REGION_FLAG_RIVERS;
     moist = 1.0f;
     for (x = 0; x < REGION_GRID; x++) {
       r = continent[x][y];
-      moist -= 1.0f / REGION_CENTER;
+      moist -= 5.0f / REGION_CENTER;
       //Mountains block rainfall
       if (r.climate == CLIMATE_MOUNTAIN) {
         moist -= 0.1f * r.mountain_height;
         r.color_grass = glRgbaInterpolate (dry_grass, wet_grass, r.moisture);
       }
 
-
-
       //Devise a random but plausible dirt color
       {
         GLrgba    cold_dirt, warm_dirt, dry_dirt, wet_dirt;
         //warm dirt us a fade from wet to dry
         warm_dirt = glRgbaInterpolate (dry_dirt, wet_dirt, r.moisture);
         fade = MathScalar (r.temperature, FREEZING, 1.0f);
-        //Final color is a fade from warm to cold
-        //r.color_dirt = glRgbaInterpolate (cold_dirt, warm_dirt, fade);
-        r.color_dirt = warm_dirt;///////////////////////////////
+        r.color_dirt = glRgbaInterpolate (cold_dirt, warm_dirt, fade);
+      }
+
+      //"atmosphere" is the overall color of the lighting & fog. 
+      {
+
+        GLrgba    humid_air, dry_air, cold_air, warm_air;
+
+        humid_air = glRgba (1.0f, 1.0f, 0.3f);
+        dry_air = glRgba (1.0f, 0.7f, 0.3f);
+        warm_air = glRgbaInterpolate (dry_air, humid_air, r.moisture);
+        cold_air = glRgba (0.3f, 0.7f, 1.0f);
+        r.color_atmosphere = glRgbaInterpolate (cold_air, warm_air, r.temperature);
       }
 
       //Devise a rock color
       case CLIMATE_OCEAN:
         break;//We set this when we made the ocean
       case CLIMATE_RIVER:
-        r.color_map = glRgba (0.0f, 1.0f, 1.0f);
+        r.color_map = glRgba (0.0f, 0.0f, 0.6f);
         break;
       default:
         r.color_map = r.color_grass;break;
       }
-      r.color_atmosphere = (glRgba (0.0f, 1.0f, 1.0f) * 1 + r.color_grass) / 2;
-      r.color_atmosphere = glRgba (r.moisture / 2, r.moisture, 1.0f);
-    
+      //r.color_atmosphere = (glRgba (0.0f, 1.0f, 1.0f) * 1 + r.color_grass) / 2;
+      //r.color_atmosphere = glRgba (r.moisture / 2, r.moisture, 1.0f);
+    /*
       
       if (r.climate != CLIMATE_OCEAN) {
         //r.color_map = glRgba (r.temperature, 1.0f - r.temperature * 2, 1.0f - r.temperature);
         if (r.climate == CLIMATE_RIVER) 
           r.color_map = glRgba (0.0f, 0.5f, 1.0f);
       }
+      */
 
-
+      //r.color_map = r.color_atmosphere;
       continent[x][y] = r;
     }
   }
-#define REGION_SIZE       64
+#define REGION_SIZE       16
 #define REGION_HALF       (REGION_SIZE / 2)
-#define REGION_GRID       128
+#define REGION_GRID       64
+#define REGION_GRID_EDGE  (REGION_GRID + 1)
 #define REGION_CENTER     (REGION_GRID / 2)
 
 #define REGION_FLAG_TEST        0x0001

Terrain/Render.cpp

 #include "texture.h"
 #include "text.h"
 #include "world.h"
+#include "water.h"
 
 static int            view_width;
 static int            view_height;
 
 }
 
-void WaterRender (bool underwater)
+void  water_map (bool underwater)
 {
-  /*
+
   GLtexture*      t;
 
-  t = TextureFromName ("water3.bmp", MASK_LUMINANCE);
-  glBindTexture (GL_TEXTURE_2D, t->id);
-  glEnable (GL_TEXTURE_2D);
-  glEnable (GL_BLEND);
-  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-  glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
-  //draw_water (256);
-  if (!underwater) {
-    glBindTexture (GL_TEXTURE_2D, RegionMap ());
-  	//glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);	
-    glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	
-    glBlendFunc (GL_ONE, GL_SRC_COLOR);
-    //glBlendFunc (GL_ONE, GL_ONE);
-    glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
-    draw_water (1);
-  }
-  */
-  GLtexture*      t;
-
-
   glBindTexture (GL_TEXTURE_2D, RegionMap ());
   glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	
-  glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);	
+  //glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);	
   glEnable (GL_TEXTURE_2D);
-  glDisable (GL_BLEND);
-  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-  glColor4f (1.0f, 1.0f, 1.0f, 0.5f);
+  glEnable (GL_BLEND);
+//  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+  glBlendFunc (GL_ONE, GL_ONE);
   glColor3f (1.0f, 1.0f, 1.0f);
+  glDepthMask (false);
   draw_water (1);
+  glDepthMask (true);
   return;
   if (!underwater) {
     t = TextureFromName ("water1.bmp", MASK_LUMINANCE);
   fovy = FOV;
   if (view_aspect > 1.0f) 
     fovy /= view_aspect; 
-  gluPerspective (fovy, view_aspect, 0.1f, RENDER_DISTANCE);
+  //gluPerspective (fovy, view_aspect, 0.1f, RENDER_DISTANCE);
+  gluPerspective (fovy, view_aspect, 0.1f, 400);
 	glMatrixMode (GL_MODELVIEW);
   size = min (width, height); 
   d = 128;
   GLvector        pos;
   GLvector        angle;
   Env*            e;
+  float           water_level;
 
   pos = CameraPosition ();
   e = EnvGet ();
-  if (pos.z >= 0) {
+  water_level = RegionWaterLevel ((int)pos.x, (int)pos.y);
+  water_level = max (water_level, 0);
+  if (pos.z >= water_level) {
     //cfog = (current_diffuse + glRgba (0.0f, 0.0f, 1.0f)) / 2;
-    glFogf(GL_FOG_START, RENDER_DISTANCE / 2);				// Fog Start Depth
-    glFogf(GL_FOG_END, RENDER_DISTANCE);				// Fog End Depth
+    //glFogf(GL_FOG_START, RENDER_DISTANCE / 2);				// Fog Start Depth
+    //glFogf(GL_FOG_END, RENDER_DISTANCE);				// Fog End Depth
     glFogf(GL_FOG_START, e->fog_min);				// Fog Start Depth
     glFogf(GL_FOG_END, e->fog_max);				// Fog End Depth
   } else {
   }
   glEnable (GL_FOG);
   glFogi (GL_FOG_MODE, GL_LINEAR);
+  //glFogi (GL_FOG_MODE, GL_EXP);
   glFogfv (GL_FOG_COLOR, &e->color[ENV_COLOR_FOG].red);
   glClearColor (e->color[ENV_COLOR_FOG].red, e->color[ENV_COLOR_FOG].green, e->color[ENV_COLOR_FOG].blue, 1.0f);
   //glClearColor (0, 0, 0, 1.0f);
   SceneRender ();
   if (terrain_debug)
     SceneRenderDebug (terrain_debug);
+  //WaterRender (pos.z <= 0.0f);
   if (world_debug)
     WorldRenderDebug ();
-  WaterRender (pos.z <= 0.0f);
   TextRender ();
   if (show_map) 
     RenderTexture (RegionMap ());

Terrain/Scene.cpp

 #include "sdl.h"
 #include "text.h"
 #include "texture.h"
+#include "water.h"
 
 #define GRASS_GRID      5
 #define GRASS_HALF      (GRASS_GRID / 2)
       grass[x][y].Set (current.x + x - GRASS_HALF, current.y + y - GRASS_HALF);
     }
   }
+  WaterBuild ();
   for (y = 0; y < REGION_GRID; y++) {
     for (x = 0; x < REGION_GRID; x++) {
       water[x][y] = glVector (x * REGION_SIZE, y * REGION_SIZE, RegionWaterLevel (x * REGION_SIZE, y * REGION_SIZE));
     }
   }
+  
 
 }
 
   }
 
 
+  WaterRender ();
 
+  return;
   
   glColor3f (0.4f, 0.7f, 1.0f);
   glNormal3f (0, 0, 1);
 #include "camera.h"
 #include "env.h"
 #include "math.h"
+#include "random.h"
 #include "sdl.h"
 #include "texture.h"
 #include "vbo.h"
 
 #define STAR_TILE   3
 #define DISC        8
-#define SKY_GRID    8
+#define SKY_GRID    12
 #define SKY_EDGE    (SKY_GRID + 1)
 #define SKY_HALF    (SKY_GRID / 2)
-#define SKY_DOME    1.5f
-#define SKY_TILE    3
+#define SKY_DOME    0.5f
+#define SKY_TILE    5
 
 struct skyvert
 {
   starcube.Create (GL_TRIANGLES, index.size (), vert.size (), &index[0], &vert[0], &normal[0], NULL, &uv[0]);
   */
 
-  int     x, y;
-  int     offset;
-  float   dist;
+  int       x, y;
+  int       offset;
+  float     dist;
+  GLvector2 distance;
 
   for (y = 0; y < SKY_EDGE; y++) {
     for (x = 0; x < SKY_EDGE; x++) {
-      offset = max (abs (x - SKY_HALF), abs (y - SKY_HALF));
-      dist = 1.0f - ((float)offset / (SKY_HALF));
-      vert.push_back (glVector ((float)x - SKY_HALF, (float)y - SKY_HALF, dist * SKY_DOME) - SKY_DOME / 8);
+      distance = glVector ((float)x - SKY_HALF, (float)y - SKY_HALF);
+      //offset = max (abs (x - SKY_HALF), abs (y - SKY_HALF));
+      //dist = 1.0f - ((float)offset / (SKY_HALF));
+      dist = 1.0f - glVectorLength (distance) / (SKY_HALF - 3);
+      //vert.push_back (glVector ((float)x - SKY_HALF, (float)y - SKY_HALF, dist * SKY_DOME) - SKY_DOME / 8);
+      vert.push_back (glVector ((float)x - SKY_HALF, (float)y - SKY_HALF, dist * SKY_DOME));
       normal.push_back (glVector (0.0f, 0.0f, 1.0f));
-      uv.push_back (glVector (((float)x / SKY_GRID) * SKY_TILE, ((float)y / SKY_GRID) * SKY_TILE));
+      //uv.push_back (glVector (((float)x / SKY_GRID) * SKY_TILE, ((float)y / SKY_GRID) * SKY_TILE));
+      uv.push_back (glVector (((float)(x + RandomFloat ()) / SKY_GRID) * SKY_TILE, ((float)(y + RandomFloat ()) / SKY_GRID) * SKY_TILE));
 
     }
   }
     }
   }
   skydome.Create (GL_TRIANGLES, index.size (), vert.size (), &index[0], &vert[0], &normal[0], NULL, &uv[0]);
+  //skydome.Create (GL_LINE_STRIP, index.size (), vert.size (), &index[0], &vert[0], &normal[0], NULL, &uv[0]);
 
 
 }
   build_sky ();
   
   tip.env_color = ENV_COLOR_TOP;
-  tip.pos = glVector (0.0f, 0.0f, 0.15f);
+  tip.pos = glVector (0.0f, 0.0f, 0.3f);
   for (int i = 0; i < DISC; i++) {
     angle = 22.5f + (((float)i / DISC) * 360.0f) * DEGREES_TO_RADIANS; 
     sky[i].pos.x = sin (angle);
 
   GLvector angle;
 
-  return;
+  //return;
   angle = CameraAngle ();
   glPushMatrix ();
   glLoadIdentity ();
   glDisable (GL_TEXTURE_2D);
   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
   //glBegin (GL_TRIANGLE_FAN);
+  
   glBegin (GL_TRIANGLE_FAN);
   glColor3fv (&tip.color.red);
   glVertex3fv (&tip.pos.x);
     glVertex3fv (&sky[i % DISC].pos.x);
   }
   glEnd ();
+  
   /*
   glBegin (GL_QUAD_STRIP);
   for (int i = 0; i <= DISC; i++) {
   skydome.Render ();
 
 
+  GLtexture* t;
 
+  t = TextureFromName ("clouds2.bmp", MASK_LUMINANCE);
 
-  glBindTexture (GL_TEXTURE_2D, TextureIdFromName ("clouds2.bmp"));
+  //glBindTexture (GL_TEXTURE_2D, TextureIdFromName ("clouds2.bmp"));
+  glBindTexture (GL_TEXTURE_2D, t->id);
+  //glBindTexture (GL_TEXTURE_2D, 0);
   glColor3f (0.3f,0.3f,0.3f);
+  //starcube.Render ();
+  glEnable (GL_ALPHA_TEST);
+  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+  glBlendFunc (GL_ONE, GL_ONE);
+  glColor3f (0.1f,0.1f,0.1f);
+
+  static float    x;
+  float o;
+
+  glMatrixMode (GL_TEXTURE);
+  glLoadIdentity ();
+  x += 0.001f;
+  o = sin (x);
+
+  glAlphaFunc (GL_GREATER, abs (o));
+
+  glTranslatef (x, 0.0f, 5.0f);
+  glPolygonMode(GL_FRONT_AND_BACK, GL_LINES);
+  //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+  glBlendFunc (GL_SRC_COLOR, GL_DST_COLOR);
+  //glBlendFunc (GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
+  glBlendFunc (GL_ONE, GL_ONE);
   skydome.Render ();
-  //starcube.Render ();
+  glLoadIdentity ();
 
 
+  glMatrixMode (GL_MODELVIEW);
 
-
+  glAlphaFunc (GL_GREATER, 0.0f);
   glEnable (GL_LIGHTING);
   glDepthMask (true);
   glPopMatrix ();

Terrain/Terrain.vcxproj

     <ClCompile Include="Sdl.cpp" />
     <ClCompile Include="Texture.cpp" />
     <ClCompile Include="VBO.cpp" />
+    <ClCompile Include="Water.cpp" />
     <ClCompile Include="World.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Text.h" />
     <ClInclude Include="Texture.h" />
     <ClInclude Include="VBO.h" />
+    <ClInclude Include="Water.h" />
     <ClInclude Include="World.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />