Skip to content

Commit 5b2f3e4

Browse files
committed
Made this feature switchable on and off. Default is good ol' gamma space.
1 parent c3b319b commit 5b2f3e4

File tree

12 files changed

+67
-39
lines changed

12 files changed

+67
-39
lines changed

src/Layers/xrRender/xrRender_console.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ const xr_token qmsaa__atest_token[] = {
115115
u32 ps_r3_minmax_sm = 3; // = 0;
116116
const xr_token qminmax_sm_token[] = {{"off", 0}, {"on", 1}, {"auto", 2}, {"autodetect", 3}, {nullptr, 0}};
117117

118+
u32 ps_r3_rendering_space = 0; // = 0;
119+
const xr_token rendering__space_token[] = {
120+
{"gamma", 0}, {"linear", 1}, {nullptr, 0}};
121+
118122
// “Off”
119123
// “DX10.0 style [Standard]”
120124
// “DX10.1 style [Higher quality]”
@@ -1100,6 +1104,7 @@ void xrRender_initconsole()
11001104
//CMD3(CCC_Mask, "r3_msaa_alphatest", &ps_r2_ls_flags, (u32)R3FLAG_MSAA_ALPHATEST);
11011105
CMD3(CCC_Token, "r3_msaa_alphatest", &ps_r3_msaa_atest, qmsaa__atest_token);
11021106
CMD3(CCC_Token, "r3_minmax_sm", &ps_r3_minmax_sm, qminmax_sm_token);
1107+
CMD3(CCC_Token, "r3_rendering_space", &ps_r3_rendering_space, rendering__space_token);
11031108

11041109
// Allow real-time fog config reload
11051110
#if (RENDER == R_R3) || (RENDER == R_R4)

src/Layers/xrRender/xrRender_console.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ extern ECORE_API const xr_token qmsaa__atest_token[];
2929
extern ECORE_API u32 ps_r3_minmax_sm; // = 0;
3030
extern ECORE_API const xr_token qminmax_sm_token[];
3131

32+
extern ECORE_API u32 ps_r3_rendering_space; // = 0;
33+
extern ECORE_API const xr_token rendering__space_token[];
34+
3235
extern ENGINE_API int ps_r__Supersample;
3336
extern ECORE_API int ps_r__LightSleepFrames;
3437

src/Layers/xrRenderDX11/dx11HW.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,9 @@ bool CHW::CreateSwapChain(HWND hwnd)
271271
sd.BufferDesc.Height = Device.dwHeight;
272272

273273
// TODO: DX11: implement dynamic format selection
274-
constexpr DXGI_FORMAT formats[] =
275-
{
276-
//DXGI_FORMAT_R16G16B16A16_FLOAT, // Do we even need this?
277-
//DXGI_FORMAT_R10G10B10A2_UNORM, // D3DX11SaveTextureToMemory fails on this format
278-
DXGI_FORMAT_R8G8B8A8_UNORM,
279-
};
274+
sd.BufferDesc.Format = selectBackBufferFormat();
280275

281276
// Select back-buffer format
282-
sd.BufferDesc.Format = SelectFormat(D3D_FORMAT_SUPPORT_DISPLAY, formats);
283277
Caps.fTarget = dx11TextureUtils::ConvertTextureFormat(sd.BufferDesc.Format);
284278

285279
// Buffering
@@ -329,16 +323,8 @@ bool CHW::CreateSwapChain2(HWND hwnd)
329323
desc.Width = Device.dwWidth;
330324
desc.Height = Device.dwHeight;
331325

332-
constexpr DXGI_FORMAT formats[] =
333-
{
334-
//DXGI_FORMAT_R16G16B16A16_FLOAT,
335-
//DXGI_FORMAT_R10G10B10A2_UNORM,
336-
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
337-
//DXGI_FORMAT_R8G8B8A8_UNORM,
338-
};
326+
desc.Format = selectBackBufferFormat();
339327

340-
// Select back-buffer format
341-
desc.Format = SelectFormat(D3D11_FORMAT_SUPPORT_DISPLAY, formats);
342328
Caps.fTarget = dx11TextureUtils::ConvertTextureFormat(desc.Format);
343329

344330
// Buffering
@@ -389,6 +375,31 @@ bool CHW::CreateSwapChain2(HWND hwnd)
389375
return false;
390376
}
391377

