Skip to content

Commit 48efbe8

Browse files
committed
Hotfix
Fix to diffuse transmission for overbrightening Several fixes to computebuffers to stop errors Fixed issue where diffuse would lose brightness as other lobes got included
1 parent 8fbc4eb commit 48efbe8

File tree

10 files changed

+32
-30
lines changed

10 files changed

+32
-30
lines changed

TrueTrace.unitypackage

-2.63 KB
Binary file not shown.

TrueTrace/Resources/AssetManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ public int UpdateTLAS(CommandBuffer cmd)
18701870
CurLightMesh.Center = LightTransforms[i].position;
18711871
LightMeshes[i] = CurLightMesh;
18721872
}
1873-
if (LightMeshBuffer != null && LightMeshCount != 0 && LightMeshCount == LightMeshBuffer.count) LightMeshBuffer.SetData(LightMeshes);
1873+
if (LightMeshBuffer != null && LightMeshBuffer.IsValid() && LightMeshCount != 0 && LightMeshCount == LightMeshBuffer.count) LightMeshBuffer.SetData(LightMeshes);
18741874
else {
18751875
CommonFunctions.CreateComputeBuffer(ref LightMeshBuffer, LightMeshes);
18761876
}

TrueTrace/Resources/Builders/CommonVars.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,9 @@ public static void CreateComputeBuffer<T>(ref ComputeBuffer buffer, List<T> data
894894
where T : struct
895895
{
896896
int stride = System.Runtime.InteropServices.Marshal.SizeOf<T>();
897+
Debug.Log("EEEEE");
897898
if (buffer != null) {
898-
if (data == null || data.Count == 0 || buffer.count != data.Count || buffer.stride != stride) {
899+
if (data == null || data.Count == 0 || !buffer.IsValid() || buffer.count != data.Count || buffer.stride != stride) {
899900
buffer.Release();
900901
buffer = null;
901902
}
@@ -911,9 +912,10 @@ public static void CreateComputeBuffer<T>(ref ComputeBuffer buffer, T[] data)
911912
where T : struct
912913
{
913914
int stride = System.Runtime.InteropServices.Marshal.SizeOf<T>();
915+
Debug.Log("EEEEE");
914916
if (buffer != null) {
915-
if (data == null || data.Length == 0 || buffer.count != data.Length || buffer.stride != stride) {
916-
buffer.ReleaseSafe();
917+
if (data == null || data.Length == 0 || !buffer.IsValid() || buffer.count != data.Length || buffer.stride != stride) {
918+
buffer.Release();
917919
buffer = null;
918920
}
919921
}

TrueTrace/Resources/GlobalDefines.cginc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#define AdvancedAlphaMapped
22
#define ExtraSampleValidation
33
#define IgnoreGlassShadow
4-
// #define IgnoreGlassMain
5-
// #define HDRP
6-
// #define HardwareRT
7-
// #define PointFiltering
4+
//#define IgnoreGlassMain
5+
//#define PointFiltering
86
#define StainedGlassShadows
9-
// #define DX11
10-
// #define LightMapping
11-
// #define IgnoreBackfacing
12-
// #define WhiteLights
7+
//#define LightMapping
8+
//#define IgnoreBackfacing
9+
//#define WhiteLights
1310
#define LBVH
1411
#define AccurateEmissionTex
15-
#define RadianceCache
16-
// #define RadianceDebug
17-
// #define IndirectRetraceWeighting
12+
//#define RadianceDebug
13+
#define IndirectRetraceWeighting
1814

15+
//#define HDRP
16+
//#define HardwareRT
17+
//#define DX11
18+
#define RadianceCache
1919

2020

2121
//Dont change the ones below
@@ -46,4 +46,4 @@
4646

4747
bool GetFlag(int FlagVar, int flag) {
4848
return (((int)FlagVar >> flag) & (int)1) == 1;
49-
}
49+
}

TrueTrace/Resources/MainCompute/Materials.cginc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static float3 SampleDisneyDiffuse(const MaterialData hitDat, float3 wo, bool thi
648648

649649
float diffuse = EvaluateDisneyDiffuse(hitDat, wo, wm, wi, thin);
650650
forwardPdfW = abs(dotNL) * pdf;
651-
return (sheen + color * (diffuse / pdf)) * extinction;
651+
return (sheen + color * (diffuse)) * extinction;
652652
}
653653

654654
static float3 SampleDisneyBRDF(const MaterialData hitDat, float3 wo, out float forwardPdfW, out float3 wi, uint pixel_index)
@@ -954,7 +954,7 @@ float3 ReconstructDisney(MaterialData hitDat, float3 wo, float3 wi, bool thin,
954954
break;
955955
case 2:
956956
if(P.z > 0) {
957-
reflectance = (EvaluateDisneyDiffuse(hitDat, wo, wm, wi, thin) * hitDat.surfaceColor + EvaluateSheen(hitDat, wo, wm, wi)) * P[2];
957+
reflectance = (EvaluateDisneyDiffuse(hitDat, wo, wm, wi, thin) * hitDat.surfaceColor + EvaluateSheen(hitDat, wo, wm, wi));
958958
forwardPdf = AbsCosTheta(wi);
959959
Success = forwardPdf > 0;
960960
}
@@ -1006,7 +1006,7 @@ bool SampleDisney(MaterialData hitDat, inout float3 v, bool thin, out float PDF,
10061006
break;
10071007
case 2:
10081008
hitDat.surfaceColor *= PI;
1009-
Reflection = SampleDisneyDiffuse(hitDat, v, thin, PDF, wi, Refracted, pixel_index) * P[2];
1009+
Reflection = SampleDisneyDiffuse(hitDat, v, thin, PDF, wi, Refracted, pixel_index);// * P[2];
10101010
break;
10111011
case 3:
10121012
Reflection = SampleDisneySpecTransmission(hitDat, v, thin, PDF, wi, Refracted, pixel_index, GotFlipped);

TrueTrace/Resources/MainCompute/RayTracingShader.compute

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
306306
#endif
307307
if(CurBounce > 0 && (CacheInstance.pathLength >> 5) & 0x1) {
308308
float3 res2 = 0;
309-
// if((hit.t >= CalcVoxelSize(ray.origin) * lerp(1.0f, 2.0f, random(64, pixel_index).x))) {
309+
if((hit.t >= CalcVoxelSize(ray.origin) * lerp(1.0f, 2.0f, random(64, pixel_index).x))) {
310310
if(RetrieveCacheRadiance(CacheInstance, ray.origin, norm, res2)) {
311311
Color.Indirect += Color.throughput * res2;
312312
}
313-
// }
313+
}
314314
CacheInstance.pathLength |= (1u << 6);
315315
} else if((!(MaterialLobe == 0 && hitDat.roughness < 0.05) && MaterialLobe != 3)) CacheInstance.pathLength |= (1u << 5);
316316

TrueTrace/Resources/RayTracingMaster.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private void SetBool(string Name, bool IN) {
476476
private void SetShaderParameters(CommandBuffer cmd)
477477
{
478478
if(RenderScale != 1.0f) _camera.renderingPath = RenderingPath.DeferredShading;
479-
_camera.depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;
479+
_camera.depthTextureMode |= DepthTextureMode.MotionVectors;
480480
if(UseReSTIRGI && UseASVGF && !ReSTIRASVGFCode.Initialized) ReSTIRASVGFCode.init(SourceWidth, SourceHeight);
481481
else if ((!UseASVGF || !UseReSTIRGI) && ReSTIRASVGFCode.Initialized) ReSTIRASVGFCode.ClearAll();
482482
if (!UseReSTIRGI && UseASVGF && !ASVGFCode.Initialized) ASVGFCode.init(SourceWidth, SourceHeight);
@@ -762,7 +762,7 @@ private void SetShaderParameters(CommandBuffer cmd)
762762

763763
private void ResetAllTextures() {
764764
// _camera.renderingPath = RenderingPath.DeferredShading;
765-
_camera.depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;
765+
_camera.depthTextureMode |= DepthTextureMode.MotionVectors;
766766
if(PrevResFactor != RenderScale || TargetWidth != _camera.scaledPixelWidth) {
767767
TargetWidth = _camera.scaledPixelWidth;
768768
TargetHeight = _camera.scaledPixelHeight;

TrueTrace/Resources/RenderPipelines/RenderHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void Start()
1313
if(GameObject.FindObjectsOfType<TrueTrace.RayTracingMaster>().Length == 0) {RayMaster = null; return;}
1414
RayMaster = GameObject.FindObjectsOfType<TrueTrace.RayTracingMaster>()[0];
1515
gameObject.GetComponent<Camera>().renderingPath = RenderingPath.DeferredShading;
16-
gameObject.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;
16+
gameObject.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.MotionVectors;
1717
RayMaster.TossCamera(gameObject.GetComponent<Camera>());
1818
RayMaster.Start2();
1919

TrueTrace/Resources/Utility/BVHRefitter.compute

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ void RefitLayer(uint3 id : SV_DispatchThreadID)
180180
if (id.x > NodeCount)
181181
return;
182182
id.x = WorkingBuffer[id.x];
183-
float3 RunningMax = AllNodes[id.x].BBMax;
184-
float3 RunningMin = AllNodes[id.x].BBMin;
183+
float3 RunningMax = -99999999.0f;//AllNodes[id.x].BBMax;
184+
float3 RunningMin = 99999999.0f;//AllNodes[id.x].BBMin;
185185
const Layer CurrentLayer = ReverseStack[id.x];
186186
int Stack[8];
187187
int stack_count = 0;
@@ -219,8 +219,8 @@ void RefitBVHLayer(uint3 id : SV_DispatchThreadID)
219219
if (id.x > NodeCount)
220220
return;
221221
id.x = WorkingBuffer[id.x];
222-
float3 RunningMax = AllNodes[id.x].BBMax;
223-
float3 RunningMin = AllNodes[id.x].BBMin;
222+
float3 RunningMax = -99999999.0f;//AllNodes[id.x].BBMax;
223+
float3 RunningMin = 99999999.0f;//AllNodes[id.x].BBMin;
224224
const Layer CurrentLayer = ReverseStack[id.x];
225225
int Stack[8];
226226
int stack_count = 0;

TrueTrace/Resources/Utility/MaterialMappings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5859,8 +5859,8 @@
58595859
</TexturePairs>
58605860
<TexturePairs>
58615861
<Purpose>1</Purpose>
5862-
<ReadIndex>0</ReadIndex>
5863-
<TextureName>_ClippingMask</TextureName>
5862+
<ReadIndex>3</ReadIndex>
5863+
<TextureName>_MainTex</TextureName>
58645864
</TexturePairs>
58655865
<TexturePairs>
58665866
<Purpose>6</Purpose>

0 commit comments

Comments
 (0)