Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 28 Feb 2013
Offline Last Active Mar 27 2015 04:10 AM

Topics I've Started

Correct way of using multipass effects in Effects framework

04 March 2015 - 06:46 AM


I am using sharpDX with effect framework and I want to render multipass effect, but faced with the issue that I could not apply second pass:


Here is my effect code:

Texture2D Texture;
SamplerState TextureSampler;

matrix OrthoMatrix;

struct VertexInputType
   float4 position : SV_POSITION;
   float4 color: COLOR;
   float2 tex : TEXCOORD0;

struct PixelInputType
   float4 position : SV_POSITION;
   float4 color: COLOR;
   float2 tex : TEXCOORD0;

PixelInputType SpriteVertexShader(VertexInputType input)
   PixelInputType output;
   output.color = float4(0, 0, 0, 0);
   output.position = float4(0, 0, 0, 0);
   // Change the position vector to be 4 units for proper matrix calculations.
   input.position.w = 1.0f;

   output.position = mul(input.position, OrthoMatrix);

   // Store the texture coordinates for the pixel shader.
   output.tex = input.tex;
   output.color = input.color;
   return output;

float4 SpritePixelShader(PixelInputType input) : SV_TARGET
   return Texture.Sample(TextureSampler, input.tex)* input.color;

float4 SpritePixelShader2(PixelInputType input) : SV_TARGET
   /*return Texture.Sample(TextureSampler, input.tex)+ input.color;*/
   return float4(0,1,0,0);

technique10 SpriteBatch
   pass P0
      SetVertexShader(CompileShader(vs_4_0, SpriteVertexShader()));
      SetPixelShader(CompileShader(ps_4_0, SpritePixelShader()));

   pass P1
      SetPixelShader(CompileShader(ps_4_0, SpritePixelShader2()));

And here is how I use effect:

var effectByteCode = ShaderBytecode.CompileFromFile(@"Content\Effects\SpriteBatchEffect.fx", "fx_5_0");
effect = new Effect(this.graphicsDevice, effectByteCode);

int passesCount = effect.GetTechniqueByName("SpriteBatch").Description.PassCount;
         var technique = effect.GetTechniqueByName("SpriteBatch");

         graphicsDevice.SetVertexBuffers(0, vertexBufferBinding);
         EffectPass localpass;
         for (int i = 0; i < passesCount; i++)
            localpass = technique.GetPassByIndex(i);

            var passSignature = localpass.Description.Signature;

            layout = new InputLayout(graphicsDevice, passSignature, inputElements);

            graphicsDevice.InputLayout = layout;


            graphicsDevice.DrawIndexed(indexCount, 0, 0);

On this line var 

passSignature = localpass.Description.Signature;

in the second pass I receive outofrange exception.


If I comment that line, There is no exception, but the second pass will never apply.


Could someone, please, say what I am doing wrong here?

Collada controller data sorting

25 February 2015 - 03:28 PM



I am trying to implement animation in my engine and I`ve noticed that if controller contained ordered bones (like they present in skeleton) then, animation work fine, but if boned unordered, then I receive kust a mess of polygons.

So, I decided that I need to sort controller bones, but I after that I still doesnt received satisfying result - model is still becomes a mess of triangles.


So, I think I must do something else - may be I need to sort joint-weights pairs?

And do I need to do something with mesh, attach to this controller?


Could someone, please, point me on the right way?

Bone animation implementation problem

13 February 2015 - 03:58 AM

Hi. I want to implement bone animation in my engine and I faced with the issue that when I multiply all bone matrices and set them to shader, my model is disassembling. 

As far as I understood the theory correct, I need multiply bind shape matrix on inverse bind matrix for each bone * key frame matrix for current bone and then go throught the bones hierarhy and multiply each chld bone matrix on parent bone matrix. Then I need to pass the result as matrix array to shader and multiply each position with corresponding final joint matrix * joint weight and then do standart multiplication on World, View, Projection amtrices. That shoud be all, but my implementation is not eorking although I double checked my matrices and all other data. I think problem is in matrices, but I cannot find where exactly. 


Here is my method for matrix calculation. Could someone tell me what I am doing wrong here? Maybe I am missing something.

private Matrix[] JointMatrices;
private int counter = 0;
private void CalculateInterprolation(AnimationControllerComponent controller, AnimationComponent animation, Dictionary<ulong, Entity> entities)
         JointMatrices = new Matrix[controller.JointDictionary.Count];
         Dictionary<string, Matrix> final = new Dictionary<string, Matrix>();

         foreach (var inverseBindMatrixName in controller.JointDictionary)
            //multiply bind shape * inverse bind * key frame matrix
            Matrix finalMatrix = controller.BindShapeMatrix * inverseBindMatrixName.Value * animation.Animations[inverseBindMatrixName.Key].Matrices[counter];
            final.Add(inverseBindMatrixName.Key, finalMatrix);

         if (counter > animation.Animations.Count - 1)
            counter = 0;

         Stack<Joint> joints = new Stack<Joint>();
         while (joints.Count > 0)
            Joint currentJoint = joints.Pop();

            if (final.ContainsKey(currentJoint.JointName))
               if (currentJoint.Parent != null)
                  //multiply child * parent joint matrix
                  final[currentJoint.JointName] = final[currentJoint.JointName]* final[currentJoint.Parent.JointName];

            foreach (var joint in currentJoint.Children)

         int index = 0;
         //copy final matrices to matrix array for setting it to shader
         foreach (var matrix in final)
            JointMatrices[index] = matrix.Value;

         var renderSystem = (RenderSystem)EntityWorld.SystemManager.GetSystems<RenderSystem>()[0];
         var matrixArray = renderSystem.customEffect.GetVariableByName("jointsArray").AsMatrix();
         //set final matrix array to shader


Shader code:

matrix jointsArray[10];
float4 pos = float4(0,0,0,0);
   // Change the position vector to be 4 units for proper matrix calculations.
   input.position.w = 1.0f;

   pos += mul(jointsArray[input.jointIndices.x], input.position)*input.jointWeights.x;
   pos += mul(jointsArray[input.jointIndices.y], input.position)*input.jointWeights.y;
   pos += mul(jointsArray[input.jointIndices.z], input.position)*input.jointWeights.z;
   pos += mul(jointsArray[input.jointIndices.w], input.position)*input.jointWeights.w;

   // Calculate the position of the vertex against the world, view, and projection matrices.
   output.position = pos;
   output.position = mul(output.position, worldMatrix);
   output.position = mul(output.position, viewMatrix);
   output.position = mul(output.position, projectionMatrix);

Before calling that method I have model on image 1 and after - on image 2.


P.S. I am using managed DX 11 with sharpdx .

Set/Get array of value using effects framework C#

11 February 2015 - 09:33 AM

I faced with fact that I dont know how to get or set array of values to/from shader via effects framework.


In my case I need to pass array of matrices to shader.

Could someone help me with this? Need I use constant buffers or somethig else?


P.S. I am using managed code with sharpdx, but I think that in pure C++ the way to do it must be the same.

Why RawInput does not work from dll C#

20 January 2015 - 12:33 PM

I am using sharpdx rawinput lib from my C# lib and I see that its not working at all, BUT if I start it from my main WPF app it works pretty well.

Could someone say why it is so? Why I dont receive any event from mouse if I use it from lib and not from the main app?