Sign in to follow this  
hiul

[SlimDX] shader from file problem

Recommended Posts

hiul    122
Hi every body. I come here because i can't find the problem in my little program. it's the sample "miniTri" that I used to create my project by reading and copying. but it seems that when I load the shader file (here "shader.fx") the Effect framwork can't parse it correctly and end up not finding the technique10 and pass sections. so i'd like to know how am I suposed do to get it work ... I post the entire code: [code Csharp] using System; using System.Drawing; using SlimDX; using SlimDX.Direct3D10; using SlimDX.DXGI; using SlimDX.Windows; using Device = SlimDX.Direct3D10.Device; namespace ProjetDeTest01 { /// <summary> /// test de slimDX /// </summary> static class ProjetDeTest01 { // point d'entré de l'application [STAThread] static void Main() { RenderForm form = new RenderForm("Premier programme SlimDX"); SwapChainDescription desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(800, 600, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; Device device; SwapChain swapChain; Device.CreateWithSwapChain(null, DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain); // on empèche Alt+Entrer de mettre en plain écran Factory factory = swapChain.GetParent<Factory>(); factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter); Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0); RenderTargetView renderView = new RenderTargetView(device, backBuffer); device.Rasterizer.SetViewports(new Viewport(0, 0, 800, 600, 0.0f, 1.0f)); Effect effect = Effect.FromFile(device, "shader.fx", "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); if (effect.Description.TechniqueCount > 0) { EffectTechnique technique = effect.GetTechniqueByIndex(0); if (technique.IsValid) { EffectPass pass = technique.GetPassByIndex(0); if (pass.IsValid) { InputLayout layout = new InputLayout(device, pass.Description.Signature, new InputElement[]{ new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); DataStream stream = new DataStream(16 * 6, true, true); stream.WriteRange(new[] { new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f) }); stream.Position = 0; SlimDX.Direct3D10.Buffer vertexBuffer = new SlimDX.Direct3D10.Buffer(device, stream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 16 * 6, Usage = ResourceUsage.Default }); stream.Dispose(); device.OutputMerger.SetTargets(renderView); device.Rasterizer.SetViewports(new Viewport(0, 0, 800, 600, 0.0f, 1.0f)); MessagePump.Run(form, () => { device.ClearRenderTargetView(renderView, Color.Black); device.InputAssembler.SetInputLayout(layout); device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 32, 0)); for (int i = 0; i < technique.Description.PassCount; i++) { pass.Apply(); device.Draw(3, 0); } swapChain.Present(0, PresentFlags.None); }); vertexBuffer.Dispose(); layout.Dispose(); } else throw new Exception("La classe EffectPass n'a pas pus être initialisé."); } else throw new Exception("La classe EffectTechnique n'a pas pus être initialisé."); } else throw new Exception("La classe Effect n'a pas pus être initialisé."); effect.Dispose(); renderView.Dispose(); backBuffer.Dispose(); device.Dispose(); swapChain.Dispose(); } } } [/code Csharp] ----------------------------shader.fx------------------------------- struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : COLOR; }; PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; output.pos = input.pos; output.col = input.col; return output; } float4 PS( PS_IN input ) : SV_Target { return input.col; } technique10 Render { pass P0 { SetGeometryShader( 0 ); SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } }

Share this post


Link to post
Share on other sites
hiul    122
so that was it hummmm

in fact vs uses "utf-8 bom" wich kills the file while "utf-8 without bom" works
tricky heh ?

thx mike it works now

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this