Skip to content

Commit

Permalink
Review feedback updates
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Nov 26, 2023
1 parent 0df34e5 commit 7848944
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 235 deletions.
8 changes: 4 additions & 4 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
94 changes: 48 additions & 46 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/Avatar.metal
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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 [email protected]
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 <http://www.gnu.org/licenses/>.
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 [email protected]
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 <metal_stdlib>
using namespace metal;


typedef struct {
typedef struct
{
float4 position [[position]];
float2 uvPosition;
half4 color;
Expand All @@ -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<half> layer [[ texture(0) ]],
constant float4& blendColor [[ buffer(0 )]])
fragment half4 PreprocessAvatarFragmentShader(PreprocessAvatarTexturesInOut in [[stage_in]],
texture2d<half> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ using namespace metal;

#include "ShaderVertex.h"

typedef struct {
typedef struct
{
float4 TexU0;
float4 TexV0;

Expand All @@ -57,7 +58,8 @@ typedef struct {
float4 ScaleBias;
} vs_BiasNormalsUniforms;

typedef struct {
typedef struct
{
float4 position [[position]];
float4 texCoord0;
float4 texCoord1;
Expand All @@ -66,35 +68,33 @@ 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;

return out;
}

fragment float4 ps_BiasNormals(vs_BiasNormalsOut in [[stage_in]],
texture2d<float> t0 [[ texture(0) ]],
texture2d<float> t1 [[ texture(1) ]]) {
fragment float4 ps_BiasNormals(vs_BiasNormalsOut in [[ stage_in ]],
texture2d<float> t0 [[ texture(0) ]],
texture2d<float> t1 [[ texture(1) ]])
{
// Composite the cosines together.
// Input map is cosine(pix) for each of
// the 4 waves.
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,27 @@ using namespace metal;

#include "ShaderVertex.h"

typedef struct {
typedef struct
{
float4 c0;
float4 c1;
float4 c2;
float4 c3;
float4 c4;
} vs_CompCosinesUniforms;

typedef struct {
typedef struct
{
float4 position [[position]];
float4 texCoord0;
float4 texCoord1;
float4 texCoord2;
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);
Expand All @@ -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;
Expand All @@ -89,12 +93,13 @@ typedef struct {
float4 c5;
} ps_CompCosinesUniforms;

fragment float4 ps_CompCosines(vs_CompCosinesnInOut in [[stage_in]],
texture2d<float> t0 [[ texture(0) ]],
texture2d<float> t1 [[ texture(1) ]],
texture2d<float> t2 [[ texture(2) ]],
texture2d<float> t3 [[ texture(3) ]],
constant ps_CompCosinesUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]]) {
fragment float4 ps_CompCosines(vs_CompCosinesnInOut in [[ stage_in ]],
texture2d<float> t0 [[ texture(0) ]],
texture2d<float> t1 [[ texture(1) ]],
texture2d<float> t2 [[ texture(2) ]],
texture2d<float> t3 [[ texture(3) ]],
constant ps_CompCosinesUniforms & uniforms [[ buffer(VertexShaderArgumentMaterialShaderUniforms) ]])
{
// Composite the cosines together.
// Input map is cosine(pix) for each of
// the 4 waves.
Expand All @@ -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;
}
Loading

0 comments on commit 7848944

Please sign in to comment.