Jump to content

  • Log In with Google      Sign In   
  • Create Account

BlackJoker

Member Since 28 Feb 2013
Offline Last Active Aug 18 2016 02:51 AM

#5306322 Marching cubes on GPU (DirectX)

Posted by on 17 August 2016 - 04:40 AM

Hi all.

 

Recently I started to study marching cubes technique to generate infinite terrains on GPU in runtime.

I found these articles: 

http://www.geisswerks.com/about_terrain.html

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html

 

But partial demo source code is very hard to understand and also it is almost 10 years old.

 

I understand how this should work in theory, but don`t understand yet how it should be implemented in code.

 

So, I want to ask if someone has already faced with this technique and has more recent working open source implementation on DirectX11 (C++ or C#), could you share your source code, please?




#5297105 Logarithmic depth buffer/Infinite far clip plane?

Posted by on 18 June 2016 - 01:00 AM

Hodgman

Is there any changes how I should make my intersection tests with Ray/Bounbox/etc using inverse Depth buffer?




#5294428 False negative result in bounding frustum test

Posted by on 01 June 2016 - 03:17 AM

Ok, after spending the whole day of debugging I finally fixed this issue:

The root cause of the issue was that OrientedBoundingBox.GetCorners() method returns incorrect points. I don`t know why this is happening, especially that I update my OBB matrix and scale each frame and it should be correct.

But If I get corners from basic OBB (without any transformations applied) and transform all these points with my World matrix with Vector3.TransformCoord(), then issue will gone and all frustum checks goes correctly.

That is very strange issue.

 

Here is SharpdX OBB code for GetCorners()

Is there anything wrong with it:

/// <summary>
      /// Retrieves the eight corners of the bounding box.
      /// </summary>
      /// <returns>An array of points representing the eight corners of the bounding box.</returns>
      public Vector3[] GetCorners()
      {
         var xv = new Vector3(Extents.X, 0, 0);
         var yv = new Vector3(0, Extents.Y, 0);
         var zv = new Vector3(0, 0, Extents.Z);
         Vector3.TransformNormal(ref xv, ref Transformation, out xv);
         Vector3.TransformNormal(ref yv, ref Transformation, out yv);
         Vector3.TransformNormal(ref zv, ref Transformation, out zv);

         var center = Transformation.TranslationVector;

         var corners = new Vector3[8];
         corners[0] = center + xv + yv + zv;
         corners[1] = center + xv + yv - zv;
         corners[2] = center - xv + yv - zv;
         corners[3] = center - xv + yv + zv;
         corners[4] = center + xv - yv + zv;
         corners[5] = center + xv - yv - zv;
         corners[6] = center - xv - yv - zv;
         corners[7] = center - xv - yv + zv;

         return corners;
      }



#5287949 Update only portion of data inside constant buffer D3D12

Posted by on 21 April 2016 - 06:20 AM

Hi.

I started to learn DX12 and I have a question regarding constant buffer update.

 

I need to write only to the certain parts of my constant buffer by offset.

In D3D11 I could do like that:

 

BackingBuffer is type of DataBuffer and I could write there my data separately by offsets like this:

BackingBuffer.Set(offset, ref value);

And then update my constant buffer:

// Setup the dest region inside the buffer
            if ((this.Description.BindFlags & BindFlags.ConstantBuffer) != 0)
            {
               device.UpdateSubresource(new DataBox(BackingBuffer.Pointer, 0, 0), constantBuffer);
            }
            else
            {
               var destRegion = new ResourceRegion(offsetInBytes, 0, 0, offsetInBytes + BackingBuffer.Size, 1, 1);
               device.UpdateSubresource(new DataBox(BackingBuffer.Pointer, 0, 0), constantBuffer, 0, destRegion);
            }

How can I do the same in D3D12?




#5267934 Place message loop inside each window

Posted by on 25 December 2015 - 04:35 PM

I dont want to be dependent from WInForms or WPF as they has their own bugs and I want to make my own UI Control system from scratch.

 

 

 

Pick one thread to run the UI (likely your main thread which is already running a message pump) and issue messages to it when you want it to do something either through your own message passing system, or the PostMessage Win32 function.

 

You mean that I must not create windows in other threads than main? Or just post messages to the threads, where windows was created?




#5264580 Draw 2D empty and filled circle

Posted by on 02 December 2015 - 07:51 AM

Maybe because I am a little bit stupid)

 

1. I iterate to 363 because I thought that less will made circle unfinished, but obviously I was wrong.

2. I added three vertices per iteration because I didnt fully understand triangle strip yet and work with it like with triangle list

3. This is also because of point 2.

 

Now, I apply your algorithm (which was obviously very simple) and not it works as expected.

 

Thanks a lot for that!

Attached Thumbnails

  • circle.png



#5263520 Render GUI elements with projection matrix

Posted by on 25 November 2015 - 02:15 AM

OK, I understand. I wanted to merge 2D and 3D UI, but seem this is not possible.

I need to separate 2D and 3D UI.




#5263385 Render GUI elements with projection matrix

Posted by on 24 November 2015 - 04:45 AM

Thanks to all for your answers. 

 

What do you think about using PerspectiveOffCenterLH matrix for this?

Seems it project DirectX units directly to pixels and position correspondingly. Using this matrix 0.0 will be at the top left corner of the window without any additional manipulations.




#5263298 Render GUI elements with projection matrix

Posted by on 23 November 2015 - 12:53 PM

I mean that I want to draw controls using true depth feeling, which could be made only with projection matrix. With ortho I need to scale objects manually if I want make them smaller when they are far from the camera.




#5263247 Render GUI elements with projection matrix

Posted by on 23 November 2015 - 06:23 AM

By visible depth I mean z-ordering with z-buffer. I want a real 3D UI behaviour.

 

How I need to render it in that case taking into account that I want to convert 3D Zero(0,0,0) in the middle of coordinates to the 2D Zero (0,0) at the left top corner?




#5224347 [SharpDX] Correctly handle mouse delta in Raw input

Posted by on 19 April 2015 - 01:51 PM

Ok, seems I get it myself. 

I found out that mouse can send more than one event before my input update mehod with called and I used earlier only last deltas. SO, movement was jerky.

Now I create a buffer for deltas and update camera rotation in loop.

Now camera rotations become much smoother.




#5212160 Bone animation implementation problem

Posted by on 21 February 2015 - 03:33 PM

OK, digging around I found an issue:

1. I import collada to DirectX, so all matrices should be transposed.

2. I use Yup axis and Blender has Zup axis, so I have to change axis with special matrix 

 

M11 - 1

M23 - 1

M32 - 1

M44 - 1

 

multiply each joint matrix once like this - newjointMatrix = axisChangeMatrix * jointMatrix * axisChangeMatrix

 

You need to do this once during load.

 

Then I should just multiply offset * keyframeMatrix. Or If I have hierarchy - keyframe*keyFrame.Parent *..... Parent and so on.

 

Then - send final matrices array to shader.

Thats all.

 

Now animation works correct.




#5210276 Set/Get array of value using effects framework C#

Posted by on 12 February 2015 - 08:51 AM

Thanks for help!

In sharpdx there is a little difference, but in general almost the same:

var matrixArray = renderSystem.customEffect.GetVariableByName("jointsArray").AsMatrix();
matrixArray.SetMatrix(JointMatrices);



#5206149 Why RawInput does not work from dll C#

Posted by on 23 January 2015 - 01:25 AM

I am using C# + Sharpdx, so I have managed raw input lib without any Win 32. 

But seems I understood the problem - on main thread I need to register device and then I can subscribe to events on any part of the code.




#5192720 Corrupting of the view if far from world center

Posted by on 13 November 2014 - 02:54 PM

Hello to all. 

I have a strange issue related (I think so) with view matrix of my camera class.

 

When camera is far from center of the world, it begins corrupting the view. 

Far - its starting from ~ 1.2*10^5-6.

 

I checked already my world matrix - it is correct, because if I put model back to the zero coordinates, it start looking correctly again.

Also view corrupting even if I don`t move model, but move camera.

Results on the screenshots attached to this post.

 

Here is my Camera class code. Maybe someone who wants help to solve this issue could find error, because I don`t see it (at least now).

