Skip to content

Commit 552c3d5

Browse files
committed
Metallic Tex Hotfix
Fixed Metallic Textures Added AgX Tonemapper
1 parent d1e3ef8 commit 552c3d5

File tree

7 files changed

+54
-4
lines changed

7 files changed

+54
-4
lines changed

TrueTrace.unitypackage

366 KB
Binary file not shown.

TrueTrace/Editor/PathTracerSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ public void CreateGUI() {
11741174
TonemapSettings.Add("Uchimura");
11751175
TonemapSettings.Add("Reinhard");
11761176
TonemapSettings.Add("Uncharted 2");
1177+
TonemapSettings.Add("AgX");
11771178
PopupField<string> ToneMapField = new PopupField<string>("Tonemapper");
11781179
ToneMapField.choices = TonemapSettings;
11791180
ToneMapField.index = RayMaster.ToneMapper;

TrueTrace/Resources/AssetManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private void PackAndCompact(Dictionary<int, TexObj> DictTex, ref RenderTexture A
241241
case 3:
242242
case 4:
243243
case 7:
244-
CopyShader.SetInt("OutputRead", ((TexChannelIndex == null) ? ReadIndex : SelectedTex.ReadIndex));
244+
CopyShader.SetInt("OutputRead", SelectedTex.ReadIndex);
245245
CopyShader.SetTexture(2, "AdditionTex", SelectedTex.Tex);
246246
CopyShader.SetTexture(2, "ResultSingle", Atlas);
247247
CopyShader.Dispatch(2, (int)Mathf.CeilToInt(TempRect.Width * Scale.x / 32.0f), (int)Mathf.CeilToInt(TempRect.Height * Scale.y / 32.0f), 1);

TrueTrace/Resources/PostProcess/Compute/ToneMap.compute

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,50 @@ float3 HejlBurgess(float3 texColor) {
112112
return retColor;
113113
}
114114

115+
struct ParamsLogC
116+
{
117+
float cut;
118+
float a, b, c, d, e, f;
119+
};
120+
121+
static const ParamsLogC LogC =
122+
{
123+
0.011361, // cut
124+
5.555556, // a
125+
0.047996, // b
126+
0.244161, // c
127+
0.386036, // d
128+
5.301883, // e
129+
0.092819 // f
130+
};
131+
132+
float LinearToLogC_Precise(half x)
133+
{
134+
float o;
135+
if (x > LogC.cut)
136+
o = LogC.c * log10(LogC.a * x + LogC.b) + LogC.d;
137+
else
138+
o = LogC.e * x + LogC.f;
139+
return o;
140+
}
141+
142+
inline float3 AgX(float3 stimulus) {
143+
// Apply a non-linear transform that the LUT is encoded with.
144+
const float3 encoded = stimulus;// / (stimulus + 1.0);
145+
146+
// Align the encoded range to texel centers.
147+
float3 uv = encoded;// * ((LUT_DIMS - 1.0) / LUT_DIMS) + 0.5 / LUT_DIMS;
148+
149+
// Note: for OpenGL, do `uv.y = 1.0 - uv.y`
150+
uv = float3(
151+
LinearToLogC_Precise(uv.x),
152+
LinearToLogC_Precise(uv.y),
153+
LinearToLogC_Precise(uv.z)
154+
);
155+
156+
return LUT.SampleLevel(sampler_linear_clamp, uv, 0);
157+
}
158+
115159
[numthreads(16,16,1)]
116160
void CSMain (uint3 id : SV_DispatchThreadID)
117161
{
@@ -133,6 +177,9 @@ void CSMain (uint3 id : SV_DispatchThreadID)
133177
case 4:
134178
result = Uncharted2ToneMapping(result);
135179
break;
180+
case 5:
181+
result = AgX(result);
182+
break;
136183
};
137184
Result[id.xy] = float4(result, 1.0);
138185
}

TrueTrace/Resources/PostProcess/Denoiser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public void ExecuteUpsample(ref RenderTexture Input, ref RenderTexture Output, i
506506
}
507507

508508

509-
public void ExecuteToneMap(ref RenderTexture Output, CommandBuffer cmd, ref Texture3D LUT, int ToneMapSelection)
509+
public void ExecuteToneMap(ref RenderTexture Output, CommandBuffer cmd, ref Texture3D LUT, ref Texture3D LUT2, int ToneMapSelection)
510510
{//need to fix this so it doesnt create new textures every time
511511
cmd.BeginSample("ToneMap");
512512
cmd.SetComputeIntParam(ToneMapper,"ToneMapSelection", ToneMapSelection);
@@ -515,7 +515,7 @@ public void ExecuteToneMap(ref RenderTexture Output, CommandBuffer cmd, ref Text
515515
cmd.SetComputeIntParam(ToneMapper,"ScreenWidth", Output.width);
516516
cmd.SetComputeIntParam(ToneMapper,"ScreenHeight", Output.height);
517517
cmd.SetComputeTextureParam(ToneMapper, 0, "Result", Output);
518-
cmd.SetComputeTextureParam(ToneMapper, 0, "LUT", LUT);
518+
cmd.SetComputeTextureParam(ToneMapper, 0, "LUT", ToneMapSelection == 5 ? LUT2 : LUT);
519519
cmd.DispatchCompute(ToneMapper, 0, threadGroupsX2, threadGroupsY2, 1);
520520
cmd.EndSample("ToneMap");
521521
}

TrueTrace/Resources/RayTracingMaster.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class RayTracingMaster : MonoBehaviour
8080
#endif
8181

8282
private Texture3D ToneMapTex;
83+
private Texture3D ToneMapTex2;
8384
private Material _addMaterial;
8485
private Material _FireFlyMaterial;
8586
private int _currentSample = 0;
@@ -195,6 +196,7 @@ unsafe public void Start2()
195196
ReCurDen = new ReCurDenoiser();
196197
ReSTIRASVGFCode = new ReSTIRASVGF();
197198
ToneMapTex = Resources.Load<Texture3D>("Utility/ToneMapTex");
199+
ToneMapTex2 = Resources.Load<Texture3D>("Utility/AgXBC");
198200
if (ShadingShader == null) {ShadingShader = Resources.Load<ComputeShader>("MainCompute/RayTracingShader"); }
199201
if (IntersectionShader == null) {IntersectionShader = Resources.Load<ComputeShader>("MainCompute/IntersectionKernels"); }
200202
if (GenerateShader == null) {GenerateShader = Resources.Load<ComputeShader>("MainCompute/RayGenKernels"); }
@@ -983,7 +985,7 @@ private void Render(RenderTexture destination, CommandBuffer cmd)
983985
Denoisers.ExecuteAutoExpose(ref _FinalTex, Exposure, cmd, DoExposureAuto);
984986
}
985987
if (AllowBloom) Denoisers.ExecuteBloom(ref _FinalTex, BloomStrength, cmd);
986-
if(AllowToneMap) Denoisers.ExecuteToneMap(ref _FinalTex, cmd, ref ToneMapTex, ToneMapper);
988+
if(AllowToneMap) Denoisers.ExecuteToneMap(ref _FinalTex, cmd, ref ToneMapTex, ref ToneMapTex2, ToneMapper);
987989
if (AllowTAA) Denoisers.ExecuteTAA(ref _FinalTex, _currentSample, cmd);
988990

989991
cmd.Blit(_FinalTex, destination);
362 KB
Binary file not shown.

0 commit comments

Comments
 (0)