Skip to content

Commit 3bdbb90

Browse files
committed
GITechDemo:
*The HDR tone mapping pass now also performs color correction through the use of a 3D color lookup table *Added anamorphic bokeh effect as an option (disabled by default) *Lens flare textures now have full mip chain Synesthesia3D: *Fixed an issue where the addressing mode on the W axis for 3D textures was not properly set
1 parent 15832bd commit 3bdbb90

File tree

10 files changed

+56
-25
lines changed

10 files changed

+56
-25
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ bld/
2020
!/*/[Bb]uild/**
2121
/*/[Bb]uild/**/
2222
/*/[Bb]in/
23+
/*/[Dd]ata/[Mm]odels/
24+
/*/[Dd]ata/[Tt]extures/
2325
[Oo]bj/
2426
[Bb]in[Tt]emp/
2527
[Ll]ogs/

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/HDRToneMappingPass.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ using namespace GITechDemoApp;
3737
namespace GITechDemoApp
3838
{
3939
bool HDR_TONE_MAPPING_ENABLED = true;
40+
bool SRGB_COLOR_CORRECTION = false;
4041
}
4142

4243
HDRToneMappingPass::HDRToneMappingPass(const char* const passName, RenderPass* const parentPass)
@@ -66,14 +67,19 @@ void HDRToneMappingPass::Update(const float fDeltaTime)
6667

6768
ResourceMgr->GetTexture(LDRToneMappedImageBuffer.GetRenderTarget()->GetColorBuffer(0))->SetFilter(SF_MIN_MAG_LINEAR_MIP_NONE);
6869
ResourceMgr->GetTexture(LDRToneMappedImageBuffer.GetRenderTarget()->GetColorBuffer(0))->SetSRGBEnabled(true);
69-
70+
71+
ColorCorrectionTexture.GetTexture()->SetFilter(SF_MIN_MAG_LINEAR_MIP_NONE);
72+
ColorCorrectionTexture.GetTexture()->SetAddressingMode(SAM_CLAMP);
73+
ColorCorrectionTexture.GetTexture()->SetSRGBEnabled(SRGB_COLOR_CORRECTION);
74+
7075
GITechDemoApp::RenderTarget* const rtBkp = AdaptedLuminance[0];
7176
AdaptedLuminance[0] = AdaptedLuminance[1];
7277
AdaptedLuminance[1] = rtBkp;
7378

7479
fFrameTime = gmtl::Math::clamp(fDeltaTime, 0.f, 1.f / fLumaAdaptSpeed);
7580

7681
texLumaTarget = AverageLuminanceBuffer[3]->GetRenderTarget()->GetColorBuffer(0);
82+
texColorCorrection = ColorCorrectionTexture.GetTextureIndex();
7783
}
7884

7985
// Measure average luminance level of scene

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/LensFlarePass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ void LensFlarePass::Update(const float fDeltaTime)
6868
texGhostColorLUT = LensFlareGhostColorLUT.GetTextureIndex();
6969

7070
LensFlareDirt.GetTexture()->SetAddressingMode(SAM_CLAMP);
71-
LensFlareDirt.GetTexture()->SetFilter(SF_MIN_MAG_LINEAR_MIP_NONE);
71+
LensFlareDirt.GetTexture()->SetFilter(SF_MIN_MAG_LINEAR_MIP_LINEAR);
7272
texLensFlareDirt = LensFlareDirt.GetTextureIndex();
7373

7474
LensFlareStarBurst.GetTexture()->SetAddressingMode(SAM_CLAMP);
75-
LensFlareStarBurst.GetTexture()->SetFilter(SF_MIN_MAG_LINEAR_MIP_NONE);
75+
LensFlareStarBurst.GetTexture()->SetFilter(SF_MIN_MAG_LINEAR_MIP_LINEAR);
7676
texLensFlareStarBurst = LensFlareStarBurst.GetTextureIndex();
7777

7878
nDownsampleFactor = 1;

GITechDemo/Code/AppMain/GITechDemo/Resources/AppResources.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ namespace GITechDemoApp
139139

140140
// Tone mapping
141141
extern bool HDR_TONE_MAPPING_ENABLED;
142+
extern bool SRGB_COLOR_CORRECTION;
142143

143144
// FXAA
144145
extern bool FXAA_ENABLED;
@@ -220,6 +221,7 @@ namespace GITechDemoApp
220221
CREATE_TEXTURE_OBJECT(LensFlareStarBurst, "textures/LensFlareStarBurst.s3dtex");
221222
CREATE_TEXTURE_OBJECT(BayerMatrix, "textures/bayer_matrix.s3dtex");
222223
CREATE_TEXTURE_OBJECT(NoiseTexture, "textures/noise.s3dtex");
224+
CREATE_TEXTURE_OBJECT(ColorCorrectionTexture, "textures/ContrastEnhance.s3dtex");
223225
//------------------------------------------------------
224226

225227

@@ -452,17 +454,18 @@ namespace GITechDemoApp
452454

453455
/* Post-processing parameters */
454456
// Tone mapping
455-
CREATE_SHADER_CONSTANT_OBJECT(fExposureBias, float, 0.5f );
456-
CREATE_SHADER_CONSTANT_OBJECT(f2AvgLumaClamp, Vec2f, Vec2f(0.00001f, 0.75f) );
457-
CREATE_SHADER_CONSTANT_OBJECT(fShoulderStrength, float, 0.15f );
458-
CREATE_SHADER_CONSTANT_OBJECT(fLinearStrength, float, 0.5f );
459-
CREATE_SHADER_CONSTANT_OBJECT(fLinearAngle, float, 0.07f );
460-
CREATE_SHADER_CONSTANT_OBJECT(fToeStrength, float, 3.f );
461-
CREATE_SHADER_CONSTANT_OBJECT(fToeNumerator, float, 0.02f );
462-
CREATE_SHADER_CONSTANT_OBJECT(fToeDenominator, float, 0.25f );
463-
CREATE_SHADER_CONSTANT_OBJECT(fLinearWhite, float, 11.2f );
457+
CREATE_SHADER_CONSTANT_OBJECT(fExposureBias, float, 0.2f );
458+
CREATE_SHADER_CONSTANT_OBJECT(f2AvgLumaClamp, Vec2f, Vec2f(0.0001f, 0.75f) );
459+
CREATE_SHADER_CONSTANT_OBJECT(fShoulderStrength, float, 0.5f );
460+
CREATE_SHADER_CONSTANT_OBJECT(fLinearStrength, float, 0.58f );
461+
CREATE_SHADER_CONSTANT_OBJECT(fLinearAngle, float, 0.35f );
462+
CREATE_SHADER_CONSTANT_OBJECT(fToeStrength, float, 0.48f );
463+
CREATE_SHADER_CONSTANT_OBJECT(fToeNumerator, float, 0.12f );
464+
CREATE_SHADER_CONSTANT_OBJECT(fToeDenominator, float, 0.58f );
465+
CREATE_SHADER_CONSTANT_OBJECT(fLinearWhite, float, 3.f );
464466
CREATE_SHADER_CONSTANT_OBJECT(fLumaAdaptSpeed, float, 1.f );
465467
CREATE_SHADER_CONSTANT_OBJECT(fFilmGrainAmount, float, 0.003f );
468+
CREATE_SHADER_CONSTANT_OBJECT(bApplyColorCorrection, bool, true );
466469
// Bloom
467470
CREATE_SHADER_CONSTANT_OBJECT(fBrightnessThreshold, float, 0.2f );
468471
CREATE_SHADER_CONSTANT_OBJECT(fBloomPower, float, 1.f );
@@ -483,6 +486,7 @@ namespace GITechDemoApp
483486
CREATE_SHADER_CONSTANT_OBJECT(fHighlightThreshold, float, 3.f );
484487
CREATE_SHADER_CONSTANT_OBJECT(fHighlightGain, float, 15.f );
485488
CREATE_SHADER_CONSTANT_OBJECT(fApertureSize, float, 0.01f );
489+
CREATE_SHADER_CONSTANT_OBJECT(bAnamorphicBokeh, bool, false );
486490
CREATE_SHADER_CONSTANT_OBJECT(bVignetting, bool, true );
487491
CREATE_SHADER_CONSTANT_OBJECT(fVignOut, float, 0.75f );
488492
CREATE_SHADER_CONSTANT_OBJECT(fVignIn, float, 0.25f );
@@ -570,6 +574,7 @@ namespace GITechDemoApp
570574
CREATE_SHADER_CONSTANT_OBJECT(bInitialLumaPass, bool );
571575
CREATE_SHADER_CONSTANT_OBJECT(bFinalLumaPass, bool );
572576
CREATE_SHADER_CONSTANT_OBJECT(texAvgLuma, s3dSampler2D );
577+
CREATE_SHADER_CONSTANT_OBJECT(texColorCorrection, s3dSampler3D );
573578
CREATE_SHADER_CONSTANT_OBJECT(texSource, s3dSampler2D );
574579
CREATE_SHADER_CONSTANT_OBJECT(fFrameTime, float );
575580
CREATE_SHADER_CONSTANT_OBJECT(texLumaTarget, s3dSampler2D );
@@ -718,6 +723,7 @@ namespace GITechDemoApp
718723
CREATE_ARTIST_PARAMETER_OBJECT("DoF pass count", "The number of times to apply the DoF shader", "Depth of field", DOF_NUM_PASSES, 1.f);
719724
CREATE_ARTIST_PARAMETER_OBJECT("Highlight threshold", "Brightness-pass filter threshold (higher = sparser bokeh)", "Depth of field", fHighlightThreshold.GetCurrentValue(), 0.1f);
720725
CREATE_ARTIST_PARAMETER_OBJECT("Highlight gain", "Brightness gain (higher = more prominent bokeh)", "Depth of field", fHighlightGain.GetCurrentValue(), 0.1f);
726+
CREATE_ARTIST_BOOLPARAM_OBJECT("Anamorphic bokeh", "Stretch bokeh effect like on an anamorphic lens", "Depth of field", bAnamorphicBokeh.GetCurrentValue());
721727
CREATE_ARTIST_BOOLPARAM_OBJECT("Autofocus", "Use autofocus", "Depth of field", bAutofocus.GetCurrentValue());
722728
CREATE_ARTIST_PARAMETER_OBJECT("Autofocus time", "Autofocus animation duration in seconds", "Depth of field", DOF_AUTOFOCUS_TIME, 1.f);;
723729

