mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
Add config var to toggle between incorrect/correct normal generation for GeoMipTerrain
This commit is contained in:
parent
83d9c4f528
commit
da1d5755f9
@ -30,6 +30,14 @@
|
|||||||
|
|
||||||
#include "collideMask.h"
|
#include "collideMask.h"
|
||||||
|
|
||||||
|
static ConfigVariableBool geomipterrain_incorrect_normals
|
||||||
|
("geomipterrain-incorrect-normals", true,
|
||||||
|
PRC_DESC("If true, uses the incorrect normal vector calculation that "
|
||||||
|
"was used in Panda3D versions 1.9.0 and earlier. If false, "
|
||||||
|
"uses the correct calculation. For backward compatibility, "
|
||||||
|
"the default value is true in 1.9 releases, and false in "
|
||||||
|
"Panda3D 1.10.0 and above."));
|
||||||
|
|
||||||
TypeHandle GeoMipTerrain::_type_handle;
|
TypeHandle GeoMipTerrain::_type_handle;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -123,12 +131,12 @@ generate_block(unsigned short mx,
|
|||||||
LVecBase4f color = _color_map.get_xel_a(
|
LVecBase4f color = _color_map.get_xel_a(
|
||||||
int((mx * _block_size + x) * cmap_xratio),
|
int((mx * _block_size + x) * cmap_xratio),
|
||||||
int((my * _block_size + y) * cmap_yratio));
|
int((my * _block_size + y) * cmap_yratio));
|
||||||
cwriter.add_data4f(color);
|
cwriter.set_data4f(color);
|
||||||
}
|
}
|
||||||
vwriter.add_data3(x - 0.5 * _block_size, y - 0.5 * _block_size, get_pixel_value(mx, my, x, y));
|
vwriter.set_data3(x - 0.5 * _block_size, y - 0.5 * _block_size, get_pixel_value(mx, my, x, y));
|
||||||
twriter.add_data2((mx * _block_size + x) * tc_xscale,
|
twriter.set_data2((mx * _block_size + x) * tc_xscale,
|
||||||
(my * _block_size + y) * tc_yscale);
|
(my * _block_size + y) * tc_yscale);
|
||||||
nwriter.add_data3(get_normal(mx, my, x, y));
|
nwriter.set_data3(get_normal(mx, my, x, y));
|
||||||
|
|
||||||
if (x > 0 && y > 0) {
|
if (x > 0 && y > 0) {
|
||||||
// Left border
|
// Left border
|
||||||
@ -328,11 +336,15 @@ get_normal(int x, int y) {
|
|||||||
if (ny < 0) ny++;
|
if (ny < 0) ny++;
|
||||||
if (px >= int(_xsize)) px--;
|
if (px >= int(_xsize)) px--;
|
||||||
if (py >= int(_ysize)) py--;
|
if (py >= int(_ysize)) py--;
|
||||||
double drx = get_pixel_value(px, y) - get_pixel_value(nx, y);
|
double drx = get_pixel_value(nx, y) - get_pixel_value(px, y);
|
||||||
double dry = get_pixel_value(x, py) - get_pixel_value(x, ny);
|
double dry = get_pixel_value(x, py) - get_pixel_value(x, ny);
|
||||||
LVector3 normal(drx * 0.5, dry * 0.5, 1);
|
LVector3 normal(drx * 0.5, dry * 0.5, 1);
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
|
|
||||||
|
if (geomipterrain_incorrect_normals) {
|
||||||
|
normal[0] = -normal[0];
|
||||||
|
}
|
||||||
|
|
||||||
return normal;
|
return normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user