From 7f1774054ab9ae24f756bec3637eb0446ef1013c Mon Sep 17 00:00:00 2001 From: Chris Laurel Date: Fri, 16 Mar 2001 21:26:29 +0000 Subject: [PATCH] Added user settable BumpHeight parameter for bump maps. --- src/render.cpp | 3 ++- src/solarsys.cpp | 32 ++++++++++++++++++++++++++++++++ src/surface.h | 1 + src/texmanager.cpp | 4 ++-- src/texmanager.h | 2 +- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/render.cpp b/src/render.cpp index b110819c..86cb766c 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -874,7 +874,8 @@ void Renderer::renderPlanet(const Body& body, surface.bumpTexture != "") { if (!textureManager->find(surface.bumpTexture, &bumpTex)) - bumpTex = textureManager->loadBumpMap(surface.bumpTexture); + bumpTex = textureManager->loadBumpMap(surface.bumpTexture, + surface.bumpHeight); } if (tex == NULL) diff --git a/src/solarsys.cpp b/src/solarsys.cpp index a61e1899..cd194bc3 100644 --- a/src/solarsys.cpp +++ b/src/solarsys.cpp @@ -52,6 +52,33 @@ Planet SolSystem[] = }; +static Surface* CreateSurface(Hash* surfaceData) +{ + Surface* surface = new Surface(); + + surface->color = Color(1.0f, 1.0f, 1.0f); + surfaceData->getColor("Color", surface->color); + bool applyBaseTexture = surfaceData->getString("Texture", surface->baseTexture); + bool applyBumpMap = surfaceData->getString("BumpMap", surface->bumpTexture); + surface->bumpHeight = 2.5f; + surfaceData->getNumber("BumpHeight", surface->bumpHeight); + bool blendTexture = false; + surfaceData->getBoolean("BlendTexture", blendTexture); + bool compressTexture = false; + surfaceData->getBoolean("CompressTexture", compressTexture); + if (blendTexture) + surface->appearanceFlags |= Surface::BlendTexture; + if (applyBaseTexture) + surface->appearanceFlags |= Surface::ApplyBaseTexture; + if (applyBumpMap) + surface->appearanceFlags |= Surface::ApplyBumpMap; + if (compressTexture) + surface->appearanceFlags |= Surface::CompressBaseTexture; + + return surface; +} + + static Body* createSatellite(Planet* p) { EllipticalOrbit* orbit = new EllipticalOrbit(astro::AUtoKilometers(p->semiMajorAxis), @@ -167,6 +194,7 @@ static Body* CreatePlanet(PlanetarySystem* system, planetData->getNumber("RotationPeriod", rotationPeriod); body->setRotationPeriod(rotationPeriod); +#if 0 Surface surface; surface.color = Color(1.0f, 1.0f, 1.0f); planetData->getColor("Color", surface.color); @@ -185,6 +213,10 @@ static Body* CreatePlanet(PlanetarySystem* system, if (compressTexture) surface.appearanceFlags |= Surface::CompressBaseTexture; body->setSurface(surface); +#endif + Surface* surface = CreateSurface(planetData); + body->setSurface(*surface); + delete surface; string mesh(""); planetData->getString("Mesh", mesh); diff --git a/src/surface.h b/src/surface.h index 8fa6b059..100a0e3b 100644 --- a/src/surface.h +++ b/src/surface.h @@ -33,6 +33,7 @@ class Surface std::string baseTexture; std::string bumpTexture; uint32 appearanceFlags; + float bumpHeight; }; #endif // _SURFACE_H_ diff --git a/src/texmanager.cpp b/src/texmanager.cpp index ce0c6bf9..63f38e3b 100644 --- a/src/texmanager.cpp +++ b/src/texmanager.cpp @@ -43,13 +43,13 @@ CTexture* TextureManager::load(const string& name, bool compress) } -CTexture* TextureManager::loadBumpMap(const string& name) +CTexture* TextureManager::loadBumpMap(const string& name, float bumpHeight) { DPRINTF("Loading bump map: %s\n", name.c_str()); CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name); if (tex != NULL) { - tex->normalMap(2.5f, true); + tex->normalMap(bumpHeight, true); tex->bindName(CTexture::WrapTexture); } addResource(name, static_cast(tex)); diff --git a/src/texmanager.h b/src/texmanager.h index ada4fca7..2d1ab3ce 100644 --- a/src/texmanager.h +++ b/src/texmanager.h @@ -26,7 +26,7 @@ class TextureManager : public ResourceManager bool find(const std::string& name, CTexture**); CTexture* load(const std::string& name, bool compress = false); - CTexture* loadBumpMap(const std::string& name); + CTexture* loadBumpMap(const std::string& name, float bumpHeight); }; #endif // _TEXMANAGER_H_