KRMesh::renderSubmesh is now private.

Added KRMesh::renderNoMaterials.
Replaced renderSubmesh loops outside KRMesh with calls to KRMesh::renderNoMaterials.
Added KRMesh::getVertexAttributes.
Call sites are now using KRMesh::getVertexAttributes and KRMesh::getModelFormat to configure the pipeline.
This commit is contained in:
2022-07-06 23:04:43 -07:00
parent b7e4415b16
commit 93d665b356
3 changed files with 65 additions and 58 deletions

View File

@@ -281,7 +281,6 @@ void KRLight::render(RenderInfo& ri) {
, "Light Particles" , "Light Particles"
#endif #endif
); );
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3));
vkCmdDraw(ri.commandBuffer, particle_count * 3, 1, 0, 0); vkCmdDraw(ri.commandBuffer, particle_count * 3, 1, 0, 0);
} }
} }
@@ -316,6 +315,8 @@ void KRLight::render(RenderInfo& ri) {
info.renderPass = KRNode::RENDER_PASS_ADDITIVE_PARTICLES; info.renderPass = KRNode::RENDER_PASS_ADDITIVE_PARTICLES;
info.rasterMode = PipelineInfo::RasterMode::kAdditive; info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone; info.cullMode = PipelineInfo::CullMode::kCullNone;
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX);
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
@@ -336,55 +337,53 @@ void KRLight::render(RenderInfo& ri) {
, "Participating Media" , "Participating Media"
#endif #endif
); );
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, slice_count*6)); vkCmdDraw(ri.commandBuffer, slice_count * 6, 1, 0, 0);
} }
if(ri.renderPass == KRNode::RENDER_PASS_PARTICLE_OCCLUSION) { if(ri.renderPass == KRNode::RENDER_PASS_PARTICLE_OCCLUSION) {
if(m_flareTexture.size() && m_flareSize > 0.0f) { if(m_flareTexture.size() && m_flareSize > 0.0f) {
std::vector<KRMesh*> sphereModels = getContext().getMeshManager()->getModel("__sphere");
if (sphereModels.size()) {
Matrix4 occlusion_test_sphere_matrix = Matrix4();
occlusion_test_sphere_matrix.scale(m_localScale * m_flareOcclusionSize);
occlusion_test_sphere_matrix.translate(m_localTranslation);
if(m_parentNode) {
occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix();
}
Matrix4 occlusion_test_sphere_matrix = Matrix4(); PipelineInfo info{};
occlusion_test_sphere_matrix.scale(m_localScale * m_flareOcclusionSize); std::string shader_name("occlusion_test");
occlusion_test_sphere_matrix.translate(m_localTranslation); info.shader_name = &shader_name;
if(m_parentNode) { info.pCamera = ri.camera;
occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix(); info.point_lights = &ri.point_lights;
} info.directional_lights = &ri.directional_lights;
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.modelFormat = sphereModels[0]->getModelFormat();
info.vertexAttributes = sphereModels[0]->getVertexAttributes();
PipelineInfo info{}; KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
std::string shader_name("occlusion_test"); pPipeline->bind(*info.pCamera, ri.viewport, occlusion_test_sphere_matrix, info.point_lights, info.directional_lights, info.spot_lights, info.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
info.shader_name = &shader_name;
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;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
// TODO: set info.vertexAttributes and info.modelFormat
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery));
pPipeline->bind(*info.pCamera, ri.viewport, occlusion_test_sphere_matrix, info.point_lights, info.directional_lights, info.spot_lights, info.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero()); #if TARGET_OS_IPHONE || defined(ANDROID)
GLDEBUG(glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, m_occlusionQuery));
#else
GLDEBUG(glBeginQuery(GL_SAMPLES_PASSED, m_occlusionQuery));
#endif
GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery)); sphereModels[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "occlusion_test", 1.0f);
#if TARGET_OS_IPHONE || defined(ANDROID)
GLDEBUG(glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, m_occlusionQuery));
#else
GLDEBUG(glBeginQuery(GL_SAMPLES_PASSED, m_occlusionQuery));
#endif
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
if(sphereModels.size()) {
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
sphereModels[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "occlusion_test", 1.0f);
}
}
#if TARGET_OS_IPHONE || defined(ANDROID) #if TARGET_OS_IPHONE || defined(ANDROID)
GLDEBUG(glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT)); GLDEBUG(glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT));
#else #else
GLDEBUG(glEndQuery(GL_SAMPLES_PASSED)); GLDEBUG(glEndQuery(GL_SAMPLES_PASSED));
#endif #endif
}
} }
} }
@@ -404,6 +403,8 @@ void KRLight::render(RenderInfo& ri) {
} }
if(m_pFlareTexture) { if(m_pFlareTexture) {
KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES;
// Render light flare on transparency pass // Render light flare on transparency pass
PipelineInfo info{}; PipelineInfo info{};
std::string shader_name("flare"); std::string shader_name("flare");
@@ -415,6 +416,10 @@ void KRLight::render(RenderInfo& ri) {
info.renderPass = ri.renderPass; info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest; info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest;
info.cullMode = PipelineInfo::CullMode::kCullNone; info.cullMode = PipelineInfo::CullMode::kCullNone;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->bind(*ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero()); pShader->bind(*ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
@@ -422,8 +427,8 @@ void KRLight::render(RenderInfo& ri) {
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f); pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f);
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize); 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->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE);
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0);
} }
} }
} }

