Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make anisotropic_filtering configurable #749

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metadrive/component/block/base_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
self.side_texture.setWrapU(Texture.WM_repeat)
self.side_texture.setWrapV(Texture.WM_repeat)
self.side_texture.setMinfilter(SamplerState.FT_linear_mipmap_linear)
self.side_texture.setAnisotropicDegree(8)
self.side_texture.setAnisotropicDegree(8 if self.engine.global_config["anisotropic_filtering"] else 1)
self.side_normal = self.loader.loadTexture(AssetLoader.file_path("textures", "sidewalk", "normal.png"))
# self.side_normal.set_format(Texture.F_srgb)
self.side_normal.setWrapU(Texture.WM_repeat)
Expand Down
2 changes: 1 addition & 1 deletion metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def __init__(self, global_config):
use_330=False
)

self.sky_box = SkyBox(not self.global_config["show_skybox"])
self.sky_box = SkyBox(not self.global_config["show_skybox"], self.global_config["anisotropic_filtering"])
self.sky_box.attach_to_world(self.render, self.physics_world)

self.world_light = Light()
Expand Down
4 changes: 2 additions & 2 deletions metadrive/engine/core/sky_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SkyBox(BaseObject):
ROTATION_MAX = 5000
SEMANTIC_LABEL = Semantics.SKY.label

def __init__(self, pure_background: bool = False):
def __init__(self, pure_background: bool = False, use_anisotropic_filtering: bool = True):
super(SkyBox, self).__init__(random_seed=0)
self._accumulate = 0
self.f = 1
Expand All @@ -30,7 +30,7 @@ def __init__(self, pure_background: bool = False):
skybox_texture.set_magfilter(SamplerState.FT_linear)
skybox_texture.set_wrap_u(SamplerState.WM_repeat)
skybox_texture.set_wrap_v(SamplerState.WM_mirror)
skybox_texture.set_anisotropic_degree(16)
skybox_texture.set_anisotropic_degree(16 if use_anisotropic_filtering else 1)
skybox.set_texture(skybox_texture)

gles = ConfigVariableString("load-display").getValue()
Expand Down
7 changes: 4 additions & 3 deletions metadrive/engine/core/terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ def __init__(self, show_terrain, engine):

self.render = self.render and show_terrain

self.use_anisotropic_filtering = engine.global_config["anisotropic_filtering"]

if self.use_mesh_terrain or self.render:
self._load_height_field_image(engine)

if self.render:
# if engine.use_render_pipeline:
self._load_mesh_terrain_textures(engine)
self._load_mesh_terrain_textures(engine, anisotropic_degree= 16 if self.use_anisotropic_filtering else 1)
self._mesh_terrain_node = ShaderTerrainMesh()
# prepare semantic texture
semantic_size = self._semantic_map_size * self._semantic_map_pixel_per_meter
Expand Down Expand Up @@ -385,7 +387,7 @@ def _generate_card_terrain(self):
card.setTexture(self.ts_color, self.terrain_texture)
# card.setTexture(self.ts_normal, self.terrain_normal)
self.terrain_texture.setMinfilter(SamplerState.FT_linear_mipmap_linear)
self.terrain_texture.setAnisotropicDegree(8)
self.terrain_texture.setAnisotropicDegree(8 if self.use_anisotropic_filtering else 1)
card.setQuat(LQuaternionf(math.cos(-math.pi / 4), math.sin(-math.pi / 4), 0, 0))

def _load_height_field_image(self, engine):
Expand Down Expand Up @@ -490,7 +492,6 @@ def _load_mesh_terrain_textures(self, engine, anisotropic_degree=16, filter_type
v_wrap = Texture.WMRepeat
u_warp = Texture.WMMirror
filter_type = Texture.FTLinearMipmapLinear
anisotropic_degree = 16
for tex in [self.road_texture_rough, self.road_texture, self.road_texture_normal]:
tex.set_wrap_u(u_warp)
tex.set_wrap_v(v_wrap)
Expand Down
2 changes: 2 additions & 0 deletions metadrive/envs/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@
preload_models=True,
# model compression increasing the launch time
disable_model_compression=True,
# Whether to use anisotropic filtering. Very expensive option.
anisotropic_filtering=True,

# ===== Terrain =====
# The size of the square map region, which is centered at [0, 0]. The map objects outside it are culled.
Expand Down
Loading