Skip to content

Commit

Permalink
[dxbc] Reciprocate W component of SV_POSITION in pixel shaders
Browse files Browse the repository at this point in the history
Fixes the fog effect in Nier:Automata, as well as some major
visual issues in Rise of the Tomb Raider, and potentially
other games.
  • Loading branch information
doitsujin committed Apr 5, 2018
1 parent 4d28f76 commit bd17be4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/dxbc/dxbc_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5002,12 +5002,25 @@ namespace dxvk {
}

DxbcRegisterPointer ptrIn;
ptrIn.type.ctype = DxbcScalarType::Float32;
ptrIn.type.ccount = 4;
ptrIn.type = { DxbcScalarType::Float32, 4 };
ptrIn.id = m_ps.builtinFragCoord;

return emitRegisterExtract(
emitValueLoad(ptrIn), mask);
// The X, Y and Z components of the SV_POSITION semantic
// are identical to Vulkan's FragCoord builtin, but we
// need to compute the reciprocal of the W component.
DxbcRegisterValue fragCoord = emitValueLoad(ptrIn);

uint32_t componentIndex = 3;
uint32_t t_f32 = m_module.defFloatType(32);
uint32_t v_wComp = m_module.opCompositeExtract(t_f32, fragCoord.id, 1, &componentIndex);
v_wComp = m_module.opFDiv(t_f32, m_module.constf32(1.0f), v_wComp);

fragCoord.id = m_module.opCompositeInsert(
getVectorTypeId(fragCoord.type),
v_wComp, fragCoord.id,
1, &componentIndex);

return emitRegisterExtract(fragCoord, mask);
} break;

case DxbcSystemValue::IsFrontFace: {
Expand Down

0 comments on commit bd17be4

Please sign in to comment.