Subversion Repository Public Repository

Divide-Dependencies

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef TESSELLATION_CG
#define TESSELLATION_CG

#include <config.cg>
#include <globals.cg>

#if !defined(ADAPTIVE_TESSELLATION)
#define ADAPTIVE_TESSELLATION 1
#endif

#if !defined(WEIGHTED_TESSELLATION)
#define WEIGHTED_TESSELLATION 1
#endif

#if !defined(ENABLE_EXTRA_SEMANTICS)
#define ENABLE_EXTRA_SEMANTICS 1
#endif

#if !defined(ENABLE_INTERIOR_DISTANCE)
#define ENABLE_INTERIOR_DISTANCE 1
#endif

#if ENABLE_TESSELLATION==0

//--------------------------------------------------------------------------------------
// Vertex Shader Output
//--------------------------------------------------------------------------------------

struct VertexOut
{
	FragmentParameters params;
	float4 screenSpacePosition : POSITION;
};

#else

struct VertexOut
{
	FragmentParameters params;
	float4 screenSpacePosition : POSITION;
#if ENABLE_EXTRA_SEMANTICS
	float4      localPosition  : SEMANTIC_MODEL_POSITION;
	uint        flagsDisp      : SEMANTIC_DISPLACEMENT_FLAGS;
	float4      modelMatrix[4] : SEMANTIC_MODEL_MATRIX;
#endif
};

//--------------------------------------------------------------------------------------
// Constants
//--------------------------------------------------------------------------------------

BEGIN_CBUFFER(cbTessellation)
// x = Edge Factor
// y = Inside factor
// z = Distance factor where (1 - (z/x)) clamps distance LOD
// w = Optional screen-space factor
CONST_TYPE float4 g_tessFactor             : packoffset(c0);

// x = Min distance for LOD scaling
// y = Max distance for LOD scaling
CONST_TYPE float2 g_tessMinMaxDistance     : packoffset(c1);

// x = Height scaling factor
// y = Height bias (applied before scaling)
CONST_TYPE float2 g_tessHeightScaleAndBias : packoffset(c1.z);

// x = U scaling factor
// y = V scaling factor
CONST_TYPE float2 g_tessUVScale            : packoffset(c2);

END_CBUFFER(cbTessellation)


//--------------------------------------------------------------------------------------
// Static Constants 
//--------------------------------------------------------------------------------------

static const uint X_FLAG     = 0;
static const uint Y_FLAG     = 1;
static const uint Z_FLAG     = 2;
static const uint AXIS_MASK  = 3;//X_FLAG | Y_FLAG | Z_FLAG;
static const uint FIXED_FLAG = 4;
static const uint INTERIOR_FLAG = 8;

//--------------------------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------------------------

float getDisplacementWeight(uint uFlags)
{
	return (uFlags & FIXED_FLAG) ? 0.f : 1.f;
}

uint  getDisplacementAxis(uint uFlags)
{
	return uFlags & AXIS_MASK;
}

bool  isEdgeInterior(uint uFlags)
{
	return uFlags & INTERIOR_FLAG;
}

/*
float getInteriorDistance(float3 vEdgeFactors, float3 vBaryCoords)
{
	float3 vEdgeCoords = float3(1,1,1) - 
	                     normalize(float3(vBaryCoords.x + vBaryCoords.y,
	                                      vBaryCoords.y + vBaryCoords.z,
	                                      vBaryCoords.z + vBaryCoords.x) * .5);
	if(vEdgeFactors.x > 0.)
		vEdgeCoords.x = 0.;
	if(vEdgeFactors.y > 0.)
		vEdgeCoords.y = 0.;
	if(vEdgeFactors.z > 0.)
		vEdgeCoords.z = 0.;

	return sqrt(max(vEdgeCoords.x, max(vEdgeCoords.y, vEdgeCoords.z)));
}*/

float getInteriorDistance(float3 edgeFactors, float3 baryCoords)
{
	// Calculate distance from triangle exterior [0...1]
	float3 vInteriorDistance  = sqrt(baryCoords*edgeFactors);
	//float3 vInteriorDistance  = baryCoords*edgeFactors;
	vInteriorDistance        += float3(1,1,1) - edgeFactors;
	return clamp(min(min(vInteriorDistance.x, vInteriorDistance.y), vInteriorDistance.z), 0, 1);
	//float fInteriorDistance = 3.f * min(min(fU+input.EdgeFactors.x, fV+input.EdgeFactors.y), fW+input.EdgeFactors.z);
	//float fInteriorDistance = 3.f * min(min(fU, fV), fW);
}

// Distance between point and line segment defined by p0 -> p1
float computeDistance(float3 worldSpacePosition, float3 p0, float3 p1)
{
	float3 v = p1 - p1;
	float3 w = worldSpacePosition - p0;

    float c1 = dot(w,v);
    if ( c1 <= 0 )
        return distance(worldSpacePosition, p0);

    float c2 = dot(v,v);
    if ( c2 <= c1 )
        return distance(worldSpacePosition, p1);

    float b = c1 / c2;
    return distance(worldSpacePosition, p0 + b * v);
}

// LOD distance based on viewpoint
float computeDistance(float3 worldSpacePosition, float3 eyePosition)
{
	// Min and max distance should be chosen according to scene quality requirements
	const float fMinDistance = g_tessMinMaxDistance.x;//x5.0f;
	const float fMaxDistance = g_tessMinMaxDistance.y;//100.f;

	// Calculate distance between vertex and camera, and a vertex distance factor issued from it
	float fDistance = distance( worldSpacePosition.xyz, eyePosition );
	return 1.0 - clamp( ( ( fDistance - fMinDistance ) / ( fMaxDistance - fMinDistance ) ),
	                    0.0,
	                    1.0 - g_tessFactor.z/g_tessFactor.x);
}

float3 pointInPlane(in float3 n, in float3 p,  in float3 pPlane)
{
	return p - dot(n, p - pPlane) * n;
}

float3 computeBarycentricCoordinates(in float3 p, in float3 n, in float3 a, in float3 b, in float3 c)
{
	float3 pProj = pointInPlane(n, p, a);

	float abc = dot(n, cross(b-a,     c-a));
	float pbc = dot(n, cross(b-pProj, c-pProj));
	float pca = dot(n, cross(c-pProj, a-pProj));

	float x0 = pbc / abc;
	float x1 = pca / abc;
	float x2 = 1.0f - x0 - x1;

	return float3(x0, x1, x2);
}

#endif /* ENABLE_TESSELLATION==1 */

#endif

Commits for Divide-Dependencies/physx/APEX_1.4/media/SampleRenderer/4/shaders/include/tessellation.cg

Diff revisions: vs.
Revision Author Commited Message
105 IonutCava picture IonutCava Tue 16 Apr, 2019 19:55:41 +0000

Forgot to actually add physx