Added color gradient for the terrain blend maps

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...
This commit is contained in:
iDunnoDev
2022-05-04 14:09:59 +01:00
committed by iDunnoDev
parent 7a57c73ac3
commit bc906064e5
15 changed files with 597 additions and 254 deletions

View File

@ -1,15 +1,31 @@
#pragma once
#include "DirectXFramework.h"
#include <fstream>
#include <vector>
#include "ColorGradient.h"
#include "DDSTextureLoader.h"
#include "WICTextureLoader.h"
#include "SharedMethods.h"
#include "SceneNode.h"
#include "Vector3D.h"
typedef struct TerrainVertex
{
XMFLOAT3 Position;
XMFLOAT3 Normal;
XMFLOAT2 TexCoord;
XMFLOAT2 BlendMapTexCoord;
} TerrainVertex;
class TerrainNode : public SceneNode
{
public:
TerrainNode(wstring name, wstring heightMap, int widthX = 1023, int widthZ = 1023, int rows = 10, int cols = 10);
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);
@ -19,14 +35,16 @@ private:
int _widthX;
int _widthZ;
UINT _gridRows;
UINT _gridCols;
unsigned int _gridRows;
unsigned int _gridCols;
int _cellSizeX;
int _cellSizeZ;
bool _usedHeightMap;
float _waterHeight;
UINT _polygonsCount;
UINT _indiciesCount;
UINT _vertexCount;
@ -37,12 +55,12 @@ private:
float _terrainEndZ;
wstring _heightMap;
wstring _textureName;
wstring _seedString;
unsigned int _seedHash;
vector<VERTEX> _terrainVerts;
vector<TerrainVertex> _terrainVerts;
vector<int> _indices;
vector<float> _heightValues;
vector<Vector3D> _terrainNormals;
XMFLOAT4 _ambientLight;
XMFLOAT4 _directionalLightVector;
@ -62,24 +80,31 @@ private:
ComPtr<ID3D11InputLayout> _layout;
ComPtr<ID3D11Buffer> _constantBuffer;
ComPtr<ID3D11ShaderResourceView> _texture;
ComPtr<ID3D11BlendState> _transparentBlendState;
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 BuildBlendState();
void BuildRendererStates();
void BuildTexture();
void LoadTerrainTextures();
void GenerateBlendMap();
bool LoadHeightMap(wstring heightMapFilename);
float GetHeightMapValueAt(int index);
void AddNormalToVertex(int row, int col, int vertexIndex, Vector3D normal);
void AddNormalToVertex(int row, int col, int vertexIndex, XMVECTOR normal);
void BuildExtraMaps();
};