a bit late I know and you probably already have test code, but if it helps debugging
my code based on sample code, changed a bit
compositor HgSAO.compositor
Code: Select all
compositor_node GenMipmapsTest_Node
{
in 0 rt_renderwindow
texture rt0 target_width target_height PF_R8G8B8 mipmaps 5 no_gamma no_fsaa uav
target rt0
{
pass clear
{
colour_value 0.2 0.4 0.6 1
}
pass render_scene
{
overlays off
}
pass generate_mipmaps
{
// compute_hq won't work on Mac use MetalTexture::_autogenerateMipmaps instead
mipmap_method compute_hq
}
}
target rt_renderwindow
{
pass render_quad
{
material HgSAO
input 0 rt0
quad_normals camera_far_corners_view_space
}
pass render_scene
{
lod_update_list off
//Render Overlays
overlays on
rq_first 254
rq_last 255
}
}
}
workspace HgSAO_Workspace
{
connect_output GenMipmapsTest_Node 0
}
material HgSAO.material
Code: Select all
// GLSL shaders
vertex_program HgSAO_vs_GLSL glsl
{
source HgSAO_vs.glsl
}
fragment_program HgSAO_ps_GLSL glsl
{
source HgSAO_ps.glsl
default_params
{
param_named depthTexture int 0
}
}
// HLSL shaders
vertex_program HgSAO_vs_HLSL hlsl
{
source HgSAO_vs.hlsl
entry_point main
target vs_5_0 vs_4_0 vs_4_0_level_9_1 vs_4_0_level_9_3
}
fragment_program HgSAO_ps_HLSL hlsl
{
source HgSAO_ps.hlsl
entry_point main
target ps_5_0 ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3
}
// Metal shaders
vertex_program HgSAO_vs_Metal metal
{
source HgSAO_vs.metal
}
fragment_program HgSAO_ps_Metal metal
{
source HgSAO_ps.metal
shader_reflection_pair_hint HgSAO_vs_Metal
}
// Unified definitions
vertex_program HgSAO_vs unified
{
delegate HgSAO_vs_HLSL
delegate HgSAO_vs_GLSL
delegate HgSAO_vs_Metal
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
}
}
fragment_program HgSAO_ps unified
{
delegate HgSAO_ps_HLSL
delegate HgSAO_ps_GLSL
delegate HgSAO_ps_Metal
}
// Material definition
material HgSAO
{
technique
{
pass
{
depth_check off
depth_write off
cull_hardware none
vertex_program_ref HgSAO_vs
{
}
fragment_program_ref HgSAO_ps
{
}
texture_unit
{
filtering none none point
tex_address_mode clamp
texture BeachStones.jpg
}
}
}
}
vertex shader HgSAO_vs.metal
Code: Select all
#include <metal_stdlib>
using namespace metal;
struct VS_INPUT
{
float4 position [[attribute(VES_POSITION)]];
float3 normal [[attribute(VES_NORMAL)]];
float2 uv0 [[attribute(VES_TEXTURE_COORDINATES0)]];
};
struct PS_INPUT
{
float2 uv0;
float3 cameraDir;
float4 gl_Position [[position]];
};
vertex PS_INPUT main_metal
(
VS_INPUT input [[stage_in]],
constant float4x4 &worldViewProj [[buffer(PARAMETER_SLOT)]]
)
{
PS_INPUT outVs;
outVs.gl_Position = ( worldViewProj * input.position ).xyzw;
outVs.uv0 = input.uv0;
outVs.cameraDir = input.normal;
return outVs;
}
fragement shader HgSAO_ps.metal
Code: Select all
#include <metal_stdlib>
using namespace metal;
struct PS_INPUT
{
float2 uv0;
float3 cameraDir;
};
fragment float4 main_metal
(
PS_INPUT inPs [[stage_in]],
texture2d<float> depthTexture [[texture(0)]],
sampler samplerState [[sampler(0)]],
constant float2 &projectionParams [[buffer(PARAMETER_SLOT)]]
)
{
float3 fColor = depthTexture.sample( samplerState, inPs.uv0, level(2) ).xyz;
return float4( fColor, 1.0);
}
comment out mipmap_method compute_hq or change to api_default to get auto mipmaps of BeachStones.jpg
I wanted it for an HgSAO. A nice occulsion tech I had working in in an old ogre I did it using a compositor pass listener and generated mipmaps of depth Gbuffer with render calls in the listener, I've got a video of it
https://vimeo.com/15932418.
Entirely separate issue, I post for interest.
As I understand it the metal depth texture doesn't have mipmaps but I think I can sort of see how to add them, I don't know if the other rendering systems have them., but with something like
Code: Select all
//-----------------------------------------------------------------------------------
void MetalDepthTexture::_createSurfaceList()
{
mSurfaceList.clear();
__unsafe_unretained id<MTLTexture> renderTexture = mTexture;
__unsafe_unretained id<MTLTexture> resolveTexture = 0;
if( mMsaaTexture )
{
renderTexture = mMsaaTexture;
resolveTexture = mTexture;
}
for (uint8 face = 0; face < getNumFaces(); face++)
{
{
v1::HardwarePixelBuffer *buf = OGRE_NEW v1::MetalDepthPixelBuffer( this, mName,
mWidth, mHeight,
mDepth, mFormat );
mSurfaceList.push_back( v1::HardwarePixelBufferSharedPtr(buf) );
}
for (uint8 mip = 1; mip <= getNumMipmaps(); mip++)
{
v1::MetalHardwarePixelBuffer *buf = OGRE_NEW v1::MetalTextureBuffer(renderTexture, resolveTexture, mDevice, mName,
getMetalTextureTarget(), mWidth, mHeight, mDepth, mFormat,
static_cast<int32>(face), mip,
static_cast<v1::HardwareBuffer::Usage>(mUsage),
mHwGamma, mFSAA );
mSurfaceList.push_back( v1::HardwarePixelBufferSharedPtr(buf) );
}
}
}
somewhere mMipmapsDirty = true and somewhere where MetalRenderSystem::_createDepthBufferFor desc.mipmapLevelCount needs to be whatever it needs to be
could 'perhaps' get a mipmapped depth buffer this way.
If I ever get it working I'll post it.