Moved remaining spherical harmonic things from render_skybox.cpp to SphericalHarmonic class

This commit is contained in:
Elderme
2015-08-02 23:01:52 +02:00
parent 2817fda910
commit 3a50a4d5d2
5 changed files with 102 additions and 102 deletions

View File

@@ -353,8 +353,6 @@ public:
void getOpenGLData(std::string *vendor, std::string *renderer,
std::string *version);
void prepareSkybox();
void generateDiffuseCoefficients();
void renderSkybox(const scene::ICameraSceneNode *camera);
void setPhase(STKRenderingPass);
STKRenderingPass getPhase() const;

View File

@@ -618,6 +618,17 @@ void IrrDriver::renderFixed(float dt)
m_video_driver->endScene();
}
// ----------------------------------------------------------------------------
void IrrDriver::renderSkybox(const scene::ICameraSceneNode *camera)
{
if(m_skybox)
{
m_skybox->render(camera);
}
} // renderSkybox
// ----------------------------------------------------------------------------
void IrrDriver::renderParticles()

View File

@@ -31,81 +31,11 @@
//***************************************************************************
// Currently unused functions, they will be used later so please DON'T remove
//***************************************************************************
/*static float getTexelValue(unsigned i, unsigned j, size_t width, size_t height,
float *Coeff, float *Y00, float *Y1minus1,
float *Y10, float *Y11, float *Y2minus2,
float * Y2minus1, float * Y20, float *Y21,
float *Y22)
{
float solidangle = 1.;
size_t idx = i * height + j;
float reconstructedVal = Y00[idx] * Coeff[0];
reconstructedVal += Y1minus1[i * height + j] * Coeff[1]
+ Y10[i * height + j] * Coeff[2]
+ Y11[i * height + j] * Coeff[3];
reconstructedVal += Y2minus2[idx] * Coeff[4]
+ Y2minus1[idx] * Coeff[5] + Y20[idx] * Coeff[6]
+ Y21[idx] * Coeff[7] + Y22[idx] * Coeff[8];
reconstructedVal /= solidangle;
return MAX2(255.0f * reconstructedVal, 0.f);
}*/ // getTexelValue
// ----------------------------------------------------------------------------
/*static void unprojectSH(float *output[], size_t width, size_t height,
float *Y00[], float *Y1minus1[], float *Y10[],
float *Y11[], float *Y2minus2[], float *Y2minus1[],
float * Y20[], float *Y21[], float *Y22[],
float *blueSHCoeff, float *greenSHCoeff,
float *redSHCoeff)
{
for (unsigned face = 0; face < 6; face++)
{
for (unsigned i = 0; i < width; i++)
{
for (unsigned j = 0; j < height; j++)
{
float fi = float(i), fj = float(j);
fi /= width, fj /= height;
fi = 2 * fi - 1, fj = 2 * fj - 1;
output[face][4 * height * i + 4 * j + 2] =
getTexelValue(i, j, width, height, redSHCoeff, Y00[face],
Y1minus1[face], Y10[face], Y11[face],
Y2minus2[face], Y2minus1[face], Y20[face],
Y21[face], Y22[face]);
output[face][4 * height * i + 4 * j + 1] =
getTexelValue(i, j, width, height, greenSHCoeff, Y00[face],
Y1minus1[face], Y10[face], Y11[face],
Y2minus2[face], Y2minus1[face], Y20[face],
Y21[face], Y22[face]);
output[face][4 * height * i + 4 * j] =
getTexelValue(i, j, width, height, blueSHCoeff, Y00[face],
Y1minus1[face], Y10[face], Y11[face],
Y2minus2[face], Y2minus1[face], Y20[face],
Y21[face], Y22[face]);
}
}
}
}*/ // unprojectSH
// ----------------------------------------------------------------------------
/*static void displayCoeff(float *SHCoeff)
{
printf("L00:%f\n", SHCoeff[0]);
printf("L1-1:%f, L10:%f, L11:%f\n", SHCoeff[1], SHCoeff[2], SHCoeff[3]);
printf("L2-2:%f, L2-1:%f, L20:%f, L21:%f, L22:%f\n",
SHCoeff[4], SHCoeff[5], SHCoeff[6], SHCoeff[7], SHCoeff[8]);
}*/ // displayCoeff
// ----------------------------------------------------------------------------
void IrrDriver::renderSkybox(const scene::ICameraSceneNode *camera)
{
if(m_skybox)
{
m_skybox->render(camera);
}
} // renderSkybox

