Skip to content

Commit

Permalink
fix rgb camera for mac
Browse files Browse the repository at this point in the history
- only 8-bit colors for mac
- use glsl 330 for mac
  • Loading branch information
JakobSpahn committed Nov 13, 2024
1 parent 0dd67b8 commit 414e7d9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
7 changes: 5 additions & 2 deletions metadrive/component/sensors/rgb_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion metadrive/third_party/simplepbr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 414e7d9

Please sign in to comment.