Skip to content

Commit

Permalink
Add the hdr shader code
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Nov 16, 2023
1 parent a09f22b commit 12ab4c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions D3D11Drv/FileResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ std::string FileResource::readAllText(const std::string& filename)
float Saturation;
float Brightness;
int GrayFormula;
int Padding1;
int HdrMode;
int Padding2;
int Padding3;
}
Expand Down Expand Up @@ -218,6 +218,11 @@ std::string FileResource::readAllText(const std::string& filename)
return floor(c.rgb * 255.0 + threshold) / 255.0;
}
float3 linearHdr(float3 c)
{
return c;//return pow(c, float3(2.2, 2.2, 2.2)) * 1.2;
}
float3 applyGamma(float3 c)
{
float3 valgray;
Expand All @@ -244,7 +249,14 @@ std::string FileResource::readAllText(const std::string& filename)
Output main(Input input)
{
Output output;
output.outColor = float4(dither(applyGamma(tex.Sample(samplerTex, input.texCoord).rgb), input.fragCoord), 1.0f);
if (HdrMode == 0)
{
output.outColor = float4(dither(applyGamma(tex.Sample(samplerTex, input.texCoord).rgb), input.fragCoord), 1.0f);
}
else
{
output.outColor = float4(linearHdr(applyGamma(tex.Sample(samplerTex, input.texCoord).rgb)), 1.0f);
}
return output;
}
)";
Expand Down
1 change: 1 addition & 0 deletions D3D11Drv/UD3D11RenderDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ void UD3D11RenderDevice::Unlock(UBOOL Blit)
pushconstants.Brightness = clamp(D3DBrightness, -15.0f, 15.f);
pushconstants.GrayFormula = clamp(D3DGrayFormula, 0, 2);
}
pushconstants.HdrMode = D3DHdr ? 1 : 0;
Context->UpdateSubresource(PresentPass.PresentConstantBuffer, 0, nullptr, &pushconstants, 0, 0);

Context->Draw(6, 0);
Expand Down
2 changes: 1 addition & 1 deletion D3D11Drv/UD3D11RenderDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct PresentPushConstants
float Saturation;
float Brightness;
int GrayFormula;
int32_t padding1;
int HdrMode;
int32_t padding2;
int32_t padding3;
};
Expand Down

0 comments on commit 12ab4c3

Please sign in to comment.