sphereEnvironmentProbe.cpp
Engine/source/T3D/lighting/sphereEnvironmentProbe.cpp
Public Variables
bool
For frame signal.
Public Functions
ConsoleDocClass(SphereEnvironmentProbe , "@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>" )
Detailed Description
Public Variables
ColorI gCanvasClearColor
bool gEditingMission
For frame signal.
Public Functions
ConsoleDocClass(SphereEnvironmentProbe , "@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>" )
IMPLEMENT_CO_NETOBJECT_V1(SphereEnvironmentProbe )
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/sphereEnvironmentProbe.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; 61 62IMPLEMENT_CO_NETOBJECT_V1(SphereEnvironmentProbe); 63 64ConsoleDocClass(SphereEnvironmentProbe, 65 "@brief An example scene object which renders a mesh.\n\n" 66 "This class implements a basic SceneObject that can exist in the world at a " 67 "3D position and render itself. There are several valid ways to render an " 68 "object in Torque. This class implements the preferred rendering method which " 69 "is to submit a MeshRenderInst along with a Material, vertex buffer, " 70 "primitive buffer, and transform and allow the RenderMeshMgr handle the " 71 "actual setup and rendering for you.\n\n" 72 "See the C++ code for implementation details.\n\n" 73 "@ingroup Examples\n"); 74 75//----------------------------------------------------------------------------- 76// Object setup and teardown 77//----------------------------------------------------------------------------- 78SphereEnvironmentProbe::SphereEnvironmentProbe() : ReflectionProbe() 79{ 80 mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK; 81 mProbeShapeType = ProbeRenderInst::Sphere; 82} 83 84SphereEnvironmentProbe::~SphereEnvironmentProbe() 85{ 86} 87 88//----------------------------------------------------------------------------- 89// Object Editing 90//----------------------------------------------------------------------------- 91void SphereEnvironmentProbe::initPersistFields() 92{ 93 // SceneObject already handles exposing the transform 94 Parent::initPersistFields(); 95 96 removeField("scale"); 97} 98 99void SphereEnvironmentProbe::inspectPostApply() 100{ 101 Parent::inspectPostApply(); 102 103 mDirty = true; 104 105 // Flag the network mask to send the updates 106 // to the client object 107 setMaskBits(-1); 108} 109 110bool SphereEnvironmentProbe::onAdd() 111{ 112 if (!Parent::onAdd()) 113 return false; 114 115 return true; 116} 117 118void SphereEnvironmentProbe::onRemove() 119{ 120 Parent::onRemove(); 121} 122 123U32 SphereEnvironmentProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream) 124{ 125 // Allow the Parent to get a crack at writing its info 126 U32 retMask = Parent::packUpdate(conn, mask, stream); 127 128 return retMask; 129} 130 131void SphereEnvironmentProbe::unpackUpdate(NetConnection *conn, BitStream *stream) 132{ 133 // Let the Parent read any info it sent 134 Parent::unpackUpdate(conn, stream); 135 136 if (mDirty) 137 { 138 updateProbeParams(); 139 } 140} 141 142//----------------------------------------------------------------------------- 143// Object Rendering 144//----------------------------------------------------------------------------- 145 146void SphereEnvironmentProbe::updateProbeParams() 147{ 148 mProbeShapeType = ProbeRenderInst::Sphere; 149 Parent::updateProbeParams(); 150} 151 152void SphereEnvironmentProbe::prepRenderImage(SceneRenderState *state) 153{ 154 if (!mEnabled || !ReflectionProbe::smRenderPreviewProbes) 155 return; 156 157#ifdef TORQUE_TOOLS 158 if (ReflectionProbe::smRenderPreviewProbes && gEditingMission && mEditorShapeInst && mPrefilterMap != nullptr) 159 { 160 GFXTransformSaver saver; 161 162 // Calculate the distance of this object from the camera 163 Point3F cameraOffset; 164 getRenderTransform().getColumn(3, &cameraOffset); 165 cameraOffset -= state->getDiffuseCameraPosition(); 166 F32 dist = cameraOffset.len(); 167 if (dist < 0.01f) 168 dist = 0.01f; 169 170 // Set up the LOD for the shape 171 F32 invScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z)); 172 173 mEditorShapeInst->setDetailFromDistance(state, dist * invScale); 174 175 // Make sure we have a valid level of detail 176 if (mEditorShapeInst->getCurrentDetail() < 0) 177 return; 178 179 BaseMatInstance* probePrevMat = mEditorShapeInst->getMaterialList()->getMaterialInst(0); 180 181 setPreviewMatParameters(state, probePrevMat); 182 183 // GFXTransformSaver is a handy helper class that restores 184 // the current GFX matrices to their original values when 185 // it goes out of scope at the end of the function 186 187 // Set up our TS render state 188 TSRenderState rdata; 189 rdata.setSceneState(state); 190 rdata.setFadeOverride(1.0f); 191 192 // We might have some forward lit materials 193 // so pass down a query to gather lights. 194 LightQuery query; 195 query.init(getWorldSphere()); 196 rdata.setLightQuery(&query); 197 198 // Set the world matrix to the objects render transform 199 MatrixF mat = getRenderTransform(); 200 mat.scale(Point3F(1, 1, 1)); 201 GFX->setWorldMatrix(mat); 202 203 // Animate the the shape 204 mEditorShapeInst->animate(); 205 206 // Allow the shape to submit the RenderInst(s) for itself 207 mEditorShapeInst->render(rdata); 208 209 saver.restore(); 210 } 211 212 // If the light is selected or light visualization 213 // is enabled then register the callback. 214 const bool isSelectedInEditor = (gEditingMission && isSelected()); 215 if (isSelectedInEditor) 216 { 217 ObjectRenderInst *ri = state->getRenderPass()->allocInst<ObjectRenderInst>(); 218 ri->renderDelegate.bind(this, &ReflectionProbe::_onRenderViz); 219 ri->type = RenderPassManager::RIT_Editor; 220 state->getRenderPass()->addInst(ri); 221 } 222#endif 223} 224 225void SphereEnvironmentProbe::setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat) 226{ 227 Parent::setPreviewMatParameters(renderState, mat); 228} 229