Do you mean it wont compile and run or it is broken ?
Edit nvm ok i guess it works i had two textures that were about the same in there.
It compiles and runs with some minor changes.
If you need to make it run with ps_2_0 then look to the link at the bottom you would have to make further additional changes probably also including a basic vertex shader as well as shown in the post example.
//
// refract
//
#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
//matrix WorldViewProjection;
float2 DisplacementScroll;
Texture2D TextureA;
sampler2D TextureSamplerA = sampler_state
{
Texture = <TextureA>;
};
Texture2D TextureB;
sampler2D DisplacementSampler = sampler_state
{
Texture = <TextureB>;
};
float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
// Look up the displacement amount.
float2 displacement = tex2D(DisplacementSampler, DisplacementScroll + texCoord / 3);
// Offset the main texture coordinates.
texCoord += displacement * 0.2 - 0.15;
// Look up into the main texture.
return tex2D(TextureSamplerA, texCoord) * color;
}
technique Refraction
{
pass Pass0
{
PixelShader = compile PS_SHADERMODEL main(); // ps_2_0 doesn't error either.
}
}
the relevant part of the game1 pretty obvious what my textures are and calls are that you need to change.
other then that i dunno what its supposed to be doing.
protected override void Draw(GameTime gameTime)
{
Gu.device.Clear(Color.CornflowerBlue);
//GraphicsDevice.SetRenderTarget(rt);
//GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue , 1f, 0); //new Vector4(1.0f, .99f, .99f, 1.0f)
DrawRefractCat(gameTime);
base.Draw(gameTime);
}
void DrawRefractCat(GameTime gameTime)
{
// Draw the background image.
Gu.spriteBatch.Begin();
Gu.spriteBatch.Draw(BasicTextures.checkerBoard, GraphicsDevice.Viewport.Bounds, Color.White);
Gu.spriteBatch.End();
// Set an effect parameter to make the
// displacement texture scroll in a giant circle.
refractionEffect.Parameters["DisplacementScroll"].SetValue(MoveInCircle(gameTime, new Vector2(100, 100), 0.1f));
refractionEffect.Parameters["TextureA"].SetValue(BasicTextures.grid);
refractionEffect.Parameters["TextureB"].SetValue(BasicTextures.checkerBoard);
// Set the displacement texture.
//Gu.graphics.GraphicsDevice.Textures[1] = BasicTextures.grid;
// Begin the sprite batch.
Gu.spriteBatch.Begin(0, null, null, null, null, refractionEffect);
// Draw the sprite.
Gu.spriteBatch.Draw(BasicTextures.checkerBoardRed, MoveInCircle(gameTime,new Vector2(100,100), 1),Color.White);
// End the sprite batch.
Gu.spriteBatch.End();
}
/// <summary>
/// Helper for moving a value around in a circle.
/// </summary>
static Vector2 MoveInCircle(GameTime gameTime, Vector2 position, float speed)
{
double time = gameTime.TotalGameTime.TotalSeconds * speed;
float x = (float)Math.Cos(time);
float y = (float)Math.Sin(time);
return new Vector2(x, y) + position;
}
protected override void QuickDrawSpriteBatch(GameTime gameTime)
{
itemList01.Draw(gameTime);
// DrawTest1(gameTime);
DrawTest2_bound(gameTime);
}
Look to the bottom example were i got the ps_2_0 shader to run thru spritebatch also look at game1 's draw its a little hacky but it worked.