-
-
Notifications
You must be signed in to change notification settings - Fork 213
ADDING SMOOTHNESS VIA TESSELLATION SHADERS #1688
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
perminder-17
wants to merge
15
commits into
OpenChemistry:master
Choose a base branch
from
perminder-17:smoothing-via-tessellation
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 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e033a74
smooothing-via-bezier-surface
perminder-17 0d40651
creating shader program
perminder-17 c7943b8
fixing
perminder-17 659996f
fixes
perminder-17 2801d59
fixes
perminder-17 6dab739
Completingg tessellation shaders
perminder-17 4bdf4e4
fixes
perminder-17 ae1d1f8
some fixes
perminder-17 08414a6
fixes
perminder-17 195b594
made-it-working
perminder-17 a4626a1
minor-fixes
perminder-17 dab7b54
Removing debbugging peices
perminder-17 96cabc8
Reverting changes
perminder-17 048c898
Removing debugging peices.
perminder-17 e5454a2
fixes
perminder-17 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #version 400 | ||
| precision highp float; // precision qualifier | ||
|
|
||
| // outputing a single CP | ||
| layout(vertices = 1) out; | ||
|
|
||
| in vec3 WorldPos_CS_in[]; | ||
| in vec2 TexCoord_CS_in[]; | ||
| in vec3 fnormal[]; | ||
|
|
||
| struct OutputPatch { | ||
| vec3 WorldPos_B030; | ||
| vec3 WorldPos_B021; | ||
| vec3 WorldPos_B012; | ||
| vec3 WorldPos_B003; | ||
| vec3 WorldPos_B102; | ||
| vec3 WorldPos_B201; | ||
| vec3 WorldPos_B300; | ||
| vec3 WorldPos_B210; | ||
| vec3 WorldPos_B120; | ||
| vec3 WorldPos_B111; | ||
|
|
||
| vec3 Normal[3]; | ||
| vec2 TexCoord[3]; | ||
| }; | ||
|
|
||
| const float gTessellationLevel = 4.0; // Constant declaration is fine | ||
|
|
||
| // encapsulated all the data of the output patch in the OutputPatch | ||
| // struct above and declared an output variable called oPatch of that type | ||
|
|
||
| out patch OutputPatch oPatch; | ||
|
|
||
|
|
||
| // This function is used by CalcPositions() to project a midpoint on | ||
| // the plane defined by the nearest vertex and its normal. | ||
| vec3 ProjectToPlane(vec3 Point, vec3 PlanePoint, vec3 PlaneNormal) { | ||
| vec3 v = Point - PlanePoint; | ||
| float Len = dot(v, PlaneNormal); | ||
| vec3 d = Len * PlaneNormal; | ||
| return (Point - d); | ||
| } | ||
|
|
||
| void CalcPositions() { | ||
| // The original vertices stay the same | ||
| oPatch.WorldPos_B030 = WorldPos_CS_in[0]; | ||
| oPatch.WorldPos_B003 = WorldPos_CS_in[1]; | ||
| oPatch.WorldPos_B300 = WorldPos_CS_in[2]; | ||
|
|
||
| // Edges are named according to the opposing vertex | ||
| vec3 EdgeB300 = oPatch.WorldPos_B003 - oPatch.WorldPos_B030; | ||
| vec3 EdgeB030 = oPatch.WorldPos_B300 - oPatch.WorldPos_B003; | ||
| vec3 EdgeB003 = oPatch.WorldPos_B030 - oPatch.WorldPos_B300; | ||
|
|
||
| // Generate two midpoints on each edge | ||
| oPatch.WorldPos_B021 = oPatch.WorldPos_B030 + EdgeB300 / 3.0; | ||
| oPatch.WorldPos_B012 = oPatch.WorldPos_B030 + EdgeB300 * 2.0 / 3.0; | ||
| oPatch.WorldPos_B102 = oPatch.WorldPos_B003 + EdgeB030 / 3.0; | ||
| oPatch.WorldPos_B201 = oPatch.WorldPos_B003 + EdgeB030 * 2.0 / 3.0; | ||
| oPatch.WorldPos_B210 = oPatch.WorldPos_B300 + EdgeB003 / 3.0; | ||
| oPatch.WorldPos_B120 = oPatch.WorldPos_B300 + EdgeB003 * 2.0 / 3.0; | ||
|
|
||
| // Project each midpoint on the plane defined by the nearest vertex and its normal | ||
| oPatch.WorldPos_B021 = ProjectToPlane(oPatch.WorldPos_B021, oPatch.WorldPos_B030, oPatch.Normal[0]); | ||
| oPatch.WorldPos_B012 = ProjectToPlane(oPatch.WorldPos_B012, oPatch.WorldPos_B003, oPatch.Normal[1]); | ||
| oPatch.WorldPos_B102 = ProjectToPlane(oPatch.WorldPos_B102, oPatch.WorldPos_B003, oPatch.Normal[1]); | ||
| oPatch.WorldPos_B201 = ProjectToPlane(oPatch.WorldPos_B201, oPatch.WorldPos_B300, oPatch.Normal[2]); | ||
| oPatch.WorldPos_B210 = ProjectToPlane(oPatch.WorldPos_B210, oPatch.WorldPos_B300, oPatch.Normal[2]); | ||
| oPatch.WorldPos_B120 = ProjectToPlane(oPatch.WorldPos_B120, oPatch.WorldPos_B030, oPatch.Normal[0]); | ||
|
|
||
| // Handle the center | ||
| vec3 Center = (oPatch.WorldPos_B003 + oPatch.WorldPos_B030 + oPatch.WorldPos_B300) / 3.0; | ||
| oPatch.WorldPos_B111 = (oPatch.WorldPos_B021 + oPatch.WorldPos_B012 + oPatch.WorldPos_B102 + | ||
| oPatch.WorldPos_B201 + oPatch.WorldPos_B210 + oPatch.WorldPos_B120) / 6.0; | ||
| oPatch.WorldPos_B111 += (oPatch.WorldPos_B111 - Center) / 2.0; | ||
| } | ||
|
|
||
| void main(void) { | ||
|
|
||
| // The three normals and texture coordinates are copied | ||
| // as-is from the input into the output patch. | ||
|
|
||
| for (int i = 0 ; i < 3 ; i++) { | ||
| oPatch.Normal[i] = fnormal[i]; | ||
| oPatch.TexCoord[i] = TexCoord_CS_in[i]; | ||
| } | ||
|
|
||
| // The 10 CPs that we are going to generate contain only a position value. | ||
| // This is done in a dedicated function called CalcPositions() | ||
|
|
||
| CalcPositions(); | ||
|
|
||
| // Calculate the tessellation levels | ||
| gl_TessLevelOuter[0] = gTessellationLevel; | ||
| gl_TessLevelOuter[1] = gTessellationLevel; | ||
| gl_TessLevelOuter[2] = gTessellationLevel; | ||
| gl_TessLevelOuter[3] = gTessellationLevel; | ||
| gl_TessLevelInner[0] = gTessellationLevel; | ||
| gl_TessLevelInner[1] = gTessellationLevel; | ||
| } |
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,59 @@ | ||
| #version 400 | ||
| precision highp float; // precision qualifier | ||
| layout(triangles, equal_spacing, ccw) in; // layout qualifier | ||
|
|
||
| uniform mat4 projection; | ||
| uniform mat4 modelView; | ||
|
|
||
| struct OutputPatch { | ||
| vec3 WorldPos_B030; | ||
| vec3 WorldPos_B021; | ||
| vec3 WorldPos_B012; | ||
| vec3 WorldPos_B003; | ||
| vec3 WorldPos_B102; | ||
| vec3 WorldPos_B201; | ||
| vec3 WorldPos_B300; | ||
| vec3 WorldPos_B210; | ||
| vec3 WorldPos_B120; | ||
| vec3 WorldPos_B111; | ||
|
|
||
| vec3 Normal[3]; | ||
| vec2 TexCoord[3]; | ||
| }; | ||
|
|
||
| in patch OutputPatch oPatch; // input patch qualifier | ||
| out vec3 WorldPos_FS_in; | ||
| out vec2 TexCoord_FS_in; | ||
| out vec3 Normal_FS_in; | ||
|
|
||
| vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2) { | ||
| return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2; | ||
| } | ||
|
|
||
| vec3 interpolate3D(vec3 v0, vec3 v1, vec3 v2) { | ||
| return vec3(gl_TessCoord.x) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2; | ||
| } | ||
|
|
||
| void main() { | ||
| // Interpolate the attributes of the output vertex using the barycentric coordinates | ||
| TexCoord_FS_in = interpolate2D(oPatch.TexCoord[0], oPatch.TexCoord[1], oPatch.TexCoord[2]); | ||
| Normal_FS_in = interpolate3D(oPatch.Normal[0], oPatch.Normal[1], oPatch.Normal[2]); | ||
|
|
||
| // bezier curve formula. | ||
|
|
||
| float u = gl_TessCoord.x; | ||
| float v = gl_TessCoord.y; | ||
| float w = gl_TessCoord.z; | ||
| float uPow3 = pow(u, 3); | ||
| float vPow3 = pow(v, 3); | ||
| float wPow3 = pow(w, 3); | ||
| float uPow2 = pow(u, 2); | ||
| float vPow2 = pow(v, 2); | ||
| float wPow2 = pow(w, 2); | ||
| WorldPos_FS_in = oPatch.WorldPos_B300 * wPow3 + oPatch.WorldPos_B030 * uPow3 + oPatch.WorldPos_B003 * vPow3 + | ||
| oPatch.WorldPos_B210 * 3.0 * wPow2 * u + oPatch.WorldPos_B120 * 3.0 * w * uPow2 + oPatch.WorldPos_B201 * 3.0 * wPow2 * v + | ||
| oPatch.WorldPos_B021 * 3.0 * uPow2 * v + oPatch.WorldPos_B102 * 3.0 * w * vPow2 + oPatch.WorldPos_B012 * 3.0 * u * vPow2 + | ||
| oPatch.WorldPos_B111 * 6.0 * w * u * v; | ||
|
|
||
| gl_Position = modelView * projection * vec4(WorldPos_FS_in, 1.0); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.