Показать сообщение отдельно
Старый 10.04.2012, 21:42   #1
Igor
Мастер
 
Аватар для Igor
 
Регистрация: 03.05.2010
Адрес: Подмосковье
Сообщений: 1,218
Написано 438 полезных сообщений
(для 790 пользователей)
XNA шейдер 3.0

Учусь, пишу шейдер для рисования на 2д текстуре (ну или на экране).
При попытке использовать версию шейдера 3.0 компилятор ругается на то что вершинный шейдер должен быть той же версии.
Что делать? Я вершинный шейдер в коде вообще не использую, возможно он как-то по дефолту работает, но методом тыка искать выход из этой ситуации не получается, а знаний пока нет.

P.S. Версия 2.0 не подходит, если использовать чуть большее количество команд. Производительность особо не волнует, потому что для для формирования изображения эффект применяется только один раз.

На всякий случай код программы:

namespace WindowsGame1
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

RenderTarget2D renderTarget2D;
Effect Shader;
Vector2[] position;
int time=0;

public Game1(){
graphics = new GraphicsDeviceManager(this);
graphics.IsFullScreen = true;
graphics.PreferredBackBufferHeight = 768;
graphics.PreferredBackBufferWidth = 1366;
Content.RootDirectory = "Content";}

protected override void Initialize(){
renderTarget2D = new RenderTarget2D(GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
base.Initialize();
position = new Vector2[3];
}

protected override void LoadContent(){
spriteBatch = new SpriteBatch(GraphicsDevice);
Shader = Content.Load<Effect>("Interference");}

protected override void UnloadContent(){}

protected override void Update(GameTime gameTime){
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
this.Exit();

time+=4;
position[0] = new Vector2((float)( 0.52 + 0.3 * Math.Sin(0.0005 * time)), (float)(0.5 + 0.45*Math.Cos(0.0007 * time)));
position[1] = new Vector2((float)( 0.6 + 0.3 * Math.Cos(0.0006 * time)), (float)(0.6 + 0.3 * Math.Sin(0.0003 * time)));
position[2] = new Vector2((float)( 0.3 + 0.2 * Math.Sin(0.0009 * time)), (float)(0.6 + 0.3 * Math.Cos(0.0015 * time)));

base.Update(gameTime);
}

/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
Shader.Parameters["ratio"].SetValue(new Vector2(1.0f*graphics.PreferredBackBufferHeight/graphics.PreferredBackBufferWidth, 1));
Shader.Parameters["light"].SetValue(new Vector4(1f, 0.7f, 0, 1f));

//кuтайский код
Shader.Parameters["position0"].SetValue(position[0]);
Shader.Parameters["position1"].SetValue(position[1]);
Shader.Parameters["position2"].SetValue(position[2]);

GraphicsDevice.SetRenderTarget(renderTarget2D);
GraphicsDevice.Clear(Color.Black);

GraphicsDevice.SetRenderTarget(null);

spriteBatch.Begin(0,BlendState.AlphaBlend, null, null, null, Shader);
spriteBatch.Draw(renderTarget2D,Vector2.Zero,Color .White);
spriteBatch.End();

base.Draw(gameTime);
}
}
}

код шейдера
sampler ColorSampler : register(s0);

float2 ratio;
float4 light;

//китайский кодинг
float2 position0;
float2 position1;
float2 position2;

float Add(float2 dR)
{
return sin(length(dR/ratio)*50);
}

float4 terferencePS(float2 TexCoords : TEXCOORD0):COLOR0
{
float intens=Add(TexCoords-position0)
+Add(TexCoords-position1)
+Add(TexCoords-position2);
intens=abs(intens/3);
return light*intens+float4(0,0,0,1);
}

technique Interference
{
pass Pass1
{
PixelShader = compile ps_2_0 InterferencePS();
}
}
__________________
О¯О ¡¡¡ʁɔvʎнdǝʚǝdǝu dиW
(Offline)
 
Ответить с цитированием