Torque3D Documentation / _generateds / reflectionProbe.h

reflectionProbe.h

Engine/source/T3D/lighting/reflectionProbe.h

More...

Classes:

Public Typedefs

Detailed Description

Public Typedefs

typedef ReflectionProbe::ReflectionModeType ReflectionModeEnum 
typedef ProbeRenderInst::ProbeShapeType ReflectProbeType 

Public Functions

DefineEnumType(ReflectionModeEnum )

DefineEnumType(ReflectProbeType )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef REFLECTIONPROBE_H
 25#define REFLECTIONPROBE_H
 26
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30#ifndef _GFXVERTEXBUFFER_H_
 31#include "gfx/gfxVertexBuffer.h"
 32#endif
 33#ifndef _GFXPRIMITIVEBUFFER_H_
 34#include "gfx/gfxPrimitiveBuffer.h"
 35#endif
 36#ifndef _TSSHAPEINSTANCE_H_
 37#include "ts/tsShapeInstance.h"
 38#endif
 39#include "lighting/lightInfo.h"
 40
 41#ifndef _RENDERPASSMANAGER_H_
 42#include "renderInstance/renderPassManager.h"
 43#endif
 44
 45#ifndef RENDER_PROBE_MGR_H
 46#include "renderInstance/renderProbeMgr.h"
 47#endif
 48
 49class BaseMatInstance;
 50
 51//-----------------------------------------------------------------------------
 52// This class implements a basic SceneObject that can exist in the world at a
 53// 3D position and render itself. There are several valid ways to render an
 54// object in Torque. This class implements the preferred rendering method which
 55// is to submit a MeshRenderInst along with a Material, vertex buffer,
 56// primitive buffer, and transform and allow the RenderMeshMgr handle the
 57// actual setup and rendering for you.
 58//-----------------------------------------------------------------------------
 59
 60class ReflectionProbe : public SceneObject
 61{
 62   typedef SceneObject Parent;
 63   friend class RenderProbeMgr;
 64
 65public:
 66
 67   /// <summary>
 68   /// Used to dictate what sort of cubemap the probes use when using IBL
 69   /// </summary>
 70   enum ReflectionModeType
 71   {
 72      NoReflection = 0,
 73      StaticCubemap = 1,
 74      BakedCubemap = 2,
 75      DynamicCubemap = 5,
 76   };
 77
 78protected:
 79
 80   // Networking masks
 81   // We need to implement a mask specifically to handle
 82   // updating our transform from the server object to its
 83   // client-side "ghost". We also need to implement a
 84   // maks for handling editor updates to our properties
 85   // (like material).
 86   enum MaskBits
 87   {
 88      TransformMask = Parent::NextFreeMask << 0,
 89      StaticDataMask = Parent::NextFreeMask << 1,
 90      EnabledMask = Parent::NextFreeMask << 2,
 91      NextFreeMask = Parent::NextFreeMask << 3
 92   };
 93
 94   /// <summary>
 95   /// Only used for interfacing with the editor's inspector bake button
 96   /// </summary>
 97   bool mBakeReflections;
 98
 99   /// <summary>
100   /// Whether this probe is enabled or not
101   /// </summary>
102   bool mEnabled;
103   
104   bool mDirty;
105
106   /// <summary>
107   /// Whether this probe's cubemap is dirty or not
108   /// </summary>
109   bool mCubemapDirty;
110
111#ifdef TORQUE_TOOLS
112   /// <summary>
113   /// Used only when the editor is loaded, this is the shape data used for the probe viewing(aka, a sphere)
114   /// </summary>
115   Resource<TSShape> mEditorShape;
116   /// <summary>
117   /// This is the shape instance of the editor shape data
118   /// </summary>
119   TSShapeInstance* mEditorShapeInst;
120#endif // TORQUE_TOOLS
121
122   //--------------------------------------------------------------------------
123   // Rendering variables
124   //--------------------------------------------------------------------------
125   /// <summary>
126   /// The shape of the probe
127   /// </summary>
128   ProbeRenderInst::ProbeShapeType mProbeShapeType;
129
130   /// <summary>
131   /// This is effectively a packed cache of the probe data actually utilized for rendering.
132   /// The RenderProbeManager uses this via the probe calling registerProbe on creation, and unregisterProbe on destruction
133   /// When the manager goes to render it has the compacted data to read over more efficiently for setting up what probes should
134   /// Actually render in that frame
135   /// </summary>
136   ProbeRenderInst mProbeInfo;
137
138   /// <summary>
139   /// Used to dictate what sort of cubemap the probes use when using IBL
140   /// </summary>
141   ReflectionModeType mReflectionModeType;
142
143   /// <summary>
144   /// The radius of the probe's influence. Only really relevent in Sphere probes
145   /// </summary>
146   F32 mRadius;
147   /// <summary>
148   /// The reference positional offset for the probe. This is used for adjusting the perceived center and area of influence.
149   /// Helpful in adjusting parallax issues
150   /// </summary>
151   Point3F mProbeRefOffset;
152   /// <summary>
153   /// The reference scale for the probe. This is used for adjusting the perceived center and area of influence.
154   /// Helpful in adjusting parallax issues
155   /// </summary>
156   Point3F mProbeRefScale;
157
158   /// <summary>
159   /// Only used for interfacing with the editor's inspector edit offset button
160   /// </summary>
161   bool mEditPosOffset;
162
163   /// <summary>
164   /// This is used when a static cubemap is used. The name of the cubemap is looked up and loaded for the IBL calculations
165   /// </summary>
166   String mCubemapName;
167   CubemapData *mStaticCubemap;
168   GFXCubemapHandle  mDynamicCubemap;
169
170   String cubeDescName;
171   U32 cubeDescId;
172   ReflectorDesc *reflectorDesc;
173
174   //Utilized in dynamic reflections
175   //CubeReflector mCubeReflector;
176
177   ///Prevents us from saving out the cubemaps(for now) but allows us the full HDR range on the in-memory cubemap captures
178   bool mUseHDRCaptures;
179
180   //irridiance resources
181   CubemapData *mIrridianceMap;
182
183   //prefilter resources
184   CubemapData *mPrefilterMap;
185   U32 mPrefilterMipLevels;
186   U32 mPrefilterSize;
187
188   /// <summary>
189   /// This is calculated based on the object's persistantID. Effectively a unique hash ID to set it apart from other probes
190   /// Used to ensure the cubemaps named when baking are unique
191   /// </summary>
192   String mProbeUniqueID;
193
194   //Debug rendering
195   static bool smRenderPreviewProbes;
196
197   U32 mDynamicLastBakeMS;
198   U32 mRefreshRateMS;
199
200   F32 mMaxDrawDistance;
201
202   bool mResourcesCreated;
203   U32 mCaptureMask;
204
205public:
206   ReflectionProbe();
207   virtual ~ReflectionProbe();
208
209   // Declare this object as a ConsoleObject so that we can
210   // instantiate it into the world and network it
211   DECLARE_CONOBJECT(ReflectionProbe);
212
213   //--------------------------------------------------------------------------
214   // Object Editing
215   // Since there is always a server and a client object in Torque and we
216   // actually edit the server object we need to implement some basic
217   // networking functions
218   //--------------------------------------------------------------------------
219   // Set up any fields that we want to be editable (like position)
220   static void initPersistFields();
221
222   // Allows the object to update its editable settings
223   // from the server object to the client
224   virtual void inspectPostApply();
225
226   static bool _setEnabled(void *object, const char *index, const char *data);
227   static bool _doBake(void *object, const char *index, const char *data);
228   static bool _toggleEditPosOffset(void *object, const char *index, const char *data);
229   static bool _setRadius(void *object, const char *index, const char *data);
230   static bool _setReflectionMode(void *object, const char *index, const char *data);
231
232   // Handle when we are added to the scene and removed from the scene
233   bool onAdd();
234   void onRemove();
235
236   /// <summary>
237   /// This is called when the object is deleted. It allows us to do special-case cleanup actions
238   /// In probes' case, it's used to delete baked cubemap files
239   /// </summary>
240   virtual void handleDeleteAction();
241
242   // Override this so that we can dirty the network flag when it is called
243   virtual void setTransform(const MatrixF &mat);
244   virtual const MatrixF& getTransform() const;
245   virtual void setScale(const VectorF &scale);
246   virtual const VectorF& getScale() const;
247
248   virtual bool writeField(StringTableEntry fieldname, const char *value);
249
250   // This function handles sending the relevant data from the server
251   // object to the client object
252   U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
253   // This function handles receiving relevant data from the server
254   // object and applying it to the client object
255   void unpackUpdate(NetConnection *conn, BitStream *stream);
256
257   //--------------------------------------------------------------------------
258   // Object Rendering
259   // Torque utilizes a "batch" rendering system. This means that it builds a
260   // list of objects that need to render (via RenderInst's) and then renders
261   // them all in one batch. This allows it to optimized on things like
262   // minimizing texture, state, and shader switching by grouping objects that
263   // use the same Materials.
264   //--------------------------------------------------------------------------
265
266   // Create the geometry for rendering
267   void createEditorResources();
268
269   /// <summary>
270   /// Updates the probe rendering data
271   /// </summary>
272   virtual void updateProbeParams();
273   
274   bool createClientResources();
275
276   /// <summary>
277   /// Updates the probe's cubemaps in the array when using dynamic reflections
278   /// </summary>
279   void processDynamicCubemap();
280   /// <summary>
281   /// Updates the probe's cubemaps in the array when using baked cubemaps
282   /// </summary>
283   void processBakedCubemap();
284   /// <summary>
285   /// Updates the probe's cubemaps in the array when using a static cubemaps
286   /// </summary>
287   void processStaticCubemap();
288
289   // This is the function that allows this object to submit itself for rendering
290   void prepRenderImage(SceneRenderState *state);
291
292   void _onRenderViz(ObjectRenderInst *ri,
293      SceneRenderState *state,
294      BaseMatInstance *overrideMat);
295
296   void setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat);
297
298   /// <summary>
299   /// This gets the filepath to the prefilter cubemap associated to this probe.
300   /// In the event the probe is set to use a static cubemap, it is the prefiltered version of the cubemap's file
301   /// </summary>
302   /// <returns>The filepath to the prefilter cubemap</returns>
303   String getPrefilterMapPath();
304   /// <summary>
305   /// This gets the filepath to the irradiance cubemap associated to this probe.
306   /// In the event the probe is set to use a static cubemap, it is the irradiance version of the cubemap's file
307   /// </summary>
308   /// <returns>The filepath to the irradiance cubemap</returns>
309   String getIrradianceMapPath();
310
311   /// <summary>
312   /// Invokes a cubemap bake action for this probe
313   /// </summary>
314   void bake();
315};
316
317typedef ProbeRenderInst::ProbeShapeType ReflectProbeType;
318DefineEnumType(ReflectProbeType);
319
320typedef ReflectionProbe::ReflectionModeType ReflectionModeEnum;
321DefineEnumType(ReflectionModeEnum);
322
323#endif // _ReflectionProbe_H_
324