Sign in to follow this  

fx file global variables not changing

This topic is 3786 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

I'm learning about HLSL and am playing around with the EffectParam.fx file I have modified it by adding a new global variable: float myFloat = 4.0f; Also, as the first line in both the vertex shader and pixel shader I added: myFloat += 0.1f; Then on each frame of my render function, I extract the value of myFloat and print it out on the screen. My expectation is that since the vertex and pixel shaders are being called thousands of times per frame, the value of myFloat should be increasing very rapidly. However, I always read the value 4.0f What part of this am I misunderstanding? PS - excuse the horrible code, it's just test code and I'm just learning
dxDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		dxDevice->BeginScene();
		
		UINT cPasses;
		//g_pEffect->ApplyParameterBlock(g_hParameters);
		
		g_pEffect->SetMatrix( "g_mView", &view );
		g_pEffect->SetMatrix( "g_mProj", &proj );
		g_pEffect->SetMatrix( "g_mWorld", &world );

		g_pEffect->Begin(&cPasses, 0);
		for (UINT iPass = 0; iPass < cPasses; iPass++)
		{
			g_pEffect->BeginPass(iPass);
			// Only call CommitChanges if any state changes have happened
			// after BeginPass is called
			g_pEffect->CommitChanges();
			// Render the mesh with the applied technique			
			dxDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, num_tris);
			
			g_pEffect->EndPass();
		}		
		
		//read global variable out of GPU and print on screen to see if it is changing
		float myFloat;
		g_pEffect->GetFloat("myFloat", &myFloat);

		g_pEffect->End();

		char str[100];
		sprintf(str, "my float = %f, time = %d", myFloat, (int)clock() );

		RECT FontPosition = {0, 0, 640, 480 };
		g_Font->DrawTextA(NULL, str, -1, &FontPosition, DT_CENTER, D3DCOLOR_XRGB(255,0,0) );
		
		dxDevice->EndScene();
		dxDevice->Present(NULL, NULL, NULL, NULL);

Share this post


Link to post
Share on other sites
Global variables get "reset" to their original values each time the shader runs. There's no way to "change" the value of a global var.

Share this post


Link to post
Share on other sites
Hmm. So the only way to get the result of a computation in the GPU is to look at the buffer it was rendering to?

What's the use of the Effect->GetParameter functions if they just return the value you already passed in?

Share this post


Link to post
Share on other sites
Quote:
Original post by yahastu
What's the use of the Effect->GetParameter functions if they just return the value you already passed in?

That they return the value you passed in.

[EDIT] In other words, not much.

Share this post


Link to post
Share on other sites

This topic is 3786 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.

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