I finally finished it.
There were few reports in commits to repository.
Depth is now passed simplest as it can be to texture that has 32 bits (only one channel for float in red channel).
All happens in vertex program.
Fragment program is used only for passing TEXCOORD (single float). To texture (also single float) PF_FLOAT32_R.
Texture is not rendered - it is passed to next componen right now.
I think it could not be simplified more.
Right now I am doing the post-effect.
This is how rendering to a texture looks right now (detailed description in revision comments - this one has a lot of things corrected):
compositor
Code: Select all
compositor OSP_SolidMaterialsBuffer
{
technique
{
// GBuffer enconding: --------------------------------------------------
// depthTexture: r --> normalized linear depth [0, 1]
// ---------------------------------------------------------------------
texture depthTexture target_width target_height PF_FLOAT32_R chain_scope
texture occlusion target_width target_height PF_FLOAT32_RGBA chain_scope
target depthTexture
{
input none
shadows off
pass clear
{
buffers colour depth stencil
depth_value 1.0
}
pass render_scene {}
}
}
}
compositor OSP_ShowDepth
{
technique
{
texture_ref occlusion OSP_SolidMaterialsBuffer occlusion
target occlusion
{
input none
pass render_quad
{
// Renders a fullscreen quad with a material
material OSP_ShowDepth
}
}
}
}
compositor OSP_PostFilter
{
technique
{
target_output
{
input none
pass render_quad
{
material OSP_PostFilter
}
}
}
}
Code: Select all
//DepthBuffer
material OSP_SolidMaterialsBuffer
{
technique
{
pass
{
vertex_program_ref OSP_SolidMaterialsBuffer_vp
{
param_named_auto worldViewProjection worldviewproj_matrix
param_named_auto depthRange scene_depth_range
}
fragment_program_ref OSP_SolidMaterialsBuffer_fp
{
}
}
}
}
//------------------------------------------------
material OSP_ShowDepth
{
technique
{
pass
{
depth_check off
vertex_program_ref Ogre/Compositor/StdQuad_vp {}
fragment_program_ref OSP_ShowDepth_fp {}
texture_unit
{
content_type compositor OSP_SolidMaterialsBuffer depthTexture
tex_address_mode clamp
filtering none
}
/*texture_unit
{
texture gray256.png
tex_address_mode wrap
filtering none
}*/
}
}
}
//---------------------------------------------------
material OSP_PostFilter
{
technique
{
pass
{
cull_hardware none
cull_software none
depth_check off
vertex_program_ref Ogre/Compositor/StdQuad_vp {}
fragment_program_ref OSP_PostFilter_fp {}
texture_unit
{
content_type compositor OSP_SolidMaterialsBuffer occlusion
tex_address_mode clamp
filtering none
}
}
}
}
Code: Select all
vertex_program OSP_SolidMaterialsBuffer_vp_cg cg
{
source OSP.cg
entry_point OSP_SolidMaterialsBuffer_vp
profiles vs_2_x arbvp1
}
vertex_program OSP_SolidMaterialsBuffer_vp unified
{
delegate OSP_SolidMaterialsBuffer_vp_cg
}
fragment_program OSP_SolidMaterialsBuffer_fp_cg cg
{
source OSP.cg
entry_point OSP_SolidMaterialsBuffer_fp
profiles ps_3_0 arbfp1
}
fragment_program OSP_SolidMaterialsBuffer_fp unified
{
delegate OSP_SolidMaterialsBuffer_fp_cg
}
//------------------------------------------------
fragment_program OSP_ShowDepth_fp_cg cg
{
source OSP.cg
entry_point OSP_ShowDepth_fp
profiles ps_2_x arbfp1
}
fragment_program OSP_ShowDepth_fp unified
{
delegate OSP_ShowDepth_fp_cg
}
//------------------------------------------------
fragment_program OSP_PostFilter_fp_cg cg
{
source OSP.cg
entry_point OSP_PostFilter_fp
profiles ps_3_0 ps_2_x arbfp1
}
fragment_program OSP_PostFilter_fp unified
{
delegate OSP_PostFilter_fp_cg
}
Code: Select all
void OSP_SolidMaterialsBuffer_vp(
float4 inputPosition : POSITION,
out float4 outputPosition : POSITION,
out float outputDepth : TEXCOORD0,
uniform float4x4 worldViewProjection,
uniform float4 depthRange
)
{
outputPosition = mul(worldViewProjection, inputPosition);
outputDepth = (outputPosition.z - depthRange.x) * depthRange.w;
}
void OSP_SolidMaterialsBuffer_fp(
float inputDepth : TEXCOORD0,
out float oDepth : COLOR //linear depth [0, 1]
)
{
oDepth = inputDepth;
}
void OSP_ShowDepth_fp
(
in float2 iTexCoord: TEXCOORD0,
out float4 oColor0 : COLOR0,
uniform sampler depthTexture: register(s0)
)
{
float depth = tex2D(depthTexture, iTexCoord).r;
oColor0 = float4(depth,depth,depth, 1);
}
void OSP_PostFilter_fp (
in float2 uv : TEXCOORD0,
out float4 oColor0 : COLOR0,
uniform sampler sOcclusion : register(s0)
)
{
oColor0 = float4(tex2D(sOcclusion, uv).xyz, 1);
}
When i red this post it turned out that "mask" symtax was just proposition.
Solution in the end is the same solution as in Deffered Shading, so I suppose it is the only one correct (render queue + litenets + identifier bits). I found that helpfull.
About order of rendering:
I simplified depth acquisition to fit it.
It seems that presented proposition is two-pass solution for colour and for depth. (that means the most heavy one).
Rigt now colour (defined by default materials given to objects on level of *.cpp) is lost, because special material had to be granted to objects that acquire depth (it will change when I give a new pass to material, by material listeners + rendering queues).
One-pass would mean that you have to take everything into considetarion (setting normals, lights, everything that people could think of, to calculate colour in the same pass) in one vertex program. I haven't found yet solution that would do everything, without listener - so I think your proposition to continue multiple-pass soltion is good.
At the moment "show depth" material is temporary one .
Compositor "Show depth" uses textures acquired by buffer compositor to create and render output texture. For step 3 used in particle effects, I'll use simmilar structure to get multiple textures from previous passes to mage depth test there.
I am wondering if my current solution will have to be rebuilt completely when I add rendering_queque (I hope that rendered textures won't be lost between two queues).