Skip to content

Commit 03eb2a9

Browse files
committed
Add tested noise octaves
1 parent 20d70b4 commit 03eb2a9

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

src/volumetric_clouds/main.clj

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void main()
667667

668668
(def noise-mock
669669
"#version 130
670-
float noise (vec3 idx)
670+
float noise(vec3 idx)
671671
{
672672
ivec3 v = ivec3(floor(idx.x), floor(idx.y), floor(idx.z)) % 2;
673673
return ((v.x == 1) == (v.y == 1)) == (v.z == 1) ? 1.0 : 0.0;
@@ -684,7 +684,6 @@ void main()
684684
fragColor = vec4(noise(vec3(<%= x %>, <%= y %>, <%= z %>)));
685685
}"))
686686

687-
(noise-probe 1 2 3)
688687

689688
(tabular "Test noise mock"
690689
(fact (nth (render-pixels [vertex-test] [noise-mock (noise-probe ?x ?y ?z)] 1 1) 0) => ?result)
@@ -699,6 +698,45 @@ void main()
699698
1 1 1 1.0)
700699

701700

701+
(def noise-octaves
702+
(template/fn [octaves]
703+
"#version 130
704+
out vec4 fragColor;
705+
float noise(vec3 idx);
706+
float octaves(vec3 idx)
707+
{
708+
float result = 0.0;
709+
<% (doseq [multiplier octaves] %>
710+
result += <%= multiplier %> * noise(idx);
711+
idx *= 2.0;
712+
<%= ) %>
713+
return result;
714+
}"))
715+
716+
717+
(def octaves-probe
718+
(template/fn [x y z]
719+
"#version 130
720+
out vec4 fragColor;
721+
float octaves(vec3 idx);
722+
void main()
723+
{
724+
fragColor = vec4(octaves(vec3(<%= x %>, <%= y %>, <%= z %>)));
725+
}"))
726+
727+
728+
(tabular "Test octaves of noise"
729+
(fact (nth (render-pixels [vertex-test] [noise-mock (noise-octaves ?octaves) (octaves-probe ?x ?y ?z)] 1 1) 0)
730+
=> ?result)
731+
?x ?y ?z ?octaves ?result
732+
0 0 0 [1.0] 0.0
733+
1 0 0 [1.0] 1.0
734+
1 0 0 [0.5] 0.5
735+
0.5 0 0 [0.0 1.0] 1.0
736+
0.5 0 0 [0.0 1.0] 1.0
737+
1 0 0 [1.0 0.0] 1.0)
738+
739+
702740
(GLFW/glfwDestroyWindow window)
703741

704742
(GLFW/glfwTerminate)

0 commit comments

Comments
 (0)