Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualNightCreature83

Posted 12 May 2013 - 03:24 PM

Pixel shader and vertex shader constant buffers are seperate, I use this to set mine. You need to also make sure that in your shaders you are using cb0 and not set them on the vertex shader object by accident as that will give an error.
void Effect::setWVPContent( WVPBufferContent& wvpContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[0], 0, 0, (void*)&wvpContent, 0, 0);
}

void Effect::setMaterialContent( MaterialContent& materialContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[1], 0, 0, (void*)&materialContent, 0, 0);
}

//In the shader
cbuffer WVPConstants : register(cb0)
{
matrix World;
matrix View;
matrix Projection;
};

cbuffer MaterialConstants : register(cb0)
{
float4 ambient;
float4 diffuse;
float4 specular;
float4 emissive;
float shininess;
};
The error is actually in your code after seeing your last message have a good look at the Pixel shader setup as you are setting your buffers in the oposite order from the Vertex Shader. If that is how you have setup your shaders and that is how they are bound to the registers this is fine otherwise flip them.

While I'm asking about constant buffers, when using xnamath matrices (with XMFLOAT4X4 for members), is there a reason for it to be necessary to transpose them before sending them to the constant buffer? I didn't see this mentioned anywhere, but a while back I found that not transposing them lead to very wrong results visually, but everything works fine when you transpose them. Does anybody know why this would be, or should I just keep doing it?

You either tell the DX11 runtime that your matrices are row order or you transpose them on the CPU so that the shader interprets them correctly. The flag you are interested in is D3DCOMPILE_PACK_MATRIX_ROW_MAJOR or D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR and should be passed to the D3DX11CompileFromFile function call.

#3NightCreature83

Posted 12 May 2013 - 03:23 PM

Pixel shader and vertex shader constant buffers are seperate, I use this to set mine. You need to also make sure that in your shaders you are using cb0 and not set them on the vertex shader object by accident as that will give an error.
void Effect::setWVPContent( WVPBufferContent& wvpContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[0], 0, 0, (void*)&wvpContent, 0, 0);
}

void Effect::setMaterialContent( MaterialContent& materialContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[1], 0, 0, (void*)&materialContent, 0, 0);
}

//In the shader
cbuffer WVPConstants : register(cb0)
{
matrix World;
matrix View;
matrix Projection;
};

cbuffer MaterialConstants : register(cb0)
{
float4 ambient;
float4 diffuse;
float4 specular;
float4 emissive;
float shininess;
};
The error is actually in your code after seeing your last message have a good look at the Pixel shader setup as you are setting your buffers in the oposite order from the Vertex Shader. If that is how you have setup your shaders and that is how they are bound to the registers this is fine otherwise flip them.

While I'm asking about constant buffers, when using xnamath matrices (with XMFLOAT4X4 for members), is there a reason for it to be necessary to transpose them before sending them to the constant buffer? I didn't see this mentioned anywhere, but a while back I found that not transposing them lead to very wrong results visually, but everything works fine when you transpose them. Does anybody know why this would be, or should I just keep doing it?

You either tell the DX11 runtime that your matrices are row order or you transpose them on the CPU so that the shader interprets them correctly. The flag you are interested in is D3DCOMPILE_PACK_MATRIX_ROW_MAJOR or D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR and should be passed to the D3DXCompileFromFile function call.

#2NightCreature83

Posted 12 May 2013 - 03:20 PM

Pixel shader and vertex shader constant buffers are seperate, I use this to set mine. You need to also make sure that in your shaders you are using cb0 and not set them on the vertex shader object by accident as that will give an error.
void Effect::setWVPContent( WVPBufferContent& wvpContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[0], 0, 0, (void*)&wvpContent, 0, 0);
}

void Effect::setMaterialContent( MaterialContent& materialContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[1], 0, 0, (void*)&materialContent, 0, 0);
}

//In the shader
cbuffer WVPConstants : register(cb0)
{
matrix World;
matrix View;
matrix Projection;
};

cbuffer MaterialConstants : register(cb0)
{
float4 ambient;
float4 diffuse;
float4 specular;
float4 emissive;
float shininess;
};
The error is actually in your code after seeing your last message have a good look at the Pixel shader setup as you are setting your buffers in the oposite order from the Vertex Shader. If that is how you have setup your shaders and that is how they are bound to the registers this is fine otherwise flip them.

#1NightCreature83

Posted 12 May 2013 - 03:19 PM

Pixel shader and vertex shader constant buffers are seperate, I use this to set mine. You need to also make sure that in your shaders you are using cb0 and not set them on the vertex shader object by accident as that will give an error.

[code=auto:0]
void Effect::setWVPContent( WVPBufferContent& wvpContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[0], 0, 0, (void*)&wvpContent, 0, 0);
}

void Effect::setMaterialContent( MaterialContent& materialContent )
{
DeviceManager::getInstance().getDeviceContext()->UpdateSubresource( m_constantBuffers[1], 0, 0, (void*)&materialContent, 0, 0);
}

//In the shader
cbuffer WVPConstants : register(cb0)
{
matrix World;
matrix View;
matrix Projection;
};

cbuffer MaterialConstants : register(cb0)
{
float4 ambient;
float4 diffuse;
float4 specular;
float4 emissive;
float shininess;
};
[\code]

The error is actually in your code after seeing your last message have a good look at the Pixel shader setup as you are setting your buffers in the oposite order from the Vertex Shader. If that is how you have setup your shaders and that is how they are bound to the registers this is fine otherwise flip them.

PARTNERS