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

Merged
merged 5 commits into from
Dec 19, 2024
Merged
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
8 changes: 7 additions & 1 deletion 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 @@ -41,13 +42,18 @@ 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)
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
12 changes: 9 additions & 3 deletions metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class EngineCore(ShowBase.ShowBase):
if is_mac():
# latest macOS supported openGL version
loadPrcFileData("", "gl-version 4 1")
loadPrcFileData("", " framebuffer-srgb truein")
loadPrcFileData("", "framebuffer-multisample 1")
loadPrcFileData("", "multisamples 4")
else:
# anti-aliasing does not work on macOS
loadPrcFileData("", "framebuffer-multisample 1")
loadPrcFileData("", "multisamples 8")

Expand Down Expand Up @@ -294,7 +294,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
10 changes: 2 additions & 8 deletions metadrive/third_party/simplepbr/shaders/tonemap.frag.glsl
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
#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 = texture2D(tex, v_texcoord).rgb;
vec3 color = texture(tex, v_texcoord).rgb;

color *= exposure;
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
}
Loading