[SOLVED] Making a Simple D3D9 HLSL Shader work with D3D11

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

[SOLVED] Making a Simple D3D9 HLSL Shader work with D3D11

Post by Mind Calamity »

I just wandered into the world of shaders, and for that I chose JaJDoo's Guide, JaJDoo is great at making shader programming look simple, and he actually succeeded explaining the complex stuff in simpler terms, but as I followed his guide, I wrote my little shader, which just colors the objects orange, basically an adaption of the "Orange Shader" written in Cg, but since I'm having problems with Cg (I'm going to post another thread on that).

So, here's how my shader structure currently looks:

Shader1_fp.hlsl:

Code: Select all

float4 mainFP() : COLOR 
{
	return float4(1.0, 0.7, 0.0, 1.0);
}
Shader1_vp.hlsl:

Code: Select all

float4 mainVP(float4 pos : POSITION, uniform float4x4 worldViewProj_m) : POSITION
{
	return mul(worldViewProj_m, pos);
}
Shader1.material:

Code: Select all

vertex_program Shader1_HLSL_vp hlsl
{
	source  Shader1_vp.hlsl
	entry_point mainVP
	target vs_3_0
	default_params
	{
		param_named_auto worldViewProj_m worldviewproj_matrix
	}
}
 
fragment_program Shader1_HLSL_fp hlsl
{
	source Shader1_fp.hlsl
	entry_point mainFP
	target ps_3_0
}

material Shader1_HLSL
{
	technique
	{
		pass
		{
			vertex_program_ref Shader1_HLSL_vp
			{
			}
			fragment_program_ref Shader1_HLSL_fp
			{
			}
		}
	}
}
This works perfectly in Direct3D 9, but not in Direct3D 11, it crashes saying:
23:02:07: WARNING: material Shader1_HLSL has no supportable Techniques and will be blank. Explanation:
Pass 0: Vertex program Shader1_HLSL_vp cannot be used - not supported.
and:

Code: Select all

23:02:07: OGRE EXCEPTION(3:RenderingAPIException): Attempted to render to a D3D11 device without both vertex and fragment shaders there is no fixed pipeline in d3d11 - use the RTSS or write custom shaders. in D3D11RenderSystem::_render at D:\Libraries\ogre\RenderSystems\Direct3D11\src\OgreD3D11RenderSystem.cpp (line 2082)
But that's one reason (out of many) that I started learning shader programming, and when I finally felt happy with the little I have created, this just gets out and punches me in the face... :(

Is there anything special that needs to be specified in the materials/shaders to make them work with Direct3D 11 ?

-----------------------------------------------------------------------------------------------------

My problem has been solved:

Go to answer.

(or just scroll down to the last post ;) )
Last edited by Mind Calamity on Sat Oct 22, 2011 10:45 pm, edited 3 times in total.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7153
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 518

Re: Making a Simple D3D9 HLSL Shader work with D3D11

Post by Kojack »

Your pixel and vertex shaders are using shader model 3 (ps_3_0 and vs_3_0).
DirectX 11 doesn't support shaders below shader model 4.

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Making a Simple D3D9 HLSL Shader work with D3D11

Post by Mind Calamity »

Kojack wrote:Your pixel and vertex shaders are using shader model 3 (ps_3_0 and vs_3_0).
DirectX 11 doesn't support shaders below shader model 4.
Yes, so it seems.

And it also seems that making simple stuff work with ps/vs_4_0 is a real pain in the ass...

But, I'm going to take Asaaf's advice on looking through the DX SDK since that thing had a whole lot of stuff I haven't seen (I've never actually opened it's directory).

Also, I now have this blocking my way:

Code: Select all

11:42:06: OGRE EXCEPTION(3:RenderingAPIException): D3D11 device cannot draw indexed
Error Description:ID3D11DeviceContext::DrawIndexed: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is not D3D11_SO_NO_RASTERIZED_STREAM) but position is not provided by the last shader before the Rasterization Unit.
 in D3D11RenderSystem::_render at D:\Libraries\ogre\RenderSystems\Direct3D11\src\OgreD3D11RenderSystem.cpp (line 2194)
My pixel shader now looks like this:

Code: Select all

float4 mainFP() : SV_TARGET 
{
	return float4(1.0, 0.7, 0.0, 1.0);
}
and my vertex shader remains unchanged:

Code: Select all

float4 mainVP(float4 pos : POSITION, uniform float4x4 worldViewProj_m) : POSITION
{
	return mul(worldViewProj_m, pos);
}
And this trio results in the exception above.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Making a Simple D3D9 HLSL Shader work with D3D11

Post by Mind Calamity »

Well thanks to Asaaf for providing me with the useful MSDN Link, I finally managed to understand that shader models are kinda like new versions of a SDK which brings changes to the API, and code that worked with the previous version, probably won't with the new one.

And so, here's my current working "orange" shader:

Fragment Program:

Code: Select all

float4 mainFP() : SV_TARGET 
{
	return float4(1.0, 0.7, 0.0, 1.0);
}
Vertex Program:

Code: Select all

float4 mainVP(float4 pos : SV_POSITION, uniform float4x4 worldViewProj_m) : SV_Position
{
	return mul(worldViewProj_m, pos);
}
Material script:

Code: Select all

vertex_program Shader1_HLSL_vp_4 hlsl
{
	source  Shader1_vp_4_0.hlsl
	entry_point mainVP
	target vs_4_0
	default_params
	{
		param_named_auto worldViewProj_m worldviewproj_matrix
	}
}
 
fragment_program Shader1_HLSL_fp_4 hlsl
{
	source Shader1_fp_4_0.hlsl
	entry_point mainFP
	target ps_4_0
}

material Shader1_HLSL_4_0
{
	technique
	{
		pass
		{
			vertex_program_ref Shader1_HLSL_vp_4
			{
			}
			fragment_program_ref Shader1_HLSL_fp_4
			{
			}
		}
	}
}
EDIT: I created a wiki article on the subject, since I think that a starting point for using the Direct3D11 rederer is necessary.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt

Post Reply