Small change in enabling/disabling shadow mapping
parent
d3ccdebd9f
commit
9effa308ce
|
@ -306,7 +306,7 @@ public:
|
|||
virtual void DebugLights() = 0;
|
||||
|
||||
//! Returns a name of this device
|
||||
virtual std::string&& GetName() = 0;
|
||||
virtual std::string GetName() = 0;
|
||||
|
||||
//! Initializes the device, setting the initial state
|
||||
virtual bool Create() = 0;
|
||||
|
|
|
@ -44,9 +44,9 @@ void CNullDevice::DebugLights()
|
|||
{
|
||||
}
|
||||
|
||||
std::string&& CNullDevice::GetName()
|
||||
std::string CNullDevice::GetName()
|
||||
{
|
||||
return "Null Device";
|
||||
return std::string("Null Device");
|
||||
}
|
||||
|
||||
bool CNullDevice::Create()
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
void DebugHook() override;
|
||||
void DebugLights() override;
|
||||
|
||||
std::string&& GetName() override;
|
||||
std::string GetName() override;
|
||||
|
||||
bool Create() override;
|
||||
void Destroy() override;
|
||||
|
|
|
@ -3552,150 +3552,172 @@ void CEngine::UseShadowMapping(bool enable)
|
|||
if (!m_shadowMapping) return;
|
||||
if (m_shadowMap.id == 0) return;
|
||||
|
||||
if (enable) // Enable shadow mapping
|
||||
// all devices that are not OpenGL 1.4
|
||||
if (m_device->GetName() != "OpenGL 1.4")
|
||||
{
|
||||
m_device->SetShadowColor(m_shadowColor);
|
||||
|
||||
if (m_qualityShadows)
|
||||
if (enable)
|
||||
{
|
||||
// Texture Unit 2
|
||||
m_device->SetShadowColor(m_shadowColor);
|
||||
|
||||
m_device->SetTextureEnabled(2, true);
|
||||
m_device->SetTexture(2, m_shadowMap);
|
||||
m_device->SetTransform(TRANSFORM_SHADOW, m_shadowTextureMat);
|
||||
|
||||
Math::Matrix identity;
|
||||
identity.LoadIdentity();
|
||||
m_device->SetTransform(TRANSFORM_WORLD, identity);
|
||||
|
||||
float shadowBias = 0.6f;
|
||||
float shadowUnbias = 1.0f - shadowBias;
|
||||
|
||||
TextureStageParams params;
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
|
||||
params.colorArg2 = TEX_MIX_ARG_FACTOR;
|
||||
params.colorOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.factor = Color(shadowBias, shadowBias, shadowBias, 1.0f);
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(2, params);
|
||||
|
||||
TextureGenerationParams genParams;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
genParams.coords[i].mode = TEX_GEN_EYE_LINEAR;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
genParams.coords[i].plane[j] = (i == j ? 1.0f : 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
m_device->SetTextureCoordGeneration(2, genParams);
|
||||
|
||||
// Texture Unit 3
|
||||
m_device->SetTextureEnabled(3, true);
|
||||
m_device->SetTexture(3, m_shadowMap);
|
||||
|
||||
params.LoadDefault();
|
||||
params.colorOperation = TEX_MIX_OPER_ADD;
|
||||
params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||
params.colorArg2 = TEX_MIX_ARG_FACTOR;
|
||||
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.factor = Color(shadowUnbias, shadowUnbias, shadowUnbias, 0.0f);
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(3, params);
|
||||
|
||||
// Texture Unit 4
|
||||
m_device->SetTextureEnabled(4, true);
|
||||
m_device->SetTexture(4, m_shadowMap);
|
||||
|
||||
params.LoadDefault();
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||
params.colorArg2 = TEX_MIX_ARG_SRC_COLOR;
|
||||
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(4, params);
|
||||
|
||||
// Texture Unit 5
|
||||
m_device->SetTextureEnabled(5, true);
|
||||
m_device->SetTexture(5, m_shadowMap);
|
||||
|
||||
params.LoadDefault();
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||
params.colorArg2 = TEX_MIX_ARG_TEXTURE_0;
|
||||
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(5, params);
|
||||
}
|
||||
else // Simpler shadows
|
||||
else
|
||||
{
|
||||
// Texture Unit 2
|
||||
m_device->SetTextureEnabled(2, true);
|
||||
m_device->SetTexture(2, m_shadowMap);
|
||||
m_device->SetTransform(TRANSFORM_SHADOW, m_shadowTextureMat);
|
||||
|
||||
Math::Matrix identity;
|
||||
identity.LoadIdentity();
|
||||
m_device->SetTransform(TRANSFORM_WORLD, identity);
|
||||
|
||||
TextureStageParams params;
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
m_device->SetTextureStageParams(2, params);
|
||||
|
||||
TextureGenerationParams genParams;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
genParams.coords[i].mode = TEX_GEN_EYE_LINEAR;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
genParams.coords[i].plane[j] = (i == j ? 1.0f : 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
m_device->SetTextureCoordGeneration(2, genParams);
|
||||
m_device->SetTexture(2, 0);
|
||||
m_device->SetTextureEnabled(2, false);
|
||||
}
|
||||
}
|
||||
else // Disable shadow mapping
|
||||
// special case for OpenGL 1.4 device
|
||||
else
|
||||
{
|
||||
Math::Matrix identity;
|
||||
identity.LoadIdentity();
|
||||
|
||||
m_device->SetTexture(2, 0);
|
||||
m_device->SetTextureEnabled(2, false);
|
||||
m_device->SetTransform(TRANSFORM_SHADOW, identity);
|
||||
|
||||
TextureGenerationParams params;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
params.coords[i].mode = TEX_GEN_NONE;
|
||||
|
||||
m_device->SetTextureCoordGeneration(2, params);
|
||||
|
||||
if (m_qualityShadows)
|
||||
if (enable)
|
||||
{
|
||||
m_device->SetTexture(3, 0);
|
||||
m_device->SetTextureEnabled(3, false);
|
||||
m_device->SetShadowColor(m_shadowColor);
|
||||
|
||||
m_device->SetTexture(4, 0);
|
||||
m_device->SetTextureEnabled(4, false);
|
||||
if (m_qualityShadows)
|
||||
{
|
||||
// Texture Unit 2
|
||||
m_device->SetTextureEnabled(2, true);
|
||||
m_device->SetTexture(2, m_shadowMap);
|
||||
m_device->SetTransform(TRANSFORM_SHADOW, m_shadowTextureMat);
|
||||
|
||||
m_device->SetTexture(5, 0);
|
||||
m_device->SetTextureEnabled(5, false);
|
||||
Math::Matrix identity;
|
||||
identity.LoadIdentity();
|
||||
m_device->SetTransform(TRANSFORM_WORLD, identity);
|
||||
|
||||
float shadowBias = m_shadowColor;
|
||||
float shadowUnbias = 1.0f - shadowBias;
|
||||
|
||||
TextureStageParams params;
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
|
||||
params.colorArg2 = TEX_MIX_ARG_FACTOR;
|
||||
params.colorOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.factor = Color(shadowBias, shadowBias, shadowBias, 1.0f);
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(2, params);
|
||||
|
||||
TextureGenerationParams genParams;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
genParams.coords[i].mode = TEX_GEN_EYE_LINEAR;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
genParams.coords[i].plane[j] = (i == j ? 1.0f : 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
m_device->SetTextureCoordGeneration(2, genParams);
|
||||
|
||||
// Texture Unit 3
|
||||
m_device->SetTextureEnabled(3, true);
|
||||
m_device->SetTexture(3, m_shadowMap);
|
||||
|
||||
params.LoadDefault();
|
||||
params.colorOperation = TEX_MIX_OPER_ADD;
|
||||
params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||
params.colorArg2 = TEX_MIX_ARG_FACTOR;
|
||||
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.factor = Color(shadowUnbias, shadowUnbias, shadowUnbias, 0.0f);
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(3, params);
|
||||
|
||||
// Texture Unit 4
|
||||
m_device->SetTextureEnabled(4, true);
|
||||
m_device->SetTexture(4, m_shadowMap);
|
||||
|
||||
params.LoadDefault();
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||
params.colorArg2 = TEX_MIX_ARG_SRC_COLOR;
|
||||
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(4, params);
|
||||
|
||||
// Texture Unit 5
|
||||
m_device->SetTextureEnabled(5, true);
|
||||
m_device->SetTexture(5, m_shadowMap);
|
||||
|
||||
params.LoadDefault();
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
|
||||
params.colorArg2 = TEX_MIX_ARG_TEXTURE_0;
|
||||
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
|
||||
m_device->SetTextureStageParams(5, params);
|
||||
}
|
||||
else // Simpler shadows
|
||||
{
|
||||
// Texture Unit 2
|
||||
m_device->SetTextureEnabled(2, true);
|
||||
m_device->SetTexture(2, m_shadowMap);
|
||||
m_device->SetTransform(TRANSFORM_SHADOW, m_shadowTextureMat);
|
||||
|
||||
Math::Matrix identity;
|
||||
identity.LoadIdentity();
|
||||
m_device->SetTransform(TRANSFORM_WORLD, identity);
|
||||
|
||||
TextureStageParams params;
|
||||
params.colorOperation = TEX_MIX_OPER_MODULATE;
|
||||
params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
|
||||
m_device->SetTextureStageParams(2, params);
|
||||
|
||||
TextureGenerationParams genParams;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
genParams.coords[i].mode = TEX_GEN_EYE_LINEAR;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
genParams.coords[i].plane[j] = (i == j ? 1.0f : 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
m_device->SetTextureCoordGeneration(2, genParams);
|
||||
}
|
||||
}
|
||||
// disable shadows
|
||||
else
|
||||
{
|
||||
Math::Matrix identity;
|
||||
identity.LoadIdentity();
|
||||
|
||||
m_device->SetTexture(2, 0);
|
||||
m_device->SetTextureEnabled(2, false);
|
||||
m_device->SetTransform(TRANSFORM_SHADOW, identity);
|
||||
|
||||
TextureGenerationParams params;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
params.coords[i].mode = TEX_GEN_NONE;
|
||||
|
||||
m_device->SetTextureCoordGeneration(2, params);
|
||||
|
||||
if (m_qualityShadows)
|
||||
{
|
||||
m_device->SetTexture(3, 0);
|
||||
m_device->SetTextureEnabled(3, false);
|
||||
|
||||
m_device->SetTexture(4, 0);
|
||||
m_device->SetTextureEnabled(4, false);
|
||||
|
||||
m_device->SetTexture(5, 0);
|
||||
m_device->SetTextureEnabled(5, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,9 +163,9 @@ void CGL21Device::DebugLights()
|
|||
m_worldMat = saveWorldMat;
|
||||
}
|
||||
|
||||
std::string&& CGL21Device::GetName()
|
||||
std::string CGL21Device::GetName()
|
||||
{
|
||||
return "OpenGL 2.1";
|
||||
return std::string("OpenGL 2.1");
|
||||
}
|
||||
|
||||
bool CGL21Device::Create()
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
void DebugHook() override;
|
||||
void DebugLights() override;
|
||||
|
||||
std::string&& GetName() override;
|
||||
std::string GetName() override;
|
||||
|
||||
bool Create() override;
|
||||
void Destroy() override;
|
||||
|
|
|
@ -162,9 +162,9 @@ void CGL33Device::DebugLights()
|
|||
SetTransform(TRANSFORM_WORLD, saveWorldMat);
|
||||
}
|
||||
|
||||
std::string&& CGL33Device::GetName()
|
||||
std::string CGL33Device::GetName()
|
||||
{
|
||||
return "OpenGL 3.3";
|
||||
return std::string("OpenGL 3.3");
|
||||
}
|
||||
|
||||
bool CGL33Device::Create()
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
void DebugHook() override;
|
||||
void DebugLights() override;
|
||||
|
||||
std::string&& GetName() override;
|
||||
std::string GetName() override;
|
||||
|
||||
bool Create() override;
|
||||
void Destroy() override;
|
||||
|
|
|
@ -158,9 +158,9 @@ void CGLDevice::DebugLights()
|
|||
UpdateModelviewMatrix();
|
||||
}
|
||||
|
||||
std::string&& CGLDevice::GetName()
|
||||
std::string CGLDevice::GetName()
|
||||
{
|
||||
return "OpenGL 1.4";
|
||||
return std::string("OpenGL 1.4");
|
||||
}
|
||||
|
||||
bool CGLDevice::Create()
|
||||
|
|
|
@ -81,7 +81,7 @@ public:
|
|||
void DebugHook() override;
|
||||
void DebugLights() override;
|
||||
|
||||
std::string&& GetName() override;
|
||||
std::string GetName() override;
|
||||
|
||||
bool Create() override;
|
||||
void Destroy() override;
|
||||
|
|
Loading…
Reference in New Issue