Skip to content

Commit

Permalink
Frequency control for noise
Browse files Browse the repository at this point in the history
  • Loading branch information
Slowyn committed Sep 9, 2024
1 parent 3434ecd commit 6221efb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ perlinSpheresScene w aspectRatio samplesPerPixel maxDepth gen = do
focusDist
samplesPerPixel
maxDepth
perlinTexture <- mkNoiseTexture gen
perlinTexture <- mkNoiseTexture gen 4
let perlinSurface = Lambertian perlinTexture
sphereGround = mkSomeObject (mkSphere (fromXYZ (0, -1000, 0)) 1000) perlinSurface
sphere1 = mkSomeObject (mkSphere (fromXYZ (0, 2, 0)) 2.0) perlinSurface
Expand Down
10 changes: 5 additions & 5 deletions app/Texture/Perlin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ noise perlin point = trilinearInterpolation c u' v' w'
values perlin V.! (dx `xor` dy `xor` dz)
)

newtype NoiseTexture = NoiseTexture Perlin
data NoiseTexture = NoiseTexture !Perlin !Double

instance Show NoiseTexture where
show _ = "Noise Texture"

instance Texture NoiseTexture where
value (NoiseTexture perlin) _u _v point = fromXYZ (1, 1, 1) .^ noise perlin point
value (NoiseTexture perlin scale) _u _v point = fromXYZ (1, 1, 1) .^ noise perlin (point .^ scale)

mkNoiseTexture :: (StatefulGen g m, PrimMonad m) => g -> m NoiseTexture
mkNoiseTexture gen = do
mkNoiseTexture :: (StatefulGen g m, PrimMonad m) => g -> Double -> m NoiseTexture
mkNoiseTexture gen scale = do
perlin <- mkPerlin gen
pure $ NoiseTexture perlin
pure $ NoiseTexture perlin scale
Binary file modified test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6221efb

Please sign in to comment.