| Support Forum Library Source SourceForge Page G3D Web Page |
The surface of a model, posed and ready for rendering. More...
Inherits G3D::ReferenceCountedObject.
Inherited by G3D::HeightfieldModel::Tile, G3D::PhysicsFrameSplineEditor::SplineSurface, G3D::SkyboxSurface, G3D::UniversalSurface, G3D::VisualizeCameraSurface, and G3D::VisualizeLightSurface.
Classes | |
| class | Environment |
| Per-frame, view-dependent lighting information. More... | |
Public Types | |
| enum | AlphaMode { ALPHA_BINARY, ALPHA_TO_COVERAGE, ALPHA_BLEND } |
| How sortAndRender() configures the RenderDevice to process alpha. More... | |
| typedef shared_ptr< class Surface > | Ref |
Public Member Functions | |
| virtual | ~Surface () |
| virtual bool | canRenderIntoGBuffer () const =0 |
| Can this particular instance of this type of surface render into a GBuffer? Often set to false for surfaces with special back-to-front rendering needs. | |
| virtual bool | castsShadows () const |
| True if this surface casts shadows. | |
| virtual bool | depthWriteHint (float distanceToCamera) const |
| A hint to the renderer indicating that this surface should write to the depth buffer. | |
| virtual void | getCoordinateFrame (CoordinateFrame &cframe, bool previous=false) const =0 |
| virtual void | getObjectSpaceBoundingBox (AABox &box, bool previous=false) const =0 |
| May be infinite. | |
| virtual void | getObjectSpaceBoundingSphere (Sphere &sphere, bool previous=false) const =0 |
| May be infinite. | |
| virtual void | getObjectSpaceGeometry (Array< int > &index, Array< Point3 > &vertex, Array< Vector3 > &normal, Array< Vector4 > &packedTangent, Array< Point2 > &texCoord, bool previous=false) |
| Clears the arrays and appends indexed triangle list information. | |
| virtual void | getTrisHomogeneous (const Array< shared_ptr< Surface > > &surfaceArray, CPUVertexArray &cpuVertexArray, Array< Tri > &triArray, bool computePrevPosition=false) const |
| Creates and appends Tris and CPUVertexArray::Vertices onto the parameter arrays using the cpuGeom's of the surfaces in surfaceArray. | |
| virtual bool | hasPartialCoverage () const |
| If true, this object's material produces subpixel coverage (i.e. | |
| virtual bool | hasTransmission () const |
| If true, this object transmits light and depends on back-to-front rendering order and should be rendered in sorted order. | |
| virtual std::string | name () const =0 |
| Name of the underlying model or part for debugging purposes. | |
| virtual void | render (RenderDevice *rd, const Environment &environment) const |
| The default implementation calls renderHomogeneous. | |
| virtual void | renderDepthOnlyHomogeneous (RenderDevice *rd, const Array< shared_ptr< Surface > > &surfaceArray, bool renderTransmissiveSurfaces) const |
| Use the current RenderDevice::cullFace. | |
| virtual void | renderHomogeneous (RenderDevice *rd, const Array< shared_ptr< Surface > > &surfaceArray, const Environment &environment) const =0 |
| Forward-render all illumination terms for each element of surfaceArray, which must all be of the same most-derived type as this. | |
| virtual void | renderIntoGBufferHomogeneous (RenderDevice *rd, Array< shared_ptr< Surface > > &surfaceArray, const shared_ptr< GBuffer > &gbuffer, const CFrame &previousCameraFrame) const |
| Render all instances of surfaceArray to the currently-bound Framebuffer using the fields and mapping dictated by specification. | |
| virtual void | renderWireframeHomogeneous (RenderDevice *rd, const Array< shared_ptr< Surface > > &surfaceArray, const Color4 &color, bool previous) const =0 |
| Rendering a set of surfaces in wireframe, using the current blending mode. | |
| virtual void | sendGeometry (RenderDevice *rd) const |
| Sends all geometry including texture coordinates (uploading it first if necessary) but does not set any render device state or use any textures. | |
Static Public Member Functions | |
| static void | cull (const CoordinateFrame &cameraFrame, const class Projection &cameraProjection, const class Rect2D &viewport, const Array< shared_ptr< Surface > > &allModels, Array< shared_ptr< Surface > > &outModels, bool previous=false) |
| Computes the array of models that can be seen by camera. | |
| static void | cull (const CoordinateFrame &cameraFrame, const class Projection &cameraProjection, const class Rect2D &viewport, Array< shared_ptr< Surface > > &allModels, bool previous=false) |
| Culls models in place. | |
| static void | extractTranslucent (Array< shared_ptr< Surface > > &all, Array< shared_ptr< Surface > > &translucent, bool treatPartialCoverageAsTranslucent) |
| Removes elements from all and puts them in translucent. | |
| static void | getBoxBounds (const Array< shared_ptr< Surface > > &surfaceArray, AABox &bounds, bool previous=false, bool &anyInfinite=ignoreBool, bool onlyShadowCasters=false) |
| Computes the world-space bounding box of an array of Surfaces of any type. | |
| static void | getSphereBounds (const Array< shared_ptr< Surface > > &surfaceArray, Sphere &bounds, bool previous=false, bool &anyInfinite=ignoreBool, bool onlyShadowCasters=false) |
| Computes the world-space bounding sphere of an array of Surfaces of any type. | |
| static void | getTris (const Array< shared_ptr< Surface > > &surfaceArray, CPUVertexArray &cpuVertexArray, Array< Tri > &triArray, bool computePrevPosition=false) |
| Returns a CPUVertexArray and an Array<Tri> generated from the surfaces in surfaceArray, with everything transformed to world space First separates surfaceArray by derived type and then calls getTrisHomogenous. | |
| static void | render (class RenderDevice *rd, const CoordinateFrame &cameraFrame, const class Projection &cameraProjection, const Array< shared_ptr< Surface > > &sortedVisibleModels, const Array< shared_ptr< Surface > > &allModels, const shared_ptr< Lighting > &lighting, const Environment &environment, AlphaMode alphaMode=ALPHA_BINARY, bool updateShadowMaps=true) |
| Renders an array of models with the full G3D illumination model (correct transparency, multiple direct lights, multiple shadow mapped lights), optimizing ArticulatedModels separately to minimize state changes. | |
| static void | renderDepthOnly (RenderDevice *rd, const Array< shared_ptr< Surface > > &surfaceArray, CullFace cull, bool renderTransmissiveSurfaces=true) |
| Render geometry only (no shading), and ignore color (but do perform alpha testing). | |
| static void | renderIntoGBuffer (RenderDevice *rd, Array< shared_ptr< Surface > > &sortedVisible, const GBuffer::Ref &gbuffer, const CoordinateFrame &previousCameraFrame=CoordinateFrame()) |
| Renders front-to-back to a GBuffer using current stencil and depth operations. | |
| static void | renderShadowMaps (RenderDevice *rd, Array< shared_ptr< class Light > > &lightArray, const Array< shared_ptr< Surface > > &allSurfaces) |
| Update the shadow maps in the enabled shadow casting lights from the array of surfaces. | |
| static void | renderTranslucent (RenderDevice *rd, const Array< shared_ptr< Surface > > &modelArray, const shared_ptr< Lighting > &lighting, const Environment &environment, RefractionQuality maxRefractionQuality=RefractionQuality::BEST, AlphaMode alphaMode=ALPHA_BINARY) |
| Render elements of modelArray, handling transmission reasonably. | |
| static void | renderWireframe (RenderDevice *rd, const Array< shared_ptr< Surface > > &surfaceArray, const Color4 &color=Color3::black(), bool previous=false) |
| Utility function for rendering a set of surfaces in wireframe using the current blending mode. | |
| static void | sendGeometry (RenderDevice *rd, const Array< shared_ptr< Surface > > &surface3D) |
| Sends the geometry for all of the specified surfaces, each with the corresponding coordinateFrame bound as the RenderDevice objectToWorld matrix. | |
| static void | sortBackToFront (Array< shared_ptr< Surface > > &surfaces, const Vector3 &wsLookVector) |
| static void | sortFrontToBack (Array< shared_ptr< Surface > > &surfaces, const Vector3 &wsLookVector) |
| Divides the inModels into a front-to-back sorted array of opaque models and a back-to-front sorted array of potentially transparent models. | |
Protected Member Functions | |
| Surface () | |
| virtual void | defaultRender (RenderDevice *rd) const |
| Implementation must obey the current stencil, depth write, color write, and depth test modes. | |
The surface of a model, posed and ready for rendering.
Most methods support efficient OpenGL rendering, but this class also supports extracting a mesh that approximates the surface for ray tracing or collision detection.
"Homogeneous" Methods: Many subclasses of Surface need to bind shader and other state in order to render. To amortize the cost of doing so, renderers use categorizeByDerivedType<shared_ptr<Surface> > to distinguish subclasses and then invoke the methods with names ending in "Homogeneous" on arrays of derived instances.
"previous" Arguments: To support motion blur and reverse reprojection, Surface represents the surface at two times: the "current" time, and some "previous" time that is usually the previous frame. The pose of the underlying model at these times is specified to the class that created the Surface. All rendering methods, including shading, operate on the current-time version. A GBuffer can represent a forward difference estimate of velocity in these with a GBuffer::Field::CS_POSITION_CHANGE field. Access methods on Surface take a boolean argument previous that specifies whether the "current" or "previous" description of the surface is desired.
Note that one could also render at multiple times by posing the original models at different times. However, models do not guarantee that they will produce the same number of Surfaces, or Surfaces with the same topology each time that they are posed. The use of timeOffset allows the caller to assume that the geometry deforms but has the same topology across an interval.
| typedef shared_ptr<class Surface> G3D::Surface::Ref |
How sortAndRender() configures the RenderDevice to process alpha.
|
inlineprotected |
|
inlinevirtual |
|
pure virtual |
Can this particular instance of this type of surface render into a GBuffer? Often set to false for surfaces with special back-to-front rendering needs.
Surfaces with transmission may be implemented to return true, rendering into a GBuffer and obscuring objects behind them–it is up to the caller's rendering algorithm to test for transmission if that is undesirable behavior. Such behavior would be desirable for example, if casting primary rays in a ray tracer using a GBuffer.
Implemented in G3D::UniversalSurface, G3D::PhysicsFrameSplineEditor::SplineSurface, G3D::HeightfieldModel::Tile, G3D::VisualizeLightSurface, G3D::SkyboxSurface, and G3D::VisualizeCameraSurface.
|
inlinevirtual |
True if this surface casts shadows.
The default implementation returns true.
Reimplemented in G3D::UniversalSurface, G3D::HeightfieldModel::Tile, G3D::SkyboxSurface, and G3D::VisualizeLightSurface.
|
static |
Computes the array of models that can be seen by camera.
Preserves order
|
static |
Culls models in place.
|
inlineprotectedvirtual |
Implementation must obey the current stencil, depth write, color write, and depth test modes.
Implementation may freely set the blending, and alpha test modes.
Default implementation renders the triangles returned by getIndices and getGeometry.
Reimplemented in G3D::UniversalSurface, and G3D::PhysicsFrameSplineEditor::SplineSurface.
|
inlinevirtual |
A hint to the renderer indicating that this surface should write to the depth buffer.
Typically overridden to return false for surfaces with very low partial coverage (alpha) or transmission values, or to resolve artifacts for specific scenes. The default value is ! hasTransmission().
Reimplemented in G3D::UniversalSurface, and G3D::VisualizeLightSurface.
|
static |
Removes elements from all and puts them in translucent.
translucent is cleared first.
Always treats hasTransmissive() objects as translucent.
If treatPartialCoverageAsTranslucent is true, also treats hasPartialCoverage as translucent.
Preserves order of elements.
|
static |
|
pure virtual |
|
pure virtual |
May be infinite.
Implemented in G3D::UniversalSurface, G3D::PhysicsFrameSplineEditor::SplineSurface, G3D::HeightfieldModel::Tile, G3D::SkyboxSurface, G3D::VisualizeLightSurface, and G3D::VisualizeCameraSurface.
|
pure virtual |
May be infinite.
Implemented in G3D::UniversalSurface, G3D::PhysicsFrameSplineEditor::SplineSurface, G3D::HeightfieldModel::Tile, G3D::SkyboxSurface, G3D::VisualizeLightSurface, and G3D::VisualizeCameraSurface.
|
inlinevirtual |
Clears the arrays and appends indexed triangle list information.
Many subclasses will ignore previous because they only use that for rigid-body transformations and can be represented by the current geometry and moving coordinate frame. However, it is possible to include skinning or keyframe information in a Surface and respond to timeOffset.
Not required to be implemented.
|
static |
|
static |
Returns a CPUVertexArray and an Array<Tri> generated from the surfaces in surfaceArray, with everything transformed to world space First separates surfaceArray by derived type and then calls getTrisHomogenous.
|
inlinevirtual |
Creates and appends Tris and CPUVertexArray::Vertices onto the parameter arrays using the cpuGeom's of the surfaces in surfaceArray.
Invoking this with elements of surfaceArray that are not of the same most-derived type as this will result in an error.
This function maintains a table of already used cpuGeoms, so that we don't need to duplicate things unneccessarily.
Reimplemented in G3D::UniversalSurface.
|
inlinevirtual |
If true, this object's material produces subpixel coverage (i.e.
alpha) and may require back-to-front rendering depending on Surface::AlphaMode.
The default implementation returns false.
Reimplemented in G3D::UniversalSurface, G3D::HeightfieldModel::Tile, and G3D::VisualizeLightSurface.
|
inlinevirtual |
If true, this object transmits light and depends on back-to-front rendering order and should be rendered in sorted order.
The default implementation returns false.
Reimplemented in G3D::UniversalSurface, G3D::HeightfieldModel::Tile, and G3D::VisualizeLightSurface.
Referenced by depthWriteHint().
|
pure virtual |
Name of the underlying model or part for debugging purposes.
Implemented in G3D::UniversalSurface, G3D::HeightfieldModel::Tile, G3D::PhysicsFrameSplineEditor::SplineSurface, G3D::SkyboxSurface, G3D::VisualizeLightSurface, and G3D::VisualizeCameraSurface.
|
virtual |
The default implementation calls renderHomogeneous.
Reimplemented in G3D::UniversalSurface, and G3D::PhysicsFrameSplineEditor::SplineSurface.
|
static |
Renders an array of models with the full G3D illumination model (correct transparency, multiple direct lights, multiple shadow mapped lights), optimizing ArticulatedModels separately to minimize state changes.
Calls renderTranslucent() for translucent surface rendering. If you need to perform other rendering before translucents, explicitly remove non-opaque objects from allModels yourself and then call renderTranslucent later. Note that you can use the shadow maps that were computed by sortAndRender.
| updateShadowMaps | If the scene and lighting have not changed since the previous call, you may set this to false to avoid re-rendering the static shadow map. |
| sortedVisibleModels | Objects that are visible (not culled by the camera), assumed to be sorted back-to-front |
| allModels | All objects, unsorted. Used for shadow casting |
|
static |
Render geometry only (no shading), and ignore color (but do perform alpha testing).
Render only back or front faces (two-sided surfaces render no matter what).
Does not sort or cull based on the view frustum of the camera like other batch rendering routines–sort before invoking if you want that.
Used for early-Z and shadow mapping.
|
virtual |
Use the current RenderDevice::cullFace.
Reimplemented in G3D::UniversalSurface, G3D::HeightfieldModel::Tile, G3D::SkyboxSurface, G3D::VisualizeLightSurface, and G3D::VisualizeCameraSurface.
|
pure virtual |
Forward-render all illumination terms for each element of surfaceArray, which must all be of the same most-derived type as this.
Rendering proceeds in the order of elements in the surfaceArray. The caller may sort the array first to create back-to-front or front-to-back ordering. To improve the rendering of
Implementations must obey the semantics of the current stencil, viewport, clipping, and depth tests.
Elements may have partial coverage but are assumed to not have transmission.
Invoking this with elements of surfaceArray that are not of the same most-derived type as this will result in an error.
| timeOffset | All lighting occurs at timeOffset = 0, but object positions should be moved to respect the timeOffset. |
| environment | World-space, screen-space, and light-space data needed for illumination. |
Implemented in G3D::UniversalSurface, G3D::HeightfieldModel::Tile, G3D::SkyboxSurface, G3D::PhysicsFrameSplineEditor::SplineSurface, G3D::VisualizeLightSurface, and G3D::VisualizeCameraSurface.
|
static |
Renders front-to-back to a GBuffer using current stencil and depth operations.
| sortedSurfaceArray | Surfaces that are visible to the camera (i.e., already culled) and sorted from back to front. |
| previousCameraFrame | Used for rendering GBuffer::CS_POSITION_CHANGE frames. |
|
inlinevirtual |
Render all instances of surfaceArray to the currently-bound Framebuffer using the fields and mapping dictated by specification.
This is also used for depth-only (e.g., z-prepass) rendering.
Invoking this with elements of surfaceArray that are not of the same most-derived type as this will result in an error.
| velocityStartOffset | Time at which the previous frame should be sampled when computing the GBuffer velocity buffer. Set to -1/framerate if performing reverse reprojection using velocity buffers. |
| previousCameraFrame | Used for rendering GBuffer::CS_POSITION_CHANGE frames. |
Reimplemented in G3D::HeightfieldModel::Tile.
|
static |
Update the shadow maps in the enabled shadow casting lights from the array of surfaces.
|
static |
Render elements of modelArray, handling transmission reasonably.
Special cased code for refracting UniversalSurface instances. Called from sortAndRender().
Assumes:
Works correctly, but is inefficient for non-translucent surfaces.
| alphaMode | Mode for resolving partial coverage (which is independent of transmission) |
|
static |
Utility function for rendering a set of surfaces in wireframe using the current blending mode.
| previous | If true, the caller should set the RenderDevice camera transformation to the previous one. |
|
pure virtual |
Rendering a set of surfaces in wireframe, using the current blending mode.
This is primarily used for debugging.
Invoking this with elements of surfaceArray that are not of the same most-derived type as this will result in an error.
| previous | If true, the caller should set the RenderDevice camera transformation to the previous one. This is provided for debugging previous frame data. |
Implemented in G3D::UniversalSurface, G3D::HeightfieldModel::Tile, G3D::SkyboxSurface, G3D::PhysicsFrameSplineEditor::SplineSurface, G3D::VisualizeLightSurface, and G3D::VisualizeCameraSurface.
|
inlinevirtual |
Sends all geometry including texture coordinates (uploading it first if necessary) but does not set any render device state or use any textures.
Reimplemented in G3D::UniversalSurface, G3D::PhysicsFrameSplineEditor::SplineSurface, and G3D::SkyboxSurface.
|
static |
Sends the geometry for all of the specified surfaces, each with the corresponding coordinateFrame bound as the RenderDevice objectToWorld matrix.
|
inlinestatic |
|
static |
Divides the inModels into a front-to-back sorted array of opaque models and a back-to-front sorted array of potentially transparent models.
Any data originally in the output arrays is cleared.
| wsLookVector | Sort axis; usually the -Z axis of the camera. |
Referenced by sortBackToFront().
1.8.2