Reduced boilerplate needed to select and bind a KRPipeline
This commit is contained in:
@@ -140,7 +140,7 @@ void KRAmbientZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, st
|
||||
|
||||
KRPipeline *pPipeline = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pPipeline, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pPipeline, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -207,7 +207,7 @@ void KRAudioSource::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, st
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -102,7 +102,7 @@ void KRBone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vect
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if(sphereModels.size()) {
|
||||
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
|
||||
|
||||
@@ -340,19 +340,13 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
if(m_pSkyBoxTexture) {
|
||||
|
||||
std::string shader_name("sky_box");
|
||||
std::vector<KRPointLight*> no_point_lights;
|
||||
std::vector<KRDirectionalLight*> no_directional_lights;
|
||||
std::vector<KRSpotLight*> no_spot_lights;
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = this;
|
||||
info.point_lights = &no_point_lights;
|
||||
info.directional_lights = &no_directional_lights;
|
||||
info.spot_lights = &no_spot_lights;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE;
|
||||
|
||||
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(info);
|
||||
getContext().getPipelineManager()->selectPipeline(*this, pPipeline, m_viewport, Matrix4(), no_point_lights, no_directional_lights, no_spot_lights, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
getContext().getPipelineManager()->selectPipeline(*this, pPipeline, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE);
|
||||
|
||||
@@ -539,16 +533,10 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
|
||||
std::vector<KRPointLight*> no_point_lights;
|
||||
std::vector<KRDirectionalLight*> no_directional_lights;
|
||||
std::vector<KRSpotLight*> no_spot_lights;
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("visualize_overlay");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = this;
|
||||
info.point_lights = &no_point_lights;
|
||||
info.directional_lights = &no_directional_lights;
|
||||
info.spot_lights = &no_spot_lights;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
KRPipeline *pVisShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
@@ -557,7 +545,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
Matrix4 matModel = Matrix4();
|
||||
matModel.scale((*itr).first.size() * 0.5f);
|
||||
matModel.translate((*itr).first.center());
|
||||
if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
}
|
||||
@@ -782,22 +770,16 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
|
||||
GLDEBUG(glViewport(0, 0, (GLsizei)m_viewport.getSize().x, (GLsizei)m_viewport.getSize().y));
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
std::vector<KRPointLight*> no_point_lights;
|
||||
std::vector<KRDirectionalLight*> no_directional_lights;
|
||||
std::vector<KRSpotLight*> no_spot_lights;
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("PostShader");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = this;
|
||||
info.point_lights = &no_point_lights;
|
||||
info.directional_lights = &no_directional_lights;
|
||||
info.spot_lights = &no_spot_lights;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
|
||||
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
|
||||
Vector3 rim_color;
|
||||
getContext().getPipelineManager()->selectPipeline(*this, postShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color);
|
||||
getContext().getPipelineManager()->selectPipeline(*this, postShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color);
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture);
|
||||
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 1, compositeColorTexture);
|
||||
@@ -979,19 +961,13 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
|
||||
// Enable alpha blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
std::vector<KRPointLight*> no_point_lights;
|
||||
std::vector<KRDirectionalLight*> no_directional_lights;
|
||||
std::vector<KRSpotLight*> no_spot_lights;
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("debug_font");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = this;
|
||||
info.point_lights = &no_point_lights;
|
||||
info.directional_lights = &no_directional_lights;
|
||||
info.spot_lights = &no_spot_lights;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI);
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ void KRCollider::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -130,9 +130,6 @@ void KRDirectionalLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamer
|
||||
std::vector<KRDirectionalLight *> this_light;
|
||||
this_light.push_back(this);
|
||||
|
||||
std::vector<KRPointLight*> no_point_lights;
|
||||
std::vector<KRSpotLight*> no_spot_lights;
|
||||
|
||||
Matrix4 matModelViewInverseTranspose = viewport.getViewMatrix() * getModelMatrix();
|
||||
matModelViewInverseTranspose.transpose();
|
||||
matModelViewInverseTranspose.invert();
|
||||
@@ -145,13 +142,11 @@ void KRDirectionalLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamer
|
||||
std::string shader_name("light_directional");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &no_point_lights;
|
||||
info.directional_lights = &this_light;
|
||||
info.spot_lights = &no_spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), no_point_lights, this_light, no_spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), nullptr, &this_light, nullptr, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
|
||||
|
||||
@@ -268,7 +268,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, particleModelMatrix, &this_point_light, &this_directional_light, &this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_PARTICLE_ORIGIN, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
|
||||
@@ -316,7 +316,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
|
||||
KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pFogShader, viewport, Matrix4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pFogShader, viewport, Matrix4(), &this_point_light, &this_directional_light, &this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5;
|
||||
|
||||
float slice_near = -pCamera->settings.getPerspectiveNearZ();
|
||||
@@ -413,7 +413,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize);
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE);
|
||||
@@ -528,20 +528,14 @@ void KRLight::renderShadowBuffers(VkCommandBuffer& commandBuffer, KRCamera *pCam
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
// Use shader program
|
||||
std::vector<KRPointLight*> no_point_lights;
|
||||
std::vector<KRDirectionalLight*> no_directional_lights;
|
||||
std::vector<KRSpotLight*> no_spot_lights;
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("ShadowShader");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &no_point_lights;
|
||||
info.directional_lights = &no_directional_lights;
|
||||
info.spot_lights = &no_spot_lights;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
KRPipeline *shadowShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
|
||||
getContext().getPipelineManager()->selectPipeline(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
getContext().getPipelineManager()->selectPipeline(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
|
||||
getScene().render(commandBuffer, pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true);
|
||||
|
||||
@@ -349,7 +349,7 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
Vector4 fade_color;
|
||||
if(!getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, rim_power, fade_color)) {
|
||||
if(!getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, matModel, &point_lights, &directional_lights, &spot_lights, 0, renderPass, rim_color, rim_power, fade_color)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ void KRParticleSystemNewtonian::render(VkCommandBuffer& commandBuffer, KRCamera
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
|
||||
// Vector3 rim_color; Vector4 fade_color;
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f);
|
||||
|
||||
KRDataBlock index_data;
|
||||
|
||||
@@ -584,7 +584,7 @@ void KRPipeline::bind(VkCommandBuffer& commandBuffer)
|
||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline);
|
||||
}
|
||||
|
||||
bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) {
|
||||
bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> *point_lights, const std::vector<KRDirectionalLight *> *directional_lights, const std::vector<KRSpotLight *> *spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) {
|
||||
if(m_iProgram == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -606,58 +606,60 @@ bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix
|
||||
if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && renderPass != KRNode::RENDER_PASS_DEFERRED_GBUFFER && renderPass != KRNode::RENDER_PASS_DEFERRED_OPAQUE && renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS) {
|
||||
|
||||
|
||||
for(std::vector<KRDirectionalLight *>::const_iterator light_itr=directional_lights.begin(); light_itr != directional_lights.end(); light_itr++) {
|
||||
KRDirectionalLight *directional_light = (*light_itr);
|
||||
if(light_directional_count == 0) {
|
||||
int cShadowBuffers = directional_light->getShadowBufferCount();
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] != -1 && cShadowBuffers > 0) {
|
||||
if(m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 3, directional_light->getShadowTextures()[0])) {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
}
|
||||
if (directional_lights) {
|
||||
for (std::vector<KRDirectionalLight*>::const_iterator light_itr = directional_lights->begin(); light_itr != directional_lights->end(); light_itr++) {
|
||||
KRDirectionalLight* directional_light = (*light_itr);
|
||||
if (light_directional_count == 0) {
|
||||
int cShadowBuffers = directional_light->getShadowBufferCount();
|
||||
if (m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] != -1 && cShadowBuffers > 0) {
|
||||
if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 3, directional_light->getShadowTextures()[0])) {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
}
|
||||
|
||||
m_pContext->getTextureManager()->_setWrapModeS(3, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(3, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1 && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) {
|
||||
if(m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 4, directional_light->getShadowTextures()[1])) {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
}
|
||||
m_pContext->getTextureManager()->_setWrapModeS(4, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(4, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1 && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) {
|
||||
if(m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 5, directional_light->getShadowTextures()[2])) {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
}
|
||||
m_pContext->getTextureManager()->_setWrapModeS(5, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(5, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
Matrix4 matBias;
|
||||
matBias.translate(1.0, 1.0, 1.0);
|
||||
matBias.scale(0.5);
|
||||
for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) {
|
||||
setUniform(KRENGINE_UNIFORM_SHADOWMVP1 + iShadow, matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias);
|
||||
}
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1) {
|
||||
Matrix4 inverseModelMatrix = matModel;
|
||||
inverseModelMatrix.invert();
|
||||
|
||||
// Bind the light direction vector
|
||||
Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection());
|
||||
lightDirObject.normalize();
|
||||
setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject);
|
||||
}
|
||||
m_pContext->getTextureManager()->_setWrapModeS(3, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(3, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
light_directional_count++;
|
||||
if (m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1 && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) {
|
||||
if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 4, directional_light->getShadowTextures()[1])) {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
}
|
||||
m_pContext->getTextureManager()->_setWrapModeS(4, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(4, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
if (m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1 && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) {
|
||||
if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 5, directional_light->getShadowTextures()[2])) {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
}
|
||||
m_pContext->getTextureManager()->_setWrapModeS(5, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(5, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
Matrix4 matBias;
|
||||
matBias.translate(1.0, 1.0, 1.0);
|
||||
matBias.scale(0.5);
|
||||
for (int iShadow = 0; iShadow < cShadowBuffers; iShadow++) {
|
||||
setUniform(KRENGINE_UNIFORM_SHADOWMVP1 + iShadow, matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias);
|
||||
}
|
||||
|
||||
if (m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1) {
|
||||
Matrix4 inverseModelMatrix = matModel;
|
||||
inverseModelMatrix.invert();
|
||||
|
||||
// Bind the light direction vector
|
||||
Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection());
|
||||
lightDirObject.normalize();
|
||||
setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject);
|
||||
}
|
||||
}
|
||||
|
||||
light_directional_count++;
|
||||
}
|
||||
}
|
||||
|
||||
//light_point_count = point_lights.size();
|
||||
//light_spot_count = spot_lights.size();
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
virtual ~KRPipeline();
|
||||
const char *getKey() const;
|
||||
|
||||
bool bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
bool bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> *point_lights, const std::vector<KRDirectionalLight *> *directional_lights, const std::vector<KRSpotLight *>*spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
void bind(VkCommandBuffer& commandBuffer);
|
||||
|
||||
enum {
|
||||
|
||||
@@ -98,9 +98,16 @@ KRPipeline *KRPipelineManager::getPipeline(const PipelineInfo &info) {
|
||||
int light_point_count = 0;
|
||||
int light_spot_count = 0;
|
||||
if(info.renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && info.renderPass != KRNode::RENDER_PASS_DEFERRED_GBUFFER && info.renderPass != KRNode::RENDER_PASS_DEFERRED_OPAQUE && info.renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS) {
|
||||
light_directional_count = (int)info.directional_lights->size();
|
||||
light_point_count = (int)info.point_lights->size();
|
||||
light_spot_count = (int)info.spot_lights->size();
|
||||
if (info.directional_lights) {
|
||||
light_directional_count = (int)info.directional_lights->size();
|
||||
}
|
||||
|
||||
if (info.point_lights) {
|
||||
light_point_count = (int)info.point_lights->size();
|
||||
}
|
||||
if (info.spot_lights) {
|
||||
light_spot_count = (int)info.spot_lights->size();
|
||||
}
|
||||
for(std::vector<KRDirectionalLight *>::const_iterator light_itr=info.directional_lights->begin(); light_itr != info.directional_lights->end(); light_itr++) {
|
||||
KRDirectionalLight *directional_light =(*light_itr);
|
||||
iShadowQuality = directional_light->getShadowBufferCount();
|
||||
@@ -282,10 +289,10 @@ KRPipeline *KRPipelineManager::getPipeline(const PipelineInfo &info) {
|
||||
bool KRPipelineManager::selectPipeline(const PipelineInfo& info, const KRViewport& viewport, const Matrix4& matModel, const Vector3& rim_color, float rim_power, const Vector4& fade_color)
|
||||
{
|
||||
KRPipeline* pPipeline = getPipeline(info);
|
||||
return selectPipeline(*info.pCamera, pPipeline, viewport, matModel, *info.point_lights, *info.directional_lights, *info.spot_lights, info.bone_count, info.renderPass, rim_color, rim_power, fade_color);
|
||||
return selectPipeline(*info.pCamera, pPipeline, viewport, matModel, info.point_lights, info.directional_lights, info.spot_lights, info.bone_count, info.renderPass, rim_color, rim_power, fade_color);
|
||||
}
|
||||
|
||||
bool KRPipelineManager::selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color)
|
||||
bool KRPipelineManager::selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> *point_lights, const std::vector<KRDirectionalLight *> *directional_lights, const std::vector<KRSpotLight *> *spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color)
|
||||
{
|
||||
if(pPipeline) {
|
||||
return pPipeline->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color);
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
|
||||
KRPipeline *getPipeline(KRSurface& surface, KRRenderPass& renderPass, const std::string& shader_name, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat);
|
||||
KRPipeline* getPipeline(const PipelineInfo& info);
|
||||
bool selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
bool selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector<KRPointLight *> *point_lights, const std::vector<KRDirectionalLight *> *directional_lights, const std::vector<KRSpotLight *> *spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color);
|
||||
bool selectPipeline(const PipelineInfo& info, const KRViewport& viewport, const Matrix4& matModel, const Vector3& rim_color, float rim_power, const Vector4& fade_color);
|
||||
|
||||
size_t getPipelineHandlesUsed();
|
||||
|
||||
@@ -96,18 +96,14 @@ void KRPointLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std
|
||||
|
||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ());
|
||||
|
||||
std::vector<KRDirectionalLight*> no_directional_lights;
|
||||
std::vector<KRSpotLight*> no_spot_lights;
|
||||
std::string shader_name(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"));
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &this_light;
|
||||
info.directional_lights = &no_directional_lights;
|
||||
info.spot_lights = &no_spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &this_light, nullptr, nullptr, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
|
||||
|
||||
@@ -138,7 +138,7 @@ void KRReverbZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
|
||||
@@ -165,7 +165,7 @@ void KRSprite::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::ve
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE);
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
|
||||
Reference in New Issue
Block a user