1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-05 06:45:37 +01:00
GiantsTools/Shaders/fx/Water.fx

62 lines
1.7 KiB
HLSL
Raw Normal View History

2020-08-11 21:08:49 +02:00
//--------------------------------------------------------------------------------------
// Water.fx
// Very basic shader that implements D3DTOP_ADDSMOOTH functionality in HLSL, replicating
// the original fixed-function water rendering behavior.
//--------------------------------------------------------------------------------------
float4x4 g_WorldViewProjection : WorldViewProjection;
float4 g_TextureFactor : TextureFactor;
//float4 g_Fog : Fog;
texture2D g_WaterTexture : Texture0;
2020-08-11 21:08:49 +02:00
sampler2D g_WaterTextureSampler =
sampler_state
{
Texture = <g_WaterTexture>;
};
struct VS_OUTPUT
{
float4 Position : POSITION; // vertex position
float2 TextureUV : TEXCOORD0; // vertex texture coords
float4 Color : COLOR0;
//float Fog : FOG;
};
VS_OUTPUT RenderSceneVS(float4 inPos : POSITION,
float4 inDiffuse : COLOR0,
float4 inTextureUV : TEXCOORD0)
{
VS_OUTPUT Output;
Output.Position = mul(inPos, g_WorldViewProjection);
Output.TextureUV = inTextureUV;
Output.Color = inDiffuse;
// Don't think this is right, but we can use FFP fog unless this is compiled for SM 3.0
//float4 r0;
//r0.z = inPos.z * g_WorldViewProjection[3];
//r0.x = -r0.z + g_Fog.y;
//Output.Fog.x = r0.x * g_Fog.z;
return Output;
}
float4 RenderScenePS(VS_OUTPUT input) : COLOR0
{
float4 texel = tex2D(g_WaterTextureSampler, input.TextureUV);
float4 result = saturate(texel + (1 - texel) * g_TextureFactor); // equivalent to saturate((texel + g_TextureFactor) - (texel * g_TextureFactor));
result.a = input.Color.a * g_TextureFactor.a;
return result;
}
technique RenderScene
{
pass P0
{
VertexShader = compile vs_2_0 RenderSceneVS();
PixelShader = compile ps_2_0 RenderScenePS();
}
}