Raymarcher mostly working, need to fix specular still

This commit is contained in:
Krzosa Karol
2022-09-28 13:10:26 +02:00
parent 0050abe190
commit 4510f39397
5 changed files with 59 additions and 22 deletions

View File

@@ -1,12 +1,12 @@
sqrtf :: #foreign (value: F32): F32
cosf :: #foreign (value: F32): F32
sinf :: #foreign (value: F32): F32
Vec2I :: struct;; x: S64; y: S64
Vec2 :: struct;; x: F32; y: F32
Vec3 :: struct;; x: F32; y: F32; z: F32
Vec3_Length :: (a: Vec3): F32
result := sqrtf(a.x*a.x + a.y*a.y + a.z*a.z)
return result
Vec3_Cross :: (a: Vec3, b: Vec3): Vec3
result := Vec3{
@@ -25,6 +25,12 @@ Vec3_Normalize :: (a: Vec3): Vec3
}
return result
Vec3_Reflect :: (a: Vec3, normal: Vec3): Vec3
an := Vec3_Dot(a, normal)*2
result := Vec3_Sub(a, Vec3_MulF32(a, an))
return result
Vec3_ConvertToARGB :: (a: Vec3): U32
a.x = F32_Clamp(0, a.x, 1)
a.y = F32_Clamp(0, a.y, 1)
@@ -35,10 +41,11 @@ Vec3_ConvertToARGB :: (a: Vec3): U32
result := r | g | b
return result
Vec3_Length :: (a: Vec3): F32 ;; return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z)
Vec3_Negate :: (a: Vec3): Vec3 ;; return Vec3{-a.x, -a.y, -a.z}
Vec3_Dot :: (a: Vec3, b: Vec3): F32 ;; return a.x*b.x + a.y*b.y + a.z*b.z
Vec3_Mul :: (a: Vec3, b: Vec3): Vec3 ;; return Vec3{a.x*b.x, a.y*b.y, a.z*b.z}
Vec3_MulF32 :: (a: Vec3, b: F32): Vec3 ;; return Vec3{a.x*b, a.y*b, a.z*b}
Vec3_MulF32 :: (a: Vec3, b: F32) : Vec3 ;; return Vec3{a.x*b, a.y*b, a.z*b}
Vec3_Add :: (a: Vec3, b: Vec3): Vec3 ;; return Vec3{a.x+b.x, a.y+b.y, a.z+b.z}
Vec3_Div :: (a: Vec3, b: Vec3): Vec3 ;; return Vec3{a.x/b.x, a.y/b.y, a.z/b.z}
Vec3_Sub :: (a: Vec3, b: Vec3): Vec3 ;; return Vec3{a.x-b.x, a.y-b.y, a.z-b.z}
@@ -48,6 +55,10 @@ F32_Clamp :: (min: F32, value: F32, max: F32): F32
if value < min;; return min
return value
F32_ClampBottom :: (min: F32, value: F32): F32
if value < min;; return min
return value
F32_Absolute :: (val: F32): F32
if val < 0;; return -val
return val