A dissolve shader of your own
Updated
A script registers a custom dissolve preset, gives the crate a Shader Material with it, and tweens its progress uniform from 0 to 1 on crate/destroy before destroying the crate.
Press Destroy to burn the crate away along a blocky pattern. Drag to orbit the camera, scroll to zoom.
A dissolve shader of your own
#pragma lifecycle(startup)
const DISSOLVE = `#pragma shader(name=dissolve, label="Dissolve", description="Burns away along a blocky noise pattern.")#pragma material(shading=lit)#pragma uniform(ref=progress, type=Slider, min=0, max=1, step=0.01, default=0)#pragma uniform(ref=edgeColor, type=Color, default=0xff6a00)#pragma uniform(ref=cells, type=Number, min=1, max=64, default=8)
float hash(vec3 p) { return fract(sin(dot(p, vec3(12.9898, 78.233, 37.719))) * 43758.5453);}
void fragment(inout Surface s) { float n = hash(floor(vLocalPosition * cells)); if (n < progress) discard; float edge = 1.0 - smoothstep(0.0, 0.08, n - progress); s.emissive = edgeColor * edge * 4.0;}`;
let material;
function setProgress(value) { material.setProps({ uniforms: Object.assign({}, material.props.uniforms, { progress: value }) });}
function startup() { if (!ShaderPreset.get('dissolve')) ShaderPreset.register(DISSOLVE);
const crate = self.parent; material = new ShaderMaterialComponent({ preset: 'dissolve', color: '#a16207' }); crate.addComponent(material);
on('crate/destroy', async () => { const finished = await Tween.value(0, 1, setProgress, { duration: 1.5, ease: Ease.InQuad }); if (finished) destroy(crate); });}How it works
Section titled “How it works”The script is explained step by step in A dissolve shader of your own.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
DissolveCrate.xrproj