Extending pre-pass renderer to support custom render targets

I want to extend babylon’s pre-renderer to support some custom render-target(s).
An example could be a id map rtt inspired by the one used in gpu-picking.
Sample: https://playground.babylonjs.com/#3W87R0#2

I found a way of integrating this by modifying the default.fragment.fx in packages/dev/core/src/Shaders/default.fragment.fx and including a block which writes to a separate rtt

	#ifdef PREPASS_IDMAP
		gl_FragData[PREPASS_IDMAP_INDEX] = vec4(1.0, 0.0, 0.0, writeGeometryInfo);
	#endif

I had to also add the textureFormat I wanted in the prepassRenderer, along with some other minor updates to fix all references.

  {
            purpose: Constants.PREPASS_IDMAP_TEXTURE_TYPE,
            type: Constants.TEXTURETYPE_UNSIGNED_BYTE,
            format: Constants.TEXTUREFORMAT_RGBA,
            name: "prePass_IdMap",
 }

I wanted to know if there is a simpler way of adding such a render target to the existing prePassRenderer ?

3 Likes

This might be the kind of thing that is addressed by the new Frame Graph system, but maybe @Evgeni_Popov can comment when he is back.