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
|
|
|
//
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
2015-05-26 23:35:06 +00:00
|
|
|
// Patches.VertexBSpline
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
|
|
void vs_main_patches( in InputVertex input,
|
|
|
|
out HullVertex output )
|
|
|
|
{
|
2015-05-21 14:25:04 +00:00
|
|
|
output.position = input.position;
|
2012-12-11 01:15:13 +00:00
|
|
|
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(input.position);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
// Patches.HullBSpline
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
|
|
|
|
2015-04-18 21:00:23 +00:00
|
|
|
[domain("quad")]
|
2015-05-26 23:35:06 +00:00
|
|
|
[partitioning(OSD_PARTITIONING)]
|
2012-12-11 01:15:13 +00:00
|
|
|
[outputtopology("triangle_cw")]
|
|
|
|
[outputcontrolpoints(16)]
|
|
|
|
[patchconstantfunc("HSConstFunc")]
|
2015-05-26 23:35:06 +00:00
|
|
|
OsdPerPatchVertexBSpline hs_main_patches(
|
2015-05-20 17:49:45 +00:00
|
|
|
in InputPatch<HullVertex, 16> patch,
|
2012-12-11 01:15:13 +00:00
|
|
|
uint primitiveID : SV_PrimitiveID,
|
|
|
|
in uint ID : SV_OutputControlPointID )
|
|
|
|
{
|
2015-05-26 23:35:06 +00:00
|
|
|
OsdPerPatchVertexBSpline output;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-26 23:35:06 +00:00
|
|
|
float3 cv[16];
|
|
|
|
for (int i=0; i<16; ++i) {
|
|
|
|
cv[i] = patch[i].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
|
|
|
int3 patchParam = OsdGetPatchParam(OsdGetPatchIndex(primitiveID));
|
2015-05-26 23:35:06 +00:00
|
|
|
OsdComputePerPatchVertexBSpline(patchParam, ID, cv, output);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:25:04 +00:00
|
|
|
HS_CONSTANT_FUNC_OUT
|
|
|
|
HSConstFunc(
|
|
|
|
InputPatch<HullVertex, 16> patch,
|
2015-05-26 23:35:06 +00:00
|
|
|
OutputPatch<OsdPerPatchVertexBSpline, 16> bezierPatch,
|
2015-05-21 14:25:04 +00:00
|
|
|
uint primitiveID : SV_PrimitiveID)
|
|
|
|
{
|
|
|
|
HS_CONSTANT_FUNC_OUT output;
|
|
|
|
|
2015-05-26 23:35:06 +00:00
|
|
|
float3 cv[16];
|
|
|
|
for (int i=0; i<16; ++i) {
|
|
|
|
cv[i] = bezierPatch[i].P;
|
2015-05-21 14:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int3 patchParam = OsdGetPatchParam(OsdGetPatchIndex(primitiveID));
|
|
|
|
|
2015-05-26 23:35:06 +00:00
|
|
|
OsdComputeBSplineBoundaryPoints(cv, patchParam);
|
2015-05-21 14:25:04 +00:00
|
|
|
|
|
|
|
float4 tessLevelOuter = float4(0,0,0,0);
|
2015-05-26 23:35:06 +00:00
|
|
|
float2 tessLevelInner = float2(0,0);
|
2015-05-21 14:25:04 +00:00
|
|
|
float4 tessOuterLo = float4(0,0,0,0);
|
|
|
|
float4 tessOuterHi = float4(0,0,0,0);
|
|
|
|
|
2015-05-26 23:35:06 +00:00
|
|
|
OSD_PATCH_CULL(16);
|
|
|
|
|
|
|
|
OsdGetTessLevels(cv, patchParam,
|
2015-05-21 14:25:04 +00:00
|
|
|
tessLevelOuter, tessLevelInner,
|
|
|
|
tessOuterLo, tessOuterHi);
|
|
|
|
|
|
|
|
output.tessLevelOuter[0] = tessLevelOuter[0];
|
|
|
|
output.tessLevelOuter[1] = tessLevelOuter[1];
|
|
|
|
output.tessLevelOuter[2] = tessLevelOuter[2];
|
|
|
|
output.tessLevelOuter[3] = tessLevelOuter[3];
|
|
|
|
|
|
|
|
output.tessLevelInner[0] = tessLevelInner[0];
|
|
|
|
output.tessLevelInner[1] = tessLevelInner[1];
|
|
|
|
|
|
|
|
output.tessOuterLo = tessOuterLo;
|
|
|
|
output.tessOuterHi = tessOuterHi;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
2013-06-24 19:03:57 +00:00
|
|
|
// Patches.DomainBSpline
|
2012-12-11 01:15:13 +00:00
|
|
|
//----------------------------------------------------------
|
|
|
|
|
2015-04-18 21:00:23 +00:00
|
|
|
[domain("quad")]
|
2012-12-11 01:15:13 +00:00
|
|
|
void ds_main_patches(
|
|
|
|
in HS_CONSTANT_FUNC_OUT input,
|
2015-05-26 23:35:06 +00:00
|
|
|
in OutputPatch<OsdPerPatchVertexBSpline, 16> patch,
|
2013-06-24 19:03:57 +00:00
|
|
|
in float2 domainCoord : SV_DomainLocation,
|
2012-12-11 01:15:13 +00:00
|
|
|
out OutputVertex output )
|
|
|
|
{
|
2015-05-26 23:35:06 +00:00
|
|
|
float3 P = float3(0,0,0), dPu = float3(0,0,0), dPv = float3(0,0,0);
|
|
|
|
float3 N = float3(0,0,0), dNu = float3(0,0,0), dNv = float3(0,0,0);
|
|
|
|
|
|
|
|
OsdPerPatchVertexBSpline cv[16];
|
|
|
|
for (int i=0; i<16; ++i) {
|
|
|
|
cv[i] = patch[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
|
|
|
float2 UV = OsdGetTessParameterization(domainCoord,
|
|
|
|
input.tessOuterLo,
|
|
|
|
input.tessOuterHi);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-26 23:35:06 +00:00
|
|
|
int3 patchParam = patch[0].patchParam;
|
|
|
|
OsdEvalPatchBSpline(patchParam, UV, cv, P, dPu, dPv, N, dNu, dNv);
|
2015-04-18 21:00:23 +00:00
|
|
|
|
2015-05-26 23:35:06 +00:00
|
|
|
// all code below here is client code
|
|
|
|
output.position = mul(OsdModelViewMatrix(), float4(P, 1.0f));
|
|
|
|
output.normal = mul(OsdModelViewMatrix(), float4(N, 0.0f)).xyz;
|
|
|
|
output.tangent = mul(OsdModelViewMatrix(), float4(dPu, 0.0f)).xyz;
|
|
|
|
output.bitangent = mul(OsdModelViewMatrix(), float4(dPv, 0.0f)).xyz;
|
2015-04-18 21:00:23 +00:00
|
|
|
#ifdef OSD_COMPUTE_NORMAL_DERIVATIVES
|
2015-05-26 23:35:06 +00:00
|
|
|
output.Nu = dNu;
|
|
|
|
output.Nv = dNv;
|
2015-04-18 21:00:23 +00:00
|
|
|
#endif
|
2015-05-26 23:35:06 +00:00
|
|
|
#ifdef OSD_PATCH_ENABLE_SINGLE_CREASE
|
|
|
|
output.sharpness = cv[0].sharpness;
|
2015-04-18 21:00:23 +00:00
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-26 23:35:06 +00:00
|
|
|
output.patchCoord = OsdInterpolatePatchCoord(UV, patchParam);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
OSD_DISPLACEMENT_CALLBACK;
|
2015-04-18 21:00:23 +00:00
|
|
|
|
2015-05-21 14:25:04 +00:00
|
|
|
output.positionOut = mul(OsdProjectionMatrix(), output.position);
|
2015-04-18 21:00:23 +00:00
|
|
|
output.edgeDistance = 0;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|