@@ -15,13 +15,13 @@ import {
1515 estimateNormal ,
1616 march ,
1717} from 'src/lib-ray-marching' ;
18- import tgpu , { type TgpuRoot , unstable_asUniform } from 'typegpu' ;
18+ import tgpu , { type TgpuRoot } from 'typegpu' ;
1919import * as d from 'typegpu/data' ;
2020
2121import { store } from 'src/lib/store.ts' ;
22- import type { GBuffer } from '../../gBuffer' ;
23- import { ONES_3F } from '../wgslUtils/mathConstants' ;
24- import { Material , skyColor , worldMat , worldSdf } from './worldSdf' ;
22+ import type { GBuffer } from '../../gBuffer.ts ' ;
23+ import { ONES_3F } from '../wgslUtils/mathConstants.ts ' ;
24+ import { Material , skyColor , worldMat , worldSdf } from './worldSdf.ts ' ;
2525
2626const BlockSize = 8 ;
2727
@@ -50,30 +50,35 @@ export const accumulatedLayersAtom = atom(0);
5050 * @param mat_roughness
5151 */
5252const reflect = tgpu [ '~unstable' ]
53- . fn ( [
54- d . vec3f ,
53+ . fn (
54+ {
55+ rayDir : d . vec3f ,
56+ normal : d . vec3f ,
57+ matRoughness : d . f32 ,
58+ outRoughness : d . ptrFn ( d . f32 ) ,
59+ } ,
5560 d . vec3f ,
56- d . f32 ,
57- d . ptrFn ( d . f32 ) ,
58- ] ) ( `(ray_dir: vec3f, normal: vec3f, mat_roughness: f32, out_roughness: ptr<function, f32>) -> vec3f {
59- let slope = dot(ray_dir, normal);
61+ ) ( `{
62+ let slope = dot(rayDir, normal);
6063 let dn2 = 2. * slope;
61- let refl_dir = ray_dir - dn2 * normal;
64+ let refl_dir = rayDir - dn2 * normal;
6265
6366 let fresnel = 1. - pow(1. + slope, 16.);
64- let roughness = mat_roughness * fresnel;
65- *out_roughness = roughness;
67+ let roughness = matRoughness * fresnel;
68+ *outRoughness = roughness;
6669
67- var new_ray_dir = randOnHemisphere (normal);
70+ var new_ray_dir = randf.onHemisphere (normal);
6871 new_ray_dir = mix(refl_dir, new_ray_dir, roughness);
6972 return normalize(new_ray_dir);
7073 }` )
71- . $uses ( { randOnHemisphere : randf . onHemisphere } )
74+ . $uses ( { randf } )
7275 . $name ( 'reflect' ) ;
7376
7477const renderSubPixel = tgpu [ '~unstable' ]
75- . fn ( [ d . vec2f ] , d . vec3f )
76- . does ( /* wgsl */ `(coord: vec2f) -> vec3f {
78+ . fn (
79+ [ d . vec2f ] ,
80+ d . vec3f ,
81+ ) ( /* wgsl */ `(coord: vec2f) -> vec3f {
7782 // doing the first march before each sub-sample, since the first march result is the same for all of them
7883
7984 var init_shape_ctx: ShapeContext;
@@ -334,9 +339,9 @@ export function createSDFRenderer(options: SDFRendererOptions) {
334339 const mainPipeline = root [ '~unstable' ]
335340 // filling slots
336341 . with ( OutputFormat , 'rgba8unorm' )
337- . with ( getRandomSeedPrimer , unstable_asUniform ( randomSeedPrimerBuffer ) )
338- . with ( getAccumulatedLayers , unstable_asUniform ( layersBuffer ) )
339- . with ( getCameraProps , unstable_asUniform ( camera . cameraBuffer ) )
342+ . with ( getRandomSeedPrimer , randomSeedPrimerBuffer . as ( 'uniform' ) )
343+ . with ( getAccumulatedLayers , layersBuffer . as ( 'uniform' ) )
344+ . with ( getCameraProps , camera . cameraBuffer . as ( 'uniform' ) )
340345 . with ( accessViewportSize , d . vec2f ( mainPassSize [ 0 ] , mainPassSize [ 1 ] ) )
341346 . with ( MarchParams . sampleSdf , worldSdf )
342347 // ---
@@ -347,7 +352,7 @@ export function createSDFRenderer(options: SDFRendererOptions) {
347352 const auxPipeline = root [ '~unstable' ]
348353 // filling slots
349354 . with ( OutputFormat , 'rgba16float' )
350- . with ( getCameraProps , unstable_asUniform ( camera . cameraBuffer ) )
355+ . with ( getCameraProps , camera . cameraBuffer . as ( 'uniform' ) )
351356 . with ( accessViewportSize , d . vec2f ( auxPassSize [ 0 ] , auxPassSize [ 1 ] ) )
352357 . with ( MarchParams . sampleSdf , worldSdf )
353358 // ---
0 commit comments