Fix Water Shader dans le shader manager
This commit is contained in:
parent
c7d2d13388
commit
df55562d59
@ -19,7 +19,6 @@ ApplicationClass::ApplicationClass()
|
||||
m_Position = 0;
|
||||
m_Frustum = 0;
|
||||
m_DisplayPlane = 0;
|
||||
m_ReflectionShader = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -378,14 +378,15 @@ bool ShaderManagerClass::RenderRefractionShader(ID3D11DeviceContext* deviceConte
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShaderManagerClass::RenderWaterShader(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, XMMATRIX reflectionMatrix,
|
||||
ID3D11ShaderResourceView* reflectionTexture, ID3D11ShaderResourceView* refractionTexture, ID3D11ShaderResourceView* normalTexture,
|
||||
float waterTranslation, float reflectRefractScale)
|
||||
bool ShaderManagerClass::RenderWaterShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
||||
XMMATRIX reflectionMatrix, ID3D11ShaderResourceView* reflectionTexture, ID3D11ShaderResourceView* refractionTexture,
|
||||
ID3D11ShaderResourceView* normalTexture, float waterTranslation, float reflectRefractScale)
|
||||
{
|
||||
bool result;
|
||||
|
||||
|
||||
result = m_RefractionShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, clipPlane);
|
||||
result = m_WaterShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, reflectionTexture,
|
||||
refractionTexture, normalTexture, waterTranslation, reflectRefractScale);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
|
@ -41,8 +41,8 @@ public:
|
||||
bool RenderlightMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*);
|
||||
bool RenderRefractionShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
|
||||
XMFLOAT3, XMFLOAT4, XMFLOAT4, XMFLOAT4);
|
||||
bool RenderWaterShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*,
|
||||
ID3D11ShaderResourceView*, float, float);
|
||||
bool RenderWaterShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
|
||||
ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, float, float);
|
||||
private:
|
||||
TextureShaderClass* m_TextureShader;
|
||||
NormalMapShaderClass* m_NormalMapShader;
|
||||
|
72
enginecustom/water.ps
Normal file
72
enginecustom/water.ps
Normal file
@ -0,0 +1,72 @@
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
/////////////
|
||||
SamplerState SampleType : register(s0);
|
||||
|
||||
Texture2D reflectionTexture : register(t0);
|
||||
Texture2D refractionTexture : register(t1);
|
||||
Texture2D normalTexture : register(t2);
|
||||
|
||||
cbuffer WaterBuffer
|
||||
{
|
||||
float waterTranslation;
|
||||
float reflectRefractScale;
|
||||
float2 padding;
|
||||
};
|
||||
|
||||
|
||||
//////////////
|
||||
// TYPEDEFS //
|
||||
//////////////
|
||||
struct PixelInputType
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 reflectionPosition : TEXCOORD1;
|
||||
float4 refractionPosition : TEXCOORD2;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Pixel Shader
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
float4 WaterPixelShader(PixelInputType input) : SV_TARGET
|
||||
{
|
||||
float2 reflectTexCoord;
|
||||
float2 refractTexCoord;
|
||||
float4 normalMap;
|
||||
float3 normal;
|
||||
float4 reflectionColor;
|
||||
float4 refractionColor;
|
||||
float4 color;
|
||||
|
||||
// Move the position the water normal is sampled from to simulate moving water.
|
||||
input.tex.y += waterTranslation;
|
||||
|
||||
// Calculate the projected reflection texture coordinates.
|
||||
reflectTexCoord.x = input.reflectionPosition.x / input.reflectionPosition.w / 2.0f + 0.5f;
|
||||
reflectTexCoord.y = -input.reflectionPosition.y / input.reflectionPosition.w / 2.0f + 0.5f;
|
||||
|
||||
// Calculate the projected refraction texture coordinates.
|
||||
refractTexCoord.x = input.refractionPosition.x / input.refractionPosition.w / 2.0f + 0.5f;
|
||||
refractTexCoord.y = -input.refractionPosition.y / input.refractionPosition.w / 2.0f + 0.5f;
|
||||
|
||||
// Sample the normal from the normal map texture.
|
||||
normalMap = normalTexture.Sample(SampleType, input.tex);
|
||||
|
||||
// Expand the range of the normal from (0,1) to (-1,+1).
|
||||
normal = (normalMap.xyz * 2.0f) - 1.0f;
|
||||
|
||||
// Re-position the texture coordinate sampling position by the normal map value to simulate the rippling wave effect.
|
||||
reflectTexCoord = reflectTexCoord + (normal.xy * reflectRefractScale);
|
||||
refractTexCoord = refractTexCoord + (normal.xy * reflectRefractScale);
|
||||
|
||||
// Sample the texture pixels from the textures using the updated texture coordinates.
|
||||
reflectionColor = reflectionTexture.Sample(SampleType, reflectTexCoord);
|
||||
refractionColor = refractionTexture.Sample(SampleType, refractTexCoord);
|
||||
|
||||
// Combine the reflection and refraction results for the final color.
|
||||
color = lerp(reflectionColor, refractionColor, 0.6f);
|
||||
|
||||
return color;
|
||||
}
|
@ -31,14 +31,14 @@ bool WaterShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
int error;
|
||||
|
||||
// Set the filename of the vertex shader.
|
||||
error = wcscpy_s(vsFilename, 128, L"../Engine/water.vs");
|
||||
error = wcscpy_s(vsFilename, 128, L"water.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the filename of the pixel shader.
|
||||
error = wcscpy_s(psFilename, 128, L"../Engine/water.ps");
|
||||
error = wcscpy_s(psFilename, 128, L"water.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user