• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Ty Typhoon
      Before read everything i am honest:
      Payment after release you get your percentage lifetime for that project.
       
      Second:
      i dont need your inspirations, ideas, music or designs.
      My head is full with that.
      I need workers who i can trust.
       
       
       
      Please let us talk in discord.
      I got a lot of stuff planned, there is much work to do.
       
      But first my team and me try to start with a small mini game and we need maybe exactly you.
      Planned for more than pc, like ps4, xbox one and mobile - so its very important to us to hopefully welcome a programmer.
       
      The mini game will be part of the planned big game. There will be never before seen guns and gameplay, you will get deeper info if youre a safe part of the team.
       
      I need:
      Programmers
      Animators
      Zbrush pros
       
      Join here please:
      https://discord.gg/YtjE3sV
       
      You find me here:
      Joerg Federmann Composing#2898
       
       
    • By fs1
      I have been trying to see how the ID3DInclude, and how its methods Open and Close work.
      I would like to add a custom path for the D3DCompile function to search for some of my includes.
      I have not found any working example. Could someone point me on how to implement these functions? I would like D3DCompile to look at a custom C:\Folder path for some of the include files.
      Thanks
    • By Ricardo3Ddev
      Hi guys!
      This is a independent game being produced by me and my brother. We’ve been working on it for about 6 months and we’ve already done a good part of the game. We hope to finalize and make it available on Steam by the end of this year.
      We are using Blender 3D and Gimp software for production.
       
      About the Game: Dongo Adventure will be a 3D platform style game, where the main character (Dongo) is a mouse that ventures through various scenarios (sewers, culverts, streets, electric grid, etc.) and faces several enemies along the way (cockroaches, mosquitoes, spiders, toxic gases, electrical wires, etc.). He carries a basket / backpack with cheeses that he uses to throw and defend himself from enemies, as well as being able to push objects that helps him to overcome obstacles. The ultimate goal will be a surprise!
       
      Now we are developing new scenarios and enemies. We hope to publish news soon...
      Game page on Steam: http://store.steampowered.com/app/811450/Dongo_Adventure/ - (Teaser UPDATED)
      Dongo Adventure - Indie Game Project (First Teaser) https://www.youtube.com/watch?v=X2nmxtkE0xk

      Thanks for following the project!
    • By Ty Typhoon
      So me and my co try to do a game.
      It should be in unity couse my co do everything in this engine.
       
      We got the rpg package from evila for inventor, but it only runs on pc right now.
       
      I like to make a online store for guns in the game and a multiplayer open world that runs on pc, android, mobile, ps4, xbox one. 
      Somebody told me that you "only" need to program it like so and that its possible in every engine...
       
      [recruitment wording deleted by moderator]
       
      And yes, this is no recruitment post.
      [recruitment wording deleted by moderator]]
       
      Also discord:
      Joerg Federmann Composing#2898
    • By Epicghost 505
      Hello,
      We are looking for people to be apart of a team, to help create a horror game we are looking for 3d modelers, coders, artist, animators, fx artist, level designers, and audio design, there will be a payment plan once release of game                                                                                                                                                                                                                                                                                              if your interested come join our discord                                                                                                                                                                                                                                                                         We hope to see you there
      https://discord.gg/6rcc6xr
      -Epicghost505
  • Advertisement
  • Advertisement

DX11 Instance Shader Problem

Recommended Posts

I am using slimDX and am having a problem with a shader. I have an instance Shader that works perfect but I needed one for drawing fonts manually. The idea is to create the plane and simple instance it with separate position color and texture coordinates for each char.  I know this post is terribly long but any help would be appreciated. I tried to provide everything needed but if you need more I will be glad to post it.

This is the shader. the only difference between it and the working one is the instance texture coordinates. I was able to render 4,000 spheres with 30,000 faces with the original and still maintain a 100+ framerate. I don't know if that is a lot but it looked like it to me.

cbuffer cbVSPerFrame:register(b0)
{
	row_major matrix world;
	row_major matrix viewProj;
};

Texture2D g_Tex;
SamplerState g_Sampler;

struct VSInstance
{
	float4 Pos : POSITION;
	float3 Normal : NORMAL;
	float2 Texcoord : TEXCOORD0;

	float4 model_matrix0 : TEXCOORD1;

	float4 model_matrix1 : TEXCOORD2;

	float4 model_matrix2 : TEXCOORD3;

	float4 model_matrix3 : TEXCOORD4;
  // this is the only addition
	float2 instanceCoord:TEXCOORD5;
	float4 Color:COLOR;
};
struct PSInput
{
	float4 Pos : SV_Position;
	float3 Normal : NORMAL;
	float4 Color:COLOR;
	float2 Texcoord : TEXCOORD0;
};


