Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhooking Metal shadows from the lighting system #1645

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,6 @@ 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;

//w is attenation
float4 direction;
Expand All @@ -640,7 +638,8 @@ vertex ColorInOut shadowCastVertexShader(Vertex in
}

const float3 dotResult = dot(Ndirection, direction.xyz);
const half3 diffuse = MDiffuse.rgb * half3(max(0.h, dotResult)) * shadowState.power;
// Post lighting diffuse color needs to be clamped to the 0..1 range even though >1.f is valid.
const half3 diffuse = clamp(shadowState.opacity * half3(max(0.h, dotResult)) * shadowState.power, 0.f, 1.f);
out.vtxColor = half4(diffuse, 1.f);

const float4 vCamPosition = position * uniforms.worldToCameraMatrix;
Expand Down
27 changes: 1 addition & 26 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,9 +3202,6 @@ bool plMetalPipeline::IPushShadowCastState(plShadowSlave* slave)
if (!slave->SetupViewTransform(this))
return false;

// Set texture to U_LUT
fCurrentRenderPassUniforms->specularSrc = 0.0;

// if( !ref->fTexture )
//{
// if( ref->fData )
Expand Down Expand Up @@ -3759,6 +3756,7 @@ void plMetalPipeline::IRenderShadowsOntoSpan(const plRenderPrimFunc& render, con
// The shadow light isn't used in generating the shadow map, it's used
// in projecting the shadow map onto the scene.
plShadowState shadowState;
shadowState.opacity = first ? mat->GetLayer(0)->GetOpacity() : 1.f;
ISetupShadowState(fShadows[i], shadowState);

struct plMetalFragmentShaderDescription passDescription{};
Expand Down Expand Up @@ -3846,9 +3844,6 @@ void plMetalPipeline::ISetupShadowRcvTextureStages(hsGMaterial* mat)
// same one.
fForceMatHandle = true;

// Set the D3D lighting/material model
ISetShadowLightState(mat);

// Zbuffering on read-only

if (fState.fCurrentDepthStencilState != fDevice.fNoZWriteStencilState) {
Expand Down Expand Up @@ -3885,26 +3880,6 @@ void plMetalPipeline::ISetupShadowRcvTextureStages(hsGMaterial* mat)
fDevice.CurrentRenderCommandEncoder()->setFragmentBytes(&layerIndex, sizeof(int), FragmentShaderArgumentShadowCastAlphaSrc);
}

// ISetShadowLightState //////////////////////////////////////////////////////////////////
// Set the D3D lighting/material model for projecting the shadow map onto this material.
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();
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;
}

// IDisableLightsForShadow ///////////////////////////////////////////////////////////
// Disable any lights that are enabled. We'll only want the shadow light illuminating
// the surface.
Expand Down
3 changes: 1 addition & 2 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ class plMetalPipeline : public pl3DPipeline<plMetalDevice>
hsGDeviceRef* SharedRenderTargetRef(plRenderTarget* share, plRenderTarget* owner);
void IRenderShadowsOntoSpan(const plRenderPrimFunc& render, const plSpan* span, hsGMaterial* mat, plMetalVertexBufferRef* vRef);
void ISetupShadowRcvTextureStages(hsGMaterial* mat);
void ISetupShadowSlaveTextures(plShadowSlave* slave);
void ISetShadowLightState(hsGMaterial* mat);
void ISetupShadowSlaveTextures(plShadowSlave* slave);
void ISetupShadowState(plShadowSlave* slave, plShadowState& shadowState);
void IDisableLightsForShadow();
void IReleaseRenderTargetPools();
Expand Down
Loading