Initial implementation of the filament rendering backend for mujoco.

This is intended as a drop-in replacement for mjr_render to enable high
quality, physically-based rendering (PBR) using the filament render engine.

This is a work-in-progress and, as such, some features may be missing. This
is also a code-only drop; build files (including instructions on how to
generate the filament materials) will be provided at a later date.

This library is intended to be run with the experimental studio app.

PiperOrigin-RevId: 817593684
Change-Id: Ib9cd14c1881e4897c1111275bd749aa38ebb5317
This commit is contained in:
Haroon Qureshi
2025-10-10 05:00:46 -07:00
committed by Copybara-Service
parent bd68f0c6cc
commit ff7c613c79
56 changed files with 6969 additions and 19 deletions
Binary file not shown.
+54
View File
@@ -0,0 +1,54 @@
// 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
//
// http://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.
material {
name : pbr,
shadingModel : lit,
culling: none,
flipUV: false,
parameters : [
{ type : sampler2d, name : BaseColor },
{ type : sampler2d, name : Normal },
{ type : sampler2d, name : Occlusion },
{ type : sampler2d, name : Roughness },
{ type : sampler2d, name : Metallic },
{ type : sampler2d, name : Emissive },
{ type : float4, name : BaseColorFactor },
{ type : float, name : MetallicFactor },
{ type : float, name : RoughnessFactor }
],
requires : [
uv0
]
}
fragment {
void material(inout MaterialInputs material) {
vec2 uv = getUV0();
material.normal = texture(materialParams_Normal, uv).xyz * 2.0 - 1.0;
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.ambientOcclusion = texture(materialParams_Occlusion, uv).r;
material.roughness = materialParams.RoughnessFactor;
material.roughness *= texture(materialParams_Roughness, uv).r;
material.metallic = materialParams.MetallicFactor;
material.metallic *= texture(materialParams_Metallic, uv).r;
material.emissive = texture(materialParams_Emissive, uv);
material.emissive.a = 1.0 - material.emissive.a;
}
}
@@ -0,0 +1,51 @@
// 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
//
// http://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.
material {
name : pbr_packed,
shadingModel : lit,
culling: none,
flipUV: false,
parameters : [
{ type : sampler2d, name : BaseColor },
{ type : sampler2d, name : Normal },
{ type : sampler2d, name : ORM },
{ type : sampler2d, name : Emissive },
{ type : float4, name : BaseColorFactor },
{ type : float, name : MetallicFactor },
{ type : float, name : RoughnessFactor }
],
requires : [
uv0
]
}
fragment {
void material(inout MaterialInputs material) {
vec2 uv = getUV0();
material.normal = texture(materialParams_Normal, uv).xyz * 2.0 - 1.0;
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.ambientOcclusion = texture(materialParams_ORM, uv).r;
material.roughness = materialParams.RoughnessFactor;
material.roughness *= texture(materialParams_ORM, uv).g;
material.metallic = materialParams.MetallicFactor;
material.metallic *= texture(materialParams_ORM, uv).b;
material.emissive = texture(materialParams_Emissive, uv);
material.emissive.a = 1.0 - material.emissive.a;
}
}
@@ -0,0 +1,50 @@
// 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
//
// http://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.
material {
name : phong_2d,
shadingModel : specularGlossiness,
culling : none,
flipUV : false,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor },
{ type : float3, name : UvScale },
{ type : sampler2d, name : BaseColor }
],
variables : [
vertex_pos
]
}
vertex {
void materialVertex(inout MaterialVertexInputs material) {
material.vertex_pos = getPosition();
}
}
fragment {
void material(inout MaterialInputs material) {
vec2 uv = variable_vertex_pos.xy * materialParams.UvScale.xy;
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,51 @@
// 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
//
// http://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.
material {
name : phong_2d,
shadingModel : specularGlossiness,
culling : none,
flipUV : false,
blending: fade,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor },
{ type : float3, name : UvScale },
{ type : sampler2d, name : BaseColor }
],
variables : [
vertex_pos
]
}
vertex {
void materialVertex(inout MaterialVertexInputs material) {
material.vertex_pos = getPosition();
}
}
fragment {
void material(inout MaterialInputs material) {
vec2 uv = variable_vertex_pos.xy * materialParams.UvScale.xy;
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,43 @@
// 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
//
// http://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.
material {
name : phong_2d_uv,
shadingModel : specularGlossiness,
culling : none,
flipUV : false,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor },
{ type : sampler2d, name : BaseColor }
],
requires : [
uv0
],
}
fragment {
void material(inout MaterialInputs material) {
vec2 uv = getUV0();
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,44 @@
// 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
//
// http://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.
material {
name : phong_2d_uv,
shadingModel : specularGlossiness,
culling : none,
flipUV : false,
blending: fade,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor },
{ type : sampler2d, name : BaseColor }
],
requires : [
uv0
],
}
fragment {
void material(inout MaterialInputs material) {
vec2 uv = getUV0();
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,35 @@
// 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
//
// http://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.
material {
name : phong_color,
shadingModel : specularGlossiness,
culling: none,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor }
]
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,36 @@
// 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
//
// http://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.
material {
name : phong_color_fade,
shadingModel : specularGlossiness,
culling: none,
blending: fade,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor }
]
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,50 @@
// 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
//
// http://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.
material {
name : phong_cube,
shadingModel : specularGlossiness,
culling : none,
flipUV : false,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor },
{ type : float3, name : UvScale },
{ type : samplerCubemap, name : BaseColor }
],
variables : [
vertex_pos
]
}
vertex {
void materialVertex(inout MaterialVertexInputs material) {
material.vertex_pos = getPosition();
}
}
fragment {
void material(inout MaterialInputs material) {
vec3 uv = variable_vertex_pos.xyz * materialParams.UvScale;
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,51 @@
// 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
//
// http://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.
material {
name : phong_cube,
shadingModel : specularGlossiness,
culling : none,
flipUV : false,
blending: fade,
parameters : [
{ type : float4, name : BaseColorFactor },
{ type : float, name : SpecularFactor },
{ type : float, name : GlossinessFactor },
{ type : float, name : EmissiveFactor },
{ type : float3, name : UvScale },
{ type : samplerCubemap, name : BaseColor }
],
variables : [
vertex_pos
]
}
vertex {
void materialVertex(inout MaterialVertexInputs material) {
material.vertex_pos = getPosition();
}
}
fragment {
void material(inout MaterialInputs material) {
vec3 uv = variable_vertex_pos.xyz * materialParams.UvScale;
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
material.baseColor *= texture(materialParams_BaseColor, uv);
material.specularColor = vec3(materialParams.SpecularFactor);
material.glossiness = materialParams.GlossinessFactor;
material.emissive = vec4(materialParams.EmissiveFactor);
}
}
@@ -0,0 +1,31 @@
// 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
//
// http://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.
material {
name : unlit_depth,
shadingModel : unlit,
blending : opaque,
culling: none,
depthWrite: true
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
float3 worldPosition = getWorldPosition();
float4 clipPosition = mulMat4x4Float3(getClipFromWorldMatrix(), worldPosition);
float3 normalizedPosition = clipPosition.xyz / clipPosition.w;
material.baseColor.rgb = vec3(normalizedPosition.z);
}
}
@@ -0,0 +1,29 @@
// 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
//
// http://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.
material {
name : unlit_segmentation,
shadingModel : unlit,
culling: none,
parameters : [
{ type : float4, name : BaseColorFactor }
]
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = materialParams.BaseColorFactor;
}
}
@@ -0,0 +1,43 @@
// 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
//
// http://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.
material {
name : unlit_ui,
parameters : [
{
type : sampler2d,
name : glyph
}
],
requires : [
uv0,
color
],
shadingModel : unlit,
culling : none,
depthCulling: false,
blending : transparent,
featureLevel : 0
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
vec2 uv = getUV0();
uv.y = 1.0 - uv.y;
vec4 tex_color = texture2D(materialParams_glyph, uv);
material.baseColor = getColor() * tex_color;
material.baseColor.rgb *= material.baseColor.a;
}
}