Various bug fixes + Material setters
This commit is contained in:
parent
e35cca1830
commit
f5c912c489
5 changed files with 53 additions and 22 deletions
|
|
@ -13,17 +13,17 @@ import (
|
|||
const MAX_DIST = 1000.0
|
||||
const MAX_STEP = 1000
|
||||
const EPS = 0.01
|
||||
const WIDTH = 250
|
||||
const HEIGHT = 250
|
||||
const WIDTH = 500
|
||||
const HEIGHT = 500
|
||||
const PI = math.Pi
|
||||
|
||||
var lightPos Vector3 = Vector3{0, -200, 600}
|
||||
var sphere Sphere = Sphere{Vector3{0, 100, 5}, 10, RED_MAT}
|
||||
var plane Plane = Plane{Vector3{0, 0, 1}, 0, WHITE_GREY_GRID_MAT}
|
||||
|
||||
var scene SmoothUnionSDF = SmoothUnionSDF{sphere, plane, 3.5}
|
||||
var sphereMat = RED_MAT
|
||||
var lightPos = Vector3{0, -200, 800}
|
||||
var sphere = Sphere{Vector3{0, 100, 5}, 10, &sphereMat}
|
||||
var plane = Plane{Vector3{0, 0, 1}, 0, WHITE_GREY_GRID_MAT}
|
||||
|
||||
// var scene UnionSDF = UnionSDF{sphere, plane}
|
||||
var scene = SmoothUnionSDF{sphere, plane, 2}
|
||||
var cameraPos Vector3 = Vector3{0, -10, 30}
|
||||
|
||||
// radius, theta, phi
|
||||
|
|
@ -32,14 +32,14 @@ var screenPhysicalSize float64 = 5
|
|||
|
||||
func phongShading(point Vector3, normal Vector3, mat Material) Vector3 {
|
||||
lightVec := (lightPos.Sub(point)).Normalized()
|
||||
reflectLight := Reflect(lightVec.Scale(-1), normal)
|
||||
reflectLight := Reflect(lightVec, normal)
|
||||
eyeVec := (cameraPos.Sub(point)).Normalized()
|
||||
ambiant := mat.ambiantColor.GetColor(point).Scale(0.1)
|
||||
|
||||
diffusePower := mat.diffuseFac * max(0, normal.Dot(lightVec))
|
||||
diffuse := mat.diffuseColor.GetColor(point).Scale(diffusePower)
|
||||
|
||||
specularPower := mat.specularFac * math.Pow(max(0, -reflectLight.Dot(eyeVec)), mat.specularExp)
|
||||
specularPower := mat.specularFac * math.Pow(max(0, reflectLight.Dot(eyeVec)), mat.specularExp)
|
||||
specular := mat.specularColor.GetColor(point).Scale(specularPower)
|
||||
|
||||
return ambiant.Add(diffuse).Add(specular)
|
||||
|
|
@ -100,6 +100,10 @@ func genImage() *rl.Image {
|
|||
}
|
||||
|
||||
func main() {
|
||||
// ChangeDiffuseColor(&sphereMat, Vector3{0, 0, 255})
|
||||
ChangeSpecularFac(&sphereMat, 0.5)
|
||||
ChangeSpecularExp(&sphereMat, 20)
|
||||
// ChangeSpecularColor(&sphereMat, Vector3{0, 0, 255})
|
||||
rl.InitWindow(WIDTH, HEIGHT, "raymarching")
|
||||
texture := rl.LoadTextureFromImage(genImage())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue