Browse files

Rando textures

  • Loading branch information...
1 parent 5131325 commit 65f87e31b91e9a803f3432965919ee35194d125f @ejcaruso ejcaruso committed Dec 15, 2011
Showing with 62 additions and 22 deletions.
  1. +45 −9 gen/SystemGenerator.cpp
  2. +9 −9 geom/Planet.cpp
  3. +8 −4 shaders/terrain.frag
View
54 gen/SystemGenerator.cpp
@@ -1,13 +1,49 @@
#include "SystemGenerator.h"
#define MIN_ORB_RADIUS 8.0
-#define MAX_ORB_RADIUS 70.0
-#define MIN_PL_RADIUS 0.6
-#define MAX_PL_RADIUS 2.0
+#define MAX_ORB_RADIUS 50.0
+#define MIN_PL_RADIUS 0.4
+#define MAX_PL_RADIUS 1.6
#define MIN_SUN_RADIUS 3.0
#define MAX_SUN_RADIUS 5.5
#define MIN_NUM_PLANETS 4
-#define MAX_NUM_PLANETS 12
+#define MAX_NUM_PLANETS 10
+
+#define NUM_LOWTEX 6
+#define NUM_MLTEX 7
+#define NUM_MHTEX 3
+#define NUM_HITEX 3
+
+const char *lowtex[] = {
+ "../CS123-Final-Project/textures/unsorted/Rust0141_7_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/Rust0143_15_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/SoilSand0181_23_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/SoilSand0182_11_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/SoilCracked0157_7_M.jpg",
+ "/course/cs123/data/image/terrain/rock.JPG"
+};
+
+const char *medlowtex[] = {
+ "../CS123-Final-Project/textures/unsorted/SoilSand0181_23_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/SoilSand0182_11_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/SoilCracked0157_7_M.jpg",
+ "../CS123-Final-Project/textures/unsorted/Grass0126_2_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/NatureForests0009_2_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/NatureForests0072_12_S.jpg",
+ "/course/cs123/data/image/terrain/grass.JPG"
+};
+
+const char *medhitex[] = {
+ "../CS123-Final-Project/textures/unsorted/Cliffs0143_9_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/Cliffs0199_189_S.jpg",
+ "/course/cs123/data/image/terrain/dirt.JPG"
+};
+
+const char *hitex[] = {
+ "../CS123-Final-Project/textures/unsorted/Snow0041_5_S.jpg",
+ "../CS123-Final-Project/textures/unsorted/Ice0044_42_S.jpg",
+ "/course/cs123/data/image/terrain/snow.JPG"
+};
int randi(int min, int max) {
return rand()%(max - min)+min;
@@ -74,13 +110,13 @@ QList<Planet> SystemGenerator::generate() {
planet.setAxis(axis[idx]);
planet.setAxialRotation(axial_rot[idx]);
planet.setOrbitalRotation(orb_rot[idx]);
- planet.setTerrainAmplitude(randf(.04, .12));
+ planet.setTerrainAmplitude(randf(.02, .1));
// lol textchers
- planet.setTexture("/course/cs123/data/image/terrain/grass.JPG", 0);
- planet.setTexture("/course/cs123/data/image/terrain/dirt.JPG", 1);
- planet.setTexture("/course/cs123/data/image/terrain/snow.JPG", 2);
- planet.setTexture("/course/cs123/data/image/terrain/rock.JPG", 3);
+ planet.setTexture(lowtex[randi(0,NUM_LOWTEX)], 0);
+ planet.setTexture(medlowtex[randi(0,NUM_MLTEX)], 1);
+ planet.setTexture(medhitex[randi(0,NUM_MHTEX)], 2);
+ planet.setTexture(hitex[randi(0,NUM_HITEX)], 3);
planets.push_back(planet);
}
}
View
18 geom/Planet.cpp
@@ -123,20 +123,20 @@ void Planet::render() {
m_planetShader->setUniformValue("tex4", (GLuint)3);
// load in other uniforms
- m_planetShader->setUniformValue("global_amp_scale",(GLfloat)0.10);
+ m_planetShader->setUniformValue("global_amp_scale",(GLfloat)m_terrainAmplitude);
m_planetShader->setUniformValue("global_pos_scale",(GLfloat)2.0);
m_planetShader->setUniformValue("planet_seed",(GLuint)getSeed());
m_planetShader->setUniformValue("noise_octaves",(GLuint)getOctaveCount());
// load data about how the textures are to be mapped for the planet shader
- m_planetShader->setUniformValue("tex1_min", (GLfloat)-0.02);
- m_planetShader->setUniformValue("tex1_max", (GLfloat)0);
- m_planetShader->setUniformValue("tex2_min", (GLfloat)0);
- m_planetShader->setUniformValue("tex2_max", (GLfloat)0.02);
- m_planetShader->setUniformValue("tex3_min", (GLfloat)0.02);
- m_planetShader->setUniformValue("tex3_max", (GLfloat)0.1);
- m_planetShader->setUniformValue("tex4_min", (GLfloat)-0.1);
- m_planetShader->setUniformValue("tex4_max", (GLfloat)-0.02);
+ m_planetShader->setUniformValue("tex1_min", (GLfloat)-1.0);
+ m_planetShader->setUniformValue("tex1_max", (GLfloat)-0.015);
+ m_planetShader->setUniformValue("tex2_min", (GLfloat)-0.015);
+ m_planetShader->setUniformValue("tex2_max", (GLfloat)0.0);
+ m_planetShader->setUniformValue("tex3_min", (GLfloat)0.0);
+ m_planetShader->setUniformValue("tex3_max", (GLfloat)0.015);
+ m_planetShader->setUniformValue("tex4_min", (GLfloat)0.015);
+ m_planetShader->setUniformValue("tex4_max", (GLfloat)1.0);
} else {
m_starShader->bind();
View
12 shaders/terrain.frag
@@ -15,16 +15,20 @@ varying float depth;
vec4 sampleTextures() {
float tex1_rng = tex1_max-tex1_min;
- float tex1_w = max(0.0,(tex1_rng-abs(height-tex1_max))/tex1_rng);
+ float tex1_avg = (tex1_max+tex1_min)/2;
+ float tex1_w = max(0.0,(tex1_rng-abs(height-tex1_avg))/tex1_rng);
float tex2_rng = tex2_max-tex2_min;
- float tex2_w = max(0.0,(tex2_rng-abs(height-tex2_max))/tex2_rng);
+ float tex2_avg = (tex2_max+tex2_min)/2;
+ float tex2_w = max(0.0,(tex2_rng-abs(height-tex2_avg))/tex2_rng);
float tex3_rng = tex3_max-tex3_min;
- float tex3_w = max(0.0,(tex3_rng-abs(height-tex3_max))/tex3_rng);
+ float tex3_avg = (tex3_max+tex3_min)/2;
+ float tex3_w = max(0.0,(tex3_rng-abs(height-tex3_avg))/tex3_rng);
float tex4_rng = tex4_max-tex4_min;
- float tex4_w = max(0.0,(tex4_rng-abs(height-tex4_max))/tex4_rng);
+ float tex4_avg = (tex4_max+tex4_min)/2;
+ float tex4_w = max(0.0,(tex4_rng-abs(height-tex4_avg))/tex4_rng);
vec4 sample = tex1_w*texture2D(tex1, gl_TexCoord[0].st * 6.0);
sample += tex2_w*texture2D(tex2, gl_TexCoord[0].st * 6.0);

0 comments on commit 65f87e3

Please sign in to comment.