Sign in to follow this  
adelamro

How would you save D3D effects?

Recommended Posts

adelamro    122
How would you save the state of a Direct3D effect? I mean, you could create a vector of parameters of various types( float, float4, string.. etc), and save that, but the effect file could be changed between runs. So the number and types of parameters in an effect is not constant, yet we need to store their values since they could be changed by a script or an event or something. Any thoughts?

Share this post


Link to post
Share on other sites
51mon    342
I'm not sure if I understands you. You could store almost anything around the GPU in a .fx file. But if you want to store variables stored in the constant table during run IDirect3DDevice9 has a lot of functions for you, and disc save them to a .fx file. But basicly I don't understand your problem, all the GPU data has to go through the CPU? The .fx file is interpeted by the application.

Share this post


Link to post
Share on other sites
adelamro    122
I'm sorry I didn't clarify more. Also, I'm sorry I posted this too soon - I have come up with a solution myself. So here it is if you're still interested.

Suppose we're writing a game, and each material is a D3D effect. Now, the player's sword uses a metal material. Now assume some script changes the color of the matal to reflect, say, corrosion. How do we maintain this change when the game is saved?

One solution is to modify the metal color in the effect file itself, but this is not good - logically, a material file shouldn't be modified by the app which uses it. The right answer is to store information on each material in the scene. Now, since it's hard to tell which parameters have changed since the material (effect) was first loaded, we need to store all parameters of an effect as type-value pairs when the game is saved, and load them and apply them to the corresponding effect interface when the game is loaded. The problem that was troubling me was changing the effect file between runs, possibly adding and removing parameters.

The solution is, rather than store the effect parameters as an array of type-value pairs, we store them as {name, type, value} structures. Now, when loading, we search the effect interface for the parameters stored along with the scene and modify their values as needed, and we add any new parameters and we remove the ones which are no longer present in the effect file.

Thank you, gentlemen, and again, sorry.

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