Skip to content

Commit

Permalink
Hlms property to emulate user clip planes on devices without HW suppo…
Browse files Browse the repository at this point in the history
…rt, like Google Pixel 7 Pro
  • Loading branch information
eugenegff committed Sep 14, 2023
1 parent afee2d2 commit 5c85ef5
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ namespace Ogre
int32 numClipDist = std::max( getProperty( HlmsBaseProp::PsoClipDistances ), 1 );
setProperty( HlmsBaseProp::PsoClipDistances, numClipDist );
setProperty( HlmsBaseProp::GlobalClipPlanes, 1 );
// some Android devices(e.g. Mali-G77, Google Pixel 7 Pro) do not support Vulkan shaderClipDistance feature
if(!mRenderSystem->getCapabilities()->hasCapability(RSC_USER_CLIP_PLANES))
setProperty(HlmsBaseProp::EmulateClipDistances, 1); //turn on emulation of clipDistances
}

mListener->preparePassHash( shadowNode, casterPass, dualParaboloid, sceneManager, this );
Expand Down
1 change: 1 addition & 0 deletions OgreMain/include/OgreHlms.h
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ namespace Ogre
// Change per scene pass
static const IdString PsoClipDistances;
static const IdString GlobalClipPlanes;
static const IdString EmulateClipDistances;
static const IdString DualParaboloidMapping;
static const IdString InstancedStereo;
static const IdString StaticBranchLights;
Expand Down
4 changes: 4 additions & 0 deletions OgreMain/src/OgreHlms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ namespace Ogre
// Change per scene pass
const IdString HlmsBaseProp::PsoClipDistances = IdString( "hlms_pso_clip_distances" );
const IdString HlmsBaseProp::GlobalClipPlanes = IdString( "hlms_global_clip_planes" );
const IdString HlmsBaseProp::EmulateClipDistances = IdString( "hlms_emulate_clip_distances" );
const IdString HlmsBaseProp::DualParaboloidMapping = IdString( "hlms_dual_paraboloid_mapping" );
const IdString HlmsBaseProp::InstancedStereo = IdString( "hlms_instanced_stereo" );
const IdString HlmsBaseProp::StaticBranchLights = IdString( "hlms_static_branch_lights" );
Expand Down Expand Up @@ -3252,6 +3253,9 @@ namespace Ogre
{
setProperty( HlmsBaseProp::PsoClipDistances, 1 );
setProperty( HlmsBaseProp::GlobalClipPlanes, 1 );
// some Android devices(e.g. Mali-G77, Google Pixel 7 Pro) do not support Vulkan shaderClipDistance feature
if(!mRenderSystem->getCapabilities()->hasCapability(RSC_USER_CLIP_PLANES))
setProperty(HlmsBaseProp::EmulateClipDistances, 1); //turn on emulation of clipDistances
}

const RenderPassDescriptor *renderPassDesc = mRenderSystem->getCurrentPassDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@

#define outVs_Position gl_Position
#define outVs_viewportIndex gl_ViewportIndex
@property( hlms_emulate_clip_distances )
#define outVs_clipDistance0 outVs.clipDistance0
@else
#define outVs_clipDistance0 gl_ClipDistance[0]
@end

#define gl_SampleMaskIn0 gl_SampleMaskIn[0]
#define reversebits bitfieldReverse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,10 @@ struct Material
@end
@end
@end
@property( hlms_emulate_clip_distances && hlms_pso_clip_distances )
@foreach( hlms_pso_clip_distances, n )
INTERPOLANT( float clipDistance@n, @counter(texcoord) );
@end
@end
@insertpiece( custom_VStoPS )
@end
7 changes: 7 additions & 0 deletions Samples/Media/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,13 @@

@property( !hlms_shadowcaster )
@piece( DefaultBodyPS )
@property( hlms_emulate_clip_distances && hlms_global_clip_planes && hlms_pso_clip_distances && syntax == glslvk )
@foreach( hlms_pso_clip_distances, n )
if( inPs.clipDistance@n < 0.0 )
discard;
@end
@end

@property( hlms_screen_pos_uv )
float2 screenPosUv = gl_FragCoord.xy * passBuf.invWindowRes.xy;
@end
Expand Down
2 changes: 1 addition & 1 deletion Samples/Media/Hlms/Pbs/GLSL/VertexShader_vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
out gl_PerVertex
{
vec4 gl_Position;
@property( hlms_pso_clip_distances )
@property( hlms_pso_clip_distances && !hlms_emulate_clip_distances )
float gl_ClipDistance[@value(hlms_pso_clip_distances)];
@end
};
Expand Down
7 changes: 7 additions & 0 deletions Samples/Media/Hlms/Terra/Any/800.PixelShader_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@
@piece( DefaultTerraBodyPS )
PixelData pixelData;

@property( hlms_emulate_clip_distances && hlms_global_clip_planes && hlms_pso_clip_distances && syntax == glslvk)
@foreach( hlms_pso_clip_distances, n )
if( inPs.clipDistance@n < 0.0 )
discard;
@end
@end

@insertpiece( LoadMaterial )
@insertpiece( UnpackTextureIndices0 )
@insertpiece( UnpackTextureIndices1 )
Expand Down
2 changes: 1 addition & 1 deletion Samples/Media/Hlms/Terra/GLSL/VertexShader_vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
out gl_PerVertex
{
vec4 gl_Position;
@property( hlms_pso_clip_distances )
@property( hlms_pso_clip_distances && !hlms_emulate_clip_distances )
float gl_ClipDistance[@value(hlms_pso_clip_distances)];
@end
};
Expand Down
5 changes: 5 additions & 0 deletions Samples/Media/Hlms/Unlit/Any/500.StructsUnlit_piece_all.any
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
@end
@end
@end
@property( hlms_emulate_clip_distances && hlms_pso_clip_distances )
@foreach( hlms_pso_clip_distances, n )
INTERPOLANT( float clipDistance@n, @counter(texcoord) );
@end
@end
@insertpiece( custom_VStoPS )
@end

Expand Down
7 changes: 7 additions & 0 deletions Samples/Media/Hlms/Unlit/Any/800.PixelShader_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
@end

@piece( DefaultBodyPS )
@property( hlms_emulate_clip_distances && hlms_global_clip_planes && hlms_pso_clip_distances && syntax == glslvk)
@foreach( hlms_pso_clip_distances, n )
if( inPs.clipDistance@n < 0.0 )
discard;
@end
@end

midf4 diffuseCol = midf4_c( 1.0f, 1.0f, 1.0f, 1.0f );

@property( diffuse_map || alpha_test || diffuse )
Expand Down
2 changes: 1 addition & 1 deletion Samples/Media/Hlms/Unlit/GLSL/VertexShader_vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
out gl_PerVertex
{
vec4 gl_Position;
@property( hlms_pso_clip_distances )
@property( hlms_pso_clip_distances && !hlms_emulate_clip_distances )
float gl_ClipDistance[@value(hlms_pso_clip_distances)];
@end
};
Expand Down

0 comments on commit 5c85ef5

Please sign in to comment.