From f0243fbdae8f87bd352ea860715fad1307aa4fac Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sun, 7 Jan 2024 15:13:57 -0800 Subject: [PATCH] Initial Metal lighting calc cleanup --- .../ShaderSrc/FixedPipelineShaders.metal | 68 +++++---- .../pfMetalPipeline/ShaderSrc/ShaderTypes.h | 21 ++- .../pfMetalPipeline/plMetalPipeline.cpp | 143 +++++++++--------- .../pfMetalPipeline/plMetalPipeline.h | 1 + 4 files changed, 126 insertions(+), 107 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal index 6b9bbc8884..8aa5d2d29f 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/FixedPipelineShaders.metal @@ -100,7 +100,7 @@ constant const uint32_t miscFlags8 [[ function_constant(FunctionConstantLayerFla constant const uint8_t sourceTypes[MAX_BLEND_PASSES] = { sourceType1, sourceType2, sourceType3, sourceType4, sourceType5, sourceType6, sourceType7, sourceType8}; constant const uint32_t blendModes[MAX_BLEND_PASSES] = { blendModes1, blendModes2, blendModes3, blendModes4, blendModes5, blendModes6, blendModes7, blendModes8}; constant const uint32_t miscFlags[MAX_BLEND_PASSES] = { miscFlags1, miscFlags2, miscFlags3, miscFlags4, miscFlags5, miscFlags6, miscFlags7, miscFlags8}; - constant const uint8_t passCount = (sourceType1 > 0) + (sourceType2 > 0) + (sourceType3 > 0) + (sourceType4 > 0) + (sourceType5 > 0) + (sourceType6 > 0) + (sourceType7 > 0) + (sourceType8 > 0); +constant const uint8_t passCount = (sourceType1 > 0) + (sourceType2 > 0) + (sourceType3 > 0) + (sourceType4 > 0) + (sourceType5 > 0) + (sourceType6 > 0) + (sourceType7 > 0) + (sourceType8 > 0); constant const bool has2DTexture1 = (sourceType1 == PassTypeTexture && hasLayer1); constant const bool has2DTexture2 = (sourceType2 == PassTypeTexture && hasLayer2); @@ -172,31 +172,20 @@ typedef struct float4 position [[position, invariant]]; float3 texCoord1; } 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) ]]) + +half4 calcLitMaterialColor(constant plMetalLights & lights, + const half4 materialColor, + constant plMaterialLightingDescriptor & materialLighting, + const float4 position, + const float3 normal) { - 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.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.h, 0.h, 0.h); half3 LDiffuse = half3(0.h, 0.h, 0.h); - - const float3 Ndirection = normalize(float4(in.normal, 0.f) * uniforms.localToWorldMatrix).xyz; - - float4 position = float4(in.position, 1.f) * uniforms.localToWorldMatrix; - if (temp_hasOnlyWeight1) { - const float4 position2 = blendMatrix1 * float4(in.position, 1.f); - position = (in.weight1 * position) + ((1.f - in.weight1) * position2); - } - + + const half3 MAmbient = mix(materialColor.rgb, materialLighting.ambientCol, materialLighting.ambientSrc); + const half4 MDiffuse = mix(materialColor, materialLighting.diffuseCol, materialLighting.diffuseSrc); + const half3 MEmissive = mix(materialColor.rgb, materialLighting.emissiveCol, materialLighting.emissiveSrc); + for (size_t i = 0; i < lights.count; i++) { constant const plMetalShaderLightSource *lightSource = &lights.lampSources[i]; if (lightSource->scale == 0.0h) @@ -231,16 +220,35 @@ 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); + const float3 dotResult = dot(normal, direction.xyz); 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.h, 1.h); + const half3 ambient = (MAmbient.rgb) * clamp(materialLighting.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)); + return clamp(half4(ambient + diffuse + MEmissive.rgb, MDiffuse.a), 0.h, 1.h); +} + +vertex ColorInOut pipelineVertexShader(Vertex in [[stage_in]], + constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]], + constant plMaterialLightingDescriptor & materialLighting [[ buffer( VertexShaderArgumentMaterialLighting) ]], + constant plMetalLights & lights [[ buffer(VertexShaderArgumentLights) ]], + constant float4x4 & blendMatrix1 [[ buffer(VertexShaderArgumentBlendMatrix1), function_constant(temp_hasOnlyWeight1) ]]) +{ + ColorInOut out; + const half4 inColor = half4(in.color.b, in.color.g, in.color.r, in.color.a) / half4(255.f); - out.vtxColor = half4(material.rgb, abs(uniforms.invVtxAlpha - MDiffuse.a)); + const float3 Ndirection = normalize(float4(in.normal, 0.f) * uniforms.localToWorldMatrix).xyz; + + float4 position = float4(in.position, 1.f) * uniforms.localToWorldMatrix; + if (temp_hasOnlyWeight1) { + const float4 position2 = blendMatrix1 * float4(in.position, 1.f); + position = (in.weight1 * position) + ((1.f - in.weight1) * position2); + } + + out.vtxColor = calcLitMaterialColor(lights, inColor, materialLighting, position, Ndirection); + out.vtxColor.a = abs(uniforms.invVtxAlpha - out.vtxColor.a); + const float4 vCamPosition = position * uniforms.worldToCameraMatrix; // Fog @@ -612,6 +620,7 @@ fragment half4 shadowFragmentShader(ShadowCasterInOut in [[stage_in]]) vertex ColorInOut shadowCastVertexShader(Vertex in [[ stage_in ]], constant VertexUniforms & uniforms [[ buffer( VertexShaderArgumentFixedFunctionUniforms) ]], + constant plMaterialLightingDescriptor & materialLighting [[ buffer( VertexShaderArgumentMaterialLighting) ]], constant plShadowState & shadowState [[ buffer(VertexShaderArgumentShadowState) ]]) { ColorInOut out; @@ -619,7 +628,8 @@ vertex ColorInOut shadowCastVertexShader(Vertex in 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; + // FIXME: Should this be something more specific + const half4 MDiffuse = materialLighting.diffuseCol; //w is attenation float4 direction; diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/ShaderTypes.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/ShaderTypes.h index 2845921eb8..1651db7a7d 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/ShaderTypes.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/ShaderSrc/ShaderTypes.h @@ -62,6 +62,8 @@ enum plMetalVertexShaderArgument VertexShaderArgumentMaterialShaderUniforms = 3, /// Light Table VertexShaderArgumentLights = 4, + /// Material properties for vertex lighting + VertexShaderArgumentMaterialLighting = 5, /// Blend matrix for GPU side animation blending VertexShaderArgumentBlendMatrix1 = 6, /// Describes the state of a shadow caster for shadow cast shader @@ -168,15 +170,8 @@ struct UVOutDescriptor static_assert(std::is_trivial_v, "UVOutDescriptor must be a trivial type!"); #endif -struct VertexUniforms +struct plMaterialLightingDescriptor { - // transformation - matrix_float4x4 projectionMatrix; - matrix_float4x4 localToWorldMatrix; - matrix_float4x4 cameraToWorldMatrix; - matrix_float4x4 worldToCameraMatrix; - - // lighting half4 globalAmb; half3 ambientCol; uint8_t ambientSrc; @@ -186,6 +181,16 @@ struct VertexUniforms uint8_t emissiveSrc; half3 specularCol; uint8_t specularSrc; +}; + +struct VertexUniforms +{ + // transformation + matrix_float4x4 projectionMatrix; + matrix_float4x4 localToWorldMatrix; + matrix_float4x4 cameraToWorldMatrix; + matrix_float4x4 worldToCameraMatrix; + bool invVtxAlpha; uint8_t fogExponential; diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp index 85f527ede2..3a8a026a71 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp @@ -151,6 +151,7 @@ bool plRenderTriListFunc::RenderPrims() const size_t uniformsSize = offsetof(VertexUniforms, uvTransforms) + sizeof(UVOutDescriptor) * fDevice->fPipeline->fCurrNumLayers; fDevice->CurrentRenderCommandEncoder()->setVertexBytes(fDevice->fPipeline->fCurrentRenderPassUniforms, sizeof(VertexUniforms), VertexShaderArgumentFixedFunctionUniforms); + fDevice->CurrentRenderCommandEncoder()->setVertexBytes(&fDevice->fPipeline->fCurrentRenderPassMaterialLighting, sizeof(plMaterialLightingDescriptor), VertexShaderArgumentMaterialLighting); plMetalLights* lights = &fDevice->fPipeline->fLights; size_t lightSize = offsetof(plMetalLights, lampSources) + (sizeof(plMetalShaderLightSource) * lights->count); @@ -1304,16 +1305,18 @@ void plMetalPipeline::IRenderProjection(const plRenderPrimFunc& render, plLightI IScaleLight(0, true); - fCurrentRenderPassUniforms->ambientSrc = 1; - fCurrentRenderPassUniforms->diffuseSrc = 1; - fCurrentRenderPassUniforms->emissiveSrc = 1; - fCurrentRenderPassUniforms->specularSrc = 1; - fCurrentRenderPassUniforms->globalAmb = {1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->ambientCol = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->emissiveCol = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->specularCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.ambientSrc = 1; + fCurrentRenderPassMaterialLighting.diffuseSrc = 1; + fCurrentRenderPassMaterialLighting.emissiveSrc = 1; + fCurrentRenderPassMaterialLighting.specularSrc = 1; + fCurrentRenderPassMaterialLighting.globalAmb = {1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.ambientCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.emissiveCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.specularCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.diffuseCol = {1.f, 1.f, 1.f, 1.f}; + + // FIXME: NEEDED? fCurrentRenderPassUniforms->fogColor = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->diffuseCol = {1.f, 1.f, 1.f, 1.f}; matrix_float4x4 tXfm; hsMatrix2SIMD(proj->GetTransform(), &tXfm); @@ -1483,12 +1486,12 @@ void plMetalPipeline::IRenderAuxSpan(const plSpan& span, const plAuxSpan* aux) for (int32_t pass = 0; pass < mRef->GetNumPasses(); pass++) { IHandleMaterialPass(material, pass, &span, vRef); if (aux->fFlags & plAuxSpan::kOverrideLiteModel) { - fCurrentRenderPassUniforms->ambientCol = {1.0f, 1.0f, 1.0f}; + fCurrentRenderPassMaterialLighting.ambientCol = {1.0f, 1.0f, 1.0f}; - fCurrentRenderPassUniforms->diffuseSrc = 1.0; - fCurrentRenderPassUniforms->ambientSrc = 1.0; - fCurrentRenderPassUniforms->emissiveSrc = 0.0; - fCurrentRenderPassUniforms->specularSrc = 1.0; + fCurrentRenderPassMaterialLighting.diffuseSrc = 1.0; + fCurrentRenderPassMaterialLighting.ambientSrc = 1.0; + fCurrentRenderPassMaterialLighting.emissiveSrc = 0.0; + fCurrentRenderPassMaterialLighting.specularSrc = 1.0; } render.RenderPrims(); @@ -2118,18 +2121,18 @@ void plMetalPipeline::ICalcLighting(plMetalMaterialShaderRef* mRef, const plLaye // plProfile_Inc(MatLightState); if (IsDebugFlagSet(plPipeDbg::kFlagAllBright)) { - fCurrentRenderPassUniforms->globalAmb = {1.f, 1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.globalAmb = {1.f, 1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->ambientCol = {1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->diffuseCol = {1.f, 1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->emissiveCol = {1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->emissiveCol = {1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->specularCol = {1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.ambientCol = {1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.diffuseCol = {1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.emissiveCol = {1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.emissiveCol = {1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.specularCol = {1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->ambientSrc = 1; - fCurrentRenderPassUniforms->diffuseSrc = 1; - fCurrentRenderPassUniforms->emissiveSrc = 1; - fCurrentRenderPassUniforms->specularSrc = 1; + fCurrentRenderPassMaterialLighting.ambientSrc = 1; + fCurrentRenderPassMaterialLighting.diffuseSrc = 1; + fCurrentRenderPassMaterialLighting.emissiveSrc = 1; + fCurrentRenderPassMaterialLighting.specularSrc = 1; return; } @@ -2149,42 +2152,42 @@ void plMetalPipeline::ICalcLighting(plMetalMaterialShaderRef* mRef, const plLaye case plSpan::kLiteMaterial: // Material shading { if (state.fShadeFlags & hsGMatState::kShadeWhite) { - fCurrentRenderPassUniforms->globalAmb = {1.f, 1.f, 1.f, 1.f}; - fCurrentRenderPassUniforms->ambientCol = {1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.globalAmb = {1.f, 1.f, 1.f, 1.f}; + fCurrentRenderPassMaterialLighting.ambientCol = {1.f, 1.f, 1.f}; } else if (IsDebugFlagSet(plPipeDbg::kFlagNoPreShade)) { - fCurrentRenderPassUniforms->globalAmb = {0.f, 0.f, 0.f, 1.f}; - fCurrentRenderPassUniforms->ambientCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.globalAmb = {0.f, 0.f, 0.f, 1.f}; + fCurrentRenderPassMaterialLighting.ambientCol = {0.f, 0.f, 0.f}; } else { hsColorRGBA amb = currLayer->GetPreshadeColor(); - fCurrentRenderPassUniforms->globalAmb = {static_cast(amb.r), static_cast(amb.g), static_cast(amb.b), 1.f}; - fCurrentRenderPassUniforms->ambientCol = {static_cast(amb.r), static_cast(amb.g), static_cast(amb.b)}; + fCurrentRenderPassMaterialLighting.globalAmb = {static_cast(amb.r), static_cast(amb.g), static_cast(amb.b), 1.f}; + fCurrentRenderPassMaterialLighting.ambientCol = {static_cast(amb.r), static_cast(amb.g), static_cast(amb.b)}; } hsColorRGBA dif = currLayer->GetRuntimeColor(); - fCurrentRenderPassUniforms->diffuseCol = {static_cast(dif.r), static_cast(dif.g), static_cast(dif.b), static_cast(currLayer->GetOpacity())}; + fCurrentRenderPassMaterialLighting.diffuseCol = {static_cast(dif.r), static_cast(dif.g), static_cast(dif.b), static_cast(currLayer->GetOpacity())}; hsColorRGBA em = currLayer->GetAmbientColor(); - fCurrentRenderPassUniforms->emissiveCol = {static_cast(em.r), static_cast(em.g), static_cast(em.b)}; + fCurrentRenderPassMaterialLighting.emissiveCol = {static_cast(em.r), static_cast(em.g), static_cast(em.b)}; // Set specular properties if (state.fShadeFlags & hsGMatState::kShadeSpecular) { hsColorRGBA spec = currLayer->GetSpecularColor(); - fCurrentRenderPassUniforms->specularCol = {static_cast(spec.r), static_cast(spec.g), static_cast(spec.b)}; + fCurrentRenderPassMaterialLighting.specularCol = {static_cast(spec.r), static_cast(spec.g), static_cast(spec.b)}; #if 0 mat.Power = currLayer->GetSpecularPower(); #endif } else { - fCurrentRenderPassUniforms->specularCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.specularCol = {0.f, 0.f, 0.f}; } - fCurrentRenderPassUniforms->diffuseSrc = 1.f; - fCurrentRenderPassUniforms->emissiveSrc = 1.f; - fCurrentRenderPassUniforms->specularSrc = 1.f; + fCurrentRenderPassMaterialLighting.diffuseSrc = 1.f; + fCurrentRenderPassMaterialLighting.emissiveSrc = 1.f; + fCurrentRenderPassMaterialLighting.specularSrc = 1.f; if (state.fShadeFlags & hsGMatState::kShadeNoShade) { - fCurrentRenderPassUniforms->ambientSrc = 1.f; + fCurrentRenderPassMaterialLighting.ambientSrc = 1.f; } else { - fCurrentRenderPassUniforms->ambientSrc = 0.f; + fCurrentRenderPassMaterialLighting.ambientSrc = 0.f; } fCurrLightingMethod = plSpan::kLiteMaterial; @@ -2193,20 +2196,20 @@ void plMetalPipeline::ICalcLighting(plMetalMaterialShaderRef* mRef, const plLaye case plSpan::kLiteVtxPreshaded: // Vtx preshaded { - fCurrentRenderPassUniforms->globalAmb = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->ambientCol = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->diffuseCol = {0.f, 0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->emissiveCol = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->specularCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.globalAmb = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.ambientCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.diffuseCol = {0.f, 0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.emissiveCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.specularCol = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->diffuseSrc = 0.f; - fCurrentRenderPassUniforms->ambientSrc = 1.f; - fCurrentRenderPassUniforms->specularSrc = 1.f; + fCurrentRenderPassMaterialLighting.diffuseSrc = 0.f; + fCurrentRenderPassMaterialLighting.ambientSrc = 1.f; + fCurrentRenderPassMaterialLighting.specularSrc = 1.f; if (state.fShadeFlags & hsGMatState::kShadeEmissive) { - fCurrentRenderPassUniforms->emissiveSrc = 0.f; + fCurrentRenderPassMaterialLighting.emissiveSrc = 0.f; } else { - fCurrentRenderPassUniforms->emissiveSrc = 1.f; + fCurrentRenderPassMaterialLighting.emissiveSrc = 1.f; } fCurrLightingMethod = plSpan::kLiteVtxPreshaded; @@ -2215,30 +2218,30 @@ void plMetalPipeline::ICalcLighting(plMetalMaterialShaderRef* mRef, const plLaye case plSpan::kLiteVtxNonPreshaded: // Vtx non-preshaded { - fCurrentRenderPassUniforms->ambientCol = {0.f, 0.f, 0.f}; - fCurrentRenderPassUniforms->diffuseCol = {0.f, 0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.ambientCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.diffuseCol = {0.f, 0.f, 0.f, 0.f}; hsColorRGBA em = currLayer->GetAmbientColor(); - fCurrentRenderPassUniforms->emissiveCol = {static_cast(em.r), static_cast(em.g), static_cast(em.b)}; + fCurrentRenderPassMaterialLighting.emissiveCol = {static_cast(em.r), static_cast(em.g), static_cast(em.b)}; // Set specular properties if (state.fShadeFlags & hsGMatState::kShadeSpecular) { hsColorRGBA spec = currLayer->GetSpecularColor(); - fCurrentRenderPassUniforms->specularCol = {static_cast(spec.r), static_cast(spec.g), static_cast(spec.b)}; + fCurrentRenderPassMaterialLighting.specularCol = {static_cast(spec.r), static_cast(spec.g), static_cast(spec.b)}; #if 0 mat.Power = currLayer->GetSpecularPower(); #endif } else { - fCurrentRenderPassUniforms->specularCol = {0.f, 0.f, 0.f}; + fCurrentRenderPassMaterialLighting.specularCol = {0.f, 0.f, 0.f}; } hsColorRGBA amb = currLayer->GetPreshadeColor(); - fCurrentRenderPassUniforms->globalAmb = {static_cast(amb.r), static_cast(amb.g), static_cast(amb.b), static_cast(amb.a)}; + fCurrentRenderPassMaterialLighting.globalAmb = {static_cast(amb.r), static_cast(amb.g), static_cast(amb.b), static_cast(amb.a)}; - fCurrentRenderPassUniforms->ambientSrc = 0; - fCurrentRenderPassUniforms->diffuseSrc = 0; - fCurrentRenderPassUniforms->emissiveSrc = 1; - fCurrentRenderPassUniforms->specularSrc = 1; + fCurrentRenderPassMaterialLighting.ambientSrc = 0; + fCurrentRenderPassMaterialLighting.diffuseSrc = 0; + fCurrentRenderPassMaterialLighting.emissiveSrc = 1; + fCurrentRenderPassMaterialLighting.specularSrc = 1; fCurrLightingMethod = plSpan::kLiteVtxNonPreshaded; break; @@ -3197,7 +3200,7 @@ bool plMetalPipeline::IPushShadowCastState(plShadowSlave* slave) return false; // Set texture to U_LUT - fCurrentRenderPassUniforms->specularSrc = 0.0; + fCurrentRenderPassMaterialLighting.specularSrc = 0.0; // if( !ref->fTexture ) //{ @@ -3886,17 +3889,17 @@ void plMetalPipeline::ISetShadowLightState(hsGMaterial* mat) fCurrLightingMethod = plSpan::kLiteShadow; if (mat && mat->GetNumLayers() && mat->GetLayer(0)) - fCurrentRenderPassUniforms->diffuseCol.r = fCurrentRenderPassUniforms->diffuseCol.g = fCurrentRenderPassUniforms->diffuseCol.b = mat->GetLayer(0)->GetOpacity(); + fCurrentRenderPassMaterialLighting.diffuseCol.r = fCurrentRenderPassMaterialLighting.diffuseCol.g = fCurrentRenderPassMaterialLighting.diffuseCol.b = mat->GetLayer(0)->GetOpacity(); else - fCurrentRenderPassUniforms->diffuseCol.r = fCurrentRenderPassUniforms->diffuseCol.g = fCurrentRenderPassUniforms->diffuseCol.b = 1.f; - fCurrentRenderPassUniforms->diffuseCol.a = 1.f; - - fCurrentRenderPassUniforms->diffuseSrc = 1.0f; - fCurrentRenderPassUniforms->emissiveSrc = 1.0f; - fCurrentRenderPassUniforms->emissiveCol = 0.0f; - fCurrentRenderPassUniforms->specularSrc = 0.0f; - fCurrentRenderPassUniforms->ambientSrc = 0.0f; - fCurrentRenderPassUniforms->globalAmb = 0.0f; + fCurrentRenderPassMaterialLighting.diffuseCol.r = fCurrentRenderPassMaterialLighting.diffuseCol.g = fCurrentRenderPassMaterialLighting.diffuseCol.b = 1.f; + fCurrentRenderPassMaterialLighting.diffuseCol.a = 1.f; + + fCurrentRenderPassMaterialLighting.diffuseSrc = 1.0f; + fCurrentRenderPassMaterialLighting.emissiveSrc = 1.0f; + fCurrentRenderPassMaterialLighting.emissiveCol = 0.0f; + fCurrentRenderPassMaterialLighting.specularSrc = 0.0f; + fCurrentRenderPassMaterialLighting.ambientSrc = 0.0f; + fCurrentRenderPassMaterialLighting.globalAmb = 0.0f; } // IDisableLightsForShadow /////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h index 4d819490c7..185f912a74 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h @@ -168,6 +168,7 @@ class plMetalPipeline : public pl3DPipeline private: VertexUniforms* fCurrentRenderPassUniforms; + plMaterialLightingDescriptor fCurrentRenderPassMaterialLighting; bool fIsFullscreen;