PSInput Instancing(VSInstance In)
{
	PSInput Out;
	// construct the model matrix

	row_major float4x4 modelMatrix =
	{
		In.model_matrix0,
		In.model_matrix1,
		In.model_matrix2,
		In.model_matrix3
	};
  
	Out.Normal = mul(In.Normal, (row_major float3x3)modelMatrix);
	float4 WorldPos = mul(In.Pos, modelMatrix);

	Out.Pos = mul(WorldPos, viewProj);
	Out.Texcoord = In.instanceCoord;
	Out.Color = In.Color;
	return Out;
}

float4 PS(PSInput In) : SV_Target
{
	return g_Tex.Sample(g_Sampler, In.Texcoord);
}

technique11 HWInstancing
{
	pass P0
	{
		SetGeometryShader(0);
		SetVertexShader(CompileShader(vs_4_0, Instancing()));
		SetPixelShader(CompileShader(ps_4_0, PS()));
	}
}

this is the input elements for the 2 buffers

        private static readonly InputElement[] TextInstance = {
            new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
            new InputElement("NORMAL", 0, Format.R32G32B32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0),
            new InputElement("TEXCOORD", 0, Format.R32G32_Float, InputElement.AppendAligned, 0, InputClassification.PerVertexData, 0),
            new InputElement("TEXCOORD", 1, Format.R32G32B32A32_Float, 0, 1, InputClassification.PerInstanceData, 1 ),
            new InputElement("TEXCOORD", 2, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ),
            new InputElement("TEXCOORD", 3, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ),
            new InputElement("TEXCOORD", 4, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ),
            new InputElement("TEXCOORD", 5, Format.R32G32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 ),
            new InputElement("COLOR", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 1, InputClassification.PerInstanceData, 1 )
        };

the struct for holding instance data. 

    [StructLayout(LayoutKind.Sequential)]
    public struct InstancedText
    {
        public Matrix InstancePosition;
        public Vector2 InstanceCoords;
        public Color4 Color;
    };

instanceData buffer creation. Instance Positions is a simple List<InstancedText> above

            DataStream ds = new DataStream(InstancePositions.ToArray(), true, true);
            
            BufferDescription vbDesc = new BufferDescription();
            vbDesc.BindFlags = BindFlags.VertexBuffer;
            vbDesc.CpuAccessFlags = CpuAccessFlags.None;
            vbDesc.OptionFlags = ResourceOptionFlags.None;
            vbDesc.Usage = ResourceUsage.Default;
            vbDesc.SizeInBytes = InstancePositions.Count * Marshal.SizeOf<InstancedText>();
            vbDesc.StructureByteStride = Marshal.SizeOf<InstancedText>();
            ds.Position = 0;

            instanceData = new Buffer(renderer.Device, vbDesc);

 

and finally the render code.

the mesh is a model class that contains the plane's data. PositionNormalTexture is just a struct for those elements.

            renderer.Context.InputAssembler.InputLayout = new InputLayout(renderer.Device,
                effect.GetTechniqueByName("HWInstancing").GetPassByIndex(0).Description.Signature, TextInstance);
            renderer.Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            renderer.Context.InputAssembler.SetVertexBuffers(0, new 
               VertexBufferBinding(mesh.VertexBuffer, Marshal.SizeOf<PositionNormalTexture>(), 0));
            renderer.Context.InputAssembler.SetIndexBuffer(mesh.IndexBuffer, SlimDX.DXGI.Format.R32_UInt, 0);
            renderer.Context.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(instanceData,
                 Marshal.SizeOf<InstancedText>(), 0));

            effect.GetVariableByName("g_Tex").AsResource().SetResource(textures[fonts[name].Name]);

            EffectTechnique currentTechnique = effect.GetTechniqueByName("HWInstancing");
            for (int pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
            {
                EffectPass Pass = currentTechnique.GetPassByIndex(pass);
                System.Diagnostics.Debug.Assert(Pass.IsValid, "Invalid EffectPass");
                Pass.Apply(renderer.Context);
                renderer.Context.DrawIndexedInstanced(mesh.IndexCount, InstancePositions.Count, 0, 0, 0);
            };

I have been over everything I can think of to find the problem but I can't seem to locate it.

my best guess is the instance data buffer is wrong somehow since VS graphics debugger shows no output from vertex shader stage

 but I just can't see where.

Edited by Zototh

Share this post


Link to post
Share on other sites
Advertisement

wow it just hit me what I missed.

instanceData = new Buffer(renderer.Device, vbDesc); <---- should be instanceData = new Buffer(renderer.Device, ds, vbDesc);

LOL what a dumb mistake and spent 2 days trying to find it.

edit: seems I forgot to do a scaling matrix also when I created the positions but the shader works perfect

Edited by Zototh

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


  • Advertisement