├── README.md ├── Volumetric Explosion Sample.sln ├── Volumetric Explosion Sample.v11.suo └── Volumetric Explosion Sample ├── AntTweakBar ├── include │ └── AntTweakBar.h └── lib │ ├── AntTweakBar.dll │ ├── AntTweakBar.lib │ ├── AntTweakBar64.dll │ ├── AntTweakBar64.lib │ └── Readme.txt ├── Common.h ├── DirectXTK ├── DirectXTK.debug.lib ├── DirectXTK.lib └── Inc │ ├── Audio.h │ ├── CommonStates.h │ ├── DDSTextureLoader.h │ ├── DirectXHelpers.h │ ├── Effects.h │ ├── GamePad.h │ ├── GeometricPrimitive.h │ ├── Model.h │ ├── PrimitiveBatch.h │ ├── ScreenGrab.h │ ├── SimpleMath.h │ ├── SimpleMath.inl │ ├── SpriteBatch.h │ ├── SpriteFont.h │ ├── VertexTypes.h │ ├── WICTextureLoader.h │ └── XboxDDSTextureLoader.h ├── Main.cpp ├── RenderExplosion.hlsli ├── RenderExplosionDS.hlsl ├── RenderExplosionHS.hlsl ├── RenderExplosionPS.hlsl ├── RenderExplosionVS.hlsl ├── Resource.h ├── Volumetric Explosion Sample.vcxproj ├── Volumetric Explosion Sample.vcxproj.filters ├── Volumetric Explosion Sample.vcxproj.user ├── directx.ico ├── gradient.dds └── noise_32x32x32.dat /README.md: -------------------------------------------------------------------------------- 1 | volumetric-explosions 2 | ===================== 3 | 4 | This sample project was created using Visual Studio 2012 and was created 5 | to demonstrate the volumetric rendering technique proposed in the book 6 | GPU Pro 6. 7 | 8 | Requirements: 9 | Visual Studio 2012 10 | Windows 8 SDK/DirectX 11 11 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Volumetric Explosion Sample", "Volumetric Explosion Sample\Volumetric Explosion Sample.vcxproj", "{21E537E9-0EB9-4E5D-A7EF-F83E8DA8252E}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {21E537E9-0EB9-4E5D-A7EF-F83E8DA8252E}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {21E537E9-0EB9-4E5D-A7EF-F83E8DA8252E}.Debug|Win32.Build.0 = Debug|Win32 14 | {21E537E9-0EB9-4E5D-A7EF-F83E8DA8252E}.Release|Win32.ActiveCfg = Release|Win32 15 | {21E537E9-0EB9-4E5D-A7EF-F83E8DA8252E}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample.v11.suo -------------------------------------------------------------------------------- /Volumetric Explosion Sample/AntTweakBar/include/AntTweakBar.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // 3 | // @file AntTweakBar.h 4 | // 5 | // @brief AntTweakBar is a light and intuitive graphical user interface 6 | // that can be readily integrated into OpenGL and DirectX 7 | // applications in order to interactively tweak parameters. 8 | // 9 | // @author Philippe Decaudin 10 | // 11 | // @doc http://anttweakbar.sourceforge.net/doc 12 | // 13 | // @license This file is part of the AntTweakBar library. 14 | // AntTweakBar is a free software released under the zlib license. 15 | // For conditions of distribution and use, see License.txt 16 | // 17 | // ---------------------------------------------------------------------------- 18 | 19 | 20 | #if !defined TW_INCLUDED 21 | #define TW_INCLUDED 22 | 23 | #include 24 | 25 | #define TW_VERSION 116 // Version Mmm : M=Major mm=minor (e.g., 102 is version 1.02) 26 | 27 | 28 | #ifdef __cplusplus 29 | # if defined(_MSC_VER) 30 | # pragma warning(push) 31 | # pragma warning(disable: 4995 4530) 32 | # include 33 | # pragma warning(pop) 34 | # else 35 | # include 36 | # endif 37 | extern "C" { 38 | #endif // __cplusplus 39 | 40 | 41 | // ---------------------------------------------------------------------------- 42 | // OS specific definitions 43 | // ---------------------------------------------------------------------------- 44 | 45 | #if (defined(_WIN32) || defined(_WIN64)) && !defined(TW_STATIC) 46 | # define TW_CALL __stdcall 47 | # define TW_CDECL_CALL __cdecl 48 | # define TW_EXPORT_API __declspec(dllexport) 49 | # define TW_IMPORT_API __declspec(dllimport) 50 | #else 51 | # define TW_CALL 52 | # define TW_CDECL_CALL 53 | # define TW_EXPORT_API 54 | # define TW_IMPORT_API 55 | #endif 56 | 57 | #if defined TW_EXPORTS 58 | # define TW_API TW_EXPORT_API 59 | #elif defined TW_STATIC 60 | # define TW_API 61 | # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA) 62 | # ifdef _WIN64 63 | # pragma comment(lib, "AntTweakBarStatic64") 64 | # else 65 | # pragma comment(lib, "AntTweakBarStatic") 66 | # endif 67 | # endif 68 | #else 69 | # define TW_API TW_IMPORT_API 70 | # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA) 71 | # ifdef _WIN64 72 | # pragma comment(lib, "AntTweakBar64") 73 | # else 74 | # pragma comment(lib, "AntTweakBar") 75 | # endif 76 | # endif 77 | #endif 78 | 79 | 80 | // ---------------------------------------------------------------------------- 81 | // Bar functions and definitions 82 | // ---------------------------------------------------------------------------- 83 | 84 | typedef struct CTwBar TwBar; // structure CTwBar is not exposed. 85 | 86 | TW_API TwBar * TW_CALL TwNewBar(const char *barName); 87 | TW_API int TW_CALL TwDeleteBar(TwBar *bar); 88 | TW_API int TW_CALL TwDeleteAllBars(); 89 | TW_API int TW_CALL TwSetTopBar(const TwBar *bar); 90 | TW_API TwBar * TW_CALL TwGetTopBar(); 91 | TW_API int TW_CALL TwSetBottomBar(const TwBar *bar); 92 | TW_API TwBar * TW_CALL TwGetBottomBar(); 93 | TW_API const char * TW_CALL TwGetBarName(const TwBar *bar); 94 | TW_API int TW_CALL TwGetBarCount(); 95 | TW_API TwBar * TW_CALL TwGetBarByIndex(int barIndex); 96 | TW_API TwBar * TW_CALL TwGetBarByName(const char *barName); 97 | TW_API int TW_CALL TwRefreshBar(TwBar *bar); 98 | 99 | // ---------------------------------------------------------------------------- 100 | // Var functions and definitions 101 | // ---------------------------------------------------------------------------- 102 | 103 | typedef enum ETwType 104 | { 105 | TW_TYPE_UNDEF = 0, 106 | #ifdef __cplusplus 107 | TW_TYPE_BOOLCPP = 1, 108 | #endif // __cplusplus 109 | TW_TYPE_BOOL8 = 2, 110 | TW_TYPE_BOOL16, 111 | TW_TYPE_BOOL32, 112 | TW_TYPE_CHAR, 113 | TW_TYPE_INT8, 114 | TW_TYPE_UINT8, 115 | TW_TYPE_INT16, 116 | TW_TYPE_UINT16, 117 | TW_TYPE_INT32, 118 | TW_TYPE_UINT32, 119 | TW_TYPE_FLOAT, 120 | TW_TYPE_DOUBLE, 121 | TW_TYPE_COLOR32, // 32 bits color. Order is RGBA if API is OpenGL or Direct3D10, and inversed if API is Direct3D9 (can be modified by defining 'colorOrder=...', see doc) 122 | TW_TYPE_COLOR3F, // 3 floats color. Order is RGB. 123 | TW_TYPE_COLOR4F, // 4 floats color. Order is RGBA. 124 | TW_TYPE_CDSTRING, // Null-terminated C Dynamic String (pointer to an array of char dynamically allocated with malloc/realloc/strdup) 125 | #ifdef __cplusplus 126 | # if defined(_MSC_VER) && (_MSC_VER == 1600) 127 | TW_TYPE_STDSTRING = (0x2ffe0000+sizeof(std::string)), // VS2010 C++ STL string (std::string) 128 | # else 129 | TW_TYPE_STDSTRING = (0x2fff0000+sizeof(std::string)), // C++ STL string (std::string) 130 | # endif 131 | #endif // __cplusplus 132 | TW_TYPE_QUAT4F = TW_TYPE_CDSTRING+2, // 4 floats encoding a quaternion {qx,qy,qz,qs} 133 | TW_TYPE_QUAT4D, // 4 doubles encoding a quaternion {qx,qy,qz,qs} 134 | TW_TYPE_DIR3F, // direction vector represented by 3 floats 135 | TW_TYPE_DIR3D // direction vector represented by 3 doubles 136 | } TwType; 137 | #define TW_TYPE_CSSTRING(n) ((TwType)(0x30000000+((n)&0xfffffff))) // Null-terminated C Static String of size n (defined as char[n], with n<2^28) 138 | 139 | typedef void (TW_CALL * TwSetVarCallback)(const void *value, void *clientData); 140 | typedef void (TW_CALL * TwGetVarCallback)(void *value, void *clientData); 141 | typedef void (TW_CALL * TwButtonCallback)(void *clientData); 142 | 143 | TW_API int TW_CALL TwAddVarRW(TwBar *bar, const char *name, TwType type, void *var, const char *def); 144 | TW_API int TW_CALL TwAddVarRO(TwBar *bar, const char *name, TwType type, const void *var, const char *def); 145 | TW_API int TW_CALL TwAddVarCB(TwBar *bar, const char *name, TwType type, TwSetVarCallback setCallback, TwGetVarCallback getCallback, void *clientData, const char *def); 146 | TW_API int TW_CALL TwAddButton(TwBar *bar, const char *name, TwButtonCallback callback, void *clientData, const char *def); 147 | TW_API int TW_CALL TwAddSeparator(TwBar *bar, const char *name, const char *def); 148 | TW_API int TW_CALL TwRemoveVar(TwBar *bar, const char *name); 149 | TW_API int TW_CALL TwRemoveAllVars(TwBar *bar); 150 | 151 | typedef struct CTwEnumVal 152 | { 153 | int Value; 154 | const char * Label; 155 | } TwEnumVal; 156 | typedef struct CTwStructMember 157 | { 158 | const char * Name; 159 | TwType Type; 160 | size_t Offset; 161 | const char * DefString; 162 | } TwStructMember; 163 | typedef void (TW_CALL * TwSummaryCallback)(char *summaryString, size_t summaryMaxLength, const void *value, void *clientData); 164 | 165 | TW_API int TW_CALL TwDefine(const char *def); 166 | TW_API TwType TW_CALL TwDefineEnum(const char *name, const TwEnumVal *enumValues, unsigned int nbValues); 167 | TW_API TwType TW_CALL TwDefineEnumFromString(const char *name, const char *enumString); 168 | TW_API TwType TW_CALL TwDefineStruct(const char *name, const TwStructMember *structMembers, unsigned int nbMembers, size_t structSize, TwSummaryCallback summaryCallback, void *summaryClientData); 169 | 170 | typedef void (TW_CALL * TwCopyCDStringToClient)(char **destinationClientStringPtr, const char *sourceString); 171 | TW_API void TW_CALL TwCopyCDStringToClientFunc(TwCopyCDStringToClient copyCDStringFunc); 172 | TW_API void TW_CALL TwCopyCDStringToLibrary(char **destinationLibraryStringPtr, const char *sourceClientString); 173 | #ifdef __cplusplus 174 | typedef void (TW_CALL * TwCopyStdStringToClient)(std::string& destinationClientString, const std::string& sourceString); 175 | TW_API void TW_CALL TwCopyStdStringToClientFunc(TwCopyStdStringToClient copyStdStringToClientFunc); 176 | TW_API void TW_CALL TwCopyStdStringToLibrary(std::string& destinationLibraryString, const std::string& sourceClientString); 177 | #endif // __cplusplus 178 | 179 | typedef enum ETwParamValueType 180 | { 181 | TW_PARAM_INT32, 182 | TW_PARAM_FLOAT, 183 | TW_PARAM_DOUBLE, 184 | TW_PARAM_CSTRING // Null-terminated array of char (ie, c-string) 185 | } TwParamValueType; 186 | TW_API int TW_CALL TwGetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int outValueMaxCount, void *outValues); 187 | TW_API int TW_CALL TwSetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int inValueCount, const void *inValues); 188 | 189 | 190 | // ---------------------------------------------------------------------------- 191 | // Management functions and definitions 192 | // ---------------------------------------------------------------------------- 193 | 194 | typedef enum ETwGraphAPI 195 | { 196 | TW_OPENGL = 1, 197 | TW_DIRECT3D9 = 2, 198 | TW_DIRECT3D10 = 3, 199 | TW_DIRECT3D11 = 4, 200 | TW_OPENGL_CORE = 5 201 | } TwGraphAPI; 202 | 203 | TW_API int TW_CALL TwInit(TwGraphAPI graphAPI, void *device); 204 | TW_API int TW_CALL TwTerminate(); 205 | 206 | TW_API int TW_CALL TwDraw(); 207 | TW_API int TW_CALL TwWindowSize(int width, int height); 208 | 209 | TW_API int TW_CALL TwSetCurrentWindow(int windowID); // multi-windows support 210 | TW_API int TW_CALL TwGetCurrentWindow(); 211 | TW_API int TW_CALL TwWindowExists(int windowID); 212 | 213 | typedef enum ETwKeyModifier 214 | { 215 | TW_KMOD_NONE = 0x0000, // same codes as SDL keysym.mod 216 | TW_KMOD_SHIFT = 0x0003, 217 | TW_KMOD_CTRL = 0x00c0, 218 | TW_KMOD_ALT = 0x0100, 219 | TW_KMOD_META = 0x0c00 220 | } TwKeyModifier; 221 | typedef enum EKeySpecial 222 | { 223 | TW_KEY_BACKSPACE = '\b', 224 | TW_KEY_TAB = '\t', 225 | TW_KEY_CLEAR = 0x0c, 226 | TW_KEY_RETURN = '\r', 227 | TW_KEY_PAUSE = 0x13, 228 | TW_KEY_ESCAPE = 0x1b, 229 | TW_KEY_SPACE = ' ', 230 | TW_KEY_DELETE = 0x7f, 231 | TW_KEY_UP = 273, // same codes and order as SDL 1.2 keysym.sym 232 | TW_KEY_DOWN, 233 | TW_KEY_RIGHT, 234 | TW_KEY_LEFT, 235 | TW_KEY_INSERT, 236 | TW_KEY_HOME, 237 | TW_KEY_END, 238 | TW_KEY_PAGE_UP, 239 | TW_KEY_PAGE_DOWN, 240 | TW_KEY_F1, 241 | TW_KEY_F2, 242 | TW_KEY_F3, 243 | TW_KEY_F4, 244 | TW_KEY_F5, 245 | TW_KEY_F6, 246 | TW_KEY_F7, 247 | TW_KEY_F8, 248 | TW_KEY_F9, 249 | TW_KEY_F10, 250 | TW_KEY_F11, 251 | TW_KEY_F12, 252 | TW_KEY_F13, 253 | TW_KEY_F14, 254 | TW_KEY_F15, 255 | TW_KEY_LAST 256 | } TwKeySpecial; 257 | 258 | TW_API int TW_CALL TwKeyPressed(int key, int modifiers); 259 | TW_API int TW_CALL TwKeyTest(int key, int modifiers); 260 | 261 | typedef enum ETwMouseAction 262 | { 263 | TW_MOUSE_RELEASED, 264 | TW_MOUSE_PRESSED 265 | } TwMouseAction; 266 | typedef enum ETwMouseButtonID 267 | { 268 | TW_MOUSE_LEFT = 1, // same code as SDL_BUTTON_LEFT 269 | TW_MOUSE_MIDDLE = 2, // same code as SDL_BUTTON_MIDDLE 270 | TW_MOUSE_RIGHT = 3 // same code as SDL_BUTTON_RIGHT 271 | } TwMouseButtonID; 272 | 273 | TW_API int TW_CALL TwMouseButton(TwMouseAction action, TwMouseButtonID button); 274 | TW_API int TW_CALL TwMouseMotion(int mouseX, int mouseY); 275 | TW_API int TW_CALL TwMouseWheel(int pos); 276 | 277 | TW_API const char * TW_CALL TwGetLastError(); 278 | typedef void (TW_CALL * TwErrorHandler)(const char *errorMessage); 279 | TW_API void TW_CALL TwHandleErrors(TwErrorHandler errorHandler); 280 | 281 | 282 | // ---------------------------------------------------------------------------- 283 | // Helper functions to translate events from some common window management 284 | // frameworks to AntTweakBar. 285 | // They call TwKeyPressed, TwMouse* and TwWindowSize for you (implemented in 286 | // files TwEventWin.c TwEventSDL*.c TwEventGLFW.c TwEventGLUT.c) 287 | // ---------------------------------------------------------------------------- 288 | 289 | // For Windows message proc 290 | #ifndef _W64 // Microsoft specific (detection of 64 bits portability issues) 291 | # define _W64 292 | #endif // _W64 293 | #ifdef _WIN64 294 | TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned __int64 _W64 wParam, __int64 _W64 lParam); 295 | #else 296 | TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam); 297 | #endif 298 | #define TwEventWin32 TwEventWin // For compatibility with AntTweakBar versions prior to 1.11 299 | 300 | // For libSDL event loop 301 | TW_API int TW_CALL TwEventSDL(const void *sdlEvent, unsigned char sdlMajorVersion, unsigned char sdlMinorVersion); 302 | 303 | // For GLFW event callbacks 304 | // You should define GLFW_CDECL before including AntTweakBar.h if your version of GLFW uses cdecl calling convensions 305 | #ifdef GLFW_CDECL 306 | TW_API int TW_CDECL_CALL TwEventMouseButtonGLFWcdecl(int glfwButton, int glfwAction); 307 | TW_API int TW_CDECL_CALL TwEventKeyGLFWcdecl(int glfwKey, int glfwAction); 308 | TW_API int TW_CDECL_CALL TwEventCharGLFWcdecl(int glfwChar, int glfwAction); 309 | TW_API int TW_CDECL_CALL TwEventMousePosGLFWcdecl(int mouseX, int mouseY); 310 | TW_API int TW_CDECL_CALL TwEventMouseWheelGLFWcdecl(int wheelPos); 311 | # define TwEventMouseButtonGLFW TwEventMouseButtonGLFWcdecl 312 | # define TwEventKeyGLFW TwEventKeyGLFWcdecl 313 | # define TwEventCharGLFW TwEventCharGLFWcdecl 314 | # define TwEventMousePosGLFW TwEventMousePosGLFWcdecl 315 | # define TwEventMouseWheelGLFW TwEventMouseWheelGLFWcdecl 316 | #else 317 | TW_API int TW_CALL TwEventMouseButtonGLFW(int glfwButton, int glfwAction); 318 | TW_API int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction); 319 | TW_API int TW_CALL TwEventCharGLFW(int glfwChar, int glfwAction); 320 | # define TwEventMousePosGLFW TwMouseMotion 321 | # define TwEventMouseWheelGLFW TwMouseWheel 322 | #endif 323 | 324 | // For GLUT event callbacks (Windows calling convention for GLUT callbacks is cdecl) 325 | #if defined(_WIN32) || defined(_WIN64) 326 | # define TW_GLUT_CALL TW_CDECL_CALL 327 | #else 328 | # define TW_GLUT_CALL 329 | #endif 330 | TW_API int TW_GLUT_CALL TwEventMouseButtonGLUT(int glutButton, int glutState, int mouseX, int mouseY); 331 | TW_API int TW_GLUT_CALL TwEventMouseMotionGLUT(int mouseX, int mouseY); 332 | TW_API int TW_GLUT_CALL TwEventKeyboardGLUT(unsigned char glutKey, int mouseX, int mouseY); 333 | TW_API int TW_GLUT_CALL TwEventSpecialGLUT(int glutKey, int mouseX, int mouseY); 334 | TW_API int TW_CALL TwGLUTModifiersFunc(int (TW_CALL *glutGetModifiersFunc)(void)); 335 | typedef void (TW_GLUT_CALL *GLUTmousebuttonfun)(int glutButton, int glutState, int mouseX, int mouseY); 336 | typedef void (TW_GLUT_CALL *GLUTmousemotionfun)(int mouseX, int mouseY); 337 | typedef void (TW_GLUT_CALL *GLUTkeyboardfun)(unsigned char glutKey, int mouseX, int mouseY); 338 | typedef void (TW_GLUT_CALL *GLUTspecialfun)(int glutKey, int mouseX, int mouseY); 339 | 340 | // For SFML event loop 341 | TW_API int TW_CALL TwEventSFML(const void *sfmlEvent, unsigned char sfmlMajorVersion, unsigned char sfmlMinorVersion); 342 | 343 | // For X11 event loop 344 | #if defined(_UNIX) 345 | TW_API int TW_CDECL_CALL TwEventX11(void *xevent); 346 | #endif 347 | 348 | // ---------------------------------------------------------------------------- 349 | // Make sure the types have the right sizes 350 | // ---------------------------------------------------------------------------- 351 | 352 | #define TW_COMPILE_TIME_ASSERT(name, x) typedef int TW_DUMMY_ ## name[(x) * 2 - 1] 353 | 354 | TW_COMPILE_TIME_ASSERT(TW_CHAR, sizeof(char) == 1); 355 | TW_COMPILE_TIME_ASSERT(TW_SHORT, sizeof(short) == 2); 356 | TW_COMPILE_TIME_ASSERT(TW_INT, sizeof(int) == 4); 357 | TW_COMPILE_TIME_ASSERT(TW_FLOAT, sizeof(float) == 4); 358 | TW_COMPILE_TIME_ASSERT(TW_DOUBLE, sizeof(double) == 8); 359 | 360 | // Check pointer size on Windows 361 | #if !defined(_WIN64) && defined(_WIN32) 362 | // If the following assert failed, the platform is not 32-bit and _WIN64 is not defined. 363 | // When targetting 64-bit Windows platform, _WIN64 must be defined. 364 | TW_COMPILE_TIME_ASSERT(TW_PTR32, sizeof(void*) == 4); 365 | #elif defined(_WIN64) 366 | // If the following assert failed, _WIN64 is defined but the targeted platform is not 64-bit. 367 | TW_COMPILE_TIME_ASSERT(TW_PTR64, sizeof(void*) == 8); 368 | #endif 369 | 370 | // --------------------------------------------------------------------------- 371 | 372 | 373 | #ifdef __cplusplus 374 | } // extern "C" 375 | #endif // __cplusplus 376 | 377 | 378 | #endif // !defined TW_INCLUDED 379 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar.dll -------------------------------------------------------------------------------- /Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar.lib -------------------------------------------------------------------------------- /Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar64.dll -------------------------------------------------------------------------------- /Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/AntTweakBar/lib/AntTweakBar64.lib -------------------------------------------------------------------------------- /Volumetric Explosion Sample/AntTweakBar/lib/Readme.txt: -------------------------------------------------------------------------------- 1 | These files are part of the AntTweakBar library. 2 | http://anttweakbar.sourceforge.net/doc 3 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/Common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | // ======================================================================= 5 | // Global register indices 6 | // ======================================================================= 7 | #define S_BILINEAR_CLAMPED_SAMPLER 0 8 | #define S_BILINEAR_WRAPPED_SAMPLER 1 9 | 10 | #define B_EXPLOSION_PARAMS 0 11 | #define T_NOISE_VOLUME 0 12 | #define T_GRADIENT_TEX 1 13 | 14 | #define PI (3.14159265359f) 15 | 16 | #ifdef WIN32 17 | // ======================================================================= 18 | // C++ ONLY 19 | // ======================================================================= 20 | #define CONSTANT_BUFFER( name, reg ) __declspec(align(16)) struct name 21 | 22 | typedef DirectX::XMFLOAT4X4 float4x4; 23 | 24 | typedef DirectX::XMFLOAT4 float4; 25 | typedef DirectX::XMFLOAT3 float3; 26 | typedef DirectX::XMFLOAT2 float2; 27 | 28 | typedef DirectX::XMUINT4 uint4; 29 | typedef DirectX::XMUINT3 uint3; 30 | typedef DirectX::XMUINT2 uint2; 31 | typedef unsigned int uint; 32 | 33 | #endif 34 | 35 | 36 | 37 | #if HLSL 38 | // ======================================================================= 39 | // HLSL ONLY 40 | // ======================================================================= 41 | 42 | #define S_REG(oo) s##oo 43 | #define T_REG(oo) t##oo 44 | #define U_REG(oo) u##oo 45 | #define B_REG(oo) b##oo 46 | 47 | SamplerState BilinearClampedSampler : register( S_REG( S_BILINEAR_CLAMPED_SAMPLER ) ); 48 | SamplerState BilinearWrappedSampler : register( S_REG( S_BILINEAR_WRAPPED_SAMPLER ) ); 49 | 50 | #define CONSTANT_BUFFER( name, reg ) cbuffer name : register( b##reg ) 51 | 52 | #endif 53 | 54 | 55 | 56 | // ======================================================================= 57 | // Shared ( C++ & HLSL ) 58 | // ======================================================================= 59 | CONSTANT_BUFFER( ExplosionParams, B_EXPLOSION_PARAMS ) 60 | { 61 | float4x4 g_WorldToViewMatrix; 62 | float4x4 g_ViewToProjectionMatrix; 63 | float4x4 g_ProjectionToViewMatrix; 64 | float4x4 g_WorldToProjectionMatrix; 65 | float4x4 g_ProjectionToWorldMatrix; 66 | float4x4 g_ViewToWorldMatrix; 67 | 68 | float3 g_EyePositionWS; 69 | float g_NoiseAmplitudeFactor; 70 | 71 | float3 g_EyeForwardWS; 72 | float g_NoiseScale; 73 | 74 | float4 g_ProjectionParams; 75 | 76 | float4 g_ScreenParams; 77 | 78 | float3 g_ExplosionPositionWS; 79 | float g_ExplosionRadiusWS; 80 | 81 | float3 g_NoiseAnimationSpeed; 82 | float g_Time; 83 | 84 | float g_EdgeSoftness; 85 | float g_NoiseFrequencyFactor; 86 | uint g_PrimitiveIdx; 87 | float g_Opacity; 88 | 89 | float g_DisplacementWS; 90 | float g_StepSizeWS; 91 | uint g_MaxNumSteps; 92 | float g_NoiseInitialAmplitude; 93 | 94 | float2 g_UvScaleBias; 95 | float g_InvMaxNoiseDisplacement; 96 | uint g_NumOctaves; 97 | 98 | float g_SkinThickness; 99 | uint g_NumHullOctaves; 100 | uint g_NumHullSteps; 101 | float g_TessellationFactor; 102 | }; 103 | 104 | 105 | #endif // COMMON_H -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/DirectXTK.debug.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/DirectXTK/DirectXTK.debug.lib -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/DirectXTK.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/DirectXTK/DirectXTK.lib -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/Audio.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: Audio.h 3 | // 4 | // DirectXTK for Audio header 5 | // 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 7 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 8 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 9 | // PARTICULAR PURPOSE. 10 | // 11 | // Copyright (c) Microsoft Corporation. All rights reserved. 12 | // 13 | // http://go.microsoft.com/fwlink/?LinkId=248929 14 | //-------------------------------------------------------------------------------------- 15 | 16 | #pragma once 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #if defined(_XBOX_ONE) && defined(_TITLE) 23 | #include 24 | #pragma comment(lib,"acphal.lib") 25 | #endif 26 | 27 | #if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 28 | #pragma comment(lib,"PhoneAudioSes.lib") 29 | #endif 30 | 31 | #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) 32 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 33 | #error DirectX Tool Kit for Audio does not support VS 2010 without the DirectX SDK 34 | #endif 35 | #include 36 | #include 37 | #include 38 | #include 39 | #pragma comment(lib,"xaudio2.lib") 40 | #else 41 | // Using XAudio 2.7 requires the DirectX SDK 42 | #include 43 | #include 44 | #include 45 | #include 46 | #pragma warning(push) 47 | #pragma warning( disable : 4005 ) 48 | #include 49 | #pragma warning(pop) 50 | #pragma comment(lib,"x3daudio.lib") 51 | #pragma comment(lib,"xapofx.lib") 52 | #endif 53 | 54 | #include 55 | 56 | #pragma warning(push) 57 | #pragma warning(disable : 4005) 58 | #include 59 | #pragma warning(pop) 60 | 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | // VS 2010 doesn't support explicit calling convention for std::function 67 | #ifndef DIRECTX_STD_CALLCONV 68 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 69 | #define DIRECTX_STD_CALLCONV 70 | #else 71 | #define DIRECTX_STD_CALLCONV __cdecl 72 | #endif 73 | #endif 74 | 75 | #pragma warning(push) 76 | #pragma warning(disable : 4481) 77 | // VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012 78 | 79 | namespace DirectX 80 | { 81 | #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) 82 | #define XM_CALLCONV __fastcall 83 | typedef const XMVECTOR& HXMVECTOR; 84 | typedef const XMMATRIX& FXMMATRIX; 85 | #endif 86 | 87 | class SoundEffectInstance; 88 | 89 | //---------------------------------------------------------------------------------- 90 | struct AudioStatistics 91 | { 92 | size_t playingOneShots; // Number of one-shot sounds currently playing 93 | size_t playingInstances; // Number of sound effect instances currently playing 94 | size_t allocatedInstances; // Number of SoundEffectInstance allocated 95 | size_t allocatedVoices; // Number of XAudio2 voices allocated (standard, 3D, one-shots, and idle one-shots) 96 | size_t allocatedVoices3d; // Number of XAudio2 voices allocated for 3D 97 | size_t allocatedVoicesOneShot; // Number of XAudio2 voices allocated for one-shot sounds 98 | size_t allocatedVoicesIdle; // Number of XAudio2 voices allocated for one-shot sounds but not currently in use 99 | size_t audioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks 100 | #if defined(_XBOX_ONE) && defined(_TITLE) 101 | size_t xmaAudioBytes; // Total wave data (in bytes) in SoundEffects and in-memory WaveBanks allocated with ApuAlloc 102 | #endif 103 | }; 104 | 105 | 106 | //---------------------------------------------------------------------------------- 107 | class IVoiceNotify 108 | { 109 | public: 110 | virtual void __cdecl OnBufferEnd() = 0; 111 | // Notfication that a voice buffer has finished 112 | // Note this is called from XAudio2's worker thread, so it should perform very minimal and thread-safe operations 113 | 114 | virtual void __cdecl OnCriticalError() = 0; 115 | // Notification that the audio engine encountered a critical error 116 | 117 | virtual void __cdecl OnReset() = 0; 118 | // Notification of an audio engine reset 119 | 120 | virtual void __cdecl OnUpdate() = 0; 121 | // Notification of an audio engine per-frame update (opt-in) 122 | 123 | virtual void __cdecl OnDestroyEngine() = 0; 124 | // Notification that the audio engine is being destroyed 125 | 126 | virtual void __cdecl OnTrim() = 0; 127 | // Notification of a request to trim the voice pool 128 | 129 | virtual void __cdecl GatherStatistics( AudioStatistics& stats ) const = 0; 130 | // Contribute to statistics request 131 | }; 132 | 133 | //---------------------------------------------------------------------------------- 134 | enum AUDIO_ENGINE_FLAGS 135 | { 136 | AudioEngine_Default = 0x0, 137 | 138 | AudioEngine_EnvironmentalReverb = 0x1, 139 | AudioEngine_ReverbUseFilters = 0x2, 140 | AudioEngine_UseMasteringLimiter = 0x4, 141 | 142 | AudioEngine_Debug = 0x10000, 143 | AudioEngine_ThrowOnNoAudioHW = 0x20000, 144 | AudioEngine_DisableVoiceReuse = 0x40000, 145 | }; 146 | 147 | inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b) { return static_cast( static_cast(a) | static_cast(b) ); } 148 | 149 | enum SOUND_EFFECT_INSTANCE_FLAGS 150 | { 151 | SoundEffectInstance_Default = 0x0, 152 | 153 | SoundEffectInstance_Use3D = 0x1, 154 | SoundEffectInstance_ReverbUseFilters = 0x2, 155 | SoundEffectInstance_NoSetPitch = 0x4, 156 | 157 | SoundEffectInstance_UseRedirectLFE = 0x10000, 158 | }; 159 | 160 | inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b) { return static_cast( static_cast(a) | static_cast(b) ); } 161 | 162 | enum AUDIO_ENGINE_REVERB 163 | { 164 | Reverb_Off, 165 | Reverb_Default, 166 | Reverb_Generic, 167 | Reverb_Forest, 168 | Reverb_PaddedCell, 169 | Reverb_Room, 170 | Reverb_Bathroom, 171 | Reverb_LivingRoom, 172 | Reverb_StoneRoom, 173 | Reverb_Auditorium, 174 | Reverb_ConcertHall, 175 | Reverb_Cave, 176 | Reverb_Arena, 177 | Reverb_Hangar, 178 | Reverb_CarpetedHallway, 179 | Reverb_Hallway, 180 | Reverb_StoneCorridor, 181 | Reverb_Alley, 182 | Reverb_City, 183 | Reverb_Mountains, 184 | Reverb_Quarry, 185 | Reverb_Plain, 186 | Reverb_ParkingLot, 187 | Reverb_SewerPipe, 188 | Reverb_Underwater, 189 | Reverb_SmallRoom, 190 | Reverb_MediumRoom, 191 | Reverb_LargeRoom, 192 | Reverb_MediumHall, 193 | Reverb_LargeHall, 194 | Reverb_Plate, 195 | Reverb_MAX 196 | }; 197 | 198 | enum SoundState 199 | { 200 | STOPPED = 0, 201 | PLAYING, 202 | PAUSED 203 | }; 204 | 205 | 206 | //---------------------------------------------------------------------------------- 207 | class AudioEngine 208 | { 209 | public: 210 | explicit AudioEngine( AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr, 211 | AUDIO_STREAM_CATEGORY category = AudioCategory_GameEffects ); 212 | 213 | AudioEngine(AudioEngine&& moveFrom); 214 | AudioEngine& operator= (AudioEngine&& moveFrom); 215 | virtual ~AudioEngine(); 216 | 217 | bool __cdecl Update(); 218 | // Performs per-frame processing for the audio engine, returns false if in 'silent mode' 219 | 220 | bool __cdecl Reset( _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr ); 221 | // Reset audio engine from critical error/silent mode using a new device; can also 'migrate' the graph 222 | // Returns true if succesfully reset, false if in 'silent mode' due to no default device 223 | // Note: One shots are lost, all SoundEffectInstances are in the STOPPED state after successful reset 224 | 225 | void __cdecl Suspend(); 226 | void __cdecl Resume(); 227 | // Suspend/resumes audio processing (i.e. global pause/resume) 228 | 229 | void __cdecl SetReverb( AUDIO_ENGINE_REVERB reverb ); 230 | void __cdecl SetReverb( _In_opt_ const XAUDIO2FX_REVERB_PARAMETERS* native ); 231 | // Sets environmental reverb for 3D positional audio (if active) 232 | 233 | void __cdecl SetMasteringLimit( int release, int loudness ); 234 | // Sets the mastering volume limiter properties (if active) 235 | 236 | AudioStatistics __cdecl GetStatistics() const; 237 | // Gathers audio engine statistics 238 | 239 | WAVEFORMATEXTENSIBLE __cdecl GetOutputFormat() const; 240 | // Returns the format consumed by the mastering voice (which is the same as the device output if defaults are used) 241 | 242 | uint32_t __cdecl GetChannelMask() const; 243 | // Returns the output channel mask 244 | 245 | int __cdecl GetOutputChannels() const; 246 | // Returns the number of output channels 247 | 248 | bool __cdecl IsAudioDevicePresent() const; 249 | // Returns true if the audio graph is operating normally, false if in 'silent mode' 250 | 251 | bool __cdecl IsCriticalError() const; 252 | // Returns true if the audio graph is halted due to a critical error (which also places the engine into 'silent mode') 253 | 254 | // Voice pool management. 255 | void __cdecl SetDefaultSampleRate( int sampleRate ); 256 | // Sample rate for voices in the reuse pool (defaults to 44100) 257 | 258 | void __cdecl SetMaxVoicePool( size_t maxOneShots, size_t maxInstances ); 259 | // Maximum number of voices to allocate for one-shots and instances 260 | // Note: one-shots over this limit are ignored; too many instance voices throws an exception 261 | 262 | void __cdecl TrimVoicePool(); 263 | // Releases any currently unused voices 264 | 265 | void __cdecl AllocateVoice( _In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, _Outptr_result_maybenull_ IXAudio2SourceVoice** voice ); 266 | 267 | void __cdecl DestroyVoice( _In_ IXAudio2SourceVoice* voice ); 268 | // Should only be called for instance voices, not one-shots 269 | 270 | void __cdecl RegisterNotify( _In_ IVoiceNotify* notify, bool usesUpdate ); 271 | void __cdecl UnregisterNotify( _In_ IVoiceNotify* notify, bool usesOneShots, bool usesUpdate ); 272 | 273 | // XAudio2 interface access 274 | IXAudio2* __cdecl GetInterface() const; 275 | IXAudio2MasteringVoice* __cdecl GetMasterVoice() const; 276 | IXAudio2SubmixVoice* __cdecl GetReverbVoice() const; 277 | X3DAUDIO_HANDLE& __cdecl Get3DHandle() const; 278 | 279 | struct RendererDetail 280 | { 281 | std::wstring deviceId; 282 | std::wstring description; 283 | }; 284 | 285 | static std::vector __cdecl GetRendererDetails(); 286 | // Returns a list of valid audio endpoint devices 287 | 288 | private: 289 | // Private implementation. 290 | class Impl; 291 | std::unique_ptr pImpl; 292 | 293 | // Prevent copying. 294 | AudioEngine(AudioEngine const&); 295 | AudioEngine& operator= (AudioEngine const&); 296 | }; 297 | 298 | 299 | //---------------------------------------------------------------------------------- 300 | class WaveBank 301 | { 302 | public: 303 | WaveBank( _In_ AudioEngine* engine, _In_z_ const wchar_t* wbFileName ); 304 | 305 | WaveBank(WaveBank&& moveFrom); 306 | WaveBank& operator= (WaveBank&& moveFrom); 307 | virtual ~WaveBank(); 308 | 309 | void __cdecl Play( int index ); 310 | void __cdecl Play( _In_z_ const char* name ); 311 | 312 | std::unique_ptr __cdecl CreateInstance( int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); 313 | std::unique_ptr __cdecl CreateInstance( _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); 314 | 315 | bool __cdecl IsPrepared() const; 316 | bool __cdecl IsInUse() const; 317 | bool __cdecl IsStreamingBank() const; 318 | 319 | size_t __cdecl GetSampleSizeInBytes( int index ) const; 320 | // Returns size of wave audio data 321 | 322 | size_t __cdecl GetSampleDuration( int index ) const; 323 | // Returns the duration in samples 324 | 325 | size_t __cdecl GetSampleDurationMS( int index ) const; 326 | // Returns the duration in milliseconds 327 | 328 | const WAVEFORMATEX* __cdecl GetFormat( int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, size_t maxsize ) const; 329 | 330 | int __cdecl Find( _In_z_ const char* name ) const; 331 | 332 | #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) 333 | bool __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const; 334 | #else 335 | void __cdecl FillSubmitBuffer( int index, _Out_ XAUDIO2_BUFFER& buffer ) const; 336 | #endif 337 | 338 | private: 339 | // Private implementation. 340 | class Impl; 341 | 342 | std::unique_ptr pImpl; 343 | 344 | // Prevent copying. 345 | WaveBank(WaveBank const&); 346 | WaveBank& operator= (WaveBank const&); 347 | 348 | // Private interface 349 | void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance ); 350 | 351 | friend class SoundEffectInstance; 352 | }; 353 | 354 | 355 | //---------------------------------------------------------------------------------- 356 | class SoundEffect 357 | { 358 | public: 359 | SoundEffect( _In_ AudioEngine* engine, _In_z_ const wchar_t* waveFileName ); 360 | 361 | SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, 362 | _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes ); 363 | 364 | SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, 365 | _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes, 366 | uint32_t loopStart, uint32_t loopLength ); 367 | 368 | #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) 369 | 370 | SoundEffect( _In_ AudioEngine* engine, _Inout_ std::unique_ptr& wavData, 371 | _In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes, 372 | _In_reads_(seekCount) const uint32_t* seekTable, size_t seekCount ); 373 | 374 | #endif 375 | 376 | SoundEffect(SoundEffect&& moveFrom); 377 | SoundEffect& operator= (SoundEffect&& moveFrom); 378 | virtual ~SoundEffect(); 379 | 380 | void __cdecl Play(); 381 | 382 | std::unique_ptr __cdecl CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); 383 | 384 | bool __cdecl IsInUse() const; 385 | 386 | size_t __cdecl GetSampleSizeInBytes() const; 387 | // Returns size of wave audio data 388 | 389 | size_t __cdecl GetSampleDuration() const; 390 | // Returns the duration in samples 391 | 392 | size_t __cdecl GetSampleDurationMS() const; 393 | // Returns the duration in milliseconds 394 | 395 | const WAVEFORMATEX* __cdecl GetFormat() const; 396 | 397 | #if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) 398 | bool __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer, _Out_ XAUDIO2_BUFFER_WMA& wmaBuffer ) const; 399 | #else 400 | void __cdecl FillSubmitBuffer( _Out_ XAUDIO2_BUFFER& buffer ) const; 401 | #endif 402 | 403 | private: 404 | // Private implementation. 405 | class Impl; 406 | 407 | std::unique_ptr pImpl; 408 | 409 | // Prevent copying. 410 | SoundEffect(SoundEffect const&); 411 | SoundEffect& operator= (SoundEffect const&); 412 | 413 | // Private interface 414 | void __cdecl UnregisterInstance( _In_ SoundEffectInstance* instance ); 415 | 416 | friend class SoundEffectInstance; 417 | }; 418 | 419 | 420 | //---------------------------------------------------------------------------------- 421 | struct AudioListener : public X3DAUDIO_LISTENER 422 | { 423 | AudioListener() 424 | { 425 | memset( this, 0, sizeof(X3DAUDIO_LISTENER) ); 426 | 427 | OrientFront.z = 428 | OrientTop.y = 1.f; 429 | } 430 | 431 | void XM_CALLCONV SetPosition( FXMVECTOR v ) 432 | { 433 | XMStoreFloat3( reinterpret_cast( &Position ), v ); 434 | } 435 | void __cdecl SetPosition( const XMFLOAT3& pos ) 436 | { 437 | Position.x = pos.x; 438 | Position.y = pos.y; 439 | Position.z = pos.z; 440 | } 441 | 442 | void XM_CALLCONV SetVelocity( FXMVECTOR v ) 443 | { 444 | XMStoreFloat3( reinterpret_cast( &Velocity ), v ); 445 | } 446 | void __cdecl SetVelocity( const XMFLOAT3& vel ) 447 | { 448 | Velocity.x = vel.x; 449 | Velocity.y = vel.y; 450 | Velocity.z = vel.z; 451 | } 452 | 453 | void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up ) 454 | { 455 | XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); 456 | XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); 457 | } 458 | void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up ) 459 | { 460 | OrientFront.x = forward.x; OrientTop.x = up.x; 461 | OrientFront.y = forward.y; OrientTop.y = up.y; 462 | OrientFront.z = forward.z; OrientTop.z = up.z; 463 | } 464 | 465 | void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat ) 466 | { 467 | XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat ); 468 | XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); 469 | 470 | XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat ); 471 | XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); 472 | } 473 | 474 | void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt ) 475 | // Updates velocity and orientation by tracking changes in position over time... 476 | { 477 | if ( dt > 0.f ) 478 | { 479 | XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast( &Position ) ); 480 | 481 | XMVECTOR vDelta = ( newPos - lastPos ); 482 | XMVECTOR v = vDelta / dt; 483 | XMStoreFloat3( reinterpret_cast( &Velocity ), v ); 484 | 485 | vDelta = XMVector3Normalize( vDelta ); 486 | XMStoreFloat3( reinterpret_cast( &OrientFront ), vDelta ); 487 | 488 | v = XMVector3Cross( upDir, vDelta ); 489 | v = XMVector3Normalize( v ); 490 | 491 | v = XMVector3Cross( vDelta, v ); 492 | v = XMVector3Normalize( v ); 493 | XMStoreFloat3( reinterpret_cast( &OrientTop ), v ); 494 | 495 | XMStoreFloat3( reinterpret_cast( &Position ), newPos ); 496 | } 497 | } 498 | }; 499 | 500 | 501 | //---------------------------------------------------------------------------------- 502 | struct AudioEmitter : public X3DAUDIO_EMITTER 503 | { 504 | float EmitterAzimuths[XAUDIO2_MAX_AUDIO_CHANNELS]; 505 | 506 | AudioEmitter() 507 | { 508 | memset( this, 0, sizeof(X3DAUDIO_EMITTER) ); 509 | memset( EmitterAzimuths, 0, sizeof(EmitterAzimuths) ); 510 | 511 | OrientFront.z = 512 | OrientTop.y = 513 | ChannelRadius = 514 | CurveDistanceScaler = 515 | DopplerScaler = 1.f; 516 | 517 | ChannelCount = 1; 518 | pChannelAzimuths = EmitterAzimuths; 519 | 520 | InnerRadiusAngle = X3DAUDIO_PI / 4.0f; 521 | } 522 | 523 | void XM_CALLCONV SetPosition( FXMVECTOR v ) 524 | { 525 | XMStoreFloat3( reinterpret_cast( &Position ), v ); 526 | } 527 | void __cdecl SetPosition( const XMFLOAT3& pos ) 528 | { 529 | Position.x = pos.x; 530 | Position.y = pos.y; 531 | Position.z = pos.z; 532 | } 533 | 534 | void XM_CALLCONV SetVelocity( FXMVECTOR v ) 535 | { 536 | XMStoreFloat3( reinterpret_cast( &Velocity ), v ); 537 | } 538 | void __cdecl SetVelocity( const XMFLOAT3& vel ) 539 | { 540 | Velocity.x = vel.x; 541 | Velocity.y = vel.y; 542 | Velocity.z = vel.z; 543 | } 544 | 545 | void XM_CALLCONV SetOrientation( FXMVECTOR forward, FXMVECTOR up ) 546 | { 547 | XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); 548 | XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); 549 | } 550 | void __cdecl SetOrientation( const XMFLOAT3& forward, const XMFLOAT3& up ) 551 | { 552 | OrientFront.x = forward.x; OrientTop.x = up.x; 553 | OrientFront.y = forward.y; OrientTop.y = up.y; 554 | OrientFront.z = forward.z; OrientTop.z = up.z; 555 | } 556 | 557 | void XM_CALLCONV SetOrientationFromQuaternion( FXMVECTOR quat ) 558 | { 559 | XMVECTOR forward = XMVector3Rotate( g_XMIdentityR2, quat ); 560 | XMStoreFloat3( reinterpret_cast( &OrientFront ), forward ); 561 | 562 | XMVECTOR up = XMVector3Rotate( g_XMIdentityR1, quat ); 563 | XMStoreFloat3( reinterpret_cast( &OrientTop ), up ); 564 | } 565 | 566 | void XM_CALLCONV Update( FXMVECTOR newPos, XMVECTOR upDir, float dt ) 567 | // Updates velocity and orientation by tracking changes in position over time... 568 | { 569 | if ( dt > 0.f ) 570 | { 571 | XMVECTOR lastPos = XMLoadFloat3( reinterpret_cast( &Position ) ); 572 | 573 | XMVECTOR vDelta = ( newPos - lastPos ); 574 | XMVECTOR v = vDelta / dt; 575 | XMStoreFloat3( reinterpret_cast( &Velocity ), v ); 576 | 577 | vDelta = XMVector3Normalize( vDelta ); 578 | XMStoreFloat3( reinterpret_cast( &OrientFront ), vDelta ); 579 | 580 | v = XMVector3Cross( upDir, vDelta ); 581 | v = XMVector3Normalize( v ); 582 | 583 | v = XMVector3Cross( vDelta, v ); 584 | v = XMVector3Normalize( v ); 585 | XMStoreFloat3( reinterpret_cast( &OrientTop ), v ); 586 | 587 | XMStoreFloat3( reinterpret_cast( &Position ), newPos ); 588 | } 589 | } 590 | }; 591 | 592 | 593 | //---------------------------------------------------------------------------------- 594 | class SoundEffectInstance 595 | { 596 | public: 597 | SoundEffectInstance(SoundEffectInstance&& moveFrom); 598 | SoundEffectInstance& operator= (SoundEffectInstance&& moveFrom); 599 | virtual ~SoundEffectInstance(); 600 | 601 | void __cdecl Play( bool loop = false ); 602 | void __cdecl Stop( bool immediate = true ); 603 | void __cdecl Pause(); 604 | void __cdecl Resume(); 605 | 606 | void __cdecl SetVolume( float volume ); 607 | void __cdecl SetPitch( float pitch ); 608 | void __cdecl SetPan( float pan ); 609 | 610 | void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter ); 611 | 612 | bool __cdecl IsLooped() const; 613 | 614 | SoundState __cdecl GetState(); 615 | 616 | // Notifications. 617 | void __cdecl OnDestroyParent(); 618 | 619 | private: 620 | // Private implementation. 621 | class Impl; 622 | 623 | std::unique_ptr pImpl; 624 | 625 | // Private constructors 626 | SoundEffectInstance( _In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags ); 627 | SoundEffectInstance( _In_ AudioEngine* engine, _In_ WaveBank* effect, int index, SOUND_EFFECT_INSTANCE_FLAGS flags ); 628 | 629 | friend std::unique_ptr __cdecl SoundEffect::CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS ); 630 | friend std::unique_ptr __cdecl WaveBank::CreateInstance( int, SOUND_EFFECT_INSTANCE_FLAGS ); 631 | 632 | // Prevent copying. 633 | SoundEffectInstance(SoundEffectInstance const&); 634 | SoundEffectInstance& operator= (SoundEffectInstance const&); 635 | }; 636 | 637 | 638 | //---------------------------------------------------------------------------------- 639 | class DynamicSoundEffectInstance 640 | { 641 | public: 642 | DynamicSoundEffectInstance( _In_ AudioEngine* engine, 643 | _In_opt_ std::function bufferNeeded, 644 | int sampleRate, int channels, int sampleBits = 16, 645 | SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default ); 646 | DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom); 647 | DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance&& moveFrom); 648 | virtual ~DynamicSoundEffectInstance(); 649 | 650 | void __cdecl Play(); 651 | void __cdecl Stop( bool immediate = true ); 652 | void __cdecl Pause(); 653 | void __cdecl Resume(); 654 | 655 | void __cdecl SetVolume( float volume ); 656 | void __cdecl SetPitch( float pitch ); 657 | void __cdecl SetPan( float pan ); 658 | 659 | void __cdecl Apply3D( const AudioListener& listener, const AudioEmitter& emitter ); 660 | 661 | void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes ); 662 | void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes ); 663 | 664 | SoundState __cdecl GetState(); 665 | 666 | size_t __cdecl GetSampleDuration( size_t bytes ) const; 667 | // Returns duration in samples of a buffer of a given size 668 | 669 | size_t __cdecl GetSampleDurationMS( size_t bytes ) const; 670 | // Returns duration in milliseconds of a buffer of a given size 671 | 672 | size_t __cdecl GetSampleSizeInBytes( uint64_t duration ) const; 673 | // Returns size of a buffer for a duration given in milliseconds 674 | 675 | int __cdecl GetPendingBufferCount() const; 676 | 677 | const WAVEFORMATEX* __cdecl GetFormat() const; 678 | 679 | private: 680 | // Private implementation. 681 | class Impl; 682 | 683 | std::unique_ptr pImpl; 684 | 685 | // Prevent copying. 686 | DynamicSoundEffectInstance(DynamicSoundEffectInstance const&); 687 | DynamicSoundEffectInstance& operator= (DynamicSoundEffectInstance const&); 688 | }; 689 | } 690 | 691 | #pragma warning(pop) -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/CommonStates.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: CommonStates.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | 24 | 25 | namespace DirectX 26 | { 27 | class CommonStates 28 | { 29 | public: 30 | explicit CommonStates(_In_ ID3D11Device* device); 31 | CommonStates(CommonStates&& moveFrom); 32 | CommonStates& operator= (CommonStates&& moveFrom); 33 | virtual ~CommonStates(); 34 | 35 | // Blend states. 36 | ID3D11BlendState* __cdecl Opaque() const; 37 | ID3D11BlendState* __cdecl AlphaBlend() const; 38 | ID3D11BlendState* __cdecl Additive() const; 39 | ID3D11BlendState* __cdecl NonPremultiplied() const; 40 | 41 | // Depth stencil states. 42 | ID3D11DepthStencilState* __cdecl DepthNone() const; 43 | ID3D11DepthStencilState* __cdecl DepthDefault() const; 44 | ID3D11DepthStencilState* __cdecl DepthRead() const; 45 | 46 | // Rasterizer states. 47 | ID3D11RasterizerState* __cdecl CullNone() const; 48 | ID3D11RasterizerState* __cdecl CullClockwise() const; 49 | ID3D11RasterizerState* __cdecl CullCounterClockwise() const; 50 | ID3D11RasterizerState* __cdecl Wireframe() const; 51 | 52 | // Sampler states. 53 | ID3D11SamplerState* __cdecl PointWrap() const; 54 | ID3D11SamplerState* __cdecl PointClamp() const; 55 | ID3D11SamplerState* __cdecl LinearWrap() const; 56 | ID3D11SamplerState* __cdecl LinearClamp() const; 57 | ID3D11SamplerState* __cdecl AnisotropicWrap() const; 58 | ID3D11SamplerState* __cdecl AnisotropicClamp() const; 59 | 60 | private: 61 | // Private implementation. 62 | class Impl; 63 | 64 | std::shared_ptr pImpl; 65 | 66 | // Prevent copying. 67 | CommonStates(CommonStates const&); 68 | CommonStates& operator= (CommonStates const&); 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/DDSTextureLoader.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DDSTextureLoader.h 3 | // 4 | // Functions for loading a DDS texture and creating a Direct3D 11 runtime resource for it 5 | // 6 | // Note these functions are useful as a light-weight runtime loader for DDS files. For 7 | // a full-featured DDS file reader, writer, and texture processing pipeline see 8 | // the 'Texconv' sample and the 'DirectXTex' library. 9 | // 10 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 11 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 12 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 13 | // PARTICULAR PURPOSE. 14 | // 15 | // Copyright (c) Microsoft Corporation. All rights reserved. 16 | // 17 | // http://go.microsoft.com/fwlink/?LinkId=248926 18 | // http://go.microsoft.com/fwlink/?LinkId=248929 19 | //-------------------------------------------------------------------------------------- 20 | 21 | #pragma once 22 | 23 | #if defined(_XBOX_ONE) && defined(_TITLE) 24 | #include 25 | #else 26 | #include 27 | #endif 28 | 29 | #pragma warning(push) 30 | #pragma warning(disable : 4005) 31 | #include 32 | #pragma warning(pop) 33 | 34 | namespace DirectX 35 | { 36 | enum DDS_ALPHA_MODE 37 | { 38 | DDS_ALPHA_MODE_UNKNOWN = 0, 39 | DDS_ALPHA_MODE_STRAIGHT = 1, 40 | DDS_ALPHA_MODE_PREMULTIPLIED = 2, 41 | DDS_ALPHA_MODE_OPAQUE = 3, 42 | DDS_ALPHA_MODE_CUSTOM = 4, 43 | }; 44 | 45 | // Standard version 46 | HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice, 47 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 48 | _In_ size_t ddsDataSize, 49 | _Outptr_opt_ ID3D11Resource** texture, 50 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 51 | _In_ size_t maxsize = 0, 52 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 53 | ); 54 | 55 | HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice, 56 | _In_z_ const wchar_t* szFileName, 57 | _Outptr_opt_ ID3D11Resource** texture, 58 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 59 | _In_ size_t maxsize = 0, 60 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 61 | ); 62 | 63 | // Standard version with optional auto-gen mipmap support 64 | #if defined(_XBOX_ONE) && defined(_TITLE) 65 | HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice, 66 | _In_opt_ ID3D11DeviceContextX* d3dContext, 67 | #else 68 | HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice, 69 | _In_opt_ ID3D11DeviceContext* d3dContext, 70 | #endif 71 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 72 | _In_ size_t ddsDataSize, 73 | _Outptr_opt_ ID3D11Resource** texture, 74 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 75 | _In_ size_t maxsize = 0, 76 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 77 | ); 78 | 79 | #if defined(_XBOX_ONE) && defined(_TITLE) 80 | HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, 81 | _In_opt_ ID3D11DeviceContextX* d3dContext, 82 | #else 83 | HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice, 84 | _In_opt_ ID3D11DeviceContext* d3dContext, 85 | #endif 86 | _In_z_ const wchar_t* szFileName, 87 | _Outptr_opt_ ID3D11Resource** texture, 88 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 89 | _In_ size_t maxsize = 0, 90 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 91 | ); 92 | 93 | // Extended version 94 | HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, 95 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 96 | _In_ size_t ddsDataSize, 97 | _In_ size_t maxsize, 98 | _In_ D3D11_USAGE usage, 99 | _In_ unsigned int bindFlags, 100 | _In_ unsigned int cpuAccessFlags, 101 | _In_ unsigned int miscFlags, 102 | _In_ bool forceSRGB, 103 | _Outptr_opt_ ID3D11Resource** texture, 104 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 105 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 106 | ); 107 | 108 | HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice, 109 | _In_z_ const wchar_t* szFileName, 110 | _In_ size_t maxsize, 111 | _In_ D3D11_USAGE usage, 112 | _In_ unsigned int bindFlags, 113 | _In_ unsigned int cpuAccessFlags, 114 | _In_ unsigned int miscFlags, 115 | _In_ bool forceSRGB, 116 | _Outptr_opt_ ID3D11Resource** texture, 117 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 118 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 119 | ); 120 | 121 | // Extended version with optional auto-gen mipmap support 122 | #if defined(_XBOX_ONE) && defined(_TITLE) 123 | HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice, 124 | _In_opt_ ID3D11DeviceContextX* d3dContext, 125 | #else 126 | HRESULT __cdecl CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, 127 | _In_opt_ ID3D11DeviceContext* d3dContext, 128 | #endif 129 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 130 | _In_ size_t ddsDataSize, 131 | _In_ size_t maxsize, 132 | _In_ D3D11_USAGE usage, 133 | _In_ unsigned int bindFlags, 134 | _In_ unsigned int cpuAccessFlags, 135 | _In_ unsigned int miscFlags, 136 | _In_ bool forceSRGB, 137 | _Outptr_opt_ ID3D11Resource** texture, 138 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 139 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 140 | ); 141 | 142 | #if defined(_XBOX_ONE) && defined(_TITLE) 143 | HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice, 144 | _In_opt_ ID3D11DeviceContextX* d3dContext, 145 | #else 146 | HRESULT __cdecl CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice, 147 | _In_opt_ ID3D11DeviceContext* d3dContext, 148 | #endif 149 | _In_z_ const wchar_t* szFileName, 150 | _In_ size_t maxsize, 151 | _In_ D3D11_USAGE usage, 152 | _In_ unsigned int bindFlags, 153 | _In_ unsigned int cpuAccessFlags, 154 | _In_ unsigned int miscFlags, 155 | _In_ bool forceSRGB, 156 | _Outptr_opt_ ID3D11Resource** texture, 157 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 158 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr 159 | ); 160 | } -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/DirectXHelpers.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DirectXHelpers.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #define NO_D3D11_DEBUG_NAME 19 | #else 20 | #include 21 | #endif 22 | 23 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) 24 | #pragma comment(lib,"dxguid.lib") 25 | #endif 26 | 27 | #include 28 | 29 | #pragma warning(push) 30 | #pragma warning(disable : 4005) 31 | #include 32 | #pragma warning(pop) 33 | 34 | // 35 | // The core Direct3D headers provide the following helper C++ classes 36 | // CD3D11_RECT 37 | // CD3D11_BOX 38 | // CD3D11_DEPTH_STENCIL_DESC 39 | // CD3D11_BLEND_DESC, CD3D11_BLEND_DESC1 40 | // CD3D11_RASTERIZER_DESC, CD3D11_RASTERIZER_DESC1 41 | // CD3D11_BUFFER_DESC 42 | // CD3D11_TEXTURE1D_DESC 43 | // CD3D11_TEXTURE2D_DESC 44 | // CD3D11_TEXTURE3D_DESC 45 | // CD3D11_SHADER_RESOURCE_VIEW_DESC 46 | // CD3D11_RENDER_TARGET_VIEW_DESC 47 | // CD3D11_VIEWPORT 48 | // CD3D11_DEPTH_STENCIL_VIEW_DESC 49 | // CD3D11_UNORDERED_ACCESS_VIEW_DESC 50 | // CD3D11_SAMPLER_DESC 51 | // CD3D11_QUERY_DESC 52 | // CD3D11_COUNTER_DESC 53 | // 54 | 55 | 56 | namespace DirectX 57 | { 58 | // simliar to std::lock_guard for exception-safe Direct3D 11 resource locking 59 | class MapGuard : public D3D11_MAPPED_SUBRESOURCE 60 | { 61 | public: 62 | MapGuard( _In_ ID3D11DeviceContext* context, 63 | _In_ ID3D11Resource *resource, 64 | _In_ UINT subresource, 65 | _In_ D3D11_MAP mapType, 66 | _In_ UINT mapFlags ) 67 | : mContext(context), mResource(resource), mSubresource(subresource) 68 | { 69 | HRESULT hr = mContext->Map( resource, subresource, mapType, mapFlags, this ); 70 | if (FAILED(hr)) 71 | { 72 | throw std::exception(); 73 | } 74 | } 75 | 76 | ~MapGuard() 77 | { 78 | mContext->Unmap( mResource, mSubresource ); 79 | } 80 | 81 | uint8_t* get() const 82 | { 83 | return reinterpret_cast( pData ); 84 | } 85 | uint8_t* get(size_t slice) const 86 | { 87 | return reinterpret_cast( pData ) + ( slice * DepthPitch ); 88 | } 89 | 90 | uint8_t* scanline(size_t row) const 91 | { 92 | return reinterpret_cast( pData ) + ( row * RowPitch ); 93 | } 94 | uint8_t* scanline(size_t slice, size_t row) const 95 | { 96 | return reinterpret_cast( pData ) + ( slice * DepthPitch ) + ( row * RowPitch ); 97 | } 98 | 99 | private: 100 | ID3D11DeviceContext* mContext; 101 | ID3D11Resource* mResource; 102 | UINT mSubresource; 103 | 104 | MapGuard(MapGuard const&); 105 | MapGuard& operator= (MapGuard const&); 106 | }; 107 | 108 | 109 | // Helper sets a D3D resource name string (used by PIX and debug layer leak reporting). 110 | template 111 | inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength]) 112 | { 113 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) 114 | resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); 115 | #else 116 | UNREFERENCED_PARAMETER(resource); 117 | UNREFERENCED_PARAMETER(name); 118 | #endif 119 | } 120 | } -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/Effects.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: Effects.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | #include 24 | 25 | #pragma warning(push) 26 | #pragma warning(disable : 4481) 27 | // VS 2010 considers 'override' to be a extension, but it's part of C++11 as of VS 2012 28 | 29 | namespace DirectX 30 | { 31 | #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) 32 | #define XM_CALLCONV __fastcall 33 | typedef const XMVECTOR& HXMVECTOR; 34 | typedef const XMMATRIX& FXMMATRIX; 35 | #endif 36 | 37 | //---------------------------------------------------------------------------------- 38 | // Abstract interface representing any effect which can be applied onto a D3D device context. 39 | class IEffect 40 | { 41 | public: 42 | virtual ~IEffect() { } 43 | 44 | virtual void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) = 0; 45 | 46 | virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) = 0; 47 | }; 48 | 49 | 50 | // Abstract interface for effects with world, view, and projection matrices. 51 | class IEffectMatrices 52 | { 53 | public: 54 | virtual ~IEffectMatrices() { } 55 | 56 | virtual void XM_CALLCONV SetWorld(FXMMATRIX value) = 0; 57 | virtual void XM_CALLCONV SetView(FXMMATRIX value) = 0; 58 | virtual void XM_CALLCONV SetProjection(FXMMATRIX value) = 0; 59 | }; 60 | 61 | 62 | // Abstract interface for effects which support directional lighting. 63 | class IEffectLights 64 | { 65 | public: 66 | virtual ~IEffectLights() { } 67 | 68 | virtual void __cdecl SetLightingEnabled(bool value) = 0; 69 | virtual void __cdecl SetPerPixelLighting(bool value) = 0; 70 | virtual void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) = 0; 71 | 72 | virtual void __cdecl SetLightEnabled(int whichLight, bool value) = 0; 73 | virtual void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) = 0; 74 | virtual void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) = 0; 75 | virtual void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) = 0; 76 | 77 | virtual void __cdecl EnableDefaultLighting() = 0; 78 | 79 | static const int MaxDirectionalLights = 3; 80 | }; 81 | 82 | 83 | // Abstract interface for effects which support fog. 84 | class IEffectFog 85 | { 86 | public: 87 | virtual ~IEffectFog() { } 88 | 89 | virtual void __cdecl SetFogEnabled(bool value) = 0; 90 | virtual void __cdecl SetFogStart(float value) = 0; 91 | virtual void __cdecl SetFogEnd(float value) = 0; 92 | virtual void XM_CALLCONV SetFogColor(FXMVECTOR value) = 0; 93 | }; 94 | 95 | 96 | // Abstract interface for effects which support skinning 97 | class IEffectSkinning 98 | { 99 | public: 100 | virtual ~IEffectSkinning() { } 101 | 102 | virtual void __cdecl SetWeightsPerVertex(int value) = 0; 103 | virtual void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0; 104 | virtual void __cdecl ResetBoneTransforms() = 0; 105 | 106 | static const int MaxBones = 72; 107 | }; 108 | 109 | 110 | //---------------------------------------------------------------------------------- 111 | // Built-in shader supports optional texture mapping, vertex coloring, directional lighting, and fog. 112 | class BasicEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog 113 | { 114 | public: 115 | explicit BasicEffect(_In_ ID3D11Device* device); 116 | BasicEffect(BasicEffect&& moveFrom); 117 | BasicEffect& operator= (BasicEffect&& moveFrom); 118 | virtual ~BasicEffect(); 119 | 120 | // IEffect methods. 121 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; 122 | 123 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; 124 | 125 | // Camera settings. 126 | void XM_CALLCONV SetWorld(FXMMATRIX value) override; 127 | void XM_CALLCONV SetView(FXMMATRIX value) override; 128 | void XM_CALLCONV SetProjection(FXMMATRIX value) override; 129 | 130 | // Material settings. 131 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); 132 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); 133 | void XM_CALLCONV SetSpecularColor(FXMVECTOR value); 134 | void __cdecl SetSpecularPower(float value); 135 | void __cdecl DisableSpecular(); 136 | void __cdecl SetAlpha(float value); 137 | 138 | // Light settings. 139 | void __cdecl SetLightingEnabled(bool value) override; 140 | void __cdecl SetPerPixelLighting(bool value) override; 141 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; 142 | 143 | void __cdecl SetLightEnabled(int whichLight, bool value) override; 144 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; 145 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; 146 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; 147 | 148 | void __cdecl EnableDefaultLighting() override; 149 | 150 | // Fog settings. 151 | void __cdecl SetFogEnabled(bool value) override; 152 | void __cdecl SetFogStart(float value) override; 153 | void __cdecl SetFogEnd(float value) override; 154 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override; 155 | 156 | // Vertex color setting. 157 | void __cdecl SetVertexColorEnabled(bool value); 158 | 159 | // Texture setting. 160 | void __cdecl SetTextureEnabled(bool value); 161 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); 162 | 163 | private: 164 | // Private implementation. 165 | class Impl; 166 | 167 | std::unique_ptr pImpl; 168 | 169 | // Prevent copying. 170 | BasicEffect(BasicEffect const&); 171 | BasicEffect& operator= (BasicEffect const&); 172 | }; 173 | 174 | 175 | 176 | // Built-in shader supports per-pixel alpha testing. 177 | class AlphaTestEffect : public IEffect, public IEffectMatrices, public IEffectFog 178 | { 179 | public: 180 | explicit AlphaTestEffect(_In_ ID3D11Device* device); 181 | AlphaTestEffect(AlphaTestEffect&& moveFrom); 182 | AlphaTestEffect& operator= (AlphaTestEffect&& moveFrom); 183 | virtual ~AlphaTestEffect(); 184 | 185 | // IEffect methods. 186 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; 187 | 188 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; 189 | 190 | // Camera settings. 191 | void XM_CALLCONV SetWorld(FXMMATRIX value) override; 192 | void XM_CALLCONV SetView(FXMMATRIX value) override; 193 | void XM_CALLCONV SetProjection(FXMMATRIX value) override; 194 | 195 | // Material settings. 196 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); 197 | void __cdecl SetAlpha(float value); 198 | 199 | // Fog settings. 200 | void __cdecl SetFogEnabled(bool value) override; 201 | void __cdecl SetFogStart(float value) override; 202 | void __cdecl SetFogEnd(float value) override; 203 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override; 204 | 205 | // Vertex color setting. 206 | void __cdecl SetVertexColorEnabled(bool value); 207 | 208 | // Texture setting. 209 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); 210 | 211 | // Alpha test settings. 212 | void __cdecl SetAlphaFunction(D3D11_COMPARISON_FUNC value); 213 | void __cdecl SetReferenceAlpha(int value); 214 | 215 | private: 216 | // Private implementation. 217 | class Impl; 218 | 219 | std::unique_ptr pImpl; 220 | 221 | // Prevent copying. 222 | AlphaTestEffect(AlphaTestEffect const&); 223 | AlphaTestEffect& operator= (AlphaTestEffect const&); 224 | }; 225 | 226 | 227 | 228 | // Built-in shader supports two layer multitexturing (eg. for lightmaps or detail textures). 229 | class DualTextureEffect : public IEffect, public IEffectMatrices, public IEffectFog 230 | { 231 | public: 232 | explicit DualTextureEffect(_In_ ID3D11Device* device); 233 | DualTextureEffect(DualTextureEffect&& moveFrom); 234 | DualTextureEffect& operator= (DualTextureEffect&& moveFrom); 235 | ~DualTextureEffect(); 236 | 237 | // IEffect methods. 238 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; 239 | 240 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; 241 | 242 | // Camera settings. 243 | void XM_CALLCONV SetWorld(FXMMATRIX value) override; 244 | void XM_CALLCONV SetView(FXMMATRIX value) override; 245 | void XM_CALLCONV SetProjection(FXMMATRIX value) override; 246 | 247 | // Material settings. 248 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); 249 | void __cdecl SetAlpha(float value); 250 | 251 | // Fog settings. 252 | void __cdecl SetFogEnabled(bool value) override; 253 | void __cdecl SetFogStart(float value) override; 254 | void __cdecl SetFogEnd(float value) override; 255 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override; 256 | 257 | // Vertex color setting. 258 | void __cdecl SetVertexColorEnabled(bool value); 259 | 260 | // Texture settings. 261 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); 262 | void __cdecl SetTexture2(_In_opt_ ID3D11ShaderResourceView* value); 263 | 264 | private: 265 | // Private implementation. 266 | class Impl; 267 | 268 | std::unique_ptr pImpl; 269 | 270 | // Prevent copying. 271 | DualTextureEffect(DualTextureEffect const&); 272 | DualTextureEffect& operator= (DualTextureEffect const&); 273 | }; 274 | 275 | 276 | 277 | // Built-in shader supports cubic environment mapping. 278 | class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog 279 | { 280 | public: 281 | explicit EnvironmentMapEffect(_In_ ID3D11Device* device); 282 | EnvironmentMapEffect(EnvironmentMapEffect&& moveFrom); 283 | EnvironmentMapEffect& operator= (EnvironmentMapEffect&& moveFrom); 284 | virtual ~EnvironmentMapEffect(); 285 | 286 | // IEffect methods. 287 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; 288 | 289 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; 290 | 291 | // Camera settings. 292 | void XM_CALLCONV SetWorld(FXMMATRIX value) override; 293 | void XM_CALLCONV SetView(FXMMATRIX value) override; 294 | void XM_CALLCONV SetProjection(FXMMATRIX value) override; 295 | 296 | // Material settings. 297 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); 298 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); 299 | void __cdecl SetAlpha(float value); 300 | 301 | // Light settings. 302 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; 303 | 304 | void __cdecl SetLightEnabled(int whichLight, bool value) override; 305 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; 306 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; 307 | 308 | void __cdecl EnableDefaultLighting() override; 309 | 310 | // Fog settings. 311 | void __cdecl SetFogEnabled(bool value) override; 312 | void __cdecl SetFogStart(float value) override; 313 | void __cdecl SetFogEnd(float value) override; 314 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override; 315 | 316 | // Texture setting. 317 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); 318 | 319 | // Environment map settings. 320 | void __cdecl SetEnvironmentMap(_In_opt_ ID3D11ShaderResourceView* value); 321 | void __cdecl SetEnvironmentMapAmount(float value); 322 | void XM_CALLCONV SetEnvironmentMapSpecular(FXMVECTOR value); 323 | void __cdecl SetFresnelFactor(float value); 324 | 325 | private: 326 | // Private implementation. 327 | class Impl; 328 | 329 | std::unique_ptr pImpl; 330 | 331 | // Unsupported interface methods. 332 | void __cdecl SetLightingEnabled(bool value) override; 333 | void __cdecl SetPerPixelLighting(bool value) override; 334 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; 335 | 336 | // Prevent copying. 337 | EnvironmentMapEffect(EnvironmentMapEffect const&); 338 | EnvironmentMapEffect& operator= (EnvironmentMapEffect const&); 339 | }; 340 | 341 | 342 | 343 | // Built-in shader supports skinned animation. 344 | class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog, public IEffectSkinning 345 | { 346 | public: 347 | explicit SkinnedEffect(_In_ ID3D11Device* device); 348 | SkinnedEffect(SkinnedEffect&& moveFrom); 349 | SkinnedEffect& operator= (SkinnedEffect&& moveFrom); 350 | virtual ~SkinnedEffect(); 351 | 352 | // IEffect methods. 353 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; 354 | 355 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; 356 | 357 | // Camera settings. 358 | void XM_CALLCONV SetWorld(FXMMATRIX value) override; 359 | void XM_CALLCONV SetView(FXMMATRIX value) override; 360 | void XM_CALLCONV SetProjection(FXMMATRIX value) override; 361 | 362 | // Material settings. 363 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); 364 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); 365 | void XM_CALLCONV SetSpecularColor(FXMVECTOR value); 366 | void __cdecl SetSpecularPower(float value); 367 | void __cdecl DisableSpecular(); 368 | void __cdecl SetAlpha(float value); 369 | 370 | // Light settings. 371 | void __cdecl SetPerPixelLighting(bool value) override; 372 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; 373 | 374 | void __cdecl SetLightEnabled(int whichLight, bool value) override; 375 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; 376 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; 377 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; 378 | 379 | void __cdecl EnableDefaultLighting() override; 380 | 381 | // Fog settings. 382 | void __cdecl SetFogEnabled(bool value) override; 383 | void __cdecl SetFogStart(float value) override; 384 | void __cdecl SetFogEnd(float value) override; 385 | void XM_CALLCONV SetFogColor(FXMVECTOR value) override; 386 | 387 | // Texture setting. 388 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); 389 | 390 | // Animation settings. 391 | void __cdecl SetWeightsPerVertex(int value) override; 392 | void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override; 393 | void __cdecl ResetBoneTransforms() override; 394 | 395 | private: 396 | // Private implementation. 397 | class Impl; 398 | 399 | std::unique_ptr pImpl; 400 | 401 | // Unsupported interface method. 402 | void __cdecl SetLightingEnabled(bool value) override; 403 | 404 | // Prevent copying. 405 | SkinnedEffect(SkinnedEffect const&); 406 | SkinnedEffect& operator= (SkinnedEffect const&); 407 | }; 408 | 409 | 410 | 411 | //---------------------------------------------------------------------------------- 412 | // Built-in effect for Visual Studio Shader Designer (DGSL) shaders 413 | class DGSLEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectSkinning 414 | { 415 | public: 416 | explicit DGSLEffect( _In_ ID3D11Device* device, _In_opt_ ID3D11PixelShader* pixelShader = nullptr, 417 | _In_ bool enableSkinning = false ); 418 | DGSLEffect(DGSLEffect&& moveFrom); 419 | DGSLEffect& operator= (DGSLEffect&& moveFrom); 420 | virtual ~DGSLEffect(); 421 | 422 | // IEffect methods. 423 | void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) override; 424 | 425 | void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) override; 426 | 427 | // Camera settings. 428 | void XM_CALLCONV SetWorld(FXMMATRIX value) override; 429 | void XM_CALLCONV SetView(FXMMATRIX value) override; 430 | void XM_CALLCONV SetProjection(FXMMATRIX value) override; 431 | 432 | // Material settings. 433 | void XM_CALLCONV SetAmbientColor(FXMVECTOR value); 434 | void XM_CALLCONV SetDiffuseColor(FXMVECTOR value); 435 | void XM_CALLCONV SetEmissiveColor(FXMVECTOR value); 436 | void XM_CALLCONV SetSpecularColor(FXMVECTOR value); 437 | void __cdecl SetSpecularPower(float value); 438 | void __cdecl DisableSpecular(); 439 | void __cdecl SetAlpha(float value); 440 | 441 | // Additional settings. 442 | void XM_CALLCONV SetUVTransform(FXMMATRIX value); 443 | void __cdecl SetViewport( float width, float height ); 444 | void __cdecl SetTime( float time ); 445 | void __cdecl SetAlphaDiscardEnable(bool value); 446 | 447 | // Light settings. 448 | void __cdecl SetLightingEnabled(bool value) override; 449 | void XM_CALLCONV SetAmbientLightColor(FXMVECTOR value) override; 450 | 451 | void __cdecl SetLightEnabled(int whichLight, bool value) override; 452 | void XM_CALLCONV SetLightDirection(int whichLight, FXMVECTOR value) override; 453 | void XM_CALLCONV SetLightDiffuseColor(int whichLight, FXMVECTOR value) override; 454 | void XM_CALLCONV SetLightSpecularColor(int whichLight, FXMVECTOR value) override; 455 | 456 | void __cdecl EnableDefaultLighting() override; 457 | 458 | static const int MaxDirectionalLights = 4; 459 | 460 | // Vertex color setting. 461 | void __cdecl SetVertexColorEnabled(bool value); 462 | 463 | // Texture settings. 464 | void __cdecl SetTextureEnabled(bool value); 465 | void __cdecl SetTexture(_In_opt_ ID3D11ShaderResourceView* value); 466 | void __cdecl SetTexture(int whichTexture, _In_opt_ ID3D11ShaderResourceView* value); 467 | 468 | static const int MaxTextures = 8; 469 | 470 | // Animation setting. 471 | void __cdecl SetWeightsPerVertex(int value) override; 472 | void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) override; 473 | void __cdecl ResetBoneTransforms() override; 474 | 475 | private: 476 | // Private implementation. 477 | class Impl; 478 | 479 | std::unique_ptr pImpl; 480 | 481 | // Unsupported interface methods. 482 | void __cdecl SetPerPixelLighting(bool value) override; 483 | 484 | // Prevent copying. 485 | DGSLEffect(DGSLEffect const&); 486 | DGSLEffect& operator= (DGSLEffect const&); 487 | }; 488 | 489 | 490 | 491 | //---------------------------------------------------------------------------------- 492 | // Abstract interface to factory for sharing effects and texture resources 493 | class IEffectFactory 494 | { 495 | public: 496 | virtual ~IEffectFactory() {} 497 | 498 | struct EffectInfo 499 | { 500 | const WCHAR* name; 501 | bool perVertexColor; 502 | bool enableSkinning; 503 | float specularPower; 504 | float alpha; 505 | DirectX::XMFLOAT3 ambientColor; 506 | DirectX::XMFLOAT3 diffuseColor; 507 | DirectX::XMFLOAT3 specularColor; 508 | DirectX::XMFLOAT3 emissiveColor; 509 | const WCHAR* texture; 510 | 511 | EffectInfo() { memset( this, 0, sizeof(EffectInfo) ); }; 512 | }; 513 | 514 | virtual std::shared_ptr __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) = 0; 515 | 516 | virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) = 0; 517 | }; 518 | 519 | 520 | // Factory for sharing effects and texture resources 521 | class EffectFactory : public IEffectFactory 522 | { 523 | public: 524 | explicit EffectFactory(_In_ ID3D11Device* device); 525 | EffectFactory(EffectFactory&& moveFrom); 526 | EffectFactory& operator= (EffectFactory&& moveFrom); 527 | virtual ~EffectFactory(); 528 | 529 | // IEffectFactory methods. 530 | virtual std::shared_ptr __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override; 531 | virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override; 532 | 533 | // Settings. 534 | void __cdecl ReleaseCache(); 535 | 536 | void __cdecl SetSharing( bool enabled ); 537 | 538 | void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path ); 539 | 540 | private: 541 | // Private implementation. 542 | class Impl; 543 | 544 | std::shared_ptr pImpl; 545 | 546 | // Prevent copying. 547 | EffectFactory(EffectFactory const&); 548 | EffectFactory& operator= (EffectFactory const&); 549 | }; 550 | 551 | 552 | // Factory for sharing Visual Studio Shader Designer (DGSL) shaders and texture resources 553 | class DGSLEffectFactory : public IEffectFactory 554 | { 555 | public: 556 | explicit DGSLEffectFactory(_In_ ID3D11Device* device); 557 | DGSLEffectFactory(DGSLEffectFactory&& moveFrom); 558 | DGSLEffectFactory& operator= (DGSLEffectFactory&& moveFrom); 559 | virtual ~DGSLEffectFactory(); 560 | 561 | // IEffectFactory methods. 562 | virtual std::shared_ptr __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override; 563 | virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override; 564 | 565 | // DGSL methods. 566 | struct DGSLEffectInfo : public EffectInfo 567 | { 568 | const WCHAR* textures[7]; 569 | const WCHAR* pixelShader; 570 | 571 | DGSLEffectInfo() { memset( this, 0, sizeof(DGSLEffectInfo) ); }; 572 | }; 573 | 574 | virtual std::shared_ptr __cdecl CreateDGSLEffect( _In_ const DGSLEffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ); 575 | 576 | virtual void __cdecl CreatePixelShader( _In_z_ const WCHAR* shader, _Outptr_ ID3D11PixelShader** pixelShader ); 577 | 578 | // Settings. 579 | void __cdecl ReleaseCache(); 580 | 581 | void __cdecl SetSharing( bool enabled ); 582 | 583 | void __cdecl SetDirectory( _In_opt_z_ const WCHAR* path ); 584 | 585 | private: 586 | // Private implementation. 587 | class Impl; 588 | 589 | std::shared_ptr pImpl; 590 | 591 | // Prevent copying. 592 | DGSLEffectFactory(DGSLEffectFactory const&); 593 | DGSLEffectFactory& operator= (DGSLEffectFactory const&); 594 | }; 595 | 596 | } 597 | 598 | #pragma warning(pop) 599 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/GamePad.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: GamePad.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #ifndef _XBOX_ONE 17 | #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) 18 | #if (_WIN32_WINNT >= 0x0602) 19 | #pragma comment(lib,"xinput.lib") 20 | #else 21 | #pragma comment(lib,"xinput9_1_0.lib") 22 | #endif 23 | #endif 24 | #endif 25 | 26 | #include 27 | 28 | #pragma warning(push) 29 | #pragma warning(disable : 4005) 30 | #include 31 | #include 32 | #pragma warning(pop) 33 | 34 | namespace DirectX 35 | { 36 | class GamePad 37 | { 38 | public: 39 | GamePad(); 40 | GamePad(GamePad&& moveFrom); 41 | GamePad& operator= (GamePad&& moveFrom); 42 | virtual ~GamePad(); 43 | 44 | #ifdef _XBOX_ONE 45 | static const int MAX_PLAYER_COUNT = 8; 46 | #else 47 | static const int MAX_PLAYER_COUNT = 4; 48 | #endif 49 | 50 | enum DeadZone 51 | { 52 | DEAD_ZONE_INDEPENDENT_AXES = 0, 53 | DEAD_ZONE_CIRCULAR, 54 | DEAD_ZONE_NONE, 55 | }; 56 | 57 | struct Buttons 58 | { 59 | bool a; 60 | bool b; 61 | bool x; 62 | bool y; 63 | bool leftStick; 64 | bool rightStick; 65 | bool leftShoulder; 66 | bool rightShoulder; 67 | bool back; 68 | bool start; 69 | }; 70 | 71 | struct DPad 72 | { 73 | bool up; 74 | bool down; 75 | bool right; 76 | bool left; 77 | }; 78 | 79 | struct ThumbSticks 80 | { 81 | float leftX; 82 | float leftY; 83 | float rightX; 84 | float rightY; 85 | }; 86 | 87 | struct Triggers 88 | { 89 | float left; 90 | float right; 91 | }; 92 | 93 | struct State 94 | { 95 | bool connected; 96 | uint64_t packet; 97 | Buttons buttons; 98 | DPad dpad; 99 | ThumbSticks thumbSticks; 100 | Triggers triggers; 101 | 102 | bool __cdecl IsConnected() const { return connected; } 103 | 104 | // Is the button pressed currently? 105 | bool __cdecl IsAPressed() const { return buttons.a; } 106 | bool __cdecl IsBPressed() const { return buttons.b; } 107 | bool __cdecl IsXPressed() const { return buttons.x; } 108 | bool __cdecl IsYPressed() const { return buttons.y; } 109 | 110 | bool __cdecl IsLeftStickPressed() const { return buttons.leftStick; } 111 | bool __cdecl IsRightStickPressed() const { return buttons.rightStick; } 112 | 113 | bool __cdecl IsLeftShoulderPressed() const { return buttons.leftShoulder; } 114 | bool __cdecl IsRightShoulderPressed() const { return buttons.rightShoulder; } 115 | 116 | bool __cdecl IsBackPressed() const { return buttons.back; } 117 | bool __cdecl IsViewPressed() const { return buttons.back; } 118 | bool __cdecl IsStartPressed() const { return buttons.start; } 119 | bool __cdecl IsMenuPressed() const { return buttons.start; } 120 | 121 | bool __cdecl IsDPadDownPressed() const { return dpad.down; }; 122 | bool __cdecl IsDPadUpPressed() const { return dpad.up; }; 123 | bool __cdecl IsDPadLeftPressed() const { return dpad.left; }; 124 | bool __cdecl IsDPadRightPressed() const { return dpad.right; }; 125 | 126 | bool __cdecl IsLeftThumbStickUp() const { return (thumbSticks.leftY > 0.5f) != 0; } 127 | bool __cdecl IsLeftThumbStickDown() const { return (thumbSticks.leftY < -0.5f) != 0; } 128 | bool __cdecl IsLeftThumbStickLeft() const { return (thumbSticks.leftX < -0.5f) != 0; } 129 | bool __cdecl IsLeftThumbStickRight() const { return (thumbSticks.leftX > 0.5f) != 0; } 130 | 131 | bool __cdecl IsRightThumbStickUp() const { return (thumbSticks.rightY > 0.5f ) != 0; } 132 | bool __cdecl IsRightThumbStickDown() const { return (thumbSticks.rightY < -0.5f) != 0; } 133 | bool __cdecl IsRightThumbStickLeft() const { return (thumbSticks.rightX < -0.5f) != 0; } 134 | bool __cdecl IsRightThumbStickRight() const { return (thumbSticks.rightX > 0.5f) != 0; } 135 | 136 | bool __cdecl IsLeftTriggerPressed() const { return (triggers.left > 0.5f) != 0; } 137 | bool __cdecl IsRightTriggerPressed() const { return (triggers.right > 0.5f) != 0; } 138 | }; 139 | 140 | struct Capabilities 141 | { 142 | enum Type 143 | { 144 | UNKNOWN = 0, 145 | GAMEPAD, 146 | WHEEL, 147 | ARCADE_STICK, 148 | FLIGHT_STICK, 149 | DANCE_PAD, 150 | GUITAR, 151 | GUITAR_ALTERNATE, 152 | DRUM_KIT, 153 | GUITAR_BASS = 11, 154 | ARCADE_PAD = 19, 155 | }; 156 | 157 | bool connected; 158 | Type gamepadType; 159 | uint64_t id; 160 | 161 | bool __cdecl IsConnected() const { return connected; } 162 | }; 163 | 164 | class ButtonStateTracker 165 | { 166 | public: 167 | enum ButtonState 168 | { 169 | UP = 0, // Button is up 170 | HELD = 1, // Button is held down 171 | RELEASED = 2, // Button was just released 172 | PRESSED = 3, // Buton was just pressed 173 | }; 174 | 175 | ButtonState a; 176 | ButtonState b; 177 | ButtonState x; 178 | ButtonState y; 179 | 180 | ButtonState leftStick; 181 | ButtonState rightStick; 182 | 183 | ButtonState leftShoulder; 184 | ButtonState rightShoulder; 185 | 186 | ButtonState back; 187 | ButtonState start; 188 | 189 | ButtonState dpadUp; 190 | ButtonState dpadDown; 191 | ButtonState dpadLeft; 192 | ButtonState dpadRight; 193 | 194 | ButtonStateTracker() { Reset(); } 195 | 196 | void __cdecl Update( const State& state ); 197 | 198 | void __cdecl Reset(); 199 | 200 | private: 201 | State lastState; 202 | }; 203 | 204 | // Retrieve the current state of the gamepad of the associated player index 205 | State __cdecl GetState(int player, DeadZone deadZoneMode = DEAD_ZONE_INDEPENDENT_AXES); 206 | 207 | // Retrieve the current capabilities of the gamepad of the associated player index 208 | Capabilities __cdecl GetCapabilities(int player); 209 | 210 | // Set the vibration motor speeds of the gamepad 211 | bool __cdecl SetVibration( int player, float leftMotor, float rightMotor, float leftTrigger = 0.f, float rightTrigger = 0.f ); 212 | 213 | // Handle suspending/resuming 214 | void __cdecl Suspend(); 215 | void __cdecl Resume(); 216 | 217 | private: 218 | // Private implementation. 219 | class Impl; 220 | 221 | std::unique_ptr pImpl; 222 | 223 | // Prevent copying. 224 | GamePad(GamePad const&); 225 | GamePad& operator=(GamePad const&); 226 | }; 227 | } 228 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/GeometricPrimitive.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: GeometricPrimitive.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | // VS 2010 doesn't support explicit calling convention for std::function 28 | #ifndef DIRECTX_STD_CALLCONV 29 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 30 | #define DIRECTX_STD_CALLCONV 31 | #else 32 | #define DIRECTX_STD_CALLCONV __cdecl 33 | #endif 34 | #endif 35 | 36 | namespace DirectX 37 | { 38 | #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) 39 | #define XM_CALLCONV __fastcall 40 | typedef const XMVECTOR& HXMVECTOR; 41 | typedef const XMMATRIX& FXMMATRIX; 42 | #endif 43 | 44 | class IEffect; 45 | 46 | class GeometricPrimitive 47 | { 48 | public: 49 | ~GeometricPrimitive(); 50 | 51 | // Factory methods. 52 | static std::unique_ptr __cdecl CreateCube (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 53 | static std::unique_ptr __cdecl CreateSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true); 54 | static std::unique_ptr __cdecl CreateGeoSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true); 55 | static std::unique_ptr __cdecl CreateCylinder (_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true); 56 | static std::unique_ptr __cdecl CreateCone (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true); 57 | static std::unique_ptr __cdecl CreateTorus (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true); 58 | static std::unique_ptr __cdecl CreateTetrahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 59 | static std::unique_ptr __cdecl CreateOctahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 60 | static std::unique_ptr __cdecl CreateDodecahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 61 | static std::unique_ptr __cdecl CreateIcosahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 62 | static std::unique_ptr __cdecl CreateTeapot (_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true); 63 | 64 | // Draw the primitive. 65 | void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White, _In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false, 66 | _In_opt_ std::function setCustomState = nullptr ); 67 | 68 | // Draw the primitive using a custom effect. 69 | void __cdecl Draw( _In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, bool wireframe = false, 70 | _In_opt_ std::function setCustomState = nullptr ); 71 | 72 | // Create input layout for drawing with a custom effect. 73 | void __cdecl CreateInputLayout( _In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout ); 74 | 75 | private: 76 | GeometricPrimitive(); 77 | 78 | // Private implementation. 79 | class Impl; 80 | 81 | std::unique_ptr pImpl; 82 | 83 | // Prevent copying. 84 | GeometricPrimitive(GeometricPrimitive const&); 85 | GeometricPrimitive& operator= (GeometricPrimitive const&); 86 | }; 87 | } 88 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/Model.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: Model.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #pragma warning(push) 32 | #pragma warning(disable : 4005) 33 | #include 34 | #include 35 | #pragma warning(pop) 36 | 37 | #include 38 | 39 | // VS 2010 doesn't support explicit calling convention for std::function 40 | #ifndef DIRECTX_STD_CALLCONV 41 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 42 | #define DIRECTX_STD_CALLCONV 43 | #else 44 | #define DIRECTX_STD_CALLCONV __cdecl 45 | #endif 46 | #endif 47 | 48 | namespace DirectX 49 | { 50 | #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) 51 | #define XM_CALLCONV __fastcall 52 | typedef const XMVECTOR& HXMVECTOR; 53 | typedef const XMMATRIX& FXMMATRIX; 54 | #endif 55 | 56 | class IEffect; 57 | class IEffectFactory; 58 | class CommonStates; 59 | class ModelMesh; 60 | 61 | // Each mesh part is a submesh with a single effect 62 | class ModelMeshPart 63 | { 64 | public: 65 | ModelMeshPart(); 66 | 67 | uint32_t indexCount; 68 | uint32_t startIndex; 69 | uint32_t vertexOffset; 70 | uint32_t vertexStride; 71 | D3D_PRIMITIVE_TOPOLOGY primitiveType; 72 | DXGI_FORMAT indexFormat; 73 | Microsoft::WRL::ComPtr inputLayout; 74 | Microsoft::WRL::ComPtr indexBuffer; 75 | Microsoft::WRL::ComPtr vertexBuffer; 76 | std::shared_ptr effect; 77 | std::shared_ptr> vbDecl; 78 | bool isAlpha; 79 | 80 | typedef std::vector> Collection; 81 | 82 | // Draw mesh part with custom effect 83 | void __cdecl Draw( _In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, _In_ ID3D11InputLayout* iinputLayout, 84 | _In_opt_ std::function setCustomState = nullptr ) const; 85 | 86 | // Create input layout for drawing with a custom effect. 87 | void __cdecl CreateInputLayout( _In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout ); 88 | 89 | // Change effect used by part and regenerate input layout (be sure to call Model::Modified as well) 90 | void __cdecl ModifyEffect( _In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr& ieffect, bool isalpha = false ); 91 | }; 92 | 93 | 94 | // A mesh consists of one or more model parts 95 | class ModelMesh 96 | { 97 | public: 98 | ModelMesh(); 99 | 100 | BoundingSphere boundingSphere; 101 | BoundingBox boundingBox; 102 | ModelMeshPart::Collection meshParts; 103 | std::wstring name; 104 | bool ccw; 105 | bool pmalpha; 106 | 107 | typedef std::vector> Collection; 108 | 109 | // Setup states for drawing mesh 110 | void __cdecl PrepareForRendering( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, bool alpha = false, bool wireframe = false ) const; 111 | 112 | // Draw the mesh 113 | void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, 114 | bool alpha = false, _In_opt_ std::function setCustomState = nullptr ) const; 115 | }; 116 | 117 | 118 | // A model consists of one or more meshes 119 | class Model 120 | { 121 | public: 122 | ModelMesh::Collection meshes; 123 | std::wstring name; 124 | 125 | // Draw all the meshes in the model 126 | void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, 127 | bool wireframe = false, _In_opt_ std::function setCustomState = nullptr ) const; 128 | 129 | // Notify model that effects, parts list, or mesh list has changed 130 | void __cdecl Modified() { mEffectCache.clear(); } 131 | 132 | // Update all effects used by the model 133 | void __cdecl UpdateEffects( _In_ std::function setEffect ); 134 | 135 | // Loads a model from a Visual Studio Starter Kit .CMO file 136 | static std::unique_ptr __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, size_t dataSize, 137 | _In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false ); 138 | static std::unique_ptr __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName, 139 | _In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false ); 140 | 141 | // Loads a model from a DirectX SDK .SDKMESH file 142 | static std::unique_ptr __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize, 143 | _In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false ); 144 | static std::unique_ptr __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName, 145 | _In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false ); 146 | 147 | // Loads a model from a .VBO file 148 | static std::unique_ptr __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize, 149 | _In_opt_ std::shared_ptr ieffect = nullptr, bool ccw = false, bool pmalpha = false ); 150 | static std::unique_ptr __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName, 151 | _In_opt_ std::shared_ptr ieffect = nullptr, bool ccw = false, bool pmalpha = false ); 152 | 153 | private: 154 | std::set mEffectCache; 155 | }; 156 | } -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/PrimitiveBatch.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: PrimitiveBatch.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | #include 24 | 25 | #pragma warning(push) 26 | #pragma warning(disable: 4005) 27 | #include 28 | #pragma warning(pop) 29 | 30 | 31 | namespace DirectX 32 | { 33 | namespace Internal 34 | { 35 | // Base class, not to be used directly: clients should access this via the derived PrimitiveBatch. 36 | class PrimitiveBatchBase 37 | { 38 | protected: 39 | PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize); 40 | PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom); 41 | PrimitiveBatchBase& operator= (PrimitiveBatchBase&& moveFrom); 42 | virtual ~PrimitiveBatchBase(); 43 | 44 | public: 45 | // Begin/End a batch of primitive drawing operations. 46 | void __cdecl Begin(); 47 | void __cdecl End(); 48 | 49 | protected: 50 | // Internal, untyped drawing method. 51 | void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, _Out_ void** pMappedVertices); 52 | 53 | private: 54 | // Private implementation. 55 | class Impl; 56 | 57 | std::unique_ptr pImpl; 58 | 59 | // Prevent copying. 60 | PrimitiveBatchBase(PrimitiveBatchBase const&); 61 | PrimitiveBatchBase& operator= (PrimitiveBatchBase const&); 62 | }; 63 | } 64 | 65 | 66 | // Template makes the API typesafe, eg. PrimitiveBatch. 67 | template 68 | class PrimitiveBatch : public Internal::PrimitiveBatchBase 69 | { 70 | static const size_t DefaultBatchSize = 2048; 71 | 72 | public: 73 | PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, size_t maxVertices = DefaultBatchSize) 74 | : PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex)) 75 | { } 76 | 77 | PrimitiveBatch(PrimitiveBatch&& moveFrom) 78 | : PrimitiveBatchBase(std::move(moveFrom)) 79 | { } 80 | 81 | PrimitiveBatch& __cdecl operator= (PrimitiveBatch&& moveFrom) 82 | { 83 | PrimitiveBatchBase::operator=(std::move(moveFrom)); 84 | return *this; 85 | } 86 | 87 | 88 | // Similar to the D3D9 API DrawPrimitiveUP. 89 | void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount) 90 | { 91 | void* mappedVertices; 92 | 93 | PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices); 94 | 95 | memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); 96 | } 97 | 98 | 99 | // Similar to the D3D9 API DrawIndexedPrimitiveUP. 100 | void __cdecl DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices, size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount) 101 | { 102 | void* mappedVertices; 103 | 104 | PrimitiveBatchBase::Draw(topology, true, indices, indexCount, vertexCount, &mappedVertices); 105 | 106 | memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); 107 | } 108 | 109 | 110 | void __cdecl DrawLine(TVertex const& v1, TVertex const& v2) 111 | { 112 | TVertex* mappedVertices; 113 | 114 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast(&mappedVertices)); 115 | 116 | mappedVertices[0] = v1; 117 | mappedVertices[1] = v2; 118 | } 119 | 120 | 121 | void __cdecl DrawTriangle(TVertex const& v1, TVertex const& v2, TVertex const& v3) 122 | { 123 | TVertex* mappedVertices; 124 | 125 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, reinterpret_cast(&mappedVertices)); 126 | 127 | mappedVertices[0] = v1; 128 | mappedVertices[1] = v2; 129 | mappedVertices[2] = v3; 130 | } 131 | 132 | 133 | void __cdecl DrawQuad(TVertex const& v1, TVertex const& v2, TVertex const& v3, TVertex const& v4) 134 | { 135 | static const uint16_t quadIndices[] = { 0, 1, 2, 0, 2, 3 }; 136 | 137 | TVertex* mappedVertices; 138 | 139 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, reinterpret_cast(&mappedVertices)); 140 | 141 | mappedVertices[0] = v1; 142 | mappedVertices[1] = v2; 143 | mappedVertices[2] = v3; 144 | mappedVertices[3] = v4; 145 | } 146 | }; 147 | } 148 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/ScreenGrab.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: ScreenGrab.h 3 | // 4 | // Function for capturing a 2D texture and saving it to a file (aka a 'screenshot' 5 | // when used on a Direct3D 11 Render Target). 6 | // 7 | // Note these functions are useful as a light-weight runtime screen grabber. For 8 | // full-featured texture capture, DDS writer, and texture processing pipeline, 9 | // see the 'Texconv' sample and the 'DirectXTex' library. 10 | // 11 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 12 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 13 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 14 | // PARTICULAR PURPOSE. 15 | // 16 | // Copyright (c) Microsoft Corporation. All rights reserved. 17 | // 18 | // http://go.microsoft.com/fwlink/?LinkId=248926 19 | // http://go.microsoft.com/fwlink/?LinkId=248929 20 | //-------------------------------------------------------------------------------------- 21 | 22 | #pragma once 23 | 24 | #if defined(_XBOX_ONE) && defined(_TITLE) 25 | #include 26 | #else 27 | #include 28 | #endif 29 | 30 | #include 31 | 32 | #pragma warning(push) 33 | #pragma warning(disable : 4005) 34 | #include 35 | #pragma warning(pop) 36 | 37 | #include 38 | 39 | // VS 2010 doesn't support explicit calling convention for std::function 40 | #ifndef DIRECTX_STD_CALLCONV 41 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 42 | #define DIRECTX_STD_CALLCONV 43 | #else 44 | #define DIRECTX_STD_CALLCONV __cdecl 45 | #endif 46 | #endif 47 | 48 | namespace DirectX 49 | { 50 | HRESULT __cdecl SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, 51 | _In_ ID3D11Resource* pSource, 52 | _In_z_ LPCWSTR fileName ); 53 | 54 | #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (_WIN32_WINNT > _WIN32_WINNT_WIN8) 55 | 56 | HRESULT __cdecl SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, 57 | _In_ ID3D11Resource* pSource, 58 | _In_ REFGUID guidContainerFormat, 59 | _In_z_ LPCWSTR fileName, 60 | _In_opt_ const GUID* targetFormat = nullptr, 61 | _In_opt_ std::function setCustomProps = nullptr ); 62 | 63 | #endif 64 | } -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/SpriteBatch.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: SpriteBatch.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | // VS 2010 doesn't support explicit calling convention for std::function 28 | #ifndef DIRECTX_STD_CALLCONV 29 | #if defined(_MSC_VER) && (_MSC_VER < 1700) 30 | #define DIRECTX_STD_CALLCONV 31 | #else 32 | #define DIRECTX_STD_CALLCONV __cdecl 33 | #endif 34 | #endif 35 | 36 | namespace DirectX 37 | { 38 | #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) 39 | #define XM_CALLCONV __fastcall 40 | typedef const XMVECTOR& HXMVECTOR; 41 | typedef const XMMATRIX& FXMMATRIX; 42 | #endif 43 | 44 | enum SpriteSortMode 45 | { 46 | SpriteSortMode_Deferred, 47 | SpriteSortMode_Immediate, 48 | SpriteSortMode_Texture, 49 | SpriteSortMode_BackToFront, 50 | SpriteSortMode_FrontToBack, 51 | }; 52 | 53 | 54 | enum SpriteEffects 55 | { 56 | SpriteEffects_None = 0, 57 | SpriteEffects_FlipHorizontally = 1, 58 | SpriteEffects_FlipVertically = 2, 59 | SpriteEffects_FlipBoth = SpriteEffects_FlipHorizontally | SpriteEffects_FlipVertically, 60 | }; 61 | 62 | 63 | class SpriteBatch 64 | { 65 | public: 66 | explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext); 67 | SpriteBatch(SpriteBatch&& moveFrom); 68 | SpriteBatch& operator= (SpriteBatch&& moveFrom); 69 | virtual ~SpriteBatch(); 70 | 71 | // Begin/End a batch of sprite drawing operations. 72 | void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred, _In_opt_ ID3D11BlendState* blendState = nullptr, _In_opt_ ID3D11SamplerState* samplerState = nullptr, _In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr, _In_opt_ ID3D11RasterizerState* rasterizerState = nullptr, 73 | _In_opt_ std::function setCustomShaders = nullptr, FXMMATRIX transformMatrix = MatrixIdentity); 74 | void __cdecl End(); 75 | 76 | // Draw overloads specifying position, origin and scale as XMFLOAT2. 77 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color = Colors::White); 78 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 79 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 80 | 81 | // Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR. 82 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color = Colors::White); 83 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 84 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 85 | 86 | // Draw overloads specifying position as a RECT. 87 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color = Colors::White); 88 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 89 | 90 | // Rotation mode to be applied to the sprite transformation 91 | void __cdecl SetRotation( DXGI_MODE_ROTATION mode ); 92 | DXGI_MODE_ROTATION __cdecl GetRotation() const; 93 | 94 | // Set viewport for sprite transformation 95 | void __cdecl SetViewport( const D3D11_VIEWPORT& viewPort ); 96 | 97 | private: 98 | // Private implementation. 99 | class Impl; 100 | 101 | std::unique_ptr pImpl; 102 | 103 | static const XMMATRIX MatrixIdentity; 104 | static const XMFLOAT2 Float2Zero; 105 | 106 | // Prevent copying. 107 | SpriteBatch(SpriteBatch const&); 108 | SpriteBatch& operator= (SpriteBatch const&); 109 | }; 110 | } 111 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/SpriteFont.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: SpriteFont.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #include "SpriteBatch.h" 17 | 18 | 19 | namespace DirectX 20 | { 21 | class SpriteFont 22 | { 23 | public: 24 | struct Glyph; 25 | 26 | SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName); 27 | SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize); 28 | SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing); 29 | 30 | SpriteFont(SpriteFont&& moveFrom); 31 | SpriteFont& operator= (SpriteFont&& moveFrom); 32 | virtual ~SpriteFont(); 33 | 34 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 35 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 36 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 37 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 38 | 39 | XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) const; 40 | 41 | float __cdecl GetLineSpacing() const; 42 | void __cdecl SetLineSpacing(float spacing); 43 | 44 | wchar_t __cdecl GetDefaultCharacter() const; 45 | void __cdecl SetDefaultCharacter(wchar_t character); 46 | 47 | bool __cdecl ContainsCharacter(wchar_t character) const; 48 | 49 | 50 | // Describes a single character glyph. 51 | struct Glyph 52 | { 53 | uint32_t Character; 54 | RECT Subrect; 55 | float XOffset; 56 | float YOffset; 57 | float XAdvance; 58 | }; 59 | 60 | 61 | private: 62 | // Private implementation. 63 | class Impl; 64 | 65 | std::unique_ptr pImpl; 66 | 67 | static const XMFLOAT2 Float2Zero; 68 | 69 | // Prevent copying. 70 | SpriteFont(SpriteFont const&); 71 | SpriteFont& operator= (SpriteFont const&); 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/VertexTypes.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: VertexTypes.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved. 10 | // 11 | // http://go.microsoft.com/fwlink/?LinkId=248929 12 | //-------------------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | #if defined(_XBOX_ONE) && defined(_TITLE) 17 | #include 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | 24 | 25 | namespace DirectX 26 | { 27 | #if (DIRECTX_MATH_VERSION < 305) && !defined(XM_CALLCONV) 28 | #define XM_CALLCONV __fastcall 29 | typedef const XMVECTOR& HXMVECTOR; 30 | typedef const XMMATRIX& FXMMATRIX; 31 | #endif 32 | 33 | // Vertex struct holding position and color information. 34 | struct VertexPositionColor 35 | { 36 | VertexPositionColor() 37 | { } 38 | 39 | VertexPositionColor(XMFLOAT3 const& position, XMFLOAT4 const& color) 40 | : position(position), 41 | color(color) 42 | { } 43 | 44 | VertexPositionColor(FXMVECTOR position, FXMVECTOR color) 45 | { 46 | XMStoreFloat3(&this->position, position); 47 | XMStoreFloat4(&this->color, color); 48 | } 49 | 50 | XMFLOAT3 position; 51 | XMFLOAT4 color; 52 | 53 | static const int InputElementCount = 2; 54 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 55 | }; 56 | 57 | 58 | // Vertex struct holding position and texture mapping information. 59 | struct VertexPositionTexture 60 | { 61 | VertexPositionTexture() 62 | { } 63 | 64 | VertexPositionTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate) 65 | : position(position), 66 | textureCoordinate(textureCoordinate) 67 | { } 68 | 69 | VertexPositionTexture(FXMVECTOR position, FXMVECTOR textureCoordinate) 70 | { 71 | XMStoreFloat3(&this->position, position); 72 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate); 73 | } 74 | 75 | XMFLOAT3 position; 76 | XMFLOAT2 textureCoordinate; 77 | 78 | static const int InputElementCount = 2; 79 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 80 | }; 81 | 82 | 83 | // Vertex struct holding position and normal vector. 84 | struct VertexPositionNormal 85 | { 86 | VertexPositionNormal() 87 | { } 88 | 89 | VertexPositionNormal(XMFLOAT3 const& position, XMFLOAT3 const& normal) 90 | : position(position), 91 | normal(normal) 92 | { } 93 | 94 | VertexPositionNormal(FXMVECTOR position, FXMVECTOR normal) 95 | { 96 | XMStoreFloat3(&this->position, position); 97 | XMStoreFloat3(&this->normal, normal); 98 | } 99 | 100 | XMFLOAT3 position; 101 | XMFLOAT3 normal; 102 | 103 | static const int InputElementCount = 2; 104 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 105 | }; 106 | 107 | 108 | // Vertex struct holding position, color, and texture mapping information. 109 | struct VertexPositionColorTexture 110 | { 111 | VertexPositionColorTexture() 112 | { } 113 | 114 | VertexPositionColorTexture(XMFLOAT3 const& position, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) 115 | : position(position), 116 | color(color), 117 | textureCoordinate(textureCoordinate) 118 | { } 119 | 120 | VertexPositionColorTexture(FXMVECTOR position, FXMVECTOR color, FXMVECTOR textureCoordinate) 121 | { 122 | XMStoreFloat3(&this->position, position); 123 | XMStoreFloat4(&this->color, color); 124 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate); 125 | } 126 | 127 | XMFLOAT3 position; 128 | XMFLOAT4 color; 129 | XMFLOAT2 textureCoordinate; 130 | 131 | static const int InputElementCount = 3; 132 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 133 | }; 134 | 135 | 136 | // Vertex struct holding position, normal vector, and color information. 137 | struct VertexPositionNormalColor 138 | { 139 | VertexPositionNormalColor() 140 | { } 141 | 142 | VertexPositionNormalColor(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color) 143 | : position(position), 144 | normal(normal), 145 | color(color) 146 | { } 147 | 148 | VertexPositionNormalColor(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color) 149 | { 150 | XMStoreFloat3(&this->position, position); 151 | XMStoreFloat3(&this->normal, normal); 152 | XMStoreFloat4(&this->color, color); 153 | } 154 | 155 | XMFLOAT3 position; 156 | XMFLOAT3 normal; 157 | XMFLOAT4 color; 158 | 159 | static const int InputElementCount = 3; 160 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 161 | }; 162 | 163 | 164 | // Vertex struct holding position, normal vector, and texture mapping information. 165 | struct VertexPositionNormalTexture 166 | { 167 | VertexPositionNormalTexture() 168 | { } 169 | 170 | VertexPositionNormalTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT2 const& textureCoordinate) 171 | : position(position), 172 | normal(normal), 173 | textureCoordinate(textureCoordinate) 174 | { } 175 | 176 | VertexPositionNormalTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR textureCoordinate) 177 | { 178 | XMStoreFloat3(&this->position, position); 179 | XMStoreFloat3(&this->normal, normal); 180 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate); 181 | } 182 | 183 | XMFLOAT3 position; 184 | XMFLOAT3 normal; 185 | XMFLOAT2 textureCoordinate; 186 | 187 | static const int InputElementCount = 3; 188 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 189 | }; 190 | 191 | 192 | // Vertex struct holding position, normal vector, color, and texture mapping information. 193 | struct VertexPositionNormalColorTexture 194 | { 195 | VertexPositionNormalColorTexture() 196 | { } 197 | 198 | VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) 199 | : position(position), 200 | normal(normal), 201 | color(color), 202 | textureCoordinate(textureCoordinate) 203 | { } 204 | 205 | VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color, CXMVECTOR textureCoordinate) 206 | { 207 | XMStoreFloat3(&this->position, position); 208 | XMStoreFloat3(&this->normal, normal); 209 | XMStoreFloat4(&this->color, color); 210 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate); 211 | } 212 | 213 | XMFLOAT3 position; 214 | XMFLOAT3 normal; 215 | XMFLOAT4 color; 216 | XMFLOAT2 textureCoordinate; 217 | 218 | static const int InputElementCount = 4; 219 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 220 | }; 221 | 222 | 223 | // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, 224 | // tangent, color (RGBA), and texture mapping information 225 | struct VertexPositionNormalTangentColorTexture 226 | { 227 | VertexPositionNormalTangentColorTexture() 228 | { } 229 | 230 | XMFLOAT3 position; 231 | XMFLOAT3 normal; 232 | XMFLOAT4 tangent; 233 | uint32_t color; 234 | XMFLOAT2 textureCoordinate; 235 | 236 | VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, XMFLOAT2 const& textureCoordinate) 237 | : position(position), 238 | normal(normal), 239 | tangent(tangent), 240 | color(rgba), 241 | textureCoordinate(textureCoordinate) 242 | { 243 | } 244 | 245 | VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate) 246 | : color(rgba) 247 | { 248 | XMStoreFloat3(&this->position, position); 249 | XMStoreFloat3(&this->normal, normal); 250 | XMStoreFloat4(&this->tangent, tangent); 251 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate); 252 | } 253 | 254 | VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate) 255 | : position(position), 256 | normal(normal), 257 | tangent(tangent), 258 | textureCoordinate(textureCoordinate) 259 | { 260 | SetColor( color ); 261 | } 262 | 263 | VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate) 264 | { 265 | XMStoreFloat3(&this->position, position); 266 | XMStoreFloat3(&this->normal, normal); 267 | XMStoreFloat4(&this->tangent, tangent); 268 | XMStoreFloat2(&this->textureCoordinate, textureCoordinate); 269 | 270 | SetColor( color ); 271 | } 272 | 273 | void __cdecl SetColor( XMFLOAT4 const& icolor ) { SetColor( XMLoadFloat4( &icolor ) ); } 274 | void XM_CALLCONV SetColor( FXMVECTOR icolor ); 275 | 276 | static const int InputElementCount = 5; 277 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 278 | }; 279 | 280 | 281 | // Vertex struct for Visual Studio Shader Designer (DGSL) holding position, normal, 282 | // tangent, color (RGBA), texture mapping information, and skinning weights 283 | struct VertexPositionNormalTangentColorTextureSkinning : public VertexPositionNormalTangentColorTexture 284 | { 285 | VertexPositionNormalTangentColorTextureSkinning() 286 | { } 287 | 288 | uint32_t indices; 289 | uint32_t weights; 290 | 291 | VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, 292 | XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights) 293 | : VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate) 294 | { 295 | SetBlendIndices( indices ); 296 | SetBlendWeights( weights ); 297 | } 298 | 299 | VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate, 300 | XMUINT4 const& indices, CXMVECTOR weights) 301 | : VertexPositionNormalTangentColorTexture(position,normal,tangent,rgba,textureCoordinate) 302 | { 303 | SetBlendIndices( indices ); 304 | SetBlendWeights( weights ); 305 | } 306 | 307 | VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, 308 | XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights) 309 | : VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate) 310 | { 311 | SetBlendIndices( indices ); 312 | SetBlendWeights( weights ); 313 | } 314 | 315 | VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate, 316 | XMUINT4 const& indices, CXMVECTOR weights) 317 | : VertexPositionNormalTangentColorTexture(position,normal,tangent,color,textureCoordinate) 318 | { 319 | SetBlendIndices( indices ); 320 | SetBlendWeights( weights ); 321 | } 322 | 323 | void __cdecl SetBlendIndices( XMUINT4 const& iindices ); 324 | 325 | void __cdecl SetBlendWeights( XMFLOAT4 const& iweights ) { SetBlendWeights( XMLoadFloat4( &iweights ) ); } 326 | void XM_CALLCONV SetBlendWeights( FXMVECTOR iweights ); 327 | 328 | static const int InputElementCount = 7; 329 | static const D3D11_INPUT_ELEMENT_DESC InputElements[InputElementCount]; 330 | }; 331 | } 332 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/WICTextureLoader.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: WICTextureLoader.h 3 | // 4 | // Function for loading a WIC image and creating a Direct3D 11 runtime texture for it 5 | // (auto-generating mipmaps if possible) 6 | // 7 | // Note: Assumes application has already called CoInitializeEx 8 | // 9 | // Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for 10 | // auto-gen mipmap support. 11 | // 12 | // Note these functions are useful for images created as simple 2D textures. For 13 | // more complex resources, DDSTextureLoader is an excellent light-weight runtime loader. 14 | // For a full-featured DDS file reader, writer, and texture processing pipeline see 15 | // the 'Texconv' sample and the 'DirectXTex' library. 16 | // 17 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 18 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 19 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 20 | // PARTICULAR PURPOSE. 21 | // 22 | // Copyright (c) Microsoft Corporation. All rights reserved. 23 | // 24 | // http://go.microsoft.com/fwlink/?LinkId=248926 25 | // http://go.microsoft.com/fwlink/?LinkId=248929 26 | //-------------------------------------------------------------------------------------- 27 | 28 | #pragma once 29 | 30 | #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (_WIN32_WINNT <= _WIN32_WINNT_WIN8) 31 | #error WIC is not supported on Windows Phone 8.0 32 | #endif 33 | 34 | #if defined(_XBOX_ONE) && defined(_TITLE) 35 | #include 36 | #else 37 | #include 38 | #endif 39 | 40 | #pragma warning(push) 41 | #pragma warning(disable : 4005) 42 | #include 43 | #pragma warning(pop) 44 | 45 | namespace DirectX 46 | { 47 | // Standard version 48 | HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice, 49 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 50 | _In_ size_t wicDataSize, 51 | _Out_opt_ ID3D11Resource** texture, 52 | _Out_opt_ ID3D11ShaderResourceView** textureView, 53 | _In_ size_t maxsize = 0 54 | ); 55 | 56 | HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice, 57 | _In_z_ const wchar_t* szFileName, 58 | _Out_opt_ ID3D11Resource** texture, 59 | _Out_opt_ ID3D11ShaderResourceView** textureView, 60 | _In_ size_t maxsize = 0 61 | ); 62 | 63 | // Standard version with optional auto-gen mipmap support 64 | #if defined(_XBOX_ONE) && defined(_TITLE) 65 | HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice, 66 | _In_opt_ ID3D11DeviceContextX* d3dContext, 67 | #else 68 | HRESULT __cdecl CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice, 69 | _In_opt_ ID3D11DeviceContext* d3dContext, 70 | #endif 71 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 72 | _In_ size_t wicDataSize, 73 | _Out_opt_ ID3D11Resource** texture, 74 | _Out_opt_ ID3D11ShaderResourceView** textureView, 75 | _In_ size_t maxsize = 0 76 | ); 77 | 78 | #if defined(_XBOX_ONE) && defined(_TITLE) 79 | HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, 80 | _In_opt_ ID3D11DeviceContextX* d3dContext, 81 | #else 82 | HRESULT __cdecl CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice, 83 | _In_opt_ ID3D11DeviceContext* d3dContext, 84 | #endif 85 | _In_z_ const wchar_t* szFileName, 86 | _Out_opt_ ID3D11Resource** texture, 87 | _Out_opt_ ID3D11ShaderResourceView** textureView, 88 | _In_ size_t maxsize = 0 89 | ); 90 | 91 | // Extended version 92 | HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, 93 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 94 | _In_ size_t wicDataSize, 95 | _In_ size_t maxsize, 96 | _In_ D3D11_USAGE usage, 97 | _In_ unsigned int bindFlags, 98 | _In_ unsigned int cpuAccessFlags, 99 | _In_ unsigned int miscFlags, 100 | _In_ bool forceSRGB, 101 | _Out_opt_ ID3D11Resource** texture, 102 | _Out_opt_ ID3D11ShaderResourceView** textureView 103 | ); 104 | 105 | HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice, 106 | _In_z_ const wchar_t* szFileName, 107 | _In_ size_t maxsize, 108 | _In_ D3D11_USAGE usage, 109 | _In_ unsigned int bindFlags, 110 | _In_ unsigned int cpuAccessFlags, 111 | _In_ unsigned int miscFlags, 112 | _In_ bool forceSRGB, 113 | _Out_opt_ ID3D11Resource** texture, 114 | _Out_opt_ ID3D11ShaderResourceView** textureView 115 | ); 116 | 117 | // Extended version with optional auto-gen mipmap support 118 | #if defined(_XBOX_ONE) && defined(_TITLE) 119 | HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11DeviceX* d3dDevice, 120 | _In_opt_ ID3D11DeviceContextX* d3dContext, 121 | #else 122 | HRESULT __cdecl CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, 123 | _In_opt_ ID3D11DeviceContext* d3dContext, 124 | #endif 125 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 126 | _In_ size_t wicDataSize, 127 | _In_ size_t maxsize, 128 | _In_ D3D11_USAGE usage, 129 | _In_ unsigned int bindFlags, 130 | _In_ unsigned int cpuAccessFlags, 131 | _In_ unsigned int miscFlags, 132 | _In_ bool forceSRGB, 133 | _Out_opt_ ID3D11Resource** texture, 134 | _Out_opt_ ID3D11ShaderResourceView** textureView 135 | ); 136 | 137 | #if defined(_XBOX_ONE) && defined(_TITLE) 138 | HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11DeviceX* d3dDevice, 139 | _In_opt_ ID3D11DeviceContextX* d3dContext, 140 | #else 141 | HRESULT __cdecl CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice, 142 | _In_opt_ ID3D11DeviceContext* d3dContext, 143 | #endif 144 | _In_z_ const wchar_t* szFileName, 145 | _In_ size_t maxsize, 146 | _In_ D3D11_USAGE usage, 147 | _In_ unsigned int bindFlags, 148 | _In_ unsigned int cpuAccessFlags, 149 | _In_ unsigned int miscFlags, 150 | _In_ bool forceSRGB, 151 | _Out_opt_ ID3D11Resource** texture, 152 | _Out_opt_ ID3D11ShaderResourceView** textureView 153 | ); 154 | } -------------------------------------------------------------------------------- /Volumetric Explosion Sample/DirectXTK/Inc/XboxDDSTextureLoader.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: XboxDDSTextureLoader.h 3 | // 4 | // Functions for loading a DDS texture using the XBOX extended header and creating a 5 | // Direct3D11.X runtime resource for it via the CreatePlacement APIs 6 | // 7 | // Note these functions will not load standard DDS files. Use the DDSTextureLoader 8 | // module in the DirectXTex package or as part of the DirectXTK library to load 9 | // these files which use standard Direct3D 11 resource creation APIs. 10 | // 11 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 12 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 13 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 14 | // PARTICULAR PURPOSE. 15 | // 16 | // Copyright (c) Microsoft Corporation. All rights reserved. 17 | // 18 | // http://go.microsoft.com/fwlink/?LinkId=248926 19 | // http://go.microsoft.com/fwlink/?LinkId=248929 20 | //-------------------------------------------------------------------------------------- 21 | 22 | #pragma once 23 | 24 | #if !defined(_XBOX_ONE) || !defined(_TITLE) 25 | #error This module only supports Xbox One exclusive apps 26 | #endif 27 | 28 | #include 29 | 30 | #include 31 | 32 | namespace Xbox 33 | { 34 | enum DDS_ALPHA_MODE 35 | { 36 | DDS_ALPHA_MODE_UNKNOWN = 0, 37 | DDS_ALPHA_MODE_STRAIGHT = 1, 38 | DDS_ALPHA_MODE_PREMULTIPLIED = 2, 39 | DDS_ALPHA_MODE_OPAQUE = 3, 40 | DDS_ALPHA_MODE_CUSTOM = 4, 41 | }; 42 | 43 | HRESULT __cdecl CreateDDSTextureFromMemory( _In_ ID3D11DeviceX* d3dDevice, 44 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 45 | _In_ size_t ddsDataSize, 46 | _Outptr_opt_ ID3D11Resource** texture, 47 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 48 | _Outptr_ void** grfxMemory, 49 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, 50 | _In_ bool forceSRGB = false 51 | ); 52 | 53 | HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, 54 | _In_z_ const wchar_t* szFileName, 55 | _Outptr_opt_ ID3D11Resource** texture, 56 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 57 | _Outptr_ void** grfxMemory, 58 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, 59 | _In_ bool forceSRGB = false 60 | ); 61 | } -------------------------------------------------------------------------------- /Volumetric Explosion Sample/Main.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // Realistic Volumetric Explosions in Games. 3 | // GPU Pro 6 4 | // Alex Dunn 5 | // 6 | // This sample demonstrates how to render volumetric explosions in games 7 | // using DirectX 11. The source code presented below forms the basis of 8 | // the matching chapter in the book GPU Pro 6. 9 | //-------------------------------------------------------------------------------------- 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "Common.h" 22 | 23 | using namespace DirectX; 24 | using namespace DirectX::PackedVector; 25 | 26 | //-------------------------------------------------------------------------------------- 27 | // Global Variables 28 | //-------------------------------------------------------------------------------------- 29 | HINSTANCE g_hInst = nullptr; 30 | HWND g_hWnd = nullptr; 31 | D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; 32 | D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; 33 | ID3D11Device* g_pd3dDevice = nullptr; 34 | ID3D11Device1* g_pd3dDevice1 = nullptr; 35 | ID3D11DeviceContext* g_pImmediateContext = nullptr; 36 | ID3D11DeviceContext1* g_pImmediateContext1 = nullptr; 37 | IDXGISwapChain* g_pSwapChain = nullptr; 38 | IDXGISwapChain1* g_pSwapChain1 = nullptr; 39 | ID3D11RenderTargetView* g_pRenderTargetView = nullptr; 40 | 41 | ID3D11Buffer* g_pExplosionParamsCB = nullptr; 42 | ID3D11ShaderResourceView* g_pNoiseVolumeSRV = nullptr; 43 | ID3D11ShaderResourceView* g_pGradientSRV = nullptr; 44 | ID3D11VertexShader* g_pRenderExplosionVS = nullptr; 45 | ID3D11HullShader* g_pRenderExplosionHS = nullptr; 46 | ID3D11DomainShader* g_pRenderExplosionDS = nullptr; 47 | ID3D11PixelShader* g_pRenderExplosionPS = nullptr; 48 | ID3D11InputLayout* g_pExplosionLayout = nullptr; 49 | ID3D11SamplerState* g_pSamplerClampedLinear = nullptr; 50 | ID3D11SamplerState* g_pSamplerWrappedLinear = nullptr; 51 | 52 | ID3D11DepthStencilState* g_pTestWriteDepth = nullptr; 53 | ID3D11BlendState* g_pOverBlendState = nullptr; 54 | 55 | // Explosion parameters. 56 | const XMFLOAT3 kNoiseAnimationSpeed(0.0f, 0.02f, 0.0f); 57 | const float kNoiseInitialAmplitude = 3.0f; 58 | const UINT kMaxNumSteps = 256; 59 | const UINT kNumHullSteps = 2; 60 | const float kStepSize = 0.04f; 61 | const UINT kNumOctaves = 4; 62 | const UINT kNumHullOctaves = 2; 63 | const float kSkinThicknessBias = 0.6f; 64 | const float kTessellationFactor = 16; 65 | float g_MaxSkinThickness; 66 | float g_MaxNoiseDisplacement; 67 | static bool g_EnableHullShrinking = true; 68 | static float g_EdgeSoftness = 0.05f; 69 | static float g_NoiseScale = 0.04f; 70 | static float g_ExplosionRadius = 4.0f; 71 | static float g_DisplacementAmount = 1.75f; 72 | static XMFLOAT2 g_UvScaleBias(2.1f, 0.35f); 73 | static float g_NoiseAmplitudeFactor = 0.4f; 74 | static float g_NoiseFrequencyFactor = 3.0f; 75 | 76 | // Camera variables. 77 | const UINT kResolutionX = 800; 78 | const UINT kResolutionY = 640; 79 | const float kNearClip = 0.01f; 80 | const float kFarClip = 20.0f; 81 | const XMFLOAT3 kEyeLookAtWS = XMFLOAT3(0.0f, 0.0f, 0.0f); 82 | XMFLOAT3 g_EyePositionWS; 83 | XMFLOAT3 g_EyeForwardWS; 84 | XMMATRIX g_WorldToProjectionMatrix, g_ProjectionToWorldMatrix, g_InvProjMatrix, g_ViewToWorldMatrix; 85 | XMFLOAT4X4 g_ViewMatrix, g_ProjMatrix; 86 | XMFLOAT4 g_ProjectionParams; 87 | POINT g_LastMousePos; 88 | float g_CameraTheta = 0, g_CameraPhi = 0, g_CameraRadius = 10; 89 | 90 | // Timer Variables 91 | __int64 g_CounterStart = 0; 92 | double g_CountsPerSecond = 0.0; 93 | double g_ElapsedTime = 0.0; 94 | 95 | TwBar* g_pUI; 96 | 97 | enum PrimitiveType 98 | { 99 | kPrimitiveSphere, 100 | kPrimitiveCylinder, 101 | kPrimitiveCone, 102 | kPrimitiveTorus, 103 | kPrimitiveBox 104 | } g_Primitive = kPrimitiveSphere; 105 | 106 | //-------------------------------------------------------------------------------------- 107 | // Forward declarations 108 | //-------------------------------------------------------------------------------------- 109 | HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow ); 110 | HRESULT InitDevice(); 111 | void InitUI(); 112 | void CleanupDevice(); 113 | LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); 114 | void Render(); 115 | void StartTimer(); 116 | double GetTime(); 117 | void OnMouseDown(int x, int y); 118 | void OnMouseUp(); 119 | void OnMouseMove(WPARAM btnState, int x, int y); 120 | void UpdateViewMatrix(); 121 | 122 | //-------------------------------------------------------------------------------------- 123 | // Entry point to the program. Initializes everything and goes into a message processing 124 | // loop. Idle time is used to render the scene. 125 | //-------------------------------------------------------------------------------------- 126 | int WINAPI wWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow ) 127 | { 128 | UNREFERENCED_PARAMETER( hPrevInstance ); 129 | UNREFERENCED_PARAMETER( lpCmdLine ); 130 | 131 | if( FAILED( InitWindow( hInstance, nCmdShow ) ) ) 132 | return 0; 133 | 134 | if( FAILED( InitDevice() ) ) 135 | { 136 | CleanupDevice(); 137 | return 0; 138 | } 139 | 140 | StartTimer(); 141 | 142 | TwInit(TW_DIRECT3D11, g_pd3dDevice); 143 | TwWindowSize(kResolutionX, kResolutionY); 144 | 145 | InitUI(); 146 | 147 | // Main message loop 148 | MSG msg = {0}; 149 | while( WM_QUIT != msg.message ) 150 | { 151 | if( PeekMessage( &msg, nullptr, 0, 0, PM_REMOVE ) ) 152 | { 153 | TranslateMessage( &msg ); 154 | DispatchMessage( &msg ); 155 | } 156 | else 157 | { 158 | // Update scene timer 159 | g_ElapsedTime = GetTime(); 160 | 161 | Render(); 162 | } 163 | } 164 | 165 | TwTerminate(); 166 | 167 | CleanupDevice(); 168 | 169 | return ( int )msg.wParam; 170 | } 171 | 172 | 173 | //-------------------------------------------------------------------------------------- 174 | // Register class and create window 175 | //-------------------------------------------------------------------------------------- 176 | HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow ) 177 | { 178 | // Register class 179 | WNDCLASSEX wcex; 180 | wcex.cbSize = sizeof( WNDCLASSEX ); 181 | wcex.style = CS_HREDRAW | CS_VREDRAW; 182 | wcex.lpfnWndProc = WndProc; 183 | wcex.cbClsExtra = 0; 184 | wcex.cbWndExtra = 0; 185 | wcex.hInstance = hInstance; 186 | wcex.hIcon = LoadIcon( hInstance, "directx.ico" ); 187 | wcex.hCursor = LoadCursor( nullptr, IDC_ARROW ); 188 | wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 ); 189 | wcex.lpszMenuName = nullptr; 190 | wcex.lpszClassName = "VolumetricExplosionSample"; 191 | wcex.hIconSm = LoadIcon( wcex.hInstance, "directx.ico" ); 192 | if( !RegisterClassEx( &wcex ) ) return E_FAIL; 193 | 194 | // Create window 195 | g_hInst = hInstance; 196 | RECT rc = { 0, 0, kResolutionX, kResolutionY }; 197 | AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE ); 198 | g_hWnd = CreateWindow( "VolumetricExplosionSample", "GPU Pro 6 - Volumetric Explosions", 199 | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 200 | CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, hInstance, 201 | nullptr ); 202 | 203 | if( !g_hWnd ) return E_FAIL; 204 | 205 | ShowWindow( g_hWnd, nCmdShow ); 206 | 207 | return S_OK; 208 | } 209 | 210 | //-------------------------------------------------------------------------------------- 211 | // Create Direct3D device and swap chain 212 | //-------------------------------------------------------------------------------------- 213 | HRESULT InitDevice() 214 | { 215 | HRESULT hr = S_OK; 216 | 217 | RECT rc; 218 | GetClientRect( g_hWnd, &rc ); 219 | UINT width = rc.right - rc.left; 220 | UINT height = rc.bottom - rc.top; 221 | 222 | UINT createDeviceFlags = 0; 223 | #ifdef _DEBUG 224 | createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; 225 | #endif 226 | 227 | D3D_DRIVER_TYPE driverTypes[] = 228 | { 229 | D3D_DRIVER_TYPE_HARDWARE, 230 | D3D_DRIVER_TYPE_WARP, 231 | D3D_DRIVER_TYPE_REFERENCE, 232 | }; 233 | UINT numDriverTypes = ARRAYSIZE( driverTypes ); 234 | 235 | D3D_FEATURE_LEVEL featureLevels[] = 236 | { 237 | D3D_FEATURE_LEVEL_11_1, 238 | D3D_FEATURE_LEVEL_11_0, 239 | D3D_FEATURE_LEVEL_10_1, 240 | D3D_FEATURE_LEVEL_10_0, 241 | }; 242 | UINT numFeatureLevels = ARRAYSIZE( featureLevels ); 243 | 244 | for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) 245 | { 246 | g_driverType = driverTypes[driverTypeIndex]; 247 | hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, 248 | D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext ); 249 | 250 | if ( hr == E_INVALIDARG ) 251 | { 252 | // DirectX 11.0 platforms will not recognize D3D_FEATURE_LEVEL_11_1 so we need to retry without it 253 | hr = D3D11CreateDevice( nullptr, g_driverType, nullptr, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1, 254 | D3D11_SDK_VERSION, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext ); 255 | } 256 | 257 | if( SUCCEEDED( hr ) ) 258 | break; 259 | } 260 | if( FAILED( hr ) ) 261 | return hr; 262 | 263 | // Obtain DXGI factory from device (since we used nullptr for pAdapter above) 264 | IDXGIFactory1* dxgiFactory = nullptr; 265 | { 266 | IDXGIDevice* dxgiDevice = nullptr; 267 | hr = g_pd3dDevice->QueryInterface( __uuidof(IDXGIDevice), reinterpret_cast(&dxgiDevice) ); 268 | if (SUCCEEDED(hr)) 269 | { 270 | IDXGIAdapter* adapter = nullptr; 271 | hr = dxgiDevice->GetAdapter(&adapter); 272 | if (SUCCEEDED(hr)) 273 | { 274 | hr = adapter->GetParent( __uuidof(IDXGIFactory1), reinterpret_cast(&dxgiFactory) ); 275 | adapter->Release(); 276 | } 277 | dxgiDevice->Release(); 278 | } 279 | } 280 | if (FAILED(hr)) 281 | return hr; 282 | 283 | // Create swap chain 284 | IDXGIFactory2* dxgiFactory2 = nullptr; 285 | hr = dxgiFactory->QueryInterface( __uuidof(IDXGIFactory2), reinterpret_cast(&dxgiFactory2) ); 286 | if ( dxgiFactory2 ) 287 | { 288 | // DirectX 11.1 or later 289 | hr = g_pd3dDevice->QueryInterface( __uuidof(ID3D11Device1), reinterpret_cast(&g_pd3dDevice1) ); 290 | if (SUCCEEDED(hr)) 291 | { 292 | (void) g_pImmediateContext->QueryInterface( __uuidof(ID3D11DeviceContext1), reinterpret_cast(&g_pImmediateContext1) ); 293 | } 294 | 295 | DXGI_SWAP_CHAIN_DESC1 sd; 296 | ZeroMemory(&sd, sizeof(sd)); 297 | sd.Width = width; 298 | sd.Height = height; 299 | sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 300 | sd.SampleDesc.Count = 1; 301 | sd.SampleDesc.Quality = 0; 302 | sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 303 | sd.BufferCount = 1; 304 | 305 | hr = dxgiFactory2->CreateSwapChainForHwnd( g_pd3dDevice, g_hWnd, &sd, nullptr, nullptr, &g_pSwapChain1 ); 306 | if (SUCCEEDED(hr)) 307 | { 308 | hr = g_pSwapChain1->QueryInterface( __uuidof(IDXGISwapChain), reinterpret_cast(&g_pSwapChain) ); 309 | } 310 | 311 | dxgiFactory2->Release(); 312 | } 313 | else 314 | { 315 | // DirectX 11.0 systems 316 | DXGI_SWAP_CHAIN_DESC sd; 317 | ZeroMemory(&sd, sizeof(sd)); 318 | sd.BufferCount = 1; 319 | sd.BufferDesc.Width = width; 320 | sd.BufferDesc.Height = height; 321 | sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 322 | sd.BufferDesc.RefreshRate.Numerator = 60; 323 | sd.BufferDesc.RefreshRate.Denominator = 1; 324 | sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 325 | sd.OutputWindow = g_hWnd; 326 | sd.SampleDesc.Count = 1; 327 | sd.SampleDesc.Quality = 0; 328 | sd.Windowed = TRUE; 329 | 330 | hr = dxgiFactory->CreateSwapChain( g_pd3dDevice, &sd, &g_pSwapChain ); 331 | } 332 | 333 | // Note this tutorial doesn't handle full-screen swapchains so we block the ALT+ENTER shortcut 334 | dxgiFactory->MakeWindowAssociation( g_hWnd, DXGI_MWA_NO_ALT_ENTER ); 335 | 336 | dxgiFactory->Release(); 337 | 338 | if (FAILED(hr)) 339 | return hr; 340 | 341 | ID3D11Texture2D* pBackBuffer = nullptr; 342 | hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast( &pBackBuffer ) ); 343 | if( FAILED( hr ) ) return hr; 344 | 345 | hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, nullptr, &g_pRenderTargetView ); 346 | pBackBuffer->Release(); 347 | if( FAILED( hr ) ) return hr; 348 | 349 | ID3DBlob* pVSBlob = NULL; 350 | if( FAILED( hr = D3DReadFileToBlob( L"RenderExplosionVS.cso", &pVSBlob ) ) ) return hr; 351 | if( FAILED( hr = g_pd3dDevice->CreateVertexShader( pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), nullptr, &g_pRenderExplosionVS ) ) ) 352 | { 353 | pVSBlob->Release(); 354 | return hr; 355 | } 356 | 357 | D3D11_INPUT_ELEMENT_DESC layout[] = 358 | { 359 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 360 | }; 361 | UINT numElements = ARRAYSIZE( layout ); 362 | 363 | hr = g_pd3dDevice->CreateInputLayout( layout, numElements, pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), &g_pExplosionLayout ); 364 | pVSBlob->Release(); 365 | if( FAILED( hr ) ) return hr; 366 | 367 | ID3DBlob* pHSBlob = nullptr; 368 | if( FAILED( hr = D3DReadFileToBlob( L"RenderExplosionHS.cso", &pHSBlob ) ) ) return hr; 369 | hr = g_pd3dDevice->CreateHullShader( pHSBlob->GetBufferPointer(), pHSBlob->GetBufferSize(), nullptr, &g_pRenderExplosionHS ); 370 | pHSBlob->Release(); 371 | if( FAILED( hr ) ) return hr; 372 | 373 | ID3DBlob* pDSBlob = nullptr; 374 | if( FAILED( hr = D3DReadFileToBlob( L"RenderExplosionDS.cso", &pDSBlob ) ) ) return hr; 375 | hr = g_pd3dDevice->CreateDomainShader( pDSBlob->GetBufferPointer(), pDSBlob->GetBufferSize(), nullptr, &g_pRenderExplosionDS ); 376 | pDSBlob->Release(); 377 | if( FAILED( hr ) ) return hr; 378 | 379 | ID3DBlob* pPSBlob = nullptr; 380 | if( FAILED( hr = D3DReadFileToBlob( L"RenderExplosionPS.cso", &pPSBlob ) ) ) return hr; 381 | hr = g_pd3dDevice->CreatePixelShader( pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), nullptr, &g_pRenderExplosionPS ); 382 | pPSBlob->Release(); 383 | if( FAILED( hr ) ) return hr; 384 | 385 | D3D11_BUFFER_DESC bd; 386 | ZeroMemory( &bd, sizeof(bd) ); 387 | bd.Usage = D3D11_USAGE_DYNAMIC; 388 | bd.ByteWidth = sizeof( ExplosionParams ); 389 | bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 390 | bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 391 | hr = g_pd3dDevice->CreateBuffer( &bd, nullptr, &g_pExplosionParamsCB ); 392 | if( FAILED( hr ) ) return hr; 393 | 394 | D3D11_SAMPLER_DESC sampDesc; 395 | ZeroMemory( &sampDesc, sizeof(sampDesc) ); 396 | sampDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; 397 | sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; 398 | sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; 399 | sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; 400 | sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; 401 | sampDesc.MinLOD = 0; 402 | sampDesc.MaxLOD = D3D11_FLOAT32_MAX; 403 | hr = g_pd3dDevice->CreateSamplerState( &sampDesc, &g_pSamplerClampedLinear ); 404 | if( FAILED( hr ) ) return hr; 405 | 406 | sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; 407 | sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; 408 | sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; 409 | hr = g_pd3dDevice->CreateSamplerState( &sampDesc, &g_pSamplerWrappedLinear ); 410 | if( FAILED( hr ) ) return hr; 411 | 412 | HALF maxNoiseValue = 0, minNoiseValue = 0xFFFF; 413 | HALF noiseValues[32*32*32] = { 0 }; 414 | std::fstream f; 415 | f.open("noise_32x32x32.dat", std::ios::in); 416 | if(f.is_open()) 417 | { 418 | for(UINT i=0 ; i<32*32*32 ; i++) 419 | { 420 | HALF noiseValue; 421 | f >> noiseValue; 422 | 423 | maxNoiseValue = max(maxNoiseValue, noiseValue); 424 | minNoiseValue = min(minNoiseValue, noiseValue); 425 | 426 | noiseValues[i] = noiseValue; 427 | } 428 | f.close(); 429 | } 430 | 431 | D3D11_TEXTURE3D_DESC texDesc; 432 | ZeroMemory( &texDesc, sizeof(texDesc) ); 433 | texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 434 | texDesc.CPUAccessFlags = 0; 435 | texDesc.Depth = 32; 436 | texDesc.Format = DXGI_FORMAT_R16_FLOAT; 437 | texDesc.Height = 32; 438 | texDesc.MipLevels = 1; 439 | texDesc.MiscFlags = 0; 440 | texDesc.Usage = D3D11_USAGE_DEFAULT; 441 | texDesc.Width = 32; 442 | 443 | ID3D11Texture3D* pNoiseVolume; 444 | D3D11_SUBRESOURCE_DATA initialData; 445 | initialData.pSysMem = noiseValues; 446 | initialData.SysMemPitch = 32 * 2; 447 | initialData.SysMemSlicePitch = 32 * 32 * 2; 448 | 449 | hr = g_pd3dDevice->CreateTexture3D( &texDesc, &initialData, &pNoiseVolume ); 450 | if( FAILED( hr ) ) return hr; 451 | 452 | hr = g_pd3dDevice->CreateShaderResourceView( pNoiseVolume, nullptr, &g_pNoiseVolumeSRV ); 453 | if( FAILED( hr ) ) return hr; 454 | 455 | hr = CreateDDSTextureFromFile( g_pd3dDevice, L"gradient.dds", nullptr, &g_pGradientSRV ); 456 | if( FAILED( hr ) ) return hr; 457 | 458 | D3D11_DEPTH_STENCIL_DESC dsDesc; 459 | ZeroMemory( &dsDesc, sizeof(dsDesc) ); 460 | dsDesc.DepthEnable = true; 461 | dsDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; 462 | dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; 463 | dsDesc.StencilEnable = false; 464 | 465 | hr = g_pd3dDevice->CreateDepthStencilState( &dsDesc, &g_pTestWriteDepth ); 466 | if( FAILED( hr ) ) return hr; 467 | 468 | D3D11_BLEND_DESC bsDesc; 469 | ZeroMemory( &bsDesc, sizeof(bsDesc) ); 470 | bsDesc.AlphaToCoverageEnable = false; 471 | bsDesc.RenderTarget[0].BlendEnable = true; 472 | bsDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; 473 | bsDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; 474 | bsDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; 475 | bsDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; 476 | bsDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; 477 | bsDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; 478 | bsDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; 479 | 480 | hr = g_pd3dDevice->CreateBlendState( &bsDesc, &g_pOverBlendState ); 481 | if( FAILED( hr ) ) return hr; 482 | 483 | 484 | // Calculate the maximum possible displacement from noise based on our 485 | // fractal noise parameters. This is used to ensure our explosion primitive 486 | // fits in our base sphere. 487 | float largestAbsoluteNoiseValue = max( abs( XMConvertHalfToFloat( maxNoiseValue ) ), abs( XMConvertHalfToFloat( minNoiseValue ) ) ); 488 | g_MaxNoiseDisplacement = 0; 489 | for(UINT i=0 ; iClearState(); 543 | 544 | if( g_pExplosionParamsCB ) g_pExplosionParamsCB->Release(); 545 | if( g_pNoiseVolumeSRV ) g_pNoiseVolumeSRV->Release(); 546 | if( g_pGradientSRV ) g_pGradientSRV->Release(); 547 | if( g_pRenderExplosionVS ) g_pRenderExplosionVS->Release(); 548 | if( g_pRenderExplosionHS ) g_pRenderExplosionHS->Release(); 549 | if( g_pRenderExplosionDS ) g_pRenderExplosionDS->Release(); 550 | if( g_pRenderExplosionPS ) g_pRenderExplosionPS->Release(); 551 | if( g_pExplosionLayout ) g_pExplosionLayout->Release(); 552 | if( g_pSamplerClampedLinear ) g_pSamplerClampedLinear->Release(); 553 | if( g_pSamplerWrappedLinear ) g_pSamplerWrappedLinear->Release(); 554 | if( g_pTestWriteDepth ) g_pTestWriteDepth->Release(); 555 | if( g_pOverBlendState ) g_pOverBlendState->Release(); 556 | 557 | if( g_pRenderTargetView ) g_pRenderTargetView->Release(); 558 | if( g_pSwapChain1 ) g_pSwapChain1->Release(); 559 | if( g_pSwapChain ) g_pSwapChain->Release(); 560 | if( g_pImmediateContext1 ) g_pImmediateContext1->Release(); 561 | if( g_pImmediateContext ) g_pImmediateContext->Release(); 562 | if( g_pd3dDevice1 ) g_pd3dDevice1->Release(); 563 | if( g_pd3dDevice ) g_pd3dDevice->Release(); 564 | } 565 | 566 | 567 | //-------------------------------------------------------------------------------------- 568 | // Called every time the application receives a message 569 | //-------------------------------------------------------------------------------------- 570 | LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) 571 | { 572 | if( TwEventWin(hWnd, message, wParam, lParam) ) return 0; 573 | 574 | PAINTSTRUCT ps; 575 | HDC hdc; 576 | 577 | switch( message ) 578 | { 579 | case WM_PAINT: 580 | hdc = BeginPaint( hWnd, &ps ); 581 | EndPaint( hWnd, &ps ); 582 | break; 583 | 584 | case WM_DESTROY: 585 | PostQuitMessage( 0 ); 586 | break; 587 | 588 | case WM_LBUTTONDOWN: 589 | case WM_MBUTTONDOWN: 590 | case WM_RBUTTONDOWN: 591 | OnMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); 592 | return 0; 593 | case WM_LBUTTONUP: 594 | case WM_MBUTTONUP: 595 | case WM_RBUTTONUP: 596 | OnMouseUp(); 597 | return 0; 598 | case WM_MOUSEMOVE: 599 | OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); 600 | return 0; 601 | 602 | // Note that this tutorial does not handle resizing (WM_SIZE) requests, 603 | // so we created the window without the resize border. 604 | default: 605 | return DefWindowProc( hWnd, message, wParam, lParam ); 606 | } 607 | 608 | return 0; 609 | } 610 | 611 | void StartTimer() 612 | { 613 | LARGE_INTEGER frequencyCount; 614 | QueryPerformanceFrequency(&frequencyCount); 615 | 616 | g_CountsPerSecond = double(frequencyCount.QuadPart); 617 | 618 | QueryPerformanceCounter(&frequencyCount); 619 | g_CounterStart = frequencyCount.QuadPart; 620 | } 621 | 622 | double GetTime() 623 | { 624 | LARGE_INTEGER currentTime; 625 | QueryPerformanceCounter(¤tTime); 626 | return double(currentTime.QuadPart-g_CounterStart)/g_CountsPerSecond; 627 | } 628 | 629 | void OnMouseDown(int x, int y) 630 | { 631 | g_LastMousePos.x = x; 632 | g_LastMousePos.y = y; 633 | 634 | SetCapture(g_hWnd); 635 | } 636 | 637 | void OnMouseUp() 638 | { 639 | ReleaseCapture(); 640 | } 641 | 642 | void OnMouseMove(WPARAM btnState, int x, int y) 643 | { 644 | bool updateMatrices = false; 645 | 646 | if( (btnState & MK_LBUTTON) != 0 ) 647 | { 648 | float dx = XMConvertToRadians(0.25f * (float)(x - g_LastMousePos.x)); 649 | float dy = XMConvertToRadians(0.25f * (float)(y - g_LastMousePos.y)); 650 | 651 | g_CameraTheta -= dx; 652 | g_CameraPhi -= dy; 653 | 654 | updateMatrices = true; 655 | } 656 | else if( (btnState & MK_RBUTTON) != 0 ) 657 | { 658 | float dx = 0.1f * (float)(x - g_LastMousePos.x); 659 | float dy = 0.1f * (float)(y - g_LastMousePos.y); 660 | 661 | g_CameraRadius += dx - dy; 662 | 663 | updateMatrices = true; 664 | } 665 | 666 | g_LastMousePos.x = x; 667 | g_LastMousePos.y = y; 668 | 669 | if(updateMatrices) 670 | { 671 | UpdateViewMatrix(); 672 | } 673 | } 674 | 675 | void UpdateViewMatrix() 676 | { 677 | g_CameraRadius = max(g_CameraRadius, 1.0f); 678 | g_CameraRadius = min(g_CameraRadius, 20.0f); 679 | 680 | g_CameraPhi = max(g_CameraPhi, 0.1f); 681 | g_CameraPhi = min(g_CameraPhi, PI - 0.1f); 682 | 683 | float x = g_CameraRadius * sinf(g_CameraPhi) * cosf(g_CameraTheta); 684 | float y = g_CameraRadius * cosf(g_CameraPhi); 685 | float z = g_CameraRadius * sinf(g_CameraPhi) * sinf(g_CameraTheta); 686 | 687 | g_EyePositionWS = XMFLOAT3(x, y, z); 688 | 689 | XMStoreFloat4x4(&g_ViewMatrix, XMMatrixLookAtLH(XMLoadFloat3(&g_EyePositionWS), XMLoadFloat3(&kEyeLookAtWS), XMLoadFloat3(&XMFLOAT3(0, 1, 0)))); 690 | XMStoreFloat3( &g_EyeForwardWS, XMVector3Normalize( XMVectorSubtract( XMLoadFloat3(&kEyeLookAtWS), XMLoadFloat3(&g_EyePositionWS) ) ) ); 691 | 692 | g_WorldToProjectionMatrix = XMMatrixMultiply( XMLoadFloat4x4(&g_ViewMatrix), XMLoadFloat4x4(&g_ProjMatrix) ); 693 | 694 | XMVECTOR det; 695 | g_ProjectionToWorldMatrix = XMMatrixInverse( &det, g_WorldToProjectionMatrix); 696 | g_ViewToWorldMatrix = XMMatrixInverse( &det, XMLoadFloat4x4( &g_ViewMatrix ) ); 697 | } 698 | 699 | void UpdateExplosionParams(ID3D11DeviceContext* const pContext) 700 | { 701 | D3D11_MAPPED_SUBRESOURCE MappedSubResource; 702 | pContext->Map( g_pExplosionParamsCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedSubResource ); 703 | { 704 | ((ExplosionParams *)MappedSubResource.pData)->g_WorldToViewMatrix = g_ViewMatrix; 705 | ((ExplosionParams *)MappedSubResource.pData)->g_ViewToProjectionMatrix = g_ProjMatrix; 706 | XMStoreFloat4x4( &((ExplosionParams *)MappedSubResource.pData)->g_ProjectionToViewMatrix, g_InvProjMatrix ); 707 | XMStoreFloat4x4( &((ExplosionParams *)MappedSubResource.pData)->g_WorldToProjectionMatrix, g_WorldToProjectionMatrix ); 708 | XMStoreFloat4x4( &((ExplosionParams *)MappedSubResource.pData)->g_ProjectionToWorldMatrix, g_ProjectionToWorldMatrix ); 709 | XMStoreFloat4x4( &((ExplosionParams *)MappedSubResource.pData)->g_ViewToWorldMatrix, g_ViewToWorldMatrix ); 710 | ((ExplosionParams *)MappedSubResource.pData)->g_EyePositionWS = g_EyePositionWS; 711 | ((ExplosionParams *)MappedSubResource.pData)->g_NoiseAmplitudeFactor = g_NoiseAmplitudeFactor; 712 | ((ExplosionParams *)MappedSubResource.pData)->g_EyeForwardWS = g_EyeForwardWS; 713 | ((ExplosionParams *)MappedSubResource.pData)->g_NoiseScale = g_NoiseScale; 714 | ((ExplosionParams *)MappedSubResource.pData)->g_ProjectionParams = g_ProjectionParams; 715 | ((ExplosionParams *)MappedSubResource.pData)->g_ScreenParams = XMFLOAT4((FLOAT)kResolutionX, (FLOAT)kResolutionY, 1.f/kResolutionX, 1.f/kResolutionY); 716 | ((ExplosionParams *)MappedSubResource.pData)->g_ExplosionPositionWS = kEyeLookAtWS; 717 | ((ExplosionParams *)MappedSubResource.pData)->g_ExplosionRadiusWS = g_ExplosionRadius; 718 | ((ExplosionParams *)MappedSubResource.pData)->g_NoiseAnimationSpeed = kNoiseAnimationSpeed; 719 | ((ExplosionParams *)MappedSubResource.pData)->g_Time = (float)g_ElapsedTime; 720 | ((ExplosionParams *)MappedSubResource.pData)->g_EdgeSoftness = g_EdgeSoftness; 721 | ((ExplosionParams *)MappedSubResource.pData)->g_NoiseFrequencyFactor = g_NoiseFrequencyFactor; 722 | ((ExplosionParams *)MappedSubResource.pData)->g_PrimitiveIdx = g_Primitive; 723 | ((ExplosionParams *)MappedSubResource.pData)->g_Opacity = 1.0f; 724 | ((ExplosionParams *)MappedSubResource.pData)->g_DisplacementWS = g_DisplacementAmount; 725 | ((ExplosionParams *)MappedSubResource.pData)->g_StepSizeWS = kStepSize; 726 | ((ExplosionParams *)MappedSubResource.pData)->g_MaxNumSteps = kMaxNumSteps; 727 | ((ExplosionParams *)MappedSubResource.pData)->g_UvScaleBias = g_UvScaleBias; 728 | ((ExplosionParams *)MappedSubResource.pData)->g_NoiseInitialAmplitude = kNoiseInitialAmplitude; 729 | ((ExplosionParams *)MappedSubResource.pData)->g_InvMaxNoiseDisplacement = 1.0f/g_MaxNoiseDisplacement; 730 | ((ExplosionParams *)MappedSubResource.pData)->g_NumOctaves = kNumOctaves; 731 | ((ExplosionParams *)MappedSubResource.pData)->g_SkinThickness = g_MaxSkinThickness; 732 | ((ExplosionParams *)MappedSubResource.pData)->g_NumHullOctaves = kNumHullOctaves; 733 | ((ExplosionParams *)MappedSubResource.pData)->g_NumHullSteps = g_EnableHullShrinking ? kNumHullSteps : 0; 734 | ((ExplosionParams *)MappedSubResource.pData)->g_TessellationFactor = kTessellationFactor; 735 | } 736 | pContext->Unmap( g_pExplosionParamsCB, 0 ); 737 | } 738 | 739 | 740 | //-------------------------------------------------------------------------------------- 741 | // Render a frame 742 | //-------------------------------------------------------------------------------------- 743 | void Render() 744 | { 745 | g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, Colors::Black ); 746 | 747 | D3D11_VIEWPORT vp; 748 | vp.Width = (FLOAT)kResolutionX; 749 | vp.Height = (FLOAT)kResolutionY; 750 | vp.MinDepth = 0.0f; 751 | vp.MaxDepth = 1.0f; 752 | vp.TopLeftX = 0; 753 | vp.TopLeftY = 0; 754 | g_pImmediateContext->RSSetViewports( 1, &vp ); 755 | 756 | const float blendFactor[4] = { 1, 1, 1, 1 }; 757 | g_pImmediateContext->OMSetBlendState(g_pOverBlendState, blendFactor, 0xFFFFFFFF); 758 | g_pImmediateContext->OMSetDepthStencilState(g_pTestWriteDepth, 0); 759 | g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, nullptr ); 760 | 761 | g_pImmediateContext->IASetInputLayout( g_pExplosionLayout ); 762 | g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST ); 763 | 764 | g_pImmediateContext->VSSetShader( g_pRenderExplosionVS, nullptr, 0 ); 765 | g_pImmediateContext->HSSetShader( g_pRenderExplosionHS, nullptr, 0 ); 766 | g_pImmediateContext->DSSetShader( g_pRenderExplosionDS, nullptr, 0 ); 767 | g_pImmediateContext->PSSetShader( g_pRenderExplosionPS, nullptr, 0 ); 768 | 769 | UpdateExplosionParams( g_pImmediateContext ); 770 | 771 | ID3D11SamplerState* const pSamplers[] = { g_pSamplerClampedLinear, g_pSamplerWrappedLinear }; 772 | g_pImmediateContext->DSSetSamplers( S_BILINEAR_CLAMPED_SAMPLER, 2, pSamplers ); 773 | g_pImmediateContext->PSSetSamplers( S_BILINEAR_CLAMPED_SAMPLER, 2, pSamplers ); 774 | 775 | g_pImmediateContext->HSSetConstantBuffers( B_EXPLOSION_PARAMS, 1, &g_pExplosionParamsCB ); 776 | g_pImmediateContext->DSSetConstantBuffers( B_EXPLOSION_PARAMS, 1, &g_pExplosionParamsCB ); 777 | g_pImmediateContext->PSSetConstantBuffers( B_EXPLOSION_PARAMS, 1, &g_pExplosionParamsCB ); 778 | 779 | g_pImmediateContext->DSSetShaderResources( T_NOISE_VOLUME, 1, &g_pNoiseVolumeSRV ); 780 | g_pImmediateContext->PSSetShaderResources( T_NOISE_VOLUME, 1, &g_pNoiseVolumeSRV ); 781 | g_pImmediateContext->PSSetShaderResources( T_GRADIENT_TEX, 1, &g_pGradientSRV ); 782 | 783 | g_pImmediateContext->Draw( 1, 0 ); 784 | 785 | TwDraw(); 786 | 787 | g_pSwapChain->Present( 0, 0 ); 788 | } -------------------------------------------------------------------------------- /Volumetric Explosion Sample/RenderExplosion.hlsli: -------------------------------------------------------------------------------- 1 | #include "Common.h" 2 | 3 | Texture3D g_NoiseVolumeRO : register(T_REG(T_NOISE_VOLUME)); 4 | Texture2D g_GradientTexRO : register(T_REG(T_GRADIENT_TEX)); 5 | 6 | struct HS_CONSTANT_DATA_OUTPUT 7 | { 8 | float EdgeTessFactor[4] : SV_TessFactor; 9 | float InsideTessFactor[2] : SV_InsideTessFactor; 10 | }; 11 | 12 | struct HS_OUTPUT {}; 13 | 14 | struct PS_INPUT 15 | { 16 | float4 PosPS : SV_Position; 17 | noperspective float2 rayHitNearFar : RAYHIT; 18 | noperspective float3 rayDirectionWS : RAYDIR; 19 | }; 20 | 21 | float Noise( float3 uvw ) 22 | { 23 | const float noiseVal = g_NoiseVolumeRO.SampleLevel(BilinearWrappedSampler, uvw, 0); 24 | 25 | return noiseVal; 26 | } 27 | 28 | float FractalNoiseAtPositionWS( float3 posWS, uint numOctaves ) 29 | { 30 | const float3 animation = g_NoiseAnimationSpeed * g_Time; 31 | 32 | float3 uvw = posWS * g_NoiseScale + animation; 33 | float amplitude = g_NoiseInitialAmplitude; 34 | 35 | float noiseValue = 0; 36 | for(uint i=0 ; i quad) 5 | { 6 | float2 posClipSpace = UV.xy * 2.0f - 1.0f; 7 | float2 posClipSpaceAbs = abs(posClipSpace.xy); 8 | float maxLen = max(posClipSpaceAbs.x, posClipSpaceAbs.y); 9 | 10 | float3 dir = normalize(float3(posClipSpace.xy, (maxLen - 1.0f))); 11 | float innerRadius = g_ExplosionRadiusWS - g_DisplacementWS; 12 | 13 | // Even though our geometry only extends around the front of the explosion volume, 14 | // we can calculate the reverse side of the hull here aswell. 15 | 16 | // First get the front world space position of the hull. 17 | float3 frontNormDir = dir; 18 | float3 frontPosWS = mul(g_ViewToWorldMatrix, float4(frontNormDir, 0)).xyz * g_ExplosionRadiusWS + g_ExplosionPositionWS; 19 | float3 frontDirWS = normalize(frontPosWS); 20 | // Then perform the shrink wrapping step using sphere tracing. 21 | for(uint i=0 ; i 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {21E537E9-0EB9-4E5D-A7EF-F83E8DA8252E} 15 | VolumetricExplosionSample 16 | 17 | 18 | 19 | Application 20 | true 21 | v110 22 | MultiByte 23 | 24 | 25 | Application 26 | false 27 | v110 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Build 43 | Run 44 | $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); 45 | $(VCInstallDir)atlmfc\src\mfc;$(VCInstallDir)atlmfc\src\mfcm;$(VCInstallDir)atlmfc\src\atl;$(VCInstallDir)crt\src; 46 | 47 | 48 | 49 | Level3 50 | Disabled 51 | true 52 | $(ProjectDir)AntTweakBar\include;$(ProjectDir)DirectXTK\Inc;%(AdditionalIncludeDirectories) 53 | 54 | 55 | true 56 | anttweakbar.lib;DirectXTK.debug.lib;d3dcompiler.lib;d3d11.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 57 | $(ProjectDir)AntTweakBar\lib;$(ProjectDir)DirectXTK;%(AdditionalLibraryDirectories) 58 | 59 | 60 | xcopy $(ProjectDir)\noisevalues_32x32x32.txt $(OutDir) /r /y 61 | 62 | 63 | 64 | 65 | xcopy "$(ProjectDir)noise_32x32x32.dat" "$(OutDir)" /r /y & 66 | xcopy "$(ProjectDir)gradient.dds" "$(OutDir)" /r /y & 67 | xcopy "$(ProjectDir)AntTweakBar\lib\*.dll" "$(OutDir)" /r /y 68 | Copy media to output. 69 | 70 | 71 | 72 | 73 | Level3 74 | MaxSpeed 75 | true 76 | true 77 | true 78 | WIN32;_MBCS;%(PreprocessorDefinitions) 79 | $(ProjectDir)AntTweakBar\include;$(ProjectDir)DirectXTK\Inc;%(AdditionalIncludeDirectories) 80 | 81 | 82 | true 83 | true 84 | true 85 | anttweakbar.lib;DirectXTK.lib;d3dcompiler.lib;d3d11.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 86 | $(ProjectDir)AntTweakBar\lib;$(ProjectDir)DirectXTK;%(AdditionalLibraryDirectories) 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | xcopy "$(ProjectDir)noise_32x32x32.dat" "$(OutDir)" /r /y & 98 | xcopy "$(ProjectDir)gradient.dds" "$(OutDir)" /r /y & 99 | xcopy "$(ProjectDir)AntTweakBar\lib\*.dll" "$(OutDir)" /r /y 100 | Copy media to output. 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Domain 113 | 5.0 114 | Domain 115 | 5.0 116 | HLSL 117 | HLSL 118 | 119 | 120 | Hull 121 | 5.0 122 | Hull 123 | 5.0 124 | HLSL 125 | HLSL 126 | 127 | 128 | Pixel 129 | Pixel 130 | 5.0 131 | HLSL 132 | 5.0 133 | HLSL 134 | 135 | 136 | Vertex 137 | Vertex 138 | 5.0 139 | HLSL 140 | 5.0 141 | HLSL 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/Volumetric Explosion Sample.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Shaders 19 | 20 | 21 | Shaders 22 | 23 | 24 | Shaders 25 | 26 | 27 | Shaders 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | Shaders 36 | 37 | 38 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/Volumetric Explosion Sample.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutDir) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutDir) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /Volumetric Explosion Sample/directx.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/directx.ico -------------------------------------------------------------------------------- /Volumetric Explosion Sample/gradient.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smb02dunnal/volumetric-explosions/c0e2ff4f71a0f7dbb0ae7c766fbc972884053b4f/Volumetric Explosion Sample/gradient.dds --------------------------------------------------------------------------------