Skip to content

Commit 8e3825e

Browse files
committed
Hotfixes
FINALLY fixed camera in unity 2022 or higher Fixed material presets
1 parent 1055192 commit 8e3825e

File tree

7 files changed

+209
-93
lines changed

7 files changed

+209
-93
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ A passion projects that has been going on for a while with the goal of bringing
4141
</br>
4242

4343
If you have any questions, or suggestions, etc. let me know either through github issues, my twitter, or my discord! I am always looking for more stuff to add, and more ways to make this project more user friendly or appealing for others to use
44-
## You can contact me easiest through my discord server(above) or my twitter(https://twitter.com/Pjbomb2)
44+
## You can contact me easiest through my discord server(above) or my twitter(https://x.com/Pjbomb2)
4545

4646

4747
## Notes:

TrueTrace.unitypackage

-67 MB
Binary file not shown.

TrueTrace/DemoScene.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ MonoBehaviour:
3131
PPToneMap: 0
3232
PPTAA: 0
3333
RenderScale: 1
34-
UseASVGF: 1
34+
UseASVGF: 0
3535
UseTAAU: 0
3636
ReSTIRGIUpdateRate: 7
3737
UseReSTIRGITemporal: 1
@@ -52,7 +52,7 @@ MonoBehaviour:
5252
SkyDesaturate: 0
5353
ClayColor: {x: 0.20754719, y: 0.20754719, z: 0.20754719}
5454
GroundColor: {x: 0.1, y: 0.1, z: 0.1}
55-
FireflyFrameCount: 0
55+
FireflyFrameCount: 533
5656
FireflyStrength: 1
5757
FireflyOffset: 0
5858
OIDNFrameCount: 122

TrueTrace/Editor/MasterMaterialEditor.cs

Lines changed: 187 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,197 @@
33
using UnityEngine;
44
using UnityEngine.UIElements;
55
using CommonVars;
6+
using System.IO;
7+
using System.Xml;
8+
using System.Xml.Serialization;
69

710
#if UNITY_EDITOR
811
#if UNITY_2021
912
#else
1013
using UnityEditor.UIElements;
1114
using UnityEditor;
1215
namespace TrueTrace {
16+
17+
18+
public class SavePopup2 : PopupWindowContent
19+
{
20+
string PresetName = "Null";
21+
RayTracingObject ThisOBJ;
22+
int SaveIndex;
23+
24+
public SavePopup2(RayTracingObject ThisOBJ, int SaveIndex) {
25+
this.ThisOBJ = ThisOBJ;
26+
this.SaveIndex = SaveIndex;
27+
}
28+
public override Vector2 GetWindowSize()
29+
{
30+
return new Vector2(460, 50);
31+
}
32+
33+
public override void OnGUI(Rect rect) {
34+
// Debug.Log("ONINSPECTORGUI");
35+
36+
PresetName = GUILayout.TextField(PresetName, 32);
37+
38+
if(GUILayout.Button("Save Preset")) {
39+
RayObjs PresetRays;
40+
int CopyIndex = -1;
41+
UnityEditor.AssetDatabase.Refresh();
42+
using (var A = new StringReader(Resources.Load<TextAsset>("Utility/MaterialPresets").text)) {
43+
var serializer = new XmlSerializer(typeof(RayObjs));
44+
PresetRays = serializer.Deserialize(A) as RayObjs;
45+
int RayReadCount = PresetRays.RayObj.Count;
46+
for(int i = 0; i < RayReadCount; i++) {
47+
if(PresetRays.RayObj[i].MatName.Equals(PresetName)) {
48+
CopyIndex = i;
49+
break;
50+
}
51+
}
52+
}
53+
RayObjectDatas TempRay = new RayObjectDatas() {
54+
ID = 0,
55+
MatName = PresetName,
56+
OptionID = (int)ThisOBJ.MaterialOptions[SaveIndex],
57+
TransCol = ThisOBJ.TransmissionColor[SaveIndex],
58+
BaseCol = ThisOBJ.BaseColor[SaveIndex],
59+
MetRemap = ThisOBJ.MetallicRemap[SaveIndex],
60+
RoughRemap = ThisOBJ.RoughnessRemap[SaveIndex],
61+
Emiss = ThisOBJ.emmission[SaveIndex],
62+
EmissCol = ThisOBJ.EmissionColor[SaveIndex],
63+
Rough = ThisOBJ.Roughness[SaveIndex],
64+
IOR = ThisOBJ.IOR[SaveIndex],
65+
Met = ThisOBJ.Metallic[SaveIndex],
66+
SpecTint = ThisOBJ.SpecularTint[SaveIndex],
67+
Sheen = ThisOBJ.Sheen[SaveIndex],
68+
SheenTint = ThisOBJ.SheenTint[SaveIndex],
69+
Clearcoat = ThisOBJ.ClearCoat[SaveIndex],
70+
ClearcoatGloss = ThisOBJ.ClearCoatGloss[SaveIndex],
71+
Anisotropic = ThisOBJ.Anisotropic[SaveIndex],
72+
Flatness = ThisOBJ.Flatness[SaveIndex],
73+
DiffTrans = ThisOBJ.DiffTrans[SaveIndex],
74+
SpecTrans = ThisOBJ.SpecTrans[SaveIndex],
75+
FollowMat = ThisOBJ.FollowMaterial[SaveIndex],
76+
ScatterDist = ThisOBJ.ScatterDist[SaveIndex],
77+
Spec = ThisOBJ.Specular[SaveIndex],
78+
AlphaCutoff = ThisOBJ.AlphaCutoff[SaveIndex],
79+
NormStrength = ThisOBJ.NormalStrength[SaveIndex],
80+
Hue = ThisOBJ.Hue[SaveIndex],
81+
Brightness = ThisOBJ.Brightness[SaveIndex],
82+
Contrast = ThisOBJ.Contrast[SaveIndex],
83+
Saturation = ThisOBJ.Saturation[SaveIndex],
84+
BlendColor = ThisOBJ.BlendColor[SaveIndex],
85+
BlendFactor = ThisOBJ.BlendFactor[SaveIndex],
86+
MainTexScaleOffset = ThisOBJ.MainTexScaleOffset[SaveIndex],
87+
SecondaryTextureScale = ThisOBJ.SecondaryTextureScale[SaveIndex],
88+
Rotation = ThisOBJ.Rotation[SaveIndex],
89+
Flags = ThisOBJ.Flags[SaveIndex]
90+
};
91+
if(CopyIndex != -1) PresetRays.RayObj[CopyIndex] = TempRay;
92+
else PresetRays.RayObj.Add(TempRay);
93+
94+
using(StreamWriter writer = new StreamWriter(Application.dataPath + "/TrueTrace/Resources/Utility/MaterialPresets.xml")) {
95+
var serializer = new XmlSerializer(typeof(RayObjs));
96+
serializer.Serialize(writer.BaseStream, PresetRays);
97+
UnityEditor.AssetDatabase.Refresh();
98+
}
99+
this.editorWindow.Close();
100+
}
101+
102+
103+
}
104+
}
105+
public class LoadPopup2 : PopupWindowContent
106+
{
107+
RayObjs PresetRays;
108+
Vector2 ScrollPosition;
109+
MasterMaterialEditor SourceWindow;
110+
public LoadPopup2(MasterMaterialEditor editor) {
111+
this.SourceWindow = editor;
112+
}
113+
private void CallEditorFunction(RayObjectDatas RayObj) {
114+
if(SourceWindow != null) {
115+
SourceWindow.LoadFunction(RayObj);
116+
}
117+
}
118+
public override Vector2 GetWindowSize()
119+
{
120+
return new Vector2(460, 250);
121+
}
122+
123+
public override void OnGUI(Rect rect) {
124+
UnityEditor.AssetDatabase.Refresh();
125+
using (var A = new StringReader(Resources.Load<TextAsset>("Utility/MaterialPresets").text)) {
126+
var serializer = new XmlSerializer(typeof(RayObjs));
127+
PresetRays = serializer.Deserialize(A) as RayObjs;
128+
}
129+
int PresetLength = PresetRays.RayObj.Count;
130+
ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, GUILayout.Width(460), GUILayout.Height(250));
131+
for(int i = 0; i < PresetLength; i++) {
132+
GUILayout.BeginHorizontal();
133+
if(GUILayout.Button(PresetRays.RayObj[i].MatName)) {CallEditorFunction(PresetRays.RayObj[i]); this.editorWindow.Close();}
134+
if(GUILayout.Button("Delete")) {
135+
PresetRays.RayObj.RemoveAt(i);
136+
using(StreamWriter writer = new StreamWriter(Application.dataPath + "/TrueTrace/Resources/Utility/MaterialPresets.xml")) {
137+
var serializer = new XmlSerializer(typeof(RayObjs));
138+
serializer.Serialize(writer.BaseStream, PresetRays);
139+
UnityEditor.AssetDatabase.Refresh();
140+
}
141+
OnGUI(new Rect(0,0,100,10));
142+
}
143+
GUILayout.EndHorizontal();
144+
}
145+
GUILayout.EndScrollView();
146+
}
147+
}
148+
149+
150+
13151
public class MasterMaterialEditor : EditorWindow {
14152
[MenuItem("TrueTrace/Master Material Editor")]
15153
public static void ShowWindow() {
16154
GetWindow<MasterMaterialEditor>("Material Editor");
17155
}
156+
int Selected2;
157+
RayTracingObject TempRTO2;
158+
public void LoadFunction(RayObjectDatas RayObj) {
159+
TempRTO2.MaterialOptions[Selected2] = (RayTracingObject.Options)RayObj.OptionID;
160+
TempRTO2.TransmissionColor[Selected2] = RayObj.TransCol;
161+
TempRTO2.BaseColor[Selected2] = RayObj.BaseCol;
162+
TempRTO2.MetallicRemap[Selected2] = RayObj.MetRemap;
163+
TempRTO2.RoughnessRemap[Selected2] = RayObj.RoughRemap;
164+
TempRTO2.emmission[Selected2] = RayObj.Emiss;
165+
TempRTO2.EmissionColor[Selected2] = RayObj.EmissCol;
166+
TempRTO2.Roughness[Selected2] = RayObj.Rough;
167+
TempRTO2.IOR[Selected2] = RayObj.IOR;
168+
TempRTO2.Metallic[Selected2] = RayObj.Met;
169+
TempRTO2.SpecularTint[Selected2] = RayObj.SpecTint;
170+
TempRTO2.Sheen[Selected2] = RayObj.Sheen;
171+
TempRTO2.SheenTint[Selected2] = RayObj.SheenTint;
172+
TempRTO2.ClearCoat[Selected2] = RayObj.Clearcoat;
173+
TempRTO2.ClearCoatGloss[Selected2] = RayObj.ClearcoatGloss;
174+
TempRTO2.Anisotropic[Selected2] = RayObj.Anisotropic;
175+
TempRTO2.Flatness[Selected2] = RayObj.Flatness;
176+
TempRTO2.DiffTrans[Selected2] = RayObj.DiffTrans;
177+
TempRTO2.SpecTrans[Selected2] = RayObj.SpecTrans;
178+
TempRTO2.FollowMaterial[Selected2] = RayObj.FollowMat;
179+
TempRTO2.ScatterDist[Selected2] = RayObj.ScatterDist;
180+
TempRTO2.Specular[Selected2] = RayObj.Spec;
181+
TempRTO2.AlphaCutoff[Selected2] = RayObj.AlphaCutoff;
182+
TempRTO2.NormalStrength[Selected2] = RayObj.NormStrength;
183+
TempRTO2.Hue[Selected2] = RayObj.Hue;
184+
TempRTO2.Brightness[Selected2] = RayObj.Brightness;
185+
TempRTO2.Contrast[Selected2] = RayObj.Contrast;
186+
TempRTO2.Saturation[Selected2] = RayObj.Saturation;
187+
TempRTO2.BlendColor[Selected2] = RayObj.BlendColor;
188+
TempRTO2.BlendFactor[Selected2] = RayObj.BlendFactor;
189+
TempRTO2.MainTexScaleOffset[Selected2] = RayObj.MainTexScaleOffset;
190+
TempRTO2.SecondaryTextureScale[Selected2] = RayObj.SecondaryTextureScale;
191+
TempRTO2.Rotation[Selected2] = RayObj.Rotation;
192+
TempRTO2.Flags[Selected2] = RayObj.Flags;
193+
TempRTO2.CallMaterialEdited(true);
194+
}
195+
196+
18197

19198
private List<TreeViewItemData<string>> TraverseChildren(Transform t, ref int id, int depth) {
20199
List<TreeViewItemData<string>> TempList = new List<TreeViewItemData<string>>();
@@ -258,11 +437,11 @@ public void CreateGUI() {
258437
MiscBar1.style.height = 20;
259438

260439
Slider RoughnessSlider = new Slider() {label = RTO.Flags[Selected].GetFlag(CommonFunctions.Flags.UseSmoothness) ? "Smoothness: " : "Roughness: ", value = RTO.Roughness[Selected], highValue = 1.0f, lowValue = 0};
261-
RoughnessSlider.RegisterValueChangedCallback(evt => {RTO.Roughness[Selected] = evt.newValue; RTO.CallMaterialEdited(true);});
440+
RoughnessSlider.RegisterValueChangedCallback(evt => {RTO.Roughness[Selected] = (RTO.Flags[Selected].GetFlag(CommonFunctions.Flags.UseSmoothness) ? (1.0f - evt.newValue) : evt.newValue); RTO.CallMaterialEdited(true);});
262441
RoughnessSlider.style.width = 350;
263442
RoughnessSlider.showInputField = true;
264443
Toggle IsSmoothness = new Toggle("Use Smoothness: ") {value = RTO.Flags[Selected].GetFlag(CommonFunctions.Flags.UseSmoothness)};
265-
IsSmoothness.RegisterValueChangedCallback(evt => {RTO.Flags[Selected] = CommonFunctions.SetFlagVar(RTO.Flags[Selected], CommonFunctions.Flags.UseSmoothness, evt.newValue); if(evt.newValue) RoughnessSlider.label = "Smoothness: "; else RoughnessSlider.label = "Roughness";RTO.CallMaterialEdited(true);});
444+
IsSmoothness.RegisterValueChangedCallback(evt => {RTO.Flags[Selected] = CommonFunctions.SetFlagVar(RTO.Flags[Selected], CommonFunctions.Flags.UseSmoothness, evt.newValue); if(evt.newValue) RoughnessSlider.label = "Smoothness: "; else RoughnessSlider.label = "Roughness";RTO.CallMaterialEdited(true); RTO.Roughness[Selected] = 1.0f - RTO.Roughness[Selected];});
266445

267446
Toggle InvertSmoothTex = new Toggle("Invert Roughness Tex: ") {value = RTO.Flags[Selected].GetFlag(CommonFunctions.Flags.InvertSmoothnessTexture)};
268447
InvertSmoothTex.RegisterValueChangedCallback(evt => {RTO.Flags[Selected] = CommonFunctions.SetFlagVar(RTO.Flags[Selected], CommonFunctions.Flags.InvertSmoothnessTexture, evt.newValue);RTO.CallMaterialEdited(true);});
@@ -425,19 +604,23 @@ public void CreateGUI() {
425604
RotationSlider.style.width = 350;
426605
RotationSlider.showInputField = true;
427606

607+
Button SavePresetButton = new Button(() => UnityEditor.PopupWindow.Show(new Rect(0,0,10,10), new SavePopup2(RTO, Selected))) {text = "Save Material Preset"};
608+
Button LoadPresetButton = new Button(() => {TempRTO2 = RTO; Selected2 = Selected; UnityEditor.PopupWindow.Show(new Rect(0,0,100,10), new LoadPopup2(this));}){text = "Load Material Preset"};
428609

429610
TempWindow.Add(new Label(RTO.name));
611+
TempWindow.Add(SavePresetButton);
612+
TempWindow.Add(LoadPresetButton);
430613
TempWindow.Add(MatTypePopup);
431614
TempWindow.Add(ColField);
432615
TempWindow.Add(EmissField);
433616
TempWindow.Add(EmissColField);
434617
TempWindow.Add(EmissionBar);
435618
TempWindow.Add(MiscBar1);
436619
TempWindow.Add(MiscBar2);
437-
TempWindow.Add(RoughnessSlider);
438-
TempWindow.Add(RoughnessMinMax);
439620
TempWindow.Add(MetallicSlider);
440621
TempWindow.Add(MetallicMinMax);
622+
TempWindow.Add(RoughnessSlider);
623+
TempWindow.Add(RoughnessMinMax);
441624

442625
TempWindow.Add(IORSlider);
443626
TempWindow.Add(SpecularSlider);

TrueTrace/Editor/RayTracingObjectEditor.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override void OnGUI(Rect rect) {
3232
if(GUILayout.Button("Save Preset")) {
3333
RayObjs PresetRays;
3434
int CopyIndex = -1;
35+
UnityEditor.AssetDatabase.Refresh();
3536
using (var A = new StringReader(Resources.Load<TextAsset>("Utility/MaterialPresets").text)) {
3637
var serializer = new XmlSerializer(typeof(RayObjs));
3738
PresetRays = serializer.Deserialize(A) as RayObjs;
@@ -97,7 +98,6 @@ public override void OnGUI(Rect rect) {
9798
}
9899
public class LoadPopup : PopupWindowContent
99100
{
100-
RayObjs PresetRays;
101101
Vector2 ScrollPosition;
102102
RayTracingObjectEditor SourceWindow;
103103
public LoadPopup(RayTracingObjectEditor editor) {
@@ -114,6 +114,8 @@ public override Vector2 GetWindowSize()
114114
}
115115

116116
public override void OnGUI(Rect rect) {
117+
RayObjs PresetRays;
118+
UnityEditor.AssetDatabase.Refresh();
117119
using (var A = new StringReader(Resources.Load<TextAsset>("Utility/MaterialPresets").text)) {
118120
var serializer = new XmlSerializer(typeof(RayObjs));
119121
PresetRays = serializer.Deserialize(A) as RayObjs;
@@ -241,11 +243,11 @@ public override void OnInspectorGUI() {
241243
EditorGUILayout.EndHorizontal();
242244
EditorGUILayout.EndVertical();
243245

246+
serializedObject.FindProperty("Metallic").GetArrayElementAtIndex(Selected).floatValue = EditorGUILayout.Slider("Metallic: ", t.Metallic[Selected], 0, 1);
247+
EditorGUILayout.MinMaxSlider("Metallic Remap: ", ref t.MetallicRemap[Selected].x, ref t.MetallicRemap[Selected].y, 0, 1);
244248
if(Flag.GetFlag(CommonFunctions.Flags.UseSmoothness)) serializedObject.FindProperty("Roughness").GetArrayElementAtIndex(Selected).floatValue = 1.0f - EditorGUILayout.Slider("Smoothness: ", 1.0f - t.Roughness[Selected], 0, 1);
245249
else serializedObject.FindProperty("Roughness").GetArrayElementAtIndex(Selected).floatValue = EditorGUILayout.Slider("Roughness: ", t.Roughness[Selected], 0, 1);
246250
EditorGUILayout.MinMaxSlider("Roughness Remap: ", ref t.RoughnessRemap[Selected].x, ref t.RoughnessRemap[Selected].y, 0, 1);
247-
serializedObject.FindProperty("Metallic").GetArrayElementAtIndex(Selected).floatValue = EditorGUILayout.Slider("Metallic: ", t.Metallic[Selected], 0, 1);
248-
EditorGUILayout.MinMaxSlider("Metallic Remap: ", ref t.MetallicRemap[Selected].x, ref t.MetallicRemap[Selected].y, 0, 1);
249251
serializedObject.FindProperty("IOR").GetArrayElementAtIndex(Selected).floatValue = EditorGUILayout.Slider("IOR: ", t.IOR[Selected], 1, 10);
250252
serializedObject.FindProperty("Specular").GetArrayElementAtIndex(Selected).floatValue = EditorGUILayout.Slider("Specular: ", t.Specular[Selected], 0, 1);
251253
serializedObject.FindProperty("SpecularTint").GetArrayElementAtIndex(Selected).floatValue = EditorGUILayout.Slider("Specular Tint: ", t.SpecularTint[Selected], 0, 1);

TrueTrace/Resources/Utility/FlyCamera.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33

44
namespace TrueTrace {
55
public class FlyCamera : MonoBehaviour {
6-
6+
bool isPaused = false;
7+
bool isPaused2 = false;
8+
void OnApplicationFocus(bool hasFocus)
9+
{
10+
isPaused = !hasFocus;
11+
}
12+
13+
void OnApplicationPause(bool pauseStatus)
14+
{
15+
isPaused = pauseStatus;
16+
}
717
/*
818
Writen by Windexglow 11-13-10. Use it, edit it, steal it I don't care.
919
Converted to C# 27-02-13 - no credit wanted.
@@ -45,8 +55,8 @@ void Update () {
4555
StopMovement = !Input.GetMouseButton(1);
4656

4757

48-
49-
lastMouse = new Vector3(-Input.GetAxisRaw("Mouse Y") * camSens, Input.GetAxisRaw("Mouse X") * camSens, 0 );
58+
if(!isPaused2) lastMouse = new Vector3(-Input.GetAxis("Mouse Y") * camSens, Input.GetAxis("Mouse X") * camSens, 0 );
59+
else lastMouse = Vector3.zero;
5060
lastMouse = new Vector3(transform.eulerAngles.x + lastMouse.x , transform.eulerAngles.y + lastMouse.y, 0);
5161
if(lastMouse.x < 280) {
5262
if(lastMouse.x < 95) {
@@ -83,6 +93,7 @@ void Update () {
8393
transform.Translate(p);
8494
}
8595
}
96+
isPaused2 = isPaused;
8697
}
8798

8899
private Vector3 GetBaseInput() { //returns the basic values, if it's 0 than it's not active.

0 commit comments

Comments
 (0)