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

Fix rgb camera for mac #6

Open
wants to merge 2 commits 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
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
16 changes: 13 additions & 3 deletions metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ 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")
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")
loadPrcFileData("", "alpha-bits 16")

def __init__(self, global_config):
# if EngineCore.global_config is not None:
Expand Down Expand Up @@ -294,7 +298,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 = 4,
# 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
Loading