As promised, I revived BlindSide's old water shader, so here it is. However, I made quite a few changes and since I barely speak GLSL it's DX only for now.
- All terrain dependencies stripped, it's only the water surface but therefore universal
- Implemented as a SceneNode with some parameters, it takes 1 line of code to create it
- It's movable, scalable and works with parents
- Should work with most custom cameras
- Sinus waves and refraction are now switchable at runtime
- Minor changes in color and transparency
- It's extremely fast, even a little faster than before due to the cuts in terrain code (in the screenshot VSync is on, therefore capped at 75fps)
If shader materials are used on objects that intersect with the clip plane (the water surface) it's necessary to implement the clip plane inside those shaders as well in order to make reflections and refractions work correctly.
In HLSL a basic shader with a custom clip plane could look like this:
Code: Select all
float4x4 xWorldViewProjection;
float4x4 xWorld;
struct VertexToPixel
{
float4 Position : POSITION0;
float2 TexCoords : TEXCOORD0;
float3 Position3D : TEXCOORD1;
};
struct PixelToFrame
{
float4 Color : COLOR0;
};
VertexToPixel vertexMain ( float4 inPos : POSITION0,
float2 inTexCoords : TEXCOORD0 )
{
VertexToPixel Output;
Output.Position = mul(inPos, xWorldViewProjection);
Output.TexCoords = inTexCoords;
Output.Position3D = mul(inPos, xWorld);
return Output;
}
// ================================================================
sampler2D diffuse : register(s0);
float seaLevel; // SceneNode Y position
PixelToFrame pixelMain(VertexToPixel PSIn)
{
clip(PSIn.Position3D.y - seaLevel); // clip if below seaLevel
PixelToFrame Output;
float4 final = tex2D(diffuse, PSIn.TexCoords);
Output.Color = final;
return Output;
}
- Implemented as a SceneNode, it takes 1 line of code to create an effect
- It's self-controlled, so actually all you need to do is call new Effect(...) just where you need it. It destroys itself on animation end, so there's no need to store a pointer.
- particle-based
- simple texture animation shader
Demo controls:
Key [ESC] : Exit
Mouse [LEFT] : Shoot (aim for Mr. Ball)
Key [1] : Show blood effect - mild
Key [2] : Show blood effect - medium
Key [3] : Show blood effect - brutal
Key [4] : Show blood effect - insane
Key [5] : Show massacre
Download package here.