Path: blob/master/thirdparty/embree/kernels/subdiv/gregory_patch_dense.h
9918 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "gregory_patch.h"67namespace embree8{9class __aligned(64) DenseGregoryPatch3fa10{11typedef Vec3fa Vec3fa_4x4[4][4];12public:1314__forceinline DenseGregoryPatch3fa (const GregoryPatch3fa& patch)15{16for (size_t y=0; y<4; y++)17for (size_t x=0; x<4; x++)18matrix[y][x] = Vec3ff(patch.v[y][x], 0.0f);1920matrix[0][0].w = patch.f[0][0].x;21matrix[0][1].w = patch.f[0][0].y;22matrix[0][2].w = patch.f[0][0].z;23matrix[0][3].w = 0.0f;2425matrix[1][0].w = patch.f[0][1].x;26matrix[1][1].w = patch.f[0][1].y;27matrix[1][2].w = patch.f[0][1].z;28matrix[1][3].w = 0.0f;2930matrix[2][0].w = patch.f[1][1].x;31matrix[2][1].w = patch.f[1][1].y;32matrix[2][2].w = patch.f[1][1].z;33matrix[2][3].w = 0.0f;3435matrix[3][0].w = patch.f[1][0].x;36matrix[3][1].w = patch.f[1][0].y;37matrix[3][2].w = patch.f[1][0].z;38matrix[3][3].w = 0.0f;39}4041__forceinline void extract_f_m(Vec3fa f_m[2][2]) const42{43f_m[0][0] = Vec3fa( matrix[0][0].w, matrix[0][1].w, matrix[0][2].w );44f_m[0][1] = Vec3fa( matrix[1][0].w, matrix[1][1].w, matrix[1][2].w );45f_m[1][1] = Vec3fa( matrix[2][0].w, matrix[2][1].w, matrix[2][2].w );46f_m[1][0] = Vec3fa( matrix[3][0].w, matrix[3][1].w, matrix[3][2].w );47}4849__forceinline Vec3fa eval(const float uu, const float vv) const50{51__aligned(64) Vec3fa f_m[2][2]; extract_f_m(f_m);52return GregoryPatch3fa::eval(*(Vec3fa_4x4*)&matrix,f_m,uu,vv);53}5455__forceinline Vec3fa normal(const float uu, const float vv) const56{57__aligned(64) Vec3fa f_m[2][2]; extract_f_m(f_m);58return GregoryPatch3fa::normal(*(Vec3fa_4x4*)&matrix,f_m,uu,vv);59}6061template<class T>62__forceinline Vec3<T> eval(const T &uu, const T &vv) const63{64Vec3<T> f_m[2][2];65f_m[0][0] = Vec3<T>( matrix[0][0].w, matrix[0][1].w, matrix[0][2].w );66f_m[0][1] = Vec3<T>( matrix[1][0].w, matrix[1][1].w, matrix[1][2].w );67f_m[1][1] = Vec3<T>( matrix[2][0].w, matrix[2][1].w, matrix[2][2].w );68f_m[1][0] = Vec3<T>( matrix[3][0].w, matrix[3][1].w, matrix[3][2].w );69return GregoryPatch3fa::eval_t(*(Vec3fa_4x4*)&matrix,f_m,uu,vv);70}7172template<class T>73__forceinline Vec3<T> normal(const T &uu, const T &vv) const74{75Vec3<T> f_m[2][2];76f_m[0][0] = Vec3<T>( matrix[0][0].w, matrix[0][1].w, matrix[0][2].w );77f_m[0][1] = Vec3<T>( matrix[1][0].w, matrix[1][1].w, matrix[1][2].w );78f_m[1][1] = Vec3<T>( matrix[2][0].w, matrix[2][1].w, matrix[2][2].w );79f_m[1][0] = Vec3<T>( matrix[3][0].w, matrix[3][1].w, matrix[3][2].w );80return GregoryPatch3fa::normal_t(*(Vec3fa_4x4*)&matrix,f_m,uu,vv);81}8283__forceinline void eval(const float u, const float v,84Vec3fa* P, Vec3fa* dPdu, Vec3fa* dPdv, Vec3fa* ddPdudu, Vec3fa* ddPdvdv, Vec3fa* ddPdudv,85const float dscale = 1.0f) const86{87__aligned(64) Vec3fa f_m[2][2]; extract_f_m(f_m);88if (P) {89*P = GregoryPatch3fa::eval(*(Vec3fa_4x4*)&matrix,f_m,u,v);90}91if (dPdu) {92assert(dPdu); *dPdu = GregoryPatch3fa::eval_du(*(Vec3fa_4x4*)&matrix,f_m,u,v)*dscale;93assert(dPdv); *dPdv = GregoryPatch3fa::eval_dv(*(Vec3fa_4x4*)&matrix,f_m,u,v)*dscale;94}95if (ddPdudu) {96assert(ddPdudu); *ddPdudu = GregoryPatch3fa::eval_dudu(*(Vec3fa_4x4*)&matrix,f_m,u,v)*sqr(dscale);97assert(ddPdvdv); *ddPdvdv = GregoryPatch3fa::eval_dvdv(*(Vec3fa_4x4*)&matrix,f_m,u,v)*sqr(dscale);98assert(ddPdudv); *ddPdudv = GregoryPatch3fa::eval_dudv(*(Vec3fa_4x4*)&matrix,f_m,u,v)*sqr(dscale);99}100}101102template<typename vbool, typename vfloat>103__forceinline void eval(const vbool& valid, const vfloat& uu, const vfloat& vv, float* P, float* dPdu, float* dPdv, const float dscale, const size_t dstride, const size_t N) const104{105__aligned(64) Vec3fa f_m[2][2]; extract_f_m(f_m);106GregoryPatch3fa::eval(matrix,f_m,valid,uu,vv,P,dPdu,dPdv,dscale,dstride,N);107}108109private:110Vec3ff matrix[4][4]; // f_p/m points are stored in 4th component111};112}113114115