Skip to content

Commit

Permalink
Fixing missing shadows bug
Browse files Browse the repository at this point in the history
Shadow stages 0 and 1 and the normal stages 0 and 1 conflict and were tromping over each other. Redoing this part of the pipeline to allow for alpha blend textures to be sourced from textures 0 or 1, while allowing the alpha blend texture coordinates to be derived in stage 3.
  • Loading branch information
colincornaby committed Aug 15, 2023
1 parent aee43de commit 5988ed3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
26 changes: 24 additions & 2 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3963,11 +3963,33 @@ void plMetalPipeline::IRenderShadowsOntoSpan(const plRenderPrimFunc& render, con

struct plMetalFragmentShaderDescription passDescription;
memset(&passDescription, 0, sizeof(passDescription));
passDescription.Populate(mat->GetLayer(0), 0);

passDescription.numLayers = fCurrNumLayers = 3;

/*
Things get a wee bit complicated here.
The texture we want to alpha blend with is already bound to texture 0 or texture 1.
However - the texture co-ords we want are in position 2 in the FVF vertex buffer. (stage 3)
Build the shader with texture descriptions set properly for textures 0 and 1,
but put the instructions on how to treat the UVW for textures 0 or 1 into
the third stage.
The shadow cast shader will automatically look in textures 0 and 1 when doing
the third stage blend. This saves us a texture bind.
*/

passDescription.PopulateTextureInfo(mat->GetLayer(0), 0);
passDescription.Populate(mat->GetLayer(0), 2);

if (mat->GetNumLayers()>1) {
passDescription.Populate(mat->GetLayer(1), 1);
passDescription.PopulateTextureInfo(mat->GetLayer(1), 1);
passDescription.Populate(mat->GetLayer(1), 2);
}
//There's no texture for the third stage if we're reusing the textures
//for the first and second stages from the last render.
passDescription.passTypes[2] = PassTypeColor;

plMetalDevice::plMetalLinkedPipeline *linkedPipeline = plMetalRenderShadowPipelineState(&fDevice, vRef, passDescription).GetRenderPipelineState();
if(fState.fCurrentPipelineState != linkedPipeline->pipelineState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,13 @@ void plMetalMaterialPassPipelineState::ConfigureBlend(MTL::RenderPipelineColorAt
ConfigureBlendMode(blendMode, descriptor);
}

void plMetalFragmentShaderDescription::Populate(plLayerInterface* layPtr, uint8_t index) {
void plMetalFragmentShaderDescription::Populate(const plLayerInterface* layPtr, const uint8_t index) {
blendModes[index] = layPtr->GetBlendFlags();
miscFlags[index] = layPtr->GetMiscFlags();

PopulateTextureInfo(layPtr, index);
}

void plMetalFragmentShaderDescription::PopulateTextureInfo(const plLayerInterface* layPtr, const uint8_t index) {
plBitmap* texture = layPtr->GetTexture();
if (texture != nullptr) {
if (plCubicEnvironmap::ConvertNoRef(texture) != nullptr || plCubicRenderTarget::ConvertNoRef(texture) != nullptr) {
Expand All @@ -327,6 +330,7 @@ void plMetalFragmentShaderDescription::Populate(plLayerInterface* layPtr, uint8_
} else {
passTypes[index] = PassTypeColor;
}

}

bool plMetalMaterialPassPipelineState::IsEqual(const plMetalPipelineState &p) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ struct plMetalFragmentShaderDescription {
return value;
}

void Populate(plLayerInterface* layPtr, uint8_t index);
void Populate(const plLayerInterface* layPtr, const uint8_t index);
void PopulateTextureInfo(const plLayerInterface* layPtr, const uint8_t index);
};

template<>
Expand Down

0 comments on commit 5988ed3

Please sign in to comment.