Jump to content

How to pass "deferred_depth" texture into a post processing fragment shader in Unigine 2.4?


photo

Recommended Posts

I did this but doesn't seem to work for me.

 

In the materail file,

 

<texture name="deferred_depth" pass="post" type="procedural"/>

 

And in the fragment shader,

 

Texture2D s_texture_0 : register(t0); // depth

 

float depth = getDeferredDepth(texture2DDeferredNorm(s_texture_0, s_sampler_0, IN.texcoord_0));

Link to comment

Hi,

 

As you can see in the attached screenshots, in Unigine 1 we used the depth value taken as above to mask out the interior of the vehilcle when we render the post processing windscreen effect. Without depth masking water drops form on the vehicle interior surfaces as well.

 

I am upgrading the project from Unigine 1 to Unigine 2 and I need to know how to achieve the same effect (get the same depth value) in Unigine 2.4.

 

Thank You

post-1331-0-29163500-1495601849_thumb.png

post-1331-0-57851100-1495601866_thumb.png

Link to comment

Hi Namal,

 

Could you provide us with a small test scene with your materials and shaders included so we can look into this issue and try to help you?

 

Thanks!

Link to comment

Hi,

 

Attached a sample scene with a post processing shader to mask the interior using the values from "deferred_depth" texture.

 

When the camera is inside the vehicle (and shader is enabled) all windscreens and windows are painted green because the depth value for the objects visible throw windows are greater than the constant defined in the fragment shader.

 

This is the technique we used in Unigine 1.

 

My question is how to achieve the same effect in Unigine 2.4?

 

Thanks

my_project.zip

post-1331-0-62994800-1495691226_thumb.png

post-1331-0-42131900-1495691294_thumb.png

Link to comment

Hi Namal,

I've converted Your scene to 2.4 and fixed material and shaders, please check them out (see the attachment).

Hope this solves Your problem!

Material:

	<material editable="0" name="ss_depth_mask">
		<blend src="none" dest="none"/>
		<state name="procedural_width" type="switch" items="half_width,width">1</state>
		<state name="procedural_height" type="switch" items="half_height,height">1</state>
		<shader pass="post" 
		defines="BASE_POST" 
		vertex="indian_bus/shaders/vertex_ss_depth_mask.shader" 
		fragment="indian_bus/shaders/fragment_ss_depth_mask.shader"/>
		<texture name="color" type="procedural"  shader="all" unit="0" pass="post" filter="bilinear"/>
		<texture unit="1" type="opacity_depth" shader="all" pass="post" filter="bilinear"/>
	</material>

Vertex shader:

// Include the UUSL header
#include <core/shaders/common/common.h>

// Input data struct
STRUCT(VERTEX_IN)
	INIT_ATTRIBUTE(float4,0,POSITION)	// Vertex position
	INIT_ATTRIBUTE(float4,1,TEXCOORD0)	// Vertex texcoords
	INIT_ATTRIBUTE(float4,2,COLOR0)		// Vertex color
END

// Output data struct
STRUCT(VERTEX_OUT)
	INIT_POSITION		// Output projected position
	INIT_OUT(float2,0)	// Texcoords (x and y only)
END

MAIN_BEGIN(VERTEX_OUT,VERTEX_IN)
	
	// Set output position
	OUT_POSITION = getPosition(IN_ATTRIBUTE(0));
	OUT_DATA(0).xy = IN_ATTRIBUTE(1).xy;
	
MAIN_END
	
// end

Fragment shader:


// Include the UUSL fragment shader header
#include <core/shaders/common/fragment.h>

static const float MASK_DEPTH = 10.0f;

// Define the color and depth textures of the scene
INIT_TEXTURE(0,TEX_COLOR)
INIT_TEXTURE(1,TEX_DEPTH)

// Input values
STRUCT(FRAGMENT_IN)
	INIT_POSITION		// Projected position
	INIT_IN(float2,0)	// Texcoords
END


MAIN_BEGIN(FRAGMENT_OUT,FRAGMENT_IN)
	
	// Get the UV
	float2 texcoord = IN_POSITION.xy * s_viewport.zw;
	
	// Get the scene color
	float4 scene_color = TEXTURE(TEX_COLOR,texcoord);
	
	// Get the linearized depth
	float scene_depth = getLinearizedDepth(TEXTURE_OUT(TEX_DEPTH),texcoord);
	
	// Apply depth mask
	if(scene_depth < MASK_DEPTH)
        OUT_COLOR = scene_color;
    else
        OUT_COLOR = float4(0, 1, 0, 1);
			
MAIN_END
			
// end

Thanks!

post-2439-0-08400800-1495775880_thumb.jpg

post-2439-0-88186400-1495775891_thumb.jpg

bus.zip

Link to comment

Thanks for the solution. Tested and works as expected (although I can see some flickering near the edges).

 

Is there any public documentation available on textures (such as 'opacity_depth') that can be used with these kinds of materials?

 

Thanks

Link to comment
×
×
  • Create New...