This commit is contained in:
MontyTRC89 2020-01-04 09:26:56 +01:00
commit c3890b0e68
6 changed files with 56 additions and 12 deletions

View file

@ -35,6 +35,11 @@ cbuffer CShadowLightBuffer : register(b4)
float3 Padding2; float3 Padding2;
}; };
cbuffer RoomBuffer : register(b5)
{
float4 AmbientColor;
};
struct VertexShaderInput struct VertexShaderInput
{ {
float3 Position: POSITION; float3 Position: POSITION;
@ -61,7 +66,6 @@ Texture2D CausticsTexture : register(t1);
Texture2D ShadowMap : register(t2); Texture2D ShadowMap : register(t2);
SamplerState ShadowMapSampler : register(s1); SamplerState ShadowMapSampler : register(s1);
PixelShaderInput VS(VertexShaderInput input) PixelShaderInput VS(VertexShaderInput input)
{ {
PixelShaderInput output; PixelShaderInput output;
@ -76,6 +80,19 @@ PixelShaderInput VS(VertexShaderInput input)
return output; return output;
} }
float getShadowFactor(Texture2D shadowMap, SamplerState shadowMapSampler, float2 coords, float realDepth) {
const float texelSize = 1.0f / 1024;
float shadowFactor = 0.0f;
//doing 9 samples
for (float x = -1; x <= 1.0f; x++) {
for (float y = -1; y <= 1.0f; y++) {
float shadowMapDepth = ShadowMap.SampleLevel(ShadowMapSampler, coords + (float2(x, y)*texelSize),0).r;
shadowFactor += shadowMapDepth < realDepth ? 1.0f : 0.0f;
}
}
return shadowFactor / 9.0f;
}
[earlydepthstencil] [earlydepthstencil]
float4 PS(PixelShaderInput input) : SV_TARGET float4 PS(PixelShaderInput input) : SV_TARGET
{ {
@ -104,8 +121,8 @@ float4 PS(PixelShaderInput input) : SV_TARGET
float realDepth = input.LightPosition.z; float realDepth = input.LightPosition.z;
// If clip space z value greater than shadow map value then pixel is in shadow // If clip space z value greater than shadow map value then pixel is in shadow
if (shadowMapDepth < realDepth) float shadow = getShadowFactor(ShadowMap, ShadowMapSampler, coords, realDepth);
return float4(output.xyz* colorMul.xyz / 2.0f, 1.0f); lighting = lerp(lighting, AmbientColor * 2, saturate(shadow));
} }
} }
@ -159,4 +176,5 @@ float4 PS(PixelShaderInput input) : SV_TARGET
output.w = 1.0f; output.w = 1.0f;
return output; return output;
} }

View file

@ -1136,7 +1136,7 @@ int CreatureActive(short itemNumber)
void InitialiseCreature(short itemNumber) void InitialiseCreature(short itemNumber)
{ {
InitialiseCreature(itemNumber); ClearItem(itemNumber);
} }
int StalkBox(ITEM_INFO* item, ITEM_INFO* enemy, short boxNumber) int StalkBox(ITEM_INFO* item, ITEM_INFO* enemy, short boxNumber)

View file

@ -73,7 +73,7 @@ typedef enum RENDERER_FADE_STATUS {
FADE_OUT FADE_OUT
}; };
#define SHADOW_MAP_SIZE 2048 #define SHADOW_MAP_SIZE 1024
#define TEXTURE_ATLAS_SIZE 4096 #define TEXTURE_ATLAS_SIZE 4096
#define TEXTURE_PAGE_SIZE 262144 #define TEXTURE_PAGE_SIZE 262144

View file

@ -602,7 +602,7 @@ bool Renderer11::Initialise(int w, int h, int refreshRate, bool windowed, HWND h
m_cbLights = createConstantBuffer(sizeof(CLightBuffer)); m_cbLights = createConstantBuffer(sizeof(CLightBuffer));
m_cbMisc = createConstantBuffer(sizeof(CMiscBuffer)); m_cbMisc = createConstantBuffer(sizeof(CMiscBuffer));
m_cbShadowMap = createConstantBuffer(sizeof(CShadowLightBuffer)); m_cbShadowMap = createConstantBuffer(sizeof(CShadowLightBuffer));
m_cbRoom = createConstantBuffer(sizeof(CRoomBuffer));
m_currentCausticsFrame = 0; m_currentCausticsFrame = 0;
m_firstWeather = true; m_firstWeather = true;
@ -921,7 +921,9 @@ bool Renderer11::drawRooms(bool transparent, bool animated)
m_stMisc.AlphaTest = !transparent; m_stMisc.AlphaTest = !transparent;
updateConstantBuffer(m_cbMisc, &m_stMisc, sizeof(CMiscBuffer)); updateConstantBuffer(m_cbMisc, &m_stMisc, sizeof(CMiscBuffer));
m_context->PSSetConstantBuffers(3, 1, &m_cbMisc); m_context->PSSetConstantBuffers(3, 1, &m_cbMisc);
m_stRoom.AmbientColor = room->AmbientLight;
updateConstantBuffer(m_cbRoom, &m_stRoom, sizeof(CRoomBuffer));
m_context->PSSetConstantBuffers(5, 1, &m_cbRoom);
for (int j = firstBucket; j < lastBucket; j++) for (int j = firstBucket; j < lastBucket; j++)
{ {
RendererBucket* bucket; RendererBucket* bucket;

View file

@ -582,6 +582,10 @@ struct CMiscBuffer {
float Padding[14]; float Padding[14];
}; };
struct CRoomBuffer {
Vector4 AmbientColor;
};
struct RendererAnimatedTexture struct RendererAnimatedTexture
{ {
int Id; int Id;
@ -832,6 +836,8 @@ private:
ID3D11Buffer* m_cbLights; ID3D11Buffer* m_cbLights;
CMiscBuffer m_stMisc; CMiscBuffer m_stMisc;
ID3D11Buffer* m_cbMisc; ID3D11Buffer* m_cbMisc;
CRoomBuffer m_stRoom;
ID3D11Buffer* m_cbRoom;
CShadowLightBuffer m_stShadowMap; CShadowLightBuffer m_stShadowMap;
ID3D11Buffer* m_cbShadowMap; ID3D11Buffer* m_cbShadowMap;

View file

@ -35,6 +35,11 @@ cbuffer CShadowLightBuffer : register(b4)
float3 Padding2; float3 Padding2;
}; };
cbuffer RoomBuffer : register(b5)
{
float4 AmbientColor;
};
struct VertexShaderInput struct VertexShaderInput
{ {
float3 Position: POSITION; float3 Position: POSITION;
@ -61,7 +66,6 @@ Texture2D CausticsTexture : register(t1);
Texture2D ShadowMap : register(t2); Texture2D ShadowMap : register(t2);
SamplerState ShadowMapSampler : register(s1); SamplerState ShadowMapSampler : register(s1);
PixelShaderInput VS(VertexShaderInput input) PixelShaderInput VS(VertexShaderInput input)
{ {
PixelShaderInput output; PixelShaderInput output;
@ -76,6 +80,19 @@ PixelShaderInput VS(VertexShaderInput input)
return output; return output;
} }
float getShadowFactor(Texture2D shadowMap, SamplerState shadowMapSampler, float2 coords, float realDepth) {
const float texelSize = 1.0f / 1024;
float shadowFactor = 0.0f;
//doing 9 samples
for (float x = -1; x <= 1.0f; x++) {
for (float y = -1; y <= 1.0f; y++) {
float shadowMapDepth = ShadowMap.SampleLevel(ShadowMapSampler, coords + (float2(x, y)*texelSize),0).r;
shadowFactor += shadowMapDepth < realDepth ? 1.0f : 0.0f;
}
}
return shadowFactor / 9.0f;
}
[earlydepthstencil] [earlydepthstencil]
float4 PS(PixelShaderInput input) : SV_TARGET float4 PS(PixelShaderInput input) : SV_TARGET
{ {
@ -104,8 +121,8 @@ float4 PS(PixelShaderInput input) : SV_TARGET
float realDepth = input.LightPosition.z; float realDepth = input.LightPosition.z;
// If clip space z value greater than shadow map value then pixel is in shadow // If clip space z value greater than shadow map value then pixel is in shadow
if (shadowMapDepth < realDepth) float shadow = getShadowFactor(ShadowMap, ShadowMapSampler, coords, realDepth);
return float4(output.xyz* colorMul.xyz / 2.0f, 1.0f); lighting = lerp(lighting, AmbientColor * 2, saturate(shadow));
} }
} }
@ -159,4 +176,5 @@ float4 PS(PixelShaderInput input) : SV_TARGET
output.w = 1.0f; output.w = 1.0f;
return output; return output;
} }