diff --git a/Images/IESInstructions0.png b/Images/IESInstructions0.png
new file mode 100644
index 00000000..f28df918
Binary files /dev/null and b/Images/IESInstructions0.png differ
diff --git a/README.md b/README.md
index 912710fb..aaa7825b 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,8 @@ A passion projects that has been going on for a while with the goal of bringing
Enironment Map Importance Sampling
Radiance Cache
Material Preset System
-Prototype Panorama Rendering
+Panorama Rendering
+IES for spotlights
[Ylitie et al](https://research.nvidia.com/sites/default/files/publications/ylitie2017hpg-paper.pdf)
@@ -90,12 +91,11 @@ Camera Controls: WASD, Mouse, hold right click rotate the camera, and shift incr
## Creating Panoramas
- - Keep in mind this is a prototype and thus is not fully fleshed out yet
- - To set up, you need to have the game view resolution have a width that evenly divides 10,000(so 500, 1000, 2000, etc.), and a height of 5,000
- Attatch the "PanoramaDoer" script to the "Scene" gameobject in the hierarchy
- - Enter Play Mode like normal and click the panorama button in TrueTrace Settings
+ - Set your settings in the PanoramaDoer
+ - Enter Play Mode like normal and click the "Create Panorama" button in TrueTrace Settings
- The rest is automatic, from rendering, to stitching and will automatically exit play mode when finished
- - The final Panorama(10,000 by 5,000) will be put in Assets -> Screenshots, and the intermediate slices are in Assets -> TempPanorama
+ - The final Panorama will be put in Assets -> Screenshots, and the intermediate slices are in Assets -> TempPanorama
## Using Instancing
@@ -242,6 +242,12 @@ TrueTrace Options Description -
+## IES System
+
+ - Add the texture highlighted in the image below to the "IES Profile" slot in the raytracinglights component thats added to standard unity lights(directional, point, spot, etc. type lights)
+ - ![](/Images/IESInstructions0.png)
+
+
# Known Bugs:
diff --git a/TrueTrace.unitypackage b/TrueTrace.unitypackage
index c8b9bf2b..c2a5c67f 100644
Binary files a/TrueTrace.unitypackage and b/TrueTrace.unitypackage differ
diff --git a/TrueTrace/DemoScene.asset b/TrueTrace/DemoScene.asset
index 116503ff..2a2b2780 100644
--- a/TrueTrace/DemoScene.asset
+++ b/TrueTrace/DemoScene.asset
@@ -27,25 +27,25 @@ MonoBehaviour:
DoFAperatureScale: 0.54
DoFFocal: 4.8121676
PPExposure: 0
- ExposureAuto: 1
+ ExposureAuto: 0
PPToneMap: 0
PPTAA: 0
RenderScale: 1
- UseASVGF: 0
+ UseASVGF: 1
UseTAAU: 0
- ReSTIRGIUpdateRate: 0
+ ReSTIRGIUpdateRate: 7
UseReSTIRGITemporal: 1
UseReSTIRGISpatial: 1
- UseReSTIRGI: 0
+ UseReSTIRGI: 1
ReSTIRGISpatialCount: 24
ReSTIRGISpatialRadius: 50
ReSTIRGITemporalMCap: 4
DoReSTIRGIConnectionValidation: 1
- Exposure: 8.9
+ Exposure: 6.4
DoPartialRendering: 0
PartialRenderingFactor: 3
DoFirefly: 0
- ImprovedPrimaryHit: 0
+ ImprovedPrimaryHit: 1
RISCount: 12
ToneMapper: 0
SunDesaturate: 0
@@ -55,8 +55,8 @@ MonoBehaviour:
FireflyFrameCount: 533
FireflyStrength: 1
FireflyOffset: 0
- OIDNFrameCount: 122
- UseOIDN: 1
+ OIDNFrameCount: 322
+ UseOIDN: 0
DoSharpen: 0
Sharpness: 0
MainDesiredRes: 16384
@@ -65,5 +65,5 @@ MonoBehaviour:
BackgroundType: 0
BackgroundIntensity: 1
SceneBackgroundColor: {x: 0, y: 0, z: 0}
- SecondaryBackgroundType: 2
+ SecondaryBackgroundType: 0
SecondarySceneBackgroundColor: {x: 0, y: 0, z: 0}
diff --git a/TrueTrace/DemoScene.unity b/TrueTrace/DemoScene.unity
index 7b702d38..5d1494e9 100644
--- a/TrueTrace/DemoScene.unity
+++ b/TrueTrace/DemoScene.unity
@@ -6341,7 +6341,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c103227aee5e4584a96e35173641b818, type: 3}
m_Name:
m_EditorClassIdentifier:
- MaterialOptions: 00000000
+ MaterialOptions: 01000000
TransmissionColor:
- {x: 0, y: 0, z: 0}
BaseColor:
@@ -11639,8 +11639,11 @@ MonoBehaviour:
SpotAngle: {x: 0, y: 0}
ZAxisRotation: 0
Softness: 0
+ IESTex: {x: 0, y: 0}
ArrayIndex: 0
+ IESIndex: 0
ShadowSoftness: 0
+ IESProfile: {fileID: 0}
--- !u!108 &610660759
Light:
m_ObjectHideFlags: 0
@@ -11710,14 +11713,14 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 610660757}
- m_LocalRotation: {x: 0.45742938, y: 0.3890402, z: -0.20943713, w: 0.7717138}
- m_LocalPosition: {x: -3.9019775, y: 21.382568, z: -1.7173462}
+ m_LocalRotation: {x: 0.45743093, y: 0.38903746, z: -0.20943484, w: 0.77171487}
+ m_LocalPosition: {x: -3.231081, y: 5.3338814, z: 1.2922773}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
- m_LocalEulerAnglesHint: {x: 22.43, y: 179.944, z: 0}
+ m_LocalEulerAnglesHint: {x: 60.339, y: 55.708, z: 3.785}
--- !u!4 &611049998 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -4090820614514019212, guid: 16500a523b718314091d7e9b83146c62,
@@ -13349,7 +13352,7 @@ MonoBehaviour:
- 1
Contrast:
- 1
- FollowMaterial: 01
+ FollowMaterial: 00
ScatterDist:
- 0
SharedMaterials:
@@ -21173,7 +21176,7 @@ MonoBehaviour:
- 1
Contrast:
- 1
- FollowMaterial: 01
+ FollowMaterial: 00
ScatterDist:
- 0
SharedMaterials:
@@ -23340,43 +23343,6 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1770587712}
m_PrefabAsset: {fileID: 0}
---- !u!84 &1204680554
-RenderTexture:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_Name:
- m_ImageContentsHash:
- serializedVersion: 2
- Hash: 00000000000000000000000000000000
- m_ForcedFallbackFormat: 4
- m_DownscaleFallback: 0
- m_IsAlphaChannelOptional: 0
- serializedVersion: 5
- m_Width: 1
- m_Height: 1
- m_AntiAliasing: 1
- m_MipCount: -1
- m_DepthStencilFormat: 0
- m_ColorFormat: 4
- m_MipMap: 0
- m_GenerateMips: 1
- m_SRGB: 1
- m_UseDynamicScale: 0
- m_BindMS: 0
- m_EnableCompatibleFormat: 1
- m_TextureSettings:
- serializedVersion: 2
- m_FilterMode: 1
- m_Aniso: 1
- m_MipBias: 0
- m_WrapU: 1
- m_WrapV: 1
- m_WrapW: 1
- m_Dimension: 2
- m_VolumeDepth: 1
- m_ShadowSamplingMode: 2
--- !u!114 &1210713451
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -29876,13 +29842,6 @@ MonoBehaviour:
MultiScatterTex: {fileID: 0}
IrradianceTex: {fileID: 0}
Assets: {fileID: 0}
- Denoisers:
- Initialized: 0
- _TAAPrev: {fileID: 0}
- Intermediate: {fileID: 0}
- SuperIntermediate: {fileID: 0}
- BloomSamplesDown: []
- BloomIntermediate: {fileID: 0}
ShadingShader: {fileID: 0}
ScreenSpaceInfo: {fileID: 0}
_currentSample: 0
@@ -29891,6 +29850,7 @@ MonoBehaviour:
SampleCount: 0
PrevReSTIRGI: 0
DoPanorama: 1
+ DoChainedImages: 0
LocalTTSettings: {fileID: 11400000, guid: f713a0b44e81ebd429d4ffe701492e4b, type: 2}
SkyboxTexture: {fileID: 0}
AtmoNumLayers: 8
@@ -29909,6 +29869,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
TotalParentObjectSize: 0
LightEnergyScale: 1
+ IESAtlas: {fileID: 0}
AlbedoAtlas: {fileID: 0}
NormalAtlas: {fileID: 0}
SingleComponentAtlas: {fileID: 0}
@@ -29917,8 +29878,9 @@ MonoBehaviour:
HeightmapAtlas: {fileID: 0}
AlphaMapAtlas: {fileID: 0}
AlbedoAtlasSize: 0
+ IESAtlasSize: 0
VideoPlayerObject: {fileID: 0}
- VideoTexture: {fileID: 1204680554}
+ VideoTexture: {fileID: 1811650031}
MaterialsChanged: []
_Materials: []
MyMeshesCompacted: []
@@ -29979,7 +29941,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0c0a645c565400043a70a5ac2a4de0c1, type: 3}
m_Name:
m_EditorClassIdentifier:
- TimeBetweenSegments: 4
+ Cameras:
+ - {fileID: 2057202813}
+ TimeBetweenSegments: 5
+ MaxSamples: 300
+ FinalAtlasSize: {x: 10000, y: 5000}
+ HorizontalSegments: 10
--- !u!114 &1572504600
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -2153551,6 +2153518,43 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 2698434832336476688, guid: 16500a523b718314091d7e9b83146c62, type: 3}
+--- !u!84 &1811650031
+RenderTexture:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_Name:
+ m_ImageContentsHash:
+ serializedVersion: 2
+ Hash: 00000000000000000000000000000000
+ m_ForcedFallbackFormat: 4
+ m_DownscaleFallback: 0
+ m_IsAlphaChannelOptional: 0
+ serializedVersion: 5
+ m_Width: 1
+ m_Height: 1
+ m_AntiAliasing: 1
+ m_MipCount: -1
+ m_DepthStencilFormat: 0
+ m_ColorFormat: 4
+ m_MipMap: 0
+ m_GenerateMips: 1
+ m_SRGB: 1
+ m_UseDynamicScale: 0
+ m_BindMS: 0
+ m_EnableCompatibleFormat: 1
+ m_TextureSettings:
+ serializedVersion: 2
+ m_FilterMode: 1
+ m_Aniso: 1
+ m_MipBias: 0
+ m_WrapU: 1
+ m_WrapV: 1
+ m_WrapW: 1
+ m_Dimension: 2
+ m_VolumeDepth: 1
+ m_ShadowSamplingMode: 2
--- !u!4 &1814278736 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -6155464518912450076, guid: 16500a523b718314091d7e9b83146c62,
@@ -2160835,8 +2160839,8 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2057202810}
- m_LocalRotation: {x: -0.012630247, y: 0.7058897, z: 0.0051552355, w: 0.70819044}
- m_LocalPosition: {x: -1.2152853, y: 2.4668305, z: 0.50386786}
+ m_LocalRotation: {x: -0.09387351, y: 0.81802064, z: -0.13980192, w: -0.5499868}
+ m_LocalPosition: {x: 5.173573, y: 3.006142, z: 1.08526}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -2160850,7 +2160854,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2057202810}
- m_Enabled: 0
+ m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 25708ab1647d3af43927c5c250594658, type: 3}
m_Name:
diff --git a/TrueTrace/Editor/PathTracerSettings.cs b/TrueTrace/Editor/PathTracerSettings.cs
index 600c1708..3417a534 100644
--- a/TrueTrace/Editor/PathTracerSettings.cs
+++ b/TrueTrace/Editor/PathTracerSettings.cs
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
+using System;
using UnityEngine;
using UnityEditor;
using CommonVars;
@@ -1051,17 +1052,17 @@ void AddAssetsToMenu() {
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Base Texture"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Normal Texture"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Emission Texture"));
- OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Metallic Texture"));
+ OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Metallic Texture(Single Component)"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(float), Port.Capacity.Single, "Metallic Range"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(float), Port.Capacity.Single, "Metallic Min"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(float), Port.Capacity.Single, "Metallic Max"));
- OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Roughness Texture"));
+ OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Roughness Texture(Single Component)"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(float), Port.Capacity.Single, "Roughness Range"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(float), Port.Capacity.Single, "Roughness Min"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(float), Port.Capacity.Single, "Roughness Max"));
- OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Alpha Texture"));
+ OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "Alpha Texture(Single Component)"));
OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "MatCap Texture"));
- OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "MatCap Mask"));
+ OutputNode.inputContainer.Add(_graphView.GeneratePort(OutputNode, Direction.Input, typeof(Texture), Port.Capacity.Single, "MatCap Mask(Single Component)"));
_graphView.AddElement(OutputNode);
Vector2 Pos = new Vector2(30, 10);
@@ -1400,6 +1401,54 @@ private void TakeScreenshot() {
}
bool HasNoMore = false;
+
+void AddResolution(int width, int height, string label)
+ {
+ Type gameViewSize = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSize");
+ Type gameViewSizes = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes");
+ Type gameViewSizeType = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizeType");
+ Type generic = typeof(ScriptableSingleton<>).MakeGenericType(gameViewSizes);
+ MethodInfo getGroup = gameViewSizes.GetMethod("GetGroup");
+ object instance = generic.GetProperty("instance").GetValue(null, null);
+ object group = getGroup.Invoke(instance, new object[] { (int)GameViewSizeGroupType.Standalone });
+ Type[] types = new Type[] { gameViewSizeType, typeof(int), typeof(int), typeof(string)};
+ ConstructorInfo constructorInfo = gameViewSize.GetConstructor(types);
+ object entry = constructorInfo.Invoke(new object[] { 1, width, height, label });
+ MethodInfo addCustomSize = getGroup.ReturnType.GetMethod("AddCustomSize");
+ addCustomSize.Invoke(group, new object[] { entry });
+ }
+ void RemoveResolution(int index)
+ {
+ Type gameViewSizes = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes");
+ Type generic = typeof(ScriptableSingleton<>).MakeGenericType(gameViewSizes);
+ MethodInfo getGroup = gameViewSizes.GetMethod("GetGroup");
+ object instance = generic.GetProperty("instance").GetValue(null, null);
+ object group = getGroup.Invoke(instance, new object[] { (int)GameViewSizeGroupType.Standalone });
+ MethodInfo removeCustomSize = getGroup.ReturnType.GetMethod("RemoveCustomSize");
+ removeCustomSize.Invoke(group, new object[] { index });
+ }
+
+ int GetCount()
+ {
+ Type gameViewSizes = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes");
+ Type generic = typeof(ScriptableSingleton<>).MakeGenericType(gameViewSizes);
+ MethodInfo getGroup = gameViewSizes.GetMethod("GetGroup");
+ object instance = generic.GetProperty("instance").GetValue(null, null);
+ PropertyInfo currentGroupType = instance.GetType().GetProperty("currentGroupType");
+ GameViewSizeGroupType groupType = (GameViewSizeGroupType)(int)currentGroupType.GetValue(instance, null);
+ object group = getGroup.Invoke(instance, new object[] { (int)groupType });
+ MethodInfo getBuiltinCount = group.GetType().GetMethod("GetBuiltinCount");
+ MethodInfo getCustomCount = group.GetType().GetMethod("GetCustomCount");
+ return (int)getBuiltinCount.Invoke(group, null) + (int)getCustomCount.Invoke(group, null);
+ }
+
+ void SetResolution(int index)
+ {
+ Type gameView = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
+ PropertyInfo selectedSizeIndex = gameView.GetProperty("selectedSizeIndex", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ EditorWindow window = EditorWindow.GetWindow(gameView);
+ selectedSizeIndex.SetValue(window, index, null);
+ }
public void CreateGUI() {
HasNoMore = false;
if(!PlayerPrefs.HasKey("ScreenShotPath")) {
@@ -1513,19 +1562,37 @@ public void CreateGUI() {
Button PanoramaButton = new Button(() => {
var TempPan = GameObject.Find("Scene").GetComponent();
- if((10000.0f / (float)RayTracingMaster._camera.pixelWidth) != Mathf.Ceil(10000.0f / (float)RayTracingMaster._camera.pixelWidth)) {
- Debug.LogError("You need to set the resolution width to evenly divide 10,000(500, 1000, etc.), and the height to 5,000");
- } else {
+ // if(TempPan != null && ((float)TempPan.FinalAtlasSize.x / (float)RayTracingMaster._camera.pixelWidth) != Mathf.Ceil((float)TempPan.FinalAtlasSize.x / (float)RayTracingMaster._camera.pixelWidth)) {
+ // Debug.LogError("You need to set the resolution width to evenly divide the width (" + TempPan.FinalAtlasSize.x + "), and the height to " + TempPan.FinalAtlasSize.y);
+ // } else {
if(TempPan != null) {
+ AddResolution(Mathf.CeilToInt((float)TempPan.FinalAtlasSize.x / (float)TempPan.HorizontalSegments), TempPan.FinalAtlasSize.y, "TempPanoramaSize");
+ SetResolution(GetCount() - 1);
TempPan.Init();
RayMaster.DoPanorama = true;
+ RayMaster.DoChainedImages = true;
} else {
Debug.LogError("You need to add the PanoramaDoer to the Scene Gameobject");
}
- }
- }) {text = "Make Panorama"};
+ // }
+ }) {text = "Create Panorama"};
PanoramaButton.style.minWidth = 105;
+ Button ChainedImageButton = new Button(() => {
+ var TempPan = GameObject.Find("Scene").GetComponent();
+ if(TempPan != null) {
+ AddResolution(TempPan.FinalAtlasSize.x, TempPan.FinalAtlasSize.y, "TempPanoramaSize");
+ SetResolution(GetCount() - 1);
+ TempPan.HorizontalSegments = 1;
+ TempPan.Init();
+ RayMaster.DoPanorama = false;
+ RayMaster.DoChainedImages = true;
+ } else {
+ Debug.LogError("You need to add the PanoramaDoer to the Scene Gameobject");
+ }
+ }) {text = "Create Qued Screenshots"};
+ ChainedImageButton.style.minWidth = 105;
+
ClearButton = new Button(() => {
if(!Application.isPlaying) {
@@ -1560,6 +1627,7 @@ public void CreateGUI() {
ButtonField2.Add(ClearButton);
ButtonField2.Add(QuickStartButton);
ButtonField2.Add(ForceInstancesButton);
+ ButtonField2.Add(ChainedImageButton);
MainSource.Add(ButtonField2);
Box TopEnclosingBox = new Box();
diff --git a/TrueTrace/Resources/AssetManager.cs b/TrueTrace/Resources/AssetManager.cs
index e4350dea..4af0f4e0 100644
--- a/TrueTrace/Resources/AssetManager.cs
+++ b/TrueTrace/Resources/AssetManager.cs
@@ -20,7 +20,8 @@ public class AssetManager : MonoBehaviour
public int TotalParentObjectSize;
[HideInInspector] public float LightEnergyScale = 1.0f;
//emissive, alpha, metallic, roughness
- public Texture2D AlbedoAtlas;
+ [HideInInspector] public Texture2D IESAtlas;
+ [HideInInspector] public Texture2D AlbedoAtlas;
[HideInInspector] public Texture2D NormalAtlas;
[HideInInspector] public Texture2D SingleComponentAtlas;
[HideInInspector] public Texture2D EmissiveAtlas;
@@ -41,6 +42,7 @@ public class AssetManager : MonoBehaviour
[HideInInspector] public int AlbedoAtlasSize;
+ [HideInInspector] public int IESAtlasSize;
[HideInInspector] public VideoObject VideoPlayerObject;
[HideInInspector] public RenderTexture VideoTexture;
@@ -79,6 +81,7 @@ public void SetMeshTraceBuffers(ComputeShader ThisShader, int Kernel) {
ThisShader.SetComputeBuffer(Kernel, "_MeshData", MeshDataBuffer);
ThisShader.SetComputeBuffer(Kernel, "_Materials", MaterialBuffer);
ThisShader.SetTexture(Kernel, "_AlphaAtlas", AlphaAtlas);
+ ThisShader.SetTexture(Kernel, "_IESAtlas", IESAtlas);
ThisShader.SetTexture(Kernel, "_TextureAtlas", AlbedoAtlas);
#if HardwareRT
ThisShader.SetRayTracingAccelerationStructure(Kernel, "myAccelerationStructure", AccelStruct);
@@ -172,6 +175,7 @@ public void ClearAll()
CommonFunctions.DeepClean(ref MyMeshesCompacted);
CommonFunctions.DeepClean(ref UnityLights);
+ DestroyImmediate(IESAtlas);
DestroyImmediate(AlbedoAtlas);
DestroyImmediate(NormalAtlas);
DestroyImmediate(SingleComponentAtlas);
@@ -280,6 +284,15 @@ private void PackAndCompact(Dictionary DictTex, ref RenderTexture A
AlbedoAtlas = new Texture2D(DesiredRes,DesiredRes, TextureFormat.BC6H, false);
}
break;
+ case 8://IESMap
+ desc.graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.R32G32_SInt;
+ Atlas = new RenderTexture(desc);
+ IESAtlasSize = DesiredRes;
+ if(IESAtlas != null && IESAtlas.width != DesiredRes) {
+ DestroyImmediate(IESAtlas);
+ IESAtlas = new Texture2D(DesiredRes,DesiredRes, TextureFormat.BC4, 1, false);
+ }
+ break;
}
}
if(TexCount == 0) return;
@@ -312,6 +325,12 @@ private void PackAndCompact(Dictionary DictTex, ref RenderTexture A
else if(TempRect.TexType == 7) _Materials[SelectedTex.TexObjList[j]].MatCapTex = PackRect(RectSelect);
break;
case 7: _Materials[SelectedTex.TexObjList[j]].AlphaTex = PackRect(RectSelect); break;
+ case 8:
+ LightData TempLight = UnityLights[SelectedTex.TexObjList[j]];
+ TempLight.IESTex = PackRect(RectSelect);
+ RayTracingMaster._rayTracingLights[SelectedTex.TexObjList[j]].ThisLightData.IESTex = PackRect(RectSelect);
+ UnityLights[SelectedTex.TexObjList[j]] = TempLight;
+ break;
default: break;
}
}
@@ -333,6 +352,7 @@ private void PackAndCompact(Dictionary DictTex, ref RenderTexture A
case 3://metallic
case 4://roughness
case 7://alpha
+ case 8://IES
CopyShader.SetTexture(6, "SingleInput", SelectedTex.Tex);
CopyShader.SetTexture(6, "SingleOutput", Atlas);
CopyShader.Dispatch(6, (int)Mathf.CeilToInt(TempRect.Width * Scale.x / 4.0f), (int)Mathf.CeilToInt(TempRect.Height * Scale.y / 4.0f), 1);
@@ -394,6 +414,28 @@ private void KeyCheck(int MatIndex, Texture Tex, ref Dictionary Dic
DictTextures.Add(index, newTexObj);
}
}
+
+ private void CreateAtlasIES() {//Creates texture atlas
+ Dictionary IESMapTextures = new Dictionary();
+ List IESMapRect = new List();
+ if (CopyShader == null) CopyShader = Resources.Load("Utility/CopyTextureShader");
+ if(RenderQue.Count == 0) return;
+
+ int IESLightCount = 0;
+ foreach (RayTracingLights Obj in RayTracingMaster._rayTracingLights) {
+ if(Obj.ThisLight.type == LightType.Spot && Obj.IESProfile != null) KeyCheck(IESLightCount, Obj.IESProfile, ref IESMapTextures, ref IESMapRect, 0, 8);
+ IESLightCount++;
+ }
+ PackAndCompact(IESMapTextures, ref TempTex, IESMapRect.ToArray(), MainDesiredRes, 8);
+ Graphics.CopyTexture(TempTex, 0, IESAtlas, 0);
+ TempTex.Release();
+ TempTex = null;
+ IESMapTextures.Clear();
+ IESMapTextures.TrimExcess();
+ IESMapRect.TrimExcess();
+ IESMapRect.Clear();
+ }
+
private void CreateAtlas(int TotalMatCount) {//Creates texture atlas
TotalMatCount = 0;
foreach (ParentObject Obj in RenderQue) {
@@ -434,6 +476,7 @@ private void CreateAtlas(int TotalMatCount) {//Creates texture atlas
if(RenderQue.Count == 0) return;
int CurCount = RenderQue[0].AlbedoTexs.Count;
+
foreach (ParentObject Obj in RenderQue) {
foreach (RayTracingObject Obj2 in Obj.ChildObjects) {
Obj2.MatOffset = MatCount;
@@ -561,10 +604,10 @@ private void CreateAtlas(int TotalMatCount) {//Creates texture atlas
TempTex.Release();
TempTex = null;
+
PackAndCompact(HeightMapTextures, ref HeightmapAtlas, HeightMapRect.ToArray(), 16384, 0, 0);
PackAndCompact(AlphaMapTextures, ref AlphaMapAtlas, AlphaMapRect.ToArray(), 16384, 1);
-
AlbTextures.Clear();
AlbTextures.TrimExcess();
NormTextures.Clear();
@@ -707,6 +750,7 @@ private void init() {
AccelStruct = new UnityEngine.Rendering.RayTracingAccelerationStructure();
#endif
if(AlbedoAtlas == null) AlbedoAtlas = new Texture2D(4,4, TextureFormat.BC6H, false);
+ if(IESAtlas == null) IESAtlas = new Texture2D(4,4, TextureFormat.BC4, 1, false);
if(EmissiveAtlas == null) EmissiveAtlas = new Texture2D(4,4, TextureFormat.BC6H, false);
if(NormalAtlas == null) NormalAtlas = new Texture2D(4,4, TextureFormat.BC5, 1, false);
if(SingleComponentAtlas == null) SingleComponentAtlas = new Texture2D(4,4, TextureFormat.BC4, 1, false);
@@ -1591,8 +1635,6 @@ public int UpdateTLAS(CommandBuffer cmd)
bool LightsHaveUpdated = false;
AccumulateData(cmd);
-
- // UnityEngine.Profiling.Profiler.BeginSample("Lights Update");
if (!didstart || PrevLightCount != RayTracingMaster._rayTracingLights.Count || UnityLights.Count == 0)
{
UnityLights.Clear();
@@ -1609,6 +1651,7 @@ public int UpdateTLAS(CommandBuffer cmd)
if (PrevLightCount != RayTracingMaster._rayTracingLights.Count) LightsHaveUpdated = true;
PrevLightCount = RayTracingMaster._rayTracingLights.Count;
// UnityLightBuffer.ReleaseSafe();
+ CreateAtlasIES();
CommonFunctions.CreateComputeBuffer(ref UnityLightBuffer, UnityLights);
} else {
int LightCount = RayTracingMaster._rayTracingLights.Count;
@@ -1620,8 +1663,10 @@ public int UpdateTLAS(CommandBuffer cmd)
if (RayLight.ThisLightData.Type == 1) SunDirection = RayLight.ThisLightData.Direction;
UnityLights[RayLight.ArrayIndex] = RayLight.ThisLightData;
}
- UnityLightBuffer.SetData(UnityLights);
+ cmd.SetBufferData(UnityLightBuffer, UnityLights);
}
+
+ // UnityEngine.Profiling.Profiler.BeginSample("Lights Update");
// UnityEngine.Profiling.Profiler.EndSample();
int MatOffset = 0;
diff --git a/TrueTrace/Resources/Builders/CommonVars.cs b/TrueTrace/Resources/Builders/CommonVars.cs
index 0f3fcc34..1c61277e 100644
--- a/TrueTrace/Resources/Builders/CommonVars.cs
+++ b/TrueTrace/Resources/Builders/CommonVars.cs
@@ -16,6 +16,7 @@ public struct LightData
public Vector2 SpotAngle;
public float ZAxisRotation;
public float Softness;
+ public Vector2Int IESTex;
}
[System.Serializable]
@@ -860,6 +861,15 @@ public static void ReleaseSafe(this RenderTexture Tex)
{
if (Tex != null) Tex.Release();
}
+ public static void ReleaseSafe(this RenderTexture[] Tex)
+ {
+ if (Tex != null) {
+ int TexLength = Tex.Length;
+ for(int i = 0; i < TexLength; i++) {
+ if(Tex[i] != null) Tex[i].Release();
+ }
+ }
+ }
public static void ReleaseSafe(this ComputeBuffer Buff)
{
if (Buff != null) {Buff.Release(); Buff = null;}
@@ -914,6 +924,26 @@ public static void CreateRenderTexture(ref RenderTexture ThisTex,
ThisTex.Create();
}
+ public static void CreateRenderTextureArray2(ref RenderTexture[] ThisTex,
+ int Width, int Height, int Depth,
+ RenderTextureFormat Form,
+ RenderTextureReadWrite RendRead = RenderTextureReadWrite.Linear,
+ bool UseMip = false) {
+ ThisTex = new RenderTexture[2];
+ for(int i = 0; i < Depth; i++) {
+ if(ThisTex[i] != null) ThisTex[i]?.Release();
+ ThisTex[i] = new RenderTexture(Width, Height, 0,
+ Form, RendRead);
+ if (UseMip) {
+ ThisTex[i].useMipMap = true;
+ ThisTex[i].autoGenerateMips = false;
+ }
+ ThisTex[i].enableRandomWrite = true;
+ ThisTex[i].Create();
+ }
+ }
+
+
public static void CreateRenderTexture3D(ref RenderTexture ThisTex,
int Width, int Height, int Depth,
RenderTextureFormat Form,
diff --git a/TrueTrace/Resources/GlobalDefines.cginc b/TrueTrace/Resources/GlobalDefines.cginc
index 3501fb10..33f0a632 100644
--- a/TrueTrace/Resources/GlobalDefines.cginc
+++ b/TrueTrace/Resources/GlobalDefines.cginc
@@ -1,11 +1,11 @@
#define AdvancedAlphaMapped
#define ExtraSampleValidation
-// #define IgnoreGlassShadow
+#define IgnoreGlassShadow
// #define IgnoreGlassMain
// #define HDRP
// #define HardwareRT
// #define PointFiltering
-// #define StainedGlassShadows
+#define StainedGlassShadows
// #define DX11
// #define LightMapping
// #define IgnoreBackfacing
@@ -15,6 +15,7 @@
#define AccurateEmissionTex
#define RadianceCache
// #define ImprovedRadCacheSpecularResponse
+// #define HighSpeedRadCache
// #define RadianceDebug
#define IndirectRetraceWeighting
diff --git a/TrueTrace/Resources/MainCompute/CommonData.cginc b/TrueTrace/Resources/MainCompute/CommonData.cginc
index c4e6f355..3e9b9a88 100644
--- a/TrueTrace/Resources/MainCompute/CommonData.cginc
+++ b/TrueTrace/Resources/MainCompute/CommonData.cginc
@@ -112,7 +112,7 @@ StructuredBuffer Exposure;
struct ShadowRayData {
float3 origin;
- float LuminanceIncomming;
+ uint DiffuseIlluminance;
float3 direction;
float t;
float3 illumination;
@@ -266,6 +266,7 @@ SamplerState sampler_TextureAtlas;
Texture2D _NormalAtlas;
SamplerState sampler_NormalAtlas;
Texture2D _EmissiveAtlas;
+Texture2D _IESAtlas;
Texture2D Heightmap;
@@ -315,6 +316,8 @@ struct LightData {
float2 SpotAngle;
float ZAxisRotation;
float Softness;
+ int2 IESTex;//16
+
};
StructuredBuffer _UnityLights;
@@ -571,7 +574,7 @@ inline SmallerRay CreateCameraRayPrev(float2 uv) {
return CreateRay(origin, direction);
}
-inline float2 AlignUV(float2 BaseUV, const float4 TexScale, const int2 TexDim2, float Rotation = 0, bool IsAlbedo = false) {
+inline float2 AlignUV(float2 BaseUV, float4 TexScale, int2 TexDim2, float Rotation = 0) {
if(TexDim2.x <= 0) return -1;
float4 TexDim;
TexDim.xy = float2((float)(((uint)TexDim2.x) & 0x7FFF) / 16384.0f, (float)(((uint)TexDim2.x >> 15)) / 16384.0f);
@@ -589,10 +592,7 @@ inline float2 AlignUV(float2 BaseUV, const float4 TexScale, const int2 TexDim2,
BaseUV += 0.5f;
BaseUV = fmod(abs(BaseUV), 1.0f);
}
- // TexDim.zw += 1.0f / (float)AlbedoAtlasSize;
- // TexDim.xy -= 1.0f / (float)AlbedoAtlasSize;
- if(IsAlbedo) return clamp(BaseUV * (TexDim.xy - TexDim.zw) + TexDim.zw, TexDim.zw + 1.0f / (float)AlbedoAtlasSize, TexDim.xy - 1.0f / (float)AlbedoAtlasSize);
- else return clamp(BaseUV * (TexDim.xy - TexDim.zw) + TexDim.zw, TexDim.zw + 1.0f / 16384.0f, TexDim.xy - 1.0f / 16384.0f);
+ return clamp(BaseUV * (TexDim.xy - TexDim.zw) + TexDim.zw, TexDim.zw + 1.0f / 16384.0f, TexDim.xy - 1.0f / 16384.0f);
}
inline bool triangle_intersect_shadow(int tri_id, const SmallerRay ray, float max_distance, int mesh_id, inout float3 throughput, const int MatOffset) {
diff --git a/TrueTrace/Resources/MainCompute/IntersectionKernels.compute b/TrueTrace/Resources/MainCompute/IntersectionKernels.compute
index 907b7579..dc1daefb 100644
--- a/TrueTrace/Resources/MainCompute/IntersectionKernels.compute
+++ b/TrueTrace/Resources/MainCompute/IntersectionKernels.compute
@@ -35,7 +35,7 @@ inline void IntersectTriangle(int mesh_id, const int tri_id, const SmallerRay ra
#ifdef AdvancedAlphaMapped
if(_Materials[MaterialIndex].MatType == CutoutIndex) {
float2 BaseUv = tri2.pos0 * (1.0f - u - v) + tri2.posedge1 * u + tri2.posedge2 * v;
- float2 Uv = AlignUV(BaseUv, _Materials[MaterialIndex].AlbedoTexScale, _Materials[MaterialIndex].AlphaTex, _Materials[MaterialIndex].Rotation, true);
+ float2 Uv = AlignUV(BaseUv, _Materials[MaterialIndex].AlbedoTexScale, _Materials[MaterialIndex].AlphaTex, _Materials[MaterialIndex].Rotation);
#ifdef PointFiltering
if(Uv.x != -1 && _AlphaAtlas.SampleLevel(my_point_clamp_sampler, Uv, 0) < _Materials[MaterialIndex].AlphaCutoff) return;
#else
@@ -318,7 +318,7 @@ void IntersectBVHShadow() {
uint PixelIndex = ShadowRaysBuffer[ray_index].PixelIndex;
if(CurBounce == 0) NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)] = float4(ray.origin + ray.direction * abs(ShadowRaysBuffer[ray_index].t),NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)].w);
#ifdef RadianceCache
- CacheBuffer[PixelIndex].CurrentIlluminance = EncodeRGB(DecodeRGB(CacheBuffer[PixelIndex].CurrentIlluminance) + ShadowRaysBuffer[ray_index].illumination * ((!UseReSTIRGI || ShadowRaysBuffer[ray_index].t >= 0) ? 1 : unpackRGBE(asuint(ShadowRaysBuffer[ray_index].LuminanceIncomming))));
+ CacheBuffer[PixelIndex].CurrentIlluminance = EncodeRGB(DecodeRGB(CacheBuffer[PixelIndex].CurrentIlluminance) + unpackRGBE(ShadowRaysBuffer[ray_index].DiffuseIlluminance));
#endif
if (ShadowRaysBuffer[ray_index].t >= 0) {
if (CurBounce == 0) {
@@ -331,9 +331,9 @@ void IntersectBVHShadow() {
}
} else {
#ifdef RadianceCache
- if(CurBounce != 0 && (UseReSTIRGI || GlobalColors[PixelIndex].Data.w == CurBounce)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination * (UseReSTIRGI ? unpackRGBE(asuint(ShadowRay.LuminanceIncomming)) : 1);
+ if(CurBounce != 0 && (UseReSTIRGI || GlobalColors[PixelIndex].Data.w == CurBounce)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination;
#else
- if(CurBounce != 0 && (!UseReSTIRGI && GlobalColors[PixelIndex].Data.w == -1)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination;// * unpackRGBE(asuint(ShadowRay.LuminanceIncomming));
+ if(CurBounce != 0 && (!UseReSTIRGI && GlobalColors[PixelIndex].Data.w == -1)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination;// * unpackRGBE(asuint(ShadowRay.DiffuseIlluminance));
#endif
else GlobalColors[PixelIndex].PrimaryNEERay = packRGBE(pow(unpackRGBE(GlobalColors[PixelIndex].PrimaryNEERay),2.2f) + pow(ShadowRay.illumination,rcp(2.2f)));
}
@@ -439,9 +439,9 @@ void IntersectBVHShadow() {
if(!TerrainExists) {
uint PixelIndex = ShadowRay.PixelIndex;
if(CurBounce == 0) NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)] = float4(ray2.origin + ray2.direction * abs(ShadowRaysBuffer[ray_index].t), 0);
- // if(UseReSTIRGI && ReSTIRGIUpdateRate != 0) NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)] += float4(0,0,0,ShadowRay.LuminanceIncomming);
+ // if(UseReSTIRGI && ReSTIRGIUpdateRate != 0) NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)] += float4(0,0,0,ShadowRay.DiffuseIlluminance);
#ifdef RadianceCache
- CacheBuffer[PixelIndex].CurrentIlluminance = EncodeRGB(DecodeRGB(CacheBuffer[PixelIndex].CurrentIlluminance) + ShadowRay.illumination * throughput * ((!UseReSTIRGI || ShadowRay.t >= 0) ? 1 : unpackRGBE(asuint(ShadowRay.LuminanceIncomming))));// * abs(dot(i_octahedral_32(CacheBuffer[PixelIndex].Norm), ShadowRay.direction));
+ CacheBuffer[PixelIndex].CurrentIlluminance = EncodeRGB(DecodeRGB(CacheBuffer[PixelIndex].CurrentIlluminance) + unpackRGBE(ShadowRay.DiffuseIlluminance) * throughput);// * abs(dot(i_octahedral_32(CacheBuffer[PixelIndex].Norm), ShadowRay.direction));
#endif
if (ShadowRay.t >= 0) {
@@ -454,14 +454,15 @@ void IntersectBVHShadow() {
}
} else {
#ifdef RadianceCache
- if(CurBounce != 0 && (UseReSTIRGI || GlobalColors[PixelIndex].Data.w == CurBounce)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination * throughput * (UseReSTIRGI ? unpackRGBE(asuint(ShadowRay.LuminanceIncomming)) : 1);
+ if(CurBounce != 0 && (UseReSTIRGI || GlobalColors[PixelIndex].Data.w == CurBounce)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination * throughput;
#else
- if(CurBounce != 0 && (!UseReSTIRGI && GlobalColors[PixelIndex].Data.w == -1)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination * throughput;// * unpackRGBE(asuint(ShadowRay.LuminanceIncomming));
+ if(CurBounce != 0 && (!UseReSTIRGI && GlobalColors[PixelIndex].Data.w == -1)) GlobalColors[PixelIndex].Indirect += ShadowRay.illumination * throughput;// * unpackRGBE(asuint(ShadowRay.DiffuseIlluminance));
#endif
else GlobalColors[PixelIndex].PrimaryNEERay = packRGBE(pow(unpackRGBE(GlobalColors[PixelIndex].PrimaryNEERay),2.2f) + pow(ShadowRay.illumination,rcp(2.2f)) * throughput);
}
} else {
ShadowRaysBuffer[ray_index].illumination *= throughput;
+ ShadowRaysBuffer[ray_index].DiffuseIlluminance = packRGBE(unpackRGBE(ShadowRaysBuffer[ray_index].DiffuseIlluminance) * throughput);
}
break;
}
@@ -554,9 +555,9 @@ void IntersectShadowHeightmap() {
if(!HitHeightmap) {
uint PixelIndex = ShadowRaysBuffer[ray_index].PixelIndex;
if(CurBounce == 0) NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)] = float4(ray.origin + ray.direction * abs(ShadowRaysBuffer[ray_index].t), 0);
- // if(UseReSTIRGI && ReSTIRGIUpdateRate != 0) NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)] += float4(0,0,0,ShadowRay.LuminanceIncomming);
+ // if(UseReSTIRGI && ReSTIRGIUpdateRate != 0) NEEPosA[uint2(PixelIndex % screen_width, PixelIndex / screen_width)] += float4(0,0,0,ShadowRay.DiffuseIlluminance);
#ifdef RadianceCache
- CacheBuffer[PixelIndex].CurrentIlluminance = EncodeRGB(DecodeRGB(CacheBuffer[PixelIndex].CurrentIlluminance) + ShadowRaysBuffer[ray_index].illumination * ((!UseReSTIRGI || ShadowRaysBuffer[ray_index].t >= 0) ? 1 : unpackRGBE(asuint(ShadowRaysBuffer[ray_index].LuminanceIncomming))));// * abs(dot(i_octahedral_32(CacheBuffer[PixelIndex].Norm), ShadowRay.direction));
+ CacheBuffer[PixelIndex].CurrentIlluminance = EncodeRGB(DecodeRGB(CacheBuffer[PixelIndex].CurrentIlluminance) + unpackRGBE(ShadowRaysBuffer[ray_index].DiffuseIlluminance));// * abs(dot(i_octahedral_32(CacheBuffer[PixelIndex].Norm), ShadowRay.direction));
#endif
if (ShadowRaysBuffer[ray_index].t >= 0) {
@@ -568,7 +569,7 @@ void IntersectShadowHeightmap() {
#endif
}
} else {
- if(CurBounce != 0 && UseReSTIRGI) GlobalColors[PixelIndex].Indirect += ShadowRaysBuffer[ray_index].illumination;// * unpackRGBE(asuint(ShadowRay.LuminanceIncomming));
+ if(CurBounce != 0 && UseReSTIRGI) GlobalColors[PixelIndex].Indirect += ShadowRaysBuffer[ray_index].illumination;// * unpackRGBE(asuint(ShadowRay.DiffuseIlluminance));
else GlobalColors[PixelIndex].PrimaryNEERay = packRGBE(pow(unpackRGBE(GlobalColors[PixelIndex].PrimaryNEERay),2.2f) + pow(ShadowRaysBuffer[ray_index].illumination,rcp(2.2f)));
}
}
diff --git a/TrueTrace/Resources/MainCompute/Materials.cginc b/TrueTrace/Resources/MainCompute/Materials.cginc
index a30e6be3..a9a66cb7 100644
--- a/TrueTrace/Resources/MainCompute/Materials.cginc
+++ b/TrueTrace/Resources/MainCompute/Materials.cginc
@@ -960,7 +960,7 @@ float3 ReconstructDisney(MaterialData hitDat, float3 wo, float3 wi, bool thin,
Success = Success || true;
}
} else {
- reflectance = saturate(reflectance / P[Case]);
+ reflectance = (reflectance / P[Case]);
forwardPdf *= P[Case];
}
@@ -1025,3 +1025,50 @@ inline bool ReconstructBsdf(const MaterialData hitDat, float3 DirectionIn, float
bsdf_value = ReconstructDisney(hitDat, -DirectionIn, DirectionOut, GetFlag(hitDat.Tag, Thin), PDF, TangentSpaceNorm, validbsdf, pixel_index, Case);
return validbsdf;
}
+
+float3 EvaluateDisney2(MaterialData hitDat, float3 V, float3 L, bool thin,
+ inout float forwardPdf, float3x3 TruTan, uint pixel_index)
+{
+ float3 wo = ToLocal(TruTan, V); // NDotL = L.z; NDotV = V.z; NDotH = H.z
+ float3 wi = ToLocal(TruTan, L); // NDotL = L.z; NDotV = V.z; NDotH = H.z
+
+ float3 wm = normalize(wo + wi);
+
+ float dotNV = CosTheta(wo);
+ float dotNL = CosTheta(wi);
+
+ float3 reflectance = 0;
+ forwardPdf = 0.0f;
+
+ float4 P = CalculateLobePdfs(hitDat);
+
+ float metallic = hitDat.metallic;
+ float specTrans = hitDat.specTrans;
+
+ float diffuseWeight = (1.0f - metallic) * (1.0f - specTrans);
+ float transWeight = (1.0f - metallic) * specTrans;
+
+
+ // -- Diffuse
+ if (diffuseWeight > 0.0f) {
+ float forwardDiffusePdfW = AbsCosTheta(wi);
+ float diffuse = EvaluateDisneyDiffuse(hitDat, wo, wm, wi, thin);
+ float3 sheen = EvaluateSheen(hitDat, wo, wm, wi);
+
+ reflectance += (diffuse * hitDat.surfaceColor + sheen / PI) * P[2];
+
+ forwardPdf += forwardDiffusePdfW * P[2];
+ }
+
+
+ reflectance = reflectance * abs(dotNL);
+
+ return reflectance;
+}
+
+inline bool EvaluateBsdf2(const MaterialData hitDat, float3 DirectionIn, float3 DirectionOut, float3 Normal, inout float PDF, inout float3 bsdf_value, uint pixel_index) {
+ bool validbsdf = false;
+ bsdf_value = EvaluateDisney2(hitDat, -DirectionIn, DirectionOut, GetFlag(hitDat.Tag, Thin), PDF, GetTangentSpace(Normal), pixel_index);// DisneyEval(mat, -PrevDirection, norm, to_light, bsdf_pdf, hitDat);
+ validbsdf = PDF > 0;
+ return validbsdf;
+}
diff --git a/TrueTrace/Resources/MainCompute/RayGenKernels.compute b/TrueTrace/Resources/MainCompute/RayGenKernels.compute
index 15554356..7ab5c444 100644
--- a/TrueTrace/Resources/MainCompute/RayGenKernels.compute
+++ b/TrueTrace/Resources/MainCompute/RayGenKernels.compute
@@ -47,6 +47,7 @@ void Generate(uint3 id : SV_DispatchThreadID) {
CacheBuffer[pixel_index].pathLength = 0;
CacheBuffer[pixel_index].CurrentIlluminance = 0;
CacheBuffer[pixel_index].throughput = EncodeRGB(float3(1,1,1));
+ CacheBuffer[pixel_index].samples[0].x = EncodeRGB(1);
#endif
SmallerRay ray = CreateCameraRay(uv, pixel_index);
RayData globray = {ray.origin + NearPlane * ray.direction, pixel_index, ray.direction, 0, 0,0,asuint(FarPlane),0};
@@ -88,7 +89,7 @@ void GIReTraceKernel(uint3 id : SV_DispatchThreadID, uint3 id2 : SV_GroupThreadI
GlobalColors[pixel_index] = InitCol;
}
-
+bool DoPanorama;
float2 Segment;
#pragma kernel GeneratePanorama
[numthreads(16, 16, 1)]
@@ -96,17 +97,27 @@ void GeneratePanorama(uint3 id : SV_DispatchThreadID) {
if (id.x >= screen_width || id.y >= screen_height) return;
const uint pixel_index = id.y * screen_width + id.x;
float2 jitter = ((random(0, pixel_index) - 0.5));
- float2 uv = float2((id.xy) / float2(screen_width, screen_height) * 2.0f - 1.0f);
+ float2 uv = float2((id.xy) / float2(screen_width, screen_height));
#ifdef RadianceCache
CacheBuffer[pixel_index].pathLength = 0;
CacheBuffer[pixel_index].CurrentIlluminance = 0;
CacheBuffer[pixel_index].throughput = EncodeRGB(float3(1,1,1));
#endif
- uv = (uv + 1.0f) * 0.5f;
- uv.y = 1.0f - uv.y;
- uv.x = (uv.x * (Segment.y - Segment.x)) + Segment.x;
-
- RayData globray = {mul(CamToWorld, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz + NearPlane * normalize(equirectUvToDirection(uv)), pixel_index, normalize(equirectUvToDirection(uv)), 0, 0,0,asuint(FarPlane),0};
+ SmallerRay ray;
+ if(DoPanorama) {
+ uv.y = 1.0f - uv.y;
+ uv.x = (uv.x * (Segment.y - Segment.x)) + Segment.x;
+ uv.x = 1.0f - uv.x;
+
+ ray = CreateRay(mul(CamToWorld, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz + NearPlane * normalize(equirectUvToDirection(uv)), normalize(equirectUvToDirection(uv)));
+ } else {
+ uv.x = ((uv.x * (Segment.y - Segment.x)) + Segment.x);
+ uv = (uv * 2.0f) - 1.0f;
+
+ ray = CreateCameraRay(uv, pixel_index);
+ ray.origin = ray.origin + NearPlane * ray.direction;
+ }
+ RayData globray = {ray.origin, pixel_index, ray.direction, 0, 0,0,asuint(FarPlane),0};
GlobalRays[pixel_index] = globray;
GlobalColors[pixel_index] = InitCol;
}
diff --git a/TrueTrace/Resources/MainCompute/RayTracingShader.compute b/TrueTrace/Resources/MainCompute/RayTracingShader.compute
index 8d4df315..c99a733c 100644
--- a/TrueTrace/Resources/MainCompute/RayTracingShader.compute
+++ b/TrueTrace/Resources/MainCompute/RayTracingShader.compute
@@ -117,15 +117,15 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
float2 matcapUV = float2(dot(worldViewRight, norm), dot(worldViewUp, norm)) * 0.5f + 0.5;
- float2 MatCapUV = AlignUV(matcapUV, hitDat.AlbedoTexScale, hitDat.MatCapTex, hitDat.Rotation, true);
+ float2 MatCapUV = AlignUV(matcapUV, hitDat.AlbedoTexScale, hitDat.MatCapTex, hitDat.Rotation);
float4 matcap = _TextureAtlas.SampleLevel(my_linear_clamp_sampler, MatCapUV, 0);
- float2 MatCapMaskUV = AlignUV(BaseUv, hitDat.AlbedoTexScale, hitDat.MatCapMask, hitDat.Rotation, true);
+ float2 MatCapMaskUV = AlignUV(BaseUv, hitDat.AlbedoTexScale, hitDat.MatCapMask, hitDat.Rotation);
if(MatCapMaskUV.x != -1) {
hitDat.surfaceColor = lerp(hitDat.surfaceColor, matcap.xyz, SingleComponentAtlas.SampleLevel(my_linear_clamp_sampler, MatCapMaskUV, 0).x);
}
}
}
-
+
[branch] if (hitDat.emmissive > 0.0f) {//if we hit a light, this ray is done
#ifdef WhiteLights
@@ -139,8 +139,8 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
#else
else {
CacheInstance.CurrentIlluminance = EncodeRGB(DecodeRGB(CacheInstance.CurrentIlluminance) + EmissCol);
- if(!((CacheInstance.pathLength >> 5) & 0x1))
- Color.Indirect += Color.throughput * EmissCol;
+ // if(!((CacheInstance.pathLength >> 5) & 0x1))
+ // Color.Indirect += Color.throughput * EmissCol;
}
#endif
} else {
@@ -166,8 +166,8 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
#else
else {
CacheInstance.CurrentIlluminance = EncodeRGB(DecodeRGB(CacheInstance.CurrentIlluminance) + EmissCol * w);
- if(!((CacheInstance.pathLength >> 5) & 0x1))
- Color.Indirect += Color.throughput * EmissCol * w;
+ // if(!((CacheInstance.pathLength >> 5) & 0x1))
+ // Color.Indirect += Color.throughput * EmissCol * w;
}
#endif
}
@@ -175,13 +175,13 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
#ifdef RadianceCache
if(!UseReSTIRGI || ReSTIRGIUpdateRate == 0 || RandomNums[id.xy].z == 0) {
// if(hit.t >= CalcVoxelSize(pos)) {
- if(CurBounce == 0 || UseRussianRoulette) {
- CacheInstance.Norm = octahedral_32(norm);
- if(!AddHitToCache(CacheInstance, pos, random(324, pixel_index).x)) return;
- } else {
- CacheInstance.CurrentIlluminance = EncodeRGB(DecodeRGB(CacheInstance.CurrentIlluminance) * Color.throughput);
+ // if(CurBounce == 0 || UseRussianRoulette) {
+ // CacheInstance.Norm = octahedral_32(norm);
+ // if(!AddHitToCache(CacheInstance, pos, random(324, pixel_index).x)) return;
+ // } else {
+ // CacheInstance.CurrentIlluminance = EncodeRGB(DecodeRGB(CacheInstance.CurrentIlluminance) * Color.throughput);
if(!AddHitToCache(CacheInstance, PrevOrigin, random(324, pixel_index).x)) return;
- }
+ // }
CacheInstance.CurrentIlluminance = 0;
// }
}
@@ -192,7 +192,6 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
}
}
-
[branch]if(ClayMode) {
hitDat.surfaceColor = ClayColor;
hitDat.metallic = 0;
@@ -244,23 +243,32 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
[branch] if (CurBounce == 0 || Color.Data.w == -1) {//Setting textures for denosier to use
Color.Flags = packRGBE((CurBounce == 0) ? max(hitDat.surfaceColor, 0.005f) : (unpackRGBE(Color.Flags) * max(hitDat.surfaceColor, 0.005f)));
- PrevScreenData = float4(asfloat(octahedral_32((CurBounce == 0 && Refracted) ? -Geomnorm : Geomnorm)), asfloat(octahedral_32((CurBounce == 0 && Refracted) ? -norm : norm)),PrevScreenData.z + hit.t, asfloat(((uint)(MaterialIndex << 2) >> 2) | ((CurBounce != 0 ? ((asuint(PrevScreenData.w) << 1) >> 30) : (uint)MaterialLobe) << 29) | (Refracted << 31)));
+ PrevScreenData = float4(asfloat(octahedral_32((CurBounce == 0 && Refracted) ? -Geomnorm : Geomnorm)), asfloat(octahedral_32((CurBounce == 0 && Refracted) ? -norm : norm)),PrevScreenData.z + hit.t, asfloat((CurBounce == 0 ? ((uint)(MaterialIndex << 2) >> 2) : ((asuint(PrevScreenData.w) << 3) >> 3)) | ((CurBounce != 0 ? ((asuint(PrevScreenData.w) << 1) >> 30) : (uint)MaterialLobe) << 29) | (Refracted << 31)));
Color.MetRoughIsSpec |= (Refracted << 31);
- Color.Data = float4(((CurBounce == 0) ? max(throughput, 0.005f) : (max(throughput, 0.005f) * Color.Data.xyz)), (UseASVGF && ((MaterialLobe == 3 && hitDat.roughness < 0.25f) || (hitDat.metallic == 1 && MaterialLobe == 0 && hitDat.roughness < 0.01f && CurBounce == 0))) ? -1 : (CurBounce + 1));
+ Color.Data = float4(((CurBounce == 0) ? max(throughput, 0.006f) : (max(throughput, 0.005f) * Color.Data.xyz)), (UseASVGF && ((MaterialLobe == 3 && hitDat.roughness < 0.25f) || (hitDat.metallic == 1 && MaterialLobe == 0 && hitDat.roughness < 0.01f && CurBounce == 0))) ? -1 : (CurBounce + 1));
throughput = 1;
}
#ifdef RadianceCache
- CacheInstance.samples[0].x = CacheInstance.throughput;
#ifdef RadianceDebug
if(CurBounce == 0) _DebugTex[id.xy] = float4(ray.origin, asfloat(octahedral_32(norm)));
#endif
if(CurBounce > 0 && (CacheInstance.pathLength >> 5) & 0x1) {
float3 res2 = 0;
- if((hit.t >= CalcVoxelSize(ray.origin) * lerp(1.0f, 2.0f, random(324, pixel_index).x))) {
+ if((all(Color.Indirect == 0) || CurBounce < 3) && (hit.t >= CalcVoxelSize(ray.origin) * lerp(1.0f, 2.0f, random(326, pixel_index).x))) {
if(RetrieveCacheRadiance(CacheInstance, ray.origin, norm, res2)) {
// CacheInstance.CurrentIlluminance = EncodeRGB(DecodeRGB(CacheInstance.CurrentIlluminance) + Color.Data * throughput * res2);//fabled "infinite bounce" - VERY hard to weight properly
Color.Indirect += Color.throughput * res2;
+ #ifdef HighSpeedRadCache
+ if(!all(Color.Indirect == 0)) {
+ if(!((int(id.x)/2 + int(id.y)/2 + curframe)%7==0)) return;
+ else throughput *= 7;
+ }
+ #endif
}
+ } else {
+ #ifdef HighSpeedRadCache
+ if(!((int(id.x)/2 + int(id.y)/2 + curframe)%7==0)) return;
+ #endif
}
CacheInstance.pathLength |= (1u << 6);
} else if((!(MaterialLobe == 0 && hitDat.roughness < 0.05) && MaterialLobe != 3)) CacheInstance.pathLength |= (1u << 5);
@@ -295,7 +303,8 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
SelectedLightGroup = selections[min(floor(random(114, pixel_index).x * (float)selectionoptions), selectionoptions - 1)];
if (SelectedLightGroup == 1) {
- LightData Light = _UnityLights[SelectUnityLight(pixel_index, RunningWeight, norm, pos, PrevDirection)];
+ AggTriIndex = SelectUnityLight(pixel_index, RunningWeight, norm, pos, PrevDirection);
+ LightData Light = _UnityLights[AggTriIndex];
float sinPhi, cosPhi;
LightPosition = Light.Position;
LightNorm = Light.Direction;
@@ -373,15 +382,33 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
float distance_to_light = sqrt(max(distance_to_light_squared, 0.0f));
to_light = to_light / distance_to_light;
+
+ if(LightFormat == SPOTLIGHT) {
+ float3 LocalLight = ToLocal(GetTangentSpace(LightNorm), -to_light) + 0.5f;
+ float2 AlignedUV = AlignUV(LocalLight.xz, float4(1,1,0,0), _UnityLights[AggTriIndex].IESTex);
+ if(AlignedUV.x != -1) Radiance *= _IESAtlas.SampleLevel(my_point_clamp_sampler, AlignedUV, 0);
+ }
float SurfaceCos = dot(to_light, norm);//YES KEEP THIS, IT NOT ONLY IMPROVES PERFORMANCE BUT IT ALSO HELPS KEEPS THINGS LESS BIASED AS OTHERWISE THE NORMAL OFFSET CAN RESULT IN WRONG VISABILITY!
if(SurfaceCos > 0) {
float bsdf_pdf = 0.0f;
float3 bsdf_value = 0.0f;
+ float3 bsdf_diffuse = 0;
#ifndef RadianceCache
if((UseReSTIRGI && CurBounce == 0) || (UseASVGF && (CurBounce == Color.Data.w - 1 && CurBounce > 0))) hitDat.surfaceColor = 1.0f;
#endif
- bool validbsdfNEE = EvaluateBsdf(hitDat, PrevDirection, to_light, norm, bsdf_pdf, bsdf_value, pixel_index);
+ bool validbsdfNEE;
+ #ifdef RadianceCache
+ // if(CurBounce != 0) {
+ if(hitDat.roughness > 0.6f || CurBounce == 0) validbsdfNEE = EvaluateBsdf(hitDat, PrevDirection, to_light, norm, bsdf_pdf, bsdf_diffuse, pixel_index);
+ else validbsdfNEE = EvaluateBsdf2(hitDat, PrevDirection, to_light, norm, bsdf_pdf, bsdf_diffuse, pixel_index);
+ // bsdf_value /= bsdf_pdf;
+ //} else
+ bsdf_pdf = 0;
+ validbsdfNEE = EvaluateBsdf(hitDat, PrevDirection, to_light, norm, bsdf_pdf, bsdf_value, pixel_index);
+ #else
+ validbsdfNEE = EvaluateBsdf(hitDat, PrevDirection, to_light, norm, bsdf_pdf, bsdf_value, pixel_index);
+ #endif
#ifndef RadianceCache
if((UseASVGF && (CurBounce == Color.Data.w - 1 && CurBounce > 0))) bsdf_value *= Color.Data.xyz;
#endif
@@ -392,6 +419,7 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
[branch]if (SelectedLightGroup == 1) {
NEE_pdf = distance_to_light_squared * abs(dot(to_light, LightNorm)) / area;
Illum = (Radiance * bsdf_value) / NEE_pdf * RunningWeight * ((LightFormat == AREALIGHTQUAD || LightFormat == AREALIGHTDISK) ? (MiscInfo.x) : 1.0f);
+ bsdf_diffuse = (Radiance * bsdf_diffuse) / NEE_pdf * RunningWeight * ((LightFormat == AREALIGHTQUAD || LightFormat == AREALIGHTDISK) ? (MiscInfo.x) : 1.0f);
} else if(SelectedLightGroup == 0) {
NEE_pdf = (1.0f / ((abs(dot(to_light, LightNorm)) * area) / distance_to_light_squared)) / RunningWeight;
#ifndef LBVH
@@ -399,38 +427,49 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
#endif
float NEEMISWeight = power_heuristic(NEE_pdf, bsdf_pdf);
Illum = (Radiance * bsdf_value) / NEE_pdf * NEEMISWeight;
+ bsdf_diffuse = (Radiance * bsdf_diffuse) / NEE_pdf * NEEMISWeight;
} else {
NEE_pdf = HDRIParams.x * HDRIParams.y * equirectDirectionPdf(to_light) * (luminance(Radiance) / TotSum[0]);
float NEEMISWeight = power_heuristic(NEE_pdf, bsdf_pdf);
Illum = (Radiance * bsdf_value) / NEE_pdf * RunningWeight * NEEMISWeight;
+ bsdf_diffuse = (Radiance * bsdf_diffuse) / NEE_pdf * RunningWeight * NEEMISWeight;
}
#ifndef RadianceCache
Illum *= Color.throughput;
#endif
- if(LightFormat == AREALIGHTQUAD || LightFormat == AREALIGHTDISK) Illum *= pow(saturate(dot(to_light, -LightNorm)), MiscInfo.x);
- if (LightFormat == SPOTLIGHT) Illum *= saturate(saturate(dot(to_light, -LightNorm)) * MiscInfo.y + MiscInfo.z);
+ if(LightFormat == AREALIGHTQUAD || LightFormat == AREALIGHTDISK) {
+ Illum *= pow(saturate(dot(to_light, -LightNorm)), MiscInfo.x);
+ bsdf_diffuse *= pow(saturate(dot(to_light, -LightNorm)), MiscInfo.x);
+ }
+ if (LightFormat == SPOTLIGHT) {
+ bsdf_diffuse *= saturate(saturate(dot(to_light, -LightNorm)) * MiscInfo.y + MiscInfo.z);
+ Illum *= saturate(saturate(dot(to_light, -LightNorm)) * MiscInfo.y + MiscInfo.z);
+ }
float maxillum = max(max(Illum.x, Illum.y), Illum.z);
if(DoExposure) maxillum *= Exposure[0];
if(!UseRussianRoulette || (CurBounce == 0 && ImprovedPrimaryHit)) maxillum = 1;
Illum *= rcp(saturate(maxillum));
- if(bsdf_pdf > 0.0001f && maxillum > random(117, pixel_index).y) {//NEE russian roulette, massively improves performance while giivng the same result
+ bsdf_diffuse *= rcp(saturate(maxillum));
+ if(maxillum > random(117, pixel_index).y) {//NEE russian roulette, massively improves performance while giivng the same result
uint index3;
#ifdef RadianceCache
- bool TempTemp = !(((CacheInstance.pathLength >> 5) & 0x1) && !((CacheInstance.pathLength >> 6) & 0x1));
- if(UseReSTIRGI && !TempTemp) Illum *= (bsdf_value == 0) ? 1 : rcp(bsdf_value);
+ bool TempTemp = (CurBounce != Color.Data.w - 1);//!(((CacheInstance.pathLength >> 5) & 0x1) && !((CacheInstance.pathLength >> 6) & 0x1));
+ if(UseReSTIRGI && CurBounce == 0) Illum *= (bsdf_value == 0) ? 1 : rcp(bsdf_value);
#else
bool TempTemp = (CurBounce != Color.Data.w - 1);
if(UseReSTIRGI && CurBounce == 0) Illum *= (bsdf_value == 0) ? 1 : rcp(bsdf_value);
#endif
const ShadowRayData ShadRay = {pos,
- asfloat(packRGBE(bsdf_value)),
+ packRGBE(bsdf_diffuse),
to_light,
(LightFormat == DIRECTIONALLIGHT ? 10000.0f : distance_to_light - 0.01f) * (TempTemp ? 1 : -1),
Illum,
pixel_index};
- if(TerrainExists) InterlockedAdd(BufferSizes[CurBounce].heightmap_shadow_rays, 1, index3);
- InterlockedAdd(BufferSizes[CurBounce].shadow_rays, 1, index3);
- ShadowRaysBuffer[index3] = ShadRay;
+ if(abs(ShadRay.t) > 0.001f) {
+ if(TerrainExists) InterlockedAdd(BufferSizes[CurBounce].heightmap_shadow_rays, 1, index3);
+ InterlockedAdd(BufferSizes[CurBounce].shadow_rays, 1, index3);
+ ShadowRaysBuffer[index3] = ShadRay;
+ }
}
}
}
@@ -446,10 +485,14 @@ inline void calcFinalColor(SmallerRay ray, inout ColData Color, MaterialData hit
if (random(118, pixel_index).x > p)//Simple Russian Roulette
return;
throughput *= rcp(p);//rcp is a slightly faster but less accurate version of 1 / p, I decided the inaccuracy was worth the performance bump
+ #ifdef RadianceCache
+ CacheInstance.throughput = EncodeRGB(bsdf * rcp(p));
+ #endif
+ } else {
+ #ifdef RadianceCache
+ CacheInstance.throughput = EncodeRGB(bsdf);
+ #endif
}
- #ifdef RadianceCache
- CacheInstance.throughput = EncodeRGB(clamp(bsdf,0,1));
- #endif
Color.throughput = throughput;
@@ -487,6 +530,9 @@ void kernel_shade(uint3 id : SV_DispatchThreadID) {
}
#endif
ColData Color = GlobalColors[pixel_index];
+ #ifdef RadianceCache
+ CacheBuffer[pixel_index].samples[0].x = CacheBuffer[pixel_index].throughput;
+ #endif
if (bestHit.t == FarPlane) {//if ray goes into the void, sample skybox
float3 Radiance, transmittance, debug = 0;
float Stars;
@@ -507,7 +553,7 @@ void kernel_shade(uint3 id : SV_DispatchThreadID) {
else Color.Indirect += Color.throughput * DeSat(Radiance, 1.0f - SkyDesaturate) * BackgroundIntensity;
#ifdef RadianceCache
if(!UseReSTIRGI || ReSTIRGIUpdateRate == 0 || RandomNums[id.xy].z == 0)
- AddMissToCache(CacheBuffer[pixel_index], Color.throughput * Radiance * BackgroundIntensity);
+ AddMissToCache(CacheBuffer[pixel_index], Radiance * BackgroundIntensity);
#endif
}
break;
@@ -519,7 +565,7 @@ void kernel_shade(uint3 id : SV_DispatchThreadID) {
if (CurBounce == 1) Color.Direct += DeSat(_SkyboxTexture.SampleLevel(my_linear_clamp_sampler, uv, 0).xyz * BackgroundIntensity,1.0f - SkyDesaturate) * mis;
else Color.Indirect += Color.throughput * DeSat(_SkyboxTexture.SampleLevel(my_linear_clamp_sampler, uv, 0).xyz * BackgroundIntensity,1.0f - SkyDesaturate) * mis;
#ifdef RadianceCache
- AddMissToCache(CacheBuffer[pixel_index], Color.throughput * DeSat(_SkyboxTexture.SampleLevel(my_linear_clamp_sampler, uv, 0).xyz * BackgroundIntensity,1.0f - SkyDesaturate) * mis * abs(dot(i_octahedral_32(CacheBuffer[pixel_index].Norm), ray.direction)));
+ AddMissToCache(CacheBuffer[pixel_index], DeSat(_SkyboxTexture.SampleLevel(my_linear_clamp_sampler, uv, 0).xyz * BackgroundIntensity,1.0f - SkyDesaturate) * mis);
#endif
break;
case 2:
@@ -527,7 +573,8 @@ void kernel_shade(uint3 id : SV_DispatchThreadID) {
else if (CurBounce == 1) Color.Direct += BackgroundColor * BackgroundIntensity;
else Color.Indirect += Color.throughput * BackgroundColor * BackgroundIntensity;
#ifdef RadianceCache
- AddMissToCache(CacheBuffer[pixel_index], Color.throughput * BackgroundColor * abs(dot(i_octahedral_32(CacheBuffer[pixel_index].Norm), ray.direction)));
+ // AddHitToCache(CacheBuffer[pixel_index], ray.origin, random(324, pixel_index).y);
+ AddMissToCache(CacheBuffer[pixel_index], BackgroundColor * BackgroundIntensity);
#endif
break;
}
@@ -564,10 +611,10 @@ void kernel_shade(uint3 id : SV_DispatchThreadID) {
minmat = 0;
float3 BaseCol = 0;
MaterialIndex = MaterialCount + Terrains[bestHit.triangle_id].MatOffset;
- if(Mats.x > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex].surfaceColor.xy + _Materials[MaterialIndex].transmittanceColor.xy, _Materials[MaterialIndex].AlbedoTexScale, _Materials[MaterialIndex].AlbedoTex, true), 0).xyz * Mats.x;
- if(Mats.y > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex + 1].surfaceColor.xy + _Materials[MaterialIndex + 1].transmittanceColor.xy, _Materials[MaterialIndex + 1].AlbedoTexScale, _Materials[MaterialIndex + 1].AlbedoTex, true), 0).xyz * Mats.y;
- if(Mats.z > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex + 2].surfaceColor.xy + _Materials[MaterialIndex + 2].transmittanceColor.xy, _Materials[MaterialIndex + 2].AlbedoTexScale, _Materials[MaterialIndex + 2].AlbedoTex, true), 0).xyz * Mats.z;
- if(Mats.w > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex + 3].surfaceColor.xy + _Materials[MaterialIndex + 3].transmittanceColor.xy, _Materials[MaterialIndex + 3].AlbedoTexScale, _Materials[MaterialIndex + 3].AlbedoTex, true), 0).xyz * Mats.w;
+ if(Mats.x > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex].surfaceColor.xy + _Materials[MaterialIndex].transmittanceColor.xy, _Materials[MaterialIndex].AlbedoTexScale, _Materials[MaterialIndex].AlbedoTex), 0).xyz * Mats.x;
+ if(Mats.y > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex + 1].surfaceColor.xy + _Materials[MaterialIndex + 1].transmittanceColor.xy, _Materials[MaterialIndex + 1].AlbedoTexScale, _Materials[MaterialIndex + 1].AlbedoTex), 0).xyz * Mats.y;
+ if(Mats.z > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex + 2].surfaceColor.xy + _Materials[MaterialIndex + 2].transmittanceColor.xy, _Materials[MaterialIndex + 2].AlbedoTexScale, _Materials[MaterialIndex + 2].AlbedoTex), 0).xyz * Mats.z;
+ if(Mats.w > 0.001f) BaseCol += _TextureAtlas.SampleLevel(my_point_clamp_sampler, AlignUV(BaseUv * _Materials[MaterialIndex + 3].surfaceColor.xy + _Materials[MaterialIndex + 3].transmittanceColor.xy, _Materials[MaterialIndex + 3].AlbedoTexScale, _Materials[MaterialIndex + 3].AlbedoTex), 0).xyz * Mats.w;
MaterialIndex += x;
TempMat = _Materials[MaterialIndex];
BaseUv = BaseUv * TempMat.surfaceColor.xy + TempMat.transmittanceColor.xy;
@@ -580,7 +627,7 @@ void kernel_shade(uint3 id : SV_DispatchThreadID) {
}
if(TempMat.Rotation != 0) {TempMat.Rotation *= PI;}
- float2 AlbedoUv = AlignUV(BaseUv, TempMat.AlbedoTexScale, TempMat.AlbedoTex, TempMat.Rotation, true);
+ float2 AlbedoUv = AlignUV(BaseUv, TempMat.AlbedoTexScale, TempMat.AlbedoTex, TempMat.Rotation);
float2 NormalUV = AlignUV(BaseUv, float4(TempMat.SecondaryTexScale, TempMat.AlbedoTexScale.zw), TempMat.NormalTex, TempMat.Rotation);
float2 MetallicUV = AlignUV(BaseUv, float4(TempMat.SecondaryTexScale, TempMat.AlbedoTexScale.zw), TempMat.MetallicTex, TempMat.Rotation);
float2 RoughnessUV = AlignUV(BaseUv, float4(TempMat.SecondaryTexScale, TempMat.AlbedoTexScale.zw), TempMat.RoughnessTex, TempMat.Rotation);
@@ -624,8 +671,6 @@ void kernel_shade(uint3 id : SV_DispatchThreadID) {
TempMat.roughness = max(TempMat.roughness, 0.00001f);
TempMat.surfaceColor = max(TempMat.surfaceColor, 0.005f);
-
-
#ifndef WhiteLights
if(TempMat.emmissive > 0) {
float2 EmissionUV = AlignUV(BaseUv, TempMat.AlbedoTexScale, TempMat.EmissiveTex);
@@ -687,6 +732,7 @@ void kernel_finalize(uint3 id : SV_DispatchThreadID) {//Moved final accumulation
#endif
}
float3 res = (GlobalColors[final_pixel_index].Data.w == 0) ? GlobalColors[final_pixel_index].Data.xyz : ((float)PartialRenderingFactor * ((GlobalColors[final_pixel_index].Direct + GlobalColors[final_pixel_index].Indirect * IndirectBoost) * GlobalColors[final_pixel_index].Data.xyz + pow(unpackRGBE(GlobalColors[final_pixel_index].PrimaryNEERay),2.2f)) / GBufferCol);
+ // float3 res = (GlobalColors[final_pixel_index].Data.w == 0) ? GlobalColors[final_pixel_index].Data.xyz : ((float)PartialRenderingFactor * ((GlobalColors[final_pixel_index].Direct + GlobalColors[final_pixel_index].Indirect * IndirectBoost) * GlobalColors[final_pixel_index].Data.xyz) / GBufferCol);
if (!all(res < 100000)) res = 0;
#if defined(RadianceDebug) && defined(RadianceCache)
res = 0;
diff --git a/TrueTrace/Resources/MainCompute/ReSTIRGI.compute b/TrueTrace/Resources/MainCompute/ReSTIRGI.compute
index f7df4d1c..e55e05ad 100644
--- a/TrueTrace/Resources/MainCompute/ReSTIRGI.compute
+++ b/TrueTrace/Resources/MainCompute/ReSTIRGI.compute
@@ -354,7 +354,7 @@ void ReSTIRGISpatial(uint3 id : SV_DispatchThreadID) {
}
#endif
}
- if(Data.w != 0) GlobalColors[pixel_index].Data = float4(bsdf, 1);
+ if(Data.w != 0) GlobalColors[pixel_index].Data = float4(max(bsdf, 0.0001f), 1);
GlobalColors[pixel_index].throughput = float3(asfloat(uint2(octahedral_32(GeomNorm), octahedral_32(SurfNorm))), GBuffer.z);
GlobalColors[pixel_index].Direct = CenterCol.Direct * CurrentRes.y;
GlobalColors[pixel_index].Indirect = CenterCol.Indirect * CurrentRes.y;
diff --git a/TrueTrace/Resources/Objects/RayTracingLights.cs b/TrueTrace/Resources/Objects/RayTracingLights.cs
index 8e552bd2..ee5d0def 100644
--- a/TrueTrace/Resources/Objects/RayTracingLights.cs
+++ b/TrueTrace/Resources/Objects/RayTracingLights.cs
@@ -9,7 +9,9 @@ public class RayTracingLights : MonoBehaviour {
[HideInInspector] public Light ThisLight;
[HideInInspector] public LightData ThisLightData;
[HideInInspector] public int ArrayIndex;
+ [HideInInspector] public int IESIndex;
[Range(0,40)] public float ShadowSoftness = 0.0f;
+ public Texture2D IESProfile;
public void Start() {
ThisLightData = new LightData();
diff --git a/TrueTrace/Resources/Objects/RayTracingObject.cs b/TrueTrace/Resources/Objects/RayTracingObject.cs
index e1cd42d2..5428ace8 100644
--- a/TrueTrace/Resources/Objects/RayTracingObject.cs
+++ b/TrueTrace/Resources/Objects/RayTracingObject.cs
@@ -185,8 +185,8 @@ public void matfill() {
WasDeleted = true;
return;
}
-
- if((Application.isPlaying && !mesh.isReadable) || mesh == null || SharedMaterials == null || SharedMaterials.Length == 0 || mesh.GetTopology(0) != MeshTopology.Triangles || mesh.vertexCount == 0) {
+// (Application.isPlaying && !mesh.isReadable) ||
+ if(mesh == null || SharedMaterials == null || SharedMaterials.Length == 0 || mesh.GetTopology(0) != MeshTopology.Triangles || mesh.vertexCount == 0) {
DestroyImmediate(this);
WasDeleted = true;
return;
diff --git a/TrueTrace/Resources/PostProcess/ASVGF.compute b/TrueTrace/Resources/PostProcess/ASVGF/ASVGF.compute
similarity index 87%
rename from TrueTrace/Resources/PostProcess/ASVGF.compute
rename to TrueTrace/Resources/PostProcess/ASVGF/ASVGF.compute
index fafd26bf..7c303ce1 100644
--- a/TrueTrace/Resources/PostProcess/ASVGF.compute
+++ b/TrueTrace/Resources/PostProcess/ASVGF/ASVGF.compute
@@ -1,10 +1,8 @@
-#include "../GlobalDefines.cginc"
+#include "../../GlobalDefines.cginc"
+#include "../DenoisersCommon.cginc"
#include "UnityCG.cginc"
#pragma warning( disable : 3556)
-int screen_width;
-int screen_height;
-
float ResRatio;
inline float4x4 inverse(float4x4 m) {
@@ -46,50 +44,9 @@ inline float4x4 inverse(float4x4 m) {
return ret;
}
-struct ColData {
- float3 throughput;
- float3 Direct;
- float3 Indirect;
- uint Fog;
- uint Flags;
- uint MetRoughIsSpec;
- float4 Data;
-};
-StructuredBuffer PerPixelRadiance;
-
-uint packRGBE(float3 v)
-{
- float3 va = max(0, v);
- float max_abs = max(va.r, max(va.g, va.b));
- if (max_abs == 0)
- return 0;
-
- float exponent = floor(log2(max_abs));
-
- uint result;
- result = uint(clamp(exponent + 20, 0, 31)) << 27;
- float scale = pow(2, -exponent) * 256.0;
- uint3 vu = min(511, round(va * scale));
- result |= vu.r;
- result |= vu.g << 9;
- result |= vu.b << 18;
- return result;
-}
-
-float3 unpackRGBE(uint x)
-{
- int exponent = int(x >> 27) - 20;
- float scale = pow(2, exponent) / 256.0;
- float3 v;
- v.r = float(x & 0x1ff) * scale;
- v.g = float((x >> 9) & 0x1ff) * scale;
- v.b = float((x >> 18) & 0x1ff) * scale;
-
- return v;
-}
#ifdef HDRP
Texture2DArray NormalTex;
@@ -127,14 +84,18 @@ RWTexture2D IMG_ASVGF_HIST_MOMENTS_HF_A;
RWTexture2D IMG_ASVGF_HIST_COLOR_LF_SH_A;
RWTexture2D IMG_ASVGF_HIST_COLOR_LF_COCG_A;
RWTexture2D IMG_ASVGF_ATROUS_PING_HF;
-RWTexture2D IMG_ASVGF_ATROUS_PING_SPEC;
+RWTexture2D IMG_ASVGF_ATROUS_PING_SPEC2;
RWTexture2D IMG_ASVGF_ATROUS_PING_MOMENTS;
RWTexture2D IMG_ASVGF_ATROUS_PING_LF_SH;
RWTexture2D IMG_ASVGF_ATROUS_PING_LF_COCG;
-RWTexture2D MetallicAWrite;
-Texture2D MetallicA;
-Texture2D MetallicB;
+RWTexture2D MetallicAWrite;
+Texture2D MetallicA;
+Texture2D MetallicB;
+
+RWTexture2D ReflRefracAWrite;
+Texture2D ReflRefracA;
+Texture2D ReflRefracB;
Texture2D TEX_ASVGF_HIST_MOMENTS_HF_A;
@@ -148,7 +109,6 @@ Texture2D TEX_ASVGF_HIST_COLOR_LF_SH_A;
Texture2D TEX_ASVGF_HIST_COLOR_LF_COCG_A;
Texture2D TEX_ASVGF_ATROUS_PING_HF;
-SamplerState my_linear_clamp_sampler;
SamplerState my_point_clamp_sampler;
StructuredBuffer ExposureBuffer;
@@ -170,43 +130,14 @@ static const float wavelet_kernel[2][2] = {
{ wavelet_factor, wavelet_factor * wavelet_factor }
};
-inline float luminance(in float3 color)
-{
- return dot(color, float3(0.299, 0.587, 0.114));
-}
-
#pragma kernel CopyData
-struct Ray {
- float3 origin;
- float3 direction;
-};
+
RWStructuredBuffer RayB;
RWStructuredBuffer GlobalRays;
-inline float2 msign(float2 v) {
- return (v>=0.0) ? 1.0 : -1.0;
-}
-
-uint octahedral_32(float3 nor) {
- nor.xy /= ( abs( nor.x ) + abs( nor.y ) + abs( nor.z ) );
- nor.xy = (nor.z >= 0.0) ? nor.xy : (1.0-abs(nor.yx))*msign(nor.xy);
- uint2 d = uint2(round(32767.5 + nor.xy*32767.5));
- return d.x|(d.y<<16u);
-}
-
-float3 i_octahedral_32( uint data ) {
- uint2 iv = uint2( data, data>>16u ) & 65535u;
- float2 v = float2(iv)/32767.5f - 1.0f;
- float3 nor = float3(v, 1.0f - abs(v.x) - abs(v.y)); // Rune Stubbe's version,
- float t = max(-nor.z,0.0); // much faster than original
- nor.x += (nor.x>0.0)?-t:t; // implementation of this
- nor.y += (nor.y>0.0)?-t:t; // technique
- return normalize( nor );
-}
-
struct SH {
float4 shY;
@@ -264,7 +195,6 @@ int CurFrame;
SamplerState sampler_trilinear_clamp;
-Texture2D ScreenSpaceInfo;
RWTexture2D ScreenSpaceInfoWrite;
Texture2D WorldPosData;
@@ -293,40 +223,8 @@ SH irradiance_to_SH(float3 color, float3 dir)
RWTexture2D AlbedoColorA;
Texture2D AlbedoColorB;
-float4x4 _CameraInverseProjection;
-float4x4 _CameraToWorld;
-
-Ray CreateRay(float3 origin, float3 direction) {
- Ray ray;
- ray.origin = origin;
- ray.direction = direction;
- return ray;
-}
-
-Ray CreateCameraRay(float2 uv) {
- // Transform the camera origin to world space
- float3 origin = mul(_CameraToWorld, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz;
-
- // Invert the perspective projection of the view-space position
- float3 direction = mul(_CameraInverseProjection, float4(uv, 0.0f, 1.0f)).xyz;
- // Transform the direction from camera to world space and normalize
- direction = mul(_CameraToWorld, float4(direction, 0.0f)).xyz;
- direction = normalize(direction);
-
- return CreateRay(origin, direction);
-}
-uint ToColorSpecPacked(float3 A) {
- return ((uint)(A.x * 16383.0f)) | ((uint)(A.y * 16383.0f) << 14) | ((uint)A.z << 28);
-}
-float3 FromColorSpecPacked(uint A) {
- return float3(
- (A & 0x3FFF) / 16383.0f,
- ((A >> 14) & 0x3FFF) / 16383.0f,
- ((A >> 28) & 0x3)
- );
-}
float4x4 viewprojection;
float4x4 prevviewprojection;
int PartialRenderingFactor;
@@ -334,14 +232,14 @@ int PartialRenderingFactor;
void CopyData(uint3 id : SV_DispatchThreadID)
{
int pixel_index = id.y * screen_width + id.x;
- ColData Pixel = PerPixelRadiance[pixel_index];
+ ColData Pixel = GlobalColors[pixel_index];
float3 TexBaseColor = Pixel.Data.xyz;
TexBaseColor = (TexBaseColor > 0.005f ? rcp(TexBaseColor) : 0);
float2 MetRough = FromColorSpecPacked(Pixel.MetRoughIsSpec);
if(Pixel.Data.w == 0) {
Pixel.Direct = float3(0,0,0);
Pixel.Indirect = float3(0,0,0);
- Pixel.Fog = 0;
+ Pixel.PrimaryNEERay = 0;
}
#ifdef HDRP
@@ -353,20 +251,21 @@ void CopyData(uint3 id : SV_DispatchThreadID)
float2 pos_prev = ((((float2(id.xy)+0.5f) * float2(rcp(screen_width), rcp(screen_height)) + motion) * float2(screen_width, screen_height)));
bool ReflectedRefracted = max(FromColorSpecPacked(Pixel.MetRoughIsSpec).z - 2,0);
- MetallicAWrite[id.xy] = float4(MetRough, ReflectedRefracted, 0);
+ MetallicAWrite[id.xy] = MetRough;//, ReflectedRefracted, asfloat((asuint(ScreenSpaceInfo[id.xy].w) << 3) >> 3));
+ ReflRefracAWrite[id.xy] = (ReflectedRefracted << 31) | ((asuint(ScreenSpaceInfo[id.xy].w) << 3) >> 3);
float3 WorldAlbedo = unpackRGBE(Pixel.Flags);
float Exposure = 1;
if(UseExposure) Exposure = ExposureBuffer[0];
if (!((asuint(ScreenSpaceInfo[id.xy].w) >> 31) & 0x1) && (FromColorSpecPacked(Pixel.MetRoughIsSpec).z == 2 || MetRough.y >= 0.6f)) {
AlbedoColorA[id.xy] = uint2(Pixel.Flags, any(pos_prev < 0 || pos_prev >= float2(screen_width, screen_height)) ? Pixel.Flags : AlbedoColorB[pos_prev].y);
STORE_SH(TEX_PT_COLOR_LF_SHWrite, TEX_PT_COLOR_LF_COCGWrite, id.xy, irradiance_to_SH(PartialRenderingFactor * IndirectBoost * clamp(Pixel.Indirect * ((Pixel.Data.xyz * ((WorldAlbedo > 0.001f) ? rcp(WorldAlbedo) : 0))) / 1024.0f,0,1200000.0f), asfloat(WorldPosData[id.xy].xyz)));
- TEX_PT_COLOR_HFWrite[id.xy] = float4(PartialRenderingFactor * clamp((Pixel.Direct + pow(unpackRGBE(Pixel.Fog),2.2f) * TexBaseColor) * Pixel.Data.xyz * ((WorldAlbedo > 0.001f) ? rcp(WorldAlbedo) : 1.0f),0,1200000.0f),1);
+ TEX_PT_COLOR_HFWrite[id.xy] = float4(PartialRenderingFactor * clamp((Pixel.Direct + pow(unpackRGBE(Pixel.PrimaryNEERay),2.2f) * TexBaseColor) * Pixel.Data.xyz * ((WorldAlbedo > 0.001f) ? rcp(WorldAlbedo) : 1.0f),0,1200000.0f),1);
TEX_PT_COLOR_SPECWrite[id.xy] = 0;
} else {
AlbedoColorA[id.xy] = uint2(any(pos_prev < 0 || pos_prev >= float2(screen_width, screen_height)) ? Pixel.Flags : AlbedoColorB[pos_prev].x, Pixel.Flags);
SH TempSH = { 0,0,0,0,0,0 };
STORE_SH(TEX_PT_COLOR_LF_SHWrite, TEX_PT_COLOR_LF_COCGWrite, id.xy, TempSH);
- TEX_PT_COLOR_SPECWrite[id.xy] = packRGBE(PartialRenderingFactor * max(clamp((Pixel.Direct + IndirectBoost * Pixel.Indirect + pow(unpackRGBE(Pixel.Fog),2.2f) * TexBaseColor) * Pixel.Data.xyz * ((WorldAlbedo > 0.001f) ? rcp(WorldAlbedo) : 1.0f),0,1200000.0f),0));
+ TEX_PT_COLOR_SPECWrite[id.xy] = packRGBE(PartialRenderingFactor * max(clamp((Pixel.Direct + IndirectBoost * Pixel.Indirect + pow(unpackRGBE(Pixel.PrimaryNEERay),2.2f) * TexBaseColor) * Pixel.Data.xyz * ((WorldAlbedo > 0.001f) ? rcp(WorldAlbedo) : 1.0f),0,1200000.0f),0));
TEX_PT_COLOR_HFWrite[id.xy] = 0;
}
if(!ReflectedRefracted || any(pos_prev < 0 || pos_prev >= float2(screen_width, screen_height))) {
@@ -582,7 +481,7 @@ void Reproject(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkG
IMG_ASVGF_GRAD_SMPL_POS_A[pos_grad] = asfloat(gradient_idx);
IMG_ASVGF_GRAD_HF_SPEC_PING[pos_grad] = found_prev_lum;
- RNGTexA[ipos] = float4(RNGTexB[found_pos_prev].xyz, (MetallicB[found_pos_prev].z != 0) ? 2 : 1);
+ RNGTexA[ipos] = float4(RNGTexB[found_pos_prev].xyz, (ReflRefracB[found_pos_prev] >> 31) ? 2 : 1);
GlobalRays[ipos.x + ipos.y * screen_width] = RayB[found_pos_prev.x + found_pos_prev.y * screen_width];
uint4 Target = PrimaryTriData[found_pos_prev];
float3 Pos;
@@ -872,7 +771,7 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float2 pos_prev = ((((float2(ipos)+0.5f) * float2(rcp(screen_width), rcp(screen_height)) + motion.xy) * float2(screen_width, screen_height)));// + (random(54, gl_GlobalInvocationID) - 0.5f) * 0.2f;
// Load the parameters of the target pixel
- bool ReflectedRefracted = MetallicA[gl_GlobalInvocationID.xy].z != 0;
+ bool ReflectedRefracted = ReflRefracA[gl_GlobalInvocationID.xy] >> 31;
float2 depth_curr;
float3 normal_curr;
float lum_curr_hf;
@@ -881,7 +780,7 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float4 curprojectedrefl = mul(viewprojection, float4(ray.origin + ray.direction * depth_curr.x, 1));
float4 prevprojectedrefl = mul(prevviewprojection, float4(ray.origin + ray.direction * depth_curr.x, 1));
float2 reflprojection = ((curprojectedrefl.xy / curprojectedrefl.w) - (prevprojectedrefl.xy / prevprojectedrefl.w)) * 0.5f;
-
+ int MatIndex = (ReflRefracA[gl_GlobalInvocationID.xy] << 1) >> 1;
float motion_length = length((motion.xy + reflprojection) * float2(screen_width, screen_height));
@@ -919,7 +818,7 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float depth_prev = TEX_PT_VIEW_DEPTH_B[p].x;
uint2 norms = TEX_PT_NORMALS_B[p];
- bool ReflectedRefractedPrev = MetallicB[p].z != 0;
+ bool ReflectedRefractedPrev = ReflRefracB[p] >> 31;
float3 normal_prev = i_octahedral_32(norms.y);
float3 geo_normal_prev = i_octahedral_32(norms.x);//needs to be TEX_PT_GEO_NORMAL_B, but since for now I am not worrying about normal maps yet, it can use the same texture
@@ -928,6 +827,7 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float dot_normals = dot(normal_curr, normal_prev);
float dot_geo_normals = dot(geo_normal_curr, geo_normal_prev);
+ if(MatIndex == ((ReflRefracB[p] << 1) >> 1))
[branch]if(!ReflectedRefracted && !ReflectedRefractedPrev) {
if (dist_depth < 0.1 && dot_geo_normals > 0.9f)
{
@@ -1099,7 +999,7 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
IMG_ASVGF_HIST_MOMENTS_HF_A[ipos] = out_moments_histlen_hf;
STORE_SH(IMG_ASVGF_HIST_COLOR_LF_SH_A, IMG_ASVGF_HIST_COLOR_LF_COCG_A, ipos, out_color_lf);
IMG_ASVGF_ATROUS_PING_HF[ipos] = float4(out_color_hf,1);
- IMG_ASVGF_ATROUS_PING_SPEC[ipos] = float2(asfloat(packRGBE(out_color_histlen_spec)), out_color_histlen_spec.a);
+ IMG_ASVGF_ATROUS_PING_SPEC2[ipos] = float2(asfloat(packRGBE(out_color_histlen_spec)), out_color_histlen_spec.a);
IMG_ASVGF_ATROUS_PING_MOMENTS[ipos] = out_moments_histlen_hf.xy;
GroupMemoryBarrierWithGroupSync();
@@ -1211,31 +1111,24 @@ inline void filter_image(
return;
}
- float2 jitter = 0;//float2((random(23, gl_GlobalInvocationID.xy) - 0.5));
- // Load the parameters of the anchor pixel
float3 geo_normal_center = i_octahedral_32(TEX_PT_NORMALS_A[ipos_hires].x);
float2 depth_center = TEX_PT_VIEW_DEPTH_A[ipos_hires];
float step_size = int(1u << (iteration));
if(iteration == 4) step_size = int(1u << (1));
float hist_len_lf = TEX_ASVGF_HIST_MOMENTS_HF_A[ipos_hires].a;
- float sum_w_lf = 1;// + clamp((hist_len_lf + 4) / 12.0f, 0, 1) * 1.0f;
- // sum_w_lf = clamp((hist_len_lf + 6) / 12.0f, 0, 1) * 1.0f;
+ float sum_w_lf = 1;
SH sum_color_lf = color_center_lf;
- color_center_lf.CoCg *= sum_w_lf;
- color_center_lf.shY *= sum_w_lf;
- // step_size *= clamp(step_size * (LFVarianceA[ipos_lowres] / (1.0f + (hist_len_lf / 8.0f)) + (1.0f - min(hist_len_lf / 6.0f,1))), 1.0f, max(step_size,2.0f));
- // step_size *= clamp(2.0 * ((1.0f - min(hist_len_lf / 12.0f,1))), 1.0f, 2.0f);
- // step_size *= ResRatio;
- // step_size *= exp(-clamp(fwidth_depth * 3.0f,0, 12.0f));
- // step_size++;
float TotVariance = LFVarianceA[ipos_lowres];/// (1.0f + (hist_len_lf / 8.0f));
+ float Weight1 = max((exp(img_lf_shY[ipos_lowres].w) - 1) * 1024.0f* 1024.0f,0);
// Compute the weighted average of color and moments from a sparse 3x3 pattern around the target pixel
const int r = 1;
for (int yy = -r; yy <= r; yy++) {
for (int xx = -r; xx <= r; xx++) {
+ if (xx == 0 && yy == 0)
+ continue;
int2 p_lowres = ipos_lowres + int2(xx, yy) * step_size;
int2 p_hires = p_lowres * GRAD_DWN + 1;
@@ -1250,10 +1143,8 @@ inline void filter_image(
}
p_lowres = ipos_lowres + int2(actxx, actyy) * step_size;
- p_hires = p_lowres * GRAD_DWN + 1 + jitter;
+ p_hires = p_lowres * GRAD_DWN + 1;
- if (xx == 0 && yy == 0)
- continue;
float w = float(all((p_hires >= int2(0, 0)))
&& all((p_hires < int2(screen_width, screen_height))));
@@ -1274,10 +1165,6 @@ inline void filter_image(
SH c_lf = load_SH(img_lf_shY, img_lf_CoCg, p_lowres);
- // float Weight1 = max(luminance(project_SH_irradiance(load_SH(img_lf_shY, img_lf_CoCg, ipos_lowres), geo_normal_center)) * 1024.0f* 1024.0f,0);
- // float Weight2 = max(luminance(project_SH_irradiance(load_SH(img_lf_shY, img_lf_CoCg, p_lowres), geo_normal)) * 1024.0f* 1024.0f,0);
-
- float Weight1 = max((exp(img_lf_shY[ipos_lowres].w) - 1) * 1024.0f* 1024.0f,0);
float Weight2 = max((exp(img_lf_shY[p_lowres].w) - 1) * 1024.0f* 1024.0f,0);
float GNdotGN = max(0.0, dot(geo_normal_center, geo_normal));
@@ -1337,23 +1224,14 @@ inline void deflicker_image(
float ratio = max_lum / color_center_lf.shY.w;
float ratio2 = (exp(max_lum) - 1) * 1024.0f * 1024.0f / ((exp(color_center_lf.shY.w) - 1) * 1024.0f * 1024.0f);
// if(TEX_ASVGF_HIST_MOMENTS_HF_A[ipos_hires].a > 4) {
- color_center_lf.shY *= ratio;
- color_center_lf.CoCg *= ratio;
+ // color_center_lf.shY *= ratio;
+ // color_center_lf.CoCg *= ratio;
// }
LFVarianceB[gl_GlobalInvocationID.xy] = ratio;
} else {
LFVarianceB[gl_GlobalInvocationID.xy] = 0.1f;
}
-
- {
- float ratio = color_center_lf.shY.w / (clamp(color_center_lf.shY.w / 0.282095, MinLum / 0.282095, MaxLum / 0.282095) * 0.282095);
- if(ratio < 0.001f) ratio = 1;
- // color_center_lf.shY *= (ratio == 0 ? 0 : rcp(ratio));
- // color_center_lf.CoCg *= (ratio == 0 ? 0 : rcp(ratio));
- // LFVarianceB[gl_GlobalInvocationID.xy] *= rcp(ratio);
- }
-
filtered_lf = color_center_lf;
}
@@ -1395,7 +1273,7 @@ float RoughnessSquareToSpecPower(in float alpha) {
inline void filter_image(
Texture2D img_hf,
- Texture2D img_spec,
+ Texture2D img_spec,
Texture2D img_moments,
out float3 filtered_hf,
out float3 filtered_spec,
@@ -1405,10 +1283,10 @@ inline void filter_image(
int2 ipos = int2(gl_GlobalInvocationID);
float3 color_center_hf = img_hf[ipos];
- float3 color_center_spec = unpackRGBE(asuint(img_spec[ipos].x));
+ float3 color_center_spec = unpackRGBE(img_spec[ipos]);
float2 moments_center = img_moments[ipos].xy;
- if (4 <= spec_iteration)
+ if (5 <= spec_iteration)
{
filtered_hf = color_center_hf;
filtered_spec = color_center_spec;
@@ -1456,24 +1334,24 @@ inline void filter_image(
float step_size = int(1u << spec_iteration);
if(spec_iteration != 3) {
- float MinMom = 99999.0f;
- float MaxMom = -99999.0f;
+ // float MinMom = 99999.0f;
+ // float MaxMom = -99999.0f;
float3 Min = 9999.0f;
float3 Max = -9999.0f;
[unroll]for(int i = -1; i <= 1; i++) {
[unroll]for(int j = -1; j <= 1; j++) {
int2 offID = ipos + int2(i, j);
if(i == 0 && j == 0) continue;
- Min = min(Min, unpackRGBE(asuint(img_spec[ipos].x)));
- Max = max(Max, unpackRGBE(asuint(img_spec[ipos].x)));
- MinMom = min(MinMom, img_moments[offID].y);
- MaxMom = max(MaxMom, img_moments[offID].y);
+ Min = min(Min, unpackRGBE(img_spec[ipos]));
+ Max = max(Max, unpackRGBE(img_spec[ipos]));
+ // MinMom = min(MinMom, img_moments[offID].y);
+ // MaxMom = max(MaxMom, img_moments[offID].y);
}
}
color_center_spec = clamp(color_center_spec, Min, Max);
- float Mom2 = clamp(moments_center.x, MinMom, MaxMom);
+ // float Mom2 = clamp(moments_center.x, MinMom, MaxMom);
// step_size *= clamp(step_size * (max(1e-8, moments_center.y * moments_center.y * 10.0f)) + rcp(hist_len_hf / 10.0f + 1), 1.0f, step_size);
- if(spec_iteration != 0) step_size *= clamp(step_size * (max(1e-8, Mom2 * Mom2 * 10.0f)), 1.0f, step_size);// (max(1e-8, moments_center.y * moments_center.y * 10.0f)) + rcp(hist_len_hf / 10.0f + 1), 1.0f, step_size);
+ // if(spec_iteration != 0) step_size *= clamp(step_size * (max(1e-8, Mom2 * Mom2 * 10.0f)), 1.0f, step_size);// (max(1e-8, moments_center.y * moments_center.y * 10.0f)) + rcp(hist_len_hf / 10.0f + 1), 1.0f, step_size);
}
// step_size *= ResRatio;
// step_size++;
@@ -1500,10 +1378,10 @@ inline void filter_image(
int2 p = ipos + int2(xx, yy) * step_size + jitter;
int actxx = xx;
int actyy = yy;
- if(p.x <= 0 || p.x > screen_width) {
+ if(p.x <= 0 || p.x >= screen_width) {
actxx *= -1;
}
- if(p.y <= 0 || p.y > screen_height) {
+ if(p.y <= 0 || p.y >= screen_height) {
actyy *= -1;
}
p = ipos + int2(actxx, actyy) * step_size + jitter;
@@ -1515,7 +1393,7 @@ inline void filter_image(
float3 normal = normalize(i_octahedral_32(TEX_PT_NORMALS_A[p].y));
float depth = TEX_PT_VIEW_DEPTH_A[p].x;
- float roughness = MetallicA[p].y;
+ float2 MetRough = MetallicA[p];
float dist_z = abs(depth_center.x - depth);
w *= exp(-dist_z);
@@ -1524,30 +1402,24 @@ inline void filter_image(
float w_hf = w;
float3 c_hf = img_hf[p];
- float3 c_spec = unpackRGBE(asuint(img_spec[p].x));
+ float3 c_spec = unpackRGBE(img_spec[p]);
float2 c_mom = img_moments[p].xy;
float l_hf = luminance(c_hf.rgb);
float dist_l_hf = abs(lum_mean_hf - l_hf);
w_hf *= exp(-dist_l_hf * dist_l_hf * sigma_l_hf);
- w_hf *= 1.0f - clamp(abs(MetallicA[p].x - CenterMetallic),0,1);
+ w_hf *= 1.0f - clamp(abs(MetRough.x - CenterMetallic),0,1);
float w_spec = w_hf;
- w_spec *= max(0, 1.0f - 10.0f * abs(roughness - roughness_center));
- // w_spec *= spec_filter_width_scale;
+ w_spec *= max(0, 1.0f - 10.0f * abs(MetRough.y - roughness_center));
float NdotN = max(0.0, dot(normal_center, normal));
- if (normal_weight_hf > 0)
- {
- w_hf *= clamp(pow(NdotN, normal_weight_hf),0,1);
- }
+ if (normal_weight_hf > 0) w_hf *= clamp(pow(NdotN, normal_weight_hf),0,1);
+
+ if (normal_weight_spec > 0) w_spec *= pow(NdotN, normal_weight_spec);
- if (normal_weight_spec > 0)
- {
- w_spec *= pow(NdotN, normal_weight_spec);
- }
sum_color_hf += c_hf.rgb * w_hf;
sum_color_spec += c_spec.rgb * w_spec;
@@ -1646,7 +1518,8 @@ float3 composite_color(float4 surf_base_color,
}
Texture2D TEX_ASVGF_ATROUS_PING_MOMENTS;
-Texture2D TEX_ASVGF_ATROUS_PING_SPEC;
+RWTexture2D IMG_ASVGF_ATROUS_PING_SPEC;
+Texture2D TEX_ASVGF_ATROUS_PING_SPEC;
RWTexture2D IMG_ASVGF_COLOR;
[numthreads(16, 16, 1)]
@@ -1665,33 +1538,27 @@ void Atrous(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGrou
if(spec_iteration < 3) {
IMG_ASVGF_ATROUS_PING_HF[ipos] = float4(filtered_hf,1);
- IMG_ASVGF_ATROUS_PING_SPEC[ipos] = float2(asfloat(packRGBE(filtered_spec)),0);
+ IMG_ASVGF_ATROUS_PING_SPEC[ipos] = packRGBE(filtered_spec);
IMG_ASVGF_ATROUS_PING_MOMENTS[ipos] = filtered_moments;
}
// Perform compositing on the last iteration
- if (spec_iteration == MaxIterations - 1)
+ if (spec_iteration == MaxIterations)
{
SH filtered_lf = interpolate_lf(TEX_ASVGF_ATROUS_PING_LF_SH, TEX_ASVGF_ATROUS_PING_LF_COCG, ipos);
float3 normal = i_octahedral_32(TEX_PT_NORMALS_A[ipos].y);
- float4 base_color = float4(unpackRGBE(AlbedoColorB[ipos].x),PerPixelRadiance[ipos.x + ipos.y * screen_width].Data.w);// TEX_PT_BASE_COLOR_A.SampleLevel(sampler_trilinear_clamp, ipos / float2(screen_width, screen_height), 0);
+ float4 base_color = float4(unpackRGBE(AlbedoColorB[ipos].x),GlobalColors[ipos.x + ipos.y * screen_width].Data.w);// TEX_PT_BASE_COLOR_A.SampleLevel(sampler_trilinear_clamp, ipos / float2(screen_width, screen_height), 0);
if(DiffRes && base_color.w <= 1) base_color.xyz = 1;
- if(base_color.w == 0) base_color = PerPixelRadiance[ipos.x + ipos.y * screen_width].Data;
+ if(base_color.w == 0) base_color = GlobalColors[ipos.x + ipos.y * screen_width].Data;
// Project the spherical harmonics lighting onto the actual surface normal
float3 projected_lf = project_SH_irradiance(filtered_lf, normal);
projected_lf *= 1024.0f;
float3 final_color = composite_color(base_color, projected_lf, filtered_hf, filtered_spec, (DiffRes && base_color.w <= 1) ? 1 : unpackRGBE(AlbedoColorB[ipos].y), ipos);
- // if(base_color.w != 0) {
- // SH FullSH = irradiance_to_SH(final_color, i_octahedral_32(TEX_PT_NORMALS_A[ipos].x));
-
- // IMG_ASVGF_COLOR[ipos] = float4(project_SH_irradiance(FullSH, normal) * abs(dot(normal, i_octahedral_32(TEX_PT_NORMALS_A[ipos].x))), 0);
- // } else {
- IMG_ASVGF_COLOR[ipos] = float4(final_color, 0);
- // }
+ IMG_ASVGF_COLOR[ipos] = float4(final_color, 0);
}
}
@@ -1722,4 +1589,12 @@ void DistanceCorrectionKernel(uint3 id : SV_DispatchThreadID) {
float CurDepthX2 = FetchDepth(Uv - float2(rcp(screen_width) * 2.0f, 0));
float CurDepthY2 = FetchDepth(Uv - float2(0, rcp(screen_height) * 2.0f));
TEX_PT_VIEW_DEPTH_AWRITE[id.xy] = float2(CurDepth, abs(CurDepth - CurDepthX) + abs(CurDepth - CurDepthY) + abs(CurDepth - CurDepthY2) + abs(CurDepth - CurDepthX2));
+}
+
+
+#pragma kernel TempCopyKernel
+
+[numthreads(32, 32, 1)]
+void TempCopyKernel(uint3 id : SV_DispatchThreadID) {
+ IMG_ASVGF_ATROUS_PING_SPEC[id.xy] = asuint(TEX_ASVGF_FILTERED_SPEC_B[id.xy].x);
}
\ No newline at end of file
diff --git a/TrueTrace/Resources/PostProcess/ASVGF.cs b/TrueTrace/Resources/PostProcess/ASVGF/ASVGF.cs
similarity index 82%
rename from TrueTrace/Resources/PostProcess/ASVGF.cs
rename to TrueTrace/Resources/PostProcess/ASVGF/ASVGF.cs
index 9fbe438b..0816e0e0 100644
--- a/TrueTrace/Resources/PostProcess/ASVGF.cs
+++ b/TrueTrace/Resources/PostProcess/ASVGF/ASVGF.cs
@@ -37,6 +37,9 @@ public class ASVGF
public RenderTexture MetallicA;
public RenderTexture MetallicB;
+ public RenderTexture ReflectedRefractedA;
+ public RenderTexture ReflectedRefractedB;
+
public RenderTexture CorrectedDistanceTexA;
public RenderTexture CorrectedDistanceTexB;
@@ -110,6 +113,8 @@ public void ClearAll()
TEX_PT_COLOR_SPEC.Release();
MetallicA.Release();
MetallicB.Release();
+ ReflectedRefractedA.Release();
+ ReflectedRefractedB.Release();
TEX_PT_NORMALS_A.Release();
TEX_PT_NORMALS_B.Release();
AlbedoColorA.Release();
@@ -128,7 +133,7 @@ public void init(int ScreenWidth, int ScreenHeight)
this.ScreenWidth = ScreenWidth;
this.ScreenHeight = ScreenHeight;
iter = 0;
- if (shader == null) { shader = Resources.Load("PostProcess/ASVGF"); }
+ if (shader == null) { shader = Resources.Load("PostProcess/ASVGF/ASVGF"); }
CopyData = shader.FindKernel("CopyData");
Reproject = shader.FindKernel("Reproject");
Gradient_Img = shader.FindKernel("Gradient_Img");
@@ -148,33 +153,35 @@ public void init(int ScreenWidth, int ScreenHeight)
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_LF_SH, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull4);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_LF_SH, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull4);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull2);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref PT_LF1, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
+ CommonFunctions.CreateRenderTexture(ref PT_LF2, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref AlbedoColorA, ScreenWidth, ScreenHeight, CommonFunctions.RTInt2);
CommonFunctions.CreateRenderTexture(ref AlbedoColorB, ScreenWidth, ScreenHeight, CommonFunctions.RTInt2);
- CommonFunctions.CreateRenderTexture(ref PT_LF2, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_HF, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_HF, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
CommonFunctions.CreateRenderTexture(ref ASVGF_FILTERED_SPEC_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
CommonFunctions.CreateRenderTexture(ref ASVGF_FILTERED_SPEC_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_SH_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_SH_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
- CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
- CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_A, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_B, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref ASVGF_GRAD_SMPL_POS_A, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull1);
CommonFunctions.CreateRenderTexture(ref ASVGF_GRAD_SMPL_POS_B, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull1);
CommonFunctions.CreateRenderTexture(ref TEX_PT_COLOR_HF, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
CommonFunctions.CreateRenderTexture(ref TEX_PT_COLOR_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTInt1);
- CommonFunctions.CreateRenderTexture(ref MetallicA, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
- CommonFunctions.CreateRenderTexture(ref MetallicB, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
+ CommonFunctions.CreateRenderTexture(ref MetallicA, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
+ CommonFunctions.CreateRenderTexture(ref MetallicB, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
+ CommonFunctions.CreateRenderTexture(ref ReflectedRefractedA, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
+ CommonFunctions.CreateRenderTexture(ref ReflectedRefractedB, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_MOMENTS_HF_B, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_MOMENTS_HF_A, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
- CommonFunctions.CreateRenderTexture(ref LFVarianceA, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull1);
- CommonFunctions.CreateRenderTexture(ref LFVarianceB, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull1);
+ CommonFunctions.CreateRenderTexture(ref LFVarianceA, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf1);
+ CommonFunctions.CreateRenderTexture(ref LFVarianceB, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf1);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_MOMENTS, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_MOMENTS, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref ASVGF_GRAD_LF_PING, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf2);
@@ -201,8 +208,8 @@ public void DoRNG(ref RenderTexture RNGTex, ref RenderTexture RNGTexB, int CurFr
prevEuler = Euler;
shader.SetBool("UseBackupPointSelection", UseBackupPointSelection);
shader.SetFloat("CameraDist", Vector3.Distance(camera.transform.position, PrevCamPos));
- shader.SetMatrix("_CameraToWorld", camera.cameraToWorldMatrix);
- shader.SetMatrix("_CameraInverseProjection", camera.projectionMatrix.inverse);
+ shader.SetMatrix("CamToWorld", camera.cameraToWorldMatrix);
+ shader.SetMatrix("CamInvProj", camera.projectionMatrix.inverse);
shader.SetVector("Forward", camera.transform.forward);
shader.SetFloat("FarPlane", camera.farClipPlane);
shader.SetFloat("NearPlane", camera.nearClipPlane);
@@ -231,6 +238,7 @@ public void DoRNG(ref RenderTexture RNGTex, ref RenderTexture RNGTexB, int CurFr
cmd.SetComputeTextureParam(shader, Reproject, "RNGTexA", (EvenFrame) ? RNGTex : RNGTexB);
cmd.SetComputeTextureParam(shader, Reproject, "RNGTexB", (!EvenFrame) ? RNGTex : RNGTexB);
cmd.SetComputeTextureParam(shader, Reproject, "MetallicAWrite", (EvenFrame ? MetallicA : MetallicB));
+ cmd.SetComputeTextureParam(shader, Reproject, "ReflRefracB", (!EvenFrame ? ReflectedRefractedA : ReflectedRefractedB));
cmd.SetComputeTextureParam(shader, Reproject, "MetallicB", (!EvenFrame ? MetallicA : MetallicB));
cmd.SetComputeTextureParam(shader, Reproject, "PrimaryTriData", PrimaryTriData);
cmd.SetComputeBufferParam(shader, Reproject, "RayB", (!EvenFrame) ? GlobalRays : GlobalRaysB);
@@ -259,8 +267,8 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.SetComputeFloatParam(shader, "ResRatio", ResolutionRatio);
shader.SetBool("UseExposure", DoExposure);
shader.SetFloat("IndirectBoost", IndirectBoost);
- shader.SetBuffer(CopyData, "PerPixelRadiance", _ColorBuffer);
- shader.SetBuffer(Atrous, "PerPixelRadiance", _ColorBuffer);
+ shader.SetBuffer(CopyData, "GlobalColors", _ColorBuffer);
+ shader.SetBuffer(Atrous, "GlobalColors", _ColorBuffer);
shader.SetBuffer(CopyData, "ExposureBuffer", ExposureModifier);
shader.SetBuffer(Atrous, "ExposureBuffer", ExposureModifier);
shader.SetTexture(CopyData, "ScreenSpaceInfo", ScreenSpaceInfo);
@@ -278,6 +286,7 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
shader.SetTextureFromGlobal(CopyData, "TEX_PT_MOTION", "_CameraMotionVectorsTexture");
cmd.SetComputeTextureParam(shader, CopyData, "MetallicAWrite", (EvenFrame ? MetallicA : MetallicB));
+ cmd.SetComputeTextureParam(shader, CopyData, "ReflRefracAWrite", (EvenFrame ? ReflectedRefractedA : ReflectedRefractedB));
cmd.SetComputeTextureParam(shader, CopyData, "AlbedoColorA", (EvenFrame ? AlbedoColorA : AlbedoColorB));
cmd.SetComputeTextureParam(shader, CopyData, "AlbedoColorB", (!EvenFrame ? AlbedoColorA : AlbedoColorB));
@@ -324,6 +333,8 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.BeginSample("ASVGF Temporal Kernel");
shader.SetTextureFromGlobal(Temporal, "TEX_PT_MOTION", "_CameraMotionVectorsTexture");
+ cmd.SetComputeTextureParam(shader, Temporal, "ReflRefracA", (EvenFrame ? ReflectedRefractedA : ReflectedRefractedB));
+ cmd.SetComputeTextureParam(shader, Temporal, "ReflRefracB", (!EvenFrame ? ReflectedRefractedA : ReflectedRefractedB));
cmd.SetComputeTextureParam(shader, Temporal, "MetallicA", (EvenFrame ? MetallicA : MetallicB));
cmd.SetComputeTextureParam(shader, Temporal, "MetallicB", (!EvenFrame ? MetallicA : MetallicB));
cmd.SetComputeTextureParam(shader, Temporal, "TEX_PT_VIEW_DEPTH_A", EvenFrame ? CorrectedDistanceTexA : CorrectedDistanceTexB);
@@ -335,7 +346,7 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_HIST_COLOR_LF_COCG_B", (!EvenFrame ? ASVGF_HIST_COLOR_LF_COCG_A : ASVGF_HIST_COLOR_LF_COCG_B));
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_HIST_COLOR_HF", ASVGF_HIST_COLOR_HF);
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_FILTERED_SPEC_B", (!EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
- cmd.SetComputeTextureParam(shader, Temporal, "IMG_ASVGF_ATROUS_PING_SPEC", (EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
+ cmd.SetComputeTextureParam(shader, Temporal, "IMG_ASVGF_ATROUS_PING_SPEC2", (EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_HIST_MOMENTS_HF_B", (!EvenFrame ? ASVGF_HIST_MOMENTS_HF_A : ASVGF_HIST_MOMENTS_HF_B));
cmd.SetComputeTextureParam(shader, Temporal, "TEX_PT_COLOR_LF_SH", PT_LF1);
cmd.SetComputeTextureParam(shader, Temporal, "TEX_PT_COLOR_LF_COCG", PT_LF2);
@@ -357,7 +368,13 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.EndSample("ASVGF Temporal Kernel");
shader.SetBool("DiffRes", ResolutionRatio != 1.0f);
- cmd.CopyTexture((EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B), ASVGF_ATROUS_PING_SPEC);
+ // cmd.CopyTexture((EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B), ASVGF_ATROUS_PING_SPEC);
+ cmd.BeginSample("COPY A");
+ cmd.SetComputeTextureParam(shader, DistCorrect + 1, "TEX_ASVGF_FILTERED_SPEC_B", (EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
+ cmd.SetComputeTextureParam(shader, DistCorrect + 1, "IMG_ASVGF_ATROUS_PING_SPEC", ASVGF_ATROUS_PING_SPEC);
+ cmd.DispatchCompute(shader, DistCorrect + 1, Mathf.CeilToInt((ScreenWidth) / 32.0f), Mathf.CeilToInt((ScreenHeight) / 32.0f), 1);
+ cmd.EndSample("COPY A");
+
cmd.BeginSample("ASVGF Atrous LF: " + 0);
cmd.SetComputeIntParam(shader, "iteration", 0);
cmd.SetComputeTextureParam(shader, Atrous_LF, "TEX_PT_NORMALS_A", (EvenFrame ? TEX_PT_NORMALS_A : TEX_PT_NORMALS_B));
@@ -377,6 +394,43 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.DispatchCompute(shader, Atrous_LF, Mathf.CeilToInt((ScreenWidth / 3.0f + 15) / 16.0f), Mathf.CeilToInt((ScreenHeight / 3.0f + 15) / 16.0f), 1);
cmd.EndSample("ASVGF Atrous LF: " + 0);
+ cmd.BeginSample("ASVGF Atrous " + 0);
+
+ cmd.SetComputeIntParam(shader, "spec_iteration", 0);
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_PT_NORMALS_A", (EvenFrame ? TEX_PT_NORMALS_A : TEX_PT_NORMALS_B));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_PT_VIEW_DEPTH_A", EvenFrame ? CorrectedDistanceTexA : CorrectedDistanceTexB);
+ shader.SetTextureFromGlobal(Atrous, "TEX_PT_MOTION", "_CameraMotionVectorsTexture");
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_GRAD_HF_SPEC_PONG", ASVGF_GRAD_HF_SPEC_PONG);
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_HIST_MOMENTS_HF_A", (EvenFrame ? ASVGF_HIST_MOMENTS_HF_A : ASVGF_HIST_MOMENTS_HF_B));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_HIST_COLOR_LF_SH_A", (EvenFrame ? ASVGF_HIST_COLOR_LF_SH_A : ASVGF_HIST_COLOR_LF_SH_B));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_HIST_COLOR_LF_COCG_A", (EvenFrame ? ASVGF_HIST_COLOR_LF_COCG_A : ASVGF_HIST_COLOR_LF_COCG_B));
+
+
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_HF", (0 == 1) ? ASVGF_HIST_COLOR_HF : ((0 % 2 == 0) ? ASVGF_ATROUS_PING_HF : ASVGF_ATROUS_PONG_HF));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_SPEC", ((0 % 2 == 0) ? ASVGF_ATROUS_PING_SPEC : ASVGF_ATROUS_PONG_SPEC));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_MOMENTS", ((0 % 2 == 0) ? ASVGF_ATROUS_PING_MOMENTS : ASVGF_ATROUS_PONG_MOMENTS));
+
+
+ cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_HF", (0 == 0) ? ASVGF_HIST_COLOR_HF : ((0 % 2 == 1) ? ASVGF_ATROUS_PING_HF : ASVGF_ATROUS_PONG_HF));
+ cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_SPEC", ((0 % 2 == 1) ? ASVGF_ATROUS_PING_SPEC : ASVGF_ATROUS_PONG_SPEC));
+ cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_MOMENTS", ((0 % 2 == 1) ? ASVGF_ATROUS_PING_MOMENTS : ASVGF_ATROUS_PONG_MOMENTS));
+
+
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_LF_SH", ASVGF_ATROUS_PONG_LF_SH);
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_LF_COCG", ASVGF_ATROUS_PONG_LF_COCG);
+ cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_COLOR", Output);
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_GRAD_LF_PONG", ASVGF_GRAD_LF_PONG);
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_GRAD_HF_SPEC_PONG", ASVGF_GRAD_HF_SPEC_PONG);
+ cmd.SetComputeTextureParam(shader, Atrous, "MetallicA", (EvenFrame ? MetallicA : MetallicB));
+ cmd.SetComputeTextureParam(shader, Atrous, "MetallicB", (!EvenFrame ? MetallicA : MetallicB));
+ shader.SetTextureFromGlobal(Atrous, "DiffuseGBuffer", "_CameraGBufferTexture0");
+ shader.SetTextureFromGlobal(Atrous, "SpecularGBuffer", "_CameraGBufferTexture1");
+ shader.SetTextureFromGlobal(Atrous, "NormalTex", "_CameraGBufferTexture2");
+
+ cmd.SetComputeTextureParam(shader, Atrous, "AlbedoColorB", (EvenFrame ? AlbedoColorA : AlbedoColorB));
+ shader.SetTexture(Atrous, "ScreenSpaceInfo", ScreenSpaceInfo);
+ cmd.DispatchCompute(shader, Atrous, Mathf.CeilToInt((ScreenWidth + 15) / 16.0f), Mathf.CeilToInt((ScreenHeight + 15) / 16.0f), 1);
+ cmd.EndSample("ASVGF Atrous " + 0);
for (int i = 0; i < MaxIterations; i++)
{
@@ -398,9 +452,9 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.DispatchCompute(shader, Atrous_LF, Mathf.CeilToInt((ScreenWidth / 3.0f + 15) / 16.0f), Mathf.CeilToInt((ScreenHeight / 3.0f + 15) / 16.0f), 1);
cmd.EndSample("ASVGF Atrous LF " + (e + 1));
- cmd.BeginSample("ASVGF Atrous " + e);
+ cmd.BeginSample("ASVGF Atrous " + (e + 1));
- cmd.SetComputeIntParam(shader, "spec_iteration", e);
+ cmd.SetComputeIntParam(shader, "spec_iteration", (e + 1));
cmd.SetComputeTextureParam(shader, Atrous, "TEX_PT_NORMALS_A", (EvenFrame ? TEX_PT_NORMALS_A : TEX_PT_NORMALS_B));
cmd.SetComputeTextureParam(shader, Atrous, "TEX_PT_VIEW_DEPTH_A", EvenFrame ? CorrectedDistanceTexA : CorrectedDistanceTexB);
shader.SetTextureFromGlobal(Atrous, "TEX_PT_MOTION", "_CameraMotionVectorsTexture");
@@ -410,14 +464,14 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_HIST_COLOR_LF_COCG_A", (EvenFrame ? ASVGF_HIST_COLOR_LF_COCG_A : ASVGF_HIST_COLOR_LF_COCG_B));
- cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_HF", (e == 1) ? ASVGF_HIST_COLOR_HF : ((e % 2 == 0) ? ASVGF_ATROUS_PING_HF : ASVGF_ATROUS_PONG_HF));
- cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_SPEC", ((e % 2 == 0) ? ASVGF_ATROUS_PING_SPEC : ASVGF_ATROUS_PONG_SPEC));
- cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_MOMENTS", ((e % 2 == 0) ? ASVGF_ATROUS_PING_MOMENTS : ASVGF_ATROUS_PONG_MOMENTS));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_HF", ((e + 1) == 1) ? ASVGF_HIST_COLOR_HF : (((e + 1) % 2 == 0) ? ASVGF_ATROUS_PING_HF : ASVGF_ATROUS_PONG_HF));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_SPEC", (((e + 1) % 2 == 0) ? ASVGF_ATROUS_PING_SPEC : ASVGF_ATROUS_PONG_SPEC));
+ cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_MOMENTS", (((e + 1) % 2 == 0) ? ASVGF_ATROUS_PING_MOMENTS : ASVGF_ATROUS_PONG_MOMENTS));
- cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_HF", (e == 0) ? ASVGF_HIST_COLOR_HF : ((e % 2 == 1) ? ASVGF_ATROUS_PING_HF : ASVGF_ATROUS_PONG_HF));
- cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_SPEC", ((e % 2 == 1) ? ASVGF_ATROUS_PING_SPEC : ASVGF_ATROUS_PONG_SPEC));
- cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_MOMENTS", ((e % 2 == 1) ? ASVGF_ATROUS_PING_MOMENTS : ASVGF_ATROUS_PONG_MOMENTS));
+ cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_HF", ((e + 1) == 0) ? ASVGF_HIST_COLOR_HF : (((e + 1) % 2 == 1) ? ASVGF_ATROUS_PING_HF : ASVGF_ATROUS_PONG_HF));
+ cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_SPEC", (((e + 1) % 2 == 1) ? ASVGF_ATROUS_PING_SPEC : ASVGF_ATROUS_PONG_SPEC));
+ cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_ATROUS_PING_MOMENTS", (((e + 1) % 2 == 1) ? ASVGF_ATROUS_PING_MOMENTS : ASVGF_ATROUS_PONG_MOMENTS));
cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_LF_SH", ASVGF_ATROUS_PONG_LF_SH);
@@ -434,7 +488,7 @@ public void Do(ref ComputeBuffer _ColorBuffer, ref RenderTexture Output, float R
cmd.SetComputeTextureParam(shader, Atrous, "AlbedoColorB", (EvenFrame ? AlbedoColorA : AlbedoColorB));
shader.SetTexture(Atrous, "ScreenSpaceInfo", ScreenSpaceInfo);
cmd.DispatchCompute(shader, Atrous, Mathf.CeilToInt((ScreenWidth + 15) / 16.0f), Mathf.CeilToInt((ScreenHeight + 15) / 16.0f), 1);
- cmd.EndSample("ASVGF Atrous " + e);
+ cmd.EndSample("ASVGF Atrous " + (e + 1));
}
diff --git a/TrueTrace/Resources/PostProcess/Compute/AutoExpose.compute b/TrueTrace/Resources/PostProcess/Compute/AutoExpose.compute
index d193195a..3f2a51c9 100644
--- a/TrueTrace/Resources/PostProcess/Compute/AutoExpose.compute
+++ b/TrueTrace/Resources/PostProcess/Compute/AutoExpose.compute
@@ -13,9 +13,9 @@ RWStructuredBuffer A;
uint screen_width;
uint screen_height;
-const static float histogram_log_scale = 25.0f;
+const static float histogram_log_scale = 12.0f;
const static float histogram_log_zero = 220.0f;
-RWTexture2D _DebugTex;
+
float LuminanceAP1(float3 color) {
return dot(color, float3(0.2722287168f, 0.6740817658f, 0.0536895174f));
}
@@ -67,11 +67,11 @@ float Exposure;
bool ExposureAuto;
float calculateAverageLuminance() {
const float L_min = 0.00075;
- const float L_max = 500.0;
+ const float L_max = 50.0;
const float exposureDecay = 0.05;
const float exposureGrowth = 0.035;
- float eCurrent = clamp(A[0], 0.0f,500.0f);
+ float eCurrent = clamp(A[0], 0.0f,50.0f);
float L_median = screenAverageLuma();
float keyVal = 1.5f - 2.0 / (2.0 + log10(L_median + 1.0)); // Keyvalue remap to preserve relative brightness of lighting in scenes 1.03
float eTarget = keyVal * 2.15 / clamp(L_median, L_min, L_max);
diff --git a/TrueTrace/Resources/PostProcess/Compute/ToneMap.compute b/TrueTrace/Resources/PostProcess/Compute/ToneMap.compute
index 06664e5f..c1ebccc7 100644
--- a/TrueTrace/Resources/PostProcess/Compute/ToneMap.compute
+++ b/TrueTrace/Resources/PostProcess/Compute/ToneMap.compute
@@ -12,6 +12,56 @@ int ToneMapSelection;
int width;
+
+float3 tonemap22(float3 sRGB)
+{
+ // sRGB = pow(sRGB, 2.2f);
+ // NOTE: Tune these params based on your use case.
+ // Desmos graph: https://www.desmos.com/calculator/cvt2brlyl3
+ const float EXPOSUREX = 4.0;
+ const float CONTRAST = 1.9;
+ const float RANGE = 1.5;
+
+ const float3x3 sRGB_to_LMS = transpose(float3x3(
+ 0.31399022, 0.63951294, 0.04649755,
+ 0.15537241, 0.75789446, 0.08670142,
+ 0.01775239, 0.10944209, 0.87256922));
+
+ const float3x3 LMS_to_sRGB = transpose(float3x3(
+ 5.47221206, -4.6419601 , 0.16963708,
+ -1.1252419 , 2.29317094, -0.1678952 ,
+ 0.02980165, -0.19318073, 1.16364789));
+
+ const float3 sRGB_to_Y = float3(0.2126729, 0.7151522, 0.0721750);
+
+ // Apply tonescale in LMS
+
+ float3 LMS = mul(sRGB, sRGB_to_LMS);
+
+ LMS = pow(EXPOSUREX * LMS, CONTRAST / RANGE);
+ LMS = LMS / (LMS + 1.0);
+ LMS = pow(LMS, RANGE);
+
+ sRGB = mul(LMS, LMS_to_sRGB);
+
+ // Apply gamut mapping in sRGB
+
+ float Y = dot(sRGB_to_Y, sRGB);
+ if (Y > 1.0)
+ return 1.0;
+
+ float minimum = min(sRGB.r, min(sRGB.g, sRGB.b));
+ if (minimum < 0.0)
+ sRGB = lerp(sRGB, Y, -minimum / (Y - minimum));
+
+ float maximum = max(sRGB.r, max(sRGB.g, sRGB.b));
+ if (maximum > 1.0)
+ sRGB = lerp(sRGB, Y, (1.0 - maximum) / (Y - maximum));
+
+ return sRGB;
+}
+
+
inline float3 tony_mc_mapface(float3 stimulus) {
// Apply a non-linear transform that the LUT is encoded with.
const float3 encoded = stimulus / (stimulus + 1.0);
@@ -155,6 +205,7 @@ inline float3 AgX(float3 stimulus) {
return LUT.SampleLevel(sampler_linear_clamp, uv, 0).xyz;
}
+int screen_width;
[numthreads(16,16,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
diff --git a/TrueTrace/Resources/PostProcess/Denoiser.cs b/TrueTrace/Resources/PostProcess/Denoiser.cs
index 6f11b887..d78c5f12 100644
--- a/TrueTrace/Resources/PostProcess/Denoiser.cs
+++ b/TrueTrace/Resources/PostProcess/Denoiser.cs
@@ -469,10 +469,8 @@ public void ExecuteToneMap(ref RenderTexture Output, CommandBuffer cmd, ref Text
{//need to fix this so it doesnt create new textures every time
cmd.BeginSample("ToneMap");
cmd.SetComputeIntParam(ToneMapper,"ToneMapSelection", ToneMapSelection);
- cmd.SetComputeIntParam(ToneMapper,"width", Output.width);
- cmd.SetComputeIntParam(ToneMapper,"height", Output.height);
- cmd.SetComputeIntParam(ToneMapper,"ScreenWidth", Output.width);
- cmd.SetComputeIntParam(ToneMapper,"ScreenHeight", Output.height);
+ cmd.SetComputeIntParam(ToneMapper,"screen_width", Output.width);
+ cmd.SetComputeIntParam(ToneMapper,"screen_height", Output.height);
cmd.SetComputeTextureParam(ToneMapper, 0, "Result", Output);
cmd.SetComputeTextureParam(ToneMapper, 0, "LUT", ToneMapSelection == 5 ? LUT2 : LUT);
cmd.DispatchCompute(ToneMapper, 0, threadGroupsX2, threadGroupsY2, 1);
diff --git a/TrueTrace/Resources/PostProcess/DenoisersCommon.cginc b/TrueTrace/Resources/PostProcess/DenoisersCommon.cginc
new file mode 100644
index 00000000..00cbcc7f
--- /dev/null
+++ b/TrueTrace/Resources/PostProcess/DenoisersCommon.cginc
@@ -0,0 +1,123 @@
+int screen_width;
+int screen_height;
+float4x4 CamToWorld;
+float4x4 CamInvProj;
+float4x4 CamToWorldPrev;
+float4x4 CamInvProjPrev;
+
+RWTexture2D _DebugTex;
+
+Texture2D ScreenSpaceInfo;
+SamplerState my_linear_clamp_sampler;
+
+struct ColData {
+ float3 throughput;
+ float3 Direct;
+ float3 Indirect;
+ uint PrimaryNEERay;
+ uint Flags;
+ uint MetRoughIsSpec;
+ float4 Data;//could compress down to one uint for the color, and store the bounce flag in the existing metroughisspec flag, its already 14 bits for metallic and roughness, which is very unneeded
+};
+
+StructuredBuffer GlobalColors;
+
+struct Ray {
+ float3 origin;
+ float3 direction;
+};
+
+Ray CreateRay(float3 origin, float3 direction) {
+ Ray ray;
+ ray.origin = origin;
+ ray.direction = direction;
+ return ray;
+}
+
+inline Ray CreateCameraRay(float2 uv) {
+ // Transform the camera origin to world space
+ float3 origin = mul(CamToWorld, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz;
+
+ // Invert the perspective projection of the view-space position
+ float3 direction = mul(CamInvProj, float4(uv, 0.0f, 1.0f)).xyz;
+ // Transform the direction from camera to world space and normalize
+ direction = mul(CamToWorld, float4(direction, 0.0f)).xyz;
+ direction = normalize(direction);
+
+ return CreateRay(origin, direction);
+}
+
+inline Ray CreateCameraRayPrev(float2 uv) {
+ // Transform the camera origin to world space
+ float3 origin = mul(CamToWorldPrev, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz;
+
+ // Invert the perspective projection of the view-space position
+ float3 direction = mul(CamInvProjPrev, float4(uv, 0.0f, 1.0f)).xyz;
+ // Transform the direction from camera to world space and normalize
+ direction = mul(CamToWorldPrev, float4(direction, 0.0f)).xyz;
+ direction = normalize(direction);
+
+ return CreateRay(origin, direction);
+}
+
+
+inline float luminance(in float3 color) {
+ return dot(color, float3(0.299, 0.587, 0.114));
+}
+
+float3 FromColorSpecPacked(uint A) {
+ return float3(
+ (A & 0x3FFF) / 16383.0f,
+ ((A >> 14) & 0x3FFF) / 16383.0f,
+ ((A >> 28) & 0x3)
+ );
+}
+
+uint octahedral_32(float3 nor) {
+ float oct = 1.0f / (abs(nor.x) + abs(nor.y) + abs(nor.z));
+ float t = saturate(-nor.z);
+ nor.xy = (nor.xy + (nor.xy > 0.0f ? t : -t)) * oct;
+ uint2 d = uint2(round(32767.5 + nor.xy*32767.5));
+ return d.x|(d.y<<16u);
+}
+
+float3 i_octahedral_32( uint data ) {
+ uint2 iv = uint2( data, data>>16u ) & 65535u;
+ float2 v = iv/32767.5f - 1.0f;
+ float3 nor = float3(v, 1.0f - abs(v.x) - abs(v.y)); // Rune Stubbe's version,
+ float t = max(-nor.z,0.0); // much faster than original
+ nor.xy += (nor.xy>=0.0)?-t:t; // implementation of this
+ return normalize( nor );
+}
+
+uint packRGBE(float3 v)
+{
+ float3 va = max(0, v);
+ float max_abs = max(va.r, max(va.g, va.b));
+ if (max_abs == 0) return 0;
+
+ float exponent = floor(log2(max_abs));
+
+ uint result = uint(clamp(exponent + 20, 0, 31)) << 27;
+
+ float scale = pow(2, -exponent) * 256.0;
+ uint3 vu = min(511, round(va * scale));
+ result |= vu.r;
+ result |= vu.g << 9;
+ result |= vu.b << 18;
+
+ return result;
+}
+
+float3 unpackRGBE(uint x)
+{
+ int exponent = int(x >> 27) - 20;
+ float scale = pow(2, exponent) / 256.0;
+
+ float3 v;
+ v.r = float(x & 0x1ff) * scale;
+ v.g = float((x >> 9) & 0x1ff) * scale;
+ v.b = float((x >> 18) & 0x1ff) * scale;
+
+ return v;
+}
\ No newline at end of file
diff --git a/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.compute b/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.compute
index 9d81f5a5..1a2eed93 100644
--- a/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.compute
+++ b/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.compute
@@ -1,8 +1,7 @@
#include "../../GlobalDefines.cginc"
+#include "../DenoisersCommon.cginc"
#include "UnityCG.cginc"
#pragma warning( disable : 3556)
-int screen_width;
-int screen_height;
float ResRatio;
@@ -45,51 +44,6 @@ inline float4x4 inverse(float4x4 m) {
return ret;
}
-struct ColData {
- float3 throughput;
- float3 Direct;
- float3 Indirect;
- uint Fog;
- uint Flags;
- uint MetRoughIsSpec;
- float4 Data;
-};
-StructuredBuffer PerPixelRadiance;
-
-uint packRGBE(float3 v)
-{
- float3 va = max(0, v);
- float max_abs = max(va.r, max(va.g, va.b));
- if (max_abs == 0)
- return 0;
-
- float exponent = floor(log2(max_abs));
-
- uint result;
- result = uint(clamp(exponent + 20, 0, 31)) << 27;
-
- float scale = pow(2, -exponent) * 256.0;
- uint3 vu = min(511, round(va * scale));
- result |= vu.r;
- result |= vu.g << 9;
- result |= vu.b << 18;
-
- return result;
-}
-
-float3 unpackRGBE(uint x)
-{
- int exponent = int(x >> 27) - 20;
- float scale = pow(2, exponent) / 256.0;
-
- float3 v;
- v.r = float(x & 0x1ff) * scale;
- v.g = float((x >> 9) & 0x1ff) * scale;
- v.b = float((x >> 18) & 0x1ff) * scale;
-
- return v;
-}
-
#ifdef HDRP
Texture2DArray Depth;
Texture2DArray NormalTex;
@@ -123,7 +77,8 @@ RWTexture2D IMG_ASVGF_HIST_MOMENTS_HF_A;
RWTexture2D IMG_ASVGF_HIST_COLOR_LF_SH_A;
RWTexture2D IMG_ASVGF_HIST_COLOR_LF_COCG_A;
RWTexture2D IMG_ASVGF_ATROUS_PING_HF;
-RWTexture2D IMG_ASVGF_ATROUS_PING_SPEC;
+RWTexture2D IMG_ASVGF_ATROUS_PING_SPEC;
+RWTexture2D IMG_ASVGF_ATROUS_PING_SPEC2;
RWTexture2D IMG_ASVGF_ATROUS_PING_MOMENTS;
RWTexture2D IMG_ASVGF_ATROUS_PING_LF_SH;
RWTexture2D IMG_ASVGF_ATROUS_PING_LF_COCG;
@@ -135,20 +90,19 @@ Texture2D MetallicB;
Texture2D TEX_ASVGF_HIST_MOMENTS_HF_A;
-RWTexture2D TEX_PT_NORMALS_AWrite;
-Texture2D TEX_PT_NORMALS_A;
-Texture2D TEX_PT_NORMALS_B;
+RWTexture2D TEX_PT_NORMALS_AWrite;
+Texture2D TEX_PT_NORMALS_A;
+Texture2D TEX_PT_NORMALS_B;
Texture2D TEX_ASVGF_HIST_COLOR_LF_SH_A;
Texture2D TEX_ASVGF_HIST_COLOR_LF_COCG_A;
-RWTexture2D ReflectedRefractedTexWrite;
-Texture2D ReflectedRefractedTex;
-Texture2D ReflectedRefractedTexPrev;
+RWTexture2D ReflectedRefractedTexWrite;
+Texture2D ReflectedRefractedTex;
+Texture2D ReflectedRefractedTexPrev;
Texture2D TEX_ASVGF_ATROUS_PING_HF;
-SamplerState my_linear_clamp_sampler;
SamplerState my_point_clamp_sampler;
StructuredBuffer ExposureBuffer;
@@ -170,43 +124,13 @@ static const float wavelet_kernel[2][2] = {
{ wavelet_factor, wavelet_factor * wavelet_factor }
};
-inline float luminance(in float3 color)
-{
- return dot(color, float3(0.299, 0.587, 0.114));
-}
-
#pragma kernel CopyData
-struct Ray {
- float3 origin;
- float3 direction;
-};
RWStructuredBuffer RayB;
RWStructuredBuffer GlobalRays;
-inline float2 msign(float2 v) {
- return (v>=0.0) ? 1.0 : -1.0;
-}
-
-uint octahedral_32(float3 nor) {
- nor.xy /= ( abs( nor.x ) + abs( nor.y ) + abs( nor.z ) );
- nor.xy = (nor.z >= 0.0) ? nor.xy : (1.0-abs(nor.yx))*msign(nor.xy);
- uint2 d = uint2(round(32767.5 + nor.xy*32767.5));
- return d.x|(d.y<<16u);
-}
-
-float3 i_octahedral_32( uint data ) {
- uint2 iv = uint2( data, data>>16u ) & 65535u;
- float2 v = float2(iv)/32767.5f - 1.0f;
- float3 nor = float3(v, 1.0f - abs(v.x) - abs(v.y)); // Rune Stubbe's version,
- float t = max(-nor.z,0.0); // much faster than original
- nor.x += (nor.x>0.0)?-t:t; // implementation of this
- nor.y += (nor.y>0.0)?-t:t; // technique
- return normalize( nor );
-}
-
struct SH {
float4 shY;
@@ -268,8 +192,6 @@ int CurFrame;
SamplerState sampler_trilinear_clamp;
-
-Texture2D ScreenSpaceInfo;
Texture2D ScreenSpaceInfoPrev;
Texture2D PrimaryTriData;
@@ -299,43 +221,6 @@ inline SH irradiance_to_SH(float3 color, float3 dir)
RWTexture2D AlbedoColorA;
Texture2D AlbedoColorB;
-float4x4 _CameraInverseProjection;
-float4x4 _CameraToWorld;
-
-Ray CreateRay(float3 origin, float3 direction) {
- Ray ray;
- ray.origin = origin;
- ray.direction = direction;
- return ray;
-}
-
-
-
-Ray CreateCameraRay(float2 uv) {
- // Transform the camera origin to world space
- float3 origin = mul(_CameraToWorld, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz;
-
- // Invert the perspective projection of the view-space position
- float3 direction = mul(_CameraInverseProjection, float4(uv, 0.0f, 1.0f)).xyz;
- // Transform the direction from camera to world space and normalize
- direction = mul(_CameraToWorld, float4(direction, 0.0f)).xyz;
- direction = normalize(direction);
-
- return CreateRay(origin, direction);
-}
-
-
-uint ToColorSpecPacked(float3 A) {
- return ((uint)(A.x * 16383.0f)) | ((uint)(A.y * 16383.0f) << 14) | ((uint)A.z << 28);
-}
-float3 FromColorSpecPacked(uint A) {
- return float3(
- (A & 0x3FFF) / 16383.0f,
- ((A >> 14) & 0x3FFF) / 16383.0f,
- ((A >> 28) & 0x3)
- );
-}
-
struct CudaTriangle {
float3 pos0;
@@ -408,7 +293,7 @@ void CopyData(int3 id : SV_DispatchThreadID)
{
if(id.x > screen_width || id.y > screen_height) return;
const int pixel_index = id.y * screen_width + id.x;
- ColData Pixel = PerPixelRadiance[pixel_index];
+ ColData Pixel = GlobalColors[pixel_index];
float4 TexInverted = Pixel.Data;
float3 TexBaseColor = clamp(TexInverted.xyz,0,12.0f);
TexBaseColor = (TexBaseColor > 0.005f ? rcp(TexBaseColor) : 0);
@@ -428,7 +313,7 @@ void CopyData(int3 id : SV_DispatchThreadID)
if(TexInverted.w == 0) {
Pixel.Direct = float3(0,0,0);
Pixel.Indirect = float3(0,0,0);
- Pixel.Fog = 0;
+ Pixel.PrimaryNEERay = 0;
}
bool ReflectedRefracted = max(FromColorSpecPacked(Pixel.MetRoughIsSpec).z - 2,0);
@@ -442,7 +327,7 @@ void CopyData(int3 id : SV_DispatchThreadID)
SH IndirectSH = init_SH();
float4 HFCol = 0;
uint SpecCol = 0;
- float3 Direct = Pixel.Direct + pow(unpackRGBE(Pixel.Fog),2.2f) * TexBaseColor;
+ float3 Direct = Pixel.Direct + pow(unpackRGBE(Pixel.PrimaryNEERay),2.2f) * TexBaseColor;
const float dielectric_specular = 0.04;
float3 o_albedo = lerp(unpackRGBE(AlbedoData.x) * (1.0 - dielectric_specular), 0, FromColorSpecPacked(Pixel.MetRoughIsSpec).x * (MetRough.y < 0.6f));
@@ -459,7 +344,7 @@ void CopyData(int3 id : SV_DispatchThreadID)
// if(pos_prev.x != -1000) AlbedoData.x = AlbedoColorB[pos_prev].x;
SpecCol = packRGBE(PartialRenderingFactor * max(Exposure * (Direct + IndirectBoost * Pixel.Indirect) * Pixel.Data.xyz / max(0.01f, o_base_reflectivity),0));
}
- ReflectedRefractedTexWrite[id.xy] = float4(ReflectedRefracted, ((asuint(ScreenSpaceInfo[id.xy].w) << 3) >> 3), length((motion.xy) * float2(screen_width, screen_height)), 0);
+ ReflectedRefractedTexWrite[id.xy] = (ReflectedRefracted << 31) | ((asuint(ScreenSpaceInfo[id.xy].w) << 3) >> 3);
AlbedoColorA[id.xy] = AlbedoData;
@@ -468,7 +353,7 @@ void CopyData(int3 id : SV_DispatchThreadID)
TEX_PT_COLOR_SPECWrite[id.xy] = SpecCol;
if(!ReflectedRefracted) {
// if((asuint(ScreenSpaceInfo[id.xy].w) >> 31) & 0x1) TEX_PT_NORMALS_AWrite[id.xy] = uint2(octahedral_32(-i_octahedral_32(asuint(Pixel.throughput.x))), octahedral_32(-i_octahedral_32(asuint(Pixel.throughput.y))));
- TEX_PT_NORMALS_AWrite[id.xy] = uint4(asuint(Pixel.throughput.xy), asuint(ScreenSpaceInfo[id.xy].z), 0);//GeoNorm, Norm
+ TEX_PT_NORMALS_AWrite[id.xy] = uint2(asuint(Pixel.throughput.xy));//GeoNorm, Norm
} else {
TEX_PT_NORMALS_AWrite[id.xy] = TEX_PT_NORMALS_B[pos_prev];
}
@@ -738,7 +623,6 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float2 pos_prev = ((((float2(ipos)+0.5f) * float2(rcp(screen_width), rcp(screen_height)) + motion.xy) * float2(screen_width, screen_height)));// + (random(54, gl_GlobalInvocationID) - 0.5f) * 0.2f;
// Load the parameters of the target pixel
- float2 ReflectedRefracted = ReflectedRefractedTex[gl_GlobalInvocationID.xy];
float depth_curr;
float3 normal_curr;
float lum_curr_hf;
@@ -748,8 +632,10 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float4 prevprojectedrefl = mul(prevviewprojection, float4(ray.origin + ray.direction * depth_curr, 1));
float2 reflprojection = ((curprojectedrefl.xy / curprojectedrefl.w) - (prevprojectedrefl.xy / prevprojectedrefl.w)) * 0.5f;
- int MatDat = ReflectedRefractedTex[gl_GlobalInvocationID.xy].w;
- float motion_length = max(length((motion.xy) * float2(screen_width, screen_height)), ReflectedRefractedTexPrev[pos_prev].z);
+ int MatDat = (ReflectedRefractedTex[gl_GlobalInvocationID.xy] << 1) >> 1;
+ bool ReflectedRefracted = ReflectedRefractedTex[gl_GlobalInvocationID.xy] >> 31;
+ // float motion_length = length((motion.xy + reflprojection) * float2(screen_width, screen_height));
+ float motion_length = length((motion.xy) * float2(screen_width, screen_height));
float CenterFDepth = TEX_PT_VIEW_DEPTH_A[ipos].y;
@@ -787,7 +673,6 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float depth_prev = TEX_PT_VIEW_DEPTH_B[p].x;
uint2 norms = TEX_PT_NORMALS_B[p];
- float2 ReflectedRefractedPrev = ReflectedRefractedTexPrev[p];
float3 normal_prev = i_octahedral_32(norms.y);
float3 geo_normal_prev = i_octahedral_32(norms.x);//needs to be TEX_PT_GEO_NORMAL_B, but since for now I am not worrying about normal maps yet, it can use the same texture
@@ -795,9 +680,9 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
float dist_depth = (abs(depth_curr - depth_prev) - CameraDist) / depth_curr * max(CenterFDepth,0.25f);
float dot_normals = dot(normal_curr, normal_prev);
float dot_geo_normals = dot(geo_normal_curr, geo_normal_prev);
- if(ReflectedRefractedTexPrev[p].w == MatDat)
- [branch]if(!(ReflectedRefracted.x == 1) && !(ReflectedRefractedPrev.x == 1)) {
- if (ReflectedRefracted.y == ReflectedRefractedPrev.y && dist_depth < 0.1 && dot_geo_normals > 0.8)
+ if(((ReflectedRefractedTexPrev[p] << 1) >> 1) == MatDat)
+ [branch]if(!(ReflectedRefracted) && !(ReflectedRefractedTexPrev[p] >> 31)) {
+ if (dist_depth < 0.1 && dot_geo_normals > 0.8)
{
float w_diff = w[i] * max(dot_normals, 0);
float w_spec = w[i] * pow(max(dot_normals, 0), shininess);
@@ -813,7 +698,7 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
temporal_sum_w_spec += w_spec;
}
} else {
- if (ReflectedRefracted.y == ReflectedRefractedPrev.y &&dist_depth < 0.1)
+ if (dist_depth < 0.1)
{
float w_diff = pow(w[i],clamp(6.0f / depth_curr,1.0f, 3.0f));
float w_spec = w[i];
@@ -967,7 +852,7 @@ void Temporal(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGr
IMG_ASVGF_HIST_MOMENTS_HF_A[ipos] = out_moments_histlen_hf;
STORE_SH(IMG_ASVGF_HIST_COLOR_LF_SH_A, IMG_ASVGF_HIST_COLOR_LF_COCG_A, ipos, out_color_lf);
IMG_ASVGF_ATROUS_PING_HF[ipos] = float4(out_color_hf,1);
- IMG_ASVGF_ATROUS_PING_SPEC[ipos] = float2(asfloat(packRGBE(out_color_histlen_spec)), out_color_histlen_spec.a);
+ IMG_ASVGF_ATROUS_PING_SPEC2[ipos] = float2(asfloat(packRGBE(out_color_histlen_spec)), out_color_histlen_spec.a);
IMG_ASVGF_ATROUS_PING_MOMENTS[ipos] = out_moments_histlen_hf.xy;
// GroupMemoryBarrierWithGroupSync();
@@ -1088,7 +973,7 @@ inline void filter_image(
float step_size = int(1u << (iteration));
float hist_len_lf = TEX_ASVGF_HIST_MOMENTS_HF_A[ipos_hires].a;
- if(hist_len_lf > 0 && iteration == 4) step_size = int(1u << (1));
+ if(iteration == 4) step_size = int(1u << (1));
float sum_w_lf = 1;
SH sum_color_lf = color_center_lf;
@@ -1101,8 +986,8 @@ inline void filter_image(
float HistModifier = 1.0f;//clamp(pow(hist_len_lf / 32.0f,2), 0, 1);
// Compute the weighted average of color and moments from a sparse 3x3 pattern around the target pixel
const int r = 1;
- for (int yy = -r; yy <= r; yy++) {
- for (int xx = -r; xx <= r; xx++) {
+ [unroll]for (int yy = -r; yy <= r; yy++) {
+ [unroll]for (int xx = -r; xx <= r; xx++) {
if (xx == 0 && yy == 0)
continue;
int2 p_lowres = ipos_lowres + int2(xx, yy) * step_size;
@@ -1130,7 +1015,7 @@ inline void filter_image(
float depth = TEX_PT_VIEW_DEPTH_A[p_hires].x;
- float dist_z = abs(depth_center - depth) * fwidth_depth;
+ float dist_z = abs(depth_center - depth) * (fwidth_depth + 1.0f);
w *= exp(-dist_z);
w *= wavelet_kernel[abs(xx)][abs(yy)];
@@ -1143,7 +1028,8 @@ inline void filter_image(
float GNdotGN = max(0.0, dot(geo_normal_center, geo_normal));
w_lf *= pow(GNdotGN, 8);
- float w_l = clamp(exp(-pow(abs(Weight2 - Weight1) / (1.0f + (Weight1)),1) * max(1.0f - LFVarianceA[p_lowres], 0) * HistModifier),0.01f, 1.0f);
+ float w_l = clamp(exp(-pow(abs(Weight2 - Weight1) / (1.0f + (Weight1)),1) * max(1.0f - LFVarianceA[p_lowres], 0) * clamp(pow(hist_len_lf / 32.0f,2), 0, 1)),0.01f, 1.0f);
+ // float w_l = clamp(exp(-pow(abs(Weight2 - Weight1) / (1.0f + (Weight1)),1) * max(1.0f - LFVarianceA[p_lowres], 0) * HistModifier),0.01f, 1.0f);
if ((Weight1 + Weight2) / 2048.0f > 0.01f && iteration >= 1 && iteration < 5)
w_lf *= w_l;
@@ -1178,10 +1064,10 @@ inline void deflicker_image(
float MinLum = 9999.0f;
for (int yy = -r; yy <= r; yy++) {
for (int xx = -r; xx <= r; xx++) {
- int2 p_lowres = ipos_lowres + int2(xx, yy);
-
if (xx == 0 && yy == 0)
continue;
+ int2 p_lowres = ipos_lowres + int2(xx, yy);
+
SH c_lf = load_SH(img_lf_shY, img_lf_CoCg, p_lowres);
MaxLum = max(MaxLum, c_lf.shY.w);
@@ -1195,25 +1081,11 @@ inline void deflicker_image(
if (color_center_lf.shY.w > max_lum)
{
float ratio = max_lum / color_center_lf.shY.w;
- float ratio2 = (exp(max_lum) - 1) * 1024.0f * 1024.0f / ((exp(color_center_lf.shY.w) - 1) * 1024.0f * 1024.0f);
- // if(TEX_ASVGF_HIST_MOMENTS_HF_A[ipos_hires].a > 4) {
- color_center_lf.shY *= ratio;
- color_center_lf.CoCg *= ratio;
- // }
LFVarianceB[gl_GlobalInvocationID.xy] = ratio;
} else {
LFVarianceB[gl_GlobalInvocationID.xy] = 0.1f;
}
-
- {
- float ratio = color_center_lf.shY.w / (clamp(color_center_lf.shY.w / 0.282095, MinLum / 0.282095, MaxLum / 0.282095) * 0.282095);
- if(ratio < 0.001f) ratio = 1;
- // color_center_lf.shY *= (ratio == 0 ? 0 : rcp(ratio));
- // color_center_lf.CoCg *= (ratio == 0 ? 0 : rcp(ratio));
- // LFVarianceB[gl_GlobalInvocationID.xy] *= rcp(ratio);
- }
-
filtered_lf = color_center_lf;
}
@@ -1255,7 +1127,7 @@ float RoughnessSquareToSpecPower(in float alpha) {
inline void filter_image(
Texture2D img_hf,
- Texture2D img_spec,
+ Texture2D img_spec,
Texture2D img_moments,
out float3 filtered_hf,
out float3 filtered_spec,
@@ -1265,7 +1137,7 @@ inline void filter_image(
int2 ipos = int2(gl_GlobalInvocationID);
float3 color_center_hf = img_hf[ipos];
- float3 color_center_spec = unpackRGBE(asuint(img_spec[ipos].x));
+ float3 color_center_spec = unpackRGBE(img_spec[ipos]);
float2 moments_center = img_moments[ipos].xy;
if (4 <= spec_iteration)
@@ -1276,7 +1148,7 @@ inline void filter_image(
return;
}
- float depth_center = asfloat(TEX_PT_NORMALS_A[ipos].z);
+ float depth_center = TEX_PT_VIEW_DEPTH_A[ipos].x;
float fwidth_depth = TEX_PT_VIEW_DEPTH_A[ipos].y;
float roughness_center = MetallicA[ipos].y;
@@ -1313,10 +1185,10 @@ inline void filter_image(
float3 Max = -9999.0f;
[unroll]for(int i = -1; i <= 1; i++) {
[unroll]for(int j = -1; j <= 1; j++) {
- int2 offID = ipos + int2(i, j);
if(i == 0 && j == 0) continue;
- Min = min(Min, unpackRGBE(asuint(img_spec[ipos].x)));
- Max = max(Max, unpackRGBE(asuint(img_spec[ipos].x)));
+ int2 offID = ipos + int2(i, j);
+ Min = min(Min, unpackRGBE(img_spec[ipos]));
+ Max = max(Max, unpackRGBE(img_spec[ipos]));
MinMom = min(MinMom, img_moments[offID].y);
MaxMom = max(MaxMom, img_moments[offID].y);
}
@@ -1364,7 +1236,7 @@ inline void filter_image(
float3 normal = normalize(i_octahedral_32(TEX_PT_NORMALS_A[p].y));
- float depth = asfloat(TEX_PT_NORMALS_A[p].z);
+ float depth = TEX_PT_VIEW_DEPTH_A[p].x;
float dist_z = abs(depth_center - depth);// * fwidth_depth;
w *= exp(-dist_z);
@@ -1373,7 +1245,7 @@ inline void filter_image(
float w_hf = w;
float3 c_hf = img_hf[p];
- float3 c_spec = unpackRGBE(asuint(img_spec[p].x));
+ float3 c_spec = unpackRGBE(img_spec[p]);
float2 c_mom = img_moments[p].xy;
float l_hf = luminance(c_hf.rgb);
float dist_l_hf = abs(lum_mean_hf - l_hf);
@@ -1496,7 +1368,7 @@ float3 composite_color(float4 surf_base_color,
}
Texture2D TEX_ASVGF_ATROUS_PING_MOMENTS;
-Texture2D TEX_ASVGF_ATROUS_PING_SPEC;
+Texture2D TEX_ASVGF_ATROUS_PING_SPEC;
RWTexture2D IMG_ASVGF_COLOR;
[numthreads(16, 16, 1)]
@@ -1515,7 +1387,7 @@ void Atrous(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGrou
if(spec_iteration < 3) {
IMG_ASVGF_ATROUS_PING_HF[ipos] = float4(filtered_hf,1);
- IMG_ASVGF_ATROUS_PING_SPEC[ipos] = float2(asfloat(packRGBE(filtered_spec)),0);
+ IMG_ASVGF_ATROUS_PING_SPEC[ipos] = packRGBE(filtered_spec);
IMG_ASVGF_ATROUS_PING_MOMENTS[ipos] = filtered_moments;
}
@@ -1526,9 +1398,9 @@ void Atrous(uint3 gl_GlobalInvocationID : SV_DispatchThreadID, uint3 gl_WorkGrou
float3 normal = i_octahedral_32(TEX_PT_NORMALS_A[ipos].y);
- float4 base_color = float4(unpackRGBE(AlbedoColorB[ipos].x),PerPixelRadiance[ipos.x + ipos.y * screen_width].Data.w);// TEX_PT_BASE_COLOR_A.SampleLevel(sampler_trilinear_clamp, ipos / float2(screen_width, screen_height), 0);
+ float4 base_color = float4(unpackRGBE(AlbedoColorB[ipos].x),GlobalColors[ipos.x + ipos.y * screen_width].Data.w);// TEX_PT_BASE_COLOR_A.SampleLevel(sampler_trilinear_clamp, ipos / float2(screen_width, screen_height), 0);
if(DiffRes && base_color.w <= 1) base_color.xyz = 1;
- if(base_color.w == 0) base_color = PerPixelRadiance[ipos.x + ipos.y * screen_width].Data;
+ if(base_color.w == 0) base_color = GlobalColors[ipos.x + ipos.y * screen_width].Data;
// Project the spherical harmonics lighting onto the actual surface normal
float3 projected_lf = project_SH_irradiance(filtered_lf, normal);
projected_lf *= 1024.0f;
@@ -1565,4 +1437,11 @@ void DistanceCorrectionKernel(uint3 id : SV_DispatchThreadID) {
float CurDepthX2 = FetchDepth(Uv - float2(rcp(screen_width) * 2.0f, 0));
float CurDepthY2 = FetchDepth(Uv - float2(0, rcp(screen_height) * 2.0f));
TEX_PT_VIEW_DEPTH_AWRITE[id.xy] = float2(CurDepth, abs(CurDepth - CurDepthX) + abs(CurDepth - CurDepthY) + abs(CurDepth - CurDepthY2) + abs(CurDepth - CurDepthX2));
+}
+
+#pragma kernel TempCopyKernel
+
+[numthreads(32, 32, 1)]
+void TempCopyKernel(uint3 id : SV_DispatchThreadID) {
+ IMG_ASVGF_ATROUS_PING_SPEC[id.xy] = asuint(TEX_ASVGF_FILTERED_SPEC_B[id.xy].x);
}
\ No newline at end of file
diff --git a/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.cs b/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.cs
index cdeb0eb1..112c4c35 100644
--- a/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.cs
+++ b/TrueTrace/Resources/PostProcess/ReSTIRASVGF/ReSTIRASVGF.cs
@@ -131,31 +131,31 @@ public void init(int ScreenWidth, int ScreenHeight)
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_HF, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
- CommonFunctions.CreateRenderTexture(ref TEX_PT_NORMALS_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
- CommonFunctions.CreateRenderTexture(ref TEX_PT_NORMALS_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
+ CommonFunctions.CreateRenderTexture(ref TEX_PT_NORMALS_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref TEX_PT_NORMALS_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_LF_SH, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull4);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_LF_SH, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull4);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull2);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_LF_COCG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref AlbedoColorA, ScreenWidth, ScreenHeight, CommonFunctions.RTInt2);
CommonFunctions.CreateRenderTexture(ref AlbedoColorB, ScreenWidth, ScreenHeight, CommonFunctions.RTInt2);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_HF, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_HF, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
- CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PING_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_ATROUS_PONG_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
CommonFunctions.CreateRenderTexture(ref ASVGF_FILTERED_SPEC_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
CommonFunctions.CreateRenderTexture(ref ASVGF_FILTERED_SPEC_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_SH_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_SH_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
- CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_A, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
- CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_B, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_A, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
+ CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_COLOR_LF_COCG_B, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref MetallicA, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref MetallicB, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
- CommonFunctions.CreateRenderTexture(ref ReflectedRefractedTex, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
- CommonFunctions.CreateRenderTexture(ref ReflectedRefractedTexPrev, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
+ CommonFunctions.CreateRenderTexture(ref ReflectedRefractedTex, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
+ CommonFunctions.CreateRenderTexture(ref ReflectedRefractedTexPrev, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_MOMENTS_HF_B, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
CommonFunctions.CreateRenderTexture(ref ASVGF_HIST_MOMENTS_HF_A, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf4);
CommonFunctions.CreateRenderTexture(ref LFVarianceA, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTFull1);
@@ -166,7 +166,7 @@ public void init(int ScreenWidth, int ScreenHeight)
CommonFunctions.CreateRenderTexture(ref ASVGF_GRAD_LF_PONG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref ASVGF_GRAD_HF_SPEC_PONG, ScreenWidth / 3, ScreenHeight / 3, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref InputLFSH, ScreenWidth, ScreenHeight, CommonFunctions.RTFull4);
- CommonFunctions.CreateRenderTexture(ref InputLFCOCG, ScreenWidth, ScreenHeight, CommonFunctions.RTFull2);
+ CommonFunctions.CreateRenderTexture(ref InputLFCOCG, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref TEX_PT_COLOR_SPEC, ScreenWidth, ScreenHeight, CommonFunctions.RTFull1);
CommonFunctions.CreateRenderTexture(ref CorrectedDistanceTexA, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
CommonFunctions.CreateRenderTexture(ref CorrectedDistanceTexB, ScreenWidth, ScreenHeight, CommonFunctions.RTHalf2);
@@ -201,8 +201,8 @@ public void Do(ref ComputeBuffer _ColorBuffer,
shader.SetVector("Forward", camera.transform.forward);
shader.SetFloat("FarPlane", camera.farClipPlane);
shader.SetFloat("NearPlane", camera.nearClipPlane);
- shader.SetMatrix("_CameraToWorld", camera.cameraToWorldMatrix);
- shader.SetMatrix("_CameraInverseProjection", camera.projectionMatrix.inverse);
+ shader.SetMatrix("CamToWorld", camera.cameraToWorldMatrix);
+ shader.SetMatrix("CamInvProj", camera.projectionMatrix.inverse);
shader.SetTextureFromGlobal(DistanceCorrection, "Depth", "_CameraDepthTexture");
cmd.SetComputeTextureParam(shader, DistanceCorrection, "TEX_PT_VIEW_DEPTH_AWRITE", EvenFrame ? CorrectedDistanceTexA : CorrectedDistanceTexB);
cmd.DispatchCompute(shader, DistanceCorrection, Mathf.CeilToInt((ScreenWidth) / 32.0f), Mathf.CeilToInt((ScreenHeight) / 32.0f), 1);
@@ -212,7 +212,7 @@ public void Do(ref ComputeBuffer _ColorBuffer,
cmd.SetComputeFloatParam(shader, "ResRatio", ResolutionRatio);
shader.SetBool("UseExposure", DoExposure);
shader.SetFloat("IndirectBoost", IndirectBoost);
- shader.SetBuffer(CopyData, "PerPixelRadiance", _ColorBuffer);
+ shader.SetBuffer(CopyData, "GlobalColors", _ColorBuffer);
shader.SetBuffer(CopyData, "ExposureBuffer", ExposureModifier);
shader.SetBuffer(Atrous, "ExposureBuffer", ExposureModifier);
shader.SetTexture(CopyData, "ScreenSpaceInfo", ScreenSpaceInfo);
@@ -290,7 +290,7 @@ public void Do(ref ComputeBuffer _ColorBuffer,
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_HIST_COLOR_LF_COCG_B", (!EvenFrame ? ASVGF_HIST_COLOR_LF_COCG_A : ASVGF_HIST_COLOR_LF_COCG_B));
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_HIST_COLOR_HF", ASVGF_HIST_COLOR_HF);
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_FILTERED_SPEC_B", (!EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
- cmd.SetComputeTextureParam(shader, Temporal, "IMG_ASVGF_ATROUS_PING_SPEC", (EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
+ cmd.SetComputeTextureParam(shader, Temporal, "IMG_ASVGF_ATROUS_PING_SPEC2", (EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
cmd.SetComputeTextureParam(shader, Temporal, "TEX_PT_COLOR_SPEC", TEX_PT_COLOR_SPEC);
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_HIST_MOMENTS_HF_B", (!EvenFrame ? ASVGF_HIST_MOMENTS_HF_A : ASVGF_HIST_MOMENTS_HF_B));
cmd.SetComputeTextureParam(shader, Temporal, "TEX_ASVGF_GRAD_LF_PONG", ASVGF_GRAD_LF_PONG);
@@ -312,7 +312,13 @@ public void Do(ref ComputeBuffer _ColorBuffer,
cmd.EndSample("ASVGF Temporal Kernel");
shader.SetBool("DiffRes", ResolutionRatio != 1.0f);
- cmd.CopyTexture((EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B), ASVGF_ATROUS_PING_SPEC);
+ // cmd.CopyTexture((EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B), ASVGF_ATROUS_PING_SPEC);
+ cmd.BeginSample("COPY A");
+ cmd.SetComputeTextureParam(shader, DistanceCorrection + 1, "TEX_ASVGF_FILTERED_SPEC_B", (EvenFrame ? ASVGF_FILTERED_SPEC_A : ASVGF_FILTERED_SPEC_B));
+ cmd.SetComputeTextureParam(shader, DistanceCorrection + 1, "IMG_ASVGF_ATROUS_PING_SPEC", ASVGF_ATROUS_PING_SPEC);
+ cmd.DispatchCompute(shader, DistanceCorrection + 1, Mathf.CeilToInt((ScreenWidth) / 32.0f), Mathf.CeilToInt((ScreenHeight) / 32.0f), 1);
+ cmd.EndSample("COPY A");
+
cmd.BeginSample("ASVGF Atrous LF: " + 0);
cmd.SetComputeIntParam(shader, "iteration", 0);
cmd.SetComputeTextureParam(shader, Atrous_LF, "TEX_PT_NORMALS_A", (EvenFrame ? TEX_PT_NORMALS_A : TEX_PT_NORMALS_B));
@@ -375,7 +381,7 @@ public void Do(ref ComputeBuffer _ColorBuffer,
cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_LF_SH", ASVGF_ATROUS_PONG_LF_SH);
cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_ATROUS_PING_LF_COCG", ASVGF_ATROUS_PONG_LF_COCG);
- cmd.SetComputeBufferParam(shader, Atrous, "PerPixelRadiance", _ColorBuffer);
+ cmd.SetComputeBufferParam(shader, Atrous, "GlobalColors", _ColorBuffer);
cmd.SetComputeTextureParam(shader, Atrous, "IMG_ASVGF_COLOR", Output);
cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_GRAD_LF_PONG", ASVGF_GRAD_LF_PONG);
cmd.SetComputeTextureParam(shader, Atrous, "TEX_ASVGF_GRAD_HF_SPEC_PONG", ASVGF_GRAD_HF_SPEC_PONG);
diff --git a/TrueTrace/Resources/RayTracingMaster.cs b/TrueTrace/Resources/RayTracingMaster.cs
index 02b47365..2e71a10a 100644
--- a/TrueTrace/Resources/RayTracingMaster.cs
+++ b/TrueTrace/Resources/RayTracingMaster.cs
@@ -15,7 +15,7 @@ public class RayTracingMaster : MonoBehaviour
[HideInInspector] public AtmosphereGenerator Atmo;
[HideInInspector] public AssetManager Assets;
private ReSTIRASVGF ReSTIRASVGFCode;
- public Denoiser Denoisers;
+ private Denoiser Denoisers;
private ASVGF ASVGFCode;
private bool Abandon = false;
#if UseOIDN
@@ -145,7 +145,7 @@ public static void WriteString(RayTracingObject OBJtoWrite, string NameIndex) {
public static List _rayTracingLights = new List();
- public Vector2 CurrentHorizonalPatch;
+ [HideInInspector] public Vector2 CurrentHorizonalPatch;
private float _lastFieldOfView;
[HideInInspector] public int FramesSinceStart2;
@@ -157,8 +157,9 @@ public static void WriteString(RayTracingObject OBJtoWrite, string NameIndex) {
[HideInInspector] public static bool DoCheck = false;
[HideInInspector] public bool PrevReSTIRGI = false;
- public bool DoPanorama = false;
- public TTSettings LocalTTSettings;
+ [HideInInspector] public bool DoPanorama = false;
+ [HideInInspector] public bool DoChainedImages = false;
+ [HideInInspector] public TTSettings LocalTTSettings;
public static bool SceneIsRunning = false;
@@ -279,6 +280,10 @@ unsafe public void Start2()
Denoisers = new Denoiser();
Denoisers.Initialized = false;
}
+ public void Start() {
+ DoPanorama = false;
+ DoChainedImages = false;
+ }
void Reset() {
LoadTT();
@@ -522,7 +527,7 @@ private void SetShaderParameters(CommandBuffer cmd)
SetInt("screen_width", SourceWidth, cmd);
SetInt("screen_height", SourceHeight, cmd);
SetInt("MaxBounce", LocalTTSettings.bouncecount - 1, cmd);
- SetInt("frames_accumulated", _currentSample % 65000, cmd);
+ SetInt("frames_accumulated", _currentSample, cmd);
SetInt("ReSTIRGISpatialCount", LocalTTSettings.ReSTIRGISpatialCount, cmd);
SetInt("ReSTIRGITemporalMCap", LocalTTSettings.ReSTIRGITemporalMCap, cmd);
SetInt("curframe", FramesSinceStart2, cmd);
@@ -534,6 +539,7 @@ private void SetShaderParameters(CommandBuffer cmd)
SetInt("MaterialCount", Assets.MatCount, cmd);
SetInt("PartialRenderingFactor", LocalTTSettings.DoPartialRendering ? LocalTTSettings.PartialRenderingFactor : 1, cmd);
+ SetBool("DoPanorama", DoPanorama);
SetBool("ClayMode", LocalTTSettings.ClayMode);
SetBool("ImprovedPrimaryHit", LocalTTSettings.ImprovedPrimaryHit);
SetBool("UseRussianRoulette", LocalTTSettings.UseRussianRoulette);
@@ -915,7 +921,7 @@ private void GenerateRays(CommandBuffer cmd) {
cmd.EndSample("ReSTIR GI Reproject");
} else {
cmd.BeginSample("Primary Ray Generation");
- cmd.DispatchCompute(GenerateShader, (DoPanorama ? GenPanoramaKernel : ((LocalTTSettings.UseASVGF && !LocalTTSettings.UseReSTIRGI) ? GenASVGFKernel : GenKernel)), Mathf.CeilToInt(SourceWidth / 16.0f), Mathf.CeilToInt(SourceHeight / 16.0f), 1);
+ cmd.DispatchCompute(GenerateShader, (DoChainedImages ? GenPanoramaKernel : ((LocalTTSettings.UseASVGF && !LocalTTSettings.UseReSTIRGI) ? GenASVGFKernel : GenKernel)), Mathf.CeilToInt(SourceWidth / 16.0f), Mathf.CeilToInt(SourceHeight / 16.0f), 1);
cmd.EndSample("Primary Ray Generation");
}
}
@@ -1091,7 +1097,7 @@ private void Render(RenderTexture destination, CommandBuffer cmd)
#if UseOIDN
if(LocalTTSettings.UseOIDN && SampleCount > LocalTTSettings.OIDNFrameCount) {
- if(DoPanorama) {
+ if(DoChainedImages) {
cmd.SetComputeBufferParam(ShadingShader, TTtoOIDNKernelPanorama, "OutputBuffer", ColorBuffer);
ShadingShader.SetTexture(TTtoOIDNKernelPanorama, "Result", _FinalTex);
cmd.DispatchCompute(ShadingShader, TTtoOIDNKernelPanorama, Mathf.CeilToInt(SourceWidth / 16.0f), Mathf.CeilToInt(SourceHeight / 16.0f), 1);
diff --git a/TrueTrace/Resources/Utility/MaterialMappings.xml b/TrueTrace/Resources/Utility/MaterialMappings.xml
index 1b4734f8..d43fdc7e 100644
--- a/TrueTrace/Resources/Utility/MaterialMappings.xml
+++ b/TrueTrace/Resources/Utility/MaterialMappings.xml
@@ -7399,4 +7399,49 @@
null
null
+
+ Shader Graphs/TrueTrace_Core
+
+
+ 0
+ -4
+ _MainTex
+
+
+ 2
+ -3
+ _MainTex_3
+
+
+ 3
+ -4
+ _Emmision
+
+
+ 4
+ 0
+ _MainTex_1
+
+
+ 5
+ 0
+ _MainTex_2
+
+
+ 1
+ 0
+ _Alpha
+
+
+ null
+ null
+ false
+ false
+ false
+ null
+ null
+ null
+ null
+ null
+
\ No newline at end of file
diff --git a/TrueTrace/Resources/Utility/PanoramaDoer.cs b/TrueTrace/Resources/Utility/PanoramaDoer.cs
index 1179886a..e904196a 100644
--- a/TrueTrace/Resources/Utility/PanoramaDoer.cs
+++ b/TrueTrace/Resources/Utility/PanoramaDoer.cs
@@ -1,51 +1,85 @@
+#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
+using System;
+ using UnityEngine.Profiling;
+using System.Reflection;
+
namespace TrueTrace {
public class PanoramaDoer : MonoBehaviour
{
RayTracingMaster RayMaster;
+ public Camera[] Cameras;
public float TimeBetweenSegments = 10f;
public int MaxSamples = 10000;
+ private int CurrentCamera = 0;
+ public Vector2Int FinalAtlasSize = new Vector2Int(10000, 5000);
private bool PrevPanorama = false;
private float waitedTime = 0;
- private int HorizontalSegments = 10;
+ public int HorizontalSegments = 10;
private int CurrentSegment = 0;
private Texture2D[] TexArray;
+
+ void RemoveResolution(int index)
+ {
+ Type gameViewSizes = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes");
+ Type generic = typeof(ScriptableSingleton<>).MakeGenericType(gameViewSizes);
+ MethodInfo getGroup = gameViewSizes.GetMethod("GetGroup");
+ object instance = generic.GetProperty("instance").GetValue(null, null);
+ object group = getGroup.Invoke(instance, new object[] { (int)GameViewSizeGroupType.Standalone });
+ MethodInfo removeCustomSize = getGroup.ReturnType.GetMethod("RemoveCustomSize");
+ removeCustomSize.Invoke(group, new object[] { index });
+ }
+
+ int GetCount()
+ {
+ Type gameViewSizes = typeof(Editor).Assembly.GetType("UnityEditor.GameViewSizes");
+ Type generic = typeof(ScriptableSingleton<>).MakeGenericType(gameViewSizes);
+ MethodInfo getGroup = gameViewSizes.GetMethod("GetGroup");
+ object instance = generic.GetProperty("instance").GetValue(null, null);
+ PropertyInfo currentGroupType = instance.GetType().GetProperty("currentGroupType");
+ GameViewSizeGroupType groupType = (GameViewSizeGroupType)(int)currentGroupType.GetValue(instance, null);
+ object group = getGroup.Invoke(instance, new object[] { (int)groupType });
+ MethodInfo getBuiltinCount = group.GetType().GetMethod("GetBuiltinCount");
+ MethodInfo getCustomCount = group.GetType().GetMethod("GetCustomCount");
+ return (int)getBuiltinCount.Invoke(group, null) + (int)getCustomCount.Invoke(group, null);
+ }
+
public void Start() {
RayMaster = GameObject.Find("Scene").GetComponent();
- HorizontalSegments = Mathf.CeilToInt(10000.0f / (float)Screen.width);
+ // HorizontalSegments = Mathf.CeilToInt(FinalAtlasSize.x / (float)Screen.width);
Application.runInBackground = true;
RayMaster.DoPanorama = false;
+ RayMaster.DoChainedImages = false;
+ }
+ public void OnDisable() {
+ if(RayMaster.DoChainedImages) RemoveResolution(GetCount() - 1);
}
private void FinalizePanorama() {
- Color[] FinalAtlasData = new Color[10000 * 5000];
+ Color[] FinalAtlasData = new Color[FinalAtlasSize.x * FinalAtlasSize.y];
for(int iter = 0; iter < HorizontalSegments; iter++) {
int width = TexArray[iter].width;
int height = TexArray[iter].height;
Color[] CurrentData = TexArray[iter].GetPixels(0);
- int XOffset = iter * Mathf.CeilToInt(10000.0f / (float)HorizontalSegments);
+ int XOffset = iter * Mathf.CeilToInt((float)FinalAtlasSize.x / (float)HorizontalSegments);
// int YOffset = iter * Mathf.CeilToInt(5000.0f / 5000.0f);
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++) {
int IndexChild = i + j * width;
- int IndexFinal = (i + XOffset) + (j) * 10000;
- FinalAtlasData[IndexFinal] = CurrentData[IndexChild];
+ int IndexFinal = (i + XOffset) + (j) * FinalAtlasSize.x;
+ FinalAtlasData[IndexFinal] = new Color(CurrentData[IndexChild].r, CurrentData[IndexChild].g, CurrentData[IndexChild].b, 1);
}
}
DestroyImmediate(TexArray[iter]);
}
- TexArray = null;
- Texture2D FinalAtlas = new Texture2D(10000, 5000);
+ Texture2D FinalAtlas = new Texture2D(FinalAtlasSize.x, FinalAtlasSize.y);
FinalAtlas.SetPixels(FinalAtlasData, 0);
FinalAtlas.Apply();
System.IO.File.WriteAllBytes(PlayerPrefs.GetString("ScreenShotPath") + "/" + System.DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".png", FinalAtlas.EncodeToPNG());
-
- Application.runInBackground = false;
- EditorApplication.isPlaying = false;
}
public void Init() {
RayMaster.SampleCount = 0;
@@ -53,12 +87,18 @@ public void Init() {
RayMaster._currentSample = 0;
TexArray = new Texture2D[HorizontalSegments];
PrevPanorama = true;
+ CurrentCamera = 0;
+ if(Cameras == null || Cameras.Length == 0) {
+ Cameras = new Camera[1];
+ if(RayTracingMaster._camera != null)
+ Cameras[0] = RayTracingMaster._camera;
+ }
}
IEnumerator RecordFrame()
{
yield return new WaitForEndOfFrame();
- if(RayMaster.DoPanorama && TexArray != null) {
+ if(RayMaster.DoChainedImages && TexArray != null) {
if(PrevPanorama) {
PrevPanorama = false;
RayMaster.SampleCount = 0;
@@ -68,10 +108,10 @@ IEnumerator RecordFrame()
waitedTime += Time.deltaTime;
if (RayMaster.FramesSinceStart >= MaxSamples || waitedTime >= TimeBetweenSegments) {
waitedTime = 0;
- if(!System.IO.Directory.Exists(Application.dataPath + "/TempPanoramas")) {
- AssetDatabase.CreateFolder("Assets", "TempPanoramas");
+ if(!System.IO.Directory.Exists(Application.dataPath.Replace("/Assets", "") + "/TempPanoramas")) {
+ System.IO.Directory.CreateDirectory(Application.dataPath.Replace("/Assets", "") + "/TempPanoramas");
}
- ScreenCapture.CaptureScreenshot(Application.dataPath + "/TempPanoramas/" + CurrentSegment + ".png");
+ ScreenCapture.CaptureScreenshot(Application.dataPath.Replace("/Assets", "") + "/TempPanoramas/" + CurrentSegment + ".png");
TexArray[CurrentSegment] = ScreenCapture.CaptureScreenshotAsTexture();
CurrentSegment++;
RayMaster.SampleCount = 0;
@@ -81,8 +121,20 @@ IEnumerator RecordFrame()
if(CurrentSegment == HorizontalSegments) {
CurrentSegment = 0;
waitedTime = 0;
- RayMaster.DoPanorama = false;
FinalizePanorama();
+ CurrentCamera++;
+ if(CurrentCamera < Cameras.Length) {
+ Cameras[CurrentCamera - 1].gameObject.SetActive(false);
+ Cameras[CurrentCamera].gameObject.SetActive(true);
+ RayMaster.TossCamera(Cameras[CurrentCamera]);
+ } else {
+ RemoveResolution(GetCount() - 1);
+ RayMaster.DoPanorama = false;
+ RayMaster.DoChainedImages = false;
+ Application.runInBackground = false;
+ EditorApplication.isPlaying = false;
+ }
+
}
}
}
@@ -92,4 +144,5 @@ public void LateUpdate()
StartCoroutine(RecordFrame());
}
}
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file