mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
commit ambient occlusion for terrain
This commit is contained in:
parent
58124af9f5
commit
feaac60df4
@ -1,7 +1,5 @@
|
||||
// Filename: geoMipTerrain.I
|
||||
// Created by: pro-rsoft (29jun07)
|
||||
// Modified by: CMU ETC Summer 2010 team (03aug10) (added getters
|
||||
// for _auto_flatten, _near, _far).
|
||||
// Created by: rdb (29Jun07)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -520,7 +518,7 @@ set_color_map(const string &path) {
|
||||
// Description: Returns whether a color map has been set.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool GeoMipTerrain::
|
||||
has_color_map() {
|
||||
has_color_map() const {
|
||||
return _has_color_map;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Filename: geoMipTerrain.cxx
|
||||
// Created by: pro-rsoft (29jun07)
|
||||
// Created by: rdb (29Jun07)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -73,7 +73,7 @@ generate_block(unsigned short mx,
|
||||
vdata->unclean_set_num_rows((_block_size + 1) * (_block_size + 1));
|
||||
GeomVertexWriter cwriter;
|
||||
if (_has_color_map) {
|
||||
cwriter=GeomVertexWriter(vdata, "color" );
|
||||
cwriter = GeomVertexWriter(vdata, "color");
|
||||
}
|
||||
GeomVertexWriter vwriter (vdata, "vertex" );
|
||||
GeomVertexWriter twriter (vdata, "texcoord");
|
||||
@ -355,12 +355,46 @@ make_slope_image() {
|
||||
normal.get_y() / _root.get_sy(),
|
||||
normal.get_z() / _root.get_sz());
|
||||
normal.normalize();
|
||||
result.set_gray(x, y, normal.angle_deg(LVector3f::up()) / 90.0);
|
||||
result.set_xel(x, y, normal.angle_deg(LVector3f::up()) / 90.0);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GeoMipTerrain::calc_ambient_occlusion
|
||||
// Access: Published
|
||||
// Description: Calculates an approximate for the ambient occlusion
|
||||
// and stores it in the color map, so that it will be
|
||||
// written to the vertex colors. Any existing color
|
||||
// map will be discarded.
|
||||
// You need to call this before generating the geometry.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void GeoMipTerrain::
|
||||
calc_ambient_occlusion(float radius, float contrast, float brightness) {
|
||||
_color_map = PNMImage(_xsize, _ysize);
|
||||
_color_map.make_grayscale();
|
||||
_color_map.set_maxval(_heightfield.get_maxval());
|
||||
|
||||
for (unsigned int x = 0; x < _xsize; ++x) {
|
||||
for (unsigned int y = 0; y < _ysize; ++y) {
|
||||
_color_map.set_xel(x, _ysize - y - 1, get_pixel_value(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
// We use the cheap old method of subtracting a blurred version
|
||||
// of the heightmap from the heightmap, and using that as lightmap.
|
||||
_color_map.gaussian_filter(radius);
|
||||
|
||||
for (unsigned int x = 0; x < _xsize; ++x) {
|
||||
for (unsigned int y = 0; y < _ysize; ++y) {
|
||||
_color_map.set_xel(x, y, (get_pixel_value(x, _ysize - y - 1) - _color_map.get_gray(x, y)) * contrast + brightness);
|
||||
}
|
||||
}
|
||||
|
||||
_has_color_map = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GeoMipTerrain::generate
|
||||
// Access: Published
|
||||
|
@ -1,7 +1,5 @@
|
||||
// Filename: geoMipTerrain.h
|
||||
// Created by: pro-rsoft (29jun07)
|
||||
// Modified by: CMU ETC Summer 2010 team (03aug10) (added
|
||||
// get_flatten_mode(), get_near(), get_far() ).
|
||||
// Created by: rdb (29Jun07)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -54,8 +52,9 @@ PUBLISHED:
|
||||
INLINE bool set_color_map(const PNMImage &image);
|
||||
INLINE bool set_color_map(const Texture *image);
|
||||
INLINE bool set_color_map(const string &path);
|
||||
INLINE bool has_color_map();
|
||||
INLINE bool has_color_map() const;
|
||||
INLINE void clear_color_map();
|
||||
void calc_ambient_occlusion(float radius = 32, float contrast = 2.0f, float brightness = 0.75f);
|
||||
double get_elevation(double x, double y);
|
||||
LVector3f get_normal(int x, int y);
|
||||
INLINE LVector3f get_normal(unsigned short mx, unsigned short my,
|
||||
|
Loading…
x
Reference in New Issue
Block a user