Add reflective materials.
A future CL will implement reflective surfaces and make use of these materials. PiperOrigin-RevId: 889200524 Change-Id: Icbe5c0c390f89789ed0f5d5c6058a2ef31105608
This commit is contained in:
committed by
Copybara-Service
parent
c61d239ac6
commit
02b0b40b1c
@@ -102,12 +102,16 @@ set(MATERIAL_FILES
|
||||
pbr_packed.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
|
||||
unlit_depth.mat
|
||||
unlit_line.mat
|
||||
unlit_segmentation.mat
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
material {
|
||||
name : phong_2d,
|
||||
name : phong_2d_fade,
|
||||
shadingModel : specularGlossiness,
|
||||
culling : none,
|
||||
flipUV : false,
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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_reflect,
|
||||
shadingModel : specularGlossiness,
|
||||
culling : none,
|
||||
flipUV : false,
|
||||
parameters : [
|
||||
{ type : float4, name : BaseColorFactor },
|
||||
{ type : float, name : SpecularFactor },
|
||||
{ type : float, name : GlossinessFactor },
|
||||
{ type : float, name : EmissiveFactor },
|
||||
{ type : float, name : Reflectance },
|
||||
{ type : float3, name : UvScale },
|
||||
{ type : float3, name : UvOffset },
|
||||
{ type : sampler2d, name : BaseColor },
|
||||
{ type : sampler2d, name : Reflection }
|
||||
],
|
||||
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 + materialParams.UvOffset.xy;
|
||||
vec2 screen_uv = gl_FragCoord.xy * getResolution().zw;
|
||||
|
||||
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);
|
||||
|
||||
// Apply reflection.
|
||||
vec4 reflection = texture(materialParams_Reflection, screen_uv);
|
||||
material.baseColor.rgb = mix(material.baseColor.rgb, reflection.rgb, materialParams.Reflectance);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
material {
|
||||
name : phong_2d_uv,
|
||||
name : phong_2d_uv_fade,
|
||||
shadingModel : specularGlossiness,
|
||||
culling : none,
|
||||
flipUV : false,
|
||||
|
||||
@@ -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_uv_reflect,
|
||||
shadingModel : specularGlossiness,
|
||||
culling : none,
|
||||
flipUV : false,
|
||||
parameters : [
|
||||
{ type : float4, name : BaseColorFactor },
|
||||
{ type : float, name : SpecularFactor },
|
||||
{ type : float, name : GlossinessFactor },
|
||||
{ type : float, name : EmissiveFactor },
|
||||
{ type : float, name : Reflectance },
|
||||
{ type : sampler2d, name : BaseColor },
|
||||
{ type : sampler2d, name : Reflection }
|
||||
],
|
||||
requires : [
|
||||
uv0
|
||||
],
|
||||
}
|
||||
|
||||
fragment {
|
||||
void material(inout MaterialInputs material) {
|
||||
vec2 uv = getUV0();
|
||||
vec2 screen_uv = gl_FragCoord.xy * getResolution().zw;
|
||||
|
||||
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);
|
||||
|
||||
// Apply reflection.
|
||||
vec4 reflection = texture(materialParams_Reflection, screen_uv);
|
||||
material.baseColor.rgb = mix(material.baseColor.rgb, reflection.rgb, materialParams.Reflectance);
|
||||
}
|
||||
}
|
||||
@@ -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_color_reflect,
|
||||
shadingModel : specularGlossiness,
|
||||
culling: none,
|
||||
parameters : [
|
||||
{ type : float4, name : BaseColorFactor },
|
||||
{ type : float, name : SpecularFactor },
|
||||
{ type : float, name : GlossinessFactor },
|
||||
{ type : float, name : EmissiveFactor },
|
||||
{ type : float, name : Reflectance },
|
||||
{ type : sampler2d, name : Reflection }
|
||||
]
|
||||
}
|
||||
|
||||
fragment {
|
||||
void material(inout MaterialInputs material) {
|
||||
vec2 screen_uv = gl_FragCoord.xy * getResolution().zw;
|
||||
|
||||
prepareMaterial(material);
|
||||
material.baseColor = materialParams.BaseColorFactor;
|
||||
material.specularColor = vec3(materialParams.SpecularFactor);
|
||||
material.glossiness = materialParams.GlossinessFactor;
|
||||
material.emissive = vec4(materialParams.EmissiveFactor);
|
||||
|
||||
// Apply reflection.
|
||||
vec4 reflection = texture(materialParams_Reflection, screen_uv);
|
||||
material.baseColor.rgb = mix(material.baseColor.rgb, reflection.rgb, materialParams.Reflectance);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
material {
|
||||
name : phong_cube,
|
||||
name : phong_cube_fade,
|
||||
shadingModel : specularGlossiness,
|
||||
culling : none,
|
||||
flipUV : false,
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// 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_reflect,
|
||||
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 : float, name : Reflectance },
|
||||
{ type : samplerCubemap, name : BaseColor },
|
||||
{ type : sampler2d, name : Reflection }
|
||||
],
|
||||
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;
|
||||
vec2 screen_uv = gl_FragCoord.xy * getResolution().zw;
|
||||
|
||||
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);
|
||||
|
||||
// Apply reflection.
|
||||
vec4 reflection = texture(materialParams_Reflection, screen_uv);
|
||||
material.baseColor.rgb = mix(material.baseColor.rgb, reflection.rgb, materialParams.Reflectance);
|
||||
}
|
||||
}
|
||||
@@ -89,12 +89,16 @@ ObjectManager::ObjectManager(const mjModel* model, filament::Engine* engine,
|
||||
materials_[kPbrPacked] = LoadMaterial("pbr_packed.filamat");
|
||||
materials_[kPhong2d] = LoadMaterial("phong_2d.filamat");
|
||||
materials_[kPhong2dFade] = LoadMaterial("phong_2d_fade.filamat");
|
||||
materials_[kPhong2dReflect] = LoadMaterial("phong_2d_reflect.filamat");
|
||||
materials_[kPhong2dUv] = LoadMaterial("phong_2d_uv.filamat");
|
||||
materials_[kPhong2dUvFade] = LoadMaterial("phong_2d_uv_fade.filamat");
|
||||
materials_[kPhong2dUvReflect] = LoadMaterial("phong_2d_uv_reflect.filamat");
|
||||
materials_[kPhongColor] = LoadMaterial("phong_color.filamat");
|
||||
materials_[kPhongColorFade] = LoadMaterial("phong_color_fade.filamat");
|
||||
materials_[kPhongColorReflect] = LoadMaterial("phong_color_reflect.filamat");
|
||||
materials_[kPhongCube] = LoadMaterial("phong_cube.filamat");
|
||||
materials_[kPhongCubeFade] = LoadMaterial("phong_cube_fade.filamat");
|
||||
materials_[kPhongCubeReflect] = LoadMaterial("phong_cube_reflect.filamat");
|
||||
materials_[kUnlitSegmentation] = LoadMaterial("unlit_segmentation.filamat");
|
||||
materials_[kUnlitLine] = LoadMaterial("unlit_line.filamat");
|
||||
materials_[kUnlitDepth] = LoadMaterial("unlit_depth.filamat");
|
||||
|
||||
@@ -43,12 +43,16 @@ class ObjectManager {
|
||||
kPbrPacked,
|
||||
kPhong2d,
|
||||
kPhong2dFade,
|
||||
kPhong2dReflect,
|
||||
kPhong2dUv,
|
||||
kPhong2dUvFade,
|
||||
kPhong2dUvReflect,
|
||||
kPhongColor,
|
||||
kPhongColorFade,
|
||||
kPhongColorReflect,
|
||||
kPhongCube,
|
||||
kPhongCubeFade,
|
||||
kPhongCubeReflect,
|
||||
kUnlitSegmentation,
|
||||
kUnlitDepth,
|
||||
kUnlitLine,
|
||||
|
||||
@@ -48,23 +48,6 @@
|
||||
onRuntimeInitialized: () => {
|
||||
// Define assets to prefetch. These paths are relative to the wasm_binary/ directory.
|
||||
const assetsToPrefetch = [
|
||||
"ibl.ktx",
|
||||
"pbr.filamat",
|
||||
"pbr_packed.filamat",
|
||||
"phong_2d.filamat",
|
||||
"phong_2d_uv.filamat",
|
||||
"phong_color.filamat",
|
||||
"phong_cube.filamat",
|
||||
"unlit_line.filamat",
|
||||
"unlit_ui.filamat",
|
||||
"phong_2d_fade.filamat",
|
||||
"phong_2d_uv_fade.filamat",
|
||||
"phong_color_fade.filamat",
|
||||
"phong_cube_fade.filamat",
|
||||
"unlit_depth.filamat",
|
||||
"unlit_segmentation.filamat",
|
||||
"OpenSans-Regular.ttf",
|
||||
"fontawesome-webfont.ttf",
|
||||
];
|
||||
|
||||
const assetPromises = assetsToPrefetch.map(async (relativePath) => {
|
||||
|
||||
Reference in New Issue
Block a user