Materials

This commit is contained in:
Crizomb 2025-09-26 04:33:09 +02:00
parent c0c129db88
commit f5d4a5cb7e
5 changed files with 113 additions and 106 deletions

View file

@ -1,5 +1,9 @@
package main
// RIGHT : x
// FORWARD : Y
// UP : Z
import (
"math"
@ -13,12 +17,10 @@ const WIDTH = 500
const HEIGHT = 500
const PI = math.Pi
// var sphere Sphere = Sphere{Vector3{0, 0, 100}, 10, RED}
// var plane Plane = Plane{Vector3{0, 1, 0}, -10, GREY}
// var scene UnionSDF = UnionSDF{sphere, plane}
var sphere Sphere = Sphere{Vector3{0, 100, 10}, 10, RED_MAT}
var plane Plane = Plane{Vector3{0, 0, 1}, -10, GREY_MAT}
var scene UnionSDF = UnionSDF{sphere, plane}
// x right, y forward, z up
var scene Sphere = Sphere{Vector3{0, 100, 0}, 5, RED}
var cameraPos Vector3 = Vector3{0, -10, 0}
// radius, theta, phi
@ -28,11 +30,11 @@ var screenPhysicalSize float64 = 5
func rayMarch(origin Vector3, direction Vector3) (bool, Vector3) {
p := origin
for range MAX_STEP {
dist, color := scene.Distance(p)
dist, mat := scene.Distance(p)
// fmt.Println(dist)
if dist < EPS {
// fmt.Println("hit")
return true, color.GetColor(p)
return true, mat.diffuseColor.GetColor(p)
}
if dist > MAX_DIST {
break
@ -58,7 +60,7 @@ func genImage() *rl.Image {
sx := screenPhysicalSize * (float64(pixel_x)/WIDTH - 0.5)
sy := screenPhysicalSize * (float64(pixel_y)/WIDTH - 0.5)
origin := screenCenter.Add(theta_vec.Scale(-sx)).Add(phi_vec.Scale(-sy))
origin := screenCenter.Add(phi_vec.Scale(-sx)).Add(theta_vec.Scale(sy))
direction := (origin.Sub(cameraPos)).Normalized()
// fmt.Println(origin, direction)
@ -88,42 +90,3 @@ func main() {
rl.EndDrawing()
}
}
// func main() {
// screenWidth := int32(800)
// screenHeight := int32(450)
// rl.InitWindow(screenWidth, screenHeight, "Bouncing Ball in Go - raylib")
// defer rl.CloseWindow()
// rl.SetTargetFPS(60)
// // Ball properties
// ballRadius := float32(20)
// ballPos := rl.NewVector2(float32(screenWidth)/2.0, float32(screenHeight)/2.0)
// ballSpeed := rl.NewVector2(4, 3)
// ballColor := rl.Red
// for !rl.WindowShouldClose() {
// // Update
// ballPos.X += ballSpeed.X
// ballPos.Y += ballSpeed.Y
// // Bounce on edges
// if ballPos.X >= float32(screenWidth)-ballRadius || ballPos.X <= ballRadius {
// ballSpeed.X *= -1
// }
// if ballPos.Y >= float32(screenHeight)-ballRadius || ballPos.Y <= ballRadius {
// ballSpeed.Y *= -1
// }
// // Draw
// rl.BeginDrawing()
// rl.ClearBackground(rl.RayWhite)
// rl.DrawText("Bouncing Ball Example", 10, 10, 20, rl.DarkGray)
// rl.DrawCircleV(ballPos, ballRadius, ballColor)
// rl.EndDrawing()
// }
// }