Skip to content

Commit a56a10c

Browse files
authored
Playground: Add fluent code for frame graphs (#17277)
I created the PR in draft mode, to let #17216 go first.
1 parent ff1b476 commit a56a10c

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

packages/tools/playground/public/procedural.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"subItems": ["Debug Layer", "Shadows", "Skybox", "Audio", "Lens Flare", "Sprites"],
66
"keepExpanded": true
77
},
8+
{
9+
"label": "Frame Graph",
10+
"tooltip": "Frame Graph tools",
11+
"subItems": ["Simple ", "Simple (NRG)", "Simple (NRG no autofill JS)"],
12+
"subItemsTS": ["Simple ", "Simple (NRG)", "Simple (NRG no autofill TS)"],
13+
"keepExpanded": true
14+
},
815
{
916
"label": "Cameras",
1017
"tooltip": "Select a camera type",

packages/tools/playground/public/templates.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@
3636
"insertText": "// Load the spritesheet (with appropriate settings) associated with the JSON Atlas.\nlet spriteSheet = new BABYLON.Texture(\"textures/spriteMap/none_trimmed/Legends_Level_A.png\", scene,\n false, //NoMipMaps\n false, //InvertY usually false if exported from TexturePacker\n BABYLON.Texture.NEAREST_NEAREST, //Sampling Mode\n null, //Onload, you could spin up the sprite map in a function nested here\n null, //OnError\n null, //CustomBuffer\n false, //DeleteBuffer\n BABYLON.Engine.TEXTURETYPE_RGBA //ImageFormageType RGBA\n);\n// Create an assets manager to load the JSON file\nconst assetsManager = new BABYLON.AssetsManager(scene);\nconst textTask = assetsManager.addTextFileTask(\"text task\", \"textures/spriteMap/none_trimmed/Legends_Level_A.json\");\n// Create the sprite map on succeful loading\ntextTask.onSuccess = (task) => {\n let background = new BABYLON.SpriteMap(\"background\", JSON.parse(task.text), spriteSheet, {\n stageSize: new BABYLON.Vector2(2, 2),\n flipU: true //Sometimes you need to flip, depending on the sprite format.\n }, scene);\n // Set 4 sprites one per tile.\n for (let i = 0; i < 4; i++) {\n background.changeTiles(0, new BABYLON.Vector2(i % 2, Math.floor(i / 2)), 9 * i + 9);\n }\n};\n//load the assets manager\nassetsManager.load();"
3737
},
3838

