Move filament renderer out of experimental into src/render/filament.

Also:
- renames the main header file to mjrfilament.h.
- moves filament_util under a "support" folder.
PiperOrigin-RevId: 930448415
Change-Id: Iad89756aaf1ddf4c3e67e1afc3a13776f71fa20f
This commit is contained in:
Haroon Qureshi
2026-06-11 04:42:42 -07:00
committed by Copybara-Service
parent 1aaced190a
commit 96781fa793
76 changed files with 521 additions and 495 deletions
+1
View File
@@ -171,6 +171,7 @@ endif()
add_subdirectory(src/render/noop)
if(MUJOCO_USE_FILAMENT)
add_subdirectory(src/render/filament)
add_subdirectory(src/experimental/filament)
endif()
+9 -130
View File
@@ -14,47 +14,13 @@
cmake_minimum_required(VERSION 3.16)
set(MUJOCO_FILAMENT_TARGET_NAME mujoco_filament)
set(MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME mujoco_filament_experimental)
add_library(${MUJOCO_FILAMENT_TARGET_NAME} STATIC)
target_compile_definitions(${MUJOCO_FILAMENT_TARGET_NAME} PRIVATE MJ_STATIC)
add_library(${MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME} STATIC)
target_compile_definitions(${MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME} PRIVATE MJ_STATIC)
target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
target_sources(${MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME}
PUBLIC
render_context_filament.h
render_context_filament.cc
render_context_filament_cpp.h
filament_util.h
filament_util.cc
filament/builtins.cc
filament/builtins.h
filament/color_grading_options.cc
filament/color_grading_options.h
filament/filament_context.cc
filament/filament_context.h
filament/filament_platform_factory.cc
filament/filament_platform_factory.h
filament/imgui_editor.cc
filament/light.cc
filament/light.h
filament/material_manager.cc
filament/material_manager.h
filament/mesh.cc
filament/mesh.h
filament/object_manager.cc
filament/object_manager.h
filament/outliner.cc
filament/outliner.h
filament/reflection_manager.cc
filament/reflection_manager.h
filament/render_target.cc
filament/render_target.h
filament/renderable.cc
filament/renderable.h
filament/scene_view.cc
filament/scene_view.h
filament/texture.cc
filament/texture.h
compat/light_manager.cc
compat/light_manager.h
compat/model_objects.cc
@@ -65,107 +31,20 @@ target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
compat/scene_geom_util.h
)
if(MUJOCO_USE_FILAMENT_MJR_COMPAT)
target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
target_sources(${MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME}
PUBLIC
mjr_compat.cc
)
endif()
target_include_directories(${MUJOCO_FILAMENT_TARGET_NAME}
target_include_directories(${MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME}
PUBLIC
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
)
include(third_party_deps/dear_imgui)
include(third_party_deps/filament)
target_link_libraries(${MUJOCO_FILAMENT_TARGET_NAME}
dear_imgui
filament
image # provided by filament
ktxreader # provided by filament
target_link_libraries(${MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME}
mujoco_filament
)
add_library(mujoco::filament ALIAS ${MUJOCO_FILAMENT_TARGET_NAME})
# The "mujoco::filament" library needs access to some assets (e.g. filament
# material shaders) in order to do rendering. As such, you must also include
# the assets under MUJOCO_FILAMENT_ASSETS_DIR in your project. As part of
# the filament library configuration, you will provide a function that the
# library will use to load these assets.
set(ASSETS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/assets")
set(OUTPUT_ASSETS_DIR "${CMAKE_CURRENT_BINARY_DIR}/assets")
file(MAKE_DIRECTORY ${OUTPUT_ASSETS_DIR})
file(COPY
"${ASSETS_DIR}/ibl.ktx"
DESTINATION ${OUTPUT_ASSETS_DIR}
)
set(MATC_EXECUTABLE matc)
set(MATERIAL_FILES
pbr.mat
pbr_transparent.mat
pbr_packed.mat
pbr_packed_transparent.mat
phong_2d_fade.mat
phong_2d.mat
phong_2d_reflect.mat
phong_2d_uv_fade.mat
phong_2d_uv.mat
phong_2d_uv_reflect.mat
phong_color_fade.mat
phong_color.mat
phong_color_reflect.mat
phong_cube_fade.mat
phong_cube.mat
phong_cube_reflect.mat
outline_composite.mat
outline_flatten.mat
outline_jumpflood.mat
unlit_decor.mat
unlit_depth.mat
unlit_segmentation.mat
unlit_ui.mat
)
foreach(MATERIAL_FILE ${MATERIAL_FILES})
get_filename_component(MATERIAL_NAME ${MATERIAL_FILE} NAME_WE)
set(INPUT_FILE "${ASSETS_DIR}/${MATERIAL_FILE}")
set(OUTPUT_FILE "${OUTPUT_ASSETS_DIR}/${MATERIAL_NAME}.filamat")
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(PRECOMPILED_FILE "${MUJOCO_NATIVE_BUILD_DIR}/src/experimental/filament/assets/${MATERIAL_NAME}.filamat")
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${CMAKE_COMMAND} -E copy
${PRECOMPILED_FILE}
${OUTPUT_FILE}
DEPENDS ${PRECOMPILED_FILE}
COMMENT "Copying precompiled material ${MATERIAL_NAME}.filamat"
)
else()
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${MATC_EXECUTABLE}
--platform=all
--api=vulkan
--api=opengl
--variant-filter skinning
--optimize-size
--output ${OUTPUT_FILE}
${INPUT_FILE}
DEPENDS ${INPUT_FILE}
DEPENDS matc
COMMENT "Compiling ${MATERIAL_FILE}"
)
endif()
list(APPEND MUJOCO_FILAMENT_ASSET_FILES ${OUTPUT_FILE})
endforeach()
list(APPEND MUJOCO_FILAMENT_ASSET_FILES "${OUTPUT_ASSETS_DIR}/ibl.ktx")
add_custom_target(mujoco_filament_assets DEPENDS ${MUJOCO_FILAMENT_ASSET_FILES})
add_dependencies(${MUJOCO_FILAMENT_TARGET_NAME} mujoco_filament_assets)
set(MUJOCO_FILAMENT_ASSETS_DIR ${OUTPUT_ASSETS_DIR})
add_library(mujoco::filament_experimental ALIAS ${MUJOCO_FILAMENT_EXPERIMENTAL_TARGET_NAME})
@@ -24,9 +24,9 @@
#include <math/vec4.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/compat/model_objects.h"
#include "experimental/filament/filament_util.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -18,8 +18,8 @@
#include <vector>
#include "experimental/filament/compat/model_objects.h"
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco {
@@ -29,9 +29,9 @@
#include <math/vec3.h>
#include <math/vec4.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament_util.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -19,8 +19,8 @@
#include <mujoco/mjmodel.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco {
@@ -19,18 +19,18 @@
#include <utility>
#include <math/TMatHelpers.h>
#include <math/TVecHelpers.h>
#include <math/mat4.h>
#include <math/mathfwd.h>
#include <math/TVecHelpers.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/compat/light_manager.h"
#include "experimental/filament/compat/model_objects.h"
#include "experimental/filament/compat/scene_geom_util.h"
#include "experimental/filament/filament_util.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -26,8 +26,8 @@
#include <mujoco/mujoco.h>
#include "experimental/filament/compat/light_manager.h"
#include "experimental/filament/compat/model_objects.h"
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco {
@@ -22,8 +22,8 @@
#include <mujoco/mjvisualize.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/compat/model_objects.h"
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco {
@@ -18,8 +18,8 @@
#include <mujoco/mjvisualize.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/compat/model_objects.h"
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco {
+2 -2
View File
@@ -18,8 +18,8 @@
#include <mujoco/mujoco.h>
#include "experimental/filament/compat/scene_bridge.h"
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
// This library implements the entirety of mujoco's mjr API. You can link this
// library with your application (instead of the "classic" mujoco renderer) to
+1
View File
@@ -104,6 +104,7 @@ target_link_libraries(${MUJOCO_PLATFORM_TARGET_NAME}
dear_imgui_stdlib
implot
mujoco::filament
mujoco::filament_experimental
webp
SDL2::SDL2-static
${MUJOCO_PLATFORM_RENDER_DEPS}
+2 -2
View File
@@ -28,12 +28,12 @@
#include "experimental/platform/hal/egl_utils.h"
#endif
#include "experimental/filament/compat/scene_bridge.h"
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "experimental/platform/hal/graphics_mode.h"
#include "experimental/platform/ux/imgui_bridge.h"
#include "experimental/platform/ux/imgui_widgets.h"
#include "experimental/platform/ux/plugin.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco::platform {
+2 -2
View File
@@ -23,10 +23,10 @@
#include <mujoco/mujoco.h>
#include "experimental/filament/compat/scene_bridge.h"
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "experimental/platform/hal/graphics_mode.h"
#include "experimental/platform/ux/imgui_bridge.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco::platform {
+2 -2
View File
@@ -25,8 +25,8 @@
#include <math/mat3.h>
#include <math/vec3.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco {
+2 -2
View File
@@ -20,8 +20,8 @@
#include <vector>
#include <imgui.h>
#include "experimental/filament/render_context_filament.h"
#include "experimental/filament/render_context_filament_cpp.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/mjrfilament_cpp.h"
namespace mujoco {
+1 -1
View File
@@ -82,7 +82,7 @@ function(configure_studio_target TARGET_NAME)
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_directory
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../src/experimental/filament/assets
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../src/render/filament/assets
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets
COMMENT "Copying Filament assets to build directory"
)
+157
View File
@@ -0,0 +1,157 @@
# Copyright 2025 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.16)
set(MUJOCO_FILAMENT_TARGET_NAME mujoco_filament)
add_library(${MUJOCO_FILAMENT_TARGET_NAME} STATIC)
target_compile_definitions(${MUJOCO_FILAMENT_TARGET_NAME} PRIVATE MJ_STATIC)
target_sources(${MUJOCO_FILAMENT_TARGET_NAME}
PUBLIC
mjrfilament.h
mjrfilament.cc
mjrfilament_cpp.h
core/builtins.cc
core/builtins.h
core/color_grading_options.cc
core/color_grading_options.h
core/filament_context.cc
core/filament_context.h
core/filament_platform_factory.cc
core/filament_platform_factory.h
core/imgui_editor.cc
core/light.cc
core/light.h
core/material_manager.cc
core/material_manager.h
core/mesh.cc
core/mesh.h
core/object_manager.cc
core/object_manager.h
core/outliner.cc
core/outliner.h
core/reflection_manager.cc
core/reflection_manager.h
core/render_target.cc
core/render_target.h
core/renderable.cc
core/renderable.h
core/scene_view.cc
core/scene_view.h
core/texture.cc
core/texture.h
support/filament_util.h
support/filament_util.cc
)
target_include_directories(${MUJOCO_FILAMENT_TARGET_NAME}
PUBLIC
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
)
include(third_party_deps/dear_imgui)
include(third_party_deps/filament)
target_link_libraries(${MUJOCO_FILAMENT_TARGET_NAME}
dear_imgui
filament
image # provided by filament
ktxreader # provided by filament
)
add_library(mujoco::filament ALIAS ${MUJOCO_FILAMENT_TARGET_NAME})
# The "mujoco::filament" library needs access to some assets (e.g. filament
# material shaders) in order to do rendering. As such, you must also include
# the assets under MUJOCO_FILAMENT_ASSETS_DIR in your project. As part of
# the filament library configuration, you will provide a function that the
# library will use to load these assets.
set(ASSETS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/assets")
set(OUTPUT_ASSETS_DIR "${CMAKE_CURRENT_BINARY_DIR}/assets")
file(MAKE_DIRECTORY ${OUTPUT_ASSETS_DIR})
file(COPY
"${ASSETS_DIR}/ibl.ktx"
DESTINATION ${OUTPUT_ASSETS_DIR}
)
set(MATC_EXECUTABLE matc)
set(MATERIAL_FILES
pbr.mat
pbr_transparent.mat
pbr_packed.mat
pbr_packed_transparent.mat
phong_2d_fade.mat
phong_2d.mat
phong_2d_reflect.mat
phong_2d_uv_fade.mat
phong_2d_uv.mat
phong_2d_uv_reflect.mat
phong_color_fade.mat
phong_color.mat
phong_color_reflect.mat
phong_cube_fade.mat
phong_cube.mat
phong_cube_reflect.mat
outline_composite.mat
outline_flatten.mat
outline_jumpflood.mat
unlit_decor.mat
unlit_depth.mat
unlit_segmentation.mat
unlit_ui.mat
)
foreach(MATERIAL_FILE ${MATERIAL_FILES})
get_filename_component(MATERIAL_NAME ${MATERIAL_FILE} NAME_WE)
set(INPUT_FILE "${ASSETS_DIR}/${MATERIAL_FILE}")
set(OUTPUT_FILE "${OUTPUT_ASSETS_DIR}/${MATERIAL_NAME}.filamat")
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(PRECOMPILED_FILE "${MUJOCO_NATIVE_BUILD_DIR}/src/render/filament/assets/${MATERIAL_NAME}.filamat")
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${CMAKE_COMMAND} -E copy
${PRECOMPILED_FILE}
${OUTPUT_FILE}
DEPENDS ${PRECOMPILED_FILE}
COMMENT "Copying precompiled material ${MATERIAL_NAME}.filamat"
)
else()
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${MATC_EXECUTABLE}
--platform=all
--api=vulkan
--api=opengl
--variant-filter skinning
--optimize-size
--output ${OUTPUT_FILE}
${INPUT_FILE}
DEPENDS ${INPUT_FILE}
DEPENDS matc
COMMENT "Compiling ${MATERIAL_FILE}"
)
endif()
list(APPEND MUJOCO_FILAMENT_ASSET_FILES ${OUTPUT_FILE})
endforeach()
list(APPEND MUJOCO_FILAMENT_ASSET_FILES "${OUTPUT_ASSETS_DIR}/ibl.ktx")
add_custom_target(mujoco_filament_assets DEPENDS ${MUJOCO_FILAMENT_ASSET_FILES})
add_dependencies(${MUJOCO_FILAMENT_TARGET_NAME} mujoco_filament_assets)
set(MUJOCO_FILAMENT_ASSETS_DIR ${OUTPUT_ASSETS_DIR})
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/builtins.h"
#include "render/filament/core/builtins.h"
#include <cmath>
#include <cstddef>
@@ -26,9 +26,9 @@
#include <math/vec2.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include "experimental/filament/filament_util.h"
#include "experimental/filament/filament/mesh.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/mesh.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -169,7 +169,7 @@ class TriangleBuilder : public BuiltinBuilder {
positions_.emplace_back(1, 0, 0);
positions_.emplace_back(0, 1, 0);
orientations_.resize(positions_.size(), CalculateOrientation({0, 0, 1}));
orientations_.resize(positions_.size(), CalculateOrientation({0, 0, 1}));
indices_.reserve(3);
indices_.emplace_back(0);
@@ -187,13 +187,13 @@ class LineBoxBuilder : public BuiltinBuilder {
positions_.reserve(8);
positions_.emplace_back(-1.0f, -1.0f, -1.0f);
positions_.emplace_back( 1.0f, -1.0f, -1.0f);
positions_.emplace_back(-1.0f, 1.0f, -1.0f);
positions_.emplace_back( 1.0f, 1.0f, -1.0f);
positions_.emplace_back(-1.0f, -1.0f, 1.0f);
positions_.emplace_back( 1.0f, -1.0f, 1.0f);
positions_.emplace_back(-1.0f, 1.0f, 1.0f);
positions_.emplace_back( 1.0f, 1.0f, 1.0f);
positions_.emplace_back(1.0f, -1.0f, -1.0f);
positions_.emplace_back(-1.0f, 1.0f, -1.0f);
positions_.emplace_back(1.0f, 1.0f, -1.0f);
positions_.emplace_back(-1.0f, -1.0f, 1.0f);
positions_.emplace_back(1.0f, -1.0f, 1.0f);
positions_.emplace_back(-1.0f, 1.0f, 1.0f);
positions_.emplace_back(1.0f, 1.0f, 1.0f);
orientations_.resize(positions_.size(), {0, 0, 0, 1});
@@ -622,7 +622,8 @@ class DomeBuilder : public BuiltinBuilder {
}
};
Builtins::Builtins(filament::Engine* engine, int nstack, int nslice, int nquad) {
Builtins::Builtins(filament::Engine* engine, int nstack, int nslice,
int nquad) {
line_ = BuiltinBuilder::Create<LineBuilder>(engine);
plane_ = BuiltinBuilder::Create<PlaneBuilder>(engine, nquad);
triangle_ = BuiltinBuilder::Create<TriangleBuilder>(engine);
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_BUILTINS_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_BUILTINS_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_BUILTINS_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_BUILTINS_H_
#include <memory>
#include <filament/Engine.h>
#include "experimental/filament/filament/mesh.h"
#include "render/filament/core/mesh.h"
namespace mujoco {
@@ -54,4 +54,4 @@ class Builtins {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_BUILTINS_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_BUILTINS_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/color_grading_options.h"
#include "render/filament/core/color_grading_options.h"
#include <memory>
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_COLOR_GRADING_OPTIONS_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_COLOR_GRADING_OPTIONS_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_COLOR_GRADING_OPTIONS_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_COLOR_GRADING_OPTIONS_H_
#include <cstdint>
#include <memory>
@@ -78,4 +78,4 @@ struct ColorGradingOptions {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_COLOR_GRADING_OPTIONS_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_COLOR_GRADING_OPTIONS_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/filament_context.h"
#include "render/filament/core/filament_context.h"
#include <algorithm>
#include <cstdint>
@@ -37,12 +37,12 @@
#include <utils/FixedCapacityVector.h>
#include <utils/compiler.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/filament_platform_factory.h"
#include "experimental/filament/filament/material_manager.h"
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/filament/render_target.h"
#include "experimental/filament/filament/scene_view.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/filament_platform_factory.h"
#include "render/filament/core/material_manager.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/core/render_target.h"
#include "render/filament/core/scene_view.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -96,7 +96,8 @@ mjrfFrameHandle FilamentContext::Render(
material_manager_->BeginFrame();
std::unordered_map<mjrfScene*, std::vector<const mjrfRenderRequest*>> scene_to_requests;
std::unordered_map<mjrfScene*, std::vector<const mjrfRenderRequest*>>
scene_to_requests;
for (const mjrfRenderRequest& request : requests) {
scene_to_requests[request.scene].push_back(&request);
}
@@ -131,7 +132,8 @@ mjrfFrameHandle FilamentContext::Render(
} else {
if (read_requests.empty()) {
mju_error(
"Rendering to a render target without a read request is pointless.");
"Rendering to a render target without a read request is "
"pointless.");
}
const mjrfReadPixelsRequest& read_request = read_requests[0];
@@ -12,21 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_FILAMENT_CONTEXT_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_FILAMENT_CONTEXT_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_FILAMENT_CONTEXT_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_FILAMENT_CONTEXT_H_
#include <cstdint>
#include <span>
#include <memory>
#include <span>
#include <backend/Platform.h>
#include <filament/Engine.h>
#include <filament/Renderer.h>
#include <filament/SwapChain.h>
#include <math/vec4.h>
#include "experimental/filament/filament/material_manager.h"
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/material_manager.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -61,7 +61,9 @@ class FilamentContext : public mjrfContext {
ObjectManager* GetObjectManager() const { return object_manager_.get(); }
MaterialManager* GetMaterialManager() const { return material_manager_.get(); }
MaterialManager* GetMaterialManager() const {
return material_manager_.get();
}
static FilamentContext* downcast(mjrfContext* context) {
return static_cast<FilamentContext*>(context);
@@ -90,4 +92,4 @@ class FilamentContext : public mjrfContext {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_FILAMENT_CONTEXT_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_FILAMENT_CONTEXT_H_
@@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/filament_platform_factory.h"
#include "render/filament/core/filament_platform_factory.h"
#include <memory>
#include <backend/Platform.h>
#include <filament/Engine.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_FILAMENT_PLATFORM_FACTORY_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_FILAMENT_PLATFORM_FACTORY_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_FILAMENT_PLATFORM_FACTORY_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_FILAMENT_PLATFORM_FACTORY_H_
#include <memory>
#include "experimental/filament/render_context_filament.h"
#include <backend/Platform.h>
#include <filament/Engine.h>
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -42,4 +42,4 @@ FilamentPlatformSetup CreateFilamentPlatform(const mjrFilamentConfig& config);
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_FILAMENT_PLATFORM_FACTORY_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_FILAMENT_PLATFORM_FACTORY_H_
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <algorithm>
#include <any>
#include <cstdint>
@@ -33,9 +32,9 @@
#include <math/mathfwd.h>
#include <math/scalar.h>
#include <math/vec3.h>
#include "experimental/filament/filament/color_grading_options.h"
#include "experimental/filament/filament/scene_view.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/color_grading_options.h"
#include "render/filament/core/scene_view.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -243,8 +242,8 @@ void DrawAmbientOcclusionGui(SceneView* scene_view) {
opts.power = std::max(opts.power, 0.0f);
opts.radius = std::clamp(opts.radius, 0.0f, 10.0f);
opts.bias = std::clamp(opts.bias, 0.0f, 0.001f);
opts.ssct.lightConeRad = std::clamp(opts.ssct.lightConeRad, 0.0f,
filament::math::f::PI / 2.0f);
opts.ssct.lightConeRad =
std::clamp(opts.ssct.lightConeRad, 0.0f, filament::math::f::PI / 2.0f);
view->setAmbientOcclusionOptions(opts);
}
@@ -417,10 +416,9 @@ void DrawColorGradingGui(SceneView* scene_view) {
{.step = 0.01f, .fstep = 0.1f});
changed |= Ui("Contrast", &opts.contrast, {.step = 0.01f, .fstep = 0.1f});
changed |= Ui("Vibrance", &opts.vibrance, {.step = 0.01f, .fstep = 0.1f});
changed |= Ui("Saturation", &opts.saturation,
{.step = 0.01f, .fstep = 0.1f});
changed |= Ui("Temperature", &opts.temperature,
{.step = 0.01f, .fstep = 0.1f});
changed |= Ui("Saturation", &opts.saturation, {.step = 0.01f, .fstep = 0.1f});
changed |=
Ui("Temperature", &opts.temperature, {.step = 0.01f, .fstep = 0.1f});
changed |= Ui("Tint", &opts.tint, {.step = 0.01f, .fstep = 0.1f});
changed |= Ui("Out Red", &opts.out_red);
changed |= Ui("Out Green", &opts.out_green);
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/light.h"
#include "render/filament/core/light.h"
#include <numbers>
@@ -25,9 +25,9 @@
#include <utils/Entity.h>
#include <utils/EntityManager.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament_util.h"
#include "experimental/filament/filament/texture.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/texture.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_LIGHT_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_LIGHT_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_LIGHT_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_LIGHT_H_
#include <filament/Engine.h>
#include <filament/Scene.h>
#include <math/vec3.h>
#include <utils/Entity.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -74,4 +74,4 @@ class Light : public mjrfLight {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_LIGHT_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_LIGHT_H_
@@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/material_manager.h"
#include "render/filament/core/material_manager.h"
#include <cstddef>
#include <cstdint>
#include <functional>
@@ -24,11 +25,11 @@
#include <filament/TextureSampler.h>
#include <math/vec4.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament_util.h"
#include "experimental/filament/filament/mesh.h"
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/filament/texture.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/mesh.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/core/texture.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -76,9 +77,7 @@ MaterialManager::~MaterialManager() {
}
}
void MaterialManager::BeginFrame() {
used_keys_.clear();
}
void MaterialManager::BeginFrame() { used_keys_.clear(); }
void MaterialManager::EndFrame() {
if (instances_.size() == used_keys_.size()) {
@@ -229,8 +228,8 @@ filament::MaterialInstance* MaterialManager::GetInstance(MaterialKey key) {
return it->second;
}
void MaterialManager::UpdateMaterialInstance(filament::MaterialInstance* instance,
const mjrfMaterial& material) {
void MaterialManager::UpdateMaterialInstance(
filament::MaterialInstance* instance, const mjrfMaterial& material) {
if (material.scissor[2] != 0 && material.scissor[3] != 0) {
instance->setScissor(material.scissor[0], material.scissor[1],
material.scissor[2], material.scissor[3]);
@@ -311,9 +310,7 @@ void MaterialManager::UpdateMaterialInstance(filament::MaterialInstance* instanc
TrySetTexture("Reflection", material.reflection_texture, mjTEXROLE_USER);
}
ObjectManager* MaterialManager::GetObjectManager() const {
return object_mgr_;
}
ObjectManager* MaterialManager::GetObjectManager() const { return object_mgr_; }
filament::Engine* MaterialManager::GetEngine() const {
return object_mgr_->GetEngine();
@@ -12,18 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MATERIAL_MANAGER_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MATERIAL_MANAGER_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_MATERIAL_MANAGER_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_MATERIAL_MANAGER_H_
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <filament/Engine.h>
#include <filament/MaterialInstance.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/mesh.h"
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/mesh.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -85,4 +86,4 @@ class MaterialManager {
};
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MATERIAL_MANAGER_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_MATERIAL_MANAGER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/mesh.h"
#include "render/filament/core/mesh.h"
#include <algorithm>
#include <cfloat>
@@ -23,17 +23,17 @@
#include <mutex>
#include <utility>
#include <backend/BufferDescriptor.h>
#include <filament/Box.h>
#include <filament/Engine.h>
#include <filament/IndexBuffer.h>
#include <filament/VertexBuffer.h>
#include <backend/BufferDescriptor.h>
#include <math/TVecHelpers.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament_util.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -111,9 +111,7 @@ Mesh::Mesh(filament::Engine* engine, const mjrfMeshData& data)
// If the user has provided a release callback, then we need to ensure we
// call is when filament is done with the mesh data.
if (data.release) {
shared_state_->callbacks.push_back([=]() {
data.release(data.user_data);
});
shared_state_->callbacks.push_back([=]() { data.release(data.user_data); });
}
BuildVertexBuffer(data);
@@ -215,7 +213,8 @@ void Mesh::BuildVertexBuffer(const mjrfMeshData& data) {
}
vertex_buffer_ = vb_builder.build(*engine_);
auto* user_data = new std::shared_ptr<SharedState>(shared_state_);
vertex_buffer_->setBufferAt(*engine_, 0, {bytes, nbytes, callback, user_data});
vertex_buffer_->setBufferAt(*engine_, 0,
{bytes, nbytes, callback, user_data});
} else {
// For a non-interleaved vertex buffer, we assign a separate buffer to each
// attribute.
@@ -248,7 +247,8 @@ void Mesh::BuildVertexBuffer(const mjrfMeshData& data) {
bytes = BuildOrientationsFromNormals(data.nvertices, attrib);
}
auto* user_data = new std::shared_ptr<SharedState>(shared_state_);
vertex_buffer_->setBufferAt(*engine_, i, {bytes, nbytes, callback, user_data});
vertex_buffer_->setBufferAt(*engine_, i,
{bytes, nbytes, callback, user_data});
}
}
}
@@ -258,9 +258,8 @@ void Mesh::BuildIndexBuffer(const mjrfMeshData& data) {
return;
}
const int element_size = data.index_type == mjINDEX_TYPE_U16
? sizeof(uint16_t)
: sizeof(uint32_t);
const int element_size =
data.index_type == mjINDEX_TYPE_U16 ? sizeof(uint16_t) : sizeof(uint32_t);
const int num_bytes = data.nindices * element_size;
// If indices == 0 and nindices > 0, then the user is specifying that the
@@ -269,9 +268,7 @@ void Mesh::BuildIndexBuffer(const mjrfMeshData& data) {
const void* indices = data.indices;
if (indices == nullptr) {
std::byte* sequence = new std::byte[num_bytes];
shared_state_->callbacks.push_back([=]() {
delete[] sequence;
});
shared_state_->callbacks.push_back([=]() { delete[] sequence; });
if (data.index_type == mjINDEX_TYPE_U16) {
FillSequence<uint16_t>(sequence, num_bytes);
@@ -296,9 +293,7 @@ void Mesh::BuildIndexBuffer(const mjrfMeshData& data) {
float4* Mesh::BuildOrientationsFromNormals(int nvertices,
const mjrVertexAttribute& normals) {
float4* orientations = new float4[nvertices];
shared_state_->callbacks.push_back([=]() {
delete[] orientations;
});
shared_state_->callbacks.push_back([=]() { delete[] orientations; });
const float* normals_ptr = reinterpret_cast<const float*>(normals.bytes);
for (int i = 0; i < nvertices; ++i) {
orientations[i] = CalculateOrientation(ReadFloat3(normals_ptr, i));
@@ -359,11 +354,7 @@ bool Mesh::HasVertexAttribute(mjrVertexAttributeUsage attrib) const {
return it != attributes_.end();
}
bool Mesh::HasBounds() const {
return bounds_.has_value();
}
bool Mesh::HasBounds() const { return bounds_.has_value(); }
filament::Box Mesh::GetBounds() const {
return bounds_.value();
}
filament::Box Mesh::GetBounds() const { return bounds_.value(); }
} // namespace mujoco
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MESH_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MESH_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_MESH_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_MESH_H_
#include <array>
#include <functional>
@@ -28,7 +28,7 @@
#include <filament/RenderableManager.h>
#include <filament/VertexBuffer.h>
#include <math/vec4.h>
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -60,9 +60,7 @@ class Mesh : public mjrfMesh {
// Returns the bounds of the mesh.
filament::Box GetBounds() const;
static Mesh* downcast(mjrfMesh* mesh) {
return static_cast<Mesh*>(mesh);
}
static Mesh* downcast(mjrfMesh* mesh) { return static_cast<Mesh*>(mesh); }
static const Mesh* downcast(const mjrfMesh* mesh) {
return static_cast<const Mesh*>(mesh);
}
@@ -95,4 +93,4 @@ class Mesh : public mjrfMesh {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MESH_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_MESH_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/object_manager.h"
#include "render/filament/core/object_manager.h"
#include <cstdint>
#include <memory>
@@ -27,7 +27,7 @@
#include <filament/Texture.h>
#include <math/vec2.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/builtins.h"
#include "render/filament/core/builtins.h"
#include "user/user_resource.h"
namespace mujoco {
@@ -40,7 +40,8 @@ std::string ResolveFilamentAssetPath(const std::string& filename) {
static filament::Material* LoadMaterial(filament::Engine* engine,
std::string_view filename) {
const std::string path = ResolveFilamentAssetPath(std::string(filename));
mjResource* resource = mju_openResource("", path.c_str(), nullptr, nullptr, 0);
mjResource* resource =
mju_openResource("", path.c_str(), nullptr, nullptr, 0);
void* payload = nullptr;
int size = mju_readResource(resource, const_cast<const void**>(&payload));
filament::Material::Builder material_builder;
@@ -50,31 +51,39 @@ static filament::Material* LoadMaterial(filament::Engine* engine,
return material;
};
ObjectManager::ObjectManager(filament::Engine* engine)
: engine_(engine) {
ObjectManager::ObjectManager(filament::Engine* engine) : engine_(engine) {
materials_[kPbr] = LoadMaterial(engine, "pbr.filamat");
materials_[kPbrPacked] = LoadMaterial(engine, "pbr_packed.filamat");
materials_[kPbrTransparent] = LoadMaterial(engine, "pbr_transparent.filamat");
materials_[kPbrPackedTransparent] = LoadMaterial(engine, "pbr_packed_transparent.filamat");
materials_[kPbrPackedTransparent] =
LoadMaterial(engine, "pbr_packed_transparent.filamat");
materials_[kPhong2d] = LoadMaterial(engine, "phong_2d.filamat");
materials_[kPhong2dFade] = LoadMaterial(engine, "phong_2d_fade.filamat");
materials_[kPhong2dReflect] = LoadMaterial(engine, "phong_2d_reflect.filamat");
materials_[kPhong2dReflect] =
LoadMaterial(engine, "phong_2d_reflect.filamat");
materials_[kPhong2dUv] = LoadMaterial(engine, "phong_2d_uv.filamat");
materials_[kPhong2dUvFade] = LoadMaterial(engine, "phong_2d_uv_fade.filamat");
materials_[kPhong2dUvReflect] = LoadMaterial(engine, "phong_2d_uv_reflect.filamat");
materials_[kPhong2dUvReflect] =
LoadMaterial(engine, "phong_2d_uv_reflect.filamat");
materials_[kPhongColor] = LoadMaterial(engine, "phong_color.filamat");
materials_[kPhongColorFade] = LoadMaterial(engine, "phong_color_fade.filamat");
materials_[kPhongColorReflect] = LoadMaterial(engine, "phong_color_reflect.filamat");
materials_[kPhongColorFade] =
LoadMaterial(engine, "phong_color_fade.filamat");
materials_[kPhongColorReflect] =
LoadMaterial(engine, "phong_color_reflect.filamat");
materials_[kPhongCube] = LoadMaterial(engine, "phong_cube.filamat");
materials_[kPhongCubeFade] = LoadMaterial(engine, "phong_cube_fade.filamat");
materials_[kPhongCubeReflect] = LoadMaterial(engine, "phong_cube_reflect.filamat");
materials_[kUnlitSegmentation] = LoadMaterial(engine, "unlit_segmentation.filamat");
materials_[kPhongCubeReflect] =
LoadMaterial(engine, "phong_cube_reflect.filamat");
materials_[kUnlitSegmentation] =
LoadMaterial(engine, "unlit_segmentation.filamat");
materials_[kUnlitDecor] = LoadMaterial(engine, "unlit_decor.filamat");
materials_[kUnlitDepth] = LoadMaterial(engine, "unlit_depth.filamat");
materials_[kUnlitUi] = LoadMaterial(engine, "unlit_ui.filamat");
materials_[kOutlineComposite] = LoadMaterial(engine, "outline_composite.filamat");
materials_[kOutlineComposite] =
LoadMaterial(engine, "outline_composite.filamat");
materials_[kOutlineFlatten] = LoadMaterial(engine, "outline_flatten.filamat");
materials_[kOutlineJumpFlood] = LoadMaterial(engine, "outline_jumpflood.filamat");
materials_[kOutlineJumpFlood] =
LoadMaterial(engine, "outline_jumpflood.filamat");
static uint8_t black_rgb[3] = {0, 0, 0};
static uint8_t white_rgb[3] = {255, 255, 255};
@@ -160,10 +169,7 @@ void ObjectManager::CreateQuadBuffers() {
// large triangle is more efficient than a two-triangle quad because it
// avoids the diagonal edge where pixels might be rasterized twice.)
static const filament::math::float2 kVertices[3] = {
{-1.0f, -1.0f},
{ 3.0f, -1.0f},
{-1.0f, 3.0f}
};
{-1.0f, -1.0f}, {3.0f, -1.0f}, {-1.0f, 3.0f}};
static const uint16_t kIndices[3] = {0, 1, 2};
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_OBJECT_MANAGER_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_OBJECT_MANAGER_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_OBJECT_MANAGER_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_OBJECT_MANAGER_H_
#include <array>
#include <cstddef>
@@ -27,7 +27,7 @@
#include <filament/Skybox.h>
#include <filament/Texture.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/builtins.h"
#include "render/filament/core/builtins.h"
namespace mujoco {
@@ -104,4 +104,4 @@ class ObjectManager {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_OBJECT_MANAGER_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_OBJECT_MANAGER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/outliner.h"
#include "render/filament/core/outliner.h"
#include <cstdint>
#include <memory>
@@ -20,8 +20,8 @@
#include <filament/Camera.h>
#include <filament/Material.h>
#include <filament/MaterialInstance.h>
#include <filament/RenderableManager.h>
#include <filament/RenderTarget.h>
#include <filament/RenderableManager.h>
#include <filament/Scene.h>
#include <filament/TextureSampler.h>
#include <filament/View.h>
@@ -29,10 +29,10 @@
#include <math/vec4.h>
#include <utils/EntityManager.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/filament/render_target.h"
#include "experimental/filament/filament/texture.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/core/render_target.h"
#include "render/filament/core/texture.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -44,9 +44,7 @@ Outliner::Outliner(ObjectManager* object_mgr, uint8_t layer_mask,
color_(color),
thickness_(thickness) {}
Outliner::~Outliner() {
Reset();
}
Outliner::~Outliner() { Reset(); }
void Outliner::Prepare(int width, int height) {
if (width == width_ && height == height_) {
@@ -215,8 +213,7 @@ void Outliner::Reset() {
height_ = 0;
}
void Outliner::Render(filament::Renderer* renderer,
filament::View* view,
void Outliner::Render(filament::Renderer* renderer, filament::View* view,
filament::RenderTarget* render_target) {
filament::Viewport viewport = view->getViewport();
Prepare(viewport.width, viewport.height);
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_OUTLINER_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_OUTLINER_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_OUTLINER_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_OUTLINER_H_
#include <cstdint>
#include <memory>
@@ -23,8 +23,8 @@
#include <filament/View.h>
#include <math/vec4.h>
#include <utils/Entity.h>
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/filament/render_target.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/core/render_target.h"
namespace mujoco {
@@ -84,4 +84,4 @@ class Outliner {
};
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_OUTLINER_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_OUTLINER_H_
@@ -12,27 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/reflection_manager.h"
#include "render/filament/core/reflection_manager.h"
#include <memory>
#include <filament/Engine.h>
#include "experimental/filament/filament/render_target.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/render_target.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
ReflectionManager::ReflectionManager(filament::Engine* engine)
: engine_(engine) {}
ReflectionManager::~ReflectionManager() {
}
ReflectionManager::~ReflectionManager() {}
void ReflectionManager::ClearRenderables() {
renderables_.clear();
}
void ReflectionManager::ClearRenderables() { renderables_.clear(); }
mjrfTexture* ReflectionManager::Register(mjrfRenderable* renderable, int width,
int height) {
int height) {
if (targets_.size() == renderables_.size()) {
mjrfRenderTargetConfig config;
mjrf_defaultRenderTargetConfig(&config);
@@ -46,9 +44,7 @@ mjrfTexture* ReflectionManager::Register(mjrfRenderable* renderable, int width,
return target->GetColorTexture();
}
int ReflectionManager::GetNumRenderables() const {
return renderables_.size();
}
int ReflectionManager::GetNumRenderables() const { return renderables_.size(); }
mjrfRenderable* ReflectionManager::GetRenderable(int index) const {
return renderables_[index];
@@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_REFLECTION_MANAGER_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_REFLECTION_MANAGER_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_REFLECTION_MANAGER_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_REFLECTION_MANAGER_H_
#include <memory>
#include <vector>
#include <filament/Engine.h>
#include "experimental/filament/filament/render_target.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/render_target.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -58,4 +58,4 @@ class ReflectionManager {
};
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_REFLECTION_MANAGER_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_REFLECTION_MANAGER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/render_target.h"
#include "render/filament/core/render_target.h"
#include <cstddef>
#include <cstdint>
@@ -22,12 +22,12 @@
#include <backend/DriverEnums.h>
#include <backend/PixelBufferDescriptor.h>
#include <filament/Engine.h>
#include <filament/Renderer.h>
#include <filament/RenderTarget.h>
#include <filament/Renderer.h>
#include <filament/Texture.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/texture.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/texture.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -39,9 +39,7 @@ RenderTarget::RenderTarget(filament::Engine* engine,
}
}
RenderTarget::~RenderTarget() noexcept {
Destroy();
}
RenderTarget::~RenderTarget() noexcept { Destroy(); }
void RenderTarget::Prepare(int width, int height) {
if (width == width_ && height == height_) {
@@ -65,7 +63,8 @@ void RenderTarget::Prepare(int width, int height) {
color_config.format = config_.color_format;
color_config.color_space = mjCOLORSPACE_LINEAR;
color_flags.color_attachment = true;
color_texture_ = std::make_unique<Texture>(engine_, color_config, color_flags);
color_texture_ =
std::make_unique<Texture>(engine_, color_config, color_flags);
mjrfTextureConfig depth_config;
mjrf_defaultTextureConfig(&depth_config);
@@ -76,7 +75,8 @@ void RenderTarget::Prepare(int width, int height) {
depth_config.format = config_.depth_format;
depth_config.color_space = mjCOLORSPACE_LINEAR;
depth_flags.depth_attachment = true;
depth_texture_ = std::make_unique<Texture>(engine_, depth_config, depth_flags);
depth_texture_ =
std::make_unique<Texture>(engine_, depth_config, depth_flags);
filament::RenderTarget::Builder builder;
builder.texture(filament::RenderTarget::AttachmentPoint::COLOR,
@@ -124,13 +124,9 @@ void RenderTarget::Destroy() {
depth_texture_.reset();
}
Texture* RenderTarget::GetColorTexture() const {
return color_texture_.get();
}
Texture* RenderTarget::GetColorTexture() const { return color_texture_.get(); }
Texture* RenderTarget::GetDepthTexture() const {
return depth_texture_.get();
}
Texture* RenderTarget::GetDepthTexture() const { return depth_texture_.get(); }
filament::RenderTarget* RenderTarget::GetFilamentRenderTarget() const {
return render_target_;
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_RENDER_TARGET_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_RENDER_TARGET_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_RENDER_TARGET_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_RENDER_TARGET_H_
#include <cstddef>
#include <cstdint>
@@ -21,8 +21,8 @@
#include <filament/Engine.h>
#include <filament/Texture.h>
#include "experimental/filament/filament/texture.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/texture.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -75,4 +75,4 @@ class RenderTarget : public mjrfRenderTarget {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_RENDER_TARGET_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_RENDER_TARGET_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/renderable.h"
#include "render/filament/core/renderable.h"
#include <cmath>
#include <cstdint>
@@ -35,12 +35,12 @@
#include <utils/EntityManager.h>
#include <mujoco/mujoco.h>
#include "engine/engine_vis_visualize.h"
#include "experimental/filament/filament_util.h"
#include "experimental/filament/filament/builtins.h"
#include "experimental/filament/filament/material_manager.h"
#include "experimental/filament/filament/mesh.h"
#include "experimental/filament/filament/reflection_manager.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/builtins.h"
#include "render/filament/core/material_manager.h"
#include "render/filament/core/mesh.h"
#include "render/filament/core/reflection_manager.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -127,8 +127,8 @@ void Renderable::InitPartEntity(Part& part) {
filament::IndexBuffer* index_buffer = part.mesh->GetFilamentIndexBuffer();
filament::RenderableManager::Builder builder(1);
builder.geometry(0, part.mesh->GetPrimitiveType(), vertex_buffer, index_buffer,
part.elem_offset, part.elem_count);
builder.geometry(0, part.mesh->GetPrimitiveType(), vertex_buffer,
index_buffer, part.elem_offset, part.elem_count);
if (part.mesh->HasBounds()) {
builder.boundingBox(part.mesh->GetBounds());
} else {
@@ -184,9 +184,7 @@ void Renderable::UpdateTransform() {
transform_ = tm.getTransform(tm.getInstance(parts_[0].entity));
}
const mat4f& Renderable::GetTransform() const {
return transform_;
}
const mat4f& Renderable::GetTransform() const { return transform_; }
void Renderable::AppendMesh(const Mesh* mesh) {
Part& part = parts_.emplace_back();
@@ -232,9 +230,7 @@ void Renderable::UpdateMaterial(const mjrfMaterial& material) {
material_ = material;
}
const mjrfMaterial& Renderable::GetMaterial() const {
return material_;
}
const mjrfMaterial& Renderable::GetMaterial() const { return material_; }
void Renderable::Prepare(std::span<const mjrfRenderRequest*> requests,
ReflectionManager* reflection_mgr) {
@@ -383,11 +379,11 @@ void Renderable::BindMaterialInstance(const mjrfRenderRequest& request) {
draw_queue_.pop_front();
}
MaterialManager::MaterialKey Renderable::SetMaterialInstance(MaterialManager::MaterialKey key) {
MaterialManager::MaterialKey Renderable::SetMaterialInstance(
MaterialManager::MaterialKey key) {
MaterialManager::MaterialKey prev = curr_state_.material_key;
if (key != curr_state_.material_key) {
filament::MaterialInstance* instance =
material_mgr_->GetInstance(key);
filament::MaterialInstance* instance = material_mgr_->GetInstance(key);
filament::RenderableManager& rm = GetEngine()->getRenderableManager();
for (Part& part : parts_) {
filament::RenderableManager::Instance ri = rm.getInstance(part.entity);
@@ -440,7 +436,8 @@ void Renderable::SetReceiveShadows(bool receive_shadows) {
filament::RenderableManager& rm = GetEngine()->getRenderableManager();
for (Part& part : parts_) {
rm.setReceiveShadows(rm.getInstance(part.entity), params_.receive_shadows);
rm.setReceiveShadows(rm.getInstance(part.entity),
params_.receive_shadows);
}
}
}
@@ -454,12 +451,13 @@ void Renderable::SetWireframe(bool wireframe) {
filament::RenderableManager& rm = GetEngine()->getRenderableManager();
for (Part& part : parts_) {
filament::VertexBuffer* vertex_buffer = part.mesh->GetFilamentVertexBuffer();
filament::VertexBuffer* vertex_buffer =
part.mesh->GetFilamentVertexBuffer();
filament::IndexBuffer* index_buffer = part.mesh->GetFilamentIndexBuffer();
rm.setGeometryAt(rm.getInstance(part.entity), 0,
wireframe ? kWireframeType : part.mesh->GetPrimitiveType(),
vertex_buffer, index_buffer, part.elem_offset,
part.elem_count);
rm.setGeometryAt(
rm.getInstance(part.entity), 0,
wireframe ? kWireframeType : part.mesh->GetPrimitiveType(),
vertex_buffer, index_buffer, part.elem_offset, part.elem_count);
}
}
}
@@ -509,7 +507,8 @@ void Renderable::SetGeomMesh(mjtGeom type, int nstack, int nslice, int nquad) {
bottom *= mat4f::scaling(float3{trs.size.x, trs.size.y, xz_size});
return bottom;
} else {
mju_error("Invalid index for capsule geom: %d (expected [0,2])", index);
mju_error("Invalid index for capsule geom: %d (expected [0,2])",
index);
return trs.ToTransform();
}
};
@@ -538,7 +537,8 @@ void Renderable::SetGeomMesh(mjtGeom type, int nstack, int nslice, int nquad) {
bottom *= mat4f::scaling(trs.size);
return bottom;
} else {
mju_error("Invalid index for cylinder geom: %d (expected [0,2])", index);
mju_error("Invalid index for cylinder geom: %d (expected [0,2])",
index);
return trs.ToTransform();
}
};
@@ -564,7 +564,8 @@ void Renderable::SetGeomMesh(mjtGeom type, int nstack, int nslice, int nquad) {
mat4f top_disk = base;
top_disk *= mat4f::translation(float3{0, 0, trs.size.z});
top_disk *= mat4f::rotation(std::numbers::pi, float3{1, 0, 0});
top_disk *= mat4f::scaling(float3{kArrowHeadSize, kArrowHeadSize, 1.0f});
top_disk *=
mat4f::scaling(float3{kArrowHeadSize, kArrowHeadSize, 1.0f});
return top_disk * mat4f::scaling(trs.size);
} else if (index == 3) {
mat4f bottom = base;
@@ -583,9 +584,9 @@ void Renderable::SetGeomMesh(mjtGeom type, int nstack, int nslice, int nquad) {
AppendMesh(builtins->Disk());
get_transform_fn_ = [](int index, const Trs& trs) {
mat4f base = mat4f(trs.rotation, trs.translation);
base *= mat4f::scaling(float3{1, 1, kArrowScale});
base *= mat4f::translation(float3{0, 0, trs.size.z});
mat4f base = mat4f(trs.rotation, trs.translation);
base *= mat4f::scaling(float3{1, 1, kArrowScale});
base *= mat4f::translation(float3{0, 0, trs.size.z});
if (index == 0) {
return base * mat4f::scaling(trs.size);
} else if (index == 1) {
@@ -598,7 +599,8 @@ void Renderable::SetGeomMesh(mjtGeom type, int nstack, int nslice, int nquad) {
bottom *= mat4f::rotation(std::numbers::pi, float3{1, 0, 0});
return bottom * mat4f::scaling(trs.size);
} else {
mju_error("Invalid index for arrow1 geom: %d (expected [0,2])", index);
mju_error("Invalid index for arrow1 geom: %d (expected [0,2])",
index);
return trs.ToTransform();
}
};
@@ -625,20 +627,23 @@ void Renderable::SetGeomMesh(mjtGeom type, int nstack, int nslice, int nquad) {
mat4f bottom = base;
bottom *= mat4f::translation(float3{0, 0, -trs.size.z});
bottom *= mat4f::rotation(std::numbers::pi, float3{1, 0, 0});
bottom *= mat4f::scaling(float3{kArrowHeadSize, kArrowHeadSize, 1.0f});
bottom *=
mat4f::scaling(float3{kArrowHeadSize, kArrowHeadSize, 1.0f});
return bottom * mat4f::scaling(trs.size);
} else if (index == 3) {
mat4f top_disk = base;
top_disk *= mat4f::translation(float3{0, 0, trs.size.z});
top_disk *= mat4f::rotation(std::numbers::pi, float3{1, 0, 0});
top_disk *= mat4f::scaling(float3{kArrowHeadSize, kArrowHeadSize, 1.0f});
top_disk *=
mat4f::scaling(float3{kArrowHeadSize, kArrowHeadSize, 1.0f});
return top_disk * mat4f::scaling(trs.size);
} else if (index == 4) {
mat4f bottom_disk = base;
bottom_disk *= mat4f::translation(float3{0, 0, -trs.size.z});
return bottom_disk * mat4f::scaling(trs.size);
} else {
mju_error("Invalid index for arrow2 geom: %d (expected [0,4])", index);
mju_error("Invalid index for arrow2 geom: %d (expected [0,4])",
index);
return trs.ToTransform();
}
};
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_RENDERABLE_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_RENDERABLE_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_RENDERABLE_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_RENDERABLE_H_
#include <cstdint>
#include <deque>
@@ -28,19 +28,19 @@
#include <math/vec3.h>
#include <utils/Entity.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/material_manager.h"
#include "experimental/filament/filament/mesh.h"
#include "experimental/filament/filament/reflection_manager.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/material_manager.h"
#include "render/filament/core/mesh.h"
#include "render/filament/core/reflection_manager.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
enum LayerMask : uint8_t {
kLayerMask_Object = 0x01 << 1,
kLayerMask_Decor = 0x01 << 2,
kLayerMask_Object = 0x01 << 1,
kLayerMask_Decor = 0x01 << 2,
kLayerMask_Outline = 0x01 << 3,
kLayerMask_All = 0xff,
kLayerMask_None = 0x00,
kLayerMask_All = 0xff,
kLayerMask_None = 0x00,
};
// A Renderable is effectively two things: a mesh and a material.
@@ -114,7 +114,8 @@ class Renderable : public mjrfRenderable {
// Binds the material instance for the given render request.
void BindMaterialInstance(const mjrfRenderRequest& request);
MaterialManager::MaterialKey SetMaterialInstance(MaterialManager::MaterialKey key);
MaterialManager::MaterialKey SetMaterialInstance(
MaterialManager::MaterialKey key);
static Renderable* downcast(mjrfRenderable* renderable) {
return static_cast<Renderable*>(renderable);
@@ -141,7 +142,7 @@ class Renderable : public mjrfRenderable {
filament::math::float3 size{1.0f, 1.0f, 1.0f};
filament::math::mat4f ToTransform() const {
return filament::math::mat4f(rotation, translation) *
filament::math::mat4f::scaling(size);
filament::math::mat4f::scaling(size);
}
};
@@ -185,4 +186,4 @@ class Renderable : public mjrfRenderable {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_RENDERABLE_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_RENDERABLE_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/scene_view.h"
#include "render/filament/core/scene_view.h"
#include <cstdint>
#include <memory>
@@ -24,32 +24,32 @@
#include <filament/LightManager.h>
#include <filament/Material.h>
#include <filament/Options.h>
#include <filament/Renderer.h>
#include <filament/RenderableManager.h>
#include <filament/RenderTarget.h>
#include <filament/RenderableManager.h>
#include <filament/Renderer.h>
#include <filament/Skybox.h>
#include <filament/TransformManager.h>
#include <filament/View.h>
#include <filament/Viewport.h>
#include <math/TVecHelpers.h>
#include <math/mat4.h>
#include <math/mathfwd.h>
#include <math/scalar.h>
#include <math/TVecHelpers.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <utils/EntityManager.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/filament/outliner.h"
#include "experimental/filament/filament/reflection_manager.h"
#include "experimental/filament/filament_util.h"
#include "experimental/filament/filament/color_grading_options.h"
#include "experimental/filament/filament/light.h"
#include "experimental/filament/filament/material_manager.h"
#include "experimental/filament/filament/render_target.h"
#include "experimental/filament/filament/renderable.h"
#include "experimental/filament/filament/texture.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/color_grading_options.h"
#include "render/filament/core/light.h"
#include "render/filament/core/material_manager.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/core/outliner.h"
#include "render/filament/core/reflection_manager.h"
#include "render/filament/core/render_target.h"
#include "render/filament/core/renderable.h"
#include "render/filament/core/texture.h"
#include "render/filament/mjrfilament.h"
#include "render/filament/support/filament_util.h"
namespace mujoco {
@@ -94,8 +94,8 @@ static void SetupCamera(const mjrCamera& cam,
: 0.5f * aspect_ratio * (cam.frustum_top - cam.frustum_bottom);
camera->lookAt(cam_pos, cam_at, cam_up);
camera->setProjection(type, cam.frustum_center - halfwidth,
cam.frustum_center + halfwidth, cam.frustum_bottom,
cam.frustum_top, cam.frustum_near, cam.frustum_far);
cam.frustum_center + halfwidth, cam.frustum_bottom,
cam.frustum_top, cam.frustum_near, cam.frustum_far);
}
// Sets up the `reflection_camera`'s projection matrix so that it is a
@@ -120,7 +120,8 @@ static void SetupReflectionCamera(const mat4& surface_xform,
const float3 plane_normal_camera = view_normal;
const float plane_dist_camera = -dot(plane_normal_camera, view_pos);
const float4 oblique_plane(plane_normal_camera, plane_dist_camera);
const mat4 oblique = CalculateObliqueProjection(src_projection, oblique_plane);
const mat4 oblique =
CalculateObliqueProjection(src_projection, oblique_plane);
reflection_camera->setCustomProjection(oblique, near, far);
}
@@ -252,7 +253,8 @@ void SceneView::PrepareToRender(std::span<const mjrfRenderRequest*> requests) {
}
}
void SceneView::Render(filament::Renderer* renderer, const mjrfRenderRequest& request) {
void SceneView::Render(filament::Renderer* renderer,
const mjrfRenderRequest& request) {
if (request.scene != this) {
mju_error("Invalid scene for SceneView::Render.");
}
@@ -348,9 +350,7 @@ void SceneView::SetColorGradingOptions(const ColorGradingOptions& opts) {
color_grading_options_ = opts;
}
filament::View* SceneView::GetDefaultRenderView() {
return main_view_;
}
filament::View* SceneView::GetDefaultRenderView() { return main_view_; }
ColorGradingOptions SceneView::GetColorGradingOptions() const {
return color_grading_options_;
@@ -424,17 +424,17 @@ void SceneView::Configure(const mjModel* model) {
fog_opts.enabled =
ReadElement(model, "filament.fog.enabled", fog_opts.enabled);
fog_opts.color = ReadElement(model, "filament.fog.color", fog_opts.color);
fog_opts.distance = ReadElement(
model, "filament.fog.distance", fog_opts.distance);
fog_opts.density = ReadElement(
model, "filament.fog.density", fog_opts.density);
fog_opts.cutOffDistance = ReadElement(
model, "filament.fog.cutOffDistance", fog_opts.cutOffDistance);
fog_opts.maximumOpacity = ReadElement(
model, "filament.fog.maximumOpacity", fog_opts.maximumOpacity);
fog_opts.distance =
ReadElement(model, "filament.fog.distance", fog_opts.distance);
fog_opts.density =
ReadElement(model, "filament.fog.density", fog_opts.density);
fog_opts.cutOffDistance = ReadElement(model, "filament.fog.cutOffDistance",
fog_opts.cutOffDistance);
fog_opts.maximumOpacity = ReadElement(model, "filament.fog.maximumOpacity",
fog_opts.maximumOpacity);
fog_opts.height = ReadElement(model, "filament.fog.height", fog_opts.height);
fog_opts.heightFalloff = ReadElement(
model, "filament.fog.heightFalloff", fog_opts.heightFalloff);
fog_opts.heightFalloff =
ReadElement(model, "filament.fog.heightFalloff", fog_opts.heightFalloff);
fog_opts.inScatteringStart = ReadElement(
model, "filament.fog.inScatteringStart", fog_opts.inScatteringStart);
fog_opts.inScatteringSize = ReadElement(
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_SCENE_VIEW_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_SCENE_VIEW_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_SCENE_VIEW_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_SCENE_VIEW_H_
#include <memory>
#include <span>
@@ -25,15 +25,15 @@
#include <filament/Scene.h>
#include <filament/View.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/color_grading_options.h"
#include "experimental/filament/filament/light.h"
#include "experimental/filament/filament/material_manager.h"
#include "experimental/filament/filament/object_manager.h"
#include "experimental/filament/filament/outliner.h"
#include "experimental/filament/filament/renderable.h"
#include "experimental/filament/filament/reflection_manager.h"
#include "experimental/filament/filament/texture.h"
#include "experimental/filament/render_context_filament.h"
#include "render/filament/core/color_grading_options.h"
#include "render/filament/core/light.h"
#include "render/filament/core/material_manager.h"
#include "render/filament/core/object_manager.h"
#include "render/filament/core/outliner.h"
#include "render/filament/core/reflection_manager.h"
#include "render/filament/core/renderable.h"
#include "render/filament/core/texture.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -113,4 +113,4 @@ class SceneView : public mjrfScene {
};
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_SCENE_VIEW_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_SCENE_VIEW_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament/texture.h"
#include "render/filament/core/texture.h"
#include <cstddef>
#include <cstdint>
@@ -24,7 +24,7 @@
#include <image/Ktx1Bundle.h>
#include <ktxreader/Ktx1Reader.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -67,7 +67,8 @@ static int GetNumChannels(const mjrfTextureConfig& config) {
}
}
static filament::Texture::Format GetTextureFormat(const mjrfTextureConfig& config) {
static filament::Texture::Format GetTextureFormat(
const mjrfTextureConfig& config) {
switch (config.format) {
case mjPIXEL_FORMAT_R8:
return filament::Texture::Format::R;
@@ -78,7 +79,7 @@ static filament::Texture::Format GetTextureFormat(const mjrfTextureConfig& confi
default:
mju_error("Unsupported format: %d", (int)config.format);
return filament::Texture::Format::UNUSED;
}
}
}
static filament::Texture::InternalFormat GetTextureInternalFormat(
@@ -204,7 +205,7 @@ void Texture::Upload(const mjrfTextureData& data) {
if (config_.width == config_.height) {
uint8_t* copy = new uint8_t[num_bytes];
auto release_callback = +[](void* buffer, size_t size, void* user) {
delete [] reinterpret_cast<uint8_t*>(buffer);
delete[] reinterpret_cast<uint8_t*>(buffer);
};
for (int i = 0; i < kNumFacesPerCube; ++i) {
std::memcpy(copy + (i * face_size), data.bytes, face_size);
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_TEXTURE_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_TEXTURE_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_CORE_TEXTURE_H_
#define MUJOCO_SRC_RENDER_FILAMENT_CORE_TEXTURE_H_
#include <filament/Engine.h>
#include <filament/Texture.h>
#include <math/vec3.h>
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
// Functions for creating filament textures.
namespace mujoco {
@@ -84,4 +84,4 @@ class Texture : public mjrfTexture {
};
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_TEXTURE_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_CORE_TEXTURE_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
#include <array>
#include <cstdint>
@@ -22,13 +22,13 @@
#include <math/vec3.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mujoco.h>
#include "experimental/filament/filament/filament_context.h"
#include "experimental/filament/filament/light.h"
#include "experimental/filament/filament/mesh.h"
#include "experimental/filament/filament/render_target.h"
#include "experimental/filament/filament/renderable.h"
#include "experimental/filament/filament/scene_view.h"
#include "experimental/filament/filament/texture.h"
#include "render/filament/core/filament_context.h"
#include "render/filament/core/light.h"
#include "render/filament/core/mesh.h"
#include "render/filament/core/render_target.h"
#include "render/filament/core/renderable.h"
#include "render/filament/core/scene_view.h"
#include "render/filament/core/texture.h"
template <int N>
static void setf(float (&arr)[N], const std::array<float, N>& values) {
@@ -125,7 +125,7 @@ void mjrf_destroyContext(mjrfContext* ctx) {
}
mjrfTexture* mjrf_createTexture(mjrfContext* ctx,
const mjrfTextureConfig* config) {
const mjrfTextureConfig* config) {
return new mujoco::Texture(
mujoco::FilamentContext::downcast(ctx)->GetEngine(), *config);
}
@@ -161,7 +161,7 @@ void mjrf_destroyLight(mjrfLight* light) {
}
mjrfRenderable* mjrf_createRenderable(mjrfContext* ctx,
const mjrfRenderableParams* params) {
const mjrfRenderableParams* params) {
return new mujoco::Renderable(
mujoco::FilamentContext::downcast(ctx)->GetEngine(), *params,
mujoco::FilamentContext::downcast(ctx)->GetMaterialManager());
@@ -171,8 +171,8 @@ void mjrf_destroyRenderable(mjrfRenderable* renderable) {
delete mujoco::Renderable::downcast(renderable);
}
mjrfRenderTarget* mjrf_createRenderTarget(mjrfContext* ctx,
const mjrfRenderTargetConfig* config) {
mjrfRenderTarget* mjrf_createRenderTarget(
mjrfContext* ctx, const mjrfRenderTargetConfig* config) {
return new mujoco::RenderTarget(
mujoco::FilamentContext::downcast(ctx)->GetEngine(), *config);
}
@@ -232,8 +232,8 @@ void mjrf_setRenderableMesh(mjrfRenderable* renderable, const mjrfMesh* mesh,
void mjrf_setRenderableGeomMesh(mjrfRenderable* renderable, mjtGeom type,
int nstack, int nslice, int nquad) {
mujoco::Renderable::downcast(renderable)->SetGeomMesh(type, nstack, nslice,
nquad);
mujoco::Renderable::downcast(renderable)
->SetGeomMesh(type, nstack, nslice, nquad);
}
void mjrf_setRenderableMaterial(mjrfRenderable* renderable,
@@ -253,8 +253,7 @@ void mjrf_setRenderableTransform(mjrfRenderable* renderable,
const filament::math::mat3f frotation{rotation[0], rotation[3], rotation[6],
rotation[1], rotation[4], rotation[7],
rotation[2], rotation[5], rotation[8]};
mujoco::Renderable::downcast(renderable)
->SetTransform(fposition, frotation);
mujoco::Renderable::downcast(renderable)->SetTransform(fposition, frotation);
}
void mjrf_setRenderableSize(mjrfRenderable* renderable, const float size[3]) {
@@ -293,7 +292,7 @@ void mjrf_configureSceneFromModel(mjrfScene* scene, const mjModel* model) {
}
void mjrf_resizeRenderTarget(mjrfRenderTarget* render_target, int width,
int height) {
int height) {
mujoco::RenderTarget::downcast(render_target)->Prepare(width, height);
}
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_H_
#define MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_H_
#include <cstdint>
@@ -478,4 +478,4 @@ void mjrf_DEBUG_drawImguiEditor(mjrfScene* scene);
} // extern "C"
#endif
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_H_
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_CPP_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_CPP_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_CPP_H_
#define MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_CPP_H_
#include <memory>
#include <string>
#include "experimental/filament/render_context_filament.h"
#include "render/filament/mjrfilament.h"
namespace mujoco {
@@ -71,4 +71,4 @@ std::string ResolveFilamentAssetPath(const std::string& filename);
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_RENDER_CONTEXT_FILAMENT_CPP_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_MJRFILAMENT_CPP_H_
@@ -12,15 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "experimental/filament/filament_util.h"
#include "render/filament/support/filament_util.h"
#include <limits>
#include <math/TVecHelpers.h>
#include <math/mat3.h>
#include <math/mat4.h>
#include <math/quat.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <math/TVecHelpers.h>
namespace mujoco {
@@ -86,7 +87,6 @@ mat4 CalculateObliqueProjection(const mat4& projection, const float4& plane) {
return res;
}
float4 CalculateOrientation(const float3& normal) {
float3 tangent;
float3 bitangent;
@@ -104,19 +104,17 @@ float4 CalculateOrientation(const float3& normal) {
return float4(orientation.xyz, orientation.w);
}
float3 CalculateNormal(
const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3) {
float3 CalculateNormal(const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3) {
const float3 v12 = p2 - p1;
const float3 v13 = p3 - p1;
return normalize(cross(v12, v13));
}
float4 CalculateOrientation(
const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3) {
float4 CalculateOrientation(const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3) {
return CalculateOrientation(CalculateNormal(p1, p2, p3));
}
@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_UTIL_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_UTIL_H_
#ifndef MUJOCO_SRC_RENDER_FILAMENT_SUPPORT_FILAMENT_UTIL_H_
#define MUJOCO_SRC_RENDER_FILAMENT_SUPPORT_FILAMENT_UTIL_H_
#include <string_view>
#include <math/mat3.h>
#include <math/mat4.h>
#include <math/vec2.h>
@@ -68,20 +69,18 @@ filament::math::mat4 CalculateObliqueProjection(
const filament::math::float4& plane);
// Calculates the normal of a triangle given its three vertices.
filament::math::float3 CalculateNormal(
const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3);
filament::math::float3 CalculateNormal(const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3);
// Calculates the orientation of a vertex given just its normal.
filament::math::float4 CalculateOrientation(
const filament::math::float3& normal);
// Calculates the orientation of a triangle given its three vertices.
filament::math::float4 CalculateOrientation(
const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3);
filament::math::float4 CalculateOrientation(const filament::math::float3& p1,
const filament::math::float3& p2,
const filament::math::float3& p3);
// Reads a value with the given name from the mjModel's data sections. The
// default_value is returned if the named element is not found.
@@ -130,4 +129,4 @@ T ReadElement(const mjModel* model, const char* name, T default_value = T()) {
} // namespace mujoco
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_UTIL_H_
#endif // MUJOCO_SRC_RENDER_FILAMENT_SUPPORT_FILAMENT_UTIL_H_