21#ifndef _TGX_RENDERER3D_H_
22#define _TGX_RENDERER3D_H_
51 extern const uint16_t UNIT_CUBE_FACES[6*4];
52 extern const uint16_t UNIT_CUBE_FACES_NORMALS[6 * 4];
113 template<
typename color_t, Shader LOADED_SHADERS = TGX_SHADER_MASK_ALL,
typename ZBUFFER_t =
float,
int MAX_DIRECTIONAL_LIGHTS = 1,
int MAX_SPOT_LIGHTS = 0>
120 static_assert(is_color<color_t>::value,
"color_t must be one of the color types defined in color.h");
121 static_assert((std::is_same<ZBUFFER_t, float>::value) || (std::is_same<ZBUFFER_t, uint16_t>::value),
"The Z-buffer type must be either float or uint16_t");
122 static_assert(MAX_DIRECTIONAL_LIGHTS >= 1,
"MAX_DIRECTIONAL_LIGHTS must be at least 1");
123 static_assert(MAX_SPOT_LIGHTS >= 0,
"MAX_SPOT_LIGHTS must be non-negative");
126 static constexpr int ENABLE_TEXTURING = (TGX_SHADER_HAS_ONE_FLAG(LOADED_SHADERS , (
SHADER_TEXTURE | TGX_SHADER_MASK_TEXTURE_MODE | TGX_SHADER_MASK_TEXTURE_QUALITY)));
130 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_PROJECTION),
"At least one of the two shaders SHADER_PERSPECTIVE or SHADER_ORTHO must be enabled");
131 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_ZBUFFER),
"At least one of the two shaders SHADER_NOZBUFFER or SHADER_ZBUFFER must be enabled");
132 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_SHADING),
"At least one of the shaders SHADER_UNLIT, SHADER_FLAT or SHADER_GOURAUD must be enabled");
133 static_assert(TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_TEXTURE),
"At least one of the two shaders SHADER_TEXTURE or SHADER_NOTEXTURE must be enabled");
134 static_assert((!TGX_SHADER_HAS_TEXTURE(ENABLED_SHADERS)) || (TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS,TGX_SHADER_MASK_TEXTURE_QUALITY)),
"When using texturing, at least one of the two shaders SHADER_TEXTURE_BILINEAR or SHADER_TEXTURE_NEAREST must be enabled");
135 static_assert((!TGX_SHADER_HAS_TEXTURE(ENABLED_SHADERS)) || (TGX_SHADER_HAS_ONE_FLAG(ENABLED_SHADERS, TGX_SHADER_MASK_TEXTURE_MODE)),
"When using texturing, at least one of the two shaders SHADER_TEXTURE_WRAP_POW2 or SHADER_TEXTURE_CLAMP must be enabled");
306 void setOrtho(
float left,
float right,
float bottom,
float top,
float zNear,
float zFar);
325 void setFrustum(
float left,
float right,
float bottom,
float top,
float zNear,
float zFar);
510 void setLookAt(
float eyeX,
float eyeY,
float eyeZ,
float centerX,
float centerY,
float centerZ,
float upX,
float upY,
float upZ);
883 void setMaterial(
RGBf color,
float ambiantStrength,
float diffuseStrength,
float specularStrength,
int specularExponent);
961 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr,
962 const fVec2 * T1 =
nullptr,
const fVec2 * T2 =
nullptr,
const fVec2 * T3 =
nullptr,
979 const RGBf & col1,
const RGBf & col2,
const RGBf & col3,
980 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr);
1002 const uint16_t * ind_vertices,
const fVec3 * vertices,
1003 const uint16_t * ind_normals =
nullptr,
const fVec3* normals =
nullptr,
1004 const uint16_t * ind_texture =
nullptr,
const fVec2* textures =
nullptr,
1031 const uint16_t* ind_vertices,
const fVec3* vertices,
1032 const uint16_t* ind_normals =
nullptr,
const fVec3* normals =
nullptr,
1033 const uint16_t* ind_texture =
nullptr,
const fVec2* textures =
nullptr,
1054 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr,
const fVec3 * N4 =
nullptr,
1055 const fVec2 * T1 =
nullptr,
const fVec2 * T2 =
nullptr,
const fVec2 * T3 =
nullptr,
const fVec2 * T4 =
nullptr,
1076 const RGBf & col1,
const RGBf & col2,
const RGBf & col3,
const RGBf & col4,
1077 const fVec3 * N1 =
nullptr,
const fVec3 * N2 =
nullptr,
const fVec3 * N3 =
nullptr,
const fVec3 * N4 =
nullptr);
1103 const uint16_t * ind_vertices,
const fVec3 * vertices,
1104 const uint16_t * ind_normals =
nullptr,
const fVec3* normals =
nullptr,
1105 const uint16_t * ind_texture =
nullptr,
const fVec2* textures =
nullptr,
1293 float rot_angle_y = 0.0f,
1294 float reference_height = 0.0f,
1295 float skybox_radius = 32768.0f,
1296 Shader texture_quality = SHADER_TEXTURE_NEAREST,
1297 Shader texture_mode = SHADER_TEXTURE_CLAMP
1313 float rot_angle_y = 0.0f,
1314 float reference_height = 0.0f,
1315 float skybox_radius = 32768.0f,
1316 Shader texture_quality = SHADER_TEXTURE_NEAREST,
1317 Shader texture_mode = SHADER_TEXTURE_CLAMP
1587 void drawWireFrameLines(
int nb_lines,
const uint16_t* ind_vertices,
const fVec3* vertices,
float thickness, color_t color,
float opacity);
1825 void drawWireFrameQuads(
int nb_quads,
const uint16_t* ind_vertices,
const fVec3* vertices,
float thickness, color_t color,
float opacity);
2054 void drawPixels(
int nb_pixels,
const fVec3* pos_list,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
2117 void drawDots(
int nb_dots,
const fVec3* pos_list,
const int* radius_ind,
const int* radius,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
2143 TGX_INLINE
float _clipbound_xy()
const
2145 return (256 + 3*((MAXVIEWPORTDIMENSION * 256) / ((_lx > _ly) ? _lx : _ly))) / 1024.0f;
2151 TGX_INLINE
bool _validDraw()
const
2153 return ((_lx > 0) && (_ly > 0) && (_uni.im !=
nullptr) && (_uni.im->isValid()));
2158 TGX_NOINLINE
void _recompute_wa_wb();
2165 TGX_NOINLINE
void _rectifyShaderOrtho();
2168 TGX_NOINLINE
void _rectifyShaderZbuffer();
2171 TGX_NOINLINE
void _rectifyShaderShading(Shader new_shaders);
2174 TGX_NOINLINE
void _rectifyShaderTextureWrapping();
2177 TGX_NOINLINE
void _rectifyShaderTextureQuality();
2186 void _drawTriangleClipped(
const int RASTER_TYPE,
2187 const fVec4* Q0,
const fVec4* Q1,
const fVec4* Q2,
2188 const fVec3* N0,
const fVec3* N1,
const fVec3* N2,
2189 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
2190 const RGBf& Vcol0,
const RGBf& Vcol1,
const RGBf& Vcol2);
2194 void _drawTriangleClippedSub(
const int RASTER_TYPE,
const int plane,
2195 const RasterizerVec4& P1,
const RasterizerVec4& P2,
const RasterizerVec4& P3);
2199 void _drawTriangle(
const int RASTER_TYPE,
2200 const fVec3* P0,
const fVec3* P1,
const fVec3* P2,
2201 const fVec3* N0,
const fVec3* N1,
const fVec3* N2,
2202 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
2203 const RGBf& Vcol0,
const RGBf& Vcol1,
const RGBf& Vcol2);
2207 void _drawTriangleStrip(
const int RASTER_TYPE,
int nb_indices,
2208 const uint16_t* ind_vertices,
const fVec3* vertices,
2209 const uint16_t* ind_normals,
const fVec3* normals,
2210 const uint16_t* ind_texture,
const fVec2* textures);
2214 void _drawQuad(
const int RASTER_TYPE,
2215 const fVec3* P0,
const fVec3* P1,
const fVec3* P2,
const fVec3* P3,
2216 const fVec3* N0,
const fVec3* N1,
const fVec3* N2,
const fVec3* N3,
2217 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
const fVec2* T3,
2218 const RGBf& Vcol0,
const RGBf& Vcol1,
const RGBf& Vcol2,
const RGBf& Vcol3);
2221 template<
bool TEXTURE_BILINEAR,
bool TEXTURE_WRAP>
2222 void _rasterizeSkyBoxTriangle(
const RasterizerVec4& V0,
const RasterizerVec4& V1,
const RasterizerVec4& V2);
2225 void _rasterizeSkyBoxTriangle(
const RasterizerVec4& V0,
const RasterizerVec4& V1,
const RasterizerVec4& V2,
2226 Shader texture_quality, Shader texture_mode);
2229 void _drawSkyBoxTriangleClippedSub(
const int plane,
2230 const RasterizerVec4& P1,
const RasterizerVec4& P2,
const RasterizerVec4& P3,
2231 Shader texture_quality, Shader texture_mode);
2234 void _drawSkyBoxTriangleClipped(
2235 const fVec4* Q0,
const fVec4* Q1,
const fVec4* Q2,
2236 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
2237 Shader texture_quality, Shader texture_mode);
2240 void _drawSkyBoxQuad(
2241 const fVec4* P0,
const fVec4* P1,
const fVec4* P2,
const fVec4* P3,
2242 const fVec2* T0,
const fVec2* T1,
const fVec2* T2,
const fVec2* T3,
2243 Shader texture_quality, Shader texture_mode);
2246 void _drawSkyBoxFace(
const fVec4 skybox_vertices[8],
const uint16_t* face,
const fVec2 texture_coords[4],
const Image<color_t>* texture,
2247 Shader texture_quality, Shader texture_mode);
2251 void _drawMesh(
const int RASTER_TYPE,
const Mesh3D<color_t>* mesh);
2254 void _drawMesh(
const int RASTER_TYPE,
const Mesh3Dv2<color_t>* mesh,
bool use_mesh_material);
2257 TGX_INLINE
inline bool _discardMeshlet16b(
const fVec3& sphere_center,
float sphere_radius,
const fVec3& cone_dir,
float cone_cos)
const
2259 if (cone_cos <= -1.0f)
return false;
2261 const fVec4 D = _r_modelViewM.
mult0(cone_dir);
2262 const float dd = D.
x * D.x + D.y * D.y + D.z * D.z;
2263 if (dd <= 1.0e-20f)
return false;
2274 const fVec3 anchor = sphere_center - (cone_dir * sphere_radius);
2276 dot = -(D.x * A.x + D.y * A.y + D.z * A.z);
2277 const float aa = A.
x * A.x + A.y * A.y + A.z * A.z;
2278 if (aa <= 1.0e-20f)
return false;
2282 const float c2len2 = cone_cos * cone_cos * len2;
2283 const float dot2 = dot * dot;
2284 return (cone_cos >= 0.0f) ? ((dot < 0.0f) || (dot2 < c2len2))
2285 : ((dot < 0.0f) && (dot2 > c2len2));
2294 inline void _drawWireFrameLineFast(iVec2 P0, iVec2 P1, color_t color);
2296 template<
bool CHECK_NEIGHBOR>
inline void _drawWireFrameLineAAFast(
const fVec2& P0,
const fVec2& P1, color_t color, int32_t op);
2298 template<
int MODE>
void _drawWireFrameMesh(
const Mesh3D<color_t>* mesh,
bool draw_chained_meshes, color_t color,
float opacity,
float thickness);
2300 template<
int MODE>
void _drawWireFrameMesh(
const Mesh3Dv2<color_t>* mesh, color_t color,
float opacity,
float thickness);
2302 template<
int MODE>
void _drawWireFrameLine(
const fVec3& P1,
const fVec3& P2, color_t color,
float opacity,
float thickness);
2304 template<
int MODE>
void _drawWireFrameLines(
int nb_lines,
const uint16_t* ind_vertices,
const fVec3* vertices, color_t color,
float opacity,
float thickness);
2306 template<
int MODE>
void _drawWireFrameTriangle(
const fVec3& P1,
const fVec3& P2,
const fVec3& P3, color_t color,
float opacity,
float thickness);
2308 template<
int MODE>
void _drawWireFrameTriangles(
int nb_triangles,
const uint16_t* ind_vertices,
const fVec3* vertices, color_t color,
float opacity,
float thickness);
2310 template<
int MODE>
void _drawWireFrameTriangleStrip(
int nb_indices,
const uint16_t* ind_vertices,
const fVec3* vertices, color_t color,
float opacity,
float thickness);
2312 template<
int MODE>
void _drawWireFrameQuad(
const fVec3& P1,
const fVec3& P2,
const fVec3& P3,
const fVec3& P4, color_t color,
float opacity,
float thickness);
2314 template<
int MODE>
void _drawWireFrameQuads(
int nb_quads,
const uint16_t* ind_vertices,
const fVec3* vertices, color_t color,
float opacity,
float thickness);
2324 template<
bool USE_BLENDING>
void _drawPixel(
const fVec3& pos, color_t color,
float opacity);
2327 template<
bool USE_COLORS,
bool USE_BLENDING>
void _drawPixels(
int nb_pixels,
const fVec3* pos_list,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
2330 template<
bool USE_BLENDING>
void _drawDot(
const fVec3& pos,
int r, color_t color,
float opacity);
2333 template<
bool USE_RADIUS,
bool USE_COLORS,
bool USE_BLENDING>
void _drawDots(
int nb_dots,
const fVec3* pos_list,
const int* radius_ind,
const int* radius,
const int* colors_ind,
const color_t* colors,
const int* opacities_ind,
const float* opacities);
2337 template<
bool CHECKRANGE,
bool USE_BLENDING> TGX_INLINE
inline void drawPixelZbuf(
int x,
int y, color_t color,
float opacity,
float z)
2339 if (CHECKRANGE && ((x < 0) || (x >= _uni.im->lx()) || (y < 0) || (y >= _uni.im->ly())))
return;
2340 ZBUFFER_t& W = _uni.zbuf[x + _uni.im->lx() * y];
2341 const ZBUFFER_t aa = (std::is_same<ZBUFFER_t, uint16_t>::value) ? ((ZBUFFER_t)(z * _uni.wa + _uni.wb)) : ((ZBUFFER_t)z);
2345 if (USE_BLENDING) _uni.im->template drawPixel<false>({ x, y }, color, opacity);
else _uni.im->template drawPixel<false>({ x, y }, color);
2350 template<
bool CHECKRANGE,
bool USE_BLENDING> TGX_INLINE
inline void drawHLineZbuf(
int x,
int y,
int w, color_t color,
float opacity,
float z)
2354 const int lx = _uni.im->lx();
2355 const int ly = _uni.im->ly();
2356 if ((y < 0) || (y >= ly) || (x >= lx))
return;
2357 if (x < 0) { w += x; x = 0; }
2358 if (x + w > lx) { w = lx - x; }
2361 while(w--) drawPixelZbuf<CHECKRANGE, USE_BLENDING>(x++, y, color, opacity, z);
2365 template<
bool CHECKRANGE,
bool USE_BLENDING>
void _drawCircleZbuf(
int xm,
int ym,
int r, color_t color,
float opacity,
float z);
2371 float _unitSphereScreenDiameter();
2374 template<
bool WIREFRAME,
int MODE>
void _drawSphere(
int nb_sectors,
int nb_stacks,
const Image<color_t>* texture,
float thickness, color_t color,
float opacity);
2384 TGX_INLINE
inline void _clip(
int & fl,
const fVec4 & P,
float bx,
float Bx,
float by,
float By)
2386 if (P.x >= bx) { fl &= (~(1)); }
2387 if (P.x <= Bx) { fl &= (~(2)); }
2388 if (P.y >= by) { fl &= (~(4)); }
2389 if (P.y <= By) { fl &= (~(8)); }
2390 if ((P.z >= -1.0f)&&(P.w > 0)) { fl &= (~(16)); }
2391 if (P.z <= +1.0f) { fl &= (~(32)); }
2396 TGX_INLINE
inline void _clip(
int & fl,
const fVec3 & P,
float bx,
float Bx,
float by,
float By,
const fMat4 & M)
2398 fVec4 S = M.mult1(P);
2400 return _clip(fl, S, bx, Bx, by, By);
2406 bool _discardBox(
const fBox3 & bb,
const fMat4 & M)
2408 if ((bb.minX == 0) && (bb.maxX == 0) && (bb.minY == 0) && (bb.maxY == 0) && (bb.minZ == 0) && (bb.maxZ == 0))
2411 const float bx = (_ox - 1) * _ilx - 1.0f;
2412 const float Bx = (_ox + _uni.im->width() + 1) * _ilx - 1.0f;
2413 const float by = (_oy - 1) * _ily - 1.0f;
2414 const float By = (_oy + _uni.im->height() + 1) * _ily - 1.0f;
2417 _clip(fl,
fVec3(bb.minX, bb.minY, bb.minZ), bx, Bx, by, By, M);
2418 if (fl == 0)
return false;
2419 _clip(fl,
fVec3(bb.minX, bb.minY, bb.maxZ), bx, Bx, by, By, M);
2420 if (fl == 0)
return false;
2421 _clip(fl,
fVec3(bb.minX, bb.maxY, bb.minZ), bx, Bx, by, By, M);
2422 if (fl == 0)
return false;
2423 _clip(fl,
fVec3(bb.minX, bb.maxY, bb.maxZ), bx, Bx, by, By, M);
2424 if (fl == 0)
return false;
2425 _clip(fl,
fVec3(bb.maxX, bb.minY, bb.minZ), bx, Bx, by, By, M);
2426 if (fl == 0)
return false;
2427 _clip(fl,
fVec3(bb.maxX, bb.minY, bb.maxZ), bx, Bx, by, By, M);
2428 if (fl == 0)
return false;
2429 _clip(fl,
fVec3(bb.maxX, bb.maxY, bb.minZ), bx, Bx, by, By, M);
2430 if (fl == 0)
return false;
2431 _clip(fl,
fVec3(bb.maxX, bb.maxY, bb.maxZ), bx, Bx, by, By, M);
2432 if (fl == 0)
return false;
2439 bool _discardTriangle(
const fVec4 & P1,
const fVec4 & P2,
const fVec4 & P3)
2441 const float bx = (_ox - 1) * _ilx - 1.0f;
2442 const float Bx = (_ox + _uni.im->width() + 1) * _ilx - 1.0f;
2443 const float by = (_oy - 1) * _ily - 1.0f;
2444 const float By = (_oy + _uni.im->height() + 1) * _ily - 1.0f;
2447 _clip(fl, P1, bx, Bx, by, By);
2448 if (fl == 0)
return false;
2449 _clip(fl, P2, bx, Bx, by, By);
2450 if (fl == 0)
return false;
2451 _clip(fl, P3, bx, Bx, by, By);
2452 if (fl == 0)
return false;
2458 bool _clip2(
float clipboundXY,
const fVec3 & P,
const fMat4 & M)
2460 fVec4 S = M.mult1(P);
2464 if (S.w <= 0) S.z = -2;
2466 return ((S.x <= -clipboundXY) || (S.x >= clipboundXY)
2467 || (S.y <= -clipboundXY) || (S.y >= clipboundXY)
2468 || (S.z <= -1) || (S.z >= 1));
2473 bool _clipTestNeeded(
float clipboundXY,
const fBox3 & bb,
const fMat4 & M)
2475 return (_clip2(clipboundXY,
fVec3(bb.minX, bb.minY, bb.minZ), M)
2476 || _clip2(clipboundXY,
fVec3(bb.minX, bb.minY, bb.maxZ), M)
2477 || _clip2(clipboundXY,
fVec3(bb.minX, bb.maxY, bb.minZ), M)
2478 || _clip2(clipboundXY,
fVec3(bb.minX, bb.maxY, bb.maxZ), M)
2479 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.minY, bb.minZ), M)
2480 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.minY, bb.maxZ), M)
2481 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.maxY, bb.minZ), M)
2482 || _clip2(clipboundXY,
fVec3(bb.maxX, bb.maxY, bb.maxZ), M));
2487 bool _wireFrameAANeighborCheckNeeded(
const fBox3& bb,
const fMat4& proj_modelview)
2489 if ((_uni.im ==
nullptr) || (_uni.im->lx() <= 2) || (_uni.im->ly() <= 2))
return true;
2491 const float bx = (_ox + 1.0f) * _ilx - 1.0f;
2492 const float Bx = (_ox + (float)(_uni.im->lx() - 2)) * _ilx - 1.0f;
2493 const float by = (_oy + 1.0f) * _ily - 1.0f;
2494 const float By = (_oy + (float)(_uni.im->ly() - 2)) * _ily - 1.0f;
2496 const fVec3 C[8] = {
2497 fVec3(bb.minX, bb.minY, bb.minZ),
2498 fVec3(bb.minX, bb.minY, bb.maxZ),
2499 fVec3(bb.minX, bb.maxY, bb.minZ),
2500 fVec3(bb.minX, bb.maxY, bb.maxZ),
2501 fVec3(bb.maxX, bb.minY, bb.minZ),
2502 fVec3(bb.maxX, bb.minY, bb.maxZ),
2503 fVec3(bb.maxX, bb.maxY, bb.minZ),
2504 fVec3(bb.maxX, bb.maxY, bb.maxZ)
2507 for (
int i = 0; i < 8; i++)
2509 fVec4 P = proj_modelview.mult1(C[i]);
2512 if (P.w <= 0)
return true;
2515 if ((P.z < -1.0f) || (P.z > 1.0f))
return true;
2516 if ((P.x < bx) || (P.x > Bx) || (P.y < by) || (P.y > By))
return true;
2522#if TGX_MESHLET_SPHERE_CLIP
2524 TGX_INLINE
inline void _meshletClipPlanes(
float clipboundXY,
const fMat4& M, fVec4* planes,
float* plane_norms)
const
2526 const float cx = clipboundXY;
2527 planes[0] =
fVec4(M.M[0] + cx * M.M[3], M.M[4] + cx * M.M[7], M.M[8] + cx * M.M[11], M.M[12] + cx * M.M[15]);
2528 planes[1] =
fVec4(-M.M[0] + cx * M.M[3], -M.M[4] + cx * M.M[7], -M.M[8] + cx * M.M[11], -M.M[12] + cx * M.M[15]);
2529 planes[2] =
fVec4(M.M[1] + cx * M.M[3], M.M[5] + cx * M.M[7], M.M[9] + cx * M.M[11], M.M[13] + cx * M.M[15]);
2530 planes[3] =
fVec4(-M.M[1] + cx * M.M[3], -M.M[5] + cx * M.M[7], -M.M[9] + cx * M.M[11], -M.M[13] + cx * M.M[15]);
2531 planes[4] =
fVec4(M.M[2] + M.M[3], M.M[6] + M.M[7], M.M[10] + M.M[11], M.M[14] + M.M[15]);
2532 planes[5] =
fVec4(-M.M[2] + M.M[3], -M.M[6] + M.M[7], -M.M[10] + M.M[11], -M.M[14] + M.M[15]);
2533 for (
int i = 0; i < 6; i++)
2535 const fVec4& P = planes[i];
2536 plane_norms[i] = sqrtf(P.x * P.x + P.y * P.y + P.z * P.z);
2542 TGX_INLINE
inline int _meshletSphereClip(
const fVec3& center,
float radius,
const fVec4* planes,
const float* plane_norms)
const
2544 bool intersects =
false;
2545 for (
int i = 0; i < 6; i++)
2547 const fVec4& P = planes[i];
2548 const float d = P.
x * center.x + P.y * center.y + P.z * center.z + P.w;
2549 const float r = radius * plane_norms[i];
2550 if (d < -r)
return -1;
2551 if (d < r) intersects =
true;
2553 return intersects ? 1 : 0;
2574 return (CP.
x * P.
x) + (CP.
y * P.
y) + (CP.
z * P.
z) + (CP.
w * P.
w) + off;
2587 inline float _cpfactor(
const tgx::fVec4& CP,
const float sdistA,
const float sdistB)
2589 return sdistA / (sdistA - sdistB);
2594 void _triangleClip1in(
int shader,
tgx::fVec4 CP,
2595 float cp1,
float cp2,
float cp3,
2596 const RasterizerVec4& P1,
const RasterizerVec4& P2,
const RasterizerVec4& P3,
2597 RasterizerVec4& nP1, RasterizerVec4& nP2, RasterizerVec4& nP3, RasterizerVec4& nP4);
2601 void _triangleClip2in(
int shader,
tgx::fVec4 CP,
2602 float cp1,
float cp2,
float cp3,
2603 const RasterizerVec4& P1,
const RasterizerVec4& P2,
const RasterizerVec4& P3,
2604 RasterizerVec4& nP1, RasterizerVec4& nP2, RasterizerVec4& nP3, RasterizerVec4& nP4);
2607 int _triangleClip(
int shader,
tgx::fVec4 CP,
float off,
2608 const RasterizerVec4 & P1,
const RasterizerVec4 & P2,
const RasterizerVec4 & P3,
2609 RasterizerVec4 & nP1, RasterizerVec4 & nP2, RasterizerVec4 & nP3, RasterizerVec4 & nP4);
2617 static const int _POWTABSIZE = 32;
2620 float _fastpowtab[_POWTABSIZE];
2623 TGX_INLINE
inline void _precomputeSpecularTable(
int exponent)
2625 if (_currentpow == exponent)
return;
2626 _precomputeSpecularTable2(exponent);
2629 TGX_NOINLINE
void _precomputeSpecularTable2(
int exponent);
2633 TGX_INLINE
inline float _powSpecular(
float x)
const
2635 const float indf = (_powmax - x) * _POWTABSIZE;
2636 const int indi =
max(0,(
int)indf);
2637 return (indi >= (_POWTABSIZE - 1)) ? 0.0f : (_fastpowtab[indi] + (indf - indi) * (_fastpowtab[indi + 1] - _fastpowtab[indi]));;
2644 TGX_INLINE
inline void _updateDirectionalLightTransform(
int index)
2646 _r_light[index] = _viewM.
mult0(_light[index]);
2647 _r_light[index] = -_r_light[index];
2649 _r_light_inorm[index] = _r_light[index] * _r_inorm;
2650 _r_H[index] =
fVec3(0, 0, 1);
2651 _r_H[index] += _r_light[index];
2653 _r_H_inorm[index] = _r_H[index] * _r_inorm;
2658 TGX_INLINE
inline void _updateActiveDirectionalLightInorms()
2660 for (
int i = 0; i < _directionalLightCount; i++)
2662 _r_light_inorm[i] = _r_light[i] * _r_inorm;
2663 _r_H_inorm[i] = _r_H[i] * _r_inorm;
2669 TGX_INLINE
inline void _updateActiveDirectionalLightTransforms()
2671 for (
int i = 0; i < _directionalLightCount; i++)
2673 _updateDirectionalLightTransform(i);
2679 TGX_INLINE
inline void _setRuntimeMaterialLighting(
float ambiantStrength,
float diffuseStrength,
float specularStrength)
2681 _r_ambiantColor = _ambiantColor * ambiantStrength;
2682 for (
int i = 0; i < _directionalLightCount; i++)
2684 _r_diffuseColor[i] = _diffuseColor[i] * diffuseStrength;
2685 _r_specularColor[i] = _specularColor[i] * specularStrength;
2691 TGX_INLINE
inline void _updateDirectionalLightColor(
int index)
2693 _r_diffuseColor[index] = _diffuseColor[index] * _diffuseStrength;
2694 _r_specularColor[index] = _specularColor[index] * _specularStrength;
2703 template<
bool TEXTURE> TGX_INLINE
inline RGBf _shadeVertex(
const float icu,
const fVec3 & N)
const
2705 RGBf col = _r_ambiantColor;
2706 if constexpr (MAX_DIRECTIONAL_LIGHTS == 1)
2708 col += _r_diffuseColor[0] *
max(icu *
dotProduct(N, _r_light_inorm[0]), 0.0f);
2709 col += _r_specularColor[0] * _powSpecular(icu *
dotProduct(N, _r_H_inorm[0]));
2713 for (
int i = 0; i < _directionalLightCount; i++)
2715 col += _r_diffuseColor[i] *
max(icu *
dotProduct(N, _r_light_inorm[i]), 0.0f);
2716 col += _r_specularColor[i] * _powSpecular(icu *
dotProduct(N, _r_H_inorm[i]));
2719 if (!(TEXTURE)) col *= _r_objectColor;
2726 TGX_INLINE
inline RGBf _shadeVertex(
const float icu,
const fVec3 & N,
const RGBf & color)
const
2728 RGBf col = _r_ambiantColor;
2729 if constexpr (MAX_DIRECTIONAL_LIGHTS == 1)
2731 col += _r_diffuseColor[0] *
max(icu *
dotProduct(N, _r_light_inorm[0]), 0.0f);
2732 col += _r_specularColor[0] * _powSpecular(icu *
dotProduct(N, _r_H_inorm[0]));
2736 for (
int i = 0; i < _directionalLightCount; i++)
2738 col += _r_diffuseColor[i] *
max(icu *
dotProduct(N, _r_light_inorm[i]), 0.0f);
2739 col += _r_specularColor[i] * _powSpecular(icu *
dotProduct(N, _r_H_inorm[i]));
2750 template<
bool TEXTURE> TGX_INLINE
inline RGBf _shadeFace(
const float icu,
const fVec3 & N)
const
2752 RGBf col = _r_ambiantColor;
2753 if constexpr (MAX_DIRECTIONAL_LIGHTS == 1)
2755 col += _r_diffuseColor[0] *
max(icu *
dotProduct(N, _r_light[0]), 0.0f);
2756 col += _r_specularColor[0] * _powSpecular(icu *
dotProduct(N, _r_H[0]));
2760 for (
int i = 0; i < _directionalLightCount; i++)
2762 col += _r_diffuseColor[i] *
max(icu *
dotProduct(N, _r_light[i]), 0.0f);
2763 col += _r_specularColor[i] * _powSpecular(icu *
dotProduct(N, _r_H[i]));
2766 if (!(TEXTURE)) col *= _r_objectColor;
2773 TGX_INLINE
inline void _setFlatOrUnlitFaceColor(
int raster_type,
bool texture, fVec3& faceN,
float cu)
2775 if constexpr (TGX_SHADER_HAS_UNLIT(ENABLED_SHADERS))
2777 if (TGX_SHADER_HAS_UNLIT(raster_type))
2779 _uni.facecolor = texture ? RGBf(1.0f, 1.0f, 1.0f) : _r_objectColor;
2784 const float icu = ((cu > 0) ? -1.0f : 1.0f);
2785 faceN.normalize_fast();
2787 _uni.facecolor = _shadeFace<true>(icu, faceN);
2789 _uni.facecolor = _shadeFace<false>(icu, faceN);
2809 RasterizerParams<color_t, color_t,ZBUFFER_t> _uni;
2814 int _texture_wrap_mode;
2815 int _texture_quality;
2821 fVec3 _light[MAX_DIRECTIONAL_LIGHTS];
2823 RGBf _diffuseColor[MAX_DIRECTIONAL_LIGHTS];
2824 RGBf _specularColor[MAX_DIRECTIONAL_LIGHTS];
2825 int _directionalLightCount;
2834 float _ambiantStrength;
2835 float _diffuseStrength;
2836 float _specularStrength;
2837 int _specularExponent;
2841 fMat4 _r_modelViewM;
2844 fVec3 _r_light[MAX_DIRECTIONAL_LIGHTS];
2845 fVec3 _r_light_inorm[MAX_DIRECTIONAL_LIGHTS];
2846 fVec3 _r_H[MAX_DIRECTIONAL_LIGHTS];
2847 fVec3 _r_H_inorm[MAX_DIRECTIONAL_LIGHTS];
2848 RGBf _r_ambiantColor;
2849 RGBf _r_diffuseColor[MAX_DIRECTIONAL_LIGHTS];
2850 RGBf _r_specularColor[MAX_DIRECTIONAL_LIGHTS];
2851 RGBf _r_objectColor;
2857 struct ExtVec4 :
public RasterizerVec4
2876#include "Renderer3D.inl"
Color classes [RGB565, RGB24, RGB32, RGB64, RGBf, HSV].
Mat4< float > fMat4
4x4 matrix with single (float) precision
Definition: Mat4.h:54
Compact meshlet-based 3D model mesh format with 16-bit quantization.
Utility/miscellaneous functions used throughout the library.
TGX_INLINE T max(T a, T b)
Don't know why but much faster than fmaxf() for floats.
Definition: Misc.h:153
3D triangle rasterizer function.
#define TGX_RASTERIZE_SUBPIXEL_BITS
Sub-pixel precision bits.
Definition: Rasterizer.h:46
Shader
List of shaders available for 3D graphics.
Definition: ShaderParams.h:44
@ SHADER_NOTEXTURE
disable texture mapping
Definition: ShaderParams.h:59
@ SHADER_TEXTURE
enable texture mapping
Definition: ShaderParams.h:60
Triangle shader functions.
TGX_INLINE T dotProduct(const Vec2< T > &U, const Vec2< T > &V)
Return the dot product U.V between two vectors.
Definition: Vec2.h:554
Vec3< float > fVec3
Floating point valued 3D vector with single (float) precision.
Definition: Vec3.h:52
Vec4< float > fVec4
Floating point valued 4D vector with single (float) precision.
Definition: Vec4.h:54
Image class [MAIN CLASS FOR THE 2D API].
Definition: Image.h:145
Class for drawing 3D objects onto a Image [MAIN CLASS FOR THE 3D API].
Definition: Renderer3D.h:115
void drawQuads(int nb_quads, const uint16_t *ind_vertices, const fVec3 *vertices, const uint16_t *ind_normals=nullptr, const fVec3 *normals=nullptr, const uint16_t *ind_texture=nullptr, const fVec2 *textures=nullptr, const Image< color_t > *texture_image=nullptr)
Draw a collection of quads.
void drawAdaptativeSphere(float quality=1.0f)
Draw a unit radius sphere centered at the origin S(0,1) in model space.
void setTextureQuality(Shader quality)
Set the texturing quality.
void drawWireFrameSphereAA(int nb_sectors, int nb_stacks)
Draw a wireframe unit radius sphere [antialiased] with the current material color.
void drawPixels(int nb_pixels, const fVec3 *pos_list, const int *colors_ind, const color_t *colors, const int *opacities_ind, const float *opacities)
Draw a list of pixels at given positions in model space with different colors and opacities.
void drawWireFrameMesh(const Mesh3Dv2< color_t > *mesh)
Draw a Mesh3Dv2 object in wireframe [fast].
void drawWireFrameLines(int nb_lines, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a collection of wireframe line segments [fast].
void drawWireFrameTriangleAA(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3)
Draw a wireframe triangle [antialiased] with the current material color.
void drawWireFrameLineAA(const fVec3 &P1, const fVec3 &P2)
Draw a wireframe line segment [antialiased] with the current material color.
void setDirectionalLightAmbiant(const RGBf &color)
Set the global ambiant light shared by all directional lights.
void drawQuadWithVertexColor(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4, const RGBf &col1, const RGBf &col2, const RGBf &col3, const RGBf &col4, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr, const fVec3 *N4=nullptr)
Draw a single quad with a given colors on each of its four vertices.
void setLookAt(const fVec3 eye, const fVec3 center, const fVec3 up)
Set the view matrix so that the camera is looking at a given direction.
void drawWireFrameAdaptativeSphere(float quality=1.0f)
Draw a wireframe unit radius sphere centered at the origin (in model space) [fast].
void drawWireFrameCubeAA()
Draw the wireframe cube [0,1]^3 [antialiased] with the current material color.
void drawAdaptativeSphere(const Image< color_t > *texture, float quality=1.0f)
Draw a textured unit radius sphere centered at the origin S(0,1) in model space.
void drawWireFrameLine(const fVec3 &P1, const fVec3 &P2, float thickness, color_t color, float opacity)
Draw a wireframe line segment [adjustable thickness + AA].
void setDirectionalLight(int index, const fVec3 &direction, const RGBf &diffuseColor, const RGBf &specularColor)
Configure one directional light at once.
void drawWireFrameTriangle(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3)
Draw a wireframe triangle [fast].
void setLightDiffuse(const RGBf &color)
Set the diffuse light color of the main directional light of the scene.
void drawCube(const Image< color_t > *texture_front, const Image< color_t > *texture_back, const Image< color_t > *texture_top, const Image< color_t > *texture_bottom, const Image< color_t > *texture_left, const Image< color_t > *texture_right)
draw a textured unit cube [-1,1]^3 (in model space)
void drawWireFrameMesh(const Mesh3D< color_t > *mesh, bool draw_chained_meshes=true)
Draw a mesh in wireframe [fast].
void setLightDirection(const fVec3 &direction)
Set the light source direction of the main directional light of the scene.
void setZbuffer(ZBUFFER_t *zbuffer)
Set the z-buffer.
void drawSkyBox(const fVec2 v_front_ABCD[4], const Image< color_t > *texture_front, const fVec2 v_back_EFGH[4], const Image< color_t > *texture_back, const fVec2 v_top_HADE[4], const Image< color_t > *texture_top, const fVec2 v_bottom_BGFC[4], const Image< color_t > *texture_bottom, const fVec2 v_left_HGBA[4], const Image< color_t > *texture_left, const fVec2 v_right_DCFE[4], const Image< color_t > *texture_right, float rot_angle_y=0.0f, float reference_height=0.0f, float skybox_radius=32768.0f, Shader texture_quality=SHADER_TEXTURE_NEAREST, Shader texture_mode=SHADER_TEXTURE_CLAMP)
Draw a textured sky-box around the current camera.
void drawPixels(int nb_pixels, const fVec3 *pos_list)
Draw a list of pixels at given positions in model space.
void drawWireFrameMeshAA(const Mesh3Dv2< color_t > *mesh)
Draw a Mesh3Dv2 object in wireframe [antialiased] with the current material color.
TGX_NOINLINE Renderer3D(const iVec2 &viewportSize={0, 0}, Image< color_t > *im=nullptr, ZBUFFER_t *zbuffer=nullptr)
Constructor.
void setProjectionMatrix(const fMat4 &M)
Set the projection matrix.
void drawCube()
Draw the unit cube [-1,1]^3 in model space.
fMat4 getProjectionMatrix() const
Return the current projection matrix.
void drawWireFrameCube(float thickness, color_t color, float opacity)
Draw the wireframe cube [0,1]^3 (in model space) [adjustable thickness + AA].
void drawMesh(const Mesh3Dv2< color_t > *mesh, bool use_mesh_material=true)
Draw a Mesh3Dv2 object.
void setDirectionalLightSpecular(int index, const RGBf &color)
Set the specular color of one directional light.
iVec2 modelToImage(fVec3 P)
Convert from model coordinates to the corresponding image pixel.
void setShaders(Shader shaders)
Set the shaders to use for subsequent drawing operations.
void drawPixel(const fVec3 &pos, color_t color, float opacity)
Draw a single pixel at a given position in model space.
iVec2 worldToImage(fVec3 P)
Convert from world coordinates to the corresponding image pixel.
void drawWireFrameQuad(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4, float thickness, color_t color, float opacity)
Draw a wireframe quad [adjustable thickness + AA].
void setMaterialDiffuseStrength(float strenght=0.6f)
Set how much the object material reflects the diffuse light.
void drawWireFrameQuadsAA(int nb_quads, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw wireframe quads [antialiased] with the current material color.
void setLightAmbiant(const RGBf &color)
Set the scene ambiant light color.
void drawWireFrameAdaptativeSphereAA(float quality=1.0f)
Draw an adaptive wireframe sphere [antialiased] with the current material color.
void setImage(Image< color_t > *im)
Set the image that will be drawn onto.
void drawWireFrameCube()
Draw the wireframe cube [0,1]^3 (in model space) [fast].
void drawWireFrameTriangleStrip(int nb_indices, const uint16_t *ind_vertices, const fVec3 *vertices, float thickness, color_t color, float opacity)
Draw a triangle strip in wireframe [adjustable thickness + AA].
void drawWireFrameMesh(const Mesh3D< color_t > *mesh, bool draw_chained_meshes, float thickness, color_t color, float opacity)
Draw a mesh in wireframe [adjustable thickness + AA].
void setTextureWrappingMode(Shader wrap_mode)
Set the wrap mode when for texturing.
void setViewportSize(int lx, int ly)
Set the size of the viewport.
fMat4 getViewMatrix() const
Return the current view matrix.
void setDirectionalLightCount(int count)
Set the number of active directional lights.
void drawWireFrameTriangle(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, float thickness, color_t color, float opacity)
Draw a wireframe triangle [adjustable thickness + AA].
void setViewportSize(const iVec2 &viewport_dim)
Set the size of the viewport.
void setOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
Set the projection matrix as an orthographic matrix.
void drawTriangleWithVertexColor(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const RGBf &col1, const RGBf &col2, const RGBf &col3, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr)
Draw a single triangle with a given colors on each of its vertices.
void drawWireFrameLines(int nb_lines, const uint16_t *ind_vertices, const fVec3 *vertices, float thickness, color_t color, float opacity)
Draw a collection of wireframe line segments [adjustable thickness + AA].
fMat4 getModelMatrix() const
Return the model transformation matrix.
void setMaterialSpecularStrength(float strenght=0.5f)
Set how much the object material reflects the specular light.
void drawSphere(int nb_sectors, int nb_stacks, const Image< color_t > *texture)
Draw a textured unit radius sphere centered at the origin S(0,1) in model space.
void setModelMatrix(const fMat4 &M)
Set the model transformation matrix.
void drawWireFrameMeshAA(const Mesh3D< color_t > *mesh, bool draw_chained_meshes=true)
Draw a mesh in wireframe [antialiased] with the current material color.
void drawSkyBox(const Image< color_t > *texture_front, const Image< color_t > *texture_back, const Image< color_t > *texture_top, const Image< color_t > *texture_bottom, const Image< color_t > *texture_left, const Image< color_t > *texture_right, float rot_angle_y=0.0f, float reference_height=0.0f, float skybox_radius=32768.0f, Shader texture_quality=SHADER_TEXTURE_NEAREST, Shader texture_mode=SHADER_TEXTURE_CLAMP)
Draw a textured sky-box using whole images for each face.
void drawDots(int nb_dots, const fVec3 *pos_list, const int *radius_ind, const int *radius, const int *colors_ind, const color_t *colors, const int *opacities_ind, const float *opacities)
Draw a list of dots/circles at given positions in model space.
void setFrustum(float left, float right, float bottom, float top, float zNear, float zFar)
Set the projection matrix as a perspective matrix.
void drawWireFrameSphere(int nb_sectors, int nb_stacks)
Draw a wireframe unit radius sphere centered at the origin (in model space) [fast].
void setOffset(const iVec2 &offset)
Set the offset of the image relative to the viewport.
void setPerspective(float fovy, float aspect, float zNear, float zFar)
Set the projection matrix as a perspective matrix.
void drawWireFrameLine(const fVec3 &P1, const fVec3 &P2)
Draw a wireframe line segment [fast].
void drawWireFrameQuad(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4)
Draw a wireframe quad [fast].
void setOffset(int ox, int oy)
Set the offset of the image relative to the viewport.
void drawMesh(const Mesh3D< color_t > *mesh, bool use_mesh_material=true, bool draw_chained_meshes=true)
Draw a Mesh3D object.
void drawWireFrameTrianglesAA(int nb_triangles, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw wireframe triangles [antialiased] with the current material color.
void drawTriangle(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr, const fVec2 *T1=nullptr, const fVec2 *T2=nullptr, const fVec2 *T3=nullptr, const Image< color_t > *texture=nullptr)
Draw a single triangle.
void drawCube(const fVec2 v_front_ABCD[4], const Image< color_t > *texture_front, const fVec2 v_back_EFGH[4], const Image< color_t > *texture_back, const fVec2 v_top_HADE[4], const Image< color_t > *texture_top, const fVec2 v_bottom_BGFC[4], const Image< color_t > *texture_bottom, const fVec2 v_left_HGBA[4], const Image< color_t > *texture_left, const fVec2 v_right_DCFE[4], const Image< color_t > *texture_right)
Draw a textured unit cube [-1,1]^3 in model space.
void drawDot(const fVec3 &pos, int r, color_t color, float opacity)
Draw a dot/circle at a given position in model space.
void drawWireFrameTriangles(int nb_triangles, const uint16_t *ind_vertices, const fVec3 *vertices, float thickness, color_t color, float opacity)
Draw a collection of wireframe triangles [adjustable thickness + AA].
fVec4 modelToNDC(fVec3 P)
Convert from model coordinates to normalized device coordinates (NDC).
void drawQuad(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4, const fVec3 *N1=nullptr, const fVec3 *N2=nullptr, const fVec3 *N3=nullptr, const fVec3 *N4=nullptr, const fVec2 *T1=nullptr, const fVec2 *T2=nullptr, const fVec2 *T3=nullptr, const fVec2 *T4=nullptr, const Image< color_t > *texture=nullptr)
Draw a single quad.
void usePerspectiveProjection()
Set projection mode to perspective (ie with z-divide).
void setMaterialAmbiantStrength(float strenght=0.1f)
Set how much the object material reflects the ambient light.
void setDirectionalLightDiffuse(int index, const RGBf &color)
Set the diffuse color of one directional light.
void setMaterialSpecularExponent(int exponent=16)
Set the object specular exponent.
void setModelPosScaleRot(const fVec3 ¢er=fVec3{ 0, 0, 0 }, const fVec3 &scale=fVec3(1, 1, 1), float rot_angle=0, const fVec3 &rot_dir=fVec3{ 0, 1, 0 })
Set the model transformation matrix to move an object to a given location, scale and rotation.
void setCulling(int w)
Set the face culling strategy.
void drawWireFrameLinesAA(int nb_lines, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw wireframe line segments [antialiased] with the current material color.
void useOrthographicProjection()
Set projection mode to orthographic (ie no z-divide).
void drawTriangleStrip(int nb_indices, const uint16_t *ind_vertices, const fVec3 *vertices, const uint16_t *ind_normals=nullptr, const fVec3 *normals=nullptr, const uint16_t *ind_texture=nullptr, const fVec2 *textures=nullptr, const Image< color_t > *texture_image=nullptr)
Draw a triangle strip.
void setDirectionalLightDirection(int index, const fVec3 &direction)
Set the direction of one directional light.
void setViewMatrix(const fMat4 &M)
Set the view transformation matrix.
void drawWireFrameTriangleStrip(int nb_indices, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a triangle strip in wireframe [fast].
void clearZbuffer()
Clear the Zbuffer.
void setMaterialColor(RGBf color)
Set the object material color.
fVec4 worldToNDC(fVec3 P)
Convert from world coordinates to normalized device coordinates (NDC).
void drawPixel(const fVec3 &pos)
Draw a single pixel at a given position in model space.
void drawWireFrameTriangleStripAA(int nb_indices, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a triangle strip in wireframe [antialiased] with the current material color.
void drawSphere(int nb_sectors, int nb_stacks)
Draw a unit radius sphere centered at the origin S(0,1) in model space.
void drawDot(const fVec3 &pos, int r)
Draw a dot/circle at a given position in model space.
void drawWireFrameQuads(int nb_quads, const uint16_t *ind_vertices, const fVec3 *vertices, float thickness, color_t color, float opacity)
Draw a collection of wireframe quads [adjustable thickness + AA].
void setLight(const fVec3 direction, const RGBf &ambiantColor, const RGBf &diffuseColor, const RGBf &specularColor)
Set all lighting parameters of the main directional light of the scene at once.
void drawWireFrameAdaptativeSphere(float quality, float thickness, color_t color, float opacity)
Draw a wireframe unit radius sphere centered at the origin (in model space) [adjustable thickness + A...
void setMaterial(RGBf color, float ambiantStrength, float diffuseStrength, float specularStrength, int specularExponent)
Set all the object material properties at once.
static constexpr int maxDirectionalLightCount()
Return the compile-time directional-light capacity.
Definition: Renderer3D.h:658
void setLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Set the view matrix so that the camera is looking at a given direction.
void setLightSpecular(const RGBf &color)
Set the specular light color of the main directional light of the scene.
void drawWireFrameQuads(int nb_quads, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a collection of wireframe quads [fast].
void drawWireFrameTriangles(int nb_triangles, const uint16_t *ind_vertices, const fVec3 *vertices)
Draw a collection of wireframe triangles [fast].
void drawWireFrameSphere(int nb_sectors, int nb_stacks, float thickness, color_t color, float opacity)
Draw a wireframe unit radius sphere centered at the origin (in model space) [adjustable thickness + A...
int directionalLightCount() const
Return the number of active directional lights.
void drawWireFrameMesh(const Mesh3Dv2< color_t > *mesh, float thickness, color_t color, float opacity)
Draw a Mesh3Dv2 object in wireframe [adjustable thickness + AA].
void drawWireFrameQuadAA(const fVec3 &P1, const fVec3 &P2, const fVec3 &P3, const fVec3 &P4)
Draw a wireframe quad [antialiased] with the current material color.
void drawTriangles(int nb_triangles, const uint16_t *ind_vertices, const fVec3 *vertices, const uint16_t *ind_normals=nullptr, const fVec3 *normals=nullptr, const uint16_t *ind_texture=nullptr, const fVec2 *textures=nullptr, const Image< color_t > *texture_image=nullptr)
Draw a collection of triangles.
void drawDots(int nb_dots, const fVec3 *pos_list, const int radius)
Draw a list of dots/circles at given positions in model space.
TGX_INLINE Vec4< T > mult1(const Vec3< T > &V) const
Matrix-vector multiplication (last component of vector set to w = 1)
Definition: Mat4.h:578
TGX_INLINE Vec4< T > mult0(const Vec3< T > &V) const
Matrix-vector multiplication (last component of vector set to w = 0).
Definition: Mat4.h:557
3D mesh data structure.
Definition: Mesh3D.h:157
Compact meshlet-based 3D mesh data structure.
Definition: Mesh3Dv2.h:239
Color in R,G,B float format.
Definition: Color.h:2405
TGX_INLINE void clamp()
Clamp all color channel to [0.0f,1.0f].
Definition: Color.h:2645
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64
T x
'x' coordinate (first dimension)
Definition: Vec2.h:72
T y
'y' coordinate (second dimension)
Definition: Vec2.h:73
T z
'z' coordinate (third dimension)
Definition: Vec3.h:83
void normalize()
Normalise the vector so that its norm is 1 (do nothing if the vector is 0).
Definition: Vec3.h:382
T w
'w' coordinate (fourth dimension)
Definition: Vec4.h:85
TGX_INLINE_ZDIVIDE void zdivide()
Performs the 'z-divide' operation.
Definition: Vec4.h:478