Jump to content
  • Advertisement
Sign in to follow this  

HLSL Constant Table Problem

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

Jumping straight in:
float fTime;

struct VS_OUTPUT
{
    float4 Position   : POSITION;
    float4 Diffuse    : COLOR0;
};

struct PS_OUTPUT
{
    float4 Color      : COLOR;
};

PS_OUTPUT MyPixelShader(VS_OUTPUT inVertex)
{
    PS_OUTPUT Output;
    Output.Color = float4((sin(fTime)+1.0f)/2.0f * inVertex.Diffuse.r, inVertex.Diffuse.g, inVertex.Diffuse.b, inVertex.Diffuse.a);
    return Output;
}


if(g_pPixelConstantTable != NULL)
{
	HRESULT hr = g_pPixelConstantTable->SetFloat(g_pd3dDevice, "fTime", (float) timeGetTime() / 1000.0f);
	if(FAILED(hr))
		printf("PS Time: %x\n", hr);
}


Output: PS Time: 8876086c (D3DERR_INVALIDCALL) Why is this? This however, works:
float4x4 mWorldViewProj;
float    fTime;

struct VS_OUTPUT
{
    float4 Position   : POSITION;
    float4 Diffuse    : COLOR0;
};


VS_OUTPUT MyVertexShader( in float3 inPosition : POSITION, in float3 inNormal : NORMAL, in float4 inDiffuse : COLOR0 )
{
    VS_OUTPUT Output;
	
    Output.Position = mul( float4( inPosition, 1.0f ), mWorldViewProj );
    Output.Diffuse = inDiffuse;
    Output.Diffuse = float4((cos(fTime)+1.0f)/2.0f, (cos(fTime)*sin(fTime)+1.0f)/2.0f, (sin(fTime)+1.0f)/2.0f, 1.0f);
    return Output;
}


if(g_pVertexConstantTable != NULL)
{
	HRESULT hr = g_pVertexConstantTable->SetMatrix(g_pd3dDevice, "mWorldViewProj", &g_mWorldViewProj);
	if(FAILED(hr))
		printf("VS Mat: %x\n", hr);
	hr = g_pVertexConstantTable->SetFloat(g_pd3dDevice, "fTime", fTime);
	if(FAILED(hr))
		printf("VS Time: %x\n", hr);
}


Output: VS Mat: 0 (S_OK) VS Time: 0 (S_OK) Anyone know what's causing this behavior? Of course both shaders compile just fine. The vertex shader works 100% and if I comment out the line "float fTime" and change the pixel shader to just output inVertex.Color.r (without the (sinf(fTime)+1.0f)/2.0f) and don't do the SetFloat on it the pixel shader also works fine.

Share this post


Link to post
Share on other sites
Advertisement

Try replace:
g_pPixelConstantTable->SetFloat(g_pd3dDevice, "fTime", (float) timeGetTime() / 1000.0f);

with:
float t=(float)(timeGetTime()/1000.0f);
g_pPixelConstantTable->SetFloat(g_pd3dDevice, "fTime", t);

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!