2012-12-11 01:15:13 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) Pixar. All rights reserved.
|
|
|
|
//
|
|
|
|
// This license governs use of the accompanying software. If you
|
|
|
|
// use the software, you accept this license. If you do not accept
|
|
|
|
// the license, do not use the software.
|
|
|
|
//
|
|
|
|
// 1. Definitions
|
|
|
|
// The terms "reproduce," "reproduction," "derivative works," and
|
|
|
|
// "distribution" have the same meaning here as under U.S.
|
|
|
|
// copyright law. A "contribution" is the original software, or
|
|
|
|
// any additions or changes to the software.
|
|
|
|
// A "contributor" is any person or entity that distributes its
|
|
|
|
// contribution under this license.
|
|
|
|
// "Licensed patents" are a contributor's patent claims that read
|
|
|
|
// directly on its contribution.
|
|
|
|
//
|
|
|
|
// 2. Grant of Rights
|
|
|
|
// (A) Copyright Grant- Subject to the terms of this license,
|
|
|
|
// including the license conditions and limitations in section 3,
|
|
|
|
// each contributor grants you a non-exclusive, worldwide,
|
|
|
|
// royalty-free copyright license to reproduce its contribution,
|
|
|
|
// prepare derivative works of its contribution, and distribute
|
|
|
|
// its contribution or any derivative works that you create.
|
|
|
|
// (B) Patent Grant- Subject to the terms of this license,
|
|
|
|
// including the license conditions and limitations in section 3,
|
|
|
|
// each contributor grants you a non-exclusive, worldwide,
|
|
|
|
// royalty-free license under its licensed patents to make, have
|
|
|
|
// made, use, sell, offer for sale, import, and/or otherwise
|
|
|
|
// dispose of its contribution in the software or derivative works
|
|
|
|
// of the contribution in the software.
|
|
|
|
//
|
|
|
|
// 3. Conditions and Limitations
|
|
|
|
// (A) No Trademark License- This license does not grant you
|
|
|
|
// rights to use any contributor's name, logo, or trademarks.
|
|
|
|
// (B) If you bring a patent claim against any contributor over
|
|
|
|
// patents that you claim are infringed by the software, your
|
|
|
|
// patent license from such contributor to the software ends
|
|
|
|
// automatically.
|
|
|
|
// (C) If you distribute any portion of the software, you must
|
|
|
|
// retain all copyright, patent, trademark, and attribution
|
|
|
|
// notices that are present in the software.
|
|
|
|
// (D) If you distribute any portion of the software in source
|
|
|
|
// code form, you may do so only under this license by including a
|
|
|
|
// complete copy of this license with your distribution. If you
|
|
|
|
// distribute any portion of the software in compiled or object
|
|
|
|
// code form, you may only do so under a license that complies
|
|
|
|
// with this license.
|
|
|
|
// (E) The software is licensed "as-is." You bear the risk of
|
|
|
|
// using it. The contributors give no express warranties,
|
|
|
|
// guarantees or conditions. You may have additional consumer
|
|
|
|
// rights under your local laws which this license cannot change.
|
|
|
|
// To the extent permitted under your local laws, the contributors
|
|
|
|
// exclude the implied warranties of merchantability, fitness for
|
|
|
|
// a particular purpose and non-infringement.
|
|
|
|
//
|
|
|
|
|
2013-07-01 18:58:28 +00:00
|
|
|
//----------------------------------------------------------
|
|
|
|
// Patches.Coefficients
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
|
|
#if OSD_MAX_VALENCE<=10
|
|
|
|
uniform float ef[7] = float[](
|
|
|
|
0.813008, 0.500000, 0.363636, 0.287505,
|
|
|
|
0.238692, 0.204549, 0.179211
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
uniform float ef[27] = float[](
|
|
|
|
0.812816, 0.500000, 0.363644, 0.287514,
|
|
|
|
0.238688, 0.204544, 0.179229, 0.159657,
|
|
|
|
0.144042, 0.131276, 0.120632, 0.111614,
|
|
|
|
0.103872, 0.09715, 0.0912559, 0.0860444,
|
|
|
|
0.0814022, 0.0772401, 0.0734867, 0.0700842,
|
|
|
|
0.0669851, 0.0641504, 0.0615475, 0.0591488,
|
|
|
|
0.0569311, 0.0548745, 0.0529621
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
float csf(uint n, uint j)
|
|
|
|
{
|
|
|
|
if (j%2 == 0) {
|
|
|
|
return cos((2.0f * M_PI * float(float(j-0)/2.0f))/(float(n)+3.0f));
|
|
|
|
} else {
|
|
|
|
return sin((2.0f * M_PI * float(float(j-1)/2.0f))/(float(n)+3.0f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
|
|
|
// Patches.TessVertexGregory
|
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
#ifdef OSD_PATCH_VERTEX_GREGORY_SHADER
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
uniform samplerBuffer g_VertexBuffer;
|
|
|
|
uniform isamplerBuffer g_ValenceBuffer;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
GregControlVertex 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
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2013-07-01 18:47:21 +00:00
|
|
|
int vID = gl_VertexID;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
outpt.v.hullPosition = (ModelViewMatrix * position).xyz;
|
|
|
|
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position);
|
|
|
|
OSD_USER_VARYING_PER_VERTEX();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
int ivalence = texelFetch(g_ValenceBuffer,int(vID * (2 * OSD_MAX_VALENCE + 1))).x;
|
|
|
|
outpt.v.valence = ivalence;
|
|
|
|
uint valence = uint(abs(ivalence));
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
vec3 f[OSD_MAX_VALENCE];
|
|
|
|
vec3 pos = position.xyz;
|
|
|
|
vec3 opos = vec3(0,0,0);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:58:28 +00:00
|
|
|
#ifdef OSD_PATCH_GREGORY_BOUNDARY
|
|
|
|
outpt.v.org = position.xyz;
|
|
|
|
int boundaryEdgeNeighbors[2];
|
|
|
|
uint currNeighbor = 0;
|
|
|
|
uint ibefore = 0;
|
|
|
|
uint zerothNeighbor = 0;
|
|
|
|
#endif
|
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
for (uint i=0; i<valence; ++i) {
|
2012-12-11 01:15:13 +00:00
|
|
|
uint im=(i+valence-1)%valence;
|
|
|
|
uint ip=(i+1)%valence;
|
|
|
|
|
2013-06-10 18:48:38 +00:00
|
|
|
uint idx_neighbor = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 0 + 1)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:58:28 +00:00
|
|
|
#ifdef OSD_PATCH_GREGORY_BOUNDARY
|
|
|
|
bool isBoundaryNeighbor = false;
|
|
|
|
int valenceNeighbor = texelFetch(g_ValenceBuffer,int(idx_neighbor * (2*OSD_MAX_VALENCE+1))).x;
|
|
|
|
|
|
|
|
if (valenceNeighbor < 0) {
|
|
|
|
isBoundaryNeighbor = true;
|
|
|
|
boundaryEdgeNeighbors[currNeighbor++] = int(idx_neighbor);
|
|
|
|
if (currNeighbor == 1) {
|
|
|
|
ibefore = i;
|
|
|
|
zerothNeighbor = i;
|
|
|
|
} else {
|
|
|
|
if (i-ibefore == 1) {
|
|
|
|
int tmp = boundaryEdgeNeighbors[0];
|
|
|
|
boundaryEdgeNeighbors[0] = boundaryEdgeNeighbors[1];
|
|
|
|
boundaryEdgeNeighbors[1] = tmp;
|
|
|
|
zerothNeighbor = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
vec3 neighbor =
|
2013-06-10 18:48:38 +00:00
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+2)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-10 18:48:38 +00:00
|
|
|
uint idx_diagonal = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*i + 1 + 1)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
vec3 diagonal =
|
2013-06-10 18:48:38 +00:00
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-10 18:48:38 +00:00
|
|
|
uint idx_neighbor_p = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*ip + 0 + 1)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
vec3 neighbor_p =
|
2013-06-10 18:48:38 +00:00
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_p+2)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-10 18:48:38 +00:00
|
|
|
uint idx_neighbor_m = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 0 + 1)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
vec3 neighbor_m =
|
2013-06-10 18:48:38 +00:00
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor_m+2)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-10 18:48:38 +00:00
|
|
|
uint idx_diagonal_m = uint(texelFetch(g_ValenceBuffer, int(vID * (2*OSD_MAX_VALENCE+1) + 2*im + 1 + 1)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
vec3 diagonal_m =
|
2013-06-10 18:48:38 +00:00
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal_m+2)).x);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
f[i] = (pos * float(valence) + (neighbor_p + neighbor)*2.0f + diagonal) / (float(valence)+5.0f);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
opos += f[i];
|
2013-07-01 18:47:21 +00:00
|
|
|
outpt.v.r[i] = (neighbor_p-neighbor_m)/3.0f + (diagonal - diagonal_m)/6.0f;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opos /= valence;
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt.v.position = vec4(opos, 1.0f).xyz;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
vec3 e;
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt.v.e0 = vec3(0,0,0);
|
|
|
|
outpt.v.e1 = vec3(0,0,0);
|
2013-07-01 18:47:21 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
for(uint i=0; i<valence; ++i) {
|
|
|
|
uint im = (i + valence -1) % valence;
|
2013-07-01 18:47:21 +00:00
|
|
|
e = 0.5f * (f[i] + f[im]);
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt.v.e0 += csf(valence-3, 2*i) *e;
|
|
|
|
outpt.v.e1 += csf(valence-3, 2*i + 1)*e;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt.v.e0 *= ef[valence - 3];
|
|
|
|
outpt.v.e1 *= ef[valence - 3];
|
2013-07-01 18:58:28 +00:00
|
|
|
|
|
|
|
#ifdef OSD_PATCH_GREGORY_BOUNDARY
|
|
|
|
outpt.v.zerothNeighbor = zerothNeighbor;
|
|
|
|
if (currNeighbor == 1) {
|
|
|
|
boundaryEdgeNeighbors[1] = boundaryEdgeNeighbors[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ivalence < 0) {
|
|
|
|
if (valence > 2) {
|
|
|
|
outpt.v.position = (
|
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) +
|
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) +
|
|
|
|
4.0f * pos)/6.0f;
|
|
|
|
} else {
|
|
|
|
outpt.v.position = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
outpt.v.e0 = (
|
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) -
|
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x)
|
|
|
|
)/6.0;
|
|
|
|
|
|
|
|
float k = float(float(valence) - 1.0f); //k is the number of faces
|
|
|
|
float c = cos(M_PI/k);
|
|
|
|
float s = sin(M_PI/k);
|
|
|
|
float gamma = -(4.0f*s)/(3.0f*k+c);
|
|
|
|
float alpha_0k = -((1.0f+2.0f*c)*sqrt(1.0f+c))/((3.0f*k+c)*sqrt(1.0f-c));
|
|
|
|
float beta_0 = s/(3.0f*k + c);
|
|
|
|
|
|
|
|
|
|
|
|
int idx_diagonal = texelFetch(g_ValenceBuffer,int((vID) * (2*OSD_MAX_VALENCE+1) + 2*zerothNeighbor + 1 + 1)).x;
|
|
|
|
idx_diagonal = abs(idx_diagonal);
|
|
|
|
vec3 diagonal =
|
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x);
|
|
|
|
|
|
|
|
outpt.v.e1 = gamma * pos +
|
|
|
|
alpha_0k * vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0])).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[0]+2)).x) +
|
|
|
|
alpha_0k * vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1])).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*boundaryEdgeNeighbors[1]+2)).x) +
|
|
|
|
beta_0 * diagonal;
|
|
|
|
|
|
|
|
for (uint x=1; x<valence - 1; ++x) {
|
|
|
|
uint curri = ((x + zerothNeighbor)%valence);
|
|
|
|
float alpha = (4.0f*sin((M_PI * float(x))/k))/(3.0f*k+c);
|
|
|
|
float beta = (sin((M_PI * float(x))/k) + sin((M_PI * float(x+1))/k))/(3.0f*k+c);
|
|
|
|
|
|
|
|
int idx_neighbor = texelFetch(g_ValenceBuffer, int((vID) * (2*OSD_MAX_VALENCE+1) + 2*curri + 0 + 1)).x;
|
|
|
|
idx_neighbor = abs(idx_neighbor);
|
|
|
|
|
|
|
|
vec3 neighbor =
|
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_neighbor+2)).x);
|
|
|
|
|
|
|
|
idx_diagonal = texelFetch(g_ValenceBuffer, int((vID) * (2*OSD_MAX_VALENCE+1) + 2*curri + 1 + 1)).x;
|
|
|
|
|
|
|
|
diagonal =
|
|
|
|
vec3(texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+1)).x,
|
|
|
|
texelFetch(g_VertexBuffer, int(OSD_NUM_ELEMENTS*idx_diagonal+2)).x);
|
|
|
|
|
|
|
|
outpt.v.e1 += alpha * neighbor + beta * diagonal;
|
|
|
|
}
|
|
|
|
|
|
|
|
outpt.v.e1 /= 3.0f;
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-07-01 18:47:21 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
// Patches.TessControlGregory
|
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
#ifdef OSD_PATCH_TESS_CONTROL_GREGORY_SHADER
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
layout(vertices = 4) out;
|
|
|
|
|
|
|
|
uniform isamplerBuffer g_QuadOffsetBuffer;
|
|
|
|
|
|
|
|
in block {
|
|
|
|
GregControlVertex 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 {
|
|
|
|
GregEvalVertex 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
|
|
|
|
|
|
|
#define ID gl_InvocationID
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
uint i = gl_InvocationID;
|
|
|
|
uint ip = (i+1)%4;
|
|
|
|
uint im = (i+3)%4;
|
2013-07-01 18:47:21 +00:00
|
|
|
uint valence = abs(inpt[i].v.valence);
|
|
|
|
uint n = valence;
|
2012-12-11 01:15:13 +00:00
|
|
|
int base = GregoryQuadOffsetBase;
|
|
|
|
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt[ID].v.position = inpt[ID].v.position;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-10 19:32:45 +00:00
|
|
|
uint start = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0x00ffu;
|
|
|
|
uint prev = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + i)).x) & 0xff00u;
|
2013-07-01 18:47:21 +00:00
|
|
|
prev = uint(prev/256);
|
|
|
|
|
2013-07-01 18:58:28 +00:00
|
|
|
uint start_m = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + im)).x) & 0x00ffu;
|
|
|
|
uint prev_p = uint(texelFetch(g_QuadOffsetBuffer, int(4*gl_PrimitiveID+base + ip)).x) & 0xff00u;
|
|
|
|
prev_p = uint(prev_p/256);
|
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
uint np = abs(inpt[ip].v.valence);
|
|
|
|
uint nm = abs(inpt[im].v.valence);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2012-12-11 22:26:06 +00:00
|
|
|
// Control Vertices based on :
|
|
|
|
// "Approximating Subdivision Surfaces with Gregory Patches for Hardware Tessellation"
|
|
|
|
// Loop, Schaefer, Ni, Castafio (ACM ToG Siggraph Asia 2009)
|
|
|
|
//
|
|
|
|
// P3 e3- e2+ E2
|
|
|
|
// O--------O--------O--------O
|
|
|
|
// | | | |
|
|
|
|
// | | | |
|
|
|
|
// | | f3- | f2+ |
|
|
|
|
// | O O |
|
|
|
|
// e3+ O------O O------O e2-
|
|
|
|
// | f3+ f2- |
|
|
|
|
// | |
|
|
|
|
// | |
|
|
|
|
// | f0- f1+ |
|
|
|
|
// e0- O------O O------O e1+
|
|
|
|
// | O O |
|
|
|
|
// | | f0+ | f1- |
|
|
|
|
// | | | |
|
|
|
|
// | | | |
|
|
|
|
// O--------O--------O--------O
|
|
|
|
// P0 e0+ e1- E1
|
|
|
|
//
|
|
|
|
|
2013-07-01 18:58:28 +00:00
|
|
|
#ifdef OSD_PATCH_GREGORY_BOUNDARY
|
|
|
|
vec3 Ep = vec3(0.0f,0.0f,0.0f);
|
|
|
|
vec3 Em = vec3(0.0f,0.0f,0.0f);
|
|
|
|
vec3 Fp = vec3(0.0f,0.0f,0.0f);
|
|
|
|
vec3 Fm = vec3(0.0f,0.0f,0.0f);
|
|
|
|
|
|
|
|
vec3 Em_ip;
|
|
|
|
if (inpt[ip].v.valence < -2) {
|
|
|
|
uint j = (np + prev_p - inpt[ip].v.zerothNeighbor) % np;
|
|
|
|
Em_ip = inpt[ip].v.position + cos((M_PI*j)/float(np-1))*inpt[ip].v.e0 + sin((M_PI*j)/float(np-1))*inpt[ip].v.e1;
|
|
|
|
} else {
|
2013-07-02 17:06:24 +00:00
|
|
|
Em_ip = inpt[ip].v.position + inpt[ip].v.e0*csf(np-3, 2*prev_p ) + inpt[ip].v.e1*csf(np-3, 2*prev_p + 1);
|
2013-07-01 18:58:28 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:58:28 +00:00
|
|
|
vec3 Ep_im;
|
|
|
|
if (inpt[im].v.valence < -2) {
|
|
|
|
uint j = (nm + start_m - inpt[im].v.zerothNeighbor) % nm;
|
|
|
|
Ep_im = inpt[im].v.position + cos((M_PI*j)/float(nm-1))*inpt[im].v.e0 + sin((M_PI*j)/float(nm-1))*inpt[im].v.e1;
|
|
|
|
} else {
|
2013-07-02 17:06:24 +00:00
|
|
|
Ep_im = inpt[im].v.position + inpt[im].v.e0*csf(nm-3, 2*start_m) + inpt[im].v.e1*csf(nm-3, 2*start_m + 1);
|
2013-07-01 18:58:28 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:58:28 +00:00
|
|
|
if (inpt[i].v.valence < 0) {
|
|
|
|
n = (n-1)*2;
|
|
|
|
}
|
|
|
|
if (inpt[im].v.valence < 0) {
|
|
|
|
nm = (nm-1)*2;
|
|
|
|
}
|
|
|
|
if (inpt[ip].v.valence < 0) {
|
|
|
|
np = (np-1)*2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inpt[i].v.valence > 2) {
|
2013-07-02 17:06:24 +00:00
|
|
|
Ep = inpt[i].v.position + inpt[i].v.e0*csf(n-3, 2*start) + inpt[i].v.e1*csf(n-3, 2*start + 1);
|
|
|
|
Em = inpt[i].v.position + inpt[i].v.e0*csf(n-3, 2*prev ) + inpt[i].v.e1*csf(n-3, 2*prev + 1);
|
2013-07-01 18:58:28 +00:00
|
|
|
|
|
|
|
float s1=3-2*csf(n-3,2)-csf(np-3,2);
|
|
|
|
float s2=2*csf(n-3,2);
|
|
|
|
|
|
|
|
Fp = (csf(np-3,2)*inpt[i].v.position + s1*Ep + s2*Em_ip + inpt[i].v.r[start])/3.0f;
|
|
|
|
s1 = 3.0f-2.0f*cos(2.0f*M_PI/float(n))-cos(2.0f*M_PI/float(nm));
|
|
|
|
Fm = (csf(nm-3,2)*inpt[i].v.position + s1*Em + s2*Ep_im - inpt[i].v.r[prev])/3.0f;
|
|
|
|
|
|
|
|
} else if (inpt[i].v.valence < -2) {
|
|
|
|
uint j = (valence + start - inpt[i].v.zerothNeighbor) % valence;
|
|
|
|
|
|
|
|
Ep = inpt[i].v.position + cos((M_PI*j)/float(valence-1))*inpt[i].v.e0 + sin((M_PI*j)/float(valence-1))*inpt[i].v.e1;
|
|
|
|
j = (valence + prev - inpt[i].v.zerothNeighbor) % valence;
|
|
|
|
Em = inpt[i].v.position + cos((M_PI*j)/float(valence-1))*inpt[i].v.e0 + sin((M_PI*j)/float(valence-1))*inpt[i].v.e1;
|
|
|
|
|
|
|
|
vec3 Rp = ((-2.0f * inpt[i].v.org - 1.0f * inpt[im].v.org) + (2.0f * inpt[ip].v.org + 1.0f * inpt[(i+2)%4].v.org))/3.0f;
|
|
|
|
vec3 Rm = ((-2.0f * inpt[i].v.org - 1.0f * inpt[ip].v.org) + (2.0f * inpt[im].v.org + 1.0f * inpt[(i+2)%4].v.org))/3.0f;
|
|
|
|
|
|
|
|
float s1 = 3-2*csf(n-3,2)-csf(np-3,2);
|
|
|
|
float s2 = 2*csf(n-3,2);
|
|
|
|
|
|
|
|
Fp = (csf(np-3,2)*inpt[i].v.position + s1*Ep + s2*Em_ip + inpt[i].v.r[start])/3.0f;
|
|
|
|
s1 = 3.0f-2.0f*cos(2.0f*M_PI/float(n))-cos(2.0f*M_PI/float(nm));
|
|
|
|
Fm = (csf(nm-3,2)*inpt[i].v.position + s1*Em + s2*Ep_im - inpt[i].v.r[prev])/3.0f;
|
|
|
|
|
|
|
|
if (inpt[im].v.valence < 0) {
|
|
|
|
s1 = 3-2*csf(n-3,2)-csf(np-3,2);
|
|
|
|
Fp = Fm = (csf(np-3,2)*inpt[i].v.position + s1*Ep + s2*Em_ip + inpt[i].v.r[start])/3.0f;
|
|
|
|
} else if (inpt[ip].v.valence < 0) {
|
|
|
|
s1 = 3.0f-2.0f*cos(2.0f*M_PI/n)-cos(2.0f*M_PI/nm);
|
|
|
|
Fm = Fp = (csf(nm-3,2)*inpt[i].v.position + s1*Em + s2*Ep_im - inpt[i].v.r[prev])/3.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (inpt[i].v.valence == -2) {
|
|
|
|
Ep = (2.0f * inpt[i].v.org + inpt[ip].v.org)/3.0f;
|
|
|
|
Em = (2.0f * inpt[i].v.org + inpt[im].v.org)/3.0f;
|
|
|
|
Fp = Fm = (4.0f * inpt[i].v.org + inpt[(i+2)%n].v.org + 2.0f * inpt[ip].v.org + 2.0f * inpt[im].v.org)/9.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // not OSD_PATCH_GREGORY_BOUNDARY
|
|
|
|
|
|
|
|
vec3 Ep = inpt[i].v.position + inpt[i].v.e0 * csf(n-3, 2*start) + inpt[i].v.e1*csf(n-3, 2*start + 1);
|
|
|
|
vec3 Em = inpt[i].v.position + inpt[i].v.e0 * csf(n-3, 2*prev ) + inpt[i].v.e1*csf(n-3, 2*prev + 1);
|
|
|
|
|
|
|
|
vec3 Em_ip = inpt[ip].v.position + inpt[ip].v.e0 * csf(np-3, 2*prev_p ) + inpt[ip].v.e1*csf(np-3, 2*prev_p + 1);
|
|
|
|
vec3 Ep_im = inpt[im].v.position + inpt[im].v.e0 * csf(nm-3, 2*start_m) + inpt[im].v.e1*csf(nm-3, 2*start_m + 1);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
float s1 = 3-2*csf(n-3,2)-csf(np-3,2);
|
2012-12-11 01:15:13 +00:00
|
|
|
float s2 = 2*csf(n-3,2);
|
|
|
|
|
2013-07-01 18:47:21 +00:00
|
|
|
vec3 Fp = (csf(np-3,2)*inpt[i].v.position + s1*Ep + s2*Em_ip + inpt[i].v.r[start])/3.0f;
|
2013-07-01 18:58:28 +00:00
|
|
|
s1 = 3.0f-2.0f*cos(2.0f*M_PI/float(n))-cos(2.0f*M_PI/float(nm));
|
|
|
|
vec3 Fm = (csf(nm-3,2)*inpt[i].v.position + s1*Em + s2*Ep_im - inpt[i].v.r[prev])/3.0f;
|
|
|
|
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt[ID].v.Ep = Ep;
|
|
|
|
outpt[ID].v.Em = Em;
|
|
|
|
outpt[ID].v.Fp = Fp;
|
|
|
|
outpt[ID].v.Fm = Fm;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_PER_CONTROL_POINT(ID, ID);
|
|
|
|
|
2013-05-09 16:23:01 +00:00
|
|
|
int patchLevel = GetPatchLevel();
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt[ID].v.patchCoord = vec4(0, 0,
|
2013-06-24 19:03:57 +00:00
|
|
|
patchLevel+0.5f,
|
|
|
|
gl_PrimitiveID+LevelBase+0.5f);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER;
|
|
|
|
|
|
|
|
if (ID == 0) {
|
|
|
|
OSD_PATCH_CULL(4);
|
|
|
|
|
2013-06-10 19:01:43 +00:00
|
|
|
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
2012-12-11 01:15:13 +00:00
|
|
|
gl_TessLevelOuter[0] =
|
2013-06-24 19:03:57 +00:00
|
|
|
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[1].v.hullPosition.xyz);
|
2012-12-11 01:15:13 +00:00
|
|
|
gl_TessLevelOuter[1] =
|
2013-06-24 19:03:57 +00:00
|
|
|
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz);
|
2012-12-11 01:15:13 +00:00
|
|
|
gl_TessLevelOuter[2] =
|
2013-06-24 19:03:57 +00:00
|
|
|
TessAdaptive(inpt[2].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz);
|
2012-12-11 01:15:13 +00:00
|
|
|
gl_TessLevelOuter[3] =
|
2013-06-24 19:03:57 +00:00
|
|
|
TessAdaptive(inpt[1].v.hullPosition.xyz, inpt[2].v.hullPosition.xyz);
|
2012-12-11 01:15:13 +00:00
|
|
|
gl_TessLevelInner[0] =
|
|
|
|
max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]);
|
|
|
|
gl_TessLevelInner[1] =
|
|
|
|
max(gl_TessLevelOuter[0], gl_TessLevelOuter[2]);
|
|
|
|
#else
|
|
|
|
gl_TessLevelInner[0] = GetTessLevel(patchLevel);
|
|
|
|
gl_TessLevelInner[1] = GetTessLevel(patchLevel);
|
|
|
|
gl_TessLevelOuter[0] = GetTessLevel(patchLevel);
|
|
|
|
gl_TessLevelOuter[1] = GetTessLevel(patchLevel);
|
|
|
|
gl_TessLevelOuter[2] = GetTessLevel(patchLevel);
|
|
|
|
gl_TessLevelOuter[3] = GetTessLevel(patchLevel);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2013-07-01 18:47:21 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
// Patches.TessEvalGregory
|
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
#ifdef OSD_PATCH_TESS_EVAL_GREGORY_SHADER
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
layout(quads) in;
|
|
|
|
layout(cw) in;
|
|
|
|
|
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 {
|
|
|
|
GregEvalVertex 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 {
|
|
|
|
OutputVertex 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
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
float u = gl_TessCoord.x,
|
|
|
|
v = gl_TessCoord.y;
|
|
|
|
|
|
|
|
vec3 p[20];
|
|
|
|
|
2013-06-10 19:53:04 +00:00
|
|
|
p[0] = inpt[0].v.position;
|
|
|
|
p[1] = inpt[0].v.Ep;
|
|
|
|
p[2] = inpt[0].v.Em;
|
|
|
|
p[3] = inpt[0].v.Fp;
|
|
|
|
p[4] = inpt[0].v.Fm;
|
|
|
|
|
|
|
|
p[5] = inpt[1].v.position;
|
|
|
|
p[6] = inpt[1].v.Ep;
|
|
|
|
p[7] = inpt[1].v.Em;
|
|
|
|
p[8] = inpt[1].v.Fp;
|
|
|
|
p[9] = inpt[1].v.Fm;
|
|
|
|
|
|
|
|
p[10] = inpt[2].v.position;
|
|
|
|
p[11] = inpt[2].v.Ep;
|
|
|
|
p[12] = inpt[2].v.Em;
|
|
|
|
p[13] = inpt[2].v.Fp;
|
|
|
|
p[14] = inpt[2].v.Fm;
|
|
|
|
|
|
|
|
p[15] = inpt[3].v.position;
|
|
|
|
p[16] = inpt[3].v.Ep;
|
|
|
|
p[17] = inpt[3].v.Em;
|
|
|
|
p[18] = inpt[3].v.Fp;
|
|
|
|
p[19] = inpt[3].v.Fm;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
vec3 q[16];
|
|
|
|
|
|
|
|
float U = 1-u, V=1-v;
|
|
|
|
|
|
|
|
float d11 = u+v; if(u+v==0.0f) d11 = 1.0f;
|
|
|
|
float d12 = U+v; if(U+v==0.0f) d12 = 1.0f;
|
|
|
|
float d21 = u+V; if(u+V==0.0f) d21 = 1.0f;
|
|
|
|
float d22 = U+V; if(U+V==0.0f) d22 = 1.0f;
|
|
|
|
|
|
|
|
q[ 5] = (u*p[3] + v*p[4])/d11;
|
|
|
|
q[ 6] = (U*p[9] + v*p[8])/d12;
|
|
|
|
q[ 9] = (u*p[19] + V*p[18])/d21;
|
|
|
|
q[10] = (U*p[13] + V*p[14])/d22;
|
|
|
|
|
|
|
|
q[ 0] = p[0];
|
|
|
|
q[ 1] = p[1];
|
|
|
|
q[ 2] = p[7];
|
|
|
|
q[ 3] = p[5];
|
|
|
|
q[ 4] = p[2];
|
|
|
|
q[ 7] = p[6];
|
|
|
|
q[ 8] = p[16];
|
|
|
|
q[11] = p[12];
|
|
|
|
q[12] = p[15];
|
|
|
|
q[13] = p[17];
|
|
|
|
q[14] = p[11];
|
|
|
|
q[15] = p[10];
|
|
|
|
|
|
|
|
float B[4], D[4];
|
|
|
|
|
|
|
|
Univar4x4(u, B, D);
|
|
|
|
vec3 BUCP[4], DUCP[4];
|
|
|
|
|
|
|
|
for (int i=0; i<4; ++i) {
|
|
|
|
BUCP[i] = vec3(0, 0, 0);
|
|
|
|
DUCP[i] = vec3(0, 0, 0);
|
|
|
|
|
|
|
|
for (uint j=0; j<4; ++j) {
|
|
|
|
// reverse face front
|
|
|
|
vec3 A = q[i + 4*j];
|
|
|
|
|
|
|
|
BUCP[i] += A * B[j];
|
|
|
|
DUCP[i] += A * D[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 WorldPos = vec3(0, 0, 0);
|
|
|
|
vec3 Tangent = vec3(0, 0, 0);
|
|
|
|
vec3 BiTangent = vec3(0, 0, 0);
|
|
|
|
|
|
|
|
Univar4x4(v, B, D);
|
|
|
|
|
|
|
|
for (uint i=0; i<4; ++i) {
|
|
|
|
WorldPos += B[i] * BUCP[i];
|
|
|
|
Tangent += B[i] * DUCP[i];
|
|
|
|
BiTangent += D[i] * BUCP[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
BiTangent = (ModelViewMatrix * vec4(BiTangent, 0)).xyz;
|
|
|
|
Tangent = (ModelViewMatrix * vec4(Tangent, 0)).xyz;
|
|
|
|
|
|
|
|
vec3 normal = normalize(cross(BiTangent, Tangent));
|
|
|
|
|
2013-06-24 19:03:57 +00:00
|
|
|
outpt.v.position = ModelViewMatrix * vec4(WorldPos, 1.0f);
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt.v.normal = normal;
|
2013-06-24 19:03:57 +00:00
|
|
|
outpt.v.tangent = normalize(BiTangent);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-06-28 21:05:47 +00:00
|
|
|
OSD_USER_VARYING_PER_EVAL_POINT(vec2(u,v), 0, 3, 1, 2);
|
|
|
|
|
2013-06-10 19:53:04 +00:00
|
|
|
outpt.v.patchCoord = inpt[0].v.patchCoord;
|
|
|
|
outpt.v.patchCoord.xy = vec2(v, u);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER;
|
|
|
|
|
|
|
|
OSD_DISPLACEMENT_CALLBACK;
|
|
|
|
|
2013-07-02 17:06:24 +00:00
|
|
|
gl_Position = ModelViewProjectionMatrix * vec4(WorldPos, 1.0f);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|