|
37 | 37 | #include "../../dxso/dxso_util.h"
|
38 | 38 | #include "../../d3d9/d3d9_caps.h"
|
39 | 39 |
|
| 40 | +namespace { |
| 41 | + // By default, a value of 1.f will have 0 displacement. |
| 42 | + const float kDefaultNeutralHeight = 1.f; |
| 43 | +} |
| 44 | + |
40 | 45 | namespace dxvk {
|
41 | 46 |
|
42 | 47 | uint32_t getMipLevels(ReplacementMaterialTextureType::Enum textureType, const VkExtent3D& extent) {
|
@@ -79,10 +84,12 @@ namespace dxvk {
|
79 | 84 | }
|
80 | 85 |
|
81 | 86 | VkClearColorValue TerrainBaker::getClearColor(ReplacementMaterialTextureType::Enum textureType) {
|
82 |
| - float neutral_height = m_prevFrameMaxDisplaceIn / (m_prevFrameMaxDisplaceIn + m_prevFrameMaxDisplaceOut); |
| 87 | + const float prevFrameTotalHeight = m_prevFrameMaxDisplaceIn + m_prevFrameMaxDisplaceOut; |
| 88 | + float neutral_height = prevFrameTotalHeight != 0.f ? m_prevFrameMaxDisplaceIn / prevFrameTotalHeight : kDefaultNeutralHeight; |
83 | 89 | switch (textureType) {
|
84 | 90 | case ReplacementMaterialTextureType::Height:
|
85 | 91 | // height maps should be cleared to neutral_height, which keeps the displaced surface identical to the original surface.
|
| 92 | + // The height texture should be single channel, so only the first value actually matters. |
86 | 93 | return { neutral_height, neutral_height, neutral_height, neutral_height };
|
87 | 94 | break;
|
88 | 95 |
|
@@ -188,7 +195,8 @@ namespace dxvk {
|
188 | 195 | const float materialTotalHeight = replacementMaterial->getDisplaceIn() + replacementMaterial->getDisplaceOut();
|
189 | 196 |
|
190 | 197 | conversionInfo.scale = prevFrameTotalHeight <= 0.f ? 0.f : materialTotalHeight / prevFrameTotalHeight;
|
191 |
| - conversionInfo.offset = prevFrameTotalHeight <= 0.f ? 0.f : -1.f * replacementMaterial->getDisplaceIn() / materialTotalHeight; |
| 198 | + // We want to subtract the original neutral displacement, then scale the values, then add the new neutral displacement. |
| 199 | + conversionInfo.offset = -1.f * (materialTotalHeight == 0.f ? kDefaultNeutralHeight : (replacementMaterial->getDisplaceIn() / materialTotalHeight)); |
192 | 200 | m_currFrameMaxDisplaceIn = std::max(m_currFrameMaxDisplaceIn, replacementMaterial->getDisplaceIn());
|
193 | 201 | m_currFrameMaxDisplaceOut = std::max(m_currFrameMaxDisplaceOut, replacementMaterial->getDisplaceOut());
|
194 | 202 | }
|
@@ -404,7 +412,9 @@ namespace dxvk {
|
404 | 412 | ctx->setSpecConstant(VK_PIPELINE_BIND_POINT_GRAPHICS, D3D9SpecConstantId::ReplacementTextureCategory, static_cast<uint32_t>(ReplacementMaterialTextureCategory::AlbedoOpacity));
|
405 | 413 |
|
406 | 414 | // The height value that corresponds to the original surface height.
|
407 |
| - const float neutralDisplacement = m_prevFrameMaxDisplaceIn / ( m_prevFrameMaxDisplaceIn + m_prevFrameMaxDisplaceOut); |
| 415 | + const float prevFrameTotalHeight = m_prevFrameMaxDisplaceIn + m_prevFrameMaxDisplaceOut; |
| 416 | + const float neutralDisplacement = prevFrameTotalHeight != 0.f ? m_prevFrameMaxDisplaceIn / prevFrameTotalHeight : kDefaultNeutralHeight; |
| 417 | + |
408 | 418 |
|
409 | 419 | // Bake all material textures
|
410 | 420 | for (uint32_t iTexture = 0; iTexture < numTexturesToBake; iTexture++) {
|
|
0 commit comments