Thursday, December 08, 2005

update - fx files again

A quick search on goolge revealed this site: http://www.microsoft.com/japan/msdn/directx/japan/dx9/hlsl3.asp [Translated]

Of interest is the effect.GetParameterBySemantic(null, "WORLD");

so it is possible to check up on what variable types there are and then return an
"EffectHandle". Once we have the Effecthandle we can then set the value like so:
---
myEffect.SetValue(hWorld, matWorld)
---
Where hWorld is the EffectHandle returned from the GetParameterBySemantic method
and matWorld is the value to set, in this case the world matrix

So after reading the code on the site I produced a class to hold the effect. I tested the program and guess what happened... my once nice clean space ship just dissapeared!
I ran into this problem before, it's something to do with those parameters I need to set.
Now I know the code before today was working. Luckily for me I keep backups of everyday. So I compared the code and it looked almost the same. Originaly I ran
"MyEffect.CommitChanges()" and I multiplied the matrices differently and set the values a little differently (I found out the parameter type and then got a handle to it).
I basically copied and pasted my old code for settings the values and pasted it into my render routine in my effect class. Then my once nice clean space ship got a lovely coat of gold.
Hoorah, I said quietly.
After a little looking and commenting out, it turned out that, before when I used the WorldViewProj matrix I had set it to Matrix.Identity.
Anyway now it's working.

So today before it was working I had:
---
dim matWorldViewProj As Matrix
---
and I was using the following to multiply the matrices.:
---
matWorldViewProj = Matrix.Multiply(matWorldViewProj, matWorld)
matWorldViewProj = Matrix.Multiply(matWorldViewProj, matView)
matWorldViewProj = Matrix.Multiply(matWorldViewProj, matProjection)
---
A silly error I guess, multiplying "matWorldViewProj" before it had a value.

So now the working code that multiplies the matrices is like this:
---
matWorldViewProj = Matrix.Multiply(Matrix.Multiply( _
matWorld, _
matView), _
matProjection)
---
I could've used "dim matWorldViewProj As Matrix = matrix.Identity" to solve it also, but I thought I might as well multiply the matrices this way. This seems to have solved the problem.


This screenshot shows the MetallicFlakes.fx file in action. There looks like there is a refelection as you move the camera around.


I also found this site: http://www.mvps.org/directx/indexes/direct3d_articles.htm
which has lots of articles, there are a couple that might help with selecting an object in 3d space with the mouse i.e. Ray Picking.

0 Comments:

Post a Comment

<< Home


___