Skip to content

Commit

Permalink
Additional surface fixes for FRGBA
Browse files Browse the repository at this point in the history
  • Loading branch information
jphsd committed Aug 19, 2024
1 parent e2d5a71 commit ff64be2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
img = texture.NewRGBA(width, height, alpha, 0, 0, 1, 1)
draw.Draw(res, image.Rect(width, 0, 2*width, height), img, image.Point{}, draw.Src)
// Bump Map
bm := &surface.BumpMap{nil, nil, nil, cf.Vector}
bm := &surface.BumpMap{surface.DefaultAmbient, nil, nil, cf.Vector}
img = texture.NewRGBA(width, height, bm, 0, 0, 1, 1)
draw.Draw(res, image.Rect(2*width, 0, 3*width, height), img, image.Point{}, draw.Src)
gi.SaveImage(res, fmt.Sprintf("%06d", cnt))
Expand Down
8 changes: 2 additions & 6 deletions surface/bumpmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// BumpMap collects the ambient light, a direct light, a material, and normal map required to describe
// an area. If the normal map is nil then the standard normal is use {0, 0, 1}
type BumpMap struct {
Ambient *Ambient
Ambient Ambient
Direct Light
Mat Material
Normals texture.VectorField
Expand All @@ -30,11 +30,7 @@ func (bm *BumpMap) Eval2(x, y float64) color.Color {
_, amb, diff, _, _, _ := material.Eval2(x, y)

// Ambient
ambient := bm.Ambient
if ambient == nil {
ambient = &DefaultAmbient
}
col := amb.Prod(ambient.Color)
col := amb.Prod(bm.Ambient.Color)

// Diffuse
direct := bm.Direct
Expand Down
40 changes: 19 additions & 21 deletions surface/surface.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ func (s *Surface) Eval2(x, y float64) col.Color {
lamb := amb.Prod(acol) // Ambient
col := em // Emissive
col = col.Add(lamb)
/*
if diff == nil {
return col
}
*/
if diff.A < 0.00001 {
return col
}

// Cummulative diffuse and specular for all lights
normal := normals.Eval2(x, y)
Expand All @@ -64,24 +62,24 @@ func (s *Surface) Eval2(x, y float64) col.Color {
lcol = lcol.Scale(pow / (dist * dist))
}
cdiff = cdiff.Add(lcol.Prod(diff.Scale(lambert))) // Diffuse
//if spec != nil {
if blinn {
// Blinn-Phong
half := Unit([]float64{dir[0] + view[0], dir[1] + view[1], dir[2] + view[2]})
dp := Dot(half, normal)
if dp > 0 {
phong := math.Pow(dp, shine*4)
cspec = cspec.Add(lcol.Prod(spec.Scale(phong))) // Specular
}
} else {
// Phong
dp := Dot(Reflect(dir, normal), view)
if dp > 0 {
phong := math.Pow(dp, shine)
cspec = cspec.Add(lcol.Prod(spec.Scale(phong))) // Specular
if spec.A > 0.00001 {
if blinn {
// Blinn-Phong
half := Unit([]float64{dir[0] + view[0], dir[1] + view[1], dir[2] + view[2]})
dp := Dot(half, normal)
if dp > 0 {
phong := math.Pow(dp, shine*4)
cspec = cspec.Add(lcol.Prod(spec.Scale(phong))) // Specular
}
} else {
// Phong
dp := Dot(Reflect(dir, normal), view)
if dp > 0 {
phong := math.Pow(dp, shine)
cspec = cspec.Add(lcol.Prod(spec.Scale(phong))) // Specular
}
}
}
//}
}
col = col.Add(cdiff)
col = col.Add(cspec)
Expand Down

0 comments on commit ff64be2

Please sign in to comment.