Skip to content

Commit

Permalink
check_visibility is required for the entity that is renderable
Browse files Browse the repository at this point in the history
As a result of [12582](bevyengine/bevy#12582) `check_visibility` must be implemented for the "renderable" tilemap entities. Doing this is trivial by taking advantage of the
existing `check_visibility` type arguments, which accept a [`QF: QueryFilter + 'static`](https://docs.rs/bevy/0.14.0-rc.2/bevy/render/view/fn.check_visibility.html).

The same `QueryFilter`` is used when checking `VisibleEntities`. I've chosen `With<TilemapRenderSettings` because presumably if the entity doesn't have a `TilemapRenderSettings` then it will not be rendering, but this could be as sophisticated or simple as we want.

For example `WithLight` is currently implemented as

```rust
pub type WithLight = Or<(With<PointLight>, With<SpotLight>, With<DirectionalLight>)>;
```
  • Loading branch information
ChristopherBiscardi committed Jun 7, 2024
1 parent 1386dc2 commit 1b087f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/render/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use bevy::{
},
renderer::RenderDevice,
texture::{FallbackImage, GpuImage},
view::{ExtractedView, ViewUniforms, VisibleEntities, WithMesh},
view::{ExtractedView, ViewUniforms, VisibleEntities},
Extract, Render, RenderApp, RenderSet,
},
utils::{HashMap, HashSet},
Expand All @@ -27,7 +27,7 @@ use std::{hash::Hash, marker::PhantomData};
#[cfg(not(feature = "atlas"))]
use bevy::render::renderer::RenderQueue;

use crate::prelude::TilemapId;
use crate::prelude::{TilemapId, TilemapRenderSettings};

use super::{
chunk::{ChunkId, RenderChunk2dStorage},
Expand Down Expand Up @@ -421,7 +421,7 @@ pub fn queue_material_tilemap_meshes<M: MaterialTilemap>(

for (entity, chunk_id, transform, tilemap_id) in standard_tilemap_meshes.iter() {
if !visible_entities
.iter::<WithMesh>()
.iter::<With<TilemapRenderSettings>>()
.any(|&entity| entity.index() == tilemap_id.0.index())
{
continue;
Expand Down Expand Up @@ -538,7 +538,7 @@ pub fn bind_material_tilemap_meshes<M: MaterialTilemap>(

for (chunk_id, tilemap_id) in standard_tilemap_meshes.iter() {
if !visible_entities
.iter::<WithMesh>()
.iter::<With<TilemapRenderSettings>>()
.any(|&entity| entity.index() == tilemap_id.0.index())
{
continue;
Expand Down
13 changes: 12 additions & 1 deletion src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bevy::{
render_phase::AddRenderCommand,
render_resource::{FilterMode, SpecializedRenderPipelines, VertexFormat},
texture::ImageSamplerDescriptor,
view::{check_visibility, VisibilitySystems},
Render, RenderApp, RenderSet,
},
};
Expand All @@ -18,7 +19,10 @@ use bevy::render::renderer::RenderDevice;
#[cfg(not(feature = "atlas"))]
use bevy::render::texture::GpuImage;

use crate::tiles::{TilePos, TileStorage};
use crate::{
prelude::TilemapRenderSettings,
tiles::{TilePos, TileStorage},
};
use crate::{
prelude::TilemapTexture,
render::{
Expand Down Expand Up @@ -211,6 +215,13 @@ impl Plugin for TilemapRenderingPlugin {
Shader::from_wgsl
);

app.add_systems(
PostUpdate,
(check_visibility::<With<TilemapRenderSettings>>)
.in_set(VisibilitySystems::CheckVisibility)
.after(VisibilitySystems::CalculateBounds),
);

let render_app = match app.get_sub_app_mut(RenderApp) {
Some(render_app) => render_app,
None => return,
Expand Down

0 comments on commit 1b087f4

Please sign in to comment.