skylight.cpp

Engine/source/T3D/lighting/skylight.cpp

More...

Public Variables

Public Functions

ConsoleDocClass(Skylight , "@brief An example scene object which renders <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">mesh.\n\n</a>" "This class implements <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> basic <a href="/coding/class/classsceneobject/">SceneObject</a> that can exist in the world at <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "3D position and <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> itself. There are several valid ways <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> an " "object in Torque. This class implements the preferred rendering method which " "is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> submit <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/structmeshrenderinst/">MeshRenderInst</a> along with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Material, vertex buffer, " "primitive buffer, and transform and allow the <a href="/coding/class/classrendermeshmgr/">RenderMeshMgr</a> handle the " "actual setup and rendering <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">you.\n\n</a>" "See the C++code <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> implementation <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">details.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Examples\n</a>" )
DefineEngineMethod(Skylight , postApply , void , () , "A utility method <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> forcing <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> network <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">update.\n</a>" )

Detailed Description

Public Variables

ColorI gCanvasClearColor 
bool gEditingMission 

For frame signal.

Public Functions

ConsoleDocClass(Skylight , "@brief An example scene object which renders <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">mesh.\n\n</a>" "This class implements <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> basic <a href="/coding/class/classsceneobject/">SceneObject</a> that can exist in the world at <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> " "3D position and <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> itself. There are several valid ways <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/editortool_8cpp/#editortool_8cpp_1a4cb041169a32ea3d4cacadbb955e06b4">render</a> an " "object in Torque. This class implements the preferred rendering method which " "is <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> submit <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/structmeshrenderinst/">MeshRenderInst</a> along with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Material, vertex buffer, " "primitive buffer, and transform and allow the <a href="/coding/class/classrendermeshmgr/">RenderMeshMgr</a> handle the " "actual setup and rendering <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">you.\n\n</a>" "See the C++code <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> implementation <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">details.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Examples\n</a>" )

DefineEngineMethod(Skylight , postApply , void , () , "A utility method <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> forcing <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> network <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">update.\n</a>" )

IMPLEMENT_CO_NETOBJECT_V1(Skylight )

  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#include "T3D/lighting/skylight.h"
 25#include "math/mathIO.h"
 26#include "scene/sceneRenderState.h"
 27#include "console/consoleTypes.h"
 28#include "core/stream/bitStream.h"
 29#include "materials/baseMatInstance.h"
 30#include "console/engineAPI.h"
 31#include "gfx/gfxDrawUtil.h"
 32#include "gfx/gfxDebugEvent.h"
 33#include "gfx/gfxTransformSaver.h"
 34#include "math/mathUtils.h"
 35#include "gfx/bitmap/gBitmap.h"
 36#include "core/stream/fileStream.h"
 37#include "core/fileObject.h"
 38#include "core/resourceManager.h"
 39#include "console/simPersistID.h"
 40#include "T3D/gameFunctions.h"
 41#include "postFx/postEffect.h"
 42#include "renderInstance/renderProbeMgr.h"
 43#include "renderInstance/renderProbeMgr.h"
 44
 45#include "math/util/sphereMesh.h"
 46#include "materials/materialManager.h"
 47#include "math/util/matrixSet.h"
 48#include "gfx/bitmap/cubemapSaver.h"
 49
 50#include "materials/materialFeatureTypes.h"
 51
 52#include "materials/shaderData.h"
 53#include "gfx/gfxTextureManager.h"
 54
 55#include "gfx/bitmap/imageUtils.h"
 56
 57#include "T3D/lighting/IBLUtilities.h"
 58
 59extern bool gEditingMission;
 60extern ColorI gCanvasClearColor;
 61bool Skylight::smRenderSkylights = true;
 62
 63IMPLEMENT_CO_NETOBJECT_V1(Skylight);
 64
 65ConsoleDocClass(Skylight,
 66   "@brief An example scene object which renders a mesh.\n\n"
 67   "This class implements a basic SceneObject that can exist in the world at a "
 68   "3D position and render itself. There are several valid ways to render an "
 69   "object in Torque. This class implements the preferred rendering method which "
 70   "is to submit a MeshRenderInst along with a Material, vertex buffer, "
 71   "primitive buffer, and transform and allow the RenderMeshMgr handle the "
 72   "actual setup and rendering for you.\n\n"
 73   "See the C++ code for implementation details.\n\n"
 74   "@ingroup Examples\n");
 75
 76//-----------------------------------------------------------------------------
 77// Object setup and teardown
 78//-----------------------------------------------------------------------------
 79Skylight::Skylight() : ReflectionProbe()
 80{
 81   mCaptureMask = SKYLIGHT_CAPTURE_TYPEMASK;
 82}
 83
 84Skylight::~Skylight()
 85{
 86}
 87
 88//-----------------------------------------------------------------------------
 89// Object Editing
 90//-----------------------------------------------------------------------------
 91void Skylight::initPersistFields()
 92{
 93   // SceneObject already handles exposing the transform
 94   Parent::initPersistFields();
 95
 96   removeField("radius");
 97   removeField("scale");
 98   removeField("EditPosOffset");
 99   removeField("refOffset");
100   removeField("refScale");
101}
102
103void Skylight::inspectPostApply()
104{
105   Parent::inspectPostApply();
106
107   mDirty = true;
108
109   // Flag the network mask to send the updates
110   // to the client object
111   setMaskBits(-1);
112}
113
114bool Skylight::onAdd()
115{
116   if (!Parent::onAdd())
117      return false;
118
119   return true;
120}
121
122void Skylight::onRemove()
123{
124   Parent::onRemove();
125}
126
127U32 Skylight::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
128{
129   // Allow the Parent to get a crack at writing its info
130   U32 retMask = Parent::packUpdate(conn, mask, stream);
131
132   return retMask;
133}
134
135void Skylight::unpackUpdate(NetConnection *conn, BitStream *stream)
136{
137   // Let the Parent read any info it sent
138   Parent::unpackUpdate(conn, stream);
139
140   if (mDirty)
141   {
142      updateProbeParams();
143   }
144}
145
146//-----------------------------------------------------------------------------
147// Object Rendering
148//-----------------------------------------------------------------------------
149
150void Skylight::updateProbeParams()
151{
152   mProbeShapeType = ProbeRenderInst::Skylight;
153   Parent::updateProbeParams();
154}
155
156void Skylight::prepRenderImage(SceneRenderState *state)
157{
158   if (!mEnabled || !Skylight::smRenderSkylights)
159      return;
160
161   //special hook-in for skylights
162   Point3F camPos = state->getCameraPosition();
163   mProbeInfo.mBounds.setCenter(camPos);
164
165   mProbeInfo.setPosition(camPos);
166
167   //Submit our probe to actually do the probe action
168   // Get a handy pointer to our RenderPassmanager
169   //RenderPassManager *renderPass = state->getRenderPass();
170
171   PROBEMGR->submitProbe(mProbeInfo);
172
173#ifdef TORQUE_TOOLS
174   if (Skylight::smRenderPreviewProbes && gEditingMission && mEditorShapeInst && mPrefilterMap != nullptr)
175   {
176      GFXTransformSaver saver;
177
178      // Calculate the distance of this object from the camera
179      Point3F cameraOffset;
180      getRenderTransform().getColumn(3, &cameraOffset);
181      cameraOffset -= state->getDiffuseCameraPosition();
182      F32 dist = cameraOffset.len();
183      if (dist < 0.01f)
184         dist = 0.01f;
185
186      // Set up the LOD for the shape
187      F32 invScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z));
188
189      mEditorShapeInst->setDetailFromDistance(state, dist * invScale);
190
191      // Make sure we have a valid level of detail
192      if (mEditorShapeInst->getCurrentDetail() < 0)
193         return;
194
195      BaseMatInstance* probePrevMat = mEditorShapeInst->getMaterialList()->getMaterialInst(0);
196
197      setPreviewMatParameters(state, probePrevMat);
198
199      // GFXTransformSaver is a handy helper class that restores
200      // the current GFX matrices to their original values when
201      // it goes out of scope at the end of the function
202
203      // Set up our TS render state      
204      TSRenderState rdata;
205      rdata.setSceneState(state);
206      rdata.setFadeOverride(1.0f);
207
208      // We might have some forward lit materials
209      // so pass down a query to gather lights.
210      LightQuery query;
211      query.init(getWorldSphere());
212      rdata.setLightQuery(&query);
213
214      // Set the world matrix to the objects render transform
215      MatrixF mat = getRenderTransform();
216      mat.scale(Point3F(1, 1, 1));
217      GFX->setWorldMatrix(mat);
218
219      // Animate the the shape
220      mEditorShapeInst->animate();
221
222      // Allow the shape to submit the RenderInst(s) for itself
223      mEditorShapeInst->render(rdata);
224
225      saver.restore();
226   }
227
228   // If the light is selected or light visualization
229   // is enabled then register the callback.
230   const bool isSelectedInEditor = (gEditingMission && isSelected());
231   if (isSelectedInEditor)
232   {
233   }
234#endif
235}
236
237void Skylight::setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat)
238{
239   Parent::setPreviewMatParameters(renderState, mat);
240}
241
242DefineEngineMethod(Skylight, postApply, void, (), ,
243   "A utility method for forcing a network update.\n")
244{
245   object->inspectPostApply();
246}
247