Sign in to follow this  
danromeo

Damndest problem, HLSL, XNA 4

Recommended Posts

danromeo    238
Hiya.

I'm sending a variable to my effect: [font="Consolas"][size="2"][font="Consolas"][size="2"]effect.Parameters[[font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Speed"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]].SetValue(Object[/size][/font][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Position.X);
[/size][/font][/size][/font][/size][/font][/size][/font]
where Object.Position is a Vector3 vector.

If I send static float values, [font="Consolas"][size="2"]effect.Parameters[[color="#a31515"][color="#a31515"][color="#a31515"]"Speed"[/color][/color][/color]].SetValue(0.00244[/size][/font][font="Consolas"][size="2"]), everything is fine.

But if I send the vector variable, effect.Parameters[[font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Speed"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]].SetValue(Object[/size][/font][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Position.X), the results have no discernible relationship to the value being sent....almost as if I'm sending random values.

Any idea what the HECK this is all about????

On Topic, please...I want to know why the expected values aren't getting to the shader.

The full function is below:

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]public[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] [/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] Draw([/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Matrix[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] viewprojection, [/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Effect[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] effect)

{

effect.CurrentTechnique = effect.Techniques[[/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Draw"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]];

Game.GraphicsDevice.BlendState = [/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]BlendState[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].NonPremultiplied;

[/size][/font][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]foreach[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] ([/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]EffectPass[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] pass [/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]in[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] effect.CurrentTechnique.Passes)

{

[/size][/font][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]effect.Parameters[[/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"Speed"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]].SetValue(MyObject[/size][/font][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Position.X * 0.01f);

[/size][/font][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]pass.Apply();

Game.GraphicsDevice.DrawUserIndexedPrimitives([/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]PrimitiveType[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].TriangleStrip,Vertices,0,Vertices.Length,Indices,0,Triangles);

}

}

[/size][/font][/size][/font][/size][/font][/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
AaronAsh    100
I'm not exactly a guru, but it looks like this is sending a double into your effect:
[code]effect.Parameters["Speed"].SetValue(0.00244)[/code]

whereas here you're sending a float:
[code]effect.Parameters["Speed"].SetValue(MyObject.Position.X * 0.01f);[/code]

Share this post


Link to post
Share on other sites
pekarn    173
How is Speed declared in the shader? Have you checked to make sure the contents of MyObject.Position are correct? How is Speed used in the shader?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this