add usd-21-11-win64_py39
This commit is contained in:
1 parent
41d23e71ba
commit
ba5e1f7e67
15684 files changed
+3069957
No files matched your search
@@ -0,0 +1,967 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/basisCurves.glslfx
|
||||
|
||||
#import $TOOLS/hdSt/shaders/instancing.glslfx
|
||||
#import $TOOLS/hdSt/shaders/terminals.glslfx
|
||||
#import $TOOLS/hdSt/shaders/pointId.glslfx
|
||||
#import $TOOLS/hdSt/shaders/visibility.glslfx
|
||||
|
||||
// Known issues:
|
||||
// * The direction of the 'v' post tessellation is inconsistent between
|
||||
// curve representations with regards to whether it increases from left to right
|
||||
// or right to left. If we start using materials that require 'v', we should fix
|
||||
// this to be both consistent and match the RenderMan default orientation.
|
||||
//
|
||||
// * RenderMan uses 'u' describe the parameter along curve profile and 'v' to
|
||||
// describe the curve length. It's opposite here. It would be good to align
|
||||
// these once we start to use 'u' and 'v' in curve materials.
|
||||
//
|
||||
// * We might want to explore using fractional_even_spacing to better preserve
|
||||
// the shape of cubic curves.
|
||||
//
|
||||
// * We've realized that u appears to be 'backwards' in many cases, and so we
|
||||
// have updated many of the functions to use
|
||||
// mix(endPointValue, startPointValue, u) when intuitively it should be
|
||||
// the other way around.
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Vertex.Patch
|
||||
|
||||
out CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
// We will either generate a camera facing normal or use the authored normal.
|
||||
vec3 getNormal(MAT4 transform);
|
||||
// Fwd declare methods defined in pointId.glslfx, that are used below.
|
||||
int GetPointId();
|
||||
float GetPointRasterSize(int);
|
||||
void ProcessPointId(int);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
MAT4 transform = ApplyInstanceTransform(HdGet_transform());
|
||||
MAT4 transformInv = ApplyInstanceTransformInverse(HdGet_transformInverse());
|
||||
|
||||
outData.Peye = vec4(GetWorldToViewMatrix() * transform *
|
||||
vec4(HdGet_points(), 1));
|
||||
outData.Neye = getNormal(transpose(transformInv *
|
||||
GetWorldToViewInverseMatrix()));
|
||||
|
||||
ProcessPrimvars();
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
int pointId = GetPointId();
|
||||
gl_PointSize = GetPointRasterSize(pointId);
|
||||
ProcessPointId(pointId);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Vertex.Normal.Implicit
|
||||
|
||||
vec3 getNormal(MAT4 transform)
|
||||
{
|
||||
// Generate a camera-facing normal in camera/eye space, designed to match
|
||||
// RenderMan.
|
||||
return vec3(0, 0, 1);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Vertex.Normal.Oriented
|
||||
|
||||
vec3 getNormal(MAT4 transform)
|
||||
{
|
||||
return (transform * vec4(HdGet_normals(), 0)).xyz;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Vertex.Wire
|
||||
|
||||
out CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} outData;
|
||||
|
||||
// Fwd declare methods defined in pointId.glslfx, that are used below.
|
||||
int GetPointId();
|
||||
float GetPointRasterSize(int);
|
||||
void ProcessPointId(int);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
MAT4 transform = ApplyInstanceTransform(HdGet_transform());
|
||||
|
||||
outData.Peye = vec4(GetWorldToViewMatrix() * transform *
|
||||
vec4(HdGet_points(), 1));
|
||||
|
||||
ProcessPrimvars();
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
int pointId = GetPointId();
|
||||
gl_PointSize = GetPointRasterSize(pointId);
|
||||
ProcessPointId(pointId);}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Shared
|
||||
|
||||
float GetMaxTess()
|
||||
{
|
||||
// Should be replaced with a uniform
|
||||
return 40;
|
||||
}
|
||||
|
||||
float GetPixelToTessRatio()
|
||||
{
|
||||
// Should be replaced with a uniform
|
||||
return 20.0;
|
||||
}
|
||||
|
||||
vec2 projectToScreen(MAT4 projMat, vec4 vertex, vec2 screen_size)
|
||||
{
|
||||
vec4 res = vec4(projMat * vertex);
|
||||
res /= res.w;
|
||||
return (clamp(res.xy, -1.3, 1.3) + 1) * (screen_size * 0.5);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Linear.Patch
|
||||
|
||||
layout(vertices = HD_NUM_PATCH_EVAL_VERTS) out;
|
||||
|
||||
in CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData[gl_MaxPatchVertices];
|
||||
|
||||
out CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData[HD_NUM_PATCH_EVAL_VERTS];
|
||||
|
||||
void determineLODSettings();
|
||||
void main(void)
|
||||
{
|
||||
if(gl_InvocationID == 0) {
|
||||
determineLODSettings();
|
||||
}
|
||||
|
||||
outData[gl_InvocationID].Peye = inData[gl_InvocationID].Peye;
|
||||
outData[gl_InvocationID].Neye = inData[gl_InvocationID].Neye;
|
||||
|
||||
ProcessPrimvars();
|
||||
}
|
||||
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Linear.Ribbon
|
||||
|
||||
// Use the length of the control points in screen space to determine how many
|
||||
// times to subdivide the curve.
|
||||
void determineLODSettings()
|
||||
{
|
||||
gl_TessLevelOuter[0] = 1;
|
||||
gl_TessLevelOuter[1] = 1;
|
||||
gl_TessLevelOuter[2] = 1;
|
||||
gl_TessLevelOuter[3] = 1;
|
||||
|
||||
gl_TessLevelInner[0] = 1;
|
||||
gl_TessLevelInner[1] = 1;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Linear.HalfTube
|
||||
|
||||
// Use the width of the control points in screen space to determine how
|
||||
// many times to subdivide the curve. NOTE. As a quick hack, we leverage the
|
||||
// fact that the normal isn't normalized at this point in the pipeline to
|
||||
// provide a quick estimate of width in eye space. If that becomes a bad
|
||||
// assumption in the future, this needs to be reworked.
|
||||
void determineLODSettings()
|
||||
{
|
||||
MAT4 projMat = GetProjectionMatrix();
|
||||
vec4 viewport = GetViewport();
|
||||
vec2 screen_size = vec2(viewport.z, viewport.w);
|
||||
|
||||
// NOTE. We've observed that outData.Neye is not normalized, and
|
||||
// we're using its length as an estimator of the accumulated transform
|
||||
float wEye0 = HdGet_widths(0) * length(inData[0].Neye);
|
||||
float wEye1 = HdGet_widths(1) * length(inData[1].Neye);
|
||||
|
||||
// project a point that is 'w' units away from the origin
|
||||
vec2 v_w0 = projectToScreen(projMat, vec4(wEye0, 0, 0, 1), screen_size);
|
||||
vec2 v_w1 = projectToScreen(projMat, vec4(wEye1, 0, 0, 1), screen_size);
|
||||
|
||||
float maxTess = GetMaxTess();
|
||||
// reduce the tessellation in the width by this value.
|
||||
float widthDecimation = 10.0;
|
||||
|
||||
float maxWidthScreenSpace = max(length(v_w0), length(v_w1));
|
||||
|
||||
float level_w = clamp(maxWidthScreenSpace / GetPixelToTessRatio() / widthDecimation, 1, maxTess);
|
||||
|
||||
gl_TessLevelOuter[0] = 1;
|
||||
gl_TessLevelOuter[1] = level_w;
|
||||
gl_TessLevelOuter[2] = 1;
|
||||
gl_TessLevelOuter[3] = level_w;
|
||||
|
||||
gl_TessLevelInner[0] = level_w;
|
||||
gl_TessLevelInner[1] = 1;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Cubic.Wire
|
||||
|
||||
layout(vertices = HD_NUM_PATCH_EVAL_VERTS) out;
|
||||
|
||||
in CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} inData[gl_MaxPatchVertices];
|
||||
|
||||
out CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} outData[HD_NUM_PATCH_EVAL_VERTS];
|
||||
|
||||
void determineLODSettings();
|
||||
void main(void)
|
||||
{
|
||||
if(gl_InvocationID == 0) {
|
||||
determineLODSettings();
|
||||
}
|
||||
|
||||
outData[gl_InvocationID].Peye = inData[gl_InvocationID].Peye;
|
||||
|
||||
ProcessPrimvars();
|
||||
}
|
||||
|
||||
// Use the length of the control points in screen space to determine how many
|
||||
// times to subdivide the curve.
|
||||
void determineLODSettings()
|
||||
{
|
||||
MAT4 projMat = GetProjectionMatrix();
|
||||
vec4 viewport = GetViewport();
|
||||
vec2 screen_size = vec2(viewport.z, viewport.w);
|
||||
vec2 v0 = projectToScreen(projMat, inData[0].Peye, screen_size);
|
||||
vec2 v1 = projectToScreen(projMat, inData[1].Peye, screen_size);
|
||||
vec2 v2 = projectToScreen(projMat, inData[2].Peye, screen_size);
|
||||
vec2 v3 = projectToScreen(projMat, inData[3].Peye, screen_size);
|
||||
|
||||
float maxTess = GetMaxTess();
|
||||
|
||||
// Need to handle off screen
|
||||
float dist = distance(v0, v1) + distance(v1, v2) + distance(v2, v3);
|
||||
float level = clamp(dist / GetPixelToTessRatio(), 0, maxTess);
|
||||
|
||||
gl_TessLevelOuter[0] = 1;
|
||||
gl_TessLevelOuter[1] = level;
|
||||
}
|
||||
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Cubic.Patch
|
||||
|
||||
layout(vertices = HD_NUM_PATCH_EVAL_VERTS) out;
|
||||
|
||||
in CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData[gl_MaxPatchVertices];
|
||||
|
||||
out CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData[HD_NUM_PATCH_EVAL_VERTS];
|
||||
|
||||
void determineLODSettings();
|
||||
void main(void)
|
||||
{
|
||||
if(gl_InvocationID == 0) {
|
||||
determineLODSettings();
|
||||
}
|
||||
|
||||
outData[gl_InvocationID].Peye = inData[gl_InvocationID].Peye;
|
||||
outData[gl_InvocationID].Neye = inData[gl_InvocationID].Neye;
|
||||
|
||||
ProcessPrimvars();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Cubic.Ribbon
|
||||
|
||||
// Use the length of the control points in screen space to determine how many
|
||||
// times to subdivide the curve.
|
||||
void determineLODSettings()
|
||||
{
|
||||
MAT4 projMat = GetProjectionMatrix();
|
||||
vec4 viewport = GetViewport();
|
||||
vec2 screen_size = vec2(viewport.z, viewport.w);
|
||||
vec2 v0 = projectToScreen(projMat, inData[0].Peye, screen_size);
|
||||
vec2 v1 = projectToScreen(projMat, inData[1].Peye, screen_size);
|
||||
vec2 v2 = projectToScreen(projMat, inData[2].Peye, screen_size);
|
||||
vec2 v3 = projectToScreen(projMat, inData[3].Peye, screen_size);
|
||||
|
||||
float maxTess = GetMaxTess();
|
||||
|
||||
// Need to handle off screen
|
||||
float dist = distance(v0, v1) + distance(v1, v2) + distance(v2, v3);
|
||||
float level = clamp(dist / GetPixelToTessRatio(), 0, maxTess);
|
||||
|
||||
gl_TessLevelOuter[0] = level;
|
||||
gl_TessLevelOuter[1] = 1;
|
||||
gl_TessLevelOuter[2] = level;
|
||||
gl_TessLevelOuter[3] = 1;
|
||||
|
||||
gl_TessLevelInner[0] = 1;
|
||||
gl_TessLevelInner[1] = level;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessControl.Cubic.HalfTube
|
||||
|
||||
// Use the width & length of the control points in screen space to determine how
|
||||
// many times to subdivide the curve. NOTE. As a quick hack, we leverage the
|
||||
// fact that the normal isn't normalized at this point in the pipeline to
|
||||
// provide a quick estimate of width in eye space. If that becomes a bad
|
||||
// assumption in the future, this needs to be reworked.
|
||||
void determineLODSettings()
|
||||
{
|
||||
MAT4 projMat = GetProjectionMatrix();
|
||||
vec4 viewport = GetViewport();
|
||||
vec2 screen_size = vec2(viewport.z, viewport.w);
|
||||
vec2 v0 = projectToScreen(projMat, inData[0].Peye, screen_size);
|
||||
vec2 v1 = projectToScreen(projMat, inData[1].Peye, screen_size);
|
||||
vec2 v2 = projectToScreen(projMat, inData[2].Peye, screen_size);
|
||||
vec2 v3 = projectToScreen(projMat, inData[3].Peye, screen_size);
|
||||
|
||||
// NOTE. We've observed that outData.Neye is not normalized, and
|
||||
// we're using its length as an estimator of the accumulated transform
|
||||
float wEye0 = HdGet_widths(0) * length(inData[0].Neye);
|
||||
float wEye1 = HdGet_widths(1) * length(inData[1].Neye);
|
||||
float wEye2 = HdGet_widths(2) * length(inData[2].Neye);
|
||||
float wEye3 = HdGet_widths(3) * length(inData[3].Neye);
|
||||
|
||||
// project a point that is 'w' units away from the origin
|
||||
vec2 v_w0 = projectToScreen(projMat, vec4(wEye0, 0, 0, 1), screen_size);
|
||||
vec2 v_w1 = projectToScreen(projMat, vec4(wEye1, 0, 0, 1), screen_size);
|
||||
vec2 v_w2 = projectToScreen(projMat, vec4(wEye2, 0, 0, 1), screen_size);
|
||||
vec2 v_w3 = projectToScreen(projMat, vec4(wEye3, 0, 0, 1), screen_size);
|
||||
|
||||
float maxTess = GetMaxTess();
|
||||
// reduce the tessellation in the width by this value.
|
||||
float widthDecimation = 10.0;
|
||||
|
||||
// Need to handle off screen
|
||||
float dist = distance(v0, v1) + distance(v1, v2) + distance(v2, v3);
|
||||
float level = clamp(dist / GetPixelToTessRatio(), 0, maxTess);
|
||||
|
||||
float maxWidthScreenSpace =
|
||||
max(max(max(length(v_w0), length(v_w1)), length(v_w2)), length(v_w3));
|
||||
|
||||
float level_w = clamp(maxWidthScreenSpace / GetPixelToTessRatio() / widthDecimation, 1, maxTess);
|
||||
|
||||
gl_TessLevelOuter[0] = level;
|
||||
gl_TessLevelOuter[1] = level_w;
|
||||
gl_TessLevelOuter[2] = level;
|
||||
gl_TessLevelOuter[3] = level_w;
|
||||
|
||||
gl_TessLevelInner[0] = level_w;
|
||||
gl_TessLevelInner[1] = level;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessEval.Cubic.Wire
|
||||
|
||||
layout(isolines, fractional_odd_spacing) in;
|
||||
|
||||
struct Coeffs
|
||||
{
|
||||
vec4 basis;
|
||||
vec4 tangent_basis;
|
||||
};
|
||||
|
||||
in CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} inData[gl_MaxPatchVertices];
|
||||
|
||||
out CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} outData;
|
||||
|
||||
Coeffs evaluateBasis(float u, float u2, float u3);
|
||||
|
||||
void main()
|
||||
{
|
||||
float u = gl_TessCoord.x;
|
||||
float v = .5;
|
||||
|
||||
vec4 cv0 = inData[0].Peye;
|
||||
vec4 cv1 = inData[1].Peye;
|
||||
vec4 cv2 = inData[2].Peye;
|
||||
vec4 cv3 = inData[3].Peye;
|
||||
|
||||
Coeffs coeffs = evaluateBasis(u, u*u, u*u*u);
|
||||
vec4 basis = coeffs.basis;
|
||||
vec4 pos = basis[0] * cv0 +
|
||||
basis[1] * cv1 +
|
||||
basis[2] * cv2 +
|
||||
basis[3] * cv3;
|
||||
|
||||
outData.Peye = pos;
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
ProcessPrimvars(basis, 0, 1, 2, 3, vec2(u, v)); // interpolate varying primvars
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessEval.Patch
|
||||
|
||||
layout(quads, fractional_odd_spacing, ccw) in;
|
||||
|
||||
struct Coeffs
|
||||
{
|
||||
vec4 basis;
|
||||
vec4 tangent_basis;
|
||||
};
|
||||
|
||||
in CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData[gl_MaxPatchVertices];
|
||||
|
||||
out CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
out float u;
|
||||
out float v;
|
||||
|
||||
// Predefine so that we can later swap in the correct one depending
|
||||
// on what type of curve we have
|
||||
|
||||
void evaluate(float u, float v, out vec4 position, out vec4 tangent,
|
||||
out float width, out vec3 normal);
|
||||
|
||||
Coeffs evaluateBasis(float u, float u2, float u3);
|
||||
|
||||
// it's the responsibility of orient to store Neye, usually with either
|
||||
// the computed normal or the tangent (from which the normal will be computed
|
||||
// in the fragment shader.)
|
||||
vec3 orient(float v, vec4 position, vec4 tangent, vec3 normal);
|
||||
void main()
|
||||
{
|
||||
u = gl_TessCoord.y;
|
||||
v = gl_TessCoord.x;
|
||||
|
||||
Coeffs coeffs = evaluateBasis(u, u*u, u*u*u);
|
||||
vec4 basis = coeffs.basis;
|
||||
|
||||
vec4 position;
|
||||
vec4 tangent;
|
||||
float width;
|
||||
vec3 normal;
|
||||
|
||||
evaluate(u, v, position, tangent, width, normal);
|
||||
vec3 direction = orient(v, position, tangent, normal);
|
||||
MAT4 transform = ApplyInstanceTransform(HdGet_transform());
|
||||
vec4 scaledDirection = GetWorldToViewMatrix() * transform
|
||||
* vec4(direction, 0);
|
||||
vec3 offset = direction * length(scaledDirection.xyz) * width * 0.5;
|
||||
position.xyz = position.xyz + offset;
|
||||
position.w = 1;
|
||||
|
||||
outData.Peye = position;
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
ProcessPrimvars(basis, 0, 1, 2, 3, vec2(u, v)); // interpolate varying primvars
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessEval.Linear.Patch
|
||||
|
||||
vec3 evaluateNormal(float u)
|
||||
{
|
||||
// XXX: This clamp is a hack to mask some odd orientation flipping issues
|
||||
u = clamp(u, 1e-3, 1.0 - 1e-3);
|
||||
return mix(inData[1].Neye, inData[0].Neye, u);
|
||||
}
|
||||
|
||||
void evaluate(float u, float v, out vec4 position, out vec4 tangent,
|
||||
out float width, out vec3 normal){
|
||||
vec4 p0 = inData[0].Peye;
|
||||
vec4 p1 = inData[1].Peye;
|
||||
|
||||
float w0 = HdGet_widths(0);
|
||||
float w1 = HdGet_widths(1);
|
||||
|
||||
position = mix(p1, p0, u);
|
||||
tangent = normalize(p1 - p0);
|
||||
width = mix(w1, w0, u);
|
||||
normal = normalize(evaluateNormal(u));
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessEval.Cubic.Patch
|
||||
struct Coeffs
|
||||
{
|
||||
vec4 basis;
|
||||
vec4 tangent_basis;
|
||||
};
|
||||
|
||||
Coeffs evaluateBasis(float u, float u2, float u3);
|
||||
float evaluateWidths(vec4 basis, float u);
|
||||
vec3 evaluateNormal(vec4 basis, float u);
|
||||
|
||||
void evaluate(float u, float v, out vec4 position, out vec4 tangent,
|
||||
out float width, out vec3 normal){
|
||||
vec4 p0 = inData[0].Peye;
|
||||
vec4 p1 = inData[1].Peye;
|
||||
vec4 p2 = inData[2].Peye;
|
||||
vec4 p3 = inData[3].Peye;
|
||||
|
||||
Coeffs coeffs = evaluateBasis(u, u*u, u*u*u);
|
||||
|
||||
position = coeffs.basis[0] * p0 +
|
||||
coeffs.basis[1] * p1 +
|
||||
coeffs.basis[2] * p2 +
|
||||
coeffs.basis[3] * p3;
|
||||
|
||||
tangent = coeffs.tangent_basis[0] * p0 +
|
||||
coeffs.tangent_basis[1] * p1 +
|
||||
coeffs.tangent_basis[2] * p2 +
|
||||
coeffs.tangent_basis[3] * p3;
|
||||
|
||||
width = evaluateWidths(coeffs.basis, u);
|
||||
normal = normalize(evaluateNormal(coeffs.basis, u));
|
||||
tangent = normalize(tangent);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessEval.HalfTube
|
||||
|
||||
vec3 orient(float v, vec4 position, vec4 tangent, vec3 normal){
|
||||
outData.Neye = tangent.xyz;
|
||||
vec3 d = normalize(cross(position.xyz, tangent.xyz));
|
||||
vec3 n = normalize(cross(d, tangent.xyz));
|
||||
|
||||
vec3 norm_pos = mix(n, d, (2.0*v) - 1.0);
|
||||
vec3 norm_neg = mix(-d, n, (2.0*v));
|
||||
normal = normalize(mix(norm_neg, norm_pos, step(0.5, v)));
|
||||
return normal;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessEval.Ribbon.Oriented
|
||||
|
||||
vec3 orient(float v, vec4 position, vec4 tangent, vec3 normal){
|
||||
outData.Neye = normal;
|
||||
return normalize(cross(tangent.xyz, normal) * (v - 0.5));
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.TessEval.Ribbon.Implicit
|
||||
|
||||
vec3 orient(float v, vec4 position, vec4 tangent, vec3 normal){
|
||||
outData.Neye = tangent.xyz;
|
||||
// NOTE: lava/lib/basisCurves currently uses tangent X position instead of
|
||||
// tangent X normal. We should do a more thorough evaluation to see which
|
||||
// is better but to minimize regressions, we're going to keep this as
|
||||
// tangent X normal for now.
|
||||
return normalize(cross(tangent.xyz, normal) * (v - 0.5));
|
||||
}
|
||||
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Cubic.Normals.Basis
|
||||
|
||||
vec3 evaluateNormal(vec4 basis, float u)
|
||||
{
|
||||
vec3 n0 = inData[0].Neye;
|
||||
vec3 n1 = inData[1].Neye;
|
||||
vec3 n2 = inData[2].Neye;
|
||||
vec3 n3 = inData[3].Neye;
|
||||
return n0 * basis.x
|
||||
+ n1 * basis.y
|
||||
+ n2 * basis.z
|
||||
+ n3 * basis.w;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Cubic.Normals.Linear
|
||||
|
||||
// HdSt only supports vertex (cubic) primvar indexes and expands varying
|
||||
// (linear) primvars so we pull the data out of only the two interior indices.
|
||||
// This may not be valid for all potential basis, but works well for curves with
|
||||
// vstep = 1 and bezier, the only supported cubic curves in HdSt.
|
||||
|
||||
vec3 evaluateNormal(vec4 basis, float u)
|
||||
{
|
||||
// XXX: This clamp is a hack to mask some odd orientation flipping issues
|
||||
// for oriented bezier curves.
|
||||
u = clamp(u, 1e-3, 1.0 - 1e-3);
|
||||
return mix(inData[2].Neye, inData[1].Neye, u);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Cubic.Widths.Basis
|
||||
|
||||
float evaluateWidths(vec4 basis, float u)
|
||||
{
|
||||
float w0 = HdGet_widths(0);
|
||||
float w1 = HdGet_widths(1);
|
||||
float w2 = HdGet_widths(2);
|
||||
float w3 = HdGet_widths(3);
|
||||
return w0 * basis.x
|
||||
+ w1 * basis.y
|
||||
+ w2 * basis.z
|
||||
+ w3 * basis.w;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Cubic.Widths.Linear
|
||||
|
||||
// HdSt only supports vertex (cubic) primvar indexes and expands varying
|
||||
// (linear) primvars so we pull the data out of only the two interior indices.
|
||||
// (ie. w0 -> widths[1], w1 -> widths[2])
|
||||
// This may not be valid for all potential basis, but works well for curves with
|
||||
// vstep = 1 and bezier, the only supported cubic curves in HdSt.
|
||||
float evaluateWidths(vec4 basis, float u)
|
||||
{
|
||||
float w0 = HdGet_widths(1);
|
||||
float w1 = HdGet_widths(2);
|
||||
return mix(w1, w0, u);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Linear.VaryingInterpolation
|
||||
|
||||
float ProcessPrimvar(float inPv0, float inPv1, float inPv2, float inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return inPv0 * basis.x +
|
||||
inPv1 * basis.y +
|
||||
inPv2 * basis.z +
|
||||
inPv3 * basis.w;
|
||||
}
|
||||
|
||||
vec2 ProcessPrimvar(vec2 inPv0, vec2 inPv1, vec2 inPv2, vec2 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return inPv0 * basis.x +
|
||||
inPv1 * basis.y +
|
||||
inPv2 * basis.z +
|
||||
inPv3 * basis.w;
|
||||
}
|
||||
|
||||
vec3 ProcessPrimvar(vec3 inPv0, vec3 inPv1, vec3 inPv2, vec3 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return inPv0 * basis.x +
|
||||
inPv1 * basis.y +
|
||||
inPv2 * basis.z +
|
||||
inPv3 * basis.w;
|
||||
}
|
||||
|
||||
vec4 ProcessPrimvar(vec4 inPv0, vec4 inPv1, vec4 inPv2, vec4 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return inPv0 * basis.x +
|
||||
inPv1 * basis.y +
|
||||
inPv2 * basis.z +
|
||||
inPv3 * basis.w;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Cubic.VaryingInterpolation
|
||||
|
||||
float ProcessPrimvar(float inPv0, float inPv1, float inPv2, float inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return mix(inPv2, inPv1, uv.x);
|
||||
}
|
||||
|
||||
vec2 ProcessPrimvar(vec2 inPv0, vec2 inPv1, vec2 inPv2, vec2 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return mix(inPv2, inPv1, uv.x);
|
||||
}
|
||||
|
||||
vec3 ProcessPrimvar(vec3 inPv0, vec3 inPv1, vec3 inPv2, vec3 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return mix(inPv2, inPv1, uv.x);
|
||||
}
|
||||
|
||||
vec4 ProcessPrimvar(vec4 inPv0, vec4 inPv1, vec4 inPv2, vec4 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return mix(inPv2, inPv1, uv.x);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.BezierBasis
|
||||
|
||||
Coeffs evaluateBasis(float u, float u2, float u3)
|
||||
{
|
||||
vec4 basis; vec4 tangent_basis;
|
||||
basis[0] = u3;
|
||||
basis[1] = -3.0*u3 + 3.0*u2;
|
||||
basis[2] = 3.0*u3 - 6.0*u2 + 3.0*u;
|
||||
basis[3] = -1.0*u3 + 3.0*u2 - 3.0*u + 1.0;
|
||||
|
||||
tangent_basis[0] = 3.0*u2;
|
||||
tangent_basis[1] = -9.0*u2 + 6.0*u;
|
||||
tangent_basis[2] = 9.0*u2 - 12.0*u + 3.0;
|
||||
tangent_basis[3] = -3.0*u2 + 6.0*u - 3.0;
|
||||
return Coeffs(basis, tangent_basis);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.LinearBasis
|
||||
|
||||
Coeffs evaluateBasis(float u, float u2, float u3)
|
||||
{
|
||||
vec4 basis; vec4 tangent_basis;
|
||||
basis[0] = u;
|
||||
basis[1] = 1.0 - u;
|
||||
basis[2] = 0;
|
||||
basis[3] = 0.0;
|
||||
|
||||
tangent_basis[0] = 1;
|
||||
tangent_basis[1] = -1;
|
||||
tangent_basis[2] = 0;
|
||||
tangent_basis[3] = 0;
|
||||
return Coeffs(basis, tangent_basis);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.CatmullRomBasis
|
||||
|
||||
Coeffs evaluateBasis(float u, float u2, float u3)
|
||||
{
|
||||
vec4 basis; vec4 tangent_basis;
|
||||
basis[0] = 0.5*u3 - 0.5*u2;
|
||||
basis[1] = -1.5*u3 + 2.0*u2 + 0.5*u;
|
||||
basis[2] = 1.5*u3 - 2.5*u2 + 1.0;
|
||||
basis[3] = -0.5*u3 + u2 - 0.5*u;
|
||||
|
||||
tangent_basis[0] = 1.5*u2 - u;
|
||||
tangent_basis[1] = -4.5*u2 + 4.0*u + 0.5;
|
||||
tangent_basis[2] = 4.5*u2 - 5.0*u;
|
||||
tangent_basis[3] = -1.5*u2 + 2.0*u - 0.5;
|
||||
return Coeffs(basis, tangent_basis);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.BsplineBasis
|
||||
|
||||
Coeffs evaluateBasis(float u, float u2, float u3)
|
||||
{
|
||||
vec4 basis; vec4 tangent_basis;
|
||||
basis[0] = (1.0/6.0)*u3;
|
||||
basis[1] = -0.5*u3 + 0.5*u2 + 0.5*u + (1.0/6.0);
|
||||
basis[2] = 0.5*u3 - u2 + (2.0/3.0);
|
||||
basis[3] = -(1.0/6.0)*u3 + 0.5*u2 - 0.5*u + (1.0/6.0);
|
||||
|
||||
tangent_basis[0] = 0.5*u2;
|
||||
tangent_basis[1] = -1.5*u2 + u + 0.5;
|
||||
tangent_basis[2] = 1.5*u2 - 2.0*u;
|
||||
tangent_basis[3] = -0.5*u2 + u - 0.5;
|
||||
return Coeffs(basis, tangent_basis);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Fragment.Wire
|
||||
|
||||
in CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} inData;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
DiscardBasedOnTopologicalVisibility();
|
||||
|
||||
vec4 color = vec4(0.5, 0.5, 0.5, 1);
|
||||
#ifdef HD_HAS_displayColor
|
||||
color.rgb = HdGet_displayColor().rgb;
|
||||
#endif
|
||||
#ifdef HD_HAS_displayOpacity
|
||||
color.a = HdGet_displayOpacity().r;
|
||||
#endif
|
||||
color.rgb = ApplyColorOverrides(color).rgb;
|
||||
|
||||
vec3 Peye = inData.Peye.xyz / inData.Peye.w;
|
||||
|
||||
// We would like to have a better oriented normal here, however to keep the
|
||||
// shader fast, we use this camera-facing approximation.
|
||||
vec3 Neye = vec3(0,0,1);
|
||||
|
||||
vec4 patchCoord = vec4(0);
|
||||
|
||||
color.rgb = mix(color.rgb,
|
||||
ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord).rgb,
|
||||
GetLightingBlendAmount());
|
||||
|
||||
#ifdef HD_MATERIAL_TAG_MASKED
|
||||
if (ShouldDiscardByAlpha(color)) {
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
RenderOutput(vec4(Peye, 1), Neye, color, patchCoord);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Fragment.Patch
|
||||
|
||||
/// In the previous stage, we may have stored the tangent in Neye from which
|
||||
/// we plan to compute a normal in the fragment shader.
|
||||
in CurveVertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData;
|
||||
|
||||
centroid in float u;
|
||||
centroid in float v;
|
||||
|
||||
vec3 fragmentNormal(vec3 position, vec3 normal, float v);
|
||||
void main(void)
|
||||
{
|
||||
DiscardBasedOnTopologicalVisibility();
|
||||
|
||||
vec4 color = vec4(0.5, 0.5, 0.5, 1);
|
||||
#ifdef HD_HAS_displayColor
|
||||
color.rgb = HdGet_displayColor().rgb;
|
||||
#endif
|
||||
#ifdef HD_HAS_displayOpacity
|
||||
color.a = HdGet_displayOpacity().r;
|
||||
#endif
|
||||
color.rgb = ApplyColorOverrides(color).rgb;
|
||||
|
||||
vec3 Peye = inData.Peye.xyz / inData.Peye.w;
|
||||
|
||||
vec3 Neye = fragmentNormal(Peye, inData.Neye, v);
|
||||
|
||||
vec4 patchCoord = vec4(0);
|
||||
color.rgb = mix(color.rgb,
|
||||
ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord).rgb,
|
||||
GetLightingBlendAmount());
|
||||
|
||||
#ifdef HD_MATERIAL_TAG_MASKED
|
||||
if (ShouldDiscardByAlpha(color)) {
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
RenderOutput(vec4(Peye, 1), Neye, color, patchCoord);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Fragment.HalfTube
|
||||
|
||||
vec3 fragmentNormal(in vec3 position, in vec3 tangent, in float v)
|
||||
{
|
||||
vec3 d = normalize(cross(position, tangent));
|
||||
vec3 n = normalize(cross(d, tangent));
|
||||
vec3 norm_pos = mix(n, d, (2.0*v) - 1.0);
|
||||
vec3 norm_neg = mix(-d, n, (2.0*v));
|
||||
return normalize(mix(norm_neg, norm_pos, step(0.5, v)));
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Fragment.Ribbon.Round
|
||||
|
||||
float remapFragmentV(float v){
|
||||
// As we are using a plane to approximate a tube, we don't want to shade
|
||||
// based on v but rather the projection of the tube's v onto the plane
|
||||
return clamp((asin(v * 2.0 - 1.0) / (3.146 / 2.0) + 1.0) / 2.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 fragmentNormal(vec3 position, in vec3 tangent, float v)
|
||||
{
|
||||
|
||||
// we slightly bias v towards 0.5 based on filterwidth as a hack to
|
||||
// minimize aliasing
|
||||
v = mix(remapFragmentV(v), 0.5, min(fwidth(v), .2));
|
||||
|
||||
vec3 d = normalize(cross(position, tangent));
|
||||
vec3 n = normalize(cross(d, tangent));
|
||||
vec3 norm_pos = mix(n, d, (2.0*v) - 1.0);
|
||||
vec3 norm_neg = mix(-d, n, (2.0*v));
|
||||
|
||||
return normalize(mix(norm_neg, norm_pos, step(0.5, v)));
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Fragment.Ribbon.Oriented
|
||||
|
||||
vec3 fragmentNormal(vec3 position, in vec3 normal, float v)
|
||||
{
|
||||
normal = normalize(normal);
|
||||
if (gl_FrontFacing){
|
||||
return normal;
|
||||
}
|
||||
else{
|
||||
return -normal;
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Curves.Fragment.Hair
|
||||
|
||||
// XXX: Neye is interpolated in from previous stages, however the
|
||||
// polarity is not stable due to instability in the cross-product in the
|
||||
// TessEval shader. Once that is fixed, we could use Neye directly here.
|
||||
// The normal computed here results in faceted shading.
|
||||
//
|
||||
vec3 fragmentNormal(vec3 position, in vec3 unused, float v)
|
||||
{
|
||||
return cross(dFdx(position), dFdy(position));
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/compute.glslfx
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"smoothNormalsFloatToFloat": {
|
||||
"source": [ "Compute.NormalsSrcFloat",
|
||||
"Compute.NormalsDstFloat",
|
||||
"Compute.SmoothNormals" ]
|
||||
},
|
||||
"smoothNormalsDoubleToDouble": {
|
||||
"source": [ "Compute.NormalsSrcDouble",
|
||||
"Compute.NormalsDstDouble",
|
||||
"Compute.SmoothNormals" ]
|
||||
},
|
||||
"smoothNormalsFloatToPacked": {
|
||||
"source": [ "Compute.NormalsSrcFloat",
|
||||
"Compute.NormalsDstPacked",
|
||||
"Compute.SmoothNormals" ]
|
||||
},
|
||||
"smoothNormalsDoubleToPacked": {
|
||||
"source": [ "Compute.NormalsSrcDouble",
|
||||
"Compute.NormalsDstPacked",
|
||||
"Compute.SmoothNormals" ]
|
||||
},
|
||||
"flatNormalsTriFloatToFloat": {
|
||||
"source": [ "Compute.NormalsSrcFloat",
|
||||
"Compute.NormalsDstFloat",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsTri" ]
|
||||
},
|
||||
"flatNormalsTriDoubleToDouble": {
|
||||
"source": [ "Compute.NormalsSrcDouble",
|
||||
"Compute.NormalsDstDouble",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsTri" ]
|
||||
},
|
||||
"flatNormalsTriFloatToPacked": {
|
||||
"source": [ "Compute.NormalsSrcFloat",
|
||||
"Compute.NormalsDstPacked",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsTri" ]
|
||||
},
|
||||
"flatNormalsTriDoubleToPacked": {
|
||||
"source": [ "Compute.NormalsSrcDouble",
|
||||
"Compute.NormalsDstPacked",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsTri" ]
|
||||
},
|
||||
"flatNormalsQuadFloatToFloat": {
|
||||
"source": [ "Compute.NormalsSrcFloat",
|
||||
"Compute.NormalsDstFloat",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsQuad" ]
|
||||
},
|
||||
"flatNormalsQuadDoubleToDouble": {
|
||||
"source": [ "Compute.NormalsSrcDouble",
|
||||
"Compute.NormalsDstDouble",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsQuad" ]
|
||||
},
|
||||
"flatNormalsQuadFloatToPacked": {
|
||||
"source": [ "Compute.NormalsSrcFloat",
|
||||
"Compute.NormalsDstPacked",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsQuad" ]
|
||||
},
|
||||
"flatNormalsQuadDoubleToPacked": {
|
||||
"source": [ "Compute.NormalsSrcDouble",
|
||||
"Compute.NormalsDstPacked",
|
||||
"Compute.FlatNormals",
|
||||
"Compute.FlatNormalsQuad" ]
|
||||
},
|
||||
"quadrangulateFloat": {
|
||||
"source": [ "Compute.QuadrangulateFloat",
|
||||
"Compute.Quadrangulate" ]
|
||||
},
|
||||
"quadrangulateDouble": {
|
||||
"source": [ "Compute.QuadrangulateDouble",
|
||||
"Compute.Quadrangulate" ]
|
||||
},
|
||||
"evalStencils": {
|
||||
"source": [ "Compute.EvalStencils" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.NormalsSrcFloat
|
||||
|
||||
vec3 getPoint(int index)
|
||||
{
|
||||
return vec3(points[index],
|
||||
points[index + 1],
|
||||
points[index + 2]);
|
||||
}
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.NormalsSrcDouble
|
||||
|
||||
vec3 getPoint(int index)
|
||||
{
|
||||
return vec3(points[index],
|
||||
points[index + 1],
|
||||
points[index + 2]);
|
||||
}
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.NormalsDstFloat
|
||||
|
||||
void writeNormal(int nIndex, vec3 normal)
|
||||
{
|
||||
normals[nIndex+0] = normal.x;
|
||||
normals[nIndex+1] = normal.y;
|
||||
normals[nIndex+2] = normal.z;
|
||||
}
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.NormalsDstDouble
|
||||
|
||||
void writeNormal(int nIndex, vec3 normal)
|
||||
{
|
||||
normals[nIndex+0] = normal.x;
|
||||
normals[nIndex+1] = normal.y;
|
||||
normals[nIndex+2] = normal.z;
|
||||
}
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.NormalsDstPacked
|
||||
|
||||
void writeNormal(int nIndex, vec3 normal)
|
||||
{
|
||||
normal *= 511.0;
|
||||
normals[nIndex] =
|
||||
((int(normal.x) & 0x3ff) ) |
|
||||
((int(normal.y) & 0x3ff) << 10) |
|
||||
((int(normal.z) & 0x3ff) << 20);
|
||||
}
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.SmoothNormals
|
||||
|
||||
int getPointsIndex(int idx)
|
||||
{
|
||||
return (idx+vertexOffset)*pointsStride + pointsOffset;
|
||||
}
|
||||
|
||||
int getNormalsIndex(int idx)
|
||||
{
|
||||
return (idx+vertexOffset)*normalsStride + normalsOffset;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
int index = int(hd_GlobalInvocationID.x);
|
||||
|
||||
int offIndex = index * 2 + adjacencyOffset;
|
||||
|
||||
int offset = entry[offIndex] + adjacencyOffset;
|
||||
int valence = entry[offIndex + 1];
|
||||
|
||||
vec3 normal = vec3(0);
|
||||
|
||||
vec3 current = getPoint(getPointsIndex(index));
|
||||
for (int i = 0; i < valence; ++i) {
|
||||
int entryIdx = i * 2 + offset;
|
||||
|
||||
int prevIdx = entry[entryIdx];
|
||||
int nextIdx = entry[entryIdx + 1];
|
||||
|
||||
vec3 next = getPoint(getPointsIndex(nextIdx));
|
||||
vec3 prev = getPoint(getPointsIndex(prevIdx));
|
||||
normal += cross(next - current, prev - current);
|
||||
|
||||
}
|
||||
float n = 1.0/max(length(normal), 0.000001);
|
||||
normal *= n;
|
||||
writeNormal(getNormalsIndex(index), normal);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.FlatNormals
|
||||
|
||||
int getPointsIndex(int idx)
|
||||
{
|
||||
return (idx+vertexOffset)*pointsStride + pointsOffset;
|
||||
}
|
||||
|
||||
int getNormalsIndex(int idx)
|
||||
{
|
||||
return (idx+elementOffset)*normalsStride + normalsOffset;
|
||||
}
|
||||
|
||||
int getIndicesIndex(int idx)
|
||||
{
|
||||
return (idx+topologyOffset)*indexStride + indexOffset;
|
||||
}
|
||||
|
||||
int getPrimitiveParamIndex(int idx)
|
||||
{
|
||||
return (idx+topologyOffset)*pParamStride + pParamOffset;
|
||||
}
|
||||
|
||||
int getEdgeFlag(int pParam)
|
||||
{
|
||||
return pParam & 3;
|
||||
}
|
||||
|
||||
int getFaceIndex(int pParam)
|
||||
{
|
||||
return pParam >> 2;
|
||||
}
|
||||
|
||||
vec3 computeNormalForPrimIndex(int primIndex);
|
||||
|
||||
void main()
|
||||
{
|
||||
int primIndex = int(hd_GlobalInvocationID.x);
|
||||
int pParam = primitiveParam[getPrimitiveParamIndex(primIndex)];
|
||||
int edgeFlag = getEdgeFlag(pParam);
|
||||
int faceIndex = getFaceIndex(pParam);
|
||||
vec3 normal = vec3(0);
|
||||
|
||||
if (getEdgeFlag(pParam) == 0) {
|
||||
// 0 indicates an unsplit face (as authored)
|
||||
normal += computeNormalForPrimIndex(primIndex);
|
||||
|
||||
} else if (getEdgeFlag(pParam) == 1) {
|
||||
// A subdivided face will have a run of prims with
|
||||
// edge flags like: 1, 3, 3, 3, 2; where "3" denotes an interior
|
||||
// prim. Only compute normals for the first prim in a face.
|
||||
|
||||
int primCounter = 0;
|
||||
do {
|
||||
pParam = primitiveParam[getPrimitiveParamIndex(
|
||||
primIndex+primCounter)];
|
||||
normal += computeNormalForPrimIndex(primIndex+primCounter);
|
||||
primCounter++;
|
||||
} while(getEdgeFlag(pParam) != 2);
|
||||
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
float n = 1.0/max(length(normal), 0.000001);
|
||||
normal *= n;
|
||||
writeNormal(getNormalsIndex(faceIndex), normal);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.FlatNormalsTri
|
||||
|
||||
ivec3 getIndices(int idx)
|
||||
{
|
||||
return ivec3(indices[idx],
|
||||
indices[idx+1],
|
||||
indices[idx+2]);
|
||||
}
|
||||
|
||||
vec3 computeNormalForPrimIndex(int primIndex)
|
||||
{
|
||||
ivec3 indices = getIndices(getIndicesIndex(primIndex));
|
||||
|
||||
vec3 p0 = getPoint(getPointsIndex(indices.x));
|
||||
vec3 p1 = getPoint(getPointsIndex(indices.y));
|
||||
vec3 p2 = getPoint(getPointsIndex(indices.z));
|
||||
|
||||
return cross(p1-p0, p2-p0);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.FlatNormalsQuad
|
||||
|
||||
ivec4 getIndices(int idx)
|
||||
{
|
||||
return ivec4(indices[idx],
|
||||
indices[idx+1],
|
||||
indices[idx+2],
|
||||
indices[idx+3]);
|
||||
}
|
||||
|
||||
vec3 computeNormalForPrimIndex(int primIndex)
|
||||
{
|
||||
ivec4 indices = getIndices(getIndicesIndex(primIndex));
|
||||
|
||||
vec3 p0 = getPoint(getPointsIndex(indices.x));
|
||||
vec3 p1 = getPoint(getPointsIndex(indices.y));
|
||||
vec3 p2 = getPoint(getPointsIndex(indices.z));
|
||||
vec3 p3 = getPoint(getPointsIndex(indices.w));
|
||||
|
||||
return cross(p0-p3, p2-p3) + cross(p2-p1, p0-p1);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.QuadrangulateFloat
|
||||
|
||||
#define DATATYPE float
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.QuadrangulateDouble
|
||||
|
||||
#define DATATYPE double
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.Quadrangulate
|
||||
|
||||
void main()
|
||||
{
|
||||
int index = int(hd_GlobalInvocationID.x);
|
||||
|
||||
int quadInfoIndex = index * quadInfoStride + quadInfoOffset;
|
||||
int numVert = quadInfo[quadInfoIndex];
|
||||
int dstOffset = quadInfo[quadInfoIndex+1];
|
||||
|
||||
// GPU quadinfo table layout
|
||||
//
|
||||
// struct NonQuad {
|
||||
// int numVert;
|
||||
// int dstOffset;
|
||||
// int index[maxNumVert];
|
||||
// } quadInfo[]
|
||||
//
|
||||
|
||||
for (int j = 0; j < numComponents; ++j) {
|
||||
DATATYPE center = 0;
|
||||
for (int i = 0; i < numVert; ++i) {
|
||||
int i0 = quadInfo[quadInfoIndex + 2 + i];
|
||||
int i1 = quadInfo[quadInfoIndex + 2 + (i+1)%numVert];
|
||||
|
||||
DATATYPE v0 = primvar[(i0 + vertexOffset)*primvarStride + primvarOffset + j];
|
||||
DATATYPE v1 = primvar[(i1 + vertexOffset)*primvarStride + primvarOffset + j];
|
||||
DATATYPE edge = (v0 + v1) * 0.5;
|
||||
center += v0;
|
||||
|
||||
// edge
|
||||
primvar[(dstOffset + i + vertexOffset)*primvarStride + primvarOffset + j] = edge;
|
||||
}
|
||||
// center
|
||||
center /= numVert;
|
||||
primvar[(dstOffset + numVert + vertexOffset)*primvarStride + primvarOffset + j] = center;
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Compute.EvalStencils
|
||||
|
||||
void main()
|
||||
{
|
||||
const int pointIndex = pointIndexStart + int(hd_GlobalInvocationID.x);
|
||||
if (pointIndex >= pointIndexEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int numElements = EVAL_STENCILS_NUM_ELEMENTS;
|
||||
float result[numElements];
|
||||
for (int element = 0; element < numElements; ++element) {
|
||||
result[element] = 0;
|
||||
}
|
||||
|
||||
const int stencilSize = sizes[pointIndex + sizesBase];
|
||||
const int stencilOffset = offsets[pointIndex + offsetsBase];
|
||||
|
||||
for (int stencil = 0; stencil < stencilSize; ++stencil) {
|
||||
const int index = indices[stencil + stencilOffset + indicesBase];
|
||||
const float weight = weights[stencil + stencilOffset + weightsBase];
|
||||
const int srcIndex = (index + srcBase) * srcStride;
|
||||
for (int element = 0; element < numElements; ++element) {
|
||||
result[element] += weight * primvar[srcIndex + element];
|
||||
}
|
||||
}
|
||||
|
||||
const int dstIndex = (pointIndex + dstBase) * dstStride;
|
||||
for (int element = 0; element < numElements; ++element) {
|
||||
primvar[dstIndex + element] = result[element];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"domeLightIrradiance": {
|
||||
"source": [ "DomeLight.Common",
|
||||
"DomeLight.Irradiance" ]
|
||||
},
|
||||
"domeLightPrefilter": {
|
||||
"source": [ "DomeLight.Common",
|
||||
"DomeLight.CommonSampling",
|
||||
"DomeLight.Prefilter" ]
|
||||
},
|
||||
"domeLightBRDF": {
|
||||
"source": [ "DomeLight.Common",
|
||||
"DomeLight.CommonSampling",
|
||||
"DomeLight.BRDF" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl DomeLight.Common
|
||||
|
||||
const float PI = 3.1415926536;
|
||||
|
||||
layout(binding = 0) uniform sampler2D inTexture;
|
||||
layout(rgba16f, binding = 1) uniform image2D outTexture;
|
||||
|
||||
// compute texture coords based on the size of the output image/texture
|
||||
vec2 GetTexCoords(ivec2 outCoords)
|
||||
{
|
||||
vec2 outDims = imageSize(outTexture);
|
||||
// apply a (0.5, 0.5) offset to use pixel centers and not pixel corners
|
||||
vec2 texCoords = (outCoords + vec2(0.5, 0.5)) / outDims;
|
||||
return texCoords;
|
||||
}
|
||||
|
||||
// sample lat/long env map input texture
|
||||
vec3 SampleEnvMapLod(vec3 sampleVec, float sampleLod) {
|
||||
vec2 coord = vec2((atan(sampleVec.z, sampleVec.x) + PI) / (2.0 * PI),
|
||||
acos(sampleVec.y) / PI);
|
||||
return textureLod(inTexture, coord, sampleLod).rgb;
|
||||
}
|
||||
|
||||
// compute world position from texture coords
|
||||
vec3 GetWorldPos(vec2 textureCoord)
|
||||
{
|
||||
// have theta range from [-PI, PI] so the origin is in the center
|
||||
// of the image
|
||||
float theta = (textureCoord.x * 2.0 * PI) - PI;
|
||||
float phi = (textureCoord.y * PI);
|
||||
float x = cos(theta) * sin(phi);
|
||||
float y = cos(phi);
|
||||
float z = sin(theta) * sin(phi);
|
||||
return vec3(x, y, z);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl DomeLight.CommonSampling
|
||||
|
||||
float RadicalInverse(uint a)
|
||||
{
|
||||
return float(bitfieldReverse(a)) * 2.3283064365386963e-10; // 0x1p-32
|
||||
}
|
||||
|
||||
vec2 Hammersley2d(uint a, uint N)
|
||||
{
|
||||
return vec2(float(a) / float(N), RadicalInverse(a));
|
||||
}
|
||||
|
||||
vec3 ImportanceSample_GGX(vec2 Xi, float roughness, vec3 normal)
|
||||
{
|
||||
// Maps a 2D point to a hemisphere with spread based on roughness
|
||||
float alpha = roughness * roughness;
|
||||
float phi = 2.0 * PI * Xi.x;
|
||||
float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (alpha*alpha - 1.0) * Xi.y));
|
||||
float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
|
||||
vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);
|
||||
|
||||
// Tangent space
|
||||
vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 tangentX = normalize(cross(up, normal));
|
||||
vec3 tangentY = normalize(cross(normal, tangentX));
|
||||
|
||||
// Convert to world Space
|
||||
return normalize(tangentX * H.x + tangentY * H.y + normal * H.z);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl DomeLight.Irradiance
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
const float deltaPhi = (2.0f * float(PI)) / 180.0f;
|
||||
const float deltaTheta = (0.5f * float(PI)) / 64.0f;
|
||||
|
||||
vec3 SampleEnvMap(vec3 sampleVec)
|
||||
{
|
||||
// sample from a mipmap level of the environment map determined by the
|
||||
// size of the environment map and the number of samples we are taking
|
||||
ivec2 inDims = textureSize(inTexture, 0);
|
||||
float mipLevel = ceil(log2(inDims.x * deltaPhi/(2.0 * PI)) * 2.0f);
|
||||
|
||||
return SampleEnvMapLod(sampleVec, mipLevel);
|
||||
}
|
||||
|
||||
vec3 ComputeIrradiance(vec3 inPos)
|
||||
{
|
||||
vec3 N = normalize(inPos);
|
||||
vec3 up = vec3(0.0, 1.0, 0.0);
|
||||
vec3 right = normalize(cross(up, N));
|
||||
up = cross(N, right);
|
||||
|
||||
const float TWO_PI = PI * 2.0;
|
||||
const float HALF_PI = PI * 0.5;
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
uint sampleCount = 0u;
|
||||
for (float phi = 0.0; phi < TWO_PI; phi += deltaPhi) {
|
||||
for (float theta = 0.0; theta < HALF_PI; theta += deltaTheta) {
|
||||
vec3 tempVec = cos(phi) * right + sin(phi) * up;
|
||||
vec3 sampleVector = cos(theta) * N + sin(theta) * tempVec;
|
||||
color += SampleEnvMap(sampleVector).rgb * cos(theta) * sin(theta);
|
||||
sampleCount++;
|
||||
}
|
||||
}
|
||||
return PI * color / float(sampleCount);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
ivec2 outCoords = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
vec2 texCoords = GetTexCoords(outCoords);
|
||||
vec3 pos3D = GetWorldPos(texCoords);
|
||||
vec4 outColor = vec4(ComputeIrradiance(pos3D), 1.0);
|
||||
|
||||
imageStore(outTexture, outCoords, outColor);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl DomeLight.Prefilter
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
layout(std140, binding=0) uniform Uniforms {
|
||||
float roughness;
|
||||
} uniforms;
|
||||
|
||||
// Normal Distribution function
|
||||
float Distribution_GGX(float dotNH, float roughness)
|
||||
{
|
||||
float alpha = roughness * roughness;
|
||||
float alpha2 = alpha * alpha;
|
||||
float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0;
|
||||
return (alpha2)/(PI * denom*denom);
|
||||
}
|
||||
|
||||
vec3 PrefilterEnvMap(vec3 R, float roughness)
|
||||
{
|
||||
vec3 N = R;
|
||||
vec3 V = R;
|
||||
vec3 color = vec3(0.0);
|
||||
float totalWeight = 0.0;
|
||||
float envMapDim = float(textureSize(inTexture, 0).s);
|
||||
const uint numSamples = 1024u;
|
||||
for (uint i = 0u; i < numSamples; i++) {
|
||||
vec2 Xi = Hammersley2d(i, numSamples);
|
||||
vec3 H = ImportanceSample_GGX(Xi, roughness, N);
|
||||
vec3 L = 2.0 * dot(V, H) * H - V;
|
||||
float dotNL = clamp(dot(N, L), 0.0, 1.0);
|
||||
if (dotNL > 0.0) {
|
||||
|
||||
float dotNH = clamp(dot(N, H), 0.0, 1.0);
|
||||
float dotVH = clamp(dot(V, H), 0.0, 1.0);
|
||||
|
||||
// Probability Distribution Function
|
||||
float pdf = Distribution_GGX(dotNH, roughness) * dotNH
|
||||
/ (4.0 * dotVH) + 0.0001;
|
||||
// Solid angle of current sample
|
||||
float omegaS = 1.0 / (float(numSamples) * pdf);
|
||||
// Solid angle of 1 pixel across all cube faces
|
||||
float omegaP = 4.0 * PI / (6.0 * envMapDim * envMapDim);
|
||||
// Biased (+1.0) mip level for better result
|
||||
float mipLevel = roughness == 0.0
|
||||
? 0.0 : max(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f);
|
||||
color += SampleEnvMapLod(L, mipLevel).rgb * dotNL;
|
||||
totalWeight += dotNL;
|
||||
|
||||
}
|
||||
}
|
||||
return (color / totalWeight);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
ivec2 outCoords = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
vec2 texCoords = GetTexCoords(outCoords);
|
||||
vec3 pos3D = GetWorldPos(texCoords);
|
||||
vec3 R = normalize(pos3D);
|
||||
vec4 outColor = vec4(PrefilterEnvMap(R, uniforms.roughness), 1.0);
|
||||
|
||||
imageStore(outTexture, outCoords, outColor);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl DomeLight.BRDF
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8) in;
|
||||
uniform int sampleLevel = 0;
|
||||
|
||||
float Geometry_SchlicksmithGGX(float dotNL, float dotNV, float roughness)
|
||||
{
|
||||
float k = (roughness * roughness) / 2.0;
|
||||
float GL = dotNL / (dotNL * (1.0 - k) + k);
|
||||
float GV = dotNV / (dotNV * (1.0 - k) + k);
|
||||
return GL * GV;
|
||||
}
|
||||
|
||||
vec2 ComputeBRDF(float NoV, float roughness)
|
||||
{
|
||||
// make sure NoV doesn't go exactly to 0 to avoid NaN
|
||||
NoV = max(NoV, 0.001);
|
||||
|
||||
// Normal always points along z-axis for the 2D lookup
|
||||
const vec3 N = vec3(0.0, 0.0, 1.0);
|
||||
vec3 V = vec3(sqrt(1.0 - NoV*NoV), 0.0, NoV);
|
||||
|
||||
vec2 LUT = vec2(0.0);
|
||||
const uint NUM_SAMPLES = 1024u;
|
||||
for (uint i = 0u; i < NUM_SAMPLES; i++) {
|
||||
vec2 Xi = Hammersley2d(i, NUM_SAMPLES);
|
||||
vec3 H = ImportanceSample_GGX(Xi, roughness, N);
|
||||
vec3 L = 2.0 * dot(V, H) * H - V;
|
||||
|
||||
float dotNL = max(dot(N, L), 0.0);
|
||||
float dotNV = max(dot(N, V), 0.0);
|
||||
float dotVH = max(dot(V, H), 0.0);
|
||||
float dotNH = max(dot(H, N), 0.0);
|
||||
|
||||
if (dotNL > 0.0) {
|
||||
float G = Geometry_SchlicksmithGGX(dotNL, dotNV, roughness);
|
||||
float G_Vis = (G * dotVH) / (dotNH * dotNV);
|
||||
float Fc = pow(1.0 - dotVH, 5.0);
|
||||
LUT += vec2((1.0 - Fc) * G_Vis, Fc * G_Vis);
|
||||
}
|
||||
}
|
||||
return LUT / float(NUM_SAMPLES);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
ivec2 outCoords = ivec2(gl_GlobalInvocationID.xy);
|
||||
|
||||
vec2 texCoords = GetTexCoords(outCoords);
|
||||
// texCoords.x represents N dot E and texCoords.y represents roughness
|
||||
vec4 outColor = vec4(ComputeBRDF(texCoords.x, texCoords.y), 0.0, 1.0);
|
||||
|
||||
imageStore(outTexture, outCoords, outColor);
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/edgeId.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.Fallback
|
||||
// Mixin version to use when mesh edge selection and highlighting is inactive.
|
||||
// Note: When rendering a mesh as points, this mixin isn't used. We handle it
|
||||
// in code gen.
|
||||
|
||||
int GetPrimitiveEdgeId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
float GetSelectedEdgeOpacity() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.Common
|
||||
|
||||
// Determines whether a fragment is on or close to an unhidden triangle edge.
|
||||
const float edgePickRadius = 2; // in viewport pixels
|
||||
const float edgePickParametricRadius = 0.02; // in parametric space
|
||||
|
||||
// For smooth looking edges, use an exponential falloff for the opacity.
|
||||
// Note: We use a slower falloff fn than in meshWire.glslfx to make the
|
||||
// selected edges stand out.
|
||||
float SelectedEdgeFalloff(float d) {
|
||||
return exp2(-1 * d * d);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.TriangleSurface
|
||||
|
||||
vec3 ComputeBaseFaceEdgeDistanceTriangle()
|
||||
{
|
||||
return GetEdgeDistanceTriangle();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.TriangleLines
|
||||
|
||||
vec3 ComputeBaseFaceEdgeDistanceTriangle()
|
||||
{
|
||||
// Use parametric distance since we can't use surface derivatives for lines
|
||||
vec3 param = GetEdgeParamTriangle();
|
||||
bvec3 nearEdge = lessThan(param, vec3(edgePickParametricRadius));
|
||||
return vec3(edgePickRadius) * vec3(not(nearEdge));
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.TriangleParam
|
||||
|
||||
float GetSelectedEdgeOpacity()
|
||||
{
|
||||
float closestEdgeDistance = 0.0;
|
||||
|
||||
// The sequence of comparisons should match GetPrimitiveEdgeId()
|
||||
vec3 dist = ComputeBaseFaceEdgeDistanceTriangle();
|
||||
if (dist.x < edgePickRadius) {
|
||||
closestEdgeDistance = dist.x;
|
||||
} else if (dist.y < edgePickRadius) {
|
||||
closestEdgeDistance = dist.y;
|
||||
} else if (dist.z < edgePickRadius) {
|
||||
closestEdgeDistance = dist.z;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return SelectedEdgeFalloff(closestEdgeDistance);
|
||||
}
|
||||
|
||||
// called from hdx/renderPass.glslfx and selection.glslfx
|
||||
int GetPrimitiveEdgeId()
|
||||
{
|
||||
// 2 (0,1,0)
|
||||
// ^
|
||||
// e2 / \ e1
|
||||
// / \'
|
||||
// (0,0,1) 0 ----- 1 (1,0,0)
|
||||
// e0
|
||||
|
||||
int edgeId = -1;
|
||||
|
||||
vec3 dist = ComputeBaseFaceEdgeDistanceTriangle();
|
||||
if (dist.x < edgePickRadius) {
|
||||
edgeId = 0;
|
||||
} else if (dist.y < edgePickRadius) {
|
||||
edgeId = 1;
|
||||
} else if (dist.z < edgePickRadius) {
|
||||
edgeId = 2;
|
||||
} else {
|
||||
return -1; // Not on a mesh edge
|
||||
}
|
||||
|
||||
const int edgeFlag = GetEdgeFlag();
|
||||
const int meshEdgeIndex = HdGet_edgeIndices().x;
|
||||
|
||||
// Translate face-edge to authored mesh-edge
|
||||
if (edgeFlag == 0) {
|
||||
edgeId = meshEdgeIndex + edgeId; // regular triangle face.
|
||||
} else if ((bool(edgeFlag & 1) && edgeId == 2) ||
|
||||
(bool(edgeFlag & 2) && edgeId == 0)) {
|
||||
edgeId = -1; // Not an authored mesh edge
|
||||
} else {
|
||||
edgeId = meshEdgeIndex + edgeId - 1;
|
||||
}
|
||||
return edgeId;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.QuadSurface
|
||||
|
||||
vec4 ComputeBaseFaceEdgeDistanceQuad()
|
||||
{
|
||||
return GetEdgeDistanceQuad();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.QuadLines
|
||||
|
||||
vec4 ComputeBaseFaceEdgeDistanceQuad()
|
||||
{
|
||||
// Use parametric distance since we can't use surface derivatives for lines
|
||||
vec4 param = GetEdgeParamQuad();
|
||||
bvec4 nearEdge = lessThan(param, vec4(edgePickParametricRadius));
|
||||
return vec4(edgePickRadius) * vec4(not(nearEdge));
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl EdgeId.Fragment.QuadParam
|
||||
|
||||
float GetSelectedEdgeOpacity()
|
||||
{
|
||||
float closestEdgeDistance = 0.0;
|
||||
|
||||
// The sequence of comparisons should match GetPrimitiveEdgeId()
|
||||
vec4 dist = ComputeBaseFaceEdgeDistanceQuad();
|
||||
if (dist.x < edgePickRadius) {
|
||||
closestEdgeDistance = dist.x;
|
||||
} else if (dist.y < edgePickRadius) {
|
||||
closestEdgeDistance = dist.y;
|
||||
} else if (dist.z < edgePickRadius) {
|
||||
closestEdgeDistance = dist.z;
|
||||
} else if (dist.w < edgePickRadius) {
|
||||
closestEdgeDistance = dist.w;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return SelectedEdgeFalloff(closestEdgeDistance);
|
||||
}
|
||||
|
||||
// called from hdx/renderPass.glslfx and selection.glslfx
|
||||
int GetPrimitiveEdgeId()
|
||||
{
|
||||
// e2
|
||||
// (0,1) 3 ------ 2 (1,1)
|
||||
// | |
|
||||
// e3 | | e1
|
||||
// | |
|
||||
// (0,0) 0 ------ 1 (1,0)
|
||||
// e0
|
||||
|
||||
int edgeId = -1;
|
||||
|
||||
vec4 dist = ComputeBaseFaceEdgeDistanceQuad();
|
||||
if (dist.x < edgePickRadius) {
|
||||
edgeId = 0;
|
||||
} else if (dist.y < edgePickRadius) {
|
||||
edgeId = 1;
|
||||
} else if (dist.z < edgePickRadius) {
|
||||
edgeId = 2;
|
||||
} else if (dist.w < edgePickRadius) {
|
||||
edgeId = 3;
|
||||
} else {
|
||||
return -1; // Not on a mesh edge
|
||||
}
|
||||
|
||||
const int edgeFlag = GetEdgeFlag();
|
||||
const ivec2 meshEdgeIndices = HdGet_edgeIndices();
|
||||
|
||||
// Translate face-edge to authored mesh-edge
|
||||
if (edgeFlag == 0) {
|
||||
edgeId = meshEdgeIndices[0] + edgeId; // regular quad face
|
||||
} else if (edgeId == 0) {
|
||||
edgeId = meshEdgeIndices[0];
|
||||
} else if (edgeId == 3) {
|
||||
edgeId = meshEdgeIndices[1];
|
||||
} else {
|
||||
edgeId = -1; // Not an authored mesh edge
|
||||
}
|
||||
return edgeId;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/fallbackLighting.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fallback.LightIntegrator
|
||||
#ifndef HD_HAS_integrateLights
|
||||
#define HD_HAS_integrateLights
|
||||
#endif
|
||||
|
||||
struct LightingContribution {
|
||||
vec3 diffuse;
|
||||
};
|
||||
|
||||
struct LightingInterfaceProperties {
|
||||
float unused;
|
||||
};
|
||||
|
||||
LightingContribution
|
||||
integrateLightsDefault(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
vec3 n = normalize(Neye);
|
||||
|
||||
LightingContribution result;
|
||||
result.diffuse = vec3(dot(n, vec3(0,0,1)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LightingContribution
|
||||
integrateLightsConstant(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
LightingContribution result;
|
||||
//pefectly diffuse white hemisphere contribution
|
||||
result.diffuse = vec3(1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-- glsl Fallback.Lighting
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props);
|
||||
|
||||
vec3 FallbackLighting(in vec3 Peye, in vec3 Neye, in vec3 color)
|
||||
{
|
||||
LightingInterfaceProperties props;
|
||||
LightingContribution light = integrateLights(vec4(Peye, 1), Neye, props);
|
||||
return color * light.diffuse;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/fallbackLightingShader.glslfx
|
||||
|
||||
#import $TOOLS/hdSt/shaders/fallbackLighting.glslfx
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"fragmentShader" : {
|
||||
"source": [
|
||||
"Fallback.LightIntegrator",
|
||||
"Fallback.Lighting"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/fallbackSurface.glslfx
|
||||
|
||||
---
|
||||
--- The fallback shader is used as a replacement shader if the
|
||||
--- original material shader failed to compile. It needs to
|
||||
--- define both the surfaceShader() and displacementShader() terminals.
|
||||
---
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"displacementShader": {
|
||||
"source": [ "Fallback.Displacement" ]
|
||||
},
|
||||
"surfaceShader": {
|
||||
"source": [ "Fallback.Surface" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fallback.Surface
|
||||
|
||||
vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)
|
||||
{
|
||||
// lighting
|
||||
color.rgb = FallbackLighting(Peye.xyz, Neye, color.rgb);
|
||||
return color;
|
||||
}
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fallback.Displacement
|
||||
|
||||
vec4 displacementShader(int index, vec4 Peye, vec3 Neye, vec4 patchCoord)
|
||||
{
|
||||
return Peye;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/fallbackVolume.glslfx
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"volumeShader": {
|
||||
"source": [ "FallbackVolume.VolumeShader" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl FallbackVolume.VolumeShader
|
||||
|
||||
// Functions that the volume shader of a volume material would provide.
|
||||
//
|
||||
// The functions give extinction, scattering, emission at a point as well as
|
||||
// a phase function such as Henyey-Greenstein (see, e.g., [1]).
|
||||
//
|
||||
// Only single scattering is taken into account and the result of the
|
||||
// scattering function (together with the phase function) is used to compute
|
||||
// the in-scattering component of the volume rendering equation for a light
|
||||
// source (point lights only).
|
||||
// The extinction function is supposed to return the sum of the
|
||||
// absorption and out-scattering cross section.
|
||||
// Note that the interpretation of emission here follows [1] (rather than [2]),
|
||||
// so the emission is added by the ray-marcher without being multiplied by
|
||||
// extinction.
|
||||
// Note that one cannot use the fallback volume shader for assets containing
|
||||
// "glow" rather "emission" where the convention is
|
||||
// emission = glow * extinction.
|
||||
//
|
||||
// [1] Matt Pharr, Wenzel Jakob, Greg Humphreys, "Physically Based Rendering",
|
||||
// Third Edition).
|
||||
// [2] Julian Fong, Magnus Wrenninge, Christopher Kulla, Ralf Habel,
|
||||
// "Production Volume Rendering", SIGGRAPH 2017 Course.
|
||||
|
||||
// The functions given here use a density and emission field with a fixed
|
||||
// albedo.
|
||||
//
|
||||
//
|
||||
|
||||
// Extinction function, returns sum of absorption and out-scattering cross
|
||||
// ratio.
|
||||
//
|
||||
float
|
||||
extinctionFunction(vec3 p)
|
||||
{
|
||||
return HdGet_density(p);
|
||||
}
|
||||
|
||||
// Scattering function, returns in-scattering cross-section (will be combined
|
||||
// with phase function).
|
||||
//
|
||||
// Here: constant on ellipsoid and zero outside.
|
||||
float
|
||||
scatteringFunction(vec3 p)
|
||||
{
|
||||
const float albedo = 0.18;
|
||||
|
||||
return extinctionFunction(p) * albedo;
|
||||
}
|
||||
|
||||
// Emission function, returns emission cross-section.
|
||||
//
|
||||
// Here: zero since volume is not emitting light.
|
||||
vec3
|
||||
emissionFunction(vec3 p)
|
||||
{
|
||||
return HdGet_emission(p);
|
||||
}
|
||||
|
||||
// Phase function in volume rendering equation.
|
||||
//
|
||||
// Here: isotropic.
|
||||
float
|
||||
phaseFunction(vec3 direction1, vec3 direction2)
|
||||
{
|
||||
const float pi = 3.14159265358979;
|
||||
const float sphereArea = 4.0 * pi;
|
||||
const float inverseSphereArea = 1.0 / sphereArea;
|
||||
|
||||
return inverseSphereArea;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/compute.glslfx
|
||||
|
||||
#import $TOOLS/hdSt/shaders/instancing.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ViewFrustumCull.Counting
|
||||
|
||||
layout (std430, binding = drawIndirectResult_Binding) buffer ResultData {
|
||||
int numVisibleInstances;
|
||||
};
|
||||
|
||||
void
|
||||
FrustumCullCountVisibleInstances(int resultInstanceCount)
|
||||
{
|
||||
atomicAdd(numVisibleInstances, resultInstanceCount);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ViewFrustumCull.NoCounting
|
||||
|
||||
void
|
||||
FrustumCullCountVisibleInstances(int resultInstanceCount)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ViewFrustumCull.NoTinyCull
|
||||
|
||||
bool
|
||||
FrustumCullIsTinyPrim(vec4 bboxMin, vec4 bboxMax, vec2 drawRangeNDC)
|
||||
{
|
||||
// do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ViewFrustumCull.TinyCull
|
||||
|
||||
bool
|
||||
FrustumCullIsTinyPrim(vec4 bboxMin, vec4 bboxMax, vec2 drawRangeNDC)
|
||||
{
|
||||
// Check the length of the min/max diagonal, could do something better here.
|
||||
vec2 ndcMin = (bboxMin.xy/max(.000001,bboxMin.w));
|
||||
vec2 ndcMax = (bboxMax.xy/max(.000001,bboxMax.w));
|
||||
float diag = distance(ndcMin, ndcMax);
|
||||
|
||||
// Cull prims outside the min(x)/max(y) range.
|
||||
// When max is negative, do not cull based on max size
|
||||
|
||||
#define isLargeEnough (diag > drawRangeNDC.x)
|
||||
#define isSmallEnough (drawRangeNDC.y < 0 || diag < drawRangeNDC.y)
|
||||
|
||||
return !isLargeEnough || !isSmallEnough;
|
||||
|
||||
#undef isLargeEnough
|
||||
#undef isSmallEnough
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ViewFrustumCull.IsVisible
|
||||
|
||||
bool
|
||||
FrustumCullIsVisible(MAT4 toClip, vec4 localMin, vec4 localMax, vec2 drawRangeNDC)
|
||||
{
|
||||
// Disable culling when:
|
||||
// (a) BBox is empty. An empty bbox defaults to [FLT_MAX, -FLT_MAX]), so
|
||||
// min > max.
|
||||
// (b) Bounds are infinite.
|
||||
if (any(greaterThan(localMin, localMax)) ||
|
||||
any(isinf(localMin)) || any(isinf(localMax))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Transform the corners of the bounding box to clipping space.
|
||||
vec4 p[8];
|
||||
p[0] = vec4(toClip * vec4(localMin.x, localMin.y, localMin.z, 1));
|
||||
p[2] = vec4(toClip * vec4(localMin.x, localMax.y, localMin.z, 1));
|
||||
p[5] = vec4(toClip * vec4(localMax.x, localMin.y, localMax.z, 1));
|
||||
p[7] = vec4(toClip * vec4(localMax.x, localMax.y, localMax.z, 1));
|
||||
|
||||
// This prim is visible if it wasn't culled and at least one tiny prim test
|
||||
// failed. Test two axes here because size is measured in screen space.
|
||||
// We front-load this test because it saves quite a bit of compute: in one
|
||||
// test the framerate went from 7.7 to 9.0 FPS.
|
||||
if (FrustumCullIsTinyPrim(p[0], p[7], drawRangeNDC) &&
|
||||
FrustumCullIsTinyPrim(p[2], p[5], drawRangeNDC))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finish computing points and perform frustum culling.
|
||||
p[1] = vec4(toClip * vec4(localMin.x, localMin.y, localMax.z, 1));
|
||||
p[3] = vec4(toClip * vec4(localMin.x, localMax.y, localMax.z, 1));
|
||||
p[4] = vec4(toClip * vec4(localMax.x, localMin.y, localMin.z, 1));
|
||||
p[6] = vec4(toClip * vec4(localMax.x, localMax.y, localMin.z, 1));
|
||||
|
||||
// Test the corners of the bounding box against the clipping volume.
|
||||
// clipFlags is effectively a 6-bit field, holding one bit of information
|
||||
// per frustum plane. Each component of the vector holds 2 bits.
|
||||
// If the bounding box overlaps the clip volume, then clipFlags will be
|
||||
// (0b11, 0b11, 0b11).
|
||||
ivec3 clipFlags = ivec3(0);
|
||||
for (int i=0; i<8; ++i) {
|
||||
vec4 clipPos = p[i];
|
||||
bvec3 clip0 = lessThan(clipPos.xyz, vec3(clipPos.w));
|
||||
bvec3 clip1 = greaterThan(clipPos.xyz, -vec3(clipPos.w));
|
||||
clipFlags |= ivec3(clip0) /* bit 0 */ + 2*ivec3(clip1) /*bit 1*/;
|
||||
}
|
||||
|
||||
return clipFlags == ivec3(3);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ViewFrustumCull.Vertex
|
||||
|
||||
layout (location = instanceCountInput_Binding) in int instanceCountInput;
|
||||
layout (location = drawCommandIndex_Binding) in int drawCommandIndex;
|
||||
|
||||
layout(std140, binding=ulocCullParams_Binding) uniform Uniforms {
|
||||
mat4 cullMatrix;
|
||||
vec2 drawRangeNDC;
|
||||
uint drawCommandNumUints;
|
||||
} cullParams;
|
||||
|
||||
layout (std430, binding = dispatchBuffer_Binding) buffer DispatchBuffer {
|
||||
uint drawCommands[];
|
||||
};
|
||||
|
||||
MAT4 GetCullMatrix()
|
||||
{
|
||||
return MAT4(cullParams.cullMatrix);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// instanceCountOffset is a relative offset in drawcommand struct.
|
||||
// it's a second entry in both DrawArraysCommand and DrawElementsCommand.
|
||||
const uint instanceCountOffset = 1;
|
||||
|
||||
MAT4 transform = HdGet_transform();
|
||||
MAT4 toClip = GetCullMatrix() * transform;
|
||||
|
||||
vec4 localMin = HdGet_bboxLocalMin();
|
||||
vec4 localMax = HdGet_bboxLocalMax();
|
||||
|
||||
bool isVisible = FrustumCullIsVisible(
|
||||
toClip, localMin, localMax, cullParams.drawRangeNDC);
|
||||
|
||||
// Compute the index to the 'instanceCount' struct member in drawCommands.
|
||||
uint index = uint(drawCommandIndex) *
|
||||
cullParams.drawCommandNumUints + instanceCountOffset;
|
||||
|
||||
// Set the resulting instance count to 0 if the primitive is culled
|
||||
// otherwise pass through the original incoming instance count.
|
||||
uint resultInstanceCount = instanceCountInput * uint(isVisible);
|
||||
drawCommands[index] = resultInstanceCount;
|
||||
|
||||
FrustumCullCountVisibleInstances(int(resultInstanceCount));
|
||||
}
|
||||
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ViewFrustumCull.VertexInstancing
|
||||
|
||||
/*
|
||||
per-instance culling
|
||||
|
||||
We use instance index indirection buffer to switch prototypes efficiently.
|
||||
Per-instance culling exploits this indirection to trim culled instances
|
||||
from draw call.
|
||||
|
||||
Example: Prototype mesh M is instanced for 5 instances.
|
||||
|
||||
Instancer has instance primvars (translate, rotate, ...)
|
||||
and index indirection for M.
|
||||
|
||||
InstancePrimvar (T:translate)
|
||||
+-------+-----------------------------+-----------+
|
||||
: |T0 T1 T2 T3 T4 T5 T6 T7 T8 T9| :
|
||||
+-------+-----------------------------+-----------+
|
||||
^
|
||||
InstanceIndices(for M) |
|
||||
+-----------+---------------+-----------+
|
||||
: | 0 2 5 8 9 | :
|
||||
+-----------+---------------+-----------+
|
||||
^
|
||||
|
|
||||
M: gl_InstanceID (0-5)
|
||||
|
||||
We can draw all instances of M, by just drawing with numInstance = 6.
|
||||
|
||||
For per-instance culling, we test each bbox against the frustum.
|
||||
Then, we store only passed instance indices into culledInstanceIndices buffer,
|
||||
as well as counting them.
|
||||
|
||||
InstanceIndices(for M)
|
||||
+-----------+---------------+-----------+
|
||||
: | 0 2 5 8 9 | : instanceCount = 5
|
||||
+-----------+---------------+-----------+
|
||||
V
|
||||
<Frustum culling> (say only 2 and 8 are visible in frustum)
|
||||
V
|
||||
+-----------+---------------+-----------+
|
||||
: | 2 8 x x x | : instanceCount = 2
|
||||
+-----------+---------------+-----------+
|
||||
x:undefined value
|
||||
*/
|
||||
|
||||
layout (location = drawCommandIndex_Binding) in int drawCommandIndex;
|
||||
|
||||
layout(std140, binding=ulocCullParams_Binding) uniform Uniforms {
|
||||
mat4 cullMatrix;
|
||||
vec2 drawRangeNDC;
|
||||
uint drawCommandNumUints;
|
||||
int resetPass;
|
||||
} cullParams;
|
||||
|
||||
layout (std430, binding = dispatchBuffer_Binding) buffer DispatchBuffer {
|
||||
uint drawCommands[];
|
||||
};
|
||||
|
||||
MAT4 GetCullMatrix()
|
||||
{
|
||||
return MAT4(cullParams.cullMatrix);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// instanceCountOffset is a relative offset in drawcommand struct.
|
||||
// it's a second entry in both DrawArraysCommand and DrawElementsCommand.
|
||||
const uint instanceCountOffset = 1;
|
||||
|
||||
// reset pass
|
||||
if (cullParams.resetPass == 1) {
|
||||
// note: we expect all instance invocations of this draw command is clearing
|
||||
// same field to zero, and intentionally chosen to not guard this access as atomic.
|
||||
drawCommands[drawCommandIndex * cullParams.drawCommandNumUints + instanceCountOffset] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// culling pass
|
||||
// precondition: drawCommand.instanceCount has to be reset in the separate
|
||||
// invocation unit.
|
||||
|
||||
vec4 localMin = HdGet_bboxLocalMin();
|
||||
vec4 localMax = HdGet_bboxLocalMax();
|
||||
|
||||
MAT4 toClip = GetCullMatrix() * ApplyInstanceTransform(HdGet_transform());
|
||||
|
||||
bool isVisible = FrustumCullIsVisible(
|
||||
toClip, localMin, localMax, cullParams.drawRangeNDC);
|
||||
|
||||
if (isVisible) {
|
||||
// increment the instance count and store instanceIndex to culledInstanceIndices.
|
||||
|
||||
uint id = atomicAdd(drawCommands[
|
||||
drawCommandIndex * cullParams.drawCommandNumUints +
|
||||
instanceCountOffset], 1);
|
||||
|
||||
SetCulledInstanceIndex(id);
|
||||
FrustumCullCountVisibleInstances(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/imageShader.glslfx
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"vertexShader" : {
|
||||
"source": [ "ImageShader.Vertex" ]
|
||||
},
|
||||
"fragmentShader" : {
|
||||
"source": [ "ImageShader.Fragment" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ImageShader.Vertex
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec2 uv;
|
||||
} outData;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// Position the vertices to create a large-than-screen triangle.
|
||||
// Adjust the UVs of the triangle to have 0-1 fit the screen exactly.
|
||||
// 'st' is the geometric UV where the [bottom,left] returns [0, 0].
|
||||
// Unlike gl_fragCoord where the [bottom,left] defaults to [0.5, 0.5].
|
||||
//
|
||||
// gl_VertexID=0 -> (-1,-1)
|
||||
// gl_VertexID=1 -> ( 3,-1)
|
||||
// gl_VertexID=2 -> (-1, 3)
|
||||
//
|
||||
// glDrawArrays( GL_TRIANGLES, 0, 3 );
|
||||
//
|
||||
// ID=2
|
||||
// x,y=-1,3
|
||||
// u,v=0,2
|
||||
// |\
|
||||
// | \
|
||||
// | \
|
||||
// | \
|
||||
// |--------\
|
||||
// | | \
|
||||
// | screen | \
|
||||
// | | \
|
||||
// ----------------
|
||||
// ID=0 ID=1
|
||||
// x,y=-1,-1 x,y=3,-1
|
||||
// u,v=0,0 u,v=2,0
|
||||
//
|
||||
//
|
||||
float x = -1.0 + float(((gl_VertexID%3) & 1) << 2);
|
||||
float y = -1.0 + float(((gl_VertexID%3) & 2) << 1);
|
||||
outData.uv.x = (x+1.0) * 0.5;
|
||||
outData.uv.y = (y+1.0) * 0.5;
|
||||
|
||||
gl_Position = vec4(x, y, 0, 1);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl ImageShader.Fragment
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec2 uv;
|
||||
} inData;
|
||||
|
||||
layout (location = 0) out vec4 colorOut;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
colorOut = imageShader(inData.uv);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/instancing.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Instancing.Transform
|
||||
|
||||
// quaternion to matrix. xyz = imaginary, w = real
|
||||
MAT4 GetRotationMatrix(vec4 q)
|
||||
{
|
||||
MAT4 r;
|
||||
r[0].xyzw = vec4(1 - 2 * (q.y * q.y + q.z * q.z),
|
||||
2 * (q.x * q.y + q.z * q.w),
|
||||
2 * (q.x * q.z - q.y * q.w),
|
||||
0);
|
||||
r[1].xyzw = vec4( 2 * (q.x * q.y - q.z * q.w),
|
||||
1 - 2 * (q.x * q.x + q.z * q.z),
|
||||
2 * (q.y * q.z + q.x * q.w),
|
||||
0);
|
||||
r[2].xyzw = vec4( 2 * (q.x * q.z + q.y * q.w),
|
||||
2 * (q.y * q.z - q.x * q.w),
|
||||
1 - 2 * (q.x * q.x + q.y * q.y),
|
||||
0);
|
||||
r[3] = vec4(0, 0, 0, 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
MAT4 GetInstanceTransform(int level)
|
||||
{
|
||||
MAT4 m = MAT4(1);
|
||||
#ifdef HD_HAS_INSTANCE_instanceTransform
|
||||
m = HdGetInstance_instanceTransform(level, MAT4(1)) * m;
|
||||
#endif
|
||||
|
||||
// instance transform elements are applied:
|
||||
// scale then rotate then translate
|
||||
// i.e. (T * R * S) * position
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_scale
|
||||
vec3 s = HdGetInstance_scale(level, /*default=*/vec3(1));
|
||||
m = MAT4(s.x, 0, 0, 0,
|
||||
0, s.y, 0, 0,
|
||||
0, 0, s.z, 0,
|
||||
0, 0, 0, 1) * m;
|
||||
#endif
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_rotate // GfQuat(ix, iy, iz, real)
|
||||
vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0));
|
||||
m = GetRotationMatrix(q) * m;
|
||||
#endif
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_translate
|
||||
vec3 t = HdGetInstance_translate(level, /*default=*/vec3(0));
|
||||
m = MAT4( 1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
t.x, t.y, t.z, 1) * m;
|
||||
#endif
|
||||
return m;
|
||||
}
|
||||
|
||||
MAT4 GetInstanceTransformInverse(int level)
|
||||
{
|
||||
MAT4 m = MAT4(1);
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_instanceTransform
|
||||
m = inverse(HdGetInstance_instanceTransform(level, MAT4(1))) * m;
|
||||
#endif
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_translate
|
||||
vec3 it = -HdGetInstance_translate(level, /*default=*/vec3(0)); // negate
|
||||
m = MAT4( 1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
it.x, it.y, it.z, 1) * m;
|
||||
#endif
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_rotate
|
||||
vec4 q = HdGetInstance_rotate(level, /*default=*/vec4(0));
|
||||
q.xyz = -q.xyz; // inverse rotataion axis
|
||||
m = GetRotationMatrix(q) * m;
|
||||
#endif
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_scale
|
||||
vec3 is = 1.0/HdGetInstance_scale(level, /*default=*/vec3(1)); // inverse scale
|
||||
m = MAT4(is.x, 0, 0, 0,
|
||||
0, is.y, 0, 0,
|
||||
0, 0, is.z, 0,
|
||||
0, 0, 0, 1) * m;
|
||||
#endif
|
||||
return m;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
MAT4 GetInstanceTransform()
|
||||
{
|
||||
MAT4 m = MAT4(1);
|
||||
#ifdef HD_INSTANCER_NUM_LEVELS
|
||||
for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) {
|
||||
m = GetInstanceTransform(i) * m;
|
||||
#ifdef HD_HAS_instancerTransform
|
||||
m = HdGet_instancerTransform(i) * m;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
return m;
|
||||
}
|
||||
|
||||
MAT4 GetInstanceTransformInverse()
|
||||
{
|
||||
MAT4 m = MAT4(1);
|
||||
#ifdef HD_INSTANCER_NUM_LEVELS
|
||||
for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) {
|
||||
m = m * GetInstanceTransformInverse(i);
|
||||
#ifdef HD_HAS_instancerTransformInverse
|
||||
m = m * HdGet_instancerTransformInverse(i);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
return m;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
MAT4 ApplyInstanceTransform(MAT4 m)
|
||||
{
|
||||
return GetInstanceTransform() * m;
|
||||
}
|
||||
|
||||
MAT4 ApplyInstanceTransformInverse(MAT4 m)
|
||||
{
|
||||
return m * GetInstanceTransformInverse();
|
||||
}
|
||||
|
||||
bool IsFlipped()
|
||||
{
|
||||
#if defined(HD_HAS_isFlipped)
|
||||
bool flip = (HdGet_isFlipped() != 0);
|
||||
#elif defined(HD_HAS_transform)
|
||||
// The sign of the determinant indicates whether m flips handedness
|
||||
bool flip = (determinant(HdGet_transform()) < 0.0);
|
||||
#else
|
||||
bool flip = false;
|
||||
#endif
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_scale
|
||||
for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) {
|
||||
vec3 scale = HdGetInstance_scale(i, /*default=*/vec3(1));
|
||||
flip = flip ^^ ((sign(scale.x) * sign(scale.y) * sign(scale.z)) < 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HD_HAS_INSTANCE_instanceTransform
|
||||
for (int i = 0; i < HD_INSTANCER_NUM_LEVELS; ++i) {
|
||||
MAT4 m = HdGetInstance_instanceTransform(i, MAT4(1));
|
||||
flip = flip ^^ (determinant(m) < 0.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return flip;
|
||||
}
|
||||
@@ -0,0 +1,709 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/mesh.glslfx
|
||||
|
||||
#import $TOOLS/hdSt/shaders/instancing.glslfx
|
||||
#import $TOOLS/hdSt/shaders/meshFaceCull.glslfx
|
||||
#import $TOOLS/hdSt/shaders/meshNormal.glslfx
|
||||
#import $TOOLS/hdSt/shaders/meshWire.glslfx
|
||||
#import $TOOLS/hdSt/shaders/terminals.glslfx
|
||||
#import $TOOLS/hdSt/shaders/edgeId.glslfx
|
||||
#import $TOOLS/hdSt/shaders/pointId.glslfx
|
||||
#import $TOOLS/hdSt/shaders/visibility.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.Vertex
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
out vec4 tesPatchCoord;
|
||||
out vec2 tesTessCoord;
|
||||
out vec4 gsPatchCoord;
|
||||
out vec2 gsTessCoord;
|
||||
|
||||
// Fwd declare methods defined in pointId.glslfx, that are used below.
|
||||
int GetPointId();
|
||||
float GetPointRasterSize(int);
|
||||
void ProcessPointId(int);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
ProcessPrimvars();
|
||||
|
||||
MAT4 transform = ApplyInstanceTransform(HdGet_transform());
|
||||
vec4 point = vec4(HdGet_points().xyz, 1);
|
||||
outData.Peye = vec4(GetWorldToViewMatrix() * transform * point);
|
||||
|
||||
outData.Neye = GetNormal(vec3(0), 0); // normalized
|
||||
|
||||
// Fill out redundantly, since at this point we don't know
|
||||
// the following stages include tessellation or geometry shader.
|
||||
// we rely on that compiler (linker) optimizes out these redundant
|
||||
// assignment and attribute plumbing.
|
||||
tesPatchCoord = gsPatchCoord = vec4(0);
|
||||
tesTessCoord = gsTessCoord = vec2(0);
|
||||
|
||||
int pointId = GetPointId();
|
||||
gl_PointSize = GetPointRasterSize(pointId);
|
||||
ProcessPointId(pointId);
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.TessControl.BSplineQuad
|
||||
|
||||
layout(vertices = HD_NUM_PATCH_EVAL_VERTS) out;
|
||||
|
||||
patch out vec4 tessOuterLo, tessOuterHi;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inpt[gl_MaxPatchVertices];
|
||||
|
||||
out VertexDataTess
|
||||
{
|
||||
OsdPerPatchVertexBezier v;
|
||||
} outpt[HD_NUM_PATCH_EVAL_VERTS];
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 cv[HD_NUM_PATCH_VERTS];
|
||||
for (int i = 0; i < HD_NUM_PATCH_VERTS; ++i) {
|
||||
cv[i] = inpt[i].Peye.xyz;
|
||||
}
|
||||
|
||||
ivec3 patchParam = GetPatchParam();
|
||||
|
||||
OsdComputePerPatchVertexBSpline(patchParam, gl_InvocationID, cv,
|
||||
outpt[gl_InvocationID].v);
|
||||
|
||||
// Wait for all basis conversion to be finished
|
||||
barrier();
|
||||
|
||||
if (gl_InvocationID == 0) {
|
||||
vec4 tessLevelOuter = vec4(0);
|
||||
vec2 tessLevelInner = vec2(0);
|
||||
|
||||
// Gather bezier control points to compute limit surface tess levels
|
||||
OsdPerPatchVertexBezier cpBezier[HD_NUM_PATCH_EVAL_VERTS];
|
||||
for (int i = 0; i < HD_NUM_PATCH_EVAL_VERTS; ++i) {
|
||||
cpBezier[i] = outpt[i].v;
|
||||
}
|
||||
OsdEvalPatchBezierTessLevels(cpBezier, patchParam,
|
||||
tessLevelOuter, tessLevelInner,
|
||||
tessOuterLo, tessOuterHi);
|
||||
|
||||
gl_TessLevelOuter[0] = tessLevelOuter[0];
|
||||
gl_TessLevelOuter[1] = tessLevelOuter[1];
|
||||
gl_TessLevelOuter[2] = tessLevelOuter[2];
|
||||
gl_TessLevelOuter[3] = tessLevelOuter[3];
|
||||
|
||||
gl_TessLevelInner[0] = tessLevelInner[0];
|
||||
gl_TessLevelInner[1] = tessLevelInner[1];
|
||||
}
|
||||
|
||||
ProcessPrimvars();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.TessEval.BezierQuad
|
||||
|
||||
layout(quads) in;
|
||||
|
||||
patch in vec4 tessOuterLo, tessOuterHi;
|
||||
|
||||
in VertexDataTess {
|
||||
OsdPerPatchVertexBezier v;
|
||||
} inpt[gl_MaxPatchVertices];
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
// XXX: due to NVIDIA shader compiler bug (filed as 1687344)
|
||||
// we can't put patchCoord into interface block.
|
||||
out vec4 tesPatchCoord;
|
||||
out vec2 tesTessCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
OsdPerPatchVertexBezier cv[16];
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
cv[i] = inpt[i].v;
|
||||
}
|
||||
vec2 UV = OsdGetTessParameterization(gl_TessCoord.xy,
|
||||
tessOuterLo,
|
||||
tessOuterHi);
|
||||
|
||||
vec3 P = vec3(0), dPu = vec3(0), dPv = vec3(0);
|
||||
vec3 N = vec3(0), dNu = vec3(0), dNv = vec3(0);
|
||||
|
||||
ivec3 patchParam = inpt[0].v.patchParam;
|
||||
OsdEvalPatchBezier(patchParam, UV, cv, P, dPu, dPv, N, dNu, dNv);
|
||||
|
||||
outData.Peye = vec4(P, 1);
|
||||
outData.Neye = N; // normalized
|
||||
|
||||
tesPatchCoord = OsdInterpolatePatchCoord(UV, patchParam);
|
||||
tesTessCoord = UV;
|
||||
|
||||
// Bilinear basis
|
||||
vec4 basis = vec4(
|
||||
(1.0-UV.x) * (1.0-UV.y), UV.x * (1.0-UV.y),
|
||||
(1.0-UV.x) * UV.y, UV.x * UV.y );
|
||||
|
||||
ProcessPrimvars(basis, 5, 6, 9, 10, UV);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.TessControl.BoxSplineTriangle
|
||||
|
||||
layout(vertices = HD_NUM_PATCH_EVAL_VERTS) out;
|
||||
|
||||
patch out vec4 tessOuterLo, tessOuterHi;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inpt[gl_MaxPatchVertices];
|
||||
|
||||
out VertexDataTess
|
||||
{
|
||||
OsdPerPatchVertexBezier v;
|
||||
} outpt[HD_NUM_PATCH_EVAL_VERTS];
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 cv[HD_NUM_PATCH_VERTS];
|
||||
for (int i = 0; i < HD_NUM_PATCH_VERTS; ++i) {
|
||||
cv[i] = inpt[i].Peye.xyz;
|
||||
}
|
||||
|
||||
ivec3 patchParam = GetPatchParam();
|
||||
|
||||
OsdComputePerPatchVertexBoxSplineTriangle(patchParam, gl_InvocationID, cv,
|
||||
outpt[gl_InvocationID].v);
|
||||
|
||||
// Wait for all basis conversion to be finished
|
||||
barrier();
|
||||
|
||||
if (gl_InvocationID == 0) {
|
||||
vec4 tessLevelOuter = vec4(0);
|
||||
vec2 tessLevelInner = vec2(0);
|
||||
|
||||
// Gather bezier control points to compute limit surface tess levels
|
||||
vec3 cpBezier[HD_NUM_PATCH_EVAL_VERTS];
|
||||
for (int i = 0; i < HD_NUM_PATCH_EVAL_VERTS; ++i) {
|
||||
cpBezier[i] = outpt[i].v.P;
|
||||
}
|
||||
OsdEvalPatchBezierTriangleTessLevels(cpBezier, patchParam,
|
||||
tessLevelOuter, tessLevelInner,
|
||||
tessOuterLo, tessOuterHi);
|
||||
|
||||
gl_TessLevelOuter[0] = tessLevelOuter[0];
|
||||
gl_TessLevelOuter[1] = tessLevelOuter[1];
|
||||
gl_TessLevelOuter[2] = tessLevelOuter[2];
|
||||
|
||||
gl_TessLevelInner[0] = tessLevelInner[0];
|
||||
}
|
||||
|
||||
ProcessPrimvars();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.TessEval.BezierTriangle
|
||||
|
||||
layout(triangles) in;
|
||||
|
||||
patch in vec4 tessOuterLo, tessOuterHi;
|
||||
|
||||
in VertexDataTess {
|
||||
OsdPerPatchVertexBezier v;
|
||||
} inpt[gl_MaxPatchVertices];
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
// XXX: due to NVIDIA shader compiler bug (filed as 1687344)
|
||||
// we can't put patchCoord into interface block.
|
||||
out vec4 tesPatchCoord;
|
||||
out vec2 tesTessCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
OsdPerPatchVertexBezier cv[15];
|
||||
for (int i = 0; i < 15; ++i) {
|
||||
cv[i] = inpt[i].v;
|
||||
}
|
||||
vec2 UV = OsdGetTessParameterizationTriangle(gl_TessCoord.xyz,
|
||||
tessOuterLo,
|
||||
tessOuterHi);
|
||||
|
||||
vec3 P = vec3(0), dPu = vec3(0), dPv = vec3(0);
|
||||
vec3 N = vec3(0), dNu = vec3(0), dNv = vec3(0);
|
||||
|
||||
ivec3 patchParam = inpt[0].v.patchParam;
|
||||
OsdEvalPatchBezierTriangle(patchParam, UV, cv, P, dPu, dPv, N, dNu, dNv);
|
||||
|
||||
outData.Peye = vec4(P, 1);
|
||||
outData.Neye = N; // normalized
|
||||
|
||||
tesPatchCoord = OsdInterpolatePatchCoordTriangle(UV, patchParam);
|
||||
tesTessCoord = UV;
|
||||
|
||||
// Barycentric basis
|
||||
vec4 basis = vec4(
|
||||
(1.0f-UV.x-UV.y), UV.x, UV.y, 0.0f);
|
||||
|
||||
ProcessPrimvars(basis, 4, 5, 8, 0, UV);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.Geometry.TriangleTess
|
||||
|
||||
layout(triangles) in;
|
||||
layout(triangle_strip, max_vertices = 3) out;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData[3];
|
||||
|
||||
in vec4 tesPatchCoord[3];
|
||||
in vec2 tesTessCoord[3];
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
out vec4 gsPatchCoord;
|
||||
out vec2 gsTessCoord;
|
||||
|
||||
|
||||
vec4 GetPatchCoord(int index)
|
||||
{
|
||||
return tesPatchCoord[index];
|
||||
}
|
||||
|
||||
void emit(int index, vec4 Peye, vec3 Neye)
|
||||
{
|
||||
outData.Peye = Peye;
|
||||
outData.Neye = Neye;
|
||||
gsPatchCoord = GetPatchCoord(index);
|
||||
gsTessCoord = vec2(0);
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
ProcessPrimvars(index, tesTessCoord[index]);
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
vec4 ComputeSelectionOffset(); // selection.glslfx
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_PrimitiveID = gl_PrimitiveIDIn;
|
||||
|
||||
bool isFlipped = IsFlipped(); // consider handedness AND negative-scale
|
||||
|
||||
vec3 Neye0 = isFlipped ? -inData[0].Neye : inData[0].Neye;
|
||||
Neye0 = GetNormal(Neye0, 0, tesTessCoord[0]);
|
||||
Neye0 = GetTriGeometryNormal(Neye0, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, isFlipped);
|
||||
vec3 Neye1 = isFlipped ? -inData[1].Neye : inData[1].Neye;
|
||||
Neye1 = GetNormal(Neye1, 0, tesTessCoord[1]);
|
||||
Neye1 = GetTriGeometryNormal(Neye1, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, isFlipped);
|
||||
vec3 Neye2 = isFlipped ? -inData[2].Neye : inData[2].Neye;
|
||||
Neye2 = GetNormal(Neye2, 0, tesTessCoord[2]);
|
||||
Neye2 = GetTriGeometryNormal(Neye2, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, isFlipped);
|
||||
|
||||
vec4 Peye0 = DisplacementTerminal(
|
||||
0, inData[0].Peye, Neye0, GetPatchCoord(0));
|
||||
vec4 Peye1 = DisplacementTerminal(
|
||||
1, inData[1].Peye, Neye1, GetPatchCoord(1));
|
||||
vec4 Peye2 = DisplacementTerminal(
|
||||
2, inData[2].Peye, Neye2, GetPatchCoord(2));
|
||||
|
||||
// For wireframe, add a polygon offset to selected faces to ensure they
|
||||
// rasterize over unselected faces.
|
||||
vec4 selOffset = ComputeSelectionOffset();
|
||||
Peye0 += selOffset;
|
||||
Peye1 += selOffset;
|
||||
Peye2 += selOffset;
|
||||
|
||||
// triangle 0: vertices (0,1,2)
|
||||
emit(0, Peye0, Neye0);
|
||||
emit(1, Peye1, Neye1);
|
||||
emit(2, Peye2, Neye2);
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.TessEval.VaryingInterpolation
|
||||
|
||||
float ProcessPrimvar(float inPv0, float inPv1, float inPv2, float inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return basis[0] * inPv0 +
|
||||
basis[1] * inPv1 +
|
||||
basis[2] * inPv2 +
|
||||
basis[3] * inPv3;
|
||||
}
|
||||
|
||||
vec2 ProcessPrimvar(vec2 inPv0, vec2 inPv1, vec2 inPv2, vec2 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return basis[0] * inPv0 +
|
||||
basis[1] * inPv1 +
|
||||
basis[2] * inPv2 +
|
||||
basis[3] * inPv3;
|
||||
}
|
||||
|
||||
vec3 ProcessPrimvar(vec3 inPv0, vec3 inPv1, vec3 inPv2, vec3 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return basis[0] * inPv0 +
|
||||
basis[1] * inPv1 +
|
||||
basis[2] * inPv2 +
|
||||
basis[3] * inPv3;
|
||||
}
|
||||
|
||||
vec4 ProcessPrimvar(vec4 inPv0, vec4 inPv1, vec4 inPv2, vec4 inPv3,
|
||||
vec4 basis, vec2 uv)
|
||||
{
|
||||
return basis[0] * inPv0 +
|
||||
basis[1] * inPv1 +
|
||||
basis[2] * inPv2 +
|
||||
basis[3] * inPv3;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.Geometry.Triangle
|
||||
|
||||
layout(triangles) in;
|
||||
layout(triangle_strip, max_vertices = 3) out;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData[3];
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
out vec4 gsPatchCoord;
|
||||
out vec2 gsTessCoord;
|
||||
|
||||
vec4 GetPatchCoord(int index)
|
||||
{
|
||||
vec2 uv[3];
|
||||
uv[0] = vec2(0, 0); // (0, 0, 1);
|
||||
uv[1] = vec2(1, 0); // (1, 0, 0);
|
||||
uv[2] = vec2(0, 1); // (0, 1, 0);
|
||||
|
||||
ivec3 patchParam = GetPatchParam();
|
||||
return OsdInterpolatePatchCoordTriangle(uv[index], patchParam);
|
||||
}
|
||||
|
||||
void emit(int index, vec4 Peye, vec3 Neye)
|
||||
{
|
||||
outData.Peye = Peye;
|
||||
outData.Neye = Neye;
|
||||
|
||||
gsPatchCoord = GetPatchCoord(index);
|
||||
gsTessCoord = vec2(0);
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
ProcessPrimvars(index);
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
vec4 ComputeSelectionOffset();
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_PrimitiveID = gl_PrimitiveIDIn;
|
||||
|
||||
bool isFlipped = IsFlipped(); // consider handedness AND negative-scale
|
||||
|
||||
vec3 Neye0 = GetNormal(inData[0].Neye, 0);
|
||||
Neye0 = GetTriGeometryNormal(Neye0, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, isFlipped);
|
||||
vec3 Neye1 = GetNormal(inData[1].Neye, 1);
|
||||
Neye1 = GetTriGeometryNormal(Neye1, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, isFlipped);
|
||||
vec3 Neye2 = GetNormal(inData[2].Neye, 2);
|
||||
Neye2 = GetTriGeometryNormal(Neye2, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, isFlipped);
|
||||
|
||||
vec4 Peye0 = DisplacementTerminal(
|
||||
0, inData[0].Peye, Neye0, GetPatchCoord(0));
|
||||
vec4 Peye1 = DisplacementTerminal(
|
||||
1, inData[1].Peye, Neye1, GetPatchCoord(1));
|
||||
vec4 Peye2 = DisplacementTerminal(
|
||||
2, inData[2].Peye, Neye2, GetPatchCoord(2));
|
||||
|
||||
// For wireframe, add a polygon offset to selected faces to ensure they
|
||||
// rasterize over unselected faces.
|
||||
vec4 selOffset = ComputeSelectionOffset();
|
||||
Peye0 += selOffset;
|
||||
Peye1 += selOffset;
|
||||
Peye2 += selOffset;
|
||||
|
||||
// triangle 0: vertices (0,1,2)
|
||||
emit(0, Peye0, Neye0);
|
||||
emit(1, Peye1, Neye1);
|
||||
emit(2, Peye2, Neye2);
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.Geometry.Quad
|
||||
|
||||
layout(lines_adjacency) in;
|
||||
layout(triangle_strip, max_vertices = 6) out;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData[4];
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} outData;
|
||||
|
||||
out vec4 gsPatchCoord;
|
||||
out vec2 gsTessCoord;
|
||||
|
||||
vec4 GetPatchCoord(int index)
|
||||
{
|
||||
vec2 uv[4];
|
||||
uv[0] = vec2(0, 0);
|
||||
uv[1] = vec2(1, 0);
|
||||
uv[2] = vec2(1, 1);
|
||||
uv[3] = vec2(0, 1);
|
||||
|
||||
ivec3 patchParam = GetPatchParam();
|
||||
return OsdInterpolatePatchCoord(uv[index], patchParam);
|
||||
}
|
||||
|
||||
void emit(int index, vec4 Peye, vec3 Neye)
|
||||
{
|
||||
outData.Peye = Peye;
|
||||
outData.Neye = Neye;
|
||||
|
||||
gsPatchCoord = GetPatchCoord(index);
|
||||
gsTessCoord = vec2(0);
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
ProcessPrimvars(index);
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
vec4 ComputeSelectionOffset();
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_PrimitiveID = gl_PrimitiveIDIn;
|
||||
|
||||
bool isFlipped = IsFlipped(); // consider handedness AND negative-scale
|
||||
|
||||
vec3 Neye0 = GetNormal(inData[0].Neye, 0);
|
||||
Neye0 = GetQuadGeometryNormal(Neye0, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, inData[3].Peye, isFlipped);
|
||||
vec3 Neye1 = GetNormal(inData[1].Neye, 1);
|
||||
Neye1 = GetQuadGeometryNormal(Neye1, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, inData[3].Peye, isFlipped);
|
||||
vec3 Neye2 = GetNormal(inData[2].Neye, 2);
|
||||
Neye2 = GetQuadGeometryNormal(Neye2, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, inData[3].Peye, isFlipped);
|
||||
vec3 Neye3 = GetNormal(inData[3].Neye, 3);
|
||||
Neye3 = GetQuadGeometryNormal(Neye3, inData[0].Peye, inData[1].Peye,
|
||||
inData[2].Peye, inData[3].Peye, isFlipped);
|
||||
|
||||
vec4 Peye0 = DisplacementTerminal(
|
||||
0, inData[0].Peye, Neye0, GetPatchCoord(0));
|
||||
vec4 Peye1 = DisplacementTerminal(
|
||||
1, inData[1].Peye, Neye1, GetPatchCoord(1));
|
||||
vec4 Peye2 = DisplacementTerminal(
|
||||
2, inData[2].Peye, Neye2, GetPatchCoord(2));
|
||||
vec4 Peye3 = DisplacementTerminal(
|
||||
3, inData[3].Peye, Neye3, GetPatchCoord(3));
|
||||
|
||||
// Generate triangles (3,0,2) and (1,2,0)
|
||||
// 3---2
|
||||
// | .|
|
||||
// | . |
|
||||
// |. |
|
||||
// 0---1
|
||||
// The indices post-quadrangulation/subdivision follow the convention:
|
||||
// 0 -> original (hull) vertex
|
||||
// 1,3 -> edge vertices
|
||||
// 2 -> center vertex
|
||||
//
|
||||
// By having index 2 in both the triangles, we ensure the pre-quadrangulated
|
||||
// face's normal (at the center) is part of the rasterizer interpolation,
|
||||
// which matters when we use smooth/limit normals.
|
||||
// In the case of flat normals, we use the vertex positions, so it doesn't
|
||||
// matter.
|
||||
|
||||
// For wireframe, add a polygon offset to selected faces to ensure they
|
||||
// rasterize over unselected faces.
|
||||
vec4 selOffset = ComputeSelectionOffset();
|
||||
Peye0 += selOffset;
|
||||
Peye1 += selOffset;
|
||||
Peye2 += selOffset;
|
||||
Peye3 += selOffset;
|
||||
|
||||
// triangle 0: vertices (3,0,2)
|
||||
emit(3, Peye3, Neye3);
|
||||
emit(0, Peye0, Neye0);
|
||||
emit(2, Peye2, Neye2);
|
||||
EndPrimitive();
|
||||
|
||||
// triangle 1: vertices (1,2,0)
|
||||
emit(1, Peye1, Neye1);
|
||||
emit(2, Peye2, Neye2);
|
||||
emit(0, Peye0, Neye0);
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Mesh.Fragment
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
vec3 Neye;
|
||||
} inData;
|
||||
|
||||
in vec4 gsPatchCoord;
|
||||
in vec2 gsTessCoord;
|
||||
|
||||
#ifndef HD_HAS_ptexFaceOffset
|
||||
#define HD_HAS_ptexFaceOffset
|
||||
int HdGet_ptexFaceOffset()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
vec4 GetPatchCoord(int localIndex)
|
||||
{
|
||||
return vec4(gsPatchCoord.xyz,
|
||||
gsPatchCoord.w + HdGet_ptexFaceOffset());
|
||||
}
|
||||
|
||||
vec3 ComputeScreenSpacePeye()
|
||||
{
|
||||
return inData.Peye.xyz / inData.Peye.w;
|
||||
}
|
||||
|
||||
vec3 ComputeScreenSpaceNeye()
|
||||
{
|
||||
vec3 Peye = ComputeScreenSpacePeye();
|
||||
vec3 Neye = normalize(cross(dFdx(Peye), dFdy(Peye)));
|
||||
return (gl_FrontFacing ? Neye : -Neye);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
bool isFlipped = IsFlipped();
|
||||
|
||||
DiscardBasedOnShading(gl_FrontFacing, isFlipped);
|
||||
|
||||
DiscardBasedOnTopologicalVisibility();
|
||||
|
||||
vec4 color = vec4(0.5, 0.5, 0.5, 1);
|
||||
#ifdef HD_HAS_displayColor
|
||||
color.rgb = HdGet_displayColor().rgb;
|
||||
#endif
|
||||
#ifdef HD_HAS_displayOpacity
|
||||
color.a = HdGet_displayOpacity().r;
|
||||
#endif
|
||||
|
||||
vec3 Peye = ComputeScreenSpacePeye();
|
||||
|
||||
vec3 Neye = inData.Neye;
|
||||
// Normalize Neye after rasterizer interpolation.
|
||||
if (length(Neye) > 0.0) {
|
||||
Neye = normalize(Neye);
|
||||
}
|
||||
// Give the shader key a chance to override the normal.
|
||||
Neye = GetNormal(Neye, 0);
|
||||
// Orient the normal for shading.
|
||||
Neye = GetShadingNormal(Neye, isFlipped);
|
||||
|
||||
vec4 patchCoord = GetPatchCoord();
|
||||
color = ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord);
|
||||
|
||||
color = ApplyEdgeColor(color, patchCoord);
|
||||
|
||||
#ifdef HD_MATERIAL_TAG_MASKED
|
||||
if (ShouldDiscardByAlpha(color)) {
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
RenderOutput(vec4(Peye, 1), Neye, color, patchCoord);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/meshFaceCull.glslfx
|
||||
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshFaceCull.Fragment.None
|
||||
|
||||
void DiscardBasedOnShading(bool frontFacing, bool isFlipped)
|
||||
{
|
||||
// Nothing to do since h/w face culling is used.
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshFaceCull.Fragment.SingleSided
|
||||
|
||||
void DiscardBasedOnShading(bool frontFacing, bool isFlipped)
|
||||
{
|
||||
if (ShouldCullFace(frontFacing ^^ isFlipped, /*doubleSided=*/false)) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshFaceCull.Fragment.DoubleSided
|
||||
|
||||
void DiscardBasedOnShading(bool frontFacing, bool isFlipped)
|
||||
{
|
||||
if (ShouldCullFace(frontFacing ^^ isFlipped, /*doubleSided=*/true)) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/meshNormal.glslfx
|
||||
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Scene
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index)
|
||||
{
|
||||
vec3 normal = vec3(0);
|
||||
#if defined(HD_HAS_normals)
|
||||
normal = vec3(HdGet_normals(index).xyz);
|
||||
#endif
|
||||
|
||||
MAT4 transformInv = ApplyInstanceTransformInverse(HdGet_transformInverse());
|
||||
normal = vec4(transpose(transformInv * GetWorldToViewInverseMatrix()) *
|
||||
vec4(normal,0)).xyz;
|
||||
|
||||
if (length(normal) > 0.0)
|
||||
normal = normalize(normal);
|
||||
return normal;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Scene.Patches
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index, vec2 localST)
|
||||
{
|
||||
vec3 normal = vec3(0);
|
||||
#if defined(HD_HAS_normals)
|
||||
normal = vec3(HdGet_normals(index, localST).xyz);
|
||||
#endif
|
||||
|
||||
MAT4 transformInv = ApplyInstanceTransformInverse(HdGet_transformInverse());
|
||||
normal = vec4(transpose(transformInv * GetWorldToViewInverseMatrix()) *
|
||||
vec4(normal,0)).xyz;
|
||||
|
||||
if (length(normal) > 0.0)
|
||||
normal = normalize(normal);
|
||||
return normal;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Smooth
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index)
|
||||
{
|
||||
vec3 normal = vec3(0);
|
||||
#if defined(HD_HAS_smoothNormals)
|
||||
normal = vec3(HdGet_smoothNormals(index).xyz);
|
||||
#elif defined(HD_HAS_packedSmoothNormals)
|
||||
normal = vec3(HdGet_packedSmoothNormals(index).xyz);
|
||||
#endif
|
||||
|
||||
MAT4 transformInv = ApplyInstanceTransformInverse(HdGet_transformInverse());
|
||||
normal = vec4(transpose(transformInv * GetWorldToViewInverseMatrix()) *
|
||||
vec4(normal,0)).xyz;
|
||||
|
||||
if (length(normal) > 0.0)
|
||||
normal = normalize(normal);
|
||||
return normal;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Flat
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index)
|
||||
{
|
||||
vec3 normal = vec3(0);
|
||||
#if defined(HD_HAS_flatNormals)
|
||||
normal = vec3(HdGet_flatNormals(index).xyz);
|
||||
#elif defined(HD_HAS_packedFlatNormals)
|
||||
normal = vec3(HdGet_packedFlatNormals(index).xyz);
|
||||
#endif
|
||||
|
||||
MAT4 transformInv = ApplyInstanceTransformInverse(HdGet_transformInverse());
|
||||
normal = vec4(transpose(transformInv * GetWorldToViewInverseMatrix()) *
|
||||
vec4(normal,0)).xyz;
|
||||
|
||||
if (length(normal) > 0.0)
|
||||
normal = normalize(normal);
|
||||
return normal;
|
||||
}
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index, vec2 localST)
|
||||
{
|
||||
return GetNormal(Neye, index);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Fragment.ScreenSpace
|
||||
|
||||
vec3 ComputeScreenSpaceNeye();
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index)
|
||||
{
|
||||
return ComputeScreenSpaceNeye();
|
||||
}
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index, vec2 localST)
|
||||
{
|
||||
return GetNormal(Neye, index);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Pass
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index)
|
||||
{
|
||||
return Neye;
|
||||
}
|
||||
|
||||
vec3 GetNormal(vec3 Neye, int index, vec2 localST)
|
||||
{
|
||||
return GetNormal(Neye, index);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Geometry.Flat
|
||||
|
||||
vec3 GetTriGeometryNormal(vec3 Neye, vec4 Peye0, vec4 Peye1, vec4 Peye2,
|
||||
bool isFlipped)
|
||||
{
|
||||
// ignore vertex normal and compute flat facing normal
|
||||
vec3 n = normalize(cross(Peye1.xyz - Peye0.xyz, Peye2.xyz - Peye0.xyz));
|
||||
return isFlipped ? -n : n;
|
||||
}
|
||||
|
||||
vec3 GetQuadGeometryNormal(vec3 Neye,
|
||||
vec4 Peye0, vec4 Peye1, vec4 Peye2, vec4 Peye3,
|
||||
bool isFlipped)
|
||||
{
|
||||
// 0---3
|
||||
// |. |
|
||||
// | . |
|
||||
// | .|
|
||||
// 1---2
|
||||
// ignore vertex normal and compute flat facing normal
|
||||
// average diagonal cross products to deal with co-linear edges
|
||||
vec3 A0 = Peye2.xyz - Peye3.xyz;
|
||||
vec3 B0 = Peye0.xyz - Peye3.xyz;
|
||||
vec3 A1 = Peye0.xyz - Peye1.xyz;
|
||||
vec3 B1 = Peye2.xyz - Peye1.xyz;
|
||||
vec3 n = normalize(cross(B0, A0) + cross(B1, A1));
|
||||
return isFlipped ? -n : n;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Geometry.NoFlat
|
||||
|
||||
vec3 GetTriGeometryNormal(vec3 Neye, vec4 Peye0, vec4 Peye1, vec4 Peye2,
|
||||
bool isFlipped)
|
||||
{
|
||||
return Neye;
|
||||
}
|
||||
|
||||
vec3 GetQuadGeometryNormal(vec3 Neye,
|
||||
vec4 Peye0, vec4 Peye1, vec4 Peye2, vec4 Peye3,
|
||||
bool isFlipped)
|
||||
{
|
||||
return Neye;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Fragment.SingleSided
|
||||
|
||||
vec3 GetShadingNormal(vec3 N, bool isFlipped)
|
||||
{
|
||||
// the fragment shader takes already-flipped-normals.
|
||||
// no need to flip here.
|
||||
return N;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshNormal.Fragment.DoubleSided
|
||||
|
||||
vec3 GetShadingNormal(vec3 N, bool isFlipped)
|
||||
{
|
||||
// note that negative scaling isn't taken into account in gl_FrontFacing
|
||||
// so we have to consider isFlipped here too.
|
||||
return (isFlipped ^^ gl_FrontFacing) ? N : -N;
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/meshWire.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeMaskTriangle
|
||||
|
||||
vec3 GetPrimitiveEdgeMask()
|
||||
{
|
||||
// see hd/meshUtil.cpp
|
||||
//
|
||||
// 0__ 0 0 0__
|
||||
// _/|\ \_ _/. .. . \_
|
||||
// _/ | \ \_ -> _/ . . . . \_
|
||||
// / A |C \ B \_ / A . .C . . B \_
|
||||
// 1-----2---3----4 1-----2 1---2 1----2
|
||||
//
|
||||
// Type EdgeFlag Draw
|
||||
// - 0 show all edges
|
||||
// A 1 hide [2-0]
|
||||
// B 2 hide [0-1]
|
||||
// C 3 hide [0-1] and [2-0]
|
||||
|
||||
// A value of one in this mask hides the corresponding edge.
|
||||
return vec3(0, GetEdgeFlag() & 1, GetEdgeFlag() & 2);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeMaskQuad
|
||||
|
||||
vec3 GetPrimitiveEdgeMask()
|
||||
{
|
||||
// see hd/meshUtil.cpp
|
||||
// Case EdgeFlag Draw
|
||||
// Quad/Refined face 0 hide common edge for the tri-pair
|
||||
// Non-Quad face 1/2/3 hide common edge for the tri-pair &
|
||||
// hide interior quadrangulated edges
|
||||
//
|
||||
// The first quad of a non-quad face is marked 1; the last as 2; and
|
||||
// intermediate quads as 3.
|
||||
//
|
||||
// 3...2
|
||||
// | ..
|
||||
// | . .
|
||||
// |. .
|
||||
// 0---1
|
||||
//
|
||||
|
||||
// A value of one in this mask hides the corresponding edge.
|
||||
return vec3(1, 0, GetEdgeFlag() != 0);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeMaskRefinedQuad
|
||||
|
||||
vec3 GetPrimitiveEdgeMask()
|
||||
{
|
||||
// Hide the common edge between the pair of rasterized triangles.
|
||||
return vec3(1,0,0);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeMaskNone
|
||||
|
||||
vec3 GetPrimitiveEdgeMask()
|
||||
{
|
||||
return vec3(0);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeCommon
|
||||
|
||||
vec3 GetBarycentricCoord(); // codeGen
|
||||
|
||||
// Returns the distance of the current fragment (in viewport pixel units) from
|
||||
// the nearest edge.
|
||||
float GetMinEdgeDistance()
|
||||
{
|
||||
// Hide triangle edges by adding edge mask.
|
||||
vec3 param = GetBarycentricCoord() + GetPrimitiveEdgeMask();
|
||||
vec3 edgeDistance = max(vec3(0.0), param / fwidth(param));
|
||||
return min(edgeDistance.x,
|
||||
min(edgeDistance.y,
|
||||
edgeDistance.z));
|
||||
}
|
||||
|
||||
// Use edge distance to compute a smooth opacity falloff for good looking edges.
|
||||
float GetEdgeFalloff(float d) {
|
||||
return exp2(-4 * d * d);
|
||||
}
|
||||
|
||||
float GetEdgeOpacity() {
|
||||
return GetEdgeFalloff(GetMinEdgeDistance());
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeParam
|
||||
|
||||
vec4 GetPatchCoord(int localIndex); // codeGen
|
||||
|
||||
vec3 GetEdgeParamTriangle()
|
||||
{
|
||||
// Expand barycentric coordinates
|
||||
vec2 param = GetPatchCoord(0).xy;
|
||||
vec3 barycentric = vec3(param.x, param.y, 1 - param.x - param.y);
|
||||
|
||||
// Match triangle edge order
|
||||
return barycentric.yzx;
|
||||
}
|
||||
|
||||
vec3 GetEdgeDistanceTriangle()
|
||||
{
|
||||
vec3 param = GetEdgeParamTriangle();
|
||||
return max(vec3(0.0), param / fwidth(param));
|
||||
}
|
||||
|
||||
vec4 GetEdgeParamQuad()
|
||||
{
|
||||
// Expand coordinates to opposite corners of quad
|
||||
vec2 leftBottom = GetPatchCoord(0).xy;
|
||||
vec2 rightTop = vec2(1.0) - leftBottom;
|
||||
|
||||
// Match quad edge order
|
||||
return vec4(leftBottom.y, rightTop.x, rightTop.y, leftBottom.x);
|
||||
}
|
||||
|
||||
vec4 GetEdgeDistanceQuad()
|
||||
{
|
||||
vec4 param = GetEdgeParamQuad();
|
||||
return max(vec4(0.0), param / fwidth(param));
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshPatchWire.Fragment.PatchEdgeTriangle
|
||||
|
||||
// Override for subdivided faces to make the boundary of the face stand out.
|
||||
float GetEdgeOpacityForPatch()
|
||||
{
|
||||
// Distance in pixels from triangle patch edges.
|
||||
vec3 patchEdgeDistance = GetEdgeDistanceTriangle();
|
||||
|
||||
const float patchEdgeMinDistance =
|
||||
min(patchEdgeDistance.x, min(patchEdgeDistance.y, patchEdgeDistance.z));
|
||||
|
||||
// Reduce the opacity of edges not on patch boundaries
|
||||
if (patchEdgeMinDistance > 1.0) {
|
||||
return 0.3 * GetEdgeOpacity();
|
||||
}
|
||||
|
||||
// Use distance to patch edge rather than distance to primitive edge
|
||||
return GetEdgeFalloff(patchEdgeMinDistance);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshPatchWire.Fragment.PatchEdgeQuad
|
||||
|
||||
// Override for subdivided faces to make the boundary of the face stand out.
|
||||
float GetEdgeOpacityForPatch()
|
||||
{
|
||||
// Distance in pixels from quad patch edges.
|
||||
vec4 patchEdgeDistance = GetEdgeDistanceQuad();
|
||||
|
||||
// Hide sub-patch internal edges introduced by quadrangulation
|
||||
if (GetEdgeFlag() != 0) patchEdgeDistance.yz += vec2(2.0);
|
||||
|
||||
const float patchEdgeMinDistance =
|
||||
min(min(patchEdgeDistance.x, patchEdgeDistance.y),
|
||||
min(patchEdgeDistance.z, patchEdgeDistance.w));
|
||||
|
||||
// Reduce the opacity of edges not on patch boundaries
|
||||
if (patchEdgeMinDistance > 1.0) {
|
||||
return 0.3 * GetEdgeOpacity();
|
||||
}
|
||||
|
||||
// Use distance to patch edge rather than distance to primitive edge
|
||||
return GetEdgeFalloff(patchEdgeMinDistance);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.NoEdge
|
||||
|
||||
vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord)
|
||||
{
|
||||
return Cfill;
|
||||
}
|
||||
|
||||
// Return a large value, signifying that the fragment isn't near an edge.
|
||||
float GetMinEdgeDistance()
|
||||
{
|
||||
return 1000.0;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeOnSurface
|
||||
|
||||
vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord)
|
||||
{
|
||||
float p = GetEdgeOpacity();
|
||||
|
||||
vec4 wireColor = GetWireframeColor();
|
||||
|
||||
// If wireColor is unset (zero), the fill color is just dimmed a bit.
|
||||
if (wireColor == vec4(0)) wireColor.a = 0.5;
|
||||
|
||||
vec4 Cedge = vec4(mix(Cfill.rgb, wireColor.rgb, wireColor.a), 1);
|
||||
Cfill.rgb = mix(Cfill.rgb, Cedge.rgb, p);
|
||||
|
||||
return Cfill;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeOnlyBlendColor
|
||||
|
||||
vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord)
|
||||
{
|
||||
float p = GetEdgeOpacity();
|
||||
if (p < 0.5) discard;
|
||||
|
||||
vec4 wireColor = GetWireframeColor();
|
||||
|
||||
// If wireColor is unset (zero), ignore it altogether
|
||||
|
||||
Cfill.rgb = mix(Cfill.rgb, wireColor.rgb, wireColor.a);
|
||||
Cfill.a = 1.0; // edges ignore input opacity and are opaque.
|
||||
|
||||
return Cfill;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshWire.Fragment.EdgeOnlyNoBlend
|
||||
|
||||
vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord)
|
||||
{
|
||||
float p = GetEdgeOpacity();
|
||||
if (p < 0.5) discard;
|
||||
|
||||
Cfill.a = 1.0; // edges ignore input opacity and are opaque.
|
||||
return Cfill;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshPatchWire.Fragment.EdgeOnSurface
|
||||
|
||||
vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord)
|
||||
{
|
||||
float p = GetEdgeOpacityForPatch();
|
||||
|
||||
vec4 wireColor = GetWireframeColor();
|
||||
|
||||
// If wireColor is unset (zero), the fill color is just dimmed a bit.
|
||||
if (wireColor == vec4(0)) wireColor.a = 0.5;
|
||||
|
||||
vec4 Cedge = vec4(mix(Cfill.rgb, wireColor.rgb, wireColor.a), 1);
|
||||
Cfill.rgb = mix(Cfill.rgb, Cedge.rgb, p);
|
||||
|
||||
return Cfill;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl MeshPatchWire.Fragment.EdgeOnly
|
||||
|
||||
vec4 ApplyEdgeColor(vec4 Cfill, vec4 patchCoord)
|
||||
{
|
||||
float p = GetEdgeOpacity();
|
||||
if (p < 0.5) discard;
|
||||
|
||||
Cfill.a = 1.0; // edges ignore input opacity and are opaque.
|
||||
|
||||
return Cfill;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/pointId.glslfx
|
||||
|
||||
#import $TOOLS/hdx/shaders/selection.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl PointId.Vertex.None
|
||||
|
||||
int GetPointId()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
float GetPointRasterSize(int pointId)
|
||||
{
|
||||
return GetPointSize();
|
||||
}
|
||||
|
||||
void ProcessPointId(int pointId)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl PointId.Vertex.PointParam
|
||||
|
||||
// Fwd declare accessor method defined via code gen
|
||||
int GetBaseVertexOffset();
|
||||
int GetPointId()
|
||||
{
|
||||
return gl_VertexID - GetBaseVertexOffset();
|
||||
}
|
||||
|
||||
// Fwd declare selection decoder method defined in hdx/shaders/selection.glslfx
|
||||
bool IsPointSelected(int);
|
||||
float GetPointRasterSize(int pointId)
|
||||
{
|
||||
return IsPointSelected(pointId)?
|
||||
GetPointSelectedSize() : GetPointSize();
|
||||
}
|
||||
|
||||
// Plumb the pointId, for use in the FS.
|
||||
// XXX: This works only because the TES and GS stages are disabled when
|
||||
// rendering as points. If they are enabled, we need to add the plumbing.
|
||||
flat out int vsPointId;
|
||||
void ProcessPointId(int pointId)
|
||||
{
|
||||
vsPointId = pointId;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl PointId.Fragment.Fallback
|
||||
|
||||
int GetPointId()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl PointId.Fragment.PointParam
|
||||
|
||||
flat in int vsPointId;
|
||||
|
||||
int GetPointId()
|
||||
{
|
||||
return vsPointId;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/points.glslfx
|
||||
|
||||
#import $TOOLS/hdSt/shaders/instancing.glslfx
|
||||
#import $TOOLS/hdSt/shaders/terminals.glslfx
|
||||
#import $TOOLS/hdSt/shaders/pointId.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Point.Vertex
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} outData;
|
||||
|
||||
// Fwd declare methods defined in pointId.glslfx, that are used below.
|
||||
int GetPointId();
|
||||
void ProcessPointId(int);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
MAT4 transform = ApplyInstanceTransform(HdGet_transform());
|
||||
vec4 point = vec4(HdGet_points().xyz, 1);
|
||||
|
||||
outData.Peye = vec4(GetWorldToViewMatrix() * transform * point);
|
||||
|
||||
ProcessPrimvars();
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * outData.Peye);
|
||||
ApplyClipPlanes(outData.Peye);
|
||||
|
||||
// check for primvar 'widths'
|
||||
#if defined(HD_HAS_widths)
|
||||
float pvWidth = HdGet_widths();
|
||||
#else
|
||||
float pvWidth = 1.0;
|
||||
#endif
|
||||
// scale width following prman's behavior
|
||||
vec4 w = vec4(transform * pvWidth * normalize(vec4(1,1,1,0)));
|
||||
float width = length(w.xyz);
|
||||
|
||||
// compute screenspace width
|
||||
vec4 diameter = vec4(GetProjectionMatrix() * vec4(width, 0, outData.Peye.z, 1));
|
||||
vec2 viewportScale = GetViewport().zw * 0.5;
|
||||
|
||||
gl_PointSize = clamp(viewportScale.x * diameter.x/diameter.w,
|
||||
HD_GL_POINT_SIZE_MIN, HD_GL_POINT_SIZE_MAX);
|
||||
|
||||
ProcessPointId(GetPointId());
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Point.Fragment
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec4 Peye;
|
||||
} inData;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 Peye = inData.Peye.xyz / inData.Peye.w;
|
||||
// camera facing.
|
||||
vec3 Neye = vec3(0, 0, 1);
|
||||
|
||||
vec4 color = vec4(0.5, 0.5, 0.5, 1);
|
||||
#ifdef HD_HAS_displayColor
|
||||
color.rgb = HdGet_displayColor().rgb;
|
||||
#endif
|
||||
#ifdef HD_HAS_displayOpacity
|
||||
color.a = HdGet_displayOpacity().r;
|
||||
#endif
|
||||
|
||||
vec4 patchCoord = vec4(0);
|
||||
color = ShadingTerminal(vec4(Peye, 1), Neye, color, patchCoord);
|
||||
|
||||
#ifdef HD_MATERIAL_TAG_MASKED
|
||||
if (ShouldDiscardByAlpha(color)) {
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
RenderOutput(vec4(Peye, 1), Neye, color, patchCoord);
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"ptexTextureSampler" : {
|
||||
"source": [
|
||||
"PtexTextureSampler"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-- glsl PtexTextureSampler
|
||||
|
||||
// ----- following code comes from OpenSubdiv/examples/common
|
||||
|
||||
struct PtexPacking {
|
||||
int page;
|
||||
int nMipmap;
|
||||
int uOffset;
|
||||
int vOffset;
|
||||
int adjSizeDiffs[4];
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
int computeMipmapOffsetU(int w, int level)
|
||||
{
|
||||
int width = 1 << w;
|
||||
int m = (0x55555555 & (width | (width-1))) << (w&1);
|
||||
int x = ~((1 << (w -((level-1)&~1))) - 1);
|
||||
return (m & x) + ((level+1)&~1);
|
||||
}
|
||||
|
||||
int computeMipmapOffsetV(int h, int level)
|
||||
{
|
||||
int height = 1 << h;
|
||||
int m = (0x55555555 & (height-1)) << ((h+1)&1);;
|
||||
int x = ~((1 << (h - (level&~1))) - 1 );
|
||||
return (m & x) + (level&~1);
|
||||
}
|
||||
|
||||
void evalQuadraticBSpline(float u, out float B[3], out float BU[3])
|
||||
{
|
||||
B[0] = 0.5 * (u*u - 2.0*u + 1);
|
||||
B[1] = 0.5 + u - u*u;
|
||||
B[2] = 0.5 * u*u;
|
||||
|
||||
BU[0] = u - 1.0;
|
||||
BU[1] = 1 - 2 * u;
|
||||
BU[2] = u;
|
||||
}
|
||||
|
||||
PtexPacking getPtexPacking(usampler1DArray packings, int faceID, int level)
|
||||
{
|
||||
const int layoutTexelsPerFace = 3;
|
||||
const int stride = textureSize(packings, 0).x;
|
||||
const int index = faceID * layoutTexelsPerFace;
|
||||
const int layer = index / stride;
|
||||
|
||||
const ivec2 packingIndex = ivec2(index - (layer * stride), layer);
|
||||
|
||||
const uvec2 page = texelFetch(packings, packingIndex+ivec2(0,0), 0).xy;
|
||||
const uvec2 offsets = texelFetch(packings, packingIndex+ivec2(1,0), 0).xy;
|
||||
const uvec2 sizes = texelFetch(packings, packingIndex+ivec2(2,0), 0).xy;
|
||||
|
||||
PtexPacking packing;
|
||||
packing.page = int(page.x);
|
||||
packing.nMipmap = int(page.y);
|
||||
packing.uOffset = int(offsets.x);
|
||||
packing.vOffset = int(offsets.y);
|
||||
|
||||
const int adjSizeDiffs = int(sizes.x);
|
||||
packing.adjSizeDiffs[0] = (adjSizeDiffs >> 12) & 0xf;
|
||||
packing.adjSizeDiffs[1] = (adjSizeDiffs >> 8) & 0xf;
|
||||
packing.adjSizeDiffs[2] = (adjSizeDiffs >> 4) & 0xf;
|
||||
packing.adjSizeDiffs[3] = (adjSizeDiffs >> 0) & 0xf;
|
||||
|
||||
const int wh = int(sizes.y);
|
||||
const int w = wh >> 8;
|
||||
const int h = wh & 0xff;
|
||||
|
||||
// clamp max level
|
||||
level = min(level, packing.nMipmap);
|
||||
|
||||
packing.width = 1 << (w-level);
|
||||
packing.height = 1 << (h-level);
|
||||
|
||||
if (level > 0) {
|
||||
packing.uOffset += computeMipmapOffsetU(w, level);
|
||||
packing.vOffset += computeMipmapOffsetV(h, level);
|
||||
}
|
||||
|
||||
return packing;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Non-Mipmap Lookups
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
vec4 PtexLookupNearest(vec4 patchCoord,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
vec2 uv = clamp(patchCoord.xy, vec2(0), vec2(1));
|
||||
int faceID = int(patchCoord.w);
|
||||
PtexPacking ppack = getPtexPacking(packings, faceID, 0);
|
||||
vec2 coords = vec2(uv.x * ppack.width + ppack.uOffset,
|
||||
uv.y * ppack.height + ppack.vOffset);
|
||||
return texelFetch(data, ivec3(int(coords.x), int(coords.y), ppack.page), 0);
|
||||
}
|
||||
|
||||
vec4 PtexLookupNearest(vec4 patchCoord,
|
||||
int level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
vec2 uv = clamp(patchCoord.xy, vec2(0), vec2(1));
|
||||
int faceID = int(patchCoord.w);
|
||||
PtexPacking ppack = getPtexPacking(packings, faceID, level);
|
||||
vec2 coords = vec2(uv.x * ppack.width + ppack.uOffset,
|
||||
uv.y * ppack.height + ppack.vOffset);
|
||||
return texelFetch(data, ivec3(int(coords.x), int(coords.y), ppack.page), 0);
|
||||
}
|
||||
|
||||
vec4 PtexLookupFast(vec4 patchCoord,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
vec2 uv = clamp(patchCoord.xy, vec2(0), vec2(1));
|
||||
int faceID = int(patchCoord.w);
|
||||
PtexPacking ppack = getPtexPacking(packings, faceID, 0);
|
||||
|
||||
ivec3 size = textureSize(data, 0);
|
||||
vec2 coords = vec2((uv.x * ppack.width + ppack.uOffset)/size.x,
|
||||
(uv.y * ppack.height + ppack.vOffset)/size.y);
|
||||
return texture(data, vec3(coords.x, coords.y, ppack.page));
|
||||
}
|
||||
|
||||
vec4 PtexLookupFast(vec4 patchCoord,
|
||||
int level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
vec2 uv = clamp(patchCoord.xy, vec2(0), vec2(1));
|
||||
int faceID = int(patchCoord.w);
|
||||
PtexPacking ppack = getPtexPacking(packings, faceID, level);
|
||||
|
||||
ivec3 size = textureSize(data, 0);
|
||||
vec2 coords = vec2((uv.x * ppack.width + ppack.uOffset)/size.x,
|
||||
(uv.y * ppack.height + ppack.vOffset)/size.y);
|
||||
return texture(data, vec3(coords.x, coords.y, ppack.page));
|
||||
}
|
||||
|
||||
vec4 PtexLookup(vec4 patchCoord,
|
||||
int level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
vec2 uv = clamp(patchCoord.xy, vec2(0), vec2(1));
|
||||
int faceID = int(patchCoord.w);
|
||||
PtexPacking ppack = getPtexPacking(packings, faceID, level);
|
||||
|
||||
vec2 coords = vec2(uv.x * ppack.width + ppack.uOffset,
|
||||
uv.y * ppack.height + ppack.vOffset);
|
||||
|
||||
coords -= vec2(0.5, 0.5);
|
||||
|
||||
int c0X = int(floor(coords.x));
|
||||
int c1X = int(ceil(coords.x));
|
||||
int c0Y = int(floor(coords.y));
|
||||
int c1Y = int(ceil(coords.y));
|
||||
|
||||
float t = coords.x - float(c0X);
|
||||
float s = coords.y - float(c0Y);
|
||||
|
||||
vec4 d0 = texelFetch(data, ivec3(c0X, c0Y, ppack.page), 0);
|
||||
vec4 d1 = texelFetch(data, ivec3(c0X, c1Y, ppack.page), 0);
|
||||
vec4 d2 = texelFetch(data, ivec3(c1X, c0Y, ppack.page), 0);
|
||||
vec4 d3 = texelFetch(data, ivec3(c1X, c1Y, ppack.page), 0);
|
||||
|
||||
vec4 result = (1-t) * ((1-s)*d0 + s*d1) + t * ((1-s)*d2 + s*d3);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vec4 PtexLookupQuadratic(out vec4 du,
|
||||
out vec4 dv,
|
||||
vec4 patchCoord,
|
||||
int level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
vec2 uv = clamp(patchCoord.xy, vec2(0), vec2(1));
|
||||
int faceID = int(patchCoord.w);
|
||||
PtexPacking ppack = getPtexPacking(packings, faceID, level);
|
||||
|
||||
vec2 coords = vec2(uv.x * ppack.width + ppack.uOffset,
|
||||
uv.y * ppack.height + ppack.vOffset);
|
||||
|
||||
coords -= vec2(0.5, 0.5);
|
||||
|
||||
int cX = int(round(coords.x));
|
||||
int cY = int(round(coords.y));
|
||||
|
||||
float x = 0.5 - (float(cX) - coords.x);
|
||||
float y = 0.5 - (float(cY) - coords.y);
|
||||
|
||||
vec4 d[9];
|
||||
d[0] = texelFetch(data, ivec3(cX-1, cY-1, ppack.page), 0);
|
||||
d[1] = texelFetch(data, ivec3(cX-1, cY-0, ppack.page), 0);
|
||||
d[2] = texelFetch(data, ivec3(cX-1, cY+1, ppack.page), 0);
|
||||
d[3] = texelFetch(data, ivec3(cX-0, cY-1, ppack.page), 0);
|
||||
d[4] = texelFetch(data, ivec3(cX-0, cY-0, ppack.page), 0);
|
||||
d[5] = texelFetch(data, ivec3(cX-0, cY+1, ppack.page), 0);
|
||||
d[6] = texelFetch(data, ivec3(cX+1, cY-1, ppack.page), 0);
|
||||
d[7] = texelFetch(data, ivec3(cX+1, cY-0, ppack.page), 0);
|
||||
d[8] = texelFetch(data, ivec3(cX+1, cY+1, ppack.page), 0);
|
||||
|
||||
float B[3], D[3];
|
||||
vec4 BUCP[3] = vec4[3](vec4(0,0,0,0), vec4(0,0,0,0), vec4(0,0,0,0)),
|
||||
DUCP[3] = vec4[3](vec4(0,0,0,0), vec4(0,0,0,0), vec4(0,0,0,0));
|
||||
evalQuadraticBSpline(y, B, D);
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
vec4 A = d[i*3+j];
|
||||
BUCP[i] += A * B[j];
|
||||
DUCP[i] += A * D[j];
|
||||
}
|
||||
}
|
||||
|
||||
evalQuadraticBSpline(x, B, D);
|
||||
|
||||
vec4 result = vec4(0);
|
||||
du = vec4(0);
|
||||
dv = vec4(0);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
result += B[i] * BUCP[i];
|
||||
du += D[i] * BUCP[i];
|
||||
dv += B[i] * DUCP[i];
|
||||
}
|
||||
|
||||
du *= ppack.width;
|
||||
dv *= ppack.height;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MipMap Lookups
|
||||
// ----------------------------------------------------------------------------
|
||||
vec4 PtexMipmapLookupNearest(vec4 patchCoord,
|
||||
float level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
#if defined(SEAMLESS_MIPMAP)
|
||||
// diff level
|
||||
int faceID = int(patchCoord.w);
|
||||
vec2 uv = patchCoord.xy;
|
||||
PtexPacking packing = getPtexPacking(packings, faceID);
|
||||
level += mix(mix(packing.adjSizeDiffs[0], packing.adjSizeDiffs[1], uv.x),
|
||||
mix(packing.adjSizeDiffs[3], packing.adjSizeDiffs[2], uv.x),
|
||||
uv.y);
|
||||
#endif
|
||||
|
||||
int levelm = int(floor(level));
|
||||
int levelp = int(ceil(level));
|
||||
float t = level - float(levelm);
|
||||
|
||||
vec4 result = (1-t) * PtexLookupNearest(patchCoord, levelm, data, packings)
|
||||
+ t * PtexLookupNearest(patchCoord, levelp, data, packings);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
vec4 PtexMipmapLookup(vec4 patchCoord,
|
||||
float level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
#if defined(SEAMLESS_MIPMAP)
|
||||
// diff level
|
||||
int faceID = int(patchCoord.w);
|
||||
vec2 uv = patchCoord.xy;
|
||||
PtexPacking packing = getPtexPacking(packings, faceID);
|
||||
level += mix(mix(packing.adjSizeDiffs[0], packing.adjSizeDiffs[1], uv.x),
|
||||
mix(packing.adjSizeDiffs[3], packing.adjSizeDiffs[2], uv.x),
|
||||
uv.y);
|
||||
#endif
|
||||
|
||||
int levelm = int(floor(level));
|
||||
int levelp = int(ceil(level));
|
||||
float t = level - float(levelm);
|
||||
|
||||
vec4 result = (1-t) * PtexLookup(patchCoord, levelm, data, packings)
|
||||
+ t * PtexLookup(patchCoord, levelp, data, packings);
|
||||
return result;
|
||||
}
|
||||
|
||||
vec4 PtexMipmapLookupQuadratic(out vec4 du,
|
||||
out vec4 dv,
|
||||
vec4 patchCoord,
|
||||
float level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
#if defined(SEAMLESS_MIPMAP)
|
||||
// diff level
|
||||
int faceID = int(patchCoord.w);
|
||||
vec2 uv = patchCoord.xy;
|
||||
PtexPacking packing = getPtexPacking(packings, faceID);
|
||||
level += mix(mix(packing.adjSizeDiffs[0], packing.adjSizeDiffs[1], uv.x),
|
||||
mix(packing.adjSizeDiffs[3], packing.adjSizeDiffs[2], uv.x),
|
||||
uv.y);
|
||||
#endif
|
||||
|
||||
int levelm = int(floor(level));
|
||||
int levelp = int(ceil(level));
|
||||
float t = level - float(levelm);
|
||||
|
||||
vec4 du0, du1, dv0, dv1;
|
||||
vec4 r0 = PtexLookupQuadratic(du0, dv0, patchCoord, levelm, data, packings);
|
||||
vec4 r1 = PtexLookupQuadratic(du1, dv1, patchCoord, levelp, data, packings);
|
||||
|
||||
vec4 result = mix(r0, r1, t);
|
||||
du = mix(du0, du1, t);
|
||||
dv = mix(dv0, dv1, t);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
vec4 PtexMipmapLookupQuadratic(vec4 patchCoord,
|
||||
float level,
|
||||
sampler2DArray data,
|
||||
usampler1DArray packings)
|
||||
{
|
||||
vec4 du, dv;
|
||||
return PtexMipmapLookupQuadratic(du, dv, patchCoord, level, data, packings);
|
||||
}
|
||||
|
||||
// end from OpenSubdiv/examples/common
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef HD_PTEX_TEXTURE_FACEOFFSET
|
||||
#define HD_PTEX_TEXTURE_FACEOFFSET
|
||||
uniform int ptexFaceOffset;
|
||||
#endif
|
||||
|
||||
vec4
|
||||
PtexTextureLookup(sampler2DArray data,
|
||||
usampler1DArray packings,
|
||||
vec4 patchCoord)
|
||||
{
|
||||
patchCoord.w += ptexFaceOffset;
|
||||
return PtexLookup(patchCoord,
|
||||
/*level = */0,
|
||||
data,
|
||||
packings);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/renderPass.glslfx
|
||||
|
||||
-- glsl RenderPass.Camera
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// global defines
|
||||
// ---------------------------------------------------------------------------
|
||||
// codeGen can override this range (currently not).
|
||||
// quadro 4000's max is 189.
|
||||
#ifndef HD_GL_POINT_SIZE_MAX
|
||||
#define HD_GL_POINT_SIZE_MAX 100.0
|
||||
#endif
|
||||
#ifndef HD_GL_POINT_SIZE_MIN
|
||||
#define HD_GL_POINT_SIZE_MIN .45
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// render pass states
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
MAT4 GetWorldToViewMatrix() {
|
||||
#if defined(HD_HAS_worldToViewMatrix)
|
||||
return MAT4(HdGet_worldToViewMatrix());
|
||||
#else
|
||||
return MAT4(1);
|
||||
#endif
|
||||
}
|
||||
MAT4 GetWorldToViewInverseMatrix() {
|
||||
#if defined(HD_HAS_worldToViewInverseMatrix)
|
||||
return MAT4(HdGet_worldToViewInverseMatrix());
|
||||
#else
|
||||
return MAT4(1);
|
||||
#endif
|
||||
}
|
||||
MAT4 GetProjectionMatrix() {
|
||||
#if defined(HD_HAS_projectionMatrix)
|
||||
return MAT4(HdGet_projectionMatrix());
|
||||
#else
|
||||
return MAT4(1);
|
||||
#endif
|
||||
}
|
||||
float GetLightingBlendAmount() {
|
||||
#if defined(HD_HAS_lightingBlendAmount)
|
||||
return HdGet_lightingBlendAmount();
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
vec4 GetViewport() {
|
||||
#if defined(HD_HAS_viewport)
|
||||
return HdGet_viewport();
|
||||
#else
|
||||
return vec4(0,0,1,1);
|
||||
#endif
|
||||
}
|
||||
float GetTessLevel() {
|
||||
#if defined(HD_HAS_tessLevel)
|
||||
return HdGet_tessLevel();
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
float GetPointSize() {
|
||||
#if defined(HD_HAS_pointSize)
|
||||
return HdGet_pointSize();
|
||||
#else
|
||||
return 3.0;
|
||||
#endif
|
||||
}
|
||||
float GetPointSelectedSize() {
|
||||
#if defined(HD_HAS_pointSelectedSize)
|
||||
return HdGet_pointSelectedSize();
|
||||
#else
|
||||
return 5.0;
|
||||
#endif
|
||||
}
|
||||
vec4 GetWireframeColor() {
|
||||
// Individual prims can specify an alternative wireframe color
|
||||
// to one specified in the render pass. This is used in cases were
|
||||
// there is not enough contrast with the normal one.
|
||||
#if defined(HD_HAS_overrideWireframeColor)
|
||||
return HdGet_overrideWireframeColor();
|
||||
#elif defined(HD_HAS_wireframeColor)
|
||||
return HdGet_wireframeColor();
|
||||
#else
|
||||
return vec4(0,0,0,0);
|
||||
#endif
|
||||
}
|
||||
vec4 GetMaskColor() {
|
||||
#if defined(HD_HAS_maskColor)
|
||||
return HdGet_maskColor();
|
||||
#else
|
||||
return vec4(0.5,0,0,1);
|
||||
#endif
|
||||
}
|
||||
vec4 GetIndicatorColor() {
|
||||
#if defined(HD_HAS_indicatorColor)
|
||||
return HdGet_indicatorColor();
|
||||
#else
|
||||
return vec4(0,0.5,0,1);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ShouldDiscardByAlpha(vec4 color)
|
||||
{
|
||||
#if defined(HD_HAS_alphaThreshold)
|
||||
float alphaThreshold = HdGet_alphaThreshold();
|
||||
#else
|
||||
float alphaThreshold = 0;
|
||||
#endif
|
||||
return (color.a < alphaThreshold);
|
||||
}
|
||||
|
||||
-- glsl RenderPass.ShouldCullFace
|
||||
|
||||
bool ShouldCullFace(bool frontFacing, bool doubleSided)
|
||||
{
|
||||
const uint HdCullStyleDontCare = uint(0);
|
||||
const uint HdCullStyleNothing = uint(1);
|
||||
const uint HdCullStyleBack = uint(2);
|
||||
const uint HdCullStyleFront = uint(3);
|
||||
const uint HdCullStyleBackUnlessDoubleSided = uint(4);
|
||||
const uint HdCullStyleFrontUnlessDoubleSided = uint(5);
|
||||
|
||||
#if defined(HD_HAS_cullStyle)
|
||||
uint cullStyle = HdGet_cullStyle();
|
||||
#else
|
||||
uint cullStyle = HdCullStyleNothing;
|
||||
#endif
|
||||
|
||||
return ((cullStyle == HdCullStyleBack && !frontFacing) ||
|
||||
(cullStyle == HdCullStyleFront && frontFacing) ||
|
||||
(cullStyle == HdCullStyleBackUnlessDoubleSided && !frontFacing && !doubleSided) ||
|
||||
(cullStyle == HdCullStyleFrontUnlessDoubleSided && frontFacing && !doubleSided));
|
||||
}
|
||||
|
||||
-- glsl RenderPass.ApplyClipPlanes
|
||||
|
||||
void ApplyClipPlanes(vec4 Peye)
|
||||
{
|
||||
#if defined(HD_HAS_clipPlanes)
|
||||
#if defined(HD_NUM_clipPlanes) // more than 1 (clipPlanes[N])
|
||||
for (int i=0; i<HD_NUM_clipPlanes; ++i) {
|
||||
gl_ClipDistance[i] = dot(HdGet_clipPlanes(i), Peye);
|
||||
}
|
||||
#else // only 1 (clipPlanes)
|
||||
gl_ClipDistance[0] = dot(HdGet_clipPlanes(), Peye);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
-- glsl RenderPass.NoColorOverrides
|
||||
|
||||
vec4 ApplyColorOverrides(vec4 color)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 ApplyMaskColor(vec3 color, float weight, vec4 maskColor)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 ApplyColorOverridesPostLighting(vec4 color)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
-- glsl RenderPass.NoSelection
|
||||
|
||||
vec4 ApplySelectionColor(vec4 color)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
-- glsl RenderPass.ApplyColorOverrides
|
||||
|
||||
// Forward declare selection functionality.
|
||||
// XXX: Currently, the non-empty implementation of this is in hdx.
|
||||
vec4 ApplySelectionColor(vec4 color);
|
||||
|
||||
// XXX: Make sure to update hdx/shaders/renderPass.glslfx when editing these
|
||||
// color override methods, since they're currently duplicated. This is because
|
||||
// we don't have a mixin token for color overrides in a render pass yet.
|
||||
vec4 ApplyColorOverrides(vec4 color)
|
||||
{
|
||||
#if defined(HD_HAS_overrideColor)
|
||||
// Mix in override color
|
||||
vec4 overrideColor = HdGet_overrideColor();
|
||||
color.rgb = mix(color.rgb, overrideColor.rgb, overrideColor.a);
|
||||
#endif
|
||||
return ApplySelectionColor(color);
|
||||
}
|
||||
|
||||
vec3 ApplyMaskColor(vec3 color, float weight, vec4 maskColor)
|
||||
{
|
||||
float strength = maskColor.a * clamp(weight, 0, 1);
|
||||
return mix(color, maskColor.rgb, strength);
|
||||
}
|
||||
|
||||
vec4 ApplyColorOverridesPostLighting(vec4 color)
|
||||
{
|
||||
#if defined(HD_HAS_maskWeight)
|
||||
float maskWeight = HdGet_maskWeight();
|
||||
vec4 maskColor = GetMaskColor();
|
||||
color.rgb = ApplyMaskColor(color.rgb, maskWeight, maskColor);
|
||||
#endif
|
||||
#if defined(HD_HAS_indicatorWeight)
|
||||
float indicatorWeight = HdGet_indicatorWeight();
|
||||
vec4 indicatorColor = GetIndicatorColor();
|
||||
color.rgb = ApplyMaskColor(color.rgb, indicatorWeight, indicatorColor);
|
||||
#endif
|
||||
return color;
|
||||
}
|
||||
|
||||
-- glsl RenderPass.RenderColor
|
||||
|
||||
layout (location = 0) out vec4 colorOut;
|
||||
|
||||
void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)
|
||||
{
|
||||
colorOut = color;
|
||||
}
|
||||
|
||||
-- glsl RenderPass.RenderId
|
||||
|
||||
// XXX: This whole snippet is a little sketchy and should ideally be replaced
|
||||
// with AoVs. We generate "primId" and "instanceId", and depending on how
|
||||
// the client called glDrawBuffers, they will get one or both.
|
||||
layout (location = 0) out vec4 primIdOut;
|
||||
layout (location = 1) out vec4 instanceIdOut;
|
||||
|
||||
vec4 IntToVec4(int id)
|
||||
{
|
||||
return vec4(((id >> 0) & 0xff) / 255.0,
|
||||
((id >> 8) & 0xff) / 255.0,
|
||||
((id >> 16) & 0xff) / 255.0,
|
||||
((id >> 24) & 0xff) / 255.0);
|
||||
}
|
||||
|
||||
void RenderOutput(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)
|
||||
{
|
||||
// Allow alpha threshold discard for ID renders regardless of material tag
|
||||
if (ShouldDiscardByAlpha(color)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
int primId = HdGet_primID();
|
||||
primIdOut = IntToVec4(primId);
|
||||
|
||||
// instanceIndex is a tuple of integers (num nested levels).
|
||||
// for picking, we store global instanceId (instanceIndex[0]) in the
|
||||
// selection framebuffer and then reconstruct the tuple in postprocess.
|
||||
int instanceId = GetDrawingCoord().instanceIndex[0];
|
||||
instanceIdOut = IntToVec4(instanceId);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/renderPassShader.glslfx
|
||||
|
||||
#import $TOOLS/hdSt/shaders/renderPass.glslfx
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"vertexShader" : {
|
||||
"source": [ "RenderPass.Camera",
|
||||
"RenderPass.ApplyClipPlanes" ]
|
||||
},
|
||||
"tessControlShader" : {
|
||||
"source": [ "RenderPass.Camera",
|
||||
"RenderPass.ApplyClipPlanes" ]
|
||||
},
|
||||
"tessEvalShader" : {
|
||||
"source": [ "RenderPass.Camera",
|
||||
"RenderPass.ApplyClipPlanes" ]
|
||||
},
|
||||
"geometryShader" : {
|
||||
"source": [ "RenderPass.Camera",
|
||||
"RenderPass.ApplyClipPlanes" ]
|
||||
},
|
||||
"fragmentShader" : {
|
||||
"source": [ "RenderPass.Camera",
|
||||
"RenderPass.ShouldCullFace",
|
||||
"RenderPass.NoSelection",
|
||||
"RenderPass.ApplyColorOverrides",
|
||||
"RenderPass.RenderColor" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/simpleLightingShader.glslfx
|
||||
|
||||
#import $TOOLS/glf/shaders/pcfShader.glslfx
|
||||
#import $TOOLS/glf/shaders/simpleLighting.glslfx
|
||||
|
||||
-- configuration
|
||||
{
|
||||
"techniques": {
|
||||
"default": {
|
||||
"fragmentShader" : {
|
||||
"source": [
|
||||
"PCF.ShadowFilterFragmentOnly",
|
||||
"SimpleLighting.LightIntegrator",
|
||||
"SimpleLighting.SimpleLighting",
|
||||
"LightingOverride.SimpleLighting"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-- glsl LightingOverride.SimpleLighting
|
||||
|
||||
vec3 FallbackLighting(in vec3 Peye, in vec3 Neye, in vec3 color)
|
||||
{
|
||||
return simpleLightingMaterial(
|
||||
vec4(color,1),
|
||||
vec4(Peye,1),
|
||||
Neye,
|
||||
vec4(1)).rgb;
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/terminals.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Geometry.CustomDisplacement
|
||||
|
||||
vec4 displacementShader(int index, vec4 Peye, vec3 Neye, vec4 patchCoord);
|
||||
|
||||
vec4 DisplacementTerminal(int index, vec4 Peye, vec3 Neye, vec4 patchCoord)
|
||||
{
|
||||
return displacementShader(index, Peye, Neye, patchCoord);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Geometry.NoCustomDisplacement
|
||||
|
||||
vec4 DisplacementTerminal(int index, vec4 Peye, vec3 Neye, vec4 patchCoord)
|
||||
{
|
||||
return Peye;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.CommonTerminals
|
||||
|
||||
struct ReprStyle
|
||||
{
|
||||
vec4 color;
|
||||
bool usePrimvarColor;
|
||||
bool usePrimvarAlpha;
|
||||
bool applyColorOverride;
|
||||
bool useSurfaceShaderColor;
|
||||
bool useSurfaceShaderAlpha;
|
||||
};
|
||||
|
||||
struct ScalarOverride
|
||||
{
|
||||
bool enabled;
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
ReprStyle GetReprStyle();
|
||||
ScalarOverride GetScalarOverride();
|
||||
vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord);
|
||||
vec4 postSurfaceShader(vec4 Peye, vec3 Neye, vec4 color);
|
||||
|
||||
vec4 ShadingTerminal(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)
|
||||
{
|
||||
ReprStyle reprStyle = GetReprStyle();
|
||||
|
||||
// Apply scalar override.
|
||||
ScalarOverride scalarOverride = GetScalarOverride();
|
||||
if (scalarOverride.enabled) {
|
||||
vec4 result;
|
||||
|
||||
result.rgb = scalarOverride.color;
|
||||
result.a = reprStyle.usePrimvarAlpha ? color.a: reprStyle.color.a;
|
||||
|
||||
vec4 colorOverride = ApplyColorOverrides(result);
|
||||
result = reprStyle.applyColorOverride ? colorOverride : result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Draw mode can override face color
|
||||
vec4 reprColor;
|
||||
|
||||
reprColor.rgb = reprStyle.usePrimvarColor ? color.rgb : reprStyle.color.rgb;
|
||||
reprColor.a = reprStyle.usePrimvarAlpha ? color.a : reprStyle.color.a;
|
||||
|
||||
// Compute color overrides
|
||||
vec4 colorOverride = ApplyColorOverrides(reprColor);
|
||||
reprColor = reprStyle.applyColorOverride ? colorOverride : reprColor;
|
||||
|
||||
|
||||
// Surface shading can be expensive and also can contain undesirable
|
||||
// side effects (like discards). So only run it for reprs that require it.
|
||||
|
||||
if (reprStyle.useSurfaceShaderColor ||
|
||||
reprStyle.useSurfaceShaderAlpha) {
|
||||
vec4 shadingColor;
|
||||
|
||||
shadingColor = surfaceShader(Peye,
|
||||
Neye,
|
||||
reprColor,
|
||||
patchCoord);
|
||||
|
||||
#ifdef HD_HAS_postSurfaceShader
|
||||
shadingColor = postSurfaceShader(Peye,
|
||||
Neye,
|
||||
shadingColor);
|
||||
#endif
|
||||
|
||||
reprColor.rgb = reprStyle.useSurfaceShaderColor ?
|
||||
shadingColor.rgb :
|
||||
reprColor.rgb;
|
||||
|
||||
reprColor.a = reprStyle.useSurfaceShaderAlpha ?
|
||||
shadingColor.a :
|
||||
reprColor.a;
|
||||
}
|
||||
|
||||
vec4 baseColor = color;
|
||||
baseColor = ApplyColorOverrides(baseColor);
|
||||
|
||||
vec4 litColor = mix(baseColor,
|
||||
reprColor,
|
||||
GetLightingBlendAmount());
|
||||
|
||||
// Final overrides.
|
||||
|
||||
return ApplyColorOverridesPostLighting(litColor);
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.Surface
|
||||
|
||||
#ifdef HD_HAS_integrateLights
|
||||
#ifndef HD_HAS_definedIntegrateLights
|
||||
#define HD_HAS_definedIntegrateLights
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
return integrateLightsDefault(Peye, Neye, props);
|
||||
}
|
||||
|
||||
#endif // HD_HAS_definedIntegrateLights
|
||||
#endif
|
||||
|
||||
ReprStyle GetReprStyle()
|
||||
{
|
||||
ReprStyle reprStyle;
|
||||
|
||||
reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
reprStyle.usePrimvarColor = true;
|
||||
reprStyle.usePrimvarAlpha = true;
|
||||
reprStyle.applyColorOverride = true;
|
||||
reprStyle.useSurfaceShaderColor = true;
|
||||
reprStyle.useSurfaceShaderAlpha = true;
|
||||
|
||||
return reprStyle;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.SurfaceUnlit
|
||||
|
||||
#ifdef HD_HAS_integrateLights
|
||||
#ifndef HD_HAS_definedIntegrateLights
|
||||
#define HD_HAS_definedIntegrateLights
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
return integrateLightsConstant(Peye, Neye, props);
|
||||
}
|
||||
|
||||
#endif // HD_HAS_definedIntegrateLights
|
||||
#endif
|
||||
|
||||
ReprStyle GetReprStyle()
|
||||
{
|
||||
ReprStyle reprStyle;
|
||||
|
||||
reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
reprStyle.usePrimvarColor = true;
|
||||
reprStyle.usePrimvarAlpha = true;
|
||||
reprStyle.applyColorOverride = true;
|
||||
reprStyle.useSurfaceShaderColor = true;
|
||||
reprStyle.useSurfaceShaderAlpha = true;
|
||||
|
||||
return reprStyle;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.SurfaceSheer
|
||||
|
||||
#ifdef HD_HAS_integrateLights
|
||||
#ifndef HD_HAS_definedIntegrateLights
|
||||
#define HD_HAS_definedIntegrateLights
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
return integrateLightsConstant(Peye, Neye, props);
|
||||
}
|
||||
|
||||
#endif // HD_HAS_definedIntegrateLights
|
||||
#endif
|
||||
|
||||
ReprStyle GetReprStyle()
|
||||
{
|
||||
// shade only every 2nd pixel in x and y
|
||||
// creating a thin stippled mesh grid
|
||||
float factor = step(0.5, fract((gl_FragCoord.x + 1.0) * 0.5))
|
||||
* step(0.5, fract((gl_FragCoord.y + 0.0) * 0.5));
|
||||
|
||||
// make the surface translucent so that the lines of
|
||||
// the mesh edges are visible even from the back faces.
|
||||
float alpha = 0.2 * (1.0 - factor);
|
||||
|
||||
|
||||
ReprStyle reprStyle;
|
||||
|
||||
reprStyle.color = vec4(0.0, 0.0, 0.0, alpha);
|
||||
reprStyle.usePrimvarColor = true;
|
||||
reprStyle.usePrimvarAlpha = false;
|
||||
reprStyle.applyColorOverride = true;
|
||||
reprStyle.useSurfaceShaderColor = true;
|
||||
reprStyle.useSurfaceShaderAlpha = false;
|
||||
|
||||
return reprStyle;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.SurfaceOutline
|
||||
|
||||
#ifdef HD_HAS_integrateLights
|
||||
#ifndef HD_HAS_definedIntegrateLights
|
||||
#define HD_HAS_definedIntegrateLights
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
return integrateLightsConstant(Peye, Neye, props);
|
||||
}
|
||||
|
||||
#endif // HD_HAS_definedIntegrateLights
|
||||
#endif
|
||||
|
||||
ReprStyle GetReprStyle()
|
||||
{
|
||||
ReprStyle reprStyle;
|
||||
|
||||
reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
reprStyle.usePrimvarColor = false;
|
||||
reprStyle.usePrimvarAlpha = false;
|
||||
reprStyle.applyColorOverride = false;
|
||||
reprStyle.useSurfaceShaderColor = false;
|
||||
reprStyle.useSurfaceShaderAlpha = false;
|
||||
|
||||
return reprStyle;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.ConstantColor
|
||||
|
||||
#ifdef HD_HAS_integrateLights
|
||||
#ifndef HD_HAS_definedIntegrateLights
|
||||
#define HD_HAS_definedIntegrateLights
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
return integrateLightsConstant(Peye, Neye, props);
|
||||
}
|
||||
|
||||
#endif // HD_HAS_definedIntegrateLights
|
||||
#endif
|
||||
|
||||
ReprStyle GetReprStyle()
|
||||
{
|
||||
ReprStyle reprStyle;
|
||||
|
||||
reprStyle.color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
reprStyle.usePrimvarColor = true;
|
||||
reprStyle.usePrimvarAlpha = true;
|
||||
reprStyle.applyColorOverride = true;
|
||||
reprStyle.useSurfaceShaderColor = false;
|
||||
reprStyle.useSurfaceShaderAlpha = false;
|
||||
|
||||
return reprStyle;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.HullColor
|
||||
|
||||
#ifdef HD_HAS_integrateLights
|
||||
#ifndef HD_HAS_definedIntegrateLights
|
||||
#define HD_HAS_definedIntegrateLights
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
return integrateLightsConstant(Peye, Neye, props);
|
||||
}
|
||||
|
||||
#endif // HD_HAS_definedIntegrateLights
|
||||
#endif
|
||||
|
||||
ReprStyle GetReprStyle()
|
||||
{
|
||||
vec4 hullColor = vec4(vec3(0.18), 1.0);
|
||||
|
||||
#if defined(HD_HAS_selectedWeight)
|
||||
float weight = clamp(HdGet_selectedWeight(), 0.0, 1.0);
|
||||
|
||||
if (weight <= 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// The three control points of the quadratic curve for the selection color
|
||||
// with the binomial coefficient premultiplied in.
|
||||
// constant : 1
|
||||
// linear : 1 1
|
||||
// quadratic : 1 2 1
|
||||
vec3 c0 = vec3(0.0, 0.0, 0.0); // 1.0 * Black
|
||||
vec3 c1 = vec3(2.0, 0.0, 0.0); // 2.0 * Red
|
||||
vec3 c2 = vec3(1.0, 1.0, 0.0); // 1.0 * Yellow
|
||||
|
||||
// de Casteljau quadratic curve interpolation
|
||||
// A recursive application of lerp ('mix' in glsl) reducing the order each
|
||||
// step of the recursion.
|
||||
// at weight = 0.0 we get c0
|
||||
// at weight = 0.5 we get c0 * .25 + c1 * 0.5 + c2 *.25
|
||||
// at weight = 1.0 we get c2
|
||||
// Thus it is a smooth curve going from c0 to c2 bending towards c1
|
||||
hullColor.rgb = mix(mix(c0, c1, weight),
|
||||
mix(c1, c2, weight), weight);
|
||||
|
||||
#else
|
||||
#if defined(HD_HAS_hullColor)
|
||||
hullColor.rgb = HdGet_hullColor();
|
||||
#endif
|
||||
#if defined(HD_HAS_hullOpacity)
|
||||
hullColor.a = HdGet_hullOpacity();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ReprStyle reprStyle;
|
||||
|
||||
reprStyle.color = hullColor;
|
||||
reprStyle.usePrimvarColor = false;
|
||||
reprStyle.usePrimvarAlpha = false;
|
||||
reprStyle.applyColorOverride = true;
|
||||
reprStyle.useSurfaceShaderColor = false;
|
||||
reprStyle.useSurfaceShaderAlpha = false;
|
||||
|
||||
return reprStyle;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.PointColor
|
||||
|
||||
#ifdef HD_HAS_integrateLights
|
||||
#ifndef HD_HAS_definedIntegrateLights
|
||||
#define HD_HAS_definedIntegrateLights
|
||||
|
||||
LightingContribution
|
||||
integrateLights(vec4 Peye, vec3 Neye, LightingInterfaceProperties props)
|
||||
{
|
||||
return integrateLightsConstant(Peye, Neye, props);
|
||||
}
|
||||
|
||||
#endif // HD_HAS_definedIntegrateLights
|
||||
#endif
|
||||
|
||||
ReprStyle GetReprStyle()
|
||||
{
|
||||
vec4 pointColor = vec4(vec3(0.18), 1.0);
|
||||
#if defined(HD_HAS_pointColor)
|
||||
pointColor = HdGet_pointColor();
|
||||
#endif
|
||||
|
||||
ReprStyle reprStyle;
|
||||
|
||||
reprStyle.color = pointColor;
|
||||
reprStyle.usePrimvarColor = false;
|
||||
reprStyle.usePrimvarAlpha = false;
|
||||
reprStyle.applyColorOverride = true;
|
||||
reprStyle.useSurfaceShaderColor = false;
|
||||
reprStyle.useSurfaceShaderAlpha = false;
|
||||
|
||||
return reprStyle;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.ScalarOverride
|
||||
|
||||
ScalarOverride GetScalarOverride()
|
||||
{
|
||||
ScalarOverride result;
|
||||
|
||||
#if defined(HD_HAS_scalarOverride)
|
||||
result.enabled = true;
|
||||
|
||||
// Allow a scalar value to override the color from the surface
|
||||
// for previewing heatmaps. This is useful for editing workflows.
|
||||
#if defined(HD_HAS_scalarOverrideColorRamp)
|
||||
int rampCount = constantPrimvars[GetDrawingCoord().constantCoord].
|
||||
scalarOverrideColorRamp.length();
|
||||
float scalar = HdGet_scalarOverride() * float(rampCount - 1);
|
||||
float baseIndex = floor(scalar);
|
||||
float nextIndex = min(float(rampCount - 1), baseIndex + 1.0);
|
||||
float interp = scalar - baseIndex;
|
||||
result.color = mix(HdGet_scalarOverrideColorRamp(int(baseIndex)).rgb,
|
||||
HdGet_scalarOverrideColorRamp(int(nextIndex)).rgb,
|
||||
interp);
|
||||
#else
|
||||
// If no ramp is given just gamma correct the scalar as greyscale.
|
||||
result.color = vec3(pow(HdGet_scalarOverride(), 2.2));
|
||||
#endif // HD_HAS_scalarOverrideColorRamp
|
||||
|
||||
#else // HD_HAS_scalarOverride
|
||||
result.enabled = false;
|
||||
result.color = vec3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Fragment.NoScalarOverride
|
||||
|
||||
ScalarOverride GetScalarOverride()
|
||||
{
|
||||
ScalarOverride result;
|
||||
|
||||
result.enabled = false;
|
||||
result.color = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/visibility.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Visibility.Fragment.Fallback
|
||||
void DiscardBasedOnTopologicalVisibility()
|
||||
{
|
||||
// Nothing to do, since there's no authored opinion.
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Visibility.Fragment.Topology
|
||||
|
||||
int GetElementID(); // code gen
|
||||
|
||||
void GetBitmaskBufferIndices(int id, out int arrayIndex, out int bitIndex)
|
||||
{
|
||||
arrayIndex = id / 32;
|
||||
bitIndex = id % 32;
|
||||
}
|
||||
|
||||
bool IsBitSet(uint bitmask, int bitIndex)
|
||||
{
|
||||
return bool(bitmask & (1 << bitIndex));
|
||||
}
|
||||
|
||||
bool IsElementVisible()
|
||||
{
|
||||
#if defined(HD_HAS_elementsVisibility)
|
||||
// Element (face) visibility is encoded as an array of bitmasks (uint32)
|
||||
// with 1 bit per authored face.
|
||||
int elementId = GetElementID();
|
||||
// When rendering a mesh as points, element id doesn't make sense. Code
|
||||
// gen returns -1 as a fallback for this case.
|
||||
if (elementId != -1) {
|
||||
int arrayIndex, bitIndex;
|
||||
GetBitmaskBufferIndices(elementId, arrayIndex, bitIndex);
|
||||
uint ev = HdGet_elementsVisibility(arrayIndex);
|
||||
return IsBitSet(ev, bitIndex);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int GetPointId(); // pointId.glslfx
|
||||
|
||||
bool IsPointVisible()
|
||||
{
|
||||
#if defined(HD_HAS_pointsVisibility)
|
||||
// Point visibility is encoded as an array of bitmasks (uint32) with 1 bit
|
||||
// per unrefined vertex.
|
||||
int pointId = GetPointId();
|
||||
// When *not* rendering a mesh as points, we return -1 for the point id.
|
||||
// See PointId.Fragment.Fallback
|
||||
if (pointId != -1) {
|
||||
int arrayIndex, bitIndex;
|
||||
GetBitmaskBufferIndices(pointId, arrayIndex, bitIndex);
|
||||
uint pv = HdGet_pointsVisibility(arrayIndex);
|
||||
return IsBitSet(pv, bitIndex);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void DiscardBasedOnTopologicalVisibility()
|
||||
{
|
||||
if (!IsElementVisible() || !IsPointVisible()) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,614 @@
|
||||
-- glslfx version 0.1
|
||||
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
|
||||
--- This is what an import might look like.
|
||||
--- #import $TOOLS/hdSt/shaders/volume.glslfx
|
||||
|
||||
#import $TOOLS/hdSt/shaders/instancing.glslfx
|
||||
#import $TOOLS/hdSt/shaders/pointId.glslfx
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Volume.Vertex
|
||||
|
||||
out VertexData
|
||||
{
|
||||
// Relying on perspectively correct interpolation.
|
||||
vec3 Peye;
|
||||
} outData;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// Bounding box vertex in local spce
|
||||
const vec4 point = vec4(HdGet_points().xyz, 1);
|
||||
|
||||
const MAT4 transform = ApplyInstanceTransform(HdGet_transform());
|
||||
|
||||
// Bounding box vertex in eye space.
|
||||
const vec4 pointEye = vec4(GetWorldToViewMatrix() * transform * point);
|
||||
|
||||
outData.Peye = pointEye.xyz / pointEye.w;
|
||||
|
||||
gl_Position = vec4(GetProjectionMatrix() * pointEye);
|
||||
|
||||
ProcessPrimvars();
|
||||
}
|
||||
|
||||
--- --------------------------------------------------------------------------
|
||||
-- glsl Volume.Fragment
|
||||
|
||||
// Quality knobs, should eventually be configurable.
|
||||
//
|
||||
// We also might have different values for the raymarch
|
||||
// integrating the pixel value and for the raymarch doing
|
||||
// the lighting computation.
|
||||
|
||||
const int maxNumSteps = 10000;
|
||||
|
||||
// Min transmittance (ray marching stops when underrun)
|
||||
const float minTransmittance = 0.002;
|
||||
|
||||
// Minimal scattering amount to ray march to light
|
||||
const float minScattering = 0.002;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Peye;
|
||||
} inData;
|
||||
|
||||
// Eye space to local space.
|
||||
// Used frequently per ray-marching step in both volumeIntegrator
|
||||
// and accumulatedTransmittance, so computed only once in main.
|
||||
//
|
||||
MAT4 instanceModelViewInverse;
|
||||
// Eye space to volume bounding box space
|
||||
mat4 eyeToBBox;
|
||||
float resolvedStepSizeEye;
|
||||
float resolvedStepSizeEyeLighting;
|
||||
float resolvedStepSizeWorld;
|
||||
float resolvedStepSizeWorldLighting;
|
||||
|
||||
// Transform a point by a 4x4 matrix
|
||||
vec3
|
||||
transformPoint(mat4 m, vec3 point)
|
||||
{
|
||||
const vec4 result = vec4(m * vec4(point, 1.0));
|
||||
return result.xyz / result.w;
|
||||
}
|
||||
|
||||
vec3
|
||||
transformPoint(dmat4 m, vec3 point)
|
||||
{
|
||||
const vec4 result = vec4(m * vec4(point, 1.0));
|
||||
return result.xyz / result.w;
|
||||
}
|
||||
|
||||
// Transform a direction by a 4x4 matrix
|
||||
vec3
|
||||
transformDir(mat4 m, vec3 dir)
|
||||
{
|
||||
const vec4 result = vec4(m * vec4(dir, 0.0));
|
||||
return result.xyz;
|
||||
}
|
||||
|
||||
vec3
|
||||
transformDir(dmat4 m, vec3 dir)
|
||||
{
|
||||
const vec4 result = vec4(m * vec4(dir, 0.0));
|
||||
return result.xyz;
|
||||
}
|
||||
|
||||
// Compute time when a ray starting at pos with direction dir
|
||||
// exits the axis-aligned box with vertices lMin and lMax.
|
||||
//
|
||||
// Assumes that dir.x isn't close to zero.
|
||||
float
|
||||
timeRayExitsBoxPreferX(vec3 pos, vec3 dir, vec3 lMin, vec3 lMax)
|
||||
{
|
||||
// Compute the time when the ray exists the region
|
||||
// R1 = [xMin, xMax] x [-inf,inf] x [-inf,inf].
|
||||
|
||||
// Depending on whether the the ray is going left or right, compute
|
||||
// the time when the ray is intersecting the plane containing the
|
||||
// left or right face of the box.
|
||||
float result = (((dir.x > 0.0) ? lMax.x : lMin.x) - pos.x) / dir.x;
|
||||
|
||||
// Compute the time when the ray exists the region
|
||||
// R2 = [xMin, xMax] x [yMin,yMax] x [-inf,inf].
|
||||
|
||||
// We can compute the intersection where the ray left R1 as
|
||||
// pos + dir * result.
|
||||
// If this intersection is above or below the box, we know that there
|
||||
// is an earlier intersection of the ray with the plane containing
|
||||
// the top or bottom face of the box, compute that intersection time.
|
||||
const float y = pos.y + dir.y * result;
|
||||
if (y < lMin.y) {
|
||||
result = (lMin.y - pos.y) / dir.y;
|
||||
}
|
||||
if (y > lMax.y) {
|
||||
result = (lMax.y - pos.y) / dir.y;
|
||||
}
|
||||
|
||||
// Compute the time when the ray exists the region
|
||||
// R3 = [xMin, xMax] x [yMin,yMax] x [zMin,zMax].
|
||||
|
||||
// Analogous procedure to above.
|
||||
const float z = pos.z + dir.z * result;
|
||||
if (z < lMin.z) {
|
||||
result = (lMin.z - pos.z) / dir.z;
|
||||
}
|
||||
if (z > lMax.z) {
|
||||
result = (lMax.z - pos.z) / dir.z;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Compute time when a ray starting at pos with direction dir
|
||||
// exits the axis-aligned box with vertices lMin and lMax.
|
||||
//
|
||||
// Assumes that dir is normalized.
|
||||
float
|
||||
timeRayExitsBox(vec3 pos, vec3 dir, vec3 lMin, vec3 lMax)
|
||||
{
|
||||
// Uses timeRayExitsBoxPreferX after permuting the coordinates
|
||||
// to make sure that x is not close to zero.
|
||||
//
|
||||
// Note that because dir has unit length, at least one of its entries
|
||||
// has absolute value larger 1/2 ( (1/2)^2 + (1/2)^2 + (1/2)^2 < 1^2).
|
||||
|
||||
const vec3 abs_dir = abs(dir);
|
||||
if (abs_dir.x > 0.5) {
|
||||
return timeRayExitsBoxPreferX(
|
||||
pos , dir , lMin , lMax );
|
||||
}
|
||||
if (abs_dir.y > 0.5) {
|
||||
return timeRayExitsBoxPreferX(
|
||||
pos.yzx, dir.yzx, lMin.yzx, lMax.yzx);
|
||||
}
|
||||
|
||||
return timeRayExitsBoxPreferX(
|
||||
pos.zxy, dir.zxy, lMin.zxy, lMax.zxy);
|
||||
}
|
||||
|
||||
// Given a ray in eye space starting inside a volume, compute the time when it
|
||||
// exists the volume (assuming rayDirectionEye is normalized).
|
||||
float
|
||||
timeRayExitsVolume(vec3 rayStartEye, vec3 rayDirectionEye)
|
||||
{
|
||||
// Transform ray to volume bounding box space
|
||||
const vec3 rayStartBBox = transformPoint(eyeToBBox, rayStartEye);
|
||||
const vec3 rayDirectionBBox = transformDir (eyeToBBox, rayDirectionEye);
|
||||
|
||||
// Compute when ray is leaving the volume bounding box
|
||||
return timeRayExitsBox(rayStartBBox,
|
||||
rayDirectionBBox,
|
||||
vec3(HdGet_volumeBBoxLocalMin().xyz),
|
||||
vec3(HdGet_volumeBBoxLocalMax().xyz));
|
||||
|
||||
}
|
||||
|
||||
// Given a ray in eye space, compute the time when it entered the volume
|
||||
// (assuming rayDirectionEye is normalized).
|
||||
// Note that it is assumed that the ray point is in the volume and that the
|
||||
// result will be negative.
|
||||
float
|
||||
timeRayEnteredVolume(vec3 rayEndEye, vec3 rayDirectionEye)
|
||||
{
|
||||
// Compute when reversed ray is exiting the volume bounding box
|
||||
return - timeRayExitsVolume(rayEndEye, -rayDirectionEye);
|
||||
}
|
||||
|
||||
vec3
|
||||
coordsToLocalVolumeSpace(vec3 coords)
|
||||
{
|
||||
return transformPoint(instanceModelViewInverse, coords);
|
||||
}
|
||||
|
||||
#if NUM_LIGHTS == 0
|
||||
|
||||
vec3
|
||||
lightingComputation(vec3 rayPointEye, vec3 rayDirectionEye)
|
||||
{
|
||||
return vec3(0.0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Compute how the transmittance of volume from Peye to a
|
||||
// light source in the given direction rayDirection.
|
||||
// This integrates the density from Peye to the boundary of
|
||||
// the volume. The assumption is that the light source is
|
||||
// out of the volume.
|
||||
float
|
||||
accumulatedTransmittance(vec3 rayStartEye, vec3 rayDirectionEye)
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
float totalExtinction = 0.0;
|
||||
|
||||
const vec3 rayStepEye = resolvedStepSizeEyeLighting * rayDirectionEye;
|
||||
|
||||
const float rayLength = timeRayExitsVolume(rayStartEye, rayDirectionEye);
|
||||
|
||||
const int numSteps =
|
||||
int(floor(min(maxNumSteps, rayLength / resolvedStepSizeEyeLighting)));
|
||||
|
||||
while(i < numSteps) {
|
||||
const vec3 rayPointEye = rayStartEye + i * rayStepEye;
|
||||
|
||||
totalExtinction += extinctionFunction(rayPointEye);
|
||||
|
||||
i+=1;
|
||||
}
|
||||
|
||||
return exp(-totalExtinction * resolvedStepSizeWorldLighting);
|
||||
}
|
||||
|
||||
// Computes amount of light arriving at point Peye
|
||||
// taking attenuation (e.g., by inverse-square law), shadows,
|
||||
// transmittance by volume into account.
|
||||
vec3
|
||||
lightingComputation(vec3 rayPointEye, vec3 rayDirectionEye)
|
||||
{
|
||||
vec3 result = vec3(0.0);
|
||||
for (int i = 0; i < NUM_LIGHTS; ++i) {
|
||||
|
||||
const vec4 Plight = lightSource[i].position;
|
||||
|
||||
const vec3 lightDirectionEye = normalize(
|
||||
(Plight.w == 0.0) ? Plight.xyz : Plight.xyz - rayPointEye);
|
||||
|
||||
const float atten =
|
||||
lightDistanceAttenuation(vec4(rayPointEye,1), i) *
|
||||
lightSpotAttenuation(lightDirectionEye, i);
|
||||
|
||||
// For now, not using shadows for volumes.
|
||||
#if USE_SHADOWS && 0
|
||||
const float shadow = (lightSource[i].hasShadow) ?
|
||||
shadowing(/*lightIndex=*/i, rayPointEye) : 1.0;
|
||||
#else
|
||||
const float shadow = 1.0;
|
||||
#endif
|
||||
|
||||
if (shadow > 0.0001) {
|
||||
result +=
|
||||
shadow *
|
||||
atten *
|
||||
// Assuming that light source is outside of volume's
|
||||
// bounding box (might integrate extinction along ray
|
||||
// beyond light source).
|
||||
accumulatedTransmittance(rayPointEye, lightDirectionEye) *
|
||||
phaseFunction(-rayDirectionEye, lightDirectionEye) *
|
||||
lightSource[i].diffuse.rgb;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Result of integrating volume along a ray
|
||||
struct VolumeContribution
|
||||
{
|
||||
// Coordinates where ray marching hit the first non-empty voxel
|
||||
// in eye space. 0 indicates the ray hit only empty voxels.
|
||||
vec3 firstHitPeye;
|
||||
|
||||
// Integrated color
|
||||
vec3 color;
|
||||
|
||||
// Integrated transmittance, i.e., what fraction of light from
|
||||
// geometry behind the volume is still visible.
|
||||
float transmittance;
|
||||
};
|
||||
|
||||
VolumeContribution
|
||||
volumeIntegrator(vec3 rayStartEye, vec3 rayDirectionEye, float rayLength)
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
VolumeContribution result;
|
||||
result.firstHitPeye = vec3(0.0);
|
||||
result.color = vec3(0.0);
|
||||
result.transmittance = 1.0;
|
||||
|
||||
const vec3 rayStepEye = resolvedStepSizeEye * rayDirectionEye;
|
||||
|
||||
const int numSteps =
|
||||
int(floor(min(maxNumSteps, rayLength / resolvedStepSizeEye)));
|
||||
|
||||
// integrate transmittance and light along ray for bounding box
|
||||
while(i < numSteps) {
|
||||
const vec3 rayPointEye = rayStartEye + i * rayStepEye;
|
||||
|
||||
// Evaluate volume shader functions to determine extinction,
|
||||
// scattering, and emission.
|
||||
const float extinctionValue = extinctionFunction(rayPointEye);
|
||||
const float scatteringValue = scatteringFunction(rayPointEye);
|
||||
const vec3 emissionValue = emissionFunction(rayPointEye);
|
||||
|
||||
// If this is the first time the ray is hitting a non-empty voxel,
|
||||
// record the coordinates.
|
||||
if (result.firstHitPeye == vec3(0.0)) {
|
||||
if ( extinctionValue > 0 ||
|
||||
scatteringValue > 0 ||
|
||||
any(greaterThan(emissionValue, vec3(0)))) {
|
||||
result.firstHitPeye = rayPointEye;
|
||||
}
|
||||
}
|
||||
|
||||
// In scattering contribution, lighting only computed if scattering
|
||||
// is non-trivial.
|
||||
const vec3 inScattering =
|
||||
(resolvedStepSizeWorld * scatteringValue >= minScattering) ?
|
||||
(scatteringValue *
|
||||
lightingComputation(rayPointEye, rayDirectionEye))
|
||||
: vec3(0.0);
|
||||
|
||||
// In scattering and emission contribution
|
||||
result.color +=
|
||||
(resolvedStepSizeWorld * result.transmittance) *
|
||||
(inScattering + emissionValue);
|
||||
|
||||
// Update transmittance
|
||||
result.transmittance *= exp(-extinctionValue * resolvedStepSizeWorld);
|
||||
|
||||
// Stop when the volume has become close to opaque.
|
||||
if (result.transmittance < minTransmittance) {
|
||||
break;
|
||||
}
|
||||
|
||||
i+=1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Is camera orthographic?
|
||||
bool
|
||||
isCameraOrthographic()
|
||||
{
|
||||
return abs(GetProjectionMatrix()[3][3] - 1.0) < 1e-5;
|
||||
}
|
||||
|
||||
// Convert depth value z in [-1,1] to depth in eye space [-near, -far].
|
||||
float
|
||||
NDCtoEyeZ(float z)
|
||||
{
|
||||
const MAT4 m = inverse(GetProjectionMatrix());
|
||||
return float((m[2][2] * z + m[3][2]) / (m[2][3] * z + m[3][3]));
|
||||
}
|
||||
|
||||
// Compute the z-value of the near clipping plane in eye space.
|
||||
// Negative by OpenGL convention
|
||||
float
|
||||
computeNearZ()
|
||||
{
|
||||
return NDCtoEyeZ(-1.0);
|
||||
}
|
||||
|
||||
// Compute the near clipping distance. Always returns a positive value.
|
||||
float
|
||||
computeNearDistance()
|
||||
{
|
||||
return abs(computeNearZ());
|
||||
}
|
||||
|
||||
// Consider the ray from the eye to a given point in eye space.
|
||||
// Computes the direction of this ray in both cases where the
|
||||
// camera is orthographic or perspective.
|
||||
vec3
|
||||
computeRayDirectionEye(vec3 rayPointEye)
|
||||
{
|
||||
// In NDC space, the ray is always pointing into the z-direction (0,0,1).
|
||||
// In clip space, this corresponds to (0,0,1,0).
|
||||
// We need to multiply (0,0,1,0) by the inverse projection matrix to
|
||||
// get to homogeneous eye space.
|
||||
// Or alternatively, we can get the direction in homogeneous eye space
|
||||
// by taking the respective column of the inverse projection matrix:
|
||||
const vec4 dir = vec4(inverse(GetProjectionMatrix())[2]);
|
||||
|
||||
// To compute the corresponding direction in non-homogeneous eye space,
|
||||
// compute the position of the ray after time dt << 1:
|
||||
// vec4 pHomogeneous = vec4(rayPointEye, 1.0) + dt * dir;
|
||||
// vec3 p = pHomogeneous.xyz / pHomogeneous.w;
|
||||
//
|
||||
// Or equivalently:
|
||||
// vec3 p = (rayPointEye + dt * dir.xyz) / (1.0 + dir.w * dt);
|
||||
// And since dt << 1, we have
|
||||
// vec3 p = (rayPointEye + dt * dir.xyz) * (1.0 - dir.w * dt);
|
||||
// And dropping higher order terms:
|
||||
// vec3 p = rayPointEye + dt * (dir.xyz - rayPointEye * dir.w);
|
||||
// So the new direction is given by:
|
||||
// vec3 d = dir.xyz - rayPointEye * dir.w;
|
||||
|
||||
// Normalize direction in eye space.
|
||||
return normalize(dir.xyz - rayPointEye * dir.w);
|
||||
}
|
||||
|
||||
// Given where the ray is about to leave the volume, compute where we
|
||||
// should start ray marching: this is either the point where the ray
|
||||
// would have entered the volume or the intersection with the near
|
||||
// clipping plane or a sphere about the eye (in the perspective case).
|
||||
//
|
||||
vec3
|
||||
computeRayStartEye(vec3 rayEndEye, vec3 rayDirectionEye)
|
||||
{
|
||||
// Time where ray would have entered volume (negative).
|
||||
const float startTime = timeRayEnteredVolume(rayEndEye, rayDirectionEye);
|
||||
|
||||
if (isCameraOrthographic()) {
|
||||
// Time where ray would have intersected near plane
|
||||
const float nearTime =
|
||||
(computeNearZ() - rayEndEye.z)
|
||||
/ rayDirectionEye.z;
|
||||
// Take the latter of the two times for getting the start point
|
||||
return rayEndEye + max(startTime, nearTime) * rayDirectionEye;
|
||||
}
|
||||
|
||||
// Note that we intersect the ray with sphere about the eye with
|
||||
// radius equal to the near distance in the perspective case rather
|
||||
// than just the above intersection with the near plane.
|
||||
//
|
||||
// The motivation is that the distance between the eye and the
|
||||
// near plane is non-constant across the image. Thus, ray-marching
|
||||
// would skip more volume away from the center of the image making
|
||||
// the image darker there - so we see opposite vignetting. To
|
||||
// avoid this bias, we use a sphere about the eye.
|
||||
//
|
||||
// Note that we can use points in front of the near plane
|
||||
// since OIT resolution makes no assumptions about the
|
||||
// depth value.
|
||||
//
|
||||
|
||||
// Compute point where ray would have entered volume
|
||||
const vec3 rayStartEye = rayEndEye + startTime * rayDirectionEye;
|
||||
// If this point is behind the eye or in the sphere about the eye, ...
|
||||
if (rayStartEye.z > 0.0 || length(rayStartEye) < computeNearDistance()) {
|
||||
// ... use point on sphere.
|
||||
return normalize(rayDirectionEye) * computeNearDistance();
|
||||
}
|
||||
|
||||
return rayStartEye;
|
||||
}
|
||||
|
||||
// The depth at which we hit opaque geometry in eye space (negative
|
||||
// value by OpenGL convention).
|
||||
float
|
||||
sampleZBuffer(vec2 fragcoord)
|
||||
{
|
||||
#ifdef HD_HAS_depthReadback
|
||||
// Sample the z-Buffer at the frag coordinate.
|
||||
const float bufferVal = texelFetch(HdGetSampler_depthReadback(),
|
||||
ivec2(fragcoord),
|
||||
/* lod = */ 0).z;
|
||||
#else
|
||||
// Assume far-plane if we cannot sample the z-Buffer.
|
||||
const float bufferVal = 1.0;
|
||||
#endif
|
||||
|
||||
return NDCtoEyeZ(2.0 * bufferVal - 1.0);
|
||||
}
|
||||
|
||||
// Compute how much length we need to ray march.
|
||||
//
|
||||
// The ray is encoded through it start point and direction. Its end will be
|
||||
// determined from two things:
|
||||
// - the eye space coordinates of this fragment which is part of the back-faces
|
||||
// of the volume.
|
||||
// - the z-Value of the opaque geometry (since we want to stop raymarching
|
||||
// once the ray has hit opaque geometry)
|
||||
float
|
||||
computeRayLength(vec3 rayStartEye, vec3 rayDirectionEye, vec3 rayEndEye,
|
||||
float opaqueZ)
|
||||
{
|
||||
// Recall that the camera is looking down the minus z-direction by
|
||||
// OpenGL conventions so we need to take the max to get the closer
|
||||
// point.
|
||||
const float rayEndZ = max(opaqueZ, rayEndEye.z);
|
||||
return (rayEndZ - rayStartEye.z) / rayDirectionEye.z;
|
||||
}
|
||||
|
||||
float max3(float a, float b, float c)
|
||||
{
|
||||
return max(a, max(b, c));
|
||||
}
|
||||
|
||||
// Computes the inverse of the scaling of an affine transform.
|
||||
// Approximately - since most transforms have uniform scaling
|
||||
// and no shear, this is fine.
|
||||
float
|
||||
scaleOfMatrix(MAT4 m)
|
||||
{
|
||||
// Take the maximum of the lengths of the images of the x, y
|
||||
// and z vector.
|
||||
//
|
||||
// A more general, coordinate independent implementation would take
|
||||
// the minimum singular value from the singular value decomposition.
|
||||
//
|
||||
const mat3 affinePart = mat3(m);
|
||||
return max3(length(affinePart[0]),
|
||||
length(affinePart[1]),
|
||||
length(affinePart[2]));
|
||||
}
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
instanceModelViewInverse =
|
||||
ApplyInstanceTransformInverse(HdGet_transformInverse()) *
|
||||
GetWorldToViewInverseMatrix();
|
||||
|
||||
eyeToBBox = mat4(
|
||||
MAT4(HdGet_volumeBBoxInverseTransform()) * instanceModelViewInverse);
|
||||
|
||||
ProcessSamplingTransforms(instanceModelViewInverse);
|
||||
|
||||
const float halfWorldSampleDistance =
|
||||
0.5 * float(HdGet_sampleDistance())
|
||||
/ scaleOfMatrix(instanceModelViewInverse);
|
||||
|
||||
const float viewScale = scaleOfMatrix(GetWorldToViewInverseMatrix());
|
||||
|
||||
resolvedStepSizeEye =
|
||||
HdGet_stepSize() * halfWorldSampleDistance;
|
||||
resolvedStepSizeWorld =
|
||||
viewScale * resolvedStepSizeEye;
|
||||
resolvedStepSizeEyeLighting =
|
||||
HdGet_stepSizeLighting() * halfWorldSampleDistance;
|
||||
resolvedStepSizeWorldLighting =
|
||||
viewScale * resolvedStepSizeEyeLighting;
|
||||
|
||||
// Discard front faces - ray marching stops at fragment eye position
|
||||
// and starts at the intersection of ray with volume bounding box or
|
||||
// near plane.
|
||||
if (gl_FrontFacing ^^ (determinant(instanceModelViewInverse) < 0.0)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// camera facing.
|
||||
const vec3 Neye = vec3(0, 0, 1);
|
||||
|
||||
// compute ray for ray marching
|
||||
const vec3 rayDirectionEye = computeRayDirectionEye(inData.Peye);
|
||||
const vec3 rayStartEye = computeRayStartEye(inData.Peye, rayDirectionEye);
|
||||
|
||||
// Use z-value from depth buffer to compute length for ray marching
|
||||
const float opaqueZ = sampleZBuffer(gl_FragCoord.xy);
|
||||
const float rayLength = computeRayLength(
|
||||
rayStartEye, rayDirectionEye, inData.Peye, opaqueZ);
|
||||
|
||||
const VolumeContribution volumeContribution =
|
||||
volumeIntegrator(rayStartEye, rayDirectionEye, rayLength);
|
||||
const float alpha = 1 - volumeContribution.transmittance;
|
||||
const vec4 color = ApplyColorOverrides(vec4(volumeContribution.color, alpha));
|
||||
|
||||
const vec4 patchCoord = vec4(0.0);
|
||||
|
||||
RenderOutput(vec4(volumeContribution.firstHitPeye, 1),
|
||||
Neye, color, patchCoord);
|
||||
}
|
||||
Reference in new issue
Block a user