enum CamType
    {
        Free = 0,
        FirstPerson = 1,
        ThirdPerson = 2,
        ThirdPersonAlt = 3
    }

    struct ViewMatrixDecomposeData
    {
        public Vector3 scale;
        public Quaternion rotation;
        public Vector3 translation;
    }

    class Camera
    {
        public Vector3 position;
        private Vector3 lookAt;
        private Vector3 center;
        private float radius;
        private Vector3 baseUp;
        private float fovX;
        private float fovY;
        private float aspectRatio;
        private float zNear;
        private float zFar;
        private Vector3 xAxis;
        private Vector3 yAxis;
        private Vector3 zAxis;
        private Quaternion qRotation;
        private CamType cameraType;
        private ViewMatrixDecomposeData viewMatrixDecomposeData;

        private Matrix viewMatrix;
        private Matrix projectionMatrix;

        public float ZNear
        {
            get { return zNear; }
            set { zNear = value; }
        }

        public float ZFar
        {
            get { return zFar; }
            set { zFar = value; }
        }

        public Matrix WorldMatrix { get; set; }

        public Matrix ViewMatrix
        {
            get { return viewMatrix; }
            set { viewMatrix = value; }
        }

        public Matrix ProjectionMatrix
        {
            get { return projectionMatrix; }
            set { projectionMatrix = value; }
        }

        public CamType CameraType
        {
            get
            {
                return cameraType;
            }

            set
            {
                if (cameraType != value)
                {
                    if (((cameraType == CamType.ThirdPerson) || (cameraType == CamType.ThirdPersonAlt)) && (value == CamType.Free))
                    {
                        // this is for the case of swithching from 3rd person to Free camera
                        GetViewMatrixRotation();

                        qRotation = viewMatrixDecomposeData.rotation;
                    }

                    cameraType = value;
                }
            }
        }

        public Camera(Vector3 _position, Vector3 _lookAt, Vector3 _up)
        {
            // free camera construstor
            SetFreeCamera(_position, _lookAt, _up);
        }

        public Camera(Vector3 _position, Quaternion _objectRotation, float _face_distance)
        {
            // 1st person camera construstor
            SetFirstPersonCamera(_position, _objectRotation, _face_distance);
        }

        public Camera(Vector3 _center, Quaternion _objectRotation, Vector3 _initialRelRotation, float _radius, Vector3 _lookAt, bool isAlternative)
        {
            // 3rd person camera constructor
            SetThirdPersonCamera(_center, _objectRotation, _initialRelRotation, _radius, _lookAt, isAlternative);
        }

        public void BuildPerspectiveForFovX(float _fovX, float _aspect, float _zNear, float _zFar)
        {
            fovX = _fovX;
            aspectRatio = _aspect;
            zNear = _zNear;
            zFar = _zFar;

            float e = 1.0f/(float) Math.Tan(MathUtil.DegreesToRadians(fovX/2.0f));
            float aspectInv = 1.0f/aspectRatio;
            fovY = 2.0f*(float) Math.Atan(aspectInv/e);
            float xScale = 1.0f/(float) Math.Tan(0.5f*fovY);
            float yScale = xScale/aspectInv;

            Matrix temp = ProjectionMatrix;

            temp.M11 = xScale;
            temp.M21 = 0.0f;
            temp.M31 = 0.0f;
            temp.M41 = 0.0f;

            temp.M12 = 0.0f;
            temp.M22 = yScale;
            temp.M32 = 0.0f;
            temp.M42 = 0.0f;

            temp.M13 = 0.0f;
            temp.M23 = 0.0f;
            temp.M33 = zFar/(zFar - zNear);
            temp.M43 = -zNear*zFar/(zFar - zNear);

            temp.M14 = 0.0f;
            temp.M24 = 0.0f;
            temp.M34 = 1.0f;
            temp.M44 = 0.0f;

            ProjectionMatrix = temp;
            //ProjectionMatrix = Matrix.PerspectiveFovLH(_fovX, _aspect, zNear, zFar);
        }

        public Matrix BuildPerspectiveForFovX2 (float _fovX, float _aspect, float _zNear, float _zFar)
        {
            fovX = _fovX;
            aspectRatio = _aspect;
            zNear = _zNear;
            zFar = _zFar;

            float e = 1.0f / (float)Math.Tan(MathUtil.DegreesToRadians(fovX / 2.0f));
            float aspectInv = 1.0f / aspectRatio;
            fovY = 2.0f * (float)Math.Atan(aspectInv / e);
            float xScale = 1.0f / (float)Math.Tan(0.5f * fovY);
            float yScale = xScale / aspectInv;

            Matrix temp = new Matrix();

            temp.M11 = xScale;
            temp.M21 = 0.0f;
            temp.M31 = 0.0f;
            temp.M41 = 0.0f;

            temp.M12 = 0.0f;
            temp.M22 = yScale;
            temp.M32 = 0.0f;
            temp.M42 = 0.0f;

            temp.M13 = 0.0f;
            temp.M23 = 0.0f;
            temp.M33 = zFar / (zFar - zNear);
            temp.M43 = -zNear * zFar / (zFar - zNear);

            temp.M14 = 0.0f;
            temp.M24 = 0.0f;
            temp.M34 = 1.0f;
            temp.M44 = 0.0f;

            return temp;
        }

        public void BuildPerspectiveForFovY(float _fovY, float _aspect, float _zNear, float _zFar)
        {
            ZNear = _zNear;
            ZFar = _zFar;
            ProjectionMatrix = Matrix.PerspectiveFovLH(_fovY, _aspect, zNear, zFar);
        }

        private void GetViewMatrixRotation()
        {
            ViewMatrix.Decompose(out viewMatrixDecomposeData.scale, out viewMatrixDecomposeData.rotation, out viewMatrixDecomposeData.translation);
            viewMatrixDecomposeData.rotation = Quaternion.Normalize(viewMatrixDecomposeData.rotation);
        }

        private void SetAxisFromViewMatrix()
        {
            xAxis = new Vector3(ViewMatrix.M11, ViewMatrix.M21, ViewMatrix.M31);
            yAxis = new Vector3(ViewMatrix.M12, ViewMatrix.M22, ViewMatrix.M32);
            zAxis = new Vector3(ViewMatrix.M13, ViewMatrix.M23, ViewMatrix.M33);
        }

        private void UpdateViewMatrix()
        {
            qRotation = Quaternion.Normalize(qRotation);

            if ((CameraType == CamType.ThirdPerson) || (CameraType == CamType.ThirdPersonAlt))
            {
                ViewMatrix = Matrix.Translation(Vector3.Negate(center))*Matrix.RotationQuaternion(qRotation);

                position = center - new Vector3(ViewMatrix.M13, ViewMatrix.M23, ViewMatrix.M33)*radius;

                ViewMatrix = Matrix.LookAtLH(position, lookAt,
                    new Vector3(ViewMatrix.M12, ViewMatrix.M22, ViewMatrix.M32));
            }
            else
            {
                ViewMatrix = Matrix.Translation(Vector3.Negate(position))*Matrix.RotationQuaternion(qRotation);

                if (CameraType == CamType.FirstPerson)
                {
                    ViewMatrix *= Matrix.Translation(new Vector3(0, 0, -radius));
                }
            }
        }

        public void RotateX(float _degree_angle)
        {
            if ((cameraType == CamType.ThirdPerson) || (cameraType == CamType.ThirdPersonAlt))
            {
                _degree_angle = -_degree_angle;
            }

            qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitX, MathUtil.DegreesToRadians(_degree_angle)), qRotation);
            UpdateViewMatrix();
        }

        public void RotateY(float _degree_angle)
        {
            if ((cameraType == CamType.ThirdPerson) || (cameraType == CamType.ThirdPersonAlt))
            {
                _degree_angle = -_degree_angle;
            }

            if (cameraType == CamType.ThirdPersonAlt)
            {
                qRotation = Quaternion.Multiply(qRotation, Quaternion.RotationAxis(baseUp, MathUtil.DegreesToRadians(_degree_angle)));
            }
            else
            {
                qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitY, MathUtil.DegreesToRadians(_degree_angle)), qRotation);
            }
            UpdateViewMatrix();
        }

        public void RotateZ(float _degree_angle)
        {
            qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitZ, MathUtil.DegreesToRadians(_degree_angle)), qRotation);
            UpdateViewMatrix();
        }

        public void MoveRelX(float _rel_x)
        {
            if (cameraType == CamType.Free)
            {
                SetAxisFromViewMatrix();

                position += xAxis * _rel_x;

                UpdateViewMatrix();
            }
        }

        public void MoveRelY(float _rel_y)
        {
            if (cameraType == CamType.Free)
            {
                SetAxisFromViewMatrix();

                position += yAxis * _rel_y;

                UpdateViewMatrix();
            }
        }

        public void MoveRelZ(float _rel_z)
        {
            if ((cameraType == CamType.ThirdPerson) || (cameraType == CamType.ThirdPersonAlt))
            {
                radius -= _rel_z;

                UpdateViewMatrix();
            }
            else
            {
                SetAxisFromViewMatrix();

                position += zAxis * _rel_z;

                UpdateViewMatrix();
            }
        }

        public void SetFreePosition(Vector3 _position)
        {
            position = _position;

            UpdateViewMatrix();
        }

        public void SetFreeLookAt(Vector3 _lookAt)
        {
            lookAt = _lookAt;

            Vector3 up = new Vector3(ViewMatrix.M12, ViewMatrix.M22, ViewMatrix.M32);

            ViewMatrix = Matrix.LookAtLH(position, lookAt, up);

            GetViewMatrixRotation();

            qRotation = viewMatrixDecomposeData.rotation;

            UpdateViewMatrix();
        }

        public void SetFreeCamera(Vector3 _position, Vector3 _lookAt, Vector3 _up)
        {
            cameraType = CamType.Free;    
            
            position = _position;
            lookAt = _lookAt;
            
            ViewMatrix = Matrix.LookAtLH(position, lookAt, _up);
            
            GetViewMatrixRotation();

            qRotation = viewMatrixDecomposeData.rotation;

            UpdateViewMatrix();
        }

        // SetRadius is both for 1st and 3rd person camera
        public void SetRadius(float _radius)
        {
            radius = _radius;

            UpdateViewMatrix();
        }

        public void SetFirstPersonPositionRotation(Vector3 _position, Quaternion _objectRotation)
        {
            position = _position;
            qRotation = _objectRotation;

            UpdateViewMatrix();
        }

        public void SetFirstPersonCamera(Vector3 _position , Quaternion _objectRotation, float _face_distance)
        {
            cameraType = CamType.FirstPerson;

            position = _position;
            radius = _face_distance;
            qRotation = _objectRotation;

            UpdateViewMatrix();
        }
        
        public void SetThirdPersonCenterLookAt(Vector3 _center, Vector3 _lookAt)
        {
            center = _center;
            lookAt = _lookAt;

            UpdateViewMatrix();
        }

        public void SetThirdPersonCamera(Vector3 _center, Quaternion _objectRotation, Vector3 _initialRelRotation, float _radius, Vector3 _lookAt, bool isAlternative)
        {
            if (isAlternative == true)
            {
                cameraType = CamType.ThirdPersonAlt;
            }
            else
            {
                cameraType = CamType.ThirdPerson;    
            }
            
            center = _center;
            radius = _radius;
            lookAt = _lookAt;

            qRotation = _objectRotation;

            baseUp = Matrix.RotationQuaternion(_objectRotation).Up;

            qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitX, MathUtil.DegreesToRadians(_initialRelRotation.X)), qRotation);
            qRotation = Quaternion.Multiply(qRotation, Quaternion.RotationAxis(baseUp, MathUtil.DegreesToRadians(_initialRelRotation.Y)));
            qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitZ, MathUtil.DegreesToRadians(_initialRelRotation.Z)), qRotation);

            UpdateViewMatrix();
        }
    }

Attached Thumbnails

  • Not corruptrd.png
  • Corrupted.png





PARTNERS