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);
|
SamplerState SampleType : register(s0);
|
||||||
cbuffer LightBuffer
|
cbuffer LightBuffer
|
||||||
{
|
{
|
||||||
|
float4 ambientColor;
|
||||||
float4 diffuseColor;
|
float4 diffuseColor;
|
||||||
float3 lightDirection;
|
float3 lightDirection;
|
||||||
float padding;
|
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.
|
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
|
||||||
textureColor = shaderTexture.Sample(SampleType, input.tex);
|
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.
|
// Invert the light direction for calculations.
|
||||||
lightDir = -lightDirection;
|
lightDir = -lightDirection;
|
||||||
|
|
||||||
// Calculate the amount of light on this pixel.
|
// Calculate the amount of light on this pixel.
|
||||||
lightIntensity = saturate(dot(input.normal, lightDir));
|
lightIntensity = saturate(dot(input.normal, lightDir));
|
||||||
|
|
||||||
// Determine the final amount of diffuse color based on the diffuse color combined with the light intensity.
|
if(lightIntensity > 0.0f)
|
||||||
color = saturate(diffuseColor * lightIntensity);
|
{
|
||||||
|
// 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.
|
// Multiply the texture pixel and the final diffuse color to get the final pixel color result.
|
||||||
color = color * textureColor;
|
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)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMFLOAT4 LightClass::GetAmbientColor()
|
||||||
|
{
|
||||||
|
return m_ambientColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
XMFLOAT4 LightClass::GetDiffuseColor()
|
XMFLOAT4 LightClass::GetDiffuseColor()
|
||||||
{
|
{
|
||||||
|
@ -23,13 +23,16 @@ public:
|
|||||||
LightClass(const LightClass&);
|
LightClass(const LightClass&);
|
||||||
~LightClass();
|
~LightClass();
|
||||||
|
|
||||||
void SetDirection(float, float, float);
|
void SetAmbientColor(float, float, float, float);
|
||||||
void SetDiffuseColor(float, float, float, float);
|
void SetDiffuseColor(float, float, float, float);
|
||||||
|
void SetDirection(float, float, float);
|
||||||
|
|
||||||
XMFLOAT3 GetDirection();
|
XMFLOAT4 GetAmbientColor();
|
||||||
XMFLOAT4 GetDiffuseColor();
|
XMFLOAT4 GetDiffuseColor();
|
||||||
|
XMFLOAT3 GetDirection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
XMFLOAT4 m_ambientColor;
|
||||||
XMFLOAT4 m_diffuseColor;
|
XMFLOAT4 m_diffuseColor;
|
||||||
XMFLOAT3 m_direction;
|
XMFLOAT3 m_direction;
|
||||||
};
|
};
|
||||||
|
@ -39,13 +39,19 @@ bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the filename of the pixel shader.
|
// Set the filename of the vertex shader.
|
||||||
error = wcscpy_s(psFilename, 128, L"./Light.ps");
|
error = wcscpy_s(vsFilename, 128, L"light.vs");
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
return false;
|
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.
|
// Initialize the vertex and pixel shaders.
|
||||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -66,14 +72,14 @@ void LightShaderClass::Shutdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool LightShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
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;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
// Set the shader parameters that it will use for rendering.
|
// 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)
|
if(!result)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -339,8 +345,9 @@ void LightShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND h
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
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;
|
HRESULT result;
|
||||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||||
@ -392,6 +399,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
|||||||
dataPtr2 = (LightBufferType*)mappedResource.pData;
|
dataPtr2 = (LightBufferType*)mappedResource.pData;
|
||||||
|
|
||||||
// Copy the lighting variables into the constant buffer.
|
// Copy the lighting variables into the constant buffer.
|
||||||
|
dataPtr2->ambientColor = ambientColor;
|
||||||
dataPtr2->diffuseColor = diffuseColor;
|
dataPtr2->diffuseColor = diffuseColor;
|
||||||
dataPtr2->lightDirection = lightDirection;
|
dataPtr2->lightDirection = lightDirection;
|
||||||
dataPtr2->padding = 0.0f;
|
dataPtr2->padding = 0.0f;
|
||||||
|
@ -31,6 +31,7 @@ private:
|
|||||||
|
|
||||||
struct LightBufferType
|
struct LightBufferType
|
||||||
{
|
{
|
||||||
|
XMFLOAT4 ambientColor;
|
||||||
XMFLOAT4 diffuseColor;
|
XMFLOAT4 diffuseColor;
|
||||||
XMFLOAT3 lightDirection;
|
XMFLOAT3 lightDirection;
|
||||||
float padding; // Added extra padding so structure is a multiple of 16 for CreateBuffer function requirements.
|
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);
|
bool Initialize(ID3D11Device*, HWND);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4);
|
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4, XMFLOAT4);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
|
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
|
||||||
void ShutdownShader();
|
void ShutdownShader();
|
||||||
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
|
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);
|
void RenderShader(ID3D11DeviceContext*, int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user