// // Copyright 2013 Pixar // // Licensed under the terms set forth in the LICENSE.txt file available at // https://opensubdiv.org/license. // #undef OSD_USER_VARYING_DECLARE #define OSD_USER_VARYING_DECLARE \ vec3 color; #undef OSD_USER_VARYING_ATTRIBUTE_DECLARE #define OSD_USER_VARYING_ATTRIBUTE_DECLARE \ layout(location = 1) in vec3 color; #undef OSD_USER_VARYING_PER_VERTEX #define OSD_USER_VARYING_PER_VERTEX() \ outpt.color = color #undef OSD_USER_VARYING_PER_CONTROL_POINT #define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN) \ outpt[ID_OUT].color = inpt[ID_IN].color #undef OSD_USER_VARYING_PER_EVAL_POINT #define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d) \ outpt.color = \ mix(mix(inpt[a].color, inpt[b].color, UV.x), \ mix(inpt[c].color, inpt[d].color, UV.x), UV.y) //-------------------------------------------------------------- // Uniform Blocks //-------------------------------------------------------------- layout(std140) uniform Transform { mat4 ModelViewMatrix; mat4 ProjectionMatrix; mat4 ModelViewProjectionMatrix; mat4 ModelViewInverseMatrix; mat4 UvViewMatrix; }; layout(std140) uniform Tessellation { float TessLevel; }; uniform int GregoryQuadOffsetBase; uniform int PrimitiveIdBase; //-------------------------------------------------------------- // Osd external functions //-------------------------------------------------------------- mat4 OsdModelViewMatrix() { return ModelViewMatrix; } mat4 OsdProjectionMatrix() { return ProjectionMatrix; } mat4 OsdModelViewProjectionMatrix() { return ModelViewProjectionMatrix; } float OsdTessLevel() { return TessLevel; } int OsdGregoryQuadOffsetBase() { return GregoryQuadOffsetBase; } int OsdPrimitiveIdBase() { return PrimitiveIdBase; } int OsdBaseVertex() { return 0; } //-------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------- #ifdef VERTEX_SHADER layout (location=0) in vec4 position; OSD_USER_VARYING_ATTRIBUTE_DECLARE out block { OutputVertex v; OSD_USER_VARYING_DECLARE } outpt; void main() { outpt.v.position = ModelViewMatrix * position; // We don't actually want to write all these, but some // compilers complain during about failing to fully write // outpt.v if they are excluded. outpt.v.normal = vec3(0); outpt.v.tangent = vec3(0); outpt.v.bitangent = vec3(0); outpt.v.patchCoord = vec4(0); outpt.v.tessCoord = vec2(0); #if defined OSD_COMPUTE_NORMAL_DERIVATIVES outpt.v.Nu = vec3(0); outpt.v.Nv = vec3(0); #endif // -- OSD_USER_VARYING_PER_VERTEX(); } #endif //-------------------------------------------------------------- // Geometry Shader //-------------------------------------------------------------- #ifdef GEOMETRY_SHADER #ifdef PRIM_QUAD layout(lines_adjacency) in; #define EDGE_VERTS 4 #endif // PRIM_QUAD #ifdef PRIM_TRI layout(triangles) in; #define EDGE_VERTS 3 #endif // PRIM_TRI layout(triangle_strip, max_vertices = EDGE_VERTS) out; in block { OutputVertex v; OSD_USER_VARYING_DECLARE } inpt[EDGE_VERTS]; out block { OutputVertex v; noperspective out vec4 edgeDistance; OSD_USER_VARYING_DECLARE } outpt; uniform isamplerBuffer OsdFVarParamBuffer; layout(std140) uniform OsdFVarArrayData { OsdPatchArray fvarPatchArray[2]; }; vec2 interpolateFaceVarying(vec2 uv, int fvarOffset) { int patchIndex = OsdGetPatchIndex(gl_PrimitiveID); OsdPatchArray array = fvarPatchArray[0]; ivec3 fvarPatchParam = texelFetch(OsdFVarParamBuffer, patchIndex).xyz; OsdPatchParam param = OsdPatchParamInit(fvarPatchParam.x, fvarPatchParam.y, fvarPatchParam.z); int patchType = OsdPatchParamIsRegular(param) ? array.regDesc : array.desc; float wP[20], wDu[20], wDv[20], wDuu[20], wDuv[20], wDvv[20]; int numPoints = OsdEvaluatePatchBasisNormalized(patchType, param, uv.s, uv.t, wP, wDu, wDv, wDuu, wDuv, wDvv); int primOffset = patchIndex * array.stride; vec2 result = vec2(0); for (int i=0; i