Jump to content

  • Log In with Google      Sign In   
  • Create Account

DirectX11/HLSL issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • This topic is locked This topic is locked
1 reply to this topic

#1 stgFX   Members   -  Reputation: 116

Like
0Likes
Like

Posted 29 October 2011 - 12:56 PM

Hello everyone!

I'm quite new to DirectX and I'm making a school project in DX11. I have some issues with constants in HLSL...


Could anyone pls explain to me, how do constants/global variables in HLSL work? Because I'm making a simple demo, and want to access constants in cbuffer from pixel shader. But it doesn't work! I tried to even put them outside the cbuffer and set it manually in .fx source - same result.

snippet from .fx file:
cbuffer ConstantBuffer : register (b0)
{
	matrix mWorld;
	matrix mView;
	matrix mProj;
	float4 cColor; // - always black
}

float4 gColor = float4(1.0f,0.0f,0.0f,1.0f); //same here

... VS.....

float4 PS_Main( PS_Input frag ) : SV_TARGET
{
	//return cColor; // - doesn't work, always black
	//return gColor; // - same here
	//return frag.color; //works, but not elegant
	return float4( 1.0f,0.0f,0.0f,1.0f); //works, also not nice
}

Any answer greatly appreciated


EDIT1: partially solved, forgot to call PSSetConstantBuffers.... jeez
EDIT2: the global stuff still not working

Sponsor:

#2 Tom Sloper   Moderators   -  Reputation: 9869

Like
0Likes
Like

Posted 29 October 2011 - 02:54 PM

Closed at request of OP (problem solved).
-- Tom Sloper
Sloperama Productions
Making games fun and getting them done.
www.sloperama.com

Please do not PM me. My email address is easy to find, but note that I do not give private advice.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS