Skip to content

Commit

Permalink
Merge pull request #29 from niligulmohar/fix-blocky-water-surfaces
Browse files Browse the repository at this point in the history
Fix blocky appearance of water surfaces
  • Loading branch information
PeterTh authored Dec 17, 2016
2 parents d360f6c + 2c27e5c commit 03e99d0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions d3d9dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,37 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetPixelShaderConstantB(UINT StartRegister,
}

HRESULT APIENTRY hkIDirect3DDevice9::SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount) {
static const UINT HALF_RESOLUTION_REGISTER = 164;
static const float HALF_X_RESOLUTION = 512;
static const float HALF_Y_RESOLUTION = 360;
static const float RECIPROCAL_HALF_X_RESOLUTION = 1 / HALF_X_RESOLUTION;
static const float RECIPROCAL_HALF_Y_RESOLUTION = 1 / HALF_Y_RESOLUTION;

if (StartRegister <= HALF_RESOLUTION_REGISTER && HALF_RESOLUTION_REGISTER < StartRegister + Vector4fCount) {
SDLOG(2, "Updating pixel shader constant register c%d\n", HALF_RESOLUTION_REGISTER);
size_t offset = (HALF_RESOLUTION_REGISTER - StartRegister) * 4;
if (pConstantData[offset] == HALF_X_RESOLUTION &&
pConstantData[offset + 1] == HALF_Y_RESOLUTION &&
pConstantData[offset + 2] == RECIPROCAL_HALF_X_RESOLUTION &&
pConstantData[offset + 3] == RECIPROCAL_HALF_Y_RESOLUTION) {

SDLOG(2, "Fixing half resolution register\n");
size_t bufferSize = sizeof(float) * 4 * Vector4fCount;
float* pBuffer = static_cast<float*>(alloca(bufferSize));
memcpy_s(pBuffer, bufferSize, pConstantData, bufferSize);

UINT width;
UINT height;
getDofRes(HALF_X_RESOLUTION, HALF_Y_RESOLUTION, width, height);
pBuffer[offset] = static_cast<float>(width);
pBuffer[offset + 1] = static_cast<float>(height);
pBuffer[offset + 2] = 1.f / width;
pBuffer[offset + 3] = 1.f / height;

return m_pD3Ddev->SetPixelShaderConstantF(StartRegister, pBuffer, Vector4fCount);
}
}

return m_pD3Ddev->SetPixelShaderConstantF(StartRegister,pConstantData,Vector4fCount);
}

Expand Down

0 comments on commit 03e99d0

Please sign in to comment.