Skip to content

Commit

Permalink
Implement inverse tonemapping capability
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Sep 29, 2024
1 parent 13cb84b commit 9fe7cd9
Show file tree
Hide file tree
Showing 36 changed files with 282 additions and 197 deletions.
15 changes: 6 additions & 9 deletions shaders/cAutoExposure.fx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
#include "shared/cMacros.fxh"
#include "shared/cProcedural.fxh"

#define INCLUDE_CCAMERA_INPUT
#define INCLUDE_CCAMERA_OUTPUT
#include "shared/cCamera.fxh"

#define INCLUDE_CTONEMAP_OUTPUT
#include "shared/cTonemap.fxh"

/*
[Shader Options]
*/
Expand Down Expand Up @@ -55,6 +48,10 @@ uniform bool _DisplaySpotMeterMask <
> = false;

#include "shared/cShade.fxh"
#include "shared/cCameraInput.fxh"
#include "shared/cCameraOutput.fxh"
#include "shared/cTonemapOutput.fxh"

#include "shared/cBlend.fxh"

/*
Expand Down Expand Up @@ -91,7 +88,7 @@ float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0
Tex = SpotMeterTex;
}

float4 Color = tex2D(CShade_SampleColorTex, Tex);
float4 Color = CShade_BackBuffer2D(Tex);
float LogLuminance = GetLogLuminance(Color.rgb);

return CCamera_CreateExposureTex(LogLuminance, _Frametime);
Expand All @@ -101,7 +98,7 @@ float3 PS_Exposure(CShade_VS2PS_Quad Input) : SV_TARGET0
{
// Get textures
float Luma = tex2Dlod(SampleLumaTex, float4(Input.Tex0, 0.0, 99.0)).r;
float4 NonExposedColor = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 NonExposedColor = CShade_BackBuffer2D(Input.Tex0);

// Get exposure data
Exposure ExposureData = CCamera_GetExposureData(Luma);
Expand Down
2 changes: 1 addition & 1 deletion shaders/cBlend.fx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CREATE_SRGB_SAMPLER(SampleDestTex, CShade_ColorTex, LINEAR, CLAMP, CLAMP, CLAMP)

float4 PS_Copy(CShade_VS2PS_Quad Input) : SV_TARGET0
{
return tex2D(CShade_SampleColorTex, Input.Tex0);
return CShade_BackBuffer2D(Input.Tex0);
}

float4 PS_Blend(CShade_VS2PS_Quad Input) : SV_TARGET0
Expand Down
15 changes: 6 additions & 9 deletions shaders/cBloom.fx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
#include "shared/cColor.fxh"
#include "shared/cMath.fxh"

#define INCLUDE_CCAMERA_INPUT
#define INCLUDE_CCAMERA_OUTPUT
#include "shared/cCamera.fxh"

#define INCLUDE_CTONEMAP_OUTPUT
#include "shared/cTonemap.fxh"
#include "shared/cShade.fxh"
#include "shared/cCameraInput.fxh"
#include "shared/cCameraOutput.fxh"
#include "shared/cTonemapOutput.fxh"

/*
[Shader Options]
Expand Down Expand Up @@ -55,7 +53,6 @@ uniform float3 _ColorShift <
ui_max = 1.0;
> = 1.0;

#include "shared/cShade.fxh"
#include "shared/cBlend.fxh"

#ifndef USE_AUTOEXPOSURE
Expand Down Expand Up @@ -103,7 +100,7 @@ float4 PS_Prefilter(CShade_VS2PS_Quad Input) : SV_TARGET0
const float Knee = mad(_Threshold, _Smooth, 1e-5);
const float3 Curve = float3(_Threshold - Knee, Knee * 2.0, 0.25 / Knee);

float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 Color = CShade_BackBuffer2D(Input.Tex0);

// Apply auto-exposure backbuffer
#if USE_AUTOEXPOSURE
Expand Down Expand Up @@ -166,7 +163,7 @@ CREATE_PS_UPSCALE(PS_Upscale1, SampleTempTex2)

float4 PS_Composite(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float3 BaseColor = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
float3 BaseColor = CShade_BackBuffer2D(Input.Tex0).rgb;
float3 BloomColor = tex2D(SampleTempTex1, Input.Tex0).rgb;

// Apply auto-exposure to input
Expand Down
2 changes: 1 addition & 1 deletion shaders/cChromaticity.fx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uniform int _Select <

float4 PS_Chromaticity(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
float3 Color = CShade_BackBuffer2D(Input.Tex0).rgb;
float3 Gamma = tex2D(CShade_SampleGammaTex, Input.Tex0).rgb;
float4 Chromaticity = 0.0;

Expand Down
4 changes: 2 additions & 2 deletions shaders/cCircles.fx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ float GetTileCircleLength(Tile Input)
#if ENABLE_MONO
float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 Color = CShade_BackBuffer2D(Input.Tex0);
switch(_Select)
{
case 0:
Expand Down Expand Up @@ -301,7 +301,7 @@ float GetTileCircleLength(Tile Input)
#else
float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0
{
return tex2D(CShade_SampleColorTex, Input.Tex0);
return CShade_BackBuffer2D(Input.Tex0);
}

float4 PS_Circles(CShade_VS2PS_Quad Input) : SV_TARGET0
Expand Down
18 changes: 9 additions & 9 deletions shaders/cContrastNormalization.fx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ float4 GetCensusTransform(sampler2D Image, float2 Tex)

const int Neighbors = 8;
float4 SampleNeighbor[Neighbors];
SampleNeighbor[0] = tex2D(CShade_SampleColorTex, Tex0.xy);
SampleNeighbor[1] = tex2D(CShade_SampleColorTex, Tex1.xy);
SampleNeighbor[2] = tex2D(CShade_SampleColorTex, Tex2.xy);
SampleNeighbor[3] = tex2D(CShade_SampleColorTex, Tex0.xz);
SampleNeighbor[4] = tex2D(CShade_SampleColorTex, Tex2.xz);
SampleNeighbor[5] = tex2D(CShade_SampleColorTex, Tex0.xw);
SampleNeighbor[6] = tex2D(CShade_SampleColorTex, Tex1.xw);
SampleNeighbor[7] = tex2D(CShade_SampleColorTex, Tex2.xw);
float4 CenterSample = tex2D(CShade_SampleColorTex, Tex1.xz);
SampleNeighbor[0] = CShade_BackBuffer2D(Tex0.xy);
SampleNeighbor[1] = CShade_BackBuffer2D(Tex1.xy);
SampleNeighbor[2] = CShade_BackBuffer2D(Tex2.xy);
SampleNeighbor[3] = CShade_BackBuffer2D(Tex0.xz);
SampleNeighbor[4] = CShade_BackBuffer2D(Tex2.xz);
SampleNeighbor[5] = CShade_BackBuffer2D(Tex0.xw);
SampleNeighbor[6] = CShade_BackBuffer2D(Tex1.xw);
SampleNeighbor[7] = CShade_BackBuffer2D(Tex2.xw);
float4 CenterSample = CShade_BackBuffer2D(Tex1.xz);

// Generate 8-bit integer from the 8-pixel neighborhood
for(int i = 0; i < Neighbors; i++)
Expand Down
4 changes: 2 additions & 2 deletions shaders/cEnsor.fx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CREATE_SRGB_SAMPLER(SampleTempTex0, TempTex0_RGBA8_8, POINT, MIRROR, MIRROR, MIR

float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 Color = CShade_BackBuffer2D(Input.Tex0);

switch(_DetectionMode)
{
Expand Down Expand Up @@ -89,7 +89,7 @@ float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0

float4 PS_Censor(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 Color = CShade_BackBuffer2D(Input.Tex0);
float4 Blocks = tex2Dlod(SampleTempTex0, float4(Input.Tex0, 0.0, _Blockiness));

// Initialize variables
Expand Down
2 changes: 1 addition & 1 deletion shaders/cFrameBlend.fx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CREATE_SRGB_SAMPLER(SampleBlendTex, BlendTex, 1, CLAMP, CLAMP, CLAMP)
float4 PS_Blend(CShade_VS2PS_Quad Input) : SV_TARGET0
{
// Copy backbuffer to a that continuously blends with its previous result
return float4(tex2D(CShade_SampleColorTex, Input.Tex0).rgb, _BlendFactor);
return float4(CShade_BackBuffer2D(Input.Tex0).rgb, _BlendFactor);
}

float4 PS_Display(CShade_VS2PS_Quad Input) : SV_TARGET0
Expand Down
8 changes: 4 additions & 4 deletions shaders/cGaussianBlur.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ float4 GetGaussianBlur(float2 Tex, bool IsHorizontal)

if(_Sigma == 0.0)
{
return tex2Dlod(CShade_SampleColorTex, float4(Tex, 0.0, 0.0));
return CShade_BackBuffer2Dlod(float4(Tex, 0.0, 0.0));
}
else
{
// Sample and weight center first to get even number sides
float TotalWeight = CBlur_GetGaussianWeight(0.0, _Sigma);
float4 OutputColor = tex2D(CShade_SampleColorTex, Tex) * TotalWeight;
float4 OutputColor = CShade_BackBuffer2D(Tex) * TotalWeight;

for(float i = 1.0; i < KernelSize; i += 2.0)
{
float LinearWeight = 0.0;
float LinearOffset = CBlur_GetGaussianOffset(i, _Sigma, LinearWeight);
OutputColor += tex2Dlod(CShade_SampleColorTex, float4(Tex - LinearOffset * PixelSize, 0.0, 0.0)) * LinearWeight;
OutputColor += tex2Dlod(CShade_SampleColorTex, float4(Tex + LinearOffset * PixelSize, 0.0, 0.0)) * LinearWeight;
OutputColor += CShade_BackBuffer2Dlod(float4(Tex - LinearOffset * PixelSize, 0.0, 0.0)) * LinearWeight;
OutputColor += CShade_BackBuffer2Dlod(float4(Tex + LinearOffset * PixelSize, 0.0, 0.0)) * LinearWeight;
TotalWeight += LinearWeight * 2.0;
}

Expand Down
2 changes: 1 addition & 1 deletion shaders/cGrayscale.fx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uniform int _Select <

float4 PS_Luminance(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 Color = CShade_BackBuffer2D(Input.Tex0);
float3 Luma = CColor_GetLuma(Color.rgb, _Select);
return CBlend_OutputChannels(float4(Luma, _CShadeAlphaFactor));
}
Expand Down
4 changes: 2 additions & 2 deletions shaders/cMotionBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CREATE_SAMPLER(SampleOFlowTex, OFlowTex, LINEAR, MIRROR, MIRROR, MIRROR)

float2 PS_Normalize(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
float3 Color = CShade_BackBuffer2D(Input.Tex0).rgb;
return CColor_GetSphericalRG(Color).xy;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ float4 PS_MotionBlur(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float Random = (CProcedural_GetInterleavedGradientNoise(Input.HPos.xy + k) * 2.0) - 1.0;
float2 RandomTex = Input.Tex0.xy + (ScaledVelocity * Random);
OutputColor += tex2D(CShade_SampleColorTex, RandomTex);
OutputColor += CShade_BackBuffer2D(RandomTex);
}

return CBlend_OutputChannels(float4(OutputColor.rgb / Samples, _CShadeAlphaFactor));
Expand Down
2 changes: 1 addition & 1 deletion shaders/cNoiseBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ float4 PS_NoiseBlur(CShade_VS2PS_Quad Input) : SV_TARGET0
float2 SampleOffset = mul(AngleShift, RotationMatrix) * FalloffFactor;
SampleOffset *= _Radius;
SampleOffset.x *= AspectRatio;
OutputColor += tex2D(CShade_SampleColorTex, Input.Tex0 + (SampleOffset * 0.01));
OutputColor += CShade_BackBuffer2D(Input.Tex0 + (SampleOffset * 0.01));
Weight++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion shaders/cOpticalFlow.fx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ CREATE_SAMPLER(SampleOFlowTex, OFlowTex, LINEAR, MIRROR, MIRROR, MIRROR)

float2 PS_Normalize(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
float3 Color = CShade_BackBuffer2D(Input.Tex0).rgb;
return CColor_GetSphericalRG(Color).xy;
}

Expand Down
2 changes: 1 addition & 1 deletion shaders/cPixelate.fx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uniform int2 _Pixels <
float4 PS_Color(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float2 Tex = floor(Input.Tex0 * _Pixels) / _Pixels;
float4 OutputColor = tex2D(CShade_SampleColorTex, Tex);
float4 OutputColor = CShade_BackBuffer2D(Tex);

return CBlend_OutputChannels(float4(OutputColor.rgb, _CShadeAlphaFactor));
}
Expand Down
2 changes: 1 addition & 1 deletion shaders/cRCAS.fx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ uniform int _RenderMode <
> = 0;

uniform float _Sharpening <
ui_category = "Robust Contrast Adaptive Sharpening";
ui_label = "Sharpening";
ui_type = "slider";
ui_min = 0.0;
Expand All @@ -27,6 +26,7 @@ float4 PS_RCAS(CShade_VS2PS_Quad Input): SV_TARGET0
float4 OutputColor = 1.0;
float4 OutputMask = 1.0;
FFX_RCAS(
CShade_SampleColorTex,
OutputColor,
OutputMask,
Input.Tex0,
Expand Down
2 changes: 1 addition & 1 deletion shaders/cThreshold.fx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ float4 PS_Threshold(CShade_VS2PS_Quad Input) : SV_TARGET0
{
const float Knee = mad(_Threshold, _Smooth, 1e-5f);
const float3 Curve = float3(_Threshold - Knee, Knee * 2.0, 0.25 / Knee);
float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 Color = CShade_BackBuffer2D(Input.Tex0);

// Under-threshold
float Brightness = CColor_GetLuma(Color.rgb, 3);
Expand Down
2 changes: 1 addition & 1 deletion shaders/kContour.fx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ float3 PS_Grad(CShade_VS2PS_Quad Input) : SV_TARGET0
}

// Getting textures
float3 Base = tex2D(CShade_SampleColorTex, Input.Tex0.xy).rgb;
float3 Base = CShade_BackBuffer2D(Input.Tex0.xy).rgb;
float3 BackgroundColor = lerp(Base.rgb, _BackColor.rgb, _BackColor.a);

if (_DisplayMode == 1)
Expand Down
6 changes: 3 additions & 3 deletions shaders/kDatamosh.fx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ CREATE_SRGB_SAMPLER(SampleFeedbackTex, FeedbackTex, LINEAR, MIRROR, MIRROR, MIRR

float2 PS_Normalize(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
float3 Color = CShade_BackBuffer2D(Input.Tex0).rgb;
return CColor_GetSphericalRG(Color).xy;
}

Expand Down Expand Up @@ -277,7 +277,7 @@ float4 PS_Datamosh(CShade_VS2PS_Quad Input) : SV_TARGET0
MV = CMotionEstimation_NormalizeMotionVectors(MV, TexSize);

// Color from the original image
float4 Source = tex2D(CShade_SampleColorTex, Input.Tex0);
float4 Source = CShade_BackBuffer2D(Input.Tex0);

// Displacement vector
float Disp = tex2D(SampleAccumTex, Input.Tex0).r;
Expand Down Expand Up @@ -307,7 +307,7 @@ float4 PS_Datamosh(CShade_VS2PS_Quad Input) : SV_TARGET0

float4 PS_CopyColorTex(CShade_VS2PS_Quad Input) : SV_TARGET0
{
return tex2D(CShade_SampleColorTex, Input.Tex0);
return CShade_BackBuffer2D(Input.Tex0);
}

#define CREATE_PASS(VERTEX_SHADER, PIXEL_SHADER, RENDER_TARGET) \
Expand Down
2 changes: 1 addition & 1 deletion shaders/kMirror.fx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ float4 PS_Mirror(CShade_VS2PS_Quad Input) : SV_TARGET0

// Reflection at the border of the screen.
Input.Tex0 = max(min(Input.Tex0, 2.0 - Input.Tex0), -Input.Tex0);
return CBlend_OutputChannels(float4(tex2D(CShade_SampleColorTex, Input.Tex0).rgb, _CShadeAlphaFactor));
return CBlend_OutputChannels(float4(CShade_BackBuffer2D(Input.Tex0).rgb, _CShadeAlphaFactor));
}

technique CShade_KinoMirror < ui_tooltip = "Keijiro Takahashi | Mirroring and kaleidoscope effect"; >
Expand Down
4 changes: 2 additions & 2 deletions shaders/shared/cBlend.fxh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#if !defined(INCLUDE_BLENDOP)
#define INCLUDE_BLENDOP
#if !defined(INCLUDE_CBLENDOP)
#define INCLUDE_CBLENDOP

/*
BlendEnable0 to BlendEnable7 allow to enable or disable color and alpha blending for the respective render target.
Expand Down
4 changes: 2 additions & 2 deletions shaders/shared/cBlur.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "cMath.fxh"
#include "cProcedural.fxh"

#if !defined(INCLUDE_BLUR)
#define INCLUDE_BLUR
#if !defined(INCLUDE_CBLUR)
#define INCLUDE_CBLUR

/*
Linear Gaussian blur
Expand Down
Loading

0 comments on commit 9fe7cd9

Please sign in to comment.