├── .gitignore ├── Demo ├── Code │ ├── Demo.cpp │ ├── SeparableSSS.cpp │ ├── SeparableSSS.h │ └── Support │ │ ├── Animation.h │ │ ├── AreaTex.h │ │ ├── Bloom.cpp │ │ ├── Bloom.h │ │ ├── Camera.cpp │ │ ├── Camera.h │ │ ├── DepthOfField.cpp │ │ ├── DepthOfField.h │ │ ├── Fade.cpp │ │ ├── Fade.h │ │ ├── FilmGrain.cpp │ │ ├── FilmGrain.h │ │ ├── RenderTarget.cpp │ │ ├── RenderTarget.h │ │ ├── SMAA.cpp │ │ ├── SMAA.h │ │ ├── SearchTex.h │ │ ├── ShadowMap.cpp │ │ ├── ShadowMap.h │ │ ├── SkyDome.cpp │ │ ├── SkyDome.h │ │ ├── SplashScreen.cpp │ │ ├── SplashScreen.h │ │ ├── Timer.cpp │ │ └── Timer.h ├── DXUT │ ├── Core │ │ ├── DXUT.cpp │ │ ├── DXUT.h │ │ ├── DXUT_2008.sln │ │ ├── DXUT_2008.vcproj │ │ ├── DXUT_2010.sln │ │ ├── DXUT_2010.vcxproj │ │ ├── DXUT_2010.vcxproj.filters │ │ ├── DXUTenum.cpp │ │ ├── DXUTenum.h │ │ ├── DXUTmisc.cpp │ │ ├── DXUTmisc.h │ │ └── dpiaware.manifest │ └── Optional │ │ ├── DXUTLockFreePipe.h │ │ ├── DXUTOpt_2008.sln │ │ ├── DXUTOpt_2008.vcproj │ │ ├── DXUTOpt_2010.sln │ │ ├── DXUTOpt_2010.vcxproj │ │ ├── DXUTOpt_2010.vcxproj.filters │ │ ├── DXUTShapes.cpp │ │ ├── DXUTShapes.h │ │ ├── DXUTcamera.cpp │ │ ├── DXUTcamera.h │ │ ├── DXUTgui.cpp │ │ ├── DXUTgui.h │ │ ├── DXUTguiIME.cpp │ │ ├── DXUTguiIME.h │ │ ├── DXUTres.cpp │ │ ├── DXUTres.h │ │ ├── DXUTsettingsdlg.cpp │ │ ├── DXUTsettingsdlg.h │ │ ├── ImeUi.cpp │ │ ├── ImeUi.h │ │ ├── SDKmesh.cpp │ │ ├── SDKmesh.h │ │ ├── SDKmisc.cpp │ │ ├── SDKmisc.h │ │ ├── SDKsound.cpp │ │ ├── SDKsound.h │ │ ├── SDKwavefile.cpp │ │ ├── SDKwavefile.h │ │ └── directx.ico ├── Demo.rc ├── Demo.sln ├── Demo.vcxproj ├── Demo.vcxproj.filters ├── Demo.vcxproj.user ├── DirectX.ico ├── Media │ ├── Background.png │ ├── BeckmannMap.dds │ ├── BigTitles.dds │ ├── BigTitles.psd │ ├── Enviroment │ │ ├── Eucalyptus │ │ │ ├── DiffuseMap.dds │ │ │ ├── IrradianceMap.dds │ │ │ └── SkyDome.sdkmesh │ │ ├── Grace │ │ │ ├── DiffuseMap.dds │ │ │ ├── IrradianceMap.dds │ │ │ └── SkyDome.sdkmesh │ │ └── StPeters │ │ │ ├── DiffuseMap.dds │ │ │ ├── IrradianceMap.dds │ │ │ └── SkyDome.sdkmesh │ ├── Head │ │ ├── DiffuseMap.dds │ │ ├── Head.sdkmesh │ │ ├── NormalMap.dds │ │ └── SpecularAOMap.dds │ ├── Help.txt │ ├── Music.xwm │ ├── Noise.dds │ ├── Presets │ │ ├── Preset0.txt │ │ ├── Preset1.txt │ │ ├── Preset2.txt │ │ ├── Preset3.txt │ │ ├── Preset4.txt │ │ ├── Preset5.txt │ │ ├── Preset6.txt │ │ ├── Preset7.txt │ │ ├── Preset8.txt │ │ └── Preset9.txt │ ├── SmallTitles.dds │ └── SmallTitles.psd └── Shaders │ ├── Bloom.fx │ ├── DepthOfField.fx │ ├── FilmGrain.fx │ ├── Main.fx │ ├── SMAA.fx │ ├── SMAA.h │ ├── SeparableSSS.fx │ ├── ShadowMap.fx │ └── SkyDome.fx ├── LICENSE.txt ├── README.md └── SeparableSSS.h /.gitignore: -------------------------------------------------------------------------------- 1 | Demo/Debug/ 2 | Demo/Release/ 3 | Demo/ipch/ 4 | Demo/Demo.opensdf 5 | Demo/Demo.sdf 6 | Demo/Demo.suo 7 | -------------------------------------------------------------------------------- /Demo/Code/SeparableSSS.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com) 3 | * Copyright (C) 2012 Diego Gutierrez (diegog@unizar.es) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution: 15 | * 16 | * "Uses Separable SSS. Copyright (C) 2012 by Jorge Jimenez and Diego 17 | * Gutierrez." 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 20 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * The views and conclusions contained in the software and documentation are 32 | * those of the authors and should not be interpreted as representing official 33 | * policies, either expressed or implied, of the copyright holders. 34 | */ 35 | 36 | 37 | #ifndef SSS_H 38 | #define SSS_H 39 | 40 | #include "RenderTarget.h" 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | class SeparableSSS { 48 | public: 49 | /** 50 | * width, height: should match the backbuffer's size. 51 | * 52 | * fovy: field of view angle used for rendering the scene, in degrees. 53 | * 54 | * sssWidth: specifies the global level of subsurface scattering, or in 55 | * other words, the width of the filter. 56 | * 57 | * nSamples: number of samples of the kernel convolution. 58 | * 59 | * followShape: irradiance diffusion should occur on the surface of the 60 | * object, not in a screen oriented plane. Setting 'followShape' to 61 | * 'true' will ensure that diffusion is more accurately calculated, 62 | * at the expense of more memory accesses. This is usually only 63 | * noticeable under specific lighting configurations. 64 | * 65 | * separateStrengthSource: this parameter enables to use a specific 66 | * buffer for fetching the SSS strength, instead of using the alpha 67 | * channel of the color buffer. 68 | * 69 | * stencilInitialized: if an stencil is initialized for selectively 70 | * processing the frame buffer, set this to 'true'. For example, 71 | * this cannot be easily done, when using multisampling. See 72 | * @STENCIL below for more info. 73 | * 74 | * format: format of the temporal framebuffer. Should be left as is, 75 | * unless an HDR format is desired. 76 | */ 77 | SeparableSSS(ID3D10Device *device, 78 | int width, int height, 79 | float fovy, 80 | float sssWidth, 81 | int nSamples=17, 82 | bool stencilInitialized=true, 83 | bool followShape=true, 84 | bool separateStrengthSource=false, 85 | DXGI_FORMAT format=DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); 86 | ~SeparableSSS(); 87 | 88 | /** 89 | * IMPORTANT NOTICE: all render targets below must not be multisampled. 90 | * 91 | * mainRTV and mainSRV: render target and shader resources of the 92 | * final rendered image. The filter works on place, so they should 93 | * be associated to the same resource. The SSS intensity should be 94 | * stored in the alpha channel. 95 | * 96 | * depthSRV: shader resource of the the linear depth buffer of the 97 | * scene, resolved in case of using multisampling. The resolve 98 | * should be a simple average to avoid artifacts in the silhouette 99 | * of objects. 100 | * 101 | * @STENCIL 102 | * depthDSV: two possibilities over here: 103 | * a) if 'stencilInitialized' was set to 'true', then only the 104 | * pixels marked in the stencil buffer with the value 'id' will 105 | * be processed in both the horizontal and vertical passes. 106 | * b) if 'stencilInitialized' was set to 'false' (for example when 107 | * using multisampling), then it will be initialized on the fly 108 | * for optimizing the second vertical pass. 109 | * 110 | * stregthSRV: if 'separateStrengthSource' was set to 'true' when 111 | * creating this object, the SSS stregth will be fetched from the 112 | * alpha channel of this texture instead of the alpha channel of 113 | * the color buffer. 114 | * 115 | * id: stencil value used to render the objects we must apply 116 | * subsurface scattering on. Should be left as is in case 117 | * 'stencilInitialized' was set to false when creating the object. 118 | * 119 | * Note that 'depthSRV' and 'depthDSV' cannot be the views of the same 120 | * depth-stencil buffer. 121 | */ 122 | void go(ID3D10RenderTargetView *mainRTV, 123 | ID3D10ShaderResourceView *mainSRV, 124 | ID3D10ShaderResourceView *depthSRV, 125 | ID3D10DepthStencilView *depthDSV, 126 | ID3D10ShaderResourceView *stregthSRV = NULL, 127 | int id=1); 128 | 129 | /** 130 | * This parameter specifies the global level of subsurface scattering, 131 | * or in other words, the width of the filter. 132 | */ 133 | void setWidth(float width) { this->sssWidth = width; } 134 | float getWidth() const { return sssWidth; } 135 | 136 | /** 137 | * @STRENGTH 138 | * 139 | * This parameter specifies the how much of the diffuse light gets into 140 | * the skin, and thus gets modified by the SSS mechanism. 141 | * 142 | * It can be seen as a per-channel mix factor between the original 143 | * image, and the SSS-filtered image. 144 | */ 145 | void setStrength(D3DXVECTOR3 strength) { this->strength = strength; calculateKernel(); } 146 | D3DXVECTOR3 getStrength() const { return strength; } 147 | 148 | /** 149 | * This parameter defines the per-channel falloff of the gradients 150 | * produced by the subsurface scattering events. 151 | * 152 | * It can be used to fine tune the color of the gradients. 153 | */ 154 | void setFalloff(D3DXVECTOR3 falloff) { this->falloff = falloff; calculateKernel(); } 155 | D3DXVECTOR3 getFalloff() const { return falloff; } 156 | 157 | /** 158 | * This one is just for convenience, it returns the shader code of 159 | * current kernel. 160 | */ 161 | std::string getKernelCode() const; 162 | 163 | private: 164 | D3DXVECTOR3 gaussian(float variance, float r); 165 | D3DXVECTOR3 profile(float r); 166 | void calculateKernel(); 167 | 168 | ID3D10Device *device; 169 | 170 | float sssWidth; 171 | int nSamples; 172 | bool stencilInitialized; 173 | D3DXVECTOR3 strength; 174 | D3DXVECTOR3 falloff; 175 | 176 | ID3D10Effect *effect; 177 | RenderTarget *tmpRT; 178 | Quad *quad; 179 | 180 | std::vector kernel; 181 | ID3D10EffectScalarVariable *idVariable, *sssWidthVariable; 182 | ID3D10EffectVectorVariable *kernelVariable; 183 | ID3D10EffectShaderResourceVariable *colorTexVariable, *depthTexVariable, *strengthTexVariable; 184 | ID3D10EffectTechnique *technique; 185 | }; 186 | 187 | #endif 188 | -------------------------------------------------------------------------------- /Demo/Code/Support/Animation.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef ANIMATION_H 33 | #define ANIMATION_H 34 | 35 | class Animation { 36 | public: 37 | template 38 | static T linear(float t, float t0, float t1, T v0, T v1) { 39 | float p = (t - t0) / (t1 - t0); 40 | return interpolate(p, v0, v1); 41 | } 42 | 43 | template 44 | static T smooth(float t, float t0, float t1, T v0, T v1, T stepness) { 45 | /** 46 | * Catmull-Rom spline interpolation 47 | */ 48 | float u = (t - t0) / (t1 - t0); 49 | float u2 = u * u; 50 | float u3 = u * u * u; 51 | return v0 * (2 * u3 - 3 * u2 + 1) + 52 | v1 * (3 * u2 - 2 * u3) + 53 | stepness * (u3 - 2 * u2 + u) + 54 | stepness * (u3 - u2); 55 | } 56 | 57 | template 58 | static T smooth2(float t, float t0, float t1, T v0, T v1, T stepness) { 59 | if (t < t0) 60 | return v0; 61 | else if (t > t1) 62 | return v1; 63 | else 64 | return smooth(t, t0, t1, v0, v1, stepness); 65 | } 66 | 67 | template 68 | static T constant(float t, float t0, float t1, T c) { 69 | if (t > t0 && t < t1) 70 | return c; 71 | else 72 | return T(0.0); 73 | } 74 | 75 | static float linearFade(float t, float in, float out, float inLength, float outLength) { 76 | if (t < in + inLength) 77 | return Animation::linear(t, in, in + inLength, 0.0f, 1.0f); 78 | else 79 | return Animation::linear(t, out - outLength, out, 1.0f, 0.0f); 80 | } 81 | 82 | static float smoothFade(float t, float in, float out, float inLength, float outLength) { 83 | if (t < in + inLength) 84 | return Animation::smooth2(t, in, in + inLength, 0.0f, 1.0f, 0.0f); 85 | else 86 | return Animation::smooth2(t, out - outLength, out, 1.0f, 0.0f, 0.0f); 87 | } 88 | 89 | template 90 | static T interpolate(float p, T v0, T v1) { 91 | float pp = max(min(p, 1.0f), 0.0f); 92 | return v0 + pp * (v1 - v0); 93 | } 94 | 95 | template 96 | static T push(float t, float t0, T v0, T velocity) { 97 | return v0 + (t - t0) * velocity; 98 | } 99 | }; 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /Demo/Code/Support/Bloom.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include 33 | #include "Bloom.h" 34 | using namespace std; 35 | 36 | 37 | #pragma region Useful Macros from DXUT (copy-pasted here as we prefer this to be as self-contained as possible) 38 | #if defined(DEBUG) || defined(_DEBUG) 39 | #ifndef V 40 | #define V(x) { hr = (x); if (FAILED(hr)) { DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 41 | #endif 42 | #ifndef V_RETURN 43 | #define V_RETURN(x) { hr = (x); if (FAILED(hr)) { return DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 44 | #endif 45 | #else 46 | #ifndef V 47 | #define V(x) { hr = (x); } 48 | #endif 49 | #ifndef V_RETURN 50 | #define V_RETURN(x) { hr = (x); if( FAILED(hr) ) { return hr; } } 51 | #endif 52 | #endif 53 | 54 | #ifndef SAFE_DELETE 55 | #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } } 56 | #endif 57 | #ifndef SAFE_DELETE_ARRAY 58 | #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } } 59 | #endif 60 | #ifndef SAFE_RELEASE 61 | #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } 62 | #endif 63 | #pragma endregion 64 | 65 | 66 | Bloom::Bloom(ID3D10Device *device, int width, int height, DXGI_FORMAT format, ToneMapOperator toneMapOperator, float exposure, float bloomThreshold, float bloomWidth, float bloomIntensity, float defocus) 67 | : device(device), 68 | width(width), 69 | height(height), 70 | toneMapOperator(toneMapOperator), 71 | exposure(exposure), 72 | burnout(numeric_limits::infinity()), 73 | bloomThreshold(bloomThreshold), 74 | bloomWidth(bloomWidth), 75 | bloomIntensity(bloomIntensity), 76 | defocus(defocus) { 77 | 78 | HRESULT hr; 79 | 80 | vector defines; 81 | 82 | stringstream s; 83 | s << int(toneMapOperator); 84 | string toneMapOperatorString = s.str(); 85 | D3D10_SHADER_MACRO toneMapOperatorMacro = { "TONEMAP_OPERATOR", toneMapOperatorString.c_str() }; 86 | defines.push_back(toneMapOperatorMacro); 87 | 88 | D3D10_SHADER_MACRO null = { NULL, NULL }; 89 | defines.push_back(null); 90 | 91 | V(D3DX10CreateEffectFromResource(GetModuleHandle(NULL), L"Bloom.fx", NULL, &defines.front(), NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL)); 92 | 93 | D3D10_PASS_DESC desc; 94 | V(effect->GetTechniqueByName("GlareDetection")->GetPassByIndex(0)->GetDesc(&desc)); 95 | quad = new Quad(device, desc); 96 | 97 | glareRT = new RenderTarget(device, width / 2, height / 2, format); 98 | 99 | int base = 2; 100 | for (int i = 0; i < N_PASSES; i++) { 101 | tmpRT[i][0] = new RenderTarget(device, max(width / base, 1), max(height / base, 1), format); 102 | tmpRT[i][1] = new RenderTarget(device, max(width / base, 1), max(height / base, 1), format); 103 | base *= 2; 104 | } 105 | } 106 | 107 | 108 | Bloom::~Bloom() { 109 | SAFE_RELEASE(effect); 110 | SAFE_DELETE(quad); 111 | SAFE_DELETE(glareRT); 112 | for (int i = 0; i < N_PASSES; i++) { 113 | SAFE_DELETE(tmpRT[i][0]); 114 | SAFE_DELETE(tmpRT[i][1]); 115 | } 116 | } 117 | 118 | 119 | void Bloom::go(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst) { 120 | HRESULT hr; 121 | 122 | SaveViewportsScope saveViewport(device); 123 | SaveRenderTargetsScope saveRenderTargets(device); 124 | SaveInputLayoutScope saveInputLayout(device); 125 | 126 | quad->setInputLayout(); 127 | 128 | V(effect->GetVariableByName("exposure")->AsScalar()->SetFloat(exposure)); 129 | V(effect->GetVariableByName("burnout")->AsScalar()->SetFloat(burnout)); 130 | V(effect->GetVariableByName("bloomThreshold")->AsScalar()->SetFloat(bloomThreshold)); 131 | V(effect->GetVariableByName("bloomWidth")->AsScalar()->SetFloat(bloomWidth)); 132 | V(effect->GetVariableByName("bloomIntensity")->AsScalar()->SetFloat(bloomIntensity)); 133 | V(effect->GetVariableByName("defocus")->AsScalar()->SetFloat(defocus)); 134 | V(effect->GetVariableByName("finalTex")->AsShaderResource()->SetResource(src)); 135 | 136 | if (bloomIntensity > 0.0f) { 137 | glareDetection(); 138 | 139 | ID3D10ShaderResourceView *current = *glareRT; 140 | for (int i = 0; i < N_PASSES; i++) { 141 | D3DXVECTOR2 pixelSize = D3DXVECTOR2(1.0f / tmpRT[i][0]->getWidth(), 142 | 1.0f / tmpRT[i][0]->getHeight()); 143 | V(effect->GetVariableByName("pixelSize")->AsVector()->SetFloatVector(pixelSize)); 144 | 145 | tmpRT[i][0]->setViewport(); 146 | 147 | horizontalBlur(current, *tmpRT[i][0]); 148 | verticalBlur(*tmpRT[i][0], *tmpRT[i][1]); 149 | 150 | current = *tmpRT[i][1]; 151 | } 152 | 153 | combine(dst); 154 | } else { 155 | toneMap(dst); 156 | } 157 | } 158 | 159 | 160 | void Bloom::glareDetection() { 161 | HRESULT hr; 162 | 163 | glareRT->setViewport(); 164 | 165 | D3DXVECTOR2 pixelSize = D3DXVECTOR2(1.0f / glareRT->getWidth(), 1.0f / glareRT->getHeight()); 166 | V(effect->GetVariableByName("pixelSize")->AsVector()->SetFloatVector(pixelSize)); 167 | V(effect->GetTechniqueByName("GlareDetection")->GetPassByIndex(0)->Apply(0)); 168 | 169 | device->OMSetRenderTargets(1, *glareRT, NULL); 170 | quad->draw(); 171 | device->OMSetRenderTargets(0, NULL, NULL); 172 | } 173 | 174 | 175 | void Bloom::horizontalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst) { 176 | HRESULT hr; 177 | 178 | V(effect->GetVariableByName("srcTex")->GetElement(0)->AsShaderResource()->SetResource(src)); 179 | V(effect->GetVariableByName("direction")->AsVector()->SetFloatVector(D3DXVECTOR2(1.0f, 0.0f))); 180 | V(effect->GetTechniqueByName("Blur")->GetPassByIndex(0)->Apply(0)); 181 | 182 | device->OMSetRenderTargets(1, &dst, NULL); 183 | quad->draw(); 184 | device->OMSetRenderTargets(0, NULL, NULL); 185 | } 186 | 187 | 188 | void Bloom::verticalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst) { 189 | HRESULT hr; 190 | 191 | V(effect->GetVariableByName("srcTex")->GetElement(0)->AsShaderResource()->SetResource(src)); 192 | V(effect->GetVariableByName("direction")->AsVector()->SetFloatVector(D3DXVECTOR2(0.0f, 1.0f))); 193 | V(effect->GetTechniqueByName("Blur")->GetPassByIndex(0)->Apply(0)); 194 | 195 | device->OMSetRenderTargets(1, &dst, NULL); 196 | quad->draw(); 197 | device->OMSetRenderTargets(0, NULL, NULL); 198 | } 199 | 200 | 201 | void Bloom::combine(ID3D10RenderTargetView *dst) { 202 | HRESULT hr; 203 | 204 | D3D10_VIEWPORT viewport = Utils::viewportFromView(dst); 205 | device->RSSetViewports(1, &viewport); 206 | 207 | D3DXVECTOR2 pixelSize = D3DXVECTOR2(1.0f / viewport.Width, 1.0f / viewport.Height); 208 | 209 | V(effect->GetVariableByName("pixelSize")->AsVector()->SetFloatVector(pixelSize)); 210 | for (int i = 0; i < N_PASSES; i++) 211 | V(effect->GetVariableByName("srcTex")->GetElement(i)->AsShaderResource()->SetResource(*tmpRT[i][1])); 212 | V(effect->GetTechniqueByName("Combine")->GetPassByIndex(0)->Apply(0)); 213 | 214 | device->OMSetRenderTargets(1, &dst, NULL); 215 | quad->draw(); 216 | device->OMSetRenderTargets(0, NULL, NULL); 217 | } 218 | 219 | 220 | void Bloom::toneMap(ID3D10RenderTargetView *dst) { 221 | HRESULT hr; 222 | 223 | D3D10_VIEWPORT viewport = Utils::viewportFromView(dst); 224 | device->RSSetViewports(1, &viewport); 225 | 226 | V(effect->GetTechniqueByName("ToneMap")->GetPassByIndex(0)->Apply(0)); 227 | 228 | device->OMSetRenderTargets(1, &dst, NULL); 229 | quad->draw(); 230 | device->OMSetRenderTargets(0, NULL, NULL); 231 | } 232 | -------------------------------------------------------------------------------- /Demo/Code/Support/Bloom.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef BLOOMSHADER_H 33 | #define BLOOMSHADER_H 34 | 35 | #include "RenderTarget.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | class Bloom { 42 | public: 43 | enum ToneMapOperator { TONEMAP_LINEAR = 0, 44 | TONEMAP_EXPONENTIAL = 1, 45 | TONEMAP_EXPONENTIAL_HSV = 2, 46 | TONEMAP_REINHARD = 3, 47 | TONEMAP_FILMIC = 4 }; 48 | 49 | Bloom(ID3D10Device *device, int width, int height, DXGI_FORMAT format, 50 | ToneMapOperator toneMapOperator, float exposure, 51 | float bloomThreshold, float bloomWidth, float bloomIntensity, 52 | float defocus); 53 | ~Bloom(); 54 | 55 | ToneMapOperator getToneMapOperator() const { return toneMapOperator; } 56 | 57 | void setExposure(float exposure) { this->exposure = exposure; } 58 | float getExposure() const { return exposure; } 59 | 60 | void setBurnout(float burnout) { this->burnout = burnout; } 61 | float getBurnout() const { return burnout; } 62 | 63 | void setBloomThreshold(float bloomThreshold) { this->bloomThreshold = bloomThreshold; } 64 | float getBloomThreshold() const { return bloomThreshold; } 65 | 66 | void setBloomWidth(float bloomWidth) { this->bloomWidth = bloomWidth; } 67 | float getBloomWidth() const { return bloomWidth; } 68 | 69 | void setBlooomIntensity(float bloomIntensity) { this->bloomIntensity = bloomIntensity; } 70 | float getBloomIntensity() const { return bloomIntensity; } 71 | 72 | void setDefocus(float defocus) { this->defocus = defocus; } 73 | float getDefocus() const { return defocus; } 74 | 75 | void go(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst); 76 | 77 | private: 78 | static const int N_PASSES = 6; 79 | 80 | void glareDetection(); 81 | void horizontalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst); 82 | void verticalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst); 83 | void toneMap(ID3D10RenderTargetView *dst); 84 | void combine(ID3D10RenderTargetView *dst); 85 | 86 | ID3D10Device *device; 87 | int width, height; 88 | ToneMapOperator toneMapOperator; 89 | float exposure, burnout; 90 | float bloomThreshold, bloomWidth, bloomIntensity; 91 | float defocus; 92 | 93 | ID3D10Effect *effect; 94 | Quad *quad; 95 | RenderTarget *glareRT; 96 | RenderTarget *tmpRT[N_PASSES][2]; 97 | }; 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /Demo/Code/Support/Camera.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include "Camera.h" 33 | using namespace std; 34 | 35 | 36 | #pragma region Useful Macros from DXUT (copy-pasted here as we prefer this to be as self-contained as possible) 37 | #if defined(DEBUG) || defined(_DEBUG) 38 | #ifndef V 39 | #define V(x) { hr = (x); if (FAILED(hr)) { DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 40 | #endif 41 | #ifndef V_RETURN 42 | #define V_RETURN(x) { hr = (x); if (FAILED(hr)) { return DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 43 | #endif 44 | #else 45 | #ifndef V 46 | #define V(x) { hr = (x); } 47 | #endif 48 | #ifndef V_RETURN 49 | #define V_RETURN(x) { hr = (x); if( FAILED(hr) ) { return hr; } } 50 | #endif 51 | #endif 52 | 53 | #ifndef SAFE_DELETE 54 | #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } } 55 | #endif 56 | #ifndef SAFE_DELETE_ARRAY 57 | #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } } 58 | #endif 59 | #ifndef SAFE_RELEASE 60 | #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } 61 | #endif 62 | #pragma endregion 63 | 64 | 65 | LRESULT Camera::handleMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { 66 | switch(msg) { 67 | case WM_LBUTTONDOWN: { 68 | POINT point; 69 | GetCursorPos(&point); 70 | mousePos = D3DXVECTOR2(float(point.x), float(point.y)); 71 | draggingLeft = true; 72 | attenuation = 4.0f; 73 | SetCapture(hwnd); 74 | return true; 75 | } 76 | case WM_LBUTTONUP: 77 | draggingLeft = false; 78 | if (wparam & MK_CONTROL) 79 | attenuation = 0.0f; 80 | else 81 | attenuation = 4.0f; 82 | ReleaseCapture(); 83 | return true; 84 | case WM_RBUTTONDOWN: { 85 | POINT point; 86 | GetCursorPos(&point); 87 | mousePos = D3DXVECTOR2(float(point.x), float(point.y)); 88 | draggingRight = true; 89 | SetCapture(hwnd); 90 | return true; 91 | } 92 | case WM_RBUTTONUP: { 93 | draggingRight = false; 94 | ReleaseCapture(); 95 | return true; 96 | } 97 | case WM_MBUTTONDOWN: { 98 | POINT point; 99 | GetCursorPos(&point); 100 | mousePos = D3DXVECTOR2(float(point.x), float(point.y)); 101 | draggingMiddle = true; 102 | SetCapture(hwnd); 103 | return true; 104 | } 105 | case WM_MBUTTONUP: { 106 | draggingMiddle = false; 107 | ReleaseCapture(); 108 | return true; 109 | } 110 | case WM_MOUSEMOVE: { 111 | POINT point; 112 | GetCursorPos(&point); 113 | D3DXVECTOR2 newMousePos = D3DXVECTOR2(float(point.x), float(point.y)); 114 | if (draggingLeft) { 115 | D3DXVECTOR2 delta = newMousePos - mousePos; 116 | angularVelocity -= delta; 117 | mousePos = newMousePos; 118 | } 119 | if (draggingMiddle) { 120 | D3DXVECTOR2 delta = newMousePos - mousePos; 121 | updatePosition(delta); 122 | mousePos = newMousePos; 123 | } 124 | if (draggingRight) { 125 | distance += (newMousePos.y - mousePos.y) / 75.0f; 126 | mousePos = newMousePos; 127 | } 128 | return true; 129 | } 130 | case WM_MOUSEWHEEL: { 131 | short value = short(HIWORD(wparam)); 132 | distance -= float(value) / 400.0f; 133 | return 0; 134 | } 135 | case WM_CAPTURECHANGED: { 136 | if ((HWND) lparam != hwnd) { 137 | draggingLeft = false; 138 | draggingMiddle = false; 139 | draggingRight = false; 140 | } 141 | break; 142 | } 143 | } 144 | return 0; 145 | } 146 | 147 | 148 | void Camera::frameMove(FLOAT elapsedTime) { 149 | angle += angularVelocity * elapsedTime / 150.0f; 150 | angularVelocity = angularVelocity / (1.0f + attenuation * elapsedTime); 151 | distance += distanceVelocity * elapsedTime / 150.0f; 152 | panPosition += panVelocity * elapsedTime / 150.0f; 153 | build(); 154 | } 155 | 156 | 157 | void Camera::setProjection(float fov, float aspect, float nearPlane, float farPlane) { 158 | D3DXMatrixPerspectiveFovLH(&projection, fov, aspect, nearPlane, farPlane); 159 | } 160 | 161 | 162 | void Camera::build() { 163 | D3DXMatrixTranslation(&view, -panPosition.x, -panPosition.y, distance); 164 | 165 | D3DXMATRIX t; 166 | D3DXMatrixRotationX(&t, angle.y); 167 | view = t * view; 168 | 169 | D3DXMatrixRotationY(&t, angle.x); 170 | view = t * view; 171 | 172 | D3DXMATRIX viewInverse; 173 | float det; 174 | D3DXMatrixInverse(&viewInverse, &det, &view); 175 | 176 | D3DXVECTOR4 lookAtPosition4 = D3DXVECTOR4(0.0f, 0.0f, distance, 1.0f); 177 | D3DXVec4Transform(&lookAtPosition4, &lookAtPosition4, &viewInverse); 178 | lookAtPosition = D3DXVECTOR3(lookAtPosition4); 179 | 180 | D3DXVECTOR4 eyePosition4 = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 1.0f); 181 | D3DXVec4Transform(&eyePosition4, &eyePosition4, &viewInverse); 182 | eyePosition = D3DXVECTOR3(eyePosition4); 183 | } 184 | 185 | 186 | void Camera::updatePosition(D3DXVECTOR2 delta) { 187 | delta.x /= viewportSize.x / 2.0f; 188 | delta.y /= viewportSize.y / 2.0f; 189 | 190 | D3DXMATRIX transform; 191 | D3DXMatrixTranslation(&transform, 0.0f, 0.0f, distance); 192 | transform *= projection; 193 | 194 | D3DXMATRIX inverse; 195 | float det; 196 | D3DXMatrixInverse(&inverse, &det, &transform); 197 | 198 | D3DXVECTOR4 t = D3DXVECTOR4(panPosition.x, panPosition.y, 0.0f, 1.0f); 199 | D3DXVec4Transform(&t, &t, &transform); 200 | t.x -= delta.x * t.w; 201 | t.y += delta.y * t.w; 202 | D3DXVec4Transform(&t, &t, &inverse); 203 | panPosition = D3DXVECTOR2(t); 204 | } 205 | 206 | 207 | ostream &operator <<(ostream &os, const Camera &camera) { 208 | os << camera.distance << endl; 209 | os << camera.angle.x << " " << camera.angle.y << endl; 210 | os << camera.panPosition.x << " " << camera.panPosition.y << endl; 211 | os << camera.angularVelocity.x << " " << camera.angularVelocity.y << endl; 212 | return os; 213 | } 214 | 215 | 216 | istream &operator >>(istream &is, Camera &camera) { 217 | is >> camera.distance; 218 | is >> camera.angle.x >> camera.angle.y; 219 | is >> camera.panPosition.x >> camera.panPosition.y; 220 | is >> camera.angularVelocity.x >> camera.angularVelocity.y; 221 | return is; 222 | } 223 | -------------------------------------------------------------------------------- /Demo/Code/Support/Camera.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef CAMERA_H 33 | #define CAMERA_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | class Camera { 42 | public: 43 | Camera() : 44 | distance(0.0f), 45 | distanceVelocity(0.0f), 46 | angle(0.0f, 0.0f), 47 | angularVelocity(0.0f, 0.0f), 48 | panPosition(0.0f, 0.0f), 49 | panVelocity(0.0f, 0.0f), 50 | viewportSize(1.0f, 1.0f), 51 | mousePos(0.0f, 0.0f), 52 | attenuation(0.0f), 53 | draggingLeft(false), 54 | draggingMiddle(false), 55 | draggingRight(false) { build(); } 56 | 57 | LRESULT handleMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); 58 | 59 | void frameMove(FLOAT elapsedTime); 60 | 61 | void setDistance(float distance) { this->distance = distance; } 62 | float getDistance() const { return distance; } 63 | 64 | void setDistanceVelocity(float distanceVelocity) { this->distanceVelocity = distanceVelocity; } 65 | float getDistanceVelocity() const { return distanceVelocity; } 66 | 67 | void setPanPosition(const D3DXVECTOR2 &panPosition) { this->panPosition = panPosition; } 68 | const D3DXVECTOR2 &getPanPosition() const { return panPosition; } 69 | 70 | void setPanVelocity(const D3DXVECTOR2 &panVelocity) { this->panVelocity = panVelocity; } 71 | const D3DXVECTOR2 &getPanVelocity() const { return panVelocity; } 72 | 73 | void setAngle(const D3DXVECTOR2 &angle) { this->angle = angle; } 74 | const D3DXVECTOR2 &getAngle() const { return angle; } 75 | 76 | void setAngularVelocity(const D3DXVECTOR2 &angularVelocity) { this->angularVelocity = angularVelocity; } 77 | const D3DXVECTOR2 &getAngularVelocity() const { return angularVelocity; } 78 | 79 | void setProjection(float fov, float aspect, float nearPlane, float farPlane); 80 | void setViewportSize(const D3DXVECTOR2 &viewportSize) { this->viewportSize = viewportSize; } 81 | 82 | const D3DXMATRIX &getViewMatrix() { return view; } 83 | const D3DXMATRIX &getProjectionMatrix() const { return projection; } 84 | 85 | const D3DXVECTOR3 &getLookAtPosition() { return lookAtPosition; } 86 | const D3DXVECTOR3 &getEyePosition() { return eyePosition; } 87 | 88 | friend std::ostream& operator <<(std::ostream &os, const Camera &camera); 89 | friend std::istream& operator >>(std::istream &is, Camera &camera); 90 | 91 | private: 92 | void build(); 93 | void updatePosition(D3DXVECTOR2 delta); 94 | 95 | float distance, distanceVelocity; 96 | D3DXVECTOR2 panPosition, panVelocity; 97 | D3DXVECTOR2 angle, angularVelocity; 98 | D3DXVECTOR2 viewportSize; 99 | 100 | D3DXMATRIX view, projection; 101 | D3DXVECTOR3 lookAtPosition; 102 | D3DXVECTOR3 eyePosition; 103 | 104 | D3DXVECTOR2 mousePos; 105 | float attenuation; 106 | bool draggingLeft, draggingMiddle, draggingRight; 107 | }; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /Demo/Code/Support/DepthOfField.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include 33 | #include "DepthOfField.h" 34 | using namespace std; 35 | 36 | 37 | #pragma region Useful Macros from DXUT (copy-pasted here as we prefer this to be as self-contained as possible) 38 | #if defined(DEBUG) || defined(_DEBUG) 39 | #ifndef V 40 | #define V(x) { hr = (x); if (FAILED(hr)) { DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 41 | #endif 42 | #ifndef V_RETURN 43 | #define V_RETURN(x) { hr = (x); if (FAILED(hr)) { return DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 44 | #endif 45 | #else 46 | #ifndef V 47 | #define V(x) { hr = (x); } 48 | #endif 49 | #ifndef V_RETURN 50 | #define V_RETURN(x) { hr = (x); if( FAILED(hr) ) { return hr; } } 51 | #endif 52 | #endif 53 | 54 | #ifndef SAFE_DELETE 55 | #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } } 56 | #endif 57 | #ifndef SAFE_DELETE_ARRAY 58 | #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } } 59 | #endif 60 | #ifndef SAFE_RELEASE 61 | #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } 62 | #endif 63 | #pragma endregion 64 | 65 | 66 | DepthOfField::DepthOfField(ID3D10Device *device, int width, int height, DXGI_FORMAT format, float focusDistance, float focusRange, const D3DXVECTOR2 &focusFalloff, float blurWidth) 67 | : device(device), 68 | width(width), 69 | height(height), 70 | focusDistance(focusDistance), 71 | focusRange(focusRange), 72 | focusFalloff(focusFalloff), 73 | blurWidth(blurWidth) { 74 | 75 | HRESULT hr; 76 | 77 | V(D3DX10CreateEffectFromResource(GetModuleHandle(NULL), L"DepthOfField.fx", NULL, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL)); 78 | 79 | D3D10_PASS_DESC desc; 80 | V(effect->GetTechniqueByName("Blur")->GetPassByIndex(0)->GetDesc(&desc)); 81 | quad = new Quad(device, desc); 82 | 83 | tmpRT = new RenderTarget(device, width, height, format); 84 | cocRT = new RenderTarget(device, width, height, DXGI_FORMAT_R8_UNORM); 85 | } 86 | 87 | 88 | DepthOfField::~DepthOfField() { 89 | SAFE_RELEASE(effect); 90 | SAFE_DELETE(quad); 91 | SAFE_DELETE(tmpRT); 92 | SAFE_DELETE(cocRT); 93 | } 94 | 95 | 96 | void DepthOfField::go(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, ID3D10ShaderResourceView *depth) { 97 | SaveViewportsScope saveViewport(device); 98 | SaveRenderTargetsScope saveRenderTargets(device); 99 | SaveInputLayoutScope saveInputLayout(device); 100 | 101 | quad->setInputLayout(); 102 | 103 | coc(depth, *cocRT); 104 | horizontalBlur(src, *tmpRT, blurWidth); 105 | verticalBlur(*tmpRT, dst, blurWidth); 106 | } 107 | 108 | 109 | void DepthOfField::coc(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst) { 110 | HRESULT hr; 111 | 112 | D3D10_VIEWPORT viewport = Utils::viewportFromView(dst); 113 | device->RSSetViewports(1, &viewport); 114 | 115 | V(effect->GetVariableByName("focusDistance")->AsScalar()->SetFloat(focusDistance)); 116 | V(effect->GetVariableByName("focusRange")->AsScalar()->SetFloat(focusRange)); 117 | V(effect->GetVariableByName("focusFalloff")->AsVector()->SetFloatVector(focusFalloff)); 118 | V(effect->GetVariableByName("depthTex")->AsShaderResource()->SetResource(src)); 119 | V(effect->GetTechniqueByName("CoC")->GetPassByIndex(0)->Apply(0)); 120 | 121 | device->OMSetRenderTargets(1, &dst, NULL); 122 | quad->draw(); 123 | device->OMSetRenderTargets(0, NULL, NULL); 124 | } 125 | 126 | void DepthOfField::horizontalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, float width) { 127 | HRESULT hr; 128 | 129 | D3D10_VIEWPORT viewport = Utils::viewportFromView(dst); 130 | device->RSSetViewports(1, &viewport); 131 | 132 | D3DXVECTOR2 pixelSize = D3DXVECTOR2(1.0f / viewport.Width, 1.0f / viewport.Height); 133 | V(effect->GetVariableByName("pixelSize")->AsVector()->SetFloatVector(pixelSize)); 134 | V(effect->GetVariableByName("direction")->AsVector()->SetFloatVector(D3DXVECTOR2(1.0f, 0.0f))); 135 | V(effect->GetVariableByName("blurWidth")->AsScalar()->SetFloat(width)); 136 | V(effect->GetVariableByName("blurredTex")->AsShaderResource()->SetResource(src)); 137 | V(effect->GetVariableByName("cocTex")->AsShaderResource()->SetResource(*cocRT)); 138 | V(effect->GetTechniqueByName("Blur")->GetPassByIndex(0)->Apply(0)); 139 | 140 | device->OMSetRenderTargets(1, &dst, NULL); 141 | quad->draw(); 142 | device->OMSetRenderTargets(0, NULL, NULL); 143 | } 144 | 145 | void DepthOfField::verticalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, float width) { 146 | HRESULT hr; 147 | 148 | D3D10_VIEWPORT viewport = Utils::viewportFromView(dst); 149 | device->RSSetViewports(1, &viewport); 150 | 151 | D3DXVECTOR2 pixelSize = D3DXVECTOR2(1.0f / viewport.Width, 1.0f / viewport.Height); 152 | V(effect->GetVariableByName("pixelSize")->AsVector()->SetFloatVector(pixelSize)); 153 | V(effect->GetVariableByName("direction")->AsVector()->SetFloatVector(D3DXVECTOR2(0.0f, 1.0f))); 154 | V(effect->GetVariableByName("blurWidth")->AsScalar()->SetFloat(width)); 155 | V(effect->GetVariableByName("blurredTex")->AsShaderResource()->SetResource(src)); 156 | V(effect->GetVariableByName("cocTex")->AsShaderResource()->SetResource(*cocRT)); 157 | V(effect->GetTechniqueByName("Blur")->GetPassByIndex(0)->Apply(0)); 158 | 159 | device->OMSetRenderTargets(1, &dst, NULL); 160 | quad->draw(); 161 | device->OMSetRenderTargets(0, NULL, NULL); 162 | } 163 | -------------------------------------------------------------------------------- /Demo/Code/Support/DepthOfField.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef DEPTHOFFIELD_H 33 | #define DEPTHOFFIELD_H 34 | 35 | #include "RenderTarget.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | class DepthOfField { 42 | public: 43 | DepthOfField(ID3D10Device *device, int width, int height, DXGI_FORMAT format, float focusDistance, float focusRange, const D3DXVECTOR2 &focusFalloff, float blurWidth); 44 | ~DepthOfField(); 45 | 46 | void setBlurWidth(float blurWidth) { this->blurWidth = blurWidth; } 47 | float getBlurWidth() const { return blurWidth; } 48 | 49 | void setFocusDistance(float focusDistance) { this->focusDistance = focusDistance; } 50 | float getFocusDistance() const { return focusDistance; } 51 | 52 | void setFocusRange(float focusRange) { this->focusRange = focusRange; } 53 | float getFocusRange() const { return focusRange; } 54 | 55 | void setFocusFalloff(const D3DXVECTOR2 &focusFalloff) { this->focusFalloff = focusFalloff; } 56 | D3DXVECTOR2 getFocusFalloff() const { return focusFalloff; } 57 | 58 | void go(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, ID3D10ShaderResourceView *depth); 59 | 60 | private: 61 | void horizontalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, float width); 62 | void verticalBlur(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, float width); 63 | void coc(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst); 64 | 65 | ID3D10Device *device; 66 | int width, height; 67 | float blurWidth; 68 | float focusDistance; 69 | float focusRange; 70 | D3DXVECTOR2 focusFalloff; 71 | 72 | ID3D10Effect *effect; 73 | Quad *quad; 74 | RenderTarget *tmpRT; 75 | RenderTarget *cocRT; 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Demo/Code/Support/Fade.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include 33 | #include "Animation.h" 34 | #include "Fade.h" 35 | using namespace std; 36 | 37 | 38 | #pragma region Useful Macros from DXUT (copy-pasted here as we prefer this to be as self-contained as possible) 39 | #if defined(DEBUG) || defined(_DEBUG) 40 | #ifndef V 41 | #define V(x) { hr = (x); if (FAILED(hr)) { DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 42 | #endif 43 | #ifndef V_RETURN 44 | #define V_RETURN(x) { hr = (x); if (FAILED(hr)) { return DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 45 | #endif 46 | #else 47 | #ifndef V 48 | #define V(x) { hr = (x); } 49 | #endif 50 | #ifndef V_RETURN 51 | #define V_RETURN(x) { hr = (x); if( FAILED(hr) ) { return hr; } } 52 | #endif 53 | #endif 54 | 55 | #ifndef SAFE_DELETE 56 | #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } } 57 | #endif 58 | #ifndef SAFE_DELETE_ARRAY 59 | #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } } 60 | #endif 61 | #ifndef SAFE_RELEASE 62 | #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } 63 | #endif 64 | #pragma endregion 65 | 66 | 67 | ID3D10Device *Fade::device; 68 | ID3D10BlendState *Fade::spriteBlendState; 69 | ID3D10Effect *Fade::effect; 70 | Quad *Fade::quad; 71 | 72 | 73 | void Fade::init(ID3D10Device *device) { 74 | Fade::device = device; 75 | 76 | HRESULT hr; 77 | 78 | D3D10_BLEND_DESC blendDesc; 79 | ZeroMemory(&blendDesc, sizeof(D3D10_BLEND_DESC)); 80 | blendDesc.AlphaToCoverageEnable = FALSE; 81 | blendDesc.BlendEnable[0] = TRUE; 82 | blendDesc.SrcBlend = D3D10_BLEND_ZERO; 83 | blendDesc.DestBlend = D3D10_BLEND_SRC_ALPHA; 84 | blendDesc.BlendOp = D3D10_BLEND_OP_ADD; 85 | blendDesc.SrcBlendAlpha = D3D10_BLEND_ZERO; 86 | blendDesc.DestBlendAlpha = D3D10_BLEND_ZERO; 87 | blendDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; 88 | blendDesc.RenderTargetWriteMask[0] = 0xf; 89 | device->CreateBlendState(&blendDesc, &spriteBlendState); 90 | 91 | string s = "float alpha;" 92 | "float4 VS(float4 position: POSITION, float2 texcoord: TEXCOORD0) : SV_POSITION { return position; }" 93 | "float4 PS() : SV_TARGET { return float4(0.0, 0.0, 0.0, alpha); }" 94 | "DepthStencilState DisableDepthStencil { DepthEnable = FALSE; StencilEnable = FALSE; };" 95 | "technique10 Black { pass Black {" 96 | "SetVertexShader(CompileShader(vs_4_0, VS())); SetGeometryShader(NULL); SetPixelShader(CompileShader(ps_4_0, PS()));" 97 | "SetDepthStencilState(DisableDepthStencil, 0);" 98 | "}}"; 99 | V(D3DX10CreateEffectFromMemory(s.c_str(), s.length(), NULL, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL)); 100 | 101 | D3D10_PASS_DESC desc; 102 | V(effect->GetTechniqueByName("Black")->GetPassByIndex(0)->GetDesc(&desc)); 103 | quad = new Quad(device, desc); 104 | } 105 | 106 | 107 | void Fade::release() { 108 | SAFE_RELEASE(spriteBlendState); 109 | SAFE_RELEASE(effect); 110 | SAFE_DELETE(quad); 111 | } 112 | 113 | 114 | void Fade::linear(float t, float in, float out, float inLength, float outLength) { 115 | go(Animation::linearFade(t, in, out, inLength, outLength)); 116 | } 117 | 118 | 119 | void Fade::smooth(float t, float in, float out, float inLength, float outLength) { 120 | go(Animation::smoothFade(t, in, out, inLength, outLength)); 121 | } 122 | 123 | 124 | void Fade::go(float fade) { 125 | device->OMSetBlendState(spriteBlendState, 0, 0xffffffff); 126 | HRESULT hr; 127 | if (fade < 1.0f) { 128 | V(effect->GetVariableByName("alpha")->AsScalar()->SetFloat(pow(fade, 2.2f))); 129 | V(effect->GetTechniqueByName("Black")->GetPassByIndex(0)->Apply(0)); 130 | quad->setInputLayout(); 131 | quad->draw(); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /Demo/Code/Support/Fade.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef FADE_H 33 | #define FADE_H 34 | 35 | #include "RenderTarget.h" 36 | 37 | class Fade { 38 | public: 39 | static void init(ID3D10Device *device); 40 | static void release(); 41 | 42 | static void linear(float t, float in, float out, float inLength, float outLength); 43 | static void smooth(float t, float in, float out, float inLength, float outLength); 44 | static void go(float fade); 45 | 46 | private: 47 | static ID3D10Device *device; 48 | static ID3D10BlendState *spriteBlendState; 49 | static ID3D10Effect *effect; 50 | static Quad *quad; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Demo/Code/Support/FilmGrain.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include 33 | #include "FilmGrain.h" 34 | using namespace std; 35 | 36 | 37 | #pragma region Useful Macros from DXUT (copy-pasted here as we prefer this to be as self-contained as possible) 38 | #if defined(DEBUG) || defined(_DEBUG) 39 | #ifndef V 40 | #define V(x) { hr = (x); if (FAILED(hr)) { DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 41 | #endif 42 | #ifndef V_RETURN 43 | #define V_RETURN(x) { hr = (x); if (FAILED(hr)) { return DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 44 | #endif 45 | #else 46 | #ifndef V 47 | #define V(x) { hr = (x); } 48 | #endif 49 | #ifndef V_RETURN 50 | #define V_RETURN(x) { hr = (x); if( FAILED(hr) ) { return hr; } } 51 | #endif 52 | #endif 53 | 54 | #ifndef SAFE_DELETE 55 | #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } } 56 | #endif 57 | #ifndef SAFE_DELETE_ARRAY 58 | #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } } 59 | #endif 60 | #ifndef SAFE_RELEASE 61 | #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } 62 | #endif 63 | #pragma endregion 64 | 65 | 66 | FilmGrain::FilmGrain(ID3D10Device *device, int width, int height, float noiseIntensity, float exposure) 67 | : device(device), 68 | width(width), 69 | height(height), 70 | noiseIntensity(noiseIntensity), 71 | exposure(exposure) { 72 | 73 | HRESULT hr; 74 | 75 | V(D3DX10CreateEffectFromResource(GetModuleHandle(NULL), L"FilmGrain.fx", NULL, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL)); 76 | 77 | D3D10_PASS_DESC desc; 78 | V(effect->GetTechniqueByName("FilmGrain")->GetPassByIndex(0)->GetDesc(&desc)); 79 | quad = new Quad(device, desc); 80 | 81 | D3DX10_IMAGE_LOAD_INFO loadInfo; 82 | ZeroMemory(&loadInfo, sizeof(D3DX10_IMAGE_LOAD_INFO)); 83 | loadInfo.BindFlags = D3D10_BIND_SHADER_RESOURCE; 84 | loadInfo.MipLevels = 1; 85 | loadInfo.Format = DXGI_FORMAT_R8_UNORM; 86 | V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), L"Noise.dds", &loadInfo, NULL, &noiseSRV, NULL)); 87 | } 88 | 89 | 90 | FilmGrain::~FilmGrain() { 91 | SAFE_RELEASE(effect); 92 | SAFE_DELETE(quad); 93 | SAFE_RELEASE(noiseSRV); 94 | } 95 | 96 | 97 | void FilmGrain::go(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, float t) { 98 | HRESULT hr; 99 | 100 | SaveViewportsScope saveViewport(device); 101 | SaveRenderTargetsScope saveRenderTargets(device); 102 | SaveInputLayoutScope saveInputLayout(device); 103 | 104 | quad->setInputLayout(); 105 | 106 | D3DXVECTOR2 pixelSize = D3DXVECTOR2(1.0f / width, 1.0f / height); 107 | V(effect->GetVariableByName("pixelSize")->AsVector()->SetFloatVector(pixelSize)); 108 | V(effect->GetVariableByName("noiseIntensity")->AsScalar()->SetFloat(noiseIntensity)); 109 | V(effect->GetVariableByName("exposure")->AsScalar()->SetFloat(exposure)); 110 | V(effect->GetVariableByName("t")->AsScalar()->SetFloat(t)); 111 | V(effect->GetVariableByName("srcTex")->AsShaderResource()->SetResource(src)); 112 | V(effect->GetVariableByName("noiseTex")->AsShaderResource()->SetResource(noiseSRV)); 113 | 114 | D3D10_VIEWPORT viewport = Utils::viewportFromView(dst); 115 | device->RSSetViewports(1, &viewport); 116 | 117 | V(effect->GetTechniqueByName("FilmGrain")->GetPassByIndex(0)->Apply(0)); 118 | 119 | device->OMSetRenderTargets(1, &dst, NULL); 120 | quad->draw(); 121 | device->OMSetRenderTargets(0, NULL, NULL); 122 | } 123 | -------------------------------------------------------------------------------- /Demo/Code/Support/FilmGrain.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef FILMGRAIN_H 33 | #define FILMGRAIN_H 34 | 35 | #include "RenderTarget.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | class FilmGrain { 42 | public: 43 | FilmGrain(ID3D10Device *device, int width, int height, float noiseIntensity=1.0f, float exposure=1.0f); 44 | ~FilmGrain(); 45 | 46 | void setNoiseIntensity(float noiseIntensity) { this->noiseIntensity = noiseIntensity; } 47 | float getNoiseIntensity() const { return noiseIntensity; } 48 | 49 | void setExposure(float exposure) { this->exposure = exposure; } 50 | float getExposure() const { return exposure; } 51 | 52 | void go(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, float t); 53 | 54 | private: 55 | ID3D10Device *device; 56 | int width, height; 57 | 58 | float noiseIntensity; 59 | float exposure; 60 | 61 | ID3D10Effect *effect; 62 | Quad *quad; 63 | ID3D10ShaderResourceView *noiseSRV; 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /Demo/Code/Support/RenderTarget.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef RENDERTARGET_H 33 | #define RENDERTARGET_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | class NoMSAA : public DXGI_SAMPLE_DESC { 43 | public: 44 | inline NoMSAA() { 45 | Count = 1; 46 | Quality = 0; 47 | } 48 | }; 49 | 50 | 51 | class RenderTarget { 52 | public: 53 | RenderTarget(ID3D10Device *device, int width, int height, 54 | DXGI_FORMAT format, 55 | const DXGI_SAMPLE_DESC &sampleDesc=NoMSAA(), 56 | bool typeless=true); 57 | 58 | /** 59 | * These two are just convenience constructors to build from existing 60 | * resources. 61 | */ 62 | RenderTarget(ID3D10Device *device, ID3D10Texture2D *texture2D, DXGI_FORMAT format); 63 | RenderTarget(ID3D10Device *device, 64 | ID3D10RenderTargetView *renderTargetView, 65 | ID3D10ShaderResourceView *shaderResourceView); 66 | 67 | ~RenderTarget(); 68 | 69 | operator ID3D10Texture2D * () const { return texture2D; } 70 | operator ID3D10RenderTargetView * () const { return renderTargetView; } 71 | operator ID3D10RenderTargetView *const * () const { return &renderTargetView; } 72 | operator ID3D10ShaderResourceView * () const { return shaderResourceView; } 73 | 74 | int getWidth() const { return width; } 75 | int getHeight() const { return height; } 76 | 77 | void setViewport(float minDepth=0.0f, float maxDepth=1.0f) const; 78 | 79 | static DXGI_FORMAT makeTypeless(DXGI_FORMAT format); 80 | 81 | private: 82 | void createViews(ID3D10Device *device, D3D10_TEXTURE2D_DESC desc, DXGI_FORMAT format); 83 | 84 | ID3D10Device *device; 85 | int width, height; 86 | ID3D10Texture2D *texture2D; 87 | ID3D10RenderTargetView *renderTargetView; 88 | ID3D10ShaderResourceView *shaderResourceView; 89 | }; 90 | 91 | 92 | class DepthStencil { 93 | public: 94 | DepthStencil(ID3D10Device *device, int width, int height, 95 | DXGI_FORMAT texture2DFormat = DXGI_FORMAT_R32_TYPELESS, 96 | DXGI_FORMAT depthStencilViewFormat = DXGI_FORMAT_D32_FLOAT, 97 | DXGI_FORMAT shaderResourceViewFormat = DXGI_FORMAT_R32_FLOAT, 98 | const DXGI_SAMPLE_DESC &sampleDesc=NoMSAA()); 99 | ~DepthStencil(); 100 | 101 | operator ID3D10Texture2D * const () { return texture2D; } 102 | operator ID3D10DepthStencilView * const () { return depthStencilView; } 103 | operator ID3D10ShaderResourceView * const () { return shaderResourceView; } 104 | 105 | int getWidth() const { return width; } 106 | int getHeight() const { return height; } 107 | 108 | void setViewport(float minDepth=0.0f, float maxDepth=1.0f) const; 109 | 110 | private: 111 | ID3D10Device *device; 112 | int width, height; 113 | ID3D10Texture2D *texture2D; 114 | ID3D10DepthStencilView *depthStencilView; 115 | ID3D10ShaderResourceView *shaderResourceView; 116 | }; 117 | 118 | 119 | class BackbufferRenderTarget { 120 | public: 121 | BackbufferRenderTarget(ID3D10Device *device, IDXGISwapChain *swapChain); 122 | ~BackbufferRenderTarget(); 123 | 124 | operator ID3D10Texture2D * () const { return texture2D; } 125 | operator ID3D10RenderTargetView * () const { return renderTargetView; } 126 | operator ID3D10RenderTargetView *const * () const { return &renderTargetView; } 127 | operator ID3D10ShaderResourceView * () const { return shaderResourceView; } 128 | 129 | int getWidth() const { return width; } 130 | int getHeight() const { return height; } 131 | 132 | private: 133 | int width, height; 134 | ID3D10Texture2D *texture2D; 135 | ID3D10RenderTargetView *renderTargetView; 136 | ID3D10ShaderResourceView *shaderResourceView; 137 | }; 138 | 139 | 140 | class Quad { 141 | public: 142 | Quad(ID3D10Device *device, const D3D10_PASS_DESC &desc); 143 | ~Quad(); 144 | void setInputLayout() { device->IASetInputLayout(vertexLayout); } 145 | void draw(); 146 | 147 | private: 148 | ID3D10Device *device; 149 | ID3D10Buffer *buffer; 150 | ID3D10InputLayout *vertexLayout; 151 | }; 152 | 153 | 154 | class SaveViewportsScope { 155 | public: 156 | SaveViewportsScope(ID3D10Device *device); 157 | ~SaveViewportsScope(); 158 | 159 | private: 160 | ID3D10Device *device; 161 | UINT numViewports; 162 | std::vector viewports; 163 | }; 164 | 165 | 166 | class SaveRenderTargetsScope { 167 | public: 168 | SaveRenderTargetsScope(ID3D10Device *device); 169 | ~SaveRenderTargetsScope(); 170 | 171 | private: 172 | ID3D10Device *device; 173 | ID3D10RenderTargetView *renderTargets[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT]; 174 | ID3D10DepthStencilView *depthStencil; 175 | }; 176 | 177 | 178 | class SaveInputLayoutScope { 179 | public: 180 | SaveInputLayoutScope(ID3D10Device *device); 181 | ~SaveInputLayoutScope(); 182 | 183 | private: 184 | ID3D10Device *device; 185 | ID3D10InputLayout *inputLayout; 186 | }; 187 | 188 | 189 | class SaveBlendStateScope { 190 | public: 191 | SaveBlendStateScope(ID3D10Device *device); 192 | ~SaveBlendStateScope(); 193 | 194 | private: 195 | ID3D10Device *device; 196 | ID3D10BlendState *blendState; 197 | FLOAT blendFactor[4]; 198 | UINT sampleMask; 199 | }; 200 | 201 | 202 | class SaveDepthStencilScope { 203 | public: 204 | SaveDepthStencilScope(ID3D10Device *device); 205 | ~SaveDepthStencilScope(); 206 | 207 | private: 208 | ID3D10Device *device; 209 | ID3D10DepthStencilState *depthStencilState; 210 | UINT stencilRef; 211 | }; 212 | 213 | 214 | class Utils { 215 | public: 216 | static ID3D10Texture2D *createStagingTexture(ID3D10Device *device, ID3D10Texture2D *texture); 217 | static D3D10_VIEWPORT viewportFromView(ID3D10View *view); 218 | static D3D10_VIEWPORT viewportFromTexture2D(ID3D10Texture2D *texture2D); 219 | }; 220 | 221 | #endif 222 | -------------------------------------------------------------------------------- /Demo/Code/Support/ShadowMap.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include "DXUT.h" 33 | #include "ShadowMap.h" 34 | 35 | 36 | ID3D10Effect *ShadowMap::effect; 37 | ID3D10InputLayout *ShadowMap::vertexLayout; 38 | 39 | 40 | void ShadowMap::init(ID3D10Device *device) { 41 | HRESULT hr; 42 | if (effect == NULL) 43 | V(D3DX10CreateEffectFromResource(GetModuleHandle(NULL), L"ShadowMap.fx", NULL, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL)); 44 | 45 | const D3D10_INPUT_ELEMENT_DESC layout[] = { 46 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0 } 47 | }; 48 | UINT numElements = sizeof(layout) / sizeof(D3D10_INPUT_ELEMENT_DESC); 49 | 50 | D3D10_PASS_DESC desc; 51 | V(effect->GetTechniqueByName("ShadowMap")->GetPassByIndex(0)->GetDesc(&desc)); 52 | V(device->CreateInputLayout(layout, numElements, desc.pIAInputSignature, desc.IAInputSignatureSize, &vertexLayout)); 53 | } 54 | 55 | 56 | void ShadowMap::release() { 57 | SAFE_RELEASE(effect); 58 | SAFE_RELEASE(vertexLayout); 59 | } 60 | 61 | 62 | ShadowMap::ShadowMap(ID3D10Device *device, int width, int height) 63 | : device(device) { 64 | depthStencil = new DepthStencil(device, width, height); 65 | } 66 | 67 | 68 | ShadowMap::~ShadowMap() { 69 | SAFE_DELETE(depthStencil); 70 | } 71 | 72 | 73 | void ShadowMap::begin(const D3DXMATRIX &view, const D3DXMATRIX &projection) { 74 | HRESULT hr; 75 | 76 | device->IASetInputLayout(vertexLayout); 77 | 78 | device->ClearDepthStencilView(*depthStencil, D3D10_CLEAR_DEPTH, 1.0, 0); 79 | 80 | /** 81 | * This is for rendering linear values: 82 | * Check this: http://www.mvps.org/directx/articles/linear_z/linearz.htm 83 | */ 84 | D3DXMATRIX linearProjection = projection; 85 | float Q = projection._33; 86 | float N = -projection._43 / projection._33; 87 | float F = -N * Q / (1 - Q); 88 | linearProjection._33 /= F; 89 | linearProjection._43 /= F; 90 | 91 | V(effect->GetVariableByName("view")->AsMatrix()->SetMatrix((float*) &view)); 92 | V(effect->GetVariableByName("projection")->AsMatrix()->SetMatrix((float*) &linearProjection)); 93 | 94 | device->OMSetRenderTargets(0, NULL, *depthStencil); 95 | 96 | UINT numViewports = 1; 97 | device->RSGetViewports(&numViewports, &viewport); 98 | depthStencil->setViewport(); 99 | } 100 | 101 | 102 | void ShadowMap::setWorldMatrix(const D3DXMATRIX &world) { 103 | HRESULT hr; 104 | V(effect->GetVariableByName("world")->AsMatrix()->SetMatrix((float*) &world)); 105 | } 106 | 107 | 108 | void ShadowMap::end() { 109 | device->RSSetViewports(1, &viewport); 110 | device->OMSetRenderTargets(0, NULL, NULL); 111 | } 112 | 113 | 114 | D3DXMATRIX ShadowMap::getViewProjectionTextureMatrix(const D3DXMATRIX &view, const D3DXMATRIX &projection) { 115 | D3DXMATRIX scale; 116 | D3DXMatrixScaling(&scale, 0.5f, -0.5f, 1.0f); 117 | 118 | D3DXMATRIX translation; 119 | D3DXMatrixTranslation(&translation, 0.5f, 0.5f, 0.0f); 120 | 121 | return view * projection * scale * translation; 122 | } 123 | -------------------------------------------------------------------------------- /Demo/Code/Support/ShadowMap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef SHADOWMAP_H 33 | #define SHADOWMAP_H 34 | 35 | #include "RenderTarget.h" 36 | 37 | class ShadowMap { 38 | public: 39 | static void init(ID3D10Device *device); 40 | static void release(); 41 | 42 | ShadowMap(ID3D10Device *device, int width, int height); 43 | ~ShadowMap(); 44 | 45 | void begin(const D3DXMATRIX &view, const D3DXMATRIX &projection); 46 | void setWorldMatrix(const D3DXMATRIX &world); 47 | void end(); 48 | 49 | ID3D10EffectTechnique *getTechnique() const { return effect->GetTechniqueByName("ShadowMap"); } 50 | operator ID3D10ShaderResourceView * const () { return *depthStencil; } 51 | 52 | static D3DXMATRIX getViewProjectionTextureMatrix(const D3DXMATRIX &view, const D3DXMATRIX &projection); 53 | 54 | private: 55 | ID3D10Device *device; 56 | DepthStencil *depthStencil; 57 | D3D10_VIEWPORT viewport; 58 | 59 | static ID3D10Effect *effect; 60 | static ID3D10InputLayout *vertexLayout; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Demo/Code/Support/SkyDome.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include 33 | #include 34 | #include "SkyDome.h" 35 | using namespace std; 36 | 37 | 38 | SkyDome::SkyDome(ID3D10Device *device, const std::wstring &dir, float intensity) 39 | : device(device), 40 | intensity(intensity), 41 | angle(0.0f, 0.0f) { 42 | HRESULT hr; 43 | V(D3DX10CreateEffectFromResource(GetModuleHandle(NULL), L"SkyDome.fx", NULL, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL)); 44 | createMesh(dir); 45 | } 46 | 47 | 48 | SkyDome::~SkyDome() { 49 | SAFE_RELEASE(effect); 50 | mesh.Destroy(); 51 | } 52 | 53 | 54 | void SkyDome::render(const D3DXMATRIX &view, const D3DXMATRIX &projection, float scale) { 55 | HRESULT hr; 56 | 57 | D3DXMATRIX world; 58 | D3DXMatrixScaling(&world, scale, scale, scale); 59 | 60 | D3DXMATRIX t; 61 | D3DXMatrixRotationX(&t, angle.y); 62 | world = t * world; 63 | 64 | D3DXMatrixRotationY(&t, angle.x); 65 | world = t * world; 66 | 67 | V(effect->GetVariableByName("world")->AsMatrix()->SetMatrix((D3DXMATRIX) world)); 68 | V(effect->GetVariableByName("view")->AsMatrix()->SetMatrix((D3DXMATRIX) view)); 69 | V(effect->GetVariableByName("projection")->AsMatrix()->SetMatrix((D3DXMATRIX) projection)); 70 | V(effect->GetVariableByName("intensity")->AsScalar()->SetFloat(intensity)); 71 | 72 | mesh.Render(device, effect->GetTechniqueByName("RenderSkyDome"), effect->GetVariableByName("skyTex")->AsShaderResource()); 73 | } 74 | 75 | 76 | void SkyDome::setDirectory(const std::wstring &dir) { 77 | mesh.Destroy(); 78 | createMesh(dir); 79 | } 80 | 81 | 82 | void SkyDome::createMesh(const std::wstring &dir) { 83 | HRESULT hr; 84 | 85 | HRSRC src = FindResource(GetModuleHandle(NULL), (dir + L"\\SkyDome.sdkmesh").c_str(), RT_RCDATA); 86 | HGLOBAL res = LoadResource(GetModuleHandle(NULL), src); 87 | UINT size = SizeofResource(GetModuleHandle(NULL), src); 88 | LPBYTE data = (LPBYTE) LockResource(res); 89 | 90 | SDKMESH_CALLBACKS10 callbacks; 91 | ZeroMemory(&callbacks, sizeof(SDKMESH_CALLBACKS10)); 92 | callbacks.pCreateTextureFromFile = &createTextureFromFile; 93 | callbacks.pContext = (void *) dir.c_str(); 94 | 95 | V(mesh.Create(device, data, size, true, true, &callbacks)); 96 | } 97 | 98 | 99 | void CALLBACK SkyDome::createTextureFromFile(ID3D10Device* device, 100 | char *filename, ID3D10ShaderResourceView **shaderResourceView, 101 | void *context, 102 | bool srgb) { 103 | if (string(filename) != "default-normalmap.dds") { 104 | HRESULT hr; 105 | 106 | wstringstream s; 107 | s << ((wchar_t *) context) << "\\" << filename; 108 | 109 | V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), s.str().c_str(), NULL, NULL, shaderResourceView, NULL)); 110 | } else { 111 | *shaderResourceView = (ID3D10ShaderResourceView *) ERROR_RESOURCE_VALUE; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Demo/Code/Support/SkyDome.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef SKYDOME_H 33 | #define SKYDOME_H 34 | 35 | #include 36 | #include "SDKmisc.h" 37 | #include "SDKmesh.h" 38 | #include "RenderTarget.h" 39 | 40 | class SkyDome { 41 | public: 42 | SkyDome(ID3D10Device *device, const std::wstring &dir, float intensity=1.0f); 43 | ~SkyDome(); 44 | 45 | void render(const D3DXMATRIX &view, const D3DXMATRIX &projection, float scale); 46 | void setDirectory(const std::wstring &dir); 47 | 48 | void setIntensity(float intensity) { this->intensity = intensity; } 49 | float getIntensity() const { return intensity; } 50 | 51 | void setAngle(const D3DXVECTOR2 &angle) { this->angle = angle; } 52 | D3DXVECTOR2 getAngle() const { return angle; } 53 | 54 | private: 55 | void createMesh(const std::wstring &dir); 56 | static void CALLBACK createTextureFromFile(ID3D10Device* device, 57 | char *filename, 58 | ID3D10ShaderResourceView **shaderResourceView, 59 | void *context, 60 | bool srgb); 61 | 62 | ID3D10Device *device; 63 | ID3D10Effect *effect; 64 | CDXUTSDKMesh mesh; 65 | float intensity; 66 | D3DXVECTOR2 angle; 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Demo/Code/Support/SplashScreen.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include 33 | #include "SplashScreen.h" 34 | #include "Animation.h" 35 | using namespace std; 36 | 37 | 38 | SplashScreen::SplashScreen(ID3D10Device *device, ID3DX10Sprite *sprite) 39 | : device(device), sprite(sprite) { 40 | HRESULT hr; 41 | 42 | D3DX10_IMAGE_LOAD_INFO loadInfo; 43 | ZeroMemory(&loadInfo, sizeof(D3DX10_IMAGE_LOAD_INFO)); 44 | loadInfo.BindFlags = D3D10_BIND_SHADER_RESOURCE; 45 | loadInfo.MipLevels = 1; 46 | loadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; 47 | loadInfo.Filter = D3DX10_FILTER_POINT | D3DX10_FILTER_SRGB_IN; 48 | V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), L"SmallTitles.dds", &loadInfo, NULL, &smallTitlesSRV, NULL)); 49 | V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), L"BigTitles.dds", &loadInfo, NULL, &bigTitlesSRV, NULL)); 50 | V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), L"Background.png", &loadInfo, NULL, &backgroundSRV, NULL)); 51 | 52 | D3D10_BLEND_DESC blendDesc; 53 | ZeroMemory(&blendDesc, sizeof(D3D10_BLEND_DESC)); 54 | blendDesc.AlphaToCoverageEnable = FALSE; 55 | blendDesc.BlendEnable[0] = TRUE; 56 | blendDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA; 57 | blendDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; 58 | blendDesc.BlendOp = D3D10_BLEND_OP_ADD; 59 | blendDesc.SrcBlendAlpha = D3D10_BLEND_ZERO; 60 | blendDesc.DestBlendAlpha = D3D10_BLEND_ZERO; 61 | blendDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; 62 | blendDesc.RenderTargetWriteMask[0] = 0xf; 63 | V(device->CreateBlendState(&blendDesc, &spriteBlendState)); 64 | } 65 | 66 | 67 | SplashScreen::~SplashScreen() { 68 | SAFE_RELEASE(smallTitlesSRV); 69 | SAFE_RELEASE(bigTitlesSRV); 70 | SAFE_RELEASE(backgroundSRV); 71 | SAFE_RELEASE(spriteBlendState); 72 | } 73 | 74 | 75 | void SplashScreen::intro(float t) { 76 | HRESULT hr; 77 | 78 | float clearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; 79 | device->ClearRenderTargetView(DXUTGetD3D10RenderTargetView(), clearColor); 80 | 81 | D3D10_VIEWPORT viewport; 82 | UINT numViewports = 1; 83 | device->RSGetViewports(&numViewports, &viewport); 84 | 85 | D3DX10_SPRITE s[7]; 86 | s[0] = newSprite(backgroundSRV, viewport, 0, 0, 0, 1, 1920, 1080, Animation::linearFade(t, 0.0f, 16.0f, 2.0f, 3.0f)); // Gradient 87 | s[1] = newSprite(smallTitlesSRV, viewport, 0, 45, 0, 7, 1024, 24, Animation::linearFade(t, 1.0f, 7.5f, 2.0f, 2.0f)); // Jorge Jimenez 88 | s[2] = newSprite(smallTitlesSRV, viewport, 0, -15, 1, 7, 1024, 24, Animation::linearFade(t, 1.5f, 7.5f, 2.0f, 2.0f)); // Diego Gutierrez 89 | s[3] = newSprite(smallTitlesSRV, viewport, 0, -95, 2, 7, 1024, 24, Animation::linearFade(t, 2.0f, 7.5f, 2.5f, 2.0f)); // Universidad de Zaragoza 90 | s[4] = newSprite(bigTitlesSRV, viewport, 0, 20, 0, 1, 1174, 127, Animation::linearFade(t, 8.0f, 14.0f, 1.0f, 3.0f)); // SSSS 91 | s[5] = newSprite(smallTitlesSRV, viewport, -45, 30, 3, 7, 1024, 24, Animation::linearFade(t, 15.0f, 25.0f, 2.0f, 3.0f)); // It is our imperfections... 92 | s[6] = newSprite(smallTitlesSRV, viewport, 45, -30, 4, 7, 1024, 24, Animation::linearFade(t, 18.0f, 25.0f, 2.0f, 3.0f)); // ...That makes us so perfect 93 | 94 | device->OMSetBlendState(spriteBlendState, 0, 0xffffffff); 95 | V(sprite->Begin(D3DX10_SPRITE_SAVE_STATE)); 96 | V(sprite->DrawSpritesImmediate(s, 7, 0, 0)); 97 | V(sprite->End()); 98 | } 99 | 100 | 101 | void SplashScreen::outro(float t) { 102 | HRESULT hr; 103 | 104 | float clearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; 105 | device->ClearRenderTargetView(DXUTGetD3D10RenderTargetView(), clearColor); 106 | 107 | D3D10_VIEWPORT viewport; 108 | UINT numViewports = 1; 109 | device->RSGetViewports(&numViewports, &viewport); 110 | 111 | D3DX10_SPRITE s[3]; 112 | s[0] = newSprite(smallTitlesSRV, viewport, 0, 0, 6, 7, 1024, 24, Animation::linearFade(t, 3.0f, 9.0f, 2.0f, 3.0f)); // To the memory of my Father 113 | s[1] = newSprite(bigTitlesSRV, viewport, 0, 20, 0, 1, 1174, 127, Animation::linearFade(t, 10.0f, 19.0f, 1.0f, 3.0f)); // SSSS 114 | s[2] = newSprite(smallTitlesSRV, viewport, 0, -120, 5, 7, 1024, 24, Animation::linearFade(t, 10.0f, 17.0f, 1.0f, 3.0f)); // www.iryoku.com 115 | 116 | device->OMSetBlendState(spriteBlendState, 0, 0xffffffff); 117 | V(sprite->Begin(D3DX10_SPRITE_SAVE_STATE)); 118 | V(sprite->DrawSpritesImmediate(s, 3, 0, 0)); 119 | V(sprite->End()); 120 | } 121 | 122 | 123 | D3DX10_SPRITE SplashScreen::newSprite(ID3D10ShaderResourceView *spriteSRV, const D3D10_VIEWPORT &viewport, 124 | int x, int y, int i, int n, int width, int height, float alpha) { 125 | D3DXMATRIX scale, translation; 126 | D3DXMatrixScaling(&scale, 2.0f * width / viewport.Width, 2.0f * height / viewport.Height, 1.0f); 127 | D3DXMatrixTranslation(&translation, 2.0f * float(x) / viewport.Width, 2.0f * float(y) / viewport.Height, 0.0f); 128 | 129 | D3DX10_SPRITE s; 130 | s.ColorModulate = D3DXCOLOR(1.0f, 1.0f, 1.0f, pow(alpha, 2.2f)); 131 | s.matWorld = scale * translation; 132 | s.pTexture = spriteSRV; 133 | s.TexCoord = D3DXVECTOR2(0.0f, float(i) / n); 134 | s.TexSize = D3DXVECTOR2(1.0f, 1.0f / n); 135 | s.TextureIndex = 0; 136 | return s; 137 | } 138 | -------------------------------------------------------------------------------- /Demo/Code/Support/SplashScreen.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef SPLASHSCREEN_H 33 | #define SPLASHSCREEN_H 34 | 35 | #include "RenderTarget.h" 36 | 37 | class SplashScreen { 38 | public: 39 | SplashScreen(ID3D10Device *device, ID3DX10Sprite *sprite); 40 | ~SplashScreen(); 41 | 42 | void intro(float t); 43 | void outro(float t); 44 | bool introHasFinished(float t) const { return t > 28.0f; } 45 | bool outroHasFinished(float t) const { return t > 21.0f; } 46 | 47 | private: 48 | D3DX10_SPRITE newSprite(ID3D10ShaderResourceView *spriteSRV, const D3D10_VIEWPORT &viewport, 49 | int x, int y, int i, int n, int width, int height, float alpha); 50 | void renderGradient(float fade); 51 | 52 | ID3D10Device *device; 53 | 54 | ID3DX10Sprite *sprite; 55 | ID3D10ShaderResourceView *smallTitlesSRV; 56 | ID3D10ShaderResourceView *bigTitlesSRV; 57 | ID3D10ShaderResourceView *backgroundSRV; 58 | ID3D10BlendState *spriteBlendState; 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Demo/Code/Support/Timer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #include "timer.h" 33 | using namespace std; 34 | 35 | 36 | #pragma region Useful Macros from DXUT (copy-pasted here as we prefer this to be as self-contained as possible) 37 | #if defined(DEBUG) || defined(_DEBUG) 38 | #ifndef V 39 | #define V(x) { hr = (x); if (FAILED(hr)) { DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 40 | #endif 41 | #ifndef V_RETURN 42 | #define V_RETURN(x) { hr = (x); if (FAILED(hr)) { return DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); } } 43 | #endif 44 | #else 45 | #ifndef V 46 | #define V(x) { hr = (x); } 47 | #endif 48 | #ifndef V_RETURN 49 | #define V_RETURN(x) { hr = (x); if( FAILED(hr) ) { return hr; } } 50 | #endif 51 | #endif 52 | 53 | #ifndef SAFE_DELETE 54 | #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } } 55 | #endif 56 | #ifndef SAFE_DELETE_ARRAY 57 | #define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } } 58 | #endif 59 | #ifndef SAFE_RELEASE 60 | #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } 61 | #endif 62 | #pragma endregion 63 | 64 | 65 | #ifdef TIMER_DIRECTX_9 66 | Timer::Timer(IDirect3DDevice9 *device) : enabled(true), flushEnabled(true), windowSize(10), repetitionCount(1) { 67 | HRESULT hr; 68 | 69 | V(device->CreateQuery(D3DQUERYTYPE_EVENT, &event)); 70 | 71 | start(); 72 | } 73 | #else 74 | Timer::Timer(ID3D10Device *device) : enabled(true), flushEnabled(true), windowSize(10), repetitionCount(1) { 75 | HRESULT hr; 76 | 77 | D3D10_QUERY_DESC desc; 78 | desc.Query = D3D10_QUERY_EVENT; 79 | desc.MiscFlags = 0; 80 | V(device->CreateQuery(&desc, &event)); 81 | 82 | start(); 83 | } 84 | #endif 85 | 86 | 87 | Timer::~Timer() { 88 | SAFE_RELEASE(event); 89 | } 90 | 91 | 92 | void Timer::start() { 93 | if (enabled) { 94 | if (flushEnabled) 95 | flush(); 96 | 97 | accum = 0.0f; 98 | QueryPerformanceCounter((LARGE_INTEGER*) &t0); 99 | } 100 | } 101 | 102 | 103 | float Timer::clock(const wstring &msg) { 104 | if (enabled) { 105 | if (flushEnabled) 106 | flush(); 107 | 108 | __int64 t1, freq; 109 | QueryPerformanceCounter((LARGE_INTEGER*) &t1); 110 | QueryPerformanceFrequency((LARGE_INTEGER*) &freq); 111 | float t = float(double(t1 - t0) / double(freq)); 112 | 113 | float m = mean(msg, t); 114 | accum += m; 115 | 116 | QueryPerformanceCounter((LARGE_INTEGER*) &t0); 117 | 118 | return m; 119 | } else { 120 | return 0.0f; 121 | } 122 | } 123 | 124 | 125 | void Timer::sleep(float t) { 126 | Sleep(max(int(1000.0f * (t - clock())), 0)); 127 | } 128 | 129 | 130 | float Timer::mean(const std::wstring &msg, float t) { 131 | Section §ion = sections[msg]; 132 | if (windowSize > 1) { 133 | section.buffer.resize(windowSize, make_pair(0.0f, false)); 134 | section.buffer[(section.pos++) % windowSize] = make_pair(t, true); 135 | 136 | section.mean = 0.0; 137 | float n = 0; 138 | for (int i = 0; i < int(section.buffer.size()); i++) { 139 | pair val = section.buffer[i]; 140 | if (val.second) { 141 | section.mean += val.first; 142 | n++; 143 | } 144 | } 145 | section.mean /= n; 146 | 147 | if (section.completed < 1.0f) 148 | section.completed = float(section.pos - 1) / windowSize; 149 | 150 | return section.mean; 151 | } else { 152 | section.mean = t; 153 | return section.mean; 154 | } 155 | } 156 | 157 | 158 | void Timer::flush() { 159 | #ifdef TIMER_DIRECTX_9 160 | event->Issue(D3DISSUE_END); 161 | while (event->GetData(NULL, 0, D3DGETDATA_FLUSH) == S_FALSE); 162 | #else 163 | event->End(); 164 | 165 | BOOL queryData; 166 | while (event->GetData(&queryData, sizeof(BOOL), 0) != S_OK); 167 | #endif 168 | } 169 | 170 | 171 | wostream &operator<<(wostream &out, const Timer &timer) { 172 | for (std::map::const_iterator section = timer.sections.begin(); 173 | section != timer.sections.end(); 174 | section++) { 175 | const wstring &name = section->first; 176 | float mean = section->second.mean / timer.repetitionCount; 177 | float accum = timer.accum / timer.repetitionCount; 178 | out << name << L" : " << 1000.0f * mean << L"ms : " << int(100.0f * mean / accum) << L"% : " << int(1.0 / mean) << L"fps [" << int(100.0f * section->second.completed) << L"%]" << endl; 179 | } 180 | return out; 181 | } 182 | -------------------------------------------------------------------------------- /Demo/Code/Support/Timer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | #ifndef TIMER_H 33 | #define TIMER_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | 41 | #ifdef TIMER_DIRECTX_9 42 | #include 43 | #else 44 | #include 45 | #endif 46 | #include 47 | 48 | 49 | class Timer { 50 | public: 51 | #ifdef TIMER_DIRECTX_9 52 | Timer(IDirect3DDevice9 *device); 53 | #else 54 | Timer(ID3D10Device *device); 55 | #endif 56 | ~Timer(); 57 | 58 | void reset() { sections.clear(); } 59 | void start(); 60 | float clock(const std::wstring &msg=L""); 61 | float accumulated() const { return accum; } 62 | 63 | void sleep(float ms); 64 | 65 | void setEnabled(bool enabled) { this->enabled = enabled; } 66 | bool isEnabled() const { return enabled; } 67 | 68 | void setFlushEnabled(bool flushEnabled) { this->flushEnabled = flushEnabled; } 69 | bool isFlushEnabled() const { return flushEnabled; } 70 | 71 | void setWindowSize(int windowSize) { this->windowSize = windowSize; } 72 | int getWindowSize() const { return windowSize; } 73 | 74 | void setRepetitionsCount(int repetitionCount) { this->repetitionCount = repetitionCount; } 75 | int getRepetitionsCount() const { return repetitionCount; } 76 | 77 | float getSection(const std::wstring &name) { return 1000.0f * sections[name].mean / repetitionCount; } 78 | 79 | friend std::wostream &operator<<(std::wostream &out, const Timer &timer); 80 | 81 | private: 82 | float mean(const std::wstring &msg, float t); 83 | void flush(); 84 | 85 | #ifdef TIMER_DIRECTX_9 86 | IDirect3DQuery9 *event; 87 | #else 88 | ID3D10Query *event; 89 | #endif 90 | 91 | __int64 t0; 92 | float accum; 93 | 94 | bool enabled; 95 | bool flushEnabled; 96 | int windowSize; 97 | int repetitionCount; 98 | 99 | class Section { 100 | public: 101 | Section() : mean(0.0), pos(0), completed(0.0f) {} 102 | std::vector > buffer; 103 | float mean; 104 | int pos; 105 | float completed; 106 | }; 107 | std::map sections; 108 | }; 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /Demo/DXUT/Core/DXUT_2008.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "DXUT_2008.vcproj", "{E0CF097B-F22D-465B-A884-D89E55BD7ECD}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Debug|x64 = Debug|x64 9 | Profile|Win32 = Profile|Win32 10 | Profile|x64 = Profile|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.Build.0 = Debug|Win32 17 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|x64.ActiveCfg = Debug|x64 18 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|x64.Build.0 = Debug|x64 19 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|Win32.ActiveCfg = Profile|Win32 20 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|Win32.Build.0 = Profile|Win32 21 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|x64.ActiveCfg = Profile|x64 22 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|x64.Build.0 = Profile|x64 23 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.ActiveCfg = Release|Win32 24 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.Build.0 = Release|Win32 25 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|x64.ActiveCfg = Release|x64 26 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|x64.Build.0 = Release|x64 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Demo/DXUT/Core/DXUT_2008.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /Demo/DXUT/Core/DXUT_2010.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2010 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUT", "DXUT_2010.vcxproj", "{E0CF097B-F22D-465B-A884-D89E55BD7ECD}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Debug|x64 = Debug|x64 9 | Profile|Win32 = Profile|Win32 10 | Profile|x64 = Profile|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.Build.0 = Debug|Win32 17 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|x64.ActiveCfg = Debug|x64 18 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|x64.Build.0 = Debug|x64 19 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|Win32.ActiveCfg = Profile|Win32 20 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|Win32.Build.0 = Profile|Win32 21 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|x64.ActiveCfg = Profile|x64 22 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Profile|x64.Build.0 = Profile|x64 23 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.ActiveCfg = Release|Win32 24 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.Build.0 = Release|Win32 25 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|x64.ActiveCfg = Release|x64 26 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|x64.Build.0 = Release|x64 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Demo/DXUT/Core/DXUT_2010.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {8e114980-c1a3-4ada-ad7c-83caadf5daeb} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Demo/DXUT/Core/dpiaware.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | 7 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/DXUTLockFreePipe.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // DXUTLockFreePipe.h 3 | // 4 | // See the "Lockless Programming Considerations for Xbox 360 and Microsoft Windows" 5 | // article in the DirectX SDK for more details. 6 | // 7 | // http://msdn2.microsoft.com/en-us/library/bb310595.aspx 8 | // 9 | // XNA Developer Connection 10 | // Copyright (C) Microsoft Corporation. All rights reserved. 11 | //-------------------------------------------------------------------------------------- 12 | #pragma once 13 | 14 | #include 15 | 16 | #ifdef _XBOX_VER 17 | // Prevent the CPU from rearranging loads 18 | // and stores, sufficiently for read-acquire 19 | // and write-release. 20 | #define DXUTImportBarrier __lwsync 21 | #define DXUTExportBarrier __lwsync 22 | #else 23 | #pragma pack(push) 24 | #pragma pack(8) 25 | #include 26 | #pragma pack (pop) 27 | 28 | extern "C" 29 | void _ReadWriteBarrier(); 30 | #pragma intrinsic(_ReadWriteBarrier) 31 | 32 | // Prevent the compiler from rearranging loads 33 | // and stores, sufficiently for read-acquire 34 | // and write-release. This is sufficient on 35 | // x86 and x64. 36 | #define DXUTImportBarrier _ReadWriteBarrier 37 | #define DXUTExportBarrier _ReadWriteBarrier 38 | #endif 39 | 40 | // 41 | // Pipe class designed for use by at most two threads: one reader, one writer. 42 | // Access by more than two threads isn't guaranteed to be safe. 43 | // 44 | // In order to provide efficient access the size of the buffer is passed 45 | // as a template parameter and restricted to powers of two less than 31. 46 | // 47 | 48 | template class DXUTLockFreePipe 49 | { 50 | public: 51 | DXUTLockFreePipe() : m_readOffset( 0 ), 52 | m_writeOffset( 0 ) 53 | { 54 | } 55 | 56 | DWORD GetBufferSize() const 57 | { 58 | return c_cbBufferSize; 59 | } 60 | 61 | __forceinline unsigned long BytesAvailable() const 62 | { 63 | return m_writeOffset - m_readOffset; 64 | } 65 | 66 | bool __forceinline Read( void* pvDest, unsigned long cbDest ) 67 | { 68 | // Store the read and write offsets into local variables--this is 69 | // essentially a snapshot of their values so that they stay constant 70 | // for the duration of the function (and so we don't end up with cache 71 | // misses due to false sharing). 72 | DWORD readOffset = m_readOffset; 73 | DWORD writeOffset = m_writeOffset; 74 | 75 | // Compare the two offsets to see if we have anything to read. 76 | // Note that we don't do anything to synchronize the offsets here. 77 | // Really there's not much we *can* do unless we're willing to completely 78 | // synchronize access to the entire object. We have to assume that as we 79 | // read, someone else may be writing, and the write offset we have now 80 | // may be out of date by the time we read it. Fortunately that's not a 81 | // very big deal. We might miss reading some data that was just written. 82 | // But the assumption is that we'll be back before long to grab more data 83 | // anyway. 84 | // 85 | // Note that this comparison works because we're careful to constrain 86 | // the total buffer size to be a power of 2, which means it will divide 87 | // evenly into ULONG_MAX+1. That, and the fact that the offsets are 88 | // unsigned, means that the calculation returns correct results even 89 | // when the values wrap around. 90 | DWORD cbAvailable = writeOffset - readOffset; 91 | if( cbDest > cbAvailable ) 92 | { 93 | return false; 94 | } 95 | 96 | // The data has been made available, but we need to make sure 97 | // that our view on the data is up to date -- at least as up to 98 | // date as the control values we just read. We need to prevent 99 | // the compiler or CPU from moving any of the data reads before 100 | // the control value reads. This import barrier serves this 101 | // purpose, on Xbox 360 and on Windows. 102 | 103 | // Reading a control value and then having a barrier is known 104 | // as a "read-acquire." 105 | DXUTImportBarrier(); 106 | 107 | unsigned char* pbDest = ( unsigned char* )pvDest; 108 | 109 | unsigned long actualReadOffset = readOffset & c_sizeMask; 110 | unsigned long bytesLeft = cbDest; 111 | 112 | // 113 | // Copy from the tail, then the head. Note that there's no explicit 114 | // check to see if the write offset comes between the read offset 115 | // and the end of the buffer--that particular condition is implicitly 116 | // checked by the comparison with AvailableToRead(), above. If copying 117 | // cbDest bytes off the tail would cause us to cross the write offset, 118 | // then the previous comparison would have failed since that would imply 119 | // that there were less than cbDest bytes available to read. 120 | // 121 | unsigned long cbTailBytes = min( bytesLeft, c_cbBufferSize - actualReadOffset ); 122 | memcpy( pbDest, m_pbBuffer + actualReadOffset, cbTailBytes ); 123 | bytesLeft -= cbTailBytes; 124 | 125 | if( bytesLeft ) 126 | { 127 | memcpy( pbDest + cbTailBytes, m_pbBuffer, bytesLeft ); 128 | } 129 | 130 | // When we update the read offset we are, effectively, 'freeing' buffer 131 | // memory so that the writing thread can use it. We need to make sure that 132 | // we don't free the memory before we have finished reading it. That is, 133 | // we need to make sure that the write to m_readOffset can't get reordered 134 | // above the reads of the buffer data. The only way to guarantee this is to 135 | // have an export barrier to prevent both compiler and CPU rearrangements. 136 | DXUTExportBarrier(); 137 | 138 | // Advance the read offset. From the CPUs point of view this is several 139 | // operations--read, modify, store--and we'd normally want to make sure that 140 | // all of the operations happened atomically. But in the case of a single 141 | // reader, only one thread updates this value and so the only operation that 142 | // must be atomic is the store. That's lucky, because 32-bit aligned stores are 143 | // atomic on all modern processors. 144 | // 145 | readOffset += cbDest; 146 | m_readOffset = readOffset; 147 | 148 | return true; 149 | } 150 | 151 | bool __forceinline Write( const void* pvSrc, unsigned long cbSrc ) 152 | { 153 | // Reading the read offset here has the same caveats as reading 154 | // the write offset had in the Read() function above. 155 | DWORD readOffset = m_readOffset; 156 | DWORD writeOffset = m_writeOffset; 157 | 158 | // Compute the available write size. This comparison relies on 159 | // the fact that the buffer size is always a power of 2, and the 160 | // offsets are unsigned integers, so that when the write pointer 161 | // wraps around the subtraction still yields a value (assuming 162 | // we haven't messed up somewhere else) between 0 and c_cbBufferSize - 1. 163 | DWORD cbAvailable = c_cbBufferSize - ( writeOffset - readOffset ); 164 | if( cbSrc > cbAvailable ) 165 | { 166 | return false; 167 | } 168 | 169 | // It is theoretically possible for writes of the data to be reordered 170 | // above the reads to see if the data is available. Improbable perhaps, 171 | // but possible. This barrier guarantees that the reordering will not 172 | // happen. 173 | DXUTImportBarrier(); 174 | 175 | // Write the data 176 | const unsigned char* pbSrc = ( const unsigned char* )pvSrc; 177 | unsigned long actualWriteOffset = writeOffset & c_sizeMask; 178 | unsigned long bytesLeft = cbSrc; 179 | 180 | // See the explanation in the Read() function as to why we don't 181 | // explicitly check against the read offset here. 182 | unsigned long cbTailBytes = min( bytesLeft, c_cbBufferSize - actualWriteOffset ); 183 | memcpy( m_pbBuffer + actualWriteOffset, pbSrc, cbTailBytes ); 184 | bytesLeft -= cbTailBytes; 185 | 186 | if( bytesLeft ) 187 | { 188 | memcpy( m_pbBuffer, pbSrc + cbTailBytes, bytesLeft ); 189 | } 190 | 191 | // Now it's time to update the write offset, but since the updated position 192 | // of the write offset will imply that there's data to be read, we need to 193 | // make sure that the data all actually gets written before the update to 194 | // the write offset. The writes could be reordered by the compiler (on any 195 | // platform) or by the CPU (on Xbox 360). We need a barrier which prevents 196 | // the writes from being reordered past each other. 197 | // 198 | // Having a barrier and then writing a control value is called "write-release." 199 | DXUTExportBarrier(); 200 | 201 | // See comments in Read() as to why this operation isn't interlocked. 202 | writeOffset += cbSrc; 203 | m_writeOffset = writeOffset; 204 | 205 | return true; 206 | } 207 | 208 | private: 209 | // Values derived from the buffer size template parameter 210 | // 211 | const static BYTE c_cbBufferSizeLog2 = min( cbBufferSizeLog2, 31 ); 212 | const static DWORD c_cbBufferSize = ( 1 << c_cbBufferSizeLog2 ); 213 | const static DWORD c_sizeMask = c_cbBufferSize - 1; 214 | 215 | // Leave these private and undefined to prevent their use 216 | DXUTLockFreePipe( const DXUTLockFreePipe& ); 217 | DXUTLockFreePipe& operator =( const DXUTLockFreePipe& ); 218 | 219 | // Member data 220 | // 221 | BYTE m_pbBuffer[c_cbBufferSize]; 222 | // Note that these offsets are not clamped to the buffer size. 223 | // Instead the calculations rely on wrapping at ULONG_MAX+1. 224 | // See the comments in Read() for details. 225 | volatile DWORD __declspec( align( 4 ) ) m_readOffset; 226 | volatile DWORD __declspec( align( 4 ) ) m_writeOffset; 227 | }; -------------------------------------------------------------------------------- /Demo/DXUT/Optional/DXUTOpt_2008.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "DXUTOpt_2008.vcproj", "{9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Debug|x64 = Debug|x64 9 | Profile|Win32 = Profile|Win32 10 | Profile|x64 = Profile|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|Win32.Build.0 = Debug|Win32 17 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|x64.ActiveCfg = Debug|x64 18 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|x64.Build.0 = Debug|x64 19 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|Win32.ActiveCfg = Profile|Win32 20 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|Win32.Build.0 = Profile|Win32 21 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|x64.ActiveCfg = Profile|x64 22 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|x64.Build.0 = Profile|x64 23 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|Win32.ActiveCfg = Release|Win32 24 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|Win32.Build.0 = Release|Win32 25 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|x64.ActiveCfg = Release|x64 26 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|x64.Build.0 = Release|x64 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/DXUTOpt_2010.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2010 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOpt", "DXUTOpt_2010.vcxproj", "{9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Debug|x64 = Debug|x64 9 | Profile|Win32 = Profile|Win32 10 | Profile|x64 = Profile|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|Win32.Build.0 = Debug|Win32 17 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|x64.ActiveCfg = Debug|x64 18 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Debug|x64.Build.0 = Debug|x64 19 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|Win32.ActiveCfg = Profile|Win32 20 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|Win32.Build.0 = Profile|Win32 21 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|x64.ActiveCfg = Profile|x64 22 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Profile|x64.Build.0 = Profile|x64 23 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|Win32.ActiveCfg = Release|Win32 24 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|Win32.Build.0 = Release|Win32 25 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|x64.ActiveCfg = Release|x64 26 | {9F64786D-4F8F-43BF-ADA0-133ABAE1E52D}.Release|x64.Build.0 = Release|x64 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/DXUTOpt_2010.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {8e114980-c1a3-4ada-ad7c-83caadf5daeb} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/DXUTShapes.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DXUTShapes.h 3 | // 4 | // Shape creation functions for DXUT 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved 7 | //-------------------------------------------------------------------------------------- 8 | #pragma once 9 | #ifndef DXUT_SHAPES_H 10 | #define DXUT_SHAPES_H 11 | 12 | HRESULT WINAPI DXUTCreateBox( ID3D10Device* pDevice, float fWidth, float fHeight, float fDepth, ID3DX10Mesh** ppMesh ); 13 | HRESULT WINAPI DXUTCreateCylinder( ID3D10Device* pDevice, float fRadius1, float fRadius2, float fLength, UINT uSlices, 14 | UINT uStacks, ID3DX10Mesh** ppMesh ); 15 | HRESULT WINAPI DXUTCreatePolygon( ID3D10Device* pDevice, float fLength, UINT uSides, ID3DX10Mesh** ppMesh ); 16 | HRESULT WINAPI DXUTCreateSphere( ID3D10Device* pDevice, float fRadius, UINT uSlices, UINT uStacks, 17 | ID3DX10Mesh** ppMesh ); 18 | HRESULT WINAPI DXUTCreateTorus( ID3D10Device* pDevice, float fInnerRadius, float fOuterRadius, UINT uSides, 19 | UINT uRings, ID3DX10Mesh** ppMesh ); 20 | HRESULT WINAPI DXUTCreateTeapot( ID3D10Device* pDevice, ID3DX10Mesh** ppMesh ); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/DXUTguiIME.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DXUTguiIME.h 3 | // 4 | // Copyright (c) Microsoft Corporation. All rights reserved. 5 | //-------------------------------------------------------------------------------------- 6 | #pragma once 7 | #ifndef DXUT_IME_H 8 | #define DXUT_IME_H 9 | 10 | #include 11 | #include 12 | #include "ImeUi.h" 13 | 14 | 15 | //-------------------------------------------------------------------------------------- 16 | // Forward declarations 17 | //-------------------------------------------------------------------------------------- 18 | class CDXUTIMEEditBox; 19 | 20 | 21 | //----------------------------------------------------------------------------- 22 | // IME-enabled EditBox control 23 | //----------------------------------------------------------------------------- 24 | #define MAX_COMPSTRING_SIZE 256 25 | 26 | 27 | class CDXUTIMEEditBox : public CDXUTEditBox 28 | { 29 | public: 30 | 31 | static HRESULT CreateIMEEditBox( CDXUTDialog* pDialog, int ID, LPCWSTR strText, int x, int y, int width, 32 | int height, bool bIsDefault=false, CDXUTIMEEditBox** ppCreated=NULL ); 33 | 34 | CDXUTIMEEditBox( CDXUTDialog* pDialog = NULL ); 35 | virtual ~CDXUTIMEEditBox(); 36 | 37 | static void InitDefaultElements( CDXUTDialog* pDialog ); 38 | 39 | static void WINAPI Initialize( HWND hWnd ); 40 | static void WINAPI Uninitialize(); 41 | 42 | static HRESULT WINAPI StaticOnCreateDevice(); 43 | static bool WINAPI StaticMsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 44 | 45 | static void WINAPI SetImeEnableFlag( bool bFlag ); 46 | 47 | virtual void Render( float fElapsedTime ); 48 | virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam ); 49 | virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam ); 50 | virtual void UpdateRects(); 51 | virtual void OnFocusIn(); 52 | virtual void OnFocusOut(); 53 | 54 | void PumpMessage(); 55 | 56 | virtual void RenderCandidateReadingWindow( float fElapsedTime, bool bReading ); 57 | virtual void RenderComposition( float fElapsedTime ); 58 | virtual void RenderIndicator( float fElapsedTime ); 59 | 60 | protected: 61 | static void WINAPI EnableImeSystem( bool bEnable ); 62 | 63 | static WORD WINAPI GetLanguage() 64 | { 65 | return ImeUi_GetLanguage(); 66 | } 67 | static WORD WINAPI GetPrimaryLanguage() 68 | { 69 | return ImeUi_GetPrimaryLanguage(); 70 | } 71 | static void WINAPI SendKey( BYTE nVirtKey ); 72 | static DWORD WINAPI GetImeId( UINT uIndex = 0 ) 73 | { 74 | return ImeUi_GetImeId( uIndex ); 75 | }; 76 | static void WINAPI CheckInputLocale(); 77 | static void WINAPI CheckToggleState(); 78 | static void WINAPI SetupImeApi(); 79 | static void WINAPI ResetCompositionString(); 80 | 81 | 82 | static void SetupImeUiCallback(); 83 | 84 | protected: 85 | enum 86 | { 87 | INDICATOR_NON_IME, 88 | INDICATOR_CHS, 89 | INDICATOR_CHT, 90 | INDICATOR_KOREAN, 91 | INDICATOR_JAPANESE 92 | }; 93 | 94 | struct CCandList 95 | { 96 | CUniBuffer HoriCand; // Candidate list string (for horizontal candidate window) 97 | int nFirstSelected; // First character position of the selected string in HoriCand 98 | int nHoriSelectedLen; // Length of the selected string in HoriCand 99 | RECT rcCandidate; // Candidate rectangle computed and filled each time before rendered 100 | }; 101 | 102 | static POINT s_ptCompString; // Composition string position. Updated every frame. 103 | static int s_nFirstTargetConv; // Index of the first target converted char in comp string. If none, -1. 104 | static CUniBuffer s_CompString; // Buffer to hold the composition string (we fix its length) 105 | static DWORD s_adwCompStringClause[MAX_COMPSTRING_SIZE]; 106 | static CCandList s_CandList; // Data relevant to the candidate list 107 | static WCHAR s_wszReadingString[32];// Used only with horizontal reading window (why?) 108 | static bool s_bImeFlag; // Is ime enabled 109 | 110 | // Color of various IME elements 111 | D3DCOLOR m_ReadingColor; // Reading string color 112 | D3DCOLOR m_ReadingWinColor; // Reading window color 113 | D3DCOLOR m_ReadingSelColor; // Selected character in reading string 114 | D3DCOLOR m_ReadingSelBkColor; // Background color for selected char in reading str 115 | D3DCOLOR m_CandidateColor; // Candidate string color 116 | D3DCOLOR m_CandidateWinColor; // Candidate window color 117 | D3DCOLOR m_CandidateSelColor; // Selected candidate string color 118 | D3DCOLOR m_CandidateSelBkColor; // Selected candidate background color 119 | D3DCOLOR m_CompColor; // Composition string color 120 | D3DCOLOR m_CompWinColor; // Composition string window color 121 | D3DCOLOR m_CompCaretColor; // Composition string caret color 122 | D3DCOLOR m_CompTargetColor; // Composition string target converted color 123 | D3DCOLOR m_CompTargetBkColor; // Composition string target converted background 124 | D3DCOLOR m_CompTargetNonColor; // Composition string target non-converted color 125 | D3DCOLOR m_CompTargetNonBkColor;// Composition string target non-converted background 126 | D3DCOLOR m_IndicatorImeColor; // Indicator text color for IME 127 | D3DCOLOR m_IndicatorEngColor; // Indicator text color for English 128 | D3DCOLOR m_IndicatorBkColor; // Indicator text background color 129 | 130 | // Edit-control-specific data 131 | int m_nIndicatorWidth; // Width of the indicator symbol 132 | RECT m_rcIndicator; // Rectangle for drawing the indicator button 133 | 134 | #if defined(DEBUG) || defined(_DEBUG) 135 | static bool m_bIMEStaticMsgProcCalled; 136 | #endif 137 | }; 138 | 139 | 140 | 141 | #endif // DXUT_IME_H 142 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/DXUTres.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // File: dxutres.h 3 | // 4 | // Functions to create DXUT media from arrays in memory 5 | // 6 | // Copyright (c) Microsoft Corp. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #pragma once 9 | #ifndef DXUT_RES_H 10 | #define DXUT_RES_H 11 | 12 | HRESULT WINAPI DXUTCreateGUITextureFromInternalArray9( LPDIRECT3DDEVICE9 pd3dDevice, IDirect3DTexture9** ppTexture, 13 | D3DXIMAGE_INFO* pInfo ); 14 | HRESULT WINAPI DXUTCreateGUITextureFromInternalArray10( ID3D10Device* pd3dDevice, ID3D10Texture2D** ppTexture, 15 | D3DX10_IMAGE_INFO* pInfo ); 16 | HRESULT WINAPI DXUTCreateArrowMeshFromInternalArray( LPDIRECT3DDEVICE9 pd3dDevice, ID3DXMesh** ppMesh ); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/ImeUi.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: ImeUi.h 3 | // 4 | // Copyright (c) Microsoft Corporation. All rights reserved. 5 | //-------------------------------------------------------------------------------------- 6 | #ifndef _IMEUI_H_ 7 | #define _IMEUI_H_ 8 | #if _WIN32_WINNT < 0x0400 9 | #error IMEUI requires _WIN32_WINNT to be 0x0400 or higher. Please add "_WIN32_WINNT=0x0400" to your project's preprocessor setting. 10 | #endif 11 | #include 12 | 13 | class CImeUiFont_Base 14 | { 15 | public: 16 | virtual void SetHeight( UINT uHeight ) { uHeight; }; // for backward compatibility 17 | virtual void SetColor( DWORD color ) = 0; 18 | virtual void SetPosition( int x, int y ) = 0; 19 | virtual void GetTextExtent( LPCTSTR szText, DWORD* puWidth, DWORD* puHeight ) = 0; 20 | virtual void DrawText( LPCTSTR pszText ) = 0; 21 | }; 22 | 23 | typedef struct 24 | { 25 | // symbol (Henkan-kyu) 26 | DWORD symbolColor; 27 | DWORD symbolColorOff; 28 | DWORD symbolColorText; 29 | BYTE symbolHeight; 30 | BYTE symbolTranslucence; 31 | BYTE symbolPlacement; 32 | CImeUiFont_Base* symbolFont; 33 | 34 | // candidate list 35 | DWORD candColorBase; 36 | DWORD candColorBorder; 37 | DWORD candColorText; 38 | 39 | // composition string 40 | DWORD compColorInput; 41 | DWORD compColorTargetConv; 42 | DWORD compColorConverted; 43 | DWORD compColorTargetNotConv; 44 | DWORD compColorInputErr; 45 | BYTE compTranslucence; 46 | DWORD compColorText; 47 | 48 | // caret 49 | BYTE caretWidth; 50 | BYTE caretYMargin; 51 | } IMEUI_APPEARANCE; 52 | 53 | typedef struct // D3DTLVERTEX compatible 54 | { 55 | float sx; 56 | float sy; 57 | float sz; 58 | float rhw; 59 | DWORD color; 60 | DWORD specular; 61 | float tu; 62 | float tv; 63 | } IMEUI_VERTEX; 64 | 65 | // IME States 66 | #define IMEUI_STATE_OFF 0 67 | #define IMEUI_STATE_ON 1 68 | #define IMEUI_STATE_ENGLISH 2 69 | 70 | // IME const 71 | #define MAX_CANDLIST 10 72 | 73 | // IME Flags 74 | #define IMEUI_FLAG_SUPPORT_CARET 0x00000001 75 | 76 | bool ImeUi_Initialize( HWND hwnd, bool bDisable = false ); 77 | void ImeUi_Uninitialize(); 78 | void ImeUi_SetAppearance( const IMEUI_APPEARANCE* pia ); 79 | void ImeUi_GetAppearance( IMEUI_APPEARANCE* pia ); 80 | bool ImeUi_IgnoreHotKey( const MSG* pmsg ); 81 | LPARAM ImeUi_ProcessMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM& lParam, bool * trapped ); 82 | void ImeUi_SetScreenDimension( UINT width, UINT height ); 83 | void ImeUi_RenderUI( bool bDrawCompAttr = true, bool bDrawOtherUi = true ); 84 | void ImeUi_SetCaretPosition( UINT x, UINT y ); 85 | void ImeUi_SetCompStringAppearance( CImeUiFont_Base* pFont, DWORD color, const RECT* prc ); 86 | bool ImeUi_GetCaretStatus(); 87 | void ImeUi_SetInsertMode( bool bInsert ); 88 | void ImeUi_SetState( DWORD dwState ); 89 | DWORD ImeUi_GetState(); 90 | void ImeUi_EnableIme( bool bEnable ); 91 | bool ImeUi_IsEnabled( void ); 92 | void ImeUi_FinalizeString( bool bSend = false ); 93 | void ImeUi_ToggleLanguageBar( BOOL bRestore ); 94 | bool ImeUi_IsSendingKeyMessage(); 95 | void ImeUi_SetWindow( HWND hwnd ); 96 | UINT ImeUi_GetInputCodePage(); 97 | DWORD ImeUi_GetFlags(); 98 | void ImeUi_SetFlags( DWORD dwFlags, bool bSet ); 99 | 100 | WORD ImeUi_GetPrimaryLanguage(); 101 | DWORD ImeUi_GetImeId(UINT uIndex); 102 | WORD ImeUi_GetLanguage(); 103 | LPTSTR ImeUi_GetIndicatior(); 104 | bool ImeUi_IsShowReadingWindow(); 105 | bool ImeUi_IsShowCandListWindow(); 106 | bool ImeUi_IsVerticalCand(); 107 | bool ImeUi_IsHorizontalReading(); 108 | TCHAR* ImeUi_GetCandidate(UINT idx); 109 | TCHAR* ImeUi_GetCompositionString(); 110 | DWORD ImeUi_GetCandidateSelection(); 111 | DWORD ImeUi_GetCandidateCount(); 112 | BYTE* ImeUi_GetCompStringAttr(); 113 | DWORD ImeUi_GetImeCursorChars(); 114 | 115 | extern void (CALLBACK *ImeUiCallback_DrawRect )( int x1, int y1, int x2, int y2, DWORD color ); 116 | extern void* (__cdecl *ImeUiCallback_Malloc )( size_t bytes ); 117 | extern void (__cdecl *ImeUiCallback_Free )( void* ptr ); 118 | extern void (CALLBACK *ImeUiCallback_DrawFans )( const IMEUI_VERTEX* paVertex, UINT uNum ); 119 | extern void (CALLBACK *ImeUiCallback_OnChar )( WCHAR wc ); 120 | 121 | #endif //_IMEUI_H_ 122 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/SDKsound.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // File: DXUTsound.h 3 | // 4 | // Copyright (c) Microsoft Corp. All rights reserved. 5 | //----------------------------------------------------------------------------- 6 | #ifndef DXUTSOUND_H 7 | #define DXUTSOUND_H 8 | 9 | //----------------------------------------------------------------------------- 10 | // Header Includes 11 | //----------------------------------------------------------------------------- 12 | #include 13 | #define _KS_NO_ANONYMOUS_STRUCTURES_ // avoids most nameless structure in ks.h 14 | #pragma warning( disable : 4201 ) // disable nonstandard extension used : nameless struct/union 15 | #include 16 | #pragma warning( default : 4201 ) 17 | 18 | //----------------------------------------------------------------------------- 19 | // Classes used by this header 20 | //----------------------------------------------------------------------------- 21 | class CSoundManager; 22 | class CSound; 23 | class CStreamingSound; 24 | class CWaveFile; 25 | 26 | 27 | //----------------------------------------------------------------------------- 28 | // Typing macros 29 | //----------------------------------------------------------------------------- 30 | #define DXUT_StopSound(s) { if(s) s->Stop(); } 31 | #define DXUT_PlaySound(s) { if(s) s->Play( 0, 0 ); } 32 | #define DXUT_PlaySoundLooping(s) { if(s) s->Play( 0, DSBPLAY_LOOPING ); } 33 | 34 | 35 | //----------------------------------------------------------------------------- 36 | // Name: class CSoundManager 37 | // Desc: 38 | //----------------------------------------------------------------------------- 39 | class CSoundManager 40 | { 41 | protected: 42 | IDirectSound8* m_pDS; 43 | 44 | public: 45 | CSoundManager(); 46 | ~CSoundManager(); 47 | 48 | HRESULT Initialize( HWND hWnd, DWORD dwCoopLevel ); 49 | inline LPDIRECTSOUND8 GetDirectSound() 50 | { 51 | return m_pDS; 52 | } 53 | HRESULT SetPrimaryBufferFormat( DWORD dwPrimaryChannels, DWORD dwPrimaryFreq, 54 | DWORD dwPrimaryBitRate ); 55 | HRESULT Get3DListenerInterface( LPDIRECTSOUND3DLISTENER* ppDSListener ); 56 | 57 | HRESULT Create( CSound** ppSound, LPWSTR strWaveFileName, DWORD dwCreationFlags = 0, 58 | GUID guid3DAlgorithm = GUID_NULL, DWORD dwNumBuffers = 1 ); 59 | HRESULT CreateFromMemory( CSound** ppSound, BYTE* pbData, ULONG ulDataSize, LPWAVEFORMATEX pwfx, 60 | DWORD dwCreationFlags = 0, GUID guid3DAlgorithm = GUID_NULL, 61 | DWORD dwNumBuffers = 1 ); 62 | HRESULT CreateStreaming( CStreamingSound** ppStreamingSound, LPWSTR strWaveFileName, 63 | DWORD dwCreationFlags, GUID guid3DAlgorithm, DWORD dwNotifyCount, 64 | DWORD dwNotifySize, HANDLE hNotifyEvent ); 65 | }; 66 | 67 | 68 | //----------------------------------------------------------------------------- 69 | // Name: class CSound 70 | // Desc: Encapsulates functionality of a DirectSound buffer. 71 | //----------------------------------------------------------------------------- 72 | class CSound 73 | { 74 | protected: 75 | LPDIRECTSOUNDBUFFER* m_apDSBuffer; 76 | DWORD m_dwDSBufferSize; 77 | CWaveFile* m_pWaveFile; 78 | DWORD m_dwNumBuffers; 79 | DWORD m_dwCreationFlags; 80 | 81 | HRESULT RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, BOOL* pbWasRestored ); 82 | 83 | public: 84 | CSound( LPDIRECTSOUNDBUFFER* apDSBuffer, DWORD dwDSBufferSize, DWORD dwNumBuffers, 85 | CWaveFile* pWaveFile, DWORD dwCreationFlags ); 86 | virtual ~CSound(); 87 | 88 | HRESULT Get3DBufferInterface( DWORD dwIndex, LPDIRECTSOUND3DBUFFER* ppDS3DBuffer ); 89 | HRESULT FillBufferWithSound( LPDIRECTSOUNDBUFFER pDSB, BOOL bRepeatWavIfBufferLarger ); 90 | LPDIRECTSOUNDBUFFER GetFreeBuffer(); 91 | LPDIRECTSOUNDBUFFER GetBuffer( DWORD dwIndex ); 92 | 93 | HRESULT Play( DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lVolume = 0, LONG lFrequency = -1, 94 | LONG lPan = 0 ); 95 | HRESULT Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lFrequency = 0 ); 96 | HRESULT Stop(); 97 | HRESULT Reset(); 98 | BOOL IsSoundPlaying(); 99 | }; 100 | 101 | 102 | //----------------------------------------------------------------------------- 103 | // Name: class CStreamingSound 104 | // Desc: Encapsulates functionality to play a wave file with DirectSound. 105 | // The Create() method loads a chunk of wave file into the buffer, 106 | // and as sound plays more is written to the buffer by calling 107 | // HandleWaveStreamNotification() whenever hNotifyEvent is signaled. 108 | //----------------------------------------------------------------------------- 109 | class CStreamingSound : public CSound 110 | { 111 | protected: 112 | DWORD m_dwLastPlayPos; 113 | DWORD m_dwPlayProgress; 114 | DWORD m_dwNotifySize; 115 | DWORD m_dwNextWriteOffset; 116 | BOOL m_bFillNextNotificationWithSilence; 117 | 118 | public: 119 | CStreamingSound( LPDIRECTSOUNDBUFFER pDSBuffer, DWORD dwDSBufferSize, CWaveFile* pWaveFile, 120 | DWORD dwNotifySize ); 121 | ~CStreamingSound(); 122 | 123 | HRESULT HandleWaveStreamNotification( BOOL bLoopedPlay ); 124 | HRESULT Reset(); 125 | }; 126 | 127 | #endif // DXUTSOUND_H 128 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/SDKwavefile.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // File: WaveFile.h 3 | // 4 | // Copyright (c) Microsoft Corp. All rights reserved. 5 | //----------------------------------------------------------------------------- 6 | #ifndef DXUTWAVEFILE_H 7 | #define DXUTWAVEFILE_H 8 | 9 | //----------------------------------------------------------------------------- 10 | // Typing macros 11 | //----------------------------------------------------------------------------- 12 | #define WAVEFILE_READ 1 13 | #define WAVEFILE_WRITE 2 14 | 15 | //----------------------------------------------------------------------------- 16 | // Name: class CWaveFile 17 | // Desc: Encapsulates reading or writing sound data to or from a wave file 18 | //----------------------------------------------------------------------------- 19 | class CWaveFile 20 | { 21 | public: 22 | WAVEFORMATEX* m_pwfx; // Pointer to WAVEFORMATEX structure 23 | HMMIO m_hmmio; // MM I/O handle for the WAVE 24 | MMCKINFO m_ck; // Multimedia RIFF chunk 25 | MMCKINFO m_ckRiff; // Use in opening a WAVE file 26 | DWORD m_dwSize; // The size of the wave file 27 | MMIOINFO m_mmioinfoOut; 28 | DWORD m_dwFlags; 29 | BOOL m_bIsReadingFromMemory; 30 | BYTE* m_pbData; 31 | BYTE* m_pbDataCur; 32 | ULONG m_ulDataSize; 33 | CHAR* m_pResourceBuffer; 34 | 35 | protected: 36 | HRESULT ReadMMIO(); 37 | HRESULT WriteMMIO( WAVEFORMATEX* pwfxDest ); 38 | 39 | public: 40 | CWaveFile(); 41 | ~CWaveFile(); 42 | 43 | HRESULT Open( LPWSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags ); 44 | HRESULT OpenFromMemory( BYTE* pbData, ULONG ulDataSize, WAVEFORMATEX* pwfx, DWORD dwFlags ); 45 | HRESULT Close(); 46 | 47 | HRESULT Read( BYTE* pBuffer, DWORD dwSizeToRead, DWORD* pdwSizeRead ); 48 | HRESULT Write( UINT nSizeToWrite, BYTE* pbData, UINT* pnSizeWrote ); 49 | 50 | DWORD GetSize(); 51 | HRESULT ResetFile(); 52 | WAVEFORMATEX* GetFormat() 53 | { 54 | return m_pwfx; 55 | }; 56 | }; 57 | 58 | 59 | #endif // DXUTWAVEFILE_H 60 | -------------------------------------------------------------------------------- /Demo/DXUT/Optional/directx.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/DXUT/Optional/directx.ico -------------------------------------------------------------------------------- /Demo/Demo.rc: -------------------------------------------------------------------------------- 1 | 1 ICON "DirectX.ico" 2 | 3 | SeparableSSS.fx RCDATA Shaders\SeparableSSS.fx 4 | SeparableSSS.h RCDATA "..\\SeparableSSS.h" 5 | 6 | SMAA.fx RCDATA Shaders\SMAA.fx 7 | SMAA.h RCDATA Shaders\SMAA.h 8 | 9 | Bloom.fx RCDATA Shaders\Bloom.fx 10 | FilmGrain.fx RCDATA Shaders\FilmGrain.fx 11 | DepthOfField.fx RCDATA Shaders\DepthOfField.fx 12 | Main.fx RCDATA Shaders\Main.fx 13 | ShadowMap.fx RCDATA Shaders\ShadowMap.fx 14 | SkyDome.fx RCDATA Shaders\SkyDome.fx 15 | 16 | Head\Head.sdkmesh RCDATA Media\Head\Head.sdkmesh 17 | Head\DiffuseMap.dds RCDATA Media\Head\DiffuseMap.dds 18 | Head\NormalMap.dds RCDATA Media\Head\NormalMap.dds 19 | Head\SpecularAOMap.dds RCDATA Media\Head\SpecularAOMap.dds 20 | 21 | Enviroment\StPeters\SkyDome.sdkmesh RCDATA Media\Enviroment\StPeters\SkyDome.sdkmesh 22 | Enviroment\StPeters\DiffuseMap.dds RCDATA Media\Enviroment\StPeters\DiffuseMap.dds 23 | Enviroment\StPeters\IrradianceMap.dds RCDATA Media\Enviroment\StPeters\IrradianceMap.dds 24 | Enviroment\Grace\SkyDome.sdkmesh RCDATA Media\Enviroment\Grace\SkyDome.sdkmesh 25 | Enviroment\Grace\DiffuseMap.dds RCDATA Media\Enviroment\Grace\DiffuseMap.dds 26 | Enviroment\Grace\IrradianceMap.dds RCDATA Media\Enviroment\Grace\IrradianceMap.dds 27 | Enviroment\Eucalyptus\SkyDome.sdkmesh RCDATA Media\Enviroment\Eucalyptus\SkyDome.sdkmesh 28 | Enviroment\Eucalyptus\DiffuseMap.dds RCDATA Media\Enviroment\Eucalyptus\DiffuseMap.dds 29 | Enviroment\Eucalyptus\IrradianceMap.dds RCDATA Media\Enviroment\Eucalyptus\IrradianceMap.dds 30 | 31 | BeckmannMap.dds RCDATA Media\BeckmannMap.dds 32 | SmallTitles.dds RCDATA Media\SmallTitles.dds 33 | BigTitles.dds RCDATA Media\BigTitles.dds 34 | Noise.dds RCDATA Media\Noise.dds 35 | Background.png RCDATA Media\Background.png 36 | 37 | Help.txt RCDATA Media\Help.txt 38 | 39 | Music.xwm WAV Media\Music.xwm 40 | 41 | Preset0.txt RCDATA "Media\\Presets\\Preset0.txt" 42 | Preset1.txt RCDATA "Media\\Presets\\Preset1.txt" 43 | Preset2.txt RCDATA "Media\\Presets\\Preset2.txt" 44 | Preset3.txt RCDATA "Media\\Presets\\Preset3.txt" 45 | Preset4.txt RCDATA "Media\\Presets\\Preset4.txt" 46 | Preset5.txt RCDATA "Media\\Presets\\Preset5.txt" 47 | Preset6.txt RCDATA "Media\\Presets\\Preset6.txt" 48 | Preset7.txt RCDATA "Media\\Presets\\Preset7.txt" 49 | Preset8.txt RCDATA "Media\\Presets\\Preset8.txt" 50 | Preset9.txt RCDATA "Media\\Presets\\Preset9.txt" 51 | -------------------------------------------------------------------------------- /Demo/Demo.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual C++ Express 2010 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo.vcxproj", "{D3D1000C-96D0-4629-88B8-122C0256058C}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Debug|x64 = Debug|x64 9 | Release|Win32 = Release|Win32 10 | Release|x64 = Release|x64 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {D3D1000C-96D0-4629-88B8-122C0256058C}.Debug|Win32.ActiveCfg = Debug|Win32 14 | {D3D1000C-96D0-4629-88B8-122C0256058C}.Debug|Win32.Build.0 = Debug|Win32 15 | {D3D1000C-96D0-4629-88B8-122C0256058C}.Debug|x64.ActiveCfg = Debug|Win32 16 | {D3D1000C-96D0-4629-88B8-122C0256058C}.Release|Win32.ActiveCfg = Release|Win32 17 | {D3D1000C-96D0-4629-88B8-122C0256058C}.Release|Win32.Build.0 = Release|Win32 18 | {D3D1000C-96D0-4629-88B8-122C0256058C}.Release|x64.ActiveCfg = Release|Win32 19 | EndGlobalSection 20 | GlobalSection(SolutionProperties) = preSolution 21 | HideSolutionNode = FALSE 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /Demo/Demo.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {37b64c45-a08f-4fe9-af50-45c5c2f603fc} 6 | 7 | 8 | {509ace0a-bd70-4611-b1f1-a99d4866a35d} 9 | 10 | 11 | {f43f35c7-2c90-4e14-92ff-e9c6d7c1a952} 12 | 13 | 14 | {edba3141-f6d2-48e7-94af-3edeedb2c126} 15 | 16 | 17 | {34390a93-39d2-489a-9555-1415e8ab81d6} 18 | 19 | 20 | {915892a5-f2e0-4fff-bcd1-9256c432b06d} 21 | 22 | 23 | {14db4bca-5f23-4b23-b2a1-1bf48ecad710} 24 | 25 | 26 | 27 | 28 | DXUT 29 | 30 | 31 | DXUT 32 | 33 | 34 | DXUT 35 | 36 | 37 | DXUT 38 | 39 | 40 | DXUT 41 | 42 | 43 | DXUT 44 | 45 | 46 | DXUT 47 | 48 | 49 | DXUT 50 | 51 | 52 | DXUT 53 | 54 | 55 | Source 56 | 57 | 58 | Source\Support 59 | 60 | 61 | Source\Support 62 | 63 | 64 | Source\Support 65 | 66 | 67 | Source\Support 68 | 69 | 70 | Source\Support 71 | 72 | 73 | Source\Support 74 | 75 | 76 | Source\Support 77 | 78 | 79 | Source\Support 80 | 81 | 82 | DXUT 83 | 84 | 85 | Source 86 | 87 | 88 | Source\Support 89 | 90 | 91 | Source\Support 92 | 93 | 94 | Source\Support 95 | 96 | 97 | 98 | 99 | DXUT 100 | 101 | 102 | DXUT 103 | 104 | 105 | DXUT 106 | 107 | 108 | DXUT 109 | 110 | 111 | DXUT 112 | 113 | 114 | DXUT 115 | 116 | 117 | DXUT 118 | 119 | 120 | DXUT 121 | 122 | 123 | DXUT 124 | 125 | 126 | Headers\Support 127 | 128 | 129 | Headers\Support 130 | 131 | 132 | Headers\Support 133 | 134 | 135 | Headers\Support 136 | 137 | 138 | Headers\Support 139 | 140 | 141 | Headers\Support 142 | 143 | 144 | Headers\Support 145 | 146 | 147 | Headers\Support 148 | 149 | 150 | Headers\Support 151 | 152 | 153 | DXUT 154 | 155 | 156 | Headers 157 | 158 | 159 | Shaders 160 | 161 | 162 | Headers\Support 163 | 164 | 165 | Headers\Support 166 | 167 | 168 | Shaders\Support 169 | 170 | 171 | Headers\Support 172 | 173 | 174 | 175 | 176 | Shaders 177 | 178 | 179 | Shaders\Support 180 | 181 | 182 | Shaders\Support 183 | 184 | 185 | Shaders\Support 186 | 187 | 188 | Shaders\Support 189 | 190 | 191 | Shaders\Support 192 | 193 | 194 | Shaders\Support 195 | 196 | 197 | Shaders\Support 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /Demo/Demo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /Demo/DirectX.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/DirectX.ico -------------------------------------------------------------------------------- /Demo/Media/Background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Background.png -------------------------------------------------------------------------------- /Demo/Media/BeckmannMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/BeckmannMap.dds -------------------------------------------------------------------------------- /Demo/Media/BigTitles.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/BigTitles.dds -------------------------------------------------------------------------------- /Demo/Media/BigTitles.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/BigTitles.psd -------------------------------------------------------------------------------- /Demo/Media/Enviroment/Eucalyptus/DiffuseMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/Eucalyptus/DiffuseMap.dds -------------------------------------------------------------------------------- /Demo/Media/Enviroment/Eucalyptus/IrradianceMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/Eucalyptus/IrradianceMap.dds -------------------------------------------------------------------------------- /Demo/Media/Enviroment/Eucalyptus/SkyDome.sdkmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/Eucalyptus/SkyDome.sdkmesh -------------------------------------------------------------------------------- /Demo/Media/Enviroment/Grace/DiffuseMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/Grace/DiffuseMap.dds -------------------------------------------------------------------------------- /Demo/Media/Enviroment/Grace/IrradianceMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/Grace/IrradianceMap.dds -------------------------------------------------------------------------------- /Demo/Media/Enviroment/Grace/SkyDome.sdkmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/Grace/SkyDome.sdkmesh -------------------------------------------------------------------------------- /Demo/Media/Enviroment/StPeters/DiffuseMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/StPeters/DiffuseMap.dds -------------------------------------------------------------------------------- /Demo/Media/Enviroment/StPeters/IrradianceMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/StPeters/IrradianceMap.dds -------------------------------------------------------------------------------- /Demo/Media/Enviroment/StPeters/SkyDome.sdkmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Enviroment/StPeters/SkyDome.sdkmesh -------------------------------------------------------------------------------- /Demo/Media/Head/DiffuseMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Head/DiffuseMap.dds -------------------------------------------------------------------------------- /Demo/Media/Head/Head.sdkmesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Head/Head.sdkmesh -------------------------------------------------------------------------------- /Demo/Media/Head/NormalMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Head/NormalMap.dds -------------------------------------------------------------------------------- /Demo/Media/Head/SpecularAOMap.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Head/SpecularAOMap.dds -------------------------------------------------------------------------------- /Demo/Media/Help.txt: -------------------------------------------------------------------------------- 1 | Hi, welcome to our SSS demo! 2 | 3 | Here you'll find what hopefully will be useful information for gamedevs and artists, including what subsurface 4 | scattering (SSS) is, what the parameters are, as well as some useful tips to achieve the highest realism possible out 5 | of the shader. Most of the info here is basic stuff but I'd like to give a quick summary anyway. 6 | 7 | First of all, lets explain what Subsurface Scattering is. It's a process in which light falling onto an object enters 8 | its body at one point, scatters within it, then exits the object at some other point. This process happens in skin, and 9 | has a vital importance in its visual appearance. In an object without subsurface scattering such as a rock, the light 10 | doesn't enter the object, so the entry and exit point are the very same. Ok, now for lets go with the most relevant 11 | controls on the right, from top to bottom. But before that, please take into account that besides the controls, the 12 | alpha channel of the diffuse map can be used to modulate how strong is the SSS effect in each zone of the face. 13 | 14 | The first one is 'Separate Speculars'. When light hits the surface of the skin, a percentage of it just reflects 15 | (speculars), while other manages to get inside of the skin, and scatters within it. So, this means that SSS only 16 | happens in the diffuse component of the lighting. In some cases, it may be too expensive to store the diffuse and 17 | specular components separately, and thus subsurface scattering must be applied to both, which still yields very 18 | realistic results despite not being a perfect solution. Having separate speculars allows to apply SSS only to the 19 | diffuse component, as happens in the real world. 20 | 21 | You may want to enable/disable 'SSS rendering', or to simply push S, to enable/disable the filter effects, and see how 22 | important is to simulate SSS. Notice how SSS depends on the lighting configuration, which rules out precalculation. 23 | 24 | The light diffusion produced by the SSS mechanism should occur on the surface of the object, not in a screen oriented 25 | plane. Enabling 'Follow Surface' will ensure that diffusion is correctly calculated, at the expense of more memory 26 | accesses. 27 | 28 | Now, to the parameters that control the SSS filter: 29 | 1) SSS Width: specifies the global level of subsurface scattering, or in other words, the width of the filter. 30 | 2) SSS Strength: specifies the how much of the diffuse light gets into the skin, and thus gets modified by the SSS 31 | mechanism. It can be seen as a per-channel mix factor between the original image, and the SSS filtered image. 32 | 3) SSS Falloff: defines the per-channel falloff of the gradients produced by the subsurface scattering events. It can 33 | be used to fine tune the color of the gradients. 34 | 4) SSS Translucency: controls the translucency of thin slabs like the ears or nose. 35 | 36 | The specular controls on the left, are exposed to showcase the potential of the Kelemen/Szirmay-Kalos model used the 37 | specular component. Physically accurate speculars like these are crucial for believable skin. Playing with the 38 | roughness you can make the face to look sweaty. Note that these parameters are global tweaks, they are already changing 39 | over the face (for example, to make speculars stronger on the forehead). 40 | 41 | Finally, the 'Bumpiness' control is exposed to showcase the huge importance of a proper normal map. Notice that without 42 | bumps, what SSS does is just to colorize the gradients in the shadows and shading boundaries. Properly crafted normal 43 | maps make for most of the realism obtained with SSS shaders. Also, remember that SSS softens the bumps, and thus they 44 | must be designed much more sharper than what an artist would usually do if SSS was not available. My recommendation is 45 | to take a look into the scanned normal map included in the demo, and use it as reference for developing bump maps with 46 | the proper appearance. Bump tiling can be used when using high resolution maps isn't a possibility. It's also worth 47 | noting that the albedo is blurred with the lighting, so it should also be stronger than usual (using "Smart Sharpen" 48 | in Photoshop works fine). -------------------------------------------------------------------------------- /Demo/Media/Music.xwm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Music.xwm -------------------------------------------------------------------------------- /Demo/Media/Noise.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/Noise.dds -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset0.txt: -------------------------------------------------------------------------------- 1 | 5.12666 2 | -0.131138 0.179364 3 | -0.0048045 0.289718 4 | 7.27215 5.45403 5 | 1.91333 6 | 1.5805 -0.208219 7 | 0 0 8 | 0 0 9 | 1.05 10 | 1.05 11 | 1.05 12 | 3.24 13 | 0.80454 -0.612405 14 | 0 0 15 | 0 0 16 | 0.55 17 | 0.55 18 | 0.55 19 | 2 20 | -2.62401 -0.825794 21 | 0 0 22 | 8 0 23 | 1.4 24 | 1.4 25 | 1.4 26 | 2 27 | 0 0 28 | 0 0 29 | 0 0 30 | 0 31 | 0 32 | 0 33 | 2 34 | 0 0 35 | 0 0 36 | 0 0 37 | 0 38 | 0 39 | 0 40 | 0.61 41 | 0.55 42 | 0.66 43 | 0.7 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset1.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1.72 7 | 1.18331 0.124121 8 | -0.16126 -0.0736686 9 | 3.07412 0.984051 10 | 1.38 11 | -0.449064 -0.134761 12 | 0.0259918 0.0480182 13 | 1.4013e-044 -1.4013e-044 14 | 3.85 15 | 3.85 16 | 3.85 17 | 3.24 18 | 6.25257 0.110409 19 | 0 0 20 | -1.54143e-044 1.54143e-044 21 | 0 22 | 0 23 | 0 24 | 2 25 | -2.73357 -0.262273 26 | 0 0 27 | 0 0 28 | 0 29 | 0 30 | 0 31 | 2 32 | 0 0 33 | 0 0 34 | 0 0 35 | 0 36 | 0 37 | 0 38 | 2 39 | 0 0 40 | 0 0 41 | 0 0 42 | 0 43 | 0 44 | 0 45 | 0.07 46 | 0.1 47 | 0.78 48 | 0.58 49 | 20 50 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset2.txt: -------------------------------------------------------------------------------- 1 | 1.9 2 | -0.145051 -0.294696 3 | -0.00888094 -0.133661 4 | 5.26584 0.397228 5 | 1.91333 6 | 1.5805 -0.208219 7 | 0 0 8 | 0 0 9 | 1.05 10 | 1.05 11 | 1.05 12 | 2.24 13 | 0.80454 -0.612405 14 | 0 0 15 | -16 0 16 | 0.55 17 | 0.55 18 | 0.55 19 | 2 20 | -2.73357 -0.262273 21 | 0 0 22 | 0 0 23 | 1.55 24 | 1.55 25 | 1.55 26 | 2 27 | 0 0 28 | 0 0 29 | 0 0 30 | 0 31 | 0 32 | 0 33 | 2 34 | 0 0 35 | 0 0 36 | 0 0 37 | 0 38 | 0 39 | 0 40 | 0.61 41 | 0.55 42 | 0.72 43 | 0.68 44 | 20 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset3.txt: -------------------------------------------------------------------------------- 1 | 2.04667 2 | -1.31571 0.1962 3 | 0.214375 -0.10014 4 | 4.65539 -0.736155 5 | 1.91333 6 | 0.292411 -0.6591 7 | 0 0 8 | 1.26117e-044 1.26117e-044 9 | 0 10 | 0 11 | 0 12 | 3.24 13 | 0.81667 -0.257313 14 | 0 0 15 | 1.4013e-044 -1.4013e-044 16 | 5 17 | 5 18 | 5 19 | 2 20 | -2.73357 -0.262273 21 | 0 0 22 | 0 0 23 | 1.2 24 | 1.2 25 | 1.2 26 | 2 27 | 0 0 28 | 0 0 29 | 0 0 30 | 0 31 | 0 32 | 0 33 | 2 34 | 0 0 35 | 0 0 36 | 0 0 37 | 0 38 | 0 39 | 0 40 | 0.61 41 | 0.55 42 | 0.72 43 | 0.64 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset4.txt: -------------------------------------------------------------------------------- 1 | 1.86 2 | 2.58088 0.782071 3 | 0.043764 -0.0430616 4 | 2.7362 -3.59518e-009 5 | 1.91333 6 | 1.84628 0.0638519 7 | 0 0 8 | 1.4013e-044 1.4013e-044 9 | 0 10 | 0 11 | 0 12 | 3.24 13 | 1.08134 -0.492958 14 | 0 0 15 | -1.4013e-044 1.4013e-044 16 | 1.1 17 | 1.1 18 | 1.1 19 | 2 20 | 4.48193 5.59946 21 | 0 0 22 | -1.4013e-044 1.4013e-044 23 | 1.0 24 | 1.0 25 | 1.0 26 | 2 27 | 0 0 28 | 0 0 29 | 0 0 30 | 0 31 | 0 32 | 0 33 | 2 34 | 0 0 35 | 0 0 36 | 0 0 37 | 0 38 | 0 39 | 0 40 | 0.58 41 | 0.55 42 | 0.4 43 | 0.83 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset5.txt: -------------------------------------------------------------------------------- 1 | 1.81333 2 | 1.21207 0.638401 3 | -0.111167 0.00765136 4 | -0.284353 0.724526 5 | 2.0 6 | 1.58525 -0.632297 7 | 0 0 8 | 0 0 9 | 1.1 10 | 1.1 11 | 1.1 12 | 3.24 13 | 0.80454 -0.612405 14 | 0 0 15 | 0 0 16 | 0.2 17 | 0.2 18 | 0.2 19 | 1 20 | -2.73357 -0.262273 21 | 0 0 22 | -3 3 23 | 1.35 24 | 1.35 25 | 1.35 26 | 2 27 | -3.77475 -2.0313 28 | 0 0 29 | 0 -8 30 | 0.7 31 | 0.7 32 | 0.7 33 | 7.19999 34 | -1.15423 0.00112459 35 | 0 0 36 | -8.91291e-006 2.10166e-005 37 | 0.9 38 | 0.9 39 | 0.9 40 | 0.61 41 | 0.55 42 | 0.66 43 | 0.71 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset6.txt: -------------------------------------------------------------------------------- 1 | 1.42666 2 | 1.03232 -0.724756 3 | -0.23862 -0.121406 4 | 0.818272 -0.00032035 5 | 1.91333 6 | 0.432477 -0.629112 7 | 0 0 8 | -11.5582 4.20295 9 | 0.85 10 | 0.85 11 | 0.85 12 | 3.24 13 | 0.80454 -0.612405 14 | 0 0 15 | 0 0 16 | 0 17 | 0 18 | 0 19 | 2 20 | -2.73357 -0.262273 21 | 0 0 22 | 0 0 23 | 0 24 | 0 25 | 0 26 | 2 27 | 0 0 28 | 0 0 29 | 0 0 30 | 0 31 | 0 32 | 0 33 | 2 34 | 0 0 35 | 0 0 36 | 0 0 37 | 0 38 | 0 39 | 0 40 | 0.17 41 | 0.09 42 | 0.76 43 | 0.66 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset7.txt: -------------------------------------------------------------------------------- 1 | 1.94 2 | 0.118962 0.16605 3 | -0.0631882 -0.103166 4 | 2.34518 0.243918 5 | 1.91333 6 | 1.5805 -0.208219 7 | 0 0 8 | 0 0 9 | 1.1 10 | 1.1 11 | 1.1 12 | 3.24 13 | -1.65118 -0.281551 14 | 0 0 15 | 2.8026e-045 -2.8026e-045 16 | 0.65 17 | 0.65 18 | 0.65 19 | 2 20 | -2.73357 -0.262273 21 | 0 0 22 | 0 0 23 | 0 24 | 0 25 | 0 26 | 2 27 | 0 0 28 | 0 0 29 | 0 0 30 | 0 31 | 0 32 | 0 33 | 2 34 | 0 0 35 | 0 0 36 | 0 0 37 | 0 38 | 0 39 | 0 40 | 0.46 41 | 0.55 42 | 0.66 43 | 0.55 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset8.txt: -------------------------------------------------------------------------------- 1 | 1.20667 2 | -0.0177753 -0.00941049 3 | -0.0194315 0.119604 4 | 0 3.80782 5 | 5.20666 6 | 2.2683 0.0883085 7 | 0 0 8 | -2.8026e-045 2.8026e-045 9 | 0.5 10 | 0.5 11 | 0.5 12 | 2.02667 13 | -2.27879 0.133232 14 | 0 0 15 | -2.8026e-045 2.8026e-045 16 | 0.5 17 | 0.5 18 | 0.5 19 | 9.69333 20 | -2.7276 -0.240081 21 | 0 0 22 | -2.8026e-045 -2.8026e-045 23 | 1.45 24 | 1.45 25 | 1.45 26 | 4.54666 27 | -0.0277367 -1.01091 28 | 0 0 29 | -2.8026e-045 2.8026e-045 30 | 0.5 31 | 0.5 32 | 0.5 33 | 9.62666 34 | -0.545473 -2.92996 35 | -0.00258883 -0.0422221 36 | -2.8026e-045 2.8026e-045 37 | 1.45 38 | 1.45 39 | 1.45 40 | 0.59 41 | 0.6 42 | 0.66 43 | 0.65 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/Presets/Preset9.txt: -------------------------------------------------------------------------------- 1 | 3.1 2 | -0.49005 0.0508272 3 | -0.0168704 0.0729295 4 | 0 0 5 | 1.91333 6 | 1.5805 -0.208219 7 | 0 0 8 | 0 0 9 | 1.05 10 | 1.05 11 | 1.05 12 | 3.24 13 | 0.80454 -0.612405 14 | 0 0 15 | 0 0 16 | 0.55 17 | 0.55 18 | 0.55 19 | 2 20 | -2.73357 -0.262273 21 | 0 0 22 | 0 0 23 | 1.55 24 | 1.55 25 | 1.55 26 | 2 27 | 0 0 28 | 0 0 29 | 0 0 30 | 0 31 | 0 32 | 0 33 | 2 34 | 0 0 35 | 0 0 36 | 0 0 37 | 0 38 | 0 39 | 0 40 | 0.61 41 | 0.55 42 | 0.66 43 | 0.76 44 | 15 45 | -------------------------------------------------------------------------------- /Demo/Media/SmallTitles.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/SmallTitles.dds -------------------------------------------------------------------------------- /Demo/Media/SmallTitles.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Media/SmallTitles.psd -------------------------------------------------------------------------------- /Demo/Shaders/DepthOfField.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | // Can be 13, 11, 9, 7 or 5 33 | #define N_SAMPLES 13 34 | 35 | 36 | float2 pixelSize; 37 | float2 direction; 38 | float blurWidth; 39 | float focusDistance; 40 | float focusRange; 41 | float2 focusFalloff; 42 | 43 | Texture2D blurredTex; 44 | Texture2D depthTex; 45 | Texture2D cocTex; 46 | 47 | 48 | SamplerState PointSampler { 49 | Filter = MIN_MAG_MIP_POINT; 50 | AddressU = Clamp; 51 | AddressV = Clamp; 52 | }; 53 | 54 | SamplerState LinearSampler { 55 | Filter = MIN_MAG_MIP_LINEAR; 56 | AddressU = Clamp; 57 | AddressV = Clamp; 58 | }; 59 | 60 | 61 | void PassVS(float4 position : POSITION, 62 | out float4 svposition : SV_POSITION, 63 | inout float2 texcoord : TEXCOORD0) { 64 | svposition = position; 65 | } 66 | 67 | 68 | float4 CoCPS(float4 position : SV_POSITION, 69 | float2 texcoord : TEXCOORD0) : SV_TARGET { 70 | float depth = depthTex.Sample(PointSampler, texcoord).r; 71 | if (abs(depth - focusDistance) > focusRange / 2.0) { 72 | if (depth - focusDistance > 0.0) { 73 | float t = saturate(abs(depth - focusDistance) - focusRange / 2.0); 74 | return saturate(t * focusFalloff.x); 75 | } else { 76 | float t = saturate(abs(depth - focusDistance) - focusRange / 2.0); 77 | return saturate(t * focusFalloff.y); 78 | } 79 | } else 80 | return 0.0; 81 | } 82 | 83 | 84 | float4 BlurPS(float4 position : SV_POSITION, 85 | float2 texcoord : TEXCOORD0, 86 | uniform float2 step) : SV_TARGET { 87 | #if N_SAMPLES == 13 88 | float offsets[] = { -1.7688, -1.1984, -0.8694, -0.6151, -0.3957, -0.1940, 0.1940, 0.3957, 0.6151, 0.8694, 1.1984, 1.7688 }; 89 | const float n = 12.0; 90 | #elif N_SAMPLES == 11 91 | float offsets[] = { -1.6906, -1.0968, -0.7479, -0.4728, -0.2299, 0.2299, 0.4728, 0.7479, 1.0968, 1.6906 }; 92 | const float n = 10.0; 93 | #elif N_SAMPLES == 9 94 | float offsets[] = { -1.5932, -0.9674, -0.5895, -0.2822, 0.2822, 0.5895, 0.9674, 1.5932 }; 95 | const float n = 8.0; 96 | #elif N_SAMPLES == 7 97 | float offsets[] = { -1.4652, -0.7916, -0.3661, 0.3661, 0.7916, 1.4652 }; 98 | const float n = 6.0; 99 | #else 100 | float offsets[] = { -1.282, -0.524, 0.524, 1.282 }; 101 | const float n = 4.0; 102 | #endif 103 | 104 | float CoC = cocTex.Sample(LinearSampler, texcoord).r; 105 | 106 | float4 color = blurredTex.Sample(LinearSampler, texcoord); 107 | float sum = 1.0; 108 | for (int i = 0; i < int(n); i++) { 109 | float tapCoC = cocTex.Sample(LinearSampler, texcoord + step * offsets[i] * CoC).r; 110 | float4 tap = blurredTex.Sample(LinearSampler, texcoord + step * offsets[i] * CoC); 111 | 112 | float contribution = tapCoC > CoC? 1.0f : tapCoC; 113 | color += contribution * tap; 114 | sum += contribution; 115 | } 116 | return color / sum; 117 | } 118 | 119 | 120 | DepthStencilState DisableDepthStencil { 121 | DepthEnable = FALSE; 122 | StencilEnable = FALSE; 123 | }; 124 | 125 | BlendState NoBlending { 126 | AlphaToCoverageEnable = FALSE; 127 | BlendEnable[0] = FALSE; 128 | }; 129 | 130 | 131 | technique10 CoC { 132 | pass CoC { 133 | SetVertexShader(CompileShader(vs_4_0, PassVS())); 134 | SetGeometryShader(NULL); 135 | SetPixelShader(CompileShader(ps_4_0, CoCPS())); 136 | 137 | SetDepthStencilState(DisableDepthStencil, 0); 138 | SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); 139 | } 140 | } 141 | 142 | technique10 Blur { 143 | pass Blur { 144 | SetVertexShader(CompileShader(vs_4_0, PassVS())); 145 | SetGeometryShader(NULL); 146 | SetPixelShader(CompileShader(ps_4_0, BlurPS(pixelSize * blurWidth * direction))); 147 | 148 | SetDepthStencilState(DisableDepthStencil, 0); 149 | SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /Demo/Shaders/FilmGrain.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | cbuffer UpdatedOncePerFrame { 33 | float2 pixelSize; 34 | float noiseIntensity; 35 | float exposure; 36 | float t; 37 | } 38 | 39 | Texture2D srcTex; 40 | Texture3D noiseTex; 41 | 42 | 43 | SamplerState LinearSampler { 44 | Filter = MIN_MAG_MIP_LINEAR; 45 | AddressU = Clamp; 46 | AddressV = Clamp; 47 | }; 48 | 49 | SamplerState LinearSamplerWrap { 50 | Filter = MIN_MAG_MIP_LINEAR; 51 | AddressU = Wrap; 52 | AddressV = Wrap; 53 | AddressW = Wrap; 54 | }; 55 | 56 | 57 | void PassVS(float4 position : POSITION, 58 | out float4 svposition : SV_POSITION, 59 | inout float2 texcoord : TEXCOORD0) { 60 | svposition = position; 61 | } 62 | 63 | 64 | float3 Overlay(float3 a, float3 b){ 65 | return pow(abs(b), 2.2) < 0.5? 2 * a * b : 1.0 - 2 * (1.0 - a) * (1.0 - b); 66 | } 67 | 68 | 69 | float3 AddNoise(float3 color, float2 texcoord) { 70 | float2 coord = texcoord * 2.0; 71 | coord.x *= pixelSize.y / pixelSize.x; 72 | float noise = noiseTex.Sample(LinearSamplerWrap, float3(coord, t)).r; 73 | float exposureFactor = exposure / 2.0; 74 | exposureFactor = sqrt(exposureFactor); 75 | float t = lerp(3.5 * noiseIntensity, 1.13 * noiseIntensity, exposureFactor); 76 | return Overlay(color, lerp(0.5, noise, t)); 77 | } 78 | 79 | 80 | float4 FilmGrainPS(float4 position : SV_POSITION, 81 | float2 texcoord : TEXCOORD0) : SV_TARGET { 82 | float3 color = srcTex.Sample(LinearSampler, texcoord).rgb; 83 | color = AddNoise(color, texcoord); 84 | return float4(color, 1.0); 85 | } 86 | 87 | 88 | DepthStencilState DisableDepthStencil { 89 | DepthEnable = FALSE; 90 | StencilEnable = FALSE; 91 | }; 92 | 93 | BlendState NoBlending { 94 | AlphaToCoverageEnable = FALSE; 95 | BlendEnable[0] = FALSE; 96 | }; 97 | 98 | 99 | technique10 FilmGrain { 100 | pass FilmGrain { 101 | SetVertexShader(CompileShader(vs_4_0, PassVS())); 102 | SetGeometryShader(NULL); 103 | SetPixelShader(CompileShader(ps_4_0, FilmGrainPS())); 104 | 105 | SetDepthStencilState(DisableDepthStencil, 0); 106 | SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Demo/Shaders/SMAA.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iryoku/separable-sss/b2174689ab22d90647825fdbada7bbd08e7e4e49/Demo/Shaders/SMAA.h -------------------------------------------------------------------------------- /Demo/Shaders/SeparableSSS.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com) 3 | * Copyright (C) 2012 Diego Gutierrez (diegog@unizar.es) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution: 15 | * 16 | * "Uses Separable SSS. Copyright (C) 2012 by Jorge Jimenez and Diego 17 | * Gutierrez." 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 20 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * The views and conclusions contained in the software and documentation are 32 | * those of the authors and should not be interpreted as representing official 33 | * policies, either expressed or implied, of the copyright holders. 34 | */ 35 | 36 | 37 | // Set the HLSL version: 38 | #ifndef SMAA_HLSL_4 39 | #define SSSS_HLSL_4 1 40 | #endif 41 | 42 | // Texture used to fecth the SSS strength: 43 | Texture2D strengthTex; 44 | 45 | // And include our header! 46 | #include "SeparableSSS.h" 47 | 48 | 49 | /** 50 | * If STENCIL_INITIALIZED is set to 1, the stencil buffer is expected to be 51 | * initialized with the pixels that need SSS processing, marked with some id 52 | * (see 'id' below). 53 | * 54 | * If set to 0, then the bound stencil buffer is expected to be cleared. 55 | * The stencil will be initialized in the first pass, to at least optimize 56 | * the second pass. When using MSAA, the stencil buffer will probably be 57 | * uninitialized. 58 | */ 59 | #ifndef STENCIL_INITIALIZED 60 | #define STENCIL_INITIALIZED 0 61 | #endif 62 | 63 | /** 64 | * This specifies the stencil id we must apply subsurface scattering on. 65 | * If !STENCIL_INITIALIZED, it should be set to an unused value, as 66 | * pixels will be marked in the stencil buffer in the first pass to 67 | * optimize the second one. 68 | */ 69 | int id; 70 | 71 | /** 72 | * See |SeparableSSS.h| for more details. 73 | */ 74 | float sssWidth; 75 | 76 | 77 | /** 78 | * DepthStencilState's and company 79 | */ 80 | DepthStencilState BlurStencil { 81 | DepthEnable = FALSE; 82 | StencilEnable = TRUE; 83 | FrontFaceStencilFunc = EQUAL; 84 | }; 85 | 86 | DepthStencilState InitStencil { 87 | DepthEnable = FALSE; 88 | StencilEnable = TRUE; 89 | FrontFaceStencilPass = REPLACE; 90 | }; 91 | 92 | BlendState NoBlending { 93 | AlphaToCoverageEnable = FALSE; 94 | BlendEnable[0] = FALSE; 95 | BlendEnable[1] = FALSE; 96 | }; 97 | 98 | 99 | /** 100 | * Input textures 101 | */ 102 | Texture2D colorTex; 103 | Texture2D depthTex; 104 | 105 | 106 | /** 107 | * Function wrappers 108 | */ 109 | void DX10_SSSSBlurVS(float4 position : POSITION, 110 | out float4 svPosition : SV_POSITION, 111 | inout float2 texcoord : TEXCOORD0) { 112 | SSSSBlurVS(position, svPosition, texcoord); 113 | } 114 | 115 | float4 DX10_SSSSBlurPS(float4 position : SV_POSITION, 116 | float2 texcoord : TEXCOORD0, 117 | uniform SSSSTexture2D colorTex, 118 | uniform SSSSTexture2D depthTex, 119 | uniform float sssWidth, 120 | uniform float2 dir, 121 | uniform bool initStencil) : SV_TARGET { 122 | return SSSSBlurPS(texcoord, colorTex, depthTex, sssWidth, dir, initStencil); 123 | } 124 | 125 | 126 | /** 127 | * Time for some techniques! 128 | */ 129 | technique10 SSS { 130 | pass SSSSBlurX { 131 | SetVertexShader(CompileShader(vs_4_0, DX10_SSSSBlurVS())); 132 | SetGeometryShader(NULL); 133 | 134 | #if STENCIL_INITIALIZED == 1 135 | SetPixelShader(CompileShader(ps_4_0, DX10_SSSSBlurPS(colorTex, depthTex, sssWidth, float2(1.0, 0.0), false))); 136 | SetDepthStencilState(BlurStencil, id); 137 | #else 138 | SetPixelShader(CompileShader(ps_4_0, DX10_SSSSBlurPS(colorTex, depthTex, sssWidth, float2(1.0, 0.0), true))); 139 | SetDepthStencilState(InitStencil, id); 140 | #endif 141 | 142 | SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); 143 | } 144 | 145 | pass SSSSBlurY { 146 | SetVertexShader(CompileShader(vs_4_0, DX10_SSSSBlurVS())); 147 | SetGeometryShader(NULL); 148 | SetPixelShader(CompileShader(ps_4_0, DX10_SSSSBlurPS(colorTex, depthTex, sssWidth, float2(0.0, 1.0), false))); 149 | 150 | SetDepthStencilState(BlurStencil, id); 151 | SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /Demo/Shaders/ShadowMap.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | uniform float4x4 world; 33 | uniform float4x4 view; 34 | uniform float4x4 projection; 35 | 36 | 37 | float4 ShadowMapVS(float4 position : POSITION0, 38 | uniform float4x4 worldViewProjection) : SV_POSITION { 39 | float4 pos = mul(position, worldViewProjection); 40 | pos.z *= pos.w; // We want linear positions 41 | return pos; 42 | } 43 | 44 | 45 | DepthStencilState EnableDepthDisableStencil { 46 | DepthEnable = TRUE; 47 | DepthWriteMask = ALL; 48 | DepthFunc = LESS_EQUAL; 49 | StencilEnable = FALSE; 50 | }; 51 | 52 | 53 | BlendState NoBlending { 54 | AlphaToCoverageEnable = FALSE; 55 | BlendEnable[0] = FALSE; 56 | }; 57 | 58 | 59 | technique10 ShadowMap { 60 | pass ShadowMap { 61 | SetVertexShader(CompileShader(vs_4_0, ShadowMapVS(mul(mul(world, view), projection)))); 62 | SetGeometryShader(NULL); 63 | SetPixelShader(NULL); 64 | 65 | SetDepthStencilState(EnableDepthDisableStencil, 0); 66 | SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Demo/Shaders/SkyDome.fx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Jorge Jimenez (jorge@iryoku.com). All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 15 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 18 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * The views and conclusions contained in the software and documentation are 27 | * those of the authors and should not be interpreted as representing official 28 | * policies, either expressed or implied, of the copyright holders. 29 | */ 30 | 31 | 32 | cbuffer UpdatedPerFrame { 33 | matrix view; 34 | matrix projection; 35 | matrix world; 36 | float intensity; 37 | } 38 | 39 | TextureCube skyTex; 40 | 41 | 42 | SamplerState LinearSampler { 43 | Filter = MIN_MAG_MIP_LINEAR; 44 | AddressU = Clamp; 45 | AddressV = Clamp; 46 | }; 47 | 48 | 49 | void SkyDomeVS(float4 position : POSITION, 50 | out float4 svposition : SV_POSITION, 51 | out float3 texcoord : TEXCOORD0, 52 | uniform float4x4 worldViewProjection) { 53 | svposition = mul(position, worldViewProjection); 54 | texcoord = position.xyz; 55 | } 56 | 57 | float4 SkyDomePS(float4 position : SV_POSITION, 58 | float3 texcoord : TEXCOORD0) : SV_TARGET0 { 59 | return float4(intensity * skyTex.Sample(LinearSampler, texcoord).rgb, 0.0); 60 | } 61 | 62 | 63 | DepthStencilState EnableDepthDisableStencil { 64 | DepthEnable = TRUE; 65 | StencilEnable = FALSE; 66 | }; 67 | 68 | BlendState NoBlending { 69 | AlphaToCoverageEnable = FALSE; 70 | BlendEnable[0] = FALSE; 71 | }; 72 | 73 | 74 | technique10 RenderSkyDome { 75 | pass RenderSkyDome { 76 | SetVertexShader(CompileShader(vs_4_0, SkyDomeVS(mul(mul(world, view), projection)))); 77 | SetGeometryShader(NULL); 78 | SetPixelShader(CompileShader(ps_4_0, SkyDomePS())); 79 | 80 | SetDepthStencilState(EnableDepthDisableStencil, 0); 81 | SetBlendState(NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com) 2 | Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es) 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution: 14 | 15 | "Uses Separable SSS. Copyright (C) 2011 by Jorge Jimenez and Diego 16 | Gutierrez." 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 19 | IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 22 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. 29 | 30 | The views and conclusions contained in the software and documentation are 31 | those of the authors and should not be interpreted as representing official 32 | policies, either expressed or implied, of the copyright holders. 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Separable Subsurface Scattering 2 | =============================== 3 | 4 | Separable Subsurface Scattering is a technique that allows to efficiently perform subsurface scattering calculations in screen space in just two passes. 5 | 6 | 7 | Thanks To 8 | --------- 9 | 10 | **Josh Checa** ‒ for its invaluable support and inspiration. 11 | 12 | 13 | Usage 14 | ----- 15 | 16 | See [SeparableSSS.h](https://github.com/iryoku/separable-sss/blob/master/SeparableSSS.h) for integration info. The directory [Demo](https://github.com/iryoku/separable-sss/blob/master/Demo) contain an integration example for DirectX 10. This demo contains very detailed information about our technique (look for the help button). 17 | 18 | 19 | Bug Tracker 20 | ----------- 21 | 22 | Found a bug? Please create an issue here on GitHub! 23 | 24 | https://github.com/iryoku/separable-sss/issues 25 | 26 | 27 | Authors 28 | ------- 29 | 30 | **Jorge Jimenez** http://www.iryoku.com/ 31 | 32 | **Diego Gutierrez** http://giga.cps.unizar.es/~diegog/ 33 | 34 | 35 | Copyright and License 36 | --------------------- 37 | 38 | Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com) 39 | Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es) 40 | All rights reserved. 41 | 42 | Redistribution and use in source and binary forms, with or without 43 | modification, are permitted provided that the following conditions are met: 44 | 45 | 1. Redistributions of source code must retain the above copyright notice, 46 | this list of conditions and the following disclaimer. 47 | 48 | 2. Redistributions in binary form must reproduce the following disclaimer 49 | in the documentation and/or other materials provided with the 50 | distribution: 51 | 52 | "Uses Separable SSS. Copyright (C) 2011 by Jorge Jimenez and Diego 53 | Gutierrez." 54 | 55 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 56 | IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 57 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 58 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS 59 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 60 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 61 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 62 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 63 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 64 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 65 | POSSIBILITY OF SUCH DAMAGE. 66 | 67 | The views and conclusions contained in the software and documentation are 68 | those of the authors and should not be interpreted as representing official 69 | policies, either expressed or implied, of the copyright holders. 70 | --------------------------------------------------------------------------------