Jump to content

Depth Clear Material


photo

Recommended Posts

We have a requirement to render craters with visible parts below terrain surface over polygonal terrain static mesh surface without complex re-tesselation. The basic idea for achiving this effect is as follows

 

  1. render terrain mesh
  2. render crater mask decal co-planar to terrain mesh with a special depth clear material which simply writes out far-clip z-values in the fragment shader to the z-buffer (mask-local z-buffer-clear)
  3. render actual crater geometry where below-terrain parts now don't get clipped by terrain surface due to previous per-pixel z-depth 'clear'

Is such depth clear material possible with UNIGINE ? For OpenGL glFragDepth instruction seems to be a possible way to write custom z-values as fragment shader output. How can this be accomplished with DX9/10/11 (haven't found a fragment shader sample for writing z-depth )?

Link to comment

Try following syntax for HLSL:

 

struct FRAGMENT_OUT {
 float4 color : COLOR;
 float depth : DEPTH;
};

FRAGMENT_OUT main(FRAGMENT_IN) {
FRAGMENT_OUT OUT;
OUT.color = my_color;
OUT.depth = my_depth;
return OUT;
}

Link to comment

Hi Alexander, thanks for the sample. Unfortunately - after some testing and googling - the general idea for clearing per-pixel-depth from DepthClearMaterail fragment shader does not seem to be usable with current UNIGINE material system.

 

Reason is that the depth output from fragment shader via gl_FragDepth/ out DEPTH/SV_DEPTH will NOT be written directly to the depth buffer, but will first also be depth-tested according to configured depth test mode against existing fragement depth in z-buffer. As UNIGINE uses by default DEPTH_LEQUAL test, writing out larger depth values from DepthClearMaterial fragment shader (in this case max possible depth) than already stored depth value from terrain mesh surface will discard DepthClearMaterial fragment output itself...grrr, no depth-write/clear will happen at all

 

Solution for this problem would be to use DEPTH_GEQUAL depth test while rendering DepthClearMaterial, but unfortunately there is no explicit depth test control for UNIGINE materials.

 

Would it be possible to get material depth mode control similar to existing blend mode ? Or is there any other possible approach for achieving the desired effect of rendering crater subsurface-parts on-top of terrain mesh surfaces without complicate re-tesselation ? Other standard approach to use stencil buffer operations has the same problem of missing UNIGINE material support.

 

Any ideas would be highly appreciated

Link to comment
  • 7 years later...

Next Unigine Release will provide a solution for this feature request :-) Took some time, but great feature implementation !

  • Like 1
Link to comment

Ulf, some features take time indeed, but we are adding them one by one.

The 2.8 release will bring even more long-awaited updates on terrain side.

Link to comment
×
×
  • Create New...