diff --git a/kraken/KRAmbientZone.cpp b/kraken/KRAmbientZone.cpp index 89bcbfd..4a80747 100755 --- a/kraken/KRAmbientZone.cpp +++ b/kraken/KRAmbientZone.cpp @@ -129,7 +129,7 @@ void KRAmbientZone::render(RenderInfo& ri) if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { Matrix4 sphereModelMatrix = getModelMatrix(); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = ri.camera; @@ -137,6 +137,7 @@ void KRAmbientZone::render(RenderInfo& ri) info.directional_lights = &ri.directional_lights; info.spot_lights = &ri.spot_lights; info.renderPass = ri.renderPass; + info.rasterMode = PipelineInfo::RasterMode::kAdditive; KRPipeline *pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); diff --git a/kraken/KRAudioSource.cpp b/kraken/KRAudioSource.cpp index db63c66..7166737 100755 --- a/kraken/KRAudioSource.cpp +++ b/kraken/KRAudioSource.cpp @@ -196,7 +196,7 @@ void KRAudioSource::render(RenderInfo& ri) if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { Matrix4 sphereModelMatrix = getModelMatrix(); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRBone.cpp b/kraken/KRBone.cpp index 1150ae7..5feaf39 100755 --- a/kraken/KRBone.cpp +++ b/kraken/KRBone.cpp @@ -91,7 +91,7 @@ void KRBone::render(RenderInfo& ri) // Disable z-buffer test GLDEBUG(glDisable(GL_DEPTH_TEST)); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index 0864fe6..5e8b4d5 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -33,6 +33,7 @@ #include "KRCamera.h" #include "KRDirectionalLight.h" #include "KRRenderPass.h" +#include "KRPipeline.h" /* static */ void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo) @@ -299,7 +300,12 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface) bool haveMesh = testVertices.isVBOReady(); if (haveMesh) { - KRPipeline* testPipeline = m_pContext->getPipelineManager()->getPipeline(surface, forwardOpaquePass, "vulkan_test", testVertices.getVertexAttributes(), KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP); + PipelineInfo info{}; + std::string shader_name("vulkan_test"); + info.shader_name = &shader_name; + info.pCamera = this; + info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT; + KRPipeline* testPipeline = m_pContext->getPipelineManager()->getPipeline(surface, info, testVertices.getVertexAttributes(), KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP); testPipeline->bind(commandBuffer); testVertices.bind(commandBuffer); vkCmdDraw(commandBuffer, 4, 1, 0, 0); @@ -340,7 +346,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface) if(m_pSkyBoxTexture) { std::string shader_name("sky_box"); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; info.shader_name = &shader_name; info.pCamera = this; info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE; @@ -533,7 +539,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface) GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE)); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = this; @@ -770,7 +776,7 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface) GLDEBUG(glViewport(0, 0, (GLsizei)m_viewport.getSize().x, (GLsizei)m_viewport.getSize().y)); GLDEBUG(glDisable(GL_DEPTH_TEST)); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("PostShader"); info.shader_name = &shader_name; info.pCamera = this; @@ -961,7 +967,7 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface) // Enable alpha blending GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("debug_font"); info.shader_name = &shader_name; info.pCamera = this; diff --git a/kraken/KRCollider.cpp b/kraken/KRCollider.cpp index 351ab92..78a79cc 100755 --- a/kraken/KRCollider.cpp +++ b/kraken/KRCollider.cpp @@ -204,7 +204,7 @@ void KRCollider::render(RenderInfo& ri) GL_PUSH_GROUP_MARKER("Debug Overlays"); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRDirectionalLight.cpp b/kraken/KRDirectionalLight.cpp index c30b4d7..91f092f 100755 --- a/kraken/KRDirectionalLight.cpp +++ b/kraken/KRDirectionalLight.cpp @@ -138,7 +138,7 @@ void KRDirectionalLight::render(RenderInfo& ri) { light_direction_view_space = Matrix4::Dot(matModelViewInverseTranspose, light_direction_view_space); light_direction_view_space.normalize(); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("light_directional"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRLight.cpp b/kraken/KRLight.cpp index 4032753..7ae0a49 100755 --- a/kraken/KRLight.cpp +++ b/kraken/KRLight.cpp @@ -258,7 +258,7 @@ void KRLight::render(RenderInfo& ri) { this_point_light.push_back(point_light); } - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("dust_particle"); info.shader_name = &shader_name; info.pCamera = ri.camera; @@ -306,7 +306,7 @@ void KRLight::render(RenderInfo& ri) { this_point_light.push_back(point_light); } - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; info.shader_name = &shader_name; info.pCamera = ri.camera; info.point_lights = &this_point_light; @@ -348,7 +348,7 @@ void KRLight::render(RenderInfo& ri) { occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix(); } - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("occlusion_test"); info.shader_name = &shader_name; info.pCamera = ri.camera; @@ -403,7 +403,7 @@ void KRLight::render(RenderInfo& ri) { GLDEBUG(glDepthRangef(0.0, 1.0)); // Render light flare on transparency pass - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("flare"); info.shader_name = &shader_name; info.pCamera = ri.camera; @@ -528,7 +528,7 @@ void KRLight::renderShadowBuffers(RenderInfo& ri) GLDEBUG(glDisable(GL_BLEND)); // Use shader program - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("ShadowShader"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRMaterial.cpp b/kraken/KRMaterial.cpp index 6802c35..de98d14 100755 --- a/kraken/KRMaterial.cpp +++ b/kraken/KRMaterial.cpp @@ -320,7 +320,7 @@ bool KRMaterial::bind(const KRNode::RenderInfo& ri, const std::vector 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{}; + PipelineInfo info{}; std::string shader_name("ObjectShader"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRParticleSystemNewtonian.cpp b/kraken/KRParticleSystemNewtonian.cpp index f2d3f96..3cbfcb6 100755 --- a/kraken/KRParticleSystemNewtonian.cpp +++ b/kraken/KRParticleSystemNewtonian.cpp @@ -96,7 +96,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri) { m_pContext->getTextureManager()->selectTexture(0, pParticleTexture, 0.0f, KRTexture::TEXTURE_USAGE_PARTICLE); int particle_count = 10000; - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("dust_particle"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index a3d9616..6e4e39d 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -110,7 +110,7 @@ const char *KRPipeline::KRENGINE_UNIFORM_NAMES[] = { "fade_color", // KRENGINE_UNIFORM_FADE_COLOR }; -KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, KRRenderPass& renderPass, const char* szKey, const std::vector& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat) +KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat) : KRContextObject(context) , m_iProgram(0) // not used for Vulkan { @@ -321,6 +321,8 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, KRRenderPass& ren depthStencil.front = {}; depthStencil.back = {}; + KRRenderPass& renderPass = surface.getForwardOpaquePass(); // TODO - This needs to be selected dynamically from info.render_pass + VkGraphicsPipelineCreateInfo pipelineInfo{}; pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.stageCount = stage_count; diff --git a/kraken/KRPipeline.h b/kraken/KRPipeline.h index 0c8de9d..bb4cb25 100644 --- a/kraken/KRPipeline.h +++ b/kraken/KRPipeline.h @@ -35,7 +35,6 @@ #define KRPIPELINE_H #include "KREngine-common.h" -#include "KRPipeline.h" #include "KRCamera.h" #include "KRNode.h" #include "KRViewport.h" @@ -45,10 +44,44 @@ class KRShader; class KRSurface; class KRRenderPass; - -class KRPipeline : public KRContextObject { +class PipelineInfo { public: - KRPipeline(KRContext& context, KRSurface& surface, KRRenderPass& renderPass, const char* szKey, const std::vector& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat); + enum class RasterMode : uint32_t { + kOpaque = 0, + kAlphaBlend = 1, + kAdditive = 2 + }; + const std::string* shader_name; + KRCamera* pCamera; + const std::vector* point_lights; + const std::vector* directional_lights; + const std::vector* spot_lights; + int bone_count; + bool bDiffuseMap : 1; + bool bNormalMap : 1; + bool bSpecMap : 1; + bool bReflectionMap : 1; + bool bReflectionCubeMap : 1; + bool bLightMap : 1; + bool bDiffuseMapScale : 1; + bool bSpecMapScale : 1; + bool bNormalMapScale : 1; + bool bReflectionMapScale : 1; + bool bDiffuseMapOffset : 1; + bool bSpecMapOffset : 1; + bool bNormalMapOffset : 1; + bool bReflectionMapOffset : 1; + bool bAlphaTest : 1; + bool bAlphaBlend : 1; + bool bRimColor : 1; + RasterMode rasterMode; + KRNode::RenderPass renderPass; +}; + +class KRPipeline : public KRContextObject { +public: + + KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector& shaders, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat); KRPipeline(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource); virtual ~KRPipeline(); const char *getKey() const; diff --git a/kraken/KRPipelineManager.cpp b/kraken/KRPipelineManager.cpp index 2335fa8..f47fab7 100644 --- a/kraken/KRPipelineManager.cpp +++ b/kraken/KRPipelineManager.cpp @@ -63,10 +63,10 @@ KRPipelineManager::~KRPipelineManager() { #endif // ANDROID } -KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, KRRenderPass& renderPass, const std::string& shader_name, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat) +KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInfo& info, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat) { std::pair > key; - key.first = shader_name; + key.first = *info.shader_name; key.second.push_back(surface.m_deviceHandle); key.second.push_back(surface.m_swapChain->m_imageFormat); key.second.push_back(surface.m_swapChain->m_extent.width); @@ -80,9 +80,9 @@ KRPipeline* KRPipelineManager::getPipeline(KRSurface& surface, KRRenderPass& ren } std::vector shaders; - shaders.push_back(m_pContext->getShaderManager()->get(shader_name + ".vert", "spv")); - shaders.push_back(m_pContext->getShaderManager()->get(shader_name + ".frag", "spv")); - KRPipeline* pipeline = new KRPipeline(*m_pContext, surface, renderPass, shader_name.c_str(), shaders, vertexAttributes, modelFormat); + shaders.push_back(m_pContext->getShaderManager()->get(*info.shader_name + ".vert", "spv")); + shaders.push_back(m_pContext->getShaderManager()->get(*info.shader_name + ".frag", "spv")); + KRPipeline* pipeline = new KRPipeline(*m_pContext, surface, info, info.shader_name->c_str(), shaders, vertexAttributes, modelFormat); m_pipelines[key] = pipeline; @@ -166,6 +166,7 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf key.second.push_back((int)(info.pCamera->settings.vignette_falloff * 1000.0f)); key.second.push_back(info.bRimColor); key.second.push_back(bFadeColorEnabled); + key.second.push_back((int)info.rasterMode); KRPipeline *pPipeline = m_pipelines[key]; diff --git a/kraken/KRPipelineManager.h b/kraken/KRPipelineManager.h index 0a36970..fcf3681 100644 --- a/kraken/KRPipelineManager.h +++ b/kraken/KRPipelineManager.h @@ -47,42 +47,17 @@ using std::vector; #define KRPIPELINEMANAGER_H class KRPipeline; +class PipelineInfo; class KRCamera; class KRPipelineManager : public KRContextObject { public: - typedef struct { - const std::string* shader_name; - KRCamera* pCamera; - const std::vector* point_lights; - const std::vector* directional_lights; - const std::vector* spot_lights; - int bone_count; - bool bDiffuseMap : 1; - bool bNormalMap : 1; - bool bSpecMap : 1; - bool bReflectionMap : 1; - bool bReflectionCubeMap : 1; - bool bLightMap : 1; - bool bDiffuseMapScale : 1; - bool bSpecMapScale : 1; - bool bNormalMapScale : 1; - bool bReflectionMapScale : 1; - bool bDiffuseMapOffset : 1; - bool bSpecMapOffset : 1; - bool bNormalMapOffset : 1; - bool bReflectionMapOffset : 1; - bool bAlphaTest : 1; - bool bAlphaBlend : 1; - bool bRimColor : 1; - KRNode::RenderPass renderPass; - } PipelineInfo; KRPipelineManager(KRContext &context); virtual ~KRPipelineManager(); 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(KRSurface& surface, const PipelineInfo& info, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat); KRPipeline* getPipeline(KRSurface& surface, const PipelineInfo& info); bool selectPipeline(KRSurface& surface, KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector *point_lights, const std::vector *directional_lights, const std::vector *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); diff --git a/kraken/KRPointLight.cpp b/kraken/KRPointLight.cpp index 0705f67..3856972 100755 --- a/kraken/KRPointLight.cpp +++ b/kraken/KRPointLight.cpp @@ -97,7 +97,7 @@ void KRPointLight::render(RenderInfo& ri) 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{}; + PipelineInfo info{}; info.shader_name = &shader_name; info.pCamera = ri.camera; info.point_lights = &this_light; diff --git a/kraken/KRReverbZone.cpp b/kraken/KRReverbZone.cpp index e58577c..7b2af35 100755 --- a/kraken/KRReverbZone.cpp +++ b/kraken/KRReverbZone.cpp @@ -127,7 +127,7 @@ void KRReverbZone::render(RenderInfo& ri) if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) { Matrix4 sphereModelMatrix = getModelMatrix(); - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRScene.cpp b/kraken/KRScene.cpp index 007a85d..a392d68 100755 --- a/kraken/KRScene.cpp +++ b/kraken/KRScene.cpp @@ -301,7 +301,7 @@ void KRScene::render(KRNode::RenderInfo& ri, KROctreeNode* pOctreeNode, unordere // Disable z-buffer write GLDEBUG(glDepthMask(GL_FALSE)); } - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("occlusion_test"); info.shader_name = &shader_name; info.pCamera = ri.camera; diff --git a/kraken/KRSprite.cpp b/kraken/KRSprite.cpp index 3f563fc..a157cdd 100755 --- a/kraken/KRSprite.cpp +++ b/kraken/KRSprite.cpp @@ -156,7 +156,7 @@ void KRSprite::render(RenderInfo& ri) { GLDEBUG(glDepthRangef(0.0, 1.0)); // Render light sprite on transparency pass - KRPipelineManager::PipelineInfo info{}; + PipelineInfo info{}; std::string shader_name("sprite"); info.shader_name = &shader_name; info.pCamera = ri.camera;