From 7848944490db333d063905369fb0301714961af4 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 25 Nov 2023 17:12:29 -0800 Subject: [PATCH] Review feedback updates --- .../FeatureLib/pfMetalPipeline/CMakeLists.txt | 8 +- .../pfMetalPipeline/ShaderSrc/Avatar.metal | 94 ++++++++-------- .../ShaderSrc/BiasNormals.metal | 45 ++++---- .../ShaderSrc/CompCosines.metal | 47 ++++---- .../ShaderSrc/FixedPipelineShaders.metal | 105 +++++++++--------- .../ShaderSrc/GammaCorrection.metal | 16 ++- .../pfMetalPipeline/ShaderSrc/Grass.metal | 73 +++++++++--- .../ShaderSrc/PlateShaders.metal | 25 +++-- .../ShaderSrc/TextFontShader.metal | 10 +- .../ShaderSrc/WaveDec1Lay_7.metal | 16 ++- .../ShaderSrc/WaveDecEnv.metal | 18 +-- .../pfMetalPipeline/ShaderSrc/WaveRip.metal | 16 ++- .../pfMetalPipeline/ShaderSrc/WaveSet7.metal | 18 +-- .../pfMetalPipeline/plMetalDeviceRef.h | 2 +- .../plMetalMaterialShaderRef.cpp | 15 +-- .../plMetalMaterialShaderRef.h | 14 +-- .../pfMetalPipeline/plMetalPipeline.h | 12 +- .../pfMetalPipeline/plMetalPlateManager.cpp | 2 +- 18 files changed, 301 insertions(+), 235 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt b/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt index 194097c557..2fc73c1de7 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt @@ -1,9 +1,9 @@ include(FetchContent) FetchContent_Declare( - metalcpp - URL_HASH_SHA256 0afd87ca851465191ae4e3980aa036c7e9e02fe32e7c760ac1a74244aae6023b - URL "https://developer.apple.com/metal/cpp/files/metal-cpp_macOS13.3_iOS16.4.zip" + metalcpp + URL_HASH_SHA256 0afd87ca851465191ae4e3980aa036c7e9e02fe32e7c760ac1a74244aae6023b + URL "https://developer.apple.com/metal/cpp/files/metal-cpp_macOS13.3_iOS16.4.zip" ) FetchContent_MakeAvailable(metalcpp) @@ -59,7 +59,7 @@ target_include_directories(pfMetalPipeline PUBLIC "ShaderSrc") source_group("Source Files" FILES ${pfMetalPipeline_SOURCES}) source_group("Header Files" FILES ${pfMetalPipeline_HEADERS}) -add_library( pfMetalPipelineShaders INTERFACE ) +add_library(pfMetalPipelineShaders INTERFACE) set(pfMetalPipeline_SHADERS ShaderSrc/FixedPipelineShaders.metal ShaderSrc/PlateShaders.metal diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Avatar.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Avatar.metal index f6626e2e03..6e4e083d47 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Avatar.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Avatar.metal @@ -1,50 +1,51 @@ /*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com + + CyanWorlds.com Engine - MMOG client, server and tools + Copyright (C) 2011 Cyan Worlds, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Additional permissions under GNU GPL version 3 section 7 + + If you modify this Program, or any covered work, by linking or + combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, + NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent + JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK + (or a modified version of those libraries), + containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, + PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG + JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the + licensors of this Program grant you additional + permission to convey the resulting work. Corresponding Source for a + non-source form of such a combination shall include the source code for + the parts of OpenSSL and IJG JPEG Library used as well as that of the covered + work. + + You can contact Cyan Worlds, Inc. by email legal@cyan.com or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + + *==LICENSE==*/ #include using namespace metal; -typedef struct { +typedef struct +{ float4 position [[position]]; float2 uvPosition; half4 color; @@ -56,20 +57,21 @@ typedef struct float2 uvPostion [[attribute(1)]]; } PreprocessAvatarVertex; -vertex PreprocessAvatarTexturesInOut PreprocessAvatarVertexShader(PreprocessAvatarVertex in [[stage_in]]) { +vertex PreprocessAvatarTexturesInOut PreprocessAvatarVertexShader(PreprocessAvatarVertex in [[stage_in]]) +{ return { float4(in.position.x, in.position.y, 0.0, 1.0 ), in.uvPostion }; } -fragment half4 PreprocessAvatarFragmentShader(PreprocessAvatarTexturesInOut in [[stage_in]], - texture2d layer [[ texture(0) ]], - constant float4& blendColor [[ buffer(0 )]]) +fragment half4 PreprocessAvatarFragmentShader(PreprocessAvatarTexturesInOut in [[stage_in]], + texture2d layer [[ texture(0) ]], + constant float4& blendColor [[ buffer(0 )]]) { constexpr sampler colorSampler(mip_filter::linear, mag_filter::linear, min_filter::linear, address::clamp_to_zero); - + half4 colorSample = layer.sample(colorSampler, in.uvPosition.xy) * half4(blendColor); - + return colorSample; } diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/BiasNormals.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/BiasNormals.metal index c9421562a3..bb055a7feb 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/BiasNormals.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/BiasNormals.metal @@ -45,7 +45,8 @@ using namespace metal; #include "ShaderVertex.h" -typedef struct { +typedef struct +{ float4 TexU0; float4 TexV0; @@ -57,7 +58,8 @@ typedef struct { float4 ScaleBias; } vs_BiasNormalsUniforms; -typedef struct { +typedef struct +{ float4 position [[position]]; float4 texCoord0; float4 texCoord1; @@ -66,25 +68,22 @@ typedef struct { float4 color2; } vs_BiasNormalsOut; -vertex vs_BiasNormalsOut vs_BiasNormals(Vertex in [[stage_in]], - constant vs_BiasNormalsUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +vertex vs_BiasNormalsOut vs_BiasNormals(Vertex in [[ stage_in ]], + constant vs_BiasNormalsUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ vs_BiasNormalsOut out; out.position = float4(in.position, 1.0); - out.texCoord0 = float4( - dot(float4(in.texCoord1, 1.0), uniforms.TexU0), + out.texCoord0 = float4(dot(float4(in.texCoord1, 1.0), uniforms.TexU0), dot(float4(in.texCoord1, 1.0), uniforms.TexV0), - 0, - 1 - ); + 0.f, + 1.f); - out.texCoord1 = float4( - dot(float4(in.texCoord1, 1.0), uniforms.TexU1), + out.texCoord1 = float4(dot(float4(in.texCoord1, 1.0), uniforms.TexU1), dot(float4(in.texCoord1, 1.0), uniforms.TexV1), - 0, - 1 - ); + 0.f, + 1.f); out.color1 = uniforms.ScaleBias.xxzz; out.color2 = uniforms.ScaleBias.yyzz; @@ -92,9 +91,10 @@ vertex vs_BiasNormalsOut vs_BiasNormals(Vertex in [[stage_in]], return out; } -fragment float4 ps_BiasNormals(vs_BiasNormalsOut in [[stage_in]], - texture2d t0 [[ texture(0) ]], - texture2d t1 [[ texture(1) ]]) { +fragment float4 ps_BiasNormals(vs_BiasNormalsOut in [[ stage_in ]], + texture2d t0 [[ texture(0) ]], + texture2d t1 [[ texture(1) ]]) +{ // Composite the cosines together. // Input map is cosine(pix) for each of // the 4 waves. @@ -111,13 +111,14 @@ fragment float4 ps_BiasNormals(vs_BiasNormalsOut in [[stage_in]], // Note also the c4 used for biasing back at the end. constexpr sampler colorSampler = sampler(mip_filter::linear, - mag_filter::linear, - min_filter::linear, - address::repeat); + mag_filter::linear, + min_filter::linear, + address::repeat); + float4 sample1 = t0.sample(colorSampler, in.texCoord0.xy); float4 sample2 = t1.sample(colorSampler, in.texCoord0.xy); - float4 out = float4(sample1.rgb - 0.5 + sample2.rgb - 0.5, - sample1.a + sample2.a); + float4 out = float4(sample1.rgb - 0.5 + sample2.rgb - 0.5, sample1.a + sample2.a); out.rgb = (out.rgb * in.color1.rgb) + in.color2.rgb; + return out; } diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/CompCosines.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/CompCosines.metal index aedd304976..a3620fc26f 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/CompCosines.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/CompCosines.metal @@ -45,7 +45,8 @@ using namespace metal; #include "ShaderVertex.h" -typedef struct { +typedef struct +{ float4 c0; float4 c1; float4 c2; @@ -53,7 +54,8 @@ typedef struct { float4 c4; } vs_CompCosinesUniforms; -typedef struct { +typedef struct +{ float4 position [[position]]; float4 texCoord0; float4 texCoord1; @@ -61,8 +63,9 @@ typedef struct { float4 texCoord3; } vs_CompCosinesnInOut; -vertex vs_CompCosinesnInOut vs_CompCosines(Vertex in [[stage_in]], - constant vs_CompCosinesUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +vertex vs_CompCosinesnInOut vs_CompCosines(Vertex in [[ stage_in ]], + constant vs_CompCosinesUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ vs_CompCosinesnInOut out; out.position = float4(in.position, 1.0); @@ -80,7 +83,8 @@ vertex vs_CompCosinesnInOut vs_CompCosines(Vertex in [[stage_in]], return out; } -typedef struct { +typedef struct +{ float4 c0; float4 c1; float4 c2; @@ -89,12 +93,13 @@ typedef struct { float4 c5; } ps_CompCosinesUniforms; -fragment float4 ps_CompCosines(vs_CompCosinesnInOut in [[stage_in]], - texture2d t0 [[ texture(0) ]], - texture2d t1 [[ texture(1) ]], - texture2d t2 [[ texture(2) ]], - texture2d t3 [[ texture(3) ]], - constant ps_CompCosinesUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +fragment float4 ps_CompCosines(vs_CompCosinesnInOut in [[ stage_in ]], + texture2d t0 [[ texture(0) ]], + texture2d t1 [[ texture(1) ]], + texture2d t2 [[ texture(2) ]], + texture2d t3 [[ texture(3) ]], + constant ps_CompCosinesUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ // Composite the cosines together. // Input map is cosine(pix) for each of // the 4 waves. @@ -111,18 +116,18 @@ fragment float4 ps_CompCosines(vs_CompCosinesnInOut in [[stage_in]], // Note also the c4 used for biasing back at the end. constexpr sampler colorSampler = sampler(mip_filter::linear, - mag_filter::linear, - min_filter::linear, - address::repeat); - - float4 out = 2 * (t0.sample(colorSampler, fract(in.texCoord0.xy)) - 0.5) * uniforms.c0; - out += 2 * (t1.sample(colorSampler, fract(in.texCoord1.xy)) - 0.5) * uniforms.c1; - out += 2 * (t2.sample(colorSampler, fract(in.texCoord2.xy)) - 0.5) * uniforms.c2; - out += 2 * (t3.sample(colorSampler, fract(in.texCoord3.xy)) - 0.5) * uniforms.c3; + mag_filter::linear, + min_filter::linear, + address::repeat); + + float4 out = 2.f * (t0.sample(colorSampler, fract(in.texCoord0.xy)) - 0.5f) * uniforms.c0; + out += 2.f * (t1.sample(colorSampler, fract(in.texCoord1.xy)) - 0.5f) * uniforms.c1; + out += 2.f * (t2.sample(colorSampler, fract(in.texCoord2.xy)) - 0.5f) * uniforms.c2; + out += 2.f * (t3.sample(colorSampler, fract(in.texCoord3.xy)) - 0.5f) * uniforms.c3; // Now bias it back into range [0..1] for output. out *= uniforms.c4; out += uniforms.c5; - out.b = 1.0; - out.a = 1.0; + out.b = 1.f; + out.a = 1.f; return out; } diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal index 3707a237ff..6b9bbc8884 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal @@ -58,7 +58,8 @@ using namespace metal; #include "hsGMatStateEnums.h" -enum plUVWSrcModifiers: uint32_t{ +enum plUVWSrcModifiers: uint32_t +{ kUVWPassThru = 0x00000000, kUVWIdxMask = 0x0000ffff, kUVWNormal = 0x00010000, @@ -119,7 +120,8 @@ constant const bool hasCubicTexture6 = (sourceType6 == PassTypeCubicTexture && h constant const bool hasCubicTexture7 = (sourceType7 == PassTypeCubicTexture && hasLayer7); constant const bool hasCubicTexture8 = (sourceType8 == PassTypeCubicTexture && hasLayer8); -struct FragmentShaderArguments { +struct FragmentShaderArguments +{ texture2d textures [[ texture(FragmentShaderArgumentAttributeTextures), function_constant(has2DTexture1) ]]; texture2d texture2 [[ texture(FragmentShaderArgumentAttributeTextures + 1), function_constant(has2DTexture2) ]]; texture2d texture3 [[ texture(FragmentShaderArgumentAttributeTextures + 2), function_constant(has2DTexture3) ]]; @@ -172,27 +174,27 @@ typedef struct } ShadowCasterInOut; vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]], - constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]], - constant plMetalLights & lights [[ buffer(VertexShaderArgumentLights) ]], - constant float4x4 & blendMatrix1 [[ buffer(VertexShaderArgumentBlendMatrix1), function_constant(temp_hasOnlyWeight1) ]]) + constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]], + constant plMetalLights & lights [[ buffer(VertexShaderArgumentLights) ]], + constant float4x4 & blendMatrix1 [[ buffer(VertexShaderArgumentBlendMatrix1), function_constant(temp_hasOnlyWeight1) ]]) { ColorInOut out; // we should have been able to swizzle, but it didn't work in Xcode beta? Try again later. - const half4 inColor = half4(in.color.b, in.color.g, in.color.r, in.color.a) / half4(255.0f); + const half4 inColor = half4(in.color.b, in.color.g, in.color.r, in.color.a) / half4(255.f); const half3 MAmbient = mix(inColor.rgb, uniforms.ambientCol, uniforms.ambientSrc); const half4 MDiffuse = mix(inColor, uniforms.diffuseCol, uniforms.diffuseSrc); const half3 MEmissive = mix(inColor.rgb, uniforms.emissiveCol, uniforms.emissiveSrc); - half3 LAmbient = half3(0.0, 0.0, 0.0); - half3 LDiffuse = half3(0.0, 0.0, 0.0); + half3 LAmbient = half3(0.h, 0.h, 0.h); + half3 LDiffuse = half3(0.h, 0.h, 0.h); - const float3 Ndirection = normalize(float4(in.normal, 0.0) * uniforms.localToWorldMatrix).xyz; + const float3 Ndirection = normalize(float4(in.normal, 0.f) * uniforms.localToWorldMatrix).xyz; - float4 position = (float4(in.position, 1.0) * uniforms.localToWorldMatrix); + float4 position = float4(in.position, 1.f) * uniforms.localToWorldMatrix; if (temp_hasOnlyWeight1) { - const float4 position2 = blendMatrix1 * float4(in.position, 1.0); - position = (in.weight1 * position) + ((1.0f - in.weight1) * position2); + const float4 position2 = blendMatrix1 * float4(in.position, 1.f); + position = (in.weight1 * position) + ((1.f - in.weight1) * position2); } for (size_t i = 0; i < lights.count; i++) { @@ -203,18 +205,18 @@ vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]], // direction.w is attenuation float4 direction; - if (lightSource->position.w == 0.0) { + if (lightSource->position.w == 0.f) { // Directional Light with no attenuation - direction = float4(-(lightSource->direction).xyz, 1.0); + direction = float4(-(lightSource->direction).xyz, 1.f); } else { // Omni Light in all directions const float3 v2l = lightSource->position.xyz - position.xyz; const float distance = length(v2l); direction.xyz = normalize(v2l); - direction.w = 1.0 / (lightSource->constAtten + lightSource->linAtten * distance + lightSource->quadAtten * pow(distance, 2.0)); + direction.w = 1.f / (lightSource->constAtten + lightSource->linAtten * distance + lightSource->quadAtten * pow(distance, 2.f)); - if (lightSource->spotProps.x > 0.0) { + if (lightSource->spotProps.x > 0.f) { // Spot Light with cone falloff const float theta = dot(direction.xyz, normalize(-lightSource->direction).xyz); // inner cutoff @@ -222,7 +224,7 @@ vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]], // outer cutoff const float phi = lightSource->spotProps.z; const float epsilon = (gamma - phi); - const float intensity = clamp((theta - phi) / epsilon, 0.0, 1.0); + const float intensity = clamp((theta - phi) / epsilon, 0.f, 1.f); direction.w *= pow(intensity, lightSource->spotProps.x); } @@ -230,12 +232,12 @@ vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]], LAmbient.rgb = LAmbient.rgb + half3(direction.w * (lightSource->ambient.rgb * lightSource->scale)); const float3 dotResult = dot(Ndirection, direction.xyz); - LDiffuse.rgb = LDiffuse.rgb + MDiffuse.rgb * (lightSource->diffuse.rgb * lightSource->scale) * half3(max(0.0, dotResult) * direction.w); + LDiffuse.rgb = LDiffuse.rgb + MDiffuse.rgb * (lightSource->diffuse.rgb * lightSource->scale) * half3(max(0.f, dotResult) * direction.w); } - const half3 ambient = (MAmbient.rgb) * clamp(uniforms.globalAmb.rgb + LAmbient.rgb, 0.0, 1.0); - const half3 diffuse = clamp(LDiffuse.rgb, 0.0, 1.0); - const half4 material = half4(clamp(ambient + diffuse + MEmissive.rgb, 0.0, 1.0), + const half3 ambient = (MAmbient.rgb) * clamp(uniforms.globalAmb.rgb + LAmbient.rgb, 0.h, 1.h); + const half3 diffuse = clamp(LDiffuse.rgb, 0.h, 1.h); + const half4 material = half4(clamp(ambient + diffuse + MEmissive.rgb, 0.h, 1.h), abs(uniforms.invVtxAlpha - MDiffuse.a)); out.vtxColor = half4(material.rgb, abs(uniforms.invVtxAlpha - MDiffuse.a)); @@ -244,7 +246,7 @@ vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]], // Fog out.fogColor = uniforms.calcFog(vCamPosition); - const float4 normal = (uniforms.localToWorldMatrix * float4(in.normal, 0.0)) * uniforms.worldToCameraMatrix; + const float4 normal = (uniforms.localToWorldMatrix * float4(in.normal, 0.f)) * uniforms.worldToCameraMatrix; for (size_t layer=0; layer 0) { resultColor.a = exp(-pow(fogValues.y * length(camPosition), fogValues.x)); @@ -392,7 +394,8 @@ half4 VertexUniforms::calcFog(float4 camPosition) constant { return resultColor; } -half4 FragmentShaderArguments::sampleLayer(const size_t index, const half4 vertexColor, const uint8_t passType, float3 sampleCoord) const { +half4 FragmentShaderArguments::sampleLayer(const size_t index, const half4 vertexColor, const uint8_t passType, float3 sampleCoord) const +{ if (passType == PassTypeColor) { return vertexColor; } else { @@ -406,7 +409,7 @@ half4 FragmentShaderArguments::sampleLayer(const size_t index, const half4 verte } else if (passType == PassTypeCubicTexture) { return (&cubicTextures)[index].sample((&samplers)[index], sampleCoord.xyz); } else { - return half4(0); + return half4(0.h); } } } @@ -454,7 +457,8 @@ fragment half4 pipelineFragmentShader(ColorInOut in [[stage_in]], return currentColor; } -constexpr void blendFirst(half4 srcSample, thread half4 &destSample, const uint32_t blendFlags) { +constexpr void blendFirst(half4 srcSample, thread half4 &destSample, const uint32_t blendFlags) +{ // Local variable to store the color value if (blendFlags & kBlendInvertColor) { srcSample.rgb = 1.0h - srcSample.rgb; @@ -476,7 +480,8 @@ constexpr void blendFirst(half4 srcSample, thread half4 &destSample, const uint3 } } -constexpr void blend(half4 srcSample, thread half4 &destSample, const uint32_t blendFlags) { +constexpr void blend(half4 srcSample, thread half4 &destSample, const uint32_t blendFlags) +{ // Local variable to store the color value if (blendFlags & kBlendInvertColor) { srcSample.rgb = 1.0h - srcSample.rgb; @@ -569,8 +574,8 @@ constexpr void blend(half4 srcSample, thread half4 &destSample, const uint32_t b } } -vertex ShadowCasterInOut shadowVertexShader(Vertex in [[stage_in]], - constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]]) +vertex ShadowCasterInOut shadowVertexShader(Vertex in [[stage_in]], + constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]]) { ShadowCasterInOut out; @@ -605,14 +610,14 @@ fragment half4 shadowFragmentShader(ShadowCasterInOut in [[stage_in]]) property. There is no need to push an entirely new light table. */ -vertex ColorInOut shadowCastVertexShader(Vertex in [[stage_in]], - constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]], - constant plShadowState & shadowState [[ buffer(VertexShaderArgumentShadowState) ]]) +vertex ColorInOut shadowCastVertexShader(Vertex in [[ stage_in ]], + constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]], + constant plShadowState & shadowState [[ buffer(VertexShaderArgumentShadowState) ]]) { ColorInOut out; - float4 position = (float4(in.position, 1.0) * uniforms.localToWorldMatrix); - const float3 Ndirection = normalize(float4(in.normal, 0.0) * uniforms.localToWorldMatrix).xyz; + float4 position = (float4(in.position, 1.f) * uniforms.localToWorldMatrix); + const float3 Ndirection = normalize(float4(in.normal, 0.f) * uniforms.localToWorldMatrix).xyz; // Shadow casting uses the diffuse material color to control opacity const half4 MDiffuse = uniforms.diffuseCol; @@ -621,16 +626,16 @@ vertex ColorInOut shadowCastVertexShader(Vertex in [[stage_in]], if (shadowState.directional == true) { // Directional Light with no attenuation - direction = float4(-(shadowState.lightDirection).xyz, 1.0); + direction = float4(-(shadowState.lightDirection).xyz, 1.f); } else { // Omni Light in all directions const float3 v2l = shadowState.lightPosition.xyz - position.xyz; direction.xyz = normalize(v2l); - direction.w = 1.0; + direction.w = 1.f; } const float3 dotResult = dot(Ndirection, direction.xyz); - const half3 diffuse = MDiffuse.rgb * half3(max(0.0, dotResult)) * shadowState.power; + const half3 diffuse = MDiffuse.rgb * half3(max(0.h, dotResult)) * shadowState.power; out.vtxColor = half4(diffuse, 1.f); const float4 vCamPosition = position * uniforms.worldToCameraMatrix; @@ -638,7 +643,7 @@ vertex ColorInOut shadowCastVertexShader(Vertex in [[stage_in]], // Fog out.fogColor = uniforms.calcFog(vCamPosition); - const float4 normal = (uniforms.localToWorldMatrix * float4(in.normal, 0.0)) * uniforms.worldToCameraMatrix; + const float4 normal = (uniforms.localToWorldMatrix * float4(in.normal, 0.f)) * uniforms.worldToCameraMatrix; for (size_t layer=0; layer texture [[ texture(16) ]], - constant plMetalShadowCastFragmentShaderArgumentBuffer & fragmentUniforms [[ buffer(FragmentShaderArgumentShadowCastUniforms) ]], + texture2d texture [[ texture(16) ]], + constant plMetalShadowCastFragmentShaderArgumentBuffer & fragmentUniforms [[ buffer(FragmentShaderArgumentShadowCastUniforms) ]], FragmentShaderArguments layers, - constant int & alphaSrc [[ buffer(FragmentShaderArgumentShadowCastAlphaSrc) ]]) + constant int & alphaSrc [[ buffer(FragmentShaderArgumentShadowCastAlphaSrc) ]]) { float3 sampleCoords = in.texCoord1; if (fragmentUniforms.pointLightCast) { @@ -675,7 +680,7 @@ fragment half4 shadowCastFragmentShader(ColorInOut in [[stage_in]], // only possible alpha sources are layers 0 or 1 if (alphaSrc == 0 && passCount > 0) { - half4 layerColor = layers.sampleLayer(0, in.vtxColor,sourceTypes[0], in.texCoord3); + half4 layerColor = layers.sampleLayer(0.h, in.vtxColor,sourceTypes[0], in.texCoord3); currentColor.rgb *= layerColor.a; currentColor.rgb *= in.vtxColor.a; diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/GammaCorrection.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/GammaCorrection.metal index 63000b5e69..bc1be0ff26 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/GammaCorrection.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/GammaCorrection.metal @@ -55,23 +55,21 @@ struct GammaVertexOut float2 texturePosition; }; -vertex GammaVertexOut gammaCorrectVertex(constant GammaVertexIn *in [[ buffer(0) ]], - uint vertexID [[ vertex_id ]]) +vertex GammaVertexOut gammaCorrectVertex(constant GammaVertexIn *in [[ buffer(0) ]], + uint vertexID [[ vertex_id ]]) { GammaVertexOut out; // Just pass the position through. We're clearing in NDC space. - out.position = float4(in[vertexID].position, 0.5, 1.0); + out.position = float4(in[vertexID].position, 0.5f, 1.f); out.texturePosition = float2(in[vertexID].texturePosition); return out; } -const constant sampler lutSampler = sampler( - filter::nearest - ); +const constant sampler lutSampler = sampler(filter::nearest); -fragment half4 gammaCorrectFragment(GammaVertexOut in [[stage_in]], - texture2d inputTexture [[texture(0)]], - texture1d_array LUT [[texture(1)]]) +fragment half4 gammaCorrectFragment(GammaVertexOut in [[stage_in]], + texture2d inputTexture [[texture(0)]], + texture1d_array LUT [[texture(1)]]) { float4 color = inputTexture.read(ushort2(in.position.xy)); return { diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Grass.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Grass.metal index f5e5470b13..888ba89d76 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Grass.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Grass.metal @@ -1,9 +1,44 @@ -// -// GrassShader.metal -// plGLClient -// -// Created by Colin Cornaby on 1/1/22. -// +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ #include using namespace metal; @@ -12,7 +47,8 @@ using namespace metal; // ignoring the int and pi constants here and using whats built in // but reserving space for them in the buffer -typedef struct { +typedef struct +{ matrix_float4x4 Local2NDC; float4 intConstants; float4 time; @@ -26,14 +62,16 @@ typedef struct { float4 waveSpeed; } vs_GrassUniforms; -typedef struct { +typedef struct +{ float4 position [[position]]; float4 color; float4 texCoord; } vs_GrassInOut; -vertex vs_GrassInOut vs_GrassShader(Vertex in [[stage_in]], - constant vs_GrassUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +vertex vs_GrassInOut vs_GrassShader(Vertex in [[stage_in]], + constant vs_GrassUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ vs_GrassInOut out; float4 r0 = (in.position.x * uniforms.waveDirX) + (in.position.y * uniforms.waveDirX); @@ -41,7 +79,7 @@ vertex vs_GrassInOut vs_GrassShader(Vertex in [[stage_in]], r0 += (uniforms.time.x * uniforms.waveSpeed); // scale by speed and add to X,Y input r0 = fract(r0); - r0 = (r0 - 0.5) * M_PI_F * 2; + r0 = (r0 - 0.5f) * M_PI_F * 2.f; float4 pow2 = r0 * r0; float4 pow3 = pow2 * r0; @@ -60,19 +98,20 @@ vertex vs_GrassInOut vs_GrassShader(Vertex in [[stage_in]], dot(r0, uniforms.waveDistortZ) ); - offset *= (2.0 * (1.0 - in.texCoord1.y)); // mult by Y tex coord. So the waves only affect the top verts + offset *= (2.f * (1.f - in.texCoord1.y)); // mult by Y tex coord. So the waves only affect the top verts float4 position = float4(in.position.xyz + offset, 1); out.position = position * uniforms.Local2NDC; - out.color = float4(in.color.r, in.color.g, in.color.b, in.color.a) / 255.0; - out.texCoord = float4(in.texCoord1, 0.0); + out.color = float4(in.color.r, in.color.g, in.color.b, in.color.a) / 255.f; + out.texCoord = float4(in.texCoord1, 0.f); return out; } -fragment half4 ps_GrassShader(vs_GrassInOut in [[stage_in]], - texture2d t0 [[ texture(0) ]]) { +fragment half4 ps_GrassShader(vs_GrassInOut in [[stage_in]], + texture2d t0 [[ texture(0) ]]) +{ constexpr sampler colorSampler = sampler(mip_filter::linear, mag_filter::linear, min_filter::linear, @@ -80,7 +119,7 @@ fragment half4 ps_GrassShader(vs_GrassInOut in [[stage_in]], half4 out = t0.sample(colorSampler, in.texCoord.xy); out *= half4(in.color); - if (out.a <= 0.1) + if (out.a <= 0.1h) discard_fragment(); return out; } diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/PlateShaders.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/PlateShaders.metal index 810ddb7355..fc4db3f84a 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/PlateShaders.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/PlateShaders.metal @@ -52,9 +52,10 @@ using namespace metal; using namespace metal; -typedef struct { - array, 8> textures [[ id(FragmentShaderArgumentAttributeTextures) ]]; - array, 8> cubicTextures [[ id(FragmentShaderArgumentAttributeCubicTextures) ]]; +typedef struct +{ + array, 8> textures [[ id(FragmentShaderArgumentAttributeTextures) ]]; + array, 8> cubicTextures [[ id(FragmentShaderArgumentAttributeCubicTextures) ]]; } FragmentShaderArguments; typedef struct @@ -71,26 +72,26 @@ typedef struct } ColorInOut; vertex ColorInOut plateVertexShader(PlateVertex in [[stage_in]], - constant VertexUniforms & uniforms [[ buffer(VertexShaderArgumentFixedFunctionUniforms) ]], - uint v_id [[vertex_id]]) + constant VertexUniforms & uniforms [[ buffer(VertexShaderArgumentFixedFunctionUniforms) ]], + uint v_id [[ vertex_id ]]) { ColorInOut out; - float4 position = float4(in.position, 0.0, 1.0); + float4 position = float4(in.position, 0.f, 1.f); position = position * uniforms.projectionMatrix; out.position = ( position * uniforms.localToWorldMatrix); - out.position.y *= -1.0f; + out.position.y *= -1.f; out.texCoord = (float4(in.texCoord, 1.0) * uniforms.uvTransforms[0].transform).xyz; - out.texCoord.y = 1.0 - out.texCoord.y; - out.normal = float4(0.0, 0.0, 1.0, 0.0); + out.texCoord.y = 1.f - out.texCoord.y; + out.normal = float4(0.f, 0.f, 1.f, 0.f); return out; } fragment float4 fragmentShader(ColorInOut in [[stage_in]], - constant VertexUniforms & uniforms [[ buffer(VertexShaderArgumentFixedFunctionUniforms) ]], - constant float & alpha [[ buffer(6) ]], - texture2d colorMap [[ texture( FragmentShaderArgumentTexture) ]]) + constant VertexUniforms & uniforms [[ buffer(VertexShaderArgumentFixedFunctionUniforms) ]], + constant float & alpha [[ buffer(6) ]], + texture2d colorMap [[ texture(FragmentShaderArgumentTexture) ]]) { constexpr sampler colorSampler(mip_filter::linear, mag_filter::linear, diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/TextFontShader.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/TextFontShader.metal index 89513a03eb..8d4b396082 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/TextFontShader.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/TextFontShader.metal @@ -42,12 +42,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include using namespace metal; -// File for Metal kernel and shader functions #include #include -// Including header shared between this Metal shader code and Swift/C code executing Metal API commands #import "ShaderTypes.h" @@ -68,8 +66,8 @@ typedef struct half4 color; } ColorInOut; -vertex ColorInOut textFontVertexShader(constant Vertex *in [[ buffer(0) ]], - constant matrix_float4x4 & transform [[ buffer(1) ]], +vertex ColorInOut textFontVertexShader(constant Vertex *in [[ buffer(0) ]], + constant matrix_float4x4 & transform [[ buffer(1) ]], uint v_id [[vertex_id]]) { ColorInOut out; @@ -84,8 +82,8 @@ vertex ColorInOut textFontVertexShader(constant Vertex *in [[ buffer(0) ]], return out; } -fragment half4 textFontFragmentShader(ColorInOut in [[stage_in]], - texture2d colorMap [[ texture(0) ]]) +fragment half4 textFontFragmentShader(ColorInOut in [[stage_in]], + texture2d colorMap [[ texture(0) ]]) { constexpr sampler colorSampler(mip_filter::nearest, mag_filter::nearest, diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDec1Lay_7.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDec1Lay_7.metal index c190044888..bbce3cfcaa 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDec1Lay_7.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDec1Lay_7.metal @@ -45,7 +45,8 @@ using namespace metal; #include "ShaderVertex.h" -typedef struct { +typedef struct +{ matrix_float4x4 WorldToNDC; float4 Frequency; float4 Phase; @@ -84,15 +85,17 @@ typedef struct { float4 DirYSqKW; // Only used by DecalEnv } vs_WaveDev1Lay_7Uniforms; -typedef struct { +typedef struct +{ float4 position [[position]]; half4 c0; float4 texCoord0; half4 fog; } vs_WaveDev1Lay_7InOut; -vertex vs_WaveDev1Lay_7InOut vs_WaveDec1Lay_7(Vertex in [[stage_in]], - constant vs_WaveDev1Lay_7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +vertex vs_WaveDev1Lay_7InOut vs_WaveDec1Lay_7(Vertex in [[stage_in]], + constant vs_WaveDev1Lay_7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ vs_WaveDev1Lay_7InOut out; // Store our input position in world space in r6 float4 worldPosition = float4(0); @@ -270,8 +273,9 @@ vertex vs_WaveDev1Lay_7InOut vs_WaveDec1Lay_7(Vertex in [[stage_in]], return out; } -fragment half4 ps_CbaseAbase(vs_WaveDev1Lay_7InOut in [[stage_in]], - texture2d texture [[ texture(0) ]]) { +fragment half4 ps_CbaseAbase(vs_WaveDev1Lay_7InOut in [[stage_in]], + texture2d texture [[ texture(0) ]]) +{ constexpr sampler colorSampler = sampler(mip_filter::linear, mag_filter::linear, diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDecEnv.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDecEnv.metal index f74fe431fe..b70c05c335 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDecEnv.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveDecEnv.metal @@ -45,7 +45,8 @@ using namespace metal; #include "ShaderVertex.h" -typedef struct { +typedef struct +{ matrix_float4x4 WorldToNDC; float4 Frequency; float4 Phase; @@ -84,7 +85,8 @@ typedef struct { float4 DirYSqKW; // Only used by DecalEnv } vs_WaveDecEnv7Uniforms; -typedef struct { +typedef struct +{ float4 position [[position]]; float4 c1; float4 texCoord0; @@ -94,8 +96,9 @@ typedef struct { float fog; } vs_WaveDecEnv7InOut; -vertex vs_WaveDecEnv7InOut vs_WaveDecEnv_7(Vertex in [[stage_in]], - constant vs_WaveDecEnv7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +vertex vs_WaveDecEnv7InOut vs_WaveDecEnv_7(Vertex in [[ stage_in ]], + constant vs_WaveDecEnv7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ vs_WaveDecEnv7InOut out; // Store our input position in world space in r6 @@ -403,9 +406,10 @@ vertex vs_WaveDecEnv7InOut vs_WaveDecEnv_7(Vertex in [[stage_in]], return out; } -fragment float4 ps_WaveDecEnv(vs_WaveDecEnv7InOut in [[stage_in]], - texture2d normalMap [[ texture(0) ]], - texturecube environmentMap [[ texture(FragmentShaderArgumentAttributeCubicTextures + 1) ]]) { +fragment float4 ps_WaveDecEnv(vs_WaveDecEnv7InOut in [[ stage_in ]], + texture2d normalMap [[ texture(0) ]], + texturecube environmentMap [[ texture(FragmentShaderArgumentAttributeCubicTextures + 1) ]]) +{ // Very simular to ps_WaveFixed.inl. Only the final coloring is different. // Even though so far they are identical. diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveRip.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveRip.metal index 83885af0a7..1b59e2bed4 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveRip.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveRip.metal @@ -45,7 +45,8 @@ using namespace metal; #include "ShaderVertex.h" -typedef struct { +typedef struct +{ matrix_float4x4 WorldToNDC; float4 FogSet; float4 Frequency; @@ -81,15 +82,17 @@ typedef struct { float4 RampBias; } vs_WaveRip7Uniforms; -typedef struct { +typedef struct +{ float4 position [[position]]; half4 c1; float2 texCoord0; float fog; } waveRipInOut; -vertex waveRipInOut vs_WaveRip7(Vertex in [[stage_in]], - constant vs_WaveRip7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +vertex waveRipInOut vs_WaveRip7(Vertex in [[stage_in]], + constant vs_WaveRip7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ waveRipInOut out; // Store our input position in world space in r6 @@ -289,8 +292,9 @@ vertex waveRipInOut vs_WaveRip7(Vertex in [[stage_in]], return out; } -fragment half4 ps_WaveRip(waveRipInOut in [[stage_in]], - texture2d texture [[ texture(0) ]]) { +fragment half4 ps_WaveRip(waveRipInOut in [[stage_in]], + texture2d texture [[ texture(0) ]]) +{ constexpr sampler colorSampler = sampler(mip_filter::linear, mag_filter::linear, min_filter::linear, diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveSet7.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveSet7.metal index f56e600f8e..d0efefcce6 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveSet7.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/WaveSet7.metal @@ -45,7 +45,8 @@ using namespace metal; #include "ShaderVertex.h" -typedef struct { +typedef struct +{ matrix_float4x4 WorldToNDC; float4 WaterTint; float4 Frequency; @@ -82,7 +83,8 @@ typedef struct { float4 DirYSqKW; } vs_WaveFixedFin7Uniforms; -typedef struct { +typedef struct +{ float4 position [[position]]; float4 c1; float4 c2; @@ -93,8 +95,9 @@ typedef struct { float fog; } vs_WaveFixedFin7InOut; -vertex vs_WaveFixedFin7InOut vs_WaveFixedFin7(Vertex in [[stage_in]], - constant vs_WaveFixedFin7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) { +vertex vs_WaveFixedFin7InOut vs_WaveFixedFin7(Vertex in [[stage_in]], + constant vs_WaveFixedFin7Uniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) +{ vs_WaveFixedFin7InOut out; // Store our input position in world space in r6 @@ -437,9 +440,10 @@ vertex vs_WaveFixedFin7InOut vs_WaveFixedFin7(Vertex in [[stage_in]], return out; } -fragment float4 ps_WaveFixed(vs_WaveFixedFin7InOut in [[stage_in]], - texture2d normalMap [[ texture(0) ]], - texturecube environmentMap [[ texture(FragmentShaderArgumentAttributeCubicTextures + 3) ]]) { +fragment float4 ps_WaveFixed(vs_WaveFixedFin7InOut in [[stage_in]], + texture2d normalMap [[ texture(0) ]], + texturecube environmentMap [[ texture(FragmentShaderArgumentAttributeCubicTextures + 3) ]]) +{ // Short pixel shader. Use the texm3x3vspec to do a per-pixel // reflected lookup into our environment map. // Input: diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h index 8206757594..5d9dbd2321 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h @@ -289,7 +289,7 @@ class plMetalRenderTargetRef : public plMetalTextureRef void Link(plMetalRenderTargetRef** back) { plMetalDeviceRef::Link((plMetalDeviceRef**)back); } plMetalRenderTargetRef* GetNext() const { return (plMetalRenderTargetRef*)fNext; } - plMetalRenderTargetRef() : fDepthBuffer(nullptr) + plMetalRenderTargetRef() : fDepthBuffer() { } diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.cpp index 85269bf520..725eb9eb74 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.cpp @@ -165,12 +165,13 @@ void plMetalMaterialShaderRef::FastEncodeArguments(MTL::RenderCommandEncoder* en encoder->setFragmentBuffer(fPassArgumentBuffers[pass], 0, FragmentShaderArgumentUniforms); } -void plMetalMaterialShaderRef::EncodeArguments(MTL::RenderCommandEncoder* encoder, - VertexUniforms* vertexUniforms, uint pass, +void plMetalMaterialShaderRef::EncodeArguments(MTL::RenderCommandEncoder* encoder, + VertexUniforms* vertexUniforms, + const uint pass, plMetalFragmentShaderDescription* passDescription, std::vector* piggyBacks, - std::function preEncodeTransform, - std::function postEncodeTransform) + const std::function preEncodeTransform, + const std::function postEncodeTransform) { std::vector layers = GetLayersForPass(pass); @@ -201,7 +202,7 @@ void plMetalMaterialShaderRef::EncodeArguments(MTL::RenderCommandEncoder* encode encoder->setFragmentBytes(&uniforms, sizeof(plMetalFragmentShaderArgumentBuffer), FragmentShaderArgumentUniforms); } -void plMetalMaterialShaderRef::EncodeTransform(plLayerInterface* layer, UVOutDescriptor* transform) +void plMetalMaterialShaderRef::EncodeTransform(const plLayerInterface* layer, UVOutDescriptor* transform) { matrix_float4x4 tXfm; hsMatrix2SIMD(layer->GetTransform(), &tXfm); @@ -307,7 +308,7 @@ const hsGMatState plMetalMaterialShaderRef::ICompositeLayerState(const plLayerIn return state; } -void plMetalMaterialShaderRef::IBuildLayerTexture(MTL::RenderCommandEncoder* encoder, uint32_t offsetFromRootLayer, plLayerInterface* layer) +void plMetalMaterialShaderRef::IBuildLayerTexture(MTL::RenderCommandEncoder* encoder, const uint32_t offsetFromRootLayer, plLayerInterface* layer) { // Reminder: Encoder is allowed to be null when Plasma is precompiling pipeline states // Metal needs to know if a shader is 2D or Cubic to compile shaders @@ -411,7 +412,7 @@ bool plMetalMaterialShaderRef::ICanEatLayer(plLayerInterface* lay) return true; } -uint32_t plMetalMaterialShaderRef::IHandleMaterial(uint32_t layer, +uint32_t plMetalMaterialShaderRef::IHandleMaterial(uint32_t layer, plMetalFragmentShaderDescription* passDescription, plMetalFragmentShaderArgumentBuffer* uniforms, std::vector* piggybacks, diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h index 0ab3eddd66..ae643e56cb 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h @@ -80,16 +80,16 @@ class plMetalMaterialShaderRef : public plMetalDeviceRef uint32_t GetNumPasses() const { return fNumPasses; } - uint32_t GetPassIndex(size_t which) const { return fPassIndices[which]; } + uint32_t GetPassIndex(const size_t which) const { return fPassIndices[which]; } const std::vector GetLayersForPass(size_t pass) const { return fPasses[pass]; } - void EncodeArguments(MTL::RenderCommandEncoder* encoder, + void EncodeArguments(MTL::RenderCommandEncoder* encoder, VertexUniforms* vertexUniforms, - uint pass, + const uint pass, plMetalFragmentShaderDescription* passDescription, std::vector* piggyBacks, - std::function preEncodeTransform, - std::function postEncodeTransform); + const std::function preEncodeTransform, + const std::function postEncodeTransform); void FastEncodeArguments(MTL::RenderCommandEncoder* encoder, VertexUniforms* vertexUniforms, uint pass); // probably not a good idea to call prepareTextures directly // mostly just a hack to keep plates working for now @@ -119,8 +119,8 @@ class plMetalMaterialShaderRef : public plMetalDeviceRef bool ICanEatLayer(plLayerInterface* lay); uint32_t ILayersAtOnce(uint32_t which); - void IBuildLayerTexture(MTL::RenderCommandEncoder* encoder, uint32_t offsetFromRootLayer, plLayerInterface* layer); - void EncodeTransform(plLayerInterface* layer, UVOutDescriptor *transform); + void IBuildLayerTexture(MTL::RenderCommandEncoder* encoder, const uint32_t offsetFromRootLayer, plLayerInterface* layer); + void EncodeTransform(const plLayerInterface* layer, UVOutDescriptor *transform); std::vector> fPasses; std::vector fFragmentShaderDescriptions; }; diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h index 2d9541780f..4d819490c7 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h @@ -102,7 +102,7 @@ class plMetalPipeline : public pl3DPipeline public: plMetalPipeline(hsWindowHndl display, hsWindowHndl window, const hsG3DDeviceModeRecord* devMode); - virtual ~plMetalPipeline(); + ~plMetalPipeline(); CLASSNAME_REGISTER(plMetalPipeline); GETINTERFACE_ANY(plMetalPipeline, plPipeline); @@ -201,12 +201,12 @@ class plMetalPipeline : public pl3DPipeline plLayerInterface* IPushOverAllLayer(plLayerInterface* li); plLayerInterface* IPopOverAllLayer(plLayerInterface* li); - void IPushPiggyBacks(hsGMaterial* mat); - void IPopPiggyBacks(); - void IPushProjPiggyBack(plLayerInterface* li); - void IPopProjPiggyBacks(); + void IPushPiggyBacks(hsGMaterial* mat); + void IPopPiggyBacks(); + void IPushProjPiggyBack(plLayerInterface* li); + void IPopProjPiggyBacks(); size_t ISetNumActivePiggyBacks(); - bool ICheckAuxBuffers(const plAuxSpan* span); + bool ICheckAuxBuffers(const plAuxSpan* span); void ISetPipeConsts(plShader* shader); bool ISetShaders(const plMetalVertexBufferRef* vRef, const hsGMatState blendMode, plShader* vShader, plShader* pShader); diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.cpp index 82db658b66..9f6b1a387b 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.cpp @@ -49,7 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com plMetalPlateManager::plMetalPlateManager(plMetalPipeline* pipe) : plPlateManager(pipe), - fVtxBuffer(nullptr) + fVtxBuffer() { MTL::DepthStencilDescriptor *depthDescriptor = MTL::DepthStencilDescriptor::alloc()->init(); depthDescriptor->setDepthCompareFunction(MTL::CompareFunctionAlways);