[D3D12] tfetch: change epsilon sign, add 0.5 to getWeights coords

This commit is contained in:
Triang3l 2019-01-29 12:35:22 +03:00
parent 61fd5a6dc2
commit 0c8ce2af04
1 changed files with 20 additions and 15 deletions

View File

@ -1373,23 +1373,26 @@ void DxbcShaderTranslator::ProcessTextureFetchInstruction(
// It's probably applicable to tfetchCube too, we're going to assume it's // It's probably applicable to tfetchCube too, we're going to assume it's
// used for them the same way as for stacked textures. // used for them the same way as for stacked textures.
// http://web.archive.org/web/20090511231340/http://msdn.microsoft.com:80/en-us/library/bb313959.aspx // http://web.archive.org/web/20090511231340/http://msdn.microsoft.com:80/en-us/library/bb313959.aspx
// Adding 1/1024 - quarter of one fixed-point unit of subpixel precision // Subtracting 1/1024 - quarter of one fixed-point unit of subpixel
// (not to touch rounding when the GPU is converting to fixed-point) - to // precision (not to touch rounding when the GPU is converting to
// resolve the ambiguity when the texture coordinate is directly between two // fixed-point) - to resolve the ambiguity when the texture coordinate is
// pixels, which hurts nearest-neighbor sampling (fixes the XBLA logo being // directly between two pixels, which hurts nearest-neighbor sampling (fixes
// blocky in Banjo-Kazooie and the outlines around things and overall // the XBLA logo being blocky in Banjo-Kazooie and the outlines around
// blockiness in Halo 3). // things and overall blockiness in Halo 3). The sign was checked in Halo 3,
float offset_x = instr.attributes.offset_x; // with plus there are outlines when MSAA is enabled, and also outline
if (instr.opcode != FetchOpcode::kGetTextureWeights) { // around the weapon when it's drawn over a shadow.
offset_x += 1.0f / 1024.0f; float offset_x = instr.attributes.offset_x - (1.0f / 1024.0f);
if (instr.opcode == FetchOpcode::kGetTextureWeights) {
// Needed for correct shadow filtering (at least in Halo 3).
offset_x += 0.5f;
} }
float offset_y = 0.0f, offset_z = 0.0f; float offset_y = 0.0f, offset_z = 0.0f;
if (instr.dimension == TextureDimension::k2D || if (instr.dimension == TextureDimension::k2D ||
instr.dimension == TextureDimension::k3D || instr.dimension == TextureDimension::k3D ||
instr.dimension == TextureDimension::kCube) { instr.dimension == TextureDimension::kCube) {
offset_y = instr.attributes.offset_y; offset_y = instr.attributes.offset_y - (1.0f / 1024.0f);
if (instr.opcode != FetchOpcode::kGetTextureWeights) { if (instr.opcode == FetchOpcode::kGetTextureWeights) {
offset_y += 1.0f / 1024.0f; offset_y += 0.5f;
} }
// Don't care about the Z offset for cubemaps when getting weights because // Don't care about the Z offset for cubemaps when getting weights because
// zero Z will be returned anyway (the face index doesn't participate in // zero Z will be returned anyway (the face index doesn't participate in
@ -1398,10 +1401,12 @@ void DxbcShaderTranslator::ProcessTextureFetchInstruction(
(instr.dimension == TextureDimension::kCube && (instr.dimension == TextureDimension::kCube &&
instr.opcode != FetchOpcode::kGetTextureWeights)) { instr.opcode != FetchOpcode::kGetTextureWeights)) {
offset_z = instr.attributes.offset_z; offset_z = instr.attributes.offset_z;
if (instr.opcode != FetchOpcode::kGetTextureWeights && if (instr.dimension == TextureDimension::k3D) {
instr.dimension == TextureDimension::k3D) {
// Z is the face index for cubemaps, so don't apply the epsilon to it. // Z is the face index for cubemaps, so don't apply the epsilon to it.
offset_z += 1.0f / 1024.0f; offset_z -= 1.0f / 1024.0f;
if (instr.opcode == FetchOpcode::kGetTextureWeights) {
offset_z += 0.5f;
}
} }
} }
} }