Jump to content

[SOLVED] Cannot sample Auxiliary buffer in Post Material, even though the Auxiliary debug output is correct.


photo

Recommended Posts

Posted

I'm trying to render outline for interactive objects and was following both the docs (https://developer.unigine.com/ch/docs/future/content/materials/scriptable)  and this other topic (https://developer.unigine.com/forum/topic/7111-simple-outlinehighlight-effect/) which is very similar to what I want to do.

This hammer is the object I'm trying to render the outline of:

viewCapturar.thumb.PNG.db801da7415a3df888a608cf17731897.PNG
 

And this is the Shader Graph being used for the hammer:

graphCapturar.PNG.171fa6e9e81d97d9c6b70cf0d2cce10e.PNG

 

Everything was going fine and I was able to render the desired object into the Auxiliary Buffer, but when I try to sample it in my custom Post Material I get nothing.

This is currently the Material I'm using, it's just a simple sampling of the Aux Buffer:

 

// More information on ULON format - https://developer.unigine.com/docs/code/formats/ulon_format
// More information on scriptable materials - https://developer.unigine.com/docs/content/materials/scriptable
BaseMaterial post_sobel <options_hidden=1 preview_hidden=1 var_prefix=var texture_prefix=tex>
{
	// Texture to be used in a shader (see Fragment shader below). Will be displayed in the Editor UI.
	Texture2D screen_texture <type=procedural internal=true>
	Texture2D auxiliary <type=auxiliary internal=true>

	// Custom parameter to be used in a shader (see Fragment shader below). Will be displayed in the Editor UI.
	Color selection_color = [0.5 0.5 0.5 1.0]
	Slider threshold = 1.0 <min=0.0 max=1.0>
	Slider distance = 1.0 <min=0.0 max=5.0>

	// Declaration of a custom rendering pass named 'selection_pass'. You can add as many passes as necessary.
	Pass selection_pass
	{
		// Shader declaration (you can add multiple shaders for a single pass)
		Fragment =
		#{
			#include <core/materials/shaders/render/common.h>

			STRUCT_FRAG_BEGIN
				INIT_COLOR(float4)
			STRUCT_FRAG_END

			MAIN_FRAG_BEGIN(FRAGMENT_IN)

				// take 3x3 samples
				float4 aux_color = TEXTURE_BIAS_ZERO(tex_auxiliary, IN_UV);

				// Choose between scene and selection colors
				OUT_COLOR = aux_color;

			MAIN_FRAG_END
		#}
	}

	// Expression written in Unigine Script to be called after the specified stage of the rendering sequence
	// the name should be the same as the corresponding callback of the Render class
	// (here RENDER_CALLBACK_END_POST_MATERIALS to execute it after rendering Post Materials)
	Expression RENDER_CALLBACK_END_POST_MATERIALS =
	#{
		// Get the screen color texture rendered for the current frame
		Texture screen_texture = engine.render_state.getScreenColorTexture();

		Texture source = engine.render.getTemporaryTexture(screen_texture);
		source.copy(screen_texture);

		// Set the source texture to be used as the 'screen_texture' in the shader
		setTexture("screen_texture", source);

		// Render the pass named 'selection_pass' and put the result to the screen color texture of the current frame
		renderPassToTexture("selection_pass", screen_texture);

		// Release the temporary texture
		engine.render.releaseTemporaryTexture(source);
	#}
}

 

This gives me a completely black screen, while the debug output of the Aux Buffer clearly shows the object:

 

auxDebugCapturar.thumb.PNG.a17468e2b6003fb978f26498fc613a17.PNG

 

The in-game debug view of the textures also show the object in the Aux Buffer:

debugCapturar.PNG.120fef5a32f172b76b16e917ac3e7cfc.PNG

 

Is there anything I'm doing wrong? Would appreciate any help, thanks!

 

 

 

 

Posted

Hello. You need to use "source" instead of "type" in your Texture2D definitions

image.png

Posted

Wow, don't know how I missed that... That was it! Thank you very much.

  • Like 1
  • silent changed the title to [SOLVED] Cannot sample Auxiliary buffer in Post Material, even though the Auxiliary debug output is correct.
×
×
  • Create New...