Deferred renderer: accept material by pointer, casts_shadow is a property of material
This commit is contained in:
parent
6690e23037
commit
5cb74583a4
2 changed files with 23 additions and 23 deletions
|
|
@ -36,6 +36,7 @@ namespace psemek::gfx
|
||||||
bool transparent = false;
|
bool transparent = false;
|
||||||
bool lit = true;
|
bool lit = true;
|
||||||
bool blooming = false;
|
bool blooming = false;
|
||||||
|
bool casts_shadow = true;
|
||||||
|
|
||||||
float diffuse = 1.f;
|
float diffuse = 1.f;
|
||||||
struct
|
struct
|
||||||
|
|
@ -59,8 +60,7 @@ namespace psemek::gfx
|
||||||
// 4 - mat3x4 per-instance transform (used in conjunction with transform)
|
// 4 - mat3x4 per-instance transform (used in conjunction with transform)
|
||||||
|
|
||||||
gfx::mesh const * mesh = nullptr;
|
gfx::mesh const * mesh = nullptr;
|
||||||
material mat;
|
material const * mat = nullptr;
|
||||||
bool casts_shadow = true;
|
|
||||||
geom::box<float, 3> bbox;
|
geom::box<float, 3> bbox;
|
||||||
std::optional<geom::matrix<float, 3, 4>> pre_transform;
|
std::optional<geom::matrix<float, 3, 4>> pre_transform;
|
||||||
std::optional<geom::matrix<float, 3, 4>> post_transform;
|
std::optional<geom::matrix<float, 3, 4>> post_transform;
|
||||||
|
|
|
||||||
|
|
@ -889,15 +889,15 @@ void main()
|
||||||
std::uint32_t mask(deferred_renderer::object const & o)
|
std::uint32_t mask(deferred_renderer::object const & o)
|
||||||
{
|
{
|
||||||
std::uint32_t m = 0;
|
std::uint32_t m = 0;
|
||||||
if (o.mat.color) m |= O_UNIFORM_COLOR;
|
if (o.mat->color) m |= O_UNIFORM_COLOR;
|
||||||
if (o.mat.texture) m |= O_TEXTURE_COLOR;
|
if (o.mat->texture) m |= O_TEXTURE_COLOR;
|
||||||
if (o.mat.transparent) m |= O_TRANSPARENT;
|
if (o.mat->transparent) m |= O_TRANSPARENT;
|
||||||
if (o.mat.lit) m |= O_LIT;
|
if (o.mat->lit) m |= O_LIT;
|
||||||
if (o.casts_shadow) m |= O_CASTS_SHADOW;
|
if (o.mat->casts_shadow) m |= O_CASTS_SHADOW;
|
||||||
if (o.pre_transform) m |= O_PRE_TRANSFORM;
|
if (o.pre_transform) m |= O_PRE_TRANSFORM;
|
||||||
if (o.post_transform) m |= O_POST_TRANSFORM;
|
if (o.post_transform) m |= O_POST_TRANSFORM;
|
||||||
if (o.mesh->is_instanced()) m |= O_INSTANCED;
|
if (o.mesh->is_instanced()) m |= O_INSTANCED;
|
||||||
if (o.mat.blooming) m |= O_BLOOMING;
|
if (o.mat->blooming) m |= O_BLOOMING;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -923,19 +923,19 @@ void main()
|
||||||
auto const & o = objects[i];
|
auto const & o = objects[i];
|
||||||
assert(o.mesh);
|
assert(o.mesh);
|
||||||
|
|
||||||
if (o.mat.lit && o.mat.transparent)
|
if (o.mat->lit && o.mat->transparent)
|
||||||
throw std::runtime_error("Materials that are both tit & transparent are not supported");
|
throw std::runtime_error("Materials that are both tit & transparent are not supported");
|
||||||
|
|
||||||
if (o.mat.lit && o.mat.blooming)
|
if (o.mat->lit && o.mat->blooming)
|
||||||
throw std::runtime_error("Materials that are both tit & blooming are not supported");
|
throw std::runtime_error("Materials that are both tit & blooming are not supported");
|
||||||
|
|
||||||
if (o.casts_shadow && o.mat.transparent)
|
if (o.mat->casts_shadow && o.mat->transparent)
|
||||||
throw std::runtime_error("Transparent objects cannot cast shadow");
|
throw std::runtime_error("Transparent objects cannot cast shadow");
|
||||||
|
|
||||||
objects_by_mask[mask(objects[i])].push_back(i);
|
objects_by_mask[mask(objects[i])].push_back(i);
|
||||||
|
|
||||||
if (o.mat.lit) lit_bbox |= o.bbox;
|
if (o.mat->lit) lit_bbox |= o.bbox;
|
||||||
if (o.casts_shadow) casts_shadow_bbox |= o.bbox;
|
if (o.mat->casts_shadow) casts_shadow_bbox |= o.bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize g-buffer if needed
|
// Resize g-buffer if needed
|
||||||
|
|
@ -1081,12 +1081,12 @@ void main()
|
||||||
auto const & o = objects[i];
|
auto const & o = objects[i];
|
||||||
|
|
||||||
if (mask & O_UNIFORM_COLOR)
|
if (mask & O_UNIFORM_COLOR)
|
||||||
impl().g_buffer_pass_program["u_color"] = *o.mat.color;
|
impl().g_buffer_pass_program["u_color"] = *o.mat->color;
|
||||||
|
|
||||||
if (mask & O_TEXTURE_COLOR)
|
if (mask & O_TEXTURE_COLOR)
|
||||||
{
|
{
|
||||||
gl::ActiveTexture(gl::TEXTURE0);
|
gl::ActiveTexture(gl::TEXTURE0);
|
||||||
o.mat.texture->bind();
|
o.mat->texture->bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & O_PRE_TRANSFORM)
|
if (mask & O_PRE_TRANSFORM)
|
||||||
|
|
@ -1095,7 +1095,7 @@ void main()
|
||||||
if (mask & O_POST_TRANSFORM)
|
if (mask & O_POST_TRANSFORM)
|
||||||
impl().g_buffer_pass_program["u_post_transform"] = *o.post_transform;
|
impl().g_buffer_pass_program["u_post_transform"] = *o.post_transform;
|
||||||
|
|
||||||
impl().g_buffer_pass_program["u_material"] = geom::vector<float, 3>{o.mat.diffuse, o.mat.specular.intensity, o.mat.specular.shininess};
|
impl().g_buffer_pass_program["u_material"] = geom::vector<float, 3>{o.mat->diffuse, o.mat->specular.intensity, o.mat->specular.shininess};
|
||||||
|
|
||||||
o.mesh->draw();
|
o.mesh->draw();
|
||||||
}
|
}
|
||||||
|
|
@ -1131,12 +1131,12 @@ void main()
|
||||||
auto const & o = objects[i];
|
auto const & o = objects[i];
|
||||||
|
|
||||||
if (mask & O_UNIFORM_COLOR)
|
if (mask & O_UNIFORM_COLOR)
|
||||||
impl().transparent_pass_program["u_color"] = *o.mat.color;
|
impl().transparent_pass_program["u_color"] = *o.mat->color;
|
||||||
|
|
||||||
if (mask & O_TEXTURE_COLOR)
|
if (mask & O_TEXTURE_COLOR)
|
||||||
{
|
{
|
||||||
gl::ActiveTexture(gl::TEXTURE0);
|
gl::ActiveTexture(gl::TEXTURE0);
|
||||||
o.mat.texture->bind();
|
o.mat->texture->bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & O_PRE_TRANSFORM)
|
if (mask & O_PRE_TRANSFORM)
|
||||||
|
|
@ -1183,12 +1183,12 @@ void main()
|
||||||
auto const & o = objects[i];
|
auto const & o = objects[i];
|
||||||
|
|
||||||
if (mask & O_UNIFORM_COLOR)
|
if (mask & O_UNIFORM_COLOR)
|
||||||
impl().bloom_pass_program["u_color"] = *o.mat.color;
|
impl().bloom_pass_program["u_color"] = *o.mat->color;
|
||||||
|
|
||||||
if (mask & O_TEXTURE_COLOR)
|
if (mask & O_TEXTURE_COLOR)
|
||||||
{
|
{
|
||||||
gl::ActiveTexture(gl::TEXTURE0);
|
gl::ActiveTexture(gl::TEXTURE0);
|
||||||
o.mat.texture->bind();
|
o.mat->texture->bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & O_PRE_TRANSFORM)
|
if (mask & O_PRE_TRANSFORM)
|
||||||
|
|
@ -1197,7 +1197,7 @@ void main()
|
||||||
if (mask & O_POST_TRANSFORM)
|
if (mask & O_POST_TRANSFORM)
|
||||||
impl().bloom_pass_program["u_post_transform"] = *o.post_transform;
|
impl().bloom_pass_program["u_post_transform"] = *o.post_transform;
|
||||||
|
|
||||||
impl().bloom_pass_program["u_material"] = geom::vector<float, 3>{o.mat.diffuse, o.mat.specular.intensity, o.mat.specular.shininess};
|
impl().bloom_pass_program["u_material"] = geom::vector<float, 3>{o.mat->diffuse, o.mat->specular.intensity, o.mat->specular.shininess};
|
||||||
|
|
||||||
o.mesh->draw();
|
o.mesh->draw();
|
||||||
}
|
}
|
||||||
|
|
@ -1231,12 +1231,12 @@ void main()
|
||||||
auto const & o = objects[i];
|
auto const & o = objects[i];
|
||||||
|
|
||||||
if (mask & O_UNIFORM_COLOR)
|
if (mask & O_UNIFORM_COLOR)
|
||||||
impl().transparent_pass_program["u_color"] = *o.mat.color;
|
impl().transparent_pass_program["u_color"] = *o.mat->color;
|
||||||
|
|
||||||
if (mask & O_TEXTURE_COLOR)
|
if (mask & O_TEXTURE_COLOR)
|
||||||
{
|
{
|
||||||
gl::ActiveTexture(gl::TEXTURE0);
|
gl::ActiveTexture(gl::TEXTURE0);
|
||||||
o.mat.texture->bind();
|
o.mat->texture->bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & O_PRE_TRANSFORM)
|
if (mask & O_PRE_TRANSFORM)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue