@@ -26,6 +26,15 @@ static const float epsilon = 0.00004;
26
26
27
27
// structs
28
28
struct Ray { float3 origin; float3 direction; };
29
+ struct Data { float2 a; float3 b; };
30
+
31
+ // data contructor
32
+ Data DataConstr(float2 a, float3 b) {
33
+ Data data;
34
+ data.a = a;
35
+ data.b = b;
36
+ return data;
37
+ }
29
38
30
39
Ray CreateRay(float3 origin, float3 direction) {
31
40
Ray ray;
@@ -42,10 +51,16 @@ Ray CreateCameraRay(float2 uv) {
42
51
return CreateRay(origin, direction);
43
52
}
44
53
54
+ // orbit trap
55
+ void Trap(float3 z, inout float3 trap) {
56
+ //z = abs(z);
57
+ if (length(z) < length(trap))
58
+ trap = z;
59
+ }
45
60
46
61
// mandelbulb distance estimator from http://blog.hvidtfeldts.net/index.php/2011/09/distance-estimated-3d-fractals-v-the-mandelbulb-different-de-approximations/
47
- float2 DE(float3 p) {
48
- float3 z = p;
62
+ Data DE(float3 p) {
63
+ float3 z = p, trap = p;
49
64
float r, dr = 1;
50
65
int i;
51
66
@@ -68,27 +83,32 @@ float2 DE(float3 p) {
68
83
if (Alt) z = zr * float3(cos(theta) * cos(phi), cos(theta) * sin(phi), sin(theta));
69
84
else z = zr * float3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
70
85
z += Julia * C + (1 - Julia) * p;
86
+
87
+
88
+ Trap(z, trap); // trap
71
89
}
72
-
90
+
91
+ trap = abs(trap);
73
92
float dst = 0.1 * log(r) * r / dr;
74
- return float2(dst, sin(i));
93
+ return DataConstr( float2(dst, sin(i)), trap );
75
94
}
76
95
77
96
// cast a ray and return the result
78
- float3 March(Ray ray) {
79
- float2 d = 0 ;
97
+ Data March(Ray ray) {
98
+ Data d ;
80
99
float3 eye = ray.origin;
81
100
82
101
int s = 0;
83
102
while (s < steps) {
84
103
d = DE(ray.origin); // calculate distance
85
104
if (length(eye - ray.origin) > 100) s = steps; // to far away
86
- if (d.x < epsilon) break; // hit
87
- ray.origin += ray.direction * d.x; // march
105
+ if (d.a. x < epsilon) break; // hit
106
+ ray.origin += ray.direction * d.a. x; // march
88
107
s++; // next iteration
89
108
}
90
-
91
- return float3(1 - s / float(steps), length(eye - ray.origin), d.y);
109
+
110
+ return DataConstr(float2(1 - s / float(steps), d.a.y), d.b);
111
+ //return float3(1 - s / float(steps), length(eye - ray.origin), d.y);
92
112
}
93
113
94
114
// main method
@@ -103,8 +123,10 @@ void CSMain (uint3 id : SV_DispatchThreadID) {
103
123
Ray ray = CreateCameraRay(uv);
104
124
105
125
// render
106
- float3 res = March(ray);
107
- float a = res.x * (2 - Mix * 2) + res.z * (Mix * 2);
126
+ Data res = March(ray);
127
+ // float a = res.a. x * (2 - Mix * 2) + res.a.y * (Mix * 2);
108
128
//Texture[id.xy] = Source[id.xy] + (float4(a, a, a, 0) * float4(0.8, 0.2, 0.2, 0));
109
- Texture[id.xy] = float4(1, 1, 1, 1) * (res.x + 0.1) + float4(0.8, 0.2, 0.2, 0) * res.z;
129
+ //float4 a = TrapColoring ? float4(res.b, 0) : float4(0.8, 0.2, 0.2, 0);
130
+ float4 a = float4(res.b, 0) * Mix + float4(0.8, 0.2, 0.2, 0) * (1 - Mix);
131
+ Texture[id.xy] = float4(1, 1, 1, 1) * (res.a.x + 0.1) + a * res.a.y;
110
132
}
0 commit comments