2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-12-11 01:15:13 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
// Patches.TessVertexBSpline
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
#ifdef OSD_PATCH_VERTEX_BSPLINE_SHADER
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-24 19:03:57 +00:00
|
|
|
layout(location = 0) in vec4 position;
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_ATTRIBUTE_DECLARE
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
out block {
|
|
|
|
ControlVertex v;
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_DECLARE
|
2013-06-10 19:53:04 +00:00
|
|
|
} outpt;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-24 19:03:57 +00:00
|
|
|
void main()
|
|
|
|
{
|
2013-12-03 23:59:38 +00:00
|
|
|
outpt.v.position = OsdModelViewMatrix() * position;
|
2012-12-11 01:15:13 +00:00
|
|
|
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position);
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_PER_VERTEX();
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
// Patches.TessControlBSpline
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
#ifdef OSD_PATCH_TESS_CONTROL_BSPLINE_SHADER
|
|
|
|
|
|
|
|
// Regular
|
|
|
|
uniform mat4 Q = mat4(
|
|
|
|
1.f/6.f, 4.f/6.f, 1.f/6.f, 0.f,
|
|
|
|
0.f, 4.f/6.f, 2.f/6.f, 0.f,
|
|
|
|
0.f, 2.f/6.f, 4.f/6.f, 0.f,
|
|
|
|
0.f, 1.f/6.f, 4.f/6.f, 1.f/6.f
|
|
|
|
);
|
|
|
|
|
2014-10-13 15:52:09 +00:00
|
|
|
// Infinite sharp
|
|
|
|
uniform mat4 Mi = mat4(
|
|
|
|
1.f/6.f, 4.f/6.f, 1.f/6.f, 0.f,
|
|
|
|
0.f, 4.f/6.f, 2.f/6.f, 0.f,
|
|
|
|
0.f, 2.f/6.f, 4.f/6.f, 0.f,
|
|
|
|
0.f, 0.f, 1.f, 0.f
|
|
|
|
);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
layout(vertices = 16) out;
|
|
|
|
|
|
|
|
in block {
|
|
|
|
ControlVertex v;
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_DECLARE
|
2013-06-10 19:53:04 +00:00
|
|
|
} inpt[];
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
out block {
|
|
|
|
ControlVertex v;
|
2015-04-17 23:26:57 +00:00
|
|
|
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
|
2014-10-13 15:52:09 +00:00
|
|
|
vec4 P1;
|
|
|
|
vec4 P2;
|
|
|
|
float sharpness;
|
2014-10-23 22:59:05 +00:00
|
|
|
#endif
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_DECLARE
|
2013-06-10 19:53:04 +00:00
|
|
|
} outpt[];
|
2012-12-11 01:15:13 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
patch out vec4 tessOuterLo, tessOuterHi;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
#define ID gl_InvocationID
|
2015-04-17 14:42:53 +00:00
|
|
|
|
2014-10-13 15:52:09 +00:00
|
|
|
// compute single-crease patch matrix
|
|
|
|
mat4
|
|
|
|
ComputeMatrixSimplified(float sharpness)
|
|
|
|
{
|
|
|
|
float s = pow(2.0f, sharpness);
|
|
|
|
float s2 = s*s;
|
|
|
|
float s3 = s2*s;
|
|
|
|
|
|
|
|
mat4 m = mat4(
|
|
|
|
0, s + 1 + 3*s2 - s3, 7*s - 2 - 6*s2 + 2*s3, (1-s)*(s-1)*(s-1),
|
|
|
|
0, (1+s)*(1+s), 6*s - 2 - 2*s2, (s-1)*(s-1),
|
|
|
|
0, 1+s, 6*s - 2, 1-s,
|
|
|
|
0, 1, 6*s - 2, 1);
|
|
|
|
|
|
|
|
m /= (s*6.0);
|
|
|
|
m[0][0] = 1.0/6.0;
|
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void main()
|
|
|
|
{
|
2013-06-24 19:03:57 +00:00
|
|
|
int i = ID%4;
|
|
|
|
int j = ID/4;
|
|
|
|
|
2015-04-21 16:50:34 +00:00
|
|
|
vec3 position[16];
|
2015-04-17 14:42:53 +00:00
|
|
|
for (int i=0; i<16; ++i) {
|
|
|
|
position[i] = inpt[i].v.position.xyz;
|
2013-06-24 19:03:57 +00:00
|
|
|
}
|
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
ivec3 patchParam = OsdGetPatchParam(OsdGetPatchIndex(gl_PrimitiveID));
|
2013-06-24 19:03:57 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
OsdComputeBSplineBoundaryPoints(position, patchParam);
|
2014-10-13 15:52:09 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
vec3 H[4];
|
2013-06-24 19:03:57 +00:00
|
|
|
for (int l=0; l<4; ++l) {
|
2012-12-11 01:15:13 +00:00
|
|
|
H[l] = vec3(0,0,0);
|
2013-06-24 19:03:57 +00:00
|
|
|
for (int k=0; k<4; ++k) {
|
2015-04-17 14:42:53 +00:00
|
|
|
H[l] += Q[i][k] * position[l*4 + k].xyz;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-17 23:26:57 +00:00
|
|
|
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
float sharpness = OsdGetPatchSharpness(patchParam);
|
2015-04-17 23:26:57 +00:00
|
|
|
if (sharpness > 0) {
|
|
|
|
float Sf = floor(sharpness);
|
|
|
|
float Sc = ceil(sharpness);
|
|
|
|
float Sr = fract(sharpness);
|
|
|
|
mat4 Mf = ComputeMatrixSimplified(Sf);
|
|
|
|
mat4 Mc = ComputeMatrixSimplified(Sc);
|
|
|
|
mat4 Mj = (1-Sr) * Mf + Sr * Mi;
|
|
|
|
mat4 Ms = (1-Sr) * Mf + Sr * Mc;
|
|
|
|
|
|
|
|
vec3 P = vec3(0);
|
|
|
|
vec3 P1 = vec3(0);
|
|
|
|
vec3 P2 = vec3(0);
|
|
|
|
for (int k=0; k<4; ++k) {
|
|
|
|
P += Mi[j][k]*H[k]; // 0 to 1-2^(-Sf)
|
|
|
|
P1 += Mj[j][k]*H[k]; // 1-2^(-Sf) to 1-2^(-Sc)
|
|
|
|
P2 += Ms[j][k]*H[k]; // 1-2^(-Sc) to 1
|
|
|
|
}
|
|
|
|
outpt[ID].v.position = vec4(P, 1.0);
|
|
|
|
outpt[ID].P1 = vec4(P1, 1.0);
|
|
|
|
outpt[ID].P2 = vec4(P2, 1.0);
|
|
|
|
outpt[ID].sharpness = sharpness;
|
|
|
|
} else {
|
|
|
|
vec3 pos = vec3(0,0,0);
|
|
|
|
for (int k=0; k<4; ++k) {
|
|
|
|
pos += Q[j][k]*H[k];
|
|
|
|
}
|
|
|
|
outpt[ID].v.position = vec4(pos, 1.0);
|
|
|
|
outpt[ID].P1 = vec4(0);
|
|
|
|
outpt[ID].P2 = vec4(0);
|
|
|
|
outpt[ID].sharpness = 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
vec3 pos = vec3(0,0,0);
|
|
|
|
for (int k=0; k<4; ++k) {
|
|
|
|
pos += Q[j][k]*H[k];
|
|
|
|
}
|
|
|
|
outpt[ID].v.position = vec4(pos, 1.0);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2014-10-13 15:52:09 +00:00
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-04-17 14:42:53 +00:00
|
|
|
OSD_USER_VARYING_PER_CONTROL_POINT(ID, ID);
|
2013-06-28 21:05:47 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
outpt[ID].v.patchCoord = OsdGetPatchCoord(patchParam);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-04-21 16:50:34 +00:00
|
|
|
#if defined OSD_ENABLE_SCREENSPACE_TESSELLATION
|
|
|
|
// Wait for all basis conversion to be finished
|
|
|
|
barrier();
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
if (ID == 0) {
|
2013-06-24 19:43:02 +00:00
|
|
|
OSD_PATCH_CULL(OSD_PATCH_INPUT_SIZE);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-04-21 16:50:34 +00:00
|
|
|
#if defined OSD_ENABLE_SCREENSPACE_TESSELLATION
|
|
|
|
// Gather bezier control points to compute limit surface tess levels
|
|
|
|
for (int i=0; i<16; ++i) {
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
position[i] = outpt[i].v.position.xyz;
|
2015-04-21 16:50:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-04-17 14:42:53 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
vec4 tessLevelOuter = vec4(0);
|
|
|
|
vec2 tessLevelInner = vec2(0);
|
|
|
|
|
|
|
|
OsdGetTessLevels(position, patchParam,
|
|
|
|
tessLevelOuter, tessLevelInner,
|
|
|
|
tessOuterLo, tessOuterHi);
|
2015-04-17 14:42:53 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
gl_TessLevelOuter[0] = tessLevelOuter[0];
|
|
|
|
gl_TessLevelOuter[1] = tessLevelOuter[1];
|
|
|
|
gl_TessLevelOuter[2] = tessLevelOuter[2];
|
|
|
|
gl_TessLevelOuter[3] = tessLevelOuter[3];
|
|
|
|
|
|
|
|
gl_TessLevelInner[0] = tessLevelInner[0];
|
|
|
|
gl_TessLevelInner[1] = tessLevelInner[1];
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
// Patches.TessEvalBSpline
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
#ifdef OSD_PATCH_TESS_EVAL_BSPLINE_SHADER
|
2012-12-11 01:15:13 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
layout(quads) in;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-28 17:10:25 +00:00
|
|
|
#if defined OSD_FRACTIONAL_ODD_SPACING
|
2013-06-27 20:34:25 +00:00
|
|
|
layout(fractional_odd_spacing) in;
|
2013-06-28 17:10:25 +00:00
|
|
|
#elif defined OSD_FRACTIONAL_EVEN_SPACING
|
2013-06-27 20:34:25 +00:00
|
|
|
layout(fractional_even_spacing) in;
|
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
in block {
|
|
|
|
ControlVertex v;
|
2015-04-17 23:26:57 +00:00
|
|
|
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
|
2014-10-13 15:52:09 +00:00
|
|
|
vec4 P1;
|
|
|
|
vec4 P2;
|
|
|
|
float sharpness;
|
2014-10-23 22:59:05 +00:00
|
|
|
#endif
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_DECLARE
|
2013-06-10 19:53:04 +00:00
|
|
|
} inpt[];
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
out block {
|
|
|
|
OutputVertex v;
|
2015-04-17 23:26:57 +00:00
|
|
|
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
|
|
|
|
float sharpness;
|
|
|
|
#endif
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_DECLARE
|
2013-06-10 19:53:04 +00:00
|
|
|
} outpt;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
patch in vec4 tessOuterLo, tessOuterHi;
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void main()
|
|
|
|
{
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
vec2 UV = OsdGetTessParameterization(gl_TessCoord.xy,
|
|
|
|
tessOuterLo,
|
|
|
|
tessOuterHi);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-09-21 01:23:28 +00:00
|
|
|
#ifdef OSD_COMPUTE_NORMAL_DERIVATIVES
|
|
|
|
float B[4], D[4], C[4];
|
2014-10-04 23:22:43 +00:00
|
|
|
vec3 BUCP[4] = vec3[4](vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0)),
|
|
|
|
DUCP[4] = vec3[4](vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0)),
|
|
|
|
CUCP[4] = vec3[4](vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0));
|
2013-09-21 01:23:28 +00:00
|
|
|
Univar4x4(UV.x, B, D, C);
|
|
|
|
#else
|
2013-06-28 00:26:22 +00:00
|
|
|
float B[4], D[4];
|
2014-10-04 23:22:43 +00:00
|
|
|
vec3 BUCP[4] = vec3[4](vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0)),
|
|
|
|
DUCP[4] = vec3[4](vec3(0,0,0), vec3(0,0,0), vec3(0,0,0), vec3(0,0,0));
|
2013-09-21 01:23:28 +00:00
|
|
|
Univar4x4(UV.x, B, D);
|
|
|
|
#endif
|
2013-06-28 00:26:22 +00:00
|
|
|
|
2015-04-17 23:26:57 +00:00
|
|
|
// ----------------------------------------------------------------
|
|
|
|
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
|
|
|
|
// sharpness
|
2014-10-13 15:52:09 +00:00
|
|
|
float sharpness = inpt[0].sharpness;
|
2015-04-17 23:26:57 +00:00
|
|
|
if (sharpness != 0) {
|
|
|
|
float s0 = 1.0 - pow(2.0f, -floor(sharpness));
|
|
|
|
float s1 = 1.0 - pow(2.0f, -ceil(sharpness));
|
|
|
|
|
|
|
|
for (int i=0; i<4; ++i) {
|
|
|
|
for (int j=0; j<4; ++j) {
|
|
|
|
int k = 4*i + j;
|
|
|
|
float s = UV.y;
|
|
|
|
|
|
|
|
vec3 A = (s < s0) ?
|
|
|
|
inpt[k].v.position.xyz :
|
|
|
|
((s < s1) ?
|
|
|
|
inpt[k].P1.xyz :
|
|
|
|
inpt[k].P2.xyz);
|
|
|
|
|
|
|
|
BUCP[i] += A * B[j];
|
|
|
|
DUCP[i] += A * D[j];
|
|
|
|
#ifdef OSD_COMPUTE_NORMAL_DERIVATIVES
|
|
|
|
CUCP[i] += A * C[j];
|
2013-06-28 00:26:22 +00:00
|
|
|
#endif
|
2015-04-17 23:26:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
outpt.sharpness = sharpness;
|
|
|
|
} else {
|
|
|
|
for (int i=0; i<4; ++i) {
|
|
|
|
for (int j=0; j<4; ++j) {
|
|
|
|
vec3 A = inpt[4*i + j].v.position.xyz;
|
|
|
|
BUCP[i] += A * B[j];
|
|
|
|
DUCP[i] += A * D[j];
|
2013-09-21 01:23:28 +00:00
|
|
|
#ifdef OSD_COMPUTE_NORMAL_DERIVATIVES
|
2015-04-17 23:26:57 +00:00
|
|
|
CUCP[i] += A * C[j];
|
2013-09-21 01:23:28 +00:00
|
|
|
#endif
|
2015-04-17 23:26:57 +00:00
|
|
|
}
|
2013-06-28 00:26:22 +00:00
|
|
|
}
|
2015-04-17 23:26:57 +00:00
|
|
|
outpt.sharpness = 0;
|
2013-06-28 00:26:22 +00:00
|
|
|
}
|
2015-04-17 23:26:57 +00:00
|
|
|
#else
|
|
|
|
// ----------------------------------------------------------------
|
|
|
|
for (int i=0; i<4; ++i) {
|
|
|
|
for (int j=0; j<4; ++j) {
|
|
|
|
vec3 A = inpt[4*i + j].v.position.xyz;
|
|
|
|
BUCP[i] += A * B[j];
|
|
|
|
DUCP[i] += A * D[j];
|
|
|
|
#ifdef OSD_COMPUTE_NORMAL_DERIVATIVES
|
|
|
|
CUCP[i] += A * C[j];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// ----------------------------------------------------------------
|
2013-06-28 00:26:22 +00:00
|
|
|
|
|
|
|
vec3 WorldPos = vec3(0);
|
|
|
|
vec3 Tangent = vec3(0);
|
|
|
|
vec3 BiTangent = vec3(0);
|
|
|
|
|
2013-09-21 01:23:28 +00:00
|
|
|
#ifdef OSD_COMPUTE_NORMAL_DERIVATIVES
|
|
|
|
// used for weingarten term
|
|
|
|
Univar4x4(UV.y, B, D, C);
|
|
|
|
|
|
|
|
vec3 dUU = vec3(0);
|
|
|
|
vec3 dVV = vec3(0);
|
|
|
|
vec3 dUV = vec3(0);
|
|
|
|
|
|
|
|
for (int k=0; k<4; ++k) {
|
|
|
|
WorldPos += B[k] * BUCP[k];
|
|
|
|
Tangent += B[k] * DUCP[k];
|
|
|
|
BiTangent += D[k] * BUCP[k];
|
|
|
|
|
|
|
|
dUU += B[k] * CUCP[k];
|
|
|
|
dVV += C[k] * BUCP[k];
|
|
|
|
dUV += D[k] * DUCP[k];
|
|
|
|
}
|
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
int level = inpt[0].v.patchCoord.z;
|
2013-09-21 01:23:28 +00:00
|
|
|
Tangent *= 3 * level;
|
|
|
|
BiTangent *= 3 * level;
|
|
|
|
dUU *= 6 * level;
|
|
|
|
dVV *= 6 * level;
|
|
|
|
dUV *= 9 * level;
|
|
|
|
|
|
|
|
vec3 n = cross(Tangent, BiTangent);
|
|
|
|
vec3 normal = normalize(n);
|
|
|
|
|
|
|
|
float E = dot(Tangent, Tangent);
|
|
|
|
float F = dot(Tangent, BiTangent);
|
|
|
|
float G = dot(BiTangent, BiTangent);
|
|
|
|
float e = dot(normal, dUU);
|
|
|
|
float f = dot(normal, dUV);
|
|
|
|
float g = dot(normal, dVV);
|
|
|
|
|
|
|
|
vec3 Nu = (f*F-e*G)/(E*G-F*F) * Tangent + (e*F-f*E)/(E*G-F*F) * BiTangent;
|
|
|
|
vec3 Nv = (g*F-f*G)/(E*G-F*F) * Tangent + (f*F-g*E)/(E*G-F*F) * BiTangent;
|
|
|
|
|
|
|
|
Nu = Nu/length(n) - n * (dot(Nu,n)/pow(dot(n,n), 1.5));
|
|
|
|
Nv = Nv/length(n) - n * (dot(Nv,n)/pow(dot(n,n), 1.5));
|
|
|
|
|
2015-04-17 14:42:53 +00:00
|
|
|
outpt.v.tangent = Tangent;
|
|
|
|
outpt.v.bitangent = BiTangent;
|
|
|
|
outpt.v.Nu = Nu;
|
|
|
|
outpt.v.Nv = Nv;
|
2013-09-21 01:23:28 +00:00
|
|
|
#else
|
2013-06-28 00:26:22 +00:00
|
|
|
Univar4x4(UV.y, B, D);
|
|
|
|
|
|
|
|
for (int k=0; k<4; ++k) {
|
|
|
|
WorldPos += B[k] * BUCP[k];
|
|
|
|
Tangent += B[k] * DUCP[k];
|
|
|
|
BiTangent += D[k] * BUCP[k];
|
|
|
|
}
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
int level = inpt[0].v.patchCoord.z;
|
2013-09-21 01:23:28 +00:00
|
|
|
Tangent *= 3 * level;
|
|
|
|
BiTangent *= 3 * level;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
vec3 normal = normalize(cross(Tangent, BiTangent));
|
|
|
|
|
2015-04-17 14:42:53 +00:00
|
|
|
outpt.v.tangent = Tangent;
|
|
|
|
outpt.v.bitangent = BiTangent;
|
2013-09-21 01:23:28 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt.v.position = vec4(WorldPos, 1.0f);
|
|
|
|
outpt.v.normal = normal;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_PER_EVAL_POINT(UV, 5, 6, 9, 10);
|
|
|
|
|
Updated handling of patchParam and patchCoord
Each patch has a corresponding patchParam. This is a set of three values
specifying additional information about the patch:
faceId -- topological face identifier (e.g. Ptex FaceId)
bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
sharpness -- crease sharpness for a single-crease patch
These are stored in OsdPatchParamBuffer indexed by the value returned
from OsdGetPatchIndex() which is a function of the current PrimitiveID
along with an optional client provided offset.
Accessors are provided to extract values from a patchParam. These are
all named OsdGetPatch*().
While drawing patches, the patchParam is condensed into a patchCoord which
has four values (u, v, faceLevel, faceId). These patchCoords are treated
as int values during per-prim processing but are converted to float values
during per-vertex processing where the values are interpolated.
Also, cleaned up more of the shader namespace by giving an Osd prefix
to public functions, and consolidated boundary and transition handling
code into the PatchCommon shader files. The functions determining
tessellation levels are now all named OsdGetTessLevel*().
2015-05-02 00:52:37 +00:00
|
|
|
outpt.v.tessCoord = UV;
|
|
|
|
outpt.v.patchCoord = OsdInterpolatePatchCoord(UV, inpt[0].v.patchCoord);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
OSD_DISPLACEMENT_CALLBACK;
|
|
|
|
|
2013-12-03 23:59:38 +00:00
|
|
|
gl_Position = (OsdProjectionMatrix() * vec4(WorldPos, 1.0f));
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|