-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
259 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package bsdf | ||
|
||
const ( | ||
deltaEps = 1.0e-12 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,71 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"fmt" | ||
"math" | ||
) | ||
|
||
type Color struct { | ||
R, G, B Float | ||
R, G, B Float | ||
} | ||
|
||
func NewColor(r, g, b Float) *Color { | ||
c := &Color{} | ||
c.R = r | ||
c.G = g | ||
c.B = b | ||
return c | ||
c := &Color{} | ||
c.R = r | ||
c.G = g | ||
c.B = b | ||
return c | ||
} | ||
|
||
func NewColorWithString(s string) *Color { | ||
var r, g, b Float | ||
n, _ := fmt.Sscanf(s, "(%f, %f, %f)", &r, &g, &b) | ||
if n != 3 { | ||
panic(fmt.Sprintf("Failed to parse Vector3d: %s", s)) | ||
} | ||
return &Color{r, g, b} | ||
var r, g, b Float | ||
n, _ := fmt.Sscanf(s, "(%f, %f, %f)", &r, &g, &b) | ||
if n != 3 { | ||
panic(fmt.Sprintf("Failed to parse Vector3d: %s", s)) | ||
} | ||
return &Color{r, g, b} | ||
} | ||
|
||
|
||
func (c *Color) Y() Float { | ||
return 0.299 * c.R + 0.587 * c.G + 0.114 * c.B | ||
return 0.299*c.R + 0.587*c.G + 0.114*c.B | ||
} | ||
|
||
func (c *Color) IsBlack() bool { | ||
return c.R == 0.0 && c.G == 0.0 && c.B == 0.0 | ||
return c.R == 0.0 && c.G == 0.0 && c.B == 0.0 | ||
} | ||
|
||
func (c *Color) IsNaN() bool { | ||
return math.IsNaN(c.R) || math.IsNaN(c.G) || math.IsNaN(c.B) | ||
} | ||
|
||
func (c *Color) IsInf() bool { | ||
return math.IsInf(c.R, 0) || math.IsInf(c.G, 0) || math.IsInf(c.B, 0) | ||
} | ||
|
||
func (c *Color) IsValid() bool { | ||
return !c.IsInf() && !c.IsNaN() | ||
} | ||
|
||
func (c1 *Color) Add(c2 *Color) *Color { | ||
ret := &Color{} | ||
ret.R = c1.R + c2.R | ||
ret.G = c1.G + c2.G | ||
ret.B = c1.B + c2.B | ||
return ret | ||
ret := &Color{} | ||
ret.R = c1.R + c2.R | ||
ret.G = c1.G + c2.G | ||
ret.B = c1.B + c2.B | ||
return ret | ||
} | ||
|
||
func (c *Color) Scale(x Float) *Color { | ||
ret := &Color{} | ||
ret.R = c.R * x | ||
ret.G = c.G * x | ||
ret.B = c.B * x | ||
return ret | ||
ret := &Color{} | ||
ret.R = c.R * x | ||
ret.G = c.G * x | ||
ret.B = c.B * x | ||
return ret | ||
} | ||
|
||
func (c1 *Color) Multiply(c2 *Color) *Color { | ||
ret := &Color{} | ||
ret.R = c1.R * c2.R | ||
ret.G = c1.G * c2.G | ||
ret.B = c1.B * c2.B | ||
return ret | ||
ret := &Color{} | ||
ret.R = c1.R * c2.R | ||
ret.G = c1.G * c2.G | ||
ret.B = c1.B * c2.B | ||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
package core | ||
|
||
import "math" | ||
|
||
type Intersection struct { | ||
Pos, Normal, Wo *Vector3d | ||
primitive *Primitive | ||
Pos, Normal, Wo *Vector3d | ||
primitive *Primitive | ||
} | ||
|
||
func NewIntersection(pos, normal, wo *Vector3d) *Intersection { | ||
isect := &Intersection{} | ||
isect.Pos = pos | ||
isect.Normal = normal | ||
isect.Wo = wo | ||
isect.primitive = nil | ||
return isect | ||
isect := &Intersection{} | ||
isect.Pos = pos | ||
isect.Normal = normal | ||
isect.Wo = wo | ||
isect.primitive = nil | ||
return isect | ||
} | ||
|
||
func (isect *Intersection) SpawnRay(wi *Vector3d) *Ray { | ||
return NewRay(isect.Pos, wi) | ||
return NewRay(isect.Pos, wi) | ||
} | ||
|
||
func (isect *Intersection) Bsdf() *Bsdf { | ||
return NewBsdf(isect, isect.primitive.Bxdf()) | ||
return NewBsdf(isect, isect.primitive.Bxdf()) | ||
} | ||
|
||
func (isect *Intersection) Le(wi *Vector3d) *Color { | ||
if isect.primitive.Light() == nil { | ||
return NewColor(0.0, 0.0, 0.0) | ||
} | ||
dot := wi.Dot(isect.Normal) | ||
return isect.primitive.Light().Le().Scale(dot) | ||
if isect.primitive.Light() == nil { | ||
return NewColor(0.0, 0.0, 0.0) | ||
} | ||
dot := math.Max(0.0, wi.Dot(isect.Normal)) | ||
return isect.primitive.Light().Le().Scale(dot) | ||
} |
Oops, something went wrong.