Skip to content

Commit 2f36065

Browse files
committed
experiments and bug fixes
- experimented with DOF and Cross Eye 3D - fixed some bugs - random things...
1 parent 26ce909 commit 2f36065

25 files changed

+192
-190
lines changed

Fractals Project/Assets/Scenes/Mandelbox.unity

+1-142
Original file line numberDiff line numberDiff line change
@@ -730,146 +730,6 @@ CanvasRenderer:
730730
m_PrefabAsset: {fileID: 0}
731731
m_GameObject: {fileID: 799978735}
732732
m_CullTransparentMesh: 0
733-
--- !u!1001 &800593720
734-
PrefabInstance:
735-
m_ObjectHideFlags: 0
736-
serializedVersion: 2
737-
m_Modification:
738-
m_TransformParent: {fileID: 1501641092}
739-
m_Modifications:
740-
- target: {fileID: 2886464298844970360, guid: 1f834fe602c595649a57bd478ffa5942,
741-
type: 3}
742-
propertyPath: app
743-
value:
744-
objectReference: {fileID: 1608730836}
745-
- target: {fileID: 2886464298844970360, guid: 1f834fe602c595649a57bd478ffa5942,
746-
type: 3}
747-
propertyPath: optionName
748-
value: O_Color
749-
objectReference: {fileID: 0}
750-
- target: {fileID: 4412081283409038069, guid: 1f834fe602c595649a57bd478ffa5942,
751-
type: 3}
752-
propertyPath: m_AnchorMax.y
753-
value: 1
754-
objectReference: {fileID: 0}
755-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
756-
type: 3}
757-
propertyPath: m_LocalPosition.x
758-
value: 0
759-
objectReference: {fileID: 0}
760-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
761-
type: 3}
762-
propertyPath: m_LocalPosition.y
763-
value: 0
764-
objectReference: {fileID: 0}
765-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
766-
type: 3}
767-
propertyPath: m_LocalPosition.z
768-
value: 0
769-
objectReference: {fileID: 0}
770-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
771-
type: 3}
772-
propertyPath: m_LocalRotation.x
773-
value: -0
774-
objectReference: {fileID: 0}
775-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
776-
type: 3}
777-
propertyPath: m_LocalRotation.y
778-
value: -0
779-
objectReference: {fileID: 0}
780-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
781-
type: 3}
782-
propertyPath: m_LocalRotation.z
783-
value: -0
784-
objectReference: {fileID: 0}
785-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
786-
type: 3}
787-
propertyPath: m_LocalRotation.w
788-
value: 1
789-
objectReference: {fileID: 0}
790-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
791-
type: 3}
792-
propertyPath: m_RootOrder
793-
value: 6
794-
objectReference: {fileID: 0}
795-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
796-
type: 3}
797-
propertyPath: m_LocalEulerAnglesHint.x
798-
value: 0
799-
objectReference: {fileID: 0}
800-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
801-
type: 3}
802-
propertyPath: m_LocalEulerAnglesHint.y
803-
value: 0
804-
objectReference: {fileID: 0}
805-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
806-
type: 3}
807-
propertyPath: m_LocalEulerAnglesHint.z
808-
value: 0
809-
objectReference: {fileID: 0}
810-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
811-
type: 3}
812-
propertyPath: m_AnchoredPosition.x
813-
value: 150
814-
objectReference: {fileID: 0}
815-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
816-
type: 3}
817-
propertyPath: m_AnchoredPosition.y
818-
value: -619.5
819-
objectReference: {fileID: 0}
820-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
821-
type: 3}
822-
propertyPath: m_SizeDelta.x
823-
value: 300
824-
objectReference: {fileID: 0}
825-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
826-
type: 3}
827-
propertyPath: m_SizeDelta.y
828-
value: 63
829-
objectReference: {fileID: 0}
830-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
831-
type: 3}
832-
propertyPath: m_AnchorMin.x
833-
value: 0
834-
objectReference: {fileID: 0}
835-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
836-
type: 3}
837-
propertyPath: m_AnchorMin.y
838-
value: 1
839-
objectReference: {fileID: 0}
840-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
841-
type: 3}
842-
propertyPath: m_AnchorMax.x
843-
value: 0
844-
objectReference: {fileID: 0}
845-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
846-
type: 3}
847-
propertyPath: m_AnchorMax.y
848-
value: 1
849-
objectReference: {fileID: 0}
850-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
851-
type: 3}
852-
propertyPath: m_Pivot.x
853-
value: 0.5
854-
objectReference: {fileID: 0}
855-
- target: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
856-
type: 3}
857-
propertyPath: m_Pivot.y
858-
value: 0.5
859-
objectReference: {fileID: 0}
860-
- target: {fileID: 4412081284719302609, guid: 1f834fe602c595649a57bd478ffa5942,
861-
type: 3}
862-
propertyPath: m_Name
863-
value: Color
864-
objectReference: {fileID: 0}
865-
m_RemovedComponents: []
866-
m_SourcePrefab: {fileID: 100100000, guid: 1f834fe602c595649a57bd478ffa5942, type: 3}
867-
--- !u!224 &800593721 stripped
868-
RectTransform:
869-
m_CorrespondingSourceObject: {fileID: 4412081284719302608, guid: 1f834fe602c595649a57bd478ffa5942,
870-
type: 3}
871-
m_PrefabInstance: {fileID: 800593720}
872-
m_PrefabAsset: {fileID: 0}
873733
--- !u!1 &818309054
874734
GameObject:
875735
m_ObjectHideFlags: 0
@@ -1483,7 +1343,6 @@ RectTransform:
14831343
- {fileID: 327790844}
14841344
- {fileID: 1088167009}
14851345
- {fileID: 1746320083}
1486-
- {fileID: 800593721}
14871346
m_Father: {fileID: 1101691800}
14881347
m_RootOrder: 2
14891348
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -2408,7 +2267,7 @@ PrefabInstance:
24082267
- target: {fileID: 5125280062814694898, guid: 16cccd673ab22324ea5caab99a233270,
24092268
type: 3}
24102269
propertyPath: m_AnchoredPosition.y
2411-
value: -524
2270+
value: -318
24122271
objectReference: {fileID: 0}
24132272
- target: {fileID: 5125280062814694898, guid: 16cccd673ab22324ea5caab99a233270,
24142273
type: 3}

Fractals Project/Assets/Scenes/MengerSponge.unity

+1
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ MonoBehaviour:
13021302
m_EditorClassIdentifier:
13031303
shader: {fileID: 7200000, guid: 48cf9e093e9510f49934b23cd58f1670, type: 3}
13041304
canvas: {fileID: 1620219076}
1305+
dof: {fileID: 7200000, guid: dff2e43a0d6503646801503442117e2c, type: 3}
13051306
--- !u!4 &650338642
13061307
Transform:
13071308
m_ObjectHideFlags: 0

Fractals Project/Assets/Scripts/InfiniteSpheres/InfiniteSpheres.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected override void Render(RenderTexture s) {
2323
shader.SetMatrix("CamToWorld", cam.cameraToWorldMatrix);
2424
shader.SetMatrix("CamInverseProjection", cam.projectionMatrix.inverse);
2525

26-
shader.Dispatch(0, Mathf.CeilToInt(w / 8), Mathf.CeilToInt(h / 8), 1);
26+
shader.Dispatch(0, Mathf.CeilToInt(w / 8f), Mathf.CeilToInt(h / 8f), 1);
2727
}
2828

2929
// options

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ float Scale;
1414
bool Julia;
1515
float3 C;
1616
float Color;
17+
RWStructuredBuffer<float3> Colors;
1718

1819
// constants
1920
static const int steps = 400;
@@ -57,10 +58,16 @@ Data DataConstr(float n, float3 p) {
5758
return data;
5859
}
5960

61+
float3 Trap(float3 z, float3 trap) {
62+
if (length(z) < trap.x)
63+
trap.x = length(z);
64+
return trap;
65+
}
66+
6067
// mandelbox distance estimator from http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/
6168
Data DE(float3 p) {
6269

63-
float3 trap = p;
70+
float3 trap = float3(length(p), 0, 0);
6471
float3 z = p;
6572
float dr = 1.0;
6673
int i = 0;
@@ -72,9 +79,7 @@ Data DE(float3 p) {
7279
z += Julia ? C : p;
7380
dr = dr * abs(Scale) + 1.0;
7481

75-
if (length(z) < length(trap)) {
76-
trap = z;
77-
}
82+
trap = Trap(z, trap);
7883

7984
i++;
8085
}
@@ -136,9 +141,5 @@ void CSMain (uint3 id : SV_DispatchThreadID) {
136141

137142
// render
138143
Data res = March(ray);
139-
float4 a = float4(normalize(abs(res.p)), 0);
140-
float4 b = length(res.p / 5);
141-
Texture[id.xy] = Source[id.xy] + res.n * (a * Color + b * (1 - Color));
142-
//Texture[id.xy] = Source[id.xy] + (res.n * float4(normalize(abs(res.p)), 0));
143-
//Texture[id.xy] = Source[id.xy] + res.n * length(res.p / 5);
144-
}
144+
Texture[id.xy] = Source[id.xy] + res.n * length(res.p.x / 5);
145+
}

Fractals Project/Assets/Scripts/Mandelbox/Mandelbox.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ public class Mandelbox : App {
66
private int iterations = 20;
77
private bool julia = false;
88
private Vector3 c = Vector3.zero;
9-
private float color = 0.5f;
109

1110
private void Start() {
1211
cameraType = CameraType.Orbit;
1312
maxR = 20;
14-
sens = 1;
13+
sens = 4;
1514
}
1615

1716
protected override void Render(RenderTexture s) {
@@ -25,9 +24,8 @@ protected override void Render(RenderTexture s) {
2524
shader.SetInt("Iterations", iterations);
2625
shader.SetBool("Julia", julia);
2726
shader.SetVector("C", c);
28-
shader.SetFloat("Color", color);
2927

30-
shader.Dispatch(0, Mathf.CeilToInt(w / 8), Mathf.CeilToInt(h / 8), 1);
28+
shader.Dispatch(0, Mathf.CeilToInt(w / 8f), Mathf.CeilToInt(h / 8f), 1);
3129
}
3230

3331
// options
@@ -51,9 +49,4 @@ public Vector3 O_C {
5149
get => c;
5250
set => c = value;
5351
}
54-
55-
public float O_Color {
56-
get => color;
57-
set => color = value;
58-
}
5952
}

Fractals Project/Assets/Scripts/Mandelbrot/Mandelbrot.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected override void Render(RenderTexture s) {
4040
shader.SetInt("Iterations", iterations);
4141
shader.SetBuffer(0, "Colors", colors);
4242

43-
shader.Dispatch(0, Mathf.CeilToInt(w / 8), Mathf.CeilToInt(h / 8), 1);
43+
shader.Dispatch(0, Mathf.CeilToInt(w / 8f), Mathf.CeilToInt(h / 8f), 1);
4444

4545
// dispose buffers
4646
colors.Dispose();

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

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ Texture2D<float4> Source;
77
// matrixes
88
float4x4 CamToWorld;
99
float4x4 CamInverseProjection;
10+
float4x4 CamToWorldL;
11+
float4x4 CamInverseProjectionL;
12+
float4x4 CamToWorldR;
13+
float4x4 CamInverseProjectionR;
1014

1115
// variables
1216
float Power;
1317
int Iterations;
1418
bool Julia;
1519
float3 C;
1620
float Mix;
21+
bool CrossEye;
1722

1823
// constants
1924
static const int steps = 300;
@@ -35,9 +40,25 @@ Ray CreateRay(float3 origin, float3 direction) {
3540

3641
// from http://blog.three-eyed-games.com/2018/05/03/gpu-ray-tracing-in-unity-part-1/
3742
Ray CreateCameraRay(float2 uv) {
38-
float3 origin = mul(CamToWorld, float4(0, 0, 0, 1)).xyz;
39-
float3 direction = mul(CamInverseProjection, float4(uv, 0, 1)).xyz;
40-
direction = mul(CamToWorld, float4(direction, 0)).xyz;
43+
44+
float4x4 ctw = CamToWorld;
45+
float4x4 cip = CamInverseProjection;
46+
47+
if (CrossEye) {
48+
if (uv.x < 0) {
49+
uv.x += 0.4;
50+
ctw = CamToWorldL;
51+
cip = CamInverseProjectionL;
52+
} else {
53+
uv.x -= 0.4;
54+
ctw = CamToWorldR;
55+
cip = CamInverseProjectionR;
56+
}
57+
}
58+
59+
float3 origin = mul(ctw, float4(0, 0, 0, 1)).xyz;
60+
float3 direction = mul(cip, float4(uv, 0, 1)).xyz;
61+
direction = mul(ctw, float4(direction, 0)).xyz;
4162
direction = normalize(direction);
4263
return CreateRay(origin, direction);
4364
}

Fractals Project/Assets/Scripts/Mandelbulb/Mandelbulb.cs

+32-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class Mandelbulb : App {
77
private bool julia = false;
88
private Vector3 c = Vector3.zero;
99
private float mix = 0.5f;
10+
private float eyeOffset = -0.1f;
11+
private bool crossEye = false;
1012

1113
private void Start() {
1214
cameraType = CameraType.Orbit;
@@ -25,8 +27,26 @@ protected override void Render(RenderTexture s) {
2527
shader.SetBool("Julia", julia);
2628
shader.SetVector("C", c);
2729
shader.SetFloat("Mix", mix);
30+
shader.SetBool("CrossEye", crossEye);
31+
if (crossEye) setEyes(); // calculate left and right eye for 3D effect
2832

29-
shader.Dispatch(0, Mathf.CeilToInt(w / 8), Mathf.CeilToInt(h / 8), 1);
33+
shader.Dispatch(0, Mathf.CeilToInt(w / 8f), Mathf.CeilToInt(h / 8f), 1);
34+
35+
void setEyes() {
36+
37+
// left eye
38+
cam.transform.Translate(new Vector3(-eyeOffset, 0));
39+
shader.SetMatrix("CamToWorldL", cam.cameraToWorldMatrix);
40+
shader.SetMatrix("CamInverseProjectionL", cam.projectionMatrix.inverse);
41+
42+
// right eye
43+
cam.transform.Translate(new Vector3(eyeOffset * 2, 0));
44+
shader.SetMatrix("CamToWorldR", cam.cameraToWorldMatrix);
45+
shader.SetMatrix("CamInverseProjectionR", cam.projectionMatrix.inverse);
46+
47+
// reset camera
48+
cam.transform.Translate(new Vector3(-eyeOffset, 0));
49+
}
3050
}
3151

3252
// options
@@ -55,4 +75,15 @@ public float O_Mix {
5575
get => mix;
5676
set => mix = value;
5777
}
78+
79+
// animate
80+
/*private int sx = 1, sy = 1, sz = 1;
81+
private void LateUpdate() {
82+
cursor = new Vector2(50f, 0) * Time.deltaTime;
83+
c += new Vector3(sx * 0.93f, sy * 0.52f, sz * 0.751f) * Time.smoothDeltaTime / 10;
84+
if (c.x > 1 || c.x < -1) sx *= -1;
85+
if (c.y > 1 || c.y < -1) sy *= -1;
86+
if (c.z > 1 || c.z < -1) sz *= -1;
87+
ReRender();
88+
}*/
5889
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void CSMain (uint3 id : SV_DispatchThreadID) {
137137
Ray ray = CreateCameraRay(uv);
138138

139139
float2 res = March(ray);
140-
float4 ao = res.x * float4(0.1, 0.74, 0.61, 0);
140+
float4 ao = res.x * float4(0.1, 0.74, 0.61, res.y / 10.0);
141141
float4 fog = 1 / (res.y + 1);
142142
Texture[id.xy] = Source[id.xy] + ao;
143143
//Texture[id.xy] = fog;

0 commit comments

Comments
 (0)