Refactoring to rename uniform related functions and members to reflect that they are actually push constants after the Vulkan refactoring.

This commit is contained in:
2022-09-07 23:48:46 -07:00
parent 10f9c17cf1
commit e695bca3f9
9 changed files with 192 additions and 192 deletions

View File

@@ -554,7 +554,7 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(surface, info);
postShader->setUniform(KRPipeline::Uniform::fade_color, m_fade_color);
postShader->setPushConstant(KRPipeline::PushConstant::fade_color, m_fade_color);
postShader->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture);

View File

@@ -157,9 +157,9 @@ void KRDirectionalLight::render(RenderInfo& ri)
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setUniform(KRPipeline::Uniform::light_direction_view_space, light_direction_view_space);
pShader->setUniform(KRPipeline::Uniform::light_color, m_color);
pShader->setUniform(KRPipeline::Uniform::light_intensity, m_intensity * 0.01f);
pShader->setPushConstant(KRPipeline::PushConstant::light_direction_view_space, light_direction_view_space);
pShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color);
pShader->setPushConstant(KRPipeline::PushConstant::light_intensity, m_intensity * 0.01f);
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), nullptr, &this_light, nullptr, ri.renderPass);
// Render a full screen quad

View File

@@ -281,9 +281,9 @@ void KRLight::render(RenderInfo& ri)
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
pParticleShader->setUniform(KRPipeline::Uniform::light_color, m_color * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
pParticleShader->setUniform(KRPipeline::Uniform::particle_origin, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
pParticleShader->setUniform(KRPipeline::Uniform::flare_size, m_dust_particle_size);
pParticleShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
pParticleShader->setPushConstant(KRPipeline::PushConstant::particle_origin, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_dust_particle_size);
pParticleShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, particleModelMatrix, &this_point_light, &this_directional_light, &this_spot_light, ri.renderPass);
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);
@@ -333,8 +333,8 @@ void KRLight::render(RenderInfo& ri)
float slice_far = -ri.camera->settings.volumetric_environment_max_distance;
float slice_spacing = (slice_far - slice_near) / slice_count;
pFogShader->setUniform(KRPipeline::Uniform::slice_depth_scale, Vector2::Create(slice_near, slice_spacing));
pFogShader->setUniform(KRPipeline::Uniform::light_color, (m_color * ri.camera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
pFogShader->setPushConstant(KRPipeline::PushConstant::slice_depth_scale, Vector2::Create(slice_near, slice_spacing));
pFogShader->setPushConstant(KRPipeline::PushConstant::light_color, (m_color * ri.camera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
pFogShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, Matrix4(), &this_point_light, &this_directional_light, &this_spot_light, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE);
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_VOLUMETRIC_LIGHTING, 1.0f);
@@ -422,8 +422,8 @@ void KRLight::render(RenderInfo& ri)
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setUniform(KRPipeline::Uniform::material_alpha, 1.0f);
pShader->setUniform(KRPipeline::Uniform::flare_size, m_flareSize);
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, 1.0f);
pShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_flareSize);
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE);

View File

