Skip to content

Commit 87e1edb

Browse files
committed
fixes & improvements
1 parent 67e3fd7 commit 87e1edb

19 files changed

+516
-451
lines changed

Fractals Project/Assets/Resources/Apps.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"Name": "The Project",
4-
"Description": "This program is a collection of all the fractals, games and other little projects that I have programmed as part of my Matura Paper.\nThe name of the paper is \"Fraktale und ihre Anwendung im Game-Design\". In it I analyze different fractals, explain how I implemented them and discuss different applications.\n\nBy selecting one of the apps on the left a quick description, the controls and some additional info about the app will be displayed. An app can be loaded by clicking the LOAD button on the bottom right of the screen.\nBy pressing R inside an app the Options menu will be opened, in which the parameters and other setting of the app can be modified. The F12 button can be used to take a screenshot. To exit the app simply press ESCAPE or click the arrow on the top left of the screen.\n\nI recommend having a decent graphics card to run this program unless you enjoy stop motion fractals.\n\nThe screenshots are saved at: C:/Users/[User]/AppData/LocalLow/srpnt3/Fractals/screenshots.\n\nThe source code of \"Fractals\" is available on GitHub: https://github.com/srpnt3/Fractals.",
4+
"Description": "This program is a collection of all the fractals, games and other little projects that I have programmed as part of my matriculation project (Maturaarbeit).\nThe name of the paper is \"Fraktale und ihre Anwendung im Game-Design\". In it I analyze different fractals, explain how I implemented them and discuss different applications.\n\nBy selecting one of the apps on the left a quick description, the controls and some additional info about the app will be displayed. An app can be loaded by clicking the LOAD button on the bottom right of the screen.\nBy pressing R inside an app the Options menu will be opened, in which the parameters and other setting of the app can be modified. The F12 button can be used to take a screenshot. To exit the app simply press ESCAPE or click the arrow on the top left of the screen.\n\nI recommend having a decent graphics card to run this program unless you enjoy stop motion fractals.\n\nThe screenshots are saved at: C:/Users/[User]/AppData/LocalLow/srpnt3/Fractals/screenshots.\n\nThe source code of \"Fractals\" is available on GitHub: https://github.com/srpnt3/Fractals.",
55
"Type": false,
66
"Size": 0,
77
"Date": ""
@@ -57,7 +57,7 @@
5757
},
5858
{
5959
"Name": "Octahedron Flake",
60-
"Description": "A cooler version of the Sierpinski Triangle that consists of octahedrons instead of pyramids.\n\nClick on the screen to toggle between a normal mouse and the camera controls.\nWhile in camera mode use the mouse to turn the fractal and the scroll wheel to zoom.",
60+
"Description": "A cooler version of the Sierpinski Triangle that consists of octahedra instead of pyramids.\n\nClick on the screen to toggle between a normal mouse and the camera controls.\nWhile in camera mode use the mouse to turn the fractal and the scroll wheel to zoom.",
6161
"Type": true,
6262
"Size": 3550,
6363
"Date": "05 MAY"

Fractals Project/Assets/Scripts/FRAX/FRAX.compute

+2-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ float2 March(Ray ray) {
115115
return float2(s / float(steps), length(eye - ray.origin));
116116
}
117117

118-
// from https://answers.unity.com/questions/142958/compute-distance-from-depth-value.html
119118
float DecodeDepth(float d) {
120119
float a = zFar / (zFar - zNear);
121120
float b = zFar * zNear / (zNear - zFar);
@@ -141,11 +140,10 @@ void CSMain (uint3 id : SV_DispatchThreadID) {
141140

142141
float2 res = March(ray);
143142
float4 ao = res.x * accent;
144-
if (DecodeDepth(Source[id.xy].w) > res.y) {
143+
if (DecodeDepth(Source[id.xy].w) > res.y)
145144
Texture[id.xy] = background + ao;
146-
} else {
145+
else
147146
Texture[id.xy] = Source[id.xy];
148-
}
149147
float a = DecodeDepth(Source[id.xy].w);
150148
float b = res.y;
151149

Fractals Project/Assets/Scripts/FRAX/ShipController.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ private void Start() {
2727
private void Update() {
2828

2929
// update values
30-
position[1] = c.throttle * 10;
30+
position[1] = c.throttle * 9;
3131
UpdateValue(ref position, -3, 20);
32-
roll[1] = c.roll * 10;
32+
roll[1] = c.roll * 7;
3333
UpdateValue(ref roll, -5, 5);
34-
yaw[1] = c.yaw * 4;
34+
yaw[1] = c.yaw * 3;
3535
UpdateValue(ref yaw, -2, 2);
36-
pitch[1] = c.pitch * 4;
36+
pitch[1] = c.pitch * 3;
3737
UpdateValue(ref pitch, -2, 2);
3838

3939

@@ -51,10 +51,10 @@ private void Update() {
5151
private void UpdateValue(ref Vector3 v, float min, float max) { // min and max velocity
5252
v[0] += v[1] * Time.deltaTime; // velocity += acceleration
5353
if (v[0] < 0) { // |velocity| -= "air resistance"
54-
v[0] += v[2] * Time.deltaTime;
54+
if (v[1] == 0) v[0] += v[2] * Time.deltaTime;
5555
v[0] = Mathf.Clamp(v[0], min, 0);
5656
} else if (v[0] > 0) {
57-
v[0] -= v[2] * Time.deltaTime;
57+
if (v[1] == 0) v[0] -= v[2] * Time.deltaTime;
5858
v[0] = Mathf.Clamp(v[0], 0, max);
5959
}
6060
}

Fractals Project/Assets/Scripts/Mandelbox/Mandelbox.compute

+17-27
Original file line numberDiff line numberDiff line change
@@ -34,54 +34,45 @@ Data DataConstr(float n, float3 p) {
3434

3535
// sphere fold from http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/
3636
void SphereFold(inout float3 z, inout float dz) {
37-
38-
float fixedRadius = 1;
39-
float fixedRadius2 = fixedRadius * fixedRadius;
40-
float minRadius2 = 0.5 * 0.5;
41-
37+
float fixedRadius = 1, minRadius = 0.5;
38+
float fixedRadius2 = pow(fixedRadius, 2), minRadius2 = pow(minRadius, 2);
4239
float r2 = dot(z, z);
40+
4341
if (fixedRadius < minRadius2) {
4442
float temp = (fixedRadius2 / minRadius2);
45-
z *= temp;
46-
dz *= temp;
43+
z *= temp, dz *= temp;
4744
} else if (r2 < fixedRadius2) {
48-
float temp =(fixedRadius2 / r2);
49-
z *= temp;
50-
dz *= temp;
45+
float temp = (fixedRadius2 / r2);
46+
z *= temp, dz *= temp;
5147
}
5248
}
5349

5450
// box fold from http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/
55-
void BoxFold(inout float3 z, inout float dz) {
51+
void BoxFold(inout float3 z) {
5652
float foldingLimit = 1;
5753
z = clamp(z, -foldingLimit, foldingLimit) * 2.0 - z;
5854
}
5955

6056
// orbit trap
61-
float3 Trap(float3 z, float3 trap) {
57+
void Trap(float3 z, inout float3 trap) {
6258
if (length(z) < length(trap))
6359
trap = z;
64-
return trap;
6560
}
6661

6762
// mandelbox distance estimator from http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/
6863
Data DE(float3 p) {
69-
70-
float3 trap = p;
71-
float3 z = p;
64+
float3 z = p, trap = p;
7265
float dr = 1.0;
73-
int i = 0;
74-
while (i < Iterations) {
75-
BoxFold(z, dr);
76-
SphereFold(z, dr);
77-
78-
z *= Scale;
79-
z += Julia ? C : p;
80-
dr = dr * abs(Scale) + 1.0;
66+
67+
for (int i = 0; i < Iterations; i++) {
68+
BoxFold(z); // box fold
69+
SphereFold(z, dr); // sphere fold
8170

82-
trap = Trap(z, trap);
71+
z *= Scale; // scale
72+
z += Julia ? C : p; // c
73+
dr = dr * abs(Scale) + 1.0; // dr
8374

84-
i++;
75+
Trap(z, trap); // trap
8576
}
8677

8778
return DataConstr(length(z) / abs(dr), trap);
@@ -116,7 +107,6 @@ Data March(Ray ray) {
116107
s++; // next iteration
117108
}
118109

119-
//return float3(1 - s / float(steps), length(eye - ray.origin), d.y / 10);
120110
return DataConstr(abs(1 - (s / steps)), d.p);
121111
}
122112

Fractals Project/Assets/Scripts/Mandelbulb/Mandelbulb.compute

+7-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool Alt;
2222

2323
// constants
2424
static const int steps = 500;
25-
static const float epsilon = 0.00001;
25+
static const float epsilon = 0.00004;
2626

2727
// structs
2828
struct Ray { float3 origin; float3 direction; };
@@ -42,14 +42,13 @@ Ray CreateCameraRay(float2 uv) {
4242
return CreateRay(origin, direction);
4343
}
4444

45+
4546
// mandelbulb distance estimator from http://blog.hvidtfeldts.net/index.php/2011/09/distance-estimated-3d-fractals-v-the-mandelbulb-different-de-approximations/
4647
float2 DE(float3 p) {
4748
float3 z = p;
48-
float dr = 1.0;
49-
float r = 0.0;
49+
float r, dr = 1;
5050

51-
int i = 0;
52-
while(i < Iterations) {
51+
for(int i = 0; i < Iterations; i++) {
5352
r = length(z);
5453

5554
if (r > 3) break;
@@ -68,12 +67,10 @@ float2 DE(float3 p) {
6867
if (Alt) z = zr * float3(cos(theta) * cos(phi), cos(theta) * sin(phi), sin(theta));
6968
else z = zr * float3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
7069
z += Julia * C + (1 - Julia) * p;
71-
72-
// next iteration
73-
i++;
7470
}
75-
float dst = 0.5 * log(r) * r / dr;
76-
return float2(dst / 2, sin(i));
71+
72+
float dst = 0.1 * log(r) * r / dr;
73+
return float2(dst, sin(i));
7774
}
7875

7976
// cast a ray and return the result

Fractals Project/Assets/Scripts/MengerSponge/MengerSponge.compute

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ float DEBox2D(float2 p, float s) {
4949
return length(max(d, 0.0)) + min(max(d.x, d.y), 0);
5050
}
5151

52-
// cross distance estimator from https://iquilezles.org/www/articles/distfunctions/distfunctions.htm
52+
// cross distance estimator from https://iquilezles.org/www/articles/menger/menger.htm
5353
float DECross(float3 p, float s) {
5454
s = s / 3;
5555
float d = DEBox2D(p.xy, s);
@@ -123,6 +123,5 @@ void CSMain (uint3 id : SV_DispatchThreadID) {
123123

124124
float2 res = March(ray);
125125
float4 ao = res.x * float4(0.3, 0.6, 0.7, 1);
126-
float4 fog = 1 / (res.y + 1);
127126
Texture[id.xy] = Source[id.xy] + ao;
128127
}

Fractals Project/Assets/Scripts/OctahedronFlake/OctahedronFlake.compute

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,20 @@ float DEOctahedron(float3 p, float s) {
3434
return length(float3(q.x, q.y - s + k, q.z - k));
3535
}
3636

37-
// fold space from http://blog.hvidtfeldts.net/index.php/2011/08/distance-estimated-3d-fractals-iii-folding-space
37+
// plane fold from http://blog.hvidtfeldts.net/index.php/2011/08/distance-estimated-3d-fractals-iii-folding-space
3838
float3 Fold(float3 p, float3 n) {
3939
return p - 2.0 * min(0.0, dot(p, n)) * n;
4040
}
4141

4242
// distance to scene
4343
float DE(float3 p) {
44-
int i = 0;
45-
while (i < Iterations) {
44+
for (int i = 0; i < Iterations; i++) {
4645
p *= SizeDec;
4746
p = Fold(p, normalize(float3(0, 1, 1)));
4847
p = Fold(p, normalize(float3(0, 1, -1)));
4948
p = Fold(p, normalize(float3(1, 1, 0)));
5049
p = Fold(p, normalize(float3(-1, 1, 0)));
5150
p -= float3(0, 1, 0) * Size;
52-
i++;
5351
}
5452
return DEOctahedron(p, Size) / pow(abs(SizeDec), i);
5553
}

Fractals Project/Assets/Scripts/Utils/AppManager.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
4+
using System.IO;
35
using Newtonsoft.Json;
46
using TMPro;
57
using UnityEngine;

Fractals Project/Assets/Scripts/Utils/ControlsHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void Update() {
8282
// orbit camera controls
8383
case App.CameraType.Orbit:
8484
Vector3 pos = app.transform.localPosition;
85-
float r = pos.magnitude - deltaZoom * Time.smoothDeltaTime * sensitivity / 30;
85+
float r = pos.magnitude - deltaZoom * sensitivity / 3000;
8686
Vector2 angles = app.CartesianCoordsToSphericalCoords(pos.normalized) + new Vector2(-cursor.x * Time.smoothDeltaTime * sensitivity, -cursor.y * Time.smoothDeltaTime * sensitivity);
8787
Vector3 vars = ClampOrbitVars(r, angles);
8888
t.localPosition = app.SphericalCoordsToCartesianCoords(vars.x, vars.y) * vars.z;

Fractals Project/Assets/Scripts/Utils/Gradients.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Colors.LCHColor[] LCHGradient(Colors.LCHColor a, Colors.LCHColor b, int s) {
6767
deltaH = (b.H - a.H) / (s + 1f);
6868
} else {
6969
deltaH = -(360f - Mathf.Abs(b.H - a.H)) / (s + 1);
70-
deltaH *= Mathf.Sign(b.H - a.H); // Sign function that H will go around the right way
70+
deltaH *= Mathf.Sign(b.H - a.H); // Sign function so that H will go around the right way
7171
}
7272

7373
// calculate and add the colors

Fractals Project/Assets/Shaders/DepthBuffer.shader

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
}
3131

3232
float4 frag(v2f i) : COLOR {
33+
34+
// actual important lines:
3335
float d = 1 - tex2D(_CameraDepthTexture, i.uv).x;
3436
return float4(1, 1, 1, 0) * tex2D(_MainTex, i.uv) + float4(0, 0, 0, d);
3537
}

Fractals Project/Packages/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"com.unity.collab-proxy": "1.3.8",
3+
"com.unity.collab-proxy": "1.3.9",
44
"com.unity.ext.nunit": "1.0.0",
55
"com.unity.ide.rider": "1.2.1",
66
"com.unity.ide.visualstudio": "2.0.2",

Fractals Project/Packages/packages-lock.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"com.unity.collab-proxy": {
4-
"version": "1.3.8",
4+
"version": "1.3.9",
55
"depth": 0,
66
"source": "registry",
77
"dependencies": {},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &1
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 61
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
13+
m_Name:
14+
m_EditorClassIdentifier:
15+
m_EnablePreviewPackages: 0
16+
m_EnablePackageDependencies: 0
17+
m_AdvancedSettingsExpanded: 1
18+
m_ScopedRegistriesSettingsExpanded: 1
19+
oneTimeWarningShown: 0
20+
m_Registries:
21+
- m_Id: main
22+
m_Name:
23+
m_Url: https://packages.unity.com
24+
m_Scopes: []
25+
m_IsDefault: 1
26+
m_Capabilities: 7
27+
m_UserSelectedRegistryName:
28+
m_UserAddingNewScopedRegistry: 0
29+
m_RegistryInfoDraft:
30+
m_ErrorMessage:
31+
m_Original:
32+
m_Id:
33+
m_Name:
34+
m_Url:
35+
m_Scopes: []
36+
m_IsDefault: 0
37+
m_Capabilities: 0
38+
m_Modified: 0
39+
m_Name:
40+
m_Url:
41+
m_Scopes:
42+
-
43+
m_SelectedScopeIndex: 0

Fractals Project/ProjectSettings/ProjectSettings.asset

+3-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ PlayerSettings:
136136
- {fileID: 0}
137137
- {fileID: 0}
138138
- {fileID: 0}
139-
- {fileID: 0}
140139
metroInputSource: 0
141140
wsaTransparentSwapchain: 0
142141
m_HolographicPauseOnTrackingLoss: 1
@@ -600,14 +599,17 @@ PlayerSettings:
600599
webGLDecompressionFallback: 0
601600
scriptingDefineSymbols:
602601
1: UNITY_POST_PROCESSING_STACK_V2
602+
4: UNITY_POST_PROCESSING_STACK_V2
603603
7: UNITY_POST_PROCESSING_STACK_V2
604604
13: UNITY_POST_PROCESSING_STACK_V2
605+
14: UNITY_POST_PROCESSING_STACK_V2
605606
19: UNITY_POST_PROCESSING_STACK_V2
606607
21: UNITY_POST_PROCESSING_STACK_V2
607608
25: UNITY_POST_PROCESSING_STACK_V2
608609
27: UNITY_POST_PROCESSING_STACK_V2
609610
28: UNITY_POST_PROCESSING_STACK_V2
610611
29: UNITY_POST_PROCESSING_STACK_V2
612+
30: UNITY_POST_PROCESSING_STACK_V2
611613
platformArchitecture: {}
612614
scriptingBackend: {}
613615
il2cppCompilerConfiguration: {}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 2020.1.2f1
2-
m_EditorVersionWithRevision: 2020.1.2f1 (7b32bc54ba47)
1+
m_EditorVersion: 2020.1.6f1
2+
m_EditorVersionWithRevision: 2020.1.6f1 (fc477ca6df10)

Images/FRAX/1.png

11.4 MB
Loading

0 commit comments

Comments
 (0)