mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +03:00
Refactored DX11 renderer; Added special effects and sprites rendering;
This commit is contained in:
parent
726d253513
commit
112112ff1a
15 changed files with 1590 additions and 393 deletions
|
@ -48,6 +48,7 @@ PixelShaderInput VS(VertexShaderInput input)
|
|||
return output;
|
||||
}
|
||||
|
||||
[earlydepthstencil]
|
||||
float4 PS(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
float4 output = Texture.Sample(Sampler, input.UV);
|
||||
|
|
|
@ -1,9 +1,26 @@
|
|||
cbuffer CameraMatrixBuffer
|
||||
struct RendererLight {
|
||||
float4 Position;
|
||||
float4 Color;
|
||||
float4 Direction;
|
||||
float Intensity;
|
||||
float In;
|
||||
float Out;
|
||||
float Range;
|
||||
};
|
||||
|
||||
cbuffer CameraMatrixBuffer : register(b0)
|
||||
{
|
||||
float4x4 View;
|
||||
float4x4 Projection;
|
||||
};
|
||||
|
||||
cbuffer LightsBuffer : register(b1)
|
||||
{
|
||||
RendererLight Lights[48];
|
||||
int NumLights;
|
||||
float3 Padding;
|
||||
};
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float3 Position: POSITION;
|
||||
|
@ -16,6 +33,7 @@ struct VertexShaderInput
|
|||
struct PixelShaderInput
|
||||
{
|
||||
float4 Position: SV_POSITION;
|
||||
float3 WorldPosition: POSITION;
|
||||
float3 Normal: NORMAL;
|
||||
float2 UV: TEXCOORD;
|
||||
float4 Color: COLOR;
|
||||
|
@ -32,16 +50,40 @@ PixelShaderInput VS(VertexShaderInput input)
|
|||
output.Normal = input.Normal;
|
||||
output.Color = input.Color;
|
||||
output.UV = input.UV;
|
||||
output.WorldPosition = input.Position.xyz;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
[earlydepthstencil]
|
||||
float4 PS(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
float4 output = Texture.Sample(Sampler, input.UV);
|
||||
clip(output.w - 0.5f);
|
||||
float3 colorMul = min(input.Color.xyz, 1.0f) * 2.0f;
|
||||
output.xyz = output.xyz * colorMul.xyz;
|
||||
|
||||
float3 lighting = colorMul.xyz;
|
||||
|
||||
for (int i = 0; i < NumLights; i++)
|
||||
{
|
||||
float3 lightPos = Lights[i].Position.xyz;
|
||||
float3 color = Lights[i].Color.xyz;
|
||||
float radius = Lights[i].Out;
|
||||
float intensity = Lights[i].Intensity;
|
||||
|
||||
float3 lightVec = (lightPos - input.WorldPosition);
|
||||
float distance = length(lightVec);
|
||||
|
||||
if (distance > radius)
|
||||
continue;
|
||||
|
||||
lightVec = normalize(lightVec);
|
||||
float attenuation = (radius - distance) / radius;
|
||||
|
||||
lighting += color * intensity * attenuation;
|
||||
}
|
||||
|
||||
output.xyz = output.xyz * lighting;
|
||||
output.w = 1.0f;
|
||||
|
||||
return output;
|
||||
|
|
54
Build/Shaders/DX11_Sky.fx
Normal file
54
Build/Shaders/DX11_Sky.fx
Normal file
|
@ -0,0 +1,54 @@
|
|||
cbuffer CameraMatrixBuffer : register(b0)
|
||||
{
|
||||
float4x4 View;
|
||||
float4x4 Projection;
|
||||
};
|
||||
|
||||
cbuffer StaticMatrixBuffer : register(b1)
|
||||
{
|
||||
float4x4 World;
|
||||
float4 StaticPosition;
|
||||
float4 Color;
|
||||
};
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float3 Position: POSITION;
|
||||
float3 Normal: NORMAL;
|
||||
float2 UV: TEXCOORD;
|
||||
float4 Color: COLOR;
|
||||
float Bone : BLENDINDICES;
|
||||
};
|
||||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 Position: SV_POSITION;
|
||||
float3 Normal: NORMAL;
|
||||
float2 UV: TEXCOORD;
|
||||
float4 Color: COLOR;
|
||||
};
|
||||
|
||||
Texture2D Texture;
|
||||
SamplerState Sampler;
|
||||
|
||||
PixelShaderInput VS(VertexShaderInput input)
|
||||
{
|
||||
PixelShaderInput output;
|
||||
|
||||
output.Position = mul(mul(mul(float4(input.Position, 1.0f), World), View), Projection);
|
||||
output.Normal = input.Normal;
|
||||
output.Color = input.Color;
|
||||
output.UV = input.UV;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
float4 output = Texture.Sample(Sampler, input.UV);
|
||||
clip(output.w - 0.5f);
|
||||
output.xyz = output.xyz * Color;
|
||||
output.w = 1.0f;
|
||||
|
||||
return output;
|
||||
}
|
47
Build/Shaders/DX11_Sprites.fx
Normal file
47
Build/Shaders/DX11_Sprites.fx
Normal file
|
@ -0,0 +1,47 @@
|
|||
cbuffer CameraMatrixBuffer : 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;
|
||||
float3 Normal: NORMAL;
|
||||
float2 UV: TEXCOORD;
|
||||
float4 Color: COLOR;
|
||||
};
|
||||
|
||||
Texture2D Texture;
|
||||
SamplerState Sampler;
|
||||
|
||||
PixelShaderInput VS(VertexShaderInput input)
|
||||
{
|
||||
PixelShaderInput output;
|
||||
|
||||
output.Position = mul(mul(float4(input.Position, 1.0f), View), Projection);
|
||||
output.Normal = input.Normal;
|
||||
output.Color = input.Color;
|
||||
output.UV = input.UV;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
float4 output = Texture.Sample(Sampler, input.UV);
|
||||
clip(output.w - 0.5f);
|
||||
output.xyz = output.xyz * input.Color.xyz;
|
||||
output.w = 1.0f;
|
||||
|
||||
return output;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue