Reputation: 3586
I'm attempting to load an FX file in slimdx, I've got this exact FX file loading and compiling fine with XNA 4.0 but I'm getting errors with slimdx, here's my code to load it.
using SlimDX.Direct3D11;
using SlimDX.D3DCompiler;
public static Effect LoadFXShader(string path)
{
Effect shader;
using (var bytecode = ShaderBytecode.CompileFromFile(path, null, "fx_2_0", ShaderFlags.None, EffectFlags.None))
shader = new Effect(Devices.GPU.GraphicsDevice, bytecode);
return shader;
}
Here's the shader:
#define TEXTURE_TILE_SIZE 16
struct VertexToPixel
{
float4 Position : POSITION;
float2 TextureCoords: TEXCOORD1;
};
struct PixelToFrame
{
float4 Color : COLOR0;
};
//------- Constants --------
float4x4 xView;
float4x4 xProjection;
float4x4 xWorld;
float4x4 preViewProjection;
//float random;
//------- Texture Samplers --------
Texture TextureAtlas;
sampler TextureSampler = sampler_state { texture = <TextureAtlas>; magfilter = Point; minfilter = point; mipfilter=linear; AddressU = mirror; AddressV = mirror;};
//------- Technique: Textured --------
VertexToPixel TexturedVS( byte4 inPos : POSITION, float2 inTexCoords: TEXCOORD0)
{
inPos.w = 1;
VertexToPixel Output = (VertexToPixel)0;
float4x4 preViewProjection = mul (xView, xProjection);
float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
Output.Position = mul(inPos, preWorldViewProjection);
Output.TextureCoords = inTexCoords / TEXTURE_TILE_SIZE;
return Output;
}
PixelToFrame TexturedPS(VertexToPixel PSIn)
{
PixelToFrame Output = (PixelToFrame)0;
Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
if(Output.Color.a != 1)
clip(-1);
return Output;
}
technique Textured
{
pass Pass0
{
VertexShader = compile vs_2_0 TexturedVS();
PixelShader = compile ps_2_0 TexturedPS();
}
}
Now this exact shader works fine in XNA, but in slimdx I get the error
ChunkDefault.fx(28,27): error X3000: unrecognized identifier 'byte4'
Upvotes: 1
Views: 983
Reputation: 861
If I remember correctly the byte4 is something from the reach/hd profiles of XNA (which use shader model 2.0). You are using directx11 but are trying to compile it to a Shader Model 2 profile. This is not supported. You have to rewrite the shader to fit the shader model 5 profile (fx_5_0) or construct your device with feature level D3D_FEATURE_LEVEL_9_1 and compile your shaders with as target ps_4_0_level_9_1.
A couple of things from your shader will not work in shader model 5. For example the sample_state is a Directx9 thing. From Directx10 and up you have to use samplerstate groups.(See here for more info) For example:
SamplerState MeshTextureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
Some other things that are not supported include:
magfilter = Point;
You have to convert that one to filter like this:
Filter = MIN_MAG_LINEAR_MIP_POINT;
Those are the things I spotted when I scanned over it. I hope this helps you a bit.
Upvotes: 2