mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Medium Quality mode for spline patch
This commit is contained in:
parent
b0e97a0d4c
commit
aa08944528
4 changed files with 323 additions and 285 deletions
|
@ -393,7 +393,7 @@ static ConfigSetting graphicsSettings[] = {
|
||||||
// Not really a graphics setting...
|
// Not really a graphics setting...
|
||||||
ReportedConfigSetting("TimerHack", &g_Config.bTimerHack, &DefaultTimerHack),
|
ReportedConfigSetting("TimerHack", &g_Config.bTimerHack, &DefaultTimerHack),
|
||||||
ReportedConfigSetting("AlphaMaskHack", &g_Config.bAlphaMaskHack, false),
|
ReportedConfigSetting("AlphaMaskHack", &g_Config.bAlphaMaskHack, false),
|
||||||
ReportedConfigSetting("LowQualitySplineBezier", &g_Config.bLowQualitySplineBezier, false),
|
ReportedConfigSetting("SplineBezierQuality", &g_Config.iSplineBezierQuality, 2),
|
||||||
ReportedConfigSetting("PostShader", &g_Config.sPostShaderName, "Off"),
|
ReportedConfigSetting("PostShader", &g_Config.sPostShaderName, "Off"),
|
||||||
|
|
||||||
ConfigSetting(false),
|
ConfigSetting(false),
|
||||||
|
|
|
@ -139,7 +139,7 @@ public:
|
||||||
bool bAlwaysDepthWrite;
|
bool bAlwaysDepthWrite;
|
||||||
bool bTimerHack;
|
bool bTimerHack;
|
||||||
bool bAlphaMaskHack;
|
bool bAlphaMaskHack;
|
||||||
bool bLowQualitySplineBezier;
|
int iSplineBezierQuality; // 0 = low , 1 = Intermediate , 2 = High
|
||||||
std::string sPostShaderName; // Off for off.
|
std::string sPostShaderName; // Off for off.
|
||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
// Here's how to evaluate them fast:
|
// Here's how to evaluate them fast:
|
||||||
// http://and-what-happened.blogspot.se/2012/07/evaluating-b-splines-aka-basis-splines.html
|
// http://and-what-happened.blogspot.se/2012/07/evaluating-b-splines-aka-basis-splines.html
|
||||||
|
|
||||||
|
enum quality {
|
||||||
|
LOW_QUALITY = 0,
|
||||||
|
MEDIUM_QUALITY = 1,
|
||||||
|
HIGH_QUALITY = 2,
|
||||||
|
};
|
||||||
|
|
||||||
// This normalizes a set of vertices in any format to SimpleVertex format, by processing away morphing AND skinning.
|
// This normalizes a set of vertices in any format to SimpleVertex format, by processing away morphing AND skinning.
|
||||||
// The rest of the transform pipeline like lighting will go as normal, either hardware or software.
|
// The rest of the transform pipeline like lighting will go as normal, either hardware or software.
|
||||||
// The implementation is initially a bit inefficient but shouldn't be a big deal.
|
// The implementation is initially a bit inefficient but shouldn't be a big deal.
|
||||||
|
@ -341,341 +347,372 @@ void spline_knot(int n, int type, float *knot) {
|
||||||
knot[n + 4] = n - 2;
|
knot[n + 4] = n - 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void _SplinePatchLowQuality(u8 *&dest, int &count, const SplinePatch &spatch, u32 origVertType) {
|
||||||
void TesselateSplinePatch(u8 *&dest, int &count, const SplinePatch &spatch, u32 origVertType) {
|
|
||||||
const float third = 1.0f / 3.0f;
|
const float third = 1.0f / 3.0f;
|
||||||
|
// Fast and easy way - just draw the control points, generate some very basic normal vector substitutes.
|
||||||
|
// Very inaccurate but okay for Loco Roco. Maybe should keep it as an option because it's fast.
|
||||||
|
|
||||||
if (g_Config.bLowQualitySplineBezier) {
|
const int tile_min_u = (spatch.type_u & START_OPEN) ? 0 : 1;
|
||||||
// Fast and easy way - just draw the control points, generate some very basic normal vector substitutes.
|
const int tile_min_v = (spatch.type_v & START_OPEN) ? 0 : 1;
|
||||||
// Very inaccurate but okay for Loco Roco. Maybe should keep it as an option because it's fast.
|
const int tile_max_u = (spatch.type_u & END_OPEN) ? spatch.count_u - 1 : spatch.count_u - 2;
|
||||||
|
const int tile_max_v = (spatch.type_v & END_OPEN) ? spatch.count_v - 1 : spatch.count_v - 2;
|
||||||
|
|
||||||
const int tile_min_u = (spatch.type_u & START_OPEN) ? 0 : 1;
|
for (int tile_v = tile_min_v; tile_v < tile_max_v; ++tile_v) {
|
||||||
const int tile_min_v = (spatch.type_v & START_OPEN) ? 0 : 1;
|
for (int tile_u = tile_min_u; tile_u < tile_max_u; ++tile_u) {
|
||||||
const int tile_max_u = (spatch.type_u & END_OPEN) ? spatch.count_u - 1 : spatch.count_u - 2;
|
int point_index = tile_u + tile_v * spatch.count_u;
|
||||||
const int tile_max_v = (spatch.type_v & END_OPEN) ? spatch.count_v - 1 : spatch.count_v - 2;
|
|
||||||
|
|
||||||
for (int tile_v = tile_min_v; tile_v < tile_max_v; ++tile_v) {
|
SimpleVertex v0 = *spatch.points[point_index];
|
||||||
for (int tile_u = tile_min_u; tile_u < tile_max_u; ++tile_u) {
|
SimpleVertex v1 = *spatch.points[point_index + 1];
|
||||||
int point_index = tile_u + tile_v * spatch.count_u;
|
SimpleVertex v2 = *spatch.points[point_index + spatch.count_u];
|
||||||
|
SimpleVertex v3 = *spatch.points[point_index + spatch.count_u + 1];
|
||||||
|
|
||||||
SimpleVertex v0 = *spatch.points[point_index];
|
// Generate UV. TODO: Do this even if UV specified in control points?
|
||||||
SimpleVertex v1 = *spatch.points[point_index+1];
|
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
|
||||||
SimpleVertex v2 = *spatch.points[point_index+spatch.count_u];
|
float u = tile_u * third;
|
||||||
SimpleVertex v3 = *spatch.points[point_index+spatch.count_u+1];
|
float v = tile_v * third;
|
||||||
|
v0.uv[0] = u;
|
||||||
// Generate UV. TODO: Do this even if UV specified in control points?
|
v0.uv[1] = v;
|
||||||
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
|
v1.uv[0] = u + third;
|
||||||
float u = tile_u * third;
|
v1.uv[1] = v;
|
||||||
float v = tile_v * third;
|
v2.uv[0] = u;
|
||||||
v0.uv[0] = u;
|
v2.uv[1] = v + third;
|
||||||
v0.uv[1] = v;
|
v3.uv[0] = u + third;
|
||||||
v1.uv[0] = u + third;
|
v3.uv[1] = v + third;
|
||||||
v1.uv[1] = v;
|
|
||||||
v2.uv[0] = u;
|
|
||||||
v2.uv[1] = v + third;
|
|
||||||
v3.uv[0] = u + third;
|
|
||||||
v3.uv[1] = v + third;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate normal if lighting is enabled (otherwise there's no point).
|
|
||||||
// This is a really poor quality algorithm, we get facet normals.
|
|
||||||
if (gstate.isLightingEnabled()) {
|
|
||||||
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
|
|
||||||
norm.Normalize();
|
|
||||||
if (gstate.patchfacing & 1)
|
|
||||||
norm *= -1.0f;
|
|
||||||
v0.nrm = norm;
|
|
||||||
v1.nrm = norm;
|
|
||||||
v2.nrm = norm;
|
|
||||||
v3.nrm = norm;
|
|
||||||
}
|
|
||||||
|
|
||||||
CopyQuad(dest, &v0, &v1, &v2, &v3);
|
|
||||||
count += 6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate normal if lighting is enabled (otherwise there's no point).
|
||||||
|
// This is a really poor quality algorithm, we get facet normals.
|
||||||
|
if (gstate.isLightingEnabled()) {
|
||||||
|
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
|
||||||
|
norm.Normalize();
|
||||||
|
if (gstate.patchfacing & 1)
|
||||||
|
norm *= -1.0f;
|
||||||
|
v0.nrm = norm;
|
||||||
|
v1.nrm = norm;
|
||||||
|
v2.nrm = norm;
|
||||||
|
v3.nrm = norm;
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyQuad(dest, &v0, &v1, &v2, &v3);
|
||||||
|
count += 6;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// Full correct tessellation of spline patches.
|
|
||||||
// Does not yet generate normals and is atrociously slow (see spline_s...)
|
|
||||||
|
|
||||||
// First, generate knot vectors.
|
}
|
||||||
int n = spatch.count_u - 1;
|
|
||||||
int m = spatch.count_v - 1;
|
|
||||||
|
|
||||||
float *knot_u = new float[n + 5];
|
void _SplinePatchFullQuality(u8 *&dest, int &count, const SplinePatch &spatch, u32 origVertType, int patch_cap) {
|
||||||
float *knot_v = new float[m + 5];
|
// Full correct tessellation of spline patches.
|
||||||
spline_knot(n, spatch.type_u, knot_u);
|
// Does not yet generate normals and is atrociously slow (see spline_s...)
|
||||||
spline_knot(m, spatch.type_v, knot_v);
|
|
||||||
|
|
||||||
// Increase tesselation based on the size. Should be approximately right?
|
// First, generate knot vectors.
|
||||||
// JPCSP is wrong at least because their method results in square loco roco.
|
int n = spatch.count_u - 1;
|
||||||
int patch_div_s = (spatch.count_u - 3) * gstate.getPatchDivisionU() / 3;
|
int m = spatch.count_v - 1;
|
||||||
int patch_div_t = (spatch.count_v - 3) * gstate.getPatchDivisionV() / 3;
|
|
||||||
|
|
||||||
if (patch_div_s <= 0) patch_div_s = 1;
|
float *knot_u = new float[n + 5];
|
||||||
if (patch_div_t <= 0) patch_div_t = 1;
|
float *knot_v = new float[m + 5];
|
||||||
|
spline_knot(n, spatch.type_u, knot_u);
|
||||||
|
spline_knot(m, spatch.type_v, knot_v);
|
||||||
|
|
||||||
// TODO: Remove this cap when spline_s has been optimized.
|
// Increase tesselation based on the size. Should be approximately right?
|
||||||
if (patch_div_s > 64) patch_div_s = 64;
|
// JPCSP is wrong at least because their method results in square loco roco.
|
||||||
if (patch_div_t > 64) patch_div_t = 64;
|
int patch_div_s = (spatch.count_u - 3) * gstate.getPatchDivisionU() / 3;
|
||||||
|
int patch_div_t = (spatch.count_v - 3) * gstate.getPatchDivisionV() / 3;
|
||||||
|
|
||||||
// First compute all the vertices and put them in an array
|
if (patch_div_s <= 0) patch_div_s = 1;
|
||||||
SimpleVertex *vertices = new SimpleVertex[(patch_div_s + 1) * (patch_div_t + 1)];
|
if (patch_div_t <= 0) patch_div_t = 1;
|
||||||
|
|
||||||
float tu_width = 1.0f + (spatch.count_u - 4) * 1.0f/3.0f;
|
// TODO: Remove this cap when spline_s has been optimized.
|
||||||
float tv_height = 1.0f + (spatch.count_v - 4) * 1.0f/3.0f;
|
if (patch_div_s > patch_cap) patch_div_s = patch_cap;
|
||||||
|
if (patch_div_t > patch_cap) patch_div_t = patch_cap;
|
||||||
|
|
||||||
bool computeNormals = gstate.isLightingEnabled();
|
// First compute all the vertices and put them in an array
|
||||||
for (int tile_v = 0; tile_v < patch_div_t + 1; tile_v++) {
|
SimpleVertex *vertices = new SimpleVertex[(patch_div_s + 1) * (patch_div_t + 1)];
|
||||||
float v = ((float)tile_v * (float)(m - 2) / (float)(patch_div_t + 0.00001f)); // epsilon to prevent division by 0 in spline_s
|
|
||||||
for (int tile_u = 0; tile_u < patch_div_s + 1; tile_u++) {
|
|
||||||
float u = ((float)tile_u * (float)(n - 2) / (float)(patch_div_s + 0.00001f));
|
|
||||||
|
|
||||||
SimpleVertex *vert = &vertices[tile_v * (patch_div_s + 1) + tile_u];
|
float tu_width = 1.0f + (spatch.count_u - 4) * 1.0f / 3.0f;
|
||||||
vert->pos.SetZero();
|
float tv_height = 1.0f + (spatch.count_v - 4) * 1.0f / 3.0f;
|
||||||
if (origVertType & GE_VTYPE_NRM_MASK) {
|
|
||||||
vert->nrm.SetZero();
|
|
||||||
} else {
|
|
||||||
vert->nrm.SetZero();
|
|
||||||
vert->nrm.z = 1.0f;
|
|
||||||
}
|
|
||||||
if (origVertType & GE_VTYPE_COL_MASK) {
|
|
||||||
memset(vert->color, 0, 4);
|
|
||||||
} else {
|
|
||||||
memcpy(vert->color, spatch.points[0]->color, 4);
|
|
||||||
}
|
|
||||||
if (origVertType & GE_VTYPE_TC_MASK) {
|
|
||||||
vert->uv[0] = 0.0f;
|
|
||||||
vert->uv[1] = 0.0f;
|
|
||||||
} else {
|
|
||||||
vert->uv[0] = tu_width * ((float)tile_u / (float)patch_div_s);
|
|
||||||
vert->uv[1] = tv_height * ((float)tile_v / (float)patch_div_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect influences from surrounding control points.
|
bool computeNormals = gstate.isLightingEnabled();
|
||||||
float u_weights[4];
|
for (int tile_v = 0; tile_v < patch_div_t + 1; tile_v++) {
|
||||||
float v_weights[4];
|
float v = ((float)tile_v * (float)(m - 2) / (float)(patch_div_t + 0.00001f)); // epsilon to prevent division by 0 in spline_s
|
||||||
|
for (int tile_u = 0; tile_u < patch_div_s + 1; tile_u++) {
|
||||||
|
float u = ((float)tile_u * (float)(n - 2) / (float)(patch_div_s + 0.00001f));
|
||||||
|
|
||||||
int iu = (int)u;
|
SimpleVertex *vert = &vertices[tile_v * (patch_div_s + 1) + tile_u];
|
||||||
int iv = (int)v;
|
vert->pos.SetZero();
|
||||||
spline_n_4(iu, u, knot_u, u_weights);
|
if (origVertType & GE_VTYPE_NRM_MASK) {
|
||||||
spline_n_4(iv, v, knot_v, v_weights);
|
vert->nrm.SetZero();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vert->nrm.SetZero();
|
||||||
|
vert->nrm.z = 1.0f;
|
||||||
|
}
|
||||||
|
if (origVertType & GE_VTYPE_COL_MASK) {
|
||||||
|
memset(vert->color, 0, 4);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
memcpy(vert->color, spatch.points[0]->color, 4);
|
||||||
|
}
|
||||||
|
if (origVertType & GE_VTYPE_TC_MASK) {
|
||||||
|
vert->uv[0] = 0.0f;
|
||||||
|
vert->uv[1] = 0.0f;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vert->uv[0] = tu_width * ((float)tile_u / (float)patch_div_s);
|
||||||
|
vert->uv[1] = tv_height * ((float)tile_v / (float)patch_div_t);
|
||||||
|
}
|
||||||
|
|
||||||
for (int ii = 0; ii < 4; ++ii) {
|
// Collect influences from surrounding control points.
|
||||||
for (int jj = 0; jj < 4; ++jj) {
|
float u_weights[4];
|
||||||
float u_spline = u_weights[ii];
|
float v_weights[4];
|
||||||
float v_spline = v_weights[jj];
|
|
||||||
float f = u_spline * v_spline;
|
|
||||||
|
|
||||||
if (f > 0.0f) {
|
int iu = (int)u;
|
||||||
SimpleVertex *a = spatch.points[spatch.count_u * (iv + jj) + (iu + ii)];
|
int iv = (int)v;
|
||||||
vert->pos += a->pos * f;
|
spline_n_4(iu, u, knot_u, u_weights);
|
||||||
if (origVertType & GE_VTYPE_TC_MASK) {
|
spline_n_4(iv, v, knot_v, v_weights);
|
||||||
vert->uv[0] += a->uv[0] * f;
|
|
||||||
vert->uv[1] += a->uv[1] * f;
|
for (int ii = 0; ii < 4; ++ii) {
|
||||||
}
|
for (int jj = 0; jj < 4; ++jj) {
|
||||||
if (origVertType & GE_VTYPE_COL_MASK) {
|
float u_spline = u_weights[ii];
|
||||||
vert->color[0] += a->color[0] * f;
|
float v_spline = v_weights[jj];
|
||||||
vert->color[1] += a->color[1] * f;
|
float f = u_spline * v_spline;
|
||||||
vert->color[2] += a->color[2] * f;
|
|
||||||
vert->color[3] += a->color[3] * f;
|
if (f > 0.0f) {
|
||||||
}
|
SimpleVertex *a = spatch.points[spatch.count_u * (iv + jj) + (iu + ii)];
|
||||||
if (origVertType & GE_VTYPE_NRM_MASK) {
|
vert->pos += a->pos * f;
|
||||||
vert->nrm += a->nrm * f;
|
if (origVertType & GE_VTYPE_TC_MASK) {
|
||||||
}
|
vert->uv[0] += a->uv[0] * f;
|
||||||
|
vert->uv[1] += a->uv[1] * f;
|
||||||
|
}
|
||||||
|
if (origVertType & GE_VTYPE_COL_MASK) {
|
||||||
|
vert->color[0] += a->color[0] * f;
|
||||||
|
vert->color[1] += a->color[1] * f;
|
||||||
|
vert->color[2] += a->color[2] * f;
|
||||||
|
vert->color[3] += a->color[3] * f;
|
||||||
|
}
|
||||||
|
if (origVertType & GE_VTYPE_NRM_MASK) {
|
||||||
|
vert->nrm += a->nrm * f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (origVertType & GE_VTYPE_NRM_MASK) {
|
}
|
||||||
vert->nrm.Normalize();
|
if (origVertType & GE_VTYPE_NRM_MASK) {
|
||||||
|
vert->nrm.Normalize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] knot_u;
|
||||||
|
delete[] knot_v;
|
||||||
|
|
||||||
|
// Hacky normal generation through central difference.
|
||||||
|
if (gstate.isLightingEnabled() && (origVertType & GE_VTYPE_NRM_MASK) == 0) {
|
||||||
|
for (int v = 0; v < patch_div_t + 1; v++) {
|
||||||
|
for (int u = 0; u < patch_div_s + 1; u++) {
|
||||||
|
int l = std::max(0, u - 1);
|
||||||
|
int t = std::max(0, v - 1);
|
||||||
|
int r = std::min(patch_div_s, u + 1);
|
||||||
|
int b = std::min(patch_div_t, v + 1);
|
||||||
|
|
||||||
|
const Vec3Packedf &right = vertices[v * (patch_div_s + 1) + r].pos - vertices[v * (patch_div_s + 1) + l].pos;
|
||||||
|
const Vec3Packedf &down = vertices[b * (patch_div_s + 1) + u].pos - vertices[t * (patch_div_s + 1) + u].pos;
|
||||||
|
|
||||||
|
vertices[v * (patch_div_s + 1) + u].nrm = Cross(right, down).Normalized();
|
||||||
|
if (gstate.patchfacing & 1) {
|
||||||
|
vertices[v * (patch_div_s + 1) + u].nrm *= -1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete [] knot_u;
|
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
|
||||||
delete [] knot_v;
|
for (int tile_v = 0; tile_v < patch_div_t; ++tile_v) {
|
||||||
|
for (int tile_u = 0; tile_u < patch_div_s; ++tile_u) {
|
||||||
|
float u = ((float)tile_u / (float)patch_div_s);
|
||||||
|
float v = ((float)tile_v / (float)patch_div_t);
|
||||||
|
|
||||||
// Hacky normal generation through central difference.
|
SimpleVertex *v0 = &vertices[tile_v * (patch_div_s + 1) + tile_u];
|
||||||
if (gstate.isLightingEnabled() && (origVertType & GE_VTYPE_NRM_MASK) == 0) {
|
SimpleVertex *v1 = &vertices[tile_v * (patch_div_s + 1) + tile_u + 1];
|
||||||
for (int v = 0; v < patch_div_t + 1; v++) {
|
SimpleVertex *v2 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u];
|
||||||
for (int u = 0; u < patch_div_s + 1; u++) {
|
SimpleVertex *v3 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u + 1];
|
||||||
int l = std::max(0, u - 1);
|
|
||||||
int t = std::max(0, v - 1);
|
|
||||||
int r = std::min(patch_div_s, u + 1);
|
|
||||||
int b = std::min(patch_div_t, v + 1);
|
|
||||||
|
|
||||||
const Vec3Packedf &right = vertices[v * (patch_div_s + 1) + r].pos - vertices[v * (patch_div_s + 1) + l].pos;
|
CopyQuad(dest, v0, v1, v2, v3);
|
||||||
const Vec3Packedf &down = vertices[b * (patch_div_s + 1) + u].pos - vertices[t * (patch_div_s + 1) + u].pos;
|
count += 6;
|
||||||
|
|
||||||
vertices[v * (patch_div_s + 1) + u].nrm = Cross(right, down).Normalized();
|
|
||||||
if (gstate.patchfacing & 1) {
|
|
||||||
vertices[v * (patch_div_s + 1) + u].nrm *= -1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
|
delete[] vertices;
|
||||||
for (int tile_v = 0; tile_v < patch_div_t; ++tile_v) {
|
}
|
||||||
for (int tile_u = 0; tile_u < patch_div_s; ++tile_u) {
|
|
||||||
float u = ((float)tile_u / (float)patch_div_s);
|
|
||||||
float v = ((float)tile_v / (float)patch_div_t);
|
|
||||||
|
|
||||||
SimpleVertex *v0 = &vertices[tile_v * (patch_div_s + 1) + tile_u];
|
void TesselateSplinePatch(u8 *&dest, int &count, const SplinePatch &spatch, u32 origVertType) {
|
||||||
SimpleVertex *v1 = &vertices[tile_v * (patch_div_s + 1) + tile_u + 1];
|
|
||||||
SimpleVertex *v2 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u];
|
|
||||||
SimpleVertex *v3 = &vertices[(tile_v + 1) * (patch_div_s + 1) + tile_u + 1];
|
|
||||||
|
|
||||||
CopyQuad(dest, v0, v1, v2, v3);
|
switch (g_Config.iSplineBezierQuality) {
|
||||||
count += 6;
|
case LOW_QUALITY:
|
||||||
|
_SplinePatchLowQuality(dest, count, spatch, origVertType);
|
||||||
|
break;
|
||||||
|
case MEDIUM_QUALITY:
|
||||||
|
_SplinePatchFullQuality(dest, count, spatch, origVertType, 8);
|
||||||
|
break;
|
||||||
|
case HIGH_QUALITY:
|
||||||
|
_SplinePatchFullQuality(dest, count, spatch, origVertType, 64);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
void _BezierPatchLowQuality(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
|
||||||
|
const float third = 1.0f / 3.0f;
|
||||||
|
// Fast and easy way - just draw the control points, generate some very basic normal vector subsitutes.
|
||||||
|
// Very inaccurate though but okay for Loco Roco. Maybe should keep it as an option.
|
||||||
|
|
||||||
|
float u_base = patch.u_index / 3.0f;
|
||||||
|
float v_base = patch.v_index / 3.0f;
|
||||||
|
|
||||||
|
for (int tile_v = 0; tile_v < 3; tile_v++) {
|
||||||
|
for (int tile_u = 0; tile_u < 3; tile_u++) {
|
||||||
|
int point_index = tile_u + tile_v * 4;
|
||||||
|
|
||||||
|
SimpleVertex v0 = *patch.points[point_index];
|
||||||
|
SimpleVertex v1 = *patch.points[point_index + 1];
|
||||||
|
SimpleVertex v2 = *patch.points[point_index + 4];
|
||||||
|
SimpleVertex v3 = *patch.points[point_index + 5];
|
||||||
|
|
||||||
|
// Generate UV. TODO: Do this even if UV specified in control points?
|
||||||
|
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
|
||||||
|
float u = u_base + tile_u * third;
|
||||||
|
float v = v_base + tile_v * third;
|
||||||
|
v0.uv[0] = u;
|
||||||
|
v0.uv[1] = v;
|
||||||
|
v1.uv[0] = u + third;
|
||||||
|
v1.uv[1] = v;
|
||||||
|
v2.uv[0] = u;
|
||||||
|
v2.uv[1] = v + third;
|
||||||
|
v3.uv[0] = u + third;
|
||||||
|
v3.uv[1] = v + third;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
delete [] vertices;
|
// Generate normal if lighting is enabled (otherwise there's no point).
|
||||||
|
// This is a really poor quality algorithm, we get facet normals.
|
||||||
|
if (gstate.isLightingEnabled()) {
|
||||||
|
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
|
||||||
|
norm.Normalize();
|
||||||
|
if (gstate.patchfacing & 1)
|
||||||
|
norm *= -1.0f;
|
||||||
|
v0.nrm = norm;
|
||||||
|
v1.nrm = norm;
|
||||||
|
v2.nrm = norm;
|
||||||
|
v3.nrm = norm;
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyQuad(dest, &v0, &v1, &v2, &v3);
|
||||||
|
count += 6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TesselateBezierPatch(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
|
void _BezierPatchHighQuality(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
|
||||||
const float third = 1.0f / 3.0f;
|
const float third = 1.0f / 3.0f;
|
||||||
|
// Full correct tesselation of bezier patches.
|
||||||
|
// Note: Does not handle splines correctly.
|
||||||
|
|
||||||
if (g_Config.bLowQualitySplineBezier) {
|
// First compute all the vertices and put them in an array
|
||||||
// Fast and easy way - just draw the control points, generate some very basic normal vector subsitutes.
|
SimpleVertex *vertices = new SimpleVertex[(tess_u + 1) * (tess_v + 1)];
|
||||||
// Very inaccurate though but okay for Loco Roco. Maybe should keep it as an option.
|
|
||||||
|
|
||||||
float u_base = patch.u_index / 3.0f;
|
Vec3Packedf *horiz = new Vec3Packedf[(tess_u + 1) * 4];
|
||||||
float v_base = patch.v_index / 3.0f;
|
Vec3Packedf *horiz2 = horiz + (tess_u + 1) * 1;
|
||||||
|
Vec3Packedf *horiz3 = horiz + (tess_u + 1) * 2;
|
||||||
|
Vec3Packedf *horiz4 = horiz + (tess_u + 1) * 3;
|
||||||
|
|
||||||
for (int tile_v = 0; tile_v < 3; tile_v++) {
|
// Precompute the horizontal curves to we only have to evaluate the vertical ones.
|
||||||
for (int tile_u = 0; tile_u < 3; tile_u++) {
|
for (int i = 0; i < tess_u + 1; i++) {
|
||||||
int point_index = tile_u + tile_v * 4;
|
float u = ((float)i / (float)tess_u);
|
||||||
|
horiz[i] = Bernstein3D(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, u);
|
||||||
|
horiz2[i] = Bernstein3D(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, u);
|
||||||
|
horiz3[i] = Bernstein3D(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, u);
|
||||||
|
horiz4[i] = Bernstein3D(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, u);
|
||||||
|
}
|
||||||
|
|
||||||
SimpleVertex v0 = *patch.points[point_index];
|
bool computeNormals = gstate.isLightingEnabled();
|
||||||
SimpleVertex v1 = *patch.points[point_index+1];
|
|
||||||
SimpleVertex v2 = *patch.points[point_index+4];
|
|
||||||
SimpleVertex v3 = *patch.points[point_index+5];
|
|
||||||
|
|
||||||
// Generate UV. TODO: Do this even if UV specified in control points?
|
for (int tile_v = 0; tile_v < tess_v + 1; ++tile_v) {
|
||||||
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
|
for (int tile_u = 0; tile_u < tess_u + 1; ++tile_u) {
|
||||||
float u = u_base + tile_u * third;
|
float u = ((float)tile_u / (float)tess_u);
|
||||||
float v = v_base + tile_v * third;
|
float v = ((float)tile_v / (float)tess_v);
|
||||||
v0.uv[0] = u;
|
float bu = u;
|
||||||
v0.uv[1] = v;
|
float bv = v;
|
||||||
v1.uv[0] = u + third;
|
|
||||||
v1.uv[1] = v;
|
|
||||||
v2.uv[0] = u;
|
|
||||||
v2.uv[1] = v + third;
|
|
||||||
v3.uv[0] = u + third;
|
|
||||||
v3.uv[1] = v + third;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate normal if lighting is enabled (otherwise there's no point).
|
// TODO: Should be able to precompute the four curves per U, then just Bernstein per V. Will benefit large tesselation factors.
|
||||||
// This is a really poor quality algorithm, we get facet normals.
|
const Vec3Packedf &pos1 = horiz[tile_u];
|
||||||
if (gstate.isLightingEnabled()) {
|
const Vec3Packedf &pos2 = horiz2[tile_u];
|
||||||
Vec3Packedf norm = Cross(v1.pos - v0.pos, v2.pos - v0.pos);
|
const Vec3Packedf &pos3 = horiz3[tile_u];
|
||||||
norm.Normalize();
|
const Vec3Packedf &pos4 = horiz4[tile_u];
|
||||||
if (gstate.patchfacing & 1)
|
|
||||||
norm *= -1.0f;
|
|
||||||
v0.nrm = norm;
|
|
||||||
v1.nrm = norm;
|
|
||||||
v2.nrm = norm;
|
|
||||||
v3.nrm = norm;
|
|
||||||
}
|
|
||||||
|
|
||||||
CopyQuad(dest, &v0, &v1, &v2, &v3);
|
SimpleVertex &vert = vertices[tile_v * (tess_u + 1) + tile_u];
|
||||||
count += 6;
|
|
||||||
|
if (computeNormals) {
|
||||||
|
Vec3Packedf derivU1 = Bernstein3DDerivative(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, bu);
|
||||||
|
Vec3Packedf derivU2 = Bernstein3DDerivative(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, bu);
|
||||||
|
Vec3Packedf derivU3 = Bernstein3DDerivative(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, bu);
|
||||||
|
Vec3Packedf derivU4 = Bernstein3DDerivative(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, bu);
|
||||||
|
Vec3Packedf derivU = Bernstein3D(derivU1, derivU2, derivU3, derivU4, bv);
|
||||||
|
Vec3Packedf derivV = Bernstein3DDerivative(pos1, pos2, pos3, pos4, bv);
|
||||||
|
|
||||||
|
// TODO: Interpolate normals instead of generating them, if available?
|
||||||
|
vert.nrm = Cross(derivU, derivV).Normalized();
|
||||||
|
if (gstate.patchfacing & 1)
|
||||||
|
vert.nrm *= -1.0f;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vert.nrm.SetZero();
|
||||||
|
}
|
||||||
|
|
||||||
|
vert.pos = Bernstein3D(pos1, pos2, pos3, pos4, bv);
|
||||||
|
|
||||||
|
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
|
||||||
|
// Generate texcoord
|
||||||
|
vert.uv[0] = u + patch.u_index * third;
|
||||||
|
vert.uv[1] = v + patch.v_index * third;
|
||||||
|
} else {
|
||||||
|
// Sample UV from control points
|
||||||
|
patch.sampleTexUV(u, v, vert.uv[0], vert.uv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (origVertType & GE_VTYPE_COL_MASK) {
|
||||||
|
patch.sampleColor(u, v, vert.color);
|
||||||
|
} else {
|
||||||
|
memcpy(vert.color, patch.points[0]->color, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// Full correct tesselation of bezier patches.
|
delete[] horiz;
|
||||||
// Note: Does not handle splines correctly.
|
|
||||||
|
|
||||||
// First compute all the vertices and put them in an array
|
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
|
||||||
SimpleVertex *vertices = new SimpleVertex[(tess_u + 1) * (tess_v + 1)];
|
for (int tile_v = 0; tile_v < tess_v; ++tile_v) {
|
||||||
|
for (int tile_u = 0; tile_u < tess_u; ++tile_u) {
|
||||||
|
float u = ((float)tile_u / (float)tess_u);
|
||||||
|
float v = ((float)tile_v / (float)tess_v);
|
||||||
|
|
||||||
Vec3Packedf *horiz = new Vec3Packedf[(tess_u + 1) * 4];
|
const SimpleVertex *v0 = &vertices[tile_v * (tess_u + 1) + tile_u];
|
||||||
Vec3Packedf *horiz2 = horiz + (tess_u + 1) * 1;
|
const SimpleVertex *v1 = &vertices[tile_v * (tess_u + 1) + tile_u + 1];
|
||||||
Vec3Packedf *horiz3 = horiz + (tess_u + 1) * 2;
|
const SimpleVertex *v2 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u];
|
||||||
Vec3Packedf *horiz4 = horiz + (tess_u + 1) * 3;
|
const SimpleVertex *v3 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u + 1];
|
||||||
|
|
||||||
// Precompute the horizontal curves to we only have to evaluate the vertical ones.
|
CopyQuad(dest, v0, v1, v2, v3);
|
||||||
for (int i = 0; i < tess_u + 1; i++) {
|
count += 6;
|
||||||
float u = ((float)i / (float)tess_u);
|
|
||||||
horiz[i] = Bernstein3D(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, u);
|
|
||||||
horiz2[i] = Bernstein3D(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, u);
|
|
||||||
horiz3[i] = Bernstein3D(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, u);
|
|
||||||
horiz4[i] = Bernstein3D(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, u);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool computeNormals = gstate.isLightingEnabled();
|
delete[] vertices;
|
||||||
|
}
|
||||||
|
|
||||||
for (int tile_v = 0; tile_v < tess_v + 1; ++tile_v) {
|
void TesselateBezierPatch(u8 *&dest, int &count, int tess_u, int tess_v, const BezierPatch &patch, u32 origVertType) {
|
||||||
for (int tile_u = 0; tile_u < tess_u + 1; ++tile_u) {
|
switch (g_Config.iSplineBezierQuality) {
|
||||||
float u = ((float)tile_u / (float)tess_u);
|
case LOW_QUALITY:
|
||||||
float v = ((float)tile_v / (float)tess_v);
|
_BezierPatchLowQuality(dest, count, tess_u, tess_v, patch, origVertType);
|
||||||
float bu = u;
|
break;
|
||||||
float bv = v;
|
case MEDIUM_QUALITY:
|
||||||
|
case HIGH_QUALITY:
|
||||||
// TODO: Should be able to precompute the four curves per U, then just Bernstein per V. Will benefit large tesselation factors.
|
_BezierPatchHighQuality(dest, count, tess_u, tess_v, patch, origVertType);
|
||||||
const Vec3Packedf &pos1 = horiz[tile_u];
|
break;
|
||||||
const Vec3Packedf &pos2 = horiz2[tile_u];
|
|
||||||
const Vec3Packedf &pos3 = horiz3[tile_u];
|
|
||||||
const Vec3Packedf &pos4 = horiz4[tile_u];
|
|
||||||
|
|
||||||
SimpleVertex &vert = vertices[tile_v * (tess_u + 1) + tile_u];
|
|
||||||
|
|
||||||
if (computeNormals) {
|
|
||||||
Vec3Packedf derivU1 = Bernstein3DDerivative(patch.points[0]->pos, patch.points[1]->pos, patch.points[2]->pos, patch.points[3]->pos, bu);
|
|
||||||
Vec3Packedf derivU2 = Bernstein3DDerivative(patch.points[4]->pos, patch.points[5]->pos, patch.points[6]->pos, patch.points[7]->pos, bu);
|
|
||||||
Vec3Packedf derivU3 = Bernstein3DDerivative(patch.points[8]->pos, patch.points[9]->pos, patch.points[10]->pos, patch.points[11]->pos, bu);
|
|
||||||
Vec3Packedf derivU4 = Bernstein3DDerivative(patch.points[12]->pos, patch.points[13]->pos, patch.points[14]->pos, patch.points[15]->pos, bu);
|
|
||||||
Vec3Packedf derivU = Bernstein3D(derivU1, derivU2, derivU3, derivU4, bv);
|
|
||||||
Vec3Packedf derivV = Bernstein3DDerivative(pos1, pos2, pos3, pos4, bv);
|
|
||||||
|
|
||||||
// TODO: Interpolate normals instead of generating them, if available?
|
|
||||||
vert.nrm = Cross(derivU, derivV).Normalized();
|
|
||||||
if (gstate.patchfacing & 1)
|
|
||||||
vert.nrm *= -1.0f;
|
|
||||||
} else {
|
|
||||||
vert.nrm.SetZero();
|
|
||||||
}
|
|
||||||
|
|
||||||
vert.pos = Bernstein3D(pos1, pos2, pos3, pos4, bv);
|
|
||||||
|
|
||||||
if ((origVertType & GE_VTYPE_TC_MASK) == 0) {
|
|
||||||
// Generate texcoord
|
|
||||||
vert.uv[0] = u + patch.u_index * third;
|
|
||||||
vert.uv[1] = v + patch.v_index * third;
|
|
||||||
} else {
|
|
||||||
// Sample UV from control points
|
|
||||||
patch.sampleTexUV(u, v, vert.uv[0], vert.uv[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (origVertType & GE_VTYPE_COL_MASK) {
|
|
||||||
patch.sampleColor(u, v, vert.color);
|
|
||||||
} else {
|
|
||||||
memcpy(vert.color, patch.points[0]->color, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete [] horiz;
|
|
||||||
|
|
||||||
// Tesselate. TODO: Use indices so we only need to emit 4 vertices per pair of triangles instead of six.
|
|
||||||
for (int tile_v = 0; tile_v < tess_v; ++tile_v) {
|
|
||||||
for (int tile_u = 0; tile_u < tess_u; ++tile_u) {
|
|
||||||
float u = ((float)tile_u / (float)tess_u);
|
|
||||||
float v = ((float)tile_v / (float)tess_v);
|
|
||||||
|
|
||||||
const SimpleVertex *v0 = &vertices[tile_v * (tess_u + 1) + tile_u];
|
|
||||||
const SimpleVertex *v1 = &vertices[tile_v * (tess_u + 1) + tile_u + 1];
|
|
||||||
const SimpleVertex *v2 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u];
|
|
||||||
const SimpleVertex *v3 = &vertices[(tile_v + 1) * (tess_u + 1) + tile_u + 1];
|
|
||||||
|
|
||||||
CopyQuad(dest, v0, v1, v2, v3);
|
|
||||||
count += 6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete [] vertices;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,8 +165,9 @@ void GameSettingsScreen::CreateViews() {
|
||||||
// vtxJit->SetEnabled(false);
|
// vtxJit->SetEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
graphicsSettings->Add(new CheckBox(&g_Config.bLowQualitySplineBezier, gs->T("LowCurves", "Low quality spline/bezier curves")));
|
static const char *quality[] = { "Low", "Medium", "High"};
|
||||||
|
graphicsSettings->Add(new PopupMultiChoice(&g_Config.iSplineBezierQuality, gs->T("LowCurves", "Spline/Bezier curves quality"), quality, 0, ARRAY_SIZE(quality), gs, screenManager()));
|
||||||
|
|
||||||
// In case we're going to add few other antialiasing option like MSAA in the future.
|
// In case we're going to add few other antialiasing option like MSAA in the future.
|
||||||
// graphicsSettings->Add(new CheckBox(&g_Config.bFXAA, gs->T("FXAA")));
|
// graphicsSettings->Add(new CheckBox(&g_Config.bFXAA, gs->T("FXAA")));
|
||||||
graphicsSettings->Add(new ItemHeader(gs->T("Texture Scaling")));
|
graphicsSettings->Add(new ItemHeader(gs->T("Texture Scaling")));
|
||||||
|
|
Loading…
Add table
Reference in a new issue