Gamma correction
This commit is contained in:
parent
297085e741
commit
8b06725106
2 changed files with 90008 additions and 90000 deletions
8
main.go
8
main.go
|
@ -147,6 +147,10 @@ func Degrees_to_radians(degrees float32) float32 {
|
||||||
return (degrees * pi) / 180.0
|
return (degrees * pi) / 180.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Linear_to_gamma(linear_component float32) float32 {
|
||||||
|
return float32(math.Sqrt(float64(linear_component)))
|
||||||
|
}
|
||||||
|
|
||||||
func RandomDouble() float32 {
|
func RandomDouble() float32 {
|
||||||
// Returns a random real in [0,1).
|
// Returns a random real in [0,1).
|
||||||
return rand.Float32()
|
return rand.Float32()
|
||||||
|
@ -173,6 +177,10 @@ func Write_color(v Vec3, samples_per_pixel int) {
|
||||||
g := v.Y() / float32(samples_per_pixel)
|
g := v.Y() / float32(samples_per_pixel)
|
||||||
b := v.Z() / float32(samples_per_pixel)
|
b := v.Z() / float32(samples_per_pixel)
|
||||||
|
|
||||||
|
r = Linear_to_gamma(r)
|
||||||
|
g = Linear_to_gamma(g)
|
||||||
|
b = Linear_to_gamma(b)
|
||||||
|
|
||||||
// Write the translate [0, 255] value of each color component
|
// Write the translate [0, 255] value of each color component
|
||||||
intensity := NewInterval(0.000, 0.999)
|
intensity := NewInterval(0.000, 0.999)
|
||||||
fmt.Println(int(intensity.Clamp(r)* 256.0), int(intensity.Clamp(g)* 256.0), int(intensity.Clamp(b)* 256.0))
|
fmt.Println(int(intensity.Clamp(r)* 256.0), int(intensity.Clamp(g)* 256.0), int(intensity.Clamp(b)* 256.0))
|
||||||
|
|
Loading…
Reference in a new issue