View File

@@ -31,7 +31,8 @@ using namespace irr;
namespace
{
void convertToFloatTexture(unsigned char *sh_rgba[6], unsigned sh_w, unsigned sh_h, Color *float_tex_cube[6]) {
void convertToFloatTexture(unsigned char *sh_rgba[6], unsigned sh_w, unsigned sh_h, Color *float_tex_cube[6])
{
for (unsigned i = 0; i < 6; i++)
{
float_tex_cube[i] = new Color[sh_w * sh_h];
@@ -44,23 +45,39 @@ namespace
}
} //convertToFloatTexture
}
// ----------------------------------------------------------------------------
void displayCoeff(float *SH_coeff)
{
Log::debug("SphericalHarmonic", "L00:%f", SH_coeff[0]);
Log::debug("SphericalHarmonic", "L1-1:%f, L10:%f, L11:%f", SH_coeff[1], SH_coeff[2], SH_coeff[3]);
Log::debug("SphericalHarmonic", "L2-2:%f, L2-1:%f, L20:%f, L21:%f, L22:%f",
SH_coeff[4], SH_coeff[5], SH_coeff[6], SH_coeff[7], SH_coeff[8]);
} // displayCoeff
void SphericalHarmonic::printCoeff() {
Log::debug("Skybox", "Blue_SH: %f, %f, %f, %f, %f, %f, %f, %f, %f",
m_blue_SH_coeff[0], m_blue_SH_coeff[1], m_blue_SH_coeff[2],
m_blue_SH_coeff[3], m_blue_SH_coeff[4], m_blue_SH_coeff[5],
m_blue_SH_coeff[6], m_blue_SH_coeff[7], m_blue_SH_coeff[8]);
Log::debug("Skybox", "Green_SH: %f, %f, %f, %f, %f, %f, %f, %f, %f",
m_green_SH_coeff[0], m_green_SH_coeff[1], m_green_SH_coeff[2],
m_green_SH_coeff[3], m_green_SH_coeff[4], m_green_SH_coeff[5],
m_green_SH_coeff[6], m_green_SH_coeff[7], m_green_SH_coeff[8]);
Log::debug("Skybox", "Red_SH: %f, %f, %f, %f, %f, %f, %f, %f, %f",
m_red_SH_coeff[0], m_red_SH_coeff[1], m_red_SH_coeff[2],
m_red_SH_coeff[3], m_red_SH_coeff[4], m_red_SH_coeff[5],
m_red_SH_coeff[6], m_red_SH_coeff[7], m_red_SH_coeff[8]);
}
// ----------------------------------------------------------------------------
float getTexelValue(unsigned i, unsigned j, size_t width, size_t height,
float *Coeff, float *Y00, float *Y1minus1,
float *Y10, float *Y11, float *Y2minus2,
float * Y2minus1, float * Y20, float *Y21,
float *Y22)
{
float solidangle = 1.;
size_t idx = i * height + j;
float reconstructedVal = Y00[idx] * Coeff[0];
reconstructedVal += Y1minus1[i * height + j] * Coeff[1]
+ Y10[i * height + j] * Coeff[2]
+ Y11[i * height + j] * Coeff[3];
reconstructedVal += Y2minus2[idx] * Coeff[4]
+ Y2minus1[idx] * Coeff[5] + Y20[idx] * Coeff[6]
+ Y21[idx] * Coeff[7] + Y22[idx] * Coeff[8];
reconstructedVal /= solidangle;
return std::max(255.0f * reconstructedVal, 0.f);
} // getTexelValue
} //namespace
// ----------------------------------------------------------------------------
SphericalHarmonic::SphericalHarmonic(const std::vector<video::ITexture *> &spherical_harmonics_textures)
{
assert(spherical_harmonics_textures.size() == 6);
@@ -105,11 +122,10 @@ SphericalHarmonic::SphericalHarmonic(const std::vector<video::ITexture *> &spher
delete[] sh_rgba[i];
delete[] float_tex_cube[i];
}
printCoeff();
}// SphericalHarmonic(const std::vector<video::ITexture *> &spherical_harmonics_textures)
// ----------------------------------------------------------------------------
SphericalHarmonic::SphericalHarmonic(const video::SColor &ambient)
{
unsigned char *sh_rgba[6];
@@ -146,13 +162,54 @@ SphericalHarmonic::SphericalHarmonic(const video::SColor &ambient)
m_green_SH_coeff[i] *= 4;
m_red_SH_coeff[i] *= 4;
}
printCoeff();
Log::debug("SphericalHarmonic", "%f %f %f", ambient.getBlue(), ambient.getGreen(), ambient.getRed());
}// SphericalHarmonic(const video::SColor &ambient)
// ----------------------------------------------------------------------------
void SphericalHarmonic::printCoeff() {
Log::debug("SphericalHarmonic", "Blue_SH:");
displayCoeff(m_blue_SH_coeff);
Log::debug("SphericalHarmonic", "Green_SH:");
displayCoeff(m_green_SH_coeff);
Log::debug("SphericalHarmonic", "Red_SH:");
displayCoeff(m_red_SH_coeff);
} //printCoeff
// ----------------------------------------------------------------------------
void SphericalHarmonic::unprojectSH(float *output[], size_t width, size_t height,
float *Y00[], float *Y1minus1[], float *Y10[],
float *Y11[], float *Y2minus2[], float *Y2minus1[],
float * Y20[], float *Y21[], float *Y22[])
{
for (unsigned face = 0; face < 6; face++)
{
for (unsigned i = 0; i < width; i++)
{
for (unsigned j = 0; j < height; j++)
{
float fi = float(i), fj = float(j);
fi /= width, fj /= height;
fi = 2 * fi - 1, fj = 2 * fj - 1;
output[face][4 * height * i + 4 * j + 2] =
getTexelValue(i, j, width, height, m_red_SH_coeff, Y00[face],
Y1minus1[face], Y10[face], Y11[face],
Y2minus2[face], Y2minus1[face], Y20[face],
Y21[face], Y22[face]);
output[face][4 * height * i + 4 * j + 1] =
getTexelValue(i, j, width, height, m_green_SH_coeff, Y00[face],
Y1minus1[face], Y10[face], Y11[face],
Y2minus2[face], Y2minus1[face], Y20[face],
Y21[face], Y22[face]);
output[face][4 * height * i + 4 * j] =
getTexelValue(i, j, width, height, m_blue_SH_coeff, Y00[face],
Y1minus1[face], Y10[face], Y11[face],
Y2minus2[face], Y2minus1[face], Y20[face],
Y21[face], Y22[face]);
}
}
}
} // unprojectSH

View File

@@ -34,18 +34,22 @@ private:
float m_green_SH_coeff[9];
float m_red_SH_coeff[9];
/** Print spherical harmonic coefficients (debug) */
void printCoeff();
public:
SphericalHarmonic(const std::vector<irr::video::ITexture *> &spherical_harmonics_textures);
SphericalHarmonic(const irr::video::SColor &ambient);
inline const float* getBlueSHCoeff() const {return m_blue_SH_coeff; }
inline const float* getBlueSHCoeff () const {return m_blue_SH_coeff; }
inline const float* getGreenSHCoeff() const {return m_green_SH_coeff; }
inline const float* getRedSHCoeff() const {return m_red_SH_coeff; }
inline const float* getRedSHCoeff () const {return m_red_SH_coeff; }
/** Print spherical harmonic coefficients (debug) */
void printCoeff();
void unprojectSH (float *output[], size_t width, size_t height,
float *Y00[], float *Y1minus1[], float *Y10[],
float *Y11[], float *Y2minus2[], float *Y2minus1[],
float * Y20[], float *Y21[], float *Y22[]);
};
#endif //HEADER_SPHERICAL_HARMONIC_HPP