@@ -775,6 +781,10 @@ namespace GITechDemoApp
775781
CREATE_ARTIST_PARAMETER_OBJECT("Linear white", "Reference linear white value of the filmic tone mapping curve", "HDR tone mapping", fLinearWhite.GetCurrentValue(), 0.1f);
776782
CREATE_ARTIST_PARAMETER_OBJECT("Exposure adapt speed", "Seconds in which the exposure adapts to scene brightness", "HDR tone mapping", fLumaAdaptSpeed.GetCurrentValue(), 0.1f);
777783

784+
// Color correction (part of HDR tonemapping shader)
785+
CREATE_ARTIST_BOOLPARAM_OBJECT("Apply color correction", "Use the provided 3D color lookup table to do color correction", "Color correction", bApplyColorCorrection.GetCurrentValue());
786+
CREATE_ARTIST_BOOLPARAM_OBJECT("sRGB color lookup table", "Apply gamma correction when sampling the 3D color lookup table", "Color correction", SRGB_COLOR_CORRECTION);
787+
778788
// Film grain (part of HDR tonemapping shader)
779789
CREATE_ARTIST_PARAMETER_OBJECT("Film grain amount", "Amount of film grain applied to the image", "Film grain", fFilmGrainAmount.GetCurrentValue(), 0.001f);
780790

GITechDemo/Code/AppMain/GITechDemo/Resources/AppResources.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace GITechDemoApp
8383
CREATE_TEXTURE_HANDLE(LensFlareStarBurst);
8484
CREATE_TEXTURE_HANDLE(BayerMatrix);
8585
CREATE_TEXTURE_HANDLE(NoiseTexture);
86+
CREATE_TEXTURE_HANDLE(ColorCorrectionTexture);
8687
//------------------------------------------------------
8788

8889
// Render targets
@@ -261,6 +262,8 @@ namespace GITechDemoApp
261262

262263
// - HDRToneMapping.hlsl
263264
CREATE_SHADER_CONSTANT_HANDLE(texAvgLuma, s3dSampler2D );
265+
CREATE_SHADER_CONSTANT_HANDLE(texColorCorrection, s3dSampler3D );
266+
CREATE_SHADER_CONSTANT_HANDLE(bApplyColorCorrection, bool );
264267
CREATE_SHADER_CONSTANT_HANDLE(fExposureBias, float );
265268
CREATE_SHADER_CONSTANT_HANDLE(fShoulderStrength, float );
266269
CREATE_SHADER_CONSTANT_HANDLE(fLinearStrength, float );
@@ -311,6 +314,7 @@ namespace GITechDemoApp
311314
CREATE_SHADER_CONSTANT_HANDLE(fApertureSize, float );
312315
CREATE_SHADER_CONSTANT_HANDLE(fHighlightThreshold, float );
313316
CREATE_SHADER_CONSTANT_HANDLE(fHighlightGain, float );
317+
CREATE_SHADER_CONSTANT_HANDLE(bAnamorphicBokeh, bool );
314318
CREATE_SHADER_CONSTANT_HANDLE(bVignetting, bool );
315319
CREATE_SHADER_CONSTANT_HANDLE(fVignOut, float );
316320
CREATE_SHADER_CONSTANT_HANDLE(fVignIn, float );

