Skip to content

Commit bc3be52

Browse files
committed
Bugfix for determining negative division indices
1 parent a4d8484 commit bc3be52

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/volumetric_clouds/main.clj

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
:tags [:visualization]}}}
1212

1313
(ns volumetric-clouds.main
14-
(:require [clojure.math :refer (PI sqrt cos sin tan to-radians pow)]
14+
(:require [clojure.math :refer (PI sqrt cos sin tan to-radians pow floor)]
1515
[midje.sweet :refer (fact facts tabular => roughly)]
1616
[fastmath.vector :refer (vec2 vec3 add mult sub div mag dot normalize)]
1717
[fastmath.matrix :refer (mat->float-array mulm mulv inverse
@@ -177,16 +177,19 @@
177177
(wrap-get (wrap-get t 5) 3) => (vec2 1 3)))
178178

179179

180+
;; The following function converts a noise coordinate to the index of a cell in the random point array.
180181
(defn division-index
181182
[{:keys [cellsize]} x]
182-
(int (/ x cellsize)))
183-
183+
(int (floor (/ x cellsize))))
184184

185185
(facts "Convert coordinate to division index"
186-
(division-index {:cellsize 4} 3.5) => 0
187-
(division-index {:cellsize 4} 7.5) => 1)
188-
186+
(division-index {:cellsize 4} 3.5) => 0
187+
(division-index {:cellsize 4} 7.5) => 1
188+
(division-index {:cellsize 4} -0.5) => -1)
189189

190+
;; ### Getting indices of Neighbours
191+
;;
192+
;; The following function determines the neighbouring indices of a cell.recursing over each dimension.
190193
(defn neighbours
191194
[& args]
192195
(if (seq args)
@@ -197,6 +200,7 @@
197200

198201
(facts "Get neighbouring indices"
199202
(neighbours) => [[]]
203+
(neighbours 0) => [[-1] [0] [1]]
200204
(neighbours 3) => [[2] [3] [4]]
201205
(neighbours 1 10) => [[0 9] [1 9] [2 9] [0 10] [1 10] [2 10] [0 11] [1 11] [2 11]])
202206

@@ -1226,7 +1230,7 @@ void main()
12261230
(+ 0.75 (* 0.25 (scatter-amount (to-radians theta))))))
12271231
(range 361)) })]
12281232
(-> scatter
1229-
(plotly/base {:=title "Mie scattering" :=mode "lines"})
1233+
(plotly/base {:=title "Mixed Mie and isotropic scattering" :=mode "lines"})
12301234
(plotly/layer-point {:=x :x :=y :y})
12311235
plotly/plot
12321236
(assoc-in [:layout :yaxis :scaleanchor] "x")))
@@ -1279,7 +1283,8 @@ float shadow(vec3 point)
12791283
(GLFW/glfwTerminate)
12801284

12811285
;; ## Further topics
1282-
;; * vertical cloud profile
1283-
;; * powder function
1284-
;; * curl noise
1285-
;; * deep opacity maps https://www.wedesoft.de/software/2023/05/03/volumetric-clouds/
1286+
;;
1287+
;; * [Vertical density profile](https://www.wedesoft.de/software/2023/05/03/volumetric-clouds/)
1288+
;; * [Powder function](https://advances.realtimerendering.com/s2015/index.html)
1289+
;; * [Curl noise](https://www.wedesoft.de/software/2023/03/20/procedural-global-cloud-cover/)
1290+
;; * [Deep opacity maps](https://www.wedesoft.de/software/2023/05/03/volumetric-clouds/)

0 commit comments

Comments
 (0)