Jump to content
  • Advertisement

XBuilder

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

108 Neutral

About XBuilder

  • Rank
    Newbie
  1. Hello LyGuy,   thanks for your help! I have created a new test WinForms-Application and have found the error (swapped parameters is second InputElement 0, 12  should be 12, 0): var elements = new[] { new InputElement(Helper3D.POSITION_ELEMENT_NAME, 0, Format.R32G32B32_Float, 0, 0), new InputElement(Helper3D.NORMAL_ELEMENT_NAME, 0, Format.R32G32B32_Float, 12, 0) }; It's works nice now! Thank you for your hints!    
  2. Hello there,   I have tried to use graphics debugger, but it is no support for WPF hosted Direct3D in the debugger. As i have read, third party debuggers have no support for this scenario too.   So i should continue error searching without debugger     Any other idea?
  3. Hallo LyGuy,   I am using VisualStudio 2012 with SharpDX Wrapper for C# (only low level without toolkit). I compile the effect file at the runtime. I have found a graphic debugger window. I will try it out.    I bind the buffer as follows (setup before rendering): device.InputAssembler.InputLayout = _VertexLayout; device.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_Vertices, VERTEX_SIZE, 0)); Render code: //Draw schene for (int i = 0; i < technique.Description.PassCount; ++i) { pass.Apply(); device.Draw(3, 0); }
  4. It the same situation as at start - nothing to see. I have now added a SimpleVertex struct to my code, but this have no effect too.   Code now: internal struct SimpleVertex { Vector3 Position; Vector3 Normal; public SimpleVertex(Vector3 pos, Vector3 norm) { Position = pos; Normal = norm; } }; const int VERTEX_SIZE = 24; var elements = new[] { new InputElement(Helper3D.POSITION_ELEMENT_NAME, 0, Format.R32G32B32_Float, 0, 0), new InputElement(Helper3D.NORMAL_ELEMENT_NAME, 0, Format.R32G32B32_Float, 0, 12) }; _VertexLayout = new InputLayout(device, pass.Description.Signature, elements); _VertexStream = new DataStream(3 * VERTEX_SIZE, true, true); _VertexStream.Write(new SimpleVertex(new Vector3(0.0f, 0.5f, 0.5f), new Vector3(0.0f, 0.0f, 1.0f))); _VertexStream.Write(new SimpleVertex(new Vector3(0.5f, -0.5f, 0.5f), new Vector3(0.0f, 0.0f, 1.0f))); _VertexStream.Write(new SimpleVertex(new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.0f, 0.0f, 1.0f))); _VertexStream.Position = 0; _Vertices = new SharpDX.Direct3D10.Buffer(device, _VertexStream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 3 * VERTEX_SIZE, Usage = ResourceUsage.Default });
  5. I have tried it already. If I try to change the elements array as following, I get the exception "HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: Invalid Argument." on InputLayout creation. The official DirectX 10 example using the Declaration with Vector3. As i have understood the mapping and the conversion is done by the system.   New elements array: var elements = new[] { new InputElement(Helper3D.POSITION_ELEMENT_NAME, 0, Format.R32G32B32A32_Float, 0, 0), new InputElement(Helper3D.NORMAL_ELEMENT_NAME, 0, Format.R32G32B32_Float, 0, 16) }; D3D10 Example 6: // Define the input layout D3D10_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }, }; //... SimpleVertex vertices[] = { { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) }, ... }
  6. Hello LyGuy,   thanks for your answer! I have tryed to write all data at once, but it doesn't changed anything. As i understand, the mapping is done by the constructor of the InputLayout class. It extracts the register information directly from the shader. But it seems that the vertex shader can't access normals from the buffer.   I have tried to hard-code the normals as the output of the vertex shader (line 25) and it works, but if i try to access the normal from the input (commented out line 24) it's doesn't render anything more. PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; output.pos = mul(input.pos, view); output.pos = mul(output.pos, projection); //output.norm = input.norm; output.norm = float3(0,0,1) return output; } float4 PS( PS_IN input ) : SV_Target { float4 finalColor = 0; finalColor = saturate( dot((float3)vLightDir, input.norm) * vLightColor); finalColor.a = 1; return finalColor; }
  7. Hello there,   I'm trying to learn how to render a simple scene in DirectX 10 with SharpDX's low level wrappers. I have already created a simple application with a single triangle on the screen and a camera. Now i am trying to add a single directed light to the scene (like in the DX10 Example 6).    It works fine with hard-coded normals in the Effect-File (active line in the PS shader), but if I try to pass normals from my vector buffer (commented out line below) I don't see anything.   What i don't understand is why the type of the position vector should be float3 in the element definition and why is it float4 in the shader file (copied from DX10 example). And how maps the shader this two structures?   My setup for the test triangle (like in the DX10 Example) and my effect file follows:   thanks in advance! ShaderBytecode shaderBytes = ShaderBytecode.CompileFromFile(_ShaderFile, "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); _SimpleEffect = new Effect(device, shaderBytes); EffectTechnique technique = _SimpleEffect.GetTechniqueByName("Render"); EffectPass pass = technique.GetPassByIndex(0); var elements = new[] { new InputElement(Helper3D.POSITION_ELEMENT_NAME, 0, Format.R32G32B32_Float, 0, 0), new InputElement(Helper3D.NORMAL_ELEMENT_NAME, 0, Format.R32G32B32_Float, 0, 12) }; _LightDir = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); _LightDir.Normalize(); _LightColor = new Vector4( 0.5f, 0.5f, 0.5f, 1.0f ); _VertexLayout = new InputLayout(device, pass.Description.Signature, elements); _VertexStream = new DataStream(3 * 24, true, true); _VertexStream.Write(new Vector3(0.0f, 0.5f, 0.5f)); _VertexStream.Write(new Vector3(0.0f, 0.0f, 1.0f)); _VertexStream.Write(new Vector3(0.5f, -0.5f, 0.5f)); _VertexStream.Write(new Vector3(0.0f, 0.0f, 1.0f)); _VertexStream.Write(new Vector3(-0.5f, -0.5f, 0.5f)); _VertexStream.Write(new Vector3(0.0f, 0.0f, 1.0f)); _VertexStream.Position = 0; _Vertices = new SharpDX.Direct3D10.Buffer(device, _VertexStream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 3 * 24, Usage = ResourceUsage.Default }); _Camera.Position = new Vector3(0.0f, 0.0f, -20.0f); matrix view; matrix projection; float4 vLightDir; float4 vLightColor; struct VS_IN { float4 pos : POSITION; float3 norm : NORMAL; }; struct PS_IN { float4 pos : SV_POSITION; float3 norm : TEXCOORD0; }; PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; output.pos = mul(input.pos, view); output.pos = mul(output.pos, projection); output.norm = input.norm; return output; } float4 PS( PS_IN input ) : SV_Target { float4 finalColor = 0; //finalColor = saturate( dot((float3)vLightDir, input.norm) * vLightColor); finalColor = saturate(dot((float3)vLightDir, float3(0,0,1)) * vLightColor); finalColor.a = 1; return finalColor; } float4 PSSolid( PS_IN input) : SV_Target { return float4(1,0,0,1); } technique10 Render { pass P0 { SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( 0 ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } } technique10 RenderLight { pass P0 { SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( 0 ); SetPixelShader( CompileShader( ps_4_0, PSSolid() ) ); } }
  • 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!