SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
SLRaytracer hold all the methods for Whitted style Ray Tracing. More...
#include <SLRaytracer.h>
Public Member Functions | |
SLRaytracer () | |
~SLRaytracer () override | |
SLbool | renderClassic (SLSceneView *sv) |
SLbool | renderDistrib (SLSceneView *sv) |
void | renderSlices (bool isMainThread, SLuint threadNum) |
void | renderSlicesMS (bool isMainThread, SLuint threadNum) |
SLCol4f | trace (SLRay *ray) |
SLCol4f | shade (SLRay *ray) |
void | sampleAAPixels (bool isMainThread, SLuint threadNum) |
void | renderUIBeforeUpdate () |
Must be called before an inbetween frame updateRec. More... | |
void | setPrimaryRay (SLfloat x, SLfloat y, SLRay *primaryRay) |
Set the parameters of a primary ray for a pixel position at x, y. More... | |
void | getAAPixels () |
SLCol4f | fogBlend (SLfloat z, SLCol4f color) |
virtual void | printStats (SLfloat sec) |
virtual void | initStats (SLint depth) |
void | state (SLRTState state) |
void | maxDepth (SLint depth) |
void | resolutionFactor (SLfloat rf) |
void | doDistributed (SLbool distrib) |
void | doContinuous (SLbool cont) |
void | doFresnel (SLbool fresnel) |
void | aaSamples (SLint samples) |
void | gamma (SLfloat g) |
SLRTState | state () const |
SLint | maxDepth () const |
SLbool | doDistributed () const |
SLbool | doContinuous () const |
SLbool | doFresnel () const |
SLint | aaSamples () const |
SLint | progressPC () const |
SLfloat | aaThreshold () const |
SLfloat | renderSec () const |
SLfloat | gamma () const |
SLfloat | oneOverGamma () const |
SLfloat | resolutionFactor () const |
SLint | resolutionFactorPC () const |
SLfloat | raysPerMS () |
virtual void | prepareImage () |
virtual void | renderImage (bool updateTextureGL) |
virtual void | saveImage () |
Saves the current RT image as PNG image. More... | |
Public Member Functions inherited from SLGLTexture | |
SLGLTexture () | |
Default ctor for all stack instances (not created with new) More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLVCol4f &colors, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLint wrapS=GL_REPEAT, const SLstring &name="2D-Texture") | |
ctor for 1D texture with internal image allocation More... | |
SLGLTexture (SLAssetManager *assetMgr, SLint min_filter, SLint mag_filter, SLint wrapS, SLint wrapT, SLenum target=GL_TEXTURE_2D) | |
ctor for empty 2D textures More... | |
SLGLTexture (SLAssetManager *assetMgr, unsigned char *data, int width, int height, int cvtype, SLint min_filter, SLint mag_filter, SLTextureType type, SLint wrapS, SLint wrapT) | |
ctor for 2D textures from byte pointer More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLstring &imageFilename, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT) | |
ctor for 2D textures with internal image allocation More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLVstring &imageFilenames, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT, const SLstring &name="3D-Texture", SLbool loadGrayscaleIntoAlpha=false) | |
ctor for 3D texture with internal image allocation More... | |
SLGLTexture (SLAssetManager *assetMgr, SLint depth, const SLstring &imageFilename, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT, const SLstring &name="3D-Texture", SLbool loadGrayscaleIntoAlpha=false) | |
ctor for 3D texture from a single file with depth as 3rd dimension More... | |
SLGLTexture (SLAssetManager *assetMgr, const SLstring &imageFilenameXPos, const SLstring &imageFilenameXNeg, const SLstring &imageFilenameYPos, const SLstring &imageFilenameYNeg, const SLstring &imageFilenameZPos, const SLstring &imageFilenameZNeg, SLint min_filter=GL_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown) | |
ctor for cube mapping with internal image allocation More... | |
~SLGLTexture () override | |
virtual void | build (SLint texUnit) |
void | deleteData (SLbool deleteAlsoOnGPU) |
Delete all data (CVImages and GPU textures) More... | |
void | deleteDataGpu () |
Deletes the OpenGL texture objects and releases the memory on the GPU. More... | |
void | deleteImages () |
Deletes the CVImages in _images. No more texture mapping in ray tracing. More... | |
void | bindActive (SLuint texUnit=0) |
void | fullUpdate () |
void | drawSprite (SLbool doUpdate, SLfloat x, SLfloat y, SLfloat w, SLfloat h) |
Draws the texture as 2D sprite with OpenGL buffers. More... | |
void | cubeUV2XYZ (SLint index, SLfloat u, SLfloat v, SLfloat &x, SLfloat &y, SLfloat &z) |
Computes the unnormalised vector x,y,z from tex. coords. uv with cubemap index. More... | |
void | cubeXYZ2UV (SLfloat x, SLfloat y, SLfloat z, SLint &index, SLfloat &u, SLfloat &v) |
Computes the uv and cubemap image index from a unnormalised vector x,y,z. More... | |
SLstring | filterString (SLint glFilter) |
Returns OpenGL texture filter as string. More... | |
void | texType (SLTextureType bt) |
void | uvIndex (SLbyte i) |
void | bumpScale (SLfloat bs) |
void | minFiler (SLint minF) |
void | magFiler (SLint magF) |
void | needsUpdate (SLbool update) |
void | textureSize (int width, int height) |
void | deleteImageAfterBuild (SLbool delImg) |
If deleteImageAfterBuild is set to true you won't be able to ray trace the scene. More... | |
SLuint | width () |
SLuint | height () |
SLuint | depth () |
SLbyte | uvIndex () |
SLint | bytesPerPixel () |
SLint | bytesOnGPU () |
SLint | bytesInFile () |
CVVImage & | images () |
SLenum | target () const |
SLuint | texID () const |
SLTextureType | texType () |
SLfloat | bumpScale () const |
SLCol4f | getTexelf (SLfloat u, SLfloat v, SLuint imgIndex=0) |
SLGLTexture::getTexelf returns a pixel color from u & v texture coordinates. More... | |
SLCol4f | getTexelf (const SLVec3f &cubemapDir) |
SLGLTexture::getTexelf returns a pixel color at the specified cubemap direction. More... | |
SLbool | hasAlpha () |
SLMat4f | tm () |
SLbool | autoCalcTM3D () const |
SLbool | needsUpdate () |
SLstring | typeName () |
Returns the texture type as string. More... | |
SLstring | typeShortName () |
Returns the texture type short. More... | |
bool | isTexture () |
SLstring | minificationFilterName () |
SLstring | magnificationFilterName () |
void | build2DMipmaps (SLint target, SLuint index) |
SLbool | copyVideoImage (SLint camWidth, SLint camHeight, CVPixelFormatGL glFormat, SLuchar *data, SLbool isContinuous, SLbool isTopLeft) |
Copies the image data from a video camera into the current video image. More... | |
SLbool | copyVideoImage (SLint camWidth, SLint camHeight, CVPixelFormatGL srcFormat, CVPixelFormatGL dstFormat, SLuchar *data, SLbool isContinuous, SLbool isTopLeft) |
void | calc3DGradients (SLint sampleRadius, const function< void(int)> &onUpdateProgress=nullptr) |
void | smooth3DGradients (SLint smoothRadius, function< void(int)> onUpdateProgress=nullptr) |
SLVec2f | dudv (SLfloat u, SLfloat v) |
Public Member Functions inherited from SLObject | |
SLObject (const SLstring &Name="", const SLstring &url="") | |
virtual | ~SLObject () |
void | name (const SLstring &Name) |
void | url (const SLstring &url) |
const SLstring & | name () const |
const SLstring & | url () const |
Public Member Functions inherited from SLEventHandler | |
SLEventHandler () | |
virtual | ~SLEventHandler () |
virtual SLbool | onMouseDown (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod) |
virtual SLbool | onMouseUp (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod) |
virtual SLbool | onMouseMove (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod) |
virtual SLbool | onDoubleClick (const SLMouseButton button, const SLint x, const SLint y, const SLKey mod) |
virtual SLbool | onMouseWheel (const SLint delta, const SLKey mod) |
virtual SLbool | onTouch2Down (const SLint x1, const SLint y1, const SLint x2, const SLint y2) |
virtual SLbool | onTouch2Move (const SLint x1, const SLint y1, const SLint x2, const SLint y2) |
virtual SLbool | onTouch2Up (const SLint x1, const SLint y1, const SLint x2, const SLint y2) |
virtual SLbool | onTouch3Down (const SLint x1, const SLint y1) |
virtual SLbool | onTouch3Move (const SLint x1, const SLint y1) |
virtual SLbool | onTouch3Up (const SLint x1, const SLint y1) |
virtual SLbool | onKeyPress (const SLKey key, const SLKey mod) |
virtual SLbool | onKeyRelease (const SLKey key, const SLKey mod) |
virtual SLbool | onRotationPYR (const SLfloat pitchRAD, const SLfloat yawRAD, const SLfloat rollRAD) |
void | mouseRotationFactor (SLfloat rf) |
SLfloat | mouseRotationFactor () |
Static Public Member Functions | |
static SLuint | numThreads () |
Static Public Member Functions inherited from SLGLTexture | |
static SLTextureType | detectType (const SLstring &filename) |
Detects the texture type from the filename appendix (See SLTexType def.) More... | |
static string | internalFormatStr (int internalFormat) |
Returns the internal pixel format from OpenGL. More... | |
Protected Attributes | |
function< void(bool, SLuint)> | renderSlicesAsync |
function< void(bool, SLuint)> | sampleAAPixelsAsync |
SLSceneView * | _sv |
Parent sceneview. More... | |
SLRTState | _state |
RT state;. More... | |
SLCamera * | _cam |
shortcut to the camera More... | |
SLfloat | _resolutionFactor |
screen to RT image size factor (default 1.0) More... | |
SLint | _maxDepth |
Max. allowed recursion depth. More... | |
SLbool | _doContinuous |
if true state goes into ready again More... | |
SLbool | _doDistributed |
Flag for parallel distributed RT. More... | |
SLbool | _doFresnel |
Flag for Fresnel reflection. More... | |
SLint | _progressPC |
progress in % More... | |
SLfloat | _renderSec |
Rendering time in seconds. More... | |
AvgFloat | _raysPerMS |
Averaged rays per ms. More... | |
SLfloat | _pxSize |
Pixel size. More... | |
SLVec3f | _eye |
Camera position. More... | |
SLVec3f | _la |
SLVec3f | _lu |
SLVec3f | _lr |
Camera lookat, lookup, lookright. More... | |
SLVec3f | _bl |
Bottom left vector. More... | |
SLint | _nextLine |
next line index to render RT in a thread More... | |
SLVPixel | _aaPixels |
Vector for antialiasing pixels. More... | |
SLfloat | _gamma |
gamma correction value More... | |
SLfloat | _oneOverGamma |
one over gamma correction value More... | |
SLfloat | _aaThreshold |
threshold for anti aliasing More... | |
SLint | _aaSamples |
SQRT of uneven num. of AA samples. More... | |
Protected Attributes inherited from SLGLTexture | |
CVVImage | _images |
Vector of CVImage pointers. More... | |
SLuint | _texID |
OpenGL texture ID. More... | |
SLTextureType | _texType |
See SLTextureType. More... | |
SLint | _width |
Texture image width in pixels (images exist either in _images or on the GPU or on both) More... | |
SLint | _height |
Texture image height in pixels (images exist either in _images or on the GPU or on both) More... | |
SLint | _depth |
3D Texture image depth (images exist either in _images or on the GPU or on both) More... | |
SLbyte | _uvIndex |
Texture coordinate index in SLMesh (0 = default) More... | |
SLint | _internalFormat |
Internal OpenGL format. More... | |
SLint | _bytesPerPixel |
Bytes per texture image pixel (images exist either in _images or on the GPU or on both) More... | |
SLint | _min_filter |
Minification filter. More... | |
SLint | _mag_filter |
Magnification filter. More... | |
SLint | _wrap_s |
Wrapping in s direction. More... | |
SLint | _wrap_t |
Wrapping in t direction. More... | |
SLenum | _target |
texture target More... | |
SLMat4f | _tm |
texture matrix More... | |
SLuint | _bytesOnGPU |
NO. of bytes on GPU. More... | |
SLuint | _bytesInFile |
NO. of bytes in file. More... | |
SLbool | _autoCalcTM3D |
Flag if texture matrix should be calculated from AABB for 3D mapping. More... | |
SLfloat | _bumpScale |
Bump mapping scale factor. More... | |
SLbool | _resizeToPow2 |
Flag if image should be resized to n^2. More... | |
SLGLVertexArray | _vaoSprite |
Vertex array object for sprite rendering. More... | |
std::atomic< bool > | _needsUpdate {} |
Flag if image needs an single update. More... | |
std::mutex | _mutex |
Mutex to protect parallel access (used in ray tracing) More... | |
SLbool | _deleteImageAfterBuild |
Flag if images should be deleted after build on GPU. More... | |
SLbool | _compressedTexture = false |
True for compressed texture format on GPU. More... | |
Protected Attributes inherited from SLObject | |
SLstring | _name |
name of an object More... | |
SLstring | _url |
uniform resource locator More... | |
Protected Attributes inherited from SLEventHandler | |
SLfloat | _mouseRotationFactor |
Mouse rotation sensibility. More... | |
SLfloat | _keyboardDeltaPos |
Delta dist. for keyboard translation. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from SLGLTexture | |
static SLfloat | maxAnisotropy = -1.0f |
Returns the derivation as [s,t]. More... | |
static SLuint | totalNumBytesOnGPU = 0 |
Total NO. of bytes used for textures on GPU. More... | |
Protected Member Functions inherited from SLGLTexture | |
void | load (const SLstring &filename, SLbool flipVertical=true, SLbool loadGrayscaleIntoAlpha=false) |
Loads the texture, converts color depth & applies vertical mirroring. More... | |
void | load (const SLVCol4f &colors) |
Loads the 1D color data into an image of height 1. More... | |
SLRaytracer hold all the methods for Whitted style Ray Tracing.
SLRaytracer implements the methods render, eyeToPixel, trace and shade for classic Whitted style Ray Tracing. This class is a friend class of SLScene and can access via the pointer _s all members of SLScene. The scene traversal for the ray intersection tests is done within the intersection method of all nodes.
Definition at line 55 of file SLRaytracer.h.
SLRaytracer::SLRaytracer | ( | ) |
Definition at line 22 of file SLRaytracer.cpp.
|
override |
Definition at line 46 of file SLRaytracer.cpp.
|
inline |
Definition at line 118 of file SLRaytracer.h.
Definition at line 101 of file SLRaytracer.h.
|
inline |
Definition at line 121 of file SLRaytracer.h.
|
inline |
Definition at line 116 of file SLRaytracer.h.
Definition at line 91 of file SLRaytracer.h.
|
inline |
Definition at line 115 of file SLRaytracer.h.
Definition at line 90 of file SLRaytracer.h.
|
inline |
Definition at line 117 of file SLRaytracer.h.
Definition at line 96 of file SLRaytracer.h.
fogBlend: Blends the a fog color to the passed color according to to OpenGL fog calculation. See OpenGL docs for more information on fog properties.
Definition at line 757 of file SLRaytracer.cpp.
|
inline |
Definition at line 123 of file SLRaytracer.h.
Definition at line 106 of file SLRaytracer.h.
void SLRaytracer::getAAPixels | ( | ) |
This method fills the pixels into the vector pix that need to be sub-sampled because the contrast to its left and/or above neighbor is above a threshold.
Definition at line 605 of file SLRaytracer.cpp.
Initialises the statistic variables in SLRay to zero
Definition at line 785 of file SLRaytracer.cpp.
|
inline |
Definition at line 114 of file SLRaytracer.h.
|
inlinestatic |
Definition at line 119 of file SLRaytracer.h.
|
inline |
Definition at line 124 of file SLRaytracer.h.
|
virtual |
Creates the inherited image in the texture class. The RT is drawn into a texture map that is displayed with OpenGL in 2D-orthographic projection. Also precalculate as much as possible.
Definition at line 842 of file SLRaytracer.cpp.
Prints some statistics after the rendering
Definition at line 804 of file SLRaytracer.cpp.
|
inline |
Definition at line 120 of file SLRaytracer.h.
|
inline |
Definition at line 127 of file SLRaytracer.h.
SLbool SLRaytracer::renderClassic | ( | SLSceneView * | sv | ) |
This is the main rendering method for the classic ray tracing. It loops over all lines and pixels and determines for each pixel a color with a partly global illumination calculation.
Definition at line 56 of file SLRaytracer.cpp.
SLbool SLRaytracer::renderDistrib | ( | SLSceneView * | sv | ) |
This is the main rendering method for parallel and distributed ray tracing.
Definition at line 125 of file SLRaytracer.cpp.
|
virtual |
Draw the RT-Image as a textured quad in 2D-Orthographic projection
Definition at line 924 of file SLRaytracer.cpp.
|
inline |
Definition at line 122 of file SLRaytracer.h.
Renders slices of 4 rows until the full width of the image is rendered. This method can be called as a function by multiple threads. The _nextLine index is used and incremented by every thread. So it should be locked or an atomic index. I prefer not protecting it because it's faster. If the increment is not done properly some pixels may get ray traced twice. Only the main thread is allowed to call a repaint of the image.
Definition at line 221 of file SLRaytracer.cpp.
Renders slices of 4 rows multi-sampled until the full width of the image is rendered. Every pixel is multi-sampled for depth of field lens sampling. This method can be called as a function by multiple threads. The _nextLine index is used and incremented by every thread. So it should be locked or an atomic index. I prefer not protecting it because it's faster. If the increment is not done properly some pixels may get ray traced twice. Only the main thread is allowed to call a repaint of the image.
Definition at line 295 of file SLRaytracer.cpp.
void SLRaytracer::renderUIBeforeUpdate | ( | ) |
Must be called before an inbetween frame updateRec.
Definition at line 968 of file SLRaytracer.cpp.
|
inline |
Definition at line 125 of file SLRaytracer.h.
Definition at line 89 of file SLRaytracer.h.
|
inline |
Definition at line 126 of file SLRaytracer.h.
SLRaytracer::sampleAAPixels does the subsampling of the pixels that need to be antialiased. See also getAAPixels. This routine can be called by multiple threads. The _nextLine index is used and incremented by every thread. So it should be locked or an atomic index. I prefer not protecting it because it's faster. If the increment is not done properly some pixels may get ray traced twice. Only the main thread is allowed to call a repaint of the image.
Definition at line 671 of file SLRaytracer.cpp.
|
virtual |
Saves the current RT image as PNG image.
Reimplemented in SLPathtracer.
Definition at line 950 of file SLRaytracer.cpp.
Set the parameters of a primary ray for a pixel position at x, y.
Definition at line 464 of file SLRaytracer.cpp.
This method calculates the local illumination at the rays intersection point. It uses the Blinn-Phong local reflection model where the color is calculated as follows: color = material emission + global ambient light scaled by the material's ambient color + ambient, diffuse, and specular contributions from all lights, properly attenuated
Definition at line 503 of file SLRaytracer.cpp.
|
inline |
Definition at line 113 of file SLRaytracer.h.
This method is the classic recursive ray tracing method that checks the scene for intersection. If the ray hits an object the local color is calculated and if the material is reflective and/or transparent new rays are created and passed to this trace method again. If no object got intersected the background color is return.
Definition at line 393 of file SLRaytracer.cpp.
|
protected |
Vector for antialiasing pixels.
Definition at line 155 of file SLRaytracer.h.
|
protected |
SQRT of uneven num. of AA samples.
Definition at line 161 of file SLRaytracer.h.
|
protected |
threshold for anti aliasing
Definition at line 160 of file SLRaytracer.h.
|
protected |
Bottom left vector.
Definition at line 153 of file SLRaytracer.h.
|
protected |
shortcut to the camera
Definition at line 140 of file SLRaytracer.h.
|
protected |
if true state goes into ready again
Definition at line 143 of file SLRaytracer.h.
|
protected |
Flag for parallel distributed RT.
Definition at line 144 of file SLRaytracer.h.
|
protected |
Flag for Fresnel reflection.
Definition at line 145 of file SLRaytracer.h.
|
protected |
Camera position.
Definition at line 151 of file SLRaytracer.h.
|
protected |
gamma correction value
Definition at line 156 of file SLRaytracer.h.
|
protected |
Definition at line 152 of file SLRaytracer.h.
|
protected |
Camera lookat, lookup, lookright.
Definition at line 152 of file SLRaytracer.h.
|
protected |
Definition at line 152 of file SLRaytracer.h.
|
protected |
Max. allowed recursion depth.
Definition at line 142 of file SLRaytracer.h.
|
protected |
next line index to render RT in a thread
Definition at line 154 of file SLRaytracer.h.
|
protected |
one over gamma correction value
Definition at line 157 of file SLRaytracer.h.
|
protected |
progress in %
Definition at line 146 of file SLRaytracer.h.
|
protected |
Pixel size.
Definition at line 150 of file SLRaytracer.h.
|
protected |
Averaged rays per ms.
Definition at line 148 of file SLRaytracer.h.
|
protected |
Rendering time in seconds.
Definition at line 147 of file SLRaytracer.h.
|
protected |
screen to RT image size factor (default 1.0)
Definition at line 141 of file SLRaytracer.h.
|
protected |
RT state;.
Definition at line 139 of file SLRaytracer.h.
|
protected |
Parent sceneview.
Definition at line 138 of file SLRaytracer.h.
Definition at line 135 of file SLRaytracer.h.
Definition at line 136 of file SLRaytracer.h.