From 414e7d9931187f71f26e20a14efe2a3fb81d1556 Mon Sep 17 00:00:00 2001 From: Jakob Spahn Date: Wed, 13 Nov 2024 14:40:37 +0100 Subject: [PATCH 1/5] fix rgb camera for mac - only 8-bit colors for mac - use glsl 330 for mac --- metadrive/component/sensors/rgb_camera.py | 7 +++++-- metadrive/engine/core/engine_core.py | 13 +++++++++++-- metadrive/third_party/simplepbr/__init__.py | 2 +- .../third_party/simplepbr/shaders/tonemap.frag.glsl | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/metadrive/component/sensors/rgb_camera.py b/metadrive/component/sensors/rgb_camera.py index a00f6d099..7fa83eaa6 100644 --- a/metadrive/component/sensors/rgb_camera.py +++ b/metadrive/component/sensors/rgb_camera.py @@ -6,6 +6,7 @@ from metadrive.constants import CamMask from metadrive.constants import Semantics, CameraTagStateKey from metadrive.third_party.simplepbr import _load_shader_str +from metadrive.utils.utils import is_mac class RGBCamera(BaseCamera): @@ -39,15 +40,17 @@ def _setup_effect(self): self.manager = FilterManager(self.buffer, self.cam) fbprops = p3d.FrameBufferProperties() fbprops.float_color = True - fbprops.set_rgba_bits(16, 16, 16, 16) + # fbprops.set_rgba_bits(16, 16, 16, 16) fbprops.set_depth_bits(24) - fbprops.set_multisamples(16) + # fbprops.set_multisamples(16) self.scene_tex = p3d.Texture() self.scene_tex.set_format(p3d.Texture.F_rgba16) self.scene_tex.set_component_type(p3d.Texture.T_float) self.tonemap_quad = self.manager.render_scene_into(colortex=self.scene_tex, fbprops=fbprops) # defines = {} + if is_mac(): + defines["USE_330"] = True # post_vert_str = _load_shader_str('post.vert', defines) post_frag_str = _load_shader_str('tonemap.frag', defines) diff --git a/metadrive/engine/core/engine_core.py b/metadrive/engine/core/engine_core.py index e4978e9c5..3febf3595 100644 --- a/metadrive/engine/core/engine_core.py +++ b/metadrive/engine/core/engine_core.py @@ -104,11 +104,14 @@ class EngineCore(ShowBase.ShowBase): if is_mac(): # latest macOS supported openGL version loadPrcFileData("", "gl-version 4 1") - loadPrcFileData("", " framebuffer-srgb truein") + loadPrcFileData("", "color-bits 8 8 8") + loadPrcFileData("", "alpha-bits 8") else: # anti-aliasing does not work on macOS loadPrcFileData("", "framebuffer-multisample 1") loadPrcFileData("", "multisamples 8") + loadPrcFileData("", "color-bits 16 16 16") + loadPrcFileData("", "alpha-bits 16") def __init__(self, global_config): # if EngineCore.global_config is not None: @@ -294,7 +297,13 @@ def __init__(self, global_config): if self.global_config["daytime"] is not None: self.render_pipeline.daytime_mgr.time = self.global_config["daytime"] else: - if not is_mac(): + if is_mac(): + self.pbrpipe = init( + msaa_samples = 0, + # use_hardware_skinning=True, + use_330=True + ) + else: self.pbrpipe = init( msaa_samples=16, use_hardware_skinning=True, diff --git a/metadrive/third_party/simplepbr/__init__.py b/metadrive/third_party/simplepbr/__init__.py index 957eb022e..21e36c323 100644 --- a/metadrive/third_party/simplepbr/__init__.py +++ b/metadrive/third_party/simplepbr/__init__.py @@ -265,7 +265,7 @@ def _setup_tonemapping(self): fbprops = p3d.FrameBufferProperties() fbprops.float_color = True - fbprops.set_rgba_bits(16, 16, 16, 16) + # fbprops.set_rgba_bits(16, 16, 16, 16) fbprops.set_depth_bits(24) fbprops.set_multisamples(self.msaa_samples) scene_tex = p3d.Texture() diff --git a/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl b/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl index b728d25cb..cf33e629b 100644 --- a/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl +++ b/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl @@ -10,7 +10,7 @@ out vec4 o_color; #endif void main() { - vec3 color = texture2D(tex, v_texcoord).rgb; + vec3 color = texture(tex, v_texcoord).rgb; color *= exposure; color = max(vec3(0.0), color - vec3(0.004)); From 1689fb72826b42a0f60bd47e81fdbd62449f6b2b Mon Sep 17 00:00:00 2001 From: Jakob Spahn Date: Thu, 21 Nov 2024 10:01:54 +0100 Subject: [PATCH 2/5] macos 4x antialiasing --- metadrive/engine/core/engine_core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/metadrive/engine/core/engine_core.py b/metadrive/engine/core/engine_core.py index 3febf3595..37f98a7f7 100644 --- a/metadrive/engine/core/engine_core.py +++ b/metadrive/engine/core/engine_core.py @@ -106,8 +106,9 @@ class EngineCore(ShowBase.ShowBase): loadPrcFileData("", "gl-version 4 1") loadPrcFileData("", "color-bits 8 8 8") loadPrcFileData("", "alpha-bits 8") + loadPrcFileData("", "framebuffer-multisample 1") + loadPrcFileData("", "multisamples 4") else: - # anti-aliasing does not work on macOS loadPrcFileData("", "framebuffer-multisample 1") loadPrcFileData("", "multisamples 8") loadPrcFileData("", "color-bits 16 16 16") @@ -299,7 +300,7 @@ def __init__(self, global_config): else: if is_mac(): self.pbrpipe = init( - msaa_samples = 0, + msaa_samples = 4, # use_hardware_skinning=True, use_330=True ) From 75dbc4b8d5c4643ae21d116d9ebd28e22d9e704c Mon Sep 17 00:00:00 2001 From: Jakob Spahn Date: Mon, 16 Dec 2024 11:06:52 +0100 Subject: [PATCH 3/5] no more need to enforce 8-bit colors on mac --- metadrive/component/sensors/rgb_camera.py | 2 +- metadrive/engine/core/engine_core.py | 4 ---- metadrive/third_party/simplepbr/__init__.py | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/metadrive/component/sensors/rgb_camera.py b/metadrive/component/sensors/rgb_camera.py index 7fa83eaa6..7dee63e44 100644 --- a/metadrive/component/sensors/rgb_camera.py +++ b/metadrive/component/sensors/rgb_camera.py @@ -40,7 +40,7 @@ def _setup_effect(self): self.manager = FilterManager(self.buffer, self.cam) fbprops = p3d.FrameBufferProperties() fbprops.float_color = True - # fbprops.set_rgba_bits(16, 16, 16, 16) + fbprops.set_rgba_bits(16, 16, 16, 16) fbprops.set_depth_bits(24) # fbprops.set_multisamples(16) self.scene_tex = p3d.Texture() diff --git a/metadrive/engine/core/engine_core.py b/metadrive/engine/core/engine_core.py index 37f98a7f7..c76ebf5b9 100644 --- a/metadrive/engine/core/engine_core.py +++ b/metadrive/engine/core/engine_core.py @@ -104,15 +104,11 @@ class EngineCore(ShowBase.ShowBase): if is_mac(): # latest macOS supported openGL version loadPrcFileData("", "gl-version 4 1") - loadPrcFileData("", "color-bits 8 8 8") - loadPrcFileData("", "alpha-bits 8") loadPrcFileData("", "framebuffer-multisample 1") loadPrcFileData("", "multisamples 4") else: loadPrcFileData("", "framebuffer-multisample 1") loadPrcFileData("", "multisamples 8") - loadPrcFileData("", "color-bits 16 16 16") - loadPrcFileData("", "alpha-bits 16") def __init__(self, global_config): # if EngineCore.global_config is not None: diff --git a/metadrive/third_party/simplepbr/__init__.py b/metadrive/third_party/simplepbr/__init__.py index 21e36c323..957eb022e 100644 --- a/metadrive/third_party/simplepbr/__init__.py +++ b/metadrive/third_party/simplepbr/__init__.py @@ -265,7 +265,7 @@ def _setup_tonemapping(self): fbprops = p3d.FrameBufferProperties() fbprops.float_color = True - # fbprops.set_rgba_bits(16, 16, 16, 16) + fbprops.set_rgba_bits(16, 16, 16, 16) fbprops.set_depth_bits(24) fbprops.set_multisamples(self.msaa_samples) scene_tex = p3d.Texture() From 803a824f5d88f9a3d4f64843d692477a4867c932 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Thu, 19 Dec 2024 10:54:28 -0800 Subject: [PATCH 4/5] more samples --- metadrive/component/sensors/rgb_camera.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/metadrive/component/sensors/rgb_camera.py b/metadrive/component/sensors/rgb_camera.py index 7dee63e44..d6bba1f95 100644 --- a/metadrive/component/sensors/rgb_camera.py +++ b/metadrive/component/sensors/rgb_camera.py @@ -42,7 +42,10 @@ def _setup_effect(self): fbprops.float_color = True fbprops.set_rgba_bits(16, 16, 16, 16) fbprops.set_depth_bits(24) - # fbprops.set_multisamples(16) + if is_mac(): + fbprops.set_multisamples(4) + else: + fbprops.set_multisamples(16) self.scene_tex = p3d.Texture() self.scene_tex.set_format(p3d.Texture.F_rgba16) self.scene_tex.set_component_type(p3d.Texture.T_float) From a201fe019fbc96cb03068256e77eba0d3765e63a Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Thu, 19 Dec 2024 10:56:01 -0800 Subject: [PATCH 5/5] what is this, 1990? --- metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl b/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl index cf33e629b..297b6f487 100644 --- a/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl +++ b/metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl @@ -1,13 +1,11 @@ -#version 120 +#version 330 uniform sampler2D tex; uniform float exposure; varying vec2 v_texcoord; -#ifdef USE_330 out vec4 o_color; -#endif void main() { vec3 color = texture(tex, v_texcoord).rgb; @@ -16,9 +14,5 @@ void main() { color = max(vec3(0.0), color - vec3(0.004)); color = (color * (vec3(6.2) * color + vec3(0.5))) / (color * (vec3(6.2) * color + vec3(1.7)) + vec3(0.06)); -#ifdef USE_330 o_color = vec4(color, 1.0); -#else - gl_FragColor = vec4(color, 1.0); -#endif }