11 #include "ClipmapView.h"
12 #include "ClipmapVisibility.h"
76 unsigned int vboInstanceVertices;
77 unsigned int vboInstanceNormals;
78 unsigned int vboInstanceUV;
79 unsigned int vboInstanceFaces;
81 unsigned int vboSeamVertices[
MEDIUM_MAX][2][3];
82 unsigned int vboSeamVertNormals[
MEDIUM_MAX][2][3];
83 unsigned int vboSeamFaceNormals[
MEDIUM_MAX][2][3];
84 unsigned int vboSeamMaterials[
MEDIUM_MAX][2][3];
85 unsigned int vboSeamLightColor[
MEDIUM_MAX][2][3];
89 static const int VERT_POS_X = 2;
90 static const int VERT_POS_Y = 2;
91 static const int VERT_POS_Z = 2;
92 static const int VERT_POS_TYPE = 2;
93 static const int VERT_POS_SIZE = VERT_POS_X + VERT_POS_Y + VERT_POS_Z + VERT_POS_TYPE;
94 static const int VERT_NORMAL_OFFSET = VERT_POS_SIZE;
95 static const int VERT_NORMAL_FACE_X = 1;
96 static const int VERT_NORMAL_FACE_Z = 1;
97 static const int VERT_NORMAL_VERT_X = 1;
98 static const int VERT_NORMAL_VERT_Z = 1;
99 static const int VERT_NORMAL_SIZE = VERT_NORMAL_FACE_X + VERT_NORMAL_FACE_Z + VERT_NORMAL_VERT_X + VERT_NORMAL_VERT_Z;
100 static const int VERT_MATA_OFFSET = VERT_NORMAL_OFFSET + VERT_NORMAL_SIZE;
101 static const int VERT_MATA_ID0L = 1;
102 static const int VERT_MATA_ID0H = 1;
103 static const int VERT_MATA_ID1L = 1;
104 static const int VERT_MATA_ID1H = 1;
105 static const int VERT_MATA_SIZE = VERT_MATA_ID0L + VERT_MATA_ID0H + VERT_MATA_ID1L + VERT_MATA_ID1H;
106 static const int VERT_MATB_OFFSET = VERT_MATA_OFFSET + VERT_MATA_SIZE;
107 static const int VERT_MATB_ID2L = 1;
108 static const int VERT_MATB_ID2H = 1;
109 static const int VERT_MATB_A0 = 1;
110 static const int VERT_MATB_A1 = 1;
111 static const int VERT_MATB_SIZE = VERT_MATB_ID2L + VERT_MATB_ID2H + VERT_MATB_A0 + VERT_MATB_A1;
112 static const int VERT_COL_OFFSET = VERT_MATB_OFFSET + VERT_MATB_SIZE;
113 static const int VERT_COL_R = 1;
114 static const int VERT_COL_G = 1;
115 static const int VERT_COL_B = 1;
116 static const int VERT_COL_AMB = 1;
117 static const int VERT_COL_SIZE = VERT_COL_R + VERT_COL_G + VERT_COL_B + VERT_COL_AMB;
118 static const int VERT_SIZE = VERT_POS_SIZE + VERT_NORMAL_SIZE + VERT_MATA_SIZE + VERT_MATB_SIZE + VERT_COL_SIZE;
125 static const int VERT_BB_POS_X = 1;
126 static const int VERT_BB_POS_Y = 1;
127 static const int VERT_BB_POS_Z = 1;
128 static const int VERT_BB_POS_RIGIDITY = 1;
129 static const int VERT_BB_POS_SIZE = VERT_BB_POS_X + VERT_BB_POS_Y + VERT_BB_POS_Z + VERT_BB_POS_RIGIDITY;
130 static const int VERT_BB_NORMAL_OFFSET = VERT_BB_POS_SIZE;
131 static const int VERT_BB_NORMAL_X = 1;
132 static const int VERT_BB_NORMAL_Z = 1;
133 static const int VERT_BB_SIZE_U = 1;
134 static const int VERT_BB_SIZE_V = 1;
135 static const int VERT_BB_NORMAL_SIZE = VERT_BB_NORMAL_X + VERT_BB_NORMAL_Z + VERT_BB_SIZE_U + VERT_BB_SIZE_V;
136 static const int VERT_BB_TEX_OFFSET = VERT_BB_NORMAL_OFFSET + VERT_BB_NORMAL_SIZE;
137 static const int VERT_BB_TEX_U = 2;
138 static const int VERT_BB_TEX_V = 2;
139 static const int VERT_BB_TEX_SIZE = VERT_BB_TEX_U + VERT_BB_TEX_V;
140 static const int VERT_BB_COL_OFFSET = VERT_BB_TEX_OFFSET + VERT_BB_TEX_SIZE;
141 static const int VERT_BB_COL_R = 1;
142 static const int VERT_BB_COL_G = 1;
143 static const int VERT_BB_COL_B = 1;
144 static const int VERT_BB_COL_L = 1;
145 static const int VERT_BB_COL_SIZE = VERT_BB_COL_R + VERT_BB_COL_G + VERT_BB_COL_B + VERT_BB_COL_L;
146 static const int VERT_BB_SIZE = VERT_BB_POS_SIZE + VERT_BB_NORMAL_SIZE + VERT_BB_TEX_SIZE + VERT_BB_COL_SIZE;
147 GLuint vboBillboardVertexInfo;
148 char* billboardVertexInfo;
153 void buildIndexedBuffers();
154 void packVertexInfo();
155 void packSeamVertexInfo(
int medium,
int axis,
int front);
207 extern GLuint uniform_cellRenderProgram_shadowMapPhysics;
210 extern GLuint uniform_cellRenderProgram_sunDir;
211 extern GLuint uniform_cellRenderProgram_moonDir;
212 extern GLuint uniform_cellRenderProgram_sunColor;
213 extern GLuint uniform_cellRenderProgram_skyColor;
214 extern GLuint uniform_cellRenderProgram_ambColor1;
215 extern GLuint uniform_cellRenderProgram_ambColor2;
216 extern GLuint uniform_cellRenderProgram_ambBase;
217 extern GLuint uniform_cellRenderProgram_v3CameraPos;
218 extern GLuint uniform_cellRenderProgram_v3InvWavelength;
219 extern GLuint uniform_cellRenderProgram_fCameraHeight;
220 extern GLuint uniform_cellRenderProgram_fCameraHeight2;
221 extern GLuint uniform_cellRenderProgram_fOuterRadius;
222 extern GLuint uniform_cellRenderProgram_fOuterRadius2;
223 extern GLuint uniform_cellRenderProgram_fInnerRadius;
224 extern GLuint uniform_cellRenderProgram_fInnerRadius2;
225 extern GLuint uniform_cellRenderProgram_fKrESun;
226 extern GLuint uniform_cellRenderProgram_fKmESun;
227 extern GLuint uniform_cellRenderProgram_fKr4PI;
228 extern GLuint uniform_cellRenderProgram_fKm4PI;
229 extern GLuint uniform_cellRenderProgram_fScale;
230 extern GLuint uniform_cellRenderProgram_fScaleDepth;
231 extern GLuint uniform_cellRenderProgram_fScaleOverScaleDepth;
232 extern GLuint uniform_cellRenderProgram_g;
233 extern GLuint uniform_cellRenderProgram_g2;
234 extern GLuint uniform_cellRenderProgram_sceneHeightBounds;
235 extern GLuint uniform_cellRenderProgram_vertexPos;
236 extern GLuint uniform_cellRenderProgram_vertexNormals;
237 extern GLuint uniform_cellRenderProgram_vertexMaterialsA;
238 extern GLuint uniform_cellRenderProgram_vertexMaterialsB;
239 extern GLuint uniform_cellRenderProgram_vertexColor;
241 extern GLuint uniform_cellRenderProgram_fragmentRot;
289 extern GLuint uniform_waterProgram_sunDir;
290 extern GLuint uniform_waterProgram_moonDir;
291 extern GLuint uniform_waterProgram_sunColor;
292 extern GLuint uniform_waterProgram_skyColor;
293 extern GLuint uniform_waterProgram_ambColor1;
294 extern GLuint uniform_waterProgram_ambColor2;
295 extern GLuint uniform_waterProgram_ambBase;
296 extern GLuint uniform_waterProgram_v3CameraPos;
297 extern GLuint uniform_waterProgram_v3InvWavelength;
298 extern GLuint uniform_waterProgram_fCameraHeight;
299 extern GLuint uniform_waterProgram_fCameraHeight2;
300 extern GLuint uniform_waterProgram_fOuterRadius;
301 extern GLuint uniform_waterProgram_fOuterRadius2;
302 extern GLuint uniform_waterProgram_fInnerRadius;
303 extern GLuint uniform_waterProgram_fInnerRadius2;
304 extern GLuint uniform_waterProgram_fKrESun;
305 extern GLuint uniform_waterProgram_fKmESun;
306 extern GLuint uniform_waterProgram_fKr4PI;
307 extern GLuint uniform_waterProgram_fKm4PI;
308 extern GLuint uniform_waterProgram_fScale;
309 extern GLuint uniform_waterProgram_fScaleDepth;
310 extern GLuint uniform_waterProgram_fScaleOverScaleDepth;
311 extern GLuint uniform_waterProgram_g;
312 extern GLuint uniform_waterProgram_g2;
313 extern GLuint uniform_waterProgram_sceneHeightBounds;
314 extern GLuint uniform_waterProgram_vertexPos;
315 extern GLuint uniform_waterProgram_vertexNormals;
316 extern GLuint uniform_waterProgram_vertexMaterialsA;
317 extern GLuint uniform_waterProgram_vertexMaterialsB;
318 extern GLuint uniform_waterProgram_vertexColor;
319 extern GLuint uniform_waterProgram_time;
348 extern GLuint uniform_billboardProgram_v3CameraPos;
349 extern GLuint uniform_billboardProgram_sunDir;
350 extern GLuint uniform_billboardProgram_sunColor;
351 extern GLuint uniform_billboardProgram_skyColor;
352 extern GLuint uniform_billboardProgram_ambColor1;
353 extern GLuint uniform_billboardProgram_ambColor2;
354 extern GLuint uniform_billboardProgram_ambBase;
355 extern GLuint uniform_billboardProgram_v3InvWavelength;
356 extern GLuint uniform_billboardProgram_fCameraHeight;
357 extern GLuint uniform_billboardProgram_fCameraHeight2;
358 extern GLuint uniform_billboardProgram_fOuterRadius;
359 extern GLuint uniform_billboardProgram_fOuterRadius2;
360 extern GLuint uniform_billboardProgram_fInnerRadius;
361 extern GLuint uniform_billboardProgram_fInnerRadius2;
362 extern GLuint uniform_billboardProgram_fKrESun;
363 extern GLuint uniform_billboardProgram_fKmESun;
364 extern GLuint uniform_billboardProgram_fKr4PI;
365 extern GLuint uniform_billboardProgram_fKm4PI;
366 extern GLuint uniform_billboardProgram_fScale;
367 extern GLuint uniform_billboardProgram_fScaleDepth;
368 extern GLuint uniform_billboardProgram_fScaleOverScaleDepth;
369 extern GLuint uniform_billboardProgram_g;
370 extern GLuint uniform_billboardProgram_g2;
371 extern GLuint uniform_billboardProgram_sceneHeightBounds;
373 extern GLuint uniform_billboardProgram_vertexPos;
374 extern GLuint uniform_billboardProgram_vertexNormal;
375 extern GLuint uniform_billboardProgram_vertexUV;
376 extern GLuint uniform_billboardProgram_vertexColor;
404 extern GLuint uniform_instanceProgram_sunDir;
405 extern GLuint uniform_instanceProgram_sunColor;
406 extern GLuint uniform_instanceProgram_skyColor;
407 extern GLuint uniform_instanceProgram_ambColor1;
408 extern GLuint uniform_instanceProgram_ambColor2;
409 extern GLuint uniform_instanceProgram_ambBase;
413 extern GLuint uniform_shadowCasterProgram_vertexPos;
432 extern GLuint shadowDepthTextureIdPhysics;
465 extern float planetRadius;
466 extern float atmosphereRadius;
475 extern double lastShadowXposPhys;
476 extern double lastShadowYposPhys;
477 extern double lastShadowZposPhys;
483 extern GLenum lastGLError;
501 void extractFrustum(
Frustum& f);
502 bool sphereInFrustum(
Frustum& f, GLfloat x, GLfloat y, GLfloat z, GLfloat radius);
507 double transform[16];
514 inline void glErrorCheck()
516 GLenum error = glGetError();
517 if (error != GL_NO_ERROR && VoxelFarm::GL::lastGLError == 0)
519 VoxelFarm::GL::lastGLError = error;
528 inline void glErrorCheck() {}
GLuint uniform_cellRenderProgram_worldOffset
Shader parameter for the cell's offset based on the world coordinates when rendering started...
GLuint uniform_billboardProgram_camRight
Shader parameter for camera right direction vector.
unsigned int vboVertices[MEDIUM_MAX]
Vertex Buffer Object for the vertex array in the GPU.
bool baked
Indicates whether the Cell has been already processed and had its data moved to the GPU...
GLuint uniform_waterProgram_cursorHintPos
Shader parmeter for the add cursor coordinates.
virtual void processMesh(CMaterialLibrary *materialLibrary, CBillboardCache *billboardCache, ThreadContext *tc, LODStats stats) override
Computes normals, materials and billboards for the Cell.
unsigned int normalMap
Texture object for the normal map. Only used in the offline mode.
GLuint uniform_instanceProgram_time
Shader parameter for the current world time. This is used to animate wind.
unsigned int vboTexCoords[MEDIUM_MAX]
Vertex Buffer Object for the texture coordinates in the GPU.
GLuint uniform_cellRenderProgram_lightDir
Shader parameter for array of light incidence vectors.
GLuint uniform_waterProgram_materialArray
Shader parameter for Rectangle texture that packs material information for the shader.
GLuint uniform_instanceProgram_viewerPos
Shader parameter for current viewer position.
Contains all classes and functions for the VoxelFarm engine.
GLuint uniform_cellRenderProgram_faceNormal
Shader parameter for array of vertex normals. These normals are not smoothed.
unsigned int vboBillboardNormals
Vertex Buffer Object for the billboard normals in the GPU.
GLuint uniform_cellRenderProgram_relOffset
Shader parameter for the cell's relative offset to the viewer.
GLushort * faceIds[MEDIUM_MAX]
Face IDs.
GLuint glInstanceProgram
GLSL program ID for rendering instances.
Contains all materials available in the system.
unsigned int vboBillboardUV
Vertex Buffer Object for the billboard texture coordinates in the GPU.
GLuint uniform_billboardProgram_camUp
Shader parameter for camera up direction vector.
GLuint uniform_cellRenderProgram_shadowMap
Shader parameter for the Sunlight shadow map.
GLuint uniform_cellRenderProgram_textures
Shader parameter for the material texture array.
GLuint textureArray
Texture Id for the material texture array.
GLuint uniform_billboardProgram_applyColor
Shader parameter for an array of colors used to colorize billboards.
unsigned int vboLightColor[MEDIUM_MAX]
Vertex Buffer Object for the light color in the GPU.
double lastShadowXpos
Last viewer X position for wich shadowing was computed.
unsigned int texture
Texture object for the diffuse map. Only used in the offline mode.
GLuint skylightDepthTextureId
Texture Id for the Skylight shadowmap.
static const int MEDIUM_MAX
Number of different mediums in the world. Each medium may be subject to a different rendering logic...
unsigned int vboNormalTexCoords[MEDIUM_MAX]
Vertex Buffer Object for the texture coordinates of the normal map in the GPU.
GLuint uniform_instanceProgram_cellSize
Shader parameter for the cell dimension.
GLuint uniform_billboardProgram_skylightMap
Shader parameter for the Skylight shadow map.
GLuint uniform_waterProgram_cellSize
Shader parameter for the cell dimension.
unsigned int vboBillboardLightColor
Vertex Buffer Object for the billboard colors in the GPU.
GLuint uniform_billboardProgram_shadowMap
Shader parameter for the Sunlight shadow map.
GLuint uniform_billboardProgram_offset
Shader parameter for the cell's absolute offset.
bool lineMode
Show lines instead of trianles.
GLuint noiseTexture
Texture Id for a pink noise texture array.
GLuint uniform_UICubeProgram_textures
Shader parameter for material texture array.
GLuint uniform_cellRenderProgram_cursorPosMax
Shader parmeter for the highest corner of the cursor scope.
unsigned int vboFaceIndices[MEDIUM_MAX]
Vertex Buffer Object for face indices.
GLuint glUICubeProgram
GLSL program ID for rendering material samples in the UI.
unsigned __int64 CellId
A 64bit integer that identifies a single world octree Cell.
GLuint uniform_waterProgram_skylightMap
Shader parameter for the Skylight shadow map.
Cells Scene
A Scene is a set of cells.
unsigned int vboMaterials[MEDIUM_MAX]
Vertex Buffer Object for the material array in the GPU.
Stores the information for a Cell that has already been converted to a polygonal mesh.
GLuint glWaterProgram
GLSL program ID for rendering water.
GLuint uniform_cellRenderProgram_materialChannelA
Shader parameter for channel A of vertex material data.
GLuint uniform_cellRenderProgram_LOD
Shader parameter for Level of Detail for the cell.
GLuint uniform_cellRenderProgram_cellSize
Shader parameter for the cell dimension.
unsigned int vboBillboardSize
Vertex Buffer Object for the billboard sizes in the GPU.
GLuint uniform_instanceProgram_texture
Shader parameter for the instance texture.
GLuint materialArray
Texture Id for the material information array.
GLuint uniform_waterProgram_snowHeight
Shader parameter for an absolute height value where snow starts to appear over materials.
GLuint uniform_cellRenderProgram_materialChannelC
Shader parameter for channel C of vertex material data.
GLuint uniform_waterProgram_materialChannelC
Shader parameter for channel C of vertex material data.
bool debugMode
Show lines instead of trianles.
GLuint uniform_instanceProgram_fade
Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
GLuint uniform_waterProgram_faceNormal
Shader parameter for array of vertex normals. These normals are not smoothed.
GLuint uniform_billboardProgram_noise
Shader parameter for a pink noise texture.
GLuint uniform_billboardProgram_fade
Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
GLuint uniform_billboardProgram_time
Shader parameter for the current world time. This is used to animate wind.
StatTracker LODStats[LEVELS][STAT_NULL]
Used to track stats across all LOD.
GLuint uniform_waterProgram_worldOffset
Shader parameter for the cell's offset based on the world coordinates when rendering started...
GLuint glShadowCasterProgram
GLSL program ID for rendering light occluders to the shadow maps.
double lastShadowYpos
Last viewer Y position for wich shadowing was computed.
GLuint uniform_cellRenderProgram_fade
Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
GLuint uniform_instanceProgram_camRight
Shader parameter for camera right direction vector.
GLuint uniform_billboardProgram_cellSize
Shader parameter for the cell dimension.
unsigned int vboLightDir[MEDIUM_MAX]
Vertex Buffer Object for the light direction in the GPU.
GLuint uniform_cellRenderProgram_cursorPos
Shader parmeter for the carve cursor coordinates.
GLuint uniform_billboardProgram_viewerPos
Shader parameter for current viewer position.
GLuint uniform_cellRenderProgram_cursorHintPos
Shader parmeter for the add cursor coordinates.
GLuint instanceTextureArray
Texture Id for the instance texture array.
GLuint uniform_waterProgram_offset
Shader parameter for the cell's absolute offset.
GLuint uniform_cellRenderProgram_offset
Shader parameter for the cell's absolute offset.
double lastShadowZpos
Last viewer Z position for wich shadowing was computed.
GLuint uniform_instanceProgram_camUp
Shader parameter for camera up direction vector.
GLuint uniform_waterProgram_cursorPos
Shader parmeter for the carve cursor coordinates.
unsigned int vboFaceNormals[MEDIUM_MAX]
Vertex Buffer Object for the face normals in the GPU.
A CellData object for rendering in OpenGL.
bool vboBuilt
Indicates whether the vertex buffer objects have been built.
Represents a moving view within a world. Computes new scenes as the view moves.
GLuint uniform_cellRenderProgram_noiseTexture
Shader parameter for pink noise texture.
GLuint uniform_waterProgram_relOffset
Shader parameter for the cell's relative offset to the viewer.
void render(Scene *scene, Scene *prevScene, float sceneBlend, CClipmapView *clipmapView)
Renders the world. At any point in time, up to two different scenes could be active. This function will render a transition between the two scenes.
GLuint glCellRenderProgram
GLSL program ID for rendering world geometry.
GLuint uniform_instanceProgram_skylightMap
Shader parameter for the Skylight shadow map.
GLuint uniform_billboardProgram_texture
Shader parameter for the billboard texture.
GLuint uniform_waterProgram_viewerPos
Shader parameter for current viewer position.
GLuint uniform_waterProgram_cursorPosMin
Shader parmeter for the lower corner of the cursor scope.
GLuint uniform_instanceProgram_shadowMap
Shader parameter for the Sunlight shadow map.
GLuint uniform_cellRenderProgram_skylightMap
Shader parameter for the Skylight shadow map.
void renderShadowCasters(Scene *scene, CClipmapView *clipmapView)
Renders only the shadow casting elements in the world. This is used to create shadow maps by renderin...
GLuint uniform_instanceProgram_applyColor
Shader parameter for an array of colors used to colorize instances.
GLuint uniform_waterProgram_materialChannelA
Shader parameter for channel A of vertex material data.
GLuint uniform_waterProgram_lightDir
Shader parameter for array of light incidence vectors.
GLuint billboardTexture
Texture Id for the billboard texture atlas.
GLuint uniform_instanceProgram_noise
Shader parameter for a pink noise texture.
GLuint glBillboardProgram
GLSL program ID for rendering billboards.
GLuint shadowDepthTextureId
Texture Id for the Sunlight shadowmap.
unsigned int vboVertNormals[MEDIUM_MAX]
Vertex Buffer Object for the vertex normals in the GPU.
unsigned int vboBillboardLightDir
Vertex Buffer Object for the billboard light direction in the GPU.
GLuint uniform_waterProgram_cursorPosMax
Shader parmeter for the highest corner of the cursor scope.
GLuint uniform_instanceProgram_offset
Shader parameter for the cell's absolute offset.
GLuint uniform_waterProgram_fade
Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
A 3D plane used to extract Frustum.
GLuint uniform_waterProgram_LOD
Shader parameter for Level of Detail for the cell.
GLuint uniform_cellRenderProgram_viewerPos
Shader parameter for current viewer position.
GLuint uniform_waterProgram_noiseTexture
Shader parameter for pink noise texture.
GLuint uniform_waterProgram_materialChannelB
Shader parameter for channel B of vertex material data.
GLuint uniform_cellRenderProgram_materialChannelB
Shader parameter for channel B of vertex material data.
Keeps an billboard cache entry for each cell that had its billboards and material instances generated...
GLuint uniform_cellRenderProgram_materialArray
Shader parameter for Rectangle texture that packs material information for the shader.
unsigned int vboMaterialChannels[MEDIUM_MAX][3]
Vertex Buffer Object for the material array in the GPU.
unsigned int vboBillboardVertices
Vertex Buffer Object for the billboard vertices in the GPU.
GLuint uniform_cellRenderProgram_cursorPosMin
Shader parmeter for the lower corner of the cursor scope.
GLuint uniform_cellRenderProgram_snowHeight
Shader parameter for an absolute height value where snow starts to appear over materials.
GLuint uniform_waterProgram_shadowMap
Shader parameter for the Sunlight shadow map.
GLuint uniform_waterProgram_textures
Shader parameter for the material texture array.