GITechDemo/Code/External/Synesthesia3D/DX9/SamplerStateDX9.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const bool SamplerStateDX9::Flush()
206206
return false;
207207
}
208208

209-
if (m_tCurrentStateDX9[slot].eAddressingMode[2] == GetAddressingModeW(slot))
209+
if (m_tCurrentStateDX9[slot].eAddressingMode[2] != GetAddressingModeW(slot))
210210
{
211211
hr = device->SetSamplerState(slot, D3DSAMP_ADDRESSW, TextureAddressingModeDX9[GetAddressingModeW(slot)]);
212212
assert(SUCCEEDED(hr));

GITechDemo/Data/shaders/BokehDoF.hlsl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ const float4 f4TexSize; // xy: size, in texels, of source image; zw: normalized
6262

6363
// Camera properties
6464
#define APERTURE_BLADE_COUNT (6)
65-
const float fFocalDepth; // Focal distance value in meters (overridden by 'bAutofocus')
66-
const float fFocalLength; // Focal length in mm
67-
const float fFStop; // F-stop value
68-
const float fCoC; // Circle of confusion size in mm (35mm film = 0.03mm)
69-
const float fApertureSize; // Determines size of bokeh
70-
const bool bAutofocus; // Overrides fFocalDepth value with value taken from depth buffer
65+
const float fFocalDepth; // Focal distance value in meters (overridden by 'bAutofocus')
66+
const float fFocalLength; // Focal length in mm
67+
const float fFStop; // F-stop value
68+
const float fCoC; // Circle of confusion size in mm (35mm film = 0.03mm)
69+
const float fApertureSize; // Determines size of bokeh
70+
const bool bAutofocus; // Overrides fFocalDepth value with value taken from depth buffer
71+
const bool bAnamorphicBokeh; // Stretch bokeh effect like on an anamorphic lens
7172

7273
// Brightness filter (directly affects bokeh abundance and prominence)
7374
const float fHighlightThreshold; // Brightness-pass filter threshold (higher = sparser bokeh)
@@ -133,7 +134,7 @@ void psmain(VSOut input, out float4 f4Color : SV_TARGET)
133134
for (int i = 0; i < APERTURE_BLADE_COUNT; i++)
134135
{
135136
// Retrieve sample color and CoC value
136-
const float4 f4Sample = tex2D(texSource, input.f2TexCoord + f2KernelOffset[i] * fApertureSize * fDofBlurFactor * float2(fAspectRatioScale, 1.f));
137+
const float4 f4Sample = tex2D(texSource, input.f2TexCoord + f2KernelOffset[i] * float2(bAnamorphicBokeh ? 1.f / 2.40f : 1.f, 1.f) * fApertureSize * fDofBlurFactor * float2(fAspectRatioScale, 1.f));
137138
const float fSampleDofBlurFactor = f4Sample.a * 2.f - 1.f;
138139

139140
// Calculate sample weight

GITechDemo/Data/shaders/HDRToneMapping.hlsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void vsmain(float4 f4Position : POSITION, float2 f2TexCoord : TEXCOORD, out VSOu
4141
// Pixel shader ///////////////////////////////////////////////////
4242
const sampler2D texSource; // Source HDR texture
4343
const sampler2D texAvgLuma; // 1x1 average luma texture
44+
const sampler3D texColorCorrection; // Color correction texture
4445

4546
const float fExposureBias; // Exposure amount
4647

@@ -55,6 +56,8 @@ const float fLinearWhite; // = 11.2;
5556
const float fFrameTime;
5657
const float fFilmGrainAmount;
5758

59+
const bool bApplyColorCorrection;
60+
5861
float3 ReinhardTonemap(const float3 f3Color, const float fAvgLuma)
5962
{
6063
return f3Color / (1.f + fAvgLuma);
@@ -115,6 +118,10 @@ void psmain(VSOut input, out float4 f4Color : SV_TARGET)
115118
const float3 f3WhiteScale = rcp(FilmicTonemap(fLinearWhite));
116119
f3FinalColor *= f3WhiteScale;
117120

121+
// Color correction
122+
if(bApplyColorCorrection)
123+
f3FinalColor = tex3D(texColorCorrection, saturate(f3FinalColor)).rgb;
124+
118125
// Convert back to gamma space (not required for Duiker tonemap)
119126
// NB: Gamma correction done by RenderState::SetSRGBWriteEnabled()
120127
//f4Color = float4(pow(abs(f3FinalColor), 1.f / 2.2f), 1);

GITechDemo/DataSrc/compile_utility_textures.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@
5656
# Set custom arguments for individual files
5757
customArgs = defaultdict(lambda: "-q -f A8R8G8B8", \
5858
{
59-
"sky.dds" : "-q -f A16B16G16R16F",
60-
"LensFlareDirt.png" : "-q -f A8R8G8B8 -mip 1",
61-
"LensFlareStarBurst.png" : "-q -f A8R8G8B8 -mip 1",
62-
"bayer_matrix.dds" : "-q -f L8 -mip 1",
63-
"noise.dds" : "-q -f L8 -mip 1"
59+
"sky.dds" : "-q -f A16B16G16R16F",
60+
#"LensFlareDirt.png" : "-q -f A8R8G8B8 -mip 1",
61+
#"LensFlareStarBurst.png" : "-q -f A8R8G8B8 -mip 1",
62+
"ContrastEnhance.dds" : "-q -f A8R8G8B8 -mip 1",
63+
"bayer_matrix.dds" : "-q -f L8 -mip 1",
64+
"noise.dds" : "-q -f L8 -mip 1"
6465
})
6566

6667
# Detect modification of texture compiler executable
12.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)