Jump to content
  • Advertisement
Sign in to follow this  
maya18222

passing effect data

This topic is 3712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, At the moment im doing somthing like this, (following Frank Lunas book) .cpp

mFX->BeginPass(i);
			mFX->SetValue(mhDiffuseMtrl, &theMesh->materials[0].Diffuse, sizeof(D3DMATERIAL9));
			mFX->SetValue(mhAmbientMtrl, &theMesh->materials[0].Ambient, sizeof(D3DMATERIAL9));
			mFX->SetValue(mhSpecularMtrl, &theMesh->materials[0].Specular, sizeof(D3DMATERIAL9));
			mFX->SetFloat(mhSpecularPower, theMesh->materials[0].Power);
			mFX->SetMatrix(mhWVP, mvp);

etc etc


.fx
uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInverseTranspose;
uniform extern float4x4 gWVP;

uniform extern float4 gAmbientMtrl;
uniform extern float4 gAmbientLight;
uniform extern float4 gDiffuseMtrl;
uniform extern float4 gDiffuseLight;
uniform extern float4 gSpecularMtrl;
uniform extern float4 gSpecularLight;
uniform extern float  gSpecularPower;
uniform extern float3 gLightVecW;
uniform extern float3 gEyePosW;
uniform extern texture gTex;

etc etc


so im setting up handles in the .cpp, and then declaring the variables in the .fx as extern to access them. but is there a way to just set my material in the .cpp from a mesh, and then just access the data in my effects file using the Semantics. such as i could use in the .fx float3 diffuseCol : COLOR0 without having to use externs. where maybe i define a material in the .cpp and then the data gets punched into the pipeline somthing like D3DCOLORVALUE Diffuse : COLOUR0); D3DCOLORVALUE Ambient : COLOUR1; D3DCOLORVALUE Specular : COLOUR2; D3DCOLORVALUE Emissive : COLOUR3; float Power : (ummmm); similar to the position, which when you specify a mesh gets mapped to POSITION0 and also another question. If i set up a handle in the .cpp to a variable in the .fx, with the data being got from a variable in the app that is static, and the .fx variable being assigned as an extern, when i edit the data in the .fx, will that edit also be passed to the original in the app?

Share this post


Link to post
Share on other sites
Advertisement
POSITION0 is usually a per-vertex data-type. That is, each vertex has a position. On the other hand, gAmbientLight is constant for all vertices in one batch, and therefore it is set as a constant, and is not passed in as per-vertex-data.

You can still use semantics to set constants, though.

for example:
uniform extern float4 gAmbientMtrl : MYCOOLAMBIANTMATERIALSEMANTIC;
you can then use GetVariableBySemantic to get the variable handle (you still need to set the value like you show in your code, though).

As for your second question, when you call SetValue(), the value is copied from the variable you pass. From that point, changes to the variable do not propogate to the FX shader, and the value will be saved untill you call SetValue again.

Also, constants are read-only. You can't change gAmbientMtrl from a shader. If you do assign to it, the HLSL compiler simulates that action by using a temporary register to hold the new value. However, this register is temporary, and on the next execution of the shader, the old (constant) value is restored.

In short - you can't output data from a shader other than through writing to the rendertarget.

Hope this helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!