forked from gazebosim/gz-rendering
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metal] enable loading of the Metal render system for ogre2
- Add parameter "metal" and a member variable useMetalRenderSystem to Ogre2RenderEngine - Modify LoadPlugins to load the Metal render system if enabled - Modify CreateRenderSystem to select the Metal render system - Modify RegisterHlms to load the Metal resources - Add missing Metal shaders for the Terra (from Ogre2) - Add Metal shader for skybox - Update skybox material to support universal shaders - Create subdirectories for GLSL and Metal in media/materials/programs and update Ogre2RenderEngine with new resource locations - Add Metal and unified shaders to each material - Add placeholders for a number of shaders to prevent compile errors when running examples - Minor formatting changes to plain_color, point and skybox Metal shaders. - Port depth_camera_vs and selection_buffer_fs to Metal - The mouse_picker, ogre2_demo and transform_control demos now work correctly. - Shader formatting - replace tabs with whitespace - Port gaussian_noise vertex and pixel shaders from the GLSL counterparts - The ogre2_demo and render_pass examples now work correctly. - Port thermal_camera pixel shader - Correct error in thermal material script - Port thermal_camera pixel shaders from the GLSL counterparts - The thermal_camera examples now runs but further requires testing - Add stubs for the remaining vertex and pixel shaders to port from GLSL - Port heat_signature pixel shader - Initial ports of depth_camera and gpu_rays shaders - On Metal the compositor in Ogre2GpuRay has a pixel format exception - Texture sampling for depth_camera_final_fs.metal is not using the equivalent of OpenGL's texelFetch - Fix fragment program specifier in gaussian noise material - Unified shader had incorrect specifier - Fix depth camera vertex shader not found in selection buffer material - This is the same issue as fixed in gazebosim#456 - Switch to user RGBA format for internal textures in gpu ray sensor - Complete port of gpu rays 1st pass shader - Complete port of the GPU Rays shader - This depends upon the pixel format fix in gazebosim#468 - Add a method to render targets and cameras to retrieve the Metal texture id - These functions provide the Metal equivalent of GLId() and RenderTextureGLId() for OpenGL. - The argument is the address of a pointer to void* as the object required for Metal is an objective-c type id<MTLTexture> which we do not want exposed in the interface - There is a runtime dependency on an upstream change to ogre-next: OGRECave/ogre-next@3b11873 - cherry-pick 8fc230c - Ensure line length limits are adhered to. - Fix inconsistent parameter name in RenderTextureMetalId - Fix an inconsistent parameter name causing a CI failure. - Fix unused parameter warning in RenderTextureMetalId - Fix an unused parameter warning causing a CI failure. Signed-off-by: Rhys Mainwaring <[email protected]>
- Loading branch information
1 parent
b1d2ac8
commit 1120397
Showing
52 changed files
with
2,196 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
ogre2/src/media/2.0/scripts/materials/Terra/Metal/GpuNormalMapper_ps.metal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Our terrain has the following pattern: | ||
// | ||
// 1N 10 11 | ||
// o-o-o | ||
// |/|/| | ||
// 0N o-+-o 01 | ||
// |/|/| | ||
// o-o-o | ||
// NN N0 N1 | ||
// | ||
// We need to calculate the normal of the vertex in | ||
// the center '+', which is shared by 6 triangles. | ||
|
||
#include <metal_stdlib> | ||
using namespace metal; | ||
|
||
struct PS_INPUT | ||
{ | ||
float2 uv0; | ||
}; | ||
|
||
struct Params | ||
{ | ||
float2 heightMapResolution; | ||
float3 vScale; | ||
}; | ||
|
||
fragment float4 main_metal | ||
( | ||
PS_INPUT inPs [[stage_in]], | ||
|
||
texture2d<float, access::read> heightMap [[texture(0)]], | ||
|
||
constant Params &p [[buffer(PARAMETER_SLOT)]] | ||
) | ||
{ | ||
int2 iCoord = int2( inPs.uv0 * p.heightMapResolution ); | ||
|
||
int3 xN01; | ||
xN01.x = max( iCoord.x - 1, 0 ); | ||
xN01.y = iCoord.x; | ||
xN01.z = min( iCoord.x + 1, int(p.heightMapResolution.x) ); | ||
int3 yN01; | ||
yN01.x = max( iCoord.y - 1, 0 ); | ||
yN01.y = iCoord.y; | ||
yN01.z = min( iCoord.y + 1, int(p.heightMapResolution.y) ); | ||
|
||
//Watch out! It's heightXY, but heightMap.read uses YX. | ||
float heightNN = heightMap.read( ushort2( xN01.x, yN01.x ) ).x * p.vScale.y; | ||
float heightN0 = heightMap.read( ushort2( xN01.y, yN01.x ) ).x * p.vScale.y; | ||
//float heightN1 = heightMap.read( ushort2( xN01.z, yN01.x ) ).x * p.vScale.y; | ||
|
||
float height0N = heightMap.read( ushort2( xN01.x, yN01.y ) ).x * p.vScale.y; | ||
float height00 = heightMap.read( ushort2( xN01.y, yN01.y ) ).x * p.vScale.y; | ||
float height01 = heightMap.read( ushort2( xN01.z, yN01.y ) ).x * p.vScale.y; | ||
|
||
//float height1N = heightMap.read( ushort2( xN01.x, yN01.z ) ).x * p.vScale.y; | ||
float height10 = heightMap.read( ushort2( xN01.y, yN01.z ) ).x * p.vScale.y; | ||
float height11 = heightMap.read( ushort2( xN01.z, yN01.z ) ).x * p.vScale.y; | ||
|
||
float3 vNN = float3( -p.vScale.x, heightNN, -p.vScale.z ); | ||
float3 vN0 = float3( -p.vScale.x, heightN0, 0 ); | ||
//float3 vN1 = float3( -p.vScale.x, heightN1, p.vScale.z ); | ||
|
||
float3 v0N = float3( 0, height0N, -p.vScale.z ); | ||
float3 v00 = float3( 0, height00, 0 ); | ||
float3 v01 = float3( 0, height01, p.vScale.z ); | ||
|
||
//float3 v1N = float3( p.vScale.x, height1N, -p.vScale.z ); | ||
float3 v10 = float3( p.vScale.x, height10, 0 ); | ||
float3 v11 = float3( p.vScale.x, height11, p.vScale.z ); | ||
|
||
float3 vNormal = float3( 0, 0, 0 ); | ||
|
||
vNormal += cross( (v01 - v00), (v11 - v00) ); | ||
vNormal += cross( (v11 - v00), (v10 - v00) ); | ||
vNormal += cross( (v10 - v00), (v0N - v00) ); | ||
vNormal += cross( (v0N - v00), (vNN - v00) ); | ||
vNormal += cross( (vNN - v00), (vN0 - v00) ); | ||
vNormal += cross( (vN0 - v00), (v01 - v00) ); | ||
|
||
// vNormal += cross( (v01 - v00), (v11 - v00) ); | ||
// vNormal += cross( (v11 - v00), (v10 - v00) ); | ||
// vNormal += cross( (v10 - v00), (v1N - v00) ); | ||
// vNormal += cross( (v1N - v00), (v0N - v00) ); | ||
// vNormal += cross( (v0N - v00), (vNN - v00) ); | ||
// vNormal += cross( (vNN - v00), (vN0 - v00) ); | ||
// vNormal += cross( (vN0 - v00), (vN1 - v00) ); | ||
// vNormal += cross( (vN1 - v00), (v01 - v00) ); | ||
|
||
vNormal = normalize( vNormal ); | ||
|
||
//return vNormal.zx; | ||
return float4( vNormal.zyx * 0.5f + 0.5f, 1.0f ); | ||
} |
24 changes: 24 additions & 0 deletions
24
ogre2/src/media/2.0/scripts/materials/Terra/Metal/TerraGaussianBlur_cs.metal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//Based on GPUOpen's samples SeparableFilter11 | ||
//https://github.com/GPUOpen-LibrariesAndSDKs/SeparableFilter11 | ||
//For better understanding, read "Efficient Compute Shader Programming" from Bill Bilodeau | ||
//http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Efficient%20Compute%20Shader%20Programming.pps | ||
|
||
//TL;DR: | ||
// * Each thread works on 4 pixels at a time (for VLIW hardware, i.e. Radeon HD 5000 & 6000 series). | ||
// * 256 pixels per threadgroup. Each threadgroup works on 2 rows of 128 pixels each. | ||
// That means 32x2 threads = 64. 64 threads x 4 pixels per thread = 256 | ||
|
||
@piece( data_type )float3@end | ||
@piece( lds_data_type )float3@end | ||
@piece( lds_definition ) | ||
threadgroup float3 g_f3LDS[ 2 ] [ @value( samples_per_threadgroup ) ] | ||
@end | ||
|
||
@piece( image_sample ) | ||
return inputImage.sample( inputSampler, f2SamplePosition, level(0) ).xyz; | ||
@end | ||
|
||
@piece( image_store ) | ||
@foreach( 4, iPixel ) | ||
outputImage.write( float4( outColour[ @iPixel ], 1.0 ), uint2( i2Center + @iPixel * i2Inc ), 0 );@end | ||
@end |
Oops, something went wrong.