Add Chromium-only Blender WebEngine parity work
This commit is contained in:
49
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/CMakeLists.txt
vendored
Normal file
49
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
#
|
||||
# Copyright 2013 Pixar
|
||||
#
|
||||
# Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
# https://opensubdiv.org/license.
|
||||
#
|
||||
|
||||
# *** dxViewer ***
|
||||
|
||||
set(SHADER_FILES
|
||||
shader.hlsl
|
||||
)
|
||||
|
||||
set(PLATFORM_LIBRARIES
|
||||
"${OSD_LINK_TARGET}"
|
||||
"${DXSDK_LIBRARIES}"
|
||||
)
|
||||
|
||||
include_directories(
|
||||
"${OPENSUBDIV_INCLUDE_DIR}"
|
||||
"${DXSDK_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
if (OPENCL_FOUND)
|
||||
include_directories("${OPENCL_INCLUDE_DIRS}")
|
||||
list(APPEND PLATFORM_LIBRARIES OpenGL::GL)
|
||||
endif()
|
||||
|
||||
set(SOURCE_FILES
|
||||
dxViewer.cpp
|
||||
)
|
||||
|
||||
osd_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
osd_add_possibly_cuda_executable(dxViewer "examples" WIN32
|
||||
"${SOURCE_FILES}"
|
||||
"${INC_FILES}"
|
||||
$<TARGET_OBJECTS:regression_common_obj>
|
||||
$<TARGET_OBJECTS:regression_far_utils_obj>
|
||||
$<TARGET_OBJECTS:examples_common_dx11_obj>
|
||||
)
|
||||
|
||||
target_link_libraries(dxViewer
|
||||
${PLATFORM_LIBRARIES}
|
||||
)
|
||||
|
||||
install(TARGETS dxViewer DESTINATION "${CMAKE_BINDIR_BASE}")
|
||||
1618
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/dxviewer.cpp
vendored
Normal file
1618
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/dxviewer.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
82
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/init_shapes.h
vendored
Normal file
82
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/init_shapes.h
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Copyright 2013 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
#include "../../regression/common/shape_utils.h"
|
||||
#include "../../regression/shapes/all.h"
|
||||
|
||||
|
||||
static std::vector<ShapeDesc> g_defaultShapes;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static void initShapes() {
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_toroidal_tet", catmark_toroidal_tet, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_cube", catmark_cube, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_cubes_semisharp", catmark_cubes_semisharp, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_cubes_infsharp", catmark_cubes_infsharp, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_pyramid", catmark_pyramid, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_pyramid_creases0", catmark_pyramid_creases0, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_pyramid_creases1", catmark_pyramid_creases1, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_torus", catmark_torus, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_torus_creases0", catmark_torus_creases0, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_torus_creases1", catmark_torus_creases1, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_edgecorner", catmark_edgecorner, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_edgeonly", catmark_edgeonly, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_edgenone", catmark_edgenone, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_quadstrips", catmark_quadstrips, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_xord_interior", catmark_xord_interior, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_xord_boundary", catmark_xord_boundary, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_val2_interior", catmark_val2_interior, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_nonquads", catmark_nonquads, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_single_crease", catmark_single_crease, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_inf_crease0", catmark_inf_crease0, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_inf_crease1", catmark_inf_crease1, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_nonman_verts", catmark_nonman_verts, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_nonman_edges", catmark_nonman_edges, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_hole_test1", catmark_hole_test1, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_hole_test2", catmark_hole_test2, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_hole_test3", catmark_hole_test3, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_hole_test4", catmark_hole_test4, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_chaikin0", catmark_chaikin0, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_chaikin1", catmark_chaikin1, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_chaikin2", catmark_chaikin2, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_smoothtris0", catmark_smoothtris0, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_smoothtris1", catmark_smoothtris1, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_pole8", catmark_pole8, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_pole64", catmark_pole64, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_nonman_quadpole64",catmark_nonman_quadpole64,kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_nonman_edge100", catmark_nonman_edge100, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_helmet", catmark_helmet, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_bishop", catmark_bishop, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_pawn", catmark_pawn, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_rook", catmark_rook, kCatmark));
|
||||
g_defaultShapes.push_back(ShapeDesc("catmark_car", catmark_car, kCatmark));
|
||||
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_toroidal_tet", loop_toroidal_tet, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_tetrahedron", loop_tetrahedron, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_cube", loop_cube, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_cubes_semisharp", loop_cubes_semisharp, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_cubes_infsharp", loop_cubes_infsharp, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_cube_asymmetric", loop_cube_asymmetric, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_icosahedron", loop_icosahedron, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_icos_semisharp", loop_icos_semisharp, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_icos_infsharp", loop_icos_infsharp, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_triangle_edgecorner", loop_triangle_edgecorner, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_triangle_edgeonly", loop_triangle_edgeonly, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_triangle_edgenone", loop_triangle_edgenone, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_xord_interior", loop_xord_interior, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_xord_boundary", loop_xord_boundary, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_nonman_verts", loop_nonman_verts, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_nonman_edges", loop_nonman_edges, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_pole64", loop_pole64, kLoop));
|
||||
g_defaultShapes.push_back(ShapeDesc("loop_nonman_edge100", loop_nonman_edge100, kLoop));
|
||||
|
||||
g_defaultShapes.push_back(ShapeDesc("bilinear_cube", bilinear_cube, kBilinear));
|
||||
g_defaultShapes.push_back(ShapeDesc("bilinear_nonplanar", bilinear_nonplanar, kBilinear));
|
||||
g_defaultShapes.push_back(ShapeDesc("bilinear_nonquads0", bilinear_nonquads0, kBilinear));
|
||||
g_defaultShapes.push_back(ShapeDesc("bilinear_nonquads1", bilinear_nonquads1, kBilinear));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
476
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/shader.hlsl
vendored
Normal file
476
blender-5.2.0/extern/opensubdiv-source/examples/dxViewer/shader.hlsl
vendored
Normal file
@@ -0,0 +1,476 @@
|
||||
//
|
||||
// Copyright 2013 Pixar
|
||||
//
|
||||
// Licensed under the terms set forth in the LICENSE.txt file available at
|
||||
// https://opensubdiv.org/license.
|
||||
//
|
||||
|
||||
struct OutputPointVertex {
|
||||
float4 positionOut : SV_Position;
|
||||
};
|
||||
|
||||
cbuffer Transform : register( b0 ) {
|
||||
float4x4 ModelViewMatrix;
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 ModelViewProjectionMatrix;
|
||||
float4x4 ModelViewInverseMatrix;
|
||||
};
|
||||
|
||||
cbuffer Tessellation : register( b1 ) {
|
||||
float TessLevel;
|
||||
int GregoryQuadOffsetBase;
|
||||
int PrimitiveIdBase;
|
||||
};
|
||||
|
||||
float4x4 OsdModelViewMatrix()
|
||||
{
|
||||
return ModelViewMatrix;
|
||||
}
|
||||
float4x4 OsdProjectionMatrix()
|
||||
{
|
||||
return ProjectionMatrix;
|
||||
}
|
||||
float4x4 OsdModelViewProjectionMatrix()
|
||||
{
|
||||
return ModelViewProjectionMatrix;
|
||||
}
|
||||
float OsdTessLevel()
|
||||
{
|
||||
return TessLevel;
|
||||
}
|
||||
int OsdGregoryQuadOffsetBase()
|
||||
{
|
||||
return GregoryQuadOffsetBase;
|
||||
}
|
||||
int OsdPrimitiveIdBase()
|
||||
{
|
||||
return PrimitiveIdBase;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Vertex Shader
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void vs_main( in InputVertex input,
|
||||
out OutputVertex output )
|
||||
{
|
||||
output.positionOut = mul(ModelViewProjectionMatrix, input.position);
|
||||
output.position = mul(ModelViewMatrix, input.position);
|
||||
output.normal = mul(ModelViewMatrix,float4(input.normal, 0)).xyz;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Geometry Shader
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct GS_OUT
|
||||
{
|
||||
OutputVertex v;
|
||||
uint primitiveID : SV_PrimitiveID;
|
||||
};
|
||||
|
||||
GS_OUT
|
||||
outputVertex(OutputVertex input, float3 normal, uint primitiveID)
|
||||
{
|
||||
GS_OUT gsout;
|
||||
gsout.v = input;
|
||||
gsout.v.normal = normal;
|
||||
gsout.primitiveID = primitiveID;
|
||||
return gsout;
|
||||
}
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
#ifdef PRIM_TRI
|
||||
#define EDGE_VERTS 3
|
||||
#endif
|
||||
#ifdef PRIM_QUAD
|
||||
#define EDGE_VERTS 4
|
||||
#endif
|
||||
|
||||
static float VIEWPORT_SCALE = 1024.0; // XXXdyu
|
||||
|
||||
float edgeDistance(float2 p, float2 p0, float2 p1)
|
||||
{
|
||||
return VIEWPORT_SCALE *
|
||||
abs((p.x - p0.x) * (p1.y - p0.y) -
|
||||
(p.y - p0.y) * (p1.x - p0.x)) / length(p1.xy - p0.xy);
|
||||
}
|
||||
|
||||
GS_OUT
|
||||
outputWireVertex(OutputVertex input, float3 normal,
|
||||
int index, float2 edgeVerts[EDGE_VERTS], uint primitiveID)
|
||||
{
|
||||
GS_OUT gsout;
|
||||
gsout.v = input;
|
||||
gsout.v.normal = normal;
|
||||
|
||||
gsout.v.edgeDistance[0] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]);
|
||||
gsout.v.edgeDistance[1] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]);
|
||||
#ifdef PRIM_TRI
|
||||
gsout.v.edgeDistance[2] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]);
|
||||
#endif
|
||||
#ifdef PRIM_QUAD
|
||||
gsout.v.edgeDistance[2] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]);
|
||||
gsout.v.edgeDistance[3] =
|
||||
edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]);
|
||||
#endif
|
||||
gsout.primitiveID = primitiveID;
|
||||
return gsout;
|
||||
}
|
||||
#endif
|
||||
|
||||
[maxvertexcount(6)]
|
||||
void gs_quad( lineadj OutputVertex input[4],
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
inout TriangleStream<GS_OUT> triStream )
|
||||
{
|
||||
float3 A = (input[0].position - input[1].position).xyz;
|
||||
float3 B = (input[3].position - input[1].position).xyz;
|
||||
float3 C = (input[2].position - input[1].position).xyz;
|
||||
|
||||
float3 n0 = normalize(cross(B, A));
|
||||
|
||||
triStream.Append(outputVertex(input[0], n0, primitiveID));
|
||||
triStream.Append(outputVertex(input[1], n0, primitiveID));
|
||||
triStream.Append(outputVertex(input[3], n0, primitiveID));
|
||||
triStream.RestartStrip();
|
||||
triStream.Append(outputVertex(input[3], n0, primitiveID));
|
||||
triStream.Append(outputVertex(input[1], n0, primitiveID));
|
||||
triStream.Append(outputVertex(input[2], n0, primitiveID));
|
||||
triStream.RestartStrip();
|
||||
}
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
#ifdef PRIM_QUAD
|
||||
[maxvertexcount(6)]
|
||||
void gs_quad_wire( lineadj OutputVertex input[4],
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
inout TriangleStream<GS_OUT> triStream )
|
||||
{
|
||||
float3 A = (input[0].position - input[1].position).xyz;
|
||||
float3 B = (input[3].position - input[1].position).xyz;
|
||||
float3 C = (input[2].position - input[1].position).xyz;
|
||||
|
||||
float3 n0 = normalize(cross(B, A));
|
||||
|
||||
float2 edgeVerts[4];
|
||||
edgeVerts[0] = input[0].positionOut.xy / input[0].positionOut.w;
|
||||
edgeVerts[1] = input[1].positionOut.xy / input[1].positionOut.w;
|
||||
edgeVerts[2] = input[2].positionOut.xy / input[2].positionOut.w;
|
||||
edgeVerts[3] = input[3].positionOut.xy / input[3].positionOut.w;
|
||||
|
||||
triStream.Append(outputWireVertex(input[0], n0, 0, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[1], n0, 1, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[3], n0, 3, edgeVerts, primitiveID));
|
||||
triStream.RestartStrip();
|
||||
triStream.Append(outputWireVertex(input[3], n0, 3, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[1], n0, 1, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[2], n0, 2, edgeVerts, primitiveID));
|
||||
triStream.RestartStrip();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
[maxvertexcount(3)]
|
||||
void gs_triangle( triangle OutputVertex input[3],
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
inout TriangleStream<GS_OUT> triStream )
|
||||
{
|
||||
float3 A = (input[0].position - input[1].position).xyz;
|
||||
float3 B = (input[2].position - input[1].position).xyz;
|
||||
|
||||
float3 n0 = normalize(cross(B, A));
|
||||
|
||||
triStream.Append(outputVertex(input[0], n0, primitiveID));
|
||||
triStream.Append(outputVertex(input[1], n0, primitiveID));
|
||||
triStream.Append(outputVertex(input[2], n0, primitiveID));
|
||||
}
|
||||
|
||||
[maxvertexcount(3)]
|
||||
void gs_triangle_smooth( triangle OutputVertex input[3],
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
inout TriangleStream<GS_OUT> triStream )
|
||||
{
|
||||
triStream.Append(outputVertex(input[0], input[0].normal, primitiveID));
|
||||
triStream.Append(outputVertex(input[1], input[1].normal, primitiveID));
|
||||
triStream.Append(outputVertex(input[2], input[2].normal, primitiveID));
|
||||
}
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
#ifdef PRIM_TRI
|
||||
[maxvertexcount(3)]
|
||||
void gs_triangle_wire( triangle OutputVertex input[3],
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
inout TriangleStream<GS_OUT> triStream )
|
||||
{
|
||||
float3 A = (input[0].position - input[1].position).xyz;
|
||||
float3 B = (input[2].position - input[1].position).xyz;
|
||||
|
||||
float3 n0 = normalize(cross(B, A));
|
||||
|
||||
float2 edgeVerts[3];
|
||||
edgeVerts[0] = input[0].positionOut.xy / input[0].positionOut.w;
|
||||
edgeVerts[1] = input[1].positionOut.xy / input[1].positionOut.w;
|
||||
edgeVerts[2] = input[2].positionOut.xy / input[2].positionOut.w;
|
||||
|
||||
triStream.Append(outputWireVertex(input[0], n0, 0, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[1], n0, 1, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[2], n0, 2, edgeVerts, primitiveID));
|
||||
}
|
||||
|
||||
[maxvertexcount(3)]
|
||||
void gs_triangle_smooth_wire( triangle OutputVertex input[3],
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
inout TriangleStream<GS_OUT> triStream )
|
||||
{
|
||||
float2 edgeVerts[3];
|
||||
edgeVerts[0] = input[0].positionOut.xy / input[0].positionOut.w;
|
||||
edgeVerts[1] = input[1].positionOut.xy / input[1].positionOut.w;
|
||||
edgeVerts[2] = input[2].positionOut.xy / input[2].positionOut.w;
|
||||
|
||||
triStream.Append(outputWireVertex(input[0], input[0].normal, 0, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[1], input[1].normal, 1, edgeVerts, primitiveID));
|
||||
triStream.Append(outputWireVertex(input[2], input[2].normal, 2, edgeVerts, primitiveID));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
[maxvertexcount(1)]
|
||||
void gs_point( point OutputVertex input[1],
|
||||
inout PointStream<OutputPointVertex> pointStream )
|
||||
{
|
||||
OutputPointVertex v0;
|
||||
v0.positionOut = input[0].positionOut;
|
||||
|
||||
pointStream.Append(v0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Lighting
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#define NUM_LIGHTS 2
|
||||
|
||||
struct LightSource {
|
||||
float4 position;
|
||||
float4 ambient;
|
||||
float4 diffuse;
|
||||
float4 specular;
|
||||
};
|
||||
|
||||
cbuffer Lighting : register( b2 ) {
|
||||
LightSource lightSource[NUM_LIGHTS];
|
||||
};
|
||||
|
||||
|
||||
cbuffer Material : register( b3 ){
|
||||
float4 materialColor;
|
||||
}
|
||||
|
||||
float4
|
||||
lighting(float4 diffuse, float3 Peye, float3 Neye)
|
||||
{
|
||||
float4 color = float4(0.0, 0.0, 0.0, 0.0);
|
||||
//float4 material = float4(0.4, 0.4, 0.8, 1);
|
||||
//float4 material = float4(0.13, 0.13, 0.61, 1); // sRGB (gamma 2.2)
|
||||
|
||||
for (int i = 0; i < NUM_LIGHTS; ++i) {
|
||||
|
||||
float4 Plight = lightSource[i].position;
|
||||
|
||||
float3 l = (Plight.w == 0.0)
|
||||
? normalize(Plight.xyz) : normalize(Plight.xyz - Peye);
|
||||
|
||||
float3 n = normalize(Neye);
|
||||
float3 h = normalize(l + float3(0,0,1)); // directional viewer
|
||||
|
||||
float d = max(0.0, dot(n, l));
|
||||
float s = pow(max(0.0, dot(n, h)), 500.0f);
|
||||
|
||||
color += lightSource[i].ambient
|
||||
+ d * lightSource[i].diffuse * diffuse
|
||||
+ s * lightSource[i].specular;
|
||||
}
|
||||
|
||||
|
||||
color.a = 1.0;
|
||||
return color;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
float4
|
||||
edgeColor(float4 Cfill, float4 edgeDistance)
|
||||
{
|
||||
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
|
||||
#ifdef PRIM_TRI
|
||||
float d =
|
||||
min(edgeDistance[0], min(edgeDistance[1], edgeDistance[2]));
|
||||
#endif
|
||||
#ifdef PRIM_QUAD
|
||||
float d =
|
||||
min(min(edgeDistance[0], edgeDistance[1]),
|
||||
min(edgeDistance[2], edgeDistance[3]));
|
||||
#endif
|
||||
float v = 0.5;
|
||||
float4 Cedge = float4(Cfill.r*v, Cfill.g*v, Cfill.b*v, 1);
|
||||
float p = exp2(-2 * d * d);
|
||||
|
||||
#if defined(GEOMETRY_OUT_WIRE)
|
||||
if (p < 0.25) discard;
|
||||
#endif
|
||||
|
||||
Cfill.rgb = lerp(Cfill.rgb, Cedge.rgb, p);
|
||||
#endif
|
||||
return Cfill;
|
||||
}
|
||||
|
||||
float4
|
||||
getAdaptivePatchColor(int3 patchParam, float2 vSegments)
|
||||
{
|
||||
const float4 patchColors[7*6] = {
|
||||
float4(1.0f, 1.0f, 1.0f, 1.0f), // regular
|
||||
float4(0.0f, 1.0f, 1.0f, 1.0f), // regular pattern 0
|
||||
float4(0.0f, 0.5f, 1.0f, 1.0f), // regular pattern 1
|
||||
float4(0.0f, 0.5f, 0.5f, 1.0f), // regular pattern 2
|
||||
float4(0.5f, 0.0f, 1.0f, 1.0f), // regular pattern 3
|
||||
float4(1.0f, 0.5f, 1.0f, 1.0f), // regular pattern 4
|
||||
|
||||
float4(1.0f, 0.5f, 0.5f, 1.0f), // single crease
|
||||
float4(1.0f, 0.70f, 0.6f, 1.0f), // single crease pattern 0
|
||||
float4(1.0f, 0.65f, 0.6f, 1.0f), // single crease pattern 1
|
||||
float4(1.0f, 0.60f, 0.6f, 1.0f), // single crease pattern 2
|
||||
float4(1.0f, 0.55f, 0.6f, 1.0f), // single crease pattern 3
|
||||
float4(1.0f, 0.50f, 0.6f, 1.0f), // single crease pattern 4
|
||||
|
||||
float4(0.8f, 0.0f, 0.0f, 1.0f), // boundary
|
||||
float4(0.0f, 0.0f, 0.75f, 1.0f), // boundary pattern 0
|
||||
float4(0.0f, 0.2f, 0.75f, 1.0f), // boundary pattern 1
|
||||
float4(0.0f, 0.4f, 0.75f, 1.0f), // boundary pattern 2
|
||||
float4(0.0f, 0.6f, 0.75f, 1.0f), // boundary pattern 3
|
||||
float4(0.0f, 0.8f, 0.75f, 1.0f), // boundary pattern 4
|
||||
|
||||
float4(0.0f, 1.0f, 0.0f, 1.0f), // corner
|
||||
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 0
|
||||
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 1
|
||||
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 2
|
||||
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 3
|
||||
float4(0.5f, 1.0f, 0.5f, 1.0f), // corner pattern 4
|
||||
|
||||
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
float4(1.0f, 1.0f, 0.0f, 1.0f), // gregory
|
||||
|
||||
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
float4(1.0f, 0.5f, 0.0f, 1.0f), // gregory boundary
|
||||
|
||||
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
float4(1.0f, 0.7f, 0.3f, 1.0f), // gregory basis
|
||||
float4(1.0f, 0.7f, 0.3f, 1.0f) // gregory basis
|
||||
};
|
||||
|
||||
int patchType = 0;
|
||||
|
||||
int edgeCount = countbits(OsdGetPatchBoundaryMask(patchParam));
|
||||
if (edgeCount == 1) {
|
||||
patchType = 2; // BOUNDARY
|
||||
}
|
||||
if (edgeCount > 1) {
|
||||
patchType = 3; // CORNER (not correct for patches that are not isolated)
|
||||
}
|
||||
|
||||
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
|
||||
if (vSegments.y > 0) {
|
||||
patchType = 1;
|
||||
}
|
||||
#elif defined OSD_PATCH_GREGORY
|
||||
patchType = 4;
|
||||
#elif defined OSD_PATCH_GREGORY_BOUNDARY
|
||||
patchType = 5;
|
||||
#elif defined OSD_PATCH_GREGORY_BASIS
|
||||
patchType = 6;
|
||||
#elif defined OSD_PATCH_GREGORY_TRIANGLE
|
||||
patchType = 6;
|
||||
#endif
|
||||
|
||||
int pattern = countbits(OsdGetPatchTransitionMask(patchParam));
|
||||
|
||||
return patchColors[6*patchType + pattern];
|
||||
}
|
||||
|
||||
float4
|
||||
getAdaptiveDepthColor(int3 patchParam)
|
||||
{
|
||||
// Represent depth with repeating cycle of four colors:
|
||||
const float4 depthColors[4] = {
|
||||
float4(0.0f, 0.5f, 0.5f, 1.0f),
|
||||
float4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
float4(0.0f, 1.0f, 1.0f, 1.0f),
|
||||
float4(0.5f, 1.0f, 0.5f, 1.0f)
|
||||
};
|
||||
return depthColors[OsdGetPatchRefinementLevel(patchParam) & 3];
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Pixel Shader
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
ps_main( in OutputVertex input,
|
||||
uint primitiveID : SV_PrimitiveID,
|
||||
bool isFrontFacing : SV_IsFrontFace,
|
||||
out float4 colorOut : SV_Target )
|
||||
{
|
||||
float2 vSegments = float2(0,0);
|
||||
#ifdef OSD_PATCH_ENABLE_SINGLE_CREASE
|
||||
vSegments = input.vSegments;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(SHADING_PATCH_TYPE)
|
||||
float4 color = getAdaptivePatchColor(
|
||||
OsdGetPatchParam(OsdGetPatchIndex(primitiveID)), vSegments);
|
||||
#elif defined(SHADING_PATCH_DEPTH)
|
||||
float4 color = getAdaptiveDepthColor(
|
||||
OsdGetPatchParam(OsdGetPatchIndex(primitiveID)));
|
||||
#elif defined(SHADING_PATCH_COORD)
|
||||
float4 color = float4(input.patchCoord.x, input.patchCoord.y, 0, 1);
|
||||
#elif defined(SHADING_MATERIAL)
|
||||
float4 color = float4(0.4, 0.4, 0.8, 1.0);
|
||||
#else
|
||||
float4 color = float4(1, 1, 1, 1);
|
||||
#endif
|
||||
|
||||
float3 N = (isFrontFacing ? input.normal : -input.normal);
|
||||
float4 Cf = lighting(color, input.position.xyz, N);
|
||||
|
||||
#if defined(SHADING_NORMAL)
|
||||
Cf.rgb = N;
|
||||
#endif
|
||||
|
||||
colorOut = edgeColor(Cf, input.edgeDistance);
|
||||
}
|
||||
|
||||
void
|
||||
ps_main_point( in OutputPointVertex input,
|
||||
out float4 colorOut : SV_Target )
|
||||
{
|
||||
colorOut = float4(1, 1, 1, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user