@@ -372,11 +372,11 @@ void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __u
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
// Rim highlighting parameters
pShader->setUniform(KRPipeline::Uniform::rim_color, rim_color);
pShader->setUniform(KRPipeline::Uniform::rim_power, rim_power);
pShader->setPushConstant(KRPipeline::PushConstant::rim_color, rim_color);
pShader->setPushConstant(KRPipeline::PushConstant::rim_power, rim_power);
// Bind bones
if (pShader->hasUniform(KRPipeline::Uniform::bone_transforms)) {
if (pShader->hasPushConstant(KRPipeline::PushConstant::bone_transforms)) {
float bone_mats[256 * 16];
float* bone_mat_component = bone_mats;
for (int bone_index = 0; bone_index < bones.size(); bone_index++) {
@@ -403,40 +403,40 @@ void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __u
*bone_mat_component++ = t[i];
}
}
if (pShader->hasUniform(KRPipeline::Uniform::bone_transforms)) {
pShader->setUniform(KRPipeline::Uniform::bone_transforms, (Matrix4*)bone_mats, bones.size());
if (pShader->hasPushConstant(KRPipeline::PushConstant::bone_transforms)) {
pShader->setPushConstant(KRPipeline::PushConstant::bone_transforms, (Matrix4*)bone_mats, bones.size());
}
}
pShader->setUniform(KRPipeline::Uniform::material_ambient, m_ambientColor + ri.camera->settings.ambient_intensity);
pShader->setPushConstant(KRPipeline::PushConstant::material_ambient, m_ambientColor + ri.camera->settings.ambient_intensity);
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::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));
pShader->setPushConstant(KRPipeline::PushConstant::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::Uniform::material_diffuse, m_diffuseColor);
pShader->setPushConstant(KRPipeline::PushConstant::material_diffuse, m_diffuseColor);
}
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::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));
pShader->setPushConstant(KRPipeline::PushConstant::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::Uniform::material_specular, m_specularColor);
pShader->setPushConstant(KRPipeline::PushConstant::material_specular, m_specularColor);
}
pShader->setUniform(KRPipeline::Uniform::material_shininess, m_ns);
pShader->setUniform(KRPipeline::Uniform::material_reflection, m_reflectionColor);
pShader->setUniform(KRPipeline::Uniform::diffusetexture_scale, m_diffuseMapScale);
pShader->setUniform(KRPipeline::Uniform::speculartexture_scale, m_specularMapScale);
pShader->setUniform(KRPipeline::Uniform::reflectiontexture_scale, m_reflectionMapScale);
pShader->setUniform(KRPipeline::Uniform::normaltexture_scale, m_normalMapScale);
pShader->setUniform(KRPipeline::Uniform::diffusetexture_offset, m_diffuseMapOffset);
pShader->setUniform(KRPipeline::Uniform::speculartexture_offset, m_specularMapOffset);
pShader->setUniform(KRPipeline::Uniform::reflectiontexture_offset, m_reflectionMapOffset);
pShader->setUniform(KRPipeline::Uniform::normaltexture_offset, m_normalMapOffset);
pShader->setPushConstant(KRPipeline::PushConstant::material_shininess, m_ns);
pShader->setPushConstant(KRPipeline::PushConstant::material_reflection, m_reflectionColor);
pShader->setPushConstant(KRPipeline::PushConstant::diffusetexture_scale, m_diffuseMapScale);
pShader->setPushConstant(KRPipeline::PushConstant::speculartexture_scale, m_specularMapScale);
pShader->setPushConstant(KRPipeline::PushConstant::reflectiontexture_scale, m_reflectionMapScale);
pShader->setPushConstant(KRPipeline::PushConstant::normaltexture_scale, m_normalMapScale);
pShader->setPushConstant(KRPipeline::PushConstant::diffusetexture_offset, m_diffuseMapOffset);
pShader->setPushConstant(KRPipeline::PushConstant::speculartexture_offset, m_specularMapOffset);
pShader->setPushConstant(KRPipeline::PushConstant::reflectiontexture_offset, m_reflectionMapOffset);
pShader->setPushConstant(KRPipeline::PushConstant::normaltexture_offset, m_normalMapOffset);
pShader->setUniform(KRPipeline::Uniform::material_alpha, m_tr);
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_tr);
if (bDiffuseMap) {
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap, lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP);

View File

@@ -105,7 +105,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri)
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
pParticleShader->setUniform(KRPipeline::Uniform::flare_size, 1.0f);
pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, 1.0f);
pParticleShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);

View File

