aeafa16...4d3cf73
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// Pixel shader applies a one dimensional gaussian blur filter.
|
||||
// This is used twice by the bloom postprocess, first to
|
||||
// blur horizontally, and then again to blur vertically.
|
||||
|
||||
sampler TextureSampler : register(s0);
|
||||
|
||||
#define SAMPLE_COUNT 15
|
||||
|
||||
float2 SampleOffsets[SAMPLE_COUNT];
|
||||
float SampleWeights[SAMPLE_COUNT];
|
||||
|
||||
|
||||
float4 PixelShaderF(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 c = 0;
|
||||
|
||||
// Combine a number of weighted image filter taps.
|
||||
for (int i = 0; i < SAMPLE_COUNT; i++)
|
||||
{
|
||||
c += tex2D(TextureSampler, texCoord + SampleOffsets[i]) * SampleWeights[i];
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
technique GaussianBlur
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 PixelShaderF();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Pixel shader applies a one dimensional gaussian blur filter.
|
||||
// This is used twice by the bloom postprocess, first to
|
||||
// blur horizontally, and then again to blur vertically.
|
||||
|
||||
sampler TextureSampler : register(s0);
|
||||
|
||||
#define SAMPLE_COUNT 15
|
||||
|
||||
float2 SampleOffsets[SAMPLE_COUNT];
|
||||
float SampleWeights[SAMPLE_COUNT];
|
||||
|
||||
|
||||
float4 PixelShaderF(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 c = 0;
|
||||
|
||||
// Combine a number of weighted image filter taps.
|
||||
for (int i = 0; i < SAMPLE_COUNT; i++)
|
||||
{
|
||||
c += tex2D(TextureSampler, texCoord + SampleOffsets[i]) * SampleWeights[i];
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
technique GaussianBlur
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_2_0 PixelShaderF();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
Texture2D xTexture;
|
||||
sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
Texture2D xStencil;
|
||||
sampler StencilSampler = sampler_state { Texture = <xStencil>; };
|
||||
|
||||
float4 inColor;
|
||||
|
||||
float aCutoff;
|
||||
float aMultiplier;
|
||||
|
||||
float cCutoff;
|
||||
float cMultiplier;
|
||||
|
||||
float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 c = xTexture.Sample(TextureSampler, texCoord) * inColor;
|
||||
|
||||
float4 stencilColor = xStencil.Sample(StencilSampler, texCoord);
|
||||
|
||||
float aDiff = stencilColor.a - aCutoff;
|
||||
|
||||
clip(aDiff);
|
||||
|
||||
float cDiff = stencilColor.a - cCutoff;
|
||||
|
||||
return float4(
|
||||
lerp(stencilColor.rgb, c.rgb, clamp(cDiff * cMultiplier, 0.0f, 1.0f)),
|
||||
min(aDiff * aMultiplier, c.a));
|
||||
}
|
||||
|
||||
technique StencilShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 main();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
Texture xTexture;
|
||||
sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
Texture xStencil;
|
||||
sampler StencilSampler = sampler_state { Texture = <xStencil>; };
|
||||
|
||||
float4 inColor;
|
||||
|
||||
float aCutoff;
|
||||
float aMultiplier;
|
||||
|
||||
float cCutoff;
|
||||
float cMultiplier;
|
||||
|
||||
float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 c = tex2D(TextureSampler, texCoord) * inColor;
|
||||
|
||||
float4 stencilColor = tex2D(StencilSampler, texCoord);
|
||||
|
||||
float aDiff = stencilColor.a - aCutoff;
|
||||
|
||||
clip(aDiff);
|
||||
|
||||
float cDiff = stencilColor.a - cCutoff;
|
||||
|
||||
return float4(
|
||||
lerp(stencilColor.rgb, c.rgb, clamp(cDiff * cMultiplier, 0.0f, 1.0f)),
|
||||
min(aDiff * aMultiplier, c.a));
|
||||
}
|
||||
|
||||
technique StencilShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_2_0 main();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
Texture2D xTexture;
|
||||
sampler TextureSampler = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
float4x4 xTransform;
|
||||
|
||||
const int MaxDeformResolution = 15 * 15;
|
||||
|
||||
float2 deformArray[15 * 15];
|
||||
|
||||
int deformArrayWidth;
|
||||
int deformArrayHeight;
|
||||
|
||||
float2 uvTopLeft;
|
||||
float2 uvBottomRight;
|
||||
|
||||
float4 tintColor;
|
||||
float4 solidColor;
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexShaderOutput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0;
|
||||
};
|
||||
|
||||
VertexShaderOutput mainVS(in VertexShaderInput input)
|
||||
{
|
||||
VertexShaderOutput output = (VertexShaderOutput)0;
|
||||
|
||||
float2 normalizedUv = (input.TexCoords - uvTopLeft) / (uvBottomRight - uvTopLeft);
|
||||
|
||||
int2 deformIndexTopLeft =
|
||||
{
|
||||
min(floor(normalizedUv.x * (deformArrayWidth - 1)), deformArrayWidth - 1),
|
||||
min(floor(normalizedUv.y * (deformArrayHeight - 1)), deformArrayHeight - 1)
|
||||
};
|
||||
int2 deformIndexBottomRight =
|
||||
{
|
||||
min(deformIndexTopLeft.x + 1, deformArrayWidth - 1),
|
||||
min(deformIndexTopLeft.y + 1, deformArrayHeight - 1)
|
||||
};
|
||||
|
||||
float2 deformTopLeft = deformArray[deformIndexTopLeft.x + deformIndexTopLeft.y * deformArrayWidth];
|
||||
float2 deformTopRight = deformArray[deformIndexBottomRight.x + deformIndexTopLeft.y * deformArrayWidth];
|
||||
float2 deformBottomLeft = deformArray[deformIndexTopLeft.x + deformIndexBottomRight.y * deformArrayWidth];
|
||||
float2 deformBottomRight = deformArray[deformIndexBottomRight.x + deformIndexBottomRight.y * deformArrayWidth];
|
||||
|
||||
float divX = 1.0 / (deformArrayWidth - 1);
|
||||
float divY = 1.0 / (deformArrayHeight - 1);
|
||||
|
||||
float2 vertexOffset =
|
||||
{
|
||||
lerp(
|
||||
lerp(deformTopLeft, deformTopRight, (normalizedUv.x % divX) / divX),
|
||||
lerp(deformBottomLeft, deformBottomRight, (normalizedUv.x % divX) / divX),
|
||||
(normalizedUv.y % divY) / divY)
|
||||
};
|
||||
|
||||
output.Position = mul(input.Position + float4(vertexOffset, 0, 0), xTransform);
|
||||
output.Color = input.Color * tintColor;
|
||||
output.TexCoords = input.TexCoords;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 mainPS(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
return xTexture.Sample(TextureSampler, input.TexCoords) * input.Color;
|
||||
}
|
||||
|
||||
float4 solidColorPS(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
return solidColor * xTexture.Sample(TextureSampler, input.TexCoords).a;
|
||||
}
|
||||
|
||||
technique DeformShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_4_0_level_9_1 mainVS();
|
||||
PixelShader = compile ps_4_0_level_9_1 mainPS();
|
||||
}
|
||||
}
|
||||
|
||||
technique DeformShaderSolidColor
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_4_0_level_9_1 mainVS();
|
||||
PixelShader = compile ps_4_0_level_9_1 solidColorPS();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
Texture2D xTexture;
|
||||
sampler TextureSampler = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
float4x4 xTransform;
|
||||
|
||||
static const int MaxDeformResolution = 15 * 15;
|
||||
|
||||
float2 deformArray[15 * 15];
|
||||
|
||||
int deformArrayWidth;
|
||||
int deformArrayHeight;
|
||||
|
||||
float2 uvTopLeft;
|
||||
float2 uvBottomRight;
|
||||
|
||||
float4 tintColor;
|
||||
float4 solidColor;
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexShaderOutput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0;
|
||||
};
|
||||
|
||||
VertexShaderOutput mainVS(in VertexShaderInput input)
|
||||
{
|
||||
VertexShaderOutput output = (VertexShaderOutput)0;
|
||||
|
||||
float2 normalizedUv = (input.TexCoords - uvTopLeft) / (uvBottomRight - uvTopLeft);
|
||||
|
||||
int2 deformIndexTopLeft =
|
||||
{
|
||||
min(floor(normalizedUv.x * (deformArrayWidth - 1)), deformArrayWidth - 1),
|
||||
min(floor(normalizedUv.y * (deformArrayHeight - 1)), deformArrayHeight - 1)
|
||||
};
|
||||
int2 deformIndexBottomRight =
|
||||
{
|
||||
min(deformIndexTopLeft.x + 1, deformArrayWidth - 1),
|
||||
min(deformIndexTopLeft.y + 1, deformArrayHeight - 1)
|
||||
};
|
||||
|
||||
float2 deformTopLeft = deformArray[deformIndexTopLeft.x + deformIndexTopLeft.y * deformArrayWidth];
|
||||
float2 deformTopRight = deformArray[deformIndexBottomRight.x + deformIndexTopLeft.y * deformArrayWidth];
|
||||
float2 deformBottomLeft = deformArray[deformIndexTopLeft.x + deformIndexBottomRight.y * deformArrayWidth];
|
||||
float2 deformBottomRight = deformArray[deformIndexBottomRight.x + deformIndexBottomRight.y * deformArrayWidth];
|
||||
|
||||
float divX = 1.0 / deformArrayWidth;
|
||||
float divY = 1.0 / deformArrayHeight;
|
||||
|
||||
float2 vertexOffset =
|
||||
{
|
||||
lerp(
|
||||
lerp(deformTopLeft, deformTopRight, (normalizedUv.x % divX) / divX),
|
||||
lerp(deformBottomLeft, deformBottomRight, (normalizedUv.x % divX) / divX),
|
||||
(normalizedUv.y % divY) / divY)
|
||||
};
|
||||
|
||||
output.Position = mul(input.Position + float4(vertexOffset, 0, 0), xTransform);
|
||||
output.Color = input.Color * tintColor;
|
||||
output.TexCoords = input.TexCoords;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 mainPS(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
return xTexture.Sample(TextureSampler, input.TexCoords) * input.Color;
|
||||
}
|
||||
|
||||
float4 solidColorPS(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
return solidColor * xTexture.Sample(TextureSampler, input.TexCoords).a;
|
||||
}
|
||||
|
||||
technique DeformShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_3_0 mainVS();
|
||||
PixelShader = compile ps_3_0 mainPS();
|
||||
}
|
||||
}
|
||||
|
||||
technique DeformShaderSolidColor
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_3_0 mainVS();
|
||||
PixelShader = compile ps_3_0 solidColorPS();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
Texture2D xTexture;
|
||||
sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
Texture2D xLosTexture;
|
||||
sampler LosSampler = sampler_state { Texture = <xLosTexture>; };
|
||||
|
||||
float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 sampleColor = xTexture.Sample(TextureSampler, texCoord);
|
||||
float4 losColor = xLosTexture.Sample(LosSampler, texCoord);
|
||||
|
||||
float obscureAmount = 1.0f - losColor.r;
|
||||
|
||||
float4 outColor = float4(
|
||||
sampleColor.r * color.r,
|
||||
sampleColor.g * color.g,
|
||||
sampleColor.b * color.b,
|
||||
obscureAmount);
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
technique LosShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 main();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
Texture xTexture;
|
||||
sampler TextureSampler : register (s0) = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
Texture xLosTexture;
|
||||
sampler LosSampler = sampler_state { Texture = <xLosTexture>; };
|
||||
|
||||
float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 sampleColor = tex2D(TextureSampler, texCoord);
|
||||
float4 losColor = tex2D(LosSampler, texCoord);
|
||||
|
||||
float obscureAmount = 1.0f - losColor.r;
|
||||
|
||||
float4 outColor = float4(
|
||||
sampleColor.r * color.r,
|
||||
sampleColor.g * color.g,
|
||||
sampleColor.b * color.b,
|
||||
obscureAmount);
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
technique LosShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_2_0 main();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
Texture2D xTexture;
|
||||
sampler TextureSampler = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
Texture2D xDistortTexture;
|
||||
sampler DistortSampler =
|
||||
sampler_state
|
||||
{
|
||||
Texture = <xDistortTexture>;
|
||||
MagFilter = LINEAR;
|
||||
MinFilter = LINEAR;
|
||||
MipFilter = LINEAR;
|
||||
AddressU = WRAP;
|
||||
AddressV = WRAP;
|
||||
};
|
||||
|
||||
float blurDistance;
|
||||
|
||||
float2 distortScale;
|
||||
float2 distortUvOffset;
|
||||
|
||||
float3 chromaticAberrationStrength;
|
||||
|
||||
// Apply radial distortion to the given coordinate.
|
||||
float2 radialDistortion(float2 coord, float distortion)
|
||||
{
|
||||
float2 cc = coord - 0.5;
|
||||
float dist = dot(cc, cc) * distortion;
|
||||
//return coord * (pos + cc * (1.0 + dist) * dist) / pos;
|
||||
return coord + (dist * dist + dist) * cc;
|
||||
}
|
||||
|
||||
/*float4 sampleWithChromaticAberration(float2 samplePos)
|
||||
{
|
||||
return float4(
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.r)).r,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.g)).g,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.b)).b,
|
||||
1);
|
||||
}*/
|
||||
float3 sampleChannelsSeparately(float2 samplePosR, float2 samplePosG, float2 samplePosB)
|
||||
{
|
||||
return float3(
|
||||
tex2D(TextureSampler, samplePosR).r,
|
||||
tex2D(TextureSampler, samplePosG).g,
|
||||
tex2D(TextureSampler, samplePosB).b);
|
||||
}
|
||||
|
||||
float3 sampleWithChromaticAberration(float2 samplePos)
|
||||
{
|
||||
return float3(
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.r)).r,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.g)).g,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.b)).b);
|
||||
}
|
||||
|
||||
float4 blur(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 sample;
|
||||
sample = tex2D(TextureSampler, float2(texCoord.x + blurDistance, texCoord.y + blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(texCoord.x - blurDistance, texCoord.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(texCoord.x + blurDistance, texCoord.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(texCoord.x - blurDistance, texCoord.y + blurDistance));
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 distort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
return tex2D(TextureSampler, samplePos);
|
||||
}
|
||||
|
||||
float4 blurDistort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
float4 sample;
|
||||
sample = tex2D(TextureSampler, float2(samplePos.x + blurDistance, samplePos.y + blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(samplePos.x - blurDistance, samplePos.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(samplePos.x + blurDistance, samplePos.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(samplePos.x - blurDistance, samplePos.y + blurDistance));
|
||||
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 chromaticAberration(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
return float4(sampleWithChromaticAberration(texCoord), 1);
|
||||
}
|
||||
|
||||
float4 chromaticAberrationDistort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
return float4(sampleWithChromaticAberration(samplePos), 1);
|
||||
}
|
||||
|
||||
float4 blurChromaticAberration(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float2 samplePosR = radialDistortion(texCoord, chromaticAberrationStrength.r);
|
||||
float2 samplePosG = radialDistortion(texCoord, chromaticAberrationStrength.g);
|
||||
float2 samplePosB = radialDistortion(texCoord, chromaticAberrationStrength.b);
|
||||
|
||||
float2 blurTopLeft = -blurDistance;
|
||||
float2 blurTopRight = float2(blurDistance, -blurDistance);
|
||||
float2 blurBottomRight = blurDistance;
|
||||
float2 blurBottomLeft = float2(-blurDistance, blurDistance);
|
||||
|
||||
float3 sample;
|
||||
sample = sampleChannelsSeparately(samplePosR + blurTopLeft, samplePosG + blurTopLeft, samplePosB + blurTopLeft);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurTopRight, samplePosG + blurTopRight, samplePosB + blurTopRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomRight, samplePosG + blurBottomRight, samplePosB + blurBottomRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomLeft, samplePosG + blurBottomLeft, samplePosB + blurBottomLeft);
|
||||
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return float4(sample, 1);
|
||||
}
|
||||
|
||||
float4 blurChromaticAberrationDistort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
float2 samplePosR = radialDistortion(samplePos, chromaticAberrationStrength.r);
|
||||
float2 samplePosG = radialDistortion(samplePos, chromaticAberrationStrength.g);
|
||||
float2 samplePosB = radialDistortion(samplePos, chromaticAberrationStrength.b);
|
||||
|
||||
float2 blurTopLeft = -blurDistance;
|
||||
float2 blurTopRight = float2(blurDistance, -blurDistance);
|
||||
float2 blurBottomRight = blurDistance;
|
||||
float2 blurBottomLeft = float2(-blurDistance, blurDistance);
|
||||
|
||||
float3 sample;
|
||||
sample = sampleChannelsSeparately(samplePosR + blurTopLeft, samplePosG + blurTopLeft, samplePosB + blurTopLeft);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurTopRight, samplePosG + blurTopRight, samplePosB + blurTopRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomRight, samplePosG + blurBottomRight, samplePosB + blurBottomRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomLeft, samplePosG + blurBottomLeft, samplePosB + blurBottomLeft);
|
||||
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return float4(sample, 1);
|
||||
}
|
||||
|
||||
technique Distort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 distort();
|
||||
}
|
||||
}
|
||||
|
||||
technique Blur
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 blur();
|
||||
}
|
||||
}
|
||||
|
||||
technique BlurDistort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 blurDistort();
|
||||
}
|
||||
}
|
||||
|
||||
technique BlurChromaticAberration
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 blurChromaticAberration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
technique ChromaticAberration
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 chromaticAberration();
|
||||
}
|
||||
}
|
||||
|
||||
technique ChromaticAberrationDistort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 chromaticAberrationDistort();
|
||||
}
|
||||
}
|
||||
|
||||
technique BlurChromaticAberrationDistort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 blurChromaticAberrationDistort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
Texture2D xTexture;
|
||||
sampler TextureSampler = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
Texture2D xDistortTexture;
|
||||
sampler DistortSampler =
|
||||
sampler_state
|
||||
{
|
||||
Texture = <xDistortTexture>;
|
||||
MagFilter = LINEAR;
|
||||
MinFilter = LINEAR;
|
||||
MipFilter = LINEAR;
|
||||
AddressU = WRAP;
|
||||
AddressV = WRAP;
|
||||
};
|
||||
|
||||
float blurDistance;
|
||||
|
||||
float2 distortScale;
|
||||
float2 distortUvOffset;
|
||||
|
||||
float3 chromaticAberrationStrength;
|
||||
|
||||
// Apply radial distortion to the given coordinate.
|
||||
float2 radialDistortion(float2 coord, float distortion)
|
||||
{
|
||||
float2 cc = coord - 0.5;
|
||||
float dist = dot(cc, cc) * distortion;
|
||||
//return coord * (pos + cc * (1.0 + dist) * dist) / pos;
|
||||
return coord + (dist * dist + dist) * cc;
|
||||
}
|
||||
|
||||
/*float4 sampleWithChromaticAberration(float2 samplePos)
|
||||
{
|
||||
return float4(
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.r)).r,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.g)).g,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.b)).b,
|
||||
1);
|
||||
}*/
|
||||
float3 sampleChannelsSeparately(float2 samplePosR, float2 samplePosG, float2 samplePosB)
|
||||
{
|
||||
return float3(
|
||||
tex2D(TextureSampler, samplePosR).r,
|
||||
tex2D(TextureSampler, samplePosG).g,
|
||||
tex2D(TextureSampler, samplePosB).b);
|
||||
}
|
||||
|
||||
float3 sampleWithChromaticAberration(float2 samplePos)
|
||||
{
|
||||
return float3(
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.r)).r,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.g)).g,
|
||||
tex2D(TextureSampler, radialDistortion(samplePos, chromaticAberrationStrength.b)).b);
|
||||
}
|
||||
|
||||
float4 blur(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 sample;
|
||||
sample = tex2D(TextureSampler, float2(texCoord.x + blurDistance, texCoord.y + blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(texCoord.x - blurDistance, texCoord.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(texCoord.x + blurDistance, texCoord.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(texCoord.x - blurDistance, texCoord.y + blurDistance));
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 distort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
return tex2D(TextureSampler, samplePos);
|
||||
}
|
||||
|
||||
float4 blurDistort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
float4 sample;
|
||||
sample = tex2D(TextureSampler, float2(samplePos.x + blurDistance, samplePos.y + blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(samplePos.x - blurDistance, samplePos.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(samplePos.x + blurDistance, samplePos.y - blurDistance));
|
||||
sample += tex2D(TextureSampler, float2(samplePos.x - blurDistance, samplePos.y + blurDistance));
|
||||
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 chromaticAberration(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
return float4(sampleWithChromaticAberration(texCoord), 1);
|
||||
}
|
||||
|
||||
float4 chromaticAberrationDistort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
return float4(sampleWithChromaticAberration(samplePos), 1);
|
||||
}
|
||||
|
||||
float4 blurChromaticAberration(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float2 samplePosR = radialDistortion(texCoord, chromaticAberrationStrength.r);
|
||||
float2 samplePosG = radialDistortion(texCoord, chromaticAberrationStrength.g);
|
||||
float2 samplePosB = radialDistortion(texCoord, chromaticAberrationStrength.b);
|
||||
|
||||
float2 blurTopLeft = -blurDistance;
|
||||
float2 blurTopRight = float2(blurDistance, -blurDistance);
|
||||
float2 blurBottomRight = blurDistance;
|
||||
float2 blurBottomLeft = float2(-blurDistance, blurDistance);
|
||||
|
||||
float3 sample;
|
||||
sample = sampleChannelsSeparately(samplePosR + blurTopLeft, samplePosG + blurTopLeft, samplePosB + blurTopLeft);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurTopRight, samplePosG + blurTopRight, samplePosB + blurTopRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomRight, samplePosG + blurBottomRight, samplePosB + blurBottomRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomLeft, samplePosG + blurBottomLeft, samplePosB + blurBottomLeft);
|
||||
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return float4(sample, 1);
|
||||
}
|
||||
|
||||
float4 blurChromaticAberrationDistort(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(DistortSampler, texCoord + distortUvOffset);
|
||||
bumpColor = (bumpColor + tex2D(DistortSampler, texCoord - distortUvOffset * 2.0f)) * 0.5f;
|
||||
|
||||
float2 samplePos = texCoord;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * distortScale.x;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * distortScale.y;
|
||||
|
||||
float2 samplePosR = radialDistortion(samplePos, chromaticAberrationStrength.r);
|
||||
float2 samplePosG = radialDistortion(samplePos, chromaticAberrationStrength.g);
|
||||
float2 samplePosB = radialDistortion(samplePos, chromaticAberrationStrength.b);
|
||||
|
||||
float2 blurTopLeft = -blurDistance;
|
||||
float2 blurTopRight = float2(blurDistance, -blurDistance);
|
||||
float2 blurBottomRight = blurDistance;
|
||||
float2 blurBottomLeft = float2(-blurDistance, blurDistance);
|
||||
|
||||
float3 sample;
|
||||
sample = sampleChannelsSeparately(samplePosR + blurTopLeft, samplePosG + blurTopLeft, samplePosB + blurTopLeft);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurTopRight, samplePosG + blurTopRight, samplePosB + blurTopRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomRight, samplePosG + blurBottomRight, samplePosB + blurBottomRight);
|
||||
sample += sampleChannelsSeparately(samplePosR + blurBottomLeft, samplePosG + blurBottomLeft, samplePosB + blurBottomLeft);
|
||||
|
||||
sample = sample * 0.25f;
|
||||
|
||||
return float4(sample, 1);
|
||||
}
|
||||
|
||||
technique Distort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 distort();
|
||||
}
|
||||
}
|
||||
|
||||
technique Blur
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 blur();
|
||||
}
|
||||
}
|
||||
|
||||
technique BlurDistort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 blurDistort();
|
||||
}
|
||||
}
|
||||
|
||||
technique BlurChromaticAberration
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 blurChromaticAberration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
technique ChromaticAberration
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 chromaticAberration();
|
||||
}
|
||||
}
|
||||
|
||||
technique ChromaticAberrationDistort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 chromaticAberrationDistort();
|
||||
}
|
||||
}
|
||||
|
||||
technique BlurChromaticAberrationDistort
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 blurChromaticAberrationDistort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
float xBlurDistance;
|
||||
|
||||
Texture2D xWaterBumpMap;
|
||||
sampler WaterBumpSampler =
|
||||
sampler_state
|
||||
{
|
||||
Texture = <xWaterBumpMap>;
|
||||
MagFilter = LINEAR;
|
||||
MinFilter = LINEAR;
|
||||
MipFilter = LINEAR;
|
||||
AddressU = WRAP;
|
||||
AddressV = WRAP;
|
||||
};
|
||||
|
||||
Texture2D xTexture;
|
||||
sampler TextureSampler = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
float4x4 xTransform;
|
||||
float4x4 xUvTransform;
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0; // added
|
||||
};
|
||||
|
||||
struct VertexShaderOutput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0; // added
|
||||
};
|
||||
|
||||
|
||||
float xWaveWidth;
|
||||
float xWaveHeight;
|
||||
float2 xBumpPos;
|
||||
float2 xBumpScale;
|
||||
|
||||
float2 xUvOffset;
|
||||
|
||||
float4 waterColor;
|
||||
|
||||
VertexShaderOutput mainVS(in VertexShaderInput input)
|
||||
{
|
||||
VertexShaderOutput output = (VertexShaderOutput)0;
|
||||
|
||||
output.Position = mul(input.Position, xTransform);
|
||||
output.Color = input.Color;
|
||||
output.TexCoords = mul(input.Position, xUvTransform).xy;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 mainPS(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
float4 bumpColor = xWaterBumpMap.Sample(WaterBumpSampler, xUvOffset + (input.TexCoords+xBumpPos) * xBumpScale);
|
||||
bumpColor = (bumpColor + xWaterBumpMap.Sample(WaterBumpSampler, xUvOffset + (input.TexCoords-xBumpPos*2) * xBumpScale)) * 0.5f;
|
||||
|
||||
float2 samplePos = input.TexCoords;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * xWaveWidth * input.Color.r;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * xWaveHeight * input.Color.g;
|
||||
|
||||
float4 sample = xTexture.Sample(TextureSampler, samplePos);
|
||||
|
||||
sample.a = input.Color.a;
|
||||
sample = lerp(sample, sample * waterColor, input.Color.b);
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 mainPSBlurred(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
float4 bumpColor = xWaterBumpMap.Sample(WaterBumpSampler, xUvOffset + (input.TexCoords + xBumpPos) * xBumpScale);
|
||||
bumpColor = (bumpColor + xWaterBumpMap.Sample(WaterBumpSampler, xUvOffset + (input.TexCoords - xBumpPos * 2) * xBumpScale)) * 0.5f;
|
||||
|
||||
float2 samplePos = input.TexCoords;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * xWaveWidth * input.Color.r;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * xWaveHeight * input.Color.g;
|
||||
|
||||
float4 sample;
|
||||
sample = xTexture.Sample(TextureSampler, float2(samplePos.x + xBlurDistance, samplePos.y + xBlurDistance));
|
||||
sample += xTexture.Sample(TextureSampler, float2(samplePos.x - xBlurDistance, samplePos.y - xBlurDistance));
|
||||
sample += xTexture.Sample(TextureSampler, float2(samplePos.x + xBlurDistance, samplePos.y - xBlurDistance));
|
||||
sample += xTexture.Sample(TextureSampler, float2(samplePos.x - xBlurDistance, samplePos.y + xBlurDistance));
|
||||
|
||||
sample = sample * 0.25;
|
||||
|
||||
sample.a = input.Color.a;
|
||||
sample = lerp(sample, sample * waterColor, input.Color.b);
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 mainPostProcess(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(WaterBumpSampler, texCoord + xUvOffset + xBumpPos);
|
||||
bumpColor = (bumpColor + tex2D(WaterBumpSampler, texCoord - xUvOffset * 2.0f + xBumpPos)) * 0.5f;
|
||||
|
||||
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 * 0.25;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
technique WaterShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_4_0_level_9_1 mainVS();
|
||||
PixelShader = compile ps_4_0_level_9_1 mainPS();
|
||||
}
|
||||
}
|
||||
|
||||
technique WaterShaderBlurred
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_4_0_level_9_1 mainVS();
|
||||
PixelShader = compile ps_4_0_level_9_1 mainPSBlurred();
|
||||
}
|
||||
}
|
||||
|
||||
technique WaterShaderPostProcess
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_4_0_level_9_1 mainPostProcess();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
float xBlurDistance;
|
||||
|
||||
Texture xWaterBumpMap;
|
||||
sampler WaterBumpSampler =
|
||||
sampler_state
|
||||
{
|
||||
Texture = <xWaterBumpMap>;
|
||||
MagFilter = LINEAR;
|
||||
MinFilter = LINEAR;
|
||||
MipFilter = LINEAR;
|
||||
AddressU = WRAP;
|
||||
AddressV = WRAP;
|
||||
};
|
||||
|
||||
Texture xTexture;
|
||||
sampler TextureSampler = sampler_state { Texture = <xTexture>; };
|
||||
|
||||
float4x4 xTransform;
|
||||
float4x4 xUvTransform;
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0; // added
|
||||
};
|
||||
|
||||
struct VertexShaderOutput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float4 Color : COLOR0;
|
||||
float2 TexCoords: TEXCOORD0; // added
|
||||
};
|
||||
|
||||
|
||||
float xWaveWidth;
|
||||
float xWaveHeight;
|
||||
float2 xBumpPos;
|
||||
float2 xBumpScale;
|
||||
|
||||
float2 xUvOffset;
|
||||
|
||||
float4 waterColor;
|
||||
|
||||
VertexShaderOutput mainVS(in VertexShaderInput input)
|
||||
{
|
||||
VertexShaderOutput output = (VertexShaderOutput)0;
|
||||
|
||||
output.Position = mul(input.Position, xTransform);
|
||||
output.Color = input.Color;
|
||||
float4 texCoords = mul(input.Position, xUvTransform);
|
||||
float2 texCoords2D = texCoords.xy;
|
||||
//This is to stop the HLSL compiler from optimizing xUvTransform since that crashes MonoGame
|
||||
//Seems to be a known bug, see https://github.com/MonoGame/MonoGame/issues/5628
|
||||
//We should probably send this to them so they have more to work with
|
||||
texCoords2D.x += floor(texCoords.w*0.001);
|
||||
//--------
|
||||
output.TexCoords = texCoords2D;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 mainPS(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
float4 bumpColor = tex2D(WaterBumpSampler, xUvOffset + (input.TexCoords+xBumpPos) * xBumpScale);
|
||||
bumpColor = (bumpColor + tex2D(WaterBumpSampler, xUvOffset + (input.TexCoords-xBumpPos*2) * xBumpScale)) * 0.5f;
|
||||
|
||||
float2 samplePos = input.TexCoords;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * xWaveWidth * input.Color.r;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * xWaveHeight * input.Color.g;
|
||||
|
||||
float4 sample = tex2D(TextureSampler, samplePos);
|
||||
|
||||
sample.a = input.Color.a;
|
||||
sample = lerp(sample, sample * waterColor, input.Color.b);
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 mainPSBlurred(VertexShaderOutput input) : COLOR
|
||||
{
|
||||
float4 bumpColor = tex2D(WaterBumpSampler, xUvOffset + (input.TexCoords + xBumpPos) * xBumpScale);
|
||||
bumpColor = (bumpColor + tex2D(WaterBumpSampler, xUvOffset + (input.TexCoords - xBumpPos * 2) * xBumpScale)) * 0.5f;
|
||||
|
||||
float2 samplePos = input.TexCoords;
|
||||
|
||||
samplePos.x += (bumpColor.r - 0.5f) * xWaveWidth * input.Color.r;
|
||||
samplePos.y += (bumpColor.g - 0.5f) * xWaveHeight * input.Color.g;
|
||||
|
||||
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 * 0.25;
|
||||
|
||||
sample.a = input.Color.a;
|
||||
sample = lerp(sample, sample * waterColor, input.Color.b);
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
float4 mainPostProcess(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||
{
|
||||
float4 bumpColor = tex2D(WaterBumpSampler, texCoord + xUvOffset + xBumpPos);
|
||||
bumpColor = (bumpColor + tex2D(WaterBumpSampler, texCoord - xUvOffset * 2.0f + xBumpPos)) * 0.5f;
|
||||
|
||||
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 * 0.25;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
technique WaterShader
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_3_0 mainVS();
|
||||
PixelShader = compile ps_3_0 mainPS();
|
||||
}
|
||||
}
|
||||
|
||||
technique WaterShaderBlurred
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
VertexShader = compile vs_3_0 mainVS();
|
||||
PixelShader = compile ps_3_0 mainPSBlurred();
|
||||
}
|
||||
}
|
||||
|
||||
technique WaterShaderPostProcess
|
||||
{
|
||||
pass Pass1
|
||||
{
|
||||
PixelShader = compile ps_3_0 mainPostProcess();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user