Operators initially working! Problems with untyped literals

This commit is contained in:
Krzosa Karol
2022-09-29 15:24:49 +02:00
parent 9bb7b0dc96
commit 9e06b631d5
8 changed files with 110 additions and 65 deletions

View File

@@ -1,14 +0,0 @@
Vec3 :: struct;; x: F32; y: F32; z: F32
"+" :: (a: Vec3, b: Vec3): Vec3 ;; return Vec3{a.x+b.x, a.y+b.y, a.z+b.z}
main :: (): int
a := Vec3{1,1,1}
b := Vec3{2,3,4}
c := a + b
Assert(a.x == 3)
Assert(a.y == 4)
Assert(a.z == 5)
return 0

View File

@@ -39,7 +39,7 @@ Raymarcher_Update :: ()
hit := true
p: Vec3
for i := 0, i < 255, i+=1
p = Vec3_Add(eye, Vec3_MulF32(dir, t))
p = eye + dir*t
distance := SphereSDF(p)
if distance < Epsilon
@@ -57,22 +57,22 @@ Raymarcher_Update :: ()
SphereSDF({p.x, p.y, p.z + Epsilon}) - SphereSDF({p.x, p.y, p.z - Epsilon}),
})
light_to_point := Vec3_Normalize(Vec3_Sub(LightPos, p))
eye_to_point := Vec3_Normalize(Vec3_Sub(eye, p))
light_to_point := Vec3_Normalize(LightPos - p)
eye_to_point := Vec3_Normalize(eye - p)
reflected_light := Vec3_Normalize(Vec3_Reflect(Vec3_Negate(light_to_point), normal))
ambient :: 0.2
diffuse := Vec3_Dot(normal, light_to_point)
color := Vec3_MulF32(ambient_color, ambient)
color := ambient_color*ambient
if diffuse > Epsilon
color = Vec3_Add(color, Vec3_MulF32(diffuse_color, diffuse))
color = color + diffuse_color*diffuse
specular := Vec3_Dot(reflected_light, eye_to_point)
if specular > Epsilon
specular = specular*specular*specular*specular
color = Vec3_Add(color, Vec3_MulF32(specular_color, specular*0.2))
color = Vec3_MulF32(color, light_intensity)
color = color + specular_color*specular*0.2
color = color * light_intensity
// Gamma correction
color.x = sqrtf(color.x)