Allow px/color skybox without tex

This commit is contained in:
Zach Pomerantz 2016-03-10 12:58:49 -08:00
parent d7d351fc63
commit b627a17ce9
6 changed files with 42 additions and 84 deletions

View file

@ -3757,19 +3757,19 @@ namespace render {
switch (backgroundMode) {
case model::SunSkyStage::SKY_BOX: {
auto skybox = skyStage->getSkybox();
if (skybox && skybox->getCubemap() && skybox->getCubemap()->isDefined()) {
if (skybox) {
PerformanceTimer perfTimer("skybox");
skybox->render(batch, *(args->_viewFrustum));
break;
}
// If no skybox texture is available, render the SKY_DOME while it loads
}
// fall through to next case
// Fall through: if no skybox is available, render the SKY_DOME
case model::SunSkyStage::SKY_DOME: {
if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {
PerformanceTimer perfTimer("stars");
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::payloadRender<BackgroundRenderData>() ... stars...");
"Application::payloadRender<BackgroundRenderData>() ... My god, it's full of stars...");
// should be the first rendering pass - w/o depth buffer / lighting
static const float alpha = 1.0f;
@ -3777,6 +3777,7 @@ namespace render {
}
}
break;
case model::SunSkyStage::NO_BACKGROUND:
default:
// this line intentionally left blank

View file

@ -101,8 +101,6 @@ private:
/// A simple object wrapper for an OpenGL texture.
class Texture {
public:
friend class TextureCache;
gpu::TexturePointer getGPUTexture() const { return _textureSource->getGPUTexture(); }
gpu::TextureSourcePointer _textureSource;
};

View file

@ -21,54 +21,39 @@
using namespace model;
Skybox::Skybox() {
Data data;
_dataBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Data), (const gpu::Byte*) &data));
/* // PLease create a default engineer skybox
_cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1));
unsigned char texels[] = {
255, 0, 0, 255,
0, 255, 255, 255,
0, 0, 255, 255,
255, 255, 0, 255,
0, 255, 0, 255,
255, 0, 255, 255,
};
_cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels);*/
Schema schema;
_schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema));
}
void Skybox::setColor(const Color& color) {
_dataBuffer.edit<Data>()._color = color;
_schemaBuffer.edit<Schema>()._color = color;
}
void Skybox::setCubemap(const gpu::TexturePointer& cubemap) {
_cubemap = cubemap;
}
void Skybox::updateDataBuffer() const {
void Skybox::updateSchemaBuffer() const {
auto blend = 0.0f;
if (getCubemap() && getCubemap()->isDefined()) {
blend = 1.0f;
blend = 0.5f;
// If pitch black neutralize the color
if (glm::all(glm::equal(getColor(), glm::vec3(0.0f)))) {
blend = 2.0f;
blend = 1.0f;
}
}
if (blend != _dataBuffer.get<Data>()._blend) {
_dataBuffer.edit<Data>()._blend = blend;
if (blend != _schemaBuffer.get<Schema>()._blend) {
_schemaBuffer.edit<Schema>()._blend = blend;
}
}
void Skybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const {
updateDataBuffer();
updateSchemaBuffer();
Skybox::render(batch, frustum, (*this));
}
void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {
// Create the static shared elements used to render the skybox
static gpu::BufferPointer theConstants;
@ -98,10 +83,6 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky
// Render
gpu::TexturePointer skymap = skybox.getCubemap();
// FIXME: skymap->isDefined may not be threadsafe
assert(skymap && skymap->isDefined());
glm::mat4 projMat;
viewFrustum.evalProjectionMatrix(projMat);
@ -112,11 +93,15 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky
batch.setModelTransform(Transform()); // only for Mac
batch.setPipeline(thePipeline);
batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._dataBuffer);
batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap);
batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._schemaBuffer);
gpu::TexturePointer skymap = skybox.getCubemap();
// FIXME: skymap->isDefined may not be threadsafe
if (skymap && skymap->isDefined()) {
batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap);
}
batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr);
}

View file

@ -30,28 +30,27 @@ public:
virtual ~Skybox() {};
void setColor(const Color& color);
const Color getColor() const { return _dataBuffer.get<Data>()._color; }
const Color getColor() const { return _schemaBuffer.get<Schema>()._color; }
void setCubemap(const gpu::TexturePointer& cubemap);
const gpu::TexturePointer& getCubemap() const { return _cubemap; }
virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const;
static void render(gpu::Batch& batch, const ViewFrustum& frustum, const Skybox& skybox);
protected:
gpu::TexturePointer _cubemap;
class Data {
class Schema {
public:
glm::vec3 _color{ 1.0f, 1.0f, 1.0f };
float _blend = 1.0f;
glm::vec3 _color { 1.0f, 1.0f, 1.0f };
float _blend { 0.0f };
};
mutable gpu::BufferView _dataBuffer;
mutable gpu::BufferView _schemaBuffer;
void updateDataBuffer() const;
void updateSchemaBuffer() const;
};
typedef std::shared_ptr< Skybox > SkyboxPointer;

View file

@ -14,7 +14,8 @@
uniform samplerCube cubeMap;
struct Skybox {
vec4 _color;
vec3 _color;
float _blend;
};
uniform skyboxBuffer {
@ -24,36 +25,17 @@ uniform skyboxBuffer {
in vec3 _normal;
out vec4 _fragColor;
//PROCEDURAL_COMMON_BLOCK
#line 1001
//PROCEDURAL_BLOCK
#line 2033
void main(void) {
#ifdef PROCEDURAL
vec3 color = getSkyboxColor();
_fragColor = vec4(color, 0.0);
#else
vec3 coord = normalize(_normal);
vec3 color = _skybox._color;
// Skybox color or blend with skymap
vec3 color = _skybox._color.rgb;
if (_skybox._color.a > 0.0) {
vec3 texel = texture(cubeMap, coord).rgb;
if (_skybox._color.a < 2.0) {
color *= texel;
} else {
color = texel;
// blend is only set if there is a cubemap
if (_skybox._blend > 0.0) {
color = texture(cubeMap, coord).rgb;
if (_skybox._blend < 1.0) {
color *= _skybox._color;
}
}
}
_fragColor = vec4(color, 0.0);
#endif
}

View file

@ -38,20 +38,15 @@ void ProceduralSkybox::setProcedural(const ProceduralPointer& procedural) {
}
void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const {
ProceduralSkybox::render(batch, frustum, (*this));
if (_procedural) {
ProceduralSkybox::render(batch, frustum, (*this));
} else {
Skybox::render(batch, frustum);
}
}
void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const ProceduralSkybox& skybox) {
if (!(skybox._procedural)) {
skybox.updateDataBuffer();
Skybox::render(batch, viewFrustum, skybox);
}
if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) {
gpu::TexturePointer skymap = skybox.getCubemap();
// FIXME: skymap->isDefined may not be threadsafe
assert(skymap && skymap->isDefined());
glm::mat4 projMat;
viewFrustum.evalProjectionMatrix(projMat);
@ -60,10 +55,8 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum,
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewTransform);
batch.setModelTransform(Transform()); // only for Mac
batch.setResourceTexture(0, skybox.getCubemap());
skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1));
batch.draw(gpu::TRIANGLE_STRIP, 4);
}
}