Damn I didn't even know this language could do that, I guess an issue

with namespacing fixed itself
This commit is contained in:
Krzosa Karol
2022-09-30 16:36:55 +02:00
parent 233115cf2c
commit a6f6147df3
11 changed files with 69 additions and 61 deletions

View File

@@ -16,7 +16,7 @@ main :: (): int
static_array: [8]int
// We can get size of array using Length builtin
#Assert(Length(static_array) == 8)
#Assert(Len(static_array) == 8)
// Accessing values is like in C
// Variables are zeroed by default
@@ -40,7 +40,7 @@ main :: (): int
slice: []int = static_array
// We can't do a compile time Assert anymore
Assert(Length(slice) == 8)
Assert(Len(slice) == 8)
Assert(slice[4] == 1)
// After we loop and reassign slice values

View File

@@ -3,7 +3,11 @@ Vec3 :: struct;; x: F32; y: F32; z: F32
// We can define operator overloads for arbitrary types
// these are just regular lambdas/functions
"+" :: (a: Vec3, b: Vec3): Vec3 ;; return {a.x+b.x, a.y+b.y, a.z+b.z}
"+" :: (a: Vec3, b: Vec3): Vec3
return {a.x+b.x, a.y+b.y, a.z+b.z}
// We can make a one liner out of these using ';;' operator
// which functions as a new line with indent
"-" :: (a: Vec3, b: Vec3): Vec3 ;; return {a.x-b.x, a.y-b.y, a.z-b.z}
"-" :: (a: Vec3): Vec3 ;; return {-a.x, -a.y, -a.z}

View File

@@ -1,4 +1,6 @@
#import "Math.core"
V3 :: #import "MathVec3.core"
Vec3 :: V3.Vec3
Epsilon :: 0.00001
Screen : *U32
@@ -8,13 +10,13 @@ TotalTime: F64
LightPos := Vec3{2,4,2}
SphereSDF :: (pos: Vec3): F32
result := Vec3_Length(pos) - 1.0
result := V3.Length(pos) - 1.0
return result
Raymarcher_Update :: ()
up := Vec3{0, 1, 0}
forward := Vec3{0, 0, -1}
side := Vec3_Normalize(Vec3_Cross(forward, up))
side := V3.Normalize(V3.Cross(forward, up))
LightPos.x = cosf(TotalTime->F32)*4
LightPos.y = sinf(TotalTime->F32)*4
@@ -32,7 +34,7 @@ Raymarcher_Update :: ()
for x := 0, x < X, x+=1
uv := Vec3{x->F32 * Xf * 2 - 1, y->F32 * Yf * 2 - 1, 1.0}
uv.x *= ratio
dir := Vec3_Normalize(Vec3{Vec3_Dot(side, uv), Vec3_Dot(up, uv), Vec3_Dot(forward, uv)})
dir := V3.Normalize(Vec3{V3.Dot(side, uv), V3.Dot(up, uv), V3.Dot(forward, uv)})
t: F32
end: F32 = 100.0
@@ -51,24 +53,24 @@ Raymarcher_Update :: ()
break
if hit
normal := Vec3_Normalize(Vec3{
normal := V3.Normalize(Vec3{
SphereSDF({p.x + Epsilon, p.y, p.z}) - SphereSDF({p.x - Epsilon, p.y, p.z}),
SphereSDF({p.x, p.y + Epsilon, p.z}) - SphereSDF({p.x, p.y - Epsilon, p.z}),
SphereSDF({p.x, p.y, p.z + Epsilon}) - SphereSDF({p.x, p.y, p.z - Epsilon}),
})
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))
light_to_point := V3.Normalize(LightPos - p)
eye_to_point := V3.Normalize(eye - p)
reflected_light := V3.Normalize(V3.Reflect(V3.Negate(light_to_point), normal))
ambient :: 0.2->F32
diffuse := Vec3_Dot(normal, light_to_point)
diffuse := V3.Dot(normal, light_to_point)
color := ambient_color*ambient->F32
if diffuse > Epsilon
color = color + diffuse_color*diffuse
specular := Vec3_Dot(reflected_light, eye_to_point)
specular := V3.Dot(reflected_light, eye_to_point)
if specular > Epsilon
specular = specular*specular*specular*specular
color = color + specular_color*specular*0.2->F32
@@ -78,7 +80,7 @@ Raymarcher_Update :: ()
color.x = sqrtf(color.x)
color.y = sqrtf(color.y)
color.z = sqrtf(color.z)
Screen[x + y*X] = Vec3_ConvertToARGB(color)
Screen[x + y*X] = V3.ConvertToARGB(color)
else;; Screen[x + y*X] = 0