Merge branch 'RendererImprovement'

This commit is contained in:
Nils Gaitzsch 2020-01-14 18:06:05 +01:00
commit 3f7a5794fe
25 changed files with 654 additions and 284 deletions

BIN
Build/D3DX11d_43.pdb Normal file

Binary file not shown.

BIN
Build/DX11_PS_HUD.cso Normal file

Binary file not shown.

35
Build/Shaders/DX11_HUD.fx Normal file
View file

@ -0,0 +1,35 @@
cbuffer HUDBuffer : register(b0)
{
float4x4 ViewProjection;
};
struct VertexShaderInput
{
float3 Position: POSITION;
float3 Normal: NORMAL;
float2 UV: TEXCOORD;
float4 Color: COLOR;
float Bone : BLENDINDICES;
};
struct PixelShaderInput
{
float4 Position: SV_POSITION;
float2 UV: TEXCOORD;
float4 Color: COLOR;
};
PixelShaderInput VS(VertexShaderInput input)
{
PixelShaderInput output;
output.Position = mul(float4(input.Position, 1.0f), ViewProjection);
output.Color = input.Color;
output.UV = input.UV;
return output;
}
half4 PS(PixelShaderInput input) : SV_TARGET
{
return input.Color;
}

View file

@ -0,0 +1,19 @@
struct PixelShaderInput
{
float4 Position: SV_POSITION;
float2 UV: TEXCOORD;
float4 Color: COLOR;
};
Texture2D Texture : register(t0);
SamplerState Sampler : register(s0);
half4 PSColored(PixelShaderInput input) : SV_TARGET
{
return input.Color;
}
half4 PSTextured(PixelShaderInput input) : SV_TARGET
{
float4 output = Texture.Sample(Sampler, input.UV);
return output;
}

View file

@ -0,0 +1,41 @@
cbuffer HUDBarBuffer : register(b0)
{
float Percent;
};
struct PixelShaderInput
{
float4 Position: SV_POSITION;
float2 UV: TEXCOORD;
float4 Color: COLOR;
};
Texture2D Texture : register(t0);
SamplerState Sampler : register(s0);
half4 glassOverlay(float2 UVs, half4 originalColor) {
float y = UVs.y;
y -= 0.15f;
y = distance(0.1f, y);
y = 1 - y;
y = pow(y, 4);
y = saturate(y);
half4 color = originalColor;
return saturate(lerp(color, (color * 1.6f)+half4(0.4f, 0.4f, 0.4f, 0.0f), y));
}
half4 PSColored(PixelShaderInput input) : SV_TARGET
{
if (input.UV.x > Percent) {
discard;
}
return glassOverlay(input.UV,input.Color);
}
half4 PSTextured(PixelShaderInput input) : SV_TARGET
{
if (input.UV.x > Percent) {
discard;
}
float4 color = Texture.Sample(Sampler, input.UV);
return glassOverlay(input.UV, color);
}

View file

@ -0,0 +1,31 @@
cbuffer HUDBuffer : register(b0)
{
float4x4 View;
float4x4 Projection;
};
struct VertexShaderInput
{
float3 Position: POSITION;
float3 Normal: NORMAL;
float2 UV: TEXCOORD;
float4 Color: COLOR;
float Bone : BLENDINDICES;
};
struct PixelShaderInput
{
float4 Position: SV_POSITION;
float2 UV: TEXCOORD;
float4 Color: COLOR;
};
PixelShaderInput VS(VertexShaderInput input)
{
PixelShaderInput output;
output.Position = mul(mul(float4(input.Position, 1.0f), View),Projection);
output.Color = input.Color;
output.UV = input.UV;
return output;
}

BIN
Build/bar_border.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

BIN
Build/savegame.0 Normal file

Binary file not shown.

View file

