50 Say(
"Terrain initialization failed: invalid parameters.\n" 54 "detail repetition = %n\n")
64 Log::error(
"vertex shader or fragment shader not defined.\n");
71 bool use_uniform_transform =
false;
82 if ( (!detail_img && !
detailTexture().empty()) || !terrain_img || !heightmap_img)
84 Log::error(
"Terrain initialization failed.\n");
91 int x_subdivision = -1;
92 for(
int ch=1; ch<1024; ++ch)
94 for(
int ts=128; ts<=1024*8; ts*=2)
97 if (ch*ts-ch+1 == heightmap_img->
width())
105 int y_subdivision = -1;
106 for(
int ch=1; ch<1024; ++ch)
108 for(
int ts=128; ts<=1024*8; ts*=2)
111 if (ch*ts-ch+1 == heightmap_img->
height())
119 if ( x_subdivision == -1 )
121 Log::error(
"texture width must be of the type: cn*ts-cn+1 where cn=chunk-number, ts=texture-chunk-size\n");
124 if ( y_subdivision == -1 )
126 Log::error(
"texture height must be of the type: cn*ts-cn+1 where cn=chunk-number, ts=texture-chunk-size\n");
130 int xsize = (heightmap_img->
width() -1 + x_subdivision)/x_subdivision;
131 int zsize = (heightmap_img->
height() -1 + y_subdivision)/y_subdivision;
132 int tx_xsize = (terrain_img->
width() -1 + x_subdivision)/x_subdivision;
133 int tx_zsize = (terrain_img->
height() -1 + y_subdivision)/y_subdivision;
135 float dtu = float(1.0 / tx_xsize / 2.0);
136 float dtv = float(1.0 / tx_zsize / 2.0);
137 float dtu2 = 1.0f - dtu;
138 float dtv2 = 1.0f - dtv;
139 float du = float(1.0 / xsize / 2.0);
140 float dv = float(1.0 / zsize / 2.0);
141 float du2 = 1.0f - du;
142 float dv2 = 1.0f - dv;
144 float detail_du = detail_img ? float(1.0 / detail_img->
width() / 2.0) : 0;
145 float detail_dv = detail_img ? float(1.0 / detail_img->
height() / 2.0) : 0;
155 tmap_uv->
resize( xsize * zsize );
157 dmap_uv->
resize( xsize * zsize );
158 hmap_uv->
resize( xsize * zsize );
159 for(
int z=0; z<zsize; ++z)
161 for(
int x=0; x<xsize; ++x)
163 float u = (float)x/(xsize-1);
164 float v = (float)z/(zsize-1);
165 tmap_uv->
at(x + z*xsize).
s() = (1.0f-u) * dtu + u * dtu2;
166 tmap_uv->
at(x + z*xsize).
t() = (1.0f-v) * dtv + v * dtv2;
169 dmap_uv->
at(x + z*xsize).
s() = (1.0f-u) * detail_du + u * detail_du2;
170 dmap_uv->
at(x + z*xsize).
t() = (1.0f-v) * detail_dv + v * detail_dv2;
172 hmap_uv->
at(x + z*xsize).
s() = (1.0f-u) * du + u * du2;
173 hmap_uv->
at(x + z*xsize).
t() = (1.0f-v) * dv + v * dv2;
189 if (use_uniform_transform)
227 for(
int mz=0, tz=0; mz<heightmap_img->
height()-1; mz+=zsize-1, tz+=tx_zsize-1)
229 for(
int mx=0, tx=0; mx<heightmap_img->
width()-1; mx+=xsize-1, tx+=tx_xsize-1)
257 if (Has_GL_EXT_texture_filter_anisotropic)
260 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max);
280 dmat.
scale((xsize-1)*dx, 1.0, (zsize-1)*dz);
281 dmat.
translate(mx*dx + (xsize-1)*dx*0.5 -
width()/2.0, 0, mz*dz + (zsize-1)*dz*0.5 -
depth()/2.0);
293 for(
int z=0; z<zsize; ++z)
295 for(
int x=0; x<xsize; ++x)
298 int index = x + xsize * z;
299 verts->
at(index).
y() = sample.
r();
309 if (use_uniform_transform &&
useGLSL())
323 #if 0 // for debuggin purposes 325 terr_tile->
setColorArray(
fvec4(rand()%256/255.0f,rand()%256/255.0f,rand()%256/255.0f) );
const ShaderNode * shaderNode() const
Associates a Renderable object to an Effect and Transform.
int mDetailRepetitionCount
TexParameter * getTexParameter()
The TexParameter object associated to a Texture.
void setTexture(Texture *texture)
The texture sampler by a texture unit.
const T_Scalar & t() const
ETextureFormat detailTextureFormat() const
If enabled, do depth comparisons and update the depth buffer; Note that even if the depth buffer exis...
Vector4< float > fvec4
A 4 components vector with float precision.
A simple String formatting class.
const T_Scalar & s() const
Matrix4 & translate(T_Scalar x, T_Scalar y, T_Scalar z)
Wraps a GLSL vertex shader to be bound to a GLSLProgram: the shader this shader will run on the progr...
const T_Scalar & r() const
const ArrayAbstract * vertexArray() const
Conventional vertex array.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void setWrapT(ETexParamWrap texturewrap)
void setBoundsDirty(bool dirty)
Marks the bounding box and bounding sphere as dirty in order to be recomputed at the next rendering...
ETextureFormat terrainTextureFormat() const
Wraps a GLSL program to which you can bind vertex, fragment and geometry shaders. ...
Wraps an OpenGL texture object representing and managing all the supported texture types...
ref< Image > subImage(int xstart, int ystart, int width, int height)
Creates a new image containing the specified rectangular pixel area taken from the source image...
void setWrapS(ETexParamWrap texturewrap)
The ShaderNode class is used to conveniently manage complex hierarchies of Shader[s].
ETextureFormat heightmapTextureFormat() const
void setBoundingSphere(const Sphere &sphere)
Sets the bounding sphere of a Renderable.
void setColorArray(const fvec4 &color)
Fills the color array with the given color.
const String & heightmapTexture() const
Texture * texture()
The texture sampler by a texture unit.
VLCORE_EXPORT ref< Image > loadImage(VirtualFile *file)
Loads an image from the specified file.
void setBoundingBox(const AABB &aabb)
Sets the bounding box of a Renderable.
Visualization Library main namespace.
Wraps a GLSL fragment shader to be bound to a GLSLProgram: the shader this shader will run on the pro...
Propagates to children; does not override children settings; can be overridden.
RenderState wrapping the OpenGL function glTexEnv(), see also http://www.opengl.org/sdk/docs/man/xhtm...
void setMinFilter(ETexParamFilter minfilter)
The AABB class implements an axis-aligned bounding box using vl::real precision.
The Vector3 class is a template class that implements a generic 3 components vector, see also vl::fvec3, vl::dvec3, vl::uvec3, vl::ivec3, vl::svec3, vl::usvec3, vl::bvec3, vl::ubvec3.
float max(float a, float b)
void setMinCorner(real x, real y, real z)
Sets the corner of the AABB with the minimum x y z coordinates.
The TextureSampler class associates a Texture object to an OpenGL texture unit.
void addChild(ShaderNode *node)
void setMaxCorner(real x, real y, real z)
Sets the corner of the AABB with the maximum x y z coordinates.
void buildKdTree(ActorCollection &actors, int max_depth=100, float minimum_volume=0)
Builds a ActorKdTree with the given list of Actors.
const T_Scalar & y() const
bool empty() const
Returns true if length() == 0.
void setUniform(Uniform *uniform)
Utility function using getUniformSet(). Adds a Uniform to this program's static uniform set...
static String loadText(const String &path, EStringEncoding encoding=VL_PLATFORM_DEFAULT_ENCODING)
Loads a String from the specified path.
void setTexCoordArray(int tex_unit, ArrayAbstract *data)
Conventional texture coords arrays.
T * as()
Casts an Object to the specified class.
Matrix4 & scale(T_Scalar x, T_Scalar y, T_Scalar z)
void setUniform(Uniform *uniform)
Equivalent to getUniformSet()->setUniform(uniform)
const String & fragmentShader() const
void setUniformSet(UniformSet *uniforms)
Installs a new UniformSet.
Shader * shader(int lodi=0, int pass=0)
Utility function, same as 'lod(lodi)->at(pass);'.
Defines the sequence of Shader objects used to render an Actor.
T_VectorType & at(size_t i)
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
const String & detailTexture() const
void setShader(Shader *shader)
The ref<> class is used to reference-count an Object.
const String & terrainTexture() const
void setAnisotropy(float anisotropy)
void setRenderState(EInheritance inheritance, RenderStateNonIndexed *rs)
VLGRAPHICS_EXPORT ref< Geometry > makeGrid(const vec3 &origin, real xside, real zside, int x, int z, bool gen_texcoords=false, fvec2 uv0=fvec2(0, 0), fvec2 uv1=fvec2(1, 1), bool center=true)
Creates a 2D grid.
bool attachShader(GLSLShader *shader)
Attaches the GLSLShader to this GLSLProgram.
void setUniform(Uniform *uniform)
Equivalent to gocUniformSet()->setUniform(...)
fvec4 sample(int x, int y=0, int z=0) const
Returns the color associated to the specified pixel.
void setMagFilter(ETexParamFilter magfilter)
void setEnable(EEnable en, bool on, EInheritance inheritance=IN_Propagate)
const String & vertexShader() const
const ActorKdTree * tree() const
Returns the tree used by the scene manager.
void setMode(ETexEnvMode mode)
If enabled, cull polygons based on their winding in window coordinates, see also CullFace.