├── BBGrassPatch.cpp ├── BBGrassPatch.h ├── Billboard.cpp ├── Billboard.h ├── BillboardedTrees.cpp ├── BillboardedTrees.h ├── DXUT ├── core │ ├── DXUT.cpp │ ├── DXUT.h │ ├── DXUTCore_2005.sln │ ├── DXUTCore_2005.vcproj │ ├── DXUTCore_2008.sln │ ├── DXUTCore_2008.vcproj │ ├── DXUTenum.cpp │ ├── DXUTenum.h │ ├── DXUTmisc.cpp │ └── DXUTmisc.h └── optional │ ├── DXUTLockFreePipe.h │ ├── DXUTOptional_2005.sln │ ├── DXUTOptional_2005.vcproj │ ├── DXUTOptional_2008.sln │ ├── DXUTOptional_2008.vcproj │ ├── DXUTShapes.cpp │ ├── DXUTShapes.h │ ├── DXUTcamera.cpp │ ├── DXUTcamera.h │ ├── DXUTgui.cpp │ ├── DXUTgui.h │ ├── DXUTguiIME.cpp │ ├── DXUTguiIME.h │ ├── DXUTres.cpp │ ├── DXUTres.h │ ├── DXUTsettingsdlg.cpp │ ├── DXUTsettingsdlg.h │ ├── IMesh.h │ ├── ImeUi.cpp │ ├── ImeUi.h │ ├── SDKmesh.cpp │ ├── SDKmesh.h │ ├── SDKmesh_old.h │ ├── SDKmisc.cpp │ ├── SDKmisc.h │ ├── SDKsound.cpp │ ├── SDKsound.h │ ├── SDKwavefile.cpp │ ├── SDKwavefile.h │ ├── directx.ico │ ├── rmxfguid.h │ ├── rmxftmpl.h │ └── sdkmesh_old.cpp ├── FrameWork ├── CModel.cpp ├── CModel.h ├── DX10Base.cpp ├── DX10Base.h ├── DX10BaseHelper.h ├── GrassUI.cpp ├── GrassUI.h ├── GrassUIState.h ├── ShereConeIntersectionTest.cpp ├── camera.cpp ├── camera.h ├── skybox.cpp └── skybox.h ├── GUIControlsTest.xml ├── Grass - 2008.ncb ├── Grass - 2008.sln ├── Grass - 2008.vcproj ├── Grass.cpp ├── Grass.h ├── Grass.manifest ├── Grass.rc ├── InstancedBillboard.cpp ├── InstancedBillboard.h ├── README.md ├── TerrainPatch.cpp ├── TerrainPatch.h ├── UpgradeLog.htm ├── fx ├── BasicTNL.fx └── skyboxNEW.fx ├── ipch └── GRASS - 2015-a34bf674 │ ├── GRASS - 2008-8e5b5e3d.ipch │ └── GRASS - 2008-c5c56a43.ipch ├── licence.txt ├── main.cpp ├── resource.h └── texture ├── GRASS_GROUND.dds ├── cubemap-evul.dds ├── grass.dds ├── grassY.dds ├── grass_turf.dds ├── grasssm.dds ├── grasssm.jpg ├── grasssm1.jpg ├── seafloor.dds ├── tree01s.dds ├── tree02s.dds └── tree35s.dds /BBGrassPatch.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | 8 | #include "DXUT.h" 9 | #include "BBGrassPatch.h" 10 | 11 | BOOL SphereConeTest ( D3DXVECTOR3 sphereCenter, float radius, float fov, D3DXVECTOR3 eyePt, D3DXVECTOR3 lookAt); 12 | 13 | static const D3D10_INPUT_ELEMENT_DESC grassLayout[] = 14 | { 15 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 16 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 17 | { "vPPos", 0, DXGI_FORMAT_R32G32_FLOAT, 1, 0, D3D10_INPUT_PER_INSTANCE_DATA, 1 }, 18 | 19 | }; 20 | 21 | static const UINT numGrassLayoutElements = sizeof( grassLayout ) / sizeof( grassLayout[0] ); 22 | 23 | 24 | BBGrassPatch::BBGrassPatch( int numBB, int inPatchCount, D3DXVECTOR2* inPatchPos ) 25 | { 26 | 27 | m_numGrassBB = numBB; 28 | patchPos = inPatchPos; 29 | patchCount = inPatchCount; 30 | } 31 | 32 | BBGrassPatch::~BBGrassPatch( ) 33 | { 34 | SAFE_DELETE_ARRAY ( patchPos ); 35 | SAFE_DELETE_ARRAY ( visiblePatches ); 36 | SAFE_DELETE_ARRAY ( m_grassVerts ); 37 | } 38 | 39 | HRESULT BBGrassPatch::CreateDevice( ID3D10Device* pd3dDevice, ID3D10Effect* pEffect ) 40 | { 41 | HRESULT hr = S_OK; 42 | __super::Init(L"texture//grassY.dds", patchPos, patchCount, 43 | m_grassVerts, 6*m_numGrassBB,(D3D10_INPUT_ELEMENT_DESC*)grassLayout, numGrassLayoutElements ); 44 | ID3D10EffectTechnique* pRenderTechnique; 45 | pRenderTechnique = pEffect->GetTechniqueByName( "RenderGrass" ); 46 | hr = __super::CreateDevice( pd3dDevice , pRenderTechnique ); 47 | 48 | //__super::SetInstData( patchPos, patchCount ); 49 | return hr; 50 | 51 | } 52 | 53 | 54 | void BBGrassPatch::DestroyDevice() 55 | { 56 | InstancedBillboard::DestroyDevice(); 57 | 58 | } 59 | 60 | 61 | void BBGrassPatch::GeneratePatch( unsigned int bladeCnt, float scale ) 62 | { 63 | m_numGrassBB = bladeCnt; 64 | m_grassVerts = new BBGrassVertex[m_numGrassBB*6]; 65 | 66 | D3DXMATRIX mat; 67 | D3DXMATRIX matRandom; 68 | D3DXMatrixIdentity( &mat); 69 | 70 | for( int j=0; j< m_numGrassBB; j++ ) 71 | { 72 | // Generate each quad at random position, orientation, height 73 | D3DXMatrixIdentity( &matRandom); 74 | // float scale = 10.0f; 75 | float angle = ((float)rand()/RAND_MAX - 0.5f)*2 * D3DX_PI; // angle = [-pi,pi] 76 | float dx = ((float)rand()/RAND_MAX - 0.5f)*2 * scale; 77 | float dz = ((float)rand()/RAND_MAX - 0.5f)*2 * scale; 78 | float heightScale = ((float)rand()/RAND_MAX - 0.5f) / 2.0f + 1.0f; 79 | 80 | D3DXMatrixRotationY( &mat, angle); 81 | D3DXMatrixMultiply( &matRandom, &matRandom, &mat ); 82 | D3DXMatrixTranslation( &mat, dx, 0.0f, dz); 83 | D3DXMatrixMultiply( &matRandom, &matRandom, &mat ); 84 | D3DXMatrixScaling( &mat, 1.0f, 1.0f, heightScale); 85 | D3DXMatrixMultiply( &matRandom, &matRandom, &mat ); 86 | 87 | // Apply the transformation to each vertex of the quad 88 | for( DWORD i=0; i< 6; i++ ) 89 | { 90 | D3DXVECTOR4 pos, outPos; 91 | pos.x = grassBBVerts[i].Pos.x; 92 | pos.y = grassBBVerts[i].Pos.y; 93 | pos.z = grassBBVerts[i].Pos.z; 94 | pos.w = 1.0; 95 | D3DXVec3Transform(&outPos, (D3DXVECTOR3 *)&pos, (D3DXMATRIX *)&matRandom); 96 | int index = j * 6 + i; 97 | m_grassVerts[index].Pos.x = outPos.x; 98 | m_grassVerts[index].Pos.y = outPos.y; 99 | m_grassVerts[index].Pos.z = outPos.z; 100 | m_grassVerts[index].Tex = grassBBVerts[i].Tex; 101 | } 102 | } 103 | 104 | } 105 | 106 | void BBGrassPatch::Cull( float fov, D3DXVECTOR3 eyePt, D3DXVECTOR3 lookAt ) 107 | { 108 | int numVisibleInstances = 0; 109 | D3DXVECTOR3 patchCenter3D; 110 | BOOL visible; 111 | for( unsigned int i = 0 ; i < patchCount; i++) 112 | { 113 | patchCenter3D.x = patchPos[i].x; 114 | patchCenter3D.z = patchPos[i].y; 115 | patchCenter3D.y = 0; // we are only storing x,z positions for the patches 116 | // we want to cull the patch with a sphere of radius = to diagonal of square patch 117 | // hence radiusPatchBoundingSphere = 1.414*rpatch 118 | visible = SphereConeTest ( patchCenter3D, patchRadius*1.414f, fov, eyePt, lookAt); 119 | if( visible ) 120 | { 121 | // visible add to draw list 122 | visiblePatches[numVisibleInstances] = patchPos[i]; 123 | numVisibleInstances++; 124 | } 125 | } 126 | 127 | SetInstData( visiblePatches, numVisibleInstances ); 128 | } 129 | 130 | 131 | void BBGrassPatch::Generate( D3DXVECTOR3 surfaceCenter, float surfaceR, unsigned int patchBladeCnt, float inPatchRadius ) 132 | { 133 | patchRadius = inPatchRadius; 134 | GeneratePatch( patchBladeCnt, patchRadius ); 135 | 136 | patchCountX = int( surfaceR/patchRadius ); 137 | patchCountZ = int( surfaceR/patchRadius ); 138 | patchCount = (2*patchCountX-1)*(2*patchCountZ-1); 139 | patchPos = new D3DXVECTOR2[patchCount]; 140 | visiblePatches = new D3DXVECTOR2[patchCount]; 141 | int k = 0; 142 | for(int i = -(patchCountX-1); i < patchCountX; i++) 143 | { 144 | for(int j = -(patchCountZ-1); j < patchCountZ; j++) 145 | { 146 | patchPos[k].x = surfaceCenter.x + i*patchRadius; 147 | patchPos[k].y = surfaceCenter.z + j*patchRadius; 148 | k++; 149 | } 150 | 151 | } 152 | } -------------------------------------------------------------------------------- /BBGrassPatch.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | #include 9 | #include 10 | #define DEFAULT_NUM_GRASS_BB 70 11 | #include "InstancedBillboard.h" 12 | 13 | struct BBGrassVertex 14 | { 15 | D3DXVECTOR3 Pos; 16 | D3DXVECTOR2 Tex; 17 | }; 18 | 19 | // geometry for single grass blade 20 | static BBGrassVertex grassBBVerts[] = 21 | { 22 | // x y z tu1 tv1 23 | { D3DXVECTOR3( -10.0f, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.01f )}, 24 | { D3DXVECTOR3( 10.0f, 0.0f, 0.0f), D3DXVECTOR2( 0.01f, 0.01f )}, 25 | { D3DXVECTOR3( 10.0f, -10.0f, 0.0f), D3DXVECTOR2( 0.01f, 1.0f ) }, 26 | 27 | { D3DXVECTOR3( -10.0f, 0.0f, 0.0f), D3DXVECTOR2( 1.0f, 0.01f )}, 28 | { D3DXVECTOR3( 10.0f, -10.0f, 0.0f), D3DXVECTOR2( 0.01f, 1.0f ) }, 29 | { D3DXVECTOR3( -10.0f, -10.0f, 0.0f), D3DXVECTOR2( 1.0f, 1.0f ) }, 30 | }; 31 | 32 | // x,z instance positions ... 33 | static D3DXVECTOR2 defaultPatchPos[] = 34 | { 35 | // x z 36 | D3DXVECTOR2( 20.0f, 0.0f ) , 37 | D3DXVECTOR2( 0.0f, 0.0f ) , 38 | D3DXVECTOR2( -20.0f, 0.0f ) , 39 | 40 | D3DXVECTOR2( 20.0f, -20.0f ) , 41 | D3DXVECTOR2( 0.0f, -20.0f ) , 42 | D3DXVECTOR2( -20.0f, -20.0f ) , 43 | 44 | D3DXVECTOR2( 20.0f, 40.0f ) , 45 | D3DXVECTOR2( 20.0f, 40.0f ) , 46 | D3DXVECTOR2( 0.0f, 40.0f ) , 47 | D3DXVECTOR2( -20.0f, 40.0f ), 48 | D3DXVECTOR2( -40.0, 40.0f ), 49 | 50 | D3DXVECTOR2( 40.0f, 20.0f ) , 51 | D3DXVECTOR2( 20.0f, 20.0f ) , 52 | D3DXVECTOR2( 0.0f, 20.0f ) , 53 | D3DXVECTOR2( -20.0f, 20.0f ) , 54 | D3DXVECTOR2( -40.0f, 20.0f ) , 55 | }; 56 | 57 | const int defaultPatchCount = 16; 58 | 59 | class BBGrassPatch : public InstancedBillboard 60 | { 61 | int m_numGrassBB; 62 | BBGrassVertex* m_grassVerts; 63 | float patchRadius; 64 | int patchCountX; 65 | int patchCountZ; 66 | unsigned int patchCount; 67 | D3DXVECTOR2* patchPos; 68 | D3DXVECTOR2* visiblePatches; 69 | // Generates & Randomly Orients Blades in a patch 70 | void GeneratePatch( unsigned int bladeCnt, float scale); 71 | 72 | public: 73 | 74 | BBGrassPatch( int numBB = DEFAULT_NUM_GRASS_BB, int inPatchCount = defaultPatchCount, D3DXVECTOR2* inPatchPos = defaultPatchPos ); 75 | ~BBGrassPatch( ); 76 | HRESULT CreateDevice ( ID3D10Device* m_pd3dDevice, ID3D10Effect* m_pEffect ); 77 | void Cull ( float fov, D3DXVECTOR3 eyePt, D3DXVECTOR3 lookAt ); 78 | void DestroyDevice( ); 79 | void Generate ( D3DXVECTOR3 surfaceCenter, float surfaceR, unsigned int patchBladeCnt, float inPatchRadius ); 80 | 81 | }; -------------------------------------------------------------------------------- /Billboard.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/Billboard.cpp -------------------------------------------------------------------------------- /Billboard.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | #pragma warning ( disable : 4995 4996 ) 9 | #include 10 | #include 11 | #include 12 | 13 | struct SimpleVertex 14 | { 15 | D3DXVECTOR3 Pos; 16 | D3DXVECTOR2 Tex; 17 | }; 18 | 19 | // Define a default input layout 20 | static const D3D10_INPUT_ELEMENT_DESC defaultlayout[] = 21 | { 22 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 23 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 24 | }; 25 | static const UINT defaultnumElements = sizeof( defaultlayout ) / sizeof( defaultlayout[0] ); 26 | 27 | 28 | template < class T_VERTEX > 29 | class Billboard 30 | { 31 | int vertexCnt; 32 | T_VERTEX* pVertices; 33 | D3D10_INPUT_ELEMENT_DESC* pLayout; 34 | int numElements; 35 | ID3D10InputLayout* pVertexLayout; 36 | ID3D10Buffer* pVertexBuffer; 37 | TCHAR pTextureName[MAX_PATH]; 38 | ID3D10ShaderResourceView* pTextureRV; 39 | ID3D10EffectTechnique* pRenderTechnique; 40 | 41 | public: 42 | Billboard( ); 43 | virtual ~Billboard(){}; 44 | 45 | virtual void Init ( TCHAR* texName, T_VERTEX* pInVertices, int numVerts, D3D10_INPUT_ELEMENT_DESC* layout = (D3D10_INPUT_ELEMENT_DESC*)defaultlayout, int numLayoutElements = defaultnumElements, 46 | WORD* indices = 0, int numIndices = 0 ); 47 | virtual void Destroy ( ) { }; 48 | 49 | virtual HRESULT CreateDevice ( ID3D10Device* pd3dDevice, ID3D10EffectTechnique* pTechique ); 50 | 51 | virtual void DestroyDevice( ); 52 | 53 | virtual void Render ( ID3D10Device* pd3dDevice, ID3D10EffectShaderResourceVariable* pDiffuseVariable ); 54 | 55 | }; 56 | 57 | template < class T_VERTEX > 58 | HRESULT Billboard 59 | ::CreateDevice( ID3D10Device* pd3dDevice, ID3D10EffectTechnique* pTechique ) 60 | { 61 | HRESULT hr = S_OK; 62 | pRenderTechnique = pTechique; 63 | 64 | // Create the input layout 65 | D3D10_PASS_DESC PassDesc; 66 | pRenderTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc ); 67 | hr = pd3dDevice->CreateInputLayout( pLayout, numElements, PassDesc.pIAInputSignature, 68 | PassDesc.IAInputSignatureSize, &pVertexLayout ); 69 | V_RETURN( hr ); 70 | 71 | // Initialize Vertex Buffers 72 | D3D10_BUFFER_DESC bd; 73 | D3D10_SUBRESOURCE_DATA InitData; 74 | 75 | bd.Usage = D3D10_USAGE_DEFAULT; 76 | bd.ByteWidth = sizeof( T_VERTEX ) * vertexCnt; 77 | bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; 78 | bd.CPUAccessFlags = 0; 79 | bd.MiscFlags = 0; 80 | InitData.pSysMem = pVertices; 81 | 82 | V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &pVertexBuffer )); 83 | 84 | // Load the Texture 85 | V_RETURN( D3DX10CreateShaderResourceViewFromFile( pd3dDevice, pTextureName, NULL, NULL, &pTextureRV, NULL )); 86 | 87 | return hr; 88 | 89 | } 90 | 91 | template < class T_VERTEX > 92 | Billboard::Billboard() 93 | { 94 | pVertexLayout = NULL; 95 | pVertexBuffer = NULL; 96 | pTextureRV = NULL; 97 | pRenderTechnique = NULL; 98 | 99 | } 100 | 101 | template < class T_VERTEX > 102 | void Billboard 103 | ::Init( TCHAR* texName, T_VERTEX* pInVertices, int numVerts, D3D10_INPUT_ELEMENT_DESC* layout, int numLayoutElements, WORD* indices /*= 0*/, int numIndices /*= 0 */ ) 104 | { 105 | _tcscpy(pTextureName, texName); 106 | pVertices = pInVertices; 107 | vertexCnt = numVerts; 108 | pLayout = layout; 109 | numElements = numLayoutElements; 110 | } 111 | 112 | 113 | 114 | template < class T_VERTEX > 115 | void Billboard 116 | ::DestroyDevice() 117 | { 118 | SAFE_RELEASE( pVertexBuffer ); 119 | SAFE_RELEASE( pVertexLayout ); 120 | SAFE_RELEASE( pTextureRV ); 121 | } 122 | template < class T_VERTEX > 123 | void Billboard 124 | ::Render( ID3D10Device* pd3dDevice, ID3D10EffectShaderResourceVariable* pDiffuseVariable ) 125 | { 126 | // Set diffuse texture 127 | pDiffuseVariable->SetResource( pTextureRV ); 128 | 129 | // Set Vertex Buffers & layout 130 | pd3dDevice->IASetInputLayout( pVertexLayout ); 131 | 132 | unsigned int offset = 0, stride = sizeof( SimpleVertex ); 133 | pd3dDevice->IASetVertexBuffers( 0, 1, &pVertexBuffer, &stride, &offset ); 134 | pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); 135 | 136 | // Render Billboard 137 | D3D10_TECHNIQUE_DESC techDesc; 138 | pRenderTechnique->GetDesc( &techDesc ); 139 | 140 | for( unsigned int p = 0; p < techDesc.Passes; ++p ) 141 | { 142 | pRenderTechnique->GetPassByIndex( p )->Apply( 0 ); 143 | pd3dDevice->Draw( vertexCnt, 0 ); 144 | } 145 | 146 | } 147 | 148 | -------------------------------------------------------------------------------- /BillboardedTrees.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "BillboardedTrees.h" 9 | 10 | static const D3D10_INPUT_ELEMENT_DESC treeLayout[] = 11 | { 12 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 13 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 14 | { "offPos", 0, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D10_INPUT_PER_INSTANCE_DATA, 1 }, 15 | { "scale", 0, DXGI_FORMAT_R32G32_FLOAT, 1, 12, D3D10_INPUT_PER_INSTANCE_DATA, 1 }, 16 | 17 | }; 18 | 19 | static const UINT numTreeLayoutElements = sizeof( treeLayout ) / sizeof( treeLayout[0] ); 20 | 21 | 22 | HRESULT BillboardedTrees::Initialize( D3DXVECTOR2 offPos, int numTrees, float height, float width, float spread ) 23 | { 24 | m_treeCnt = numTrees; 25 | D3DXMatrixIdentity( &m_TreeOrientMatrix); 26 | float yPos = -10.0; // = pos.y 27 | m_pTreeVerts = new SimpleVertex[6]; 28 | m_pTreeData = new TREE_INSTANCE_DATA[numTrees]; 29 | 30 | m_pTreeVerts[0].Pos = D3DXVECTOR3(-width, 2*height, 0 ); 31 | m_pTreeVerts[1].Pos = D3DXVECTOR3( width, 2*height, 0 ); 32 | m_pTreeVerts[2].Pos = D3DXVECTOR3( width, 0, 0 ); 33 | 34 | m_pTreeVerts[3].Pos = D3DXVECTOR3(-width, 2*height, 0 ); 35 | m_pTreeVerts[4].Pos = D3DXVECTOR3( width, 0, 0 ); 36 | m_pTreeVerts[5].Pos = D3DXVECTOR3(-width, 0, 0 ); 37 | 38 | m_pTreeVerts[0].Tex = D3DXVECTOR2( 1.0f, 0.01f ); 39 | m_pTreeVerts[1].Tex = D3DXVECTOR2( 0.0f, 0.01f ); 40 | m_pTreeVerts[2].Tex = D3DXVECTOR2( 0.01f, 1.0f ); 41 | 42 | m_pTreeVerts[3].Tex = D3DXVECTOR2( 1.0f, 0.01f ); 43 | m_pTreeVerts[4].Tex = D3DXVECTOR2( 0.0f, 1.0f ); 44 | m_pTreeVerts[5].Tex = D3DXVECTOR2( 1.0f, 1.0f ); 45 | 46 | // randomly position trees 47 | 48 | for( int i=0; iGetTechniqueByName( "RenderTree" ); 83 | hr = __super::CreateDevice( pd3dDevice , pRenderTechnique ); 84 | m_pfxOrientation = pEffect->GetVariableByName( "Orientation" )->AsMatrix(); 85 | 86 | return hr; 87 | 88 | } 89 | void BillboardedTrees::DestroyDevice() 90 | { 91 | 92 | __super::DestroyDevice(); 93 | SAFE_DELETE_ARRAY( m_pTreeVerts ); 94 | SAFE_DELETE_ARRAY( m_pTreeData ); 95 | } 96 | 97 | void BillboardedTrees::OrientTreesTo(D3DXVECTOR3 vDir) 98 | { 99 | 100 | m_Orientation = vDir; 101 | 102 | if( vDir.x < 0.0f ) 103 | D3DXMatrixRotationY( &m_TreeOrientMatrix, -atanf(vDir.z/vDir.x)-D3DX_PI/2 ); 104 | else 105 | D3DXMatrixRotationY( &m_TreeOrientMatrix, -atanf(vDir.z/vDir.x)+D3DX_PI/2 ); 106 | 107 | //// Sort trees in back-to-front order 108 | // qsort( m_Trees, m_treeCnt, sizeof(Tree), TreeSortCB ); 109 | 110 | } 111 | //----------------------------------------------------------------------------- 112 | // Name: DrawTrees() 113 | // Desc: 114 | //----------------------------------------------------------------------------- 115 | void BillboardedTrees::Render(ID3D10Device* pd3dDevice, ID3D10EffectShaderResourceVariable* pDiffuseVariable ) 116 | { 117 | m_pfxOrientation->SetMatrix((float*) &m_TreeOrientMatrix ); 118 | __super::Render( pd3dDevice,pDiffuseVariable ); 119 | 120 | } 121 | 122 | void BillboardedTrees::Destroy() 123 | { 124 | SAFE_DELETE_ARRAY (m_pTreeVerts); 125 | } 126 | -------------------------------------------------------------------------------- /BillboardedTrees.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | #include "Billboard.h" 9 | #include "InstancedBillboard.h" 10 | struct SimpleVertex; 11 | 12 | #define MAX_TREE_TEX 3 13 | #define DEFAULT_NUM_TREES 10 14 | 15 | // TODO float HeightField( FLOAT x, FLOAT y ); 16 | 17 | struct TREE_INSTANCE_DATA 18 | { 19 | D3DXVECTOR3 Pos; 20 | D3DXVECTOR2 scale; 21 | }; 22 | class BillboardedTrees : public InstancedBillboard 23 | { 24 | 25 | public: 26 | 27 | int m_treeCnt; 28 | SimpleVertex* m_pTreeVerts; 29 | TREE_INSTANCE_DATA* m_pTreeData; 30 | 31 | // tree orientation 32 | D3DXMATRIX m_TreeOrientMatrix; 33 | D3DXVECTOR3 m_Orientation; 34 | ID3D10EffectMatrixVariable* m_pfxOrientation; 35 | 36 | ID3D10EffectTechnique* m_pRenderTechnique; 37 | 38 | 39 | HRESULT Initialize ( D3DXVECTOR2 offPos, int numTrees = DEFAULT_NUM_TREES, float ht = 30.0f, 40 | float wd = 16.0f, float spread = 30.0f); 41 | 42 | HRESULT CreateDevice ( ID3D10Device* m_pd3dDevice, ID3D10Effect* m_pEffect ); 43 | 44 | void DestroyDevice ( ); 45 | 46 | void Destroy ( ); 47 | 48 | void Render ( ID3D10Device* m_pd3dDevice, ID3D10EffectShaderResourceVariable* m_pDiffuseVariable ); 49 | 50 | void OrientTreesTo ( D3DXVECTOR3); 51 | 52 | 53 | }; 54 | -------------------------------------------------------------------------------- /DXUT/core/DXUTCore_2005.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 9.00 2 | # Visual Studio 2005 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTCore", "DXUTCore_2005.vcproj", "{E0CF097B-F22D-465B-A884-D89E55BD7ECD}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Release|Win32 = Release|Win32 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.ActiveCfg = Debug|Win32 12 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.Build.0 = Debug|Win32 13 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.ActiveCfg = Release|Win32 14 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.Build.0 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | EndGlobal 20 | -------------------------------------------------------------------------------- /DXUT/core/DXUTCore_2005.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 25 | 28 | 31 | 34 | 37 | 40 | 53 | 56 | 59 | 62 | 66 | 69 | 72 | 75 | 78 | 81 | 82 | 90 | 93 | 96 | 99 | 102 | 105 | 115 | 118 | 121 | 124 | 128 | 131 | 134 | 137 | 140 | 143 | 144 | 145 | 146 | 147 | 148 | 151 | 154 | 155 | 158 | 159 | 162 | 163 | 166 | 167 | 170 | 171 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /DXUT/core/DXUTCore_2008.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTCore", "DXUTCore_2008.vcproj", "{E0CF097B-F22D-465B-A884-D89E55BD7ECD}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Release|Win32 = Release|Win32 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.ActiveCfg = Debug|Win32 12 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.Build.0 = Debug|Win32 13 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.ActiveCfg = Release|Win32 14 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.Build.0 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | EndGlobal 20 | -------------------------------------------------------------------------------- /DXUT/core/DXUTCore_2008.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 26 | 29 | 32 | 35 | 38 | 41 | 54 | 57 | 60 | 63 | 67 | 70 | 73 | 76 | 79 | 82 | 83 | 91 | 94 | 97 | 100 | 103 | 106 | 116 | 119 | 122 | 125 | 129 | 132 | 135 | 138 | 141 | 144 | 145 | 146 | 147 | 148 | 149 | 152 | 155 | 156 | 159 | 160 | 163 | 164 | 167 | 168 | 171 | 172 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /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 | #ifndef _XBOX_VER 15 | #pragma pack(push) 16 | #pragma pack(8) 17 | #include 18 | #pragma pack (pop) 19 | 20 | extern "C" 21 | void _ReadWriteBarrier(); 22 | #pragma intrinsic(_ReadWriteBarrier) 23 | #endif 24 | 25 | // 26 | // Pipe class designed for use by at most two threads: one reader, one writer. 27 | // Access by more than two threads isn't guaranteed to be safe. 28 | // 29 | // In order to provide efficient access the size of the buffer is passed 30 | // as a template parameter and restricted to powers of two less than 31. 31 | // 32 | 33 | template class DXUTLockFreePipe 34 | { 35 | public: 36 | DXUTLockFreePipe() : m_readOffset(0), m_writeOffset(0) {} 37 | 38 | DWORD GetBufferSize() const { return c_cbBufferSize; } 39 | 40 | __forceinline unsigned long BytesAvailable() const 41 | { 42 | return m_writeOffset - m_readOffset; 43 | } 44 | 45 | bool __forceinline Read( void* pvDest, unsigned long cbDest ) 46 | { 47 | // Store the read and write offsets into local variables--this is 48 | // essentially a snapshot of their values so that they stay constant 49 | // for the duration of the function (and so we don't end up with cache 50 | // misses due to false sharing). 51 | DWORD readOffset = m_readOffset; 52 | DWORD writeOffset = m_writeOffset; 53 | 54 | // Compare the two offsets to see if we have anything to read. 55 | // Note that we don't do anything to synchronize the offsets here. 56 | // Really there's not much we *can* do unless we're willing to completely 57 | // synchronize access to the entire object. We have to assume that as we 58 | // read, someone else may be writing, and the write offset we have now 59 | // may be out of date by the time we read it. Fortunately that's not a 60 | // very big deal. We might miss reading some data that was just written. 61 | // But the assumption is that we'll be back before long to grab more data 62 | // anyway. 63 | // 64 | // Note that this comparison works because we're careful to constrain 65 | // the total buffer size to be a power of 2, which means it will divide 66 | // evenly into ULONG_MAX+1. That, and the fact that the offsets are 67 | // unsigned, means that the calculation returns correct results even 68 | // when the values wrap around. 69 | DWORD cbAvailable = writeOffset - readOffset; 70 | if( cbDest > cbAvailable ) 71 | { 72 | return false; 73 | } 74 | 75 | #ifdef _XBOX_VER 76 | // at this point, since we're still in this function, we've obviously 77 | // decided that there's enough data in the buffer for us to do this read. 78 | // But there's one complication: The data we're looking for might still 79 | // be moseying its way on up from the L2 cache. That's a problem, because 80 | // our CPU has no patience for moseying and would much rather load from 81 | // the L1 cache if the data is in there. And if it does that, we will be 82 | // sad because that data will be truly stale. To prevent that from happening, 83 | // we need to emit an lwsync--that'll cause the CPU to ensure that all 84 | // subsequent reads are accessing data that is at least as fresh (with 85 | // respect to the L2 cache, anyway) as any of the reads that were issued 86 | // before the lwsync. 87 | // 88 | // Technically this little dance is a "read-acquire." 89 | __lwsync(); 90 | #else 91 | // For x86 and x64, the only hazzard here is that the compiler reorders 92 | // the operations, so we make sure to tell the compiler not to do that 93 | _ReadWriteBarrier(); 94 | #endif 95 | 96 | unsigned char* pbDest = ( unsigned char* )pvDest; 97 | 98 | unsigned long actualReadOffset = readOffset & c_sizeMask; 99 | unsigned long bytesLeft = cbDest; 100 | 101 | // 102 | // Copy from the tail, then the head. Note that there's no explicit 103 | // check to see if the write offset comes between the read offset 104 | // and the end of the buffer--that particular condition is implicitly 105 | // checked by the comparison with AvailableToRead(), above. If copying 106 | // cbDest bytes off the tail would cause us to cross the write offset, 107 | // then the previous comparison would have failed since that would imply 108 | // that there were less than cbDest bytes available to read. 109 | // 110 | unsigned long cbTailBytes = min( bytesLeft, c_cbBufferSize - actualReadOffset ); 111 | #ifdef _XBOX_VER 112 | XMemCpy( pbDest, m_pbBuffer + actualReadOffset, cbTailBytes ); 113 | #else 114 | memcpy( pbDest, m_pbBuffer + actualReadOffset, cbTailBytes ); 115 | #endif 116 | bytesLeft -= cbTailBytes; 117 | 118 | if( bytesLeft ) 119 | { 120 | #ifdef _XBOX_VER 121 | XMemCpy( pbDest + cbTailBytes, m_pbBuffer, bytesLeft ); 122 | #else 123 | memcpy( pbDest + cbTailBytes, m_pbBuffer, bytesLeft ); 124 | #endif 125 | } 126 | 127 | // Advance the read offset. From the CPUs point of view this is several 128 | // operations--read, modify, store--and we'd normally want to make sure that 129 | // all of the operations happened atomically. But in the case of a single 130 | // reader, only one thread updates this value and so the only operation that 131 | // must be atomic is the store. That's lucky, because 32-bit aligned stores are 132 | // atomic on all modern processors. 133 | // 134 | readOffset += cbDest; 135 | m_readOffset = readOffset; 136 | 137 | return true; 138 | } 139 | 140 | bool __forceinline Write( const void* pvSrc, unsigned long cbSrc ) 141 | { 142 | // Reading the read offset here has the same caveats as reading 143 | // the write offset had in the Read() function above. 144 | DWORD readOffset = m_readOffset; 145 | DWORD writeOffset = m_writeOffset; 146 | 147 | // Compute the available write size. This comparison relies on 148 | // the fact that the buffer size is always a power of 2, and the 149 | // offsets are unsigned integers, so that when the write pointer 150 | // wraps around the subtraction still yields a value (assuming 151 | // we haven't messed up somewhere else) between 0 and c_cbBufferSize - 1. 152 | DWORD cbAvailable = c_cbBufferSize - ( writeOffset - readOffset ); 153 | if( cbSrc > cbAvailable ) 154 | { 155 | return false; 156 | } 157 | 158 | // Write the data 159 | const unsigned char* pbSrc = ( const unsigned char* )pvSrc; 160 | unsigned long actualWriteOffset = writeOffset & c_sizeMask; 161 | unsigned long bytesLeft = cbSrc; 162 | 163 | // See the explanation in the Read() function as to why we don't 164 | // explicitly check against the read offset here. 165 | unsigned long cbTailBytes = min( bytesLeft, c_cbBufferSize - actualWriteOffset ); 166 | #ifdef _XBOX_VER 167 | XMemCpy( m_pbBuffer + actualWriteOffset, pbSrc, cbTailBytes ); 168 | #else 169 | memcpy( m_pbBuffer + actualWriteOffset, pbSrc, cbTailBytes ); 170 | #endif 171 | bytesLeft -= cbTailBytes; 172 | 173 | if( bytesLeft ) 174 | { 175 | #ifdef _XBOX_VER 176 | XMemCpy( m_pbBuffer, pbSrc + cbTailBytes, bytesLeft ); 177 | #else 178 | memcpy( m_pbBuffer, pbSrc + cbTailBytes, bytesLeft ); 179 | #endif 180 | } 181 | 182 | #ifdef _XBOX_VER 183 | // Now it's time to update the write offset, but since the updated position 184 | // of the write offset will imply that there's data to be read, we need to 185 | // make sure that the data all actually gets written before the update to 186 | // the write offset makes it out into L2. The CPU doesn't guarantee the order 187 | // in which writes are performed once they leave this core, so it could 188 | // (and will) decide that it would be better to retire the write offset 189 | // update before finishing up the mem copies that we just asked for. That 190 | // would make us sad. The solution is to emit an lwsync here, which effectively 191 | // acts as a write barrier--it guarantees that all of the store instructions 192 | // issued before the sync are fully complete before any of the store instructions 193 | // issued after the sync are allowed to continue. 194 | // 195 | // If you want to get fancy, this is called "write-release." 196 | __lwsync(); 197 | #else 198 | // For x86 and x64, the only hazzard here is that the compiler reorders 199 | // the operations, so we make sure to tell the compiler not to do that 200 | _ReadWriteBarrier(); 201 | #endif 202 | 203 | // See comments in Read() as to why this operation isn't interlocked. 204 | writeOffset += cbSrc; 205 | m_writeOffset = writeOffset; 206 | 207 | return true; 208 | } 209 | 210 | private: 211 | // Values derived from the buffer size template parameter 212 | // 213 | const static BYTE c_cbBufferSizeLog2 = min( cbBufferSizeLog2, 31 ); 214 | const static DWORD c_cbBufferSize = ( 1 << c_cbBufferSizeLog2 ); 215 | const static DWORD c_sizeMask = c_cbBufferSize - 1; 216 | 217 | // Leave these undefined to prevent their use 218 | DXUTLockFreePipe( const DXUTLockFreePipe& ); 219 | DXUTLockFreePipe& operator =( const DXUTLockFreePipe& ); 220 | 221 | // Member data 222 | // 223 | BYTE m_pbBuffer[c_cbBufferSize]; 224 | volatile DWORD __declspec( align( 4 ) ) m_readOffset; 225 | volatile DWORD __declspec( align( 4 ) ) m_writeOffset; 226 | }; 227 | -------------------------------------------------------------------------------- /DXUT/optional/DXUTOptional_2005.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 9.00 2 | # Visual Studio 2005 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOptional", "DXUTOptional_2005.vcproj", "{E0CF097B-F22D-465B-A884-D89E55BD7ECD}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Release|Win32 = Release|Win32 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.ActiveCfg = Debug|Win32 12 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.Build.0 = Debug|Win32 13 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.ActiveCfg = Release|Win32 14 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.Build.0 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | EndGlobal 20 | -------------------------------------------------------------------------------- /DXUT/optional/DXUTOptional_2005.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 25 | 28 | 31 | 34 | 37 | 40 | 54 | 57 | 60 | 63 | 67 | 70 | 73 | 76 | 79 | 82 | 83 | 91 | 94 | 97 | 100 | 103 | 106 | 117 | 120 | 123 | 126 | 130 | 133 | 136 | 139 | 142 | 145 | 146 | 147 | 148 | 149 | 150 | 153 | 156 | 157 | 160 | 161 | 164 | 165 | 168 | 169 | 172 | 173 | 176 | 177 | 180 | 181 | 184 | 185 | 188 | 189 | 192 | 193 | 196 | 197 | 200 | 201 | 204 | 205 | 208 | 209 | 212 | 213 | 216 | 217 | 220 | 221 | 224 | 225 | 228 | 229 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | -------------------------------------------------------------------------------- /DXUT/optional/DXUTOptional_2008.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DXUTOptional", "DXUTOptional_2008.vcproj", "{E0CF097B-F22D-465B-A884-D89E55BD7ECD}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Release|Win32 = Release|Win32 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.ActiveCfg = Debug|Win32 12 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Debug|Win32.Build.0 = Debug|Win32 13 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.ActiveCfg = Release|Win32 14 | {E0CF097B-F22D-465B-A884-D89E55BD7ECD}.Release|Win32.Build.0 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | EndGlobal 20 | -------------------------------------------------------------------------------- /DXUT/optional/DXUTOptional_2008.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 26 | 29 | 32 | 35 | 38 | 41 | 55 | 58 | 61 | 64 | 68 | 71 | 74 | 77 | 80 | 83 | 84 | 92 | 95 | 98 | 101 | 104 | 107 | 118 | 121 | 124 | 127 | 131 | 134 | 137 | 140 | 143 | 146 | 147 | 148 | 149 | 150 | 151 | 154 | 157 | 158 | 161 | 162 | 165 | 166 | 169 | 170 | 173 | 174 | 177 | 178 | 181 | 182 | 185 | 186 | 189 | 190 | 193 | 194 | 197 | 198 | 201 | 202 | 205 | 206 | 209 | 210 | 213 | 214 | 217 | 218 | 221 | 222 | 225 | 226 | 229 | 230 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /DXUT/optional/DXUTsettingsdlg.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DXUTSettingsDlg.cpp 3 | // 4 | // Copyright (c) Microsoft Corporation. All rights reserved 5 | //-------------------------------------------------------------------------------------- 6 | #pragma once 7 | #ifndef DXUT_SETTINGS_H 8 | #define DXUT_SETTINGS_H 9 | 10 | //-------------------------------------------------------------------------------------- 11 | // Header Includes 12 | //-------------------------------------------------------------------------------------- 13 | #include "DXUTgui.h" 14 | 15 | //-------------------------------------------------------------------------------------- 16 | // Control IDs 17 | //-------------------------------------------------------------------------------------- 18 | #define DXUTSETTINGSDLG_STATIC -1 19 | #define DXUTSETTINGSDLG_OK 1 20 | #define DXUTSETTINGSDLG_CANCEL 2 21 | #define DXUTSETTINGSDLG_ADAPTER 3 22 | #define DXUTSETTINGSDLG_DEVICE_TYPE 4 23 | #define DXUTSETTINGSDLG_WINDOWED 5 24 | #define DXUTSETTINGSDLG_FULLSCREEN 6 25 | #define DXUTSETTINGSDLG_ADAPTER_FORMAT 7 26 | #define DXUTSETTINGSDLG_ADAPTER_FORMAT_LABEL 8 27 | #define DXUTSETTINGSDLG_RESOLUTION 9 28 | #define DXUTSETTINGSDLG_RESOLUTION_LABEL 10 29 | #define DXUTSETTINGSDLG_REFRESH_RATE 11 30 | #define DXUTSETTINGSDLG_REFRESH_RATE_LABEL 12 31 | #define DXUTSETTINGSDLG_BACK_BUFFER_FORMAT 13 32 | #define DXUTSETTINGSDLG_BACK_BUFFER_FORMAT_LABEL 14 33 | #define DXUTSETTINGSDLG_DEPTH_STENCIL 15 34 | #define DXUTSETTINGSDLG_DEPTH_STENCIL_LABEL 16 35 | #define DXUTSETTINGSDLG_MULTISAMPLE_TYPE 17 36 | #define DXUTSETTINGSDLG_MULTISAMPLE_TYPE_LABEL 18 37 | #define DXUTSETTINGSDLG_MULTISAMPLE_QUALITY 19 38 | #define DXUTSETTINGSDLG_MULTISAMPLE_QUALITY_LABEL 20 39 | #define DXUTSETTINGSDLG_VERTEX_PROCESSING 21 40 | #define DXUTSETTINGSDLG_VERTEX_PROCESSING_LABEL 22 41 | #define DXUTSETTINGSDLG_PRESENT_INTERVAL 23 42 | #define DXUTSETTINGSDLG_PRESENT_INTERVAL_LABEL 24 43 | #define DXUTSETTINGSDLG_DEVICECLIP 25 44 | #define DXUTSETTINGSDLG_RESOLUTION_SHOW_ALL 26 45 | #define DXUTSETTINGSDLG_API_VERSION 27 46 | #define DXUTSETTINGSDLG_D3D10_ADAPTER_OUTPUT 28 47 | #define DXUTSETTINGSDLG_D3D10_ADAPTER_OUTPUT_LABEL 29 48 | #define DXUTSETTINGSDLG_D3D10_RESOLUTION 30 49 | #define DXUTSETTINGSDLG_D3D10_RESOLUTION_LABEL 31 50 | #define DXUTSETTINGSDLG_D3D10_REFRESH_RATE 32 51 | #define DXUTSETTINGSDLG_D3D10_REFRESH_RATE_LABEL 33 52 | #define DXUTSETTINGSDLG_D3D10_BACK_BUFFER_FORMAT 34 53 | #define DXUTSETTINGSDLG_D3D10_BACK_BUFFER_FORMAT_LABEL 35 54 | #define DXUTSETTINGSDLG_D3D10_MULTISAMPLE_COUNT 36 55 | #define DXUTSETTINGSDLG_D3D10_MULTISAMPLE_COUNT_LABEL 37 56 | #define DXUTSETTINGSDLG_D3D10_MULTISAMPLE_QUALITY 38 57 | #define DXUTSETTINGSDLG_D3D10_MULTISAMPLE_QUALITY_LABEL 39 58 | #define DXUTSETTINGSDLG_D3D10_PRESENT_INTERVAL 40 59 | #define DXUTSETTINGSDLG_D3D10_PRESENT_INTERVAL_LABEL 41 60 | #define DXUTSETTINGSDLG_D3D10_DEBUG_DEVICE 42 61 | #define DXUTSETTINGSDLG_MODE_CHANGE_ACCEPT 43 62 | #define DXUTSETTINGSDLG_MODE_CHANGE_REVERT 44 63 | #define DXUTSETTINGSDLG_STATIC_MODE_CHANGE_TIMEOUT 45 64 | #define DXUTSETTINGSDLG_WINDOWED_GROUP 0x0100 65 | 66 | 67 | //-------------------------------------------------------------------------------------- 68 | // Dialog for selection of device settings 69 | // Use DXUTGetD3DSettingsDialog() to access global instance 70 | // To control the contents of the dialog, use the CD3D9Enumeration class. 71 | //-------------------------------------------------------------------------------------- 72 | class CD3DSettingsDlg 73 | { 74 | public: 75 | CD3DSettingsDlg(); 76 | ~CD3DSettingsDlg(); 77 | 78 | void Init( CDXUTDialogResourceManager* pManager ); 79 | void Init( CDXUTDialogResourceManager* pManager, LPCWSTR szControlTextureFileName ); 80 | void Init( CDXUTDialogResourceManager* pManager, LPCWSTR pszControlTextureResourcename, 81 | HMODULE hModule ); 82 | 83 | HRESULT Refresh(); 84 | void OnRender( float fElapsedTime ); 85 | void OnRender9( float fElapsedTime ); 86 | void OnRender10( float fElapsedTime ); 87 | 88 | HRESULT OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice ); 89 | HRESULT OnD3D9ResetDevice(); 90 | void OnD3D9LostDevice(); 91 | void OnD3D9DestroyDevice(); 92 | 93 | HRESULT OnD3D10CreateDevice( ID3D10Device* pd3dDevice ); 94 | HRESULT OnD3D10ResizedSwapChain( ID3D10Device* pd3dDevice, 95 | const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ); 96 | void OnD3D10DestroyDevice(); 97 | 98 | CDXUTDialog* GetDialogControl() 99 | { 100 | return &m_Dialog; 101 | } 102 | bool IsActive() 103 | { 104 | return m_bActive; 105 | } 106 | void SetActive( bool bActive ) 107 | { 108 | m_bActive = bActive; if( bActive ) Refresh(); 109 | } 110 | void ShowControlSet( DXUTDeviceVersion ver ); 111 | 112 | LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 113 | 114 | protected: 115 | friend CD3DSettingsDlg* WINAPI DXUTGetD3DSettingsDialog(); 116 | 117 | void CreateControls(); 118 | HRESULT SetDeviceSettingsFromUI(); 119 | void SetSelectedD3D10RefreshRate( DXGI_RATIONAL RefreshRate ); 120 | HRESULT UpdateD3D10Resolutions(); 121 | 122 | void OnEvent( UINT nEvent, int nControlID, CDXUTControl* pControl ); 123 | static void WINAPI StaticOnEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserData ); 124 | static void WINAPI StaticOnModeChangeTimer( UINT nIDEvent, void* pUserContext ); 125 | 126 | CD3D9EnumAdapterInfo* GetCurrentAdapterInfo(); 127 | CD3D9EnumDeviceInfo* GetCurrentDeviceInfo(); 128 | CD3D9EnumDeviceSettingsCombo* GetCurrentDeviceSettingsCombo(); 129 | CD3D10EnumAdapterInfo* GetCurrentD3D10AdapterInfo(); 130 | CD3D10EnumDeviceInfo* GetCurrentD3D10DeviceInfo(); 131 | CD3D10EnumOutputInfo* GetCurrentD3D10OutputInfo(); 132 | CD3D10EnumDeviceSettingsCombo* GetCurrentD3D10DeviceSettingsCombo(); 133 | 134 | void AddAPIVersion( DXUTDeviceVersion version ); 135 | DXUTDeviceVersion GetSelectedAPIVersion(); 136 | 137 | void AddAdapter( const WCHAR* strDescription, UINT iAdapter ); 138 | UINT GetSelectedAdapter(); 139 | 140 | void AddDeviceType( D3DDEVTYPE devType ); 141 | D3DDEVTYPE GetSelectedDeviceType(); 142 | 143 | void SetWindowed( bool bWindowed ); 144 | bool IsWindowed(); 145 | 146 | void AddAdapterFormat( D3DFORMAT format ); 147 | D3DFORMAT GetSelectedAdapterFormat(); 148 | 149 | void AddResolution( DWORD dwWidth, DWORD dwHeight ); 150 | void GetSelectedResolution( DWORD* pdwWidth, DWORD* pdwHeight ); 151 | 152 | void AddRefreshRate( DWORD dwRate ); 153 | DWORD GetSelectedRefreshRate(); 154 | 155 | void AddBackBufferFormat( D3DFORMAT format ); 156 | D3DFORMAT GetSelectedBackBufferFormat(); 157 | 158 | void AddDepthStencilBufferFormat( D3DFORMAT format ); 159 | D3DFORMAT GetSelectedDepthStencilBufferFormat(); 160 | 161 | void AddMultisampleType( D3DMULTISAMPLE_TYPE type ); 162 | D3DMULTISAMPLE_TYPE GetSelectedMultisampleType(); 163 | 164 | void AddMultisampleQuality( DWORD dwQuality ); 165 | DWORD GetSelectedMultisampleQuality(); 166 | 167 | void AddVertexProcessingType( DWORD dwType ); 168 | DWORD GetSelectedVertexProcessingType(); 169 | 170 | DWORD GetSelectedPresentInterval(); 171 | 172 | void SetDeviceClip( bool bDeviceClip ); 173 | bool IsDeviceClip(); 174 | 175 | // D3D10 176 | void AddD3D10DeviceType( D3D10_DRIVER_TYPE devType ); 177 | D3D10_DRIVER_TYPE GetSelectedD3D10DeviceType(); 178 | 179 | void AddD3D10AdapterOutput( const WCHAR* strName, UINT nOutput ); 180 | UINT GetSelectedD3D10AdapterOutput(); 181 | 182 | void AddD3D10Resolution( DWORD dwWidth, DWORD dwHeight ); 183 | void GetSelectedD3D10Resolution( DWORD* pdwWidth, DWORD* pdwHeight ); 184 | 185 | void AddD3D10RefreshRate( DXGI_RATIONAL RefreshRate ); 186 | DXGI_RATIONAL GetSelectedD3D10RefreshRate(); 187 | 188 | void AddD3D10BackBufferFormat( DXGI_FORMAT format ); 189 | DXGI_FORMAT GetSelectedD3D10BackBufferFormat(); 190 | 191 | void AddD3D10MultisampleCount( UINT count ); 192 | UINT GetSelectedD3D10MultisampleCount(); 193 | 194 | void AddD3D10MultisampleQuality( UINT Quality ); 195 | UINT GetSelectedD3D10MultisampleQuality(); 196 | 197 | DWORD GetSelectedD3D10PresentInterval(); 198 | bool GetSelectedDebugDeviceValue(); 199 | 200 | HRESULT OnAPIVersionChanged( bool bRefresh=false ); 201 | HRESULT OnAdapterChanged(); 202 | HRESULT OnDeviceTypeChanged(); 203 | HRESULT OnWindowedFullScreenChanged(); 204 | HRESULT OnAdapterOutputChanged(); 205 | HRESULT OnAdapterFormatChanged(); 206 | HRESULT OnResolutionChanged(); 207 | HRESULT OnD3D10ResolutionChanged(); 208 | HRESULT OnRefreshRateChanged(); 209 | HRESULT OnBackBufferFormatChanged(); 210 | HRESULT OnDepthStencilBufferFormatChanged(); 211 | HRESULT OnMultisampleTypeChanged(); 212 | HRESULT OnMultisampleQualityChanged(); 213 | HRESULT OnVertexProcessingChanged(); 214 | HRESULT OnPresentIntervalChanged(); 215 | HRESULT OnDebugDeviceChanged(); 216 | HRESULT OnDeviceClipChanged(); 217 | 218 | void UpdateModeChangeTimeoutText( int nSecRemaining ); 219 | 220 | IDirect3DStateBlock9* m_pStateBlock; 221 | ID3D10StateBlock* m_pStateBlock10; 222 | CDXUTDialog* m_pActiveDialog; 223 | CDXUTDialog m_Dialog; 224 | CDXUTDialog m_RevertModeDialog; 225 | int m_nRevertModeTimeout; 226 | UINT m_nIDEvent; 227 | bool m_bActive; 228 | }; 229 | 230 | 231 | CD3DSettingsDlg* WINAPI DXUTGetD3DSettingsDialog(); 232 | 233 | 234 | 235 | #endif 236 | 237 | -------------------------------------------------------------------------------- /DXUT/optional/IMesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | struct SDKMESH_CALLBACKS10; 3 | class IMesh // Interface class to toggle between SDK MEsh & .X meshes 4 | { 5 | public: 6 | virtual HRESULT Create( ID3D10Device *pDev10, LPCTSTR szFileName, D3D10_INPUT_ELEMENT_DESC* playout, UINT cElements, bool bOptimize=true ) {return S_OK;} 7 | virtual HRESULT Create( ID3D10Device *pDev10, LPCTSTR szFileName, bool bOptimize=true, bool bCreateAdjacencyIndices=false, SDKMESH_CALLBACKS10* pLoaderCallbacks=NULL ){return S_OK;} 8 | //Direct3D 10 Rendering 9 | virtual void Render( ID3D10Device *pd3dDevice, 10 | ID3D10EffectTechnique* pTechnique, 11 | ID3D10EffectShaderResourceVariable* ptxDiffuse = NULL, 12 | ID3D10EffectShaderResourceVariable* ptxNormal = NULL, 13 | ID3D10EffectShaderResourceVariable* ptxSpecular = NULL, 14 | ID3D10EffectVectorVariable* pvDiffuse = NULL, 15 | ID3D10EffectVectorVariable* pvSpecular = NULL ) = 0; 16 | virtual void Destroy ( ) = 0; 17 | 18 | }; 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /DXUT/optional/SDKmesh_old.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // File: SDKMesh.h 3 | // 4 | // Desc: Support code for loading DirectX .X files. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //----------------------------------------------------------------------------- 8 | #pragma once 9 | #ifndef SDKMESH_H 10 | #define SDKMESH_H 11 | 12 | 13 | //----------------------------------------------------------------------------- 14 | // Class for loading and rendering file-based meshes using D3D10 15 | //----------------------------------------------------------------------------- 16 | class CDXUTMesh10 17 | { 18 | public: 19 | ID3DX10Mesh* m_pMesh10; 20 | DWORD m_dwNumVerts; 21 | DWORD m_dwNumIndices; 22 | DWORD m_dwNumIndicesAdj; 23 | UINT m_uStride; 24 | D3DXMATERIAL *m_pMats; 25 | ID3D10Texture2D **m_ppTexture; 26 | ID3D10ShaderResourceView **m_ppSRV; 27 | DXGI_FORMAT m_IBFormat; 28 | D3DX10_ATTRIBUTE_RANGE *m_pAttr; 29 | UINT m_dwNumAttr; 30 | bool m_bDrawAdj; 31 | 32 | protected: 33 | void RenderSubset( ID3D10EffectTechnique *pTechnique, 34 | UINT pass, 35 | ID3D10EffectShaderResourceVariable* ptxDiffuse, 36 | ID3D10EffectVectorVariable* pvDiffuse, 37 | ID3D10EffectVectorVariable* pvSpecular, 38 | DWORD dwSubset ); 39 | void SetResources( ID3D10EffectShaderResourceVariable* ptxDiffuse, 40 | ID3D10EffectVectorVariable* pvDiffuse, 41 | ID3D10EffectVectorVariable* pvSpecular, 42 | DWORD dwSubset ); 43 | HRESULT CreateMesh( ID3D10Device *pDev10, LPCTSTR szFileName, VOID* pData, DWORD dwDataSizeInBytes, D3D10_INPUT_ELEMENT_DESC* playout, UINT cElements, bool bOptimize ); 44 | 45 | public: 46 | CDXUTMesh10(); 47 | ~CDXUTMesh10(); 48 | 49 | void ConvertToAdjacencyIndices(); 50 | HRESULT Create( ID3D10Device *pDev10, LPCTSTR szFileName, D3D10_INPUT_ELEMENT_DESC* playout, UINT cElements, bool bOptimize=true ); 51 | HRESULT CreateFromFileInMemory( ID3D10Device* pDev10, VOID* pData, DWORD dwDataSizeInBytes, D3D10_INPUT_ELEMENT_DESC* playout, UINT cElements, bool bOptimize=true ); 52 | void Destroy(); 53 | void Render( ID3D10Device *pDev ); 54 | void Render( ID3D10Device *pDev, 55 | ID3D10EffectTechnique *pTechnique, 56 | ID3D10EffectShaderResourceVariable* ptxDiffuse = NULL, 57 | ID3D10EffectVectorVariable* pvDiffuse = NULL, 58 | ID3D10EffectVectorVariable* pvSpecular = NULL, 59 | DWORD dwSubset = (DWORD)-1 ); 60 | void RenderInstanced( ID3D10Device *pDev, 61 | ID3D10EffectTechnique *pTechnique, 62 | UINT uiInstanceCount, 63 | ID3D10EffectShaderResourceVariable* ptxDiffuse = NULL, 64 | ID3D10EffectVectorVariable* pvDiffuse = NULL, 65 | ID3D10EffectVectorVariable* pvSpecular = NULL ); 66 | }; 67 | 68 | 69 | //----------------------------------------------------------------------------- 70 | // Class for loading and rendering file-based meshes using D3D9 71 | //----------------------------------------------------------------------------- 72 | class CDXUTMesh 73 | { 74 | public: 75 | WCHAR m_strName[512]; 76 | LPD3DXMESH m_pMesh; // Managed mesh 77 | 78 | // Cache of data in m_pMesh for easy access 79 | IDirect3DVertexBuffer9* m_pVB; 80 | IDirect3DIndexBuffer9* m_pIB; 81 | IDirect3DVertexDeclaration9* m_pDecl; 82 | DWORD m_dwNumVertices; 83 | DWORD m_dwNumFaces; 84 | DWORD m_dwBytesPerVertex; 85 | 86 | DWORD m_dwNumMaterials; // Materials for the mesh 87 | D3DMATERIAL9* m_pMaterials; 88 | CHAR (*m_strMaterials)[MAX_PATH]; 89 | IDirect3DBaseTexture9** m_pTextures; 90 | bool m_bUseMaterials; 91 | 92 | public: 93 | // Rendering 94 | HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice, 95 | bool bDrawOpaqueSubsets = true, 96 | bool bDrawAlphaSubsets = true ); 97 | HRESULT Render( ID3DXEffect *pEffect, 98 | D3DXHANDLE hTexture = NULL, 99 | D3DXHANDLE hDiffuse = NULL, 100 | D3DXHANDLE hAmbient = NULL, 101 | D3DXHANDLE hSpecular = NULL, 102 | D3DXHANDLE hEmissive = NULL, 103 | D3DXHANDLE hPower = NULL, 104 | bool bDrawOpaqueSubsets = true, 105 | bool bDrawAlphaSubsets = true ); 106 | 107 | // Mesh access 108 | LPD3DXMESH GetMesh() { return m_pMesh; } 109 | 110 | // Rendering options 111 | void UseMeshMaterials( bool bFlag ) { m_bUseMaterials = bFlag; } 112 | HRESULT SetFVF( LPDIRECT3DDEVICE9 pd3dDevice, DWORD dwFVF ); 113 | HRESULT SetVertexDecl( LPDIRECT3DDEVICE9 pd3dDevice, const D3DVERTEXELEMENT9 *pDecl, 114 | bool bAutoComputeNormals = true, bool bAutoComputeTangents = true, 115 | bool bSplitVertexForOptimalTangents = false ); 116 | 117 | // Initializing 118 | HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice ); 119 | HRESULT InvalidateDeviceObjects(); 120 | 121 | // Creation/destruction 122 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename ); 123 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData ); 124 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, ID3DXMesh* pInMesh, D3DXMATERIAL* pd3dxMaterials, DWORD dwMaterials ); 125 | HRESULT CreateMaterials( LPCWSTR strPath, IDirect3DDevice9 *pd3dDevice, D3DXMATERIAL* d3dxMtrls, DWORD dwNumMaterials ); 126 | HRESULT Destroy(); 127 | 128 | CDXUTMesh( LPCWSTR strName = L"CDXUTMeshFile_Mesh" ); 129 | virtual ~CDXUTMesh(); 130 | }; 131 | 132 | 133 | 134 | 135 | //----------------------------------------------------------------------------- 136 | // Class for loading and rendering file-based meshes 137 | //----------------------------------------------------------------------------- 138 | class CDXUTMeshFrame 139 | { 140 | public: 141 | WCHAR m_strName[512]; 142 | D3DXMATRIX m_mat; 143 | CDXUTMesh* m_pMesh; 144 | 145 | CDXUTMeshFrame* m_pNext; 146 | CDXUTMeshFrame* m_pChild; 147 | 148 | public: 149 | // Matrix access 150 | void SetMatrix( D3DXMATRIX* pmat ) { m_mat = *pmat; } 151 | D3DXMATRIX* GetMatrix() { return &m_mat; } 152 | 153 | CDXUTMesh* FindMesh( LPCWSTR strMeshName ); 154 | CDXUTMeshFrame* FindFrame( LPCWSTR strFrameName ); 155 | bool EnumMeshes( bool (*EnumMeshCB)(CDXUTMesh*,void*), 156 | void* pContext ); 157 | 158 | HRESULT Destroy(); 159 | HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice ); 160 | HRESULT InvalidateDeviceObjects(); 161 | HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice, 162 | bool bDrawOpaqueSubsets = true, 163 | bool bDrawAlphaSubsets = true, 164 | D3DXMATRIX* pmatWorldMatrix = NULL); 165 | 166 | CDXUTMeshFrame( LPCWSTR strName = L"CDXUTMeshFile_Frame" ); 167 | virtual ~CDXUTMeshFrame(); 168 | }; 169 | 170 | 171 | 172 | 173 | //----------------------------------------------------------------------------- 174 | // Class for loading and rendering file-based meshes 175 | //----------------------------------------------------------------------------- 176 | class CDXUTMeshFile : public CDXUTMeshFrame 177 | { 178 | HRESULT LoadMesh( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData, 179 | CDXUTMeshFrame* pParentFrame ); 180 | HRESULT LoadFrame( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData, 181 | CDXUTMeshFrame* pParentFrame ); 182 | public: 183 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename ); 184 | HRESULT CreateFromResource( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strResource, LPCWSTR strType ); 185 | // For pure devices, specify the world transform. If the world transform is not 186 | // specified on pure devices, this function will fail. 187 | HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice, D3DXMATRIX* pmatWorldMatrix = NULL ); 188 | 189 | CDXUTMeshFile() : CDXUTMeshFrame( L"CDXUTMeshFile_Root" ) {} 190 | }; 191 | 192 | 193 | #endif 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /DXUT/optional/directx.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/DXUT/optional/directx.ico -------------------------------------------------------------------------------- /DXUT/optional/rmxfguid.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * 3 | * Copyright (C) 1998-1999 Microsoft Corporation. All Rights Reserved. 4 | * 5 | * File: rmxfguid.h 6 | * 7 | * Content: Defines GUIDs of D3DRM's templates. 8 | * 9 | ***************************************************************************/ 10 | 11 | #ifndef __RMXFGUID_H_ 12 | #define __RMXFGUID_H_ 13 | 14 | /* {2B957100-9E9A-11cf-AB39-0020AF71E433} */ 15 | DEFINE_GUID(TID_D3DRMInfo, 16 | 0x2b957100, 0x9e9a, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 17 | 18 | /* {3D82AB44-62DA-11cf-AB39-0020AF71E433} */ 19 | DEFINE_GUID(TID_D3DRMMesh, 20 | 0x3d82ab44, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 21 | 22 | /* {3D82AB5E-62DA-11cf-AB39-0020AF71E433} */ 23 | DEFINE_GUID(TID_D3DRMVector, 24 | 0x3d82ab5e, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 25 | 26 | /* {3D82AB5F-62DA-11cf-AB39-0020AF71E433} */ 27 | DEFINE_GUID(TID_D3DRMMeshFace, 28 | 0x3d82ab5f, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 29 | 30 | /* {3D82AB4D-62DA-11cf-AB39-0020AF71E433} */ 31 | DEFINE_GUID(TID_D3DRMMaterial, 32 | 0x3d82ab4d, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 33 | 34 | /* {35FF44E1-6C7C-11cf-8F52-0040333594A3} */ 35 | DEFINE_GUID(TID_D3DRMMaterialArray, 36 | 0x35ff44e1, 0x6c7c, 0x11cf, 0x8F, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 37 | 38 | /* {3D82AB46-62DA-11cf-AB39-0020AF71E433} */ 39 | DEFINE_GUID(TID_D3DRMFrame, 40 | 0x3d82ab46, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 41 | 42 | /* {F6F23F41-7686-11cf-8F52-0040333594A3} */ 43 | DEFINE_GUID(TID_D3DRMFrameTransformMatrix, 44 | 0xf6f23f41, 0x7686, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 45 | 46 | /* {F6F23F42-7686-11cf-8F52-0040333594A3} */ 47 | DEFINE_GUID(TID_D3DRMMeshMaterialList, 48 | 0xf6f23f42, 0x7686, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 49 | 50 | /* {F6F23F40-7686-11cf-8F52-0040333594A3} */ 51 | DEFINE_GUID(TID_D3DRMMeshTextureCoords, 52 | 0xf6f23f40, 0x7686, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 53 | 54 | /* {F6F23F43-7686-11cf-8F52-0040333594A3} */ 55 | DEFINE_GUID(TID_D3DRMMeshNormals, 56 | 0xf6f23f43, 0x7686, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 57 | 58 | /* {F6F23F44-7686-11cf-8F52-0040333594A3} */ 59 | DEFINE_GUID(TID_D3DRMCoords2d, 60 | 0xf6f23f44, 0x7686, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 61 | 62 | /* {F6F23F45-7686-11cf-8F52-0040333594A3} */ 63 | DEFINE_GUID(TID_D3DRMMatrix4x4, 64 | 0xf6f23f45, 0x7686, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 65 | 66 | /* {3D82AB4F-62DA-11cf-AB39-0020AF71E433} */ 67 | DEFINE_GUID(TID_D3DRMAnimation, 68 | 0x3d82ab4f, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 69 | 70 | /* {3D82AB50-62DA-11cf-AB39-0020AF71E433} */ 71 | DEFINE_GUID(TID_D3DRMAnimationSet, 72 | 0x3d82ab50, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 73 | 74 | /* {10DD46A8-775B-11cf-8F52-0040333594A3} */ 75 | DEFINE_GUID(TID_D3DRMAnimationKey, 76 | 0x10dd46a8, 0x775b, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xA3); 77 | 78 | /* {10DD46A9-775B-11cf-8F52-0040333594A3} */ 79 | DEFINE_GUID(TID_D3DRMFloatKeys, 80 | 0x10dd46a9, 0x775b, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xA3); 81 | 82 | /* {01411840-7786-11cf-8F52-0040333594A3} */ 83 | DEFINE_GUID(TID_D3DRMMaterialAmbientColor, 84 | 0x01411840, 0x7786, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xA3); 85 | 86 | /* {01411841-7786-11cf-8F52-0040333594A3} */ 87 | DEFINE_GUID(TID_D3DRMMaterialDiffuseColor, 88 | 0x01411841, 0x7786, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xA3); 89 | 90 | /* {01411842-7786-11cf-8F52-0040333594A3} */ 91 | DEFINE_GUID(TID_D3DRMMaterialSpecularColor, 92 | 0x01411842, 0x7786, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xA3); 93 | 94 | /* {D3E16E80-7835-11cf-8F52-0040333594A3} */ 95 | DEFINE_GUID(TID_D3DRMMaterialEmissiveColor, 96 | 0xd3e16e80, 0x7835, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 97 | 98 | /* {01411843-7786-11cf-8F52-0040333594A3} */ 99 | DEFINE_GUID(TID_D3DRMMaterialPower, 100 | 0x01411843, 0x7786, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xA3); 101 | 102 | /* {35FF44E0-6C7C-11cf-8F52-0040333594A3} */ 103 | DEFINE_GUID(TID_D3DRMColorRGBA, 104 | 0x35ff44e0, 0x6c7c, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xA3); 105 | 106 | /* {D3E16E81-7835-11cf-8F52-0040333594A3} */ 107 | DEFINE_GUID(TID_D3DRMColorRGB, 108 | 0xd3e16e81, 0x7835, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 109 | 110 | /* {A42790E0-7810-11cf-8F52-0040333594A3} */ 111 | DEFINE_GUID(TID_D3DRMGuid, 112 | 0xa42790e0, 0x7810, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 113 | 114 | /* {A42790E1-7810-11cf-8F52-0040333594A3} */ 115 | DEFINE_GUID(TID_D3DRMTextureFilename, 116 | 0xa42790e1, 0x7810, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 117 | 118 | /* {A42790E2-7810-11cf-8F52-0040333594A3} */ 119 | DEFINE_GUID(TID_D3DRMTextureReference, 120 | 0xa42790e2, 0x7810, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 121 | 122 | /* {1630B820-7842-11cf-8F52-0040333594A3} */ 123 | DEFINE_GUID(TID_D3DRMIndexedColor, 124 | 0x1630b820, 0x7842, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 125 | 126 | /* {1630B821-7842-11cf-8F52-0040333594A3} */ 127 | DEFINE_GUID(TID_D3DRMMeshVertexColors, 128 | 0x1630b821, 0x7842, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 129 | 130 | /* {4885AE60-78E8-11cf-8F52-0040333594A3} */ 131 | DEFINE_GUID(TID_D3DRMMaterialWrap, 132 | 0x4885ae60, 0x78e8, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 133 | 134 | /* {537DA6A0-CA37-11d0-941C-0080C80CFA7B} */ 135 | DEFINE_GUID(TID_D3DRMBoolean, 136 | 0x537da6a0, 0xca37, 0x11d0, 0x94, 0x1c, 0x0, 0x80, 0xc8, 0xc, 0xfa, 0x7b); 137 | 138 | /* {ED1EC5C0-C0A8-11d0-941C-0080C80CFA7B} */ 139 | DEFINE_GUID(TID_D3DRMMeshFaceWraps, 140 | 0xed1ec5c0, 0xc0a8, 0x11d0, 0x94, 0x1c, 0x0, 0x80, 0xc8, 0xc, 0xfa, 0x7b); 141 | 142 | /* {4885AE63-78E8-11cf-8F52-0040333594A3} */ 143 | DEFINE_GUID(TID_D3DRMBoolean2d, 144 | 0x4885ae63, 0x78e8, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 145 | 146 | /* {F406B180-7B3B-11cf-8F52-0040333594A3} */ 147 | DEFINE_GUID(TID_D3DRMTimedFloatKeys, 148 | 0xf406b180, 0x7b3b, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 149 | 150 | /* {E2BF56C0-840F-11cf-8F52-0040333594A3} */ 151 | DEFINE_GUID(TID_D3DRMAnimationOptions, 152 | 0xe2bf56c0, 0x840f, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 153 | 154 | /* {E2BF56C1-840F-11cf-8F52-0040333594A3} */ 155 | DEFINE_GUID(TID_D3DRMFramePosition, 156 | 0xe2bf56c1, 0x840f, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 157 | 158 | /* {E2BF56C2-840F-11cf-8F52-0040333594A3} */ 159 | DEFINE_GUID(TID_D3DRMFrameVelocity, 160 | 0xe2bf56c2, 0x840f, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 161 | 162 | /* {E2BF56C3-840F-11cf-8F52-0040333594A3} */ 163 | DEFINE_GUID(TID_D3DRMFrameRotation, 164 | 0xe2bf56c3, 0x840f, 0x11cf, 0x8f, 0x52, 0x0, 0x40, 0x33, 0x35, 0x94, 0xa3); 165 | 166 | /* {3D82AB4A-62DA-11cf-AB39-0020AF71E433} */ 167 | DEFINE_GUID(TID_D3DRMLight, 168 | 0x3d82ab4a, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 169 | 170 | /* {3D82AB51-62DA-11cf-AB39-0020AF71E433} */ 171 | DEFINE_GUID(TID_D3DRMCamera, 172 | 0x3d82ab51, 0x62da, 0x11cf, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 173 | 174 | /* {E5745280-B24F-11cf-9DD5-00AA00A71A2F} */ 175 | DEFINE_GUID(TID_D3DRMAppData, 176 | 0xe5745280, 0xb24f, 0x11cf, 0x9d, 0xd5, 0x0, 0xaa, 0x0, 0xa7, 0x1a, 0x2f); 177 | 178 | /* {AED22740-B31F-11cf-9DD5-00AA00A71A2F} */ 179 | DEFINE_GUID(TID_D3DRMLightUmbra, 180 | 0xaed22740, 0xb31f, 0x11cf, 0x9d, 0xd5, 0x0, 0xaa, 0x0, 0xa7, 0x1a, 0x2f); 181 | 182 | /* {AED22742-B31F-11cf-9DD5-00AA00A71A2F} */ 183 | DEFINE_GUID(TID_D3DRMLightRange, 184 | 0xaed22742, 0xb31f, 0x11cf, 0x9d, 0xd5, 0x0, 0xaa, 0x0, 0xa7, 0x1a, 0x2f); 185 | 186 | /* {AED22741-B31F-11cf-9DD5-00AA00A71A2F} */ 187 | DEFINE_GUID(TID_D3DRMLightPenumbra, 188 | 0xaed22741, 0xb31f, 0x11cf, 0x9d, 0xd5, 0x0, 0xaa, 0x0, 0xa7, 0x1a, 0x2f); 189 | 190 | /* {A8A98BA0-C5E5-11cf-B941-0080C80CFA7B} */ 191 | DEFINE_GUID(TID_D3DRMLightAttenuation, 192 | 0xa8a98ba0, 0xc5e5, 0x11cf, 0xb9, 0x41, 0x0, 0x80, 0xc8, 0xc, 0xfa, 0x7b); 193 | 194 | /* {3A23EEA0-94B1-11d0-AB39-0020AF71E433} */ 195 | DEFINE_GUID(TID_D3DRMInlineData, 196 | 0x3a23eea0, 0x94b1, 0x11d0, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 197 | 198 | /* {3A23EEA1-94B1-11d0-AB39-0020AF71E433} */ 199 | DEFINE_GUID(TID_D3DRMUrl, 200 | 0x3a23eea1, 0x94b1, 0x11d0, 0xab, 0x39, 0x0, 0x20, 0xaf, 0x71, 0xe4, 0x33); 201 | 202 | /* {8A63C360-997D-11d0-941C-0080C80CFA7B} */ 203 | DEFINE_GUID(TID_D3DRMProgressiveMesh, 204 | 0x8A63C360, 0x997D, 0x11d0, 0x94, 0x1C, 0x0, 0x80, 0xC8, 0x0C, 0xFA, 0x7B); 205 | 206 | /* {98116AA0-BDBA-11d1-82C0-00A0C9697271} */ 207 | DEFINE_GUID(TID_D3DRMExternalVisual, 208 | 0x98116AA0, 0xBDBA, 0x11d1, 0x82, 0xC0, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x71); 209 | 210 | /* {7F0F21E0-BFE1-11d1-82C0-00A0C9697271} */ 211 | DEFINE_GUID(TID_D3DRMStringProperty, 212 | 0x7f0f21e0, 0xbfe1, 0x11d1, 0x82, 0xc0, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x71); 213 | 214 | /* {7F0F21E1-BFE1-11d1-82C0-00A0C9697271} */ 215 | DEFINE_GUID(TID_D3DRMPropertyBag, 216 | 0x7f0f21e1, 0xbfe1, 0x11d1, 0x82, 0xc0, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x71); 217 | 218 | // {7F5D5EA0-D53A-11d1-82C0-00A0C9697271} 219 | DEFINE_GUID(TID_D3DRMRightHanded, 220 | 0x7f5d5ea0, 0xd53a, 0x11d1, 0x82, 0xc0, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x71); 221 | 222 | #endif /* __RMXFGUID_H_ */ 223 | 224 | -------------------------------------------------------------------------------- /FrameWork/CModel.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "DXUTmisc.h" 9 | #include "SDKmisc.h" 10 | #include "SDKmesh.h" 11 | 12 | #include "CModel.h" 13 | 14 | /* 15 | HRESULT CModel::LoadFromFile( ID3D10Device* pd3dDevice, WCHAR* fileName, ID3D10EffectTechnique* pTechnique, 16 | const D3D10_INPUT_ELEMENT_DESC* pLayout, UINT numElements ) 17 | { 18 | 19 | HRESULT hr; 20 | // Load the mesh from the specified file 21 | if(fname) 22 | { 23 | Destroy(); 24 | } 25 | fname = new WCHAR[MAX_PATH]; 26 | StringCchCopyW(fname, MAX_PATH,fileName); 27 | 28 | // Create the input layout 29 | D3D10_PASS_DESC PassDesc; 30 | pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc ); 31 | V_RETURN( pd3dDevice->CreateInputLayout( pLayout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pVertexLayout ) ); 32 | 33 | // Set the input layout 34 | pd3dDevice->IASetInputLayout( m_pVertexLayout ); 35 | // Load the mesh 36 | V_RETURN( m_mesh.Create( pd3dDevice, fname, true ) ); 37 | return S_OK; 38 | } 39 | 40 | template 41 | void CModel::Destroy() 42 | { 43 | delete(fname); 44 | fname = NULL; 45 | SAFE_RELEASE( m_pVertexLayout ); 46 | m_mesh.Destroy(); 47 | 48 | } 49 | */ 50 | //m_mesh.Render( pd3dDevice, g_pTechnique, g_ptxDiffuseVariable ); 51 | 52 | //template 53 | //void CModel::Render( ID3D10Device* pd3dDevice, ID3D10EffectTechnique* pTechnique, ID3D10EffectShaderResourceVariable* ptxDiffuseVariable ) 54 | //{ 55 | // pd3dDevice->IASetInputLayout( m_pVertexLayout ); 56 | // m_mesh.Render( pd3dDevice, pTechnique, ptxDiffuseVariable ); 57 | /* 58 | #ifdef SDKMESH 59 | // aModel.Render( pd3dDevice, g_pTechnique ); 60 | // 61 | // Render the mesh 62 | // 63 | UINT Strides[1]; 64 | UINT Offsets[1]; 65 | ID3D10Buffer* pVB[1]; 66 | pVB[0] = m_mesh.GetVB10(0,0); 67 | Strides[0] = (UINT)m_mesh.GetVertexStride(0,0); 68 | Offsets[0] = 0; 69 | pd3dDevice->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets ); 70 | pd3dDevice->IASetIndexBuffer( m_mesh.GetIB10(0), m_mesh.GetIBFormat10(0), 0 ); 71 | 72 | D3D10_TECHNIQUE_DESC techDesc; 73 | pTechnique->GetDesc( &techDesc ); 74 | SDKMESH_SUBSET* pSubset = NULL; 75 | ID3D10ShaderResourceView* pDiffuseRV = NULL; 76 | D3D10_PRIMITIVE_TOPOLOGY PrimType; 77 | 78 | for( UINT p = 0; p < techDesc.Passes; ++p ) 79 | { 80 | for( UINT subset = 0; subset < m_mesh.GetNumSubsets(0); ++subset ) 81 | { 82 | pSubset = m_mesh.GetSubset( 0,subset ); 83 | 84 | PrimType = m_mesh.GetPrimitiveType10( (SDKMESH_PRIMITIVE_TYPE)pSubset->PrimitiveType ); 85 | pd3dDevice->IASetPrimitiveTopology( PrimType ); 86 | 87 | pDiffuseRV = m_mesh.GetMaterial(pSubset->MaterialID)->pDiffuseRV10; 88 | ptxDiffuseVariable->SetResource( pDiffuseRV ); 89 | 90 | pTechnique->GetPassByIndex( p )->Apply(0); 91 | pd3dDevice->DrawIndexed( (UINT)pSubset->IndexCount, 0, (UINT)pSubset->VertexStart ); 92 | } 93 | } 94 | #endif 95 | */ 96 | //} 97 | -------------------------------------------------------------------------------- /FrameWork/CModel.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #ifndef _CMODEL_ 8 | #define _CMODEL_ 9 | 10 | #include "SDKmesh.h" 11 | #include "SDKmesh_old.h" 12 | 13 | //#pragma warning ( disable : 4995 ) //get rid of the anoying deprecation warnings 14 | //#include 15 | 16 | //#define SDKMESH 17 | 18 | // Define the input layout 19 | const D3D10_INPUT_ELEMENT_DESC default_layout[] = 20 | { 21 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 22 | { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 23 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 24 | }; 25 | const unsigned int numDefaultElements = sizeof(default_layout)/sizeof(D3D10_INPUT_ELEMENT_DESC); 26 | 27 | template 28 | class CModel 29 | { 30 | 31 | public: 32 | WCHAR* fname; 33 | DWORD id; 34 | 35 | T m_mesh; 36 | // CDXUTMesh10 m_mesh; 37 | // CDXUTSDKMesh m_mesh; 38 | D3DXVECTOR3 m_bvCenter; 39 | float m_bvRadius; 40 | D3DXMATRIX m_world; 41 | //CBoundingVolume bbox; 42 | ID3D10InputLayout* m_pVertexLayout; 43 | 44 | CModel():fname(NULL){}; 45 | 46 | ~CModel() { Destroy(); } 47 | 48 | D3DXMATRIX* GetMatrix ( ); 49 | void SetMatrix ( ){}; 50 | HRESULT LoadFromFile( ID3D10Device* pd3dDevice, WCHAR* fileName, ID3D10EffectTechnique* pTechnique, 51 | const D3D10_INPUT_ELEMENT_DESC* pLayout = default_layout, 52 | UINT numElements = numDefaultElements ) 53 | { 54 | HRESULT hr; 55 | // Load the mesh from the specified file 56 | if(fname) 57 | { 58 | Destroy(); 59 | } 60 | fname = new WCHAR[MAX_PATH]; 61 | StringCchCopyW(fname, MAX_PATH,fileName); 62 | 63 | // Create the input layout 64 | D3D10_PASS_DESC PassDesc; 65 | pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc ); 66 | V_RETURN( pd3dDevice->CreateInputLayout( pLayout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pVertexLayout ) ); 67 | // Set the input layout 68 | pd3dDevice->IASetInputLayout( m_pVertexLayout ); 69 | // ANU TO DO toggle based on extension or specialazation 70 | // std::wstring str(fname); 71 | V_RETURN( m_mesh.Create( pd3dDevice,fname, (D3D10_INPUT_ELEMENT_DESC*)pLayout, numElements, true )); 72 | // V_RETURN( m_mesh.Create( pd3dDevice, fname, true ) ); 73 | 74 | return S_OK; 75 | } 76 | void Render ( ID3D10Device* pd3dDevice, ID3D10EffectTechnique* pTechnique, ID3D10EffectShaderResourceVariable* ptxDiffuseVariable ) 77 | { 78 | pd3dDevice->IASetInputLayout( m_pVertexLayout ); 79 | m_mesh.Render( pd3dDevice, pTechnique, ptxDiffuseVariable ); 80 | } 81 | 82 | void Destroy ( ) 83 | { 84 | delete(fname); 85 | fname = NULL; 86 | SAFE_RELEASE( m_pVertexLayout ); 87 | m_mesh.Destroy(); 88 | }; 89 | //HRESULT GenerateSphere(LPDIRECT3DDEVICE9 pd3dDevice, int radius, int slices, int stacks); 90 | // GetBoundingBox(); 91 | }; 92 | 93 | HRESULT CModel::LoadFromFile( ID3D10Device* pd3dDevice, WCHAR* fileName, ID3D10EffectTechnique* pTechnique, 94 | const D3D10_INPUT_ELEMENT_DESC* pLayout, UINT numElements ) 95 | { 96 | 97 | HRESULT hr; 98 | // Load the mesh from the specified file 99 | if(fname) 100 | { 101 | Destroy(); 102 | } 103 | fname = new WCHAR[MAX_PATH]; 104 | StringCchCopyW(fname, MAX_PATH,fileName); 105 | 106 | // Create the input layout 107 | D3D10_PASS_DESC PassDesc; 108 | pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc ); 109 | V_RETURN( pd3dDevice->CreateInputLayout( pLayout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pVertexLayout ) ); 110 | 111 | // Set the input layout 112 | pd3dDevice->IASetInputLayout( m_pVertexLayout ); 113 | // Load the mesh 114 | V_RETURN( m_mesh.Create( pd3dDevice, fname, true ) ); 115 | return S_OK; 116 | } 117 | 118 | #endif -------------------------------------------------------------------------------- /FrameWork/DX10Base.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "DXUTgui.h" 9 | #include "DXUTsettingsdlg.h" 10 | #include "SDKmisc.h" 11 | 12 | #include "DX10Base.h" 13 | #include "DX10BaseHelper.h" 14 | #include "GrassUIState.h" 15 | #ifdef ALT_CAMERA 16 | #include "camera.h" 17 | #else 18 | #include "DXUTcamera.h" 19 | #endif // ALT_CAMERA 20 | 21 | 22 | extern CD3DSettingsDlg g_D3DSettingsDlg; 23 | bool SphereConeTest ( D3DXVECTOR3 sphereCenter, float radius, float fov, D3DXVECTOR3 eyePt, D3DXVECTOR3 lookAt); 24 | 25 | 26 | int DX10Base::Run() 27 | { 28 | DXUTSetCallbackD3D10DeviceAcceptable( &DX10BaseHelper::IsDeviceAcceptable, this ); 29 | DXUTSetCallbackD3D10DeviceCreated( &DX10BaseHelper::OnCreateDevice, this ); 30 | DXUTSetCallbackD3D10SwapChainResized( &DX10BaseHelper::OnResizedSwapChain, this ); 31 | DXUTSetCallbackD3D10SwapChainReleasing( &DX10BaseHelper::OnReleasingSwapChain, this ); 32 | DXUTSetCallbackD3D10DeviceDestroyed( &DX10BaseHelper::OnDestroyDevice, this ); 33 | DXUTSetCallbackD3D10FrameRender( &DX10BaseHelper::OnFrameRender, this ); 34 | DXUTSetCallbackMsgProc( &DX10BaseHelper::MsgProc, this ); 35 | DXUTSetCallbackKeyboard( &DX10BaseHelper::KeyboardProc, this ); 36 | DXUTSetCallbackFrameMove( &DX10BaseHelper::OnFrameMove, this ); 37 | DXUTSetCallbackDeviceChanging( &DX10BaseHelper::ModifyDeviceSettings, this ); 38 | DXUTSetCallbackDeviceRemoved( &DX10BaseHelper::OnDeviceRemoved, this ); 39 | InitApp(); 40 | DXUTInit( true, true, NULL ); // Parse the command line, show msgboxes on error, no extra command line params 41 | DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen 42 | DXUTCreateWindow( L"Grass" ); 43 | // TODO::Anu replace height/width with XML parsed data. 44 | DXUTCreateDevice( true, 800, 600 ); 45 | DXUTMainLoop(); // Enter into the DXUT render loop 46 | 47 | return DXUTGetExitCode(); 48 | 49 | } 50 | 51 | void DX10Base::InitApp() 52 | { 53 | m_UI.Init(); 54 | pSkybox = 0; 55 | m_MSAASampleCount = 1; 56 | #ifndef ALT_CAMERA 57 | m_pCamera = new CModelViewerCamera(); 58 | #endif 59 | // m_pCamera->SetRotateButtons( true, false, false ); 60 | 61 | } 62 | //-------------------------------------------------------------------------------------- 63 | // Reject any D3D10 devices that aren't acceptable by returning false 64 | //-------------------------------------------------------------------------------------- 65 | bool CALLBACK DX10Base::IsDeviceAcceptable( UINT Adapter, UINT Output, D3D10_DRIVER_TYPE DeviceType, DXGI_FORMAT BackBufferFormat, bool bWindowed ) 66 | { 67 | // No CAPS for DX10 devices :) 68 | return true; 69 | } 70 | 71 | 72 | //-------------------------------------------------------------------------------------- 73 | // Called right before creating a D3D9 or D3D10 device, allowing the app to modify the device settings as needed 74 | //-------------------------------------------------------------------------------------- 75 | bool CALLBACK DX10Base::ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings ) 76 | { 77 | // Turn vsync and debug device off 78 | pDeviceSettings->d3d10.SyncInterval = 0; 79 | #ifndef DEBUG 80 | pDeviceSettings->d3d10.CreateFlags &= ~D3D10_CREATE_DEVICE_DEBUG; 81 | #endif 82 | 83 | // For the first device created if its a REF device, optionally display a warning dialog box 84 | static bool s_bFirstTime = true; 85 | if( s_bFirstTime ) 86 | { 87 | s_bFirstTime = false; 88 | if( ( pDeviceSettings->ver == DXUT_D3D10_DEVICE) && (pDeviceSettings->d3d10.DriverType == D3D10_DRIVER_TYPE_REFERENCE )) 89 | DXUTDisplaySwitchingToREFWarning( pDeviceSettings->ver ); 90 | } 91 | 92 | return true; 93 | } 94 | 95 | 96 | //-------------------------------------------------------------------------------------- 97 | // Create any D3D10 resources that aren't dependant on the back buffer 98 | //-------------------------------------------------------------------------------------- 99 | HRESULT CALLBACK DX10Base::OnCreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ) 100 | { 101 | 102 | HRESULT hr; 103 | m_UI.Create(pd3dDevice); 104 | m_ptxDiffuse = NULL; 105 | //m_bShowHelp = TRUE; 106 | // Read the D3DX effect file doing basic T&L 107 | WCHAR str[MAX_PATH]; 108 | V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"fx//BasicTNL.fx" ) ); 109 | 110 | DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; 111 | 112 | #if defined( DEBUG ) || defined( _DEBUG ) 113 | dwShaderFlags |= D3D10_SHADER_DEBUG; 114 | // dwShaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; 115 | #endif 116 | 117 | V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, 118 | pd3dDevice, NULL, NULL, &m_pEffect, NULL, NULL ) ); 119 | 120 | m_pfxWorld = m_pEffect->GetVariableByName( "World" )->AsMatrix(); 121 | m_pfxView = m_pEffect->GetVariableByName( "View" )->AsMatrix(); 122 | m_pfxProj = m_pEffect->GetVariableByName( "Projection" )->AsMatrix(); 123 | m_fTimeVar = m_pEffect->GetVariableByName( "g_fTime" )->AsScalar(); 124 | 125 | m_ptxDiffuse = m_pEffect->GetVariableByName( "txDiffuse" )->AsShaderResource(); 126 | 127 | #ifdef ALT_CAMERA 128 | D3DXVECTOR3 pos(5.0f, 5.5f, -27.5f); 129 | 130 | m_pCamera = new camera( pos, // Position Vector 131 | -0.14f,-6.12f,0, // Rotation x,y,z 132 | 45,1.33f, // FOV, AspectRatio 133 | 0.3f,500.0f // Z - near, far 134 | ); 135 | #else 136 | D3DXVECTOR3 vecEye(0.0f, 10.0f, -40.0f); 137 | D3DXVECTOR3 vecAt (2.0f, 4.0f, -5.0f); 138 | m_pCamera->SetViewParams( &vecEye, &vecAt ); 139 | // Setup the camera's view parameters 140 | //D3DXQUATERNION quatRotation; 141 | //D3DXQuaternionRotationYawPitchRoll( &quatRotation, -0.5f, 0.7f, 0.0f ); 142 | //m_pCamera->SetWorldQuat( quatRotation ); 143 | 144 | #endif // ALT_CAMERA 145 | 146 | 147 | m_bCleanUp = TRUE; 148 | D3DXMatrixIdentity(&m_World); 149 | GetMaxMSAASampleCount( pd3dDevice, pBackBufferSurfaceDesc->Format ); 150 | 151 | return S_OK; 152 | } 153 | 154 | void CALLBACK DX10Base::OnGUIEvent(UINT nEvent, int nControlID, CDXUTControl *pControl, void* pUserContext ) 155 | { 156 | m_UI.OnGUIEvent(nEvent, nControlID, pControl, pUserContext); 157 | } 158 | 159 | //-------------------------------------------------------------------------------------- 160 | // Handle updates to the scene. This is called regardless of which D3D API is used 161 | //-------------------------------------------------------------------------------------- 162 | void CALLBACK DX10Base::OnFrameMove( double fTime, float fElapsedTime ) 163 | { 164 | 165 | m_fTime = (float)fTime; 166 | m_fTimeVar->SetFloat(m_fTime); 167 | #ifndef ALT_CAMERA 168 | // Update the camera's position based on user input 169 | m_pCamera->FrameMove( fElapsedTime ); 170 | #else 171 | //if( m_UI.GUICalled ) 172 | // m_Mouse.Ldragging = false; 173 | 174 | // Update the camera movement 175 | float fspeed = 0.00004f; 176 | 177 | if (m_Mouse.Ldragging) 178 | { 179 | m_pCamera->rotx -= fspeed*(m_Mouse.y - m_Mouse.start_y); 180 | m_pCamera->roty -= fspeed*(m_Mouse.x - m_Mouse.start_x); 181 | } 182 | if (m_Mouse.Rdragging) 183 | { 184 | m_pCamera->position += 5 * fspeed * (m_Mouse.x - m_Mouse.start_x) * m_pCamera->right; 185 | m_pCamera->position -= 5 * fspeed * (m_Mouse.y - m_Mouse.start_y) * m_pCamera->up; 186 | } 187 | if (m_Mouse.Mdragging) 188 | { 189 | m_pCamera->position -= 10 * fspeed * (m_Mouse.y - m_Mouse.start_y) * m_pCamera->forward; 190 | } 191 | 192 | fspeed = 0.125f; 193 | if (KEY_DOWN(VK_SHIFT)) 194 | fspeed = 0.25f; 195 | if (KEY_DOWN(VK_LCONTROL)) 196 | fspeed = 0.005f; 197 | 198 | if (KEY_DOWN(0x57)) // W 199 | m_pCamera->position += m_pCamera->forward*fspeed; 200 | if (KEY_DOWN(0x53)) // S 201 | m_pCamera->position -= m_pCamera->forward*fspeed; 202 | if (KEY_DOWN(0x41)) // A 203 | m_pCamera->position -= m_pCamera->right*fspeed; 204 | if (KEY_DOWN(0x44)) // D 205 | m_pCamera->position += m_pCamera->right*fspeed; 206 | 207 | m_pCamera->update(); 208 | #endif // ALT_CAMERA 209 | 210 | 211 | 212 | 213 | } 214 | 215 | 216 | //-------------------------------------------------------------------------------------- 217 | // Render the scene using the D3D10 device 218 | //-------------------------------------------------------------------------------------- 219 | void CALLBACK DX10Base::OnFrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime ) 220 | { 221 | 222 | // // Clear render target and the depth stencil 223 | float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; 224 | pd3dDevice->ClearRenderTargetView( DXUTGetD3D10RenderTargetView(), ClearColor ); 225 | pd3dDevice->ClearDepthStencilView( DXUTGetD3D10DepthStencilView(), D3D10_CLEAR_DEPTH, 1.0, 0 ); 226 | 227 | #ifdef ALT_CAMERA 228 | 229 | m_Projection = m_pCamera->proj; 230 | m_View = m_pCamera->view; 231 | 232 | #else 233 | m_World = *m_pCamera->GetWorldMatrix(); 234 | m_Projection = *m_pCamera->GetProjMatrix(); 235 | m_View = *m_pCamera->GetViewMatrix(); 236 | 237 | #endif 238 | pSkybox->Render( &m_View, &m_Projection ); 239 | 240 | m_pfxWorld->SetMatrix((float*) &m_World); 241 | m_pfxView->SetMatrix ((float*) &m_View); 242 | m_pfxProj->SetMatrix ((float*) &m_Projection); 243 | 244 | } 245 | 246 | //-------------------------------------------------------------------------------------- 247 | // Create any D3D10 resources that depend on the back buffer 248 | //-------------------------------------------------------------------------------------- 249 | HRESULT CALLBACK DX10Base::OnSwapChainResized( ID3D10Device* pd3dDevice, IDXGISwapChain *pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ) 250 | { 251 | m_UI.OnD3D10SwapChainResized(pd3dDevice,pBackBufferSurfaceDesc); 252 | // Setup the camera's projection parameters 253 | 254 | float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height; 255 | 256 | SAFE_DELETE(pSkybox); 257 | 258 | #ifdef ALT_CAMERA 259 | m_pCamera->aspect = fAspectRatio; 260 | m_pCamera->update_lookat(); 261 | pSkybox = new Skybox( pd3dDevice, m_pCamera->zfar); 262 | #else 263 | m_pCamera->SetProjParams( D3DX_PI/4, fAspectRatio, 1.0f,300.0f ); 264 | m_pCamera->SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); 265 | m_pCamera->SetButtonMasks( 0, MOUSE_WHEEL, MOUSE_LEFT_BUTTON | MOUSE_MIDDLE_BUTTON | MOUSE_RIGHT_BUTTON ); 266 | pSkybox = new Skybox( pd3dDevice, m_pCamera->GetFarClip()); 267 | #endif 268 | 269 | return S_OK; 270 | } 271 | 272 | 273 | //-------------------------------------------------------------------------------------- 274 | // Release D3D10 resources created in OnD3D10ResizedSwapChain 275 | //-------------------------------------------------------------------------------------- 276 | void CALLBACK DX10Base::OnSwapChainReleasing( ) 277 | { 278 | m_UI.OnD3D10SwapChainReleasing(); 279 | } 280 | 281 | 282 | //-------------------------------------------------------------------------------------- 283 | // Release D3D10 resources created in OnD3D10CreateDevice 284 | //-------------------------------------------------------------------------------------- 285 | void CALLBACK DX10Base::OnDestroyDevice( ) 286 | { 287 | DXUTGetGlobalResourceCache().OnDestroyDevice(); 288 | //SAFE_RELEASE( g_pRasterState ); 289 | if(m_bCleanUp) 290 | { 291 | SAFE_RELEASE( m_pEffect ); 292 | SAFE_DELETE ( pSkybox ); 293 | m_UI.Destroy(); 294 | m_bCleanUp = FALSE; 295 | } 296 | } 297 | 298 | DX10Base::~DX10Base() 299 | { 300 | if(m_bCleanUp) 301 | { 302 | SAFE_RELEASE(m_pEffect); 303 | SAFE_DELETE(pSkybox); 304 | m_UI.Destroy(); 305 | m_bCleanUp = FALSE; 306 | } 307 | SAFE_DELETE ( m_pCamera ); 308 | 309 | } 310 | 311 | //-------------------------------------------------------------------------------------- 312 | // Handle messages to the application 313 | //-------------------------------------------------------------------------------------- 314 | LRESULT CALLBACK DX10Base::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, 315 | bool* pbNoFurtherProcessing ) 316 | { 317 | m_UI.MsgProc( hWnd, uMsg, wParam, lParam, pbNoFurtherProcessing, NULL ); 318 | if(*pbNoFurtherProcessing) 319 | return 0; 320 | 321 | #ifdef ALT_CAMERA 322 | switch(uMsg) 323 | { 324 | case WM_MOUSEMOVE: 325 | m_Mouse.x = (int)LOWORD(lParam); 326 | m_Mouse.y = (int)HIWORD(lParam); 327 | break; 328 | case WM_LBUTTONDOWN: 329 | m_Mouse.Ldragging = TRUE; 330 | m_Mouse.start_x = (int)LOWORD(lParam); 331 | m_Mouse.start_y = (int)HIWORD(lParam); 332 | break; 333 | case WM_RBUTTONDOWN: 334 | m_Mouse.Rdragging = TRUE; 335 | m_Mouse.start_x = (int)LOWORD(lParam); 336 | m_Mouse.start_y = (int)HIWORD(lParam); 337 | break; 338 | case WM_MBUTTONDOWN: 339 | m_Mouse.Mdragging = TRUE; 340 | m_Mouse.start_x = (int)LOWORD(lParam); 341 | m_Mouse.start_y = (int)HIWORD(lParam); 342 | break; 343 | case WM_LBUTTONUP: 344 | m_Mouse.Ldragging = FALSE; 345 | break; 346 | case WM_RBUTTONUP: 347 | m_Mouse.Rdragging = FALSE; 348 | break; 349 | case WM_MBUTTONUP: 350 | m_Mouse.Mdragging = FALSE; 351 | break; 352 | } 353 | #else 354 | m_pCamera->HandleMessages( hWnd, uMsg, wParam, lParam ); 355 | #endif 356 | 357 | return 0; 358 | } 359 | 360 | 361 | //-------------------------------------------------------------------------------------- 362 | // Handle key presses 363 | //-------------------------------------------------------------------------------------- 364 | void CALLBACK DX10Base::KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown ) 365 | { 366 | if( bKeyDown ) 367 | { 368 | switch( nChar ) 369 | { 370 | case VK_F1: 371 | m_UI.m_bShowHelp = !m_UI.m_bShowHelp; break; 372 | case VK_UP: 373 | break; 374 | case VK_DOWN: 375 | break; 376 | case VK_LEFT: 377 | break; 378 | case VK_RIGHT: 379 | break; 380 | 381 | } 382 | } 383 | 384 | } 385 | 386 | //-------------------------------------------------------------------------------------- 387 | // Call if device was removed. Return true to find a new device, false to quit 388 | //-------------------------------------------------------------------------------------- 389 | bool CALLBACK DX10Base::OnDeviceRemoved( ) 390 | { 391 | return true; 392 | } 393 | 394 | //-------------------------------------------------------------------------------------- 395 | // Update the MSAA sample count combo box for this format 396 | //-------------------------------------------------------------------------------------- 397 | void DX10Base::GetMaxMSAASampleCount( ID3D10Device* pd3dDevice, DXGI_FORMAT fmt ) 398 | { 399 | 400 | UINT iHighestSampleCount = 1; 401 | for( UINT i = 1; i <= D3D10_MAX_MULTISAMPLE_SAMPLE_COUNT; i++ ) 402 | { 403 | UINT Quality; 404 | if( SUCCEEDED( pd3dDevice->CheckMultisampleQualityLevels( fmt, i, &Quality ) ) && 405 | Quality > 0 ) 406 | { 407 | iHighestSampleCount = i; 408 | } 409 | } 410 | m_MSAASampleCount = iHighestSampleCount; 411 | 412 | 413 | } 414 | -------------------------------------------------------------------------------- /FrameWork/DX10Base.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #define ALT_CAMERA 8 | 9 | #pragma once 10 | #include "GrassUI.h" 11 | #include "DXUT.h" 12 | #include "DXUTcamera.h" 13 | #include "SDKmisc.h" 14 | #include "CModel.h" 15 | #ifdef ALT_CAMERA 16 | #include "camera.h" 17 | #endif 18 | #include "skybox.h" 19 | 20 | 21 | #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) 22 | #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) 23 | 24 | class DX10Base 25 | { 26 | protected: 27 | BOOL m_bWireFrame; 28 | BOOL m_bCleanUp; // order of destruction is dependant on how the class is declared we use this bool to make sure state is cleared 29 | GrassUI m_UI; 30 | #ifdef ALT_CAMERA 31 | struct mouse 32 | { 33 | int x; 34 | int y; 35 | int start_x; 36 | int start_y; 37 | bool Ldragging; // left button is dragging 38 | bool Rdragging; // etc 39 | bool Mdragging; // etc 40 | }; 41 | 42 | camera* m_pCamera; // A model viewing camera 43 | mouse m_Mouse; 44 | #else 45 | CModelViewerCamera* m_pCamera; // A model viewing camera 46 | #endif // ALT_CAMERA 47 | 48 | // D3DX effect stuff 49 | ID3D10Effect* m_pEffect; 50 | ID3D10EffectMatrixVariable* m_pfxWorld; 51 | ID3D10EffectMatrixVariable* m_pfxView; 52 | ID3D10EffectMatrixVariable* m_pfxProj; 53 | ID3D10EffectScalarVariable* m_fTimeVar; 54 | ID3D10EffectShaderResourceVariable* m_ptxDiffuse; 55 | 56 | // Vars tied to effects 57 | D3DXMATRIX m_World; 58 | D3DXMATRIX m_View; 59 | D3DXMATRIX m_Projection; 60 | float m_fTime; 61 | 62 | 63 | unsigned int m_MSAASampleCount; 64 | Skybox* pSkybox; 65 | public: 66 | 67 | DX10Base () : m_pEffect(0), m_bCleanUp( FALSE ), m_bWireFrame( FALSE ){ }; 68 | 69 | virtual ~DX10Base(); 70 | 71 | int Run(); 72 | 73 | virtual void InitApp(); 74 | 75 | // Query for MSAA support 76 | void GetMaxMSAASampleCount( ID3D10Device* pd3dDevice, DXGI_FORMAT fmt ); 77 | 78 | // Messaging Events 79 | virtual LRESULT CALLBACK MsgProc ( HWND hWnd, UINT uMsg, WPARAM wParam, 80 | LPARAM lParam, bool* pbNoFurtherProcessing ); 81 | 82 | virtual void CALLBACK KeyboardProc ( UINT nChar, bool bKeyDown, bool bAltDown ); 83 | 84 | virtual void CALLBACK OnGUIEvent ( UINT nEvent, int nControlID, CDXUTControl* pControl, 85 | void* pUserContext ); 86 | 87 | 88 | // Device Creation & Deletion 89 | virtual bool CALLBACK IsDeviceAcceptable ( UINT Adapter, UINT Output, D3D10_DRIVER_TYPE DeviceType, 90 | DXGI_FORMAT BackBufferFormat, bool bWindowed ); 91 | 92 | virtual HRESULT CALLBACK OnCreateDevice ( ID3D10Device* pd3dDevice, 93 | const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ); 94 | 95 | virtual bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings ); 96 | 97 | virtual bool CALLBACK OnDeviceRemoved ( ); 98 | 99 | virtual void CALLBACK OnDestroyDevice ( ); 100 | 101 | 102 | // DX10 Specific 103 | 104 | virtual void CALLBACK OnSwapChainReleasing( ); 105 | 106 | virtual HRESULT CALLBACK OnSwapChainResized ( ID3D10Device* pd3dDevice, IDXGISwapChain *pSwapChain, 107 | const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ); 108 | 109 | 110 | // FrameUpdate 111 | 112 | virtual void CALLBACK OnFrameMove ( double fTime, float fElapsedTime ); 113 | 114 | virtual void CALLBACK OnFrameRender ( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime ); 115 | 116 | 117 | }; 118 | 119 | 120 | -------------------------------------------------------------------------------- /FrameWork/DX10BaseHelper.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | 9 | class DX10BaseHelper 10 | { 11 | public: 12 | static bool CALLBACK IsDeviceAcceptable( 13 | UINT Adapter, UINT Output, D3D10_DRIVER_TYPE DeviceType, 14 | DXGI_FORMAT BufferFormat, bool bWindowed, void* pUserContext ) 15 | { 16 | return reinterpret_cast(pUserContext) 17 | ->IsDeviceAcceptable(Adapter,Output,DeviceType,BufferFormat,bWindowed); 18 | } 19 | 20 | static HRESULT CALLBACK OnCreateDevice( 21 | ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* 22 | in_pBufferSurfaceDesc, void* pUserContext ) 23 | { 24 | return reinterpret_cast(pUserContext) 25 | ->OnCreateDevice(pd3dDevice, in_pBufferSurfaceDesc); 26 | } 27 | 28 | static bool CALLBACK ModifyDeviceSettings( 29 | DXUTDeviceSettings* pDeviceSettings, void* pUserContext) 30 | { 31 | return reinterpret_cast(pUserContext) 32 | ->ModifyDeviceSettings(pDeviceSettings); 33 | } 34 | 35 | static HRESULT CALLBACK OnResizedSwapChain( 36 | ID3D10Device* pd3dDevice, IDXGISwapChain *pSwapChain, 37 | const DXGI_SURFACE_DESC* in_pBufferSurfaceDesc, void* pUserContext ) 38 | { 39 | return reinterpret_cast(pUserContext) 40 | ->OnSwapChainResized(pd3dDevice, pSwapChain, in_pBufferSurfaceDesc); 41 | } 42 | 43 | static void CALLBACK OnReleasingSwapChain( void* pUserContext ) 44 | { 45 | reinterpret_cast(pUserContext)->OnSwapChainReleasing(); 46 | } 47 | 48 | 49 | static bool CALLBACK OnDeviceRemoved(void* pUserContext) 50 | { 51 | return reinterpret_cast(pUserContext)->OnDeviceRemoved(); 52 | } 53 | 54 | static void CALLBACK OnDestroyDevice( void* pUserContext ) 55 | { 56 | reinterpret_cast(pUserContext)->OnDestroyDevice(); 57 | } 58 | 59 | 60 | // App Specific 61 | static void CALLBACK OnFrameMove( 62 | double fTime, float fElapsedTime, void* pUserContext) 63 | { 64 | reinterpret_cast(pUserContext)->OnFrameMove(fTime, fElapsedTime); 65 | } 66 | 67 | static void CALLBACK OnFrameRender( 68 | ID3D10Device* pd3dDevice,double fTime,float fElapsedTime,void* pUserContext) 69 | { 70 | return reinterpret_cast(pUserContext) 71 | ->OnFrameRender(pd3dDevice, fTime, fElapsedTime); 72 | } 73 | 74 | 75 | static LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, 76 | bool* pbNoFurtherProcessing, void* pUserContext ) 77 | { 78 | return reinterpret_cast(pUserContext) 79 | ->MsgProc(hWnd, uMsg, wParam, lParam, pbNoFurtherProcessing); 80 | } 81 | 82 | 83 | 84 | // UI Events 85 | static void CALLBACK KeyboardProc( 86 | UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext ) 87 | { 88 | reinterpret_cast(pUserContext)->KeyboardProc( nChar, bKeyDown, bAltDown ); 89 | } 90 | 91 | }; 92 | 93 | -------------------------------------------------------------------------------- /FrameWork/GrassUI.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include 8 | #include "GrassUI.h" 9 | 10 | CD3DSettingsDlg g_D3DSettingsDlg; // Device settings dialog 11 | 12 | LRESULT GrassUI::Create(ID3D10Device* pd3dDevice) 13 | { 14 | HRESULT hr; 15 | V_RETURN( m_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) ); 16 | V_RETURN( g_D3DSettingsDlg.OnD3D10CreateDevice( pd3dDevice ) ); 17 | V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, 18 | OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, 19 | L"Arial", &m_pFont ) ); 20 | V_RETURN( D3DX10CreateSprite( pd3dDevice, 512, &m_pTextSprite ) ); 21 | m_pTxtHelper = new CDXUTTextHelper( NULL, NULL, m_pFont, m_pTextSprite, 15 ); 22 | return S_OK; 23 | 24 | } 25 | 26 | void GrassUI::Init() 27 | { 28 | // HRESULT hr; 29 | // Initialize dialogs 30 | g_D3DSettingsDlg.Init( &m_DialogResourceManager ); 31 | m_HUD.Init( &m_DialogResourceManager ); 32 | m_DefaultUI.Init( &m_DialogResourceManager ); 33 | 34 | m_HUD.SetCallback( OnGUIEvent ); int iX = 15; int iY = 10; 35 | m_HUD.AddButton ( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", iX, iY, 125, 22 ); 36 | m_HUD.AddButton ( IDC_TOGGLEREF, L"Toggle REF (F3)", iX, iY += 24, 125, 22, VK_F3 ); 37 | m_HUD.AddButton ( IDC_CHANGEDEVICE, L"Change device (F2)", iX, iY += 24, 125, 22, VK_F2 ); 38 | iX = 15; 39 | iY = 10; 40 | m_DefaultUI.SetCallback( OnGUIEvent ); 41 | 42 | // Title font for static 43 | 44 | } 45 | 46 | void GrassUI::Destroy() 47 | { 48 | m_DialogResourceManager.OnD3D10DestroyDevice(); 49 | g_D3DSettingsDlg.OnD3D10DestroyDevice(); 50 | SAFE_DELETE ( m_pTxtHelper ); 51 | SAFE_RELEASE( m_pFont ); 52 | SAFE_RELEASE( m_pTextSprite ); 53 | 54 | } 55 | 56 | BOOL GrassUI::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ) 57 | { 58 | // Always allow dialog resource manager calls to handle global messages 59 | // so GUI state is updated correctly 60 | *pbNoFurtherProcessing = m_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam ); 61 | if( *pbNoFurtherProcessing ) 62 | return FALSE; 63 | 64 | if( g_D3DSettingsDlg.IsActive() ) 65 | { 66 | g_D3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam ); 67 | return FALSE; 68 | } 69 | 70 | // Give the dialogs a chance to handle the message first 71 | *pbNoFurtherProcessing = m_HUD.MsgProc( hWnd, uMsg, wParam, lParam ); 72 | if( *pbNoFurtherProcessing ) 73 | return TRUE; 74 | *pbNoFurtherProcessing = m_DefaultUI.MsgProc( hWnd, uMsg, wParam, lParam ); 75 | if( *pbNoFurtherProcessing ) 76 | return TRUE; 77 | 78 | return FALSE; 79 | } 80 | 81 | void GrassUI::OnD3D10SwapChainReleasing( ) 82 | { 83 | m_DialogResourceManager.OnD3D10ReleasingSwapChain(); 84 | } 85 | //-------------------------------------------------------------------------------------- 86 | // Render the help and statistics text. This function uses the ID3DXFont interface for 87 | // efficient text rendering. 88 | //-------------------------------------------------------------------------------------- 89 | void GrassUI::RenderText() 90 | { 91 | 92 | // The helper object simply helps keep track of text position, and color 93 | // and then it calls pFont->DrawText( m_pTextSprite, strMsg, -1, &rc, DT_NOCLIP, m_clr ); 94 | // If NULL is passed in as the sprite object, then it will work however the 95 | // pFont->DrawText() will not be batched together. Batching calls will improves performance. 96 | m_pTxtHelper->Begin(); 97 | m_pTxtHelper->SetInsertionPos( 5, 5 ); 98 | m_pTxtHelper->SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) ); 99 | 100 | if( m_bShowHelp ) 101 | { 102 | // Output statistics 103 | m_pTxtHelper->DrawTextLine( DXUTGetFrameStats(true) ); // Show FPS 104 | m_pTxtHelper->DrawTextLine( DXUTGetDeviceStats() ); 105 | 106 | 107 | m_pTxtHelper->DrawTextLine( L"Rotate Camera : Left Mouse Drag" ); 108 | m_pTxtHelper->DrawTextLine( L"Move Camera up,down : Right Mouse Drag" ); 109 | m_pTxtHelper->DrawTextLine( L"Move Camera : W, A, S, D " ); 110 | m_pTxtHelper->DrawTextLine( L"Quit: ESC" ); 111 | } 112 | else 113 | { 114 | m_pTxtHelper->DrawTextLine( L"Press F1 for menu & help" ); 115 | } 116 | m_pTxtHelper->End(); 117 | } 118 | void GrassUI::Render(float fElapsedTime) 119 | { 120 | if(g_D3DSettingsDlg.IsActive()) 121 | { 122 | g_D3DSettingsDlg.OnRender( fElapsedTime ); 123 | 124 | } 125 | else 126 | { 127 | if( m_bShowHelp ) 128 | { 129 | m_HUD.OnRender( fElapsedTime ); 130 | m_DefaultUI.OnRender( fElapsedTime ); 131 | } 132 | RenderText(); 133 | } 134 | 135 | } 136 | void GrassUI::OnD3D10SwapChainResized( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ) 137 | { 138 | m_DialogResourceManager.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ); 139 | g_D3DSettingsDlg.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ); 140 | 141 | m_backBufHeight = pBackBufferSurfaceDesc->Height; 142 | m_backBufWidth = pBackBufferSurfaceDesc->Width; 143 | // Create a sprite to help batch calls when drawing many lines of text 144 | m_HUD.SetLocation( m_backBufWidth-170, 0 ); 145 | m_HUD.SetSize( 170, 170 ); 146 | m_DefaultUI.SetLocation(0, 0); 147 | m_DefaultUI.SetSize(m_backBufWidth, m_backBufHeight); 148 | 149 | } 150 | void CALLBACK GrassUI::OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ) 151 | { 152 | switch( nControlID ) 153 | { 154 | case IDC_TOGGLEFULLSCREEN: DXUTToggleFullScreen(); break; 155 | case IDC_TOGGLEREF: DXUTToggleREF(); break; 156 | case IDC_CHANGEDEVICE: g_D3DSettingsDlg.SetActive( !g_D3DSettingsDlg.IsActive() ); break; 157 | 158 | } 159 | 160 | } 161 | 162 | 163 | -------------------------------------------------------------------------------- /FrameWork/GrassUI.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | #include "DXUT.h" 9 | #include "DXUTgui.h" 10 | #include "DXUTsettingsdlg.h" 11 | #include "SDKmisc.h" 12 | 13 | //-------------------------------------------------------------------------------------- 14 | // UI control IDs 15 | //-------------------------------------------------------------------------------------- 16 | 17 | #define IDC_TOGGLEFULLSCREEN 1 18 | #define IDC_TOGGLEREF 2 19 | #define IDC_CHANGEDEVICE 3 20 | #define IDC_TECHNIQUE 4 21 | 22 | class GrassUI 23 | { 24 | CDXUTDialogResourceManager m_DialogResourceManager; // manager for shared resources of dialogs 25 | CDXUTDialog m_HUD; // dialog for standard controls 26 | CDXUTDialog m_DefaultUI; // dialog for sample specific controls 27 | ID3DX10Font* m_pFont; // Font for drawing text 28 | ID3DX10Sprite* m_pTextSprite; // Sprite for batching draw text calls 29 | int m_backBufWidth; 30 | int m_backBufHeight; 31 | CDXUTTextHelper* m_pTxtHelper; 32 | public: 33 | BOOL m_bShowHelp; 34 | GrassUI():m_pFont(NULL), m_pTextSprite(NULL), m_bShowHelp(FALSE) {}; 35 | 36 | ~GrassUI() { Destroy(); } 37 | 38 | LRESULT Create(ID3D10Device* pd3dDevice); 39 | void Init(); 40 | void Destroy(); 41 | void Update(); 42 | void Render(float fElapsedTime ); 43 | void RenderText(); 44 | void ToggleHelp(){m_bShowHelp = !m_bShowHelp;}; 45 | BOOL MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ); 46 | static void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ); 47 | 48 | void OnD3D10SwapChainReleasing(); 49 | void OnD3D10SwapChainResized( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ); 50 | 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /FrameWork/GrassUIState.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/FrameWork/GrassUIState.h -------------------------------------------------------------------------------- /FrameWork/ShereConeIntersectionTest.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | // the intersection function is based on Sphere Cone intersection test described in Geometric tools 8 | // by Philip J. Schneider and David H. Eberly, 9 | // The Morgan Kaufmann Series in Computer Graphics and Geometric Modeling 10 | // http://www.geometrictools.com/Documentation/IntersectionSphereCone.pdf 11 | 12 | 13 | #include "DXUT.h" 14 | BOOL SphereConeTest ( D3DXVECTOR3 sphereCenter, float radius, float fov, D3DXVECTOR3 eyePt, D3DXVECTOR3 lookAt) 15 | { 16 | float fSin = sinf(fov); 17 | float fCos = cosf(fov); 18 | float fInvSin = 1.0f/fSin; 19 | float fCosSqr = fCos*fCos; 20 | float fSinSqr = fSin*fSin; 21 | D3DXVECTOR3 vAxis = lookAt - eyePt; 22 | 23 | D3DXVECTOR3 vCmV = sphereCenter - eyePt; 24 | D3DXVECTOR3 vD = vCmV + (radius*fInvSin)*vAxis; 25 | float fDSqrLen = D3DXVec3Dot(&vD, &vD); 26 | float fE = D3DXVec3Dot(&vD,&vAxis); 27 | if (fE > 0.0f && fE*fE >= fDSqrLen*fCosSqr) 28 | { 29 | fDSqrLen = D3DXVec3Dot(&vCmV, &vCmV); 30 | fE = -D3DXVec3Dot(&vCmV, &vAxis); 31 | if (fE > 0.0f && fE*fE >= fDSqrLen*fSinSqr) 32 | { 33 | float fRSqr = radius*radius; 34 | return fDSqrLen <= fRSqr; 35 | } 36 | return TRUE; 37 | } 38 | return FALSE; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /FrameWork/camera.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "camera.h" 9 | 10 | camera::camera() 11 | { 12 | position = D3DXVECTOR3(0,0,0); 13 | fov = 45; 14 | aspect = 1.0f; 15 | znear = 0.1f; 16 | zfar = 10; 17 | rotx = 0; 18 | roty = 0; 19 | rotz = 0; 20 | this->update(); 21 | } 22 | 23 | camera::camera(D3DXVECTOR3 pos, float rotx, float roty, float rotz, float fov, float aspect, float nearz, float farz) 24 | { 25 | this->position = pos; 26 | this->fov = fov; 27 | this->aspect = aspect; 28 | this->znear = nearz; 29 | this->zfar = farz; 30 | this->rotx = rotx; 31 | this->roty = roty; 32 | this->rotz = rotz; 33 | this->update(); 34 | } 35 | 36 | camera::camera(const camera *src) 37 | { 38 | this->position = src->position; 39 | this->fov = src->fov; 40 | this->aspect = src->aspect; 41 | this->znear = src->znear; 42 | this->zfar = src->zfar; 43 | this->rotx = src->rotx; 44 | this->roty = src->roty; 45 | this->rotz = src->rotz; 46 | this->update(); 47 | } 48 | 49 | camera::~camera() 50 | { 51 | 52 | } 53 | 54 | void camera::update() 55 | { 56 | D3DXMATRIXA16 rotatex,rotatey,rotatez,translation; 57 | 58 | // perspective matrix 59 | D3DXMatrixPerspectiveFovLH(&proj, fov, aspect, znear, zfar); 60 | // view matrix 61 | D3DXMatrixRotationX(&rotatex,rotx); 62 | D3DXMatrixRotationY(&rotatey,roty); 63 | D3DXMatrixRotationZ(&rotatez,rotz); 64 | D3DXMatrixTranslation(&translation,-position.x,-position.y,-position.z); 65 | view = translation * rotatey*rotatex*rotatez; 66 | // and finally the combined viewproj 67 | viewproj = view*proj; 68 | // and all the inverses 69 | D3DXMatrixInverse(&invproj,NULL,&proj); 70 | D3DXMatrixInverse(&invview,NULL,&view); 71 | D3DXMatrixInverse(&invviewproj,NULL,&viewproj); 72 | // and the direction vectors 73 | D3DXVECTOR3 tmp = D3DXVECTOR3(0,0,1); // forward vector 74 | D3DXVec3TransformNormal(&forward,&tmp,&invview); 75 | D3DXVec3Normalize( &forward, &forward ); 76 | tmp.y = 1; tmp.z = 0; // up vector 77 | D3DXVec3TransformNormal(&up,&tmp,&invview); 78 | tmp.x = 1; tmp.y = 0; //right vector 79 | D3DXVec3TransformNormal(&right,&tmp,&invview); 80 | } 81 | 82 | // set all parameters assuming position, forward & all the perspective shit are correct 83 | void camera::update_lookat() 84 | { 85 | // perspective matrix 86 | D3DXMatrixPerspectiveFovLH(&proj, fov, aspect, znear, zfar); 87 | // view matrix 88 | D3DXVECTOR3 tmpUp = D3DXVECTOR3(0,1,0); //right 89 | lookAt = position+forward; 90 | D3DXMatrixLookAtLH( &view, &position,&lookAt, &tmpUp); 91 | 92 | // and finally the combined viewproj 93 | viewproj = view*proj; 94 | // and all the inverses 95 | D3DXMatrixInverse(&invproj,NULL,&proj); 96 | D3DXMatrixInverse(&invview,NULL,&view); 97 | D3DXMatrixInverse(&invviewproj,NULL,&viewproj); 98 | D3DXVECTOR3 tmpRight = D3DXVECTOR3(1,0,0); //right 99 | D3DXVec3TransformNormal(&right,&tmpRight ,&invview); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /FrameWork/camera.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | #include "DXUT.h" 9 | 10 | 11 | class camera{ 12 | public: 13 | camera(); 14 | camera(const camera *src); 15 | camera(D3DXVECTOR3 pos, float rotx, float roty, float rotz, float fov, float aspect, float nearz, float farz); 16 | ~camera(); 17 | void update(); 18 | void update_lookat(); 19 | void debugger(); 20 | D3DXVECTOR3* GetEyePt(){ return &position; }; // for compatibility with DXCamera Classes 21 | D3DXVECTOR3* GetLookAtPt() { lookAt = position+forward; return &lookAt; }; // for compatibility with DXCamera Classes 22 | D3DXVECTOR3 position; 23 | D3DXVECTOR3 forward,up,right, lookAt; 24 | float fov, aspect,znear, zfar, rotx, roty, rotz; 25 | D3DXMATRIXA16 view, invview, proj, invproj, viewproj, invviewproj; 26 | }; 27 | -------------------------------------------------------------------------------- /FrameWork/skybox.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "Skybox.h" 9 | 10 | Skybox::Skybox( ID3D10Device* pd3dDevice, float size ) 11 | { 12 | this->pd3dDevice = pd3dDevice; 13 | this->size = size; 14 | this->InitEffects(); 15 | this->FillBuffers(); 16 | } 17 | 18 | Skybox::~Skybox( void ) 19 | { 20 | SAFE_RELEASE( g_pSkyboxIndexBuffer ); 21 | SAFE_RELEASE( g_pSkyboxVertexBuffer ); 22 | SAFE_RELEASE( g_pSkyboxVLayout ); 23 | SAFE_RELEASE( g_pSRVSkyboxCubemap ); 24 | SAFE_RELEASE( g_pSkyboxEffect ); 25 | } 26 | 27 | 28 | // Initialize Effects 29 | HRESULT Skybox::InitEffects( void ) 30 | { 31 | HRESULT hr; 32 | 33 | WCHAR str[MAX_PATH]; 34 | V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"fx/skyboxNEW.fx" ) ); 35 | DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; 36 | 37 | #if defined( DEBUG ) || defined( _DEBUG ) 38 | dwShaderFlags |= D3D10_SHADER_DEBUG; // to debug shaders 39 | #endif 40 | 41 | V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL, 42 | NULL, &g_pSkyboxEffect, NULL, NULL ) ); 43 | 44 | // Get effects variables 45 | g_pSkyboxTechnique = g_pSkyboxEffect->GetTechniqueByName( "RenderSkybox" ); 46 | g_pSRVSkyboxCubemapVariable = g_pSkyboxEffect->GetVariableByName( "g_EnvironmentMap" )->AsShaderResource(); 47 | g_pmViewProj = g_pSkyboxEffect->GetVariableByName( "g_mViewProjection" )->AsMatrix(); 48 | g_pfSunAlpha = g_pSkyboxEffect->GetVariableByName( "g_SunAlpha" )->AsScalar(); 49 | g_pfSunTheta = g_pSkyboxEffect->GetVariableByName( "g_SunTheta" )->AsScalar(); 50 | g_pfSunShininess = g_pSkyboxEffect->GetVariableByName( "g_SunShininess" )->AsScalar(); 51 | g_pfSunStrength = g_pSkyboxEffect->GetVariableByName( "g_SunStrength" )->AsScalar(); 52 | 53 | // Set constant sun variables 54 | g_pfSunAlpha->SetFloat( 1.38f ); 55 | g_pfSunTheta->SetFloat( 1.09f ); 56 | g_pfSunShininess->SetFloat( 84.0f ); 57 | g_pfSunStrength->SetFloat( 12.0f ); 58 | 59 | // ...Including skybox texture 60 | V_RETURN( D3DX10CreateShaderResourceViewFromFile( pd3dDevice, L"texture//cubemap-evul.dds", NULL, NULL, &g_pSRVSkyboxCubemap, NULL ) ); 61 | g_pSRVSkyboxCubemapVariable->SetResource( g_pSRVSkyboxCubemap ); 62 | return S_OK; 63 | } 64 | 65 | // Fill Buffers 66 | HRESULT Skybox::FillBuffers( void ) 67 | { 68 | HRESULT hr; 69 | 70 | // Define the input layout 71 | D3D10_INPUT_ELEMENT_DESC Skyboxlayout[] = 72 | { 73 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, 74 | }; 75 | UINT numElements = sizeof( Skyboxlayout ) / sizeof( Skyboxlayout[0] ); 76 | 77 | // Create the input layout 78 | D3D10_PASS_DESC PassDesc; 79 | g_pSkyboxTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc ); 80 | V_RETURN( pd3dDevice->CreateInputLayout( Skyboxlayout, numElements, PassDesc.pIAInputSignature, 81 | PassDesc.IAInputSignatureSize, &g_pSkyboxVLayout ) ); 82 | 83 | // Create and fill vertex buffer 84 | SkyboxVertex sky_vertices[Skyboxdetail * Skyboxdetail + Skyboxdetail]; 85 | // Create sphere vertices 86 | int counter = 0; 87 | float radius = size; 88 | // from phi = -pi to pi 89 | for(float phi = -D3DX_PI ; phi < D3DX_PI ; phi += (2*D3DX_PI/(float)Skyboxdetail) ) 90 | { 91 | // from theta = 0 to 2pi 92 | for(float theta = 0 ; theta < 2*D3DX_PI; theta += (2*D3DX_PI/(float)Skyboxdetail) ) 93 | { 94 | sky_vertices[counter].Pos = 95 | D3DXVECTOR3( 96 | radius*cos(phi)*cos(theta), 97 | radius*sin(phi), 98 | radius*cos(phi)*sin(theta) 99 | ); 100 | counter++; 101 | } 102 | } 103 | 104 | D3D10_BUFFER_DESC bd; 105 | bd.Usage = D3D10_USAGE_DEFAULT; 106 | bd.ByteWidth = sizeof( SkyboxVertex ) * Skyboxdetail * Skyboxdetail; 107 | bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; 108 | bd.CPUAccessFlags = 0; 109 | bd.MiscFlags = 0; 110 | D3D10_SUBRESOURCE_DATA InitData; 111 | InitData.pSysMem = sky_vertices; 112 | hr = pd3dDevice->CreateBuffer( &bd, &InitData, &g_pSkyboxVertexBuffer ); 113 | if( FAILED( hr ) ) 114 | return hr; 115 | 116 | // Create index buffer 117 | DWORD sky_indices[Skyboxdetail * Skyboxdetail * 6]; 118 | 119 | int i = 0; 120 | int curPoint, offset; 121 | for(int deltaV=0; deltaVCreateBuffer( &bd, &InitData2, &g_pSkyboxIndexBuffer ); 150 | if( FAILED( hr ) ) 151 | return hr; 152 | 153 | return S_OK; 154 | } 155 | 156 | void Skybox::Render( D3DXMATRIX* pCamView, D3DXMATRIX* pCamProj ) 157 | { 158 | // Set buffers and topology 159 | UINT stride = sizeof( SkyboxVertex ); 160 | UINT offset = 0; 161 | pd3dDevice->IASetInputLayout( g_pSkyboxVLayout ); 162 | pd3dDevice->IASetVertexBuffers( 0, 1, &g_pSkyboxVertexBuffer, &stride, &offset ); 163 | pd3dDevice->IASetIndexBuffer( g_pSkyboxIndexBuffer, DXGI_FORMAT_R32_UINT, 0); 164 | pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); 165 | 166 | //D3DXMATRIX mProj; 167 | D3DXMATRIX mFakeView; 168 | D3DXMATRIX mFakeViewProj; 169 | D3DXMATRIX mProj = *pCamProj; 170 | 171 | // Get the projection & view matrices from the camera class then fake em up 172 | mFakeView = *pCamView; 173 | mFakeView._41 = 0; // <_41, _42, _43> corresponds to distance vector, Skybox has "no distance" 174 | mFakeView._42 = 0; 175 | mFakeView._43 = 0; 176 | mProj = *pCamProj; 177 | mFakeViewProj = mFakeView * mProj; 178 | 179 | // Set effect variables 180 | g_pmViewProj->SetMatrix( ( float* )&mFakeViewProj ); 181 | 182 | g_pSkyboxTechnique->GetPassByIndex( 0 )->Apply( 0 ); 183 | pd3dDevice->DrawIndexed( (Skyboxdetail*Skyboxdetail)*6, 0, 0 ); 184 | } 185 | -------------------------------------------------------------------------------- /FrameWork/skybox.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "SDKmisc.h" 9 | 10 | 11 | struct SkyboxVertex 12 | { 13 | D3DXVECTOR3 Pos; 14 | }; 15 | 16 | #define Skyboxdetail 5 // Skyboxdetail x Skyboxdetail vertices 17 | class Skybox 18 | { 19 | public: 20 | Skybox( ID3D10Device* pd3dDevice, float size ); 21 | ~Skybox( void ); 22 | 23 | HRESULT FillBuffers( void ); 24 | HRESULT InitEffects( void ); 25 | void Render( D3DXMATRIX* pCamView, D3DXMATRIX* pCamProj ); 26 | ID3D10ShaderResourceView* g_pSRVSkyboxCubemap; // need to share with water class 27 | 28 | 29 | private: 30 | ID3D10InputLayout* g_pSkyboxVLayout; 31 | ID3D10Buffer* g_pSkyboxVertexBuffer; 32 | ID3D10Buffer* g_pSkyboxIndexBuffer; float size; 33 | ID3D10Effect* g_pSkyboxEffect; 34 | ID3D10EffectScalarVariable* g_pfSunAlpha; 35 | ID3D10EffectScalarVariable* g_pfSunTheta; 36 | ID3D10EffectScalarVariable* g_pfSunShininess; 37 | ID3D10EffectScalarVariable* g_pfSunStrength; 38 | ID3D10EffectMatrixVariable* g_pmViewProj; 39 | ID3D10EffectShaderResourceVariable* g_pSRVSkyboxCubemapVariable; 40 | ID3D10EffectTechnique* g_pSkyboxTechnique; 41 | ID3D10Device* pd3dDevice; 42 | }; -------------------------------------------------------------------------------- /GUIControlsTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Grass 5 | H:\Work\ 6 | 7 | 8 | 9 | grass_slider 10 | Grass Density 11 | 12 | 13 | 14 | 15 | 150 16 | 20 17 | Instanced 18 | 19 | 20 | 150 21 | 20 22 | Batched 23 | 24 | 25 | 150 26 | 20 27 | None 28 | 29 | 30 | -------------------------------------------------------------------------------- /Grass - 2008.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/Grass - 2008.ncb -------------------------------------------------------------------------------- /Grass - 2008.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Grass - 2008", "Grass - 2008.vcproj", "{D3D10105-96D0-4629-88B8-122C0256058C}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Profile|Win32 = Profile|Win32 10 | Release|Win32 = Release|Win32 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {D3D10105-96D0-4629-88B8-122C0256058C}.Debug|Win32.ActiveCfg = Debug|Win32 14 | {D3D10105-96D0-4629-88B8-122C0256058C}.Debug|Win32.Build.0 = Debug|Win32 15 | {D3D10105-96D0-4629-88B8-122C0256058C}.Profile|Win32.ActiveCfg = Profile|Win32 16 | {D3D10105-96D0-4629-88B8-122C0256058C}.Profile|Win32.Build.0 = Profile|Win32 17 | {D3D10105-96D0-4629-88B8-122C0256058C}.Release|Win32.ActiveCfg = Release|Win32 18 | {D3D10105-96D0-4629-88B8-122C0256058C}.Release|Win32.Build.0 = Release|Win32 19 | EndGlobalSection 20 | GlobalSection(SolutionProperties) = preSolution 21 | HideSolutionNode = FALSE 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /Grass.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "Grass.h" 9 | 10 | HRESULT CALLBACK Grass::OnCreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ) 11 | { 12 | 13 | HRESULT hr = __super::OnCreateDevice( pd3dDevice, pBackBufferSurfaceDesc ); 14 | D3DXVECTOR3 terrainCenter = D3DXVECTOR3(0,-10,0); 15 | float terrainRadius = 45.0; 16 | float terrainTexRepeats = 10.0; 17 | terrain.Generate( terrainCenter,terrainRadius,terrainTexRepeats ); // Center, radius, texRepeats 18 | terrain.CreateDevice ( pd3dDevice, m_pEffect ); 19 | float patchRadius = 15.0; 20 | unsigned int grassBladesPerPatch = 70; 21 | bbGrassPatch.Generate( terrainCenter, terrainRadius, grassBladesPerPatch, patchRadius ); 22 | bbGrassPatch.CreateDevice( pd3dDevice, m_pEffect ); 23 | D3DXVECTOR2 treeCenter = D3DXVECTOR2(0, -25); 24 | trees.Initialize( treeCenter ); 25 | trees.CreateDevice( pd3dDevice, m_pEffect ); 26 | 27 | return hr; 28 | } 29 | 30 | void CALLBACK Grass::OnFrameMove( double fTime, float fElapsedTime ) 31 | { 32 | __super::OnFrameMove(fTime, fElapsedTime); 33 | 34 | D3DXVECTOR3 eyePt = *m_pCamera->GetEyePt(); 35 | D3DXVECTOR3 lookAtPt = *m_pCamera->GetLookAtPt(); 36 | trees.OrientTreesTo(lookAtPt - eyePt); 37 | // Cull geometry not visible 38 | bbGrassPatch.Cull( D3DX_PI/8 /* frustum cone angle = camera FOV/2*/, eyePt, lookAtPt); 39 | 40 | 41 | } 42 | 43 | void CALLBACK Grass::OnFrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime ) 44 | { 45 | __super::OnFrameRender( pd3dDevice, fTime, fElapsedTime ); 46 | terrain.Render( pd3dDevice, m_ptxDiffuse ); 47 | trees.Render( pd3dDevice, m_ptxDiffuse ); 48 | bbGrassPatch.Render( pd3dDevice, m_ptxDiffuse ); 49 | m_UI.Render(fElapsedTime); // No UI by default 50 | 51 | } 52 | 53 | void CALLBACK Grass::OnDestroyDevice() 54 | { 55 | terrain.DestroyDevice(); 56 | bbGrassPatch.DestroyDevice(); 57 | trees.DestroyDevice(); 58 | trees.Destroy(); 59 | __super::OnDestroyDevice( ); 60 | 61 | } 62 | 63 | -------------------------------------------------------------------------------- /Grass.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | 9 | #include "GrassUI.h" 10 | #include "Framework/DX10Base.h" 11 | #include "TerrainPatch.h" 12 | #include "BillboardedTrees.h" 13 | #include "BBGrassPatch.h" 14 | class Grass:public DX10Base 15 | { 16 | 17 | BBGrassPatch bbGrassPatch; 18 | TerrainPatch terrain; 19 | BillboardedTrees trees; 20 | 21 | public: 22 | void InitApp() 23 | { 24 | // call parent class 25 | __super::InitApp(); 26 | } 27 | // FrameUpdate 28 | 29 | HRESULT CALLBACK OnCreateDevice ( ID3D10Device* pd3dDevice, 30 | const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc ); 31 | void CALLBACK OnDestroyDevice ( ); 32 | 33 | void CALLBACK OnFrameMove ( double fTime, float fElapsedTime ); 34 | 35 | void CALLBACK OnFrameRender ( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime ); 36 | 37 | 38 | }; 39 | -------------------------------------------------------------------------------- /Grass.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 9 | DirectX SDK Sample Program. 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Grass.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define IDC_STATIC -1 11 | #include 12 | 13 | 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | #undef APSTUDIO_READONLY_SYMBOLS 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | // English (U.S.) resources 20 | 21 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 22 | #ifdef _WIN32 23 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 24 | #pragma code_page(1252) 25 | #endif //_WIN32 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | // 29 | // RT_MANIFEST 30 | // 31 | 32 | 1 RT_MANIFEST "Grass.manifest" 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // Icon 37 | // 38 | 39 | // Icon with lowest ID value placed first to ensure application icon 40 | // remains consistent on all systems. 41 | IDI_MAIN_ICON ICON "DXUT\Optional\\directx.ico" 42 | 43 | #ifdef APSTUDIO_INVOKED 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // 46 | // TEXTINCLUDE 47 | // 48 | 49 | 1 TEXTINCLUDE 50 | BEGIN 51 | "resource.h\0" 52 | END 53 | 54 | 2 TEXTINCLUDE 55 | BEGIN 56 | "#define IDC_STATIC -1\r\n" 57 | "#include \r\n" 58 | "\r\n" 59 | "\r\n" 60 | "\0" 61 | END 62 | 63 | 3 TEXTINCLUDE 64 | BEGIN 65 | "\r\n" 66 | "\0" 67 | END 68 | 69 | #endif // APSTUDIO_INVOKED 70 | 71 | #endif // English (U.S.) resources 72 | ///////////////////////////////////////////////////////////////////////////// 73 | 74 | 75 | 76 | #ifndef APSTUDIO_INVOKED 77 | ///////////////////////////////////////////////////////////////////////////// 78 | // 79 | // Generated from the TEXTINCLUDE 3 resource. 80 | // 81 | 82 | 83 | ///////////////////////////////////////////////////////////////////////////// 84 | #endif // not APSTUDIO_INVOKED 85 | 86 | 87 | -------------------------------------------------------------------------------- /InstancedBillboard.cpp: -------------------------------------------------------------------------------- 1 | #include "DXUT.h" 2 | #include "InstancedBillboard.h" 3 | #include 4 | 5 | -------------------------------------------------------------------------------- /InstancedBillboard.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | #pragma warning ( disable : 4995 4996 ) 9 | #include 10 | #include 11 | #include 12 | 13 | template 14 | class InstancedBillboard 15 | { 16 | 17 | int vertexCnt; 18 | T_VERTEX* pVertices; 19 | ID3D10Buffer* pVertexBuffer; 20 | 21 | D3D10_INPUT_ELEMENT_DESC* pLayout; 22 | int numElements; 23 | ID3D10InputLayout* pVertexLayout; 24 | 25 | TCHAR pTextureName[MAX_PATH]; 26 | ID3D10ShaderResourceView* pTextureRV; 27 | ID3D10EffectTechnique* pRenderTechnique; 28 | 29 | int instanceCnt; 30 | int maxInstanceCnt; 31 | T_INSTANCE* pInstanceData; 32 | ID3D10Buffer* pInstanceBuffer; 33 | 34 | HRESULT LoadInstData ( ID3D10Device* pd3dDevice, ID3D10Buffer** ppInstanceData, 35 | void* pInData, int dataSize ); 36 | 37 | public: 38 | 39 | virtual void Init ( TCHAR* texName, T_INSTANCE* pInInstanceData, int cnt, T_VERTEX* pInVertices, int numVerts, 40 | D3D10_INPUT_ELEMENT_DESC* layout, int numLayoutElements, 41 | WORD* indices = 0, int numIndices = 0 ); 42 | 43 | virtual void Destroy ( ){ }; 44 | 45 | virtual HRESULT CreateDevice ( ID3D10Device* pd3dDevice, ID3D10EffectTechnique* pTechique ); 46 | 47 | virtual void DestroyDevice( ); 48 | // virtual void PreRender ( double fTime, float fElapsedTime ){}; 49 | 50 | virtual void Render ( ID3D10Device* pd3dDevice, ID3D10EffectShaderResourceVariable* pDiffuseVariable ); 51 | 52 | virtual void SetInstData ( T_INSTANCE* pInData, int numInstances ); 53 | 54 | }; 55 | 56 | template 57 | void InstancedBillboard::SetInstData( T_INSTANCE* pInData, int numInstances ) 58 | { 59 | // ASSERT( numInstances > maxInstanceCnt ); 60 | instanceCnt = numInstances; 61 | void* pData = NULL; 62 | pInstanceBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, ( void** )&pData ); 63 | memcpy( pData, (void*)pInData, sizeof(T_INSTANCE)*instanceCnt ); 64 | pInstanceBuffer->Unmap(); 65 | } 66 | 67 | 68 | template 69 | void InstancedBillboard::Init( TCHAR* texName, T_INSTANCE* pInInstanceData, int cnt , T_VERTEX* pInVertices, int numVerts, 70 | D3D10_INPUT_ELEMENT_DESC* layout, int numLayoutElements, 71 | WORD* indices /*= 0*/, int numIndices /*= 0 */ ) 72 | { 73 | _tcscpy(pTextureName, texName); 74 | 75 | pVertices = pInVertices; 76 | vertexCnt = numVerts; 77 | pLayout = layout; 78 | numElements = numLayoutElements; 79 | pInstanceData = pInInstanceData; 80 | instanceCnt = cnt; 81 | maxInstanceCnt = cnt; 82 | } 83 | 84 | template 85 | HRESULT InstancedBillboard::CreateDevice( ID3D10Device* pd3dDevice, ID3D10EffectTechnique* pTechique) 86 | { 87 | HRESULT hr = S_OK; 88 | pRenderTechnique = pTechique; 89 | // Create the input layout 90 | D3D10_PASS_DESC PassDesc; 91 | pRenderTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc ); 92 | hr = pd3dDevice->CreateInputLayout( pLayout, numElements, PassDesc.pIAInputSignature, 93 | PassDesc.IAInputSignatureSize, &pVertexLayout ); 94 | 95 | // Initialize Vertex Buffers 96 | D3D10_BUFFER_DESC bd; 97 | D3D10_SUBRESOURCE_DATA InitData; 98 | 99 | bd.Usage = D3D10_USAGE_DEFAULT; 100 | bd.ByteWidth = sizeof( T_VERTEX ) * vertexCnt; 101 | bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; 102 | bd.CPUAccessFlags = 0; 103 | bd.MiscFlags = 0; 104 | InitData.pSysMem = pVertices; 105 | 106 | V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &pVertexBuffer )); 107 | 108 | // Create Instance Buffer 109 | // We're creating this buffer as dynamic because in a game, the instance data could be dynamic... aka 110 | // we could have moving trees. 111 | D3D10_BUFFER_DESC bufferDesc = 112 | { 113 | sizeof( T_INSTANCE )*instanceCnt, 114 | D3D10_USAGE_DYNAMIC, 115 | D3D10_BIND_VERTEX_BUFFER, 116 | D3D10_CPU_ACCESS_WRITE, 117 | 0 118 | }; 119 | 120 | V_RETURN( pd3dDevice->CreateBuffer( &bufferDesc, NULL, &pInstanceBuffer ) ); 121 | 122 | 123 | // Load the Texture 124 | V_RETURN( D3DX10CreateShaderResourceViewFromFile( pd3dDevice, pTextureName, NULL, NULL, &pTextureRV, NULL )); 125 | 126 | //Initialize instance buffer with data passed in 127 | SetInstData( pInstanceData, instanceCnt ); 128 | 129 | return hr; 130 | 131 | } 132 | 133 | template 134 | void InstancedBillboard::DestroyDevice() 135 | { 136 | SAFE_RELEASE( pVertexBuffer ); 137 | SAFE_RELEASE( pVertexLayout ); 138 | SAFE_RELEASE( pTextureRV ); 139 | SAFE_RELEASE( pInstanceBuffer ); 140 | } 141 | 142 | template 143 | void InstancedBillboard::Render (ID3D10Device* pd3dDevice, ID3D10EffectShaderResourceVariable* pDiffuseVariable ) 144 | { 145 | // Set the input layout 146 | pd3dDevice->IASetInputLayout( pVertexLayout ); 147 | 148 | ID3D10Buffer* pVB[2]; 149 | UINT strides[2]; 150 | UINT offsets[2] = {0,0}; 151 | pVB[0] = pVertexBuffer; 152 | pVB[1] = pInstanceBuffer; 153 | strides[0] = sizeof ( T_VERTEX ); 154 | strides[1] = sizeof ( T_INSTANCE ); 155 | pd3dDevice->IASetVertexBuffers( 0, //first input slot for binding 156 | 2, //number of buffers in the array 157 | pVB, //array of three vertex buffers 158 | strides, //array of stride values, one for each buffer 159 | offsets //array of offset values, one for each buffer 160 | ); 161 | 162 | // Set primitive topology 163 | pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); 164 | pDiffuseVariable->SetResource( pTextureRV ); 165 | 166 | // Render Instanced Billboards 167 | D3D10_TECHNIQUE_DESC techDesc; 168 | pRenderTechnique->GetDesc( &techDesc ); 169 | 170 | for( UINT p = 0; p < techDesc.Passes; ++p ) 171 | { 172 | pRenderTechnique->GetPassByIndex( p )->Apply( 0 ); 173 | pd3dDevice->DrawInstanced( vertexCnt, // number of vertices per instance 174 | instanceCnt, // number of instances 175 | 0, // Index of the first vertex 176 | 0 // Index of the first instance 177 | ); 178 | } 179 | } 180 | 181 | template 182 | HRESULT InstancedBillboard::LoadInstData( ID3D10Device* pd3dDevice, ID3D10Buffer** ppInstanceData, void* pInData, int dataSize ) 183 | { 184 | 185 | 186 | HRESULT hr = S_OK; 187 | 188 | // Create a resource with the input matrices 189 | // We're creating this buffer as dynamic because in a game, the instance data could be dynamic 190 | D3D10_BUFFER_DESC bufferDesc = 191 | { 192 | dataSize, 193 | D3D10_USAGE_DYNAMIC, 194 | D3D10_BIND_VERTEX_BUFFER, 195 | D3D10_CPU_ACCESS_WRITE, 196 | 0 197 | }; 198 | 199 | V_RETURN( pd3dDevice->CreateBuffer( &bufferDesc, NULL, ppInstanceData ) ); 200 | 201 | void* pData = NULL; 202 | ( *ppInstanceData )->Map( D3D10_MAP_WRITE_DISCARD, NULL, ( void** )&pData ); 203 | 204 | memcpy( pData, pInData, dataSize ); 205 | 206 | ( *ppInstanceData )->Unmap(); 207 | return hr; 208 | } 209 | 210 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rendering realistic looking grass in real-time is hard, especially on consumer graphics hardware because of its geometric complexity. The intent of this article and source provided is to introduce the concept of geometry instancing with Direct3D10 APIs to the reader and show how it can be used to implement a realistic looking grass on consumer graphics hardware. 2 | 3 | https://software.intel.com/en-us/articles/rendering-grass-with-instancing-in-directx-10 4 | 5 | ![Screenshot](https://software.intel.com/sites/default/files/m/d/4/1/d/8/grass_figure3.jpg) 6 | -------------------------------------------------------------------------------- /TerrainPatch.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "DXUT.h" 8 | #include "TerrainPatch.h" 9 | 10 | 11 | TerrainPatch::TerrainPatch() 12 | { 13 | g_pVertexBuffer = NULL; 14 | pRenderTechnique = NULL; 15 | m_pGroundVerts = 0; 16 | 17 | } 18 | 19 | HRESULT TerrainPatch::CreateDevice( ID3D10Device* pd3dDevice, ID3D10Effect* pEffect) 20 | { 21 | HRESULT hr = S_OK; 22 | 23 | pRenderTechnique = pEffect->GetTechniqueByName( "Render" ); 24 | if( m_pGroundVerts ) 25 | __super::Init(L"texture//seafloor.dds", m_pGroundVerts, 6); 26 | else 27 | __super::Init(L"texture//seafloor.dds", g_DefaultGroundVerts, 6); 28 | 29 | __super::CreateDevice(pd3dDevice , pRenderTechnique ); 30 | 31 | return hr; 32 | 33 | } 34 | 35 | void TerrainPatch::DestroyDevice() 36 | { 37 | __super::DestroyDevice(); 38 | SAFE_RELEASE( g_pVertexBuffer ); 39 | 40 | } 41 | 42 | void TerrainPatch::Generate( D3DXVECTOR3 center, float r, float texRepeat ) 43 | { 44 | m_pGroundVerts = new TerrainVertex[6]; 45 | //D3DXVECTOR3(-60.0f, -10.0f, 60.0f) 46 | m_pGroundVerts[0].Pos = D3DXVECTOR3( center.x - r, center.y, center.z + r ); 47 | m_pGroundVerts[0].Tex = D3DXVECTOR2( texRepeat, texRepeat ); 48 | // {D3DXVECTOR3( 60.0f, -10.0f, 60.0f), D3DXVECTOR2(0.0f, 10.0f )}, 49 | m_pGroundVerts[1].Pos = D3DXVECTOR3( center.x + r, center.y, center.z + r ); 50 | m_pGroundVerts[1].Tex = D3DXVECTOR2(0, texRepeat ); 51 | // {D3DXVECTOR3( 60.0f, -10.0f, -60.0f), D3DXVECTOR2(0.0f, 0.0f )}, 52 | m_pGroundVerts[2].Pos = D3DXVECTOR3( center.x + r, center.y, center.z - r ); 53 | m_pGroundVerts[2].Tex = D3DXVECTOR2(0, 0 ); 54 | 55 | // {D3DXVECTOR3(-60.0f, -10.0f, 60.0f), D3DXVECTOR2(10.0f, 10.0f )}, 56 | m_pGroundVerts[3].Pos = D3DXVECTOR3( center.x - r, center.y, center.z + r ); 57 | m_pGroundVerts[3].Tex = D3DXVECTOR2(texRepeat, texRepeat ); 58 | // {D3DXVECTOR3( 60.0f, -10.0f, -60.0f), D3DXVECTOR2(0.0f, 0.0f )}, 59 | m_pGroundVerts[4].Pos = D3DXVECTOR3( center.x + r, center.y, center.z - r ); 60 | m_pGroundVerts[4].Tex = D3DXVECTOR2(0, 0 ); 61 | // {D3DXVECTOR3(-60.0f, -10.0f, -60.0f), D3DXVECTOR2(10.0f, 0.0f )}, 62 | m_pGroundVerts[5].Pos = D3DXVECTOR3( center.x - r, center.y, center.z - r ); 63 | m_pGroundVerts[5].Tex = D3DXVECTOR2(texRepeat, 0.0 ); 64 | 65 | } 66 | 67 | TerrainPatch::~TerrainPatch() 68 | { 69 | SAFE_DELETE_ARRAY( m_pGroundVerts ); 70 | } -------------------------------------------------------------------------------- /TerrainPatch.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #pragma once 8 | #include 9 | #include 10 | #include "Billboard.h" 11 | 12 | struct TerrainVertex 13 | { 14 | D3DXVECTOR3 Pos; 15 | D3DXVECTOR2 Tex; 16 | 17 | }; 18 | 19 | static TerrainVertex g_DefaultGroundVerts[]= 20 | { 21 | // x y z tu1 tv1 22 | {D3DXVECTOR3(-60.0f, -10.0f, 60.0f), D3DXVECTOR2(10.0f, 10.0f )}, 23 | {D3DXVECTOR3( 60.0f, -10.0f, 60.0f), D3DXVECTOR2(0.0f, 10.0f )}, 24 | {D3DXVECTOR3( 60.0f, -10.0f, -60.0f), D3DXVECTOR2(0.0f, 0.0f )}, 25 | 26 | {D3DXVECTOR3(-60.0f, -10.0f, 60.0f), D3DXVECTOR2(10.0f, 10.0f )}, 27 | {D3DXVECTOR3( 60.0f, -10.0f, -60.0f), D3DXVECTOR2(0.0f, 0.0f )}, 28 | {D3DXVECTOR3(-60.0f, -10.0f, -60.0f), D3DXVECTOR2(10.0f, 0.0f )}, 29 | }; 30 | 31 | 32 | 33 | class TerrainPatch : public Billboard 34 | { 35 | ID3D10Buffer* g_pVertexBuffer; 36 | ID3D10EffectTechnique* pRenderTechnique; 37 | TerrainVertex* m_pGroundVerts; 38 | public: 39 | TerrainPatch ( ); 40 | ~TerrainPatch ( ); 41 | void Generate ( D3DXVECTOR3 center, float radius, float texRepeat ); /* TODO - Extend to add height field*/ 42 | HRESULT CreateDevice ( ID3D10Device* m_pd3dDevice, ID3D10Effect* m_pEffect ); 43 | void DestroyDevice ( ); 44 | 45 | }; 46 | 47 | 48 | -------------------------------------------------------------------------------- /UpgradeLog.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/UpgradeLog.htm -------------------------------------------------------------------------------- /fx/BasicTNL.fx: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | //-------------------------------------------------------------------------------------- 7 | // File: BasicTNL.fx 8 | // 9 | //-------------------------------------------------------------------------------------- 10 | 11 | 12 | //-------------------------------------------------------------------------------------- 13 | // Constant Buffer Variables 14 | //-------------------------------------------------------------------------------------- 15 | Texture2D txDiffuse; 16 | 17 | SamplerState samLinear 18 | { 19 | Filter = MIN_MAG_MIP_LINEAR; 20 | AddressU = Wrap; 21 | AddressV = Wrap; 22 | }; 23 | 24 | cbuffer cbNeverChanges 25 | { 26 | float4 g_vWaveDistortX = float4( 3.0f, 0.4f, 0.0f, 0.3f ); 27 | float4 g_vWaveDistortZ = float4( 3.0f, 0.4f, 0.0f, 0.3f ); 28 | float4 g_vWaveDistortY = float4( -1.0f, -0.133f, -0.333f, -0.10f ); 29 | float4 g_vWaveDirX = float4( -0.006f, -0.012f, 0.024f, 0.048f ); 30 | float4 g_vWaveDirZ = float4( -0.003f, -0.006f, -0.012f, -0.048f ); 31 | float4 g_vWaveSpeed = float4( 0.3f, 0.7f, 0.6f, 1.4f ); 32 | float g_fPIx2 = 6.28318530f; 33 | float4 g_vLightingWaveScale = float4( 0.35f, 0.10f, 0.10f, 0.03f ); 34 | float4 g_vLightingScaleBias = float4( 0.6f, 0.7f, 0.2f, 0.0f ); 35 | }; 36 | 37 | cbuffer cbChangeOnResize 38 | { 39 | matrix Projection; 40 | }; 41 | 42 | cbuffer cbChangesEveryFrame 43 | { 44 | matrix Orientation; 45 | matrix World; 46 | matrix View; 47 | float g_fTime; 48 | }; 49 | 50 | 51 | BlendState AlphaBlending 52 | { 53 | AlphaToCoverageEnable = FALSE; 54 | BlendEnable[0] = TRUE; 55 | 56 | SrcBlend = SRC_ALPHA; 57 | DestBlend = INV_SRC_ALPHA; 58 | BlendOp = ADD; 59 | SrcBlendAlpha = ZERO; 60 | DestBlendAlpha = ZERO; 61 | BlendOpAlpha = ADD; 62 | RenderTargetWriteMask[0] = 0x0F; 63 | }; 64 | 65 | BlendState QuadAlphaBlendState 66 | { 67 | AlphaToCoverageEnable = TRUE; 68 | BlendEnable[0] = TRUE; 69 | SrcBlend = ONE; 70 | DestBlend = INV_SRC_ALPHA; 71 | BlendOp = ADD; 72 | RenderTargetWriteMask[0] = 0x0F; 73 | }; 74 | 75 | RasterizerState EnableMSAA 76 | { 77 | CullMode = BACK; 78 | MultisampleEnable = TRUE; 79 | }; 80 | 81 | BlendState NoBlending 82 | { 83 | AlphaToCoverageEnable = FALSE; 84 | BlendEnable[0] = FALSE; 85 | }; 86 | 87 | DepthStencilState EnableDepthWrite 88 | { 89 | DepthEnable = TRUE; 90 | DepthWriteMask = ALL; 91 | }; 92 | 93 | DepthStencilState DisableDepthWrite 94 | { 95 | DepthEnable = TRUE; 96 | DepthWriteMask = ZERO; 97 | }; 98 | 99 | DepthStencilState DisableDepthTest 100 | { 101 | DepthEnable = TRUE; 102 | DepthWriteMask = ALL; 103 | DepthFunc = ALWAYS; 104 | }; 105 | 106 | 107 | struct VS_INPUT 108 | { 109 | float4 Pos : POSITION; 110 | float2 Tex : TEXCOORD; 111 | }; 112 | 113 | struct PS_INPUT 114 | { 115 | float4 Pos : SV_POSITION; 116 | float2 Tex : TEXCOORD0; 117 | }; 118 | 119 | struct VS_INPUT_TREE 120 | { 121 | float3 Pos : POSITION; //position 122 | float2 Tex : TEXCOORD0; //texture coordinate 123 | float3 offPos : offPos; // offsetPosition 124 | float2 scale : scale; 125 | }; 126 | 127 | struct VS_INPUT_GRASS 128 | { 129 | float3 Pos : POSITION; //position 130 | float2 Tex : TEXCOORD0; //texture coordinate 131 | float2 vPPos : vPPos; // patchPosition 132 | }; 133 | 134 | 135 | struct PS_INPUT_GRASS 136 | { 137 | float4 Pos : SV_POSITION; 138 | float4 Color : COLOR0; 139 | float2 Tex : TEXCOORD0; 140 | }; 141 | 142 | //-------------------------------------------------------------------------------------- 143 | // Vertex Shader 144 | //-------------------------------------------------------------------------------------- 145 | 146 | PS_INPUT VS( VS_INPUT input ) 147 | { 148 | PS_INPUT output = (PS_INPUT)0; 149 | output.Pos = mul( input.Pos, World ); 150 | output.Pos = mul( output.Pos, View ); 151 | output.Pos = mul( output.Pos, Projection ); 152 | output.Tex = input.Tex; 153 | 154 | return output; 155 | } 156 | 157 | 158 | //-------------------------------------------------------------------------------------- 159 | // Pixel Shader 160 | //-------------------------------------------------------------------------------------- 161 | float4 PS( PS_INPUT input) : SV_Target 162 | { 163 | return txDiffuse.Sample( samLinear, input.Tex ); 164 | } 165 | 166 | PS_INPUT RenderTreeVS( VS_INPUT_TREE input ) 167 | { 168 | PS_INPUT output = (PS_INPUT)0; 169 | 170 | output.Pos = mul( float4(input.Pos, 1), Orientation ); 171 | output.Pos.x *= input.scale.x; 172 | output.Pos.y *= input.scale.y; 173 | output.Pos += float4(input.offPos,1); 174 | 175 | output.Pos = mul( output.Pos, World ); 176 | output.Pos = mul( output.Pos, View ); 177 | output.Pos = mul( output.Pos, Projection ); 178 | output.Tex = input.Tex; 179 | 180 | 181 | return output; 182 | } 183 | 184 | PS_INPUT_GRASS RenderGrassVS( VS_INPUT_GRASS v ) 185 | { 186 | PS_INPUT_GRASS o; 187 | //sinusoidal vertex motion for waving grass 188 | //pos + sumOverI(wavedirI * texcoordy * sin( xdirI * (xpos+time)) + ydirI * (ypos+time))) 189 | 190 | 191 | // use vertex pos x and y as inputs to sinusoidal warp 192 | float4 vWaveVec = (g_vWaveDirX * v.Pos.x) + (g_vWaveDirZ * v.Pos.z); 193 | 194 | // add scaled time to move bumps according to speed 195 | vWaveVec += g_fTime * g_vWaveSpeed; 196 | 197 | // take frac of all 4 components 198 | vWaveVec = frac( vWaveVec ); 199 | 200 | vWaveVec -= 0.8f; 201 | 202 | // *=2pi coords range from (-pi to pi) 203 | vWaveVec *= g_fPIx2; // pi * 2.0 204 | 205 | // taylor series expansion replaced by actual sin fun 206 | vWaveVec = sin( vWaveVec ); 207 | 208 | float4 vWaveDistortion; 209 | vWaveDistortion.x = dot( vWaveVec, g_vWaveDistortX ); 210 | vWaveDistortion.y = dot( vWaveVec, g_vWaveDistortY ); 211 | vWaveDistortion.zw = dot( vWaveVec, g_vWaveDistortZ ); 212 | 213 | // attenuate sinusoidal warping by (1-tex0.y)^2 214 | float fSinWarp = 1.0f - v.Tex.y; 215 | fSinWarp *= fSinWarp; 216 | vWaveDistortion *= fSinWarp; 217 | 218 | // Out position -- add sinusoidal warping to grass position 219 | float4 vGrassPos; 220 | vGrassPos.xyz = vWaveDistortion + v.Pos; 221 | vGrassPos.w = 1.0; //v.Pos; 222 | vGrassPos.x += v.vPPos.x; 223 | vGrassPos.z += v.vPPos.y; 224 | 225 | o.Pos = mul( vGrassPos, World ); 226 | o.Pos = mul( o.Pos, View ); 227 | o.Pos = mul( o.Pos, Projection ); 228 | 229 | // scale and add sin waves together 230 | // scale and bias color values 231 | // (green is scaled more than red and blue) 232 | 233 | float fScaled = dot( vWaveVec, g_vLightingWaveScale ); 234 | o.Color = (g_vLightingScaleBias.zzzw * -fScaled) + g_vLightingScaleBias.y; 235 | // Pass the tex coord through 236 | o.Tex = v.Tex; 237 | 238 | return o; 239 | } 240 | 241 | float4 RenderGrassPS( PS_INPUT_GRASS input) : SV_Target 242 | { 243 | //calculate lighting assuming light color is <1,1,1,1> 244 | //float fLighting = saturate( dot( input.Norm, g_LightDir ) ); 245 | float4 outputColor = txDiffuse.Sample( samLinear, input.Tex ); 246 | outputColor.xyz *= input.Color.xyz; 247 | return outputColor; 248 | } 249 | 250 | technique10 RenderGrass 251 | { 252 | pass P0 253 | { 254 | SetVertexShader( CompileShader( vs_4_0,RenderGrassVS() ) ); 255 | SetGeometryShader( NULL ); 256 | SetPixelShader( CompileShader( ps_4_0, RenderGrassPS() ) ); 257 | 258 | SetBlendState( QuadAlphaBlendState, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); 259 | SetDepthStencilState( EnableDepthWrite, 0 ); 260 | SetRasterizerState( EnableMSAA ); 261 | 262 | } 263 | } 264 | 265 | //-------------------------------------------------------------------------------------- 266 | technique10 RenderTree 267 | { 268 | pass P0 269 | { 270 | SetVertexShader( CompileShader( vs_4_0, RenderTreeVS() ) ); 271 | SetGeometryShader( NULL ); 272 | SetPixelShader( CompileShader( ps_4_0, PS() ) ); 273 | 274 | } 275 | 276 | } 277 | 278 | //-------------------------------------------------------------------------------------- 279 | technique10 Render 280 | { 281 | pass P0 282 | { 283 | SetVertexShader( CompileShader( vs_4_0, VS() ) ); 284 | SetGeometryShader( NULL ); 285 | SetPixelShader( CompileShader( ps_4_0, PS() ) ); 286 | 287 | // SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); 288 | // SetDepthStencilState( EnableDepthWrite, 0 ); 289 | } 290 | 291 | } 292 | 293 | -------------------------------------------------------------------------------- /fx/skyboxNEW.fx: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | //-------------------------------------------------------------------------------------- 8 | // File: skyboxNEW.fx 9 | // 10 | // 11 | //-------------------------------------------------------------------------------------- 12 | 13 | 14 | //-------------------------------------------------------------------------------------- 15 | // Global variables 16 | //-------------------------------------------------------------------------------------- 17 | cbuffer cb0 18 | { 19 | float4x4 g_mViewProjection; // View * Projection matrix 20 | float g_SunAlpha, g_SunTheta, g_SunShininess, g_SunStrength; // variables for Skybox sun 21 | } 22 | 23 | TextureCube g_EnvironmentMap; // Sky texture 24 | 25 | //-------------------------------------------------------------------------------------- 26 | // SamplerStates 27 | //-------------------------------------------------------------------------------------- 28 | 29 | SamplerState samSkybox 30 | { 31 | Filter = MIN_MAG_MIP_LINEAR; 32 | AddressU = CLAMP; 33 | AddressV = CLAMP; 34 | AddressW = CLAMP; 35 | }; 36 | 37 | //-------------------------------------------------------------------------------------- 38 | // Input/Output Structures 39 | //-------------------------------------------------------------------------------------- 40 | 41 | struct RenderSkyboxVSOUT 42 | { 43 | float4 Position : SV_POSITION0; // position of sphere 44 | float3 SunPosition : TEXCOORD0; // position of sun 45 | float3 SkyTexUVW : TEXCOORD1; // texture coordinates 46 | }; 47 | 48 | //-------------------------------------------------------------------------------------- 49 | // Shader Functions 50 | //-------------------------------------------------------------------------------------- 51 | 52 | RenderSkyboxVSOUT RenderSkyboxVS( float4 vPos : POSITION ) 53 | { 54 | RenderSkyboxVSOUT Output; 55 | float zfar = 4000; 56 | 57 | Output.Position = mul( zfar*vPos, g_mViewProjection ); 58 | 59 | Output.SkyTexUVW = vPos; 60 | Output.SunPosition.x = cos(g_SunTheta)*sin(g_SunAlpha); 61 | Output.SunPosition.y = sin(g_SunTheta); 62 | Output.SunPosition.z = cos(g_SunTheta)*cos(g_SunAlpha); 63 | 64 | return Output; 65 | } 66 | 67 | float4 RenderSkyboxPS( RenderSkyboxVSOUT Input ) : SV_TARGET 68 | { 69 | float4 Output; 70 | 71 | float3 sunlight = g_SunStrength*pow( saturate(dot(normalize(Input.SkyTexUVW), Input.SunPosition)), 72 | g_SunShininess)*float3(1.2, 0.4, 0.1); 73 | 74 | Output.a = 1; 75 | Output.rgb = g_EnvironmentMap.Sample( samSkybox,Input.SkyTexUVW ) + sunlight; 76 | return Output; 77 | } 78 | 79 | //-------------------------------------------------------------------------------------- 80 | // Shader Techniques 81 | //-------------------------------------------------------------------------------------- 82 | 83 | technique10 RenderSkybox 84 | { 85 | pass P0 86 | { 87 | SetVertexShader( CompileShader( vs_4_0, RenderSkyboxVS() ) ); 88 | SetGeometryShader( NULL ); 89 | SetPixelShader( CompileShader( ps_4_0, RenderSkyboxPS() ) ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /ipch/GRASS - 2015-a34bf674/GRASS - 2008-8e5b5e3d.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/ipch/GRASS - 2015-a34bf674/GRASS - 2008-8e5b5e3d.ipch -------------------------------------------------------------------------------- /ipch/GRASS - 2015-a34bf674/GRASS - 2008-c5c56a43.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/ipch/GRASS - 2015-a34bf674/GRASS - 2008-c5c56a43.ipch -------------------------------------------------------------------------------- /licence.txt: -------------------------------------------------------------------------------- 1 |  2 | Apache License 3 | Version 2.0, January 2004 4 | 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, and 12 | distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 15 | owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all other entities 18 | that control, are controlled by, or are under common control with that entity. 19 | For the purposes of this definition, "control" means (i) the power, direct or 20 | indirect, to cause the direction or management of such entity, whether by 21 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity exercising 25 | permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, including 28 | but not limited to software source code, documentation source, and configuration 29 | files. 30 | 31 | "Object" form shall mean any form resulting from mechanical transformation or 32 | translation of a Source form, including but not limited to compiled object code, 33 | generated documentation, and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or Object form, made 36 | available under the License, as indicated by a copyright notice that is included 37 | in or attached to the work (an example is provided in the Appendix below). 38 | 39 | "Derivative Works" shall mean any work, whether in Source or Object form, that 40 | is based on (or derived from) the Work and for which the editorial revisions, 41 | annotations, elaborations, or other modifications represent, as a whole, an 42 | original work of authorship. For the purposes of this License, Derivative Works 43 | shall not include works that remain separable from, or merely link (or bind by 44 | name) to the interfaces of, the Work and Derivative Works thereof. 45 | 46 | "Contribution" shall mean any work of authorship, including the original version 47 | of the Work and any modifications or additions to that Work or Derivative Works 48 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 49 | by the copyright owner or by an individual or Legal Entity authorized to submit 50 | on behalf of the copyright owner. For the purposes of this definition, 51 | "submitted" means any form of electronic, verbal, or written communication sent 52 | to the Licensor or its representatives, including but not limited to 53 | communication on electronic mailing lists, source code control systems, and 54 | issue tracking systems that are managed by, or on behalf of, the Licensor for 55 | the purpose of discussing and improving the Work, but excluding communication 56 | that is conspicuously marked or otherwise designated in writing by the copyright 57 | owner as "Not a Contribution." 58 | 59 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 60 | of whom a Contribution has been received by Licensor and subsequently 61 | incorporated within the Work. 62 | 63 | 2. Grant of Copyright License. Subject to the terms and conditions of this 64 | License, each Contributor hereby grants to You a perpetual, worldwide, 65 | non-exclusive, no-charge, royalty-free, irrevocable copyright license to 66 | reproduce, prepare Derivative Works of, publicly display, publicly perform, 67 | sublicense, and distribute the Work and such Derivative Works in Source or 68 | Object form. 69 | 70 | 3. Grant of Patent License. Subject to the terms and conditions of this License, 71 | each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, 72 | no-charge, royalty-free, irrevocable (except as stated in this section) patent 73 | license to make, have made, use, offer to sell, sell, import, and otherwise 74 | transfer the Work, where such license applies only to those patent claims 75 | licensable by such Contributor that are necessarily infringed by their 76 | Contribution(s) alone or by combination of their Contribution(s) with the Work 77 | to which such Contribution(s) was submitted. If You institute patent litigation 78 | against any entity (including a cross-claim or counterclaim in a lawsuit) 79 | alleging that the Work or a Contribution incorporated within the Work 80 | constitutes direct or contributory patent infringement, then any patent licenses 81 | granted to You under this License for that Work shall terminate as of the date 82 | such litigation is filed. 83 | 84 | 4. Redistribution. You may reproduce and distribute copies of the Work or 85 | Derivative Works thereof in any medium, with or without modifications, and in 86 | Source or Object form, provided that You meet the following conditions: 87 | You must give any other recipients of the Work or Derivative Works a copy of 88 | this License; and 89 | 90 | 91 | You must cause any modified files to carry prominent notices stating that You 92 | changed the files; and 93 | 94 | 95 | You must retain, in the Source form of any Derivative Works that You 96 | distribute, all copyright, patent, trademark, and attribution notices from the 97 | Source form of the Work, excluding those notices that do not pertain to any 98 | part of the Derivative Works; and 99 | 100 | 101 | If the Work includes a "NOTICE" text file as part of its distribution, then 102 | any Derivative Works that You distribute must include a readable copy of the 103 | attribution notices contained within such NOTICE file, excluding those notices 104 | that do not pertain to any part of the Derivative Works, in at least one of 105 | the following places: within a NOTICE text file distributed as part of the 106 | Derivative Works; within the Source form or documentation, if provided along 107 | with the Derivative Works; or, within a display generated by the Derivative 108 | Works, if and wherever such third-party notices normally appear. The contents 109 | of the NOTICE file are for informational purposes only and do not modify the 110 | License. You may add Your own attribution notices within Derivative Works that 111 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 112 | provided that such additional attribution notices cannot be construed as 113 | modifying the License. 114 | You may add Your own copyright statement to Your modifications and may provide 115 | additional or different license terms and conditions for use, reproduction, or 116 | distribution of Your modifications, or for any such Derivative Works as a whole, 117 | provided Your use, reproduction, and distribution of the Work otherwise complies 118 | with the conditions stated in this License. 119 | 120 | 5. Submission of Contributions. Unless You explicitly state otherwise, any 121 | Contribution intentionally submitted for inclusion in the Work by You to the 122 | Licensor shall be under the terms and conditions of this License, without any 123 | additional terms or conditions. Notwithstanding the above, nothing herein shall 124 | supersede or modify the terms of any separate license agreement you may have 125 | executed with Licensor regarding such Contributions. 126 | 127 | 6. Trademarks. This License does not grant permission to use the trade names, 128 | trademarks, service marks, or product names of the Licensor, except as required 129 | for reasonable and customary use in describing the origin of the Work and 130 | reproducing the content of the NOTICE file. 131 | 132 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in 133 | writing, Licensor provides the Work (and each Contributor provides its 134 | Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 135 | KIND, either express or implied, including, without limitation, any warranties 136 | or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 137 | PARTICULAR PURPOSE. You are solely responsible for determining the 138 | appropriateness of using or redistributing the Work and assume any risks 139 | associated with Your exercise of permissions under this License. 140 | 141 | 8. Limitation of Liability. In no event and under no legal theory, whether in 142 | tort (including negligence), contract, or otherwise, unless required by 143 | applicable law (such as deliberate and grossly negligent acts) or agreed to in 144 | writing, shall any Contributor be liable to You for damages, including any 145 | direct, indirect, special, incidental, or consequential damages of any character 146 | arising as a result of this License or out of the use or inability to use the 147 | Work (including but not limited to damages for loss of goodwill, work stoppage, 148 | computer failure or malfunction, or any and all other commercial damages or 149 | losses), even if such Contributor has been advised of the possibility of such 150 | damages. 151 | 152 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or 153 | Derivative Works thereof, You may choose to offer, and charge a fee for, 154 | acceptance of support, warranty, indemnity, or other liability obligations 155 | and/or rights consistent with this License. However, in accepting such 156 | obligations, You may act only on Your own behalf and on Your sole 157 | responsibility, not on behalf of any other Contributor, and only if You agree to 158 | indemnify, defend, and hold each Contributor harmless for any liability incurred 159 | by, or claims asserted against, such Contributor by reason of your accepting any 160 | such warranty or additional liability. 161 | 162 | END OF TERMS AND CONDITIONS 163 | 164 | APPENDIX: How to apply the Apache License to your work 165 | 166 | To apply the Apache License to your work, attach the following boilerplate 167 | notice, with the fields enclosed by brackets "[]" replaced with your own 168 | identifying information. (Don't include the brackets!) The text should be 169 | enclosed in the appropriate comment syntax for the file format. We also 170 | recommend that a file or class name and description of purpose be included on 171 | the same "printed page" as the copyright notice for easier identification within 172 | third-party archives. 173 | 174 | Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, 175 | Version 2.0 (the "License"); you may not use this file except in compliance with 176 | the License. You may obtain a copy of the License at 177 | http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or 178 | agreed to in writing, software distributed under the License is distributed on 179 | an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 180 | or implied. See the License for the specific language governing permissions and 181 | limitations under the License. 182 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | 7 | #include "FrameWork/DX10Base.h" 8 | #include "Grass.h" 9 | 10 | Grass app; 11 | //DX10Base app; 12 | 13 | int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) 14 | { 15 | // Enable run-time memory check for debug builds. 16 | #if defined(DEBUG) | defined(_DEBUG) 17 | _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 18 | #endif 19 | app.Run(); 20 | } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 5 | ///////////////////////////////////////////////////////////////////////////////////////////// 6 | //{{NO_DEPENDENCIES}} 7 | // Microsoft Visual C++ generated include file. 8 | // Used by EmptyProject10.rc 9 | // 10 | #define IDI_MAIN_ICON 101 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 113 17 | #define _APS_NEXT_COMMAND_VALUE 40029 18 | #define _APS_NEXT_CONTROL_VALUE 1000 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /texture/GRASS_GROUND.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/GRASS_GROUND.dds -------------------------------------------------------------------------------- /texture/cubemap-evul.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/cubemap-evul.dds -------------------------------------------------------------------------------- /texture/grass.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/grass.dds -------------------------------------------------------------------------------- /texture/grassY.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/grassY.dds -------------------------------------------------------------------------------- /texture/grass_turf.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/grass_turf.dds -------------------------------------------------------------------------------- /texture/grasssm.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/grasssm.dds -------------------------------------------------------------------------------- /texture/grasssm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/grasssm.jpg -------------------------------------------------------------------------------- /texture/grasssm1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/grasssm1.jpg -------------------------------------------------------------------------------- /texture/seafloor.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/seafloor.dds -------------------------------------------------------------------------------- /texture/tree01s.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/tree01s.dds -------------------------------------------------------------------------------- /texture/tree02s.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/tree02s.dds -------------------------------------------------------------------------------- /texture/tree35s.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GameTechDev/GrassInstancing/c2b5c1b3e214831ac30a9b4833d1a84e96adafab/texture/tree35s.dds --------------------------------------------------------------------------------