nothing important

This commit is contained in:
Crizomb 2025-09-27 20:25:52 +02:00
parent 2e6f0a0730
commit 264a759ac5
3 changed files with 26 additions and 13 deletions

View file

@ -13,11 +13,11 @@ import (
const MAX_DIST = 1000.0
const MAX_STEP = 1000
const EPS = 0.01
const WIDTH = 500
const HEIGHT = 500
const WIDTH = 250
const HEIGHT = 250
const PI = math.Pi
const SOFT_SHADOW_COEFF = 4
const SOFT_SHADOW_COEFF = 32
var lightPos Vector3
var scene SDF
@ -28,7 +28,7 @@ var screenPhysicalSize float64
var cameraPos Vector3
func init() {
lightPos = Vector3{0, -200, 800}
lightPos = Vector3{100, -400, 400}
cameraPos = Vector3{0, -10, 25}
screenSpherical = Vector3{10, PI/2 + 0.2, PI / 2}
@ -36,11 +36,16 @@ func init() {
sphereMat := RED_MAT
sphereMat.specularFac = 0.5
sphere := TranslatedSDF{Sphere{10, sphereMat}, Vector3{0, 100, 15}}
sphere := TranslatedSDF{Sphere{5, sphereMat}, Vector3{0, 100, 10}}
// boxMat := BLUE_MAT
// box := TranslatedSDF{Box{Vector3{10, 2, 10}, boxMat}, Vector3{0, 100, 10}}
// sphere := RepeatSDF{Sphere{20, sphereMat}, Vector3{50, 50, 50}}
plane := Plane{Vector3{0, 0, 1}, WHITE_GREY_GRID_MAT}
scene = UnionSDF{sphere, plane}
// scene = SmoothUnionSDF{SubstractionSDF{box, sphere}, plane, 2.5}
scene = UnionSDF{plane, sphere}
}
@ -48,7 +53,7 @@ func phongShading(point Vector3, normal Vector3, mat Material) Vector3 {
lightVec := (lightPos.Sub(point)).Normalized()
reflectLight := Reflect(lightVec, normal)
eyeVec := (cameraPos.Sub(point)).Normalized()
ambiant := mat.ambiantColor.GetColor(point).Scale(0.1)
ambiant := mat.ambiantColor.GetColor(point)
diffusePower := mat.diffuseFac * max(0, normal.Dot(lightVec))
diffuse := mat.diffuseColor.GetColor(point).Scale(diffusePower)
@ -67,7 +72,7 @@ func shadow(point Vector3) float64 {
for range MAX_STEP {
dist, _ := scene.Distance(p)
if dist < EPS {
return 0.1
return 0
}
if dist > MAX_DIST {
break
@ -85,7 +90,7 @@ func rayMarch(origin Vector3, direction Vector3) (bool, Vector3) {
dist, mat := scene.Distance(p)
if dist < EPS {
normal := Gradient(scene, p, EPS).Normalized()
return true, phongShading(p, normal, mat).Scale(shadow(p))
return true, phongShading(p, normal, mat).Scale(max(shadow(p), 0.3))
}
if dist > MAX_DIST {
break