Jump to content
  • Advertisement
Sign in to follow this  
haansn08

DX11 [SOLVED] EffectFramework sets shaders to NULL?

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

Hello there,

I'm trying to learn how to use the effect framework and tried to recreate my "grid scene" (a floor grid with colored axis), but this time with effects instead of own compiled shaders smile.png

But I'm having a couple of problems with it not least, because the framework seems to remove the shader from the device context:

noshader.png

(This can't work...)

 

My effect file:

cbuffer cbPerObject : register(b0)
{
	float4x4 worldViewProj;
};
struct VertexIn
{
	float3 pos : POSITION;
	float4 col : COLOR;
};
struct VertexOut
{
	float4 pos : SV_POSITION;
	float4 col : COLOR;
};
VertexOut VS (VertexIn input)
{
	VertexOut vout;
	vout.pos = float4 (input.pos, 1.0f);
	vout.pos = mul(vout.pos, worldViewProj);

	vout.col = input.col;

	return vout;
}
float4 PS(VertexOut input) : SV_TARGET
{
	return input.col;
}
RasterizerState SolidCull
{
	FillMode = Solid;
	CullMode = Back;
};
technique11 ColorTech
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, VS()));
		SetPixelShader (CompileShader(ps_5_0, PS()));
		SetRasterizerState (SolidCull);
	}
}

Loading the effect:

ID3D10Blob *fx;
ID3D10Blob *error;
if (FAILED(D3DX11CompileFromFileA("Color.fx", nullptr, nullptr, 0, "fx_5_0", D3D10_SHADER_DEBUG | D3D10_SHADER_SKIP_OPTIMIZATION, 0, 0, &fx, &error, 0)))
{
	throw (char*)error->GetBufferPointer();
}
if (FAILED(D3DX11CreateEffectFromMemory(fx->GetBufferPointer(), fx->GetBufferSize(), 0, _dev, &_FXColor)))
	throw "Can't create effect.";
fx->Release();

Rendering Code:

XMMATRIX gridMatrix = _camera.GetCameraMatrix() * _proj;
_FXColor_WorldViewProj->SetMatrix((float*)(&gridMatrix));
auto colorTech = _FXColor->GetTechniqueByName("ColorTech");
D3DX11_TECHNIQUE_DESC colorTechDesc;
colorTech->GetDesc(&colorTechDesc);
for (UINT pass = 0; pass < colorTechDesc.Passes; pass++)
{
	colorTech->GetPassByIndex(pass)->Apply(0, _devcon);
	_grid->Render();
}

The Apply function seems to set the shaders to zero.

Share this post


Link to post
Share on other sites
Advertisement

Nothing looks too obvious, (unfortunately), have you verified that there are passes in the tech desc? Also you may want to check the result of Apply and see if it gives any error indications.

Share this post


Link to post
Share on other sites

I just found out I didn't set an input layout!

But it still doesn't work:

When calling ID3D11SwapChain::Present the screen goes black and I get a strange error message, later when I clear the back buffer... sad.png

 

This seems to work:

D3DX11_PASS_DESC passDesc;
_FXColor->GetTechniqueByIndex(0)->GetPassByIndex(0)->GetDesc(&passDesc);
D3D11_INPUT_ELEMENT_DESC layout[2];
VertexFormats::VertexPositionColor::GetDesc(layout);
if (FAILED(_dev->CreateInputLayout(layout, 2, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &_layout)))
	throw "Failed to create input layout.";

But of course I need the input layout...

 

EDIT: I found  the problem - it seems like my graphics card doesn't support the specified shader version... (But the Effect version needs to be 5.0... ?)

Edited by haansn08

Share this post


Link to post
Share on other sites
You mean the fx_5_0, no ? That just means the D3DX 11 effect system (technique11 in the source file) and is somewhat orthogonal to what shader model(s) you select.
 
Unless you actually need specific D3D11 features you can compile your shaders with vs_4_0, ps_4_0 etc. just fine. Off the top of my head: SM 5 is needed for certain semantics and intrinsics, geometry shader instancing and of course tesselation and (sensible) compute shaders. 
 
Also: When debugging enable the debug layer with D3D11_CREATE_DEVICE_DEBUG.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!