Implement KRNode::RenderInfo
Use KRNode::RenderInfo to reduce render related argument counts and pass KRSurface through render functions. Refactor render functions to use KRNode::RenderInfo
This commit is contained in:
@@ -118,29 +118,29 @@ void KRAmbientZone::setZone(const std::string &zone)
|
||||
m_zone = zone;
|
||||
}
|
||||
|
||||
void KRAmbientZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
void KRAmbientZone::render(RenderInfo& ri)
|
||||
{
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_AMBIENT_ZONES;
|
||||
bool bVisualize = ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_AMBIENT_ZONES;
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("visualize_overlay");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
|
||||
KRPipeline *pPipeline = getContext().getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pPipeline, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
@@ -157,7 +157,7 @@ void KRAmbientZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, st
|
||||
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if(sphereModels.size()) {
|
||||
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
|
||||
sphereModels[0]->renderSubmesh(commandBuffer, i, renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
sphereModels[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
|
||||
void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
void render(RenderInfo& ri);
|
||||
|
||||
std::string getZone();
|
||||
void setZone(const std::string &zone);
|
||||
|
||||
@@ -184,30 +184,30 @@ void KRAudioSource::queueBuffer()
|
||||
m_nextBufferIndex = (m_nextBufferIndex + 1) % m_audioFile->getBufferCount();
|
||||
}
|
||||
|
||||
void KRAudioSource::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
void KRAudioSource::render(RenderInfo& ri)
|
||||
{
|
||||
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
bool bVisualize = false;
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("visualize_overlay");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pShader, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
@@ -224,7 +224,7 @@ void KRAudioSource::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, st
|
||||
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if(sphereModels.size()) {
|
||||
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
|
||||
sphereModels[0]->renderSubmesh(commandBuffer, i, renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
sphereModels[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
virtual void physicsUpdate(float deltaTime);
|
||||
|
||||
void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
void render(RenderInfo& ri);
|
||||
|
||||
// ---- Audio Playback Controls ----
|
||||
|
||||
|
||||
@@ -69,15 +69,15 @@ AABB KRBone::getBounds() {
|
||||
return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix()); // Only required for bone debug visualization
|
||||
}
|
||||
|
||||
void KRBone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
void KRBone::render(RenderInfo& ri)
|
||||
{
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_BONES;
|
||||
bool bVisualize = ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_BONES;
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
// Enable additive blending
|
||||
@@ -94,19 +94,19 @@ void KRBone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vect
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("visualize_overlay");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pShader, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.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++) {
|
||||
sphereModels[0]->renderSubmesh(commandBuffer, i, renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
sphereModels[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "KRNode.h"
|
||||
#include "KRTexture.h"
|
||||
|
||||
class RenderInfo;
|
||||
|
||||
class KRBone : public KRNode {
|
||||
public:
|
||||
static void InitNodeInfo(KrNodeInfo* nodeInfo);
|
||||
@@ -47,7 +49,7 @@ public:
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
virtual AABB getBounds();
|
||||
|
||||
void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
void render(RenderInfo& ri);
|
||||
|
||||
void setBindPose(const Matrix4 &pose);
|
||||
const Matrix4 &getBindPose();
|
||||
|
||||
@@ -119,7 +119,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
//Matrix4 viewMatrix = Matrix4::Invert(getModelMatrix());
|
||||
|
||||
settings.setViewportSize(Vector2::Create((float)surface.getWidth(), (float)surface.getHeight()));
|
||||
Matrix4 projectionMatrix;
|
||||
Matrix4 projectionMatrix{};
|
||||
projectionMatrix.perspective(settings.perspective_fov, settings.m_viewportSize.x / settings.m_viewportSize.y, settings.perspective_nearz, settings.perspective_farz);
|
||||
m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix);
|
||||
m_viewport.setLODBias(settings.getLODBias());
|
||||
@@ -130,13 +130,13 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
scene.updateOctree(m_viewport);
|
||||
|
||||
// ----====---- Pre-stream resources ----====----
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_PRESTREAM, true);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_PRESTREAM, true);
|
||||
|
||||
// ----====---- Generate Shadowmaps for Lights ----====----
|
||||
if(settings.m_cShadowBuffers > 0) {
|
||||
GL_PUSH_GROUP_MARKER("Generate Shadowmaps");
|
||||
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_GENERATE_SHADOWMAPS, false /*settings.bEnableDeferredLighting*/);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_GENERATE_SHADOWMAPS, false /*settings.bEnableDeferredLighting*/);
|
||||
GLDEBUG(glViewport(0, 0, (GLsizei)m_viewport.getSize().x, (GLsizei)m_viewport.getSize().y));
|
||||
GL_POP_GROUP_MARKER;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
// Render the geometry
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_GBUFFER, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_GBUFFER, false);
|
||||
|
||||
|
||||
GL_POP_GROUP_MARKER;
|
||||
@@ -206,7 +206,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
|
||||
|
||||
// Render the geometry
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_LIGHTS, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_LIGHTS, false);
|
||||
|
||||
GL_POP_GROUP_MARKER;
|
||||
|
||||
@@ -241,7 +241,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
|
||||
// Render the geometry
|
||||
// TODO: At this point, we only want to render octree nodes that produced fragments during the 1st pass into the GBuffer
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_OPAQUE, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_OPAQUE, false);
|
||||
|
||||
// Deactivate source buffer texture units
|
||||
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 6, 0);
|
||||
@@ -291,7 +291,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
forwardOpaquePass.begin(commandBuffer, surface);
|
||||
|
||||
// Render the geometry
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false);
|
||||
|
||||
|
||||
// ---------- Start: Vulkan Debug Code ----------
|
||||
@@ -345,8 +345,8 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
info.pCamera = this;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE;
|
||||
|
||||
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(info);
|
||||
getContext().getPipelineManager()->selectPipeline(*this, pPipeline, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(surface, info);
|
||||
getContext().getPipelineManager()->selectPipeline(surface, *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);
|
||||
|
||||
@@ -395,7 +395,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
*/
|
||||
|
||||
// Render all transparent geometry
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, false);
|
||||
|
||||
// TODO - Vulkan refactoring...
|
||||
/*
|
||||
@@ -430,7 +430,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
*/
|
||||
|
||||
// ----====---- Perform Occlusion Tests ----====----
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, RENDER_PASS_PARTICLE_OCCLUSION, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, RENDER_PASS_PARTICLE_OCCLUSION, false);
|
||||
|
||||
// TODO - Vulkan refactoring...
|
||||
/*
|
||||
@@ -464,7 +464,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
*/
|
||||
|
||||
// Render all flares
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_ADDITIVE_PARTICLES, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_ADDITIVE_PARTICLES, false);
|
||||
|
||||
// TODO - Vulkan refactoring...
|
||||
/*
|
||||
@@ -497,7 +497,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||
}
|
||||
|
||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), volumetricLightingViewport, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, false);
|
||||
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), volumetricLightingViewport, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, false);
|
||||
|
||||
if(settings.volumetric_environment_downsample != 0) {
|
||||
// Set render target
|
||||
@@ -538,14 +538,14 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = this;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
KRPipeline *pVisShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *pVisShader = getContext().getPipelineManager()->getPipeline(surface, info);
|
||||
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f);
|
||||
for(unordered_map<AABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) {
|
||||
Matrix4 matModel = Matrix4();
|
||||
matModel.scale((*itr).first.size() * 0.5f);
|
||||
matModel.translate((*itr).first.center());
|
||||
if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(surface, *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));
|
||||
}
|
||||
}
|
||||
@@ -739,7 +739,7 @@ void KRCamera::destroyBuffers()
|
||||
*/
|
||||
}
|
||||
|
||||
void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
|
||||
void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
||||
{
|
||||
// Disable alpha blending
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
@@ -776,10 +776,10 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
|
||||
info.pCamera = this;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
|
||||
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(surface, info);
|
||||
|
||||
Vector3 rim_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);
|
||||
getContext().getPipelineManager()->selectPipeline(surface, *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);
|
||||
@@ -966,8 +966,8 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = this;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline(surface, info);
|
||||
getContext().getPipelineManager()->selectPipeline(surface, *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);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
|
||||
GLuint volumetricLightAccumulationBuffer, volumetricLightAccumulationTexture;
|
||||
|
||||
void renderPost(VkCommandBuffer& commandBuffer);
|
||||
void renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface);
|
||||
|
||||
void destroyBuffers();
|
||||
|
||||
|
||||
@@ -192,13 +192,13 @@ void KRCollider::setAudioOcclusion(float audio_occlusion)
|
||||
}
|
||||
|
||||
|
||||
void KRCollider::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
void KRCollider::render(RenderInfo& ri)
|
||||
{
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_COLLIDERS) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_COLLIDERS) {
|
||||
loadModel();
|
||||
if(m_models.size()) {
|
||||
|
||||
@@ -207,15 +207,15 @@ void KRCollider::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("visualize_overlay");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
@@ -232,7 +232,7 @@ void KRCollider::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::
|
||||
|
||||
|
||||
for(int i=0; i < m_models[0]->getSubmeshCount(); i++) {
|
||||
m_models[0]->renderSubmesh(commandBuffer, i, renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
m_models[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
}
|
||||
|
||||
// Enable alpha blending
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
float getAudioOcclusion();
|
||||
void setAudioOcclusion(float audio_occlusion);
|
||||
|
||||
void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
void render(RenderInfo& ri);
|
||||
|
||||
private:
|
||||
std::vector<KRMesh *> m_models;
|
||||
|
||||
@@ -118,19 +118,19 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
return 1;
|
||||
}
|
||||
|
||||
void KRDirectionalLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) {
|
||||
void KRDirectionalLight::render(RenderInfo& ri) {
|
||||
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRLight::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRLight::render(ri);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
|
||||
// Lights are rendered on the second pass of the deferred renderer
|
||||
|
||||
std::vector<KRDirectionalLight *> this_light;
|
||||
this_light.push_back(this);
|
||||
|
||||
Matrix4 matModelViewInverseTranspose = viewport.getViewMatrix() * getModelMatrix();
|
||||
Matrix4 matModelViewInverseTranspose = ri.viewport.getViewMatrix() * getModelMatrix();
|
||||
matModelViewInverseTranspose.transpose();
|
||||
matModelViewInverseTranspose.invert();
|
||||
|
||||
@@ -141,12 +141,12 @@ void KRDirectionalLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamer
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("light_directional");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.pCamera = ri.camera;
|
||||
info.directional_lights = &this_light;
|
||||
info.renderPass = renderPass;
|
||||
info.renderPass = ri.renderPass;
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), nullptr, &this_light, nullptr, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), nullptr, &this_light, nullptr, 0, ri.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);
|
||||
@@ -159,7 +159,7 @@ void KRDirectionalLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamer
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
Vector3 getLocalLightDirection();
|
||||
Vector3 getWorldLightDirection();
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
virtual void render(RenderInfo& ri);
|
||||
virtual AABB getBounds();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -212,22 +212,22 @@ float KRLight::getDecayStart() {
|
||||
return m_decayStart;
|
||||
}
|
||||
|
||||
void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) {
|
||||
void KRLight::render(RenderInfo& ri) {
|
||||
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_GENERATE_SHADOWMAPS && (pCamera->settings.volumetric_environment_enable || pCamera->settings.dust_particle_enable || (pCamera->settings.m_cShadowBuffers > 0 && m_casts_shadow))) {
|
||||
allocateShadowBuffers(configureShadowBufferViewports(viewport));
|
||||
renderShadowBuffers(commandBuffer, pCamera);
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_GENERATE_SHADOWMAPS && (ri.camera->settings.volumetric_environment_enable || ri.camera->settings.dust_particle_enable || (ri.camera->settings.m_cShadowBuffers > 0 && m_casts_shadow))) {
|
||||
allocateShadowBuffers(configureShadowBufferViewports(ri.viewport));
|
||||
renderShadowBuffers(ri);
|
||||
}
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES && pCamera->settings.dust_particle_enable) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES && ri.camera->settings.dust_particle_enable) {
|
||||
// Render brownian particles for dust floating in air
|
||||
if(m_cShadowBuffers >= 1 && shadowValid[0] && m_dust_particle_density > 0.0f && m_dust_particle_size > 0.0f && m_dust_particle_intensity > 0.0f) {
|
||||
|
||||
if(viewport.visible(getBounds()) || true) { // FINDME, HACK need to remove "|| true"?
|
||||
if(ri.viewport.visible(getBounds()) || true) { // FINDME, HACK need to remove "|| true"?
|
||||
|
||||
float particle_range = 600.0f;
|
||||
|
||||
@@ -240,7 +240,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
|
||||
Matrix4 particleModelMatrix;
|
||||
particleModelMatrix.scale(particle_range); // Scale the box symetrically to ensure that we don't have an uneven distribution of particles for different angles of the view frustrum
|
||||
particleModelMatrix.translate(viewport.getCameraPosition());
|
||||
particleModelMatrix.translate(ri.viewport.getCameraPosition());
|
||||
|
||||
std::vector<KRDirectionalLight *> this_directional_light;
|
||||
std::vector<KRSpotLight *> this_spot_light;
|
||||
@@ -261,21 +261,21 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("dust_particle");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &this_point_light;
|
||||
info.directional_lights = &this_directional_light;
|
||||
info.spot_lights = &this_spot_light;
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
info.renderPass = ri.renderPass;
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pParticleShader, ri.viewport, particleModelMatrix, &this_point_light, &this_directional_light, &this_spot_light, 0, ri.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_LIGHT_COLOR, m_color * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_PARTICLE_ORIGIN, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size);
|
||||
|
||||
KRDataBlock particle_index_data;
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, m_pContext->getMeshManager()->getRandomParticles(), particle_index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true, 1.0f
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, m_pContext->getMeshManager()->getRandomParticles(), particle_index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), true, 1.0f
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, "Light Particles"
|
||||
#endif
|
||||
@@ -287,8 +287,8 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
}
|
||||
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE && pCamera->settings.volumetric_environment_enable && m_light_shafts) {
|
||||
std::string shader_name = pCamera->settings.volumetric_environment_downsample != 0 ? "volumetric_fog_downsampled" : "volumetric_fog";
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE && ri.camera->settings.volumetric_environment_enable && m_light_shafts) {
|
||||
std::string shader_name = ri.camera->settings.volumetric_environment_downsample != 0 ? "volumetric_fog_downsampled" : "volumetric_fog";
|
||||
|
||||
std::vector<KRDirectionalLight *> this_directional_light;
|
||||
std::vector<KRSpotLight *> this_spot_light;
|
||||
@@ -308,26 +308,26 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &this_point_light;
|
||||
info.directional_lights = &this_directional_light;
|
||||
info.spot_lights = &this_spot_light;
|
||||
info.renderPass = KRNode::RENDER_PASS_ADDITIVE_PARTICLES;
|
||||
|
||||
KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, 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())) {
|
||||
int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5;
|
||||
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pFogShader, ri.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)(ri.camera->settings.volumetric_environment_quality * 495.0) + 5;
|
||||
|
||||
float slice_near = -pCamera->settings.getPerspectiveNearZ();
|
||||
float slice_far = -pCamera->settings.volumetric_environment_max_distance;
|
||||
float slice_near = -ri.camera->settings.getPerspectiveNearZ();
|
||||
float slice_far = -ri.camera->settings.volumetric_environment_max_distance;
|
||||
float slice_spacing = (slice_far - slice_near) / slice_count;
|
||||
|
||||
pFogShader->setUniform(KRPipeline::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE, Vector2::Create(slice_near, slice_spacing));
|
||||
pFogShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, (m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
|
||||
pFogShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, (m_color * ri.camera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
|
||||
|
||||
KRDataBlock index_data;
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, m_pContext->getMeshManager()->getVolumetricLightingVertexes(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX), true, 1.0f
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, m_pContext->getMeshManager()->getVolumetricLightingVertexes(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX), true, 1.0f
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, "Participating Media"
|
||||
#endif
|
||||
@@ -337,7 +337,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
|
||||
}
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_PARTICLE_OCCLUSION) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_PARTICLE_OCCLUSION) {
|
||||
if(m_flareTexture.size() && m_flareSize > 0.0f) {
|
||||
|
||||
|
||||
@@ -351,13 +351,13 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("occlusion_test");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(info, viewport, occlusion_test_sphere_matrix, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, info, ri.viewport, occlusion_test_sphere_matrix, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery));
|
||||
#if TARGET_OS_IPHONE || defined(ANDROID)
|
||||
@@ -369,7 +369,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if(sphereModels.size()) {
|
||||
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
|
||||
sphereModels[0]->renderSubmesh(commandBuffer, i, renderPass, getName(), "occlusion_test", 1.0f);
|
||||
sphereModels[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "occlusion_test", 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
}
|
||||
}
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||
if(m_flareTexture.size() && m_flareSize > 0.0f) {
|
||||
|
||||
if(m_occlusionQuery) {
|
||||
@@ -406,18 +406,18 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("flare");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.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);
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
@@ -493,7 +493,7 @@ int KRLight::configureShadowBufferViewports(const KRViewport &viewport)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void KRLight::renderShadowBuffers(VkCommandBuffer& commandBuffer, KRCamera *pCamera)
|
||||
void KRLight::renderShadowBuffers(RenderInfo& ri)
|
||||
{
|
||||
for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
|
||||
if(!shadowValid[iShadow]) {
|
||||
@@ -531,14 +531,14 @@ void KRLight::renderShadowBuffers(VkCommandBuffer& commandBuffer, KRCamera *pCam
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("ShadowShader");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.pCamera = ri.camera;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
KRPipeline *shadowShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *shadowShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
getContext().getPipelineManager()->selectPipeline(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, 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);
|
||||
getScene().render(ri.commandBuffer, *ri.surface, ri.camera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true);
|
||||
|
||||
GLDEBUG(glEnable(GL_CULL_FACE));
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
void setFlareOcclusionSize(float occlusion_size);
|
||||
void deleteBuffers();
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
virtual void render(RenderInfo& ri);
|
||||
|
||||
int getShadowBufferCount();
|
||||
GLuint *getShadowTextures();
|
||||
@@ -102,7 +102,7 @@ protected:
|
||||
void invalidateShadowBuffers();
|
||||
|
||||
virtual int configureShadowBufferViewports(const KRViewport &viewport);
|
||||
void renderShadowBuffers(VkCommandBuffer& commandBuffer, KRCamera *pCamera);
|
||||
void renderShadowBuffers(RenderInfo& ri);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -302,8 +302,9 @@ void KRMaterial::getTextures()
|
||||
}
|
||||
}
|
||||
|
||||
bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<Matrix4> &bind_poses, const KRViewport &viewport, const Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage) {
|
||||
bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap;
|
||||
bool KRMaterial::bind(const KRNode::RenderInfo& ri, const std::vector<KRBone *> &bones, const std::vector<Matrix4> &bind_poses, const Matrix4 &matModel, KRTexture *pLightMap, const Vector3 &rim_color, float rim_power, float lod_coverage)
|
||||
{
|
||||
bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap;
|
||||
|
||||
getTextures();
|
||||
|
||||
@@ -311,23 +312,23 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
Vector2 default_offset = Vector2::Zero();
|
||||
|
||||
bool bHasReflection = m_reflectionColor != Vector3::Zero();
|
||||
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->settings.bEnableDiffuseMap;
|
||||
bool bNormalMap = m_pNormalMap != NULL && pCamera->settings.bEnableNormalMap;
|
||||
bool bSpecMap = m_pSpecularMap != NULL && pCamera->settings.bEnableSpecMap;
|
||||
bool bReflectionMap = m_pReflectionMap != NULL && pCamera->settings.bEnableReflectionMap && pCamera->settings.bEnableReflection && bHasReflection;
|
||||
bool bReflectionCubeMap = m_pReflectionCube != NULL && pCamera->settings.bEnableReflection && bHasReflection;
|
||||
bool bDiffuseMap = m_pDiffuseMap != NULL && ri.camera->settings.bEnableDiffuseMap;
|
||||
bool bNormalMap = m_pNormalMap != NULL && ri.camera->settings.bEnableNormalMap;
|
||||
bool bSpecMap = m_pSpecularMap != NULL && ri.camera->settings.bEnableSpecMap;
|
||||
bool bReflectionMap = m_pReflectionMap != NULL && ri.camera->settings.bEnableReflectionMap && ri.camera->settings.bEnableReflection && bHasReflection;
|
||||
bool bReflectionCubeMap = m_pReflectionCube != NULL && ri.camera->settings.bEnableReflection && bHasReflection;
|
||||
bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap;
|
||||
bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE);
|
||||
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("ObjectShader");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.bone_count = (int)bones.size();
|
||||
info.renderPass = renderPass;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.bDiffuseMap = bDiffuseMap;
|
||||
info.bNormalMap = bNormalMap;
|
||||
info.bSpecMap = bSpecMap;
|
||||
@@ -345,11 +346,11 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
info.bAlphaTest = bAlphaTest;
|
||||
info.bAlphaBlend = bAlphaBlend;
|
||||
info.bRimColor = rim_power != 0.0f;
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
info.renderPass = ri.renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pShader, ri.viewport, matModel, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, rim_color, rim_power, fade_color)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -387,18 +388,18 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
}
|
||||
|
||||
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_AMBIENT, m_ambientColor + pCamera->settings.ambient_intensity);
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_AMBIENT, m_ambientColor + ri.camera->settings.ambient_intensity);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, Vector3::Create(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z));
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, Vector3::Create(m_diffuseColor.x * ri.camera->settings.light_intensity.x, m_diffuseColor.y * ri.camera->settings.light_intensity.y, m_diffuseColor.z * ri.camera->settings.light_intensity.z));
|
||||
} else {
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, m_diffuseColor);
|
||||
}
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_SPECULAR, Vector3::Create(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z));
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_SPECULAR, Vector3::Create(m_specularColor.x * ri.camera->settings.light_intensity.x, m_specularColor.y * ri.camera->settings.light_intensity.y, m_specularColor.z * ri.camera->settings.light_intensity.z));
|
||||
} else {
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_SPECULAR, m_specularColor);
|
||||
}
|
||||
@@ -428,11 +429,11 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
m_pContext->getTextureManager()->selectTexture(2, m_pNormalMap, lod_coverage, KRTexture::TEXTURE_USAGE_NORMAL_MAP);
|
||||
}
|
||||
|
||||
if(bReflectionCubeMap && (renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
|
||||
if(bReflectionCubeMap && (ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || ri.renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
|
||||
m_pContext->getTextureManager()->selectTexture(4, m_pReflectionCube, lod_coverage, KRTexture::TEXTURE_USAGE_REFECTION_CUBE);
|
||||
}
|
||||
|
||||
if(bReflectionMap && (renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
|
||||
if(bReflectionMap && (ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || ri.renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
|
||||
// GL_TEXTURE7 is used for reading the depth buffer in gBuffer pass 2 and re-used for the reflection map in gBuffer Pass 3 and in forward rendering
|
||||
m_pContext->getTextureManager()->selectTexture(7, m_pReflectionMap, lod_coverage, KRTexture::TEXTURE_USAGE_REFLECTION_MAP);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
class KRTextureManager;
|
||||
class KRContext;
|
||||
class KRSurface;
|
||||
|
||||
class KRMaterial : public KRResource {
|
||||
public:
|
||||
@@ -82,7 +83,7 @@ public:
|
||||
bool isTransparent();
|
||||
const std::string &getName() const;
|
||||
|
||||
bool bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<Matrix4> &bind_poses, const KRViewport &viewport, const Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f);
|
||||
bool bind(const KRNode::RenderInfo& ri, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, const Vector3& rim_color, float rim_power, float lod_coverage = 0.0f);
|
||||
|
||||
bool needsVertexTangents();
|
||||
|
||||
|
||||
@@ -240,10 +240,11 @@ kraken_stream_level KRMesh::getStreamLevel()
|
||||
return stream_level;
|
||||
}
|
||||
|
||||
void KRMesh::render(VkCommandBuffer& commandBuffer, const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage) {
|
||||
|
||||
void KRMesh::render(const KRNode::RenderInfo& ri, const std::string& object_name, const Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& bones, const Vector3& rim_color, float rim_power, float lod_coverage)
|
||||
{
|
||||
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
|
||||
if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||
if(ri.renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && ri.renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION && ri.renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||
preStream(lod_coverage);
|
||||
if(getStreamLevel() == kraken_stream_level::STREAM_LEVEL_OUT) {
|
||||
|
||||
@@ -253,7 +254,7 @@ void KRMesh::render(VkCommandBuffer& commandBuffer, const std::string &object_na
|
||||
getMaterials();
|
||||
|
||||
int cSubmeshes = (int)m_submeshes.size();
|
||||
if(renderPass == KRNode::RENDER_PASS_SHADOWMAP) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_SHADOWMAP) {
|
||||
for(int iSubmesh=0; iSubmesh<cSubmeshes; iSubmesh++) {
|
||||
KRMaterial *pMaterial = m_materials[iSubmesh];
|
||||
|
||||
@@ -261,7 +262,7 @@ void KRMesh::render(VkCommandBuffer& commandBuffer, const std::string &object_na
|
||||
|
||||
if(!pMaterial->isTransparent()) {
|
||||
// Exclude transparent and semi-transparent meshes from shadow maps
|
||||
renderSubmesh(commandBuffer, iSubmesh, renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,29 +274,29 @@ void KRMesh::render(VkCommandBuffer& commandBuffer, const std::string &object_na
|
||||
KRMaterial *pMaterial = m_materials[iSubmesh];
|
||||
|
||||
if(pMaterial != NULL && pMaterial == (*mat_itr)) {
|
||||
if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
if((!pMaterial->isTransparent() && ri.renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
std::vector<Matrix4> bone_bind_poses;
|
||||
for(int i=0; i < (int)bones.size(); i++) {
|
||||
bone_bind_poses.push_back(getBoneBindPose(i));
|
||||
}
|
||||
if(pMaterial->bind(pCamera, point_lights, directional_lights, spot_lights, bones, bone_bind_poses, viewport, matModel, pLightMap, renderPass, rim_color, rim_power, lod_coverage)) {
|
||||
if(pMaterial->bind(ri, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage)) {
|
||||
|
||||
switch(pMaterial->getAlphaMode()) {
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
|
||||
renderSubmesh(commandBuffer, iSubmesh, renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
break;
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
|
||||
renderSubmesh(commandBuffer, iSubmesh, renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
break;
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
||||
// Render back faces first
|
||||
GLDEBUG(glCullFace(GL_FRONT));
|
||||
renderSubmesh(commandBuffer, iSubmesh, renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
|
||||
// Render front faces second
|
||||
GLDEBUG(glCullFace(GL_BACK));
|
||||
renderSubmesh(commandBuffer, iSubmesh, renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
std::vector<std::vector<float> > bone_weights;
|
||||
} mesh_info;
|
||||
|
||||
void render(VkCommandBuffer& commandBuffer, const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const Matrix4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f);
|
||||
void render(const KRNode::RenderInfo& ri, const std::string &object_name, const Matrix4 &matModel, KRTexture *pLightMap, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f);
|
||||
|
||||
std::string m_lodBaseName;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "KRModel.h"
|
||||
#include "KRContext.h"
|
||||
#include "KRMesh.h"
|
||||
#include "KRNode.h"
|
||||
|
||||
/* static */
|
||||
void KRModel::InitNodeInfo(KrNodeInfo* nodeInfo)
|
||||
@@ -159,17 +160,22 @@ void KRModel::loadModel() {
|
||||
}
|
||||
}
|
||||
|
||||
void KRModel::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) {
|
||||
void KRModel::render(KRNode::RenderInfo& ri) {
|
||||
|
||||
if(m_lod_visible >= LOD_VISIBILITY_PRESTREAM && renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
preStream(viewport);
|
||||
if(m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
preStream(ri.viewport);
|
||||
}
|
||||
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE && renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS && renderPass != KRNode::RENDER_PASS_PRESTREAM) {
|
||||
if(ri.renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS
|
||||
&& ri.renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES
|
||||
&& ri.renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION
|
||||
&& ri.renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE
|
||||
&& ri.renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS
|
||||
&& ri.renderPass != KRNode::RENDER_PASS_PRESTREAM) {
|
||||
loadModel();
|
||||
|
||||
if(m_models.size() > 0) {
|
||||
@@ -184,7 +190,7 @@ void KRModel::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
}
|
||||
*/
|
||||
|
||||
float lod_coverage = viewport.coverage(getBounds()); // This also checks the view frustrum culling
|
||||
float lod_coverage = ri.viewport.coverage(getBounds()); // This also checks the view frustrum culling
|
||||
|
||||
if(lod_coverage > m_min_lod_coverage) {
|
||||
|
||||
@@ -205,18 +211,18 @@ void KRModel::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec
|
||||
m_pLightMap = getContext().getTextureManager()->getTexture(m_lightMap);
|
||||
}
|
||||
|
||||
if(m_pLightMap && pCamera->settings.bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP && renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) {
|
||||
if(m_pLightMap && ri.camera->settings.bEnableLightMap && ri.renderPass != RENDER_PASS_SHADOWMAP && ri.renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) {
|
||||
m_pContext->getTextureManager()->selectTexture(5, m_pLightMap, lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP);
|
||||
}
|
||||
|
||||
Matrix4 matModel = getModelMatrix();
|
||||
if(m_faces_camera) {
|
||||
Vector3 model_center = Matrix4::Dot(matModel, Vector3::Zero());
|
||||
Vector3 camera_pos = viewport.getCameraPosition();
|
||||
Vector3 camera_pos = ri.viewport.getCameraPosition();
|
||||
matModel = Quaternion::Create(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel;
|
||||
}
|
||||
|
||||
pModel->render(commandBuffer, getName(), pCamera, point_lights, directional_lights, spot_lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel], m_rim_color, m_rim_power, lod_coverage);
|
||||
pModel->render(ri, getName(), matModel, m_pLightMap, m_bones[pModel], m_rim_color, m_rim_power, lod_coverage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
virtual void render(KRNode::RenderInfo& ri);
|
||||
|
||||
virtual AABB getBounds();
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
|
||||
return new_node;
|
||||
}
|
||||
|
||||
void KRNode::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, RenderPass renderPass)
|
||||
void KRNode::render(const RenderInfo& ri)
|
||||
{
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ class KRMaterialManager;
|
||||
class KRTextureManager;
|
||||
class KRContext;
|
||||
class KRScene;
|
||||
class KRSurface;
|
||||
|
||||
class KRNode;
|
||||
class KRPointLight;
|
||||
@@ -83,6 +84,27 @@ public:
|
||||
LOD_VISIBILITY_VISIBLE
|
||||
};
|
||||
|
||||
class RenderInfo {
|
||||
public:
|
||||
RenderInfo(VkCommandBuffer& cb)
|
||||
: commandBuffer(cb)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderInfo(const RenderInfo&) = delete;
|
||||
RenderInfo& operator=(const RenderInfo&) = delete;
|
||||
|
||||
VkCommandBuffer& commandBuffer;
|
||||
KRCamera* camera;
|
||||
KRSurface* surface;
|
||||
std::vector<KRPointLight*> point_lights;
|
||||
std::vector<KRDirectionalLight*> directional_lights;
|
||||
std::vector<KRSpotLight*> spot_lights;
|
||||
KRViewport viewport;
|
||||
RenderPass renderPass;
|
||||
};
|
||||
|
||||
static void InitNodeInfo(KrNodeInfo* nodeInfo);
|
||||
|
||||
KRNode(KRScene &scene, std::string name);
|
||||
@@ -193,7 +215,7 @@ public:
|
||||
|
||||
KRScene &getScene();
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, RenderPass renderPass);
|
||||
virtual void render(const RenderInfo& ri);
|
||||
|
||||
virtual void physicsUpdate(float deltaTime);
|
||||
virtual bool hasPhysics();
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
virtual AABB getBounds() = 0;
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) = 0;
|
||||
virtual void render(RenderInfo& ri) = 0;
|
||||
|
||||
protected:
|
||||
KRParticleSystem(KRScene &scene, std::string name);
|
||||
|
||||
@@ -78,14 +78,14 @@ bool KRParticleSystemNewtonian::hasPhysics()
|
||||
return true;
|
||||
}
|
||||
|
||||
void KRParticleSystemNewtonian::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) {
|
||||
void KRParticleSystemNewtonian::render(RenderInfo& ri) {
|
||||
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||
if(viewport.visible(getBounds())) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||
if(ri.viewport.visible(getBounds())) {
|
||||
|
||||
|
||||
// Enable z-buffer test
|
||||
@@ -99,19 +99,19 @@ void KRParticleSystemNewtonian::render(VkCommandBuffer& commandBuffer, KRCamera
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("dust_particle");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(info);
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pParticleShader, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f);
|
||||
|
||||
KRDataBlock index_data;
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, m_pContext->getMeshManager()->getRandomParticles(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), false, 1.0f
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, m_pContext->getMeshManager()->getRandomParticles(), index_data, (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA), false, 1.0f
|
||||
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, "Newtonian Particles"
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
virtual AABB getBounds();
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
virtual void render(RenderInfo& ri);
|
||||
|
||||
|
||||
virtual void physicsUpdate(float deltaTime);
|
||||
|
||||
@@ -89,7 +89,7 @@ KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, KRRenderPass& ren
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
KRPipeline *KRPipelineManager::getPipeline(const PipelineInfo &info) {
|
||||
KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInfo &info) {
|
||||
|
||||
int iShadowQuality = 0; // FINDME - HACK - Placeholder code, need to iterate through lights and dynamically build shader
|
||||
|
||||
@@ -286,13 +286,13 @@ KRPipeline *KRPipelineManager::getPipeline(const PipelineInfo &info) {
|
||||
return pPipeline;
|
||||
}
|
||||
|
||||
bool KRPipelineManager::selectPipeline(const PipelineInfo& info, const KRViewport& viewport, const Matrix4& matModel, const Vector3& rim_color, float rim_power, const Vector4& fade_color)
|
||||
bool KRPipelineManager::selectPipeline(KRSurface& surface, 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);
|
||||
KRPipeline* pPipeline = getPipeline(surface, info);
|
||||
return selectPipeline(surface, *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(KRSurface& surface, 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);
|
||||
|
||||
@@ -83,9 +83,9 @@ public:
|
||||
KRPipeline* get(const char* szKey);
|
||||
|
||||
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(const PipelineInfo& info, const KRViewport& viewport, const Matrix4& matModel, const Vector3& rim_color, float rim_power, const Vector4& fade_color);
|
||||
KRPipeline* getPipeline(KRSurface& surface, const PipelineInfo& info);
|
||||
bool selectPipeline(KRSurface& surface, 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(KRSurface& surface, const PipelineInfo& info, const KRViewport& viewport, const Matrix4& matModel, const Vector3& rim_color, float rim_power, const Vector4& fade_color);
|
||||
|
||||
size_t getPipelineHandlesUsed();
|
||||
|
||||
|
||||
@@ -68,15 +68,15 @@ AABB KRPointLight::getBounds() {
|
||||
return AABB::Create(Vector3::Create(-influence_radius), Vector3::Create(influence_radius), getModelMatrix());
|
||||
}
|
||||
|
||||
void KRPointLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
void KRPointLight::render(RenderInfo& ri)
|
||||
{
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRLight::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRLight::render(ri);
|
||||
|
||||
bool bVisualize = renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && pCamera->settings.bShowDeferred;
|
||||
bool bVisualize = ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && ri.camera->settings.bShowDeferred;
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS || bVisualize) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS || bVisualize) {
|
||||
// Lights are rendered on the second pass of the deferred renderer
|
||||
|
||||
std::vector<KRPointLight *> this_light;
|
||||
@@ -90,20 +90,20 @@ void KRPointLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std
|
||||
sphereModelMatrix.scale(influence_radius);
|
||||
sphereModelMatrix.translate(light_position.x, light_position.y, light_position.z);
|
||||
|
||||
if(viewport.visible(getBounds())) { // Cull out any lights not within the view frustrum
|
||||
if(ri.viewport.visible(getBounds())) { // Cull out any lights not within the view frustrum
|
||||
|
||||
Vector3 view_light_position = Matrix4::Dot(viewport.getViewMatrix(), light_position);
|
||||
Vector3 view_light_position = Matrix4::Dot(ri.viewport.getViewMatrix(), light_position);
|
||||
|
||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ());
|
||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + ri.camera->settings.getPerspectiveNearZ()) * (influence_radius + ri.camera->settings.getPerspectiveNearZ());
|
||||
|
||||
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.pCamera = ri.camera;
|
||||
info.point_lights = &this_light;
|
||||
info.renderPass = renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &this_light, nullptr, nullptr, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
info.renderPass = ri.renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pShader, ri.viewport, sphereModelMatrix, &this_light, nullptr, nullptr, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
|
||||
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
|
||||
@@ -129,7 +129,7 @@ void KRPointLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
// Render a full screen quad
|
||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
} else {
|
||||
// Render sphere of light's influence
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
virtual std::string getElementName();
|
||||
virtual AABB getBounds();
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
virtual void render(RenderInfo& ri);
|
||||
|
||||
private:
|
||||
void generateMesh();
|
||||
|
||||
@@ -117,28 +117,28 @@ void KRReverbZone::setZone(const std::string &zone)
|
||||
m_zone = zone;
|
||||
}
|
||||
|
||||
void KRReverbZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
void KRReverbZone::render(RenderInfo& ri)
|
||||
{
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
bool bVisualize = pCamera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_REVERB_ZONES;
|
||||
bool bVisualize = ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_REVERB_ZONES;
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("visualize_overlay");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.renderPass = renderPass;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info);
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, 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(*ri.surface, *ri.camera, pShader, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
|
||||
// Enable additive blending
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
@@ -155,7 +155,7 @@ void KRReverbZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std
|
||||
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if(sphereModels.size()) {
|
||||
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
|
||||
sphereModels[0]->renderSubmesh(commandBuffer, i, renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
sphereModels[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
|
||||
void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
void render(RenderInfo& ri);
|
||||
|
||||
std::string getZone();
|
||||
void setZone(const std::string &zone);
|
||||
|
||||
@@ -96,7 +96,7 @@ std::set<KRLight *> &KRScene::getLights()
|
||||
return m_lights;
|
||||
}
|
||||
|
||||
void KRScene::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) {
|
||||
void KRScene::render(VkCommandBuffer& commandBuffer, KRSurface& surface, KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) {
|
||||
if(new_frame) {
|
||||
// Expire cached occlusion test results.
|
||||
// Cached "failed" results are expired on the next frame (marked with .second of -1)
|
||||
@@ -115,6 +115,11 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, unordere
|
||||
if(getFirstLight() == NULL) {
|
||||
addDefaultLights();
|
||||
}
|
||||
|
||||
KRNode::RenderInfo ri(commandBuffer);
|
||||
ri.camera = pCamera;
|
||||
ri.viewport = viewport;
|
||||
ri.renderPass = renderPass;
|
||||
|
||||
std::vector<KRPointLight *> point_lights;
|
||||
std::vector<KRDirectionalLight *>directional_lights;
|
||||
@@ -142,7 +147,7 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, unordere
|
||||
// Render outer nodes
|
||||
for(std::set<KRNode *>::iterator itr=outerNodes.begin(); itr != outerNodes.end(); itr++) {
|
||||
KRNode *node = (*itr);
|
||||
node->render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
node->render(ri);
|
||||
}
|
||||
|
||||
std::vector<KROctreeNode *> remainingOctrees;
|
||||
@@ -158,10 +163,10 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, unordere
|
||||
newRemainingOctrees.clear();
|
||||
newRemainingOctreesTestResults.clear();
|
||||
for(std::vector<KROctreeNode *>::iterator octree_itr = remainingOctrees.begin(); octree_itr != remainingOctrees.end(); octree_itr++) {
|
||||
render(commandBuffer, *octree_itr, visibleBounds, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, false, false);
|
||||
render(ri, *octree_itr, visibleBounds, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, false, false);
|
||||
}
|
||||
for(std::vector<KROctreeNode *>::iterator octree_itr = remainingOctreesTestResults.begin(); octree_itr != remainingOctreesTestResults.end(); octree_itr++) {
|
||||
render(commandBuffer, *octree_itr, visibleBounds, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, true, false);
|
||||
render(ri, *octree_itr, visibleBounds, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, true, false);
|
||||
}
|
||||
remainingOctrees = newRemainingOctrees;
|
||||
remainingOctreesTestResults = newRemainingOctreesTestResults;
|
||||
@@ -170,11 +175,11 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, unordere
|
||||
newRemainingOctrees.clear();
|
||||
newRemainingOctreesTestResults.clear();
|
||||
for(std::vector<KROctreeNode *>::iterator octree_itr = remainingOctreesTestResultsOnly.begin(); octree_itr != remainingOctreesTestResultsOnly.end(); octree_itr++) {
|
||||
render(commandBuffer, *octree_itr, visibleBounds, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, true, true);
|
||||
render(ri, *octree_itr, visibleBounds, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
void KRScene::render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly)
|
||||
void KRScene::render(KRNode::RenderInfo& ri, KROctreeNode* pOctreeNode, unordered_map<AABB, int>& visibleBounds, std::vector<KROctreeNode*>& remainingOctrees, std::vector<KROctreeNode*>& remainingOctreesTestResults, std::vector<KROctreeNode*>& remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly)
|
||||
{
|
||||
if(pOctreeNode) {
|
||||
|
||||
@@ -205,12 +210,12 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode,
|
||||
}
|
||||
} else {
|
||||
bool in_viewport = false;
|
||||
if(renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
// When pre-streaming, objects are streamed in behind and in-front of the camera
|
||||
AABB viewportExtents = AABB::Create(viewport.getCameraPosition() - Vector3::Create(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + Vector3::Create(pCamera->settings.getPerspectiveFarZ()));
|
||||
AABB viewportExtents = AABB::Create(ri.viewport.getCameraPosition() - Vector3::Create(ri.camera->settings.getPerspectiveFarZ()), ri.viewport.getCameraPosition() + Vector3::Create(ri.camera->settings.getPerspectiveFarZ()));
|
||||
in_viewport = octreeBounds.intersects(viewportExtents);
|
||||
} else {
|
||||
in_viewport = viewport.visible(pOctreeNode->getBounds());
|
||||
in_viewport = ri.viewport.visible(pOctreeNode->getBounds());
|
||||
}
|
||||
if(in_viewport) {
|
||||
|
||||
@@ -218,7 +223,7 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode,
|
||||
bool bVisible = false;
|
||||
bool bNeedOcclusionTest = true;
|
||||
|
||||
if(!pCamera->settings.getEnableRealtimeOcclusion()) {
|
||||
if(!ri.camera->settings.getEnableRealtimeOcclusion()) {
|
||||
bVisible = true;
|
||||
bNeedOcclusionTest = false;
|
||||
}
|
||||
@@ -226,7 +231,7 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode,
|
||||
if(!bVisible) {
|
||||
// Assume bounding boxes are visible without occlusion test queries if the camera is inside the box.
|
||||
// The near clipping plane of the camera is taken into consideration by expanding the match area
|
||||
AABB cameraExtents = AABB::Create(viewport.getCameraPosition() - Vector3::Create(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + Vector3::Create(pCamera->settings.getPerspectiveNearZ()));
|
||||
AABB cameraExtents = AABB::Create(ri.viewport.getCameraPosition() - Vector3::Create(ri.camera->settings.getPerspectiveNearZ()), ri.viewport.getCameraPosition() + Vector3::Create(ri.camera->settings.getPerspectiveNearZ()));
|
||||
bVisible = octreeBounds.intersects(cameraExtents);
|
||||
if(bVisible) {
|
||||
// Record the frame number in which the camera was within the bounds
|
||||
@@ -276,54 +281,54 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode,
|
||||
Matrix4 matModel = Matrix4();
|
||||
matModel.scale(octreeBounds.size() * 0.5f);
|
||||
matModel.translate(octreeBounds.center());
|
||||
Matrix4 mvpmatrix = matModel * viewport.getViewProjectionMatrix();
|
||||
Matrix4 mvpmatrix = matModel * ri.viewport.getViewProjectionMatrix();
|
||||
|
||||
|
||||
getContext().getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f);
|
||||
getContext().getMeshManager()->bindVBO(ri.commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f);
|
||||
|
||||
// Enable additive blending
|
||||
if(renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||
if(ri.renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT && ri.renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && ri.renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
}
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE ||
|
||||
renderPass == KRNode::RENDER_PASS_DEFERRED_GBUFFER ||
|
||||
renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE ||
|
||||
renderPass == KRNode::RENDER_PASS_SHADOWMAP) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE ||
|
||||
ri.renderPass == KRNode::RENDER_PASS_DEFERRED_GBUFFER ||
|
||||
ri.renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE ||
|
||||
ri.renderPass == KRNode::RENDER_PASS_SHADOWMAP) {
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
}
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("occlusion_test");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
info.spot_lights = &spot_lights;
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
|
||||
|
||||
if(getContext().getPipelineManager()->selectPipeline(info, viewport, matModel, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, info, ri.viewport, matModel, Vector3::Zero(), 0.0f, Vector4::Zero())) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
m_pContext->getMeshManager()->log_draw_call(renderPass, "octree", "occlusion_test", 14);
|
||||
m_pContext->getMeshManager()->log_draw_call(ri.renderPass, "octree", "occlusion_test", 14);
|
||||
}
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE ||
|
||||
renderPass == KRNode::RENDER_PASS_DEFERRED_GBUFFER ||
|
||||
renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE ||
|
||||
renderPass == KRNode::RENDER_PASS_SHADOWMAP) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE ||
|
||||
ri.renderPass == KRNode::RENDER_PASS_DEFERRED_GBUFFER ||
|
||||
ri.renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE ||
|
||||
ri.renderPass == KRNode::RENDER_PASS_SHADOWMAP) {
|
||||
|
||||
// Re-enable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_TRUE));
|
||||
// Re-enable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_TRUE));
|
||||
}
|
||||
|
||||
pOctreeNode->endOcclusionQuery();
|
||||
|
||||
if(renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||
if(ri.renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT && ri.renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && ri.renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
} else if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT) {
|
||||
} else if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT) {
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||
} else {
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE)); // RENDER_PASS_FORWARD_TRANSPARENT and RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE
|
||||
@@ -349,17 +354,17 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode,
|
||||
KRNode *node = (*itr);
|
||||
KRDirectionalLight *directional_light = dynamic_cast<KRDirectionalLight *>(node);
|
||||
if(directional_light) {
|
||||
directional_lights.push_back(directional_light);
|
||||
ri.directional_lights.push_back(directional_light);
|
||||
directional_light_count++;
|
||||
}
|
||||
KRSpotLight *spot_light = dynamic_cast<KRSpotLight *>(node);
|
||||
if(spot_light) {
|
||||
spot_lights.push_back(spot_light);
|
||||
ri.spot_lights.push_back(spot_light);
|
||||
spot_light_count++;
|
||||
}
|
||||
KRPointLight *point_light = dynamic_cast<KRPointLight *>(node);
|
||||
if(point_light) {
|
||||
point_lights.push_back(point_light);
|
||||
ri.point_lights.push_back(point_light);
|
||||
point_light_count++;
|
||||
}
|
||||
}
|
||||
@@ -367,25 +372,25 @@ void KRScene::render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode,
|
||||
// Render objects that are at this octree level
|
||||
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
|
||||
//assert(pOctreeNode->getBounds().contains((*itr)->getBounds())); // Sanity check
|
||||
(*itr)->render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
(*itr)->render(ri);
|
||||
}
|
||||
|
||||
// Render child octrees
|
||||
const int *childOctreeOrder = renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES || renderPass == KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE ? viewport.getBackToFrontOrder() : viewport.getFrontToBackOrder();
|
||||
const int *childOctreeOrder = ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || ri.renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES || ri.renderPass == KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE ? ri.viewport.getBackToFrontOrder() : ri.viewport.getFrontToBackOrder();
|
||||
|
||||
for(int i=0; i<8; i++) {
|
||||
render(commandBuffer, pOctreeNode->getChildren()[childOctreeOrder[i]], visibleBounds, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass, remainingOctrees, remainingOctreesTestResults, remainingOctreesTestResultsOnly, false, false);
|
||||
render(ri, pOctreeNode->getChildren()[childOctreeOrder[i]], visibleBounds, remainingOctrees, remainingOctreesTestResults, remainingOctreesTestResultsOnly, false, false);
|
||||
}
|
||||
|
||||
// Remove lights added at this octree level from the stack
|
||||
while(directional_light_count--) {
|
||||
directional_lights.pop_back();
|
||||
ri.directional_lights.pop_back();
|
||||
}
|
||||
while(spot_light_count--) {
|
||||
spot_lights.pop_back();
|
||||
ri.spot_lights.pop_back();
|
||||
}
|
||||
while(point_light_count--) {
|
||||
point_lights.pop_back();
|
||||
ri.point_lights.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,8 @@ public:
|
||||
bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, HitInfo &hitinfo, unsigned int layer_mask);
|
||||
|
||||
void renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface, float deltaTime);
|
||||
void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
|
||||
|
||||
void render(VkCommandBuffer& commandBuffer, KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
||||
void render(VkCommandBuffer& commandBuffer, KRSurface& surface, KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
|
||||
void render(KRNode::RenderInfo& ri, KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibleBounds, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
||||
|
||||
void updateOctree(const KRViewport &viewport);
|
||||
void buildOctreeForTheFirstTime();
|
||||
|
||||
@@ -110,9 +110,9 @@ AABB KRSprite::getBounds() {
|
||||
}
|
||||
|
||||
|
||||
void KRSprite::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) {
|
||||
void KRSprite::render(RenderInfo& ri) {
|
||||
|
||||
if(m_lod_visible >= LOD_VISIBILITY_PRESTREAM && renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
if(m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
// Pre-stream sprites, even if the alpha is zero
|
||||
if(m_spriteTexture.size() && m_pSpriteTexture == NULL) {
|
||||
if(!m_pSpriteTexture && m_spriteTexture.size()) {
|
||||
@@ -127,10 +127,10 @@ void KRSprite::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::ve
|
||||
|
||||
if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
|
||||
|
||||
KRNode::render(commandBuffer, pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
|
||||
KRNode::render(ri);
|
||||
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||
if(m_spriteTexture.size() && m_spriteAlpha > 0.0f) {
|
||||
|
||||
|
||||
@@ -159,16 +159,16 @@ void KRSprite::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::ve
|
||||
KRPipelineManager::PipelineInfo info{};
|
||||
std::string shader_name("sprite");
|
||||
info.shader_name = &shader_name;
|
||||
info.pCamera = pCamera;
|
||||
info.point_lights = &point_lights;
|
||||
info.directional_lights = &directional_lights;
|
||||
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())) {
|
||||
info.pCamera = ri.camera;
|
||||
info.point_lights = &ri.point_lights;
|
||||
info.directional_lights = &ri.directional_lights;
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.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);
|
||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
void setSpriteAlpha(float alpha);
|
||||
float getSpriteAlpha() const;
|
||||
|
||||
virtual void render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
virtual void render(RenderInfo& ri);
|
||||
|
||||
virtual AABB getBounds();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user