From 964e7848bacc3a031d4eea0f626aea1ce28cc65a Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Fri, 16 Aug 2024 14:40:30 -0700 Subject: [PATCH] make anisotropic_filtering configurable --- metadrive/component/block/base_block.py | 2 +- metadrive/engine/core/engine_core.py | 2 +- metadrive/engine/core/sky_box.py | 4 ++-- metadrive/engine/core/terrain.py | 7 ++++--- metadrive/envs/base_env.py | 2 ++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/metadrive/component/block/base_block.py b/metadrive/component/block/base_block.py index 73fc36c5f..0bcac15fb 100644 --- a/metadrive/component/block/base_block.py +++ b/metadrive/component/block/base_block.py @@ -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) diff --git a/metadrive/engine/core/engine_core.py b/metadrive/engine/core/engine_core.py index cdd529939..aad6fd4b9 100644 --- a/metadrive/engine/core/engine_core.py +++ b/metadrive/engine/core/engine_core.py @@ -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() diff --git a/metadrive/engine/core/sky_box.py b/metadrive/engine/core/sky_box.py index 99b0d970f..1155e7e62 100644 --- a/metadrive/engine/core/sky_box.py +++ b/metadrive/engine/core/sky_box.py @@ -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 @@ -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() diff --git a/metadrive/engine/core/terrain.py b/metadrive/engine/core/terrain.py index 9f1c67658..12094b52b 100644 --- a/metadrive/engine/core/terrain.py +++ b/metadrive/engine/core/terrain.py @@ -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 @@ -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): @@ -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) diff --git a/metadrive/envs/base_env.py b/metadrive/envs/base_env.py index 8846238d9..11acc42b5 100644 --- a/metadrive/envs/base_env.py +++ b/metadrive/envs/base_env.py @@ -209,6 +209,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.