39+
{
40+
"label": "Frame Graph: simple frame graph",
41+
"key": "Simple ",
42+
"documentation": "https://doc.babylonjs.com/features/featuresDeepDive/frameGraph/frameGraphBasicConcepts/frameGraphReplaceRenderLoop/",
43+
"insertText": "const frameGraph = new BABYLON.FrameGraph(scene, true);\n\nengine.onResizeObservable.add(() => {\n frameGraph.build();\n});\n\nscene.cameraToUseForPointers = camera;\nscene.frameGraph = frameGraph;\n\nconst samples = 4;\n\nconst colorTexture = frameGraph.textureManager.createRenderTargetTexture(\"color\", {\n size: { width: 100, height: 100 },\n options: {\n createMipMaps: false,\n types: [BABYLON.Constants.TEXTURETYPE_UNSIGNED_BYTE],\n formats: [BABYLON.Constants.TEXTUREFORMAT_RGBA],\n samples,\n useSRGBBuffers: [false],\n labels: [\"color\"],\n },\n sizeIsPercentage: true,\n});\n\nconst depthTexture = frameGraph.textureManager.createRenderTargetTexture(\"depth\", {\n size: { width: 100, height: 100 },\n options: {\n createMipMaps: false,\n types: [BABYLON.Constants.TEXTURETYPE_UNSIGNED_BYTE],\n formats: [BABYLON.Constants.TEXTUREFORMAT_DEPTH32_FLOAT],\n samples,\n useSRGBBuffers: [false],\n labels: [\"depth\"],\n },\n sizeIsPercentage: true,\n});\n\nconst clearTask = new BABYLON.FrameGraphClearTextureTask(\"clear\", frameGraph);\n\nclearTask.clearColor = true;\nclearTask.clearDepth = true;\nclearTask.targetTexture = colorTexture;\nclearTask.depthTexture = depthTexture;\n\nframeGraph.addTask(clearTask);\n\nconst rlist = {\n meshes: scene.meshes,\n particleSystems: scene.particleSystems,\n}\n\nconst renderTask = new BABYLON.FrameGraphObjectRendererTask(\"renderObjects\", frameGraph, scene);\n\nrenderTask.targetTexture = clearTask.outputTexture;\nrenderTask.depthTexture = clearTask.outputDepthTexture;\nrenderTask.objectList = rlist;\nrenderTask.camera = camera;\n\nframeGraph.addTask(renderTask);\n\nconst copyToBackbufferTask = new BABYLON.FrameGraphCopyToBackbufferColorTask(\"copytobackbuffer\", frameGraph);\n\ncopyToBackbufferTask.sourceTexture = renderTask.outputTexture;\n\nframeGraph.addTask(copyToBackbufferTask);\n\nframeGraph.build();\n\nawait frameGraph.whenReadyAsync();"
44+
},
45+
{
46+
"label": "Frame Graph: simple node render graph",
47+
"key": "Simple (NRG)",
48+
"documentation": "https://doc.babylonjs.com/features/featuresDeepDive/frameGraph/frameGraphBasicConcepts/frameGraphReplaceRenderLoop/#using-a-node-render-graph",
49+
"insertText": "const nrg = await BABYLON.NodeRenderGraph.ParseFromSnippetAsync(\"2LR76I\", scene);\n\nnrg.build();\n\nscene.frameGraph = nrg.frameGraph;\n\nawait nrg.whenReadyAsync();"
50+
},
51+
{
52+
"label": "Frame Graph: simple node render graph (no autofill parameters)",
53+
"key": "Simple (NRG no autofill JS)",
54+
"documentation": "https://doc.babylonjs.com/features/featuresDeepDive/frameGraph/frameGraphBasicConcepts/frameGraphReplaceRenderLoop/#using-a-node-render-graph",
55+
"language": "javascript",
56+
"insertText": "scene.cameraToUseForPointers = camera;\n\nconst nrg = await BABYLON.NodeRenderGraph.ParseFromSnippetAsync(\"2LR76I\", scene, { autoFillExternalInputs: false });\n\nconst cameraBlock = nrg.getBlockByName(\"Camera\");\ncameraBlock.value = camera;\n\nconst objectListBlock = nrg.getBlockByName(\"Object List\");\nobjectListBlock.value = { meshes: null, particleSystems: null };\n\nnrg.build();\n\nscene.frameGraph = nrg.frameGraph;\n\nawait nrg.whenReadyAsync();"
57+
},
58+
{
59+
"label": "Frame Graph: simple node render graph (no autofill parameters)",
60+
"key": "Simple (NRG no autofill TS)",
61+
"documentation": "https://doc.babylonjs.com/features/featuresDeepDive/frameGraph/frameGraphBasicConcepts/frameGraphReplaceRenderLoop/#using-a-node-render-graph",
62+
"language": "typescript",
63+
"insertText": "scene.cameraToUseForPointers = camera;\n\nconst nrg = await BABYLON.NodeRenderGraph.ParseFromSnippetAsync(\"2LR76I\", scene, { autoFillExternalInputs: false });\n\nconst cameraBlock = nrg.getBlockByName<BABYLON.NodeRenderGraphInputBlock>(\"Camera\");\ncameraBlock.value = camera;\n\nconst objectListBlock = nrg.getBlockByName<BABYLON.NodeRenderGraphInputBlock>(\"Object List\");\nobjectListBlock.value = { meshes: null, particleSystems: null };\n\nnrg.build();\n\nscene.frameGraph = nrg.frameGraph;\n\nawait nrg.whenReadyAsync();"
64+
},
65+
3966
{
4067
"label": "Add Camera : Arc Rotate Camera w/Radians",
4168
"key": "Arc Rotate (Rad)",

packages/tools/playground/src/components/commandBarComponent.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,25 @@ export class CommandBarComponent extends React.Component<ICommandBarComponentPro
237237
];
238238

239239
// Procedural Code Generator Options (build from procedural.json)
240+
const isJavaScript = this.props.globalState.language === "JS" || this.props.globalState.language === "JavaScript";
241+
240242
let proceduralOptions: any[] = [];
241-
proceduralOptions = this._procedural.map((item) => ({
242-
...item,
243-
onClick: () => {},
244-
onInsert: (snippetKey: string) => {
245-
this.onInsertSnippet(snippetKey);
246-
},
247-
}));
243+
proceduralOptions = this._procedural.map((item) => {
244+
const obj: any = {
245+
...item,
246+
onClick: () => {},
247+
onInsert: (snippetKey: string) => {
248+
this.onInsertSnippet(snippetKey);
249+
},
250+
};
251+
if (isJavaScript) {
252+
delete obj.subItemsTS;
253+
} else if (obj.subItemsTS) {
254+
obj.subItems = obj.subItemsTS;
255+
delete obj.subItemsTS;
256+
}
257+
return obj;
258+
});
248259

249260
// Engine Version Options
250261
const activeVersion = Utilities.ReadStringFromStore("version", "Latest", true);

packages/tools/playground/src/scss/commandBar.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
position: absolute;
233233
left: 200px;
234234
top: 0;
235-
width: 150px;
235+
width: 220px;
236236
display: none;
237237

238238
&.background-js {

0 commit comments

Comments
 (0)