@@ -39,75 +39,75 @@
#include "KRRenderPass.h"
const char* KRPipeline::KRENGINE_UNIFORM_NAMES[] = {
"material_ambient", // Uniform::material_ambient
"material_diffuse", // Uniform::material_diffuse
"material_specular", // Uniform::material_specular
"material_reflection", // Uniform::material_reflection
"material_alpha", // Uniform::material_alpha
"material_shininess", // Uniform::material_shininess
"light_position", // Uniform::light_position
"light_direction_model_space", // Uniform::light_direction_model_space
"light_direction_view_space", // Uniform::light_direction_view_space
"light_color", // Uniform::light_color
"light_decay_start", // Uniform::light_decay_start
"light_cutoff", // Uniform::light_cutoff
"light_intensity", // Uniform::light_intensity
"flare_size", // Uniform::flare_size
"view_space_model_origin", // Uniform::view_space_model_origin
"mvp_matrix", // Uniform::mvp
"inv_projection_matrix", // Uniform::invp
"inv_mvp_matrix", // Uniform::invmvp
"inv_mvp_matrix_no_translate", // Uniform::invmvp_no_translate
"model_view_inverse_transpose_matrix", // Uniform::model_view_inverse_transpose
"model_inverse_transpose_matrix", // Uniform::model_inverse_transpose
"model_view_matrix", // Uniform::model_view
"model_matrix", // Uniform::model_matrix
"projection_matrix", // Uniform::projection_matrix
"camera_position_model_space", // Uniform::camerapos_model_space
"viewport", // Uniform::viewport
"viewport_downsample", // Uniform::viewport_downsample
"diffuseTexture", // Uniform::diffusetexture
"specularTexture", // Uniform::speculartexture
"reflectionCubeTexture", // Uniform::reflectioncubetexture
"reflectionTexture", // Uniform::reflectiontexture
"normalTexture", // Uniform::normaltexture
"diffuseTexture_Scale", // Uniform::diffusetexture_scale
"specularTexture_Scale", // Uniform::speculartexture_scale
"reflectionTexture_Scale", // Uniform::reflectiontexture_scale
"normalTexture_Scale", // Uniform::normaltexture_scale
"normalTexture_Scale", // Uniform::ambienttexture_scale
"diffuseTexture_Offset", // Uniform::diffusetexture_offset
"specularTexture_Offset", // Uniform::speculartexture_offset
"reflectionTexture_Offset", // Uniform::reflectiontexture_offset
"normalTexture_Offset", // Uniform::normaltexture_offset
"ambientTexture_Offset", // Uniform::ambienttexture_offset
"shadow_mvp1", // Uniform::shadow_mvp1
"shadow_mvp2", // Uniform::shadow_mvp2
"shadow_mvp3", // Uniform::shadow_mvp3
"shadowTexture1", // Uniform::shadowtexture1
"shadowTexture2", // Uniform::shadowtexture2
"shadowTexture3", // Uniform::shadowtexture3
"lightmapTexture", // Uniform::lightmaptexture
"gbuffer_frame", // Uniform::gbuffer_frame
"gbuffer_depth", // Uniform::gbuffer_depth
"depthFrame", // Uniform::depth_frame
"volumetricEnvironmentFrame", // Uniform::volumetric_environment_frame
"renderFrame", // Uniform::render_frame
"time_absolute", // Uniform::absolute_time
"fog_near", // Uniform::fog_near
"fog_far", // Uniform::fog_far
"fog_density", // Uniform::fog_density
"fog_color", // Uniform::fog_color
"fog_scale", // Uniform::fog_scale
"fog_density_premultiplied_exponential", // Uniform::density_premultiplied_exponential
"fog_density_premultiplied_squared", // Uniform::density_premultiplied_squared
"slice_depth_scale", // Uniform::slice_depth_scale
"particle_origin", // Uniform::particle_origin
"bone_transforms", // Uniform::bone_transforms
"rim_color", // Uniform::rim_color
"rim_power", // Uniform::rim_power
"fade_color", // Uniform::fade_color
const char* KRPipeline::KRENGINE_PUSH_CONSTANT_NAMES[] = {
"material_ambient", // PushConstant::material_ambient
"material_diffuse", // PushConstant::material_diffuse
"material_specular", // PushConstant::material_specular
"material_reflection", // PushConstant::material_reflection
"material_alpha", // PushConstant::material_alpha
"material_shininess", // PushConstant::material_shininess
"light_position", // PushConstant::light_position
"light_direction_model_space", // PushConstant::light_direction_model_space
"light_direction_view_space", // PushConstant::light_direction_view_space
"light_color", // PushConstant::light_color
"light_decay_start", // PushConstant::light_decay_start
"light_cutoff", // PushConstant::light_cutoff
"light_intensity", // PushConstant::light_intensity
"flare_size", // PushConstant::flare_size
"view_space_model_origin", // PushConstant::view_space_model_origin
"mvp_matrix", // PushConstant::mvp
"inv_projection_matrix", // PushConstant::invp
"inv_mvp_matrix", // PushConstant::invmvp
"inv_mvp_matrix_no_translate", // PushConstant::invmvp_no_translate
"model_view_inverse_transpose_matrix", // PushConstant::model_view_inverse_transpose
"model_inverse_transpose_matrix", // PushConstant::model_inverse_transpose
"model_view_matrix", // PushConstant::model_view
"model_matrix", // PushConstant::model_matrix
"projection_matrix", // PushConstant::projection_matrix
"camera_position_model_space", // PushConstant::camerapos_model_space
"viewport", // PushConstant::viewport
"viewport_downsample", // PushConstant::viewport_downsample
"diffuseTexture", // PushConstant::diffusetexture
"specularTexture", // PushConstant::speculartexture
"reflectionCubeTexture", // PushConstant::reflectioncubetexture
"reflectionTexture", // PushConstant::reflectiontexture
"normalTexture", // PushConstant::normaltexture
"diffuseTexture_Scale", // PushConstant::diffusetexture_scale
"specularTexture_Scale", // PushConstant::speculartexture_scale
"reflectionTexture_Scale", // PushConstant::reflectiontexture_scale
"normalTexture_Scale", // PushConstant::normaltexture_scale
"normalTexture_Scale", // PushConstant::ambienttexture_scale
"diffuseTexture_Offset", // PushConstant::diffusetexture_offset
"specularTexture_Offset", // PushConstant::speculartexture_offset
"reflectionTexture_Offset", // PushConstant::reflectiontexture_offset
"normalTexture_Offset", // PushConstant::normaltexture_offset
"ambientTexture_Offset", // PushConstant::ambienttexture_offset
"shadow_mvp1", // PushConstant::shadow_mvp1
"shadow_mvp2", // PushConstant::shadow_mvp2
"shadow_mvp3", // PushConstant::shadow_mvp3
"shadowTexture1", // PushConstant::shadowtexture1
"shadowTexture2", // PushConstant::shadowtexture2
"shadowTexture3", // PushConstant::shadowtexture3
"lightmapTexture", // PushConstant::lightmaptexture
"gbuffer_frame", // PushConstant::gbuffer_frame
"gbuffer_depth", // PushConstant::gbuffer_depth
"depthFrame", // PushConstant::depth_frame
"volumetricEnvironmentFrame", // PushConstant::volumetric_environment_frame
"renderFrame", // PushConstant::render_frame
"time_absolute", // PushConstant::absolute_time
"fog_near", // PushConstant::fog_near
"fog_far", // PushConstant::fog_far
"fog_density", // PushConstant::fog_density
"fog_color", // PushConstant::fog_color
"fog_scale", // PushConstant::fog_scale
"fog_density_premultiplied_exponential", // PushConstant::density_premultiplied_exponential
"fog_density_premultiplied_squared", // PushConstant::density_premultiplied_squared
"slice_depth_scale", // PushConstant::slice_depth_scale
"particle_origin", // PushConstant::particle_origin
"bone_transforms", // PushConstant::bone_transforms
"rim_color", // PushConstant::rim_color
"rim_power", // PushConstant::rim_power
"fade_color", // PushConstant::fade_color
};
KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat)
@@ -116,8 +116,8 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
for (PushConstantStageInfo& pushConstants : m_pushConstants) {
pushConstants.buffer = nullptr;
pushConstants.bufferSize = 0;
memset(pushConstants.size, 0, kUniformCount);
memset(pushConstants.offset, 0, kUniformCount * sizeof(int));
memset(pushConstants.size, 0, kPushConstantCount);
memset(pushConstants.offset, 0, kPushConstantCount * sizeof(int));
pushConstants.layout = nullptr;
}
@@ -531,10 +531,10 @@ void KRPipeline::initPushConstantStage(ShaderStages stage, const SpvReflectShade
pushConstants.bufferSize = block.size;
// Get push constant offsets
for (int iUniform = 0; iUniform < kUniformCount; iUniform++) {
for (int iUniform = 0; iUniform < kPushConstantCount; iUniform++) {
for (int iMember = 0; iMember < block.member_count; iMember++) {
const SpvReflectBlockVariable& member = block.members[iMember];
if (stricmp(KRENGINE_UNIFORM_NAMES[iUniform], member.name) == 0) {
if (stricmp(KRENGINE_PUSH_CONSTANT_NAMES[iUniform], member.name) == 0) {
pushConstants.offset[iUniform] = member.offset;
pushConstants.size[iUniform] = member.size;
}
@@ -545,7 +545,7 @@ void KRPipeline::initPushConstantStage(ShaderStages stage, const SpvReflectShade
}
}
bool KRPipeline::hasUniform(Uniform location) const
bool KRPipeline::hasPushConstant(PushConstant location) const
{
for (const PushConstantStageInfo& stageConstants : m_pushConstants) {
if (stageConstants.size[static_cast<size_t>(location)]) {
@@ -555,7 +555,7 @@ bool KRPipeline::hasUniform(Uniform location) const
return false;
}
void KRPipeline::setUniform(Uniform location, float value)
void KRPipeline::setPushConstant(PushConstant location, float value)
{
for (PushConstantStageInfo& stageConstants : m_pushConstants) {
if (stageConstants.size[static_cast<size_t>(location)] == sizeof(value)) {
@@ -566,7 +566,7 @@ void KRPipeline::setUniform(Uniform location, float value)
}
void KRPipeline::setUniform(Uniform location, int value)
void KRPipeline::setPushConstant(PushConstant location, int value)
{
for (PushConstantStageInfo& stageConstants : m_pushConstants) {
if (stageConstants.size[static_cast<size_t>(location)] == sizeof(value)) {
@@ -576,7 +576,7 @@ void KRPipeline::setUniform(Uniform location, int value)
}
}
void KRPipeline::setUniform(Uniform location, const Vector2& value)
void KRPipeline::setPushConstant(PushConstant location, const Vector2& value)
{
for (PushConstantStageInfo& stageConstants : m_pushConstants) {
if (stageConstants.size[static_cast<size_t>(location)] == sizeof(value)) {
@@ -585,7 +585,7 @@ void KRPipeline::setUniform(Uniform location, const Vector2& value)
}
}
}
void KRPipeline::setUniform(Uniform location, const Vector3& value)
void KRPipeline::setPushConstant(PushConstant location, const Vector3& value)
{
for (PushConstantStageInfo& stageConstants : m_pushConstants) {
if (stageConstants.size[static_cast<size_t>(location)] == sizeof(value)) {
@@ -595,7 +595,7 @@ void KRPipeline::setUniform(Uniform location, const Vector3& value)
}
}
void KRPipeline::setUniform(Uniform location, const Vector4& value)
void KRPipeline::setPushConstant(PushConstant location, const Vector4& value)
{
for (PushConstantStageInfo& stageConstants : m_pushConstants) {
if (stageConstants.size[static_cast<size_t>(location)] == sizeof(value)) {
@@ -605,7 +605,7 @@ void KRPipeline::setUniform(Uniform location, const Vector4& value)
}
}
void KRPipeline::setUniform(Uniform location, const Matrix4& value)
void KRPipeline::setPushConstant(PushConstant location, const Matrix4& value)
{
for (PushConstantStageInfo& stageConstants : m_pushConstants) {
if (stageConstants.size[static_cast<size_t>(location)] == sizeof(value)) {
@@ -615,17 +615,17 @@ void KRPipeline::setUniform(Uniform location, const Matrix4& value)
}
}
void KRPipeline::setUniform(Uniform location, const Matrix4* value, const size_t count)
void KRPipeline::setPushConstant(PushConstant location, const Matrix4* value, const size_t count)
{
for (PushConstantStageInfo& stageConstants : m_pushConstants) {
// TODO - Vulkan refactoring
// GLDEBUG(glUniformMatrix4fv(pShader->m_pushConstants[0].offset[KRPipeline::Uniform::bone_transforms], (GLsizei)bones.size(), GL_FALSE, bone_mats));
// GLDEBUG(glUniformMatrix4fv(pShader->m_pushConstants[0].offset[KRPipeline::PushConstant::bone_transforms], (GLsizei)bones.size(), GL_FALSE, bone_mats));
}
}
bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const Matrix4& matModel, const std::vector<KRPointLight*>* point_lights, const std::vector<KRDirectionalLight*>* directional_lights, const std::vector<KRSpotLight*>* spot_lights, const KRNode::RenderPass& renderPass)
{
setUniform(Uniform::absolute_time, getContext().getAbsoluteTime());
setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime());
int light_directional_count = 0;
//int light_point_count = 0;
@@ -639,7 +639,7 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
KRDirectionalLight* directional_light = (*light_itr);
if (light_directional_count == 0) {
int cShadowBuffers = directional_light->getShadowBufferCount();
if (hasUniform(Uniform::shadowtexture1) && cShadowBuffers > 0) {
if (hasPushConstant(PushConstant::shadowtexture1) && cShadowBuffers > 0) {
if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 3, directional_light->getShadowTextures()[0])) {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
@@ -649,7 +649,7 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
m_pContext->getTextureManager()->_setWrapModeT(3, GL_CLAMP_TO_EDGE);
}
if (hasUniform(Uniform::shadowtexture2) && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) {
if (hasPushConstant(PushConstant::shadowtexture2) && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) {
if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 4, directional_light->getShadowTextures()[1])) {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
@@ -658,7 +658,7 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
m_pContext->getTextureManager()->_setWrapModeT(4, GL_CLAMP_TO_EDGE);
}
if (hasUniform(Uniform::shadowtexture3) && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) {
if (hasPushConstant(PushConstant::shadowtexture3) && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) {
if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 5, directional_light->getShadowTextures()[2])) {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
@@ -671,17 +671,17 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
matBias.translate(1.0, 1.0, 1.0);
matBias.scale(0.5);
for (int iShadow = 0; iShadow < cShadowBuffers; iShadow++) {
setUniform(static_cast<Uniform>(static_cast<int>(Uniform::shadow_mvp1) + iShadow), matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias);
setPushConstant(static_cast<PushConstant>(static_cast<int>(PushConstant::shadow_mvp1) + iShadow), matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias);
}
if (hasUniform(Uniform::light_direction_model_space)) {
if (hasPushConstant(PushConstant::light_direction_model_space)) {
Matrix4 inverseModelMatrix = matModel;
inverseModelMatrix.invert();
// Bind the light direction vector
Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection());
lightDirObject.normalize();
setUniform(Uniform::light_direction_model_space, lightDirObject);
setPushConstant(PushConstant::light_direction_model_space, lightDirObject);
}
}
@@ -693,57 +693,57 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
//light_spot_count = spot_lights.size();
}
if (hasUniform(Uniform::camerapos_model_space)) {
if (hasPushConstant(PushConstant::camerapos_model_space)) {
Matrix4 inverseModelMatrix = matModel;
inverseModelMatrix.invert();
if (hasUniform(Uniform::camerapos_model_space)) {
if (hasPushConstant(PushConstant::camerapos_model_space)) {
// Transform location of camera to object space for calculation of specular halfVec
Vector3 cameraPosObject = Matrix4::Dot(inverseModelMatrix, viewport.getCameraPosition());
setUniform(Uniform::camerapos_model_space, cameraPosObject);
setPushConstant(PushConstant::camerapos_model_space, cameraPosObject);
}
}
if (hasUniform(Uniform::mvp) || hasUniform(KRPipeline::Uniform::invmvp)) {
if (hasPushConstant(PushConstant::mvp) || hasPushConstant(KRPipeline::PushConstant::invmvp)) {
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
Matrix4 mvpMatrix = matModel * viewport.getViewProjectionMatrix();
setUniform(Uniform::mvp, mvpMatrix);
setPushConstant(PushConstant::mvp, mvpMatrix);
if (hasUniform(KRPipeline::Uniform::invmvp)) {
setUniform(KRPipeline::Uniform::invmvp, Matrix4::Invert(mvpMatrix));
if (hasPushConstant(KRPipeline::PushConstant::invmvp)) {
setPushConstant(KRPipeline::PushConstant::invmvp, Matrix4::Invert(mvpMatrix));
}
}
if (hasUniform(KRPipeline::Uniform::view_space_model_origin) || hasUniform(Uniform::model_view_inverse_transpose) || hasUniform(KRPipeline::Uniform::model_view)) {
if (hasPushConstant(KRPipeline::PushConstant::view_space_model_origin) || hasPushConstant(PushConstant::model_view_inverse_transpose) || hasPushConstant(KRPipeline::PushConstant::model_view)) {
Matrix4 matModelView = matModel * viewport.getViewMatrix();
setUniform(Uniform::model_view, matModelView);
setPushConstant(PushConstant::model_view, matModelView);
if (hasUniform(KRPipeline::Uniform::view_space_model_origin)) {
if (hasPushConstant(KRPipeline::PushConstant::view_space_model_origin)) {
Vector3 view_space_model_origin = Matrix4::Dot(matModelView, Vector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
setUniform(Uniform::view_space_model_origin, view_space_model_origin);
setPushConstant(PushConstant::view_space_model_origin, view_space_model_origin);
}
if (hasUniform(Uniform::model_view_inverse_transpose)) {
if (hasPushConstant(PushConstant::model_view_inverse_transpose)) {
Matrix4 matModelViewInverseTranspose = matModelView;
matModelViewInverseTranspose.transpose();
matModelViewInverseTranspose.invert();
setUniform(Uniform::model_view_inverse_transpose, matModelViewInverseTranspose);
setPushConstant(PushConstant::model_view_inverse_transpose, matModelViewInverseTranspose);
}
}
if (hasUniform(Uniform::model_inverse_transpose)) {
if (hasPushConstant(PushConstant::model_inverse_transpose)) {
Matrix4 matModelInverseTranspose = matModel;
matModelInverseTranspose.transpose();
matModelInverseTranspose.invert();
setUniform(Uniform::model_inverse_transpose, matModelInverseTranspose);
setPushConstant(PushConstant::model_inverse_transpose, matModelInverseTranspose);
}
if (hasUniform(KRPipeline::Uniform::invp)) {
setUniform(Uniform::invp, viewport.getInverseProjectionMatrix());
if (hasPushConstant(KRPipeline::PushConstant::invp)) {
setPushConstant(PushConstant::invp, viewport.getInverseProjectionMatrix());
}
if (hasUniform(KRPipeline::Uniform::invmvp_no_translate)) {
if (hasPushConstant(KRPipeline::PushConstant::invmvp_no_translate)) {
Matrix4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();;
// Remove the translation
matInvMVPNoTranslate.getPointer()[3] = 0;
@@ -755,16 +755,16 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
matInvMVPNoTranslate.getPointer()[15] = 1.0;
matInvMVPNoTranslate = matInvMVPNoTranslate * viewport.getProjectionMatrix();
matInvMVPNoTranslate.invert();
setUniform(Uniform::invmvp_no_translate, matInvMVPNoTranslate);
setPushConstant(PushConstant::invmvp_no_translate, matInvMVPNoTranslate);
}
setUniform(Uniform::model_matrix, matModel);
if (hasUniform(Uniform::projection_matrix)) {
setUniform(Uniform::projection_matrix, viewport.getProjectionMatrix());
setPushConstant(PushConstant::model_matrix, matModel);
if (hasPushConstant(PushConstant::projection_matrix)) {
setPushConstant(PushConstant::projection_matrix, viewport.getProjectionMatrix());
}
if (hasUniform(Uniform::viewport)) {
setUniform(Uniform::viewport, Vector4::Create(
if (hasPushConstant(PushConstant::viewport)) {
setPushConstant(PushConstant::viewport, Vector4::Create(
(float)0.0,
(float)0.0,
(float)viewport.getSize().x,
@@ -773,47 +773,47 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
);
}
if (hasUniform(Uniform::viewport_downsample)) {
setUniform(Uniform::viewport_downsample, camera.getDownsample());
if (hasPushConstant(PushConstant::viewport_downsample)) {
setPushConstant(PushConstant::viewport_downsample, camera.getDownsample());
}
// Fog parameters
setUniform(Uniform::fog_near, camera.settings.fog_near);
setUniform(Uniform::fog_far, camera.settings.fog_far);
setUniform(Uniform::fog_density, camera.settings.fog_density);
setUniform(Uniform::fog_color, camera.settings.fog_color);
setPushConstant(PushConstant::fog_near, camera.settings.fog_near);
setPushConstant(PushConstant::fog_far, camera.settings.fog_far);
setPushConstant(PushConstant::fog_density, camera.settings.fog_density);
setPushConstant(PushConstant::fog_color, camera.settings.fog_color);
if (hasUniform(Uniform::fog_scale)) {
setUniform(Uniform::fog_scale, 1.0f / (camera.settings.fog_far - camera.settings.fog_near));
if (hasPushConstant(PushConstant::fog_scale)) {
setPushConstant(PushConstant::fog_scale, 1.0f / (camera.settings.fog_far - camera.settings.fog_near));
}
if (hasUniform(Uniform::density_premultiplied_exponential)) {
setUniform(Uniform::density_premultiplied_exponential, -camera.settings.fog_density * 1.442695f); // -fog_density / log(2)
if (hasPushConstant(PushConstant::density_premultiplied_exponential)) {
setPushConstant(PushConstant::density_premultiplied_exponential, -camera.settings.fog_density * 1.442695f); // -fog_density / log(2)
}
if (hasUniform(Uniform::density_premultiplied_squared)) {
setUniform(Uniform::density_premultiplied_squared, (float)(-camera.settings.fog_density * camera.settings.fog_density * 1.442695)); // -fog_density * fog_density / log(2)
if (hasPushConstant(PushConstant::density_premultiplied_squared)) {
setPushConstant(PushConstant::density_premultiplied_squared, (float)(-camera.settings.fog_density * camera.settings.fog_density * 1.442695)); // -fog_density * fog_density / log(2)
}
// Sets the diffuseTexture variable to the first texture unit
setUniform(Uniform::diffusetexture, 0);
setPushConstant(PushConstant::diffusetexture, 0);
// Sets the specularTexture variable to the second texture unit
setUniform(Uniform::speculartexture, 1);
setPushConstant(PushConstant::speculartexture, 1);
// Sets the normalTexture variable to the third texture unit
setUniform(Uniform::normaltexture, 2);
setPushConstant(PushConstant::normaltexture, 2);
// Sets the shadowTexture variable to the fourth texture unit
setUniform(Uniform::shadowtexture1, 3);
setUniform(Uniform::shadowtexture2, 4);
setUniform(Uniform::shadowtexture3, 5);
setUniform(Uniform::reflectioncubetexture, 4);
setUniform(Uniform::lightmaptexture, 5);
setUniform(Uniform::gbuffer_frame, 6);
setUniform(Uniform::gbuffer_depth, 7); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass
setUniform(Uniform::reflectiontexture, 7); // Texture unit 7 is used for the reflection map textures in gBuffer pass #3 and when using forward rendering
setUniform(Uniform::depth_frame, 0);
setUniform(Uniform::render_frame, 1);
setUniform(Uniform::volumetric_environment_frame, 2);
setPushConstant(PushConstant::shadowtexture1, 3);
setPushConstant(PushConstant::shadowtexture2, 4);
setPushConstant(PushConstant::shadowtexture3, 5);
setPushConstant(PushConstant::reflectioncubetexture, 4);
setPushConstant(PushConstant::lightmaptexture, 5);
setPushConstant(PushConstant::gbuffer_frame, 6);
setPushConstant(PushConstant::gbuffer_depth, 7); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass
setPushConstant(PushConstant::reflectiontexture, 7); // Texture unit 7 is used for the reflection map textures in gBuffer pass #3 and when using forward rendering
setPushConstant(PushConstant::depth_frame, 0);
setPushConstant(PushConstant::render_frame, 1);
setPushConstant(PushConstant::volumetric_environment_frame, 2);
for (PushConstantStageInfo& pushConstants : m_pushConstants) {
if (pushConstants.buffer) {

View File

@@ -217,7 +217,7 @@ public:
bool bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const Matrix4& matModel, const std::vector<KRPointLight*>* point_lights, const std::vector<KRDirectionalLight*>* directional_lights, const std::vector<KRSpotLight*>* spot_lights, const KRNode::RenderPass& renderPass);
enum class Uniform : uint8_t
enum class PushConstant : uint8_t
{
material_ambient = 0,
material_diffuse,
@@ -287,10 +287,10 @@ public:
rim_color,
rim_power,
fade_color,
NUM_UNIFORMS
NUM_PUSH_CONSTANTS
};
static const size_t kUniformCount = static_cast<size_t>(Uniform::NUM_UNIFORMS);
static const size_t kPushConstantCount = static_cast<size_t>(PushConstant::NUM_PUSH_CONSTANTS);
enum class ShaderStages : uint8_t
{
@@ -303,24 +303,24 @@ public:
static const size_t kShaderStageCount = static_cast<size_t>(ShaderStages::shaderStageCount);
bool hasUniform(Uniform location) const;
void setUniform(Uniform location, float value);
void setUniform(Uniform location, int value);
void setUniform(Uniform location, const Vector2& value);
void setUniform(Uniform location, const Vector3& value);
void setUniform(Uniform location, const Vector4& value);
void setUniform(Uniform location, const Matrix4& value);
void setUniform(Uniform location, const Matrix4* value, const size_t count);
bool hasPushConstant(PushConstant location) const;
void setPushConstant(PushConstant location, float value);
void setPushConstant(PushConstant location, int value);
void setPushConstant(PushConstant location, const Vector2& value);
void setPushConstant(PushConstant location, const Vector3& value);
void setPushConstant(PushConstant location, const Vector4& value);
void setPushConstant(PushConstant location, const Matrix4& value);
void setPushConstant(PushConstant location, const Matrix4* value, const size_t count);
VkPipeline& getPipeline();
private:
static const char* KRENGINE_UNIFORM_NAMES[];
static const char* KRENGINE_PUSH_CONSTANT_NAMES[];
struct PushConstantStageInfo
{
int offset[kUniformCount];
__uint8_t size[kUniformCount];
int offset[kPushConstantCount];
__uint8_t size[kPushConstantCount];
uint8_t* buffer;
int bufferSize;
VkPipelineLayout layout;

View File

@@ -113,11 +113,11 @@ void KRPointLight::render(RenderInfo& ri)
info.modelFormat = bInsideLight ? ModelFormat::KRENGINE_MODEL_FORMAT_STRIP : ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setUniform(KRPipeline::Uniform::light_color, m_color);
pShader->setUniform(KRPipeline::Uniform::light_intensity, m_intensity * 0.01f);
pShader->setUniform(KRPipeline::Uniform::light_decay_start, getDecayStart());
pShader->setUniform(KRPipeline::Uniform::light_cutoff, KRLIGHT_MIN_INFLUENCE);
pShader->setUniform(KRPipeline::Uniform::light_position, light_position);
pShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color);
pShader->setPushConstant(KRPipeline::PushConstant::light_intensity, m_intensity * 0.01f);
pShader->setPushConstant(KRPipeline::PushConstant::light_decay_start, getDecayStart());
pShader->setPushConstant(KRPipeline::PushConstant::light_cutoff, KRLIGHT_MIN_INFLUENCE);
pShader->setPushConstant(KRPipeline::PushConstant::light_position, light_position);
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, sphereModelMatrix, &this_light, nullptr, nullptr, ri.renderPass);
if (bInsideLight) {

View File

@@ -162,7 +162,7 @@ void KRSprite::render(RenderInfo& ri)
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setUniform(KRPipeline::Uniform::material_alpha, m_spriteAlpha);
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_spriteAlpha);
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE);