Files
Mujoco_WASM/src/render/filament/assets/outline_flatten.mat
T
Yuval Tassa 6c86e12567 Make the selection outline occlusion-aware in the filament renderer.
PiperOrigin-RevId: 956489408
Change-Id: I948493587eb154cac6e0fc31d5df987967405ff8
2026-07-30 06:38:18 -07:00

59 lines
2.1 KiB
Plaintext

// Copyright 2026 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.
// This material writes the the screen-space position of each fragment as the
// output color of that fragment. This will provide us with the initial data for
// the Jump Flood Algorithm. See "outline_jumpflood.mat" for more details.
//
// Depth is also written so that the render target's depth attachment holds the
// depth of the selected objects; "outline_composite.mat" samples it to dim
// occluded portions of the outline.
material {
name : outline_flatten,
shadingModel : unlit,
culling : none,
depthWrite : true
}
fragment {
// Encode a vec2 value with the range [0-1] into a 32-bit (RGBA) value.
// We do this by packing each coordinate into a 16-bit value. Values are
// adjusted to ensure [0x0000] is reserved for "untouched" pixels rather
// than the pixel at the position (0, 0).
vec4 pack(vec2 value) {
// Scale and bias the value to avoid (0,0,0,0).
vec2 adjusted = value * 0.999 + 0.001;
// Pack float [0, 1] into two 8-bit channels.
float val_x = adjusted.x * 255.0;
float r_x = floor(val_x) / 255.0;
float g_x = fract(val_x);
float val_y = adjusted.y * 255.0;
float r_y = floor(val_y) / 255.0;
float g_y = fract(val_y);
return vec4(r_x, g_x, r_y, g_y);
}
void material(inout MaterialInputs material) {
prepareMaterial(material);
// Get the screen-space position of the fragment, normalized to [0-1].
vec2 uv = gl_FragCoord.xy * frameUniforms.resolution.zw;
material.baseColor = pack(uv);
}
}