Graphics/PhongMaterial: Add option to disable shadow mapping (and disable it by default on web)
This commit is contained in:
parent
44c42a85c2
commit
2c6191987f
|
|
@ -46,10 +46,17 @@ namespace Nz
|
||||||
settings.AddValueProperty<Color>("AmbientColor", Color::White());
|
settings.AddValueProperty<Color>("AmbientColor", Color::White());
|
||||||
settings.AddValueProperty<Color>("SpecularColor", Color::White());
|
settings.AddValueProperty<Color>("SpecularColor", Color::White());
|
||||||
settings.AddValueProperty<float>("Shininess", 2.f);
|
settings.AddValueProperty<float>("Shininess", 2.f);
|
||||||
|
#ifndef NAZARA_PLATFORM_WEB
|
||||||
|
settings.AddValueProperty<bool>("ShadowMapping", true);
|
||||||
|
#else
|
||||||
|
// FIXME: Shadowmapping is currently broken on web because WebGL doesn't support non-constant array indexing
|
||||||
|
settings.AddValueProperty<bool>("ShadowMapping", false);
|
||||||
|
#endif
|
||||||
settings.AddTextureProperty("EmissiveMap", ImageType::E2D);
|
settings.AddTextureProperty("EmissiveMap", ImageType::E2D);
|
||||||
settings.AddTextureProperty("HeightMap", ImageType::E2D);
|
settings.AddTextureProperty("HeightMap", ImageType::E2D);
|
||||||
settings.AddTextureProperty("NormalMap", ImageType::E2D);
|
settings.AddTextureProperty("NormalMap", ImageType::E2D);
|
||||||
settings.AddTextureProperty("SpecularMap", ImageType::E2D);
|
settings.AddTextureProperty("SpecularMap", ImageType::E2D);
|
||||||
|
settings.AddPropertyHandler(std::make_unique<OptionValuePropertyHandler>("ShadowMapping", "EnableShadowMapping"));
|
||||||
settings.AddPropertyHandler(std::make_unique<TexturePropertyHandler>("EmissiveMap", "HasEmissiveTexture"));
|
settings.AddPropertyHandler(std::make_unique<TexturePropertyHandler>("EmissiveMap", "HasEmissiveTexture"));
|
||||||
settings.AddPropertyHandler(std::make_unique<TexturePropertyHandler>("HeightMap", "HasHeightMap"));
|
settings.AddPropertyHandler(std::make_unique<TexturePropertyHandler>("HeightMap", "HasHeightMap"));
|
||||||
settings.AddPropertyHandler(std::make_unique<TexturePropertyHandler>("NormalMap", "HasNormalMap"));
|
settings.AddPropertyHandler(std::make_unique<TexturePropertyHandler>("NormalMap", "HasNormalMap"));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ option HasAlphaTexture: bool = false;
|
||||||
option AlphaTest: bool = false;
|
option AlphaTest: bool = false;
|
||||||
|
|
||||||
// Phong material options
|
// Phong material options
|
||||||
|
option EnableShadowMapping: bool = true;
|
||||||
option HasEmissiveTexture: bool = false;
|
option HasEmissiveTexture: bool = false;
|
||||||
option HasHeightTexture: bool = false;
|
option HasHeightTexture: bool = false;
|
||||||
option HasNormalTexture: bool = false;
|
option HasNormalTexture: bool = false;
|
||||||
|
|
@ -209,6 +210,8 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
specFactor = pow(specFactor, settings.Shininess);
|
specFactor = pow(specFactor, settings.Shininess);
|
||||||
|
|
||||||
let shadowFactor = 1.0;
|
let shadowFactor = 1.0;
|
||||||
|
const if (EnableShadowMapping)
|
||||||
|
{
|
||||||
if (light.invShadowMapSize.x > 0.0)
|
if (light.invShadowMapSize.x > 0.0)
|
||||||
{
|
{
|
||||||
shadowFactor = 0.0;
|
shadowFactor = 0.0;
|
||||||
|
|
@ -243,6 +246,7 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lightAmbient += attenuationFactor * light.color.rgb * lightAmbientFactor * settings.AmbientColor.rgb;
|
lightAmbient += attenuationFactor * light.color.rgb * lightAmbientFactor * settings.AmbientColor.rgb;
|
||||||
lightDiffuse += shadowFactor * attenuationFactor * lambert * light.color.rgb * lightDiffuseFactor;
|
lightDiffuse += shadowFactor * attenuationFactor * lambert * light.color.rgb * lightDiffuseFactor;
|
||||||
|
|
@ -273,6 +277,8 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
specFactor = pow(specFactor, settings.Shininess);
|
specFactor = pow(specFactor, settings.Shininess);
|
||||||
|
|
||||||
let shadowFactor = 1.0;
|
let shadowFactor = 1.0;
|
||||||
|
const if (EnableShadowMapping)
|
||||||
|
{
|
||||||
if (light.invShadowMapSize.x > 0.0)
|
if (light.invShadowMapSize.x > 0.0)
|
||||||
{
|
{
|
||||||
let shadowCoords = input.lightProjPos[i].xyz / input.lightProjPos[i].w;
|
let shadowCoords = input.lightProjPos[i].xyz / input.lightProjPos[i].w;
|
||||||
|
|
@ -289,6 +295,7 @@ fn main(input: VertToFrag) -> FragOut
|
||||||
}
|
}
|
||||||
shadowFactor /= 9.0;
|
shadowFactor /= 9.0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lightAmbient += attenuationFactor * light.color.rgb * lightAmbientFactor * settings.AmbientColor.rgb;
|
lightAmbient += attenuationFactor * light.color.rgb * lightAmbientFactor * settings.AmbientColor.rgb;
|
||||||
lightDiffuse += shadowFactor * attenuationFactor * lambert * light.color.rgb * lightDiffuseFactor;
|
lightDiffuse += shadowFactor * attenuationFactor * lambert * light.color.rgb * lightDiffuseFactor;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue