@@ -82,85 +82,85 @@ struct Custom {
82
82
83
83
struct Camera
84
84
{
85
- pos: float3 ,
86
- cam: float3x3 ,
87
- fov: float ,
88
- size: float2
85
+ pos: vec3f ,
86
+ cam: mat3x3<f32> ,
87
+ fov: f32 ,
88
+ size: vec2f
89
89
}
90
90
91
91
var<private> camera : Camera;
92
- var<private> state : uint4 ;
92
+ var<private> state : vec4u ;
93
93
94
- fn pcg4d(a: uint4 ) -> uint4
94
+ fn pcg4d(a: vec4u ) -> vec4u
95
95
{
96
96
var v = a * 1664525u + 1013904223u;
97
97
v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
98
- v = v ^ ( v >> uint4 (16u) );
98
+ v = v ^ ( v >> vec4u (16u) );
99
99
v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
100
100
return v;
101
101
}
102
102
103
- fn rand4() -> float4
103
+ fn rand4() -> vec4f
104
104
{
105
105
state = pcg4d(state);
106
- return float4 (state)/float (0xffffffffu);
106
+ return vec4f (state)/f32 (0xffffffffu);
107
107
}
108
108
109
- fn nrand4(sigma: float , mean: float4 ) -> float4
109
+ fn nrand4(sigma: f32 , mean: vec4f ) -> vec4f
110
110
{
111
111
let Z = rand4();
112
112
return mean + sigma * sqrt(-2.0 * log(Z.xxyy)) *
113
- float4 (cos(TWO_PI * Z.z),sin(TWO_PI * Z.z),cos(TWO_PI * Z.w),sin(TWO_PI * Z.w));
113
+ vec4f (cos(TWO_PI * Z.z),sin(TWO_PI * Z.z),cos(TWO_PI * Z.w),sin(TWO_PI * Z.w));
114
114
}
115
115
116
- fn GetCameraMatrix(ang: float2 ) -> float3x3
116
+ fn GetCameraMatrix(ang: vec2f ) -> mat3x3<f32>
117
117
{
118
- let x_dir = float3 (cos(ang.x)*sin(ang.y), cos(ang.y), sin(ang.x)*sin(ang.y));
119
- let y_dir = normalize(cross(x_dir, float3 (0.0,1.0,0.0)));
118
+ let x_dir = vec3f (cos(ang.x)*sin(ang.y), cos(ang.y), sin(ang.x)*sin(ang.y));
119
+ let y_dir = normalize(cross(x_dir, vec3f (0.0,1.0,0.0)));
120
120
let z_dir = normalize(cross(y_dir, x_dir));
121
- return float3x3 (-x_dir, y_dir, z_dir);
121
+ return mat3x3<f32> (-x_dir, y_dir, z_dir);
122
122
}
123
123
124
- fn SetCamera(ang: float2 , fov: float )
124
+ fn SetCamera(ang: vec2f , fov: f32 )
125
125
{
126
126
camera.fov = fov;
127
127
camera.cam = GetCameraMatrix(ang);
128
- camera.pos = - (camera.cam*float3 (3.0*custom.Radius+0.5,0.0,0.0));
129
- camera.size = float2 (textureDimensions(screen));
128
+ camera.pos = - (camera.cam*vec3f (3.0*custom.Radius+0.5,0.0,0.0));
129
+ camera.size = vec2f (textureDimensions(screen));
130
130
}
131
131
132
132
//project to clip space
133
- fn Project(cam: Camera, p: float3 ) -> float3
133
+ fn Project(cam: Camera, p: vec3f ) -> vec3f
134
134
{
135
135
let td = distance(cam.pos, p);
136
136
let dir = (p - cam.pos)/td;
137
137
let screen = dir*cam.cam;
138
- return float3 (screen.yz*cam.size.y/(cam.fov*screen.x) + 0.5*cam.size,screen.x*td);
138
+ return vec3f (screen.yz*cam.size.y/(cam.fov*screen.x) + 0.5*cam.size,screen.x*td);
139
139
}
140
140
141
141
@compute @workgroup_size(16, 16)
142
- fn Clear(@builtin(global_invocation_id) id: uint3 ) {
143
- let screen_size = int2 (textureDimensions(screen));
144
- let idx0 = int (id.x) + int (screen_size.x * int (id.y));
142
+ fn Clear(@builtin(global_invocation_id) id: vec3u ) {
143
+ let screen_size = vec2i (textureDimensions(screen));
144
+ let idx0 = i32 (id.x) + i32 (screen_size.x * i32 (id.y));
145
145
146
146
atomicStore(&atomic_storage[idx0*4+0], 0);
147
147
atomicStore(&atomic_storage[idx0*4+1], 0);
148
148
atomicStore(&atomic_storage[idx0*4+2], 0);
149
149
atomicStore(&atomic_storage[idx0*4+3], 0);
150
150
}
151
151
152
- fn Pack(a: uint , b: uint ) -> int
152
+ fn Pack(a: u32 , b: u32 ) -> i32
153
153
{
154
- return int (a + (b << (31u - DEPTH_BITS)));
154
+ return i32 (a + (b << (31u - DEPTH_BITS)));
155
155
}
156
156
157
- fn Unpack(a: int ) -> float
157
+ fn Unpack(a: i32 ) -> f32
158
158
{
159
- let mask = (1 << (DEPTH_BITS - 1u)) - 1 ;
160
- return float (a & mask)/256.0;
159
+ let mask = i32(1u << (DEPTH_BITS - 1u)) - 1i ;
160
+ return f32 (a & mask)/256.0;
161
161
}
162
162
163
- fn ClosestPoint(color: float3 , depth: float , index: int )
163
+ fn ClosestPoint(color: vec3f , depth: f32 , index: i32 )
164
164
{
165
165
let inverseDepth = 1.0/depth;
166
166
let scaledDepth = (inverseDepth - 1.0/DEPTH_MAX)/(1.0/DEPTH_MIN - 1.0/DEPTH_MAX);
@@ -170,28 +170,28 @@ struct Custom {
170
170
return;
171
171
}
172
172
173
- let uintDepth = uint (scaledDepth*float ((1u << DEPTH_BITS) - 1u));
174
- let uintColor = uint3 (color * 256.0);
173
+ let uintDepth = u32 (scaledDepth*f32 ((1u << DEPTH_BITS) - 1u));
174
+ let uintColor = vec3u (color * 256.0);
175
175
176
176
atomicMax(&atomic_storage[index*4+0], Pack(uintColor.x, uintDepth));
177
177
atomicMax(&atomic_storage[index*4+1], Pack(uintColor.y, uintDepth));
178
178
atomicMax(&atomic_storage[index*4+2], Pack(uintColor.z, uintDepth));
179
179
}
180
180
181
- fn AdditiveBlend(color: float3 , depth: float , index: int )
181
+ fn AdditiveBlend(color: vec3f , depth: f32 , index: i32 )
182
182
{
183
183
let scaledColor = 256.0 * color/depth;
184
184
185
- atomicAdd(&atomic_storage[index*4+0], int (scaledColor.x));
186
- atomicAdd(&atomic_storage[index*4+1], int (scaledColor.y));
187
- atomicAdd(&atomic_storage[index*4+2], int (scaledColor.z));
185
+ atomicAdd(&atomic_storage[index*4+0], i32 (scaledColor.x));
186
+ atomicAdd(&atomic_storage[index*4+1], i32 (scaledColor.y));
187
+ atomicAdd(&atomic_storage[index*4+2], i32 (scaledColor.z));
188
188
}
189
189
190
- fn RasterizePoint(pos: float3 , color: float3 )
190
+ fn RasterizePoint(pos: vec3f , color: vec3f )
191
191
{
192
- let screen_size = int2 (camera.size);
192
+ let screen_size = vec2i (camera.size);
193
193
let projectedPos = Project(camera, pos);
194
- let screenCoord = int2 (projectedPos.xy);
194
+ let screenCoord = vec2i (projectedPos.xy);
195
195
196
196
//outside of our view
197
197
if(screenCoord.x < 0 || screenCoord.x >= screen_size.x ||
@@ -213,75 +213,75 @@ struct Custom {
213
213
}
214
214
215
215
@compute @workgroup_size(16, 16)
216
- fn Rasterize(@builtin(global_invocation_id) id: uint3 ) {
216
+ fn Rasterize(@builtin(global_invocation_id) id: vec3u ) {
217
217
// Viewport resolution (in pixels)
218
- let screen_size = int2 (textureDimensions(screen));
219
- let screen_size_f = float2 (screen_size);
218
+ let screen_size = vec2i (textureDimensions(screen));
219
+ let screen_size_f = vec2f (screen_size);
220
220
221
- // let ang = float2 (mouse.pos.xy)*float2 (-TWO_PI, PI)/screen_size_f + float2 (0.4, 0.4);
222
- let ang = float2 (0.0, 0.0)*float2 (-TWO_PI, PI)/screen_size_f + float2 (0.4, 0.4);
221
+ // let ang = vec2f (mouse.pos.xy)*vec2f (-TWO_PI, PI)/screen_size_f + vec2f (0.4, 0.4);
222
+ let ang = vec2f (0.0, 0.0)*vec2f (-TWO_PI, PI)/screen_size_f + vec2f (0.4, 0.4);
223
223
224
224
SetCamera(ang, FOV);
225
225
226
226
//RNG state
227
- state = uint4 (id.x, id.y, id.z, 0u*time.frame);
227
+ state = vec4u (id.x, id.y, id.z, 0u*time.frame);
228
228
229
- for(var i: i32 = 0; i < int (custom.Samples*MaxSamples + 1.0); i++)
229
+ for(var i: i32 = 0; i < i32 (custom.Samples*MaxSamples + 1.0); i++)
230
230
{
231
- let rand = nrand4(1.0, float4 (0.0));
231
+ let rand = nrand4(1.0, vec4f (0.0));
232
232
var pos = 0.2*rand.xyz;
233
- let col = float3 (0.5 + 0.5*sin(10.0*pos));
233
+ let col = vec3f (0.5 + 0.5*sin(10.0*pos));
234
234
235
235
let sec = 5.0+custom.Speed*time.elapsed;
236
236
//move points along sines
237
- pos += sin(float3 (2.0,1.0,1.5)*sec)*0.1*sin(30.0*custom.Sinea*pos);
238
- pos += sin(float3 (2.0,1.0,1.5)*sec)*0.02*sin(30.0*custom.Sineb*pos.zxy);
237
+ pos += sin(vec3f (2.0,1.0,1.5)*sec)*0.1*sin(30.0*custom.Sinea*pos);
238
+ pos += sin(vec3f (2.0,1.0,1.5)*sec)*0.02*sin(30.0*custom.Sineb*pos.zxy);
239
239
240
240
RasterizePoint(pos, col);
241
241
}
242
242
}
243
243
244
- fn Sample(pos: int2 ) -> float3
244
+ fn Sample(pos: vec2i ) -> vec3f
245
245
{
246
- let screen_size = int2 (textureDimensions(screen));
246
+ let screen_size = vec2i (textureDimensions(screen));
247
247
let idx = pos.x + screen_size.x * pos.y;
248
248
249
- var color: float3 ;
249
+ var color: vec3f ;
250
250
if(custom.Mode < 0.5)
251
251
{
252
- let x = float (atomicLoad(&atomic_storage[idx*4+0]))/(256.0);
253
- let y = float (atomicLoad(&atomic_storage[idx*4+1]))/(256.0);
254
- let z = float (atomicLoad(&atomic_storage[idx*4+2]))/(256.0);
252
+ let x = f32 (atomicLoad(&atomic_storage[idx*4+0]))/(256.0);
253
+ let y = f32 (atomicLoad(&atomic_storage[idx*4+1]))/(256.0);
254
+ let z = f32 (atomicLoad(&atomic_storage[idx*4+2]))/(256.0);
255
255
256
- color = tanh(0.1*float3 (x,y,z)/(custom.Samples*MaxSamples + 1.0));
256
+ color = tanh(0.1*vec3f (x,y,z)/(custom.Samples*MaxSamples + 1.0));
257
257
}
258
258
else
259
259
{
260
260
let x = Unpack(atomicLoad(&atomic_storage[idx*4+0]));
261
261
let y = Unpack(atomicLoad(&atomic_storage[idx*4+1]));
262
262
let z = Unpack(atomicLoad(&atomic_storage[idx*4+2]));
263
263
264
- color = float3 (x,y,z);
264
+ color = vec3f (x,y,z);
265
265
}
266
266
267
267
return abs(color);
268
268
}
269
269
270
270
@compute @workgroup_size(16, 16)
271
- fn main_image(@builtin(global_invocation_id) id: uint3 )
271
+ fn main_image(@builtin(global_invocation_id) id: vec3u )
272
272
{
273
- let screen_size = uint2 (textureDimensions(screen));
273
+ let screen_size = vec2u (textureDimensions(screen));
274
274
275
275
// Prevent overdraw for workgroups on the edge of the viewport
276
276
if (id.x >= screen_size.x || id.y >= screen_size.y) { return; }
277
277
278
278
// Pixel coordinates (centre of pixel, origin at bottom left)
279
- // let fragCoord = float2(float (id.x) + .5, float (id.y) + .5);
279
+ // let fragCoord = vec2f(f32 (id.x) + .5, f32 (id.y) + .5);
280
280
281
- let color = float4 (Sample(int2 (id.xy)),1.0);
281
+ let color = vec4f (Sample(vec2i (id.xy)),1.0);
282
282
283
283
// Output to screen (linear colour space)
284
- textureStore(screen, int2 (id.xy), color);
284
+ textureStore(screen, vec2i (id.xy), color);
285
285
}
286
286
` ;
287
287
0 commit comments