2222// language governing permissions and limitations under the Apache License.
2323//
2424
25- //
26- // typical shader composition ordering (see glDrawRegistry:_CompileShader)
27- //
28- //
29- // - glsl version string (#version 430)
30- //
31- // - common defines (#define OSD_ENABLE_PATCH_CULL, ...)
32- // - source defines (#define VERTEX_SHADER, ...)
33- //
34- // - osd headers (glslPatchCommon: varying structs,
35- // glslPtexCommon: ptex functions)
36- // - client header (Osd*Matrix(), displacement callback, ...)
37- //
38- // - osd shader source (glslPatchBSpline, glslPatchGregory, ...)
39- // or
40- // client shader source (vertex/geometry/fragment shader)
41- //
42-
43- // ----------------------------------------------------------
44- // Patches.Common
45- // ----------------------------------------------------------
46-
47- // XXXdyu all handling of varying data can be managed by client code
48- #ifndef OSD_USER_VARYING_DECLARE
49- #define OSD_USER_VARYING_DECLARE
50- // type var;
51- #endif
52-
53- #ifndef OSD_USER_VARYING_ATTRIBUTE_DECLARE
54- #define OSD_USER_VARYING_ATTRIBUTE_DECLARE
55- // layout(location = loc) in type var;
56- #endif
57-
58- #ifndef OSD_USER_VARYING_PER_VERTEX
59- #define OSD_USER_VARYING_PER_VERTEX()
60- // output.var = var;
61- #endif
62-
63- #ifndef OSD_USER_VARYING_PER_CONTROL_POINT
64- #define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN)
65- // output[ID_OUT].var = input[ID_IN].var
66- #endif
67-
68- #ifndef OSD_USER_VARYING_PER_EVAL_POINT
69- #define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d)
70- // output.var =
71- // mix(mix(input[a].var, input[b].var, UV.x),
72- // mix(input[c].var, input[d].var, UV.x), UV.y)
73- #endif
74-
75- #ifndef OSD_USER_VARYING_PER_EVAL_POINT_TRIANGLE
76- #define OSD_USER_VARYING_PER_EVAL_POINT_TRIANGLE(UV, a, b, c)
77- // output.var =
78- // input[a].var * (1.0f-UV.x-UV.y) +
79- // input[b].var * UV.x +
80- // input[c].var * UV.y;
81- #endif
82-
83- #if __VERSION__ < 420
84- #define centroid
85- #endif
86-
87- struct ControlVertex {
88- vec4 position;
89- #ifdef OSD_ENABLE_PATCH_CULL
90- ivec3 clipFlag;
91- #endif
92- };
93-
94- // XXXdyu all downstream data can be handled by client code
95- struct OutputVertex {
96- vec4 position;
97- vec3 normal;
98- vec3 tangent;
99- vec3 bitangent;
100- vec4 patchCoord; // u, v, faceLevel, faceId
101- vec2 tessCoord; // tesscoord.st
102- #if defined OSD_COMPUTE_NORMAL_DERIVATIVES
103- vec3 Nu;
104- vec3 Nv;
105- #endif
106- };
107-
108- // osd shaders need following functions defined
25+ // The following callback functions are used when evaluating tessellation
26+ // rates and when using legacy patch drawing.
10927mat4 OsdModelViewMatrix();
11028mat4 OsdProjectionMatrix();
111- mat4 OsdModelViewProjectionMatrix();
11229float OsdTessLevel();
113- int OsdGregoryQuadOffsetBase();
114- int OsdPrimitiveIdBase();
115- int OsdBaseVertex();
116-
117- #ifndef OSD_DISPLACEMENT_CALLBACK
118- #define OSD_DISPLACEMENT_CALLBACK
119- #endif
12030
12131// ----------------------------------------------------------------------------
12232// Patch Parameters
@@ -130,22 +40,6 @@ int OsdBaseVertex();
13040// bitfield -- refinement-level, non-quad, boundary, transition, uv-offset
13141// sharpness -- crease sharpness for single-crease patches
13242//
133- // These are stored in OsdPatchParamBuffer indexed by the value returned
134- // from OsdGetPatchIndex() which is a function of the current PrimitiveID
135- // along with an optional client provided offset.
136- //
137-
138- uniform isamplerBuffer OsdPatchParamBuffer;
139-
140- int OsdGetPatchIndex(int primitiveId)
141- {
142- return (primitiveId + OsdPrimitiveIdBase());
143- }
144-
145- ivec3 OsdGetPatchParam(int patchIndex)
146- {
147- return texelFetch(OsdPatchParamBuffer, patchIndex).xyz;
148- }
14943
15044int OsdGetPatchFaceId(ivec3 patchParam)
15145{
@@ -239,38 +133,6 @@ vec4 OsdInterpolatePatchCoordTriangle(vec2 localUV, ivec3 patchParam)
239133 return result;
240134}
241135
242- // ----------------------------------------------------------------------------
243- // patch culling
244- // ----------------------------------------------------------------------------
245-
246- #ifdef OSD_ENABLE_PATCH_CULL
247-
248- #define OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(P) \
249- vec4 clipPos = OsdModelViewProjectionMatrix() * P; \
250- bvec3 clip0 = lessThan (clipPos.xyz, vec3 (clipPos.w)); \
251- bvec3 clip1 = greaterThan (clipPos.xyz, - vec3 (clipPos.w)); \
252- outpt.v.clipFlag = ivec3 (clip0) + 2 * ivec3 (clip1); \
253-
254- #define OSD_PATCH_CULL(N) \
255- ivec3 clipFlag = ivec3 (0 ); \
256- for (int i = 0 ; i < N; ++ i) { \
257- clipFlag |= inpt[i].v.clipFlag; \
258- } \
259- if (clipFlag != ivec3 (3 ) ) { \
260- gl_TessLevelInner[0 ] = 0 ; \
261- gl_TessLevelInner[1 ] = 0 ; \
262- gl_TessLevelOuter[0 ] = 0 ; \
263- gl_TessLevelOuter[1 ] = 0 ; \
264- gl_TessLevelOuter[2 ] = 0 ; \
265- gl_TessLevelOuter[3 ] = 0 ; \
266- return ; \
267- }
268-
269- #else
270- #define OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(P)
271- #define OSD_PATCH_CULL(N)
272- #endif
273-
274136// ----------------------------------------------------------------------------
275137
276138void
@@ -582,15 +444,15 @@ OsdFlipMatrix(mat4 m)
582444}
583445
584446// Regular BSpline to Bezier
585- uniform mat4 Q = mat4 (
447+ const mat4 Q = mat4 (
586448 1 .f/ 6 .f, 4 .f/ 6 .f, 1 .f/ 6 .f, 0 .f,
587449 0 .f, 4 .f/ 6 .f, 2 .f/ 6 .f, 0 .f,
588450 0 .f, 2 .f/ 6 .f, 4 .f/ 6 .f, 0 .f,
589451 0 .f, 1 .f/ 6 .f, 4 .f/ 6 .f, 1 .f/ 6 .f
590452);
591453
592454// Infinitely Sharp (boundary)
593- uniform mat4 Mi = mat4 (
455+ const mat4 Mi = mat4 (
594456 1 .f/ 6 .f, 4 .f/ 6 .f, 1 .f/ 6 .f, 0 .f,
595457 0 .f, 4 .f/ 6 .f, 2 .f/ 6 .f, 0 .f,
596458 0 .f, 2 .f/ 6 .f, 4 .f/ 6 .f, 0 .f,
0 commit comments