-
Notifications
You must be signed in to change notification settings - Fork 61
HW 1 Submission #12
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
gracexu94
wants to merge
13
commits into
CIS700-Procedural-Graphics:master
Choose a base branch
from
gracexu94: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
HW 1 Submission #12
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6c6701a
changed shaders and started work on noise generation functions
gracexu94 23dfbd7
static offset working for one octave case
gracexu94 2993d47
transferred noise to shaders
gracexu94 9fddfba
added icosahedron level of detail to gui controls
gracexu94 7aa62ec
added displacement over time
gracexu94 745edb9
animate doesn't reset
gracexu94 ea11fe9
added multiple noise functions
gracexu94 435e833
added noise to fragment shader for coloring as well
gracexu94 f4f1784
added gui control for noise strength
gracexu94 2aa0536
updated README
gracexu94 46784a8
changed color to look more like smoke and added more octaves of noise
gracexu94 ad29070
cleaned up gui variables and updated README
gracexu94 c07272e
made some edits to gui constraints
gracexu94 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
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
| varying vec2 vUv; | ||
| varying float vNoise; | ||
| varying vec3 vNormal; | ||
|
|
||
| float linearInterpolate(float a, float b, float t) { | ||
| return a * (1.0 - t) + b * t; | ||
| } | ||
|
|
||
| void main() { | ||
| float r = linearInterpolate(0.0, 0.9, vNoise); | ||
| float g = linearInterpolate(0.0, 0.9, vNoise); | ||
| float b = linearInterpolate(0.0, 0.9, vNoise); | ||
|
|
||
| gl_FragColor = vec4(r, g, b, 1.0); | ||
| //gl_FragColor = vec4(vNormal.rgb, 1.0); | ||
| } |
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,90 @@ | ||
| varying vec2 vUv; | ||
| varying vec3 vNormal; | ||
| varying float vNoise; | ||
| uniform int numOctaves; | ||
| uniform float time; | ||
| uniform float noiseStrength; | ||
| const int aLargeNumber = 10; | ||
|
|
||
| float generateNoise(int x, int y, int z, int numOctave) { | ||
| if (numOctave == 0) { | ||
| return fract(sin(dot(vec3(x,y,z), vec3(12.9898, 78.23, 107.81))) * 43758.5453); | ||
| } else if (numOctave == 1) { | ||
| return fract(sin(dot(vec3(z,x,y), vec3(16.363, 43.597, 199.73))) * 69484.7539); | ||
| } else if (numOctave == 2) { | ||
| return fract(sin(dot(vec3(y,x,z), vec3(13.0, 68.819, 90.989))) * 92041.9823); | ||
| } else if (numOctave == 3) { | ||
| return fract(sin(dot(vec3(x,y,z), vec3(98.1577, 47.45029, 154.85161))) * 84499.0); | ||
| } else if (numOctave == 4) { | ||
| return fract(sin(dot(vec3(z,x,y), vec3(9.75367, 83.3057, 390.353))) * 15485.653); | ||
| } | ||
| } | ||
|
|
||
| float linearInterpolate(float a, float b, float t) { | ||
| return a * (1.0 - t) + b * t; | ||
| } | ||
|
|
||
| float cosineInterpolate(float a, float b, float t) { | ||
| float cos_t = (1.0 - cos(t * 3.14159265359879323846264)) * 0.5; | ||
| return linearInterpolate(a, b, cos_t); | ||
| } | ||
|
|
||
| // given a point in 3d space, produces a noise value by interpolating surrounding points | ||
| float interpolateNoise(float x, float y, float z, int numOctave) { | ||
| int integerX = int(floor(x)); | ||
| float weightX = x - float(integerX); | ||
|
|
||
| int integerY = int(floor(y)); | ||
| float weightY = y - float(integerY); | ||
|
|
||
| int integerZ = int(floor(z)); | ||
| float weightZ = z - float(integerZ); | ||
|
|
||
| float v1 = generateNoise(integerX, integerY, integerZ, numOctave); | ||
| float v2 = generateNoise(integerX, integerY, integerZ + 1, numOctave); | ||
| float v3 = generateNoise(integerX, integerY + 1, integerZ + 1, numOctave); | ||
| float v4 = generateNoise(integerX, integerY + 1, integerZ, numOctave); | ||
|
|
||
| float v5 = generateNoise(integerX + 1, integerY, integerZ, numOctave); | ||
| float v6 = generateNoise(integerX + 1, integerY, integerZ + 1, numOctave); | ||
| float v7 = generateNoise(integerX + 1, integerY + 1, integerZ + 1, numOctave); | ||
| float v8 = generateNoise(integerX + 1, integerY + 1, integerZ, numOctave); | ||
|
|
||
| float i1 = cosineInterpolate(v1, v5, weightX); | ||
| float i2 = cosineInterpolate(v2, v6, weightX); | ||
| float i3 = cosineInterpolate(v3, v7, weightX); | ||
| float i4 = cosineInterpolate(v4, v8, weightX); | ||
|
|
||
| float ii1 = cosineInterpolate(i1, i4, weightY); | ||
| float ii2 = cosineInterpolate(i2, i3, weightY); | ||
|
|
||
| return cosineInterpolate(ii1, ii2 , weightZ); | ||
| } | ||
|
|
||
| // a multi-octave noise generation function that sums multiple noise functions together | ||
| // with each subsequent noise function increasing in frequency and decreasing in amplitude | ||
| float generateMultiOctaveNoise(float x, float y, float z) { | ||
| float total = 0.0; | ||
| float persistence = 1.0/noiseStrength; | ||
|
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. It's a little odd that less "noise" makes it more noisy. |
||
|
|
||
| //loop for some number of octaves | ||
| for (int i = 0; i < aLargeNumber; i++) { | ||
| if (i == numOctaves) break; | ||
| float frequency = pow(2.0, float(i)); | ||
| float amplitude = pow(persistence, float(i)); | ||
|
|
||
| total += interpolateNoise(x * frequency, y * frequency, z * frequency, i) * amplitude; | ||
| } | ||
|
|
||
| return total; | ||
| } | ||
|
|
||
| void main() { | ||
| float offset = generateMultiOctaveNoise(position[0] + time/999.0, position[1] + time/999.0, position[2] + time/999.0); | ||
| vec3 newPosition = position + offset * normal; | ||
|
|
||
| gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 ); | ||
| vUv = uv; | ||
| vNormal = normal; | ||
| vNoise = offset; | ||
| } | ||
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.
Nice idea taking in the octave here to add variation