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 Yesterday, 12:58 AM

Topics I've Started

Very strange objects transormation issue

21 April 2015 - 05:12 AM

Hello to all.


I faced with very-very strange issue regarding any rotation/translation operations with objects inside my game engine.

Issue is that object translation and rotation looks jerky, but I cannot find the reason for that. Jerky is periodical and for some eriod of time rotation/translation looks smooth and in the next few frames it became jerky and so on.

Seems it has dependency from FPS, but I DO multiply rotation/translation variables on frame time. So, it must be smooth enough, but instead I see periodical small object jumps and it independent from object scale.


At the same time FPS is nearly 60 and I must not have such issue with this FPS. In FPS 100 issue almost invisible for the eye and if more than 100 FPS, it becomes completely invisible.

First I thought that this is camera issue, but when I start object rotation itself without camera movement at all and see that object rotation is still jerky, I think this is not camera now. But also there is no reason to say that this is my transformation, because when I move camera without object moving at all, it also was jerky.


I checked all my engine and I dont see the reason for such behaviour. 


I try this on 4 different PC with intel, nvidia and AMD graphic cards and on any PC this issue could be reproduced. 


And one more notice: on my work PC I record video of this issue with camstudio and when after that I am start playing it in cam studio player, objects rotation become smoother. As far as I stop playing video, it becomes jerky again.


I think this could be some DirectX graphics parameters, which I apply on the start, but I am not sure.



Does anyone faced with such strange issue?


P.S. I am using sharpdx libs version 3.0 alpha, but the same issue was also with version 2.6.3.

[SharpDX] Correctly handle mouse delta in Raw input

19 April 2015 - 05:45 AM

Hello. I am writing my own handler for RawInput in sharpDX and for now I am stuck with mouse events.

The thing is that I want to receive mouse delta X and Y, but faced with the issue. When there is no mouse movement, mouse delta keep staying at the last value, which is not 0, so, even if I dont move mouse, my camera (for ex.) still will be rotating, because Delta in not 0.


Could someone share experience how to handle this thing correctly?


Also I would like to know how to get absolute mouse coordinates from raw input, because for know I am getting only delta values..

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 .