378+
DXGI_FORMAT CHW::selectBackBufferFormat() const
379+
{
380+
if (ps_r3_rendering_space == 1)
381+
{
382+
constexpr DXGI_FORMAT formats[] = {
383+
// DXGI_FORMAT_R16G16B16A16_FLOAT,
384+
// DXGI_FORMAT_R10G10B10A2_UNORM,
385+
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
386+
// DXGI_FORMAT_R8G8B8A8_UNORM,
387+
};
388+
389+
// Select back-buffer format
390+
return SelectFormat(D3D11_FORMAT_SUPPORT_DISPLAY, formats);
391+
} else {
392+
constexpr DXGI_FORMAT formats[] = {
393+
// DXGI_FORMAT_R16G16B16A16_FLOAT,
394+
// DXGI_FORMAT_R10G10B10A2_UNORM,
395+
DXGI_FORMAT_R8G8B8A8_UNORM,
396+
};
397+
398+
// Select back-buffer format
399+
return SelectFormat(D3D11_FORMAT_SUPPORT_DISPLAY, formats);
400+
}
401+
}
402+
392403
bool CHW::ThisInstanceIsGlobal() const
393404
{
394405
return this == &HW;
@@ -439,6 +450,7 @@ void CHW::Reset()
439450
DXGI_MODE_DESC& desc = m_ChainDesc.BufferDesc;
440451
desc.Width = Device.dwWidth;
441452
desc.Height = Device.dwHeight;
453+
desc.Format = selectBackBufferFormat();
442454

443455
CHK_DX(m_pSwapChain->ResizeTarget(&desc));
444456
CHK_DX(m_pSwapChain->ResizeBuffers(

src/Layers/xrRenderDX11/dx11HW.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class CHW
103103
XRay::Module hD3DCompiler;
104104
XRay::Module hDXGI;
105105
XRay::Module hD3D;
106+
DXGI_FORMAT selectBackBufferFormat() const;
106107
};
107108

108109
extern ECORE_API CHW HW;

src/Layers/xrRenderDX11/dx11Texture.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ ID3DBaseTexture* CRender::texture_load(LPCSTR fRName, u32& ret_msize)
292292
fix_texture_name(fname);
293293

294294
bool force_srgb =
295-
!strstr(fname, "_bump")
295+
o.linear_space_rendering
296+
&& !strstr(fname, "_bump")
296297
&& !strstr(fname, "_mask")
297298
&& !strstr(fname, "_dudv")
298299
&& !strstr(fname, "water_normal")

src/Layers/xrRenderDX11/dx11TextureUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TextureFormatPairs TextureFormatList[] = {
2626
// D3DFMT_X4R4G4B4 Not available
2727
{D3DFMT_A2B10G10R10, DXGI_FORMAT_R10G10B10A2_UNORM},
2828
{D3DFMT_A8B8G8R8, DXGI_FORMAT_R8G8B8A8_UNORM}, // & DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
29-
{(D3DFORMAT)666, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB},
29+
{D3DFMT_HACK_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB},
3030
// D3DFMT_X8B8G8R8 Not available
3131
{D3DFMT_G16R16, DXGI_FORMAT_R16G16_UNORM},
3232
// D3DFMT_A2R10G10B10 Not available

src/Layers/xrRenderPC_R4/r4_rendertarget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ class CRenderTarget : public IRender_Target
359359

360360
void DoAsyncScreenshot();
361361

362+
363+
362364
#ifdef DEBUG
363365
void dbg_addline(const Fvector& P0, const Fvector& P1, u32 c)
364366
{
@@ -407,4 +409,13 @@ class CRenderTarget : public IRender_Target
407409
void dbg_addline(Fvector& /*P0*/, Fvector& /*P1*/, u32 /*c*/) {}
408410
void dbg_addplane(Fplane& /*P0*/, u32 /*c*/) {}
409411
#endif
412+
private:
413+
float toLinearSpace(float c) {
414+
return RImplementation.o.linear_space_rendering ? std::pow(c, 2.2f) : c;
415+
}
416+
417+
Fvector4 toLinearSpace(const Fvector4& c)
418+
{
419+
return Fvector4{toLinearSpace(c.x), toLinearSpace(c.y), toLinearSpace(c.z), c.w};
420+
}
410421
};

src/Layers/xrRenderPC_R4/r4_rendertarget_phase_combine.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55

66
#define STENCIL_CULL 0
77

8-
namespace
9-
{
10-
11-
float srgbToLinear(float c) { return std::pow(c, 2.2f); }
12-
13-
Fvector4 srgbToLinear(const Fvector4 c)
14-
{
15-
return Fvector4{srgbToLinear(c.x), srgbToLinear(c.y), srgbToLinear(c.z), c.w};
16-
}
17-
18-
} // namespace
19-
208
void CRenderTarget::DoAsyncScreenshot()
219
{
2210
// Igor: screenshot will not have postprocess applied.
@@ -228,8 +216,8 @@ void CRenderTarget::phase_combine()
228216
RCache.set_c("Ldynamic_color", sunclr);
229217
RCache.set_c("Ldynamic_dir", sundir);
230218

231-
RCache.set_c("env_color", srgbToLinear(envclr));
232-
RCache.set_c("fog_color", srgbToLinear(fogclr));
219+
RCache.set_c("env_color", toLinearSpace(envclr));
220+
RCache.set_c("fog_color", toLinearSpace(fogclr));
233221

234222
RCache.set_c("ssao_noise_tile_factor", fSSAONoise);
235223
RCache.set_c("ssao_kernel_size", fSSAOKernelSize);

src/Layers/xrRender_R2/r2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ void CRender::create()
559559
o.tessellation =
560560
HW.FeatureLevel >= D3D_FEATURE_LEVEL_11_0 && ps_r2_ls_flags_ext.test(R2FLAGEXT_ENABLE_TESSELLATION);
561561
o.support_rt_arrays = true;
562+
o.linear_space_rendering = (ps_r3_rendering_space == 1);
562563
#else
563564
o.support_rt_arrays = false;
564565
#endif

src/Layers/xrRender_R2/r2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ class CRender final : public D3DXRenderBase
275275

276276
// Yohji - New shader support
277277
u32 new_shader_support : 1;
278+
279+
u32 linear_space_rendering : 1;
278280
} o;
279281

280282
struct RenderR2Statistics

0 commit comments

Comments
 (0)