Skip to content
This repository was archived by the owner on Dec 24, 2023. It is now read-only.

Commit 1d04468

Browse files
committed
rad: Add reflectivity gamma correction
1 parent 670d915 commit 1d04468

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/rad/src/rad_sim_impl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,16 @@ void rad::RadSimImpl::samplePatchReflectivity() {
536536
texScale.s = std::max(patchSize * glm::length(texInfo.vS), 1.0f);
537537
texScale.t = std::max(patchSize * glm::length(texInfo.vT), 1.0f);
538538

539-
patch.getReflectivity() *= material.sampleColor(texPos, texScale);
539+
// A bit of gamma "correction" to increase the reflectivity
540+
glm::vec3 texel = material.sampleColor(texPos, texScale);
541+
float intensity = glm::dot(texel, RGB_INTENSITY);
542+
543+
if (intensity >= 0.0001f) {
544+
float adjustedIntensity = std::pow(intensity, 1.0f / TEXTURE_GAMMA_ADJ);
545+
texel *= adjustedIntensity / intensity;
546+
}
547+
548+
patch.getReflectivity() *= texel;
540549
}
541550
};
542551

src/rad/src/rad_sim_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ namespace rad {
2626
//! qrad also interprets color values of entities in linear space.
2727
constexpr float ENT_LIGHT_GAMMA = 2.5f;
2828

29+
//! Adjustment gamma when sampling reflectivity from textures.
30+
//! Applied to linear values. Increases low reflectivity values.
31+
constexpr float TEXTURE_GAMMA_ADJ = 1.3f;
32+
2933
//! Maximum number of lightstyles. Engine limit.
3034
constexpr int MAX_LIGHTSTYLES = 255;
3135

0 commit comments

Comments
 (0)