View File

@@ -127,7 +127,7 @@ public:
void optimize(); void optimize();
void optimizeIndexes(); void optimizeIndexes();
void renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode::RenderPass renderPass, const std::string &object_name, const std::string &material_name, float lodCoverage); void renderNoMaterials(VkCommandBuffer& commandBuffer, KRNode::RenderPass renderPass, const std::string& object_name, const std::string& material_name, float lodCoverage);
float getMaxDimension(); float getMaxDimension();
@@ -184,6 +184,8 @@ public:
int getSubmeshCount() const; int getSubmeshCount() const;
int getVertexCount(int submesh) const; int getVertexCount(int submesh) const;
__uint32_t getVertexAttributes() const;
int getTriangleVertexIndex(int submesh, int index) const; int getTriangleVertexIndex(int submesh, int index) const;
Vector3 getVertexPosition(int index) const; Vector3 getVertexPosition(int index) const;
Vector3 getVertexNormal(int index) const; Vector3 getVertexNormal(int index) const;
@@ -228,6 +230,7 @@ private:
void getSubmeshes(); void getSubmeshes();
void getMaterials(); void getMaterials();
void renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode::RenderPass renderPass, const std::string& object_name, const std::string& material_name, float lodCoverage);
static bool rayCast(const Vector3 &start, const Vector3 &dir, const Triangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, HitInfo &hitinfo); static bool rayCast(const Vector3 &start, const Vector3 &dir, const Triangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, HitInfo &hitinfo);
static bool sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const Triangle3 &tri, HitInfo &hitinfo); static bool sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const Triangle3 &tri, HitInfo &hitinfo);

View File

@@ -126,28 +126,27 @@ void KRReverbZone::render(RenderInfo& ri)
bool bVisualize = ri.camera->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(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
Matrix4 sphereModelMatrix = getModelMatrix(); std::vector<KRMesh*> sphereModels = getContext().getMeshManager()->getModel("__sphere");
PipelineInfo info{}; if (sphereModels.size()) {
std::string shader_name("visualize_overlay"); Matrix4 sphereModelMatrix = getModelMatrix();
info.shader_name = &shader_name; PipelineInfo info{};
info.pCamera = ri.camera; std::string shader_name("visualize_overlay");
info.point_lights = &ri.point_lights; info.shader_name = &shader_name;
info.directional_lights = &ri.directional_lights; info.pCamera = ri.camera;
info.spot_lights = &ri.spot_lights; info.point_lights = &ri.point_lights;
info.renderPass = ri.renderPass; info.directional_lights = &ri.directional_lights;
info.rasterMode = PipelineInfo::RasterMode::kAlphaBlend; info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAlphaBlend;
info.modelFormat = sphereModels[0]->getModelFormat();
info.vertexAttributes = sphereModels[0]->getVertexAttributes();
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->bind(*ri.camera, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
pShader->bind(*ri.camera, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero()); sphereModels[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
} // sphereModels.size()
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
if(sphereModels.size()) {
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
sphereModels[0]->renderSubmesh(ri.commandBuffer, i, ri.renderPass, getName(), "visualize_overlay", 1.0f);
}
}
} }
} }