Browse Source

Revise shader-material system

master
C. J. Howard 6 years ago
parent
commit
014e6070b8
24 changed files with 970 additions and 1226 deletions
  1. +1
    -1
      data
  2. +1
    -1
      lib/emergent
  3. +87
    -112
      src/application.cpp
  4. +32
    -34
      src/application.hpp
  5. +1
    -1
      src/configuration.hpp.in
  6. +2
    -2
      src/debug.cpp
  7. +1
    -2
      src/debug.hpp
  8. +6
    -8
      src/game/biome.cpp
  9. +6
    -6
      src/game/biome.hpp
  10. +4
    -4
      src/game/terrain.cpp
  11. +2
    -3
      src/game/terrain.hpp
  12. +320
    -57
      src/material-loader.cpp
  13. +25
    -5
      src/material-loader.hpp
  14. +0
    -89
      src/materials.hpp
  15. +339
    -770
      src/render-passes.cpp
  16. +93
    -85
      src/render-passes.hpp
  17. +1
    -0
      src/states/game-state.cpp
  18. +0
    -17
      src/states/title-state.cpp
  19. +1
    -1
      src/ui/pie-menu.cpp
  20. +1
    -1
      src/ui/pie-menu.hpp
  21. +6
    -6
      src/ui/toolbar.cpp
  22. +11
    -11
      src/ui/toolbar.hpp
  23. +14
    -3
      src/ui/ui.cpp
  24. +16
    -7
      src/ui/ui.hpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit bf5d69d87ef22cf3660e8d59d4c338995411e51d
Subproject commit 41b7c54fb2819da830a47d0e5a5756eed5a0310d

+ 1
- 1
lib/emergent

@ -1 +1 @@
Subproject commit a452354a06253cc1f6b79e5646c6fd7c704448b4
Subproject commit ce417f4eafa15035b3a7613363e23157b8e59900

+ 87
- 112
src/application.cpp View File

@ -120,13 +120,17 @@ Application::Application(int argc, char* argv[]):
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, OPENGL_VERSION_MAJOR);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, OPENGL_VERSION_MINOR);
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
// Set OpenGL buffer attributes
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
// Get all possible display modes for the default display
int displayModeCount = SDL_GetNumDisplayModes(0);
@ -701,7 +705,7 @@ void Application::saveUserSettings()
bool Application::loadModels()
{
antModel = modelLoader->load("data/models/debug-worker.mdl");
antModel = modelLoader->load("data/models/common-worker-ant.mdl");
antHillModel = modelLoader->load("data/models/ant-hill.mdl");
nestModel = modelLoader->load("data/models/nest.mdl");
forcepsModel = modelLoader->load("data/models/forceps.mdl");
@ -742,29 +746,9 @@ bool Application::loadModels()
bool Application::loadScene()
{
// Create scene layers
backgroundLayer = scene.addLayer();
defaultLayer = scene.addLayer();
uiLayer = scene.addLayer();
// BG
bgBatch.resize(1);
BillboardBatch::Range* bgRange = bgBatch.addRange();
bgRange->start = 0;
bgRange->length = 1;
Billboard* bgBillboard = bgBatch.getBillboard(0);
bgBillboard->setDimensions(Vector2(1.0f, 1.0f));
bgBillboard->setTranslation(Vector3(0.5f, 0.5f, 0.0f));
bgBillboard->setTintColor(Vector4(1, 1, 1, 1));
bgBatch.update();
vignettePass.setRenderTarget(&defaultRenderTarget);
//bgCompositor.addPass(&vignettePass);
bgCompositor.load(nullptr);
bgCamera.setOrthographic(0, 1.0f, 1.0f, 0, -1.0f, 1.0f);
bgCamera.lookAt(glm::vec3(0), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0));
bgCamera.setCompositor(&bgCompositor);
bgCamera.setCompositeIndex(0);
// Set shadow map resolution
shadowMapResolution = 4096;
@ -773,9 +757,9 @@ bool Application::loadScene()
glBindFramebuffer(GL_FRAMEBUFFER, shadowMapFramebuffer);
// Generate shadow map depth texture
glGenTextures(1, &shadowMapDepthTexture);
glBindTexture(GL_TEXTURE_2D, shadowMapDepthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, shadowMapResolution, shadowMapResolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
glGenTextures(1, &shadowMapDepthTextureID);
glBindTexture(GL_TEXTURE_2D, shadowMapDepthTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, shadowMapResolution, shadowMapResolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@ -784,7 +768,7 @@ bool Application::loadScene()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
// Attach depth texture to framebuffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowMapDepthTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowMapDepthTextureID, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
@ -797,6 +781,11 @@ bool Application::loadScene()
shadowMapRenderTarget.height = shadowMapResolution;
shadowMapRenderTarget.framebuffer = shadowMapFramebuffer;
// Setup texture class
shadowMapDepthTexture.setTextureID(shadowMapDepthTextureID);
shadowMapDepthTexture.setWidth(shadowMapResolution);
shadowMapDepthTexture.setHeight(shadowMapResolution);
// Setup shadow map render pass
shadowMapPass.setRenderTarget(&shadowMapRenderTarget);
shadowMapPass.setViewCamera(&camera);
@ -809,8 +798,8 @@ bool Application::loadScene()
// Post-processing framebuffers
{
// Generate color texture
glGenTextures(1, &framebufferAColorTexture);
glBindTexture(GL_TEXTURE_2D, framebufferAColorTexture);
glGenTextures(1, &framebufferAColorTextureID);
glBindTexture(GL_TEXTURE_2D, framebufferAColorTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, static_cast<GLsizei>(resolution.x), static_cast<GLsizei>(resolution.y), 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -818,8 +807,8 @@ bool Application::loadScene()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Generate depth texture
glGenTextures(1, &framebufferADepthTexture);
glBindTexture(GL_TEXTURE_2D, framebufferADepthTexture);
glGenTextures(1, &framebufferADepthTextureID);
glBindTexture(GL_TEXTURE_2D, framebufferADepthTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, static_cast<GLsizei>(resolution.x), static_cast<GLsizei>(resolution.y), 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -833,8 +822,8 @@ bool Application::loadScene()
glBindFramebuffer(GL_FRAMEBUFFER, framebufferA);
// Attach textures to framebuffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebufferAColorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, framebufferADepthTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebufferAColorTextureID, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, framebufferADepthTextureID, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
//glReadBuffer(GL_COLOR_ATTACHMENT0);
@ -846,12 +835,17 @@ bool Application::loadScene()
framebufferARenderTarget.width = static_cast<int>(resolution.x);
framebufferARenderTarget.height = static_cast<int>(resolution.y);
framebufferARenderTarget.framebuffer = framebufferA;
// Setup texture class
framebufferAColorTexture.setTextureID(framebufferAColorTextureID);
framebufferAColorTexture.setWidth(static_cast<int>(resolution.x));
framebufferAColorTexture.setHeight(static_cast<int>(resolution.y));
}
{
// Generate color texture
glGenTextures(1, &framebufferBColorTexture);
glBindTexture(GL_TEXTURE_2D, framebufferBColorTexture);
glGenTextures(1, &framebufferBColorTextureID);
glBindTexture(GL_TEXTURE_2D, framebufferBColorTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, static_cast<GLsizei>(resolution.x), static_cast<GLsizei>(resolution.y), 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -859,11 +853,11 @@ bool Application::loadScene()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Generate framebuffer
glGenFramebuffers(1, &framebufferA);
glBindFramebuffer(GL_FRAMEBUFFER, framebufferA);
glGenFramebuffers(1, &framebufferB);
glBindFramebuffer(GL_FRAMEBUFFER, framebufferB);
// Attach textures to framebuffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebufferBColorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebufferBColorTextureID, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
//glReadBuffer(GL_COLOR_ATTACHMENT0);
@ -874,7 +868,12 @@ bool Application::loadScene()
// Setup render target
framebufferBRenderTarget.width = static_cast<int>(resolution.x);
framebufferBRenderTarget.height = static_cast<int>(resolution.y);
framebufferBRenderTarget.framebuffer = framebufferA;
framebufferBRenderTarget.framebuffer = framebufferB;
// Setup texture class
framebufferBColorTexture.setTextureID(framebufferBColorTextureID);
framebufferBColorTexture.setWidth(static_cast<int>(resolution.x));
framebufferBColorTexture.setHeight(static_cast<int>(resolution.y));
}
// Pheromone PBO
@ -887,12 +886,13 @@ bool Application::loadScene()
glGenTextures(1, &pheromoneTextureID);
glBindTexture(GL_TEXTURE_2D, pheromoneTextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, PHEROMONE_MATRIX_COLUMNS, PHEROMONE_MATRIX_ROWS, 0, GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glBindTexture(GL_TEXTURE_2D, 0);
// Setup texture class
pheromoneTexture.setWidth(PHEROMONE_MATRIX_COLUMNS);
pheromoneTexture.setHeight(PHEROMONE_MATRIX_ROWS);
pheromoneTexture.setTextureID(pheromoneTextureID);
@ -902,32 +902,36 @@ bool Application::loadScene()
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
// Setup skybox pass
skyboxPass.setRenderTarget(&framebufferARenderTarget);
//skyboxPass.setRenderTarget(&framebufferARenderTarget);
skyboxPass.setRenderTarget(&defaultRenderTarget);
// Setup clear depth pass
clearDepthPass.setRenderTarget(&framebufferARenderTarget);
//clearDepthPass.setRenderTarget(&framebufferARenderTarget);
clearDepthPass.setRenderTarget(&defaultRenderTarget);
clearDepthPass.setClear(false, true, false);
clearDepthPass.setClearDepth(1.0f);
// Setup lighting pass
lightingPass.setRenderTarget(&framebufferARenderTarget);
lightingPass.setShadowMap(shadowMapDepthTexture);
//lightingPass.setRenderTarget(&framebufferARenderTarget);
lightingPass.setRenderTarget(&defaultRenderTarget);
lightingPass.setShadowMap(&shadowMapDepthTexture);
lightingPass.setShadowCamera(&sunlightCamera);
lightingPass.setShadowMapPass(&shadowMapPass);
// Setup blur passes
horizontalBlurPass.setRenderTarget(&framebufferBRenderTarget);
horizontalBlurPass.setTexture(framebufferAColorTexture);
horizontalBlurPass.setTexture(&framebufferAColorTexture);
horizontalBlurPass.setDirection(Vector2(0.0f, 0.0f));
verticalBlurPass.setRenderTarget(&framebufferARenderTarget);
verticalBlurPass.setTexture(framebufferBColorTexture);
verticalBlurPass.setTexture(&framebufferBColorTexture);
verticalBlurPass.setDirection(Vector2(0.0f, 0.0f));
horizontalBlurPass2.setRenderTarget(&framebufferBRenderTarget);
horizontalBlurPass2.setTexture(framebufferAColorTexture);
horizontalBlurPass2.setTexture(&framebufferAColorTexture);
horizontalBlurPass2.setDirection(Vector2(0.0f, 0.0f));
verticalBlurPass2.setRenderTarget(&defaultRenderTarget);
verticalBlurPass2.setTexture(framebufferBColorTexture);
verticalBlurPass2.setTexture(&framebufferBColorTexture);
verticalBlurPass2.setDirection(Vector2(0.0f, 0.0f));
verticalBlurPass2.setGammaCorrect(true);
// Setup debug pass
@ -936,10 +940,10 @@ bool Application::loadScene()
defaultCompositor.addPass(&clearDepthPass);
defaultCompositor.addPass(&skyboxPass);
defaultCompositor.addPass(&lightingPass);
defaultCompositor.addPass(&horizontalBlurPass);
defaultCompositor.addPass(&verticalBlurPass);
defaultCompositor.addPass(&horizontalBlurPass2);
defaultCompositor.addPass(&verticalBlurPass2);
//defaultCompositor.addPass(&horizontalBlurPass);
//defaultCompositor.addPass(&verticalBlurPass);
//defaultCompositor.addPass(&horizontalBlurPass2);
//defaultCompositor.addPass(&verticalBlurPass2);
//defaultCompositor.addPass(&debugPass);
defaultCompositor.load(nullptr);
@ -994,39 +998,33 @@ bool Application::loadUI()
// Load UI textures
textureLoader->setGamma(1.0f);
textureLoader->setCubemap(false);
textureLoader->setMipmapChain(false);
textureLoader->setMaxAnisotropy(1.0f);
textureLoader->setWrapS(false);
textureLoader->setWrapT(false);
splashTexture = textureLoader->load("data/textures/ui-splash.png");
titleTexture = textureLoader->load("data/textures/ui-title.png");
rectangularPaletteTexture = textureLoader->load("data/textures/rectangular-palette.png");
foodIndicatorTexture = textureLoader->load("data/textures/food-indicator.png");
toolBrushTexture = textureLoader->load("data/textures/tool-brush.png");
toolLensTexture = textureLoader->load("data/textures/tool-lens.png");
toolForcepsTexture = textureLoader->load("data/textures/tool-forceps.png");
toolTrowelTexture = textureLoader->load("data/textures/tool-trowel.png");
toolbarTopTexture = textureLoader->load("data/textures/toolbar-top.png");
toolbarBottomTexture = textureLoader->load("data/textures/toolbar-bottom.png");
toolbarMiddleTexture = textureLoader->load("data/textures/toolbar-middle.png");
toolbarButtonRaisedTexture = textureLoader->load("data/textures/toolbar-button-raised.png");
toolbarButtonDepressedTexture = textureLoader->load("data/textures/toolbar-button-depressed.png");
arcNorthTexture = textureLoader->load("data/textures/pie-menu-arc-north.png");
arcEastTexture = textureLoader->load("data/textures/pie-menu-arc-east.png");
arcSouthTexture = textureLoader->load("data/textures/pie-menu-arc-south.png");
arcWestTexture = textureLoader->load("data/textures/pie-menu-arc-west.png");
mouseLeftTexture = textureLoader->load("data/textures/mouse-left.png");
mouseRightTexture = textureLoader->load("data/textures/mouse-right.png");
depthTexture = new Texture();
depthTexture->setTextureID(shadowMapDepthTexture);
depthTexture->setWidth(shadowMapResolution);
depthTexture->setHeight(shadowMapResolution);
splashTexture = textureLoader->load2D("data/textures/ui-splash.png");
titleTexture = textureLoader->load2D("data/textures/ui-title.png");
rectangularPaletteTexture = textureLoader->load2D("data/textures/rectangular-palette.png");
foodIndicatorTexture = textureLoader->load2D("data/textures/food-indicator.png");
toolBrushTexture = textureLoader->load2D("data/textures/tool-brush.png");
toolLensTexture = textureLoader->load2D("data/textures/tool-lens.png");
toolForcepsTexture = textureLoader->load2D("data/textures/tool-forceps.png");
toolTrowelTexture = textureLoader->load2D("data/textures/tool-trowel.png");
toolbarTopTexture = textureLoader->load2D("data/textures/toolbar-top.png");
toolbarBottomTexture = textureLoader->load2D("data/textures/toolbar-bottom.png");
toolbarMiddleTexture = textureLoader->load2D("data/textures/toolbar-middle.png");
toolbarButtonRaisedTexture = textureLoader->load2D("data/textures/toolbar-button-raised.png");
toolbarButtonDepressedTexture = textureLoader->load2D("data/textures/toolbar-button-depressed.png");
arcNorthTexture = textureLoader->load2D("data/textures/pie-menu-arc-north.png");
arcEastTexture = textureLoader->load2D("data/textures/pie-menu-arc-east.png");
arcSouthTexture = textureLoader->load2D("data/textures/pie-menu-arc-south.png");
arcWestTexture = textureLoader->load2D("data/textures/pie-menu-arc-west.png");
mouseLeftTexture = textureLoader->load2D("data/textures/mouse-left.png");
mouseRightTexture = textureLoader->load2D("data/textures/mouse-right.png");
// Set colors
selectedColor = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
@ -1114,9 +1112,9 @@ bool Application::loadUI()
//uiRootElement->addChild(foodIndicatorImage);
depthTextureImage = new UIImage();
depthTextureImage->setTexture(depthTexture);
depthTextureImage->setTexture(&shadowMapDepthTexture);
depthTextureImage->setVisible(false);
uiRootElement->addChild(depthTextureImage);
//uiRootElement->addChild(depthTextureImage);
// Create level name label
levelNameLabel = new UILabel();
@ -2071,40 +2069,17 @@ void Application::loadLevel(std::size_t index)
const LevelParameterSet* levelParams = campaign.getLevelParams(currentWorldIndex, currentLevelIndex);
currentLevel->load(*levelParams);
PhysicalMaterial* material = materialLoader->load("data/materials/debug-terrain-surface.mtl");
material->albedoOpacityMap = &pheromoneTexture;
material->shadowCaster = false;
material->flags |= (unsigned int)PhysicalMaterial::Flags::TRANSLUCENT;
currentLevel->terrain.getSurfaceModel()->getGroup(0)->material = material;
}
/*
void Application::loadLevel()
{
if (currentLevel < 1 || currentLevel >= campaign.levels[currentWorld].size())
Material* material = materialLoader->load("data/materials/debug-terrain-surface.mtl");
ShaderTexture2D* albedoOpacityMap = static_cast<ShaderTexture2D*>(material->getVariable("albedoOpacityMap"));
if (albedoOpacityMap != nullptr)
{
std::cout << "Attempted to load invalid level" << std::endl;
return;
albedoOpacityMap->setValue(&pheromoneTexture);
}
//material->shadowCaster = false;
//material->flags |= (unsigned int)PhysicalMaterial::Flags::TRANSLUCENT;
const LevelParameterSet* levelParams = campaign.getLevelParams(currentWorld, currentLevel);
const Biome* biome = &biosphere.biomes[levelParams->biome];
soilPass.setHorizonOTexture(biome->soilHorizonO);
soilPass.setHorizonATexture(biome->soilHorizonA);
soilPass.setHorizonBTexture(biome->soilHorizonB);
soilPass.setHorizonCTexture(biome->soilHorizonC);
std::string heightmap = std::string("data/textures/") + level->heightmap;
currentLevelTerrain->load(heightmap);
// Set skybox
skyboxPass.setCubemap(biome->specularCubemap);
//changeState(playState);
currentLevel->terrain.getSurfaceModel()->getGroup(0)->material = material;
}
*/
void Application::pauseSimulation()
{

+ 32
- 34
src/application.hpp View File

@ -154,13 +154,11 @@ public:
// Scene
Scene scene;
SceneLayer* backgroundLayer;
SceneLayer* defaultLayer;
SceneLayer* uiLayer;
Camera camera;
Camera sunlightCamera;
Camera uiCamera;
Camera bgCamera;
DirectionalLight sunlight;
ModelInstance forcepsModelInstance;
ModelInstance navigatorObject;
@ -179,25 +177,28 @@ public:
RenderTarget defaultRenderTarget;
int shadowMapResolution;
GLuint shadowMapDepthTexture;
GLuint shadowMapDepthTextureID;
GLuint shadowMapFramebuffer;
RenderTarget shadowMapRenderTarget;
ShadowMapRenderPass shadowMapPass;
Compositor shadowMapCompositor;
Texture2D shadowMapDepthTexture;
GLuint framebufferAColorTexture;
GLuint framebufferADepthTexture;
GLuint framebufferAColorTextureID;
GLuint framebufferADepthTextureID;
GLuint framebufferA;
RenderTarget framebufferARenderTarget;
Texture2D framebufferAColorTexture;
GLuint framebufferBColorTexture;
GLuint framebufferBDepthTexture;
GLuint framebufferBColorTextureID;
GLuint framebufferBDepthTextureID;
GLuint framebufferB;
RenderTarget framebufferBRenderTarget;
Texture2D framebufferBColorTexture;
GLuint pheromonePBO;
GLuint pheromoneTextureID;
Texture pheromoneTexture;
Texture2D pheromoneTexture;
ClearRenderPass clearDepthPass;
LightingRenderPass lightingPass;
@ -207,9 +208,6 @@ public:
UIBatcher* uiBatcher;
UIRenderPass uiPass;
Compositor uiCompositor;
BillboardBatch bgBatch;
Compositor bgCompositor;
VignetteRenderPass vignettePass;
SkyboxRenderPass skyboxPass;
TextureLoader* textureLoader;
MaterialLoader* materialLoader;
@ -270,29 +268,29 @@ public:
Font* levelNameFont;
// UI textures
Texture* splashTexture;
Texture* titleTexture;
Texture* rectangularPaletteTexture;
Texture* foodIndicatorTexture;
Texture* toolBrushTexture;
Texture* toolLensTexture;
Texture* toolForcepsTexture;
Texture* toolTrowelTexture;
Texture* toolbarTopTexture;
Texture* toolbarBottomTexture;
Texture* toolbarMiddleTexture;
Texture* toolbarButtonRaisedTexture;
Texture* toolbarButtonDepressedTexture;
Texture* arcNorthTexture;
Texture* arcEastTexture;
Texture* arcSouthTexture;
Texture* arcWestTexture;
Texture* mouseLeftTexture;
Texture* mouseRightTexture;
Texture* depthTexture;
Texture2D* splashTexture;
Texture2D* titleTexture;
Texture2D* rectangularPaletteTexture;
Texture2D* foodIndicatorTexture;
Texture2D* toolBrushTexture;
Texture2D* toolLensTexture;
Texture2D* toolForcepsTexture;
Texture2D* toolTrowelTexture;
Texture2D* toolbarTopTexture;
Texture2D* toolbarBottomTexture;
Texture2D* toolbarMiddleTexture;
Texture2D* toolbarButtonRaisedTexture;
Texture2D* toolbarButtonDepressedTexture;
Texture2D* arcNorthTexture;
Texture2D* arcEastTexture;
Texture2D* arcSouthTexture;
Texture2D* arcWestTexture;
Texture2D* mouseLeftTexture;
Texture2D* mouseRightTexture;
Texture2D* depthTexture;
// UI elements
Vector4 selectedColor;

+ 1
- 1
src/configuration.hpp.in View File

@ -46,7 +46,7 @@ const float WORLD_WIDTH = 100.0f; // cm
const float WORLD_HEIGHT = 100.0f; // cm
const float FRAMES_PER_SECOND = 60.0f;
const float TIMESTEP = 1.0f / FRAMES_PER_SECOND;
const float PHEROMONE_MATRIX_RESOLUTION = 4.0f;
const float PHEROMONE_MATRIX_RESOLUTION = 5.12f;
const int PHEROMONE_MATRIX_COLUMNS = (int)(WORLD_WIDTH * PHEROMONE_MATRIX_RESOLUTION);
const int PHEROMONE_MATRIX_ROWS = (int)(WORLD_HEIGHT * PHEROMONE_MATRIX_RESOLUTION);
const Vector2 WORLD_BOUNDS_MIN = Vector2(-WORLD_WIDTH * 0.5f, -WORLD_HEIGHT * 0.5f);

+ 2
- 2
src/debug.cpp View File

@ -28,9 +28,9 @@ LineBatcher::LineBatcher(std::size_t lineCount):
{
batch.resize(lineCount);
range = batch.addRange();
range->material = &material;
range->material = nullptr;//&material;
material.albedo = Vector3(1.0f);
//material.albedo = Vector3(1.0f);
}
void LineBatcher::begin()

+ 1
- 2
src/debug.hpp View File

@ -21,7 +21,6 @@
#define DEBUG_HPP
#include <emergent/emergent.hpp>
#include "materials.hpp"
using namespace Emergent;
@ -49,7 +48,7 @@ private:
BillboardBatch::Range* range;
float width;
Vector4 color;
PhysicalMaterial material;
//PhysicalMaterial material;
};
inline const BillboardBatch* LineBatcher::getBatch() const

+ 6
- 8
src/game/biome.cpp View File

@ -26,26 +26,24 @@ bool Biome::load()
parameters.get("cubemap", &cubemapName);
TextureLoader textureLoader;
textureLoader.setCubemap(false);
textureLoader.setMipmapChain(false);
textureLoader.setWrapS(true);
textureLoader.setWrapT(true);
// Load soil horizon textures
soilHorizonO = textureLoader.load(std::string("data/textures/") + soilHorizonOFilename);
soilHorizonA = textureLoader.load(std::string("data/textures/") + soilHorizonAFilename);
soilHorizonB = textureLoader.load(std::string("data/textures/") + soilHorizonBFilename);
soilHorizonC = textureLoader.load(std::string("data/textures/") + soilHorizonCFilename);
soilHorizonO = textureLoader.load2D(std::string("data/textures/") + soilHorizonOFilename);
soilHorizonA = textureLoader.load2D(std::string("data/textures/") + soilHorizonAFilename);
soilHorizonB = textureLoader.load2D(std::string("data/textures/") + soilHorizonBFilename);
soilHorizonC = textureLoader.load2D(std::string("data/textures/") + soilHorizonCFilename);
// Load diffuse cubemap
textureLoader.setCubemap(true);
textureLoader.setMipmapChain(true);
textureLoader.setWrapS(false);
textureLoader.setWrapT(false);
textureLoader.setWrapR(false);
std::string diffuseCubemapFilename = std::string("data/textures/") + cubemapName + std::string("-irradiance-m%02d.hdr");
diffuseCubemap = textureLoader.load(diffuseCubemapFilename);
diffuseCubemap = textureLoader.loadCube(diffuseCubemapFilename);
if (!diffuseCubemap)
{
std::cerr << "Failed to load diffuse cubemap \"" << diffuseCubemapFilename << "\"" << std::endl;
@ -53,7 +51,7 @@ bool Biome::load()
// Load specular cubemap
std::string specularCubemapFilename = std::string("data/textures/") + cubemapName + std::string("-radiance-m%02d.hdr");
specularCubemap = textureLoader.load(specularCubemapFilename);
specularCubemap = textureLoader.loadCube(specularCubemapFilename);
if (!specularCubemap)
{
std::cerr << "Failed to load specular cubemap \"" << specularCubemapFilename << "\"" << std::endl;

+ 6
- 6
src/game/biome.hpp View File

@ -23,12 +23,12 @@ public:
std::string soilHorizonCFilename;
std::string cubemapName;
Texture* soilHorizonO;
Texture* soilHorizonA;
Texture* soilHorizonB;
Texture* soilHorizonC;
Texture* diffuseCubemap;
Texture* specularCubemap;
Texture2D* soilHorizonO;
Texture2D* soilHorizonA;
Texture2D* soilHorizonB;
Texture2D* soilHorizonC;
TextureCube* diffuseCubemap;
TextureCube* specularCubemap;
};
class Biosphere

+ 4
- 4
src/game/terrain.cpp View File

@ -108,7 +108,7 @@ void Terrain::createSurface()
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(std::uint32_t) * surfaceIndexCount, surfaceIndexData, GL_STATIC_DRAW);
// Setup material
surfaceMaterial.flags = static_cast<unsigned int>(PhysicalMaterial::Flags::OBJECT);
//surfaceMaterial.flags = static_cast<unsigned int>(PhysicalMaterial::Flags::OBJECT);
// Setup buffers
surfaceModel.setVAO(surfaceVAO);
@ -118,7 +118,7 @@ void Terrain::createSurface()
// Create model group
Model::Group* group = new Model::Group();
group->name = "default";
group->material = &surfaceMaterial;
group->material = nullptr;//&surfaceMaterial;
group->indexOffset = 0;
group->triangleCount = surfaceTriangleCount;
@ -366,7 +366,7 @@ void Terrain::createSubsurface()
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(std::uint32_t) * subsurfaceIndexCount, subsurfaceIndexData, GL_STATIC_DRAW);
// Setup material
subsurfaceMaterial.flags = static_cast<unsigned int>(PhysicalMaterial::Flags::SOIL);
//subsurfaceMaterial.flags = static_cast<unsigned int>(PhysicalMaterial::Flags::SOIL);
// Setup buffers
subsurfaceModel.setVAO(subsurfaceVAO);
@ -376,7 +376,7 @@ void Terrain::createSubsurface()
// Create model group
Model::Group* group = new Model::Group();
group->name = "default";
group->material = &subsurfaceMaterial;
group->material = nullptr;//&subsurfaceMaterial;
group->indexOffset = 0;
group->triangleCount = subsurfaceTriangleCount;

+ 2
- 3
src/game/terrain.hpp View File

@ -21,7 +21,6 @@
#define TERRAIN_HPP
#include "navmesh.hpp"
#include "../materials.hpp"
#include <emergent/emergent.hpp>
using namespace Emergent;
@ -92,7 +91,7 @@ private:
GLuint surfaceVAO;
GLuint surfaceVBO;
GLuint surfaceIBO;
PhysicalMaterial surfaceMaterial;
//PhysicalMaterial surfaceMaterial;
Model surfaceModel;
Navmesh surfaceNavmesh;
Octree<Navmesh::Triangle*>* surfaceOctree;
@ -109,7 +108,7 @@ private:
GLuint subsurfaceVAO;
GLuint subsurfaceVBO;
GLuint subsurfaceIBO;
PhysicalMaterial subsurfaceMaterial;
//PhysicalMaterial subsurfaceMaterial;
Model subsurfaceModel;
Navmesh subsurfaceNavmesh;
};

+ 320
- 57
src/material-loader.cpp View File

@ -18,16 +18,17 @@
*/
#include "material-loader.hpp"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
MaterialLoader::MaterialLoader()
{
textureLoader.setGamma(1.0f);
textureLoader.setCubemap(false);
textureLoader.setMipmapChain(false);
textureLoader.setMaxAnisotropy(16.0f);
textureLoader.setMaxAnisotropy(1.0f);
}
MaterialLoader::~MaterialLoader()
@ -43,14 +44,20 @@ void MaterialLoader::unload()
}
materialCache.clear();
for (auto it = textureCache.begin(); it != textureCache.end(); ++it)
for (auto it = texture2DCache.begin(); it != texture2DCache.end(); ++it)
{
delete it->second;
}
textureCache.clear();
texture2DCache.clear();
for (auto it = textureCubeCache.begin(); it != textureCubeCache.end(); ++it)
{
delete it->second;
}
textureCubeCache.clear();
}
PhysicalMaterial* MaterialLoader::load(const std::string& filename)
Material* MaterialLoader::load(const std::string& filename)
{
// Check if material exists in cache
auto it = materialCache.find(filename);
@ -60,7 +67,7 @@ PhysicalMaterial* MaterialLoader::load(const std::string& filename)
}
// Allocate new material
PhysicalMaterial* material = new PhysicalMaterial();
Material* material = new Material();
// Open file
std::ifstream file(filename.c_str(), std::ifstream::in);
@ -83,83 +90,139 @@ PhysicalMaterial* MaterialLoader::load(const std::string& filename)
continue;
}
// Find position of first character in command string
std::size_t firstCommand = line.find_first_not_of(whitespace, 0);
if (firstCommand == std::string::npos)
// Find position of first character in variable name
std::size_t variableNamePosition = line.find_first_not_of(whitespace, 0);
if (variableNamePosition == std::string::npos)
{
// Skip whitespace-only lines
continue;
}
// Find position of first character in delimeter string
std::size_t firstDelimeter = line.find_first_of(whitespace, firstCommand);
if (firstDelimeter == std::string::npos)
// Find position of equals sign
std::size_t equalsSignPosition = line.find_first_of("=", variableNamePosition);
if (equalsSignPosition == std::string::npos)
{
// Skip lines with no equals sign
continue;
}
// Find position of first character in arguments string
std::size_t firstArgument = line.find_first_not_of(whitespace, firstDelimeter);
if (firstArgument == std::string::npos)
// Find position of first character in variable type
std::size_t variableTypePosition = line.find_first_not_of(whitespace, equalsSignPosition + 1);
if (variableTypePosition == std::string::npos)
{
firstArgument = firstDelimeter + 1;
// Skip lines with no variable type definition
continue;
}
// Count parentheses
std::size_t leftParenthesisCount = std::count(line.begin() + variableNamePosition, line.end(), '(');
std::size_t rightParenthesisCount = std::count(line.begin() + variableNamePosition, line.end(), ')');
if (leftParenthesisCount != rightParenthesisCount || leftParenthesisCount == 0)
{
// Skip lines with invalid number of parentheses
continue;
}
// Form command string and argument list string
std::string command = line.substr(firstCommand, firstDelimeter - firstCommand);
std::string argumentList = line.substr(firstArgument);
std::string variableName = line.substr(variableNamePosition, line.find_first_of(" \t=", variableNamePosition) - variableNamePosition);
std::string variableType = line.substr(variableTypePosition, line.find_first_of(" \t[(", variableTypePosition) - variableTypePosition);
std::size_t elementCount = leftParenthesisCount;
std::size_t currentPosition = variableTypePosition;
std::vector<std::vector<std::string>> elements;
bool invalid = false;
for (std::size_t i = 0; i < elementCount; ++i)
{
std::size_t leftParenthesisPosition = line.find_first_of("(", currentPosition);
std::size_t rightParenthesisPosition = line.find_first_of(")", leftParenthesisPosition + 1);
if (leftParenthesisPosition == std::string::npos || rightParenthesisPosition == std::string::npos)
{
invalid = true;
break;
}
currentPosition = leftParenthesisPosition + 1;
std::size_t argumentCount = std::count(line.begin() + leftParenthesisPosition + 1, line.begin() + rightParenthesisPosition, ',') + 1;
std::vector<std::string> arguments;
for (std::size_t j = 0; j < argumentCount; ++j)
{
std::size_t argumentStart = line.find_first_not_of(whitespace, currentPosition);
std::size_t argumentEnd = line.find_first_of(" \t,)", argumentStart + 1);
if (argumentStart == std::string::npos || argumentEnd == std::string::npos)
{
// Unable to parse argument
invalid = true;
break;
}
std::string argument = line.substr(argumentStart, argumentEnd - argumentStart);
arguments.push_back(argument);
currentPosition = argumentEnd + 1;
}
if (invalid)
{
// Unable to parse element
break;
}
elements.push_back(arguments);
currentPosition = rightParenthesisPosition + 1;
}
// Form vector of argument strings
std::vector<std::string> arguments;
std::istringstream argumentStream(argumentList);
std::string argument;
while (argumentStream >> argument)
if (invalid)
{
arguments.push_back(argument);
// Unable to parse line
continue;
}
if (command == "albedo" && arguments.size() == 3)
if (variableType == "int")
{
std::stringstream(arguments[0]) >> material->albedo.x;
std::stringstream(arguments[1]) >> material->albedo.y;
std::stringstream(arguments[2]) >> material->albedo.z;
ShaderInt* variable = material->addVariable<int>(variableName, elements.size());
loadShaderInt(variable, elements);
}
else if (command == "opacity" && arguments.size() == 1)
else if (variableType == "float")
{
std::stringstream(arguments[0]) >> material->opacity;
ShaderFloat* variable = material->addVariable<float>(variableName, elements.size());
loadShaderFloat(variable, elements);
}
else if (command == "metalness" && arguments.size() == 1)
else if (variableType == "vec2")
{
std::stringstream(arguments[0]) >> material->metalness;
ShaderVector2* variable = material->addVariable<Vector2>(variableName, elements.size());
loadShaderVector2(variable, elements);
}
else if (command == "roughness" && arguments.size() == 1)
else if (variableType == "vec3")
{
std::stringstream(arguments[0]) >> material->roughness;
ShaderVector3* variable = material->addVariable<Vector3>(variableName, elements.size());
loadShaderVector3(variable, elements);
}
else if (command == "translucent" && arguments.size() == 1)
else if (variableType == "vec4")
{
int translucent = 0;
std::stringstream(arguments[0]) >> translucent;
if (translucent)
{
material->flags |= static_cast<unsigned int>(PhysicalMaterial::Flags::TRANSLUCENT);
}
ShaderVector4* variable = material->addVariable<Vector4>(variableName, elements.size());
loadShaderVector4(variable, elements);
}
else if (command == "albedo-opacity-map")
else if (variableType == "mat3")
{
material->albedoOpacityMap = loadTexture(argumentList);
ShaderMatrix3* variable = material->addVariable<Matrix3>(variableName, elements.size());
loadShaderMatrix3(variable, elements);
}
else if (command == "metalness-roughness-map")
else if (variableType == "mat4")
{
material->metalnessRoughnessMap = loadTexture(argumentList);
ShaderMatrix4* variable = material->addVariable<Matrix4>(variableName, elements.size());
loadShaderMatrix4(variable, elements);
}
else if (command == "normal-occlusion-map")
else if (variableType == "texture")
{
material->normalOcclusionMap = loadTexture(argumentList);
ShaderTexture2D* variable = material->addVariable<const Texture2D*>(variableName, elements.size());
loadShaderTexture2D(variable, elements);
}
else if (command[0] != '#')
else if (variableType == "textureCube")
{
std::cerr << "MaterialLoader::load(): Invalid line \"" << line << "\" in file \"" << filename << "\"" << std::endl;
ShaderTextureCube* variable = material->addVariable<const TextureCube*>(variableName, elements.size());
loadShaderTextureCube(variable, elements);
}
}
@ -172,11 +235,11 @@ PhysicalMaterial* MaterialLoader::load(const std::string& filename)
return material;
}
Texture* MaterialLoader::loadTexture(const std::string& filename)
Texture2D* MaterialLoader::loadTexture2D(const std::string& filename)
{
// Check if texture exists in cache
auto it = textureCache.find(filename);
if (it != textureCache.end())
auto it = texture2DCache.find(filename);
if (it != texture2DCache.end())
{
return it->second;
}
@ -184,15 +247,215 @@ Texture* MaterialLoader::loadTexture(const std::string& filename)
std::string fullFilename = std::string("data/textures/") + filename;
// Load texture
Texture* texture = textureLoader.load(fullFilename);
Texture2D* texture = textureLoader.load2D(fullFilename);
if (!texture)
{
std::cerr << "MaterialLoader::loadTexture(): Failed to load texture file \"" << fullFilename << "\"" << std::endl;
std::cerr << "MaterialLoader::loadTexture2D(): Failed to load texture file \"" << fullFilename << "\"" << std::endl;
return nullptr;
}
// Add texture to cache
textureCache[filename] = texture;
texture2DCache[filename] = texture;
return texture;
}
TextureCube* MaterialLoader::loadTextureCube(const std::string& filename)
{
// Check if texture exists in cache
auto it = textureCubeCache.find(filename);
if (it != textureCubeCache.end())
{
return it->second;
}
std::string fullFilename = std::string("data/textures/") + filename;
// Load texture
TextureCube* texture = textureLoader.loadCube(fullFilename);
if (!texture)
{
std::cerr << "MaterialLoader::loadTextureCube(): Failed to load texture file \"" << fullFilename << "\"" << std::endl;
return nullptr;
}
// Add texture to cache
textureCubeCache[filename] = texture;
return texture;
}
bool MaterialLoader::loadShaderInt(ShaderInt* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
int value;
std::stringstream stream;
stream << elements[i][0];
stream >> value;
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderFloat(ShaderFloat* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
float value;
std::stringstream stream;
stream << elements[i][0];
stream >> value;
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderVector2(ShaderVector2* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Vector2 value;
for (int j = 0; j < 2; ++j)
{
std::stringstream stream;
stream << elements[i][j];
stream >> value[j];
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderVector3(ShaderVector3* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Vector3 value;
for (int j = 0; j < 3; ++j)
{
std::stringstream stream;
stream << elements[i][j];
stream >> value[j];
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderVector4(ShaderVector4* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Vector4 value;
for (int j = 0; j < 4; ++j)
{
std::stringstream stream;
stream << elements[i][j];
stream >> value[j];
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderMatrix3(ShaderMatrix3* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Matrix3 value;
for (int j = 0; j < 3; ++j)
{
for (int k = 0; k < 3; ++k)
{
std::stringstream stream;
stream << elements[i][k * 3 + j];
stream >> value[j][k];
}
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderMatrix4(ShaderMatrix4* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
Matrix4 value;
for (int j = 0; j < 4; ++j)
{
for (int k = 0; k < 4; ++k)
{
std::stringstream stream;
stream << elements[i][k * 4 + j];
stream >> value[j][k];
}
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderTexture2D(ShaderTexture2D* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
std::string filename;
std::stringstream stream;
stream << elements[i][0];
stream >> filename;
Texture2D* value = loadTexture2D(filename);
if (!value)
{
std::cerr << "MaterialLoader::loadShaderTexture2D(): Failed to load 2D texture \"" << filename << "\"" << std::endl;
return false;
}
variable->setValue(i, value);
}
return true;
}
bool MaterialLoader::loadShaderTextureCube(ShaderTextureCube* variable, const std::vector<std::vector<std::string>>& elements)
{
for (int i = 0; i < elements.size(); ++i)
{
std::string filename;
std::stringstream stream;
stream << elements[i][0];
stream >> filename;
TextureCube* value = loadTextureCube(filename);
if (!value)
{
std::cerr << "MaterialLoader::loadShaderTextureCube(): Failed to load cube texture \"" << filename << "\"" << std::endl;
return false;
}
variable->setValue(i, value);
}
return true;
}

+ 25
- 5
src/material-loader.hpp View File

@ -20,8 +20,11 @@
#ifndef MATERIAL_LOADER_HPP
#define MATERIAL_LOADER_HPP
#include <emergent/emergent.hpp>
using namespace Emergent;
#include <map>
#include <string>
#include "materials.hpp"
class MaterialLoader
{
@ -30,12 +33,29 @@ public:
~MaterialLoader();
void unload();
PhysicalMaterial* load(const std::string& filename);
Material* load(const std::string& filename);
private:
Texture* loadTexture(const std::string& filename);
std::map<std::string, Texture*> textureCache;
std::map<std::string, PhysicalMaterial*> materialCache;
Shader* loadShader(const std::string& filename);
Texture2D* loadTexture2D(const std::string& filename);
TextureCube* loadTextureCube(const std::string& filename);
bool loadShaderInt(ShaderInt* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderFloat(ShaderFloat* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderVector2(ShaderVector2* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderVector3(ShaderVector3* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderVector4(ShaderVector4* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderMatrix3(ShaderMatrix3* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderMatrix4(ShaderMatrix4* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderTexture2D(ShaderTexture2D* variable, const std::vector<std::vector<std::string>>& elements);
bool loadShaderTextureCube(ShaderTextureCube* variable, const std::vector<std::vector<std::string>>& elements);
std::map<std::string, Shader*> shaderCache;
std::map<std::string, Texture2D*> texture2DCache;
std::map<std::string, TextureCube*> textureCubeCache;
std::map<std::string, Material*> materialCache;
TextureLoader textureLoader;
};

+ 0
- 89
src/materials.hpp View File

@ -1,89 +0,0 @@
/*
* Copyright (C) 2017 Christopher J. Howard
*
* This file is part of Antkeeper Source Code.
*
* Antkeeper Source Code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper Source Code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MATERIALS
#define MATERIALS
#include <emergent/emergent.hpp>
using namespace Emergent;
enum class MaterialFormat
{
UI,
PHYSICAL
};
class UIMaterial: public Material
{
public:
UIMaterial(): texture(nullptr) {}
virtual ~UIMaterial() {}
virtual unsigned int getMaterialFormatID() const;
Texture* texture;
};
inline unsigned int UIMaterial::getMaterialFormatID() const
{
return static_cast<unsigned int>(MaterialFormat::UI);
}
/// @see https://www.marmoset.co/posts/physically-based-rendering-and-you-can-too/
class PhysicalMaterial: public Material
{
public:
enum class Flags
{
OBJECT = 0x01,
TERRAIN = 0x02,
SOIL = 0x04,
TRANSLUCENT = 0x08
};
PhysicalMaterial():
albedoOpacityMap(nullptr),
metalnessRoughnessMap(nullptr),
normalOcclusionMap(nullptr),
flags((unsigned int)Flags::OBJECT),
shadowCaster(true),
shadowReceiver(true)
{};
virtual ~PhysicalMaterial() {};
virtual unsigned int getMaterialFormatID() const;
unsigned int flags;
Vector3 albedo;
float opacity;
float metalness;
float roughness;
Texture* albedoOpacityMap;
Texture* metalnessRoughnessMap;
Texture* normalOcclusionMap;
bool shadowCaster;
bool shadowReceiver;
};
inline unsigned int PhysicalMaterial::getMaterialFormatID() const
{
return static_cast<unsigned int>(MaterialFormat::PHYSICAL);
}
#endif // MATERIALS

+ 339
- 770
src/render-passes.cpp
File diff suppressed because it is too large
View File


+ 93
- 85
src/render-passes.hpp View File

@ -25,6 +25,7 @@ using namespace Emergent;
#include "material-loader.hpp"
#include "model-loader.hpp"
#include <cstdint>
/**
* Clears framebuffers
@ -62,19 +63,26 @@ public:
virtual void unload();
virtual void render(RenderContext* renderContext);
inline void setTexture(GLuint textureID) { this->textureID = textureID; }
inline void setDirection(Vector2 direction) { this->direction = direction; }
inline void setGammaCorrect(bool gammaCorrect) { this->gammaCorrect = gammaCorrect; }
/**
* Sets the texture to blur.
*/
inline void setTexture(const Texture2D* texture) { textureParam.setValue(texture); }
/**
* Sets the direction of the blur.
*/
inline void setDirection(const Vector2& direction) { directionParam.setValue(direction); }
private:
ShaderParameterSet parameterSet;
const ShaderParameter* textureParam;
const ShaderParameter* resolutionParam;
const ShaderParameter* directionParam;
ShaderLoader shaderLoader;
Shader* shader;
bool gammaCorrect;
GLuint textureID;
Vector2 direction;
Shader shader;
std::uint32_t permutation;
ShaderTexture2D textureParam;
ShaderVector2 resolutionParam;
ShaderVector2 directionParam;
int quadVertexCount;
int quadIndexCount;
@ -110,16 +118,13 @@ private:
bool operator()(const RenderOperation& opA, const RenderOperation& opB) const;
};
ShaderParameterSet parameterSet;
const ShaderParameter* modelViewProjectionParam;
const ShaderParameter* matrixPaletteParam;
ShaderLoader shaderLoader;
Shader shader;
std::uint32_t unskinnedPermutation;
std::uint32_t skinnedPermutation;
ShaderMatrix4 modelViewProjectionParam;
ShaderMatrix4* matrixPaletteParam; // data not used, just getConnectedInput() then pass pose matrix palette pointer directly
Shader* unskinnedShader;
Shader* skinnedShader;
int maxBoneCount;
int shadowMapResolution;
int croppedShadowMapResolution;
Vector4* croppedShadowMapViewports;
@ -142,11 +147,11 @@ public:
virtual void unload();
virtual void render(RenderContext* renderContext);
inline void setShadowMap(GLuint shadowMap) { this->shadowMap = shadowMap; }
inline void setShadowMap(const Texture2D* shadowMap) { this->shadowMap = shadowMap; }
inline void setShadowCamera(const Camera* camera) { this->shadowCamera = camera; }
inline void setShadowMapPass(const ShadowMapRenderPass* shadowMapPass) { this->shadowMapPass = shadowMapPass; }
inline void setDiffuseCubemap(const Texture* cubemap) { this->diffuseCubemap = cubemap; }
inline void setSpecularCubemap(const Texture* cubemap) { this->specularCubemap = cubemap; }
inline void setDiffuseCubemap(const TextureCube* cubemap) { this->diffuseCubemap = cubemap; }
inline void setSpecularCubemap(const TextureCube* cubemap) { this->specularCubemap = cubemap; }
private:
class RenderOpCompare
@ -155,53 +160,61 @@ private:
// Sort render opations
bool operator()(const RenderOperation& opA, const RenderOperation& opB) const;
};
bool loadShader(const RenderOperation& operation);
ShaderParameterSet parameterSet;
const ShaderParameter* matrixPaletteParam;
const ShaderParameter* modelParam;
const ShaderParameter* modelViewParam;
const ShaderParameter* modelViewProjectionParam;
const ShaderParameter* normalModelViewParam;
const ShaderParameter* normalModelParam;
const ShaderParameter* lightViewProjectionsParam;
const ShaderParameter* splitDistancesParam;
const ShaderParameter* shadowMapParam;
const ShaderParameter* cameraPositionParam;
const ShaderParameter* directionalLightCountParam;
const ShaderParameter* directionalLightColorsParam;
const ShaderParameter* directionalLightDirectionsParam;
const ShaderParameter* spotlightCountParam;
const ShaderParameter* spotlightColorsParam;
const ShaderParameter* spotlightPositionsParam;
const ShaderParameter* spotlightAttenuationsParam;
const ShaderParameter* spotlightDirectionsParam;
const ShaderParameter* spotlightCutoffsParam;
const ShaderParameter* spotlightExponentsParam;
const ShaderParameter* albedoOpacityMapParam;
const ShaderParameter* metalnessRoughnessMapParam;
const ShaderParameter* normalOcclusionMapParam;
const ShaderParameter* diffuseCubemapParam;
const ShaderParameter* specularCubemapParam;
Shader* unskinnedShader;
Shader* skinnedShader;
struct ParameterSet
{
ShaderMatrix4* matrixPalette;
ShaderMatrix4 modelMatrix;
ShaderMatrix4 modelViewMatrix;
ShaderMatrix4 modelViewProjectionMatrix;
ShaderMatrix3 normalModelViewMatrix;
ShaderMatrix3 normalModelMatrix;
ShaderMatrix4* lightViewProjectionMatrices;
ShaderVector4 splitDistances;
ShaderTexture2D shadowMap;
ShaderVector3 cameraPosition;
ShaderTextureCube diffuseCubemap;
ShaderTextureCube specularCubemap;
ShaderInt directionalLightCount;
ShaderVector3* directionalLightColors;
ShaderVector3* directionalLightDirections;
ShaderInt spotlightCount;
ShaderVector3 spotlightColors;
ShaderVector3 spotlightPositions;
ShaderVector3 spotlightAttenuations;
ShaderVector3 spotlightDirections;
ShaderFloat spotlightCutoffs;
ShaderFloat spotlightExponents;
ShaderTexture2D albedoOpacityMap;
ShaderTexture2D metalnessRoughnessMap;
ShaderTexture2D normalOcclusionMap;
// Material shader parameters (uploaded by material directly)
//ShaderTexture2D albedoOpacityMap;
//ShaderTexture2D metalnessRoughnessMap;
//ShaderTexture2D normalOcclusionMap;
};
//std::map<Shader* shader, ParameterSet> parameterSets;
Shader shader;
ParameterSet parameters;
std::uint32_t unskinnedPermutation;
std::uint32_t skinnedPermutation;
int maxBoneCount;
int maxDirectionalLightCount;
int maxSpotlightCount;
ShaderLoader shaderLoader;
std::map<std::size_t, Shader*> shaderCache;
//Shader* lightingShader;
Matrix4 biasMatrix;
GLuint shadowMap;
Texture* treeShadow;
const Texture* diffuseCubemap;
const Texture* specularCubemap;
const Texture2D* shadowMap;
const TextureCube* diffuseCubemap;
const TextureCube* specularCubemap;
const Camera* shadowCamera;
float time;
const ShadowMapRenderPass* shadowMapPass;
@ -224,11 +237,9 @@ public:
//void setDrawLights(bool enabled);
private:
ShaderParameterSet parameterSet;
const ShaderParameter* modelViewProjectionParam;
ShaderLoader shaderLoader;
Shader* unlitSolidShader;
Shader shader;
std::uint32_t permutation;
ShaderMatrix4 modelViewProjectionMatrixParam;
int aabbVertexCount;
int aabbIndexCount;
@ -249,20 +260,20 @@ public:
virtual void render(RenderContext* renderContext);
private:
ShaderParameterSet parameterSet;
const ShaderParameter* modelViewProjectionParam;
const ShaderParameter* textureParam;
const ShaderParameter* texcoordOffsetParam;
const ShaderParameter* texcoordScaleParam;
ShaderLoader shaderLoader;
Shader* texturedUIShader;
Shader* untexturedUIShader;
Shader shader;
std::uint32_t texturedPermutation;
std::uint32_t untexturedPermutation;
ShaderMatrix4 modelViewProjectionMatrixParam;
ShaderTexture2D textureParam;
ShaderVector2 textureOffsetParam;
ShaderVector2 textureScaleParam;
};
/**
* Renders a vignette
*/
/*
class VignetteRenderPass: public RenderPass
{
public:
@ -280,6 +291,7 @@ private:
Shader* shader;
GLuint bayerTextureID;
};
*/
/**
* Renders a skybox
@ -289,19 +301,17 @@ class SkyboxRenderPass: public RenderPass
public:
SkyboxRenderPass();
inline void setCubemap(Texture* cubemap) { this->cubemap = cubemap; }
inline void setCubemap(TextureCube* cubemap) { this->cubemap = cubemap; }
virtual bool load(const RenderContext* renderContext);
virtual void unload();
virtual void render(RenderContext* renderContext);
private:
ShaderParameterSet parameterSet;
const ShaderParameter* matrixParam;
const ShaderParameter* cubemapParam;
ShaderLoader shaderLoader;
Shader* shader;
Texture* cubemap;
Shader shader;
std::uint32_t permutation;
ShaderMatrix4 matrixParam;
ShaderTextureCube cubemapParam;
TextureCube* cubemap;
int quadVertexCount;
int quadIndexCount;
@ -310,6 +320,4 @@ private:
GLuint quadIBO;
};
#endif // RENDER_PASSES_HPP

+ 1
- 0
src/states/game-state.cpp View File

@ -410,6 +410,7 @@ void GameState::execute()
glBindTexture(GL_TEXTURE_2D, application->pheromoneTextureID);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, application->pheromoneTexture.getWidth(), application->pheromoneTexture.getHeight(), GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
//glGenerateMipmap(GL_TEXTURE_2D);
}
}
}

+ 0
- 17
src/states/title-state.cpp View File

@ -33,9 +33,6 @@ TitleState::~TitleState()
void TitleState::enter()
{
application->backgroundLayer->addObject(&application->bgCamera);
application->backgroundLayer->addObject(&application->bgBatch);
application->inputManager->addWindowObserver(this);
windowResized(application->resolution.x, application->resolution.y);
@ -163,16 +160,6 @@ void TitleState::execute()
{
application->close(EXIT_SUCCESS);
}
// Set selector icon position
/*
float lineHeight = application->menuFont->getMetrics().getHeight();
const UIContainer* container = application->menuContainers[application->currentMenuIndex];
application->menuSelectorLabel->setTranslation(
Vector2(container->getPosition().x - application->menuSelectorLabel->getDimensions().x * 1.5f,
container->getPosition().y + lineHeight * 0.5f - application->menuSelectorLabel->getDimensions().y * 0.5f + lineHeight * application->selectedMenuItemIndex));
*/
}
void TitleState::exit()
@ -185,10 +172,6 @@ void TitleState::exit()
application->copyrightLabel->setVisible(false);
application->anyKeyLabel->setVisible(false);
application->darkenImage->setVisible(false);
// Remove clear scene
application->backgroundLayer->removeObject(&application->bgCamera);
application->backgroundLayer->removeObject(&application->bgBatch);
}
void TitleState::windowClosed()

+ 1
- 1
src/ui/pie-menu.cpp View File

@ -70,7 +70,7 @@ void PieMenu::setScale(float scale)
}
}
void PieMenu::addOption(Texture* backgroundTexture, Texture* iconTexture, std::function<void()> selectedCallback, std::function<void()> deselectedCallback)
void PieMenu::addOption(Texture2D* backgroundTexture, Texture2D* iconTexture, std::function<void()> selectedCallback, std::function<void()> deselectedCallback)
{
// Allocate new option
UIImage* option = new UIImage();

+ 1
- 1
src/ui/pie-menu.hpp View File

@ -16,7 +16,7 @@ public:
void resize();
void addOption(Texture* backgroundTexture, Texture* iconTexture, std::function<void()> selectedCallback, std::function<void()> deselectedCallback);
void addOption(Texture2D* backgroundTexture, Texture2D* iconTexture, std::function<void()> selectedCallback, std::function<void()> deselectedCallback);
void select(std::size_t index);
void deselect(std::size_t index);

+ 6
- 6
src/ui/toolbar.cpp View File

@ -14,30 +14,30 @@ Toolbar::Toolbar():
toolbarContainer.addChild(&toolbarMiddleImage);
}
void Toolbar::setToolbarTopTexture(Texture* texture)
void Toolbar::setToolbarTopTexture(Texture2D* texture)
{
toolbarTopTexture = texture;
toolbarTopImage.setTexture(toolbarTopTexture);
}
void Toolbar::setToolbarBottomTexture(Texture* texture)
void Toolbar::setToolbarBottomTexture(Texture2D* texture)
{
toolbarBottomTexture = texture;
toolbarBottomImage.setTexture(toolbarBottomTexture);
}
void Toolbar::setToolbarMiddleTexture(Texture* texture)
void Toolbar::setToolbarMiddleTexture(Texture2D* texture)
{
toolbarMiddleTexture = texture;
toolbarMiddleImage.setTexture(toolbarMiddleTexture);
}
void Toolbar::setButtonRaisedTexture(Texture* texture)
void Toolbar::setButtonRaisedTexture(Texture2D* texture)
{
buttonRaisedTexture = texture;
}
void Toolbar::setButtonDepressedTexture(Texture* texture)
void Toolbar::setButtonDepressedTexture(Texture2D* texture)
{
buttonDepressedTexture = texture;
}
@ -81,7 +81,7 @@ void Toolbar::resize()
}
}
void Toolbar::addButton(Texture* iconTexture, std::function<void()> pressCallback, std::function<void()> releaseCallback)
void Toolbar::addButton(Texture2D* iconTexture, std::function<void()> pressCallback, std::function<void()> releaseCallback)
{
if (depressedButtonIndex == buttons.size())
{

+ 11
- 11
src/ui/toolbar.hpp View File

@ -13,15 +13,15 @@ class Toolbar
public:
Toolbar();
void setToolbarTopTexture(Texture* texture);
void setToolbarBottomTexture(Texture* texture);
void setToolbarMiddleTexture(Texture* texture);
void setButtonRaisedTexture(Texture* texture);
void setButtonDepressedTexture(Texture* texture);
void setToolbarTopTexture(Texture2D* texture);
void setToolbarBottomTexture(Texture2D* texture);
void setToolbarMiddleTexture(Texture2D* texture);
void setButtonRaisedTexture(Texture2D* texture);
void setButtonDepressedTexture(Texture2D* texture);
void resize();
void addButton(Texture* iconTexture, std::function<void()> pressCallback, std::function<void()> releaseCallback);
void addButton(Texture2D* iconTexture, std::function<void()> pressCallback, std::function<void()> releaseCallback);
void pressButton(std::size_t index);
void releaseButton(std::size_t index);
@ -30,11 +30,11 @@ public:
UIContainer* getContainer();
private:
Texture* toolbarTopTexture;
Texture* toolbarBottomTexture;
Texture* toolbarMiddleTexture;
Texture* buttonRaisedTexture;
Texture* buttonDepressedTexture;
Texture2D* toolbarTopTexture;
Texture2D* toolbarBottomTexture;
Texture2D* toolbarMiddleTexture;
Texture2D* buttonRaisedTexture;
Texture2D* buttonDepressedTexture;
UIContainer toolbarContainer;
UIImage toolbarTopImage;

+ 14
- 3
src/ui/ui.cpp View File

@ -26,6 +26,17 @@ void menuPrint(Application* application, const std::string& string)
std::cout << string << std::endl;
}
UIMaterial::UIMaterial()
{
texture = addVariable<const Texture2D*>("texture");
textureOffset = addVariable<Vector2>("offset");
textureScale = addVariable<Vector2>("scale");
texture->setValue(nullptr);
textureOffset->setValue(Vector2(0.0f));
textureScale->setValue(Vector2(1.0f));
}
UIElement::UIElement():
parent(nullptr),
anchor(Anchor::TOP_LEFT),
@ -218,7 +229,7 @@ UILabel::~UILabel()
void UILabel::setFont(Font* font)
{
this->font = font;
material.texture = font->getTexture();
material.texture->setValue(font->getTexture());
calculateDimensions();
}
@ -267,7 +278,7 @@ void UIBatcher::batch(BillboardBatch* result, const UIElement* ui)
return false;
}
return (a->getMaterial()->texture < b->getMaterial()->texture);
return (a->getMaterial()->texture->getValue() < b->getMaterial()->texture->getValue());
});
// Clear previous ranges
@ -315,7 +326,7 @@ BillboardBatch::Range* UIBatcher::getRange(BillboardBatch* result, const UIEleme
const UIMaterial* material = static_cast<UIMaterial*>(range->material);
if (material->texture != element->getMaterial()->texture)
if (material->texture->getValue() != element->getMaterial()->texture->getValue())
{
// Create new range for the element
range = result->addRange();

+ 16
- 7
src/ui/ui.hpp View File

@ -21,7 +21,6 @@
#define UI_HPP
#include "../input.hpp"
#include "../materials.hpp"
#include <vector>
#include <functional>
@ -37,6 +36,16 @@ namespace Anchor
static const Vector2& CENTER = Vector2(0.5f, 0.5f);
}
class UIMaterial: public Material
{
public:
UIMaterial();
ShaderTexture2D* texture;
ShaderVector2* textureOffset;
ShaderVector2* textureScale;
};
class UIElement: public MouseMotionObserver, public MouseButtonObserver
{
public:
@ -391,9 +400,9 @@ public:
virtual ~UIImage();
virtual UIElement::Type getElementType() const;
virtual const Texture* getTexture() const;
virtual const Texture2D* getTexture() const;
void setTexture(Texture* texture);
void setTexture(Texture2D* texture);
void setTextureBounds(const Rect& bounds);
const Rect& getTextureBounds() const;
@ -407,14 +416,14 @@ inline UIElement::Type UIImage::getElementType() const
return UIElement::Type::IMAGE;
}
inline const Texture* UIImage::getTexture() const
inline const Texture2D* UIImage::getTexture() const
{
return material.texture;
return material.texture->getValue();
}
inline void UIImage::setTexture(Texture* texture)
inline void UIImage::setTexture(Texture2D* texture)
{
material.texture = texture;
material.texture->setValue(texture);
}
inline void UIImage::setTextureBounds(const Rect& bounds)

Loading…
Cancel
Save