dilevin / computer-graphics-shader-pipeline

Computer Graphics Assignment about the Shader Pipeline
2 stars 5 forks source link

Perlin Noise algorithm #24

Closed Geetchopra closed 5 years ago

Geetchopra commented 5 years ago

I am having trouble getting perlin noise to be "noisy". Currently it outputs the same value for every point when used in procedural color.

For perlin noise, how are the gradient and distance vectors supposed to be calculated? And in procedural_color.glsl, I am not needed to do any randomization of the seed value, right?

rin-23 commented 5 years ago

Q: For perlin noise, how are the gradient and distance vectors supposed to be calculated? A: imagine your sphere is embedded into a 3D grid. Each point on the gird has integer coordinates. Also each grid point has a vector assigned to it pointing in a random direction. You can use random_direction function to generate that random vector. Now you want to calculate noise at some point in that grid. That point however doesnt need to have integer coordinates. Its just some point anywhere inside that 3d grid. Your job is figure which of the "subcubes" of the 3d grid contains that point. Then using random vectors at cubes corners and vector from the corner to your point you can use dot product to calculate noise value at the corners and use trilinear interpolation to calculate the noise value at your point.

This is a good resource for perlin noise - https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/perlin-noise-part-2 This is a good intro as well - https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/procedural-patterns-noise-part-1 Bookofshaders-https://thebookofshaders.com/11/

Q:And in procedural_color.glsl, I am not needed to do any randomization of the seed value, right? A: You can think of perlin_noise function as a sin(seed) function (kinda). You can change sin function by increasing its amplitude(A) and frequency(f) like this A*sin(f*seed). Same logic applies to perlin_noise. By adding noises of different amplitude and frequency you can create cool results.

Geetchopra commented 5 years ago

I was looking at these resources and used the algorithm from there. I used the procedural_color algorithm you used and am now getting this. Is this intended? (Removed the moon for brevity)

Screen Shot 2019-03-15 at 19 54 59

Geetchopra commented 5 years ago

Sub-Question - Based on the same algorithm used above this is my output for bump.fs. What could I be doing wrong?

Screen Shot 2019-03-15 at 20 21 49

rin-23 commented 5 years ago
  1. We expect that noise should look "smoother". See the example in the assignment.
  2. Hard to say by just looking at the pic.