# Post *Unigine::post* is an optional abstract foundation for scriptable image effects. It supplies the current screen image as a procedural texture and runs a pass named *post* at the end of the Post Materials stage. The base material must define that pass and its shader program. Post declares no object node, rendering options, states, numeric parameters, named *Shader* blocks, or passes. Unlike the [Mesh](../../../../code/materials_shaders/abstract_materials/mesh.md) foundation, it supplies no mesh framework or extension hooks. Post Effect graphs use their own self-contained shader and callback template. Their generated bases do not automatically inherit *Unigine::post*. The source is `/data/core/materials/abstract/post.abstmat`, where `` is the installed SDK directory. It has no abstract parent. ## Provided Interface | Part | Definition | Role | |---|---|---| | Root arguments | *preview_hidden=true*, *var_prefix=var*, *texture_prefix=tex* | Hide the preview and establish the default names for parameter and texture declarations. | | Texture input | *Texture2D color * | An input supplied by the callback, available to shader code as *tex_color*. | | Expression | *RENDER_CALLBACK_END_POST_MATERIALS* | Prepares the source image, runs the post pass, and releases the temporary texture. | | Required base implementation | *Pass post* | A pass that writes the processed image to the target provided by the expression. | The abstract description's own namespace is *Unigine*, which makes its registered name *Unigine::post*. Set the base's own namespace independently when naming your material. The *color* input is a procedural binding, not a file texture to assign in the Editor. The inherited expression updates it for each invocation. Avoid reusing the name for an unrelated texture declaration. ## How the Callback Runs the Pass For an active scriptable material, the renderer invokes the inherited expression at *RENDER_CALLBACK_END_POST_MATERIALS*. The expression performs the following operations: 1. Obtain the current screen color texture and request a matching temporary texture. 2. Swap their texture resources so the temporary texture holds the input image and the screen texture can receive the result. 3. Bind the temporary texture to the material's color input. 4. Run the post pass with the screen color texture as its output target. 5. Clear the color binding and release the temporary texture. The shader therefore reads and writes different texture resources. The wrapper uses a resource swap rather than copying the input pixels. It expects the pass to write the output image; the example below writes every pixel. The callback name determines the execution point. Calling a pass *post* alone does not schedule it. Likewise, reaching this callback does not mean that every later rendering operation has finished; see [Rendering Sequence](../../../../principles/render/sequence/index.md) for the surrounding tasks. ## A Color Tint Base In the Asset Browser, choose *Create Code → Base Material → Custom Post* and name the material *post_tint*. The Editor's template is self-contained; to reuse the Post abstract wrapper, replace the generated file's contents with the following code: ```glsl BaseMaterial { Color tint = [1.0 0.6 0.6 1.0] Pass post { Fragment = #{ #include STRUCT_FRAG_BEGIN INIT_COLOR(float4) STRUCT_FRAG_END MAIN_FRAG_BEGIN(FRAGMENT_IN) OUT_COLOR = TEXTURE(tex_color, IN_UV); OUT_COLOR.rgb *= var_tint.rgb; MAIN_FRAG_END #} } } ``` The shader samples the inherited input and multiplies RGB by the tint, preserving the input alpha. Its parameter becomes *var_tint* through the inherited prefix. No additional callback is needed because the abstract description already supplies one. For the fragment entry-point and output macros, see the UUSL [main function](../../../../code/uusl/types.md#return_main_function) and [fragment shader semantics](../../../../code/uusl/semantics.md#fragment_shader_semantics). The pass specifies only its fragment stage. The Engine supplies the default vertex shader, `core/materials/shaders/default/empty.vert`, to draw the screen geometry and provide its UV coordinates. ## Enabling the Effect 1. Save the source and let the Editor reload the base, whose manual name is Samples::post_tint. 2. Create a child material through Create Child. 3. Add and enable that child in the global Custom Post Materials list in Render settings, or in the corresponding camera's scriptable material list. 4. Adjust Tint on the child. Setting its RGB components to one should leave the input color unchanged; reducing a component attenuates that channel. Loading the base does not enable the effect globally. The active material list controls whether its expression runs. See [Scriptable Materials](../../../../content/materials/scriptable.md) for global and camera-specific setup. ## Modulating Occluded Areas A post pass can combine the inherited screen image with scene buffers declared by the base. This example uses [*gbuffer_normal*](../../../../code/formats/materials_formats/ulon_materials/textures.md#sources_gbuffer) and [*current_depth*](../../../../code/formats/materials_formats/ulon_materials/textures.md#sources_screen) to reconstruct world-space normals and positions, then projects a *modulation* texture along three world axes. The [*ssao*](../../../../code/formats/materials_formats/ulon_materials/textures.md#sources_lighting) input limits the modulation to occluded areas. Create another Custom Post base named *post_occlusion* and replace its contents with the following code. The *global_scale* parameter controls the texture's world-space repetition. The *intensity* parameter multiplies the modulated color in occluded pixels. ```glsl BaseMaterial { Texture2D normal Texture2D scene_depth Texture2D ssao Texture2D modulation = "core/textures/common/checker_d.texture" Slider global_scale = 2 Slider intensity = 1 Pass post { Fragment = #{ #include STRUCT_FRAG_BEGIN INIT_COLOR(float4) STRUCT_FRAG_END float3 sample_modulation(float2 uv, float depth) { float3 normal_ws = mul3(s_imodelview, unpackGBufferNormal(TEXTURE(tex_normal, uv).rgb)); float3 position_ws = s_camera_position + mul3(s_imodelview, nativeDepthToPositionVS(depth, uv)); float4 texcoord = position_ws.xyyz * var_global_scale; float3 weight = triplanarWeightFast(normal_ws, 0.5f); return TEXTURE_TRIPLANAR(tex_modulation, texcoord, weight).rgb; } MAIN_FRAG_BEGIN(FRAGMENT_IN) float4 base = TEXTURE(tex_color, IN_UV); OUT_COLOR = base; float depth = TEXTURE(tex_scene_depth, IN_UV).r; if (depth > 0.0f && depth < 1.0f) { float ssao = TEXTURE(tex_ssao, IN_UV).r; float3 effect = sample_modulation(IN_UV, depth); OUT_COLOR.rgb = lerp(base.rgb * effect * var_intensity, base.rgb, ssao); } MAIN_FRAG_END #} } } ``` An SSAO value of one preserves the input color. Lower values blend toward the texture-modulated color. The pass preserves the input alpha and writes the original color outside the processed depth range, so it defines the output for every pixel. Create a child of *Samples::post_occlusion* and enable it in the same scriptable material list as the tint example. Enable [SSAO](../../../../editor2/settings/render_settings/global_illumination/indirect_diffuse/ssao/index.md#ssao_enabled) to obtain its occlusion mask, then adjust *Global Scale*, *Intensity*, and the *modulation* texture on the child. These inputs come from the base's declarations. The Post foundation still supplies only its *color* input and callback. The existing illustrations show earlier versions of the color filter and occlusion-modulation examples: ![](../material1.gif) ![](../material2.gif) ## Extending the Wrapper The same tint or occlusion shader can also be used in a self-contained base. Remove *parent=Unigine::post* and declare the preview setting, prefixes, procedural *color* texture, and callback locally. The shader and *post* pass can remain the same. The Custom Post code template demonstrates this independent setup. Reusing the abstract foundation shares the screen-input and execution logic between bases. This foundation performs one call to *post* at a fixed callback. Adding more pass declarations does not make the inherited expression call them. An effect that needs intermediate targets or several operations requires execution logic that invokes those passes and manages their resources. Repeating the callback's Expression name is also different from appending code to a Shader source. Named expression lookup selects the last declaration; the bodies are not concatenated. If you replace the callback, provide the required setup and cleanup yourself. See [Material Inheritance](../../../../code/materials_shaders/inheritance/index.md) and the [Expressions](../../../../code/formats/materials_formats/ulon_materials/expressions.md) reference.