Further, you compute an expensive Pow for "p" that you may not need because
of an intervening return. Moving it below the if/return saves 5.98% of
overall runtime:
if st == missDownward {
h = h.Scale(0.2)
fc := vector.Vector{X: 3, Y: 3, Z: 3}
if int(math.Ceil(h.X)+math.Ceil(h.Y))&1 == 1 {
fc = vector.Vector{X: 3, Y: 1, Z: 1}
}
return fc.Scale(b*0.2 + 0.1)
}
//moving here after possible return saves 5.98% of execution time
p := math.Pow(l.DotProduct(r.Scale(sf)), 99)
return vector.Vector{X: p, Y: p, Z: p}.Add(sampler(h, r).Scale(0.5))
...but that's not all. That Pow() of x**99 is expensive. Doing it
explicitly saves an additional 2.33% of execution time.
//computing x**99 explicitly saves a further 2.33% of execution time
//p := math.Pow(l.DotProduct(r.Scale(sf)), 99)
p := l.DotProduct(r.Scale(sf))
p33 := p * p // p**2
p33 = p33 * p33 // p**4
p33 = p33 * p33 // p**8
p33 = p33 * p33 // p**16
p33 = p33 * p33 // p**32
p33 = p33 * p // p**33
p = p33 * p33 * p33 // p**99
return vector.Vector{X: p, Y: p, Z: p}.Add(sampler(h, r).Scale(0.5))
Michael
P.S. Note the way I calculate p**99 saves multiplies compared to
p64*p32*p2*p. This is why I'd rather see exponentiation in a language. It
allows the compiler to optimize the multiply chains.
On Thu, Sep 26, 2013 at 10:36 AM, Karan Misra wrote:Or a pull request :P :)
On Thursday, September 26, 2013 8:05:54 AM UTC+5:30, Karan Misra wrote:Yep. I have noticed that before. I am working towards a fix which will
also scale the objects along with the image size.
On Thursday, September 26, 2013 8:00:50 AM UTC+5:30, Michael Jones wrote:There is also something strange about width and height. They do not
scale in such a way that the same image is rendered at higher resolution.
Instead, an MUCH easier image is rendered because the bulk of the image is
away from the reflective spheres.
See the two attached images. "Small" was rendered in the default 512x512
size. "Large" was at 2000x2000 then reduced in Photoshop to 512x512. Note
the increase in the number of "single ray intersection" cases.
On Thu, Sep 26, 2013 at 10:17 AM, Michael Jones wrote:Karan, making this change:
if st == missUpward {
//return vector.Vector{X: 0.7, Y: 0.6, Z: 1}.Scale(math.Pow(1-dir.Z, 4))
p := 1-dir.Z
p = p*p
p = p*p
return vector.Vector{X: 0.7, Y: 0.6, Z: 1}.Scale(p)
}
saves 5.4% on runtime. Generally, using a general tool (Pow, which
works for all real exponents) when all you really want is x**4, is very
expensive.
Michael
(in Kuala Lumpur)
On Thu, Sep 26, 2013 at 9:09 AM, Karan Misra wrote:Rog,
This definitely looks to be a better way of doing it:
https://github.com/**kid0m4n/gorays/commit/**ddfe825f0902877c02467a4f65f46c**4044bc7939<
https://github.com/kid0m4n/gorays/commit/ddfe825f0902877c02467a4f65f46c4044bc7939>
Thanks for the tip.
-k
On Wednesday, September 25, 2013 2:20:42 PM UTC+5:30, rog wrote:On 24 September 2013 23:25, Karan Misra wrote:
Must say, Go is proving to be very parallel in this particular
usecase. Any
comments on the parallel version?
I'd structure it slightly differently. There's no need to add to
the WaitGroup in every row.
Something like this, perhaps:
http://play.golang.org/p/**3bq22**6CdPI<http://play.golang.org/p/3bq226CdPI>
I see another ~6% speedup from that.
--
You received this message because you are subscribed to the Google
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to golang-nuts...@googlegroups.**com.
For more options, visit
https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
Michael T. Jones | Chief Technology Advocate | m...@google.com | +1
650-335-5765
--
Michael T. Jones | Chief Technology Advocate | m...@google.com | +1
650-335-5765
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out. --
Michael T. Jones | Chief Technology Advocate |
mtj@google.com | +1
650-335-5765
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.