2012-06-16 00:52:36 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-06-16 00:52:36 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-06-16 00:52:36 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-06-16 00:52:36 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-06-16 00:52:36 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-06-16 00:52:36 +00:00
|
|
|
//
|
|
|
|
|
2012-12-11 21:50:27 +00:00
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.14159265358979323846 // fix for OSX 10.8 (M_PI is in the Khronos standard...)
|
|
|
|
#endif
|
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
struct Vertex
|
|
|
|
{
|
2014-05-09 00:20:54 +00:00
|
|
|
float v[VERTEX_STRIDE];
|
2012-06-16 00:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Varying
|
|
|
|
{
|
2014-05-09 00:20:54 +00:00
|
|
|
float v[VARYING_STRIDE];
|
2012-06-16 00:52:36 +00:00
|
|
|
};
|
|
|
|
|
2014-02-24 05:19:58 +00:00
|
|
|
static void clearVertex(struct Vertex *vertex) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < NUM_VERTEX_ELEMENTS; i++) {
|
|
|
|
vertex->v[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 05:19:58 +00:00
|
|
|
static void clearVarying(struct Varying *varying) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < NUM_VARYING_ELEMENTS; i++) {
|
|
|
|
varying->v[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
static void addWithWeight(struct Vertex *dst,
|
|
|
|
__global float *srcOrigin,
|
|
|
|
int index, float weight) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__global float *src = srcOrigin + index * VERTEX_STRIDE;
|
|
|
|
for (int i = 0; i < NUM_VERTEX_ELEMENTS; ++i) {
|
|
|
|
dst->v[i] += src[i] * weight;
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
static void addVaryingWithWeight(struct Varying *dst,
|
|
|
|
__global float *srcOrigin,
|
|
|
|
int index, float weight) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__global float *src = srcOrigin + index * VARYING_STRIDE;
|
|
|
|
for (int i = 0; i < NUM_VARYING_ELEMENTS; ++i) {
|
|
|
|
dst->v[i] += src[i] * weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void writeVertex(__global float *dstOrigin,
|
|
|
|
int index,
|
|
|
|
struct Vertex *src) {
|
|
|
|
|
|
|
|
__global float *dst = dstOrigin + index * VERTEX_STRIDE;
|
|
|
|
for (int i = 0; i < NUM_VERTEX_ELEMENTS; ++i) {
|
|
|
|
dst[i] = src->v[i];
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
static void writeVarying(__global float *dstOrigin,
|
|
|
|
int index,
|
|
|
|
struct Varying *src) {
|
|
|
|
|
|
|
|
__global float *dst = dstOrigin + index * VARYING_STRIDE;
|
|
|
|
for (int i = 0; i < NUM_VARYING_ELEMENTS; ++i) {
|
|
|
|
dst[i] = src->v[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__kernel void computeBilinearEdge(__global float *vertex,
|
|
|
|
__global float *varying,
|
2013-03-08 01:50:15 +00:00
|
|
|
__global int *E_IT,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end) {
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2014-05-09 00:20:54 +00:00
|
|
|
int vid = start + get_global_id(0) + offset;
|
2012-08-04 02:51:27 +00:00
|
|
|
int eidx0 = E_IT[2*i+0];
|
|
|
|
int eidx1 = E_IT[2*i+1];
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVertex(&dst);
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, eidx0, 0.5f);
|
|
|
|
addWithWeight(&dst, vertex, eidx1, 0.5f);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
writeVertex(vertex, vid, &dst);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
if (varying) {
|
2014-05-09 00:20:54 +00:00
|
|
|
addVaryingWithWeight(&dstVarying, varying, eidx0, 0.5f);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, eidx1, 0.5f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__kernel void computeBilinearVertex(__global float *vertex,
|
|
|
|
__global float *varying,
|
2013-03-08 01:50:15 +00:00
|
|
|
__global int *V_ITa,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end) {
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2014-05-09 00:20:54 +00:00
|
|
|
int vid = start + get_global_id(0) + offset;
|
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
int p = V_ITa[i];
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
clearVertex(&dst);
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, p, 1.0f);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
writeVertex(vertex, vid, &dst);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
if (varying) {
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVarying(&dstVarying);
|
2014-05-09 00:20:54 +00:00
|
|
|
addVaryingWithWeight(&dstVarying, varying, p, 1.0f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__kernel void computeFace(__global float *vertex,
|
|
|
|
__global float *varying,
|
2012-06-16 00:52:36 +00:00
|
|
|
__global int *F_IT,
|
|
|
|
__global int *F_ITa,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2014-05-09 00:20:54 +00:00
|
|
|
int vid = start + get_global_id(0) + offset;
|
2012-06-16 00:52:36 +00:00
|
|
|
int h = F_ITa[2*i];
|
|
|
|
int n = F_ITa[2*i+1];
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
float weight = 1.0f/n;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
struct Vertex dst;
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVertex(&dst);
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
for (int j=0; j<n; ++j) {
|
|
|
|
int index = F_IT[h+j];
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, index, weight);
|
|
|
|
if (varying) {
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, index, weight);
|
|
|
|
}
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
writeVertex(vertex, vid, &dst);
|
|
|
|
if (varying) writeVarying(varying, vid, &dstVarying);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 23:06:58 +00:00
|
|
|
__kernel void computeQuadFace(__global float *vertex,
|
|
|
|
__global float *varying,
|
|
|
|
__global int *F_IT,
|
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
|
|
|
int start, int end) {
|
|
|
|
|
|
|
|
int i = start + get_global_id(0);
|
|
|
|
int vid = start + get_global_id(0) + offset;
|
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVertex(&dst);
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
|
|
|
|
int fidx0 = F_IT[tableOffset + 4 * i + 0];
|
|
|
|
int fidx1 = F_IT[tableOffset + 4 * i + 1];
|
|
|
|
int fidx2 = F_IT[tableOffset + 4 * i + 2];
|
|
|
|
int fidx3 = F_IT[tableOffset + 4 * i + 3];
|
2014-05-30 06:02:19 +00:00
|
|
|
|
2014-05-13 23:06:58 +00:00
|
|
|
addWithWeight(&dst, vertex, fidx0, 0.25f);
|
|
|
|
addWithWeight(&dst, vertex, fidx1, 0.25f);
|
|
|
|
addWithWeight(&dst, vertex, fidx2, 0.25f);
|
|
|
|
addWithWeight(&dst, vertex, fidx3, 0.25f);
|
2014-05-30 06:02:19 +00:00
|
|
|
|
2014-05-13 23:06:58 +00:00
|
|
|
if (varying) {
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx0, 0.25f);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx1, 0.25f);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx2, 0.25f);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx3, 0.25f);
|
|
|
|
}
|
|
|
|
|
|
|
|
writeVertex(vertex, vid, &dst);
|
|
|
|
if (varying) writeVarying(varying, vid, &dstVarying);
|
|
|
|
}
|
|
|
|
|
|
|
|
__kernel void computeTriQuadFace(__global float *vertex,
|
|
|
|
__global float *varying,
|
|
|
|
__global int *F_IT,
|
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
|
|
|
int start, int end) {
|
|
|
|
|
|
|
|
int i = start + get_global_id(0);
|
|
|
|
int vid = start + get_global_id(0) + offset;
|
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVertex(&dst);
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
|
|
|
|
int fidx0 = F_IT[tableOffset + 4 * i + 0];
|
|
|
|
int fidx1 = F_IT[tableOffset + 4 * i + 1];
|
|
|
|
int fidx2 = F_IT[tableOffset + 4 * i + 2];
|
|
|
|
int fidx3 = F_IT[tableOffset + 4 * i + 3];
|
|
|
|
bool triangle = (fidx2 == fidx3);
|
|
|
|
float weight = triangle ? 1.0f / 3.0f : 1.0f / 4.0f;
|
|
|
|
|
|
|
|
addWithWeight(&dst, vertex, fidx0, weight);
|
|
|
|
addWithWeight(&dst, vertex, fidx1, weight);
|
|
|
|
addWithWeight(&dst, vertex, fidx2, weight);
|
|
|
|
if (!triangle)
|
|
|
|
addWithWeight(&dst, vertex, fidx3, weight);
|
|
|
|
|
|
|
|
if (varying) {
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx0, weight);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx1, weight);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx2, weight);
|
|
|
|
if (!triangle)
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, fidx3, weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
writeVertex(vertex, vid, &dst);
|
|
|
|
if (varying) writeVarying(varying, vid, &dstVarying);
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__kernel void computeEdge(__global float *vertex,
|
|
|
|
__global float *varying,
|
2012-06-16 00:52:36 +00:00
|
|
|
__global int *E_IT,
|
|
|
|
__global float *E_W,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2014-05-09 00:20:54 +00:00
|
|
|
int vid = start + get_global_id(0) + offset;
|
2012-06-16 00:52:36 +00:00
|
|
|
int eidx0 = E_IT[4*i+0];
|
|
|
|
int eidx1 = E_IT[4*i+1];
|
2012-08-04 02:51:27 +00:00
|
|
|
int eidx2 = E_IT[4*i+2];
|
2012-06-16 00:52:36 +00:00
|
|
|
int eidx3 = E_IT[4*i+3];
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
float vertWeight = E_W[i*2+0];
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
// Fully sharp edge : vertWeight = 0.5f;
|
|
|
|
struct Vertex dst;
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVertex(&dst);
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, eidx0, vertWeight);
|
|
|
|
addWithWeight(&dst, vertex, eidx1, vertWeight);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
if (eidx2 > -1) {
|
|
|
|
float faceWeight = E_W[i*2+1];
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, eidx2, faceWeight);
|
|
|
|
addWithWeight(&dst, vertex, eidx3, faceWeight);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
writeVertex(vertex, vid, &dst);
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2014-05-27 22:25:54 +00:00
|
|
|
if (varying) {
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, eidx0, 0.5f);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, eidx1, 0.5f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__kernel void computeRestrictedEdge(__global float *vertex,
|
|
|
|
__global float *varying,
|
|
|
|
__global int *E_IT,
|
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
|
|
|
int start, int end) {
|
|
|
|
|
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
|
|
|
int vid = start + get_global_id(0) + offset;
|
|
|
|
int eidx0 = E_IT[4*i+0];
|
|
|
|
int eidx1 = E_IT[4*i+1];
|
|
|
|
int eidx2 = E_IT[4*i+2];
|
|
|
|
int eidx3 = E_IT[4*i+3];
|
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVertex(&dst);
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
|
|
|
|
addWithWeight(&dst, vertex, eidx0, 0.25f);
|
|
|
|
addWithWeight(&dst, vertex, eidx1, 0.25f);
|
|
|
|
addWithWeight(&dst, vertex, eidx2, 0.25f);
|
|
|
|
addWithWeight(&dst, vertex, eidx3, 0.25f);
|
|
|
|
|
|
|
|
writeVertex(vertex, vid, &dst);
|
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
if (varying) {
|
2014-05-09 00:20:54 +00:00
|
|
|
addVaryingWithWeight(&dstVarying, varying, eidx0, 0.5f);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, eidx1, 0.5f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__kernel void computeVertexA(__global float *vertex,
|
|
|
|
__global float *varying,
|
2012-06-16 00:52:36 +00:00
|
|
|
__global int *V_ITa,
|
|
|
|
__global float *V_W,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end, int pass) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2014-05-09 00:20:54 +00:00
|
|
|
int vid = start + get_global_id(0) + offset;
|
2012-06-16 00:52:36 +00:00
|
|
|
int n = V_ITa[5*i+1];
|
|
|
|
int p = V_ITa[5*i+2];
|
|
|
|
int eidx0 = V_ITa[5*i+3];
|
|
|
|
int eidx1 = V_ITa[5*i+4];
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
float weight = (pass==1) ? V_W[i] : 1.0f - V_W[i];
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// In the case of fractional weight, the weight must be inverted since
|
|
|
|
// the value is shared with the k_Smooth kernel (statistically the
|
2012-06-16 00:52:36 +00:00
|
|
|
// k_Smooth kernel runs much more often than this one)
|
|
|
|
if (weight>0.0f && weight<1.0f && n > 0)
|
|
|
|
weight=1.0f-weight;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
struct Vertex dst;
|
2014-05-09 00:20:54 +00:00
|
|
|
clearVertex(&dst);
|
|
|
|
if (pass)
|
|
|
|
addWithWeight(&dst, vertex, vid, 1.0f); // copy previous result
|
2012-06-16 00:52:36 +00:00
|
|
|
|
|
|
|
if (eidx0==-1 || (pass==0 && (n==-1)) ) {
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, p, weight);
|
2012-06-16 00:52:36 +00:00
|
|
|
} else {
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, p, weight * 0.75f);
|
|
|
|
addWithWeight(&dst, vertex, eidx0, weight * 0.125f);
|
|
|
|
addWithWeight(&dst, vertex, eidx1, weight * 0.125f);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
writeVertex(vertex, vid, &dst);
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (! pass && varying) {
|
2012-06-16 00:52:36 +00:00
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVarying(&dstVarying);
|
2014-05-09 00:20:54 +00:00
|
|
|
addVaryingWithWeight(&dstVarying, varying, p, 1.0f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__kernel void computeVertexB(__global float *vertex,
|
|
|
|
__global float *varying,
|
2012-06-16 00:52:36 +00:00
|
|
|
__global int *V_ITa,
|
|
|
|
__global int *V_IT,
|
|
|
|
__global float *V_W,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2014-05-09 00:20:54 +00:00
|
|
|
int vid = start + get_global_id(0) + offset;
|
2012-06-16 00:52:36 +00:00
|
|
|
int h = V_ITa[5*i];
|
|
|
|
int n = V_ITa[5*i+1];
|
|
|
|
int p = V_ITa[5*i+2];
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
float weight = V_W[i];
|
|
|
|
float wp = 1.0f/(float)(n*n);
|
|
|
|
float wv = (n-2.0f) * n * wp;
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
clearVertex(&dst);
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, p, weight * wv);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
for (int j = 0; j < n; ++j) {
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, V_IT[h+j*2], weight * wp);
|
|
|
|
addWithWeight(&dst, vertex, V_IT[h+j*2+1], weight * wp);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
writeVertex(vertex, vid, &dst);
|
2012-06-16 00:52:36 +00:00
|
|
|
|
|
|
|
if (varying) {
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVarying(&dstVarying);
|
2014-05-09 00:20:54 +00:00
|
|
|
addVaryingWithWeight(&dstVarying, varying, p, 1.0f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:31:44 +00:00
|
|
|
__kernel void computeRestrictedVertexA(__global float *vertex,
|
|
|
|
__global float *varying,
|
|
|
|
__global int *V_ITa,
|
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
|
|
|
int start, int end) {
|
|
|
|
|
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
|
|
|
int vid = start + get_global_id(0) + offset;
|
|
|
|
int p = V_ITa[5*i+2];
|
|
|
|
int eidx0 = V_ITa[5*i+3];
|
|
|
|
int eidx1 = V_ITa[5*i+4];
|
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
clearVertex(&dst);
|
|
|
|
addWithWeight(&dst, vertex, p, 0.75f);
|
|
|
|
addWithWeight(&dst, vertex, eidx0, 0.125f);
|
|
|
|
addWithWeight(&dst, vertex, eidx1, 0.125f);
|
|
|
|
writeVertex(vertex, vid, &dst);
|
|
|
|
|
|
|
|
if (varying) {
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, p, 1.0f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__kernel void computeRestrictedVertexB1(__global float *vertex,
|
|
|
|
__global float *varying,
|
|
|
|
__global int *V_ITa,
|
|
|
|
__global int *V_IT,
|
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
|
|
|
int start, int end) {
|
|
|
|
|
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
|
|
|
int vid = start + get_global_id(0) + offset;
|
|
|
|
int h = V_ITa[5*i];
|
|
|
|
int p = V_ITa[5*i+2];
|
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
clearVertex(&dst);
|
|
|
|
|
|
|
|
addWithWeight(&dst, vertex, p, 0.5f);
|
|
|
|
|
|
|
|
for (int j = 0; j < 8; ++j, ++h) {
|
|
|
|
addWithWeight(&dst, vertex, V_IT[h], 0.0625f);
|
|
|
|
}
|
|
|
|
writeVertex(vertex, vid, &dst);
|
|
|
|
|
|
|
|
if (varying) {
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, p, 1.0f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__kernel void computeRestrictedVertexB2(__global float *vertex,
|
|
|
|
__global float *varying,
|
|
|
|
__global int *V_ITa,
|
|
|
|
__global int *V_IT,
|
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
|
|
|
int start, int end) {
|
|
|
|
|
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
|
|
|
int vid = start + get_global_id(0) + offset;
|
|
|
|
int h = V_ITa[5*i];
|
|
|
|
int n = V_ITa[5*i+1];
|
|
|
|
int p = V_ITa[5*i+2];
|
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
|
|
|
|
|
|
|
float wp = 1.0f/(float)(n*n);
|
|
|
|
float wv = (n-2.0f) * n * wp;
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
clearVertex(&dst);
|
|
|
|
|
|
|
|
addWithWeight(&dst, vertex, p, wv);
|
|
|
|
|
|
|
|
for (int j = 0; j < n; ++j) {
|
|
|
|
addWithWeight(&dst, vertex, V_IT[h+j*2], wp);
|
|
|
|
addWithWeight(&dst, vertex, V_IT[h+j*2+1], wp);
|
|
|
|
}
|
|
|
|
writeVertex(vertex, vid, &dst);
|
|
|
|
|
|
|
|
if (varying) {
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVarying(&dstVarying);
|
|
|
|
addVaryingWithWeight(&dstVarying, varying, p, 1.0f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__kernel void computeLoopVertexB(__global float *vertex,
|
|
|
|
__global float *varying,
|
2012-06-16 00:52:36 +00:00
|
|
|
__global int *V_ITa,
|
|
|
|
__global int *V_IT,
|
|
|
|
__global float *V_W,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset, int varyingOffset,
|
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end) {
|
2012-06-16 00:52:36 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2014-05-09 00:20:54 +00:00
|
|
|
int vid = start + get_global_id(0) + offset;
|
2012-06-16 00:52:36 +00:00
|
|
|
int h = V_ITa[5*i];
|
|
|
|
int n = V_ITa[5*i+1];
|
|
|
|
int p = V_ITa[5*i+2];
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex += vertexOffset;
|
|
|
|
varying += (varying ? varyingOffset :0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
float weight = V_W[i];
|
|
|
|
float wp = 1.0f/(float)(n);
|
|
|
|
float beta = 0.25f * cos((float)(M_PI) * 2.0f * wp) + 0.375f;
|
|
|
|
beta = beta * beta;
|
|
|
|
beta = (0.625f - beta) * wp;
|
|
|
|
|
|
|
|
struct Vertex dst;
|
|
|
|
clearVertex(&dst);
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, p, weight * (1.0f - (beta * n)));
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-16 00:52:36 +00:00
|
|
|
for (int j = 0; j < n; ++j) {
|
2014-05-09 00:20:54 +00:00
|
|
|
addWithWeight(&dst, vertex, V_IT[h+j], weight * beta);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
2014-05-09 00:20:54 +00:00
|
|
|
writeVertex(vertex, vid, &dst);
|
2012-06-16 00:52:36 +00:00
|
|
|
|
|
|
|
if (varying) {
|
|
|
|
struct Varying dstVarying;
|
|
|
|
clearVarying(&dstVarying);
|
2014-05-09 00:20:54 +00:00
|
|
|
addVaryingWithWeight(&dstVarying, varying, p, 1.0f);
|
|
|
|
writeVarying(varying, vid, &dstVarying);
|
2012-06-16 00:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-05-09 00:20:54 +00:00
|
|
|
__kernel void editVertexAdd(__global float *vertex,
|
2012-12-11 01:15:13 +00:00
|
|
|
__global int *editIndices,
|
|
|
|
__global float *editValues,
|
2014-05-09 00:20:54 +00:00
|
|
|
int vertexOffset,
|
2012-12-11 01:15:13 +00:00
|
|
|
int primVarOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int primVarWidth,
|
2014-05-09 00:20:54 +00:00
|
|
|
int offset, int tableOffset,
|
2013-03-08 01:50:15 +00:00
|
|
|
int start, int end) {
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
int i = start + get_global_id(0) + tableOffset;
|
2012-12-11 01:15:13 +00:00
|
|
|
int v = editIndices[i];
|
2013-03-08 01:50:15 +00:00
|
|
|
int eid = start + get_global_id(0);
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex += vertexOffset;
|
|
|
|
vertex += v * VERTEX_STRIDE + primVarOffset;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < primVarWidth; ++j) {
|
2014-05-09 00:20:54 +00:00
|
|
|
vertex[j] += editValues[eid*primVarWidth + j];
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
}
|