Populated shader reflection enum with updated material attributes

This commit is contained in:
2026-05-05 23:45:14 -07:00
parent 072b69583d
commit 04684afc42
6 changed files with 136 additions and 51 deletions

View File

@@ -712,7 +712,7 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
setPushConstant(ShaderValue::speculartexture, 1);
// Sets the normalTexture variable to the third texture unit
setPushConstant(ShaderValue::normaltexture, 2);
setPushConstant(ShaderValue::material_normaltexture, 2);
// Sets the shadowTexture variable to the fourth texture unit
setPushConstant(ShaderValue::shadowtexture1, 3);

View File

@@ -53,10 +53,125 @@ enum class ShaderValueType : uint8_t
enum class ShaderValue : uint8_t
{
material_diffuse = 0,
material_baseColor_map_texture = 0,
material_baseColor_map_texCoord,
material_baseColor_map_scale,
material_baseColor_map_offset,
material_baseColor_map_rotation,
material_baseColor_factor,
material_normal_map_texture,
material_normal_map_texCoord,
material_normal_map_scale,
material_normal_map_offset,
material_normal_map_rotation,
material_normal_scale,
material_emissive_map_texture,
material_emissive_map_texCoord,
material_emissive_map_scale,
material_emissive_map_offset,
material_emissive_map_rotation,
material_emissive_factor,
material_occlusion_map_texture,
material_occlusion_map_texCoord,
material_occlusion_map_scale,
material_occlusion_map_offset,
material_occlusion_map_rotation,
material_occlusion_strength,
material_metalicRoughness_map_texture,
material_metalicRoughness_map_texCoord,
material_metalicRoughness_map_scale,
material_metalicRoughness_map_offset,
material_metalicRoughness_map_rotation,
material_metalic_factor,
material_roughness_factor,
material_alphaMode,
material_alphaCutoff,
material_doubleSided,
material_ior,
material_shadingModel,
material_anisotropy_map_texture,
material_anisotropy_map_texCoord,
material_anisotropy_map_scale,
material_anisotropy_map_offset,
material_anisotropy_map_rotation,
material_anisotropy_strength,
material_anisotropy_rotation,
material_clearcoat_map_texture,
material_clearcoat_map_texCoord,
material_clearcoat_map_scale,
material_clearcoat_map_offset,
material_clearcoat_map_rotation,
material_clearcoat_factor,
material_clearcoatRoughness_map_texture,
material_clearcoatRoughness_map_texCoord,
material_clearcoatRoughness_map_scale,
material_clearcoatRoughness_map_offset,
material_clearcoatRoughness_map_rotation,
material_clearcoatRoughness_factor,
material_clearcoatNormal_map_texture,
material_clearcoatNormal_map_texCoord,
material_clearcoatNormal_map_scale,
material_clearcoatNormal_map_offset,
material_clearcoatNormal_map_rotation,
material_clearcoatNormal_scale,
material_dispersion,
material_specular_map_texture,
material_specular_map_texCoord,
material_specular_map_scale,
material_specular_map_offset,
material_specular_map_rotation,
material_specular_factor,
material_specularColor_map_texture,
material_specularColor_map_texCoord,
material_specularColor_map_scale,
material_specularColor_map_offset,
material_specularColor_map_rotation,
material_specularColor_factor,
material_thickness_map_texture,
material_thickness_map_texCoord,
material_thickness_map_scale,
material_thickness_map_offset,
material_thickness_map_rotation,
material_thickness_factor,
material_attenuationDistance,
material_attenuationColor,
material_transmission_map_texture,
material_transmission_map_texCoord,
material_transmission_map_scale,
material_transmission_map_offset,
material_transmission_map_rotation,
material_transmission_factor,
// Deprecated material attributes...
material_diffuse,
material_specular,
material_speculartexture_scale,
material_speculartexture_offset,
material_alpha,
material_shininess,
material_normaltexture,
material_normaltexture_scale,
material_normaltexture_offset,
material_diffusetexture_scale,
material_diffusetexture_offset,
material_ambienttexture_scale,
material_ambienttexture_offset,
light_position,
light_direction_model_space,
light_direction_view_space,
@@ -82,15 +197,6 @@ enum class ShaderValue : uint8_t
diffusetexture,
speculartexture,
reflectioncubetexture,
normaltexture,
diffusetexture_scale,
speculartexture_scale,
normaltexture_scale,
ambienttexture_scale,
diffusetexture_offset,
speculartexture_offset,
normaltexture_offset,
ambienttexture_offset,
shadow_mvp1,
shadow_mvp2,
shadow_mvp3,

View File

@@ -292,7 +292,7 @@ KRBundle* LoadGltf(KRContext& context, simdjson::ondemand::object& jsonRoot, std
tryJson(extensions_KHR_materials_specular["specularFactor"].get(new_material->m_specularFactor));
parseTextureInfo(extensions_KHR_materials_specular, "specularTexture", new_material->m_specularMap);
tryJson(extensions_KHR_materials_specular["specularColorFactor"].get(new_material->m_specularColorFactor));
parseTextureInfo(extensions_KHR_materials_specular, "specularColorTexture", new_material->m_specularColorTexture);
parseTextureInfo(extensions_KHR_materials_specular, "specularColorTexture", new_material->m_specularColorMap);
}
simdjson::ondemand::object extensions_KHR_materials_volume;

View File

@@ -252,7 +252,7 @@ KRMaterial::KRMaterial(KRContext& context, std::string name, mimir::Block* data)
}
tryJson(specularObj["factor"].get(m_specularFactor));
if (tryJson(specularObj["colorMap"].get(mapVal))) {
tryJson(m_specularColorTexture.parse(mapVal));
tryJson(m_specularColorMap.parse(mapVal));
}
tryJson(specularObj["colorFactor"].get(m_specularColorFactor));
}
@@ -432,7 +432,7 @@ bool KRMaterial::save(Block& data)
sb.append_comma();
sb.append_key_value<"factor">(m_specularFactor);
sb.append_comma();
sb.append_key_value<"colorMap">(m_specularColorTexture);
sb.append_key_value<"colorMap">(m_specularColorMap);
sb.append_comma();
sb.append_key_value<"colorFactor">(m_specularColorFactor);
sb.end_object();
@@ -531,27 +531,6 @@ KRMaterial::alpha_mode_type KRMaterial::getAlphaMode()
{
return m_alphaMode;
}
/*
void KRMaterial::setAmbient(const Vector3& c)
{
m_ambientColor = c;
}
void KRMaterial::setDiffuse(const Vector3& c)
{
m_diffuseColor = c;
}
void KRMaterial::setSpecular(const Vector3& c)
{
m_specularColor = c;
}
void KRMaterial::setReflection(const Vector3& c)
{
m_reflectionColor = c;
}
*/
void KRMaterial::setTransparency(float a)
{
@@ -585,7 +564,7 @@ void KRMaterial::getResourceBindings(std::list<KRResourceBinding*>& bindings)
bindings.push_back(&m_clearcoatRoughnessMap.texture);
bindings.push_back(&m_clearcoatNormalMap.texture);
bindings.push_back(&m_specularMap.texture);
bindings.push_back(&m_specularColorTexture.texture);
bindings.push_back(&m_specularColorMap.texture);
bindings.push_back(&m_thicknessMap.texture);
bindings.push_back(&m_transmissionMap.texture);
}
@@ -630,8 +609,8 @@ kraken_stream_level KRMaterial::getStreamLevel()
stream_level = KRMIN(stream_level, m_specularMap.texture.get()->getStreamLevel());
}
if (m_specularColorTexture.texture.isBound()) {
stream_level = KRMIN(stream_level, m_specularColorTexture.texture.get()->getStreamLevel());
if (m_specularColorMap.texture.isBound()) {
stream_level = KRMIN(stream_level, m_specularColorMap.texture.get()->getStreamLevel());
}
if (m_thicknessMap.texture.isBound()) {
@@ -726,7 +705,7 @@ void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_
}
if (bSpecMap) {
pShader->setImageBinding("specularTexture", m_specularColorTexture.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
pShader->setImageBinding("specularTexture", m_specularColorMap.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
}
if (bNormalMap) {
@@ -764,22 +743,22 @@ bool KRMaterial::getShaderValue(ShaderValue value, float* output) const
bool KRMaterial::getShaderValue(ShaderValue value, hydra::Vector2* output) const
{
switch (value) {
case ShaderValue::diffusetexture_scale:
case ShaderValue::material_diffusetexture_scale:
*output = m_baseColorMap.scale;
return true;
case ShaderValue::speculartexture_scale:
*output = m_specularColorTexture.scale;
case ShaderValue::material_speculartexture_scale:
*output = m_specularColorMap.scale;
return true;
case ShaderValue::normaltexture_scale:
case ShaderValue::material_normaltexture_scale:
*output = m_normalMap.scale;
return true;
case ShaderValue::diffusetexture_offset:
case ShaderValue::material_diffusetexture_offset:
*output = m_baseColorMap.offset;
return true;
case ShaderValue::speculartexture_offset:
*output = m_specularColorTexture.offset;
case ShaderValue::material_speculartexture_offset:
*output = m_specularColorMap.offset;
return true;
case ShaderValue::normaltexture_offset:
case ShaderValue::material_normaltexture_offset:
*output = m_normalMap.offset;
return true;
}

View File

@@ -143,7 +143,7 @@ public:
TextureMap m_specularMap{ KRTexture::TEXTURE_USAGE_MATERIAL_SPECULAR };
float m_specularFactor{ 1.f };
TextureMap m_specularColorTexture{ KRTexture::TEXTURE_USAGE_MATERIAL_SPECULAR_COLOR };
TextureMap m_specularColorMap{ KRTexture::TEXTURE_USAGE_MATERIAL_SPECULAR_COLOR };
hydra::Vector3 m_specularColorFactor{ 1.f, 1.f, 1.f };
TextureMap m_thicknessMap{ KRTexture::TEXTURE_USAGE_MATERIAL_THICKNESS };

View File

@@ -277,9 +277,9 @@ KRMaterial* KRMaterialManager::loadMtl(Block* data)
pMaterial->m_baseColorMap.scale = texture_scale;
pMaterial->m_baseColorMap.offset = texture_offset;
} else if (strcmp(szSymbol[0], "map_ks") == 0) {
pMaterial->m_specularColorTexture.texture.set(szSymbol[1]);
pMaterial->m_specularColorTexture.scale = texture_scale;
pMaterial->m_specularColorTexture.offset = texture_offset;
pMaterial->m_specularColorMap.texture.set(szSymbol[1]);
pMaterial->m_specularColorMap.scale = texture_scale;
pMaterial->m_specularColorMap.offset = texture_offset;
} else if (strcmp(szSymbol[0], "map_normal") == 0) {
pMaterial->m_normalMap.texture.set(szSymbol[1]);
pMaterial->m_normalMap.scale = texture_scale;