WIP Refactoring to generalize shader value reflection
This commit is contained in:
@@ -90,4 +90,5 @@ add_source_and_header(KRPipeline)
|
|||||||
add_source_and_header(KRPipelineManager)
|
add_source_and_header(KRPipelineManager)
|
||||||
add_source_and_header(KRSampler)
|
add_source_and_header(KRSampler)
|
||||||
add_source_and_header(KRSamplerManager)
|
add_source_and_header(KRSamplerManager)
|
||||||
|
add_source_and_header(KRShaderReflection)
|
||||||
add_source_and_header(KRViewport)
|
add_source_and_header(KRViewport)
|
||||||
|
|||||||
@@ -40,77 +40,6 @@
|
|||||||
|
|
||||||
using namespace hydra;
|
using namespace hydra;
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
"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, KrDeviceHandle deviceHandle, const KRRenderPass* renderPass, Vector2i viewport_size, Vector2i scissor_size, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat)
|
KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, const KRRenderPass* renderPass, Vector2i viewport_size, Vector2i scissor_size, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat)
|
||||||
: KRContextObject(context)
|
: KRContextObject(context)
|
||||||
, m_deviceHandle(deviceHandle)
|
, m_deviceHandle(deviceHandle)
|
||||||
@@ -511,7 +440,7 @@ void KRPipeline::initPushConstantStage(ShaderStage stage, const SpvReflectShader
|
|||||||
for (int iUniform = 0; iUniform < kPushConstantCount; iUniform++) {
|
for (int iUniform = 0; iUniform < kPushConstantCount; iUniform++) {
|
||||||
for (int iMember = 0; iMember < block.member_count; iMember++) {
|
for (int iMember = 0; iMember < block.member_count; iMember++) {
|
||||||
const SpvReflectBlockVariable& member = block.members[iMember];
|
const SpvReflectBlockVariable& member = block.members[iMember];
|
||||||
if (stricmp(KRENGINE_PUSH_CONSTANT_NAMES[iUniform], member.name) == 0) {
|
if (stricmp(SHADER_VALUE_NAMES[iUniform], member.name) == 0) {
|
||||||
pushConstants.offset[iUniform] = member.offset;
|
pushConstants.offset[iUniform] = member.offset;
|
||||||
pushConstants.size[iUniform] = member.size;
|
pushConstants.size[iUniform] = member.size;
|
||||||
}
|
}
|
||||||
@@ -559,7 +488,7 @@ void KRPipeline::initDescriptorSetStage(ShaderStage stage, const SpvReflectShade
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRPipeline::hasPushConstant(PushConstant location) const
|
bool KRPipeline::hasPushConstant(ShaderValue location) const
|
||||||
{
|
{
|
||||||
for (const StageInfo& stageInfo : m_stages) {
|
for (const StageInfo& stageInfo : m_stages) {
|
||||||
const PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
const PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -570,7 +499,7 @@ bool KRPipeline::hasPushConstant(PushConstant location) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRPipeline::setPushConstant(PushConstant location, float value)
|
void KRPipeline::setPushConstant(ShaderValue location, float value)
|
||||||
{
|
{
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -582,7 +511,7 @@ void KRPipeline::setPushConstant(PushConstant location, float value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KRPipeline::setPushConstant(PushConstant location, int value)
|
void KRPipeline::setPushConstant(ShaderValue location, int value)
|
||||||
{
|
{
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -593,7 +522,7 @@ void KRPipeline::setPushConstant(PushConstant location, int value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRPipeline::setPushConstant(PushConstant location, const Vector2& value)
|
void KRPipeline::setPushConstant(ShaderValue location, const Vector2& value)
|
||||||
{
|
{
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -603,7 +532,7 @@ void KRPipeline::setPushConstant(PushConstant location, const Vector2& value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void KRPipeline::setPushConstant(PushConstant location, const Vector3& value)
|
void KRPipeline::setPushConstant(ShaderValue location, const Vector3& value)
|
||||||
{
|
{
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -614,7 +543,7 @@ void KRPipeline::setPushConstant(PushConstant location, const Vector3& value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRPipeline::setPushConstant(PushConstant location, const Vector4& value)
|
void KRPipeline::setPushConstant(ShaderValue location, const Vector4& value)
|
||||||
{
|
{
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -625,7 +554,7 @@ void KRPipeline::setPushConstant(PushConstant location, const Vector4& value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRPipeline::setPushConstant(PushConstant location, const Matrix4& value)
|
void KRPipeline::setPushConstant(ShaderValue location, const Matrix4& value)
|
||||||
{
|
{
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -636,7 +565,7 @@ void KRPipeline::setPushConstant(PushConstant location, const Matrix4& value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRPipeline::setPushConstant(PushConstant location, const Matrix4* value, const size_t count)
|
void KRPipeline::setPushConstant(ShaderValue location, const Matrix4* value, const size_t count)
|
||||||
{
|
{
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
@@ -653,7 +582,7 @@ void KRPipeline::updateDescriptorBinding()
|
|||||||
|
|
||||||
void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matModel)
|
void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matModel)
|
||||||
{
|
{
|
||||||
setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime());
|
setPushConstant(ShaderValue::absolute_time, getContext().getAbsoluteTime());
|
||||||
|
|
||||||
int light_directional_count = 0;
|
int light_directional_count = 0;
|
||||||
//int light_point_count = 0;
|
//int light_point_count = 0;
|
||||||
@@ -665,7 +594,7 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
KRDirectionalLight* directional_light = (*light_itr);
|
KRDirectionalLight* directional_light = (*light_itr);
|
||||||
if (light_directional_count == 0) {
|
if (light_directional_count == 0) {
|
||||||
int cShadowBuffers = directional_light->getShadowBufferCount();
|
int cShadowBuffers = directional_light->getShadowBufferCount();
|
||||||
if (hasPushConstant(PushConstant::shadowtexture1) && cShadowBuffers > 0) {
|
if (hasPushConstant(ShaderValue::shadowtexture1) && cShadowBuffers > 0) {
|
||||||
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering
|
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering
|
||||||
if (m_pContext->getTextureManager()->selectTexture(0 /*GL_TEXTURE_2D*/, 3, directional_light->getShadowTextures()[0])) {
|
if (m_pContext->getTextureManager()->selectTexture(0 /*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_MIN_FILTER, GL_LINEAR));
|
||||||
@@ -673,7 +602,7 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::shadowtexture2) && cShadowBuffers > 1 && ri.camera->settings.m_cShadowBuffers > 1) {
|
if (hasPushConstant(ShaderValue::shadowtexture2) && cShadowBuffers > 1 && ri.camera->settings.m_cShadowBuffers > 1) {
|
||||||
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering
|
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering
|
||||||
if (m_pContext->getTextureManager()->selectTexture(0 /*GL_TEXTURE_2D*/, 4, directional_light->getShadowTextures()[1])) {
|
if (m_pContext->getTextureManager()->selectTexture(0 /*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_MIN_FILTER, GL_LINEAR));
|
||||||
@@ -681,7 +610,7 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::shadowtexture3) && cShadowBuffers > 2 && ri.camera->settings.m_cShadowBuffers > 2) {
|
if (hasPushConstant(ShaderValue::shadowtexture3) && cShadowBuffers > 2 && ri.camera->settings.m_cShadowBuffers > 2) {
|
||||||
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering
|
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering
|
||||||
if (m_pContext->getTextureManager()->selectTexture(0 /*GL_TEXTURE_2D*/, 5, directional_light->getShadowTextures()[2])) {
|
if (m_pContext->getTextureManager()->selectTexture(0 /*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_MIN_FILTER, GL_LINEAR));
|
||||||
@@ -693,17 +622,17 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
matBias.translate(1.0, 1.0, 1.0);
|
matBias.translate(1.0, 1.0, 1.0);
|
||||||
matBias.scale(0.5);
|
matBias.scale(0.5);
|
||||||
for (int iShadow = 0; iShadow < cShadowBuffers; iShadow++) {
|
for (int iShadow = 0; iShadow < cShadowBuffers; iShadow++) {
|
||||||
setPushConstant(static_cast<PushConstant>(static_cast<int>(PushConstant::shadow_mvp1) + iShadow), matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias);
|
setPushConstant(static_cast<ShaderValue>(static_cast<int>(ShaderValue::shadow_mvp1) + iShadow), matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::light_direction_model_space)) {
|
if (hasPushConstant(ShaderValue::light_direction_model_space)) {
|
||||||
Matrix4 inverseModelMatrix = matModel;
|
Matrix4 inverseModelMatrix = matModel;
|
||||||
inverseModelMatrix.invert();
|
inverseModelMatrix.invert();
|
||||||
|
|
||||||
// Bind the light direction vector
|
// Bind the light direction vector
|
||||||
Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection());
|
Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection());
|
||||||
lightDirObject.normalize();
|
lightDirObject.normalize();
|
||||||
setPushConstant(PushConstant::light_direction_model_space, lightDirObject);
|
setPushConstant(ShaderValue::light_direction_model_space, lightDirObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,57 +643,57 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
//light_spot_count = spot_lights.size();
|
//light_spot_count = spot_lights.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::camerapos_model_space)) {
|
if (hasPushConstant(ShaderValue::camerapos_model_space)) {
|
||||||
Matrix4 inverseModelMatrix = matModel;
|
Matrix4 inverseModelMatrix = matModel;
|
||||||
inverseModelMatrix.invert();
|
inverseModelMatrix.invert();
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::camerapos_model_space)) {
|
if (hasPushConstant(ShaderValue::camerapos_model_space)) {
|
||||||
// Transform location of camera to object space for calculation of specular halfVec
|
// Transform location of camera to object space for calculation of specular halfVec
|
||||||
Vector3 cameraPosObject = Matrix4::Dot(inverseModelMatrix, ri.viewport->getCameraPosition());
|
Vector3 cameraPosObject = Matrix4::Dot(inverseModelMatrix, ri.viewport->getCameraPosition());
|
||||||
setPushConstant(PushConstant::camerapos_model_space, cameraPosObject);
|
setPushConstant(ShaderValue::camerapos_model_space, cameraPosObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::mvp) || hasPushConstant(KRPipeline::PushConstant::invmvp)) {
|
if (hasPushConstant(ShaderValue::mvp) || hasPushConstant(ShaderValue::invmvp)) {
|
||||||
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||||
Matrix4 mvpMatrix = matModel * ri.viewport->getViewProjectionMatrix();
|
Matrix4 mvpMatrix = matModel * ri.viewport->getViewProjectionMatrix();
|
||||||
setPushConstant(PushConstant::mvp, mvpMatrix);
|
setPushConstant(ShaderValue::mvp, mvpMatrix);
|
||||||
|
|
||||||
if (hasPushConstant(KRPipeline::PushConstant::invmvp)) {
|
if (hasPushConstant(ShaderValue::invmvp)) {
|
||||||
setPushConstant(KRPipeline::PushConstant::invmvp, Matrix4::Invert(mvpMatrix));
|
setPushConstant(ShaderValue::invmvp, Matrix4::Invert(mvpMatrix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(KRPipeline::PushConstant::view_space_model_origin) || hasPushConstant(PushConstant::model_view_inverse_transpose) || hasPushConstant(KRPipeline::PushConstant::model_view)) {
|
if (hasPushConstant(ShaderValue::view_space_model_origin) || hasPushConstant(ShaderValue::model_view_inverse_transpose) || hasPushConstant(ShaderValue::model_view)) {
|
||||||
Matrix4 matModelView = matModel * ri.viewport->getViewMatrix();
|
Matrix4 matModelView = matModel * ri.viewport->getViewMatrix();
|
||||||
setPushConstant(PushConstant::model_view, matModelView);
|
setPushConstant(ShaderValue::model_view, matModelView);
|
||||||
|
|
||||||
|
|
||||||
if (hasPushConstant(KRPipeline::PushConstant::view_space_model_origin)) {
|
if (hasPushConstant(ShaderValue::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
|
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
|
||||||
setPushConstant(PushConstant::view_space_model_origin, view_space_model_origin);
|
setPushConstant(ShaderValue::view_space_model_origin, view_space_model_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::model_view_inverse_transpose)) {
|
if (hasPushConstant(ShaderValue::model_view_inverse_transpose)) {
|
||||||
Matrix4 matModelViewInverseTranspose = matModelView;
|
Matrix4 matModelViewInverseTranspose = matModelView;
|
||||||
matModelViewInverseTranspose.transpose();
|
matModelViewInverseTranspose.transpose();
|
||||||
matModelViewInverseTranspose.invert();
|
matModelViewInverseTranspose.invert();
|
||||||
setPushConstant(PushConstant::model_view_inverse_transpose, matModelViewInverseTranspose);
|
setPushConstant(ShaderValue::model_view_inverse_transpose, matModelViewInverseTranspose);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::model_inverse_transpose)) {
|
if (hasPushConstant(ShaderValue::model_inverse_transpose)) {
|
||||||
Matrix4 matModelInverseTranspose = matModel;
|
Matrix4 matModelInverseTranspose = matModel;
|
||||||
matModelInverseTranspose.transpose();
|
matModelInverseTranspose.transpose();
|
||||||
matModelInverseTranspose.invert();
|
matModelInverseTranspose.invert();
|
||||||
setPushConstant(PushConstant::model_inverse_transpose, matModelInverseTranspose);
|
setPushConstant(ShaderValue::model_inverse_transpose, matModelInverseTranspose);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(KRPipeline::PushConstant::invp)) {
|
if (hasPushConstant(ShaderValue::invp)) {
|
||||||
setPushConstant(PushConstant::invp, ri.viewport->getInverseProjectionMatrix());
|
setPushConstant(ShaderValue::invp, ri.viewport->getInverseProjectionMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(KRPipeline::PushConstant::invmvp_no_translate)) {
|
if (hasPushConstant(ShaderValue::invmvp_no_translate)) {
|
||||||
Matrix4 matInvMVPNoTranslate = matModel * ri.viewport->getViewMatrix();;
|
Matrix4 matInvMVPNoTranslate = matModel * ri.viewport->getViewMatrix();;
|
||||||
// Remove the translation
|
// Remove the translation
|
||||||
matInvMVPNoTranslate.getPointer()[3] = 0;
|
matInvMVPNoTranslate.getPointer()[3] = 0;
|
||||||
@@ -776,16 +705,16 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
matInvMVPNoTranslate.getPointer()[15] = 1.0;
|
matInvMVPNoTranslate.getPointer()[15] = 1.0;
|
||||||
matInvMVPNoTranslate = matInvMVPNoTranslate * ri.viewport->getProjectionMatrix();
|
matInvMVPNoTranslate = matInvMVPNoTranslate * ri.viewport->getProjectionMatrix();
|
||||||
matInvMVPNoTranslate.invert();
|
matInvMVPNoTranslate.invert();
|
||||||
setPushConstant(PushConstant::invmvp_no_translate, matInvMVPNoTranslate);
|
setPushConstant(ShaderValue::invmvp_no_translate, matInvMVPNoTranslate);
|
||||||
}
|
}
|
||||||
|
|
||||||
setPushConstant(PushConstant::model_matrix, matModel);
|
setPushConstant(ShaderValue::model_matrix, matModel);
|
||||||
if (hasPushConstant(PushConstant::projection_matrix)) {
|
if (hasPushConstant(ShaderValue::projection_matrix)) {
|
||||||
setPushConstant(PushConstant::projection_matrix, ri.viewport->getProjectionMatrix());
|
setPushConstant(ShaderValue::projection_matrix, ri.viewport->getProjectionMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::viewport)) {
|
if (hasPushConstant(ShaderValue::viewport)) {
|
||||||
setPushConstant(PushConstant::viewport, Vector4::Create(
|
setPushConstant(ShaderValue::viewport, Vector4::Create(
|
||||||
(float)0.0,
|
(float)0.0,
|
||||||
(float)0.0,
|
(float)0.0,
|
||||||
(float)ri.viewport->getSize().x,
|
(float)ri.viewport->getSize().x,
|
||||||
@@ -795,42 +724,42 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fog parameters
|
// Fog parameters
|
||||||
setPushConstant(PushConstant::fog_near, ri.camera->settings.fog_near);
|
setPushConstant(ShaderValue::fog_near, ri.camera->settings.fog_near);
|
||||||
setPushConstant(PushConstant::fog_far, ri.camera->settings.fog_far);
|
setPushConstant(ShaderValue::fog_far, ri.camera->settings.fog_far);
|
||||||
setPushConstant(PushConstant::fog_density, ri.camera->settings.fog_density);
|
setPushConstant(ShaderValue::fog_density, ri.camera->settings.fog_density);
|
||||||
setPushConstant(PushConstant::fog_color, ri.camera->settings.fog_color);
|
setPushConstant(ShaderValue::fog_color, ri.camera->settings.fog_color);
|
||||||
|
|
||||||
if (hasPushConstant(PushConstant::fog_scale)) {
|
if (hasPushConstant(ShaderValue::fog_scale)) {
|
||||||
setPushConstant(PushConstant::fog_scale, 1.0f / (ri.camera->settings.fog_far - ri.camera->settings.fog_near));
|
setPushConstant(ShaderValue::fog_scale, 1.0f / (ri.camera->settings.fog_far - ri.camera->settings.fog_near));
|
||||||
}
|
}
|
||||||
if (hasPushConstant(PushConstant::density_premultiplied_exponential)) {
|
if (hasPushConstant(ShaderValue::density_premultiplied_exponential)) {
|
||||||
setPushConstant(PushConstant::density_premultiplied_exponential, -ri.camera->settings.fog_density * 1.442695f); // -fog_density / log(2)
|
setPushConstant(ShaderValue::density_premultiplied_exponential, -ri.camera->settings.fog_density * 1.442695f); // -fog_density / log(2)
|
||||||
}
|
}
|
||||||
if (hasPushConstant(PushConstant::density_premultiplied_squared)) {
|
if (hasPushConstant(ShaderValue::density_premultiplied_squared)) {
|
||||||
setPushConstant(PushConstant::density_premultiplied_squared, (float)(-ri.camera->settings.fog_density * ri.camera->settings.fog_density * 1.442695)); // -fog_density * fog_density / log(2)
|
setPushConstant(ShaderValue::density_premultiplied_squared, (float)(-ri.camera->settings.fog_density * ri.camera->settings.fog_density * 1.442695)); // -fog_density * fog_density / log(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the diffuseTexture variable to the first texture unit
|
// Sets the diffuseTexture variable to the first texture unit
|
||||||
setPushConstant(PushConstant::diffusetexture, 0);
|
setPushConstant(ShaderValue::diffusetexture, 0);
|
||||||
|
|
||||||
// Sets the specularTexture variable to the second texture unit
|
// Sets the specularTexture variable to the second texture unit
|
||||||
setPushConstant(PushConstant::speculartexture, 1);
|
setPushConstant(ShaderValue::speculartexture, 1);
|
||||||
|
|
||||||
// Sets the normalTexture variable to the third texture unit
|
// Sets the normalTexture variable to the third texture unit
|
||||||
setPushConstant(PushConstant::normaltexture, 2);
|
setPushConstant(ShaderValue::normaltexture, 2);
|
||||||
|
|
||||||
// Sets the shadowTexture variable to the fourth texture unit
|
// Sets the shadowTexture variable to the fourth texture unit
|
||||||
setPushConstant(PushConstant::shadowtexture1, 3);
|
setPushConstant(ShaderValue::shadowtexture1, 3);
|
||||||
setPushConstant(PushConstant::shadowtexture2, 4);
|
setPushConstant(ShaderValue::shadowtexture2, 4);
|
||||||
setPushConstant(PushConstant::shadowtexture3, 5);
|
setPushConstant(ShaderValue::shadowtexture3, 5);
|
||||||
setPushConstant(PushConstant::reflectioncubetexture, 4);
|
setPushConstant(ShaderValue::reflectioncubetexture, 4);
|
||||||
setPushConstant(PushConstant::lightmaptexture, 5);
|
setPushConstant(ShaderValue::lightmaptexture, 5);
|
||||||
setPushConstant(PushConstant::gbuffer_frame, 6);
|
setPushConstant(ShaderValue::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(ShaderValue::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(ShaderValue::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(ShaderValue::depth_frame, 0);
|
||||||
setPushConstant(PushConstant::render_frame, 1);
|
setPushConstant(ShaderValue::render_frame, 1);
|
||||||
setPushConstant(PushConstant::volumetric_environment_frame, 2);
|
setPushConstant(ShaderValue::volumetric_environment_frame, 2);
|
||||||
|
|
||||||
for (StageInfo& stageInfo : m_stages) {
|
for (StageInfo& stageInfo : m_stages) {
|
||||||
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
PushConstantInfo& pushConstants = stageInfo.pushConstants;
|
||||||
|
|||||||
@@ -220,88 +220,16 @@ public:
|
|||||||
|
|
||||||
bool bind(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel);
|
bool bind(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel);
|
||||||
|
|
||||||
enum class PushConstant : uint8_t
|
static const size_t kPushConstantCount = static_cast<size_t>(ShaderValue::NUM_PUSH_CONSTANTS);
|
||||||
{
|
|
||||||
material_ambient = 0,
|
|
||||||
material_diffuse,
|
|
||||||
material_specular,
|
|
||||||
material_reflection,
|
|
||||||
material_alpha,
|
|
||||||
material_shininess,
|
|
||||||
light_position,
|
|
||||||
light_direction_model_space,
|
|
||||||
light_direction_view_space,
|
|
||||||
light_color,
|
|
||||||
light_decay_start,
|
|
||||||
light_cutoff,
|
|
||||||
light_intensity,
|
|
||||||
flare_size,
|
|
||||||
view_space_model_origin,
|
|
||||||
mvp,
|
|
||||||
invp,
|
|
||||||
invmvp,
|
|
||||||
invmvp_no_translate,
|
|
||||||
model_view_inverse_transpose,
|
|
||||||
model_inverse_transpose,
|
|
||||||
model_view,
|
|
||||||
model_matrix,
|
|
||||||
projection_matrix,
|
|
||||||
camerapos_model_space,
|
|
||||||
viewport,
|
|
||||||
diffusetexture,
|
|
||||||
speculartexture,
|
|
||||||
reflectioncubetexture,
|
|
||||||
reflectiontexture,
|
|
||||||
normaltexture,
|
|
||||||
diffusetexture_scale,
|
|
||||||
speculartexture_scale,
|
|
||||||
reflectiontexture_scale,
|
|
||||||
normaltexture_scale,
|
|
||||||
ambienttexture_scale,
|
|
||||||
diffusetexture_offset,
|
|
||||||
speculartexture_offset,
|
|
||||||
reflectiontexture_offset,
|
|
||||||
normaltexture_offset,
|
|
||||||
ambienttexture_offset,
|
|
||||||
shadow_mvp1,
|
|
||||||
shadow_mvp2,
|
|
||||||
shadow_mvp3,
|
|
||||||
shadowtexture1,
|
|
||||||
shadowtexture2,
|
|
||||||
shadowtexture3,
|
|
||||||
lightmaptexture,
|
|
||||||
gbuffer_frame,
|
|
||||||
gbuffer_depth,
|
|
||||||
depth_frame,
|
|
||||||
volumetric_environment_frame,
|
|
||||||
render_frame,
|
|
||||||
absolute_time,
|
|
||||||
fog_near,
|
|
||||||
fog_far,
|
|
||||||
fog_density,
|
|
||||||
fog_color,
|
|
||||||
fog_scale,
|
|
||||||
density_premultiplied_exponential,
|
|
||||||
density_premultiplied_squared,
|
|
||||||
slice_depth_scale,
|
|
||||||
particle_origin,
|
|
||||||
bone_transforms,
|
|
||||||
rim_color,
|
|
||||||
rim_power,
|
|
||||||
fade_color,
|
|
||||||
NUM_PUSH_CONSTANTS
|
|
||||||
};
|
|
||||||
|
|
||||||
static const size_t kPushConstantCount = static_cast<size_t>(PushConstant::NUM_PUSH_CONSTANTS);
|
bool hasPushConstant(ShaderValue location) const;
|
||||||
|
void setPushConstant(ShaderValue location, float value);
|
||||||
bool hasPushConstant(PushConstant location) const;
|
void setPushConstant(ShaderValue location, int value);
|
||||||
void setPushConstant(PushConstant location, float value);
|
void setPushConstant(ShaderValue location, const hydra::Vector2& value);
|
||||||
void setPushConstant(PushConstant location, int value);
|
void setPushConstant(ShaderValue location, const hydra::Vector3& value);
|
||||||
void setPushConstant(PushConstant location, const hydra::Vector2& value);
|
void setPushConstant(ShaderValue location, const hydra::Vector4& value);
|
||||||
void setPushConstant(PushConstant location, const hydra::Vector3& value);
|
void setPushConstant(ShaderValue location, const hydra::Matrix4& value);
|
||||||
void setPushConstant(PushConstant location, const hydra::Vector4& value);
|
void setPushConstant(ShaderValue location, const hydra::Matrix4* value, const size_t count);
|
||||||
void setPushConstant(PushConstant location, const hydra::Matrix4& value);
|
|
||||||
void setPushConstant(PushConstant location, const hydra::Matrix4* value, const size_t count);
|
|
||||||
|
|
||||||
void setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler);
|
void setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler);
|
||||||
|
|
||||||
@@ -312,7 +240,6 @@ private:
|
|||||||
void updateDescriptorBinding();
|
void updateDescriptorBinding();
|
||||||
void updateDescriptorSets();
|
void updateDescriptorSets();
|
||||||
void updatePushConstants(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel);
|
void updatePushConstants(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel);
|
||||||
static const char* KRENGINE_PUSH_CONSTANT_NAMES[];
|
|
||||||
|
|
||||||
struct PushConstantInfo
|
struct PushConstantInfo
|
||||||
{
|
{
|
||||||
|
|||||||
102
kraken/KRShaderReflection.cpp
Normal file
102
kraken/KRShaderReflection.cpp
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
//
|
||||||
|
// KRPipeline.cpp
|
||||||
|
// Kraken Engine
|
||||||
|
//
|
||||||
|
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
// provided with the distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||||
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// The views and conclusions contained in the software and documentation are those of the
|
||||||
|
// authors and should not be interpreted as representing official policies, either expressed
|
||||||
|
// or implied, of Kearwood Gilbert.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "KRShaderReflection.h"
|
||||||
|
|
||||||
|
const char* SHADER_VALUE_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
|
||||||
|
"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
|
||||||
|
};
|
||||||
115
kraken/KRShaderReflection.h
Normal file
115
kraken/KRShaderReflection.h
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
//
|
||||||
|
// KRShaderReflection.h
|
||||||
|
// Kraken Engine
|
||||||
|
//
|
||||||
|
// Copyright 2024 Kearwood Gilbert. All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
// provided with the distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||||
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// The views and conclusions contained in the software and documentation are those of the
|
||||||
|
// authors and should not be interpreted as representing official policies, either expressed
|
||||||
|
// or implied, of Kearwood Gilbert.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
enum class ShaderValue : uint8_t
|
||||||
|
{
|
||||||
|
material_ambient = 0,
|
||||||
|
material_diffuse,
|
||||||
|
material_specular,
|
||||||
|
material_reflection,
|
||||||
|
material_alpha,
|
||||||
|
material_shininess,
|
||||||
|
light_position,
|
||||||
|
light_direction_model_space,
|
||||||
|
light_direction_view_space,
|
||||||
|
light_color,
|
||||||
|
light_decay_start,
|
||||||
|
light_cutoff,
|
||||||
|
light_intensity,
|
||||||
|
flare_size,
|
||||||
|
view_space_model_origin,
|
||||||
|
mvp,
|
||||||
|
invp,
|
||||||
|
invmvp,
|
||||||
|
invmvp_no_translate,
|
||||||
|
model_view_inverse_transpose,
|
||||||
|
model_inverse_transpose,
|
||||||
|
model_view,
|
||||||
|
model_matrix,
|
||||||
|
projection_matrix,
|
||||||
|
camerapos_model_space,
|
||||||
|
viewport,
|
||||||
|
diffusetexture,
|
||||||
|
speculartexture,
|
||||||
|
reflectioncubetexture,
|
||||||
|
reflectiontexture,
|
||||||
|
normaltexture,
|
||||||
|
diffusetexture_scale,
|
||||||
|
speculartexture_scale,
|
||||||
|
reflectiontexture_scale,
|
||||||
|
normaltexture_scale,
|
||||||
|
ambienttexture_scale,
|
||||||
|
diffusetexture_offset,
|
||||||
|
speculartexture_offset,
|
||||||
|
reflectiontexture_offset,
|
||||||
|
normaltexture_offset,
|
||||||
|
ambienttexture_offset,
|
||||||
|
shadow_mvp1,
|
||||||
|
shadow_mvp2,
|
||||||
|
shadow_mvp3,
|
||||||
|
shadowtexture1,
|
||||||
|
shadowtexture2,
|
||||||
|
shadowtexture3,
|
||||||
|
lightmaptexture,
|
||||||
|
gbuffer_frame,
|
||||||
|
gbuffer_depth,
|
||||||
|
depth_frame,
|
||||||
|
volumetric_environment_frame,
|
||||||
|
render_frame,
|
||||||
|
absolute_time,
|
||||||
|
fog_near,
|
||||||
|
fog_far,
|
||||||
|
fog_density,
|
||||||
|
fog_color,
|
||||||
|
fog_scale,
|
||||||
|
density_premultiplied_exponential,
|
||||||
|
density_premultiplied_squared,
|
||||||
|
slice_depth_scale,
|
||||||
|
particle_origin,
|
||||||
|
bone_transforms,
|
||||||
|
rim_color,
|
||||||
|
rim_power,
|
||||||
|
fade_color,
|
||||||
|
NUM_PUSH_CONSTANTS
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* SHADER_VALUE_NAMES[];
|
||||||
|
|
||||||
|
class KRReflectedObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static std::map<ShaderValue, std::pair<size_t, size_t>> ValueMap;
|
||||||
|
};
|
||||||
@@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
#include "aabb.h"
|
#include "aabb.h"
|
||||||
|
|
||||||
|
#include "KRShaderReflection.h"
|
||||||
|
|
||||||
class KRLight;
|
class KRLight;
|
||||||
|
|
||||||
class KRViewport
|
class KRViewport
|
||||||
|
|||||||
@@ -160,9 +160,9 @@ void KRDirectionalLight::render(RenderInfo& ri)
|
|||||||
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
|
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
|
||||||
|
|
||||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_direction_view_space, light_direction_view_space);
|
pShader->setPushConstant(ShaderValue::light_direction_view_space, light_direction_view_space);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color);
|
pShader->setPushConstant(ShaderValue::light_color, m_color);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_intensity, m_intensity * 0.01f);
|
pShader->setPushConstant(ShaderValue::light_intensity, m_intensity * 0.01f);
|
||||||
pShader->bind(ri, getModelMatrix()); // TODO: Need to pass in the light index to the shader
|
pShader->bind(ri, getModelMatrix()); // TODO: Need to pass in the light index to the shader
|
||||||
|
|
||||||
// Render a full screen quad
|
// Render a full screen quad
|
||||||
|
|||||||
@@ -284,9 +284,9 @@ void KRLight::render(RenderInfo& ri)
|
|||||||
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
||||||
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
|
|
||||||
pParticleShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
|
pParticleShader->setPushConstant(ShaderValue::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(ShaderValue::particle_origin, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
|
||||||
pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_dust_particle_size);
|
pParticleShader->setPushConstant(ShaderValue::flare_size, m_dust_particle_size);
|
||||||
pParticleShader->bind(ri, particleModelMatrix); // TODO: Pass light index to shader
|
pParticleShader->bind(ri, particleModelMatrix); // TODO: Pass light index to shader
|
||||||
|
|
||||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);
|
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);
|
||||||
@@ -336,8 +336,8 @@ void KRLight::render(RenderInfo& ri)
|
|||||||
float slice_far = -ri.camera->settings.volumetric_environment_max_distance;
|
float slice_far = -ri.camera->settings.volumetric_environment_max_distance;
|
||||||
float slice_spacing = (slice_far - slice_near) / slice_count;
|
float slice_spacing = (slice_far - slice_near) / slice_count;
|
||||||
|
|
||||||
pFogShader->setPushConstant(KRPipeline::PushConstant::slice_depth_scale, Vector2::Create(slice_near, slice_spacing));
|
pFogShader->setPushConstant(ShaderValue::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->setPushConstant(ShaderValue::light_color, (m_color * ri.camera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
|
||||||
pFogShader->bind(ri, Matrix4()); // TODO: Pass indexes of lights to shader
|
pFogShader->bind(ri, Matrix4()); // TODO: Pass indexes of lights to shader
|
||||||
|
|
||||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_VOLUMETRIC_LIGHTING, 1.0f);
|
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_VOLUMETRIC_LIGHTING, 1.0f);
|
||||||
@@ -426,8 +426,8 @@ void KRLight::render(RenderInfo& ri)
|
|||||||
|
|
||||||
|
|
||||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, 1.0f);
|
pShader->setPushConstant(ShaderValue::material_alpha, 1.0f);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_flareSize);
|
pShader->setPushConstant(ShaderValue::flare_size, m_flareSize);
|
||||||
pShader->setImageBinding("diffuseTexture", m_pFlareTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
pShader->setImageBinding("diffuseTexture", m_pFlareTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
pShader->bind(ri, getModelMatrix());
|
pShader->bind(ri, getModelMatrix());
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri)
|
|||||||
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
||||||
|
|
||||||
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, 1.0f);
|
pParticleShader->setPushConstant(ShaderValue::flare_size, 1.0f);
|
||||||
pParticleShader->bind(ri, getModelMatrix());
|
pParticleShader->bind(ri, getModelMatrix());
|
||||||
|
|
||||||
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);
|
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);
|
||||||
|
|||||||
@@ -116,11 +116,11 @@ void KRPointLight::render(RenderInfo& ri)
|
|||||||
info.modelFormat = bInsideLight ? ModelFormat::KRENGINE_MODEL_FORMAT_STRIP : ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
info.modelFormat = bInsideLight ? ModelFormat::KRENGINE_MODEL_FORMAT_STRIP : ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
|
||||||
|
|
||||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color);
|
pShader->setPushConstant(ShaderValue::light_color, m_color);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_intensity, m_intensity * 0.01f);
|
pShader->setPushConstant(ShaderValue::light_intensity, m_intensity * 0.01f);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_decay_start, getDecayStart());
|
pShader->setPushConstant(ShaderValue::light_decay_start, getDecayStart());
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_cutoff, KRLIGHT_MIN_INFLUENCE);
|
pShader->setPushConstant(ShaderValue::light_cutoff, KRLIGHT_MIN_INFLUENCE);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::light_position, light_position);
|
pShader->setPushConstant(ShaderValue::light_position, light_position);
|
||||||
pShader->bind(ri, sphereModelMatrix); // TODO: Pass light index to shader
|
pShader->bind(ri, sphereModelMatrix); // TODO: Pass light index to shader
|
||||||
|
|
||||||
if (bInsideLight) {
|
if (bInsideLight) {
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ void KRSprite::render(RenderInfo& ri)
|
|||||||
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
|
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
|
||||||
|
|
||||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_spriteAlpha);
|
pShader->setPushConstant(ShaderValue::material_alpha, m_spriteAlpha);
|
||||||
pShader->setImageBinding("diffuseTexture", m_pSpriteTexture, m_pContext->getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
pShader->setImageBinding("diffuseTexture", m_pSpriteTexture, m_pContext->getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
pShader->bind(ri, getModelMatrix());
|
pShader->bind(ri, getModelMatrix());
|
||||||
|
|
||||||
|
|||||||
@@ -376,11 +376,11 @@ void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_
|
|||||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
|
|
||||||
// Rim highlighting parameters
|
// Rim highlighting parameters
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::rim_color, rim_color);
|
pShader->setPushConstant(ShaderValue::rim_color, rim_color);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::rim_power, rim_power);
|
pShader->setPushConstant(ShaderValue::rim_power, rim_power);
|
||||||
|
|
||||||
// Bind bones
|
// Bind bones
|
||||||
if (pShader->hasPushConstant(KRPipeline::PushConstant::bone_transforms)) {
|
if (pShader->hasPushConstant(ShaderValue::bone_transforms)) {
|
||||||
float bone_mats[256 * 16];
|
float bone_mats[256 * 16];
|
||||||
float* bone_mat_component = bone_mats;
|
float* bone_mat_component = bone_mats;
|
||||||
for (int bone_index = 0; bone_index < bones.size(); bone_index++) {
|
for (int bone_index = 0; bone_index < bones.size(); bone_index++) {
|
||||||
@@ -407,40 +407,40 @@ void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_
|
|||||||
*bone_mat_component++ = t[i];
|
*bone_mat_component++ = t[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pShader->hasPushConstant(KRPipeline::PushConstant::bone_transforms)) {
|
if (pShader->hasPushConstant(ShaderValue::bone_transforms)) {
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::bone_transforms, (Matrix4*)bone_mats, bones.size());
|
pShader->setPushConstant(ShaderValue::bone_transforms, (Matrix4*)bone_mats, bones.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_ambient, m_ambientColor + ri.camera->settings.ambient_intensity);
|
pShader->setPushConstant(ShaderValue::material_ambient, m_ambientColor + ri.camera->settings.ambient_intensity);
|
||||||
|
|
||||||
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
|
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
|
||||||
// We pre-multiply the light color with the material color in the forward renderer
|
// We pre-multiply the light color with the material color in the forward renderer
|
||||||
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));
|
pShader->setPushConstant(ShaderValue::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 {
|
} else {
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_diffuse, m_diffuseColor);
|
pShader->setPushConstant(ShaderValue::material_diffuse, m_diffuseColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
|
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
|
||||||
// We pre-multiply the light color with the material color in the forward renderer
|
// We pre-multiply the light color with the material color in the forward renderer
|
||||||
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));
|
pShader->setPushConstant(ShaderValue::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 {
|
} else {
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_specular, m_specularColor);
|
pShader->setPushConstant(ShaderValue::material_specular, m_specularColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_shininess, m_ns);
|
pShader->setPushConstant(ShaderValue::material_shininess, m_ns);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_reflection, m_reflectionColor);
|
pShader->setPushConstant(ShaderValue::material_reflection, m_reflectionColor);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::diffusetexture_scale, m_diffuseMapScale);
|
pShader->setPushConstant(ShaderValue::diffusetexture_scale, m_diffuseMapScale);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::speculartexture_scale, m_specularMapScale);
|
pShader->setPushConstant(ShaderValue::speculartexture_scale, m_specularMapScale);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::reflectiontexture_scale, m_reflectionMapScale);
|
pShader->setPushConstant(ShaderValue::reflectiontexture_scale, m_reflectionMapScale);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::normaltexture_scale, m_normalMapScale);
|
pShader->setPushConstant(ShaderValue::normaltexture_scale, m_normalMapScale);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::diffusetexture_offset, m_diffuseMapOffset);
|
pShader->setPushConstant(ShaderValue::diffusetexture_offset, m_diffuseMapOffset);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::speculartexture_offset, m_specularMapOffset);
|
pShader->setPushConstant(ShaderValue::speculartexture_offset, m_specularMapOffset);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::reflectiontexture_offset, m_reflectionMapOffset);
|
pShader->setPushConstant(ShaderValue::reflectiontexture_offset, m_reflectionMapOffset);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::normaltexture_offset, m_normalMapOffset);
|
pShader->setPushConstant(ShaderValue::normaltexture_offset, m_normalMapOffset);
|
||||||
|
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_tr);
|
pShader->setPushConstant(ShaderValue::material_alpha, m_tr);
|
||||||
|
|
||||||
if (bDiffuseMap) {
|
if (bDiffuseMap) {
|
||||||
m_pDiffuseMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP);
|
m_pDiffuseMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP);
|
||||||
|
|||||||
Reference in New Issue
Block a user