Jump to content

Add ability add post-processor to gui-objects or screen regions


photo

Recommended Posts

It could be great to have ability to add post-effects to screen regions (through rectangles or texture masks). This will usable for game-gui elements, when under a window we see part of world with blur or something else.

Link to comment

Masked blur sample implementation based on existing UNIGINE blur shader. Out-of-the-box UNIGINE optional mask support for all post materials would be great.

 

fragment_blur_mask_2d.shader (DIRECT3D9 excerpt)

 

...
half mask_scale;

half4 main(FRAGMENT_IN IN) : COLOR {

   half3 color = tex2D(s_texture_0,IN.texcoord_0.xy).xyz;
   half3 color_blured  = color * 0.142300f +
	tex2D(s_texture_0,IN.texcoord_1.xy).xyz * 0.134610f + tex2D(s_texture_0,IN.texcoord_1.zw).xyz * 0.134610f +
	tex2D(s_texture_0,IN.texcoord_2.xy).xyz * 0.113945f + tex2D(s_texture_0,IN.texcoord_2.zw).xyz * 0.113945f +
	tex2D(s_texture_0,IN.texcoord_3.xy).xyz * 0.086310f + tex2D(s_texture_0,IN.texcoord_3.zw).xyz * 0.086310f +
	tex2D(s_texture_0,IN.texcoord_4.xy).xyz * 0.058501f + tex2D(s_texture_0,IN.texcoord_4.zw).xyz * 0.058501f +
	tex2D(s_texture_0,IN.texcoord_5.xy).xyz * 0.035483f + tex2D(s_texture_0,IN.texcoord_5.zw).xyz * 0.035483f;

#ifdef MASK
   half mask_value = tex2D(s_texture_1,IN.texcoord_0.xy).x;

   color = lerp( color, color_blured, mask_scale * mask_value );
#endif

   return half4(color,1.0f);
}
....

 

post_h/vblur_mask_2d material definitions

 

...
<material name="post_hblur_mask_2d" parent="post_hblur_2d" editable="0">
   <state name="mask">1</state>

   <shader pass="post"
           defines="HBLUR"
           mask_defines=",MASK"
    vertex="core/shaders/post/vertex_blur_2d.shader"
    fragment="core/shaders/post/fragment_blur_mask_2d.shader"/>

   <texture name="Mask" unit="1" pass="post" mask="1" filter="bilinear">core/textures/post_blur_mask.dds</texture>

   <parameter name="mask_scale" mask="1" type="slider" shared="1" min="0.0" max="1.0">1.0</parameter>
</material>

<material name="post_vblur_mask_2d" parent="post_vblur_2d" editable="0">
   <state name="mask">1</state>

   <shader pass="post"
           defines="VBLUR"
           mask_defines=",MASK"
    vertex="core/shaders/post/vertex_blur_2d.shader"
    fragment="core/shaders/post/fragment_blur_mask_2d.shader"/>

   <texture name="Mask" unit="1" pass="post" mask="1" filter="bilinear">core/textures/post_blur_mask.dds</texture>

   <parameter name="mask_scale" mask="1" type="slider" shared="1" min="0.0" max="1.0">1.0</parameter>
</material>
....

 

Usage

 

Inherit from material post_vblur_mask_2d and/or post_hblur_mask_2d. Assign mask textures to inherited material(s) and use as render post materials. Mask influence can be dynamically scaled via material mask_scale parameter. Disabling mask state in inherited material(s) gives you default fullscreen blur.

 

Sample

 

post-82-0-97613600-1296841556_thumb.jpgpost-82-0-79307700-1296847069_thumb.jpgpost-82-0-60468600-1296844102_thumb.jpg

post-82-0-26485000-1296841772_thumb.jpgpost-82-0-24463000-1296846939_thumb.jpgpost-82-0-36394400-1296844063_thumb.jpg

  • Like 1
Link to comment

Thinking about more general solution it might be helpfull to have exposed ("hidden=0") post material hierarchy for easy setup of different user customized post material instances in material editor. Internal-only post materials like stereo post materials still could stay hidden.

 

<material name="post_base" hidden="0" editable="0">
...
</material>

<material name="post_hblur_2d" parent="post_base" hidden="0" editable="0">
...
</material>

<material name="post_stereo" hidden="1">
...
</material>

Link to comment
  • 1 month later...
  • 2 months later...
×
×
  • Create New...