Add min saturation setting to material class

This commit is contained in:
Benau 2016-07-01 23:55:56 +08:00
parent f23ec7e7b8
commit 48d94097d6
7 changed files with 27 additions and 21 deletions

View File

@ -141,6 +141,7 @@ Material::Material(const XMLNode *node, bool deprecated)
node->get("backface-culling", &m_backface_culling );
node->get("disable-z-write", &m_disable_z_write );
node->get("colorizable", &m_colorizable );
node->get("colorized-factor", &m_colorized_factor );
node->get("fog", &m_fog );
node->get("mask", &m_mask );
@ -436,6 +437,7 @@ void Material::init()
m_collision_reaction = NORMAL;
m_disable_z_write = false;
m_colorizable = false;
m_colorized_factor = 0.93f;
m_water_shader_speed_1 = 6.6667f;
m_water_shader_speed_2 = 4.0f;
m_fog = true;

View File

@ -178,6 +178,9 @@ private:
/** True if this material can be colorized (like red/blue in team game). */
bool m_colorizable;
/** Minimum resulting saturation when colorized (from 0 to 1) */
float m_colorized_factor;
/** Some textures need to be pre-multiplied, some divided to give
* the intended effect. */
//enum {ADJ_NONE, ADJ_PREMUL, ADJ_DIV}
@ -290,6 +293,10 @@ public:
*/
bool isColorizable () const { return m_colorizable; }
// ------------------------------------------------------------------------
/** Returns the minimum resulting saturation when colorized.
*/
float getColorizedFactor () const { return m_colorized_factor; }
// ------------------------------------------------------------------------
/** Returns if this material should trigger a rescue if a kart
* crashes against it. */
CollisionReaction getCollisionReaction() const { return m_collision_reaction; }

View File

@ -999,13 +999,14 @@ void draw(const T *Shader, const GLMesh *mesh, uniforms... Args)
GLenum itype = mesh->IndexType;
size_t count = mesh->IndexCount;
const bool support_change_hue = (mesh->m_render_info != NULL);
const bool support_change_hue = (mesh->m_render_info != NULL &&
mesh->m_material != NULL);
const bool need_change_hue = (support_change_hue &&
mesh->m_render_info->getHue() > 0.0f);
if (need_change_hue)
{
Shader->changeableColor(mesh->m_render_info->getHue(),
mesh->m_render_info->getMinSaturation());
mesh->m_material->getColorizedFactor());
}
Shader->setUniforms(Args...);
@ -1301,14 +1302,15 @@ void renderInstancedMeshes2ndPass(const std::vector<GLuint> &Prefilled_tex, Args
ExpandTex(*mesh, T::SecondPassTextures, Prefilled_tex[0],
Prefilled_tex[1], Prefilled_tex[2]);
const bool support_change_hue = (mesh->m_render_info != NULL);
const bool support_change_hue = (mesh->m_render_info != NULL &&
mesh->m_material != NULL);
const bool need_change_hue =
(support_change_hue && mesh->m_render_info->getHue() > 0.0f);
if (need_change_hue)
{
T::InstancedSecondPassShader::getInstance()->changeableColor
(mesh->m_render_info->getHue(),
mesh->m_render_info->getMinSaturation());
mesh->m_material->getColorizedFactor());
}
T::InstancedSecondPassShader::getInstance()->setUniforms(args...);

View File

@ -24,10 +24,9 @@
#include <ISceneManager.h>
// ----------------------------------------------------------------------------
RenderInfo::RenderInfo(float hue, float min_saturation, bool transparent)
RenderInfo::RenderInfo(float hue, bool transparent)
{
m_hue = hue;
m_min_saturation = min_saturation;
m_transparent = transparent;
} // RenderInfo

View File

@ -44,15 +44,12 @@ public:
private:
float m_hue;
float m_min_saturation;
bool m_transparent;
std::vector<int> m_colorizable_parts;
public:
RenderInfo(float hue = 0.0f, float min_saturation = 0.0f,
bool transparent = false);
RenderInfo(float hue = 0.0f, bool transparent = false);
// ------------------------------------------------------------------------
~RenderInfo() {}
// ------------------------------------------------------------------------
@ -60,15 +57,10 @@ public:
// ------------------------------------------------------------------------
void setHue(float hue) { m_hue = hue; }
// ------------------------------------------------------------------------
void setMinSaturation(float min_saturation)
{ m_min_saturation = min_saturation; }
// ------------------------------------------------------------------------
void setTransparent(bool transparent) { m_transparent = transparent; }
// ------------------------------------------------------------------------
float getHue() const { return m_hue; }
// ------------------------------------------------------------------------
float getMinSaturation() const { return m_min_saturation; }
// ------------------------------------------------------------------------
bool isTransparent() const { return m_transparent; }
// ------------------------------------------------------------------------
bool isColorizable(int mesh_buffer_index) const
@ -83,9 +75,6 @@ public:
setHue(krt == RenderInfo::KRT_BLUE ? 0.66f :
krt == RenderInfo::KRT_RED ? 1.0f : 0.0f);
setMinSaturation(krt == RenderInfo::KRT_BLUE ||
krt == RenderInfo::KRT_RED ? 0.93f : 0.0f);
setTransparent(krt == RenderInfo::KRT_TRANSPARENT ? true : false);
}
// ------------------------------------------------------------------------

View File

@ -23,6 +23,7 @@
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/render_info.hpp"
#include "graphics/shaders.hpp"
#include "modes/world.hpp"
@ -168,11 +169,17 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb, const std::string& debug_name,
RenderInfo* render_info)
{
GLMesh result = {};
result.m_render_info = render_info;
result.m_material = NULL;
result.m_render_info = NULL;
if (!mb)
return result;
result.mb = mb;
if (render_info != NULL)
{
result.m_render_info = render_info;
result.m_material = material_manager->getMaterialFor(mb
->getMaterial().getTexture(0), mb);
}
#ifdef DEBUG
result.debug_name = debug_name;
#endif

View File

@ -30,7 +30,6 @@
#include <vector>
class Material;
class RenderInfo;
enum TransparentMaterial
@ -58,6 +57,7 @@ struct GLMesh
uint64_t TextureHandles[6];
scene::IMeshBuffer *mb;
RenderInfo* m_render_info;
Material* m_material;
#ifdef DEBUG
std::string debug_name;
#endif