
Added terrainBuffer struct Added shared methods to genereate random UV's and intensities Added water to the terrain Added random UV's to the shader Removed the vector3d class since DX can deal with that stuff...
111 lines
2.7 KiB
C++
111 lines
2.7 KiB
C++
#pragma once
|
|
#include "DirectXFramework.h"
|
|
#include <fstream>
|
|
#include <vector>
|
|
#include "ColorGradient.h"
|
|
#include "DDSTextureLoader.h"
|
|
#include "WICTextureLoader.h"
|
|
#include "SharedMethods.h"
|
|
#include "SceneNode.h"
|
|
|
|
|
|
typedef struct TerrainVertex
|
|
{
|
|
XMFLOAT3 Position;
|
|
XMFLOAT3 Normal;
|
|
XMFLOAT2 TexCoord;
|
|
XMFLOAT2 BlendMapTexCoord;
|
|
} TerrainVertex;
|
|
|
|
class TerrainNode : public SceneNode
|
|
{
|
|
public:
|
|
TerrainNode(wstring name, wstring heightMap, wstring seed, float waterHeight = 150.0f, wstring waterNormalMap = L"Textures\\waterNormals.bmp", int widthX = 1023, int widthZ = 1023, int cellSizeX = 10, int cellSizeZ = 10);
|
|
|
|
void SetAmbientLight(XMFLOAT4 ambientLight);
|
|
void SetWaterColor(XMFLOAT4 waterColor);
|
|
void SetDirectionalLight(FXMVECTOR lightVector, XMFLOAT4 lightColor);
|
|
void SetCameraPosition(XMFLOAT4 cameraPosition);
|
|
|
|
bool Initialise(void);
|
|
void Render(void);
|
|
void Shutdown(void);
|
|
|
|
private:
|
|
int _widthX;
|
|
int _widthZ;
|
|
|
|
unsigned int _gridRows;
|
|
unsigned int _gridCols;
|
|
|
|
int _cellSizeX;
|
|
int _cellSizeZ;
|
|
|
|
bool _usedHeightMap;
|
|
|
|
float _waterHeight;
|
|
|
|
UINT _polygonsCount;
|
|
UINT _indiciesCount;
|
|
UINT _vertexCount;
|
|
|
|
float _terrainStartX;
|
|
float _terrainStartZ;
|
|
float _terrainEndX;
|
|
float _terrainEndZ;
|
|
|
|
wstring _heightMap;
|
|
wstring _seedString;
|
|
unsigned int _seedHash;
|
|
|
|
vector<TerrainVertex> _terrainVerts;
|
|
vector<int> _indices;
|
|
vector<float> _heightValues;
|
|
|
|
XMFLOAT4 _ambientLight;
|
|
XMFLOAT4 _directionalLightVector;
|
|
XMFLOAT4 _directionalLightColor;
|
|
XMFLOAT4 _cameraPosition;
|
|
|
|
ComPtr<ID3D11Device> _device;
|
|
ComPtr<ID3D11DeviceContext> _deviceContext;
|
|
|
|
ComPtr<ID3D11Buffer> _vertexBuffer;
|
|
ComPtr<ID3D11Buffer> _indexBuffer;
|
|
|
|
ComPtr<ID3DBlob> _vertexShaderByteCode = nullptr;
|
|
ComPtr<ID3DBlob> _pixelShaderByteCode = nullptr;
|
|
ComPtr<ID3D11VertexShader> _vertexShader;
|
|
ComPtr<ID3D11PixelShader> _pixelShader;
|
|
ComPtr<ID3D11InputLayout> _layout;
|
|
ComPtr<ID3D11Buffer> _constantBuffer;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> _texturesResourceView;
|
|
ComPtr<ID3D11ShaderResourceView> _blendMapResourceView;
|
|
|
|
ComPtr<ID3D11RasterizerState> _defaultRasteriserState;
|
|
ComPtr<ID3D11RasterizerState> _wireframeRasteriserState;
|
|
|
|
ComPtr<ID3D11ShaderResourceView> _rngNoiseMap;
|
|
ComPtr<ID3D11ShaderResourceView> _waterNormalMap;
|
|
wstring _waterNormalMapName;
|
|
XMFLOAT4 _waterColor;
|
|
|
|
void GenerateTerrainData();
|
|
void GenerateBuffers();
|
|
void BuildShaders();
|
|
void BuildVertexLayout();
|
|
void BuildConstantBuffer();
|
|
void BuildRendererStates();
|
|
|
|
void LoadTerrainTextures();
|
|
void GenerateBlendMap();
|
|
|
|
bool LoadHeightMap(wstring heightMapFilename);
|
|
float GetHeightMapValueAt(int index);
|
|
|
|
void AddNormalToVertex(int row, int col, int vertexIndex, XMVECTOR normal);
|
|
void BuildExtraMaps();
|
|
};
|
|
|