Text archives Help
- From: vpegorar@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r524 - in branches/fire: Core/Color Model/Materials scenes
- Date: Wed, 31 Aug 2005 17:44:03 -0600 (MDT)
Author: vpegorar
Date: Wed Aug 31 17:44:01 2005
New Revision: 524
Modified:
branches/fire/Core/Color/Colorimetry.cc
branches/fire/Core/Color/Colorimetry.h
branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
branches/fire/Model/Materials/InhomogeneousParticipatingMedium.h
branches/fire/scenes/primtest.cc
Log:
In InhomogeneousParticipatingMedium, added possibility to tone map the color
resulting from the integration through the volume. This provides a cheap way
to get the right color for the fire.
Modified: branches/fire/Core/Color/Colorimetry.cc
==============================================================================
--- branches/fire/Core/Color/Colorimetry.cc (original)
+++ branches/fire/Core/Color/Colorimetry.cc Wed Aug 31 17:44:01 2005
@@ -358,3 +358,49 @@
*Z = sum[2] * 683.0f;
}
}
+
+
+//
--------------------------------------------------------------------------------------
+// --- Return the average LMS of the volume using the given colorMap
+//
--------------------------------------------------------------------------------------
+float AverageLMS(const Array3<float> & volume, const ColorMap & colorMap,
int lmsMode)
+{
+ unsigned int i, j, k;
+ float LMS[3], XYZ[3], averageLMS;
+ Color color;
+ RGBColor rgbColor;
+
+ averageLMS = 0.0f;
+ for(k=0; k<volume.getNz(); k++)
+ for(j=0; j<volume.getNy(); j++)
+ for(i=0; i<volume.getNx(); i++)
+ {
+ colorMap.Lookup(volume(i, j, k), color);
+ rgbColor = color.convertRGB();
+ RGBtoXYZ(rgbColor.r(), rgbColor.g(),
rgbColor.b(), &(XYZ[0]), &(XYZ[1]), &(XYZ[2]));
+ XYZtoLMS(XYZ[0], XYZ[1], XYZ[2], &(LMS[0]),
&(LMS[1]), &(LMS[2]), lmsMode);
+ averageLMS += LMS[0] + LMS[1] + LMS[2];
+ }
+ averageLMS /= (float)(3 * volume.getNx() * volume.getNy() *
volume.getNz());
+
+ return averageLMS;
+}
+
+
+//
--------------------------------------------------------------------------------------
+// --- Tone map the RGB color given a LMS adaptation level
+//
--------------------------------------------------------------------------------------
+void ToneMap(float * R, float * G, float * B, float adaptationLevelLMS, int
lmsMode)
+{
+ float LMS[3], XYZ[3];
+
+ RGBtoXYZ(*R, *G, *B, &(XYZ[0]), &(XYZ[1]), &(XYZ[2]));
+ XYZtoLMS(XYZ[0], XYZ[1], XYZ[2], &(LMS[0]), &(LMS[1]), &(LMS[2]),
lmsMode);
+
+ LMS[0] /= adaptationLevelLMS + LMS[0];
+ LMS[1] /= adaptationLevelLMS + LMS[1];
+ LMS[2] /= adaptationLevelLMS + LMS[2];
+
+ LMStoXYZ(LMS[0], LMS[1], LMS[2], &(XYZ[0]), &(XYZ[1]), &(XYZ[2]),
lmsMode);
+ XYZtoRGB(XYZ[0], XYZ[1], XYZ[2], R, G, B);
+}
Modified: branches/fire/Core/Color/Colorimetry.h
==============================================================================
--- branches/fire/Core/Color/Colorimetry.h (original)
+++ branches/fire/Core/Color/Colorimetry.h Wed Aug 31 17:44:01 2005
@@ -2,6 +2,11 @@
#ifndef Manta_Core_Color_Colorimetry_h
#define Manta_Core_Color_Colorimetry_h
+#include <Model/Groups/GriddedGroup.h> // Array3
+#include <Core/Util/ColorMap.h>
+
+using namespace Manta;
+
#define FULL_SPECTRUM_SIZE 425
extern float const g_TristimulusCurves[FULL_SPECTRUM_SIZE][3];
@@ -13,5 +18,7 @@
extern void XYZtoxyY(float X, float Y, float Z, float * px, float
* py, float * pY);
extern void xyYtoXYZ(float x, float y, float Y, float * pX, float
* pY, float * pZ);
extern void SpectrumToXYZ(const float * spectrum, bool rescale,
float * X, float * Y, float * Z);
+extern float AverageLMS(const Array3<float> & volume, const ColorMap &
colorMap, int lmsMode = 0);
+extern void ToneMap(float * R, float * G, float * B, float
adaptationLevelLMS, int lmsMode = 0);
#endif
Modified: branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
==============================================================================
--- branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
(original)
+++ branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc Wed
Aug 31 17:44:01 2005
@@ -2,6 +2,7 @@
#include <math.h>
#include <Model/Materials/InhomogeneousParticipatingMedium.h>
#include <Model/Readers/VolumeReader.h>
+#include <Core/Color/Colorimetry.h>
#include <Interface/Scene.h>
#include <Interface/Renderer.h>
#include <Interface/RayPacket.h>
@@ -19,7 +20,8 @@
ColorMap *
emittedLightColorMap,
const char *
refractiveIndexFileName,
const Point &
minBound, const Point & maxBound,
-
double
cellStepSize, double metersPerUnit)
+
double
cellStepSize, double metersPerUnit,
+
float
adaptationLevelScale)
{
m_DefaultVolume = NULL;
@@ -85,9 +87,15 @@
m_EmittedLight->getMinMax(&min, &max);
m_EmittedLightColorMap = new ColorMap(RAINBOW_COLORS,
min, max);
}
+
+ if (adaptationLevelScale > 0.0f) m_AdaptationLevelLMS
= adaptationLevelScale * AverageLMS(*m_EmittedLight, *m_EmittedLightColorMap)
* (float)m_MetersPerUnit;
+ else
m_AdaptationLevelLMS = -1.0f;
}
else
+ {
m_EmittedLightColorMap = NULL;
+ m_AdaptationLevelLMS = -1.0f;
+ }
}
@@ -356,6 +364,18 @@
}
t += m_WorldStepSize;
+ }
+
+ if (m_AdaptationLevelLMS > 0.0f)
+ {
+ float r, g, b;
+ RGBColor rgbColor = accumColor.convertRGB();
+
+ r = rgbColor.r();
+ g = rgbColor.g();
+ b = rgbColor.b();
+ ToneMap(&r, &g, &b, m_AdaptationLevelLMS);
+ accumColor = Color(RGBColor(r, g, b));
}
if (rays.getDepth() <
context.scene->getRenderParameters().maxDepth) // Transmitted ray
Modified: branches/fire/Model/Materials/InhomogeneousParticipatingMedium.h
==============================================================================
--- branches/fire/Model/Materials/InhomogeneousParticipatingMedium.h
(original)
+++ branches/fire/Model/Materials/InhomogeneousParticipatingMedium.h Wed
Aug 31 17:44:01 2005
@@ -24,6 +24,7 @@
Vector m_CellSize;
double m_WorldStepSize;
double m_MetersPerUnit;
+ float m_AdaptationLevelLMS;
public:
@@ -32,7 +33,8 @@
ColorMap * emittedLightColorMap,
const char *
refractiveIndexFileName,
const Point & minBound, const Point
& maxBound,
-
double cellStepSize, double
metersPerUnit);
+
double cellStepSize, double
metersPerUnit,
+
float adaptationLevelScale = -1.0f);
virtual ~InhomogeneousParticipatingMedium();
virtual void preprocess(const PreprocessContext & context);
Modified: branches/fire/scenes/primtest.cc
==============================================================================
--- branches/fire/scenes/primtest.cc (original)
+++ branches/fire/scenes/primtest.cc Wed Aug 31 17:44:01 2005
@@ -260,15 +260,15 @@
ColorMap * colorMap = new ColorMap(BLACK_BODY_RADIATION, 298.0f,
2234.0f);
Material * matIPM = new InhomogeneousParticipatingMedium(
"../Data/heptane/abskgIN_M00_0450.nrrd",
"../Data/heptane/tempIN_M00_0450.nrrd",
-
NULL, //colorMap,
+
colorMap,
NULL,
//"../Data/heptane/refrIN_M00_0450.nrrd",
Point(-0.21, -0.21, 0.19),
Point(0.21, 0.21, 0.61),
-
0.5, 20.0);
+
0.5, 10.0, 0.3f);
Material * matL = new Lambertian(Color(RGB(.6,0,0)));
Primitive * primC = new Cube(matIPM, Point(-0.2, -0.2, 0.2), 0.4,
0.4, 0.4);
Primitive * primS = new Sphere(matL, Point(0.0, 0.0, 0.4), 0.1);
group->add(primC);
-// group->add(primS);
+ group->add(primS);
} else {
throw IllegalArgument("Unknown primitive type for primtest: "+primtype,
0, args);
}
- [MANTA] r524 - in branches/fire: Core/Color Model/Materials scenes, vpegorar, 08/31/2005
Archive powered by MHonArc 2.6.16.