[Add] Some more gas giant rendering work. Now procedurally generated!

[Add] Some Screenies.
This commit is contained in:
Rtch90 2017-11-22 23:25:26 +00:00
parent e8d67b6f02
commit 869c4e6a54
17 changed files with 165 additions and 69 deletions

BIN
screenshot/SPACE.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
screenshot/dockstation.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 KiB

BIN
screenshot/gasgiant1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 KiB

BIN
screenshot/gasgiant2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 KiB

BIN
screenshot/gasgiant7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
screenshot/gasplanet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

BIN
screenshot/l3d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

BIN
screenshot/rings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 KiB

BIN
screenshot/ship1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
screenshot/ship_wheels.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

View File

@ -75,6 +75,10 @@ public:
return 0;
}
double drange(double min, double max) {
return (*this)(max-min)+min;
}
double operator()(double max) {
/* Divided by 2^32 */
return max*static_cast<double>(rand_int32()) * (1./4294967296.);

View File

@ -31,14 +31,12 @@ void ObjectViewerView::Draw3D(void) {
pos = matrix4x4d::RotateYMatrix(-DEG_2_RAD*rot) * pos;
pos = matrix4x4d::RotateXMatrix(-DEG_2_RAD*rot) * pos;
/*
float lightPos[4];
lightPos[0] = 0;
lightPos[1] = 0;
lightPos[2] = 0;
lightPos[0] = 1;
lightPos[1] = 1;
lightPos[2] = 1;
lightPos[3] = 0;
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
*/
/* SBRE rendering (See ModelBody.cpp) uses this.. */
glRotatef(-rot, 0, 1, 0);

View File

@ -81,11 +81,6 @@ void subdivide(vector3d& v1, vector3d& v2, vector3d& v3, vector3d& v4, int depth
}
void DrawLovelyRoundCube(double radius) {
const float mdiff[] = { 1.0, 0.8, 0.5, 1.0 };
const float mambient[] = {0.1, 0.08, 0.05, 1.0 };
glMaterialfv(GL_FRONT, GL_AMBIENT, mambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mdiff);
vector3d p1(1, 1, 1);
vector3d p2(-1, 1, 1);
vector3d p3(-1, -1, 1);
@ -127,16 +122,9 @@ void DrawLovelyRoundCube(double radius) {
}
/* Both arguments in radians. */
void DrawHoop(float latitude, float width, const float col[4]) {
void DrawHoop(float latitude, float width, float wobble, MTRand& rng) {
glPushAttrib(GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
float mambient[4];
mambient[0] = col[0]*.1;
mambient[1] = col[1]*.1;
mambient[2] = col[2]*.1;
mambient[3] = col[3];
glMaterialfv(GL_FRONT, GL_AMBIENT, mambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, col);
glEnable(GL_NORMALIZE);
glEnable(GL_BLEND);
@ -144,7 +132,7 @@ void DrawHoop(float latitude, float width, const float col[4]) {
for(double longitude=0.0f; longitude < 2*M_PI; longitude += 0.02) {
vector3d v;
double l;
l = latitude+0.5*width;
l = latitude+0.5*width+rng(wobble*width);
v.x = sin(longitude)*cos(l);
v.y = sin(l);
v.z = cos(longitude)*cos(l);
@ -152,7 +140,7 @@ void DrawHoop(float latitude, float width, const float col[4]) {
glNormal3dv(&v.x);
glVertex3dv(&v.x);
l = latitude-0.5*width;
l = latitude-0.5*width-rng(wobble*width);
v.x = sin(longitude)*cos(l);
v.y = sin(l);
v.z = cos(longitude)*cos(l);
@ -161,17 +149,13 @@ void DrawHoop(float latitude, float width, const float col[4]) {
}
double l = latitude+0.5*width;
vector3d v;
v.x = 0;
v.y = sin(l);
v.z = cos(l);
v.x = 0; v.y = sin(l); v.z = cos(l);
v.Normalize();
glNormal3dv(&v.x);
glVertex3dv(&v.x);
l = latitude-0.5*width;
v.x = 0;
v.y = sin(l);
v.z = cos(l);
v.x = 0; v.y = sin(l); v.z = cos(l);
glNormal3dv(&v.x);
glVertex3dv(&v.x);
glEnd();
@ -191,16 +175,9 @@ static void PutPolarPoint(float latitude, float longitude) {
glVertex3dv(&v.x);
}
void DrawBlob(float latitude, float longitude, float a, float b, const float col[4]) {
float mambient[4];
void DrawBlob(float latitude, float longitude, float a, float b) {
glPushAttrib(GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
mambient[0] = col[0]*.1;
mambient[1] = col[1]*.1;
mambient[2] = col[2]*.1;
mambient[3] = col[3];
glMaterialfv(GL_FRONT, GL_AMBIENT, mambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, col);
glEnable(GL_NORMALIZE);
glEnable(GL_BLEND);
@ -226,14 +203,17 @@ void DrawBlob(float latitude, float longitude, float a, float b, const float co
static void DrawRing(double inner, double outer, const float color[4]) {
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glDisable(GL_CULL_FACE);
glColor4fv(color);
glBegin(GL_TRIANGLE_STRIP);
glNormal3f(0, 1, 0);
for(float ang = 0; ang < 2*M_PI; ang+=0.1) {
glVertex3f(inner*sin(ang), 0, inner*cos(ang));
glVertex3f(outer*sin(ang), 0, outer*cos(ang));
@ -269,30 +249,24 @@ static void SphereTriSubdivide(vector3d& v1, vector3d &v2, vector3d& v3, int dep
}
}
/*
/*
* yPos should be 1.0 for north pole, -1.0 for south pole.
* size in radians.
*/
static void DrawPole(double yPos, double size, const float col[4]) {
float mambient[4];
static void DrawPole(double yPos, double size) {
glPushAttrib(GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
mambient[0] = col[0]*.1;
mambient[1] = col[1]*.1;
mambient[2] = col[2]*.1;
mambient[3] = col[3];
glMaterialfv(GL_FRONT, GL_AMBIENT, mambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, col);
glEnable(GL_NORMALIZE);
glEnable(GL_BLEND);
const bool southPole = yPos < 0;
size = size*4/M_PI;
vector3d center(0, yPos, 0);
glBegin(GL_TRIANGLES);
for(float ang = 2*M_PI; ang > 0; ang -= 0.1) {
vector3d v1(sin(ang), yPos, cos(ang));
vector3d v2(sin(ang+0.1), yPos, cos(ang+0.1));
vector3d v1(size*sin(ang), yPos, size*cos(ang));
vector3d v2(size*sin(ang+0.1), yPos, size*cos(ang+0.1));
v1.Normalize();
v2.Normalize();
if(southPole)
@ -307,6 +281,148 @@ static void DrawPole(double yPos, double size, const float col[4]) {
glPopAttrib();
}
struct ColRangeObj_t {
float baseCol[4]; float modCol[4]; float modAll;
void GenCol(float col[4], MTRand& rng) const {
float ma = 1 + (rng(modAll*2)-modAll);
for(int i = 0; i < 4; i++) col[i] = baseCol[i] + rng.drange(-modCol[i], modCol[i]);
for(int i = 0; i < 3; i++) col[i] = CLAMP(ma*col[i], 0, 1);
}
};
struct GasGiantDef_t {
int hoopMin, hoopMax; float hoopWobble;
int blobMin, blobMax;
float poleMin, poleMax; /* Size range in radians. Zero for no poles. */
float ringProbability;
ColRangeObj_t ringCol;
ColRangeObj_t bodyCol;
ColRangeObj_t hoopCol;
ColRangeObj_t blobCol;
ColRangeObj_t poleCol;
};
static GasGiantDef_t ggdefs[] = {
{
/* Jupiter */
30, 40, 0.05,
20, 30,
0, 0,
0.5,
{ { .61,.48,.384,.1 }, { 0, 0, 0, .9 }, 0.3 },
{ { .99,.76,.62,1 }, { 0, .1, .1, 0 }, 0.3 },
{ { .99,.76,.62,.5 }, { 0, .1, .1, 0 }, 0.3 },
{ { .99,.76,.62,1 }, { 0, .1, .1, 0 }, 0.7 },
},
{
/* Saturnish */
10, 15, 0.0,
8, 20, /* Blob range */
0.2, 0.2, /* Pole size */
0.5,
{ { .61,.48,.384,.1 }, { 0, 0, 0, .9 }, 0.3 },
{ { .87, .68, .39, 1 }, { 0, 0, 0, 0 }, 0.1 },
{ { .87, .68, .39, 1 }, { 0, 0, 0, 0 }, 0.1 },
{ { .87, .68, .39, 1 }, { 0, 0, 0, 0 }, 0.1 },
{ { .77, .58, .29, 1 }, { 0, 0, 0, 0 }, 0.1 },
},
{
/* Neptunish */
3, 6, 0.0,
2, 6,
0, 0,
0.5,
{ { .61,.48,.384,.1 }, { 0, 0, 0, .9 }, 0.3 },
{ { .31,.44,.73,1 }, { 0, 0, 0, 0 }, .05 }, /* Body col */
{ { .31,.44,.73,0.5 }, { 0, 0, 0, 0 }, .1 }, /* Hoop col */
{ { .21,.34,.54,1 }, { 0, 0, 0, 0 }, .05 }, /* Blob col */
},
{
/* Uranus-like *wink* */
0, 0, 0.0,
0, 0,
0, 0,
0.5,
{ { .61,.48,.384,.1 }, { 0, 0, 0, .9 }, 0.3 },
{ { .70,.85,.86,1 }, { .1, .1, .1, 0 }, 0 },
{ { .70,.85,.86,1 }, { .1, .1, .1, 0 }, 0 },
{ { .70,.85,.86,1 }, { .1, .1, .1, 0 }, 0 },
{ { .70,.85,.86,1 }, { .1, .1, .1, 0 }, 0 }
},
{
/* Brown dwarf-like */
0, 0, 0.05,
10, 20,
0, 0,
0.5,
{ { .81,.48,.384,.1 }, { 0, 0, 0, .9 }, 0.3 },
{ { .4,.1,0,1 }, { 0, 0, 0, 0 }, 0.1 },
{ { .4,.1,0,1 }, { 0, 0, 0, 0 }, 0.1 },
{ { .4,.1,0,1 }, { 0, 0, 0, 0 }, 0.1 },
},
};
static GasGiantDef_t &ggdef = ggdefs[0];
#define PLANET_AMBIENT 0.1
static void SetMaterialColor(const float col[4]) {
float mambient[4];
mambient[0] = col[0]*PLANET_AMBIENT;
mambient[1] = col[1]*PLANET_AMBIENT;
mambient[2] = col[2]*PLANET_AMBIENT;
mambient[3] = col[3];
glMaterialfv(GL_FRONT, GL_AMBIENT, mambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, col);
}
static void DrawGasGiant(void) {
MTRand rng((int)L3D::GetGameTime());
float col[4];
ggdef.bodyCol.GenCol(col, rng);
SetMaterialColor(col);
DrawLovelyRoundCube(1.0f);
int n = rng(ggdef.hoopMin, ggdef.hoopMax);
while(n-- > 0) {
ggdef.hoopCol.GenCol(col, rng);
SetMaterialColor(col);
DrawHoop(rng(0,9*M_PI)-0.45*M_PI, rng(0.25), ggdef.hoopWobble, rng);
}
n = rng(ggdef.blobMin, ggdef.blobMax);
while(n-- > 0) {
float a = rng.drange(0.01, 0.03);
float b = a+rng(0.2)+0.1;
ggdef.blobCol.GenCol(col, rng);
SetMaterialColor(col);
DrawBlob(rng.drange(-0.3*M_PI, 0.3*M_PI), rng(2*M_PI), a, b);
}
if(ggdef.poleMin != 0) {
float size = rng.drange(ggdef.poleMin, ggdef.poleMax);
ggdef.poleCol.GenCol(col, rng);
SetMaterialColor(col);
DrawPole(1.0, size);
DrawPole(-1.0, size);
}
if(rng(1.0) < ggdef.ringProbability) {
float pos = rng.drange(1.2, 1.7);
float end = pos + rng.drange(0.1, 1.0);
end = MIN(end, 2.5);
while(pos < end) {
float size = rng(0.1);
ggdef.ringCol.GenCol(col, rng);
DrawRing(pos, pos+size, col);
pos += size;
}
}
}
void Planet::Render(const Frame* a_camFrame) {
glPushMatrix();
@ -334,29 +450,7 @@ void Planet::Render(const Frame* a_camFrame) {
glEnable(GL_LIGHTING);
} else {
glScalef(rad, rad, rad);
DrawLovelyRoundCube(1.0f);
const float col1[] = { 1, 1, 0, .7 };
const float col2[] = { 1, .2, 0, .7 };
const float col3[] = { .3, 1, 0, .7 };
const float col4[] = { 1, .6, 0, .7 };
const float col5[] = { 0, 0, 0.8, .7 };
const float white[] = { 1, 1, 1, 1 };
DrawHoop(M_PI/10.0, M_PI/20.0, col1);
DrawHoop(M_PI/12.0, M_PI/20.0, col2);
DrawHoop(0, M_PI/20.0, col2);
DrawHoop(-M_PI/10.0, M_PI/20.0, col3);
DrawHoop(M_PI/2 - M_PI/10.0, M_PI/20.0, col4);
DrawBlob(.2, -0.3, 0.05, 0.2, col5);
DrawBlob(.3, M_PI/2, 0.05, 0.2, col5);
DrawBlob(-.1, -M_PI/2, 0.05, 0.2, col5);
DrawPole(1.0, 0.1, white);
DrawPole(-1.0, 0.1, white);
DrawRing(1.5, 1.8, col1);
DrawRing(1.5, 1.8, col1);
DrawRing(1.9, 2.0, col1);
DrawRing(2.04, 2.3, col1);
//DrawBlob(1.0, 0, 0.02, 0.5, col5);
//DrawBlob(-1.0, 0, 0.02, 05, col5);
DrawGasGiant();
glClear(GL_DEPTH_BUFFER_BIT);
}
glPopMatrix();