Renderer性能优化
parent
fc75668c68
commit
d968b585fb
|
@ -207,6 +207,7 @@
|
||||||
<None Include="res\Shaders\painting.comp" />
|
<None Include="res\Shaders\painting.comp" />
|
||||||
<None Include="res\Shaders\painting.frag" />
|
<None Include="res\Shaders\painting.frag" />
|
||||||
<None Include="res\Shaders\painting.vert" />
|
<None Include="res\Shaders\painting.vert" />
|
||||||
|
<None Include="res\Shaders\painting_shadow.frag" />
|
||||||
<None Include="res\Shaders\shader.frag" />
|
<None Include="res\Shaders\shader.frag" />
|
||||||
<None Include="res\Shaders\shader.vert" />
|
<None Include="res\Shaders\shader.vert" />
|
||||||
<None Include="res\Shaders\shadow_mapping.comp" />
|
<None Include="res\Shaders\shadow_mapping.comp" />
|
||||||
|
|
|
@ -465,6 +465,7 @@
|
||||||
<Filter>Resource Files\Shaders</Filter>
|
<Filter>Resource Files\Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="res\Shaders\tone_mapping.comp" />
|
<None Include="res\Shaders\tone_mapping.comp" />
|
||||||
|
<None Include="res\Shaders\painting_shadow.frag" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtUic Include="EditorWidgetItem.ui">
|
<QtUic Include="EditorWidgetItem.ui">
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
<file>Shaders/brdf_lut.comp</file>
|
<file>Shaders/brdf_lut.comp</file>
|
||||||
<file>Shaders/pageId_downsample.comp</file>
|
<file>Shaders/pageId_downsample.comp</file>
|
||||||
<file>Shaders/tone_mapping.comp</file>
|
<file>Shaders/tone_mapping.comp</file>
|
||||||
|
<file>Shaders/painting_shadow.frag</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/qt/etc">
|
<qresource prefix="/qt/etc">
|
||||||
<file>qt.conf</file>
|
<file>qt.conf</file>
|
||||||
|
|
|
@ -46,12 +46,15 @@ void main()
|
||||||
if(gBaseColor.a<0.4)
|
if(gBaseColor.a<0.4)
|
||||||
discard;
|
discard;
|
||||||
gPosition = WorldPos;
|
gPosition = WorldPos;
|
||||||
|
|
||||||
if(texture_normal_available)
|
if(texture_normal_available)
|
||||||
gNormal = getNormalFromMap();
|
gNormal = getNormalFromMap();
|
||||||
else
|
else
|
||||||
gNormal = Normal;
|
gNormal = Normal;
|
||||||
if(!gl_FrontFacing)
|
if(!gl_FrontFacing)
|
||||||
gNormal = -gNormal;
|
gNormal = -gNormal;
|
||||||
|
gNormal = normalize(gNormal) / 2. + vec3(0.5);
|
||||||
|
|
||||||
if(texture_metallic_roughness_available)
|
if(texture_metallic_roughness_available)
|
||||||
gMetallicRoughness = texture(texture_metallic_roughness, TexCoords).bg;
|
gMetallicRoughness = texture(texture_metallic_roughness, TexCoords).bg;
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,11 +7,7 @@ in vec2 TexCoords;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 baseColor;// = texture(texture_basecolor, TexCoords);
|
vec4 baseColor = texture(texture_basecolor, TexCoords);
|
||||||
float lod = textureQueryLod(texture_basecolor, TexCoords).x;
|
|
||||||
while(!sparseTexelsResidentARB(sparseTextureLodARB(texture_basecolor, TexCoords, lod, baseColor))&&lod<textureQueryLevels(texture_basecolor))
|
|
||||||
lod++;
|
|
||||||
|
|
||||||
if(baseColor.a<0.4)
|
if(baseColor.a<0.4)
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
|
@ -28,12 +28,9 @@ void main()
|
||||||
discard;
|
discard;
|
||||||
//gBaseColor = vec4( vec3(1),1 );
|
//gBaseColor = vec4( vec3(1),1 );
|
||||||
gPosition = WorldPos;
|
gPosition = WorldPos;
|
||||||
gNormal = normalize(Normal);
|
gNormal = normalize(Normal) / 2. + vec3(0.5);
|
||||||
//gMetallicRoughness = vec2(0,1);
|
|
||||||
lod = lodExpect;
|
|
||||||
vec4 mt;
|
vec4 mt;
|
||||||
while(!sparseTexelsResidentARB(sparseTextureLodARB(texture_metallic_roughness, TexCoords, lod, mt))&&lod<levels)
|
sparseTextureLodARB(texture_metallic_roughness, TexCoords, lod, mt);
|
||||||
lod++;
|
|
||||||
gMetallicRoughness = mt.rg;
|
gMetallicRoughness = mt.rg;
|
||||||
|
|
||||||
uint w = 1<<(levels-1-lodExpect);
|
uint w = 1<<(levels-1-lodExpect);
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
in vec2 TexCoords;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
}
|
|
@ -191,7 +191,7 @@ void main()
|
||||||
float roughness = texelFetch(gMetallicRoughness, pixelLocation, 0).g;
|
float roughness = texelFetch(gMetallicRoughness, pixelLocation, 0).g;
|
||||||
|
|
||||||
vec3 worldPos = texelFetch(gPosition, pixelLocation,0).xyz;
|
vec3 worldPos = texelFetch(gPosition, pixelLocation,0).xyz;
|
||||||
vec3 normal = texelFetch(gNormal, pixelLocation,0).xyz;
|
vec3 normal = (texelFetch(gNormal, pixelLocation,0).xyz - vec3(0.5)) * 2;
|
||||||
|
|
||||||
normal = normalize(normal);
|
normal = normalize(normal);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ Light::Light(Camera* camera)
|
||||||
void Renderer::Light::updateShadowCascadeLevels()
|
void Renderer::Light::updateShadowCascadeLevels()
|
||||||
{
|
{
|
||||||
shadowCascadeLevels.clear();
|
shadowCascadeLevels.clear();
|
||||||
const float levelCount = 5;
|
const float levelCount = 4;
|
||||||
const float lambda = 0.5;
|
const float lambda = 0.5;
|
||||||
for (int i = 1; i < levelCount; i++)
|
for (int i = 1; i < levelCount; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,12 +37,12 @@ void Model::draw(QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* pain
|
||||||
mesh->draw(paintingProgram);
|
mesh->draw(paintingProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::drawShadow(QOpenGLShaderProgram* shadowProgram)
|
void Model::drawShadow(QOpenGLShaderProgram* shadowProgram, QOpenGLShaderProgram* paintingShadowProgram)
|
||||||
{
|
{
|
||||||
for (auto& mesh : meshes)
|
for (auto& mesh : meshes)
|
||||||
mesh->drawShadow(shadowProgram);
|
mesh->drawShadow(shadowProgram);
|
||||||
for (auto& mesh : paintingMeshes)
|
for (auto& mesh : paintingMeshes)
|
||||||
mesh->drawShadow(shadowProgram);
|
mesh->drawShadow(paintingShadowProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Model::loadModel(QString path)
|
void Renderer::Model::loadModel(QString path)
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Renderer
|
||||||
public:
|
public:
|
||||||
Model(QOpenGLContext* context, VirtualTextureManager* vtManager);
|
Model(QOpenGLContext* context, VirtualTextureManager* vtManager);
|
||||||
void draw(QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram);
|
void draw(QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram);
|
||||||
void drawShadow(QOpenGLShaderProgram* shadowProgram);
|
void drawShadow(QOpenGLShaderProgram* shadowProgram, QOpenGLShaderProgram* paintingShadowProgram);
|
||||||
void loadModel(QString path);
|
void loadModel(QString path);
|
||||||
void unloadModel();
|
void unloadModel();
|
||||||
const std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>>& getPaintingMap();
|
const std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>>& getPaintingMap();
|
||||||
|
|
|
@ -28,8 +28,6 @@ void PaintingMesh::drawShadow(QOpenGLShaderProgram* shadowProgram)
|
||||||
{
|
{
|
||||||
if (shadowProgram->bind())
|
if (shadowProgram->bind())
|
||||||
{
|
{
|
||||||
glFunc->glBindTextureUnit(0, textureBasecolor);
|
|
||||||
shadowProgram->setUniformValue("texture_basecolor", 0);
|
|
||||||
QOpenGLVertexArrayObject::Binder bind(&VAO);
|
QOpenGLVertexArrayObject::Binder bind(&VAO);
|
||||||
shadowProgram->setUniformValue("model", model);
|
shadowProgram->setUniformValue("model", model);
|
||||||
EBO.bind();
|
EBO.bind();
|
||||||
|
|
|
@ -7,16 +7,14 @@ namespace Renderer
|
||||||
ShadowMapPass::ShadowMapPass(GladGLContext* gl, GLuint& shadowFboHandle, int& shadowMapResolution, Light& light, Model*& model)
|
ShadowMapPass::ShadowMapPass(GladGLContext* gl, GLuint& shadowFboHandle, int& shadowMapResolution, Light& light, Model*& model)
|
||||||
: RenderPass(gl)
|
: RenderPass(gl)
|
||||||
, modelShadowShader(":/Shaders/model_shadow.vert", ":/Shaders/model_shadow.frag", ":/Shaders/model_shadow.geom")
|
, modelShadowShader(":/Shaders/model_shadow.vert", ":/Shaders/model_shadow.frag", ":/Shaders/model_shadow.geom")
|
||||||
|
, paintingShadowShader(":/Shaders/model_shadow.vert", ":/Shaders/painting_shadow.frag", ":/Shaders/model_shadow.geom")
|
||||||
, shadowFboHandle(shadowFboHandle), shadowMapResolution(shadowMapResolution), light(light), model(model)
|
, shadowFboHandle(shadowFboHandle), shadowMapResolution(shadowMapResolution), light(light), model(model)
|
||||||
{
|
{
|
||||||
modelShadowShader.bind();
|
gl->CreateBuffers(1, &lightSpaceMatricesUBO);
|
||||||
gl->GenBuffers(1, &lightSpaceMatricesUBO);
|
gl->NamedBufferData(lightSpaceMatricesUBO, sizeof(QMatrix4x4) * 16, nullptr, GL_STATIC_DRAW);
|
||||||
gl->BindBuffer(GL_UNIFORM_BUFFER, lightSpaceMatricesUBO);
|
|
||||||
gl->BufferData(GL_UNIFORM_BUFFER, sizeof(QMatrix4x4) * 16, nullptr, GL_STATIC_DRAW);
|
|
||||||
gl->BindBufferBase(GL_UNIFORM_BUFFER, 0, lightSpaceMatricesUBO);
|
gl->BindBufferBase(GL_UNIFORM_BUFFER, 0, lightSpaceMatricesUBO);
|
||||||
gl->BindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
||||||
modelShadowShader.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowMapPass::dispatch()
|
void ShadowMapPass::dispatch()
|
||||||
{
|
{
|
||||||
const std::vector<QMatrix4x4> lightMatrices = light.getLightSpaceMatrices();
|
const std::vector<QMatrix4x4> lightMatrices = light.getLightSpaceMatrices();
|
||||||
|
@ -32,7 +30,7 @@ namespace Renderer
|
||||||
gl->Clear(GL_DEPTH_BUFFER_BIT);
|
gl->Clear(GL_DEPTH_BUFFER_BIT);
|
||||||
//gl->CullFace(GL_FRONT);
|
//gl->CullFace(GL_FRONT);
|
||||||
if (model != nullptr)
|
if (model != nullptr)
|
||||||
model->drawShadow(&modelShadowShader);
|
model->drawShadow(&modelShadowShader, &paintingShadowShader);
|
||||||
//gl->CullFace(GL_BACK);
|
//gl->CullFace(GL_BACK);
|
||||||
|
|
||||||
gl->BindFramebuffer(GL_FRAMEBUFFER, 0);
|
gl->BindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Renderer
|
||||||
ShadowMapPass(GladGLContext* gl, GLuint& shadowFboHandle, int& shadowMapResolution, Light& light, Model*& model);
|
ShadowMapPass(GladGLContext* gl, GLuint& shadowFboHandle, int& shadowMapResolution, Light& light, Model*& model);
|
||||||
void dispatch();
|
void dispatch();
|
||||||
private:
|
private:
|
||||||
Shader modelShadowShader;
|
Shader modelShadowShader, paintingShadowShader;
|
||||||
GLuint& shadowFboHandle;
|
GLuint& shadowFboHandle;
|
||||||
int& shadowMapResolution;
|
int& shadowMapResolution;
|
||||||
Light& light;
|
Light& light;
|
||||||
|
|
|
@ -207,12 +207,12 @@ void RendererGLWidget::paintGL()
|
||||||
projection = camera.GetProjectionMatrix();
|
projection = camera.GetProjectionMatrix();
|
||||||
view = camera.GetViewMatrix();
|
view = camera.GetViewMatrix();
|
||||||
|
|
||||||
vtManager->commitMutex.lock();
|
//vtManager->commitMutex.lock();
|
||||||
shadowMapPass->dispatch();
|
shadowMapPass->dispatch();
|
||||||
geometryPass->dispatch();
|
geometryPass->dispatch();
|
||||||
pageIDCallbackPass->dispatch();
|
pageIDCallbackPass->dispatch();
|
||||||
gl->Finish();
|
//gl->Finish();
|
||||||
vtManager->commitMutex.unlock();
|
//vtManager->commitMutex.unlock();
|
||||||
lightingPass->dispatch();
|
lightingPass->dispatch();
|
||||||
skyboxPass->dispatch();
|
skyboxPass->dispatch();
|
||||||
toneMappingPass->dispatch();
|
toneMappingPass->dispatch();
|
||||||
|
@ -265,8 +265,6 @@ void RendererGLWidget::resizeGL(int width, int height)
|
||||||
frameHeight = ceil(devicePixelRatioF() * height);
|
frameHeight = ceil(devicePixelRatioF() * height);
|
||||||
qDebug() << frameWidth << "x" << frameHeight;
|
qDebug() << frameWidth << "x" << frameHeight;
|
||||||
camera.Ratio = (float)frameWidth / (float)frameHeight;
|
camera.Ratio = (float)frameWidth / (float)frameHeight;
|
||||||
//qDebug() << devicePixelRatioF() << width << height;
|
|
||||||
//gl->Viewport(0, 0, (GLint)devicePixelRatio()*width, (GLint)devicePixelRatio()*height);
|
|
||||||
|
|
||||||
if (fboPtr != nullptr)
|
if (fboPtr != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -286,7 +284,7 @@ void RendererGLWidget::resizeGL(int width, int height)
|
||||||
gl->GenTextures(9, gbuffers + 1);
|
gl->GenTextures(9, gbuffers + 1);
|
||||||
//Normal
|
//Normal
|
||||||
gl->BindTexture(GL_TEXTURE_2D, gbuffers[1]);
|
gl->BindTexture(GL_TEXTURE_2D, gbuffers[1]);
|
||||||
gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, frameWidth, frameHeight, 0, GL_RGB, GL_FLOAT, NULL);
|
gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB10, frameWidth, frameHeight, 0, GL_RGB, GL_UNSIGNED_INT, NULL);
|
||||||
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, gbuffers[1], 0);
|
gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, gbuffers[1], 0);
|
||||||
|
@ -314,7 +312,7 @@ void RendererGLWidget::resizeGL(int width, int height)
|
||||||
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, GL_TEXTURE_2D, gbuffers[5], 0);
|
gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, GL_TEXTURE_2D, gbuffers[5], 0);
|
||||||
//Depth, Deprecated
|
//Depth
|
||||||
gl->BindTexture(GL_TEXTURE_2D, gbuffers[6]);
|
gl->BindTexture(GL_TEXTURE_2D, gbuffers[6]);
|
||||||
gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, frameWidth, frameHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
gl->TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, frameWidth, frameHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
||||||
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
@ -326,7 +324,6 @@ void RendererGLWidget::resizeGL(int width, int height)
|
||||||
|
|
||||||
GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5 };
|
GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5 };
|
||||||
gl->DrawBuffers(6, attachments);
|
gl->DrawBuffers(6, attachments);
|
||||||
//gbuffers = fboPtr->textures();
|
|
||||||
|
|
||||||
if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
if (gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
qDebug() << "Framebuffer not complete!";
|
qDebug() << "Framebuffer not complete!";
|
||||||
|
@ -365,8 +362,7 @@ void RendererGLWidget::resizeGL(int width, int height)
|
||||||
gl->DeleteFramebuffers(1, &shadowFboHandle);
|
gl->DeleteFramebuffers(1, &shadowFboHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
//shadowMapResolution = 1.5 * std::max(frameWidth, frameHeight);
|
shadowMapResolution = std::min(2048u, qNextPowerOfTwo(static_cast<int>(std::max(frameWidth, frameHeight) * 3.8)));
|
||||||
shadowMapResolution = 2048;
|
|
||||||
gl->GenFramebuffers(1, &shadowFboHandle);
|
gl->GenFramebuffers(1, &shadowFboHandle);
|
||||||
{
|
{
|
||||||
gl->BindFramebuffer(GL_FRAMEBUFFER, shadowFboHandle);
|
gl->BindFramebuffer(GL_FRAMEBUFFER, shadowFboHandle);
|
||||||
|
|
Loading…
Reference in New Issue