mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 02:17:11 +02:00
Merge pull request #13881 from jherico/feature/no_uniforms
Remove all uniforms from our shaders
This commit is contained in:
commit
ae547f8950
80 changed files with 570 additions and 471 deletions
|
@ -9,7 +9,6 @@
|
|||
#
|
||||
|
||||
macro(AUTOSCRIBE_SHADER)
|
||||
message(STATUS "Processing shader ${SHADER_FILE}")
|
||||
unset(SHADER_INCLUDE_FILES)
|
||||
# Grab include files
|
||||
foreach(includeFile ${ARGN})
|
||||
|
|
|
@ -8,6 +8,5 @@
|
|||
macro(TARGET_JSON)
|
||||
add_dependency_external_projects(json)
|
||||
find_package(JSON REQUIRED)
|
||||
message("JSON_INCLUDE_DIRS ${JSON_INCLUDE_DIRS}")
|
||||
target_include_directories(${TARGET_NAME} PUBLIC ${JSON_INCLUDE_DIRS})
|
||||
endmacro()
|
|
@ -2664,6 +2664,10 @@ Application::~Application() {
|
|||
void Application::initializeGL() {
|
||||
qCDebug(interfaceapp) << "Created Display Window.";
|
||||
|
||||
#ifdef DISABLE_QML
|
||||
setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
|
||||
#endif
|
||||
|
||||
// initialize glut for shape drawing; Qt apparently initializes it on OS X
|
||||
if (_isGLInitialized) {
|
||||
return;
|
||||
|
@ -6872,6 +6876,9 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
|||
shortName = shortName.mid(startIndex, endIndex - startIndex);
|
||||
}
|
||||
|
||||
#ifdef DISABLE_QML
|
||||
DependencyManager::get<ScriptEngines>()->loadScript(scriptFilenameOrURL);
|
||||
#else
|
||||
QString message = "Would you like to run this script:\n" + shortName;
|
||||
ModalDialogListener* dlg = OffscreenUi::asyncQuestion(getWindow(), "Run Script", message,
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
@ -6886,7 +6893,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
|||
}
|
||||
QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
|
||||
});
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ layout(location=0) in vec2 varTexCoord0;
|
|||
layout(location=0) out vec4 outFragColor;
|
||||
|
||||
void main(void) {
|
||||
ivec2 texCoord = ivec2(floor(varTexCoord0 * textureData.textureSize));
|
||||
ivec2 texCoord = ivec2(floor(varTexCoord0 * vec2(textureData.textureSize)));
|
||||
texCoord.x /= 2;
|
||||
int row = int(floor(gl_FragCoord.y));
|
||||
if (row % 2 > 0) {
|
||||
|
|
|
@ -1609,6 +1609,7 @@ PolyVoxEntityRenderer::PolyVoxEntityRenderer(const EntityItemPointer& entity) :
|
|||
_vertexFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
|
||||
_vertexFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 12);
|
||||
});
|
||||
_params = std::make_shared<gpu::Buffer>(sizeof(glm::vec4), nullptr);
|
||||
}
|
||||
|
||||
ShapeKey PolyVoxEntityRenderer::getShapeKey() {
|
||||
|
@ -1671,9 +1672,12 @@ void PolyVoxEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& s
|
|||
|
||||
void PolyVoxEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) {
|
||||
_lastVoxelToWorldMatrix = entity->voxelToWorldMatrix();
|
||||
_lastVoxelVolumeSize = entity->getVoxelVolumeSize();
|
||||
_params->setSubData(0, vec4(_lastVoxelVolumeSize, 0.0));
|
||||
graphics::MeshPointer newMesh;
|
||||
entity->withReadLock([&] {
|
||||
newMesh = entity->_mesh;
|
||||
|
||||
});
|
||||
|
||||
if (newMesh && newMesh->getIndexBuffer()._buffer) {
|
||||
|
@ -1686,6 +1690,7 @@ void PolyVoxEntityRenderer::doRender(RenderArgs* args) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
PerformanceTimer perfTimer("RenderablePolyVoxEntityItem::render");
|
||||
gpu::Batch& batch = *args->_batch;
|
||||
|
||||
|
@ -1695,6 +1700,7 @@ void PolyVoxEntityRenderer::doRender(RenderArgs* args) {
|
|||
batch.setInputBuffer(gpu::Stream::POSITION, _mesh->getVertexBuffer()._buffer, 0,
|
||||
sizeof(PolyVox::PositionMaterialNormal));
|
||||
|
||||
|
||||
// TODO -- should we be setting this?
|
||||
// batch.setInputBuffer(gpu::Stream::NORMAL, mesh->getVertexBuffer()._buffer,
|
||||
// 12,
|
||||
|
@ -1710,7 +1716,7 @@ void PolyVoxEntityRenderer::doRender(RenderArgs* args) {
|
|||
}
|
||||
}
|
||||
|
||||
batch._glUniform3f(entities_renderer::slot::uniform::PolyvoxVoxelSize, _lastVoxelVolumeSize.x, _lastVoxelVolumeSize.y, _lastVoxelVolumeSize.z);
|
||||
batch.setUniformBuffer(0, _params);
|
||||
batch.drawIndexed(gpu::TRIANGLES, (gpu::uint32)_mesh->getNumIndices(), 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -187,6 +187,7 @@ private:
|
|||
#endif
|
||||
|
||||
graphics::MeshPointer _mesh;
|
||||
gpu::BufferPointer _params;
|
||||
std::array<NetworkTexturePointer, 3> _xyzTextures;
|
||||
glm::vec3 _lastVoxelVolumeSize;
|
||||
glm::mat4 _lastVoxelToWorldMatrix;
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#define ENTITIES_SHADER_CONSTANTS_H
|
||||
|
||||
// Polyvox
|
||||
#define ENTITIES_UNIFORM_POLYVOX_VOXEL_SIZE 0
|
||||
#define ENTITIES_TEXTURE_POLYVOX_XMAP 0
|
||||
#define ENTITIES_TEXTURE_POLYVOX_YMAP 1
|
||||
#define ENTITIES_TEXTURE_POLYVOX_ZMAP 2
|
||||
|
@ -26,17 +25,6 @@
|
|||
|
||||
namespace entities_renderer { namespace slot {
|
||||
|
||||
namespace uniform {
|
||||
enum Uniform {
|
||||
PolyvoxVoxelSize = ENTITIES_UNIFORM_POLYVOX_VOXEL_SIZE,
|
||||
};
|
||||
}
|
||||
|
||||
namespace buffer {
|
||||
enum Buffer {
|
||||
};
|
||||
} // namespace buffer
|
||||
|
||||
namespace texture {
|
||||
enum Texture {
|
||||
PolyvoxXMap = ENTITIES_TEXTURE_POLYVOX_XMAP,
|
||||
|
|
|
@ -45,7 +45,7 @@ void main(void) {
|
|||
int frontCondition = 1 -int(gl_FrontFacing) * 2;
|
||||
vec3 color = varColor.rgb;
|
||||
packDeferredFragmentTranslucent(
|
||||
interpolatedNormal * frontCondition,
|
||||
interpolatedNormal * float(frontCondition),
|
||||
texel.a * varColor.a,
|
||||
polyline.color * texel.rgb + fadeEmissive,
|
||||
vec3(0.01, 0.01, 0.01),
|
||||
|
|
|
@ -23,15 +23,22 @@ layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _worldPosition;
|
|||
layout(binding=ENTITIES_TEXTURE_POLYVOX_XMAP) uniform sampler2D xMap;
|
||||
layout(binding=ENTITIES_TEXTURE_POLYVOX_YMAP) uniform sampler2D yMap;
|
||||
layout(binding=ENTITIES_TEXTURE_POLYVOX_ZMAP) uniform sampler2D zMap;
|
||||
layout(location=ENTITIES_UNIFORM_POLYVOX_VOXEL_SIZE) uniform vec3 voxelVolumeSize;
|
||||
|
||||
struct PolyvoxParams {
|
||||
vec4 voxelVolumeSize;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform polyvoxParamsBuffer {
|
||||
PolyvoxParams params;
|
||||
};
|
||||
|
||||
void main(void) {
|
||||
vec3 worldNormal = cross(dFdy(_worldPosition.xyz), dFdx(_worldPosition.xyz));
|
||||
worldNormal = normalize(worldNormal);
|
||||
|
||||
float inPositionX = (_worldPosition.x - 0.5) / voxelVolumeSize.x;
|
||||
float inPositionY = (_worldPosition.y - 0.5) / voxelVolumeSize.y;
|
||||
float inPositionZ = (_worldPosition.z - 0.5) / voxelVolumeSize.z;
|
||||
float inPositionX = (_worldPosition.x - 0.5) / params.voxelVolumeSize.x;
|
||||
float inPositionY = (_worldPosition.y - 0.5) / params.voxelVolumeSize.y;
|
||||
float inPositionZ = (_worldPosition.z - 0.5) / params.voxelVolumeSize.z;
|
||||
|
||||
vec4 xyDiffuse = texture(xMap, vec2(-inPositionX, -inPositionY));
|
||||
vec4 xzDiffuse = texture(yMap, vec2(-inPositionX, inPositionZ));
|
||||
|
|
|
@ -27,7 +27,13 @@ layout(binding=ENTITIES_TEXTURE_POLYVOX_XMAP) uniform sampler2D xMap;
|
|||
layout(binding=ENTITIES_TEXTURE_POLYVOX_YMAP) uniform sampler2D yMap;
|
||||
layout(binding=ENTITIES_TEXTURE_POLYVOX_ZMAP) uniform sampler2D zMap;
|
||||
|
||||
layout(location=ENTITIES_UNIFORM_POLYVOX_VOXEL_SIZE) uniform vec3 voxelVolumeSize;
|
||||
struct PolyvoxParams {
|
||||
vec4 voxelVolumeSize;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform polyvoxParamsBuffer {
|
||||
PolyvoxParams params;
|
||||
};
|
||||
|
||||
// Declare after all samplers to prevent sampler location mix up with voxel shading (sampler locations are hardcoded in RenderablePolyVoxEntityItem)
|
||||
<$declareFadeFragment()$>
|
||||
|
@ -42,9 +48,9 @@ void main(void) {
|
|||
vec3 worldNormal = cross(dFdy(_worldPosition.xyz), dFdx(_worldPosition.xyz));
|
||||
worldNormal = normalize(worldNormal);
|
||||
|
||||
float inPositionX = (_worldPosition.x - 0.5) / voxelVolumeSize.x;
|
||||
float inPositionY = (_worldPosition.y - 0.5) / voxelVolumeSize.y;
|
||||
float inPositionZ = (_worldPosition.z - 0.5) / voxelVolumeSize.z;
|
||||
float inPositionX = (_worldPosition.x - 0.5) / params.voxelVolumeSize.x;
|
||||
float inPositionY = (_worldPosition.y - 0.5) / params.voxelVolumeSize.y;
|
||||
float inPositionZ = (_worldPosition.z - 0.5) / params.voxelVolumeSize.z;
|
||||
|
||||
vec4 xyDiffuse = texture(xMap, vec2(-inPositionX, -inPositionY));
|
||||
vec4 xzDiffuse = texture(yMap, vec2(-inPositionX, inPositionZ));
|
||||
|
|
|
@ -13,12 +13,16 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include gpu/ShaderConstants.h@>
|
||||
struct DrawColorParams {
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
layout(location=GPU_UNIFORM_COLOR) uniform vec4 color;
|
||||
layout(binding=0) uniform drawColorParamsBuffer {
|
||||
DrawColorParams params;
|
||||
};
|
||||
|
||||
layout(location=0) out vec4 outFragColor;
|
||||
|
||||
void main(void) {
|
||||
outFragColor = color;
|
||||
outFragColor = params.color;
|
||||
}
|
||||
|
|
|
@ -13,14 +13,19 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
<@include gpu/ShaderConstants.h@>
|
||||
|
||||
layout(binding=0) uniform sampler2D colorMap;
|
||||
layout(location=GPU_UNIFORM_COLOR) uniform vec4 color;
|
||||
|
||||
struct DrawColorParams {
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform drawColorParams {
|
||||
DrawColorParams params;
|
||||
};
|
||||
|
||||
layout(location=0) in vec2 varTexCoord0;
|
||||
layout(location=0) out vec4 outFragColor;
|
||||
|
||||
void main(void) {
|
||||
outFragColor = texture(colorMap, varTexCoord0) * color;
|
||||
outFragColor = texture(colorMap, varTexCoord0) * params.color;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,13 @@
|
|||
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
layout(location=GPU_UNIFORM_TEXCOORD_RECT) uniform vec4 texcoordRect;
|
||||
struct TexCoordRectParams {
|
||||
vec4 texcoordRect;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform texcoordRectBuffer {
|
||||
TexCoordRectParams params;
|
||||
};
|
||||
|
||||
layout(location=0) out vec2 varTexCoord0;
|
||||
|
||||
|
@ -39,5 +45,5 @@ void main(void) {
|
|||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
||||
|
||||
varTexCoord0 = ((pos.xy + 1.0) * 0.5) * texcoordRect.zw + texcoordRect.xy;
|
||||
varTexCoord0 = ((pos.xy + 1.0) * 0.5) * params.texcoordRect.zw + params.texcoordRect.xy;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ float paintStripe(float value, float offset, float scale, float edge) {
|
|||
float width = fwidth(value);
|
||||
float normalizedWidth = width * scale;
|
||||
|
||||
float x0 = (value + offset) * scale - normalizedWidth / 2;
|
||||
float x0 = (value + offset) * scale - normalizedWidth / 2.0;
|
||||
float x1 = x0 + normalizedWidth;
|
||||
|
||||
float balance = 1.0 - edge;
|
||||
|
|
|
@ -40,8 +40,6 @@
|
|||
// OSX seems to have an issue using 14 as an attribute location for passing from the vertex to the fragment shader
|
||||
#define GPU_ATTR_V2F_STEREO_SIDE 8
|
||||
|
||||
#define GPU_UNIFORM_COLOR 101
|
||||
#define GPU_UNIFORM_TEXCOORD_RECT 102
|
||||
#define GPU_UNIFORM_EXTRA0 110
|
||||
#define GPU_UNIFORM_EXTRA1 111
|
||||
#define GPU_UNIFORM_EXTRA2 112
|
||||
|
@ -98,8 +96,6 @@ enum Attribute {
|
|||
|
||||
namespace uniform {
|
||||
enum Uniform {
|
||||
Color = GPU_UNIFORM_COLOR,
|
||||
TexCoordRect = GPU_UNIFORM_TEXCOORD_RECT,
|
||||
Extra0 = GPU_UNIFORM_EXTRA0,
|
||||
Extra1 = GPU_UNIFORM_EXTRA1,
|
||||
Extra2 = GPU_UNIFORM_EXTRA2,
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#ifndef PROCEDURAL_SHADER_CONSTANTS_H
|
||||
#define PROCEDURAL_SHADER_CONSTANTS_H
|
||||
|
||||
// Polyvox
|
||||
#define PROCEDURAL_UNIFORM_TIME 200
|
||||
#define PROCEDURAL_UNIFORM_DATE 201
|
||||
#define PROCEDURAL_UNIFORM_FRAME_COUNT 202
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
|
||||
namespace ru {
|
||||
using render_utils::slot::uniform::Uniform;
|
||||
using render_utils::slot::texture::Texture;
|
||||
using render_utils::slot::buffer::Buffer;
|
||||
}
|
||||
|
@ -39,13 +38,7 @@ namespace gr {
|
|||
using graphics::slot::buffer::Buffer;
|
||||
}
|
||||
|
||||
#define ANTIALIASING_USE_TAA 1
|
||||
|
||||
#if !ANTIALIASING_USE_TAA
|
||||
#include "fxaa_vert.h"
|
||||
#include "fxaa_frag.h"
|
||||
#include "fxaa_blend_frag.h"
|
||||
|
||||
|
||||
Antialiasing::Antialiasing() {
|
||||
_geometryId = DependencyManager::get<GeometryCache>()->allocateID();
|
||||
|
@ -58,30 +51,9 @@ Antialiasing::~Antialiasing() {
|
|||
}
|
||||
}
|
||||
|
||||
const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline(RenderArgs* args) {
|
||||
int width = args->_viewport.z;
|
||||
int height = args->_viewport.w;
|
||||
|
||||
if (_antialiasingBuffer && _antialiasingBuffer->getSize() != uvec2(width, height)) {
|
||||
_antialiasingBuffer.reset();
|
||||
}
|
||||
|
||||
if (!_antialiasingBuffer) {
|
||||
// Link the antialiasing FBO to texture
|
||||
_antialiasingBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("antialiasing"));
|
||||
auto format = gpu::Element::COLOR_SRGBA_32;
|
||||
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT);
|
||||
_antialiasingTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler);
|
||||
_antialiasingBuffer->setRenderBuffer(0, _antialiasingTexture);
|
||||
}
|
||||
|
||||
const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() {
|
||||
if (!_antialiasingPipeline) {
|
||||
auto vs = fxaa_vert::getShader();
|
||||
auto ps = fxaa_frag::getShader();
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
|
||||
_texcoordOffsetLoc = program->getUniforms().findLocation("texcoordOffset");
|
||||
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render_utils::program::fxaa);
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
|
||||
state->setDepthTest(false, false, gpu::LESS_EQUAL);
|
||||
|
@ -96,9 +68,7 @@ const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline(RenderArgs* ar
|
|||
|
||||
const gpu::PipelinePointer& Antialiasing::getBlendPipeline() {
|
||||
if (!_blendPipeline) {
|
||||
auto vs = fxaa_vert::getShader();
|
||||
auto ps = fxaa_blend_frag::getShader();
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(shader::render_utils::program::fxaa_blend);
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
state->setDepthTest(false, false, gpu::LESS_EQUAL);
|
||||
PrepareStencil::testNoAA(*state);
|
||||
|
@ -119,13 +89,30 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
batch.enableStereo(false);
|
||||
batch.setViewportTransform(args->_viewport);
|
||||
|
||||
// FIXME: NEED to simplify that code to avoid all the GeometryCahce call, this is purely pixel manipulation
|
||||
float fbWidth = renderContext->args->_viewport.z;
|
||||
float fbHeight = renderContext->args->_viewport.w;
|
||||
// float sMin = args->_viewport.x / fbWidth;
|
||||
// float sWidth = args->_viewport.z / fbWidth;
|
||||
// float tMin = args->_viewport.y / fbHeight;
|
||||
// float tHeight = args->_viewport.w / fbHeight;
|
||||
if (!_paramsBuffer) {
|
||||
_paramsBuffer = std::make_shared<gpu::Buffer>(sizeof(glm::vec4), nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
int width = args->_viewport.z;
|
||||
int height = args->_viewport.w;
|
||||
if (_antialiasingBuffer && _antialiasingBuffer->getSize() != uvec2(width, height)) {
|
||||
_antialiasingBuffer.reset();
|
||||
}
|
||||
|
||||
if (!_antialiasingBuffer) {
|
||||
// Link the antialiasing FBO to texture
|
||||
_antialiasingBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("antialiasing"));
|
||||
auto format = gpu::Element::COLOR_SRGBA_32;
|
||||
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT);
|
||||
_antialiasingTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler);
|
||||
_antialiasingBuffer->setRenderBuffer(0, _antialiasingTexture);
|
||||
glm::vec2 fbExtent { args->_viewport.z, args->_viewport.w };
|
||||
glm::vec2 inverseFbExtent = 1.0f / fbExtent;
|
||||
_paramsBuffer->setSubData(0, glm::vec4(inverseFbExtent, 0.0, 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 projMat;
|
||||
Transform viewMat;
|
||||
|
@ -136,40 +123,18 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
batch.setModelTransform(Transform());
|
||||
|
||||
// FXAA step
|
||||
auto pipeline = getAntialiasingPipeline(renderContext->args);
|
||||
auto pipeline = getAntialiasingPipeline();
|
||||
batch.setResourceTexture(0, sourceBuffer->getRenderBuffer(0));
|
||||
batch.setFramebuffer(_antialiasingBuffer);
|
||||
batch.setPipeline(pipeline);
|
||||
|
||||
// initialize the view-space unpacking uniforms using frustum data
|
||||
float left, right, bottom, top, nearVal, farVal;
|
||||
glm::vec4 nearClipPlane, farClipPlane;
|
||||
|
||||
args->getViewFrustum().computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||
|
||||
// float depthScale = (farVal - nearVal) / farVal;
|
||||
// float nearScale = -1.0f / nearVal;
|
||||
// float depthTexCoordScaleS = (right - left) * nearScale / sWidth;
|
||||
// float depthTexCoordScaleT = (top - bottom) * nearScale / tHeight;
|
||||
// float depthTexCoordOffsetS = left * nearScale - sMin * depthTexCoordScaleS;
|
||||
// float depthTexCoordOffsetT = bottom * nearScale - tMin * depthTexCoordScaleT;
|
||||
|
||||
batch._glUniform2f(_texcoordOffsetLoc, 1.0f / fbWidth, 1.0f / fbHeight);
|
||||
|
||||
glm::vec4 color(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glm::vec2 bottomLeft(-1.0f, -1.0f);
|
||||
glm::vec2 topRight(1.0f, 1.0f);
|
||||
glm::vec2 texCoordTopLeft(0.0f, 0.0f);
|
||||
glm::vec2 texCoordBottomRight(1.0f, 1.0f);
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, texCoordTopLeft, texCoordBottomRight, color, _geometryId);
|
||||
|
||||
batch.setUniformBuffer(0, _paramsBuffer);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
|
||||
// Blend step
|
||||
batch.setResourceTexture(0, _antialiasingTexture);
|
||||
batch.setFramebuffer(sourceBuffer);
|
||||
batch.setPipeline(getBlendPipeline());
|
||||
|
||||
DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, texCoordTopLeft, texCoordBottomRight, color, _geometryId);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
});
|
||||
}
|
||||
#else
|
||||
|
@ -314,7 +279,11 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
// Must match the bindg point in the fxaa_blend.slf shader
|
||||
batch.setResourceFramebufferSwapChainTexture(0, _antialiasingBuffers, 1);
|
||||
// Disable sharpen if FXAA
|
||||
batch._glUniform1f(ru::Uniform::TaaSharpenIntensity, _sharpen * _params.get().regionInfo.z);
|
||||
if (!_blendParamsBuffer) {
|
||||
_blendParamsBuffer = std::make_shared<gpu::Buffer>(sizeof(glm::vec4), nullptr);
|
||||
}
|
||||
_blendParamsBuffer->setSubData(0, _sharpen * _params.get().regionInfo.z);
|
||||
batch.setUniformBuffer(0, _blendParamsBuffer);
|
||||
}
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
batch.advance(_antialiasingBuffers);
|
||||
|
|
|
@ -134,6 +134,10 @@ signals:
|
|||
#define SET_BIT(bitfield, bitIndex, value) bitfield = ((bitfield) & ~(1 << (bitIndex))) | ((value) << (bitIndex))
|
||||
#define GET_BIT(bitfield, bitIndex) ((bitfield) & (1 << (bitIndex)))
|
||||
|
||||
#define ANTIALIASING_USE_TAA 1
|
||||
|
||||
#if ANTIALIASING_USE_TAA
|
||||
|
||||
struct TAAParams {
|
||||
float nope{ 0.0f };
|
||||
float blend{ 0.15f };
|
||||
|
@ -186,7 +190,7 @@ private:
|
|||
|
||||
gpu::FramebufferSwapChainPointer _antialiasingBuffers;
|
||||
gpu::TexturePointer _antialiasingTextures[2];
|
||||
|
||||
gpu::BufferPointer _blendParamsBuffer;
|
||||
gpu::PipelinePointer _antialiasingPipeline;
|
||||
gpu::PipelinePointer _blendPipeline;
|
||||
gpu::PipelinePointer _debugBlendPipeline;
|
||||
|
@ -197,7 +201,7 @@ private:
|
|||
};
|
||||
|
||||
|
||||
/*
|
||||
#else
|
||||
class AntiAliasingConfig : public render::Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool enabled MEMBER enabled)
|
||||
|
@ -219,18 +223,15 @@ public:
|
|||
const gpu::PipelinePointer& getBlendPipeline();
|
||||
|
||||
private:
|
||||
|
||||
// Uniforms for AA
|
||||
gpu::int32 _texcoordOffsetLoc;
|
||||
|
||||
gpu::FramebufferPointer _antialiasingBuffer;
|
||||
|
||||
gpu::TexturePointer _antialiasingTexture;
|
||||
gpu::BufferPointer _paramsBuffer;
|
||||
|
||||
gpu::PipelinePointer _antialiasingPipeline;
|
||||
gpu::PipelinePointer _blendPipeline;
|
||||
int _geometryId { 0 };
|
||||
};
|
||||
*/
|
||||
#endif
|
||||
|
||||
#endif // hifi_AntialiasingEffect_h
|
||||
|
|
|
@ -184,6 +184,7 @@ void BloomDraw::run(const render::RenderContextPointer& renderContext, const Inp
|
|||
}
|
||||
|
||||
DebugBloom::DebugBloom() {
|
||||
_params = std::make_shared<gpu::Buffer>(sizeof(glm::vec4), nullptr);
|
||||
}
|
||||
|
||||
void DebugBloom::configure(const Config& config) {
|
||||
|
@ -227,7 +228,8 @@ void DebugBloom::run(const render::RenderContextPointer& renderContext, const In
|
|||
|
||||
Transform modelTransform;
|
||||
if (_mode == DebugBloomConfig::MODE_ALL_LEVELS) {
|
||||
batch._glUniform4f(gpu::slot::uniform::TexCoordRect, 0.0f, 0.0f, 1.f, 1.f);
|
||||
_params->setSubData(0, vec4(0.0f, 0.0f, 1.f, 1.f));
|
||||
batch.setUniformBuffer(0, _params);
|
||||
|
||||
modelTransform = gpu::Framebuffer::evalSubregionTexcoordTransform(framebufferSize, args->_viewport / 2);
|
||||
modelTransform.postTranslate(glm::vec3(-1.0f, 1.0f, 0.0f));
|
||||
|
@ -255,7 +257,8 @@ void DebugBloom::run(const render::RenderContextPointer& renderContext, const In
|
|||
|
||||
viewport.z /= 2;
|
||||
|
||||
batch._glUniform4f(gpu::slot::uniform::TexCoordRect, 0.5f, 0.0f, 0.5f, 1.f);
|
||||
_params->setSubData(0, vec4(0.5f, 0.0f, 0.5f, 1.f));
|
||||
batch.setUniformBuffer(0, _params);
|
||||
|
||||
modelTransform = gpu::Framebuffer::evalSubregionTexcoordTransform(framebufferSize, viewport);
|
||||
modelTransform.postTranslate(glm::vec3(-1.0f, 0.0f, 0.0f));
|
||||
|
|
|
@ -121,6 +121,7 @@ public:
|
|||
|
||||
private:
|
||||
gpu::PipelinePointer _pipeline;
|
||||
gpu::BufferPointer _params;
|
||||
DebugBloomConfig::Mode _mode;
|
||||
};
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ void main(void) {
|
|||
for (int x=0 ; x<parameters._sampleCount ; x++) {
|
||||
vec4 color = texture(colorMap, uv);
|
||||
float luminance = (color.r+color.g+color.b) / 3.0;
|
||||
float mask = clamp((luminance-parameters._threshold)*0.25, 0, 1);
|
||||
float mask = clamp((luminance-parameters._threshold)*0.25, 0.0, 1.0);
|
||||
|
||||
color *= mask;
|
||||
maskedColor += color;
|
||||
|
@ -39,6 +39,6 @@ void main(void) {
|
|||
|
||||
startUv.y += parameters._deltaUV.y;
|
||||
}
|
||||
maskedColor /= parameters._sampleCount * parameters._sampleCount;
|
||||
maskedColor /= float(parameters._sampleCount * parameters._sampleCount);
|
||||
outFragColor = vec4(maskedColor.rgb, 1.0);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
namespace ru {
|
||||
using render_utils::slot::texture::Texture;
|
||||
using render_utils::slot::buffer::Buffer;
|
||||
using render_utils::slot::uniform::Uniform;
|
||||
}
|
||||
|
||||
namespace gr {
|
||||
|
|
|
@ -2104,9 +2104,7 @@ void GeometryCache::useSimpleDrawPipeline(gpu::Batch& batch, bool noBlend) {
|
|||
auto stateNoBlend = std::make_shared<gpu::State>();
|
||||
PrepareStencil::testMaskDrawShape(*stateNoBlend);
|
||||
|
||||
auto noBlendPS = gpu::Shader::createVertex(shader::gpu::fragment::DrawTextureOpaque);
|
||||
auto programNoBlend = gpu::Shader::createProgram(shader::render_utils::program::standardDrawTextureNoBlend);
|
||||
|
||||
_standardDrawPipelineNoBlend = gpu::Pipeline::create(programNoBlend, stateNoBlend);
|
||||
});
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ layout(binding=RENDER_UTILS_BUFFER_HIGHLIGHT_PARAMS) uniform highlightParamsBuff
|
|||
layout(binding=RENDER_UTILS_TEXTURE_HIGHLIGHT_SCENE_DEPTH) uniform sampler2D sceneDepthMap;
|
||||
layout(binding=RENDER_UTILS_TEXTURE_HIGHLIGHT_DEPTH) uniform sampler2D highlightedDepthMap;
|
||||
|
||||
in vec2 varTexCoord0;
|
||||
out vec4 outFragColor;
|
||||
layout(location=0) in vec2 varTexCoord0;
|
||||
layout(location=0) out vec4 outFragColor;
|
||||
|
||||
const float FAR_Z = 1.0;
|
||||
const float LINEAR_DEPTH_BIAS = 5e-3;
|
||||
|
@ -55,10 +55,10 @@ void main(void) {
|
|||
discard;
|
||||
<@endif@>
|
||||
} else {
|
||||
vec2 halfTexel = getInvWidthHeight() / 2;
|
||||
vec2 halfTexel = getInvWidthHeight() / 2.0;
|
||||
vec2 texCoord0 = varTexCoord0+halfTexel;
|
||||
float weight = 0.0;
|
||||
vec2 deltaUv = params._size / params._blurKernelSize;
|
||||
vec2 deltaUv = params._size / float(params._blurKernelSize);
|
||||
vec2 lineStartUv = texCoord0 - params._size / 2.0;
|
||||
vec2 uv;
|
||||
int x;
|
||||
|
@ -87,7 +87,7 @@ void main(void) {
|
|||
}
|
||||
}
|
||||
|
||||
if (intensity > 0) {
|
||||
if (intensity > 0.0) {
|
||||
// sumOutlineDepth /= intensity;
|
||||
} else {
|
||||
sumOutlineDepth = FAR_Z;
|
||||
|
|
|
@ -28,7 +28,6 @@ using namespace render;
|
|||
namespace ru {
|
||||
using render_utils::slot::texture::Texture;
|
||||
using render_utils::slot::buffer::Buffer;
|
||||
using render_utils::slot::uniform::Uniform;
|
||||
}
|
||||
|
||||
namespace gr {
|
||||
|
|
|
@ -67,10 +67,10 @@ ShadowSampleOffsets evalShadowFilterOffsets(vec4 position) {
|
|||
ivec2 offset = coords & ivec2(1,1);
|
||||
offset.y = (offset.x+offset.y) & 1;
|
||||
|
||||
offsets.points[0] = shadowScale * vec3(offset + PCFkernel[0], 0.0);
|
||||
offsets.points[1] = shadowScale * vec3(offset + PCFkernel[1], 0.0);
|
||||
offsets.points[2] = shadowScale * vec3(offset + PCFkernel[2], 0.0);
|
||||
offsets.points[3] = shadowScale * vec3(offset + PCFkernel[3], 0.0);
|
||||
offsets.points[0] = shadowScale * vec3(vec2(offset) + PCFkernel[0], 0.0);
|
||||
offsets.points[1] = shadowScale * vec3(vec2(offset) + PCFkernel[1], 0.0);
|
||||
offsets.points[2] = shadowScale * vec3(vec2(offset) + PCFkernel[2], 0.0);
|
||||
offsets.points[3] = shadowScale * vec3(vec2(offset) + PCFkernel[3], 0.0);
|
||||
|
||||
return offsets;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ float evalShadowAttenuation(vec3 worldLightDir, vec4 worldPosition, float viewDe
|
|||
vec3 cascadeMix;
|
||||
bvec4 isPixelOnCascade;
|
||||
int cascadeIndex;
|
||||
float oneMinusNdotL = 1.0 - clamp(dot(worldLightDir, worldNormal), 0, 1);
|
||||
float oneMinusNdotL = 1.0 - clamp(dot(worldLightDir, worldNormal), 0.0, 1.0);
|
||||
|
||||
for (cascadeIndex=0 ; cascadeIndex<getShadowCascadeCount() ; cascadeIndex++) {
|
||||
cascadeShadowCoords[cascadeIndex] = evalShadowTexcoord(cascadeIndex, worldPosition);
|
||||
|
|
|
@ -70,9 +70,8 @@ void TextRenderer3D::draw(gpu::Batch& batch, float x, float y, const QString& st
|
|||
const glm::vec2& bounds, bool layered) {
|
||||
// The font does all the OpenGL work
|
||||
if (_font) {
|
||||
// Cache color so that the pointer stays valid.
|
||||
_color = color;
|
||||
_font->drawString(batch, x, y, str, &_color, _effectType, bounds, layered);
|
||||
_font->drawString(batch, _drawInfo, str, _color, _effectType, { x, y }, bounds, layered);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
#include <QColor>
|
||||
#include <gpu/Forward.h>
|
||||
|
||||
namespace gpu {
|
||||
class Batch;
|
||||
}
|
||||
class Font;
|
||||
|
||||
#include "text/Font.h"
|
||||
#include "text/EffectType.h"
|
||||
#include "text/FontFamilies.h"
|
||||
|
||||
|
@ -51,7 +53,7 @@ private:
|
|||
|
||||
// text color
|
||||
glm::vec4 _color;
|
||||
|
||||
Font::DrawInfo _drawInfo;
|
||||
std::shared_ptr<Font> _font;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
uniform vec4 sphereParam;
|
||||
// FIXME make into a uniform buffer or push constant if this shader ever comes into use
|
||||
vec4 sphereParam = vec4(0.0);
|
||||
|
||||
layout(location=RENDER_UTILS_ATTR_TEXCOORD01) out vec4 _texCoord01;
|
||||
|
||||
|
@ -41,7 +42,7 @@ void main(void) {
|
|||
}
|
||||
#endif
|
||||
#endif
|
||||
_texCoord01.xy = vec4(projected.xy, 0.0, 1.0) * gl_Position.w;
|
||||
_texCoord01 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w;
|
||||
} else {
|
||||
const float depth = -1.0; //Draw at near plane
|
||||
const vec4 UNIT_QUAD[4] = vec4[4](
|
||||
|
@ -60,7 +61,7 @@ void main(void) {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
_texCoord01.xy = vec4((pos.xy + 1.0) * 0.5, 0.0, 1.0);
|
||||
_texCoord01 = vec4((pos.xy + 1.0) * 0.5, 0.0, 1.0);
|
||||
|
||||
#ifdef GPU_TRANSFORM_IS_STEREO
|
||||
#ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
<@include DeferredBufferWrite.slh@>
|
||||
<@include gpu/Paint.slh@>
|
||||
|
||||
in vec4 varColor;
|
||||
in vec3 varTexcoord;
|
||||
in vec3 varEyePos;
|
||||
layout(location=0) in vec4 varColor;
|
||||
layout(location=1) in vec3 varTexcoord;
|
||||
layout(location=2) in vec3 varEyePos;
|
||||
|
||||
void main(void) {
|
||||
if (varColor.w > 0.0) {
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
<$declareWorkloadProxies()$>
|
||||
|
||||
|
||||
out vec4 varColor;
|
||||
out vec3 varTexcoord;
|
||||
out vec3 varEyePos;
|
||||
layout(location=0) out vec4 varColor;
|
||||
layout(location=1) out vec3 varTexcoord;
|
||||
layout(location=2) out vec3 varEyePos;
|
||||
|
||||
void main(void) {
|
||||
const vec4 UNIT_SPRITE[3] = vec4[3](
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
<@include DeferredBufferWrite.slh@>
|
||||
<@include gpu/Paint.slh@>
|
||||
|
||||
in vec4 varColor;
|
||||
in vec3 varTexcoord;
|
||||
in vec3 varEyePos;
|
||||
layout(location=0) in vec4 varColor;
|
||||
layout(location=1) in vec3 varTexcoord;
|
||||
layout(location=2) in vec3 varEyePos;
|
||||
|
||||
void main(void) {
|
||||
if (varColor.w > 0.0) {
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
<@include WorkloadResource.slh@>
|
||||
<$declareWorkloadViews()$>
|
||||
|
||||
out vec4 varColor;
|
||||
out vec3 varTexcoord;
|
||||
out vec3 varEyePos;
|
||||
layout(location=0) out vec4 varColor;
|
||||
layout(location=1) out vec3 varTexcoord;
|
||||
layout(location=2) out vec3 varEyePos;
|
||||
|
||||
const int NUM_VERTICES_PER_SEGMENT = 2;
|
||||
const int NUM_SEGMENT_PER_VIEW_REGION = 65;
|
||||
|
@ -79,7 +79,7 @@ void main(void) {
|
|||
<$transformModelToEyeDir(cam, obj, originSpaceTan, tanEye)$>
|
||||
|
||||
lateralDir = normalize(cross(vec3(0.0, 0.0, 1.0), normalize(tanEye)));
|
||||
posEye.xyz += (0.005 * abs(posEye.z) * (regionID + 1)) * (-1.0 + 2.0 * float(segmentVertexID)) * lateralDir;
|
||||
posEye.xyz += (0.005 * abs(posEye.z) * float(regionID + 1)) * (-1.0 + 2.0 * float(segmentVertexID)) * lateralDir;
|
||||
varEyePos = posEye.xyz;
|
||||
|
||||
<$transformEyeToClipPos(cam, posEye, gl_Position)$>
|
||||
|
|
|
@ -24,7 +24,9 @@ precision mediump int;
|
|||
|
||||
layout(binding=0) uniform sampler2D colorTexture;
|
||||
//uniform sampler2D historyTexture;
|
||||
layout(location=0) uniform vec2 texcoordOffset;
|
||||
|
||||
// FIXME make into a uniform buffer or push constant if this shader ever comes into use
|
||||
vec2 texcoordOffset = vec2(0.0);
|
||||
|
||||
layout(location=0) in vec2 varTexCoord0;
|
||||
layout(location=0) out vec4 outFragColor;
|
||||
|
@ -66,7 +68,7 @@ void main() {
|
|||
outFragColor.w = 1.0;
|
||||
|
||||
}*/
|
||||
if (gl_FragCoord.x > 800) {
|
||||
if (gl_FragCoord.x > 800.0) {
|
||||
/* // filter width limit for dependent "two-tap" texture samples
|
||||
float FXAA_SPAN_MAX = 8.0;
|
||||
|
||||
|
|
|
@ -18,7 +18,14 @@ layout(location=0) in vec2 varTexCoord0;
|
|||
layout(location=0) out vec4 outFragColor;
|
||||
|
||||
layout(binding=0) uniform sampler2D colorTexture;
|
||||
layout(location=GPU_UNIFORM_EXTRA0) uniform float sharpenIntensity;
|
||||
|
||||
struct FxaaBlendParams {
|
||||
vec4 sharpenIntensity;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform fxaaBlendParamsBuffer {
|
||||
FxaaBlendParams params;
|
||||
};
|
||||
|
||||
void main(void) {
|
||||
vec4 pixels[9];
|
||||
|
@ -39,5 +46,5 @@ void main(void) {
|
|||
|
||||
vec4 minColor = max(vec4(0), pixels[4]-vec4(0.5));
|
||||
vec4 maxColor = pixels[4]+vec4(0.5);
|
||||
outFragColor = clamp(pixels[4] + sharpenedPixel * sharpenIntensity, minColor, maxColor);
|
||||
outFragColor = clamp(pixels[4] + sharpenedPixel * params.sharpenIntensity.x, minColor, maxColor);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ void main(void) {
|
|||
|
||||
ivec3 cluster = clusterGrid_getCluster(clusterIndex);
|
||||
int numLights = cluster.x + cluster.y;
|
||||
float numLightsScale = clamp(numLights * 0.05, 0.01, 1.0);
|
||||
float numLightsScale = clamp(float(numLights) * 0.05, 0.01, 1.0);
|
||||
|
||||
int clusterOffset = cluster.z;
|
||||
|
||||
|
@ -90,6 +90,6 @@ void main(void) {
|
|||
numLightTouching++;
|
||||
}
|
||||
|
||||
_fragColor = vec4(colorRamp(1.0 - (numLightTouching / 12.0f)), (numLightTouching > 0 ? 0.5 + 0.5 * numLightsScale : 0.0));
|
||||
_fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), (numLightTouching > 0 ? 0.5 + 0.5 * numLightsScale : 0.0));
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ void main(void) {
|
|||
ivec3 cluster = clusterGrid_getCluster(gpu_InstanceID());
|
||||
int numLights = cluster.x + cluster.y;
|
||||
|
||||
float numLightsScale = clamp(numLights * 0.1, 0.0, 1.0);
|
||||
float numLightsScale = clamp(float(numLights) * 0.1, 0.0, 1.0);
|
||||
|
||||
ivec3 clusterPos = frustumGrid_indexToCluster(gpu_InstanceID());
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ void main(void) {
|
|||
|
||||
ivec3 cluster = clusterGrid_getCluster(frustumGrid_clusterToIndex(clusterPos));
|
||||
int numLights = cluster.x + cluster.y;
|
||||
float numLightsScale = clamp(numLights * 0.05, 0.01, 1.0);
|
||||
float numLightsScale = clamp(float(numLights) * 0.05, 0.01, 1.0);
|
||||
|
||||
|
||||
ivec3 dims = frustumGrid.dims.xyz;
|
||||
|
|
|
@ -43,9 +43,6 @@
|
|||
#define RENDER_UTILS_BUFFER_AMBIENT_LIGHT 6
|
||||
#define RENDER_UTILS_BUFFER_LIGHT_INDEX 7
|
||||
|
||||
#define RENDER_UTILS_UNIFORM_LIGHT_RADIUS 0
|
||||
#define RENDER_UTILS_UNIFORM_LIGHT_TEXCOORD_TRANSFORM 1
|
||||
|
||||
// Deferred lighting resolution
|
||||
#define RENDER_UTILS_TEXTURE_DEFERRRED_COLOR 0
|
||||
#define RENDER_UTILS_TEXTURE_DEFERRRED_NORMAL 1
|
||||
|
@ -140,8 +137,6 @@ enum Uniform {
|
|||
TextOutline = RENDER_UTILS_UNIFORM_TEXT_OUTLINE,
|
||||
TaaSharpenIntensity = GPU_UNIFORM_EXTRA0,
|
||||
HighlightOutlineWidth = GPU_UNIFORM_EXTRA0,
|
||||
LightRadius = RENDER_UTILS_UNIFORM_LIGHT_RADIUS,
|
||||
TexcoordTransform = RENDER_UTILS_UNIFORM_LIGHT_TEXCOORD_TRANSFORM,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
1
libraries/render-utils/src/render-utils/fxaa.slp
Normal file
1
libraries/render-utils/src/render-utils/fxaa.slp
Normal file
|
@ -0,0 +1 @@
|
|||
VERTEX gpu::vertex::DrawUnitQuadTexcoord
|
|
@ -14,8 +14,15 @@
|
|||
<@include render-utils/ShaderConstants.h@>
|
||||
|
||||
layout(binding=0) uniform sampler2D Font;
|
||||
layout(location=RENDER_UTILS_UNIFORM_TEXT_OUTLINE) uniform bool Outline;
|
||||
layout(location=RENDER_UTILS_UNIFORM_TEXT_COLOR) uniform vec4 Color;
|
||||
|
||||
struct TextParams {
|
||||
vec4 color;
|
||||
vec4 outline;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform textParamsBuffer {
|
||||
TextParams params;
|
||||
};
|
||||
|
||||
// the interpolated normal
|
||||
layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS;
|
||||
|
@ -32,7 +39,7 @@ const float taaBias = pow(2.0, TAA_TEXTURE_LOD_BIAS);
|
|||
float evalSDF(vec2 texCoord) {
|
||||
// retrieve signed distance
|
||||
float sdf = textureLod(Font, texCoord, TAA_TEXTURE_LOD_BIAS).g;
|
||||
if (Outline) {
|
||||
if (params.outline.x > 0.0) {
|
||||
if (sdf > interiorCutoff) {
|
||||
sdf = 1.0 - sdf;
|
||||
} else {
|
||||
|
@ -62,8 +69,8 @@ void main() {
|
|||
|
||||
packDeferredFragment(
|
||||
normalize(_normalWS),
|
||||
a * Color.a,
|
||||
Color.rgb,
|
||||
a * params.color.a,
|
||||
params.color.rgb,
|
||||
DEFAULT_ROUGHNESS,
|
||||
DEFAULT_METALLIC,
|
||||
DEFAULT_EMISSIVE,
|
||||
|
|
|
@ -14,8 +14,15 @@
|
|||
<@include render-utils/ShaderConstants.h@>
|
||||
|
||||
layout(binding=0) uniform sampler2D Font;
|
||||
layout(location=RENDER_UTILS_UNIFORM_TEXT_OUTLINE) uniform bool Outline;
|
||||
layout(location=RENDER_UTILS_UNIFORM_TEXT_COLOR) uniform vec4 Color;
|
||||
|
||||
struct TextParams {
|
||||
vec4 color;
|
||||
vec4 outline;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform textParamsBuffer {
|
||||
TextParams params;
|
||||
};
|
||||
|
||||
// the interpolated normal
|
||||
layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS;
|
||||
|
@ -31,7 +38,7 @@ const float outlineExpansion = 0.2;
|
|||
void main() {
|
||||
// retrieve signed distance
|
||||
float sdf = texture(Font, _texCoord0).g;
|
||||
if (Outline) {
|
||||
if (params.outline.x > 0.0) {
|
||||
if (sdf > interiorCutoff) {
|
||||
sdf = 1.0 - sdf;
|
||||
} else {
|
||||
|
@ -51,8 +58,8 @@ void main() {
|
|||
|
||||
packDeferredFragmentTranslucent(
|
||||
normalize(_normalWS),
|
||||
a * Color.a,
|
||||
Color.rgb,
|
||||
a * params.color.a,
|
||||
params.color.rgb,
|
||||
DEFAULT_FRESNEL,
|
||||
DEFAULT_ROUGHNESS);
|
||||
}
|
|
@ -91,7 +91,7 @@ void main(void) {
|
|||
normal,
|
||||
1.0,
|
||||
diffuse+fadeEmissive,
|
||||
max(0, 1.0 - shininess / 128.0),
|
||||
max(0.0, 1.0 - shininess / 128.0),
|
||||
DEFAULT_METALLIC,
|
||||
specular,
|
||||
specular);
|
||||
|
@ -100,7 +100,7 @@ void main(void) {
|
|||
normal,
|
||||
1.0,
|
||||
diffuse,
|
||||
max(0, 1.0 - shininess / 128.0),
|
||||
max(0.0, 1.0 - shininess / 128.0),
|
||||
length(specular),
|
||||
DEFAULT_EMISSIVE+fadeEmissive,
|
||||
DEFAULT_OCCLUSION,
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<@include render-utils/ShaderConstants.h@>
|
||||
|
||||
// the albedo texture
|
||||
layout(location=0) uniform sampler2D originalTexture;
|
||||
layout(binding=0) uniform sampler2D originalTexture;
|
||||
|
||||
// the interpolated normal
|
||||
layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS;
|
||||
|
|
|
@ -137,14 +137,14 @@ float getBlurCoef(int c) {
|
|||
float getAngleDitheringWorldPos(in vec3 pixelWorldPos) {
|
||||
vec3 worldPosFract = fract(pixelWorldPos * 1.0);
|
||||
|
||||
ivec3 pixelPos = ivec3(worldPosFract * 256);
|
||||
ivec3 pixelPos = ivec3(worldPosFract * 256.0);
|
||||
|
||||
return isDitheringEnabled() * ((3 * pixelPos.x ^ pixelPos.y + pixelPos.x * pixelPos.y) + (3 * pixelPos.y ^ pixelPos.z + pixelPos.x * pixelPos.z)) * 10 + getFrameDithering();
|
||||
return isDitheringEnabled() * float(((3 * pixelPos.x ^ pixelPos.y + pixelPos.x * pixelPos.y) + (3 * pixelPos.y ^ pixelPos.z + pixelPos.x * pixelPos.z)) * 10) + getFrameDithering();
|
||||
}
|
||||
|
||||
float getAngleDithering(in ivec2 pixelPos) {
|
||||
// Hash function used in the AlchemyAO paper
|
||||
return isDitheringEnabled() * (3 * pixelPos.x ^ pixelPos.y + pixelPos.x * pixelPos.y) * 10 + getFrameDithering();
|
||||
return isDitheringEnabled() * float((3 * pixelPos.x ^ pixelPos.y + pixelPos.x * pixelPos.y) * 10) + getFrameDithering();
|
||||
}
|
||||
|
||||
float evalDiskRadius(float Zeye, vec2 imageSize) {
|
||||
|
@ -162,7 +162,7 @@ const float TWO_PI = 6.28;
|
|||
|
||||
vec3 getUnitTapLocation(int sampleNumber, float spinAngle){
|
||||
// Radius relative to ssR
|
||||
float alpha = float(sampleNumber + 0.5) * getInvNumSamples();
|
||||
float alpha = (float(sampleNumber) + 0.5) * getInvNumSamples();
|
||||
float angle = alpha * (getNumSpiralTurns() * TWO_PI) + spinAngle;
|
||||
return vec3(cos(angle), sin(angle), alpha);
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ vec3 getTapLocationClamped(int sampleNumber, float spinAngle, float outerRadius,
|
|||
if (redoTap) {
|
||||
tap.xy = tapPos - pixelPos;
|
||||
tap.z = length(tap.xy);
|
||||
tap.z = 0;
|
||||
tap.z = 0.0;
|
||||
}
|
||||
|
||||
return tap;
|
||||
|
@ -253,7 +253,7 @@ vec3 fetchTapUnfiltered(ivec4 side, ivec2 ssC, vec3 tap, vec2 imageSize) {
|
|||
|
||||
vec2 tapUV = (vec2(ssP) + vec2(0.5)) / imageSize;
|
||||
|
||||
vec2 fetchUV = vec2(tapUV.x + side.w * 0.5 * (side.x - tapUV.x), tapUV.y);
|
||||
vec2 fetchUV = vec2(tapUV.x + float(side.w) * 0.5 * (float(side.x) - tapUV.x), tapUV.y);
|
||||
|
||||
vec3 P;
|
||||
P.xy = tapUV;
|
||||
|
@ -263,7 +263,7 @@ vec3 fetchTapUnfiltered(ivec4 side, ivec2 ssC, vec3 tap, vec2 imageSize) {
|
|||
}
|
||||
|
||||
vec3 fetchTap(ivec4 side, ivec2 ssC, vec3 tap, vec2 imageSize) {
|
||||
int mipLevel = evalMipFromRadius(tap.z * doFetchMips());
|
||||
int mipLevel = evalMipFromRadius(tap.z * float(doFetchMips()));
|
||||
|
||||
ivec2 ssP = ivec2(tap.xy) + ssC;
|
||||
ivec2 ssPFull = ivec2(ssP.x + side.y, ssP.y);
|
||||
|
@ -276,7 +276,7 @@ vec3 fetchTap(ivec4 side, ivec2 ssC, vec3 tap, vec2 imageSize) {
|
|||
ivec2 mipP = clamp(ssPFull >> mipLevel, ivec2(0), mipSize - ivec2(1));
|
||||
|
||||
vec2 tapUV = (vec2(ssP) + vec2(0.5)) / imageSize;
|
||||
vec2 fetchUV = vec2(tapUV.x + side.w * 0.5 * (side.x - tapUV.x), tapUV.y);
|
||||
vec2 fetchUV = vec2(tapUV.x + float(side.w) * 0.5 * (float(side.x) - tapUV.x), tapUV.y);
|
||||
// vec2 tapUV = (vec2(mipP) + vec2(0.5)) / vec2(mipSize);
|
||||
|
||||
vec3 P;
|
||||
|
|
|
@ -84,15 +84,15 @@ void main(void) {
|
|||
float keepTapRadius = 1.0;
|
||||
int keepedMip = -1;
|
||||
bool keep = false;
|
||||
|
||||
for (int i = 0; i < getNumSamples(); ++i) {
|
||||
int sampleCount = int(getNumSamples());
|
||||
for (int i = 0; i < sampleCount; ++i) {
|
||||
vec3 tap = getTapLocationClamped(i, randomPatternRotationAngle, ssDiskRadius, cursorPixelPos, imageSize);
|
||||
|
||||
// The occluding point in camera space
|
||||
vec2 fragToTap = vec2(ssC) + tap.xy - fragCoord.xy;
|
||||
if (dot(fragToTap,fragToTap) < keepTapRadius) {
|
||||
keep = true;
|
||||
keepedMip = evalMipFromRadius(tap.z * doFetchMips());
|
||||
keepedMip = evalMipFromRadius(tap.z * float(doFetchMips()));
|
||||
}
|
||||
|
||||
vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize);
|
||||
|
|
|
@ -52,8 +52,9 @@ void main(void) {
|
|||
|
||||
// Accumulate the Obscurance for each samples
|
||||
float sum = 0.0;
|
||||
for (int i = 0; i < getNumSamples(); ++i) {
|
||||
vec3 tap = getTapLocationClamped(i, randomPatternRotationAngle, ssDiskRadius, ssC, imageSize);
|
||||
int sampleCount = int(getNumSamples());
|
||||
for (int i = 0; i < sampleCount; ++i) {
|
||||
vec3 tap = getTapLocationClamped(i, randomPatternRotationAngle, ssDiskRadius, vec2(ssC), imageSize);
|
||||
|
||||
vec3 tapUVZ = fetchTap(side, ssC, tap, imageSize);
|
||||
|
||||
|
@ -68,10 +69,10 @@ void main(void) {
|
|||
// Bilateral box-filter over a quad for free, respecting depth edges
|
||||
// (the difference that this makes is subtle)
|
||||
if (abs(dFdx(Cp.z)) < 0.02) {
|
||||
A -= dFdx(A) * ((ssC.x & 1) - 0.5);
|
||||
A -= dFdx(A) * (float(ssC.x & 1) - 0.5);
|
||||
}
|
||||
if (abs(dFdy(Cp.z)) < 0.02) {
|
||||
A -= dFdy(A) * ((ssC.y & 1) - 0.5);
|
||||
A -= dFdy(A) * (float(ssC.y & 1) - 0.5);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
layout(location=0) in vec2 varTexCoord0;
|
||||
layout(location=0) out vec4 _fragColor;
|
||||
|
||||
layout(location=GPU_UNIFORM_EXTRA0) uniform vec2 uniformCursorTexcoord = vec2(0.5);
|
||||
// FIXME make into a uniform buffer or push constant if this shader ever comes into use
|
||||
vec2 uniformCursorTexcoord = vec2(0.5);
|
||||
|
||||
//uniform vec3 uniformLightVector = vec3(1.0);
|
||||
|
||||
|
@ -79,7 +80,7 @@ vec3 drawScatteringTableUV(vec2 cursor, vec2 texcoord) {
|
|||
|
||||
vec3 distance = vec3(0.0);
|
||||
for (int c = 0; c < 3; c++) {
|
||||
vec2 BRDFuv = vec2(clamp(bentNdotL[c] * 0.5 + 0.5, 0.0, 1.0), clamp(2 * curvature, 0.0, 1.0));
|
||||
vec2 BRDFuv = vec2(clamp(bentNdotL[c] * 0.5 + 0.5, 0.0, 1.0), clamp(2.0 * curvature, 0.0, 1.0));
|
||||
vec2 delta = BRDFuv - texcoord;
|
||||
distance[c] = 1.0 - dot(delta, delta);
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ vec2 taa_fetchVelocityMap(vec2 uv) {
|
|||
}
|
||||
|
||||
float taa_fetchDepth(vec2 uv) {
|
||||
return -texture(depthMap, vec2(uv), 0).x;
|
||||
return -texture(depthMap, vec2(uv), 0.0).x;
|
||||
}
|
||||
|
||||
|
||||
|
@ -230,7 +230,7 @@ vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) {
|
|||
vec2 fragUV = eyeUV;
|
||||
if (isStereo()) {
|
||||
fragUV.x *= 0.5;
|
||||
fragUV.x += stereoSide*0.5;
|
||||
fragUV.x += float(stereoSide)*0.5;
|
||||
}
|
||||
return fragUV;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ void main(void) {
|
|||
vec2 cursorVelocityDir = cursorVelocity / cursorVelocityLength;
|
||||
vec2 cursorVelocityNor = vec2(cursorVelocityDir.y, -cursorVelocityDir.x);
|
||||
|
||||
if ((dot(cursorVelocityDir, cursorToFragVec) < 0) && abs(dot(cursorVelocityNor, cursorToFragVec)) < 1.0) {
|
||||
if ((dot(cursorVelocityDir, cursorToFragVec) < 0.0) && abs(dot(cursorVelocityNor, cursorToFragVec)) < 1.0) {
|
||||
|
||||
vec3 speedColor = taa_getVelocityColorRelative(cursorToFragLength);
|
||||
|
||||
|
@ -69,7 +69,7 @@ void main(void) {
|
|||
float tenPercentHeight = 0.1 * imageSize.y;
|
||||
float centerWidth = imageSize.x * 0.5;
|
||||
|
||||
//vec2 nextOrbPos = vec2(centerWidth, imageSize.y - 3 * tenPercentHeight);
|
||||
//vec2 nextOrbPos = vec2(centerWidth, imageSize.y - 3.0 * tenPercentHeight);
|
||||
vec2 nextOrbPos = cursorPos;
|
||||
vec2 nextOrbPosToPix = pixPos - nextOrbPos;
|
||||
float nextOrbPosToPixLength = length(nextOrbPosToPix);
|
||||
|
@ -146,7 +146,7 @@ void main(void) {
|
|||
prevColor = texture(historyMap, prevTexCoord).xyz;
|
||||
}
|
||||
|
||||
outFragColor.xyz = mix(prevColor, vec3(1,0,1), clamp(distance(prevColor, nextColor) - 0.01, 0, 1));
|
||||
outFragColor.xyz = mix(prevColor, vec3(1,0,1), clamp(distance(prevColor, nextColor) - 0.01, 0.0, 1.0));
|
||||
|
||||
if (pixVelocityLength > params.debugShowVelocityThreshold) {
|
||||
vec3 speedColor = taa_getVelocityColorAboveThreshold(pixVelocityLength);
|
||||
|
|
|
@ -256,29 +256,30 @@ void Font::setupGPU() {
|
|||
}
|
||||
}
|
||||
|
||||
void Font::rebuildVertices(float x, float y, const QString& str, const glm::vec2& bounds) {
|
||||
_verticesBuffer = std::make_shared<gpu::Buffer>();
|
||||
_numVertices = 0;
|
||||
_indicesBuffer = std::make_shared<gpu::Buffer>();
|
||||
_numIndices = 0;
|
||||
void Font::buildVertices(Font::DrawInfo& drawInfo, const QString& str, const glm::vec2& origin, const glm::vec2& bounds) {
|
||||
drawInfo.verticesBuffer = std::make_shared<gpu::Buffer>();
|
||||
drawInfo.indicesBuffer = std::make_shared<gpu::Buffer>();
|
||||
drawInfo.indexCount = 0;
|
||||
int numVertices = 0;
|
||||
|
||||
_lastStringRendered = str;
|
||||
_lastBounds = bounds;
|
||||
drawInfo.string = str;
|
||||
drawInfo.bounds = bounds;
|
||||
drawInfo.origin = origin;
|
||||
|
||||
// Top left of text
|
||||
glm::vec2 advance = glm::vec2(x, y);
|
||||
glm::vec2 advance = origin;
|
||||
foreach(const QString& token, tokenizeForWrapping(str)) {
|
||||
bool isNewLine = (token == QString('\n'));
|
||||
bool forceNewLine = false;
|
||||
|
||||
// Handle wrapping
|
||||
if (!isNewLine && (bounds.x != -1) && (advance.x + computeExtent(token).x > x + bounds.x)) {
|
||||
if (!isNewLine && (bounds.x != -1) && (advance.x + computeExtent(token).x > origin.x + bounds.x)) {
|
||||
// We are out of the x bound, force new line
|
||||
forceNewLine = true;
|
||||
}
|
||||
if (isNewLine || forceNewLine) {
|
||||
// Character return, move the advance to a new line
|
||||
advance = glm::vec2(x, advance.y - _leading);
|
||||
advance = glm::vec2(origin.x, advance.y - _leading);
|
||||
|
||||
if (isNewLine) {
|
||||
// No need to draw anything, go directly to next token
|
||||
|
@ -288,7 +289,7 @@ void Font::rebuildVertices(float x, float y, const QString& str, const glm::vec2
|
|||
break;
|
||||
}
|
||||
}
|
||||
if ((bounds.y != -1) && (advance.y - _fontSize < -y - bounds.y)) {
|
||||
if ((bounds.y != -1) && (advance.y - _fontSize < -origin.y - bounds.y)) {
|
||||
// We are out of the y bound, stop drawing
|
||||
break;
|
||||
}
|
||||
|
@ -297,11 +298,11 @@ void Font::rebuildVertices(float x, float y, const QString& str, const glm::vec2
|
|||
if (!isNewLine) {
|
||||
for (auto c : token) {
|
||||
auto glyph = _glyphs[c];
|
||||
quint16 verticesOffset = _numVertices;
|
||||
quint16 verticesOffset = numVertices;
|
||||
|
||||
QuadBuilder qd(glyph, advance - glm::vec2(0.0f, _ascent));
|
||||
_verticesBuffer->append(sizeof(QuadBuilder), (const gpu::Byte*)&qd);
|
||||
_numVertices += 4;
|
||||
drawInfo.verticesBuffer->append(qd);
|
||||
numVertices += 4;
|
||||
|
||||
// Sam's recommended triangle slices
|
||||
// Triangle tri1 = { v0, v1, v3 };
|
||||
|
@ -327,8 +328,8 @@ void Font::rebuildVertices(float x, float y, const QString& str, const glm::vec2
|
|||
indices[3] = verticesOffset + 2;
|
||||
indices[4] = verticesOffset + 1;
|
||||
indices[5] = verticesOffset + 3;
|
||||
_indicesBuffer->append(sizeof(indices), (const gpu::Byte*)indices);
|
||||
_numIndices += NUMBER_OF_INDICES_PER_QUAD;
|
||||
drawInfo.indicesBuffer->append(sizeof(indices), (const gpu::Byte*)indices);
|
||||
drawInfo.indexCount += NUMBER_OF_INDICES_PER_QUAD;
|
||||
|
||||
|
||||
// Advance by glyph size
|
||||
|
@ -341,26 +342,39 @@ void Font::rebuildVertices(float x, float y, const QString& str, const glm::vec2
|
|||
}
|
||||
}
|
||||
|
||||
void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4* color,
|
||||
EffectType effectType, const glm::vec2& bounds, bool layered) {
|
||||
void Font::drawString(gpu::Batch& batch, Font::DrawInfo& drawInfo, const QString& str, const glm::vec4& color,
|
||||
EffectType effectType, const glm::vec2& origin, const glm::vec2& bounds, bool layered) {
|
||||
if (str == "") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (str != _lastStringRendered || bounds != _lastBounds) {
|
||||
rebuildVertices(x, y, str, bounds);
|
||||
if (str != drawInfo.string || bounds != drawInfo.bounds || origin != drawInfo.origin) {
|
||||
buildVertices(drawInfo, str, origin, bounds);
|
||||
}
|
||||
|
||||
setupGPU();
|
||||
|
||||
batch.setPipeline(((*color).a < 1.0f || layered) ? _transparentPipeline : _pipeline);
|
||||
batch.setResourceTexture(render_utils::slot::texture::TextFont, _texture);
|
||||
batch._glUniform1i(render_utils::slot::uniform::TextOutline, (effectType == OUTLINE_EFFECT));
|
||||
struct GpuDrawParams {
|
||||
glm::vec4 color;
|
||||
glm::vec4 outline;
|
||||
};
|
||||
|
||||
if (!drawInfo.paramsBuffer || drawInfo.params.color != color || drawInfo.params.effect != effectType) {
|
||||
drawInfo.params.color = color;
|
||||
drawInfo.params.effect = effectType;
|
||||
GpuDrawParams gpuDrawParams;
|
||||
gpuDrawParams.color = ColorUtils::sRGBToLinearVec4(drawInfo.params.color);
|
||||
gpuDrawParams.outline.x = (drawInfo.params.effect == OUTLINE_EFFECT) ? 1 : 0;
|
||||
drawInfo.paramsBuffer = std::make_shared<gpu::Buffer>(sizeof(GpuDrawParams), nullptr);
|
||||
drawInfo.paramsBuffer->setSubData(0, sizeof(GpuDrawParams), (const gpu::Byte*)&gpuDrawParams);
|
||||
}
|
||||
// need the gamma corrected color here
|
||||
glm::vec4 lrgba = ColorUtils::sRGBToLinearVec4(*color);
|
||||
batch._glUniform4fv(render_utils::slot::uniform::TextColor, 1, (const float*)&lrgba);
|
||||
|
||||
batch.setPipeline((color.a < 1.0f || layered) ? _transparentPipeline : _pipeline);
|
||||
batch.setInputFormat(_format);
|
||||
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
||||
batch.setIndexBuffer(gpu::UINT16, _indicesBuffer, 0);
|
||||
batch.drawIndexed(gpu::TRIANGLES, _numIndices, 0);
|
||||
batch.setInputBuffer(0, drawInfo.verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
||||
batch.setResourceTexture(render_utils::slot::texture::TextFont, _texture);
|
||||
batch.setUniformBuffer(0, drawInfo.paramsBuffer, 0, sizeof(GpuDrawParams));
|
||||
batch.setIndexBuffer(gpu::UINT16, drawInfo.indicesBuffer, 0);
|
||||
batch.drawIndexed(gpu::TRIANGLES, drawInfo.indexCount, 0);
|
||||
}
|
||||
|
|
|
@ -23,16 +23,34 @@ public:
|
|||
|
||||
void read(QIODevice& path);
|
||||
|
||||
struct DrawParams {
|
||||
vec4 color{ -1 };
|
||||
EffectType effect;
|
||||
};
|
||||
|
||||
struct DrawInfo {
|
||||
gpu::BufferPointer verticesBuffer;
|
||||
gpu::BufferPointer indicesBuffer;
|
||||
gpu::BufferPointer paramsBuffer;
|
||||
uint32_t indexCount;
|
||||
|
||||
QString string;
|
||||
glm::vec2 origin;
|
||||
glm::vec2 bounds;
|
||||
DrawParams params;
|
||||
};
|
||||
|
||||
glm::vec2 computeExtent(const QString& str) const;
|
||||
float getFontSize() const { return _fontSize; }
|
||||
|
||||
// Render string to batch
|
||||
void drawString(gpu::Batch& batch, float x, float y, const QString& str,
|
||||
const glm::vec4* color, EffectType effectType,
|
||||
const glm::vec2& bound, bool layered = false);
|
||||
void drawString(gpu::Batch& batch, DrawInfo& drawInfo, const QString& str,
|
||||
const glm::vec4& color, EffectType effectType,
|
||||
const glm::vec2& origin, const glm::vec2& bound, bool layered = false);
|
||||
|
||||
static Pointer load(const QString& family);
|
||||
|
||||
|
||||
private:
|
||||
static Pointer load(QIODevice& fontFile);
|
||||
QStringList tokenizeForWrapping(const QString& str) const;
|
||||
|
@ -40,7 +58,7 @@ private:
|
|||
glm::vec2 computeTokenExtent(const QString& str) const;
|
||||
|
||||
const Glyph& getGlyph(const QChar& c) const;
|
||||
void rebuildVertices(float x, float y, const QString& str, const glm::vec2& bounds);
|
||||
void buildVertices(DrawInfo& drawInfo, const QString& str, const glm::vec2& origin, const glm::vec2& bounds);
|
||||
|
||||
void setupGPU();
|
||||
|
||||
|
@ -66,15 +84,7 @@ private:
|
|||
gpu::PipelinePointer _transparentPipeline;
|
||||
gpu::TexturePointer _texture;
|
||||
gpu::Stream::FormatPointer _format;
|
||||
gpu::BufferPointer _verticesBuffer;
|
||||
gpu::BufferPointer _indicesBuffer;
|
||||
gpu::BufferStreamPointer _stream;
|
||||
unsigned int _numVertices = 0;
|
||||
unsigned int _numIndices = 0;
|
||||
|
||||
// last string render characteristics
|
||||
QString _lastStringRendered;
|
||||
glm::vec2 _lastBounds;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,7 +44,7 @@ void main(void) {
|
|||
// vec3 ambient = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(lightAmbient), fragNormal).xyz;
|
||||
// _fragColor = vec4( 0.5 * (fragNormal + vec3(1.0)), 1.0);
|
||||
|
||||
vec3 color = (sphereUV.x > 0 ? ambientMap : ambientSH);
|
||||
vec3 color = (sphereUV.x > 0.0 ? ambientMap : ambientSH);
|
||||
|
||||
color = color * 1.0 - base.w + base.xyz * base.w;
|
||||
const float INV_GAMMA_22 = 1.0 / 2.2;
|
||||
|
|
|
@ -36,6 +36,9 @@ const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() {
|
|||
|
||||
// Good to go add the brand new pipeline
|
||||
_drawCellBoundsPipeline = gpu::Pipeline::create(program, state);
|
||||
_cellBoundsFormat = std::make_shared<gpu::Stream::Format>();
|
||||
_cellBoundsFormat->setAttribute(0, 0, gpu::Element(gpu::VEC4, gpu::INT32, gpu::XYZW), 0, gpu::Stream::PER_INSTANCE);
|
||||
_cellBoundsBuffer = std::make_shared<gpu::Buffer>();
|
||||
}
|
||||
return _drawCellBoundsPipeline;
|
||||
}
|
||||
|
@ -82,8 +85,11 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS
|
|||
|
||||
// bind the one gpu::Pipeline we need
|
||||
batch.setPipeline(getDrawCellBoundsPipeline());
|
||||
batch.setInputFormat(_cellBoundsFormat);
|
||||
|
||||
auto drawCellBounds = [this, &scene, &batch](const std::vector<gpu::Stamp>& cells) {
|
||||
std::vector<ivec4> cellBounds;
|
||||
auto drawCellBounds = [this, &cellBounds, &scene, &batch](const std::vector<gpu::Stamp>& cells) {
|
||||
cellBounds.reserve(cellBounds.size() + cells.size());
|
||||
for (const auto& cellID : cells) {
|
||||
auto cell = scene->getSpatialTree().getConcreteCell(cellID);
|
||||
auto cellLoc = cell.getlocation();
|
||||
|
@ -98,14 +104,19 @@ void DrawSceneOctree::run(const RenderContextPointer& renderContext, const ItemS
|
|||
} else if (!empty && !_showVisibleCells) {
|
||||
continue;
|
||||
}
|
||||
|
||||
batch._glUniform4iv(gpu::slot::uniform::Extra0, 1, ((const int*)(&cellLocation)));
|
||||
batch.draw(gpu::LINES, 24, 0);
|
||||
cellBounds.push_back(cellLocation);
|
||||
}
|
||||
};
|
||||
|
||||
drawCellBounds(inSelection.cellSelection.insideCells);
|
||||
drawCellBounds(inSelection.cellSelection.partialCells);
|
||||
auto size = cellBounds.size() * sizeof(ivec4);
|
||||
if (size > _cellBoundsBuffer->getSize()) {
|
||||
_cellBoundsBuffer->resize(size);
|
||||
}
|
||||
_cellBoundsBuffer->setSubData(0, cellBounds);
|
||||
batch.setInputBuffer(0, _cellBoundsBuffer, 0, sizeof(ivec4));
|
||||
batch.drawInstanced((uint32_t)cellBounds.size(), gpu::LINES, 24);
|
||||
|
||||
// Draw the LOD Reticle
|
||||
{
|
||||
|
|
|
@ -54,6 +54,8 @@ namespace render {
|
|||
gpu::PipelinePointer _drawCellBoundsPipeline;
|
||||
gpu::PipelinePointer _drawLODReticlePipeline;
|
||||
gpu::PipelinePointer _drawItemBoundPipeline;
|
||||
gpu::BufferPointer _cellBoundsBuffer;
|
||||
gpu::Stream::FormatPointer _cellBoundsFormat;
|
||||
|
||||
bool _showVisibleCells; // initialized by Config
|
||||
bool _showEmptyCells; // initialized by Config
|
||||
|
|
|
@ -170,13 +170,45 @@ void DrawStatus::run(const RenderContextPointer& renderContext, const Input& inp
|
|||
batch.setPipeline(getDrawItemStatusPipeline());
|
||||
|
||||
if (_showNetwork) {
|
||||
for (size_t i = 0; i < itemBounds.size(); i++) {
|
||||
batch._glUniform3fv(gpu::slot::uniform::Extra0, 1, (const float*)&itemBounds[i].bound.getCorner());
|
||||
batch._glUniform3fv(gpu::slot::uniform::Extra1, 1, ((const float*)&itemBounds[i].bound.getScale()));
|
||||
batch._glUniform4iv(gpu::slot::uniform::Extra2, 1, (const int*)&(itemStatus[i].first));
|
||||
batch._glUniform4iv(gpu::slot::uniform::Extra3, 1, (const int*)&(itemStatus[i].second));
|
||||
batch.draw(gpu::TRIANGLES, 24 * NUM_STATUS_VEC4_PER_ITEM, 0);
|
||||
if (!_instanceBuffer) {
|
||||
_instanceBuffer = std::make_shared<gpu::Buffer>();
|
||||
}
|
||||
|
||||
struct InstanceData {
|
||||
vec4 boundPos;
|
||||
vec4 boundDim;
|
||||
ivec4 status0;
|
||||
ivec4 status1;
|
||||
};
|
||||
|
||||
if (!_vertexFormat) {
|
||||
_vertexFormat = std::make_shared<gpu::Stream::Format>();
|
||||
_vertexFormat->setAttribute(0, 0, gpu::Element(gpu::VEC4, gpu::FLOAT, gpu::XYZW), offsetof(InstanceData, boundPos), gpu::Stream::PER_INSTANCE);
|
||||
_vertexFormat->setAttribute(1, 0, gpu::Element(gpu::VEC4, gpu::FLOAT, gpu::XYZW), offsetof(InstanceData, boundDim), gpu::Stream::PER_INSTANCE);
|
||||
_vertexFormat->setAttribute(2, 0, gpu::Element(gpu::VEC4, gpu::INT32, gpu::XYZW), offsetof(InstanceData, status0), gpu::Stream::PER_INSTANCE);
|
||||
_vertexFormat->setAttribute(3, 0, gpu::Element(gpu::VEC4, gpu::INT32, gpu::XYZW), offsetof(InstanceData, status1), gpu::Stream::PER_INSTANCE);
|
||||
}
|
||||
|
||||
batch.setInputFormat(_vertexFormat);
|
||||
std::vector<InstanceData> instanceData;
|
||||
instanceData.resize(itemBounds.size());
|
||||
for (size_t i = 0; i < itemBounds.size(); i++) {
|
||||
InstanceData& item = instanceData[i];
|
||||
const auto& bound = itemBounds[i].bound;
|
||||
const auto& status = itemStatus[i];
|
||||
item.boundPos = vec4(bound.getCorner(), 1.0f);
|
||||
item.boundDim = vec4(bound.getScale(), 1.0f);
|
||||
item.status0 = status.first;
|
||||
item.status1 = status.second;
|
||||
}
|
||||
|
||||
auto instanceBufferSize = sizeof(InstanceData) * instanceData.size();
|
||||
if (_instanceBuffer->getSize() < instanceBufferSize) {
|
||||
_instanceBuffer->resize(instanceBufferSize);
|
||||
}
|
||||
_instanceBuffer->setSubData(0, instanceData);
|
||||
batch.setInputBuffer(0, _instanceBuffer, 0, sizeof(InstanceData));
|
||||
batch.drawInstanced((uint32_t)instanceData.size(), gpu::TRIANGLES, 24 * NUM_STATUS_VEC4_PER_ITEM);
|
||||
}
|
||||
batch.setResourceTexture(0, 0);
|
||||
});
|
||||
|
|
|
@ -63,6 +63,8 @@ namespace render {
|
|||
gpu::PipelinePointer _drawItemStatusPipeline;
|
||||
|
||||
gpu::BufferPointer _boundsBuffer;
|
||||
gpu::BufferPointer _instanceBuffer;
|
||||
gpu::Stream::FormatPointer _vertexFormat;
|
||||
gpu::TexturePointer _statusIconMap;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -184,8 +184,13 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
|
|||
_drawBuffer = std::make_shared<gpu::Buffer>(sizeOfItemBound);
|
||||
}
|
||||
|
||||
_drawBuffer->setData(numItems * sizeOfItemBound, (const gpu::Byte*) items.data());
|
||||
if (!_paramsBuffer) {
|
||||
_paramsBuffer = std::make_shared<gpu::Buffer>(sizeof(vec4), nullptr);
|
||||
}
|
||||
|
||||
_drawBuffer->setData(numItems * sizeOfItemBound, (const gpu::Byte*) items.data());
|
||||
glm::vec4 color(glm::vec3(0.0f), -(float) numItems);
|
||||
_paramsBuffer->setSubData(0, color);
|
||||
gpu::doInBatch("DrawBounds::run", args->_context, [&](gpu::Batch& batch) {
|
||||
args->_batch = &batch;
|
||||
|
||||
|
@ -202,7 +207,7 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
|
|||
batch.setPipeline(getPipeline());
|
||||
|
||||
glm::vec4 color(glm::vec3(0.0f), -(float) numItems);
|
||||
batch._glUniform4fv(gpu::slot::uniform::Color, 1, (const float*)(&color));
|
||||
batch.setUniformBuffer(0, _paramsBuffer);
|
||||
batch.setResourceBuffer(0, _drawBuffer);
|
||||
|
||||
static const int NUM_VERTICES_PER_CUBE = 24;
|
||||
|
@ -212,9 +217,10 @@ void DrawBounds::run(const RenderContextPointer& renderContext,
|
|||
|
||||
gpu::Stream::FormatPointer DrawQuadVolume::_format;
|
||||
|
||||
DrawQuadVolume::DrawQuadVolume(const glm::vec3& color) :
|
||||
_color{ color } {
|
||||
DrawQuadVolume::DrawQuadVolume(const glm::vec3& color) {
|
||||
_meshVertices = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(glm::vec3) * 8, nullptr), gpu::Element::VEC3F_XYZ);
|
||||
_params = std::make_shared<gpu::Buffer>(sizeof(glm::vec4), nullptr);
|
||||
_params->setSubData(0, vec4(color, 1.0));
|
||||
if (!_format) {
|
||||
_format = std::make_shared<gpu::Stream::Format>();
|
||||
_format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
|
||||
|
@ -248,8 +254,7 @@ void DrawQuadVolume::run(const render::RenderContextPointer& renderContext, cons
|
|||
batch.setProjectionTransform(projMat);
|
||||
batch.setViewTransform(viewMat);
|
||||
batch.setPipeline(getPipeline());
|
||||
|
||||
batch._glUniform4f(0, _color.x, _color.y, _color.z, 1.0f);
|
||||
batch.setUniformBuffer(0, _params);
|
||||
batch.setInputFormat(_format);
|
||||
batch.setInputBuffer(gpu::Stream::POSITION, _meshVertices);
|
||||
batch.setIndexBuffer(indices);
|
||||
|
|
|
@ -66,6 +66,7 @@ private:
|
|||
const gpu::PipelinePointer getPipeline();
|
||||
gpu::PipelinePointer _boundsPipeline;
|
||||
gpu::BufferPointer _drawBuffer;
|
||||
gpu::BufferPointer _paramsBuffer;
|
||||
};
|
||||
|
||||
class DrawQuadVolumeConfig : public render::JobConfig {
|
||||
|
@ -95,7 +96,7 @@ protected:
|
|||
const gpu::BufferView& indices, int indexCount);
|
||||
|
||||
gpu::BufferView _meshVertices;
|
||||
glm::vec3 _color;
|
||||
gpu::BufferPointer _params;
|
||||
bool _isUpdateEnabled{ true };
|
||||
|
||||
static gpu::Stream::FormatPointer _format;
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
<$declareColorWheel()$>
|
||||
<@include SceneOctree.slh@>
|
||||
|
||||
layout(location=GPU_UNIFORM_EXTRA0) uniform ivec4 inCellLocation;
|
||||
|
||||
layout(location=0) in ivec4 inCellLocation;
|
||||
layout(location=0) out vec4 varColor;
|
||||
|
||||
void main(void) {
|
||||
|
@ -62,5 +61,5 @@ void main(void) {
|
|||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
||||
|
||||
varColor = vec4(colorWheel(fract(float(inCellLocation.w) / 5.0)), 0.8 + 0.2 * cellIsEmpty);
|
||||
varColor = vec4(colorWheel(fract(float(inCellLocation.w) / 5.0)), 0.8 + 0.2 * float(cellIsEmpty));
|
||||
}
|
|
@ -20,7 +20,14 @@
|
|||
<@include gpu/Color.slh@>
|
||||
<$declareColorWheel()$>
|
||||
|
||||
layout(location=GPU_UNIFORM_COLOR) uniform vec4 inColor;
|
||||
struct DrawItemBoundsParams {
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
layout(binding=0) uniform drawItemBoundsParamsBuffer {
|
||||
DrawItemBoundsParams params;
|
||||
};
|
||||
|
||||
|
||||
struct ItemBound {
|
||||
vec4 id_boundPos;
|
||||
|
@ -91,10 +98,10 @@ void main(void) {
|
|||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
||||
|
||||
if (inColor.w < 0.0) {
|
||||
varColor = vec4(colorWheel(float(boundID)/(-inColor.w)), 1.0);
|
||||
if (params.color.w < 0.0) {
|
||||
varColor = vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0);
|
||||
} else {
|
||||
varColor = vec4(colorWheel(float(inColor.w)), 1.0);
|
||||
varColor = vec4(colorWheel(float(params.color.w)), 1.0);
|
||||
}
|
||||
varTexcoord = vec2(cubeVec.w, length(boundDim));
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
layout(location=0) out vec4 varColor;
|
||||
layout(location=1) out vec3 varTexcoord;
|
||||
|
||||
layout(location=GPU_UNIFORM_EXTRA0) uniform vec3 inBoundPos;
|
||||
layout(location=GPU_UNIFORM_EXTRA1) uniform vec3 inBoundDim;
|
||||
layout(location=GPU_UNIFORM_EXTRA2) uniform ivec4 inStatus0;
|
||||
layout(location=GPU_UNIFORM_EXTRA3) uniform ivec4 inStatus1;
|
||||
layout(location=0) in vec3 inBoundPos;
|
||||
layout(location=1) in vec3 inBoundDim;
|
||||
layout(location=2) in ivec4 inStatus0;
|
||||
layout(location=3) in ivec4 inStatus1;
|
||||
|
||||
vec3 paintRainbow(float normalizedHue) {
|
||||
float v = normalizedHue * 6.f;
|
||||
|
|
|
@ -230,8 +230,8 @@ void ShaderTests::testShaderLoad() {
|
|||
auto glBackend = std::static_pointer_cast<gpu::gl::GLBackend>(_gpuContext->getBackend());
|
||||
auto glshader = gpu::gl::GLShader::sync(*glBackend, *program);
|
||||
if (!glshader) {
|
||||
qDebug() << "Failed to compile or link vertex " << vertexId << " fragment " << fragmentId;
|
||||
continue;
|
||||
qWarning() << "Failed to compile or link vertex " << vertexId << " fragment " << fragmentId;
|
||||
QFAIL("Program link error");
|
||||
}
|
||||
|
||||
QVERIFY(glshader != nullptr);
|
||||
|
@ -301,7 +301,7 @@ void ShaderTests::testShaderLoad() {
|
|||
QFAIL(error.what());
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i <= maxShader; ++i) {
|
||||
for (uint32_t i = 1; i <= maxShader; ++i) {
|
||||
auto used = usedShaders.count(i);
|
||||
if (0 != usedShaders.count(i)) {
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue