Skip to content

Instantly share code, notes, and snippets.

@Des-Nerger
Created August 19, 2023 12:43
Show Gist options
  • Save Des-Nerger/a03c1b284ec1c6d54ca5c71f0a196938 to your computer and use it in GitHub Desktop.
Save Des-Nerger/a03c1b284ec1c6d54ca5c71f0a196938 to your computer and use it in GitHub Desktop.
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif
float xBlurDistance;
float4 xColor;
float xWaveWidth;
float xWaveHeight;
float2 xWavePos;
float2 xBumpPos;
matrix xView;
matrix xProjection;
Texture2D xTexture;
sampler2D TextureSampler = sampler_state
{
Texture = <xTexture>;
};
Texture2D xWaterBumpMap;
sampler2D WaterBumpSampler = sampler_state
{
Texture = <xWaterBumpMap>;
MagFilter = LINEAR;
MinFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
struct VertexShaderInput
{
float4 Position : POSITION0;
float4 vTexCoord0 : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 vTexCoord0 : TEXCOORD0;
};
VertexShaderOutput MainVS(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;
output.Position = mul(input.Position, mul(xView, xProjection));
output.vTexCoord0 = input.vTexCoord0;
return output;
}
float4 MainWaterPS(VertexShaderOutput input) : COLOR
{
float2 texCoord = input.vTexCoord0.xy;
float4 bumpColor = tex2D(WaterBumpSampler, texCoord+xWavePos+xBumpPos);
bumpColor = (bumpColor + tex2D(WaterBumpSampler, texCoord-xWavePos*2.0f+xBumpPos))/2.0f;
float2 samplePos = texCoord;
samplePos.x+=(bumpColor.r-0.5f)*xWaveWidth;
samplePos.y+=(bumpColor.g-0.5f)*xWaveHeight;
float4 sample;
sample = tex2D( TextureSampler, float2(samplePos.x+xBlurDistance, samplePos.y+xBlurDistance));
sample += tex2D( TextureSampler, float2(samplePos.x-xBlurDistance, samplePos.y-xBlurDistance));
sample += tex2D( TextureSampler, float2(samplePos.x+xBlurDistance, samplePos.y-xBlurDistance));
sample += tex2D( TextureSampler, float2(samplePos.x-xBlurDistance, samplePos.y+xBlurDistance));
sample = (sample * xColor) / 4;
return sample;
}
float4 MainEmptyPS(VertexShaderOutput input) : COLOR
{
return tex2D(TextureSampler, input.vTexCoord0.xy);
}
technique WaterShader
{
pass Pass0
{
VertexShader = compile VS_SHADERMODEL MainVS();
PixelShader = compile PS_SHADERMODEL MainWaterPS();
}
};
technique EmptyShader
{
pass Pass0
{
VertexShader = compile VS_SHADERMODEL MainVS();
PixelShader = compile PS_SHADERMODEL MainEmptyPS();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment