dilevin / computer-graphics-shader-pipeline

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

Perlin noise colour problem #42

Open yunhaom94 opened 4 years ago

yunhaom94 commented 4 years ago

1

Things I have tried so far:

  1. I normalized the colour value so that it falls to [0,1] ( Perlin noise results [-1, 1])
  2. I used some combinations of sin/cos functions on sphere's world coordinate as seed
  3. I tried to add up different noise values
  4. I even implemented Perlin noise in python just to see the printed output and it looks just fine lying between [-1, 1]

Yet I'm still getting this kind of stepped colour output?

yunhaom94 commented 4 years ago

image

Here is the same Perlin noise I wrote in Python, just using 2D input instead of 3D.

abhimadan commented 4 years ago

Check that the interpolation parameter passed to smooth_step lies between 0 and 1. You should verify that the basic case (no input scaling, no function composition) looks smooth before trying different effects.

yunhaom94 commented 4 years ago
3

I tried vec3(sin(sphere_fs_in.x), sin(sphere_fs_in.x), sin(sphere_fs_in.z)) as input, it looked like above

abhimadan commented 4 years ago

Is this your input to Perlin noise? You shouldn't be making the input periodic like this because it makes it tricky to ensure that the output is smooth across grid cubes. If you want to use sin and cos to create turbulence, you apply it to the output of Perlin noise.

yunhaom94 commented 4 years ago

image

This is what I got from using sphere's 3d coordinate as direct input into Perlin noise, sin() the result got similar effect

abhimadan commented 4 years ago

These discontinuities are caused by your input parameter to smooth_step not reaching 0 and 1 at the edges of the cubes. The simplest way to ensure this is that you are using unit cubes; then, you can simply use the fractional component to pass to smooth_step.

yunhaom94 commented 4 years ago

I generated the unit cube by taking floor and ceiling of the point, and I passed in the fractional part of the vertices only, it does look smoother, however there is still some strange misalignment? image

abhimadan commented 4 years ago

The pattern looks like it's oscillating very quickly inside a cube, which shouldn't happen. Make sure that you are implementing trilinear interpolation correctly. To simplify debugging, try using hardcoded colour values at each integer point in [-1,1]x[-1,1]x[-1,1] and use the fraction directly, so you can tell what the interpolation should be doing. Once you've verified this works, you can debug smooth_step and then the interpolation of random values.

yunhaom94 commented 4 years ago

Thanks, looks like my cube definition was in incorrect order. After I rearrange the corners it seems to be working now.