Jump to content

Get auxiliary buffer into post render


photo

Recommended Posts

Hi all,

 

I've tried recently to get drops effect on a windshield. I prepared test scene with particles attached to player and I assigned to them material with auxiliary pass. Next I added mat and shaders files from post_water sample. Inside mat file I wrote copy of render_compoite material which is simply used instead of post_filter_water_height material. There's some code:

<?xml version="1.0" encoding="utf-8"?>

<materials version="1.00" editable="0">
	
	<material name="drop_mask" hidden="1">		
		<!-- states -->
		<state name="auxiliary_mode" type="switch" items="none,overlay">1</state>
		<state name="blur_mask" type="switch" items="none,red">1</state>
		<state name="dof_mask" type="switch" items="none,green">1</state>
		<state name="auxiliary" hidden="1" type="toggle">0</state>
		<state name="refraction" hidden="1" type="toggle">0</state>
		<state name="motion_blur" hidden="1" type="switch">0</state>
		<state name="glow" hidden="1" type="toggle">0</state>
		<state name="dof" hidden="1" type="toggle">0</state>
		<state name="hdr" hidden="1" type="switch">0</state>
		<state name="lens" hidden="1" type="toggle">0</state>
		<state name="lut" hidden="1" type="toggle">0</state>
		
		<!-- shaders -->
		<shader pass="post"
			auxiliary_mode_defines=",AUXILIARY_OVERLAY"
			blur_mask_defines=",BLUR_RED"
			dof_mask_defines=",DOF_GREEN"
			auxiliary_defines=",AUXILIARY"
			refraction_defines=",REFRACTION"
			motion_blur_defines=",MOTION_BLUR,VELOCITY_BLUR"
			glow_defines=",GLOW"
			dof_defines=",DOF"
			hdr_defines=",HDR,HDR_LENS"
			lut_defines=",LUT"
			vertex="core/shaders/default/render/vertex_composite.shader"
			fragment="core/shaders/default/render/fragment_composite.shader"/>
		
		<!-- textures -->
		<texture name="screen_color" pass="post" type="procedural"/>
		<texture name="deferred_depth" pass="post" type="procedural"/>
		<texture name="auxiliary" pass="post" type="procedural"/>
		<texture name="refraction" pass="post" type="procedural"/>
		<texture name="velocity" pass="post" type="procedural"/>
		<texture name="glow" pass="post" type="procedural"/>
		<texture name="dof" pass="post" type="procedural"/>
		<texture name="luminance" pass="post" type="procedural"/>
		<texture name="hdr" pass="post" type="procedural"/>
		<texture name="lens" pass="post" type="procedural"/>
		<texture name="dirt" pass="post" type="procedural"/>
		<texture name="color" pass="post" unit="14" type="procedural"/>
		<texture name="dithering" pass="post" filter="point">core/textures/render_composite_dithering.dds</texture>
		
		<!-- parameters -->
		<parameter name="perspective" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="old_imodelview_x" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="old_imodelview_y" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="old_imodelview_z" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="modelviewprojection_x" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="modelviewprojection_y" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="modelviewprojection_w" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="motion_blur_scale" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="far_blur_range" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="near_blur_range" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="filmic_curve" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
		<parameter name="filmic_white" hidden="1" type="constant" shared="1">1.0 1.0 1.0 1.0</parameter>
	</material>
	
	<material name="post_filter_water_normal" hidden="1">
		
		<!-- shaders -->
		<shader pass="post"
			vertex="shaders/vertex_filter_water.shader"
			fragment="shaders/fragment_filter_water_normal.shader"/>
		
		<!-- textures -->
		<texture name="height" pass="post" type="procedural"/>
	</material>
	
	<material name="post_filter_water">
		
		<!-- states -->
		<state name="procedural_width" type="switch" items="half_width,width">0</state>
		<state name="procedural_height" type="switch" items="half_height,height">0</state>
		
		<!-- shaders -->
		<shader pass="post"
			vertex="shaders/vertex_filter_water.shader"
			fragment="shaders/fragment_filter_water.shader"/>
		
		<!-- textures -->
		<texture name="color" pass="post" type="procedural"/>
		<texture name="height" pass="post" type="procedural" materials="drop_mask"/>
		<texture name="normal" pass="post" type="procedural" materials="post_filter_water_normal,post_hblur_2d,post_vblur_2d"/>
	</material>
	
</materials>  

The problem is that shader see post_filter_water height texture as zeros. If I use drop_mask as post or composite material it seems it is generated in proper way. So how to properly pass drop_mask or auxiliary buffer into water shader.

I'll be grateful for any help.

Link to comment
Check whether the auxiliary buffer is filled correctly (the "render_show_textures 1" console command).

 

To pass the auxiliary buffer directly to the post_filter_water material, name the texture "auxiliary" and set its type as "procedural" in the .mat file:



<texture name="auxiliary" pass="post" unit="1" type="procedural"/>


Then this texture can be read in the shader by means of the specified unit.

Link to comment

It works. Thanks.

 

Unfortunately it doesn't want to be passed into "post_filter_water_normal" shader.

There's my "fragment_filter_water_shader" modification:

Texture2D s_texture_0 : register(t0);

struct FRAGMENT_IN {
	float4 position : SV_POSITION;
	float2 texcoord_0 : TEXCOORD0;
};

float4 main(FRAGMENT_IN IN) : SV_TARGET {
	return s_texture_0.Sample(s_sampler_0, IN.texcoord_0);
}

and "fragment_filter_water":

Texture2D s_texture_0 : register(t0);
Texture2D s_texture_1 : register(t1);
Texture2D s_texture_2 : register(t2);

struct FRAGMENT_IN {
	float4 position : SV_POSITION;
	float2 texcoord_0 : TEXCOORD0;
};

float4 main(FRAGMENT_IN IN) : SV_TARGET {
	half4 height = s_texture_1.Sample(s_sampler_1,IN.texcoord_0);
	half4 normal = s_texture_2.Sample(s_sampler_2,IN.texcoord_0);

	return height;//normal;
}

So, "height" is displayed properly, but when I replace it with "normal" screen is blacked.

 

I've found there's problem with passing "post_filter_water_normal" material into normal texture, not auxiliary buffer.

Edited by przemek.giebultowski
Link to comment
×
×
  • Create New...