-
Notifications
You must be signed in to change notification settings - Fork 61
EllenDuong_Project1Noise_Submission #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eldu
wants to merge
5
commits into
CIS700-Procedural-Graphics:master
Choose a base branch
from
eldu:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| varying vec2 vUv; | ||
| varying vec3 vNormal; | ||
| varying vec3 vPosition; | ||
| varying float noise; | ||
| uniform sampler2D image; | ||
| varying float vTime; | ||
|
|
||
| void main() { | ||
| gl_FragColor = vec4(vNormal, 1.0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Color should be based on a noise function as well! |
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| #define M_PI 3.14159265 | ||
|
|
||
| varying vec2 vUv; | ||
| varying vec3 vNormal; | ||
| varying vec3 vPosition; | ||
| varying float noise; | ||
| varying float vTime; | ||
|
|
||
| uniform float time; | ||
| uniform float persistence; | ||
| uniform float octaves; | ||
| const int max_octaves = 30; | ||
|
|
||
| float noise_gen2(int x, int y, int z) { | ||
| return fract(sin(dot(vec3(x, y, z), vec3(12.9898, 78.233, 43.29179))) * 43758.5453); | ||
| } | ||
|
|
||
| // Smooth Noise | ||
| // Takes into account the surrounding noise | ||
| float smoothNoise(int x, int y, int z) { | ||
| // Non-smooth noise | ||
| // return noise_gen2(x, y, z); | ||
|
|
||
| // Smooth Noise | ||
| float center = noise_gen2(x, y, z) / 8.0; | ||
| float adj = (noise_gen2(x + 1, y, z) + noise_gen2(x - 1, y, z) | ||
| + noise_gen2(x, y + 1, z) + noise_gen2(x, y - 1, z) | ||
| + noise_gen2(x, y, z + 1) + noise_gen2(x, y, z - 1)) / 16.0; | ||
| float diag = (noise_gen2(x + 1, y + 1, z) | ||
| + noise_gen2(x + 1, y - 1, z) | ||
| + noise_gen2(x - 1, y + 1, z) | ||
| + noise_gen2(x - 1, y - 1, z) | ||
| + noise_gen2(x + 1, y, z + 1) | ||
| + noise_gen2(x + 1, y, z - 1) | ||
| + noise_gen2(x - 1, y, z + 1) | ||
| + noise_gen2(x - 1, y, z - 1) | ||
| + noise_gen2(x, y + 1, z + 1) | ||
| + noise_gen2(x, y + 1, z - 1) | ||
| + noise_gen2(x, y - 1, z + 1) | ||
| + noise_gen2(x, y - 1, z - 1)) / 32.0; | ||
| float corners = (noise_gen2(x + 1, y + 1, z + 1) | ||
| + noise_gen2(x + 1, y + 1, z - 1) | ||
| + noise_gen2(x + 1, y - 1, z + 1) | ||
| + noise_gen2(x + 1, y - 1, z - 1) | ||
| + noise_gen2(x - 1, y + 1, z + 1) | ||
| + noise_gen2(x - 1, y + 1, z - 1) | ||
| + noise_gen2(x - 1, y - 1, z + 1) | ||
| + noise_gen2(x - 1, y - 1, z - 1)) / 64.0; | ||
|
|
||
| return center + adj + diag + corners; | ||
| } | ||
|
|
||
| // Cosine Interpolation | ||
| // Interpolates x, between [a, b] | ||
| // Typically use [-1, 1] | ||
| float cerp(float a, float b, float x) { | ||
| float y = x * M_PI; | ||
| y = (1.0 - cos(y)) * 0.5; // y is inbetween [0, 1] | ||
| return a * (1.0 - y) + b * y; // map y between and b | ||
| } | ||
|
|
||
| float cerpNoise(float x, float y, float z) { | ||
| int x_whole = int(x); | ||
| float x_fract = fract(x); | ||
|
|
||
| int y_whole = int(y); | ||
| float y_fract = fract(y); | ||
|
|
||
| int z_whole = int(z); | ||
| float z_fract = fract(z); | ||
|
|
||
| float v1 = smoothNoise(x_whole, y_whole, z_whole); | ||
| float v2 = smoothNoise(x_whole + 1, y_whole, z_whole); | ||
|
|
||
| float v3 = smoothNoise(x_whole, y_whole + 1, z_whole); | ||
| float v4 = smoothNoise(x_whole + 1, y_whole + 1, z_whole); | ||
|
|
||
| float v5 = smoothNoise(x_whole, y_whole, z_whole + 1); | ||
| float v6 = smoothNoise(x_whole + 1, y_whole, z_whole + 1); | ||
|
|
||
| float v7 = smoothNoise(x_whole, y_whole + 1, z_whole + 1); | ||
| float v8 = smoothNoise(x_whole + 1, y_whole + 1, z_whole + 1); | ||
|
|
||
|
|
||
| // Cerp over the x axis | ||
| float x00 = cerp(v1, v2, x_fract); | ||
| float x01 = cerp(v3, v4, x_fract); | ||
| float x10 = cerp(v5, v6, x_fract); | ||
| float x11 = cerp(v7, v8, x_fract); | ||
|
|
||
| float y0 = cerp(x00, x01, y_fract); | ||
| float y1 = cerp(x10, x11, y_fract); | ||
|
|
||
|
|
||
| return cerp(y0, y1, z_fract); | ||
| } | ||
|
|
||
| // Noise | ||
| // Perlin Noise | ||
| // Fractional Brownian Motion | ||
| float fnoise(float x, float y, float z) { | ||
| float total = 0.0; | ||
| float p = persistence; | ||
| int n = int(octaves); | ||
|
|
||
| for (int i = 0; i < max_octaves; i++) { | ||
| float frequency = pow(2.0, float(i)); | ||
| float amplitude = pow(p, float(i)); | ||
| total = total + cerpNoise(x * frequency, y * frequency, z * frequency) * amplitude; | ||
|
|
||
| if (i >= n) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return total; | ||
| } | ||
|
|
||
| void main() { | ||
| vUv = uv; | ||
| vNormal = normal; | ||
| vTime = time; | ||
|
|
||
| noise = fnoise(position[0] + vTime, position[1] + vTime, position[2] + vTime); | ||
| vec3 displacement = noise * normal; | ||
| gl_Position = projectionMatrix * modelViewMatrix * vec4(position + displacement, 1.0 ); | ||
| vPosition = vec3(gl_Position); | ||
| } |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value should probably be bounded from 0 to 1. Greater than 1 and your function grows out of control as you increase octaves.