How to store Effect parameters in class ?
I’m stuck in this problem for the 3rd day now and I think I’m slowly going to be insane.
I tried to create a class named EffectParameter so I can store/set my parameter values for each object’s shader dynamically.
I tried the to store the ParameterValue in Object type
Object ParameterData;
But I encountered a problem where I need to read from this class….this is where everything going down in the hill.
The method effect.Parameters["parametername"].SetValue() only accept a few kind of types.
And I cannot pass an object to this method.
So I tried to Cast this object.
public T ReadData<T>()
{
return (T)(object)this.ParameterDataVal;
}
But with this my problem is that I need to know the specific type of this object when I set it (Float,Texture2D etc.)
And I cannot use a type variable to determine the type of this object.
I tried to use (typevariable)(object)this.ParameterDataVal;
But it just gave me errors.
I was mad,so I searched the net for solution for dynamic typing.
But I found no method for my problem.
Then I realized maybe I’m making problems of a simple thing.
So I decided to I use an EffectParameter to store my data.
But then I had another problem with this, again when I try to set this data to the effect….
So I tried to give this Parameter to the effect with a method,but I still getting error that ‘It’s readonly.’.
So I cannot add my EffectParameter to the collection.
I tried many ways. But no success.
I’m totally lost in this. I have no idea what else to do.
Anybody ever encountered this problem or somebody can provide me a good solution plan?
The solution’s class: