mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 01:23:17 +02:00
commit
f7bc79729d
22 changed files with 194 additions and 56 deletions
|
@ -203,10 +203,11 @@ void GLBackend::releaseResourceTexture(uint32_t slot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::resetResourceStage() {
|
void GLBackend::resetResourceStage() {
|
||||||
for (uint32_t i = 0; i < _resource._buffers.size(); i++) {
|
uint32_t i;
|
||||||
|
for (i = 0; i < _resource._buffers.size(); i++) {
|
||||||
releaseResourceBuffer(i);
|
releaseResourceBuffer(i);
|
||||||
}
|
}
|
||||||
for (uint32_t i = 0; i < _resource._textures.size(); i++) {
|
for (i = 0; i < _resource._textures.size(); i++) {
|
||||||
releaseResourceTexture(i);
|
releaseResourceTexture(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,11 @@ const size_t GLVariableAllocationSupport::MAX_BUFFER_SIZE = MAX_TRANSFER_SIZE;
|
||||||
GLenum GLTexture::getGLTextureType(const Texture& texture) {
|
GLenum GLTexture::getGLTextureType(const Texture& texture) {
|
||||||
switch (texture.getType()) {
|
switch (texture.getType()) {
|
||||||
case Texture::TEX_2D:
|
case Texture::TEX_2D:
|
||||||
return GL_TEXTURE_2D;
|
if (!texture.isArray()) {
|
||||||
|
return GL_TEXTURE_2D;
|
||||||
|
} else {
|
||||||
|
return GL_TEXTURE_2D_ARRAY;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Texture::TEX_CUBE:
|
case Texture::TEX_CUBE:
|
||||||
|
@ -77,6 +81,7 @@ GLenum GLTexture::getGLTextureType(const Texture& texture) {
|
||||||
uint8_t GLTexture::getFaceCount(GLenum target) {
|
uint8_t GLTexture::getFaceCount(GLenum target) {
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case GL_TEXTURE_2D:
|
case GL_TEXTURE_2D:
|
||||||
|
case GL_TEXTURE_2D_ARRAY:
|
||||||
return TEXTURE_2D_NUM_FACES;
|
return TEXTURE_2D_NUM_FACES;
|
||||||
case GL_TEXTURE_CUBE_MAP:
|
case GL_TEXTURE_CUBE_MAP:
|
||||||
return TEXTURE_CUBE_NUM_FACES;
|
return TEXTURE_CUBE_NUM_FACES;
|
||||||
|
@ -86,17 +91,22 @@ uint8_t GLTexture::getFaceCount(GLenum target) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const std::vector<GLenum>& GLTexture::getFaceTargets(GLenum target) {
|
const std::vector<GLenum>& GLTexture::getFaceTargets(GLenum target) {
|
||||||
static std::vector<GLenum> cubeFaceTargets {
|
static const std::vector<GLenum> cubeFaceTargets {
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
||||||
};
|
};
|
||||||
static std::vector<GLenum> faceTargets {
|
static const std::vector<GLenum> faceTargets {
|
||||||
GL_TEXTURE_2D
|
GL_TEXTURE_2D
|
||||||
};
|
};
|
||||||
|
static const std::vector<GLenum> arrayFaceTargets{
|
||||||
|
GL_TEXTURE_2D_ARRAY
|
||||||
|
};
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case GL_TEXTURE_2D:
|
case GL_TEXTURE_2D:
|
||||||
return faceTargets;
|
return faceTargets;
|
||||||
|
case GL_TEXTURE_2D_ARRAY:
|
||||||
|
return arrayFaceTargets;
|
||||||
case GL_TEXTURE_CUBE_MAP:
|
case GL_TEXTURE_CUBE_MAP:
|
||||||
return cubeFaceTargets;
|
return cubeFaceTargets;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -64,7 +64,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gltexture) {
|
if (gltexture) {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, gltexture->_texture, 0);
|
if (gltexture->_target == GL_TEXTURE_2D) {
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, gltexture->_texture, 0);
|
||||||
|
} else {
|
||||||
|
glFramebufferTextureLayer(GL_FRAMEBUFFER, colorAttachments[unit], gltexture->_texture, 0,
|
||||||
|
b._subresource);
|
||||||
|
}
|
||||||
_colorBuffers.push_back(colorAttachments[unit]);
|
_colorBuffers.push_back(colorAttachments[unit]);
|
||||||
} else {
|
} else {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, 0, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, 0, 0);
|
||||||
|
@ -91,7 +96,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gltexture) {
|
if (gltexture) {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0);
|
if (gltexture->_target == GL_TEXTURE_2D) {
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0);
|
||||||
|
} else {
|
||||||
|
glFramebufferTextureLayer(GL_FRAMEBUFFER, attachement, gltexture->_texture, 0,
|
||||||
|
_gpuObject.getDepthStencilBufferSubresource());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, 0, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ void GL41Texture::syncSampler() const {
|
||||||
glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
glTexParameteri(_target, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
||||||
|
|
||||||
if (sampler.doComparison()) {
|
if (sampler.doComparison()) {
|
||||||
glTexParameteri(_target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE_ARB);
|
glTexParameteri(_target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTexParameteri(_target, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
glTexParameteri(_target, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
||||||
} else {
|
} else {
|
||||||
glTexParameteri(_target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
glTexParameteri(_target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||||
|
@ -197,7 +197,7 @@ void GL41Texture::syncSampler() const {
|
||||||
glTexParameterf(_target, GL_TEXTURE_MIN_LOD, (float)sampler.getMinMip());
|
glTexParameterf(_target, GL_TEXTURE_MIN_LOD, (float)sampler.getMinMip());
|
||||||
glTexParameterf(_target, GL_TEXTURE_MAX_LOD, (sampler.getMaxMip() == Sampler::MAX_MIP_LEVEL ? 1000.f : sampler.getMaxMip()));
|
glTexParameterf(_target, GL_TEXTURE_MAX_LOD, (sampler.getMaxMip() == Sampler::MAX_MIP_LEVEL ? 1000.f : sampler.getMaxMip()));
|
||||||
|
|
||||||
glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, sampler.getMaxAnisotropy());
|
glTexParameterf(_target, GL_TEXTURE_MAX_ANISOTROPY, sampler.getMaxAnisotropy());
|
||||||
}
|
}
|
||||||
|
|
||||||
using GL41FixedAllocationTexture = GL41Backend::GL41FixedAllocationTexture;
|
using GL41FixedAllocationTexture = GL41Backend::GL41FixedAllocationTexture;
|
||||||
|
@ -215,12 +215,19 @@ GL41FixedAllocationTexture::~GL41FixedAllocationTexture() {
|
||||||
void GL41FixedAllocationTexture::allocateStorage() const {
|
void GL41FixedAllocationTexture::allocateStorage() const {
|
||||||
const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat());
|
const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat());
|
||||||
const auto numMips = _gpuObject.getNumMips();
|
const auto numMips = _gpuObject.getNumMips();
|
||||||
|
const auto numSlices = _gpuObject.getNumSlices();
|
||||||
|
|
||||||
// glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y);
|
// glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y);
|
||||||
for (GLint level = 0; level < numMips; level++) {
|
for (GLint level = 0; level < numMips; level++) {
|
||||||
Vec3u dimensions = _gpuObject.evalMipDimensions(level);
|
Vec3u dimensions = _gpuObject.evalMipDimensions(level);
|
||||||
for (GLenum target : getFaceTargets(_target)) {
|
for (GLenum target : getFaceTargets(_target)) {
|
||||||
glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format, texelFormat.type, nullptr);
|
if (!_gpuObject.isArray()) {
|
||||||
|
glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format,
|
||||||
|
texelFormat.type, nullptr);
|
||||||
|
} else {
|
||||||
|
glTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0,
|
||||||
|
texelFormat.format, texelFormat.type, nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gltexture) {
|
if (gltexture) {
|
||||||
glNamedFramebufferTexture(_id, colorAttachments[unit], gltexture->_texture, 0);
|
if (gltexture->_target == GL_TEXTURE_2D) {
|
||||||
|
glNamedFramebufferTexture(_id, colorAttachments[unit], gltexture->_texture, 0);
|
||||||
|
} else {
|
||||||
|
glNamedFramebufferTextureLayer(_id, colorAttachments[unit], gltexture->_texture, 0, b._subresource);
|
||||||
|
}
|
||||||
_colorBuffers.push_back(colorAttachments[unit]);
|
_colorBuffers.push_back(colorAttachments[unit]);
|
||||||
} else {
|
} else {
|
||||||
glNamedFramebufferTexture(_id, colorAttachments[unit], 0, 0);
|
glNamedFramebufferTexture(_id, colorAttachments[unit], 0, 0);
|
||||||
|
@ -87,14 +91,18 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gltexture) {
|
if (gltexture) {
|
||||||
glNamedFramebufferTexture(_id, attachement, gltexture->_texture, 0);
|
if (gltexture->_target == GL_TEXTURE_2D) {
|
||||||
|
glNamedFramebufferTexture(_id, attachement, gltexture->_texture, 0);
|
||||||
|
} else {
|
||||||
|
glNamedFramebufferTextureLayer(_id, attachement, gltexture->_texture, 0,
|
||||||
|
_gpuObject.getDepthStencilBufferSubresource());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glNamedFramebufferTexture(_id, attachement, 0, 0);
|
glNamedFramebufferTexture(_id, attachement, 0, 0);
|
||||||
}
|
}
|
||||||
_depthStamp = _gpuObject.getDepthStamp();
|
_depthStamp = _gpuObject.getDepthStamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Last but not least, define where we draw
|
// Last but not least, define where we draw
|
||||||
if (!_colorBuffers.empty()) {
|
if (!_colorBuffers.empty()) {
|
||||||
glNamedFramebufferDrawBuffers(_id, (GLsizei)_colorBuffers.size(), _colorBuffers.data());
|
glNamedFramebufferDrawBuffers(_id, (GLsizei)_colorBuffers.size(), _colorBuffers.data());
|
||||||
|
|
|
@ -152,7 +152,7 @@ public:
|
||||||
glSamplerParameteri(result, GL_TEXTURE_MIN_FILTER, fm.minFilter);
|
glSamplerParameteri(result, GL_TEXTURE_MIN_FILTER, fm.minFilter);
|
||||||
glSamplerParameteri(result, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
glSamplerParameteri(result, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
||||||
if (sampler.doComparison()) {
|
if (sampler.doComparison()) {
|
||||||
glSamplerParameteri(result, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE_ARB);
|
glSamplerParameteri(result, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glSamplerParameteri(result, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
glSamplerParameteri(result, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
||||||
} else {
|
} else {
|
||||||
glSamplerParameteri(result, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
glSamplerParameteri(result, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||||
|
@ -341,7 +341,7 @@ void GL45Texture::syncSampler() const {
|
||||||
glTextureParameteri(_id, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
glTextureParameteri(_id, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
||||||
|
|
||||||
if (sampler.doComparison()) {
|
if (sampler.doComparison()) {
|
||||||
glTextureParameteri(_id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE_ARB);
|
glTextureParameteri(_id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
glTextureParameteri(_id, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
glTextureParameteri(_id, GL_TEXTURE_COMPARE_FUNC, COMPARISON_TO_GL[sampler.getComparisonFunction()]);
|
||||||
} else {
|
} else {
|
||||||
glTextureParameteri(_id, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
glTextureParameteri(_id, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||||
|
@ -374,8 +374,13 @@ void GL45FixedAllocationTexture::allocateStorage() const {
|
||||||
const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat());
|
const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat());
|
||||||
const auto dimensions = _gpuObject.getDimensions();
|
const auto dimensions = _gpuObject.getDimensions();
|
||||||
const auto mips = _gpuObject.getNumMips();
|
const auto mips = _gpuObject.getNumMips();
|
||||||
|
const auto numSlices = _gpuObject.getNumSlices();
|
||||||
|
|
||||||
glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y);
|
if (!_gpuObject.isArray()) {
|
||||||
|
glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y);
|
||||||
|
} else {
|
||||||
|
glTextureStorage3D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices);
|
||||||
|
}
|
||||||
|
|
||||||
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, 0);
|
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, 0);
|
||||||
glTextureParameteri(_id, GL_TEXTURE_MAX_LEVEL, mips - 1);
|
glTextureParameteri(_id, GL_TEXTURE_MAX_LEVEL, mips - 1);
|
||||||
|
|
|
@ -64,7 +64,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gltexture) {
|
if (gltexture) {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, gltexture->_texture, 0);
|
if (gltexture->_target == GL_TEXTURE_2D) {
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, gltexture->_texture, 0);
|
||||||
|
} else {
|
||||||
|
glFramebufferTextureLayer(GL_FRAMEBUFFER, colorAttachments[unit], gltexture->_texture, 0,
|
||||||
|
b._subresource);
|
||||||
|
}
|
||||||
_colorBuffers.push_back(colorAttachments[unit]);
|
_colorBuffers.push_back(colorAttachments[unit]);
|
||||||
} else {
|
} else {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, 0, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[unit], GL_TEXTURE_2D, 0, 0);
|
||||||
|
@ -91,7 +96,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gltexture) {
|
if (gltexture) {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0);
|
if (gltexture->_target == GL_TEXTURE_2D) {
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0);
|
||||||
|
} else {
|
||||||
|
glFramebufferTextureLayer(GL_FRAMEBUFFER, attachement, gltexture->_texture, 0,
|
||||||
|
_gpuObject.getDepthStencilBufferSubresource());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, 0, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,16 +268,27 @@ GLsizei getCompressedImageSize(int width, int height, GLenum internalFormat) {
|
||||||
void GLESFixedAllocationTexture::allocateStorage() const {
|
void GLESFixedAllocationTexture::allocateStorage() const {
|
||||||
const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat());
|
const GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat());
|
||||||
const auto numMips = _gpuObject.getNumMips();
|
const auto numMips = _gpuObject.getNumMips();
|
||||||
|
const auto numSlices = _gpuObject.getNumSlices();
|
||||||
|
|
||||||
// glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y);
|
// glTextureStorage2D(_id, mips, texelFormat.internalFormat, dimensions.x, dimensions.y);
|
||||||
for (GLint level = 0; level < numMips; level++) {
|
for (GLint level = 0; level < numMips; level++) {
|
||||||
Vec3u dimensions = _gpuObject.evalMipDimensions(level);
|
Vec3u dimensions = _gpuObject.evalMipDimensions(level);
|
||||||
for (GLenum target : getFaceTargets(_target)) {
|
for (GLenum target : getFaceTargets(_target)) {
|
||||||
if (texelFormat.isCompressed()) {
|
if (texelFormat.isCompressed()) {
|
||||||
glCompressedTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0,
|
auto size = getCompressedImageSize(dimensions.x, dimensions.y, texelFormat.internalFormat);
|
||||||
getCompressedImageSize(dimensions.x, dimensions.y, texelFormat.internalFormat), nullptr);
|
if (!_gpuObject.isArray()) {
|
||||||
|
glCompressedTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, size, nullptr);
|
||||||
|
} else {
|
||||||
|
glCompressedTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0, size * numSlices, nullptr);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format, texelFormat.type, nullptr);
|
if (!_gpuObject.isArray()) {
|
||||||
|
glTexImage2D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, 0, texelFormat.format,
|
||||||
|
texelFormat.type, nullptr);
|
||||||
|
} else {
|
||||||
|
glTexImage3D(target, level, texelFormat.internalFormat, dimensions.x, dimensions.y, numSlices, 0,
|
||||||
|
texelFormat.format, texelFormat.type, nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,10 @@ TexturePointer Texture::createRenderBuffer(const Element& texelFormat, uint16 wi
|
||||||
return create(TextureUsageType::RENDERBUFFER, TEX_2D, texelFormat, width, height, 1, 1, 0, numMips, sampler);
|
return create(TextureUsageType::RENDERBUFFER, TEX_2D, texelFormat, width, height, 1, 1, 0, numMips, sampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TexturePointer Texture::createRenderBufferArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numMips, const Sampler& sampler) {
|
||||||
|
return create(TextureUsageType::RENDERBUFFER, TEX_2D, texelFormat, width, height, 1, 1, numSlices, numMips, sampler);
|
||||||
|
}
|
||||||
|
|
||||||
TexturePointer Texture::create1D(const Element& texelFormat, uint16 width, uint16 numMips, const Sampler& sampler) {
|
TexturePointer Texture::create1D(const Element& texelFormat, uint16 width, uint16 numMips, const Sampler& sampler) {
|
||||||
return create(TextureUsageType::RESOURCE, TEX_1D, texelFormat, width, 1, 1, 1, 0, numMips, sampler);
|
return create(TextureUsageType::RESOURCE, TEX_1D, texelFormat, width, 1, 1, 1, 0, numMips, sampler);
|
||||||
}
|
}
|
||||||
|
@ -192,6 +196,10 @@ TexturePointer Texture::create2D(const Element& texelFormat, uint16 width, uint1
|
||||||
return create(TextureUsageType::RESOURCE, TEX_2D, texelFormat, width, height, 1, 1, 0, numMips, sampler);
|
return create(TextureUsageType::RESOURCE, TEX_2D, texelFormat, width, height, 1, 1, 0, numMips, sampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TexturePointer Texture::create2DArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numMips, const Sampler& sampler) {
|
||||||
|
return create(TextureUsageType::STRICT_RESOURCE, TEX_2D, texelFormat, width, height, 1, 1, numSlices, numMips, sampler);
|
||||||
|
}
|
||||||
|
|
||||||
TexturePointer Texture::createStrict(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips, const Sampler& sampler) {
|
TexturePointer Texture::createStrict(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips, const Sampler& sampler) {
|
||||||
return create(TextureUsageType::STRICT_RESOURCE, TEX_2D, texelFormat, width, height, 1, 1, 0, numMips, sampler);
|
return create(TextureUsageType::STRICT_RESOURCE, TEX_2D, texelFormat, width, height, 1, 1, 0, numMips, sampler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,9 +374,11 @@ public:
|
||||||
static const uint16 SINGLE_MIP = 1;
|
static const uint16 SINGLE_MIP = 1;
|
||||||
static TexturePointer create1D(const Element& texelFormat, uint16 width, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
static TexturePointer create1D(const Element& texelFormat, uint16 width, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
||||||
static TexturePointer create2D(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
static TexturePointer create2D(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
||||||
|
static TexturePointer create2DArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
||||||
static TexturePointer create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
static TexturePointer create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
||||||
static TexturePointer createCube(const Element& texelFormat, uint16 width, uint16 numMips = 1, const Sampler& sampler = Sampler());
|
static TexturePointer createCube(const Element& texelFormat, uint16 width, uint16 numMips = 1, const Sampler& sampler = Sampler());
|
||||||
static TexturePointer createRenderBuffer(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
static TexturePointer createRenderBuffer(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
||||||
|
static TexturePointer createRenderBufferArray(const Element& texelFormat, uint16 width, uint16 height, uint16 numSlices, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
||||||
static TexturePointer createStrict(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
static TexturePointer createStrict(const Element& texelFormat, uint16 width, uint16 height, uint16 numMips = SINGLE_MIP, const Sampler& sampler = Sampler());
|
||||||
static TexturePointer createExternal(const ExternalRecycler& recycler, const Sampler& sampler = Sampler());
|
static TexturePointer createExternal(const ExternalRecycler& recycler, const Sampler& sampler = Sampler());
|
||||||
|
|
||||||
|
|
|
@ -515,7 +515,7 @@ TexturePointer Texture::build(const ktx::KTXDescriptor& descriptor) {
|
||||||
header.getPixelHeight(),
|
header.getPixelHeight(),
|
||||||
header.getPixelDepth(),
|
header.getPixelDepth(),
|
||||||
1, // num Samples
|
1, // num Samples
|
||||||
header.getNumberOfSlices(),
|
header.isArray() ? header.getNumberOfSlices() : 0,
|
||||||
header.getNumberOfLevels(),
|
header.getNumberOfLevels(),
|
||||||
samplerDesc);
|
samplerDesc);
|
||||||
texture->setUsage(gpuktxKeyValue._usage);
|
texture->setUsage(gpuktxKeyValue._usage);
|
||||||
|
|
|
@ -163,6 +163,7 @@ namespace ktx {
|
||||||
uint32_t getPixelDepth() const { return (pixelDepth ? pixelDepth : 1); }
|
uint32_t getPixelDepth() const { return (pixelDepth ? pixelDepth : 1); }
|
||||||
uint32_t getNumberOfSlices() const { return (numberOfArrayElements ? numberOfArrayElements : 1); }
|
uint32_t getNumberOfSlices() const { return (numberOfArrayElements ? numberOfArrayElements : 1); }
|
||||||
uint32_t getNumberOfLevels() const { return (numberOfMipmapLevels ? numberOfMipmapLevels : 1); }
|
uint32_t getNumberOfLevels() const { return (numberOfMipmapLevels ? numberOfMipmapLevels : 1); }
|
||||||
|
bool isArray() const { return numberOfArrayElements > 0; }
|
||||||
bool isCompressed() const { return glFormat == COMPRESSED_FORMAT; }
|
bool isCompressed() const { return glFormat == COMPRESSED_FORMAT; }
|
||||||
|
|
||||||
uint32_t evalMaxDimension() const;
|
uint32_t evalMaxDimension() const;
|
||||||
|
|
|
@ -60,7 +60,8 @@ enum TextureSlot {
|
||||||
enum ParamSlot {
|
enum ParamSlot {
|
||||||
CameraCorrection = 0,
|
CameraCorrection = 0,
|
||||||
DeferredFrameTransform,
|
DeferredFrameTransform,
|
||||||
ShadowTransform
|
ShadowTransform,
|
||||||
|
DebugParametersBuffer
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string DEFAULT_ALBEDO_SHADER {
|
static const std::string DEFAULT_ALBEDO_SHADER {
|
||||||
|
@ -139,12 +140,11 @@ static const std::string DEFAULT_LIGHTING_SHADER {
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string DEFAULT_SHADOW_SHADER{
|
static const std::string DEFAULT_SHADOW_DEPTH_SHADER{
|
||||||
"uniform sampler2DShadow shadowMap;"
|
|
||||||
"vec4 getFragmentColor() {"
|
"vec4 getFragmentColor() {"
|
||||||
" for (int i = 255; i >= 0; --i) {"
|
" for (int i = 255; i >= 0; --i) {"
|
||||||
" float depth = i / 255.0;"
|
" float depth = i / 255.0;"
|
||||||
" if (texture(shadowMap, vec3(uv, depth)) > 0.5) {"
|
" if (texture(shadowMaps, vec4(uv, parameters._shadowCascadeIndex, depth)) > 0.5) {"
|
||||||
" return vec4(vec3(depth), 1.0);"
|
" return vec4(vec3(depth), 1.0);"
|
||||||
" }"
|
" }"
|
||||||
" }"
|
" }"
|
||||||
|
@ -323,7 +323,7 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust
|
||||||
case ShadowCascade1Mode:
|
case ShadowCascade1Mode:
|
||||||
case ShadowCascade2Mode:
|
case ShadowCascade2Mode:
|
||||||
case ShadowCascade3Mode:
|
case ShadowCascade3Mode:
|
||||||
return DEFAULT_SHADOW_SHADER;
|
return DEFAULT_SHADOW_DEPTH_SHADER;
|
||||||
case ShadowCascadeIndicesMode:
|
case ShadowCascadeIndicesMode:
|
||||||
return DEFAULT_SHADOW_CASCADE_SHADER;
|
return DEFAULT_SHADOW_CASCADE_SHADER;
|
||||||
case LinearDepthMode:
|
case LinearDepthMode:
|
||||||
|
@ -396,6 +396,7 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Mode mode, std::str
|
||||||
slotBindings.insert(gpu::Shader::Binding("cameraCorrectionBuffer", CameraCorrection));
|
slotBindings.insert(gpu::Shader::Binding("cameraCorrectionBuffer", CameraCorrection));
|
||||||
slotBindings.insert(gpu::Shader::Binding("deferredFrameTransformBuffer", DeferredFrameTransform));
|
slotBindings.insert(gpu::Shader::Binding("deferredFrameTransformBuffer", DeferredFrameTransform));
|
||||||
slotBindings.insert(gpu::Shader::Binding("shadowTransformBuffer", ShadowTransform));
|
slotBindings.insert(gpu::Shader::Binding("shadowTransformBuffer", ShadowTransform));
|
||||||
|
slotBindings.insert(gpu::Shader::Binding("parametersBuffer", DebugParametersBuffer));
|
||||||
|
|
||||||
slotBindings.insert(gpu::Shader::Binding("albedoMap", Albedo));
|
slotBindings.insert(gpu::Shader::Binding("albedoMap", Albedo));
|
||||||
slotBindings.insert(gpu::Shader::Binding("normalMap", Normal));
|
slotBindings.insert(gpu::Shader::Binding("normalMap", Normal));
|
||||||
|
@ -403,7 +404,7 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Mode mode, std::str
|
||||||
slotBindings.insert(gpu::Shader::Binding("depthMap", Depth));
|
slotBindings.insert(gpu::Shader::Binding("depthMap", Depth));
|
||||||
slotBindings.insert(gpu::Shader::Binding("obscuranceMap", AmbientOcclusion));
|
slotBindings.insert(gpu::Shader::Binding("obscuranceMap", AmbientOcclusion));
|
||||||
slotBindings.insert(gpu::Shader::Binding("lightingMap", Lighting));
|
slotBindings.insert(gpu::Shader::Binding("lightingMap", Lighting));
|
||||||
slotBindings.insert(gpu::Shader::Binding("shadowMap", Shadow));
|
slotBindings.insert(gpu::Shader::Binding("shadowMaps", Shadow));
|
||||||
slotBindings.insert(gpu::Shader::Binding("linearDepthMap", LinearDepth));
|
slotBindings.insert(gpu::Shader::Binding("linearDepthMap", LinearDepth));
|
||||||
slotBindings.insert(gpu::Shader::Binding("halfLinearDepthMap", HalfLinearDepth));
|
slotBindings.insert(gpu::Shader::Binding("halfLinearDepthMap", HalfLinearDepth));
|
||||||
slotBindings.insert(gpu::Shader::Binding("halfNormalMap", HalfNormal));
|
slotBindings.insert(gpu::Shader::Binding("halfNormalMap", HalfNormal));
|
||||||
|
@ -432,8 +433,11 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Mode mode, std::str
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugDeferredBuffer::configure(const Config& config) {
|
void DebugDeferredBuffer::configure(const Config& config) {
|
||||||
|
auto& parameters = _parameters.edit();
|
||||||
|
|
||||||
_mode = (Mode)config.mode;
|
_mode = (Mode)config.mode;
|
||||||
_size = config.size;
|
_size = config.size;
|
||||||
|
parameters._shadowCascadeIndex = glm::clamp(_mode - Mode::ShadowCascade0Mode, 0, (int)SHADOW_CASCADE_MAX_COUNT - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const Inputs& inputs) {
|
void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const Inputs& inputs) {
|
||||||
|
@ -483,14 +487,15 @@ void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const I
|
||||||
batch.setResourceTexture(Velocity, velocityFramebuffer->getVelocityTexture());
|
batch.setResourceTexture(Velocity, velocityFramebuffer->getVelocityTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
batch.setUniformBuffer(DebugParametersBuffer, _parameters);
|
||||||
|
|
||||||
auto lightStage = renderContext->_scene->getStage<LightStage>();
|
auto lightStage = renderContext->_scene->getStage<LightStage>();
|
||||||
assert(lightStage);
|
assert(lightStage);
|
||||||
assert(lightStage->getNumLights() > 0);
|
assert(lightStage->getNumLights() > 0);
|
||||||
auto lightAndShadow = lightStage->getCurrentKeyLightAndShadow();
|
auto lightAndShadow = lightStage->getCurrentKeyLightAndShadow();
|
||||||
const auto& globalShadow = lightAndShadow.second;
|
const auto& globalShadow = lightAndShadow.second;
|
||||||
if (globalShadow) {
|
if (globalShadow) {
|
||||||
const auto cascadeIndex = glm::clamp(_mode - Mode::ShadowCascade0Mode, 0, (int)globalShadow->getCascadeCount() - 1);
|
batch.setResourceTexture(Shadow, globalShadow->map);
|
||||||
batch.setResourceTexture(Shadow, globalShadow->getCascade(cascadeIndex).map);
|
|
||||||
batch.setUniformBuffer(ShadowTransform, globalShadow->getBuffer());
|
batch.setUniformBuffer(ShadowTransform, globalShadow->getBuffer());
|
||||||
batch.setUniformBuffer(DeferredFrameTransform, frameTransform->getFrameTransformBuffer());
|
batch.setUniformBuffer(DeferredFrameTransform, frameTransform->getFrameTransformBuffer());
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
DebugDeferredBufferConfig() : render::Job::Config(false) {}
|
DebugDeferredBufferConfig() : render::Job::Config(false) {}
|
||||||
|
|
||||||
void setMode(int newMode);
|
void setMode(int newMode);
|
||||||
|
|
||||||
int mode{ 0 };
|
int mode{ 0 };
|
||||||
glm::vec4 size{ 0.0f, -1.0f, 1.0f, 1.0f };
|
glm::vec4 size{ 0.0f, -1.0f, 1.0f, 1.0f };
|
||||||
signals:
|
signals:
|
||||||
|
@ -39,20 +39,26 @@ signals:
|
||||||
|
|
||||||
class DebugDeferredBuffer {
|
class DebugDeferredBuffer {
|
||||||
public:
|
public:
|
||||||
using Inputs = render::VaryingSet6<DeferredFramebufferPointer, LinearDepthFramebufferPointer, SurfaceGeometryFramebufferPointer, AmbientOcclusionFramebufferPointer, VelocityFramebufferPointer, DeferredFrameTransformPointer>;
|
using Inputs = render::VaryingSet6<DeferredFramebufferPointer,
|
||||||
|
LinearDepthFramebufferPointer,
|
||||||
|
SurfaceGeometryFramebufferPointer,
|
||||||
|
AmbientOcclusionFramebufferPointer,
|
||||||
|
VelocityFramebufferPointer,
|
||||||
|
DeferredFrameTransformPointer>;
|
||||||
using Config = DebugDeferredBufferConfig;
|
using Config = DebugDeferredBufferConfig;
|
||||||
using JobModel = render::Job::ModelI<DebugDeferredBuffer, Inputs, Config>;
|
using JobModel = render::Job::ModelI<DebugDeferredBuffer, Inputs, Config>;
|
||||||
|
|
||||||
DebugDeferredBuffer();
|
DebugDeferredBuffer();
|
||||||
~DebugDeferredBuffer();
|
~DebugDeferredBuffer();
|
||||||
|
|
||||||
void configure(const Config& config);
|
void configure(const Config& config);
|
||||||
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
|
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class DebugDeferredBufferConfig;
|
friend class DebugDeferredBufferConfig;
|
||||||
|
|
||||||
enum Mode : uint8_t {
|
enum Mode : uint8_t
|
||||||
|
{
|
||||||
// Use Mode suffix to avoid collisions
|
// Use Mode suffix to avoid collisions
|
||||||
Off = 0,
|
Off = 0,
|
||||||
DepthMode,
|
DepthMode,
|
||||||
|
@ -83,7 +89,7 @@ protected:
|
||||||
AmbientOcclusionMode,
|
AmbientOcclusionMode,
|
||||||
AmbientOcclusionBlurredMode,
|
AmbientOcclusionBlurredMode,
|
||||||
VelocityMode,
|
VelocityMode,
|
||||||
CustomMode, // Needs to stay last
|
CustomMode, // Needs to stay last
|
||||||
|
|
||||||
NumModes,
|
NumModes,
|
||||||
};
|
};
|
||||||
|
@ -92,20 +98,25 @@ private:
|
||||||
Mode _mode{ Off };
|
Mode _mode{ Off };
|
||||||
glm::vec4 _size;
|
glm::vec4 _size;
|
||||||
|
|
||||||
|
#include "debug_deferred_buffer_shared.slh"
|
||||||
|
|
||||||
|
using ParametersBuffer = gpu::StructBuffer<DebugParameters>;
|
||||||
|
|
||||||
struct CustomPipeline {
|
struct CustomPipeline {
|
||||||
gpu::PipelinePointer pipeline;
|
gpu::PipelinePointer pipeline;
|
||||||
mutable QFileInfo info;
|
mutable QFileInfo info;
|
||||||
};
|
};
|
||||||
using StandardPipelines = std::array<gpu::PipelinePointer, NumModes>;
|
using StandardPipelines = std::array<gpu::PipelinePointer, NumModes>;
|
||||||
using CustomPipelines = std::unordered_map<std::string, CustomPipeline>;
|
using CustomPipelines = std::unordered_map<std::string, CustomPipeline>;
|
||||||
|
|
||||||
bool pipelineNeedsUpdate(Mode mode, std::string customFile = std::string()) const;
|
bool pipelineNeedsUpdate(Mode mode, std::string customFile = std::string()) const;
|
||||||
const gpu::PipelinePointer& getPipeline(Mode mode, std::string customFile = std::string());
|
const gpu::PipelinePointer& getPipeline(Mode mode, std::string customFile = std::string());
|
||||||
std::string getShaderSourceCode(Mode mode, std::string customFile = std::string());
|
std::string getShaderSourceCode(Mode mode, std::string customFile = std::string());
|
||||||
|
|
||||||
|
ParametersBuffer _parameters;
|
||||||
StandardPipelines _pipelines;
|
StandardPipelines _pipelines;
|
||||||
CustomPipelines _customPipelines;
|
CustomPipelines _customPipelines;
|
||||||
int _geometryId { 0 };
|
int _geometryId{ 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_DebugDeferredBuffer_h
|
#endif // hifi_DebugDeferredBuffer_h
|
|
@ -68,7 +68,7 @@ enum DeferredShader_MapSlot {
|
||||||
SCATTERING_SPECULAR_UNIT = 9,
|
SCATTERING_SPECULAR_UNIT = 9,
|
||||||
SKYBOX_MAP_UNIT = render::ShapePipeline::Slot::LIGHT_AMBIENT_MAP, // unit = 10
|
SKYBOX_MAP_UNIT = render::ShapePipeline::Slot::LIGHT_AMBIENT_MAP, // unit = 10
|
||||||
SHADOW_MAP_UNIT = 11,
|
SHADOW_MAP_UNIT = 11,
|
||||||
nextAvailableUnit = SHADOW_MAP_UNIT + SHADOW_CASCADE_MAX_COUNT
|
nextAvailableUnit = SHADOW_MAP_UNIT
|
||||||
};
|
};
|
||||||
enum DeferredShader_BufferSlot {
|
enum DeferredShader_BufferSlot {
|
||||||
DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT = 0,
|
DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT = 0,
|
||||||
|
@ -534,9 +534,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext,
|
||||||
|
|
||||||
// Bind the shadow buffers
|
// Bind the shadow buffers
|
||||||
if (globalShadow) {
|
if (globalShadow) {
|
||||||
for (unsigned int i = 0; i < globalShadow->getCascadeCount(); i++) {
|
batch.setResourceTexture(SHADOW_MAP_UNIT, globalShadow->map);
|
||||||
batch.setResourceTexture(SHADOW_MAP_UNIT+i, globalShadow->getCascade(i).map);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto program = deferredLightingEffect->_directionalSkyboxLight;
|
auto program = deferredLightingEffect->_directionalSkyboxLight;
|
||||||
|
|
|
@ -74,8 +74,6 @@ LightStage::Shadow::Cascade::Cascade() :
|
||||||
_frustum{ std::make_shared<ViewFrustum>() },
|
_frustum{ std::make_shared<ViewFrustum>() },
|
||||||
_minDistance{ 0.0f },
|
_minDistance{ 0.0f },
|
||||||
_maxDistance{ 20.0f } {
|
_maxDistance{ 20.0f } {
|
||||||
framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::createShadowmap(MAP_SIZE));
|
|
||||||
map = framebuffer->getDepthStencilBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::mat4& LightStage::Shadow::Cascade::getView() const {
|
const glm::mat4& LightStage::Shadow::Cascade::getView() const {
|
||||||
|
@ -127,8 +125,29 @@ LightStage::Shadow::Shadow(graphics::LightPointer light, float maxDistance, unsi
|
||||||
Schema schema;
|
Schema schema;
|
||||||
schema.cascadeCount = cascadeCount;
|
schema.cascadeCount = cascadeCount;
|
||||||
_schemaBuffer = std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema);
|
_schemaBuffer = std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema);
|
||||||
|
|
||||||
|
// Create shadow cascade texture array
|
||||||
|
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); // Depth32 texel format
|
||||||
|
map = gpu::TexturePointer(gpu::Texture::createRenderBufferArray(depthFormat, MAP_SIZE, MAP_SIZE, cascadeCount));
|
||||||
|
gpu::Sampler::Desc samplerDesc;
|
||||||
|
samplerDesc._borderColor = glm::vec4(1.0f);
|
||||||
|
samplerDesc._wrapModeU = gpu::Sampler::WRAP_BORDER;
|
||||||
|
samplerDesc._wrapModeV = gpu::Sampler::WRAP_BORDER;
|
||||||
|
samplerDesc._filter = gpu::Sampler::FILTER_MIN_MAG_LINEAR;
|
||||||
|
samplerDesc._comparisonFunc = gpu::LESS;
|
||||||
|
|
||||||
|
map->setSampler(gpu::Sampler(samplerDesc));
|
||||||
|
|
||||||
_cascades.resize(cascadeCount);
|
_cascades.resize(cascadeCount);
|
||||||
|
|
||||||
|
for (uint cascadeIndex=0; cascadeIndex < cascadeCount; cascadeIndex++) {
|
||||||
|
auto& cascade = _cascades[cascadeIndex];
|
||||||
|
std::string name = "Shadowmap Cascade ";
|
||||||
|
name += '0' + cascadeIndex;
|
||||||
|
cascade.framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create(name));
|
||||||
|
cascade.framebuffer->setDepthBuffer(map, depthFormat, cascadeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
setMaxDistance(maxDistance);
|
setMaxDistance(maxDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ public:
|
||||||
Cascade();
|
Cascade();
|
||||||
|
|
||||||
gpu::FramebufferPointer framebuffer;
|
gpu::FramebufferPointer framebuffer;
|
||||||
gpu::TexturePointer map;
|
|
||||||
|
|
||||||
const std::shared_ptr<ViewFrustum>& getFrustum() const { return _frustum; }
|
const std::shared_ptr<ViewFrustum>& getFrustum() const { return _frustum; }
|
||||||
|
|
||||||
|
@ -93,6 +92,8 @@ public:
|
||||||
|
|
||||||
const graphics::LightPointer& getLight() const { return _light; }
|
const graphics::LightPointer& getLight() const { return _light; }
|
||||||
|
|
||||||
|
gpu::TexturePointer map;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
#include "Shadows_shared.slh"
|
#include "Shadows_shared.slh"
|
||||||
|
|
|
@ -227,7 +227,7 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto setupOutput = task.addJob<RenderShadowSetup>("ShadowSetup");
|
const auto setupOutput = task.addJob<RenderShadowSetup>("ShadowSetup");
|
||||||
const auto queryResolution = setupOutput.getN<RenderShadowSetup::Outputs>(2);
|
const auto queryResolution = setupOutput.getN<RenderShadowSetup::Outputs>(1);
|
||||||
// Fetch and cull the items from the scene
|
// Fetch and cull the items from the scene
|
||||||
|
|
||||||
static const auto shadowCasterReceiverFilter = ItemFilter::Builder::visibleWorldItems().withTypeShape().withOpaque().withoutLayered().withTagBits(tagBits, tagMask);
|
static const auto shadowCasterReceiverFilter = ItemFilter::Builder::visibleWorldItems().withTypeShape().withOpaque().withoutLayered().withTagBits(tagBits, tagMask);
|
||||||
|
@ -248,10 +248,12 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende
|
||||||
const auto sortedShapes = task.addJob<DepthSortShapes>("DepthSortShadow", sortedPipelines, true);
|
const auto sortedShapes = task.addJob<DepthSortShapes>("DepthSortShadow", sortedPipelines, true);
|
||||||
|
|
||||||
render::Varying cascadeFrustums[SHADOW_CASCADE_MAX_COUNT] = {
|
render::Varying cascadeFrustums[SHADOW_CASCADE_MAX_COUNT] = {
|
||||||
ViewFrustumPointer(),
|
ViewFrustumPointer()
|
||||||
ViewFrustumPointer(),
|
#if SHADOW_CASCADE_MAX_COUNT>1
|
||||||
|
,ViewFrustumPointer(),
|
||||||
ViewFrustumPointer(),
|
ViewFrustumPointer(),
|
||||||
ViewFrustumPointer()
|
ViewFrustumPointer()
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) {
|
for (auto i = 0; i < SHADOW_CASCADE_MAX_COUNT; i++) {
|
||||||
|
@ -293,13 +295,15 @@ RenderShadowSetup::RenderShadowSetup() :
|
||||||
|
|
||||||
void RenderShadowSetup::configure(const Config& configuration) {
|
void RenderShadowSetup::configure(const Config& configuration) {
|
||||||
setConstantBias(0, configuration.constantBias0);
|
setConstantBias(0, configuration.constantBias0);
|
||||||
setConstantBias(1, configuration.constantBias1);
|
|
||||||
setConstantBias(2, configuration.constantBias2);
|
|
||||||
setConstantBias(3, configuration.constantBias3);
|
|
||||||
setSlopeBias(0, configuration.slopeBias0);
|
setSlopeBias(0, configuration.slopeBias0);
|
||||||
|
#if SHADOW_CASCADE_MAX_COUNT>1
|
||||||
|
setConstantBias(1, configuration.constantBias1);
|
||||||
setSlopeBias(1, configuration.slopeBias1);
|
setSlopeBias(1, configuration.slopeBias1);
|
||||||
|
setConstantBias(2, configuration.constantBias2);
|
||||||
setSlopeBias(2, configuration.slopeBias2);
|
setSlopeBias(2, configuration.slopeBias2);
|
||||||
|
setConstantBias(3, configuration.constantBias3);
|
||||||
setSlopeBias(3, configuration.slopeBias3);
|
setSlopeBias(3, configuration.slopeBias3);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderShadowSetup::setConstantBias(int cascadeIndex, float value) {
|
void RenderShadowSetup::setConstantBias(int cascadeIndex, float value) {
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
#define SHADOW_SCREEN_SPACE_DITHER 1
|
#define SHADOW_SCREEN_SPACE_DITHER 1
|
||||||
|
|
||||||
// the shadow texture
|
// the shadow texture
|
||||||
uniform sampler2DShadow shadowMaps[SHADOW_CASCADE_MAX_COUNT];
|
uniform sampler2DArrayShadow shadowMaps;
|
||||||
|
|
||||||
// Sample the shadowMap with PCF (built-in)
|
// Sample the shadowMap with PCF (built-in)
|
||||||
float fetchShadow(int cascadeIndex, vec3 shadowTexcoord) {
|
float fetchShadow(int cascadeIndex, vec3 shadowTexcoord) {
|
||||||
return texture(shadowMaps[cascadeIndex], shadowTexcoord);
|
return texture(shadowMaps, vec4(shadowTexcoord.xy, cascadeIndex, shadowTexcoord.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 PCFkernel[4] = vec2[4](
|
vec2 PCFkernel[4] = vec2[4](
|
||||||
|
|
|
@ -23,11 +23,18 @@ uniform sampler2D occlusionMap;
|
||||||
uniform sampler2D occlusionBlurredMap;
|
uniform sampler2D occlusionBlurredMap;
|
||||||
uniform sampler2D scatteringMap;
|
uniform sampler2D scatteringMap;
|
||||||
uniform sampler2D velocityMap;
|
uniform sampler2D velocityMap;
|
||||||
|
uniform sampler2DArrayShadow shadowMaps;
|
||||||
|
|
||||||
<@include ShadowCore.slh@>
|
<@include ShadowCore.slh@>
|
||||||
|
|
||||||
<$declareDeferredCurvature()$>
|
<$declareDeferredCurvature()$>
|
||||||
|
|
||||||
|
<@include debug_deferred_buffer_shared.slh@>
|
||||||
|
|
||||||
|
layout(std140) uniform parametersBuffer {
|
||||||
|
DebugParameters parameters;
|
||||||
|
};
|
||||||
|
|
||||||
float curvatureAO(float k) {
|
float curvatureAO(float k) {
|
||||||
return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369f;
|
return 1.0f - (0.0022f * k * k) + (0.0776f * k) + 0.7369f;
|
||||||
}
|
}
|
||||||
|
|
17
libraries/render-utils/src/debug_deferred_buffer_shared.slh
Normal file
17
libraries/render-utils/src/debug_deferred_buffer_shared.slh
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// glsl / C++ compatible source as interface for FadeEffect
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# define INT32 glm::int32
|
||||||
|
#else
|
||||||
|
# define INT32 int
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct DebugParameters
|
||||||
|
{
|
||||||
|
INT32 _shadowCascadeIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
// <@if 1@>
|
||||||
|
// Trigger Scribe include
|
||||||
|
// <@endif@> <!def that !>
|
||||||
|
//
|
||||||
|
|
|
@ -370,10 +370,13 @@ void CullShapeBounds::run(const RenderContextPointer& renderContext, const Input
|
||||||
const auto& inShapes = inputs.get0();
|
const auto& inShapes = inputs.get0();
|
||||||
const auto& cullFilter = inputs.get1();
|
const auto& cullFilter = inputs.get1();
|
||||||
const auto& boundsFilter = inputs.get2();
|
const auto& boundsFilter = inputs.get2();
|
||||||
const auto& antiFrustum = inputs.get3();
|
ViewFrustumPointer antiFrustum;
|
||||||
auto& outShapes = outputs.edit0();
|
auto& outShapes = outputs.edit0();
|
||||||
auto& outBounds = outputs.edit1();
|
auto& outBounds = outputs.edit1();
|
||||||
|
|
||||||
|
if (!inputs[3].isNull()) {
|
||||||
|
antiFrustum = inputs.get3();
|
||||||
|
}
|
||||||
outShapes.clear();
|
outShapes.clear();
|
||||||
outBounds = AABox();
|
outBounds = AABox();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue