i stil have no idea what i'm doing

This commit is contained in:
2025-10-18 14:31:15 -04:00
parent 8f4bd37e1e
commit 58ae477bca
2 changed files with 58 additions and 56 deletions

View File

@@ -42,7 +42,7 @@ fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
var ray = createCameraRay2(ndc); var ray = createCameraRay2(ndc);
var result = vec3<f32>(0.0); var result = vec3<f32>(0.0);
for (var i: i32 = 0; i < 8; i++){ for (var i: i32 = 0; i < 1; i++){
var hit = trace(ray); var hit = trace(ray);
result += ray.energy * shade(&ray, hit); result += ray.energy * shade(&ray, hit);
if !any(ray.energy != vec3<f32>(0.0)) if !any(ray.energy != vec3<f32>(0.0))
@@ -51,14 +51,16 @@ fn update(@builtin(global_invocation_id) invocation_id: vec3<u32>) {
} }
} }
// let clip = vec4<f32>(ndc, 0.0, 1.0); let clip = vec4<f32>(ndc, 0.0, 1.0);
// let world = config.world_from_clip * clip; let world = config.world_from_clip * clip;
// let world_pos = world.xyz / world.w; let world_pos = world.xyz / world.w;
// let dir = normalize(world_pos - config.world_position); let dir = normalize(world_pos - config.world_position);
// let color = vec4<f32>((ray.direction * 0.5) + vec3<f32>(0.5), 1.0); let color = vec4<f32>((ray.direction * 0.1), 1.0);
// let color = vec4<f32>(ray.direction, 1.0);
// let color = vec4<f32>((ray.direction * 0.1) + vec3<f32>(0.5), 1.0);
let color = vec4<f32>(result, 1.0); // let color = vec4<f32>(result, 1.0);
let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y)); let location = vec2<i32>(i32(invocation_id.x), i32(invocation_id.y));
textureStore(output, location, color); textureStore(output, location, color);
@@ -90,7 +92,7 @@ struct Sphere
fn createRayHit() -> RayHit { fn createRayHit() -> RayHit {
var hit: RayHit; var hit: RayHit;
hit.position = vec3<f32>(0.0, 0.0, 0.0); hit.position = vec3<f32>(0.0, 0.0, 0.0);
hit.distance = 999999999999.0f; hit.distance = -999999999.0f;
hit.normal = vec3<f32>(0.0, 0.0, 0.0); hit.normal = vec3<f32>(0.0, 0.0, 0.0);
hit.albedo = vec3<f32>(0.0, 0.0, 0.0); hit.albedo = vec3<f32>(0.0, 0.0, 0.0);
hit.specular = vec3<f32>(0.0, 0.0, 0.0); hit.specular = vec3<f32>(0.0, 0.0, 0.0);
@@ -128,8 +130,8 @@ fn createCameraRay2(ndc: vec2<f32>) -> Ray {
let far_world = far_world4.xyz / far_world4.w; let far_world = far_world4.xyz / far_world4.w;
// ray starts at near plane, points toward far plane // ray starts at near plane, points toward far plane
let origin = near_world; let origin = near_world + config.world_position;
let direction = normalize(far_world - near_world); let direction = normalize(origin - near_world);
return createRay(origin, direction); return createRay(origin, direction);
} }
@@ -147,7 +149,7 @@ fn createSphere(position: vec3<f32>, radius: f32) -> Sphere
fn intersectSphere(ray: Ray, bestHit: ptr<function, RayHit>, sphereIndex: u32) fn intersectSphere(ray: Ray, bestHit: ptr<function, RayHit>, sphereIndex: u32)
{ {
//Sphere sphere = _Spheres[sphereIndex]; //Sphere sphere = _Spheres[sphereIndex];
var sphere = createSphere(vec3<f32>(0.0f, 0.0f, 0.0f), 1.0f); var sphere = createSphere(vec3<f32>(0.0f, 2.0f, 0.0f), 2.0f);
var d = ray.origin - sphere.position; var d = ray.origin - sphere.position;
@@ -198,7 +200,7 @@ fn trace(ray: Ray) -> RayHit
fn shade(ray: ptr<function, Ray>, hit: RayHit) -> vec3<f32> fn shade(ray: ptr<function, Ray>, hit: RayHit) -> vec3<f32>
{ {
if hit.distance < 999999999999.0f if hit.distance > -999999999.0f
{ {
(*ray).origin = hit.position + hit.normal * 0.001f; (*ray).origin = hit.position + hit.normal * 0.001f;
(*ray).direction = reflect((*ray).direction, hit.normal); (*ray).direction = reflect((*ray).direction, hit.normal);

View File

@@ -178,9 +178,9 @@ fn update_tracer_uniforms(
) { ) {
let (transform, cam) = rt_camera.into_inner(); let (transform, cam) = rt_camera.into_inner();
let view = transform.compute_matrix().inverse();
let clip_from_view = cam.clip_from_view(); let clip_from_view = cam.clip_from_view();
let world_from_clip = view * clip_from_view.inverse(); let world_from_clip = clip_from_view.inverse() * transform.compute_matrix().inverse();
// cam.ndc_to_world(camera_transform, ndc)
tracer_uniforms.world_from_clip = world_from_clip; tracer_uniforms.world_from_clip = world_from_clip;
tracer_uniforms.world_position = transform.translation(); tracer_uniforms.world_position = transform.translation();