@ -14,7 +14,9 @@ int FlashState = 0;
int FlashCount = 0;
int PoisonFlag = 0;
int DashTimer = 0;
extern RendererHUDBar* g_HealthBar;
extern RendererHUDBar* g_DashBar;
extern RendererHUDBar* g_AirBar;
extern LaraExtraInfo g_LaraExtra;
void DrawHealthBarOverlay(int value)
@ -26,20 +28,20 @@ void DrawHealthBarOverlay(int value)
color2 = 0xA0A000;
else
color2 = 0xA00000;
g_Renderer->DrawBar(245, 32, 150, 12, value, 0xA00000, color2);
g_Renderer->DrawBar(value, g_HealthBar);
}
}
void DrawHealthBar(int value)
void DrawHealthBar(float value)
{
if (CurrentLevel)
{
int color2;
if (Lara.poisoned || Lara.gassed)
color2 = 0xA0A000;
else
color2 = 0xA00000;
g_Renderer->DrawBar(20, 32, 150, 12, value, 0xA00000, color2);
//int color2;
//if (Lara.poisoned || Lara.gassed)
// color2 = 0xA0A000;
//else
// color2 = 0xA00000;
g_Renderer->DrawBar(value,g_HealthBar);
}
}
@ -66,14 +68,14 @@ void UpdateHealtBar(int flash)
if (!BinocularRange)
{
if (flash)
DrawHealthBar(hitPoints / 10);
DrawHealthBar(hitPoints / 1000.0f);
else
DrawHealthBar(0);
}
else
{
if (flash)
DrawHealthBarOverlay(hitPoints / 10);
DrawHealthBarOverlay(hitPoints / 1000.0f);
else
DrawHealthBarOverlay(0);
}
@ -85,11 +87,11 @@ void UpdateHealtBar(int flash)
{
if (!BinocularRange && !SniperOverlay)
{
DrawHealthBar(hitPoints / 10);
DrawHealthBar(hitPoints / 1000.0f);
}
else
{
DrawHealthBarOverlay(hitPoints / 10);
DrawHealthBarOverlay(hitPoints / 1000.0f);
}
}
@ -97,11 +99,11 @@ void UpdateHealtBar(int flash)
PoisonFlag--;
}
void DrawAirBar(int value)
void DrawAirBar(float value)
{
if (CurrentLevel)
{
g_Renderer->DrawBar(20, 10, 150, 12, value, 0x0000A0, 0x0050A0);
g_Renderer->DrawBar(value, g_AirBar);
}
}
@ -128,12 +130,12 @@ void UpdateAirBar(int flash)
if (air <= 450)
{
if (flash)
DrawAirBar((air * 100) / 1800);
DrawAirBar(air/ 1800.0f);
else
DrawAirBar(0);
}
else
DrawAirBar((air * 100) / 1800);
DrawAirBar(air / 1800.0f);
if (Lara.gassed)
{
@ -147,7 +149,7 @@ void DrawDashBar(int value)
{
if (CurrentLevel)
{
g_Renderer->DrawBar(630, 32, 150, 12, value, 0xA0A000, 0x00A000);
g_Renderer->DrawBar(value, g_DashBar);
}
}

View file

@ -5,9 +5,9 @@
#define MAX_COLLECTED_PICKUPS 32
void DrawHealthBarOverlay(int value);
void DrawHealthBar(int value);
void DrawHealthBar(float value);
void UpdateHealtBar(int flash);
void DrawAirBar(int value);
void DrawAirBar(float value);
void UpdateAirBar(int flash);
void DrawDashBar(int value);
void AddDisplayPickup(short objectNumber);

View file

@ -81,11 +81,11 @@ void Renderer11::updateAnimatedTextures()
for (int p = 0; p < bucket->Polygons.size(); p++)
{
RendererPolygon* polygon = &bucket->Polygons[p];
RendererAnimatedTextureSet* set = m_animatedTextureSets[polygon->AnimatedSet];
RendererAnimatedTextureSet& const set = m_animatedTextureSets[polygon->AnimatedSet];
int textureIndex = -1;
for (int j = 0; j < set->NumTextures; j++)
for (int j = 0; j < set.NumTextures; j++)
{
if (set->Textures[j]->Id == polygon->TextureId)
if (set.Textures[j].Id == polygon->TextureId)
{
textureIndex = j;
break;
@ -94,17 +94,17 @@ void Renderer11::updateAnimatedTextures()
if (textureIndex == -1)
continue;
if (textureIndex == set->NumTextures - 1)
if (textureIndex == set.NumTextures - 1)
textureIndex = 0;
else
textureIndex++;
polygon->TextureId = set->Textures[textureIndex]->Id;
polygon->TextureId = set.Textures[textureIndex].Id;
for (int v = 0; v < (polygon->Shape == SHAPE_RECTANGLE ? 4 : 3); v++)
{
bucket->Vertices[polygon->Indices[v]].UV.x = set->Textures[textureIndex]->UV[v].x;
bucket->Vertices[polygon->Indices[v]].UV.y = set->Textures[textureIndex]->UV[v].y;
bucket->Vertices[polygon->Indices[v]].UV.x = set.Textures[textureIndex].UV[v].x;
bucket->Vertices[polygon->Indices[v]].UV.y = set.Textures[textureIndex].UV[v].y;
}
}
}
@ -668,10 +668,10 @@ int Renderer11::getAnimatedTextureInfo(short textureId)
{
for (int i = 0; i < m_numAnimatedTextureSets; i++)
{
RendererAnimatedTextureSet* set = m_animatedTextureSets[i];
for (int j = 0; j < set->NumTextures; j++)
RendererAnimatedTextureSet& const set = m_animatedTextureSets[i];
for (int j = 0; j < set.NumTextures; j++)
{
if (set->Textures[j]->Id == textureId)
if (set.Textures[j].Id == textureId)
return i;
}
}

View file

@ -102,20 +102,12 @@ void Renderer11::FreeRendererData()
DX11_DELETE(m_sprites[i]);
free(m_sprites);
for (int i = 0; i < ID_NUMBER_OBJECTS; i++)
DX11_DELETE(m_spriteSequences[i]);
free(m_spriteSequences);
for (int i = 0; i < NUM_STATICS; i++)
DX11_DELETE(m_staticObjects[i]);
free(m_staticObjects);
m_rooms.clear();
for (int i = 0; i < m_numAnimatedTextureSets; i++)
DX11_DELETE(m_animatedTextureSets[i]);
free(m_animatedTextureSets);
DX11_DELETE(m_textureAtlas);
DX11_DELETE(m_skyTexture);
DX11_DELETE(m_roomsVertexBuffer);
@ -165,8 +157,8 @@ ID3D11VertexShader* Renderer11::compileVertexShader(const char* fileName, const
ID3DBlob* errors = NULL;
printf("Compiling vertex shader: %s\n", fileName);
res = D3DX11CompileFromFileA(fileName, NULL, NULL, function, model, D3D10_SHADER_OPTIMIZATION_LEVEL3, 0, NULL, bytecode, &errors, NULL);
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG;
res = D3DX11CompileFromFileA(fileName, NULL, NULL, function, model, flags, 0, NULL, bytecode, &errors, NULL);
if (FAILED(res))
{
printf("Compilation failed: %s\n", errors->GetBufferPointer());
@ -189,8 +181,8 @@ ID3D11PixelShader* Renderer11::compilePixelShader(const char* fileName, const ch
ID3DBlob* errors = NULL;
printf("Compiling pixel shader: %s\n", fileName);
res = D3DX11CompileFromFileA(fileName, NULL, NULL, function, model, D3D10_SHADER_OPTIMIZATION_LEVEL3, 0, NULL, bytecode, &errors, NULL);
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG;
res = D3DX11CompileFromFileA(fileName, NULL, NULL, function, model, flags, 0, NULL, bytecode, &errors, NULL);
if (FAILED(res))
{
printf("Compilation failed: %s\n", errors->GetBufferPointer());
@ -256,7 +248,7 @@ ID3D11Buffer* Renderer11::createConstantBuffer(int size)
D3D11_BUFFER_DESC desc;
ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));
desc.ByteWidth = ceil(size / 16) * 16; // Constant buffer must have a size multiple of 16 bytes
desc.ByteWidth = ceil(size / 16.0f) * 16; // Constant buffer must have a size multiple of 16 bytes
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
@ -271,3 +263,129 @@ ID3D11Buffer* Renderer11::createConstantBuffer(int size)
RendererHUDBar::RendererHUDBar(ID3D11Device* m_device,int x, int y, int w, int h, int borderSize, array<Vector4,9> colors)
{
array<Vector3, 9> barVertices = {
Vector3(x, HUD_ZERO_Y +y, 0.5),
Vector3(x + (w / 2.0f), HUD_ZERO_Y + y, 0.5),
Vector3(x + w, HUD_ZERO_Y + y, 0.5),
Vector3(x, HUD_ZERO_Y + (y + h / 2.0f), 0.5),
Vector3(x + (w / 2.0f), HUD_ZERO_Y + (y + h / 2.0f), 0.5),
Vector3(x + w, HUD_ZERO_Y + (y + h / 2.0f), 0.5),
Vector3(x, HUD_ZERO_Y + y + h, 0.5),
Vector3(x + (w / 2.0f), HUD_ZERO_Y + y + h, 0.5),
Vector3(x + w, HUD_ZERO_Y + y + h, 0.5),
};
const float HUD_BORDER_WIDTH = borderSize * (REFERENCE_RES_WIDTH/ REFERENCE_RES_HEIGHT);
const float HUD_BORDER_HEIGT = borderSize;
array<Vector3, 16> barBorderVertices = {
//top left
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y+y - HUD_BORDER_HEIGT,0),
Vector3(x ,HUD_ZERO_Y+y - HUD_BORDER_HEIGT,0),
Vector3(x ,HUD_ZERO_Y+y,0),
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y+y,0),
//top right
Vector3(x + w ,HUD_ZERO_Y+y - HUD_BORDER_HEIGT,0),
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y+y - HUD_BORDER_HEIGT,0),
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y+y,0),
Vector3(x + w ,HUD_ZERO_Y+y,0),
//bottom right
Vector3(x + w ,HUD_ZERO_Y+y + h,0),
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y+y + h,0),
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y+y + h + HUD_BORDER_HEIGT,0),
Vector3(x + w ,HUD_ZERO_Y+y + h + HUD_BORDER_HEIGT,0),
//bottom left
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y+y + h,0),
Vector3(x ,HUD_ZERO_Y+y + h,0),
Vector3(x ,HUD_ZERO_Y+y + h + HUD_BORDER_HEIGT,0),
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y+y + h + HUD_BORDER_HEIGT,0)
};
array<Vector2, 9> barUVs = {
Vector2(0,0),
Vector2(0.5,0),
Vector2(1,0),
Vector2(0,0.5),
Vector2(0.5,0.5),
Vector2(1,0.5),
Vector2(0,1),
Vector2(0.5,1),
Vector2(1,1),
};
array<Vector2, 16> barBorderUVs = {
//top left
Vector2(0,0),
Vector2(0.25,0),
Vector2(0.25,0.25),
Vector2(0,0.25),
//top right
Vector2(0.75,0),
Vector2(1,0),
Vector2(1,0.25),
Vector2(0.75,0.25),
//bottom right
Vector2(0.75,0.75),
Vector2(1,0.75),
Vector2(1,1),
Vector2(0.75,1),
//bottom left
Vector2(0,0.75),
Vector2(0.25,0.75),
Vector2(0.25,1),
Vector2(0,1),
};
array<int, 24> barIndices = {
0,1,3,1,4,3,
//
1,2,4,2,5,4,
//
3,4,6,4,7,6,
//
4,5,7,5,8,7
};
array<int, 56> barBorderIndices = {
//top left
0,1,3,1,2,3,
//top center
1,4,2,4,7,2,
//top right
4,5,7,5,6,7,
//right
7,6,8,6,9,8,
//bottom right
8,9,11,9,10,11,
//bottom
13,8,14,8,11,14,
//bottom left
12,13,15,13,14,15,
//left
3,2,12,2,13,12,
//center
2,7,13,7,8,13
};
array<RendererVertex, 9> vertices;
for (int i = 0; i < 9; i++) {
vertices[i].Position = barVertices[i];
vertices[i].Color = colors[i];
vertices[i].UV = barUVs[i];
vertices[i].Normal = Vector3(0, 0, 0);
vertices[i].Bone = 0.0f;
}
vertexBuffer = VertexBuffer::Create(m_device, vertices.size(), vertices.data());
indexBuffer = IndexBuffer::Create(m_device, barIndices.size(), barIndices.data());
array<RendererVertex, barBorderVertices.size()> verticesBorder;
for (int i = 0; i < barBorderVertices.size(); i++) {
verticesBorder[i].Position = barBorderVertices[i];
verticesBorder[i].Color = Vector4(1, 1, 1, 1);
verticesBorder[i].UV = barBorderUVs[i];
verticesBorder[i].Normal = Vector3(0, 0, 0);
verticesBorder[i].Bone = 0.0f;
}
vertexBufferBorder = VertexBuffer::Create(m_device, verticesBorder.size(), verticesBorder.data());
indexBufferBorder = IndexBuffer::Create(m_device, barBorderIndices.size(), barBorderIndices.data());
}

View file

@ -27,154 +27,20 @@
#define DX11_RELEASE(x) if (x != NULL) x->Release()
#define DX11_DELETE(x) if (x != NULL) { delete x; x = NULL; }
constexpr int REFERENCE_RES_WIDTH = 800;
constexpr int REFERENCE_RES_HEIGHT = 450;
constexpr float HUD_UNIT_X = 1.0f / REFERENCE_RES_WIDTH;
constexpr float HUD_UNIT_Y = 1.0f / REFERENCE_RES_HEIGHT;
constexpr float HUD_ZERO_Y = -REFERENCE_RES_HEIGHT;
using namespace DirectX;
using namespace DirectX::SimpleMath;
using namespace std;
template <class T>
class PreallocatedVector
{
private:
T** m_objects;
int m_maxItems;
int m_numItems;
int m_startSize;
public:
PreallocatedVector()
{
m_objects = NULL;
m_maxItems = 0;
m_startSize = 0;
m_numItems = 0;
}
~PreallocatedVector()
{
}
inline void Reserve(int numItems)
{
m_objects = (T**)malloc(sizeof(T*) * numItems);
ZeroMemory(m_objects, sizeof(T*) * m_maxItems);
m_maxItems = numItems;
m_numItems = 0;
m_startSize = numItems;
}
inline void Clear()
{
m_numItems = 0;
ZeroMemory(m_objects, sizeof(T*) * m_maxItems);
}
inline int Size()
{
return m_numItems;
}
inline void Sort(int(*compareFunc)(T*, T*))
{
qsort(m_objects, m_numItems, sizeof(T), compareFunc);
}
inline T*& operator[] (int x) {
if (x >= m_maxItems)
return m_objects[0];
return m_objects[x];
}
inline void Add(T* value)
{
if (m_numItems >= m_maxItems)
return;
m_objects[m_numItems++] = value;
}
};
template <class T, class U>
class PreallocatedDictionary
{
private:
T** m_keys;
U** m_objects;
int m_maxItems;
int m_numItems;
int m_startSize;
public:
PreallocatedDictionary()
{
m_keys = NULL;
m_objects = NULL;
m_maxItems = 0;
m_startSize = 0;
m_numItems = 0;
}
~PreallocatedDictionary()
{
free(m_keys);
free(m_objects);
}
inline void Reserve(int numItems)
{
m_keys = (T**)malloc(sizeof(T*) * numItems);
m_objects = (U**)malloc(sizeof(U*) * numItems);
ZeroMemory(m_keys, sizeof(T*) * m_maxItems);
ZeroMemory(m_objects, sizeof(U*) * m_maxItems);
m_maxItems = numItems;
m_numItems = 0;
m_startSize = numItems;
}
inline void Clear()
{
m_numItems = 0;
ZeroMemory(m_keys, sizeof(T*) * m_maxItems);
ZeroMemory(m_objects, sizeof(T*) * m_maxItems);
}
inline int Size()
{
return m_numItems;
}
inline T*& operator[] (int x) {
return m_objects[x];
}
inline bool KeyExists(T* key)
{
for (int i = 0; i < m_numItems; i++)
if (m_keys[i] == key)
return true;
return false;
}
inline U* Get(T* key)
{
for (int i = 0; i < m_numItems; i++)
if (m_keys[i] == key)
return m_objects[i];
return NULL;
}
inline void Add(T* key, U* value)
{
m_keys[m_numItems] = key;
m_objects[m_numItems++] = value;
}
};
struct RendererDisplayMode {
int Width;
int Height;
int RefreshRate;
};
struct RendererVideoAdapter {
string Name;
int Index;
@ -475,6 +341,22 @@ public:
}
};
typedef struct RendererHUDBar {
VertexBuffer* vertexBufferBorder;
IndexBuffer* indexBufferBorder;
VertexBuffer* vertexBuffer;
IndexBuffer* indexBuffer;
/*
Initialises a new Bar for rendering. the Coordinates are set in the Reference Resolution (default 800x600).
The colors are setup like this
0-----------1-----------2
| | |
3-----------4-----------5
| | |
6-----------7-----------8
*/
RendererHUDBar(ID3D11Device* m_device, int x, int y, int w, int h, int borderSize, array<Vector4,9> colors);
};
struct RendererStringToDraw
{
float X;
@ -541,6 +423,13 @@ struct ShaderLight {
float Range;
};
struct CHUDBuffer {
Matrix View;
Matrix Projection;
};
struct CHUDBarBuffer {
float Percent;
};
struct CCameraMatrixBuffer
{
Matrix View;
@ -594,14 +483,7 @@ struct RendererAnimatedTexture
struct RendererAnimatedTextureSet
{
int NumTextures;
RendererAnimatedTexture** Textures;
~RendererAnimatedTextureSet()
{
for (int i = 0; i < NumTextures; i++)
delete Textures[i];
free(Textures);
}
vector<RendererAnimatedTexture> Textures;
};
struct RendererBucket
@ -635,7 +517,7 @@ struct RendererRoom
bool Visited;
float Distance;
int RoomNumber;
PreallocatedVector<RendererLight> LightsToDraw;
vector<RendererLight*> LightsToDraw;
};
struct RendererRoomNode {
@ -653,7 +535,7 @@ struct RendererItem {
Matrix Scale;
Matrix AnimationTransforms[32];
int NumMeshes;
PreallocatedVector<RendererLight> Lights;
vector<RendererLight*> Lights;
};
struct RendererMesh
@ -668,7 +550,7 @@ struct RendererEffect {
FX_INFO* Effect;
Matrix World;
RendererMesh* Mesh;
PreallocatedVector<RendererLight> Lights;
vector<RendererLight*> Lights;
};
struct RendererObject
@ -700,21 +582,33 @@ struct RendererSprite {
struct RendererSpriteSequence {
int Id;
RendererSprite** SpritesList;
vector<RendererSprite*> SpritesList;
int NumSprites;
RendererSpriteSequence()
{
}
RendererSpriteSequence(int id, int num)
{
Id = id;
NumSprites = num;
SpritesList = (RendererSprite**)malloc(sizeof(RendererSprite*) * num);
SpritesList = vector<RendererSprite*>(NumSprites);
}
~RendererSpriteSequence()
{
/*for (int i = 0; i < NumSprites; i++)
delete SpritesList[i];
free(SpritesList);*/
RendererSpriteSequence(const RendererSpriteSequence& rhs) {
Id = rhs.Id;
NumSprites = rhs.NumSprites;
SpritesList = rhs.SpritesList;
}
RendererSpriteSequence& operator=(const RendererSpriteSequence& other) {
if (this != &other) {
Id = other.Id;
NumSprites = other.NumSprites;
SpritesList = vector<RendererSprite*>(NumSprites);
std::copy(other.SpritesList.begin(), other.SpritesList.end(),back_inserter(SpritesList));
}
return *this;
}
};
@ -813,7 +707,10 @@ private:
ID3D11PixelShader* m_psFullScreenQuad;
ID3D11VertexShader* m_vsShadowMap;
ID3D11PixelShader* m_psShadowMap;
ID3D11VertexShader* m_vsHUD;
ID3D11PixelShader* m_psHUDColor;
ID3D11PixelShader* m_psHUDTexture;
ID3D11PixelShader* m_psHUDBarColor;
ID3D11ShaderResourceView* m_shadowMapRV;
ID3D11Texture2D* m_shadowMapTexture;
@ -835,7 +732,10 @@ private:
ID3D11Buffer* m_cbRoom;
CShadowLightBuffer m_stShadowMap;
ID3D11Buffer* m_cbShadowMap;
CHUDBuffer m_stHUD;
ID3D11Buffer* m_cbHUD;
CHUDBarBuffer m_stHUDBar;
ID3D11Buffer* m_cbHUDBar;
// Text and sprites
SpriteFont* m_gameFont;
SpriteBatch* m_spriteBatch;
@ -845,6 +745,7 @@ private:
PrimitiveBatch<RendererVertex>* m_primitiveBatch;
// System resources
Texture2D* m_HUDBarBorderTexture;
Texture2D* m_caustics[NUM_CAUSTICS_TEXTURES];
Texture2D* m_binocularsTexture;
Texture2D* m_whiteTexture;
@ -894,10 +795,10 @@ private:
int m_numStatics;
int m_numSprites;
int m_numSpritesSequences;
RendererSpriteSequence** m_spriteSequences;
vector<RendererSpriteSequence> m_spriteSequences;
unordered_map<unsigned int, RendererMesh*> m_meshPointersToMesh;
Matrix m_LaraWorldMatrix;
RendererAnimatedTextureSet** m_animatedTextureSets;
vector<RendererAnimatedTextureSet> m_animatedTextureSets;
int m_numAnimatedTextureSets;
int m_currentCausticsFrame;
RendererUnderwaterDustParticle m_underwaterDustParticles[NUM_UNDERWATER_DUST_PARTICLES];
@ -1011,7 +912,7 @@ private:
bool isInRoom(int x, int y, int z, short roomNumber);
bool drawColoredQuad(int x, int y, int w, int h, Vector4 color);
bool initialiseScreen(int w, int h, int refreshRate, bool windowed, HWND handle, bool reset);
bool initialiseBars();
public:
Matrix View;
Matrix Projection;
@ -1055,7 +956,7 @@ public:
void AddSprite3D(RendererSprite* sprite, Vector3 vtx1, Vector3 vtx2, Vector3 vtx3, Vector3 vtx4, Vector4 color, float rotation, float scale, float width, float height, BLEND_MODES blendMode);
void AddLine3D(Vector3 start, Vector3 end, Vector4 color);
bool ChangeScreenResolution(int width, int height, int frequency, bool windowed);
bool DrawBar(int x, int y, int w, int h, int percent, int color1, int color2);
bool DrawBar(float percent, const RendererHUDBar* const bar);
private:
void drawFootprints();
};

View file

@ -8,8 +8,7 @@ bool Renderer11::PrepareDataForTheRenderer()
m_moveableObjects = (RendererObject * *)malloc(sizeof(RendererObject*) * ID_NUMBER_OBJECTS);
ZeroMemory(m_moveableObjects, sizeof(RendererObject*) * ID_NUMBER_OBJECTS);
m_spriteSequences = (RendererSpriteSequence * *)malloc(sizeof(RendererSpriteSequence*) * ID_NUMBER_OBJECTS);
ZeroMemory(m_spriteSequences, sizeof(RendererSpriteSequence*) * ID_NUMBER_OBJECTS);
m_spriteSequences = vector<RendererSpriteSequence>(ID_NUMBER_OBJECTS);
m_staticObjects = (RendererObject * *)malloc(sizeof(RendererObject*) * NUM_STATICS);
ZeroMemory(m_staticObjects, sizeof(RendererObject*) * NUM_STATICS);
@ -23,17 +22,18 @@ bool Renderer11::PrepareDataForTheRenderer()
short* animatedPtr = AnimatedTextureRanges;
animatedPtr++;
m_animatedTextureSets = (RendererAnimatedTextureSet * *)malloc(sizeof(RendererAnimatedTextureSet*) * NUM_ANIMATED_SETS);
m_animatedTextureSets = vector<RendererAnimatedTextureSet>(NUM_ANIMATED_SETS);
m_numAnimatedTextureSets = numSets;
for (int i = 0; i < numSets; i++)
{
RendererAnimatedTextureSet* set = new RendererAnimatedTextureSet();
m_animatedTextureSets[i] = RendererAnimatedTextureSet();
RendererAnimatedTextureSet& const set = m_animatedTextureSets[i];
short numTextures = *animatedPtr + 1;
animatedPtr++;
set->Textures = (RendererAnimatedTexture * *)malloc(sizeof(RendererAnimatedTexture) * numTextures);
set->NumTextures = numTextures;
set.Textures = vector<RendererAnimatedTexture>(numTextures);
set.NumTextures = numTextures;
for (int j = 0; j < numTextures; j++)
{
@ -42,22 +42,19 @@ bool Renderer11::PrepareDataForTheRenderer()
OBJECT_TEXTURE* texture = &ObjectTextures[textureId];
int tile = texture->tileAndFlag & 0x7FFF;
RendererAnimatedTexture* newTexture = new RendererAnimatedTexture();
newTexture->Id = textureId;
set.Textures[j] = RendererAnimatedTexture();
RendererAnimatedTexture& const newTexture = set.Textures[j];
newTexture.Id = textureId;
for (int k = 0; k < 4; k++)
{
float x = (texture->vertices[k].x * 256.0f + 0.5f + GET_ATLAS_PAGE_X(tile)) / (float)TEXTURE_ATLAS_SIZE;
float y = (texture->vertices[k].y * 256.0f + 0.5f + GET_ATLAS_PAGE_Y(tile)) / (float)TEXTURE_ATLAS_SIZE;
newTexture->UV[k] = Vector2(x, y);
newTexture.UV[k] = Vector2(x, y);
}
set->Textures[j] = newTexture;
}
m_animatedTextureSets[i] = set;
}
// Step 1: create the texture atlas
@ -142,7 +139,7 @@ bool Renderer11::PrepareDataForTheRenderer()
r.RoomNumber = i;
r.Room = room;
r.AmbientLight = Vector4(room->ambient.b / 255.0f, room->ambient.g / 255.0f, room->ambient.r / 255.0f, 1.0f);
r.LightsToDraw.Reserve(32);
r.LightsToDraw = vector<RendererLight*>(MAX_LIGHTS);
r.Statics.resize(128);
if (room->NumVertices == 0)
@ -793,12 +790,12 @@ bool Renderer11::PrepareDataForTheRenderer()
{
short numSprites = abs(obj->nmeshes);
short baseSprite = obj->meshIndex;
RendererSpriteSequence* sequence = new RendererSpriteSequence(MoveablesIds[i], numSprites);
m_spriteSequences[MoveablesIds[i]] = RendererSpriteSequence(MoveablesIds[i], numSprites);
RendererSpriteSequence& sequence = m_spriteSequences[MoveablesIds[i]];
for (int j = baseSprite; j < baseSprite + numSprites; j++)
{
sequence->SpritesList[j - baseSprite] = m_sprites[j];
sequence.SpritesList[j - baseSprite] = m_sprites[j];
}
m_spriteSequences[MoveablesIds[i]] = sequence;

View file

@ -12,6 +12,9 @@
#include "../Game/rope.h"
#include "../Game/tomb4fx.h"
extern GUNSHELL_STRUCT Gunshells[MAX_GUNSHELL];
extern RendererHUDBar* g_DashBar;
extern RendererHUDBar* g_SFXVolumeBar;
extern RendererHUDBar* g_MusicVolumeBar;
int Renderer11::DrawPickup(short objectNum)
{
drawObjectOn2DPosition(700 + PickupX, 450, objectNum, 0, m_pickupRotation, 0); // TODO: + PickupY
@ -385,8 +388,8 @@ bool Renderer11::drawGunShells()
m_stItem.AmbientLight = room.AmbientLight;
memcpy(m_stItem.BonesMatrices, &Matrix::Identity, sizeof(Matrix));
m_stLights.NumLights = item->Lights.Size();
for (int j = 0; j < item->Lights.Size(); j++)
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
updateConstantBuffer(m_cbLights, &m_stLights, sizeof(CLightBuffer));
m_context->PSSetConstantBuffers(2, 1, &m_cbLights);
@ -847,7 +850,8 @@ int Renderer11::drawInventoryScene()
PrintString(200, y, g_GameFlow->GetString(STRING_MUSIC_VOLUME),
PRINTSTRING_COLOR_ORANGE,
PRINTSTRING_OUTLINE | (ring->selectedIndex == 2 ? PRINTSTRING_BLINK : 0));
DrawBar(400, y + 4, 150, 18, ring->Configuration.MusicVolume, 0x0000FF, 0x0000FF);
//DrawBar(400, y + 4, 150, 18, ring->Configuration.MusicVolume, 0x0000FF, 0x0000FF);
DrawBar(ring->Configuration.MusicVolume / 100.0f, g_MusicVolumeBar);
y += 25;
@ -855,8 +859,8 @@ int Renderer11::drawInventoryScene()
PrintString(200, y, g_GameFlow->GetString(STRING_SFX_VOLUME),
PRINTSTRING_COLOR_ORANGE,
PRINTSTRING_OUTLINE | (ring->selectedIndex == 3 ? PRINTSTRING_BLINK : 0));
DrawBar(400, y + 4, 150, 18, ring->Configuration.SfxVolume, 0x0000FF, 0x0000FF);
//DrawBar(400, y + 4, 150, 18, ring->Configuration.SfxVolume, 0x0000FF, 0x0000FF);
DrawBar(ring->Configuration.SfxVolume / 100.0f, g_SFXVolumeBar);
y += 25;
// Apply and cancel
@ -1099,8 +1103,8 @@ int Renderer11::drawInventoryScene()
if (g_Inventory->GetType() == INV_TYPE_TITLE && g_GameFlow->TitleType == TITLE_FLYBY && drawLogo)
{
// Draw main logo
float factorX = ScreenWidth / 800.0f;
float factorY = ScreenHeight / 600.0f;
float factorX = (float)ScreenWidth / REFERENCE_RES_WIDTH;
float factorY = (float)ScreenHeight / REFERENCE_RES_HEIGHT;
RECT rect;
rect.left = 250 * factorX;
@ -1328,7 +1332,6 @@ bool Renderer11::drawLines2D()
m_context->VSSetShader(m_vsSolid, NULL, 0);
m_context->PSSetShader(m_psSolid, NULL, 0);
Matrix world = Matrix::CreateOrthographicOffCenter(0, ScreenWidth, ScreenHeight, 0, m_viewport.MinDepth, m_viewport.MaxDepth);
m_stCameraMatrices.View = Matrix::Identity;
@ -1782,7 +1785,7 @@ void Renderer11::DrawLoadingScreen(char* fileName)
m_context->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
m_swapChain->Present(0, 0);
m_context->ClearState();
if (m_fadeStatus == RENDERER_FADE_STATUS::FADE_IN && m_fadeFactor >= 1.0f)
{
m_fadeStatus = RENDERER_FADE_STATUS::NO_FADE;
@ -2024,7 +2027,7 @@ bool Renderer11::drawScene(bool dump)
// Bars
int flash = FlashIt();
if (DashTimer < 120)
DrawBar(630, 32, 150, 12, 100 * (unsigned short)DashTimer / 120, 0xA0A000, 0xA000);
DrawBar(DashTimer / 120.0f, g_DashBar);
UpdateHealtBar(flash);
UpdateAirBar(flash);
DrawAllPickups();
@ -2165,8 +2168,8 @@ bool Renderer11::drawAnimatingItem(RendererItem* item, bool transparent, bool an
updateConstantBuffer(m_cbItem, &m_stItem, sizeof(CItemBuffer));
m_context->VSSetConstantBuffers(1, 1, &m_cbItem);
m_stLights.NumLights = item->Lights.Size();
for (int j = 0; j < item->Lights.Size(); j++)
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
updateConstantBuffer(m_cbLights, &m_stLights, sizeof(CLightBuffer));
m_context->PSSetConstantBuffers(2, 1, &m_cbLights);
@ -2339,8 +2342,8 @@ bool Renderer11::drawRooms(bool transparent, bool animated)
{
RendererRoom* room = m_roomsToDraw[i];
m_stLights.NumLights = room->LightsToDraw.Size();
for (int j = 0; j < room->LightsToDraw.Size(); j++)
m_stLights.NumLights = room->LightsToDraw.size();
for (int j = 0; j < room->LightsToDraw.size(); j++)
memcpy(&m_stLights.Lights[j], room->LightsToDraw[j], sizeof(ShaderLight));
updateConstantBuffer(m_cbLights, &m_stLights, sizeof(CLightBuffer));
m_context->PSSetConstantBuffers(1, 1, &m_cbLights);

View file

@ -1,35 +1,116 @@
#include "Renderer11.h"
bool Renderer11::DrawBar(int x, int y, int w, int h, int percent, int color1, int color2)
RendererHUDBar* g_HealthBar;
RendererHUDBar* g_AirBar;
RendererHUDBar* g_DashBar;
RendererHUDBar* g_MusicVolumeBar;
RendererHUDBar* g_SFXVolumeBar;
bool Renderer11::initialiseBars()
{
byte r1 = (color1 >> 16) & 0xFF;
byte g1 = (color1 >> 8) & 0xFF;
byte b1 = (color1 >> 0) & 0xFF;
array<Vector4, 9> healthColors = {
//top
Vector4(82 / 255.0f,0,0,1),
Vector4(36 / 255.0f,46 / 255.0f,0,1),
Vector4(0,82 / 255.0f,0,1),
//center
Vector4(159 / 255.0f,0,0,1),
Vector4(78 / 255.0f,81 / 255.0f,0,1),
Vector4(0,158 / 255.0f,0,1),
//bottom
Vector4(82 / 255.0f,0,0,1),
Vector4(36 / 255.0f,46 / 255.0f,0,1),
Vector4(0,82 / 255.0f,0,1),
};
byte r2 = (color2 >> 16) & 0xFF;
byte g2 = (color2 >> 8) & 0xFF;
byte b2 = (color2 >> 0) & 0xFF;
array<Vector4, 9> airColors = {
//top
Vector4(0 ,0,90 / 255.0f,1),
Vector4(0 / 255.0f,28 / 255.0f,84 / 255.0f,1),
Vector4(0 ,47 / 255.0f,96/255.0f,1),
//center
Vector4(0,3 / 255,153 / 255.0f,1),
Vector4(0,39 / 255,155 / 255.0f,1),
Vector4(0,78 / 255.0f,159/255.0f,1),
//bottom
Vector4(0 ,0,90 / 255.0f,1),
Vector4(0 / 255.0f,28 / 255.0f,84 / 255.0f,1),
Vector4(0 ,47 / 255.0f,96 / 255.0f,1),
};
float factorX = ScreenWidth / 800.0f;
float factorY = ScreenHeight / 600.0f;
array<Vector4, 9> dashColors = {
//top
Vector4(78 / 255.0f,4 / 255.0f,0,1),
Vector4(161 / 255.0f,25 / 255.0f,84 / 255.0f,1),
Vector4(136 / 255.0f,117 / 255.0f,5 / 255.0f,1),
//center
Vector4(211 / 255.0f,29 / 255.0f,23 / 255.0f,1),
Vector4(245 / 255.0f,119 / 255,24 / 255.0f,1),
Vector4(207 / 255.0f,183 / 255.0f,27 / 255.0f,1),
//bottom
Vector4(78 / 255.0f,4 / 255.0f,0,1),
Vector4(161 / 255.0f,25 / 255.0f,84 / 255.0f,1),
Vector4(136 / 255.0f,117 / 255.0f,5 / 255.0f,1),
};
array<Vector4, 9> soundSettingColors = {
//top
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
//center
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
//bottom
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
};
g_HealthBar = new RendererHUDBar(m_device, 20, 32, 150, 8, 1, healthColors);
g_AirBar = new RendererHUDBar(m_device, 630, 32, 150, 8, 1, airColors);
g_DashBar = new RendererHUDBar(m_device, 630, 32 + 8 + 4, 150, 8, 1, dashColors);
g_MusicVolumeBar = new RendererHUDBar(m_device, 400, 212, 150, 8, 1, soundSettingColors);
g_SFXVolumeBar = new RendererHUDBar(m_device, 400, 230, 150, 8, 1, soundSettingColors);
return true;
}
bool Renderer11::DrawBar(float percent,const RendererHUDBar* const bar)
{
UINT strides = sizeof(RendererVertex);
UINT offset = 0;
float color[] = { 0,0,0,1.0f };
m_context->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xFF);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetVertexBuffers(0, 1, &bar->vertexBufferBorder->Buffer, &strides, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetIndexBuffer(bar->indexBufferBorder->Buffer, DXGI_FORMAT_R32_UINT, 0);
m_context->VSSetConstantBuffers(0, 1, &m_cbHUD);
m_context->VSSetShader(m_vsHUD, NULL, 0);
m_context->PSSetShaderResources(0, 1, &m_HUDBarBorderTexture->ShaderResourceView);
ID3D11SamplerState* sampler = m_states->LinearClamp();
m_context->PSSetSamplers(0, 1, &sampler);
m_context->PSSetShader(m_psHUDTexture, NULL, 0);
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthNone(), NULL);
m_context->RSSetState(m_states->CullNone());
m_context->DrawIndexed(56, 0, 0);
int realX = x * factorX;
int realY = y * factorY;
int realW = w * factorX;
int realH = h * factorY;
int realPercent = percent / 100.0f * realW;
for (int i = 0; i < realH; i++)
AddLine2D(realX, realY + i, realX + realW, realY + i, 0, 0, 0, 255);
for (int i = 0; i < realH; i++)
AddLine2D(realX, realY + i, realX + realPercent, realY + i, r1, g1, b1, 255);
AddLine2D(realX, realY, realX + realW, realY, 255, 255, 255, 255);
AddLine2D(realX, realY + realH, realX + realW, realY + realH, 255, 255, 255, 255);
AddLine2D(realX, realY, realX, realY + realH, 255, 255, 255, 255);
AddLine2D(realX + realW, realY, realX + realW, realY + realH + 1, 255, 255, 255, 255);
m_context->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xFF);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetVertexBuffers(0, 1, &bar->vertexBuffer->Buffer, &strides, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetIndexBuffer(bar->indexBuffer->Buffer, DXGI_FORMAT_R32_UINT, 0);
m_stHUDBar.Percent = percent;
updateConstantBuffer(m_cbHUDBar, &m_stHUDBar, sizeof(CHUDBarBuffer));
m_context->VSSetConstantBuffers(0, 1, &m_cbHUD);
m_context->PSSetConstantBuffers(0, 1, &m_cbHUDBar);
m_context->VSSetShader(m_vsHUD,NULL,0);
m_context->PSSetShader(m_psHUDBarColor, NULL,0);
m_context->OMSetBlendState(m_states->Opaque(), NULL,0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthNone(),NULL);
m_context->RSSetState(m_states->CullNone());
m_context->DrawIndexed(24, 0, 0);
return true;
}

View file

@ -323,8 +323,8 @@ bool Renderer11::drawGunFlashes()
m_stItem.AmbientLight = room.AmbientLight;
memcpy(m_stItem.BonesMatrices, &Matrix::Identity, sizeof(Matrix));
m_stLights.NumLights = item->Lights.Size();
for (int j = 0; j < item->Lights.Size(); j++)
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
updateConstantBuffer(m_cbLights, &m_stLights, sizeof(CLightBuffer));
m_context->PSSetConstantBuffers(2, 1, &m_cbLights);
@ -338,7 +338,7 @@ bool Renderer11::drawGunFlashes()
short rotationX = 0;
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthNone(), 0);
m_context->OMSetDepthStencilState(m_states->DepthRead(), 0);
if (Lara.weaponItem != WEAPON_FLARE && Lara.weaponItem != WEAPON_SHOTGUN && Lara.weaponItem != WEAPON_CROSSBOW)
{
@ -670,8 +670,8 @@ bool Renderer11::drawEffect(RendererEffect* effect, bool transparent)
updateConstantBuffer(m_cbItem, &m_stItem, sizeof(CItemBuffer));
m_context->VSSetConstantBuffers(1, 1, &m_cbItem);
m_stLights.NumLights = effect->Lights.Size();
for (int j = 0; j < effect->Lights.Size(); j++)
m_stLights.NumLights = effect->Lights.size();
for (int j = 0; j < effect->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], effect->Lights[j], sizeof(ShaderLight));
updateConstantBuffer(m_cbLights, &m_stLights, sizeof(CLightBuffer));
m_context->PSSetConstantBuffers(2, 1, &m_cbLights);
@ -763,8 +763,8 @@ bool Renderer11::drawWaterfalls()
updateConstantBuffer(m_cbItem, &m_stItem, sizeof(CItemBuffer));
m_context->VSSetConstantBuffers(1, 1, &m_cbItem);
m_stLights.NumLights = item->Lights.Size();
for (int j = 0; j < item->Lights.Size(); j++)
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
updateConstantBuffer(m_cbLights, &m_stLights, sizeof(CLightBuffer));
m_context->PSSetConstantBuffers(2, 1, &m_cbLights);

View file

@ -6,7 +6,7 @@ void Renderer11::collectRooms()
for (int i = 0; i < NumberRooms; i++)
{
m_rooms[i].Visited = false;
m_rooms[i].LightsToDraw.Clear();
m_rooms[i].LightsToDraw.clear();
}
Vector4 vp = Vector4(-1.0f, -1.0f, 1.0f, 1.0f);
@ -92,7 +92,7 @@ void Renderer11::collectStatics(short roomNumber)
void Renderer11::collectLightsForEffect(short roomNumber, RendererEffect * effect)
{
effect->Lights.Clear();
effect->Lights.clear();
if (m_rooms.size() <= roomNumber) {
return;
}
@ -188,13 +188,13 @@ void Renderer11::collectLightsForEffect(short roomNumber, RendererEffect * effec
for (int i = 0; i < min(MAX_LIGHTS_PER_ITEM, m_tempItemLights.size()); i++)
{
effect->Lights.Add(m_tempItemLights[i]);
effect->Lights.push_back(m_tempItemLights[i]);
}
}
void Renderer11::collectLightsForItem(short roomNumber, RendererItem * item)
{
item->Lights.Clear();
item->Lights.clear();
if (m_rooms.size() <= roomNumber) {
return;
}
@ -303,7 +303,7 @@ void Renderer11::collectLightsForItem(short roomNumber, RendererItem * item)
for (int i = 0; i < min(MAX_LIGHTS_PER_ITEM, m_tempItemLights.size()); i++)
{
item->Lights.Add(m_tempItemLights[i]);
item->Lights.push_back(m_tempItemLights[i]);
}
if (item->Item->objectNumber == ID_LARA)
@ -355,7 +355,7 @@ void Renderer11::collectLightsForRoom(short roomNumber)
// If the distance is less than the circle's radius, an intersection occurs
float distanceSquared = (distanceX * distanceX) + (distanceY * distanceY);
if (distanceSquared < SQUARE(light->Out))
room.LightsToDraw.Add(light);
room.LightsToDraw.push_back(light);
}
}

View file

@ -49,7 +49,9 @@ bool Renderer11::Initialise(int w, int h, int refreshRate, bool windowed, HWND h
if (m_caustics[i] == NULL)
return false;
}
m_HUDBarBorderTexture = Texture2D::LoadFromFile(m_device, "bar_border.png");
if (!m_HUDBarBorderTexture)
return false;
m_titleScreen = Texture2D::LoadFromFile(m_device, (char*)g_GameFlow->GetLevel(0)->Background.c_str());
if (m_titleScreen == NULL)
return false;
@ -164,6 +166,19 @@ bool Renderer11::Initialise(int w, int h, int refreshRate, bool windowed, HWND h
if (m_psShadowMap == NULL)
return false;
m_vsHUD = compileVertexShader("Shaders\\HUD\\DX11_VS_HUD.hlsl", "VS", "vs_4_0", &blob);
if (m_vsHUD == NULL)
return false;
m_psHUDColor = compilePixelShader("Shaders\\HUD\\DX11_PS_HUD.hlsl", "PSColored", "ps_4_0", &blob);
if (m_psHUDColor == NULL)
return false;
m_psHUDTexture = compilePixelShader("Shaders\\HUD\\DX11_PS_HUD.hlsl", "PSTextured", "ps_4_0", &blob);
if (m_psHUDTexture == NULL)
return false;
m_psHUDBarColor = compilePixelShader("Shaders\\HUD\\DX11_PS_HUDBar.hlsl", "PSColored", "ps_4_0", &blob);
if (m_psHUDBarColor == NULL)
return false;
// Initialise constant buffers
m_cbCameraMatrices = createConstantBuffer(sizeof(CCameraMatrixBuffer));
m_cbItem = createConstantBuffer(sizeof(CItemBuffer));
@ -172,6 +187,12 @@ bool Renderer11::Initialise(int w, int h, int refreshRate, bool windowed, HWND h
m_cbMisc = createConstantBuffer(sizeof(CMiscBuffer));
m_cbShadowMap = createConstantBuffer(sizeof(CShadowLightBuffer));
m_cbRoom = createConstantBuffer(sizeof(CRoomBuffer));
//Prepare HUD Constant buffer
m_cbHUDBar = createConstantBuffer(sizeof(CHUDBarBuffer));
m_cbHUD = createConstantBuffer(sizeof(CHUDBuffer));
m_stHUD.View = Matrix::CreateLookAt(Vector3::Zero, Vector3(0, 0, 1), Vector3(0, -1, 0)).Transpose();
m_stHUD.Projection =Matrix::CreateOrthographicOffCenter(0, REFERENCE_RES_WIDTH, 0, REFERENCE_RES_HEIGHT, 0, 1.0f).Transpose();
updateConstantBuffer(m_cbHUD, &m_stHUD, sizeof(CHUDBuffer));
m_currentCausticsFrame = 0;
m_firstWeather = true;
@ -193,8 +214,8 @@ bool Renderer11::Initialise(int w, int h, int refreshRate, bool windowed, HWND h
for (int i = 0; i < NUM_ITEMS; i++)
{
m_items[i].Lights.Reserve(MAX_LIGHTS_PER_ITEM);
m_effects[i].Lights.Reserve(MAX_LIGHTS_PER_ITEM);
m_items[i].Lights = vector<RendererLight*>(MAX_LIGHTS_PER_ITEM);
m_effects[i].Lights = vector<RendererLight*>(MAX_LIGHTS_PER_ITEM);
}
m_textureAtlas = NULL;
@ -211,7 +232,7 @@ bool Renderer11::Initialise(int w, int h, int refreshRate, bool windowed, HWND h
blendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
m_device->CreateBlendState(&blendStateDesc, &m_subtractiveBlendState);
initialiseBars();
return true;
}
@ -402,7 +423,7 @@ bool Renderer11::Create()
#ifdef _RELEASE
res = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, levels, 1, D3D11_SDK_VERSION, &m_device, &featureLevel, &m_context);
#else
res = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, levels, 1, D3D11_SDK_VERSION, &m_device, &featureLevel, &m_context); // D3D11_CREATE_DEVICE_DEBUG
res = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, levels, 1, D3D11_SDK_VERSION, &m_device, &featureLevel, &m_context); // D3D11_CREATE_DEVICE_DEBUG
#endif
if (FAILED(res))

View file

@ -304,8 +304,8 @@ bool Renderer11::drawLara(bool transparent, bool shadowMap)
if (!shadowMap)
{
m_stLights.NumLights = item->Lights.Size();
for (int j = 0; j < item->Lights.Size(); j++)
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
updateConstantBuffer(m_cbLights, &m_stLights, sizeof(CLightBuffer));
m_context->PSSetConstantBuffers(2, 1, &m_cbLights);

View file

@ -0,0 +1,19 @@
struct PixelShaderInput
{
float4 Position: SV_POSITION;
float2 UV: TEXCOORD;
float4 Color: COLOR;
};
Texture2D Texture : register(t0);
SamplerState Sampler : register(s0);
half4 PSColored(PixelShaderInput input) : SV_TARGET
{
return input.Color;
}
half4 PSTextured(PixelShaderInput input) : SV_TARGET
{
float4 output = Texture.Sample(Sampler, input.UV);
return output;
}

View file

@ -0,0 +1,41 @@
cbuffer HUDBarBuffer : register(b0)
{
float Percent;
};
struct PixelShaderInput
{
float4 Position: SV_POSITION;
float2 UV: TEXCOORD;
float4 Color: COLOR;
};
Texture2D Texture : register(t0);
SamplerState Sampler : register(s0);
half4 glassOverlay(float2 UVs, half4 originalColor) {
float y = UVs.y;
y -= 0.15f;
y = distance(0.1f, y);
y = 1 - y;
y = pow(y, 4);
y = saturate(y);
half4 color = originalColor;
return saturate(lerp(color, (color * 1.6f)+half4(0.4f, 0.4f, 0.4f, 0.0f), y));
}
half4 PSColored(PixelShaderInput input) : SV_TARGET
{
if (input.UV.x > Percent) {
discard;
}
return glassOverlay(input.UV,input.Color);
}
half4 PSTextured(PixelShaderInput input) : SV_TARGET
{
if (input.UV.x > Percent) {
discard;
}
float4 color = Texture.Sample(Sampler, input.UV);
return glassOverlay(input.UV, color);
}

View file

@ -0,0 +1,31 @@
cbuffer HUDBuffer : register(b0)
{
float4x4 View;
float4x4 Projection;
};
struct VertexShaderInput
{
float3 Position: POSITION;
float3 Normal: NORMAL;
float2 UV: TEXCOORD;
float4 Color: COLOR;
float Bone : BLENDINDICES;
};
struct PixelShaderInput
{
float4 Position: SV_POSITION;
float2 UV: TEXCOORD;
float4 Color: COLOR;
};
PixelShaderInput VS(VertexShaderInput input)
{
PixelShaderInput output;
output.Position = mul(mul(float4(input.Position, 1.0f), View),Projection);
output.Color = input.Color;
output.UV = input.UV;
return output;
}

View file

@ -82,6 +82,7 @@
<PostBuildEvent>
<Command>md "$(TargetDir)\Shaders"
xcopy /Y "$(ProjectDir)Shaders\*.fx" "$(TargetDir)\Shaders"
xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"
md "$(TargetDir)\Scripts"
xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
</PostBuildEvent>
@ -628,6 +629,30 @@ xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
<Image Include="Banner.bmp" />
<Image Include="C:\Users\Monty\Desktop\Banner.bmp" />
</ItemGroup>
<ItemGroup>
<None Include="Shaders\HUD\DX11_PS_HUD.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<FileType>Document</FileType>
</None>
<None Include="Shaders\HUD\DX11_PS_HUDBar.hlsl">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<FileType>Document</FileType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PSColored</EntryPointName>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">2.0</ShaderModel>
</None>
<FxCompile Include="Shaders\HUD\DX11_VS_HUD.hlsl">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<FileType>Document</FileType>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">VS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<CompileD2DCustomEffect Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileD2DCustomEffect>
</FxCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\directxtk_desktop_2015.2019.10.17.1\build\native\directxtk_desktop_2015.targets" Condition="Exists('..\packages\directxtk_desktop_2015.2019.10.17.1\build\native\directxtk_desktop_2015.targets')" />

View file

@ -871,12 +871,14 @@
<None Include="Shaders\DX11_Hairs.fx" />
<None Include="Shaders\DX11_Statics.fx" />
<None Include="Shaders\DX11_Sky.fx" />
<None Include="Shaders\DX11_Sprites.fx" />
<None Include="Shaders\DX11_Solid.fx" />
<None Include="Shaders\DX11_Inventory.fx" />
<None Include="Shaders\DX11_FullscreenQuad.fx" />
<None Include="Shaders\DX11_ShadowMap.fx" />
<None Include="RuleSet.ruleset" />
<None Include="Shaders\DX11_Sprites.fx" />
<None Include="Shaders\HUD\DX11_PS_HUD.hlsl" />
<None Include="Shaders\HUD\DX11_PS_HUDBar.hlsl" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resources.rc">
@ -894,4 +896,7 @@
<Filter>File di risorse</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<FxCompile Include="Shaders\HUD\DX11_VS_HUD.hlsl" />
</ItemGroup>
</Project>