merge avec Sprite
en espérant que ça a rien kapout pt kc
This commit is contained in:
parent
a39859b251
commit
f736a6bb54
@ -10,6 +10,7 @@ Texture2D shaderTexture : register(t0);
|
||||
SamplerState SampleType : register(s0);
|
||||
cbuffer LightBuffer
|
||||
{
|
||||
float4 ambientColor;
|
||||
float4 diffuseColor;
|
||||
float3 lightDirection;
|
||||
float padding;
|
||||
@ -41,14 +42,23 @@ float4 LightPixelShader(PixelInputType input) : SV_TARGET
|
||||
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
|
||||
textureColor = shaderTexture.Sample(SampleType, input.tex);
|
||||
|
||||
// Set the default output color to the ambient light value for all pixels.
|
||||
color = ambientColor;
|
||||
|
||||
// Invert the light direction for calculations.
|
||||
lightDir = -lightDirection;
|
||||
|
||||
// Calculate the amount of light on this pixel.
|
||||
lightIntensity = saturate(dot(input.normal, lightDir));
|
||||
|
||||
// Determine the final amount of diffuse color based on the diffuse color combined with the light intensity.
|
||||
color = saturate(diffuseColor * lightIntensity);
|
||||
if(lightIntensity > 0.0f)
|
||||
{
|
||||
// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
|
||||
color += (diffuseColor * lightIntensity);
|
||||
}
|
||||
|
||||
// Saturate the final light color.
|
||||
color = saturate(color);
|
||||
|
||||
// Multiply the texture pixel and the final diffuse color to get the final pixel color result.
|
||||
color = color * textureColor;
|
||||
|
@ -18,6 +18,13 @@ LightClass::~LightClass()
|
||||
{
|
||||
}
|
||||
|
||||
void LightClass::SetAmbientColor(float red, float green, float blue, float alpha)
|
||||
{
|
||||
m_ambientColor = XMFLOAT4(red, green, blue, alpha);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LightClass::SetDiffuseColor(float red, float green, float blue, float alpha)
|
||||
{
|
||||
@ -32,6 +39,11 @@ void LightClass::SetDirection(float x, float y, float z)
|
||||
return;
|
||||
}
|
||||
|
||||
XMFLOAT4 LightClass::GetAmbientColor()
|
||||
{
|
||||
return m_ambientColor;
|
||||
}
|
||||
|
||||
|
||||
XMFLOAT4 LightClass::GetDiffuseColor()
|
||||
{
|
||||
|
@ -23,13 +23,16 @@ public:
|
||||
LightClass(const LightClass&);
|
||||
~LightClass();
|
||||
|
||||
void SetDirection(float, float, float);
|
||||
void SetAmbientColor(float, float, float, float);
|
||||
void SetDiffuseColor(float, float, float, float);
|
||||
void SetDirection(float, float, float);
|
||||
|
||||
XMFLOAT3 GetDirection();
|
||||
XMFLOAT4 GetAmbientColor();
|
||||
XMFLOAT4 GetDiffuseColor();
|
||||
XMFLOAT3 GetDirection();
|
||||
|
||||
private:
|
||||
XMFLOAT4 m_ambientColor;
|
||||
XMFLOAT4 m_diffuseColor;
|
||||
XMFLOAT3 m_direction;
|
||||
};
|
||||
|
@ -39,13 +39,19 @@ bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the filename of the pixel shader.
|
||||
error = wcscpy_s(psFilename, 128, L"./Light.ps");
|
||||
// Set the filename of the vertex shader.
|
||||
error = wcscpy_s(vsFilename, 128, L"light.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the filename of the pixel shader.
|
||||
error = wcscpy_s(psFilename, 128, L"light.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Initialize the vertex and pixel shaders.
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
@ -66,13 +72,13 @@ void LightShaderClass::Shutdown()
|
||||
}
|
||||
|
||||
bool LightShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
||||
ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor)
|
||||
ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor)
|
||||
{
|
||||
bool result;
|
||||
|
||||
|
||||
// Set the shader parameters that it will use for rendering.
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, diffuseColor);
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor);
|
||||
if(!result)
|
||||
{
|
||||
return false;
|
||||
@ -339,8 +345,9 @@ void LightShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND h
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
||||
ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor)
|
||||
ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor)
|
||||
{
|
||||
HRESULT result;
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
@ -392,6 +399,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
dataPtr2 = (LightBufferType*)mappedResource.pData;
|
||||
|
||||
// Copy the lighting variables into the constant buffer.
|
||||
dataPtr2->ambientColor = ambientColor;
|
||||
dataPtr2->diffuseColor = diffuseColor;
|
||||
dataPtr2->lightDirection = lightDirection;
|
||||
dataPtr2->padding = 0.0f;
|
||||
|
@ -31,6 +31,7 @@ private:
|
||||
|
||||
struct LightBufferType
|
||||
{
|
||||
XMFLOAT4 ambientColor;
|
||||
XMFLOAT4 diffuseColor;
|
||||
XMFLOAT3 lightDirection;
|
||||
float padding; // Added extra padding so structure is a multiple of 16 for CreateBuffer function requirements.
|
||||
@ -43,14 +44,14 @@ public:
|
||||
|
||||
bool Initialize(ID3D11Device*, HWND);
|
||||
void Shutdown();
|
||||
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4);
|
||||
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4, XMFLOAT4);
|
||||
|
||||
private:
|
||||
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
|
||||
void ShutdownShader();
|
||||
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
|
||||
|
||||
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4);
|
||||
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4, XMFLOAT4);
|
||||
void RenderShader(ID3D11DeviceContext*, int);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user