@@ -1198,7 +1198,7 @@ float noise(vec3 idx)
11981198 (teardown-vao vao)
11991199 (GL20/glDeleteProgram program)))))
12001200
1201- ; ; The noise is rendered with a step size of 0.01.
1201+ ; ; Now we can render the mixture of 3D Perlin and Worley noise using a step size of 0.01.
12021202(rgba-array->bufimg
12031203 (render-noise 640 480
12041204 constant-scatter no-shadow (cloud-transfer " noise" 0.01 ) noise-shader)
@@ -1256,10 +1256,10 @@ float remap_noise(vec3 idx)
12561256 return remap_clamp(<%= base %>(idx), <%= low1 %>, <%= high1 %>, 0.0, <%= high2 %>);
12571257}" ))
12581258
1259-
1259+ ; ; We are going to use the following value as the upper value of the cloud density.
12601260(def cloud-strength 6.5 )
12611261
1262-
1262+ ; ; Now we can render the remapped noise values.
12631263(rgba-array->bufimg
12641264 (render-noise 640 480
12651265 constant-scatter no-shadow (cloud-transfer " remap_noise" 0.01 )
@@ -1268,7 +1268,9 @@ float remap_noise(vec3 idx)
12681268
12691269
12701270; ; ### Octaves of 3D noise
1271-
1271+ ; ;
1272+ ; ; Earlier we defined a function for creating octaves of 3D noise.
1273+ ; ; Here we create octaves of noise before remapping and clamping the values.
12721274(rgba-array->bufimg
12731275 (render-noise 640 480 constant-scatter no-shadow (cloud-transfer " remap_noise" 0.01 )
12741276 remap-clamp (remap-noise " octaves" 0.45 0.9 cloud-strength)
@@ -1277,7 +1279,9 @@ float remap_noise(vec3 idx)
12771279
12781280
12791281; ; ### Mie scattering
1280-
1282+ ; ;
1283+ ; ; In-scattering of light towards the observer depends of the angle between light source and viewing direction.
1284+ ; ; Here we are going to use the phase function by Cornette and Shanks which depends on the asymmetry g and mu = cos(theta).
12811285(def mie-scatter
12821286 (template/fn [g]
12831287" #version 450 core
@@ -1294,7 +1298,7 @@ float in_scatter(vec3 point, vec3 direction)
12941298 return mix(1.0, mie(dot(light, direction)), ANISOTROPIC);
12951299}" ))
12961300
1297-
1301+ ; ; We define a probing shader.
12981302(def mie-probe
12991303 (template/fn [mu]
13001304" #version 450 core
@@ -1306,7 +1310,7 @@ void main()
13061310 fragColor = vec4(result, 0, 0, 1);
13071311}" ))
13081312
1309-
1313+ ; ; The shader is tested using a few values.
13101314(tabular " Shader function for scattering phase function"
13111315 (fact (first (render-pixel [vertex-passthrough] [(mie-scatter ?g) (mie-probe ?mu)]))
13121316 => (roughly ?result 1e-6 ))
@@ -1317,11 +1321,11 @@ void main()
13171321 0.5 0 (/ (* 3 0.75 ) (* 8 PI 2.25 (pow 1.25 1.5 )))
13181322 0.5 1 (/ (* 6 0.75 ) (* 8 PI 2.25 (pow 0.25 1.5 ))))
13191323
1320-
1324+ ; ; We can define a function to compute a particular value of the scattering phase function using the GPU.
13211325(defn scatter-amount [theta]
13221326 (first (render-pixel [vertex-passthrough] [(mie-scatter 0.76 ) (mie-probe (cos theta))])))
13231327
1324-
1328+ ; ; We can use this function to plot a mix of isotropic and anisotropic scattering.
13251329(let [scatter
13261330 (tc/dataset {:x (map (fn [theta]
13271331 (* (cos (to-radians theta))
@@ -1337,7 +1341,7 @@ void main()
13371341 plotly/plot
13381342 (assoc-in [:layout :yaxis :scaleanchor ] " x" )))
13391343
1340-
1344+ ; ; Now the clouds look a bit more realistic.
13411345(rgba-array->bufimg
13421346 (render-noise 640 480 (mie-scatter 0.76 ) no-shadow (cloud-transfer " remap_noise" 0.01 )
13431347 remap-clamp (remap-noise " octaves" 0.45 0.9 cloud-strength)
0 commit comments