Removed bRimColor from PipelineInfo

Rim highlighting parameters now accessed through KRMesh reflection
Removed ambient_intensity and light_intensity from KRRenderSettings.  To be replaced with proper tone mapping.
This commit is contained in:
2025-08-31 15:22:55 -07:00
parent f48d99d2c2
commit 453d8d8f68
11 changed files with 52 additions and 44 deletions

View File

@@ -202,7 +202,6 @@ public:
bool bNormalMapOffset : 1; bool bNormalMapOffset : 1;
bool bReflectionMapOffset : 1; bool bReflectionMapOffset : 1;
bool bAlphaTest : 1; bool bAlphaTest : 1;
bool bRimColor : 1;
RasterMode rasterMode; RasterMode rasterMode;
CullMode cullMode; CullMode cullMode;
uint32_t vertexAttributes; uint32_t vertexAttributes;
@@ -220,7 +219,7 @@ public:
bool bind(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel); bool bind(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel);
static const size_t kPushConstantCount = static_cast<size_t>(ShaderValue::NUM_PUSH_CONSTANTS); static const size_t kPushConstantCount = static_cast<size_t>(ShaderValue::NUM_SHADER_VALUES);
void setPushConstants(const std::vector<const KRReflectedObject*> objects); void setPushConstants(const std::vector<const KRReflectedObject*> objects);
bool hasPushConstant(ShaderValue location) const; bool hasPushConstant(ShaderValue location) const;

View File

@@ -171,7 +171,6 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
key.second.push_back((int)(info.pCamera->settings.flash_intensity * 1000.0f)); key.second.push_back((int)(info.pCamera->settings.flash_intensity * 1000.0f));
key.second.push_back((int)(info.pCamera->settings.vignette_radius * 1000.0f)); key.second.push_back((int)(info.pCamera->settings.vignette_radius * 1000.0f));
key.second.push_back((int)(info.pCamera->settings.vignette_falloff * 1000.0f)); key.second.push_back((int)(info.pCamera->settings.vignette_falloff * 1000.0f));
key.second.push_back(info.bRimColor);
key.second.push_back(bFadeColorEnabled); key.second.push_back(bFadeColorEnabled);
KRPipeline *pPipeline = m_pipelines[key]; KRPipeline *pPipeline = m_pipelines[key];
@@ -233,7 +232,6 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
stream << "\n#define ENABLE_AMBIENT " << (info.pCamera->settings.bEnableAmbient ? "1" : "0"); stream << "\n#define ENABLE_AMBIENT " << (info.pCamera->settings.bEnableAmbient ? "1" : "0");
stream << "\n#define ENABLE_DIFFUSE " << (info.pCamera->settings.bEnableDiffuse ? "1" : "0"); stream << "\n#define ENABLE_DIFFUSE " << (info.pCamera->settings.bEnableDiffuse ? "1" : "0");
stream << "\n#define ENABLE_SPECULAR " << (info.pCamera->settings.bEnableSpecular ? "1" : "0"); stream << "\n#define ENABLE_SPECULAR " << (info.pCamera->settings.bEnableSpecular ? "1" : "0");
stream << "\n#define ENABLE_RIM_COLOR " << (info.bRimColor ? "1" : "0");
stream << "\n#define ENABLE_FADE_COLOR " << (bFadeColorEnabled ? "1" : "0"); stream << "\n#define ENABLE_FADE_COLOR " << (bFadeColorEnabled ? "1" : "0");
stream << "\n#define FOG_TYPE " << info.pCamera->settings.fog_type; stream << "\n#define FOG_TYPE " << info.pCamera->settings.fog_type;
switch(info.renderPass) { switch(info.renderPass) {

View File

@@ -58,9 +58,6 @@ KRRenderSettings::KRRenderSettings()
bEnableDeferredLighting = false; bEnableDeferredLighting = false;
max_anisotropy = 4.0f; max_anisotropy = 4.0f;
ambient_intensity = Vector3::Zero();
light_intensity = Vector3::One();
perspective_fov = 45.0f * D2R; perspective_fov = 45.0f * D2R;
perspective_nearz = 0.3f; // was 0.05f perspective_nearz = 0.3f; // was 0.05f
perspective_farz = 1000.0f; perspective_farz = 1000.0f;
@@ -130,8 +127,6 @@ KRRenderSettings& KRRenderSettings::operator=(const KRRenderSettings& s)
bEnableDiffuse = s.bEnableDiffuse; bEnableDiffuse = s.bEnableDiffuse;
bEnableSpecular = s.bEnableSpecular; bEnableSpecular = s.bEnableSpecular;
bEnableDeferredLighting = s.bEnableDeferredLighting; bEnableDeferredLighting = s.bEnableDeferredLighting;
light_intensity = s.light_intensity;
ambient_intensity = s.ambient_intensity;
perspective_fov = s.perspective_fov; perspective_fov = s.perspective_fov;
dof_quality = s.dof_quality; dof_quality = s.dof_quality;

View File

@@ -71,8 +71,6 @@ public:
bool bEnableDiffuse; bool bEnableDiffuse;
bool bEnableSpecular; bool bEnableSpecular;
bool bEnableDeferredLighting; bool bEnableDeferredLighting;
hydra::Vector3 light_intensity;
hydra::Vector3 ambient_intensity;
float perspective_fov; float perspective_fov;
int dof_quality; int dof_quality;

View File

@@ -120,7 +120,7 @@ enum class ShaderValue : uint8_t
rim_color, rim_color,
rim_power, rim_power,
fade_color, fade_color,
NUM_PUSH_CONSTANTS NUM_SHADER_VALUES
}; };
const char* SHADER_VALUE_NAMES[]; const char* SHADER_VALUE_NAMES[];
@@ -129,7 +129,7 @@ class KRReflectedObject
{ {
public: public:
bool getShaderValue(ShaderValue value, ShaderValueType type, void* output) const; bool getShaderValue(ShaderValue value, ShaderValueType type, void* output) const;
private: protected:
virtual bool getShaderValue(ShaderValue value, int32_t* output) const; virtual bool getShaderValue(ShaderValue value, int32_t* output) const;
virtual bool getShaderValue(ShaderValue value, int64_t* output) const; virtual bool getShaderValue(ShaderValue value, int64_t* output) const;
virtual bool getShaderValue(ShaderValue value, float* output) const; virtual bool getShaderValue(ShaderValue value, float* output) const;

View File

@@ -241,6 +241,8 @@ void KRModel::loadModel()
void KRModel::render(KRNode::RenderInfo& ri) void KRModel::render(KRNode::RenderInfo& ri)
{ {
ri.reflectedObjects.push_back(this);
if (m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass->getType() == RenderPassType::RENDER_PASS_PRESTREAM) { if (m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass->getType() == RenderPassType::RENDER_PASS_PRESTREAM) {
preStream(*ri.viewport); preStream(*ri.viewport);
} }
@@ -303,10 +305,12 @@ void KRModel::render(KRNode::RenderInfo& ri)
matModel = Quaternion::Create(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; matModel = Quaternion::Create(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel;
} }
pModel->render(ri, getName(), matModel, m_pLightMap, m_bones[pModel], m_rim_color, m_rim_power, lod_coverage); pModel->render(ri, getName(), matModel, m_pLightMap, m_bones[pModel], lod_coverage);
} }
} }
} }
ri.reflectedObjects.pop_back();
} }
void KRModel::preStream(const KRViewport& viewport) void KRModel::preStream(const KRViewport& viewport)
@@ -362,3 +366,25 @@ AABB KRModel::getBounds()
} }
} }
bool KRModel::getShaderValue(ShaderValue value, hydra::Vector3* output) const
{
switch (value) {
case ShaderValue::rim_color:
*output = m_rim_color;
return true;
}
return KRNode::getShaderValue(value, output);
}
bool KRModel::getShaderValue(ShaderValue value, float* output) const
{
switch (value) {
case ShaderValue::rim_power:
*output = m_rim_power;
return true;
}
return KRNode::getShaderValue(value, output);
}

View File

@@ -95,4 +95,8 @@ private:
hydra::Vector3 m_rim_color; hydra::Vector3 m_rim_color;
float m_rim_power; float m_rim_power;
private:
bool getShaderValue(ShaderValue value, hydra::Vector3* output) const override;
bool getShaderValue(ShaderValue value, float* output) const override;
}; };

View File

@@ -325,7 +325,7 @@ void KRMaterial::getTextures()
} }
} }
void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, const Vector3& rim_color, float rim_power, float lod_coverage) void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, float lod_coverage)
{ {
bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap; bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap;
@@ -368,17 +368,12 @@ void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_
info.bReflectionMapOffset = m_reflectionMapOffset != default_offset && bReflectionMap; info.bReflectionMapOffset = m_reflectionMapOffset != default_offset && bReflectionMap;
info.bAlphaTest = bAlphaTest; info.bAlphaTest = bAlphaTest;
info.rasterMode = bAlphaBlend ? RasterMode::kAlphaBlend : RasterMode::kOpaque; info.rasterMode = bAlphaBlend ? RasterMode::kAlphaBlend : RasterMode::kOpaque;
info.bRimColor = rim_power != 0.0f;
info.renderPass = ri.renderPass; info.renderPass = ri.renderPass;
info.modelFormat = modelFormat; info.modelFormat = modelFormat;
info.vertexAttributes = vertexAttributes; info.vertexAttributes = vertexAttributes;
info.cullMode = cullMode; info.cullMode = cullMode;
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
// Rim highlighting parameters
pShader->setPushConstant(ShaderValue::rim_color, rim_color);
pShader->setPushConstant(ShaderValue::rim_power, rim_power);
// Bind bones // Bind bones
if (pShader->hasPushConstant(ShaderValue::bone_transforms)) { if (pShader->hasPushConstant(ShaderValue::bone_transforms)) {
float bone_mats[256 * 16]; float bone_mats[256 * 16];
@@ -412,22 +407,6 @@ void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_
} }
} }
pShader->setPushConstant(ShaderValue::material_ambient, m_ambientColor + ri.camera->settings.ambient_intensity);
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
// We pre-multiply the light color with the material color in the forward renderer
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 {
pShader->setPushConstant(ShaderValue::material_diffuse, m_diffuseColor);
}
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
// We pre-multiply the light color with the material color in the forward renderer
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 {
pShader->setPushConstant(ShaderValue::material_specular, m_specularColor);
}
if (bDiffuseMap) { if (bDiffuseMap) {
m_pDiffuseMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP); m_pDiffuseMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP);
pShader->setImageBinding("diffuseTexture", m_pDiffuseMap, getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER); pShader->setImageBinding("diffuseTexture", m_pDiffuseMap, getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
@@ -514,6 +493,15 @@ bool KRMaterial::getShaderValue(ShaderValue value, hydra::Vector3* output) const
case ShaderValue::material_reflection: case ShaderValue::material_reflection:
*output = m_reflectionColor; *output = m_reflectionColor;
return true; return true;
case ShaderValue::material_ambient:
*output = m_ambientColor;
return true;
case ShaderValue::material_diffuse:
*output = m_diffuseColor;
return true;
case ShaderValue::material_specular:
*output = m_specularColor;
return true;
} }
return false; return false;
} }

View File

@@ -90,7 +90,7 @@ public:
bool isTransparent(); bool isTransparent();
const std::string& getName() const; const std::string& getName() const;
void bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<hydra::Matrix4>& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f); void bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<hydra::Matrix4>& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, float lod_coverage = 0.0f);
bool needsVertexTangents(); bool needsVertexTangents();

View File

@@ -255,7 +255,7 @@ kraken_stream_level KRMesh::getStreamLevel()
} }
void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, const Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& bones, const Vector3& rim_color, float rim_power, float lod_coverage) void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, const Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& bones, float lod_coverage)
{ {
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); //fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES && ri.renderPass->getType() != RenderPassType::RENDER_PASS_PARTICLE_OCCLUSION && ri.renderPass->getType() != RenderPassType::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES && ri.renderPass->getType() != RenderPassType::RENDER_PASS_PARTICLE_OCCLUSION && ri.renderPass->getType() != RenderPassType::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
@@ -298,20 +298,20 @@ void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, cons
switch (pMaterial->getAlphaMode()) { switch (pMaterial->getAlphaMode()) {
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5 case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage); pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage); renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break; break;
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage); pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage); renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break; break;
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces. case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
// Render back faces first // Render back faces first
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullFront, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage); pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullFront, bones, bone_bind_poses, matModel, pLightMap, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage); renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
// Render front faces second // Render front faces second
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, rim_color, rim_power, lod_coverage); pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage);
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage); renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
break; break;
} }

View File

@@ -119,7 +119,7 @@ public:
std::vector<std::vector<float> > bone_weights; std::vector<std::vector<float> > bone_weights;
} mesh_info; } mesh_info;
void render(KRNode::RenderInfo& ri, const std::string& object_name, const hydra::Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& bones, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f); void render(KRNode::RenderInfo& ri, const std::string& object_name, const hydra::Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& bones, float lod_coverage = 0.0f);
std::string m_lodBaseName; std::string m_lodBaseName;