mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2024-11-23 12:10:08 +00:00
Partial cleanup of bicubic patch shader source
- Added OSD_ prefix to preprocessor symbols - Adjusted transition sub-patch parameterization to be consistent with non-transition patches - Unified BSpline shader code - Removed duplicate Boundary, Corner, and Transition shader source - Fixed a few discrepancies in the remaining duplicate code paths
This commit is contained in:
parent
876cf3bc86
commit
9bab9185ab
@ -212,9 +212,7 @@ if( OPENGL_FOUND OR OPENGLES_FOUND )
|
||||
if ( OPENGL_FOUND )
|
||||
list(APPEND KERNEL_FILES
|
||||
glslPatchCommon.glsl
|
||||
glslPatchRegular.glsl
|
||||
glslPatchBoundary.glsl
|
||||
glslPatchCorner.glsl
|
||||
glslPatchBSpline.glsl
|
||||
glslPatchGregory.glsl
|
||||
glslPatchBoundaryGregory.glsl
|
||||
glslPatchTransition.glsl
|
||||
@ -295,9 +293,7 @@ if( DXSDK_FOUND )
|
||||
list(APPEND KERNEL_FILES
|
||||
hlslComputeKernel.hlsl
|
||||
hlslPatchCommon.hlsl
|
||||
hlslPatchRegular.hlsl
|
||||
hlslPatchBoundary.hlsl
|
||||
hlslPatchCorner.hlsl
|
||||
hlslPatchBSpline.hlsl
|
||||
hlslPatchGregory.hlsl
|
||||
hlslPatchBoundaryGregory.hlsl
|
||||
hlslPatchTransition.hlsl
|
||||
|
@ -72,14 +72,8 @@ OsdD3D11DrawConfig::~OsdD3D11DrawConfig()
|
||||
static const char *commonShaderSource =
|
||||
#include "hlslPatchCommon.inc"
|
||||
;
|
||||
static const char *regularShaderSource =
|
||||
#include "hlslPatchRegular.inc"
|
||||
;
|
||||
static const char *boundaryShaderSource =
|
||||
#include "hlslPatchBoundary.inc"
|
||||
;
|
||||
static const char *cornerShaderSource =
|
||||
#include "hlslPatchCorner.inc"
|
||||
static const char *bsplineShaderSource =
|
||||
#include "hlslPatchBSpline.inc"
|
||||
;
|
||||
static const char *gregoryShaderSource =
|
||||
#include "hlslPatchGregory.inc"
|
||||
@ -113,52 +107,54 @@ OsdD3D11DrawRegistryBase::_CreateDrawSourceConfig(
|
||||
switch (desc.GetType()) {
|
||||
case FarPatchTables::QUADS:
|
||||
case FarPatchTables::TRIANGLES:
|
||||
sconfig->vertexShader.source = regularShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.target = "vs_5_0";
|
||||
sconfig->vertexShader.entry = "vs_main";
|
||||
sconfig->pixelShader.source = regularShaderSource;
|
||||
sconfig->pixelShader.source = bsplineShaderSource;
|
||||
sconfig->pixelShader.target = "ps_5_0";
|
||||
sconfig->pixelShader.entry = "ps_main";
|
||||
break;
|
||||
case FarPatchTables::REGULAR:
|
||||
sconfig->vertexShader.source = regularShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.target = "vs_5_0";
|
||||
sconfig->vertexShader.entry = "vs_main_patches";
|
||||
sconfig->hullShader.source = regularShaderSource;
|
||||
sconfig->hullShader.source = bsplineShaderSource;
|
||||
sconfig->hullShader.target = "hs_5_0";
|
||||
sconfig->hullShader.entry = "hs_main_patches";
|
||||
sconfig->domainShader.source = regularShaderSource;
|
||||
sconfig->domainShader.source = bsplineShaderSource;
|
||||
sconfig->domainShader.target = "ds_5_0";
|
||||
sconfig->domainShader.entry = "ds_main_patches";
|
||||
sconfig->pixelShader.source = regularShaderSource;
|
||||
sconfig->pixelShader.source = bsplineShaderSource;
|
||||
sconfig->pixelShader.target = "ps_5_0";
|
||||
sconfig->pixelShader.entry = "ps_main";
|
||||
break;
|
||||
case FarPatchTables::BOUNDARY:
|
||||
sconfig->vertexShader.source = boundaryShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.target = "vs_5_0";
|
||||
sconfig->vertexShader.entry = "vs_main_patches";
|
||||
sconfig->hullShader.source = boundaryShaderSource;
|
||||
sconfig->hullShader.source = bsplineShaderSource;
|
||||
sconfig->hullShader.target = "hs_5_0";
|
||||
sconfig->hullShader.entry = "hs_main_patches";
|
||||
sconfig->domainShader.source = boundaryShaderSource;
|
||||
sconfig->hullShader.AddDefine("OSD_PATCH_BOUNDARY");
|
||||
sconfig->domainShader.source = bsplineShaderSource;
|
||||
sconfig->domainShader.target = "ds_5_0";
|
||||
sconfig->domainShader.entry = "ds_main_patches";
|
||||
sconfig->pixelShader.source = boundaryShaderSource;
|
||||
sconfig->pixelShader.source = bsplineShaderSource;
|
||||
sconfig->pixelShader.target = "ps_5_0";
|
||||
sconfig->pixelShader.entry = "ps_main";
|
||||
break;
|
||||
case FarPatchTables::CORNER:
|
||||
sconfig->vertexShader.source = cornerShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.target = "vs_5_0";
|
||||
sconfig->vertexShader.entry = "vs_main_patches";
|
||||
sconfig->hullShader.source = cornerShaderSource;
|
||||
sconfig->hullShader.source = bsplineShaderSource;
|
||||
sconfig->hullShader.target = "hs_5_0";
|
||||
sconfig->hullShader.entry = "hs_main_patches";
|
||||
sconfig->domainShader.source = cornerShaderSource;
|
||||
sconfig->hullShader.AddDefine("OSD_PATCH_CORNER");
|
||||
sconfig->domainShader.source = bsplineShaderSource;
|
||||
sconfig->domainShader.target = "ds_5_0";
|
||||
sconfig->domainShader.entry = "ds_main_patches";
|
||||
sconfig->pixelShader.source = cornerShaderSource;
|
||||
sconfig->pixelShader.source = bsplineShaderSource;
|
||||
sconfig->pixelShader.target = "ps_5_0";
|
||||
sconfig->pixelShader.entry = "ps_main";
|
||||
break;
|
||||
@ -196,16 +192,20 @@ OsdD3D11DrawRegistryBase::_CreateDrawSourceConfig(
|
||||
break;
|
||||
}
|
||||
} else { // pattern != NON_TRANSITION
|
||||
sconfig->vertexShader.source = transitionShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.target = "vs_5_0";
|
||||
sconfig->vertexShader.entry = "vs_main_patches";
|
||||
sconfig->hullShader.source = transitionShaderSource;;
|
||||
sconfig->hullShader.source =
|
||||
std::string(transitionShaderSource) + bsplineShaderSource;
|
||||
sconfig->hullShader.target = "hs_5_0";
|
||||
sconfig->hullShader.entry = "hs_main_patches";
|
||||
sconfig->domainShader.source = transitionShaderSource;
|
||||
sconfig->hullShader.AddDefine("OSD_PATCH_TRANSITION");
|
||||
sconfig->domainShader.source =
|
||||
std::string(transitionShaderSource) + bsplineShaderSource;
|
||||
sconfig->domainShader.target = "ds_5_0";
|
||||
sconfig->domainShader.entry = "ds_main_patches";
|
||||
sconfig->pixelShader.source = transitionShaderSource;
|
||||
sconfig->domainShader.AddDefine("OSD_PATCH_TRANSITION");
|
||||
sconfig->pixelShader.source = bsplineShaderSource;
|
||||
sconfig->pixelShader.target = "ps_5_0";
|
||||
sconfig->pixelShader.entry = "ps_main";
|
||||
|
||||
@ -214,19 +214,19 @@ OsdD3D11DrawRegistryBase::_CreateDrawSourceConfig(
|
||||
int subpatch = desc.GetSubPatch();
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << "CASE" << pattern << subpatch;
|
||||
ss << "OSD_TRANSITION_PATTERN" << pattern << subpatch;
|
||||
sconfig->hullShader.AddDefine(ss.str());
|
||||
sconfig->domainShader.AddDefine(ss.str());
|
||||
|
||||
ss.str("");
|
||||
ss << rotation;
|
||||
sconfig->hullShader.AddDefine("ROTATE", ss.str());
|
||||
sconfig->domainShader.AddDefine("ROTATE", ss.str());
|
||||
sconfig->hullShader.AddDefine("OSD_TRANSITION_ROTATE", ss.str());
|
||||
sconfig->domainShader.AddDefine("OSD_TRANSITION_ROTATE", ss.str());
|
||||
|
||||
if (desc.GetType() == FarPatchTables::BOUNDARY) {
|
||||
sconfig->hullShader.AddDefine("BOUNDARY");
|
||||
sconfig->hullShader.AddDefine("OSD_PATCH_BOUNDARY");
|
||||
} else if (desc.GetType() == FarPatchTables::CORNER) {
|
||||
sconfig->hullShader.AddDefine("CORNER");
|
||||
sconfig->hullShader.AddDefine("OSD_PATCH_CORNER");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,14 +68,8 @@ OsdGLDrawConfig::~OsdGLDrawConfig()
|
||||
static const char *commonShaderSource =
|
||||
#include "glslPatchCommon.inc"
|
||||
;
|
||||
static const char *regularShaderSource =
|
||||
#include "glslPatchRegular.inc"
|
||||
;
|
||||
static const char *boundaryShaderSource =
|
||||
#include "glslPatchBoundary.inc"
|
||||
;
|
||||
static const char *cornerShaderSource =
|
||||
#include "glslPatchCorner.inc"
|
||||
static const char *bsplineShaderSource =
|
||||
#include "glslPatchBSpline.inc"
|
||||
;
|
||||
static const char *gregoryShaderSource =
|
||||
#include "glslPatchGregory.inc"
|
||||
@ -110,82 +104,84 @@ OsdGLDrawRegistryBase::_CreateDrawSourceConfig(OsdDrawContext::PatchDescriptor c
|
||||
switch (desc.GetType()) {
|
||||
case FarPatchTables::QUADS:
|
||||
case FarPatchTables::TRIANGLES:
|
||||
sconfig->vertexShader.source = regularShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.version = "#version 410\n";
|
||||
sconfig->vertexShader.AddDefine("VERTEX_SHADER");
|
||||
sconfig->fragmentShader.source = regularShaderSource;
|
||||
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
||||
sconfig->vertexShader.AddDefine("OSD_VERTEX_SHADER");
|
||||
sconfig->fragmentShader.source = bsplineShaderSource;
|
||||
sconfig->fragmentShader.AddDefine("OSD_FRAGMENT_SHADER");
|
||||
sconfig->fragmentShader.version = "#version 410\n";
|
||||
break;
|
||||
case FarPatchTables::REGULAR:
|
||||
sconfig->vertexShader.source = regularShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.version = "#version 410\n";
|
||||
sconfig->vertexShader.AddDefine("PATCH_VERTEX_SHADER");
|
||||
sconfig->tessControlShader.source = regularShaderSource;
|
||||
sconfig->vertexShader.AddDefine("OSD_PATCH_VERTEX_BSPLINE_SHADER");
|
||||
sconfig->tessControlShader.source = bsplineShaderSource;
|
||||
sconfig->tessControlShader.version = "#version 410\n";
|
||||
sconfig->tessControlShader.AddDefine("PATCH_TESS_CONTROL_REGULAR_SHADER");
|
||||
sconfig->tessEvalShader.source = regularShaderSource;
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_TESS_CONTROL_BSPLINE_SHADER");
|
||||
sconfig->tessEvalShader.source = bsplineShaderSource;
|
||||
sconfig->tessEvalShader.version = "#version 410\n";
|
||||
sconfig->tessEvalShader.AddDefine("PATCH_TESS_EVAL_REGULAR_SHADER");
|
||||
sconfig->fragmentShader.source = regularShaderSource;
|
||||
sconfig->tessEvalShader.AddDefine("OSD_PATCH_TESS_EVAL_BSPLINE_SHADER");
|
||||
sconfig->fragmentShader.source = bsplineShaderSource;
|
||||
sconfig->fragmentShader.version = "#version 410\n";
|
||||
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
||||
sconfig->fragmentShader.AddDefine("OSD_FRAGMENT_SHADER");
|
||||
break;
|
||||
case FarPatchTables::BOUNDARY:
|
||||
sconfig->vertexShader.source = boundaryShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.version = "#version 410\n";
|
||||
sconfig->vertexShader.AddDefine("PATCH_VERTEX_SHADER");
|
||||
sconfig->tessControlShader.source = boundaryShaderSource;
|
||||
sconfig->vertexShader.AddDefine("OSD_PATCH_VERTEX_BSPLINE_SHADER");
|
||||
sconfig->tessControlShader.source = bsplineShaderSource;
|
||||
sconfig->tessControlShader.version = "#version 410\n";
|
||||
sconfig->tessControlShader.AddDefine("PATCH_TESS_CONTROL_BOUNDARY_SHADER");
|
||||
sconfig->tessEvalShader.source = boundaryShaderSource;
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_TESS_CONTROL_BSPLINE_SHADER");
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_BOUNDARY");
|
||||
sconfig->tessEvalShader.source = bsplineShaderSource;
|
||||
sconfig->tessEvalShader.version = "#version 410\n";
|
||||
sconfig->tessEvalShader.AddDefine("PATCH_TESS_EVAL_BOUNDARY_SHADER");
|
||||
sconfig->fragmentShader.source = boundaryShaderSource;
|
||||
sconfig->tessEvalShader.AddDefine("OSD_PATCH_TESS_EVAL_BSPLINE_SHADER");
|
||||
sconfig->fragmentShader.source = bsplineShaderSource;
|
||||
sconfig->fragmentShader.version = "#version 410\n";
|
||||
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
||||
sconfig->fragmentShader.AddDefine("OSD_FRAGMENT_SHADER");
|
||||
break;
|
||||
case FarPatchTables::CORNER:
|
||||
sconfig->vertexShader.source = cornerShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.version = "#version 410\n";
|
||||
sconfig->vertexShader.AddDefine("PATCH_VERTEX_SHADER");
|
||||
sconfig->tessControlShader.source = cornerShaderSource;
|
||||
sconfig->vertexShader.AddDefine("OSD_PATCH_VERTEX_BSPLINE_SHADER");
|
||||
sconfig->tessControlShader.source = bsplineShaderSource;
|
||||
sconfig->tessControlShader.version = "#version 410\n";
|
||||
sconfig->tessControlShader.AddDefine("PATCH_TESS_CONTROL_CORNER_SHADER");
|
||||
sconfig->tessEvalShader.source = cornerShaderSource;
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_TESS_CONTROL_BSPLINE_SHADER");
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_CORNER");
|
||||
sconfig->tessEvalShader.source = bsplineShaderSource;
|
||||
sconfig->tessEvalShader.version = "#version 410\n";
|
||||
sconfig->tessEvalShader.AddDefine("PATCH_TESS_EVAL_CORNER_SHADER");
|
||||
sconfig->fragmentShader.source = cornerShaderSource;
|
||||
sconfig->tessEvalShader.AddDefine("OSD_PATCH_TESS_EVAL_BSPLINE_SHADER");
|
||||
sconfig->fragmentShader.source = bsplineShaderSource;
|
||||
sconfig->fragmentShader.version = "#version 410\n";
|
||||
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
||||
sconfig->fragmentShader.AddDefine("OSD_FRAGMENT_SHADER");
|
||||
break;
|
||||
case FarPatchTables::GREGORY:
|
||||
sconfig->vertexShader.source = gregoryShaderSource;
|
||||
sconfig->vertexShader.version = "#version 410\n";
|
||||
sconfig->vertexShader.AddDefine("PATCH_VERTEX_GREGORY_SHADER");
|
||||
sconfig->vertexShader.AddDefine("OSD_PATCH_VERTEX_GREGORY_SHADER");
|
||||
sconfig->tessControlShader.source = gregoryShaderSource;
|
||||
sconfig->tessControlShader.version = "#version 410\n";
|
||||
sconfig->tessControlShader.AddDefine("PATCH_TESS_CONTROL_GREGORY_SHADER");
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_TESS_CONTROL_GREGORY_SHADER");
|
||||
sconfig->tessEvalShader.source = gregoryShaderSource;
|
||||
sconfig->tessEvalShader.version = "#version 410\n";
|
||||
sconfig->tessEvalShader.AddDefine("PATCH_TESS_EVAL_GREGORY_SHADER");
|
||||
sconfig->tessEvalShader.AddDefine("OSD_PATCH_TESS_EVAL_GREGORY_SHADER");
|
||||
sconfig->fragmentShader.source = gregoryShaderSource;
|
||||
sconfig->fragmentShader.version = "#version 410\n";
|
||||
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
||||
sconfig->fragmentShader.AddDefine("OSD_FRAGMENT_SHADER");
|
||||
break;
|
||||
case FarPatchTables::GREGORY_BOUNDARY:
|
||||
sconfig->vertexShader.source = boundaryGregoryShaderSource;
|
||||
sconfig->vertexShader.version = "#version 410\n";
|
||||
sconfig->vertexShader.AddDefine("PATCH_VERTEX_BOUNDARY_GREGORY_SHADER");
|
||||
sconfig->vertexShader.AddDefine("OSD_PATCH_VERTEX_BOUNDARY_GREGORY_SHADER");
|
||||
sconfig->tessControlShader.source = boundaryGregoryShaderSource;
|
||||
sconfig->tessControlShader.version = "#version 410\n";
|
||||
sconfig->tessControlShader.AddDefine("PATCH_TESS_CONTROL_BOUNDARY_GREGORY_SHADER");
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_TESS_CONTROL_BOUNDARY_GREGORY_SHADER");
|
||||
sconfig->tessEvalShader.source = boundaryGregoryShaderSource;
|
||||
sconfig->tessEvalShader.version = "#version 410\n";
|
||||
sconfig->tessEvalShader.AddDefine("PATCH_TESS_EVAL_BOUNDARY_GREGORY_SHADER");
|
||||
sconfig->tessEvalShader.AddDefine("OSD_PATCH_TESS_EVAL_BOUNDARY_GREGORY_SHADER");
|
||||
sconfig->fragmentShader.source = boundaryGregoryShaderSource;
|
||||
sconfig->fragmentShader.version = "#version 410\n";
|
||||
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
||||
sconfig->fragmentShader.AddDefine("OSD_FRAGMENT_SHADER");
|
||||
break;
|
||||
default:
|
||||
// error
|
||||
@ -194,37 +190,41 @@ OsdGLDrawRegistryBase::_CreateDrawSourceConfig(OsdDrawContext::PatchDescriptor c
|
||||
break;
|
||||
}
|
||||
} else { // pattern != NON_TRANSITION
|
||||
sconfig->vertexShader.source = transitionShaderSource;
|
||||
sconfig->vertexShader.source = bsplineShaderSource;
|
||||
sconfig->vertexShader.version = "#version 410\n";
|
||||
sconfig->vertexShader.AddDefine("PATCH_VERTEX_SHADER");
|
||||
sconfig->tessControlShader.source = transitionShaderSource;;
|
||||
sconfig->vertexShader.AddDefine("OSD_PATCH_VERTEX_BSPLINE_SHADER");
|
||||
sconfig->tessControlShader.source =
|
||||
std::string(transitionShaderSource) + bsplineShaderSource;
|
||||
sconfig->tessControlShader.version = "#version 410\n";
|
||||
sconfig->tessControlShader.AddDefine("PATCH_TESS_CONTROL_TRANSITION_SHADER");
|
||||
sconfig->tessEvalShader.source = transitionShaderSource;
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_TESS_CONTROL_BSPLINE_SHADER");
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_TRANSITION");
|
||||
sconfig->tessEvalShader.source =
|
||||
std::string(transitionShaderSource) + bsplineShaderSource;
|
||||
sconfig->tessEvalShader.version = "#version 410\n";
|
||||
sconfig->tessEvalShader.AddDefine("PATCH_TESS_EVAL_TRANSITION_SHADER");
|
||||
sconfig->fragmentShader.source = transitionShaderSource;
|
||||
sconfig->tessEvalShader.AddDefine("OSD_PATCH_TESS_EVAL_BSPLINE_SHADER");
|
||||
sconfig->tessEvalShader.AddDefine("OSD_PATCH_TRANSITION");
|
||||
sconfig->fragmentShader.source = bsplineShaderSource;
|
||||
sconfig->fragmentShader.version = "#version 410\n";
|
||||
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
||||
sconfig->fragmentShader.AddDefine("OSD_FRAGMENT_SHADER");
|
||||
|
||||
int pattern = desc.GetPattern() - 1;
|
||||
int rotation = desc.GetRotation();
|
||||
int subpatch = desc.GetSubPatch();
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << "CASE" << pattern << subpatch;
|
||||
ss << "OSD_TRANSITION_PATTERN" << pattern << subpatch;
|
||||
sconfig->tessControlShader.AddDefine(ss.str());
|
||||
sconfig->tessEvalShader.AddDefine(ss.str());
|
||||
|
||||
ss.str("");
|
||||
ss << rotation;
|
||||
sconfig->tessControlShader.AddDefine("ROTATE", ss.str());
|
||||
sconfig->tessEvalShader.AddDefine("ROTATE", ss.str());
|
||||
sconfig->tessControlShader.AddDefine("OSD_TRANSITION_ROTATE", ss.str());
|
||||
sconfig->tessEvalShader.AddDefine("OSD_TRANSITION_ROTATE", ss.str());
|
||||
|
||||
if (desc.GetType() == FarPatchTables::BOUNDARY) {
|
||||
sconfig->tessControlShader.AddDefine("BOUNDARY");
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_BOUNDARY");
|
||||
} else if (desc.GetType() == FarPatchTables::CORNER) {
|
||||
sconfig->tessControlShader.AddDefine("CORNER");
|
||||
sconfig->tessControlShader.AddDefine("OSD_PATCH_CORNER");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -56,17 +56,18 @@
|
||||
//
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessVertex
|
||||
// Patches.TessVertexBSpline
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_VERTEX_SHADER
|
||||
#ifdef OSD_PATCH_VERTEX_BSPLINE_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
layout(location = 0) in vec4 position;
|
||||
|
||||
out block {
|
||||
ControlVertex v;
|
||||
} outpt;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
outpt.v.position = ModelViewMatrix * position;
|
||||
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position);
|
||||
|
||||
@ -79,9 +80,25 @@ void main() {
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessControlRegular
|
||||
// Patches.TessControlBSpline
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_CONTROL_REGULAR_SHADER
|
||||
#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
|
||||
);
|
||||
|
||||
// Boundary / Corner
|
||||
uniform mat4x3 B = mat4x3(
|
||||
1.f, 0.f, 0.f,
|
||||
4.f/6.f, 2.f/6.f, 0.f,
|
||||
2.f/6.f, 4.f/6.f, 0.f,
|
||||
1.f/6.f, 4.f/6.f, 1.f/6.f
|
||||
);
|
||||
|
||||
layout(vertices = 16) out;
|
||||
|
||||
@ -97,25 +114,53 @@ out block {
|
||||
|
||||
void main()
|
||||
{
|
||||
int i = ID/4;
|
||||
int j = ID%4;
|
||||
int i = ID%4;
|
||||
int j = ID/4;
|
||||
|
||||
vec3 H[4];
|
||||
for (int l=0; l<4; l++) {
|
||||
#if defined OSD_PATCH_BOUNDARY
|
||||
vec3 H[3];
|
||||
for (int l=0; l<3; ++l) {
|
||||
H[l] = vec3(0,0,0);
|
||||
for (int k=0; k<4; k++) {
|
||||
float c = Q[i][k];
|
||||
// XXX: fix this in patchMeshFactory.
|
||||
// H[l] += c*inpt[l*4 + k].v.position.xyz;
|
||||
H[l] += c*inpt[l + k*4].v.position.xyz;
|
||||
for (int k=0; k<4; ++k) {
|
||||
H[l] += Q[i][k] * inpt[l*4 + k].v.position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 pos = vec3(0,0,0);
|
||||
for (int k=0; k<4; k++) {
|
||||
for (int k=0; k<3; ++k) {
|
||||
pos += B[j][k]*H[k];
|
||||
}
|
||||
|
||||
#elif defined OSD_PATCH_CORNER
|
||||
vec3 H[3];
|
||||
for (int l=0; l<3; ++l) {
|
||||
H[l] = vec3(0,0,0);
|
||||
for (int k=0; k<3; ++k) {
|
||||
H[l] += B[3-i][2-k] * inpt[l*3 + k].v.position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 pos = vec3(0,0,0);
|
||||
for (int k=0; k<3; ++k) {
|
||||
pos += B[j][k]*H[k];
|
||||
}
|
||||
|
||||
#else // not OSD_PATCH_BOUNDARY, not OSD_PATCH_CORNER
|
||||
vec3 H[4];
|
||||
for (int l=0; l<4; ++l) {
|
||||
H[l] = vec3(0,0,0);
|
||||
for (int k=0; k<4; ++k) {
|
||||
H[l] += Q[i][k] * inpt[l*4 + k].v.position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 pos = vec3(0,0,0);
|
||||
for (int k=0; k<4; ++k) {
|
||||
pos += Q[j][k]*H[k];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
outpt[ID].v.position = vec4(pos, 1.0);
|
||||
|
||||
int patchLevel = GetPatchLevel();
|
||||
@ -130,26 +175,34 @@ void main()
|
||||
if (ID == 0) {
|
||||
OSD_PATCH_CULL(16);
|
||||
|
||||
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
gl_TessLevelOuter[0] =
|
||||
TessAdaptive(inpt[5].v.position.xyz, inpt[9].v.position.xyz, patchLevel);
|
||||
gl_TessLevelOuter[1] =
|
||||
TessAdaptive(inpt[5].v.position.xyz, inpt[6].v.position.xyz, patchLevel);
|
||||
gl_TessLevelOuter[2] =
|
||||
TessAdaptive(inpt[6].v.position.xyz, inpt[10].v.position.xyz, patchLevel);
|
||||
gl_TessLevelOuter[3] =
|
||||
TessAdaptive(inpt[9].v.position.xyz, inpt[10].v.position.xyz, patchLevel);
|
||||
gl_TessLevelInner[0] =
|
||||
max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]);
|
||||
gl_TessLevelInner[1] =
|
||||
max(gl_TessLevelOuter[0], gl_TessLevelOuter[2]);
|
||||
#ifdef OSD_PATCH_TRANSITION
|
||||
vec3 cp[OSD_PATCH_INPUT_SIZE];
|
||||
for(int k = 0; k < OSD_PATCH_INPUT_SIZE; ++k) cp[k] = inpt[k].v.position.xyz;
|
||||
SetTransitionTessLevels(cp, patchLevel);
|
||||
#else
|
||||
#if defined OSD_PATCH_BOUNDARY
|
||||
const int p[4] = int[]( 1, 2, 5, 6 );
|
||||
#elif defined OSD_PATCH_CORNER
|
||||
const int p[4] = int[]( 1, 2, 4, 5 );
|
||||
#else
|
||||
const int p[4] = int[]( 5, 6, 9, 10 );
|
||||
#endif
|
||||
|
||||
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
gl_TessLevelOuter[0] = TessAdaptive(inpt[p[0]].v.position.xyz, inpt[p[2]].v.position.xyz);
|
||||
gl_TessLevelOuter[1] = TessAdaptive(inpt[p[0]].v.position.xyz, inpt[p[1]].v.position.xyz);
|
||||
gl_TessLevelOuter[2] = TessAdaptive(inpt[p[1]].v.position.xyz, inpt[p[3]].v.position.xyz);
|
||||
gl_TessLevelOuter[3] = TessAdaptive(inpt[p[2]].v.position.xyz, inpt[p[3]].v.position.xyz);
|
||||
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
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -157,12 +210,15 @@ void main()
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessEvalRegular
|
||||
// Patches.TessEvalBSpline
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_EVAL_REGULAR_SHADER
|
||||
#ifdef OSD_PATCH_TESS_EVAL_BSPLINE_SHADER
|
||||
|
||||
layout(quads) in;
|
||||
layout(equal_spacing) in;
|
||||
#ifdef OSD_TRANSITION_TRIANGLE_SUBPATCH
|
||||
layout(triangles) in;
|
||||
#else
|
||||
layout(quads) in;
|
||||
#endif
|
||||
|
||||
in block {
|
||||
ControlVertex v;
|
||||
@ -174,13 +230,16 @@ out block {
|
||||
|
||||
void main()
|
||||
{
|
||||
float u = gl_TessCoord.x,
|
||||
v = gl_TessCoord.y;
|
||||
#ifdef OSD_PATCH_TRANSITION
|
||||
vec2 UV = GetTransitionSubpatchUV();
|
||||
#else
|
||||
vec2 UV = gl_TessCoord.xy;
|
||||
#endif
|
||||
|
||||
vec3 WorldPos, Tangent, BiTangent;
|
||||
vec3 cp[16];
|
||||
for(int i = 0; i < 16; ++i) cp[i] = inpt[i].v.position.xyz;
|
||||
EvalBSpline(gl_TessCoord.xy, cp, WorldPos, Tangent, BiTangent);
|
||||
EvalBSpline(UV, cp, WorldPos, Tangent, BiTangent);
|
||||
|
||||
vec3 normal = normalize(cross(Tangent, BiTangent));
|
||||
|
||||
@ -189,10 +248,21 @@ void main()
|
||||
outpt.v.tangent = Tangent;
|
||||
|
||||
outpt.v.patchCoord = inpt[0].v.patchCoord;
|
||||
outpt.v.patchCoord.xy = vec2(u, v);
|
||||
|
||||
#if OSD_TRANSITION_ROTATE == 1
|
||||
outpt.v.patchCoord.xy = vec2(UV.y, 1.0-UV.x);
|
||||
#elif OSD_TRANSITION_ROTATE == 2
|
||||
outpt.v.patchCoord.xy = vec2(1.0-UV.x, 1.0-UV.y);
|
||||
#elif OSD_TRANSITION_ROTATE == 3
|
||||
outpt.v.patchCoord.xy = vec2(1.0-UV.y, UV.x);
|
||||
#else // OSD_TRANNSITION_ROTATE == 0, or non-transition patch
|
||||
outpt.v.patchCoord.xy = vec2(UV.x, UV.y);
|
||||
#endif
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER;
|
||||
|
||||
OSD_COMPUTE_PTEX_COMPATIBLE_TANGENT(OSD_TRANSITION_ROTATE);
|
||||
|
||||
OSD_DISPLACEMENT_CALLBACK;
|
||||
|
||||
gl_Position = (ProjectionMatrix * vec4(WorldPos, 1.0f));
|
||||
@ -203,7 +273,7 @@ void main()
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
#ifdef VERTEX_SHADER
|
||||
#ifdef OSD_VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
layout (location=1) in vec3 normal;
|
||||
@ -223,7 +293,7 @@ void main() {
|
||||
//----------------------------------------------------------
|
||||
// Patches.FragmentColor
|
||||
//----------------------------------------------------------
|
||||
#ifdef FRAGMENT_SHADER
|
||||
#ifdef OSD_FRAGMENT_SHADER
|
||||
|
||||
in block {
|
||||
OutputVertex v;
|
@ -1,269 +0,0 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessVertex
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
|
||||
out block {
|
||||
ControlVertex v;
|
||||
} outpt;
|
||||
|
||||
void main() {
|
||||
outpt.v.position = ModelViewMatrix * position;
|
||||
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position);
|
||||
|
||||
#if OSD_NUM_VARYINGS > 0
|
||||
for (int i = 0; i < OSD_NUM_VARYINGS; ++i)
|
||||
outpt.v.varyings[i] = varyings[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessControlBoundary
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_CONTROL_BOUNDARY_SHADER
|
||||
|
||||
layout(vertices = 16) out;
|
||||
|
||||
in block {
|
||||
ControlVertex v;
|
||||
} inpt[];
|
||||
|
||||
out block {
|
||||
ControlVertex v;
|
||||
} outpt[];
|
||||
|
||||
#define ID gl_InvocationID
|
||||
|
||||
void main()
|
||||
{
|
||||
int i = ID/4;
|
||||
int j = ID%4;
|
||||
|
||||
i = 3 - i;
|
||||
|
||||
vec3 H[3];
|
||||
for (int l=0; l<3; l++) {
|
||||
H[l] = vec3(0,0,0);
|
||||
for (int k=0; k<4; k++) {
|
||||
float c = Q[i][k];
|
||||
H[l] += c*inpt[l*4 + k].v.position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 pos = vec3(0,0,0);
|
||||
for (int k=0; k<3; k++) {
|
||||
pos += B[j][k]*H[k];
|
||||
}
|
||||
|
||||
outpt[ID].v.position = vec4(pos, 1.0);
|
||||
|
||||
int patchLevel = GetPatchLevel();
|
||||
// +0.5 to avoid interpolation error of integer value
|
||||
outpt[ID].v.patchCoord = vec4(0, 0,
|
||||
patchLevel+0.5,
|
||||
gl_PrimitiveID+LevelBase+0.5);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER;
|
||||
|
||||
if (ID == 0) {
|
||||
OSD_PATCH_CULL(12);
|
||||
|
||||
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
gl_TessLevelOuter[0] =
|
||||
TessAdaptive(inpt[1].v.position.xyz, inpt[2].v.position.xyz, patchLevel);
|
||||
gl_TessLevelOuter[1] =
|
||||
TessAdaptive(inpt[2].v.position.xyz, inpt[6].v.position.xyz, patchLevel);
|
||||
gl_TessLevelOuter[2] =
|
||||
TessAdaptive(inpt[5].v.position.xyz, inpt[6].v.position.xyz, patchLevel);
|
||||
gl_TessLevelOuter[3] =
|
||||
TessAdaptive(inpt[1].v.position.xyz, inpt[5].v.position.xyz, patchLevel);
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessEvalBoundary
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_EVAL_BOUNDARY_SHADER
|
||||
|
||||
layout(quads) in;
|
||||
layout(equal_spacing) in;
|
||||
|
||||
in block {
|
||||
ControlVertex v;
|
||||
} inpt[];
|
||||
|
||||
out block {
|
||||
OutputVertex v;
|
||||
} outpt;
|
||||
|
||||
void main()
|
||||
{
|
||||
float u = gl_TessCoord.x,
|
||||
v = gl_TessCoord.y;
|
||||
|
||||
/*
|
||||
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.0f, 0.0f, 0.0f);
|
||||
DUCP[i] = vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
vec3 WorldPos = vec3(0.0f, 0.0f, 0.0f);
|
||||
vec3 Tangent = vec3(0.0f, 0.0f, 0.0f);
|
||||
vec3 BiTangent = vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
Univar4x4(v, B, D);
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
Tangent += B[i] * DUCP[i];
|
||||
BiTangent += D[i] * BUCP[i];
|
||||
}
|
||||
*/
|
||||
vec3 WorldPos, Tangent, BiTangent;
|
||||
vec3 cp[16];
|
||||
for(int i = 0; i < 16; ++i) cp[i] = inpt[i].v.position.xyz;
|
||||
EvalBSpline(gl_TessCoord.xy, cp, WorldPos, Tangent, BiTangent);
|
||||
|
||||
vec3 normal = normalize(cross(Tangent, BiTangent));
|
||||
|
||||
outpt.v.position = vec4(WorldPos, 1.0f);
|
||||
outpt.v.normal = normal;
|
||||
|
||||
BiTangent = -BiTangent; // BiTangent will be used in following macro
|
||||
outpt.v.tangent = BiTangent;
|
||||
|
||||
outpt.v.patchCoord = inpt[0].v.patchCoord;
|
||||
outpt.v.patchCoord.xy = vec2(1.0-v, u);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER;
|
||||
|
||||
OSD_COMPUTE_PTEX_COMPATIBLE_TANGENT(0);
|
||||
|
||||
OSD_DISPLACEMENT_CALLBACK;
|
||||
|
||||
gl_Position = (ProjectionMatrix * vec4(WorldPos, 1.0f));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
#ifdef VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
layout (location=1) in vec3 normal;
|
||||
layout (location=2) in vec4 color;
|
||||
|
||||
out block {
|
||||
OutputVertex v;
|
||||
} outpt;
|
||||
|
||||
void main() {
|
||||
gl_Position = ModelViewProjectionMatrix * position;
|
||||
outpt.v.color = color;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.FragmentColor
|
||||
//----------------------------------------------------------
|
||||
#ifdef FRAGMENT_SHADER
|
||||
|
||||
in block {
|
||||
OutputVertex v;
|
||||
} inpt;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = inpt.v.color;
|
||||
}
|
||||
#endif
|
@ -58,7 +58,7 @@
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessVertexBoundaryGregory
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_VERTEX_BOUNDARY_GREGORY_SHADER
|
||||
#ifdef OSD_PATCH_VERTEX_BOUNDARY_GREGORY_SHADER
|
||||
|
||||
uniform samplerBuffer g_VertexBuffer;
|
||||
uniform isamplerBuffer g_ValenceBuffer;
|
||||
@ -258,7 +258,7 @@ void main()
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessControlBoundaryGregory
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_CONTROL_BOUNDARY_GREGORY_SHADER
|
||||
#ifdef OSD_PATCH_TESS_CONTROL_BOUNDARY_GREGORY_SHADER
|
||||
|
||||
layout(vertices = 4) out;
|
||||
|
||||
@ -410,13 +410,13 @@ void main()
|
||||
|
||||
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
gl_TessLevelOuter[0] =
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[1].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[1].v.hullPosition.xyz);
|
||||
gl_TessLevelOuter[1] =
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz);
|
||||
gl_TessLevelOuter[2] =
|
||||
TessAdaptive(inpt[2].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[2].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz);
|
||||
gl_TessLevelOuter[3] =
|
||||
TessAdaptive(inpt[1].v.hullPosition.xyz, inpt[2].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[1].v.hullPosition.xyz, inpt[2].v.hullPosition.xyz);
|
||||
gl_TessLevelInner[0] =
|
||||
max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]);
|
||||
gl_TessLevelInner[1] =
|
||||
@ -436,7 +436,7 @@ void main()
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessEvalBoundaryGregory
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_EVAL_BOUNDARY_GREGORY_SHADER
|
||||
#ifdef OSD_PATCH_TESS_EVAL_BOUNDARY_GREGORY_SHADER
|
||||
|
||||
layout(quads) in;
|
||||
layout(cw) in;
|
||||
@ -509,7 +509,7 @@ void main()
|
||||
|
||||
float B[4], D[4];
|
||||
|
||||
Univar4x4(gl_TessCoord.x, B, D);
|
||||
Univar4x4(u, B, D);
|
||||
vec3 BUCP[4], DUCP[4];
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
@ -529,7 +529,7 @@ void main()
|
||||
vec3 Tangent = vec3(0, 0, 0);
|
||||
vec3 BiTangent = vec3(0, 0, 0);
|
||||
|
||||
Univar4x4(gl_TessCoord.y, B, D);
|
||||
Univar4x4(v, B, D);
|
||||
|
||||
for (uint i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
@ -544,15 +544,16 @@ void main()
|
||||
|
||||
outpt.v.position = ModelViewMatrix * vec4(WorldPos, 1.0f);
|
||||
outpt.v.normal = normal;
|
||||
outpt.v.tangent = normalize(BiTangent);
|
||||
|
||||
outpt.v.patchCoord = inpt[0].v.patchCoord;
|
||||
outpt.v.patchCoord.xy = vec2(v, u);
|
||||
outpt.v.tangent = normalize(BiTangent);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER;
|
||||
|
||||
OSD_DISPLACEMENT_CALLBACK;
|
||||
|
||||
gl_Position = (ModelViewProjectionMatrix * vec4(WorldPos, 1.0f));
|
||||
gl_Position = ProjectionMatrix * outpt.v.position;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -560,7 +561,7 @@ void main()
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
#ifdef VERTEX_SHADER
|
||||
#ifdef OSD_VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
layout (location=1) in vec3 normal;
|
||||
@ -580,7 +581,7 @@ void main() {
|
||||
//----------------------------------------------------------
|
||||
// Patches.FragmentColor
|
||||
//----------------------------------------------------------
|
||||
#ifdef FRAGMENT_SHADER
|
||||
#ifdef OSD_FRAGMENT_SHADER
|
||||
|
||||
in block {
|
||||
OutputVertex v;
|
||||
|
@ -63,8 +63,16 @@
|
||||
#define OSD_NUM_VARYINGS 0
|
||||
#endif
|
||||
|
||||
#ifndef ROTATE
|
||||
#define ROTATE 0
|
||||
#ifndef OSD_TRANSITION_ROTATE
|
||||
#define OSD_TRANSITION_ROTATE 0
|
||||
#endif
|
||||
|
||||
#if defined OSD_PATCH_BOUNDARY
|
||||
#define OSD_PATCH_INPUT_SIZE 12
|
||||
#elif defined OSD_PATCH_CORNER
|
||||
#define OSD_PATCH_INPUT_SIZE 9
|
||||
#else
|
||||
#define OSD_PATCH_INPUT_SIZE 16
|
||||
#endif
|
||||
|
||||
#define M_PI 3.14159265359f
|
||||
@ -151,7 +159,7 @@ float GetPostProjectionSphereExtent(vec3 center, float diameter)
|
||||
return abs(diameter * ProjectionMatrix[1][1] / p.w);
|
||||
}
|
||||
|
||||
float TessAdaptive(vec3 p0, vec3 p1, int patchLevel)
|
||||
float TessAdaptive(vec3 p0, vec3 p1)
|
||||
{
|
||||
// Adaptive factor can be any computation that depends only on arg values.
|
||||
// Project the diameter of the edge's bounding sphere instead of using the
|
||||
@ -201,13 +209,13 @@ uniform isamplerBuffer g_ptexIndicesBuffer;
|
||||
{ \
|
||||
int rot = (inpt[0].v.ptexInfo.w + 4 - ROTATE)%4; \
|
||||
if (rot == 1) { \
|
||||
outpt.v.tangent = -normalize(Tangent); \
|
||||
} else if (rot == 2) { \
|
||||
outpt.v.tangent = -normalize(BiTangent); \
|
||||
} else if (rot == 2) { \
|
||||
outpt.v.tangent = -normalize(Tangent); \
|
||||
} else if (rot == 3) { \
|
||||
outpt.v.tangent = normalize(Tangent); \
|
||||
} else { \
|
||||
outpt.v.tangent = normalize(BiTangent); \
|
||||
} else { \
|
||||
outpt.v.tangent = normalize(Tangent); \
|
||||
} \
|
||||
}
|
||||
|
||||
@ -244,29 +252,6 @@ uniform isamplerBuffer g_ptexIndicesBuffer;
|
||||
//----------------------------------------------------------
|
||||
// Patches.Coefficients
|
||||
//----------------------------------------------------------
|
||||
// Regular
|
||||
uniform mat4 Q = mat4(
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.f,
|
||||
0.f, 2.f/3.f, 1.f/3.f, 0.f,
|
||||
0.f, 1.f/3.f, 2.f/3.f, 0.f,
|
||||
0.f, 1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
);
|
||||
|
||||
// Boundary
|
||||
uniform mat4x3 B = mat4x3(
|
||||
1.0f, 0.0f, 0.0f,
|
||||
2.f/3.f, 1.f/3.f, 0.0f,
|
||||
1.f/3.f, 2.f/3.f, 0.0f,
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
);
|
||||
|
||||
// Corner
|
||||
uniform mat4 R = mat4(
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.0f,
|
||||
0.0f, 2.f/3.f, 1.f/3.f, 0.0f,
|
||||
0.0f, 1.f/3.f, 2.f/3.f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f
|
||||
);
|
||||
|
||||
#if OSD_MAX_VALENCE<=10
|
||||
uniform float ef[7] = float[](
|
||||
@ -315,47 +300,6 @@ Univar4x4(in float u, out float B[4], out float D[4])
|
||||
D[3] = A2;
|
||||
}
|
||||
|
||||
vec4
|
||||
EvalBSpline(vec2 uv, vec4 cp[16])
|
||||
{
|
||||
float B[4], D[4];
|
||||
|
||||
Univar4x4(uv.x, B, D);
|
||||
vec3 BUCP[4], DUCP[4];
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
BUCP[i] = vec3(0.0f, 0.0f, 0.0f);
|
||||
DUCP[i] = vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
for (int j=0; j<4; ++j) {
|
||||
/*
|
||||
#if ROTATE == 1
|
||||
vec3 A = cp[4*(3-j) + (3-j)].xyz;
|
||||
#elif ROTATE == 2
|
||||
vec3 A = cp[4*i + (3-j)].xyz;
|
||||
#elif ROTATE == 3
|
||||
vec3 A = cp[4*j + i].xyz;
|
||||
#else
|
||||
vec3 A = cp[4*i + j].xyz;
|
||||
#endif
|
||||
*/
|
||||
vec3 A = cp[4*i + j].xyz;
|
||||
|
||||
BUCP[i] += A * B[j];
|
||||
DUCP[i] += A * D[j];
|
||||
}
|
||||
}
|
||||
vec3 val = vec3(0);
|
||||
|
||||
Univar4x4(uv.y, B, D);
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
val += B[i] * BUCP[i];
|
||||
}
|
||||
|
||||
return vec4(val, 1);
|
||||
}
|
||||
|
||||
void EvalBSpline(vec2 uv, vec3 cp[16],
|
||||
out vec3 position,
|
||||
out vec3 utangent,
|
||||
@ -372,13 +316,13 @@ void EvalBSpline(vec2 uv, vec3 cp[16],
|
||||
DUCP[i] = vec3(0);
|
||||
|
||||
for (int j=0; j<4; ++j) {
|
||||
#if ROTATE == 1
|
||||
vec3 A = cp[4*(3-j) + (3-i)];
|
||||
#elif ROTATE == 2
|
||||
vec3 A = cp[4*i + (3-j)];
|
||||
#elif ROTATE == 3
|
||||
vec3 A = cp[4*j + i];
|
||||
#else
|
||||
#if OSD_TRANSITION_ROTATE == 1
|
||||
vec3 A = cp[4*(3-j) + i];
|
||||
#elif OSD_TRANSITION_ROTATE == 2
|
||||
vec3 A = cp[4*(3-i) + (3-j)];
|
||||
#elif OSD_TRANSITION_ROTATE == 3
|
||||
vec3 A = cp[4*j + (3-i)];
|
||||
#else // OSD_TRANNSITION_ROTATE == 0, or non-transition patch
|
||||
vec3 A = cp[4*i + j];
|
||||
#endif
|
||||
BUCP[i] += A * B[j];
|
||||
@ -398,88 +342,3 @@ void EvalBSpline(vec2 uv, vec3 cp[16],
|
||||
vtangent += D[i] * BUCP[i];
|
||||
}
|
||||
}
|
||||
|
||||
vec4 EvalGregory(vec2 uv, GregEvalVertex ev[4])
|
||||
{
|
||||
float u = uv.x;
|
||||
float v = uv.y;
|
||||
vec3 p[20];
|
||||
|
||||
p[0] = ev[0].position;
|
||||
p[1] = ev[0].Ep;
|
||||
p[2] = ev[0].Em;
|
||||
p[3] = ev[0].Fp;
|
||||
p[4] = ev[0].Fm;
|
||||
|
||||
p[5] = ev[1].position;
|
||||
p[6] = ev[1].Ep;
|
||||
p[7] = ev[1].Em;
|
||||
p[8] = ev[1].Fp;
|
||||
p[9] = ev[1].Fm;
|
||||
|
||||
p[10] = ev[2].position;
|
||||
p[11] = ev[2].Ep;
|
||||
p[12] = ev[2].Em;
|
||||
p[13] = ev[2].Fp;
|
||||
p[14] = ev[2].Fm;
|
||||
|
||||
p[15] = ev[3].position;
|
||||
p[16] = ev[3].Ep;
|
||||
p[17] = ev[3].Em;
|
||||
p[18] = ev[3].Fp;
|
||||
p[19] = ev[3].Fm;
|
||||
|
||||
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);
|
||||
|
||||
Univar4x4(v, B, D);
|
||||
|
||||
for (uint i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
}
|
||||
return vec4(WorldPos, 1);
|
||||
}
|
||||
|
@ -1,265 +0,0 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessVertex
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
|
||||
out block {
|
||||
ControlVertex v;
|
||||
} outpt;
|
||||
|
||||
void main() {
|
||||
outpt.v.position = ModelViewMatrix * position;
|
||||
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(position);
|
||||
|
||||
#if OSD_NUM_VARYINGS > 0
|
||||
for (int i = 0; i < OSD_NUM_VARYINGS; ++i)
|
||||
outpt.v.varyings[i] = varyings[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessControlCorner
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_CONTROL_CORNER_SHADER
|
||||
|
||||
layout(vertices = 16) out;
|
||||
|
||||
in block {
|
||||
ControlVertex v;
|
||||
} inpt[];
|
||||
|
||||
out block {
|
||||
ControlVertex v;
|
||||
} outpt[];
|
||||
|
||||
#define ID gl_InvocationID
|
||||
|
||||
void main()
|
||||
{
|
||||
int i = ID/4;
|
||||
int j = ID%4;
|
||||
|
||||
vec3 H[3];
|
||||
for (int l=0; l<3; l++) {
|
||||
H[l] = vec3(0,0,0);
|
||||
for (int k=0; k<3; k++) {
|
||||
float c = B[i][2-k];
|
||||
H[l] += c*inpt[l*3 + k].v.position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 pos = vec3(0,0,0);
|
||||
for (int k=0; k<3; k++) {
|
||||
pos += B[j][k]*H[k];
|
||||
}
|
||||
|
||||
outpt[ID].v.position = vec4(pos, 1.0);
|
||||
|
||||
int patchLevel = GetPatchLevel();
|
||||
// +0.5 to avoid interpolation error of integer value
|
||||
outpt[ID].v.patchCoord = vec4(0, 0,
|
||||
patchLevel+0.5,
|
||||
gl_PrimitiveID+LevelBase+0.5);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER;
|
||||
|
||||
if (ID == 0) {
|
||||
OSD_PATCH_CULL(9);
|
||||
|
||||
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
gl_TessLevelOuter[0] =
|
||||
TessAdaptive(inpt[2].v.position.xyz, inpt[5].v.position.xyz, patchLevel);
|
||||
|
||||
gl_TessLevelOuter[1] =
|
||||
TessAdaptive(inpt[1].v.position.xyz, inpt[2].v.position.xyz, patchLevel);
|
||||
|
||||
gl_TessLevelOuter[2] =
|
||||
TessAdaptive(inpt[4].v.position.xyz, inpt[5].v.position.xyz, patchLevel);
|
||||
|
||||
gl_TessLevelOuter[3] =
|
||||
TessAdaptive(inpt[1].v.position.xyz, inpt[4].v.position.xyz, patchLevel);
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessEvalCorner
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_EVAL_CORNER_SHADER
|
||||
|
||||
layout(quads) in;
|
||||
layout(equal_spacing) in;
|
||||
|
||||
in block {
|
||||
ControlVertex v;
|
||||
} inpt[];
|
||||
|
||||
out block {
|
||||
OutputVertex v;
|
||||
} outpt;
|
||||
|
||||
void main()
|
||||
{
|
||||
float u = gl_TessCoord.x,
|
||||
v = gl_TessCoord.y;
|
||||
|
||||
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.0f, 0.0f, 0.0f);
|
||||
DUCP[i] = vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
vec3 WorldPos = vec3(0.0f, 0.0f, 0.0f);
|
||||
vec3 Tangent = vec3(0.0f, 0.0f, 0.0f);
|
||||
vec3 BiTangent = vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
Univar4x4(v, B, D);
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
Tangent += B[i] * DUCP[i];
|
||||
BiTangent += D[i] * BUCP[i];
|
||||
}
|
||||
|
||||
vec3 normal = normalize(cross(Tangent, BiTangent));
|
||||
|
||||
outpt.v.position = vec4(WorldPos, 1.0f);
|
||||
outpt.v.normal = normal;
|
||||
|
||||
BiTangent = -BiTangent; // BiTangent will be used in following macro
|
||||
outpt.v.tangent = BiTangent;
|
||||
|
||||
outpt.v.patchCoord = inpt[0].v.patchCoord;
|
||||
outpt.v.patchCoord.xy = vec2(1.0-v, u);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_TESSEVAL_SHADER;
|
||||
|
||||
OSD_COMPUTE_PTEX_COMPATIBLE_TANGENT(0);
|
||||
|
||||
OSD_DISPLACEMENT_CALLBACK;
|
||||
|
||||
gl_Position = (ProjectionMatrix * vec4(WorldPos, 1.0f));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
#ifdef VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
layout (location=1) in vec3 normal;
|
||||
layout (location=2) in vec4 color;
|
||||
|
||||
out block {
|
||||
OutputVertex v;
|
||||
} outpt;
|
||||
|
||||
void main() {
|
||||
gl_Position = ModelViewProjectionMatrix * position;
|
||||
outpt.v.color = color;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.FragmentColor
|
||||
//----------------------------------------------------------
|
||||
#ifdef FRAGMENT_SHADER
|
||||
|
||||
in block {
|
||||
OutputVertex v;
|
||||
} inpt;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = inpt.v.color;
|
||||
}
|
||||
#endif
|
@ -58,7 +58,7 @@
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessVertexGregory
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_VERTEX_GREGORY_SHADER
|
||||
#ifdef OSD_PATCH_VERTEX_GREGORY_SHADER
|
||||
|
||||
uniform samplerBuffer g_VertexBuffer;
|
||||
uniform isamplerBuffer g_ValenceBuffer;
|
||||
@ -153,7 +153,7 @@ void main()
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessControlGregory
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_CONTROL_GREGORY_SHADER
|
||||
#ifdef OSD_PATCH_TESS_CONTROL_GREGORY_SHADER
|
||||
|
||||
layout(vertices = 4) out;
|
||||
|
||||
@ -235,8 +235,8 @@ void main()
|
||||
|
||||
int patchLevel = GetPatchLevel();
|
||||
outpt[ID].v.patchCoord = vec4(0, 0,
|
||||
patchLevel+0.5,
|
||||
gl_PrimitiveID+LevelBase+0.5);
|
||||
patchLevel+0.5f,
|
||||
gl_PrimitiveID+LevelBase+0.5f);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER;
|
||||
|
||||
@ -245,13 +245,13 @@ void main()
|
||||
|
||||
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
gl_TessLevelOuter[0] =
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[1].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[1].v.hullPosition.xyz);
|
||||
gl_TessLevelOuter[1] =
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[0].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz);
|
||||
gl_TessLevelOuter[2] =
|
||||
TessAdaptive(inpt[2].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[2].v.hullPosition.xyz, inpt[3].v.hullPosition.xyz);
|
||||
gl_TessLevelOuter[3] =
|
||||
TessAdaptive(inpt[1].v.hullPosition.xyz, inpt[2].v.hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(inpt[1].v.hullPosition.xyz, inpt[2].v.hullPosition.xyz);
|
||||
gl_TessLevelInner[0] =
|
||||
max(gl_TessLevelOuter[1], gl_TessLevelOuter[3]);
|
||||
gl_TessLevelInner[1] =
|
||||
@ -271,7 +271,7 @@ void main()
|
||||
//----------------------------------------------------------
|
||||
// Patches.TessEvalGregory
|
||||
//----------------------------------------------------------
|
||||
#ifdef PATCH_TESS_EVAL_GREGORY_SHADER
|
||||
#ifdef OSD_PATCH_TESS_EVAL_GREGORY_SHADER
|
||||
|
||||
layout(quads) in;
|
||||
layout(cw) in;
|
||||
@ -377,9 +377,9 @@ void main()
|
||||
|
||||
vec3 normal = normalize(cross(BiTangent, Tangent));
|
||||
|
||||
outpt.v.position = ModelViewMatrix * vec4(WorldPos, 1.0);
|
||||
outpt.v.position = ModelViewMatrix * vec4(WorldPos, 1.0f);
|
||||
outpt.v.normal = normal;
|
||||
outpt.v.tangent = BiTangent;
|
||||
outpt.v.tangent = normalize(BiTangent);
|
||||
|
||||
outpt.v.patchCoord = inpt[0].v.patchCoord;
|
||||
outpt.v.patchCoord.xy = vec2(v, u);
|
||||
@ -396,7 +396,7 @@ void main()
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
#ifdef VERTEX_SHADER
|
||||
#ifdef OSD_VERTEX_SHADER
|
||||
|
||||
layout (location=0) in vec4 position;
|
||||
layout (location=1) in vec3 normal;
|
||||
@ -416,7 +416,7 @@ void main() {
|
||||
//----------------------------------------------------------
|
||||
// Patches.FragmentColor
|
||||
//----------------------------------------------------------
|
||||
#ifdef FRAGMENT_SHADER
|
||||
#ifdef OSD_FRAGMENT_SHADER
|
||||
|
||||
in block {
|
||||
OutputVertex v;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -55,32 +55,11 @@
|
||||
// a particular purpose and non-infringement.
|
||||
//
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Coefficients
|
||||
//----------------------------------------------------------
|
||||
|
||||
static float4x4 Q = {
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.f,
|
||||
0.f, 2.f/3.f, 1.f/3.f, 0.f,
|
||||
0.f, 1.f/3.f, 2.f/3.f, 0.f,
|
||||
0.f, 1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
};
|
||||
|
||||
// Boundary
|
||||
static float4x3 B = {
|
||||
1.0f, 0.0f, 0.0f,
|
||||
2.f/3.f, 1.f/3.f, 0.0f,
|
||||
1.f/3.f, 2.f/3.f, 0.0f,
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
};
|
||||
|
||||
// Corner
|
||||
static float4x4 R = {
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.0f,
|
||||
0.0f, 2.f/3.f, 1.f/3.f, 0.0f,
|
||||
0.0f, 1.f/3.f, 2.f/3.f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
#ifdef OSD_TRANSITION_TRIANGLE_SUBPATCH
|
||||
#define HS_DOMAIN "tri"
|
||||
#else
|
||||
#define HS_DOMAIN "quad"
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
@ -99,57 +78,94 @@ void vs_main_patches( in InputVertex input,
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.HullRegular
|
||||
// Patches.HullBSpline
|
||||
//----------------------------------------------------------
|
||||
|
||||
HS_CONSTANT_FUNC_OUT HSConstFunc(
|
||||
InputPatch<HullVertex, 12> patch,
|
||||
// Regular
|
||||
static float4x4 Q = {
|
||||
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
|
||||
};
|
||||
|
||||
// Boundary / Corner
|
||||
static float4x3 B = {
|
||||
1.f, 0.f, 0.f,
|
||||
4.f/6.f, 2.f/6.f, 0.f,
|
||||
2.f/6.f, 4.f/6.f, 0.f,
|
||||
1.f/6.f, 4.f/6.f, 1.f/6.f
|
||||
};
|
||||
|
||||
#ifdef OSD_PATCH_TRANSITION
|
||||
HS_CONSTANT_TRANSITION_FUNC_OUT
|
||||
#else
|
||||
HS_CONSTANT_FUNC_OUT
|
||||
#endif
|
||||
HSConstFunc(
|
||||
InputPatch<HullVertex, OSD_PATCH_INPUT_SIZE> patch,
|
||||
uint primitiveID : SV_PrimitiveID)
|
||||
{
|
||||
#ifdef OSD_PATCH_TRANSITION
|
||||
HS_CONSTANT_TRANSITION_FUNC_OUT output;
|
||||
#else
|
||||
HS_CONSTANT_FUNC_OUT output;
|
||||
#endif
|
||||
int patchLevel = GetPatchLevel(primitiveID);
|
||||
|
||||
OSD_PATCH_CULL(12);
|
||||
|
||||
#if OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
output.tessLevelOuter[0] =
|
||||
TessAdaptive(patch[1].position.xyz, patch[2].position.xyz, patchLevel);
|
||||
output.tessLevelOuter[1] =
|
||||
TessAdaptive(patch[2].position.xyz, patch[6].position.xyz, patchLevel);
|
||||
output.tessLevelOuter[2] =
|
||||
TessAdaptive(patch[5].position.xyz, patch[6].position.xyz, patchLevel);
|
||||
output.tessLevelOuter[3] =
|
||||
TessAdaptive(patch[1].position.xyz, patch[5].position.xyz, patchLevel);
|
||||
output.tessLevelInner[0] =
|
||||
max(output.tessLevelOuter[1], output.tessLevelOuter[3]);
|
||||
output.tessLevelInner[1] =
|
||||
max(output.tessLevelOuter[0], output.tessLevelOuter[2]);
|
||||
#ifdef OSD_TRANSITION_TRIANGLE_SUBPATCH
|
||||
OSD_PATCH_CULL_TRIANGLE(OSD_PATCH_INPUT_SIZE);
|
||||
#else
|
||||
output.tessLevelInner[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelInner[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[2] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[3] = GetTessLevel(patchLevel);
|
||||
OSD_PATCH_CULL(OSD_PATCH_INPUT_SIZE);
|
||||
#endif
|
||||
|
||||
#ifdef OSD_PATCH_TRANSITION
|
||||
float3 cp[OSD_PATCH_INPUT_SIZE];
|
||||
for(int k = 0; k < OSD_PATCH_INPUT_SIZE; ++k) cp[k] = patch[k].position.xyz;
|
||||
SetTransitionTessLevels(output, cp, patchLevel);
|
||||
#else
|
||||
#if defined OSD_PATCH_BOUNDARY
|
||||
const int p[4] = { 1, 2, 5, 6 };
|
||||
#elif defined OSD_PATCH_CORNER
|
||||
const int p[4] = { 1, 2, 4, 5 };
|
||||
#else
|
||||
const int p[4] = { 5, 6, 9, 10 };
|
||||
#endif
|
||||
|
||||
#ifdef OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
output.tessLevelOuter[0] = TessAdaptive(patch[p[0]].position.xyz, patch[p[2]].position.xyz);
|
||||
output.tessLevelOuter[1] = TessAdaptive(patch[p[0]].position.xyz, patch[p[1]].position.xyz);
|
||||
output.tessLevelOuter[2] = TessAdaptive(patch[p[1]].position.xyz, patch[p[3]].position.xyz);
|
||||
output.tessLevelOuter[3] = TessAdaptive(patch[p[2]].position.xyz, patch[p[3]].position.xyz);
|
||||
output.tessLevelInner[0] = max(output.tessLevelOuter[1], output.tessLevelOuter[3]);
|
||||
output.tessLevelInner[1] = max(output.tessLevelOuter[0], output.tessLevelOuter[2]);
|
||||
#else
|
||||
output.tessLevelInner[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelInner[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[2] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[3] = GetTessLevel(patchLevel);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
[domain("quad")]
|
||||
[domain(HS_DOMAIN)]
|
||||
[partitioning("integer")]
|
||||
[outputtopology("triangle_cw")]
|
||||
[outputcontrolpoints(16)]
|
||||
[patchconstantfunc("HSConstFunc")]
|
||||
HullVertex hs_main_patches(
|
||||
in InputPatch<HullVertex, 12> patch,
|
||||
in InputPatch<HullVertex, OSD_PATCH_INPUT_SIZE> patch,
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
in uint ID : SV_OutputControlPointID )
|
||||
{
|
||||
int i = ID/4;
|
||||
int j = ID%4;
|
||||
|
||||
i = 3 - i;
|
||||
int i = ID%4;
|
||||
int j = ID/4;
|
||||
|
||||
#if defined OSD_PATCH_BOUNDARY
|
||||
float3 H[3];
|
||||
for (int l=0; l<3; ++l) {
|
||||
H[l] = float3(0,0,0);
|
||||
@ -159,14 +175,45 @@ HullVertex hs_main_patches(
|
||||
}
|
||||
|
||||
float3 pos = float3(0,0,0);
|
||||
for (int k=0; k<3; ++k){
|
||||
pos += B[j][k] * H[k];
|
||||
for (int k=0; k<3; ++k) {
|
||||
pos += B[j][k]*H[k];
|
||||
}
|
||||
|
||||
#elif defined OSD_PATCH_CORNER
|
||||
float3 H[3];
|
||||
for (int l=0; l<3; ++l) {
|
||||
H[l] = float3(0,0,0);
|
||||
for (int k=0; k<3; ++k) {
|
||||
H[l] += B[3-i][2-k] * patch[l*3 + k].position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
float3 pos = float3(0,0,0);
|
||||
for (int k=0; k<3; ++k) {
|
||||
pos += B[j][k]*H[k];
|
||||
}
|
||||
|
||||
#else
|
||||
float3 H[4];
|
||||
for (int l=0; l<4; ++l) {
|
||||
H[l] = float3(0,0,0);
|
||||
for(int k=0; k<4; ++k) {
|
||||
H[l] += Q[i][k] * patch[l*4 + k].position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
float3 pos = float3(0,0,0);
|
||||
for (int k=0; k<4; ++k){
|
||||
pos += Q[j][k]*H[k];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
HullVertex output;
|
||||
output.position = float4(pos, 1.0);
|
||||
|
||||
int patchLevel = GetPatchLevel(primitiveID);
|
||||
|
||||
// +0.5 to avoid interpolation error of integer value
|
||||
output.patchCoord = float4(0, 0,
|
||||
patchLevel+0.5,
|
||||
@ -178,7 +225,7 @@ HullVertex hs_main_patches(
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.DomainRegular
|
||||
// Patches.DomainBSpline
|
||||
//----------------------------------------------------------
|
||||
|
||||
// B-spline basis evaluation via deBoor pyramid...
|
||||
@ -224,19 +271,30 @@ Univar4x4(in float u, out float B[4], out float D[4])
|
||||
D[3] = A2;
|
||||
}
|
||||
|
||||
[domain("quad")]
|
||||
[domain(HS_DOMAIN)]
|
||||
void ds_main_patches(
|
||||
#ifdef OSD_PATCH_TRANSITION
|
||||
in HS_CONSTANT_TRANSITION_FUNC_OUT input,
|
||||
#else
|
||||
in HS_CONSTANT_FUNC_OUT input,
|
||||
#endif
|
||||
in OutputPatch<HullVertex, 16> patch,
|
||||
in float2 uv : SV_DomainLocation,
|
||||
#ifdef OSD_TRANSITION_TRIANGLE_SUBPATCH
|
||||
in float3 domainCoord : SV_DomainLocation,
|
||||
#else
|
||||
in float2 domainCoord : SV_DomainLocation,
|
||||
#endif
|
||||
out OutputVertex output )
|
||||
{
|
||||
float u = uv.x,
|
||||
v = uv.y;
|
||||
#ifdef OSD_PATCH_TRANSITION
|
||||
float2 UV = GetTransitionSubpatchUV(domainCoord);
|
||||
#else
|
||||
float2 UV = domainCoord;
|
||||
#endif
|
||||
|
||||
float B[4], D[4];
|
||||
|
||||
Univar4x4(u, B, D);
|
||||
Univar4x4(UV.x, B, D);
|
||||
|
||||
float3 BUCP[4], DUCP[4];
|
||||
|
||||
@ -245,8 +303,15 @@ void ds_main_patches(
|
||||
DUCP[i] = float3(0,0,0);
|
||||
|
||||
for (int j=0; j<4; ++j) {
|
||||
#if OSD_TRANSITION_ROTATE == 1
|
||||
float3 A = patch[4*(3-j) + i].position.xyz;
|
||||
#elif OSD_TRANSITION_ROTATE == 2
|
||||
float3 A = patch[4*(3-i) + (3-j)].position.xyz;
|
||||
#elif OSD_TRANSITION_ROTATE == 3
|
||||
float3 A = patch[4*j + (3-i)].position.xyz;
|
||||
#else // OSD_TRANNSITION_ROTATE == 0, or non-transition patch
|
||||
float3 A = patch[4*i + j].position.xyz;
|
||||
|
||||
#endif
|
||||
BUCP[i] += A * B[j];
|
||||
DUCP[i] += A * D[j];
|
||||
}
|
||||
@ -256,27 +321,34 @@ void ds_main_patches(
|
||||
float3 Tangent = float3(0,0,0);
|
||||
float3 BiTangent = float3(0,0,0);
|
||||
|
||||
Univar4x4(v, B, D);
|
||||
Univar4x4(UV.y, B, D);
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
Tangent += B[i] * DUCP[i];
|
||||
BiTangent += D[i] * BUCP[i];
|
||||
for (int k=0; k<4; ++k) {
|
||||
WorldPos += B[k] * BUCP[k];
|
||||
Tangent += B[k] * DUCP[k];
|
||||
BiTangent += D[k] * BUCP[k];
|
||||
}
|
||||
|
||||
float3 normal = -normalize(cross(BiTangent, Tangent));
|
||||
float3 normal = normalize(cross(Tangent, BiTangent));
|
||||
|
||||
output.position = float4(WorldPos, 1.0f);
|
||||
output.normal = normal;
|
||||
output.tangent = -normalize(BiTangent);
|
||||
output.tangent = normalize(Tangent);
|
||||
|
||||
output.patchCoord = patch[0].patchCoord;
|
||||
output.patchCoord.xy = float2(1.0-v, u);
|
||||
|
||||
#if OSD_TRANSITION_ROTATE == 1
|
||||
output.patchCoord.xy = float2(UV.y, 1.0-UV.x);
|
||||
#elif OSD_TRANSITION_ROTATE == 2
|
||||
output.patchCoord.xy = float2(1.0-UV.x, 1.0-UV.y);
|
||||
#elif OSD_TRANSITION_ROTATE == 3
|
||||
output.patchCoord.xy = float2(1.0-UV.y, UV.x);
|
||||
#else // OSD_TRANNSITION_ROTATE == 0, or non-transition patch
|
||||
output.patchCoord.xy = float2(UV.x, UV.y);
|
||||
#endif
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_DOMAIN_SHADER;
|
||||
|
||||
OSD_COMPUTE_PTEX_COMPATIBLE_TANGENT(0);
|
||||
|
||||
OSD_DISPLACEMENT_CALLBACK;
|
||||
|
||||
output.positionOut = mul(ProjectionMatrix, float4(WorldPos, 1.0f));
|
@ -293,13 +293,13 @@ HS_CONSTANT_FUNC_OUT HSConstFunc(
|
||||
|
||||
#if OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
output.tessLevelOuter[0] =
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[1].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[1].hullPosition.xyz);
|
||||
output.tessLevelOuter[1] =
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[3].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[3].hullPosition.xyz);
|
||||
output.tessLevelOuter[2] =
|
||||
TessAdaptive(patch[2].hullPosition.xyz, patch[3].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[2].hullPosition.xyz, patch[3].hullPosition.xyz);
|
||||
output.tessLevelOuter[3] =
|
||||
TessAdaptive(patch[1].hullPosition.xyz, patch[2].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[1].hullPosition.xyz, patch[2].hullPosition.xyz);
|
||||
output.tessLevelInner[0] =
|
||||
max(output.tessLevelOuter[1], output.tessLevelOuter[3]);
|
||||
output.tessLevelInner[1] =
|
||||
@ -582,9 +582,10 @@ void ds_main_patches(
|
||||
|
||||
output.position = mul(ModelViewMatrix, float4(WorldPos, 1.0f));
|
||||
output.normal = normal;
|
||||
output.tangent = normalize(BiTangent);
|
||||
|
||||
output.patchCoord = patch[0].patchCoord;
|
||||
output.patchCoord.xy = float2(v, u);
|
||||
output.tangent = BiTangent;
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_DOMAIN_SHADER;
|
||||
|
||||
|
@ -56,13 +56,25 @@
|
||||
//
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Prologue
|
||||
// Patches.Common
|
||||
//----------------------------------------------------------
|
||||
|
||||
#ifndef OSD_NUM_VARYINGS
|
||||
#define OSD_NUM_VARYINGS 0
|
||||
#endif
|
||||
|
||||
#ifndef OSD_TRANSITION_ROTATE
|
||||
#define OSD_TRANSITION_ROTATE 0
|
||||
#endif
|
||||
|
||||
#if defined OSD_PATCH_BOUNDARY
|
||||
#define OSD_PATCH_INPUT_SIZE 12
|
||||
#elif defined OSD_PATCH_CORNER
|
||||
#define OSD_PATCH_INPUT_SIZE 9
|
||||
#else
|
||||
#define OSD_PATCH_INPUT_SIZE 16
|
||||
#endif
|
||||
|
||||
#define M_PI 3.14159265359f
|
||||
|
||||
struct InputVertex {
|
||||
@ -136,7 +148,8 @@ cbuffer Tessellation : register( b1 ) {
|
||||
int LevelBase;
|
||||
};
|
||||
|
||||
float GetTessLevel(int patchLevel) {
|
||||
float GetTessLevel(int patchLevel)
|
||||
{
|
||||
#if OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
return TessLevel;
|
||||
#else
|
||||
@ -150,7 +163,7 @@ float GetPostProjectionSphereExtent(float3 center, float diameter)
|
||||
return abs(diameter * ProjectionMatrix[1][1] / p.w);
|
||||
}
|
||||
|
||||
float TessAdaptive(float3 p0, float3 p1, int patchLevel)
|
||||
float TessAdaptive(float3 p0, float3 p1)
|
||||
{
|
||||
// Adaptive factor can be any computation that depends only on arg values.
|
||||
// Project the diameter of the edge's bounding sphere instead of using the
|
||||
@ -166,17 +179,14 @@ float TessAdaptive(float3 p0, float3 p1, int patchLevel)
|
||||
|
||||
Buffer<int2> g_ptexIndicesBuffer : register( t3 );
|
||||
|
||||
int GetPatchLevel(int primitiveID)
|
||||
{
|
||||
int2 ptexIndex = g_ptexIndicesBuffer[primitiveID + LevelBase].xy;
|
||||
return ptexIndex.y & 0xf;
|
||||
}
|
||||
#define GetPatchLevel(primitiveID) \
|
||||
(g_ptexIndicesBuffer[primitiveID + LevelBase].y & 0xf)
|
||||
|
||||
#define OSD_COMPUTE_PTEX_COORD_TESSCONTROL_SHADER \
|
||||
#define OSD_COMPUTE_PTEX_COORD_HULL_SHADER \
|
||||
{ \
|
||||
int2 ptexIndex = g_ptexIndicesBuffer[ID + LevelBase].xy; \
|
||||
int faceID = ptexIndex.x; \
|
||||
int lv = 1 << (ptexIndex.y & 0xf); \
|
||||
int lv = 1 << ((ptexIndex.y & 0xf) - ((ptexIndex.y >> 4) & 1)); \
|
||||
int u = (ptexIndex.y >> 17) & 0x3ff; \
|
||||
int v = (ptexIndex.y >> 7) & 0x3ff; \
|
||||
int rotation = (ptexIndex.y >> 5) & 0x3; \
|
||||
@ -184,8 +194,6 @@ int GetPatchLevel(int primitiveID)
|
||||
output.ptexInfo = int4(u, v, lv, rotation); \
|
||||
}
|
||||
|
||||
#define OSD_COMPUTE_PTEX_COORD_HULL_SHADER
|
||||
|
||||
#define OSD_COMPUTE_PTEX_COORD_DOMAIN_SHADER \
|
||||
{ \
|
||||
float2 uv = output.patchCoord.xy; \
|
||||
@ -203,13 +211,13 @@ int GetPatchLevel(int primitiveID)
|
||||
{ \
|
||||
int rot = (patch[0].ptexInfo.w + 4 - ROTATE)%4; \
|
||||
if (rot == 1) { \
|
||||
output.tangent = -normalize(Tangent); \
|
||||
} else if (rot == 2) { \
|
||||
output.tangent = -normalize(BiTangent); \
|
||||
} else if (rot == 2) { \
|
||||
output.tangent = -normalize(Tangent); \
|
||||
} else if (rot == 3) { \
|
||||
output.tangent = normalize(Tangent); \
|
||||
} else { \
|
||||
output.tangent = normalize(BiTangent); \
|
||||
} else { \
|
||||
output.tangent = normalize(Tangent); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -1,309 +0,0 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Coefficients
|
||||
//----------------------------------------------------------
|
||||
|
||||
static float4x4 Q = {
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.f,
|
||||
0.f, 2.f/3.f, 1.f/3.f, 0.f,
|
||||
0.f, 1.f/3.f, 2.f/3.f, 0.f,
|
||||
0.f, 1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
};
|
||||
|
||||
// Boundary
|
||||
static float4x3 B = {
|
||||
1.0f, 0.0f, 0.0f,
|
||||
2.f/3.f, 1.f/3.f, 0.0f,
|
||||
1.f/3.f, 2.f/3.f, 0.0f,
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
};
|
||||
|
||||
// Corner
|
||||
static float4x4 R = {
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.0f,
|
||||
0.0f, 2.f/3.f, 1.f/3.f, 0.0f,
|
||||
0.0f, 1.f/3.f, 2.f/3.f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
|
||||
void vs_main_patches( in InputVertex input,
|
||||
out HullVertex output )
|
||||
{
|
||||
output.position = mul(ModelViewMatrix, input.position);
|
||||
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(input.position);
|
||||
|
||||
#if OSD_NUM_VARYINGS > 0
|
||||
for (int i = 0; i< OSD_NUM_VARYINGS; ++i)
|
||||
output.varyings[i] = input.varyings[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.HullRegular
|
||||
//----------------------------------------------------------
|
||||
|
||||
HS_CONSTANT_FUNC_OUT HSConstFunc(
|
||||
InputPatch<HullVertex, 9> patch,
|
||||
uint primitiveID : SV_PrimitiveID)
|
||||
{
|
||||
HS_CONSTANT_FUNC_OUT output;
|
||||
int patchLevel = GetPatchLevel(primitiveID);
|
||||
|
||||
OSD_PATCH_CULL(9);
|
||||
|
||||
#if OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
output.tessLevelOuter[0] =
|
||||
TessAdaptive(patch[2].position.xyz, patch[5].position.xyz, patchLevel);
|
||||
|
||||
output.tessLevelOuter[1] =
|
||||
TessAdaptive(patch[1].position.xyz, patch[2].position.xyz, patchLevel);
|
||||
|
||||
output.tessLevelOuter[2] =
|
||||
TessAdaptive(patch[4].position.xyz, patch[5].position.xyz, patchLevel);
|
||||
|
||||
output.tessLevelOuter[3] =
|
||||
TessAdaptive(patch[1].position.xyz, patch[4].position.xyz, patchLevel);
|
||||
|
||||
output.tessLevelInner[0] =
|
||||
max(output.tessLevelOuter[1], output.tessLevelOuter[3]);
|
||||
output.tessLevelInner[1] =
|
||||
max(output.tessLevelOuter[0], output.tessLevelOuter[2]);
|
||||
#else
|
||||
output.tessLevelInner[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelInner[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[2] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[3] = GetTessLevel(patchLevel);
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
|
||||
[domain("quad")]
|
||||
[partitioning("integer")]
|
||||
[outputtopology("triangle_cw")]
|
||||
[outputcontrolpoints(16)]
|
||||
[patchconstantfunc("HSConstFunc")]
|
||||
HullVertex hs_main_patches(
|
||||
in InputPatch<HullVertex, 9> patch,
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
in uint ID : SV_OutputControlPointID )
|
||||
{
|
||||
int i = ID/4;
|
||||
int j = ID%4;
|
||||
|
||||
float3 H[3];
|
||||
for (int l=0; l<3; ++l) {
|
||||
H[l] = float3(0,0,0);
|
||||
for (int k=0; k<3; ++k) {
|
||||
H[l] += B[i][2-k] * patch[l*3 + k].position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
float3 pos = float3(0,0,0);
|
||||
for (int k=0; k<3; ++k){
|
||||
pos += B[j][k] * H[k];
|
||||
}
|
||||
|
||||
HullVertex output;
|
||||
output.position = float4(pos, 1.0);
|
||||
|
||||
int patchLevel = GetPatchLevel(primitiveID);
|
||||
// +0.5 to avoid interpolation error of integer value
|
||||
output.patchCoord = float4(0, 0,
|
||||
patchLevel+0.5,
|
||||
primitiveID+LevelBase+0.5);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_HULL_SHADER;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.DomainRegular
|
||||
//----------------------------------------------------------
|
||||
|
||||
// B-spline basis evaluation via deBoor pyramid...
|
||||
void
|
||||
EvalCubicBSpline(in float u, out float B[4], out float BU[4])
|
||||
{
|
||||
float t = u;
|
||||
float s = 1.0 - u;
|
||||
|
||||
float C0 = s * (0.5 * s);
|
||||
float C1 = t * (s + 0.5 * t) + s * (0.5 * s + t);
|
||||
float C2 = t * ( 0.5 * t);
|
||||
|
||||
B[0] = 1.f/3.f * s * C0;
|
||||
B[1] = (2.f/3.f * s + t) * C0 + (2.f/3.f * s + 1.f/3.f * t) * C1;
|
||||
B[2] = (1.f/3.f * s + 2.f/3.f * t) * C1 + ( s + 2.f/3.f * t) * C2;
|
||||
B[3] = 1.f/3.f * t * C2;
|
||||
|
||||
BU[0] = - C0;
|
||||
BU[1] = C0 - C1;
|
||||
BU[2] = C1 - C2;
|
||||
BU[3] = C2;
|
||||
}
|
||||
|
||||
void
|
||||
Univar4x4(in float u, out float B[4], out float D[4])
|
||||
{
|
||||
float t = u;
|
||||
float s = 1.0 - u;
|
||||
|
||||
float A0 = s * s;
|
||||
float A1 = 2 * s * t;
|
||||
float A2 = t * t;
|
||||
|
||||
B[0] = s * A0;
|
||||
B[1] = t * A0 + s * A1;
|
||||
B[2] = t * A1 + s * A2;
|
||||
B[3] = t * A2;
|
||||
|
||||
D[0] = - A0;
|
||||
D[1] = A0 - A1;
|
||||
D[2] = A1 - A2;
|
||||
D[3] = A2;
|
||||
}
|
||||
|
||||
[domain("quad")]
|
||||
void ds_main_patches(
|
||||
in HS_CONSTANT_FUNC_OUT input,
|
||||
in OutputPatch<HullVertex, 16> patch,
|
||||
in float2 uv : SV_DomainLocation,
|
||||
out OutputVertex output )
|
||||
{
|
||||
float u = uv.x,
|
||||
v = uv.y;
|
||||
|
||||
float B[4], D[4];
|
||||
|
||||
Univar4x4(u, B, D);
|
||||
|
||||
float3 BUCP[4], DUCP[4];
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
BUCP[i] = float3(0,0,0);
|
||||
DUCP[i] = float3(0,0,0);
|
||||
|
||||
for (int j=0; j<4; ++j) {
|
||||
float3 A = patch[4*i + j].position.xyz;
|
||||
|
||||
BUCP[i] += A * B[j];
|
||||
DUCP[i] += A * D[j];
|
||||
}
|
||||
}
|
||||
|
||||
float3 WorldPos = float3(0,0,0);
|
||||
float3 Tangent = float3(0,0,0);
|
||||
float3 BiTangent = float3(0,0,0);
|
||||
|
||||
Univar4x4(v, B, D);
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
Tangent += B[i] * DUCP[i];
|
||||
BiTangent += D[i] * BUCP[i];
|
||||
}
|
||||
|
||||
float3 normal = -normalize(cross(BiTangent, Tangent));
|
||||
|
||||
output.position = float4(WorldPos, 1.0f);
|
||||
output.normal = normal;
|
||||
output.tangent = -normalize(BiTangent);
|
||||
|
||||
output.patchCoord = patch[0].patchCoord;
|
||||
output.patchCoord.xy = float2(u, v);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_DOMAIN_SHADER;
|
||||
|
||||
OSD_COMPUTE_PTEX_COMPATIBLE_TANGENT(0);
|
||||
|
||||
OSD_DISPLACEMENT_CALLBACK;
|
||||
|
||||
output.positionOut = mul(ProjectionMatrix, float4(WorldPos, 1.0f));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
|
||||
void vs_main( in InputVertex input,
|
||||
out OutputVertex output)
|
||||
{
|
||||
output.positionOut = mul(ModelViewProjectionMatrix, input.position);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.PixelColor
|
||||
//----------------------------------------------------------
|
||||
|
||||
cbuffer Data : register( b2 ) {
|
||||
float4 color;
|
||||
};
|
||||
|
||||
void ps_main( in OutputVertex input,
|
||||
out float4 colorOut : SV_Target )
|
||||
{
|
||||
colorOut = color;
|
||||
}
|
@ -189,13 +189,13 @@ HS_CONSTANT_FUNC_OUT HSConstFunc(
|
||||
|
||||
#if OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
output.tessLevelOuter[0] =
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[1].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[1].hullPosition.xyz);
|
||||
output.tessLevelOuter[1] =
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[3].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[0].hullPosition.xyz, patch[3].hullPosition.xyz);
|
||||
output.tessLevelOuter[2] =
|
||||
TessAdaptive(patch[2].hullPosition.xyz, patch[3].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[2].hullPosition.xyz, patch[3].hullPosition.xyz);
|
||||
output.tessLevelOuter[3] =
|
||||
TessAdaptive(patch[1].hullPosition.xyz, patch[2].hullPosition.xyz, patchLevel);
|
||||
TessAdaptive(patch[1].hullPosition.xyz, patch[2].hullPosition.xyz);
|
||||
output.tessLevelInner[0] =
|
||||
max(output.tessLevelOuter[1], output.tessLevelOuter[3]);
|
||||
output.tessLevelInner[1] =
|
||||
@ -286,8 +286,8 @@ GregDomainVertex hs_main_patches(
|
||||
|
||||
int patchLevel = GetPatchLevel(primitiveID);
|
||||
output.patchCoord = float4(0, 0,
|
||||
patchLevel+0.5,
|
||||
primitiveID+LevelBase+0.5);
|
||||
patchLevel+0.5f,
|
||||
primitiveID+LevelBase+0.5f);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_HULL_SHADER;
|
||||
|
||||
@ -298,10 +298,10 @@ GregDomainVertex hs_main_patches(
|
||||
// Patches.DomainGregory
|
||||
//----------------------------------------------------------
|
||||
|
||||
void Univar4(in float u, out float B[4], out float D[4])
|
||||
void Univar4x4(in float u, out float B[4], out float D[4])
|
||||
{
|
||||
float t = u;
|
||||
float s = 1.0 - u;
|
||||
float s = 1.0f - u;
|
||||
|
||||
float A0 = s * s;
|
||||
float A1 = 2 * s * t;
|
||||
@ -383,7 +383,7 @@ void ds_main_patches(
|
||||
|
||||
float B[4], D[4];
|
||||
|
||||
Univar4(uv.x, B, D);
|
||||
Univar4x4(uv.x, B, D);
|
||||
float3 BUCP[4], DUCP[4];
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
@ -403,7 +403,7 @@ void ds_main_patches(
|
||||
float3 Tangent = float3(0, 0, 0);
|
||||
float3 BiTangent = float3(0, 0, 0);
|
||||
|
||||
Univar4(uv.y, B, D);
|
||||
Univar4x4(uv.y, B, D);
|
||||
|
||||
for (uint i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
@ -416,7 +416,7 @@ void ds_main_patches(
|
||||
|
||||
float3 normal = normalize(cross(BiTangent, Tangent));
|
||||
|
||||
output.position = mul(ModelViewMatrix, float4(WorldPos, 1.0));
|
||||
output.position = mul(ModelViewMatrix, float4(WorldPos, 1.0f));
|
||||
output.normal = normal;
|
||||
output.tangent = normalize(BiTangent);
|
||||
|
||||
|
@ -1,304 +0,0 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Coefficients
|
||||
//----------------------------------------------------------
|
||||
|
||||
static float4x4 Q = {
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.f,
|
||||
0.f, 2.f/3.f, 1.f/3.f, 0.f,
|
||||
0.f, 1.f/3.f, 2.f/3.f, 0.f,
|
||||
0.f, 1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
};
|
||||
|
||||
// Boundary
|
||||
static float4x3 B = {
|
||||
1.0f, 0.0f, 0.0f,
|
||||
2.f/3.f, 1.f/3.f, 0.0f,
|
||||
1.f/3.f, 2.f/3.f, 0.0f,
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f
|
||||
};
|
||||
|
||||
// Corner
|
||||
static float4x4 R = {
|
||||
1.f/6.f, 2.f/3.f, 1.f/6.f, 0.0f,
|
||||
0.0f, 2.f/3.f, 1.f/3.f, 0.0f,
|
||||
0.0f, 1.f/3.f, 2.f/3.f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
|
||||
void vs_main_patches( in InputVertex input,
|
||||
out HullVertex output )
|
||||
{
|
||||
output.position = mul(ModelViewMatrix, input.position);
|
||||
OSD_PATCH_CULL_COMPUTE_CLIPFLAGS(input.position);
|
||||
|
||||
#if OSD_NUM_VARYINGS > 0
|
||||
for (int i = 0; i< OSD_NUM_VARYINGS; ++i)
|
||||
output.varyings[i] = input.varyings[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.HullRegular
|
||||
//----------------------------------------------------------
|
||||
|
||||
HS_CONSTANT_FUNC_OUT HSConstFunc(
|
||||
InputPatch<HullVertex, 16> patch,
|
||||
uint primitiveID : SV_PrimitiveID)
|
||||
{
|
||||
HS_CONSTANT_FUNC_OUT output;
|
||||
int patchLevel = GetPatchLevel(primitiveID);
|
||||
|
||||
OSD_PATCH_CULL(16);
|
||||
|
||||
#if OSD_ENABLE_SCREENSPACE_TESSELLATION
|
||||
output.tessLevelOuter[0] =
|
||||
TessAdaptive(patch[5].position.xyz, patch[9].position.xyz, patchLevel);
|
||||
output.tessLevelOuter[1] =
|
||||
TessAdaptive(patch[5].position.xyz, patch[6].position.xyz, patchLevel);
|
||||
output.tessLevelOuter[2] =
|
||||
TessAdaptive(patch[6].position.xyz, patch[10].position.xyz, patchLevel);
|
||||
output.tessLevelOuter[3] =
|
||||
TessAdaptive(patch[9].position.xyz, patch[10].position.xyz, patchLevel);
|
||||
output.tessLevelInner[0] =
|
||||
max(output.tessLevelOuter[1], output.tessLevelOuter[3]);
|
||||
output.tessLevelInner[1] =
|
||||
max(output.tessLevelOuter[0], output.tessLevelOuter[2]);
|
||||
#else
|
||||
output.tessLevelInner[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelInner[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[0] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[1] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[2] = GetTessLevel(patchLevel);
|
||||
output.tessLevelOuter[3] = GetTessLevel(patchLevel);
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
|
||||
[domain("quad")]
|
||||
[partitioning("integer")]
|
||||
[outputtopology("triangle_cw")]
|
||||
[outputcontrolpoints(16)]
|
||||
[patchconstantfunc("HSConstFunc")]
|
||||
HullVertex hs_main_patches(
|
||||
in InputPatch<HullVertex, 16> patch,
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
in uint ID : SV_OutputControlPointID )
|
||||
{
|
||||
int i = ID/4;
|
||||
int j = ID%4;
|
||||
|
||||
float3 H[4];
|
||||
for (int l=0; l<4; ++l) {
|
||||
H[l] = float3(0,0,0);
|
||||
|
||||
for(int k=0; k<4; ++k) {
|
||||
H[l] += Q[i][k] * patch[l*4 + k].position.xyz;
|
||||
}
|
||||
}
|
||||
|
||||
float3 pos = float3(0,0,0);
|
||||
for (int k=0; k<4; ++k){
|
||||
pos += Q[j][k] * H[k];
|
||||
}
|
||||
|
||||
HullVertex output;
|
||||
output.position = float4(pos, 1.0);
|
||||
|
||||
int patchLevel = GetPatchLevel(primitiveID);
|
||||
// +0.5 to avoid interpolation error of integer value
|
||||
output.patchCoord = float4(0, 0,
|
||||
patchLevel+0.5,
|
||||
primitiveID+LevelBase+0.5);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_HULL_SHADER;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.DomainRegular
|
||||
//----------------------------------------------------------
|
||||
|
||||
// B-spline basis evaluation via deBoor pyramid...
|
||||
void
|
||||
EvalCubicBSpline(in float u, out float B[4], out float BU[4])
|
||||
{
|
||||
float t = u;
|
||||
float s = 1.0 - u;
|
||||
|
||||
float C0 = s * (0.5 * s);
|
||||
float C1 = t * (s + 0.5 * t) + s * (0.5 * s + t);
|
||||
float C2 = t * ( 0.5 * t);
|
||||
|
||||
B[0] = 1.f/3.f * s * C0;
|
||||
B[1] = (2.f/3.f * s + t) * C0 + (2.f/3.f * s + 1.f/3.f * t) * C1;
|
||||
B[2] = (1.f/3.f * s + 2.f/3.f * t) * C1 + ( s + 2.f/3.f * t) * C2;
|
||||
B[3] = 1.f/3.f * t * C2;
|
||||
|
||||
BU[0] = - C0;
|
||||
BU[1] = C0 - C1;
|
||||
BU[2] = C1 - C2;
|
||||
BU[3] = C2;
|
||||
}
|
||||
|
||||
void
|
||||
Univar4x4(in float u, out float B[4], out float D[4])
|
||||
{
|
||||
float t = u;
|
||||
float s = 1.0 - u;
|
||||
|
||||
float A0 = s * s;
|
||||
float A1 = 2 * s * t;
|
||||
float A2 = t * t;
|
||||
|
||||
B[0] = s * A0;
|
||||
B[1] = t * A0 + s * A1;
|
||||
B[2] = t * A1 + s * A2;
|
||||
B[3] = t * A2;
|
||||
|
||||
D[0] = - A0;
|
||||
D[1] = A0 - A1;
|
||||
D[2] = A1 - A2;
|
||||
D[3] = A2;
|
||||
}
|
||||
|
||||
[domain("quad")]
|
||||
void ds_main_patches(
|
||||
in HS_CONSTANT_FUNC_OUT input,
|
||||
in OutputPatch<HullVertex, 16> patch,
|
||||
in float2 uv : SV_DomainLocation,
|
||||
out OutputVertex output )
|
||||
{
|
||||
float u = uv.x,
|
||||
v = uv.y;
|
||||
|
||||
float B[4], D[4];
|
||||
|
||||
Univar4x4(u, B, D);
|
||||
|
||||
float3 BUCP[4], DUCP[4];
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
BUCP[i] = float3(0,0,0);
|
||||
DUCP[i] = float3(0,0,0);
|
||||
|
||||
for (int j=0; j<4; ++j) {
|
||||
float3 A = patch[i + j*4].position.xyz;
|
||||
|
||||
BUCP[i] += A * B[j];
|
||||
DUCP[i] += A * D[j];
|
||||
}
|
||||
}
|
||||
|
||||
float3 WorldPos = float3(0,0,0);
|
||||
float3 Tangent = float3(0,0,0);
|
||||
float3 BiTangent = float3(0,0,0);
|
||||
|
||||
Univar4x4(v, B, D);
|
||||
|
||||
for (int i=0; i<4; ++i) {
|
||||
WorldPos += B[i] * BUCP[i];
|
||||
Tangent += B[i] * DUCP[i];
|
||||
BiTangent += D[i] * BUCP[i];
|
||||
}
|
||||
|
||||
float3 normal = -normalize(cross(BiTangent, Tangent));
|
||||
|
||||
output.position = float4(WorldPos, 1.0f);
|
||||
output.normal = normal;
|
||||
output.tangent = Tangent;
|
||||
|
||||
output.patchCoord = patch[0].patchCoord;
|
||||
output.patchCoord.xy = float2(u, v);
|
||||
|
||||
OSD_COMPUTE_PTEX_COORD_DOMAIN_SHADER;
|
||||
|
||||
OSD_DISPLACEMENT_CALLBACK;
|
||||
|
||||
output.positionOut = mul(ProjectionMatrix, float4(WorldPos, 1.0f));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.Vertex
|
||||
//----------------------------------------------------------
|
||||
|
||||
void vs_main( in InputVertex input,
|
||||
out OutputVertex output)
|
||||
{
|
||||
output.positionOut = mul(ModelViewProjectionMatrix, input.position);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Patches.PixelColor
|
||||
//----------------------------------------------------------
|
||||
|
||||
cbuffer Data : register( b2 ) {
|
||||
float4 color;
|
||||
};
|
||||
|
||||
void ps_main( in OutputVertex input,
|
||||
out float4 colorOut : SV_Target )
|
||||
{
|
||||
colorOut = color;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user