Jump to content
• Advertisement

# DX11 Use 64bit precision (GPU)

This topic is 2005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hello,

I've bin working on a large Terrain, so now im on the Point that i reach the precision of float.

Im working with DX11 / ShaderModel 5 and this provided doubles on GPU..

My Question is: How i can use double (Matrix, inputPosition) instead of float?

I read something about Render relative to the Eye or so, but the simple solution should use doubles, but how?

#### Share this post

##### Share on other sites
Advertisement

My Question is: How i can use double (Matrix, inputPosition) instead of float?

From MSDN HLSL Scalar Types: http://msdn.microsoft.com/en-us/library/windows/desktop/bb509646(v=vs.85).aspx

• double - 64-bit floating point value. You cannot use double precision values as inputs and outputs for a stream. To pass double precision values between shaders, declare each double as a pair of uint data types. Then, use the asdouble function to pack each double into the pair of uints and the asuint function to unpack the pair of uints back into the double.

So I think you will have to encode the doubles into a pair of uint values to pass them around.

#### Share this post

##### Share on other sites

If you want to render stuff relative to the eye in float space using doubles, you:

1. Use doubles for your position vectors.

2. Use the double vector for every object position, and for your camera.

Then you have to translate your positions into a float-capable space for rendering. You translate every object position to get the position relative to the eye with:



DoubleVector3 objectPosition = object.somePosition;
DoubleVector3 cameraPosition = camera.position;
DoubleVector3 doubleRelativePosition = objectPosition - cameraPosition;

// When you translate the object by the camera position, the resulting number is representable by a float.
// Just cast the double-vector components down to floats!

FloatVector3 relativePosition;
relativePosition.x = (float)doubleRelativePosition.x;
relativePosition.y = (float)doubleRelativePosition.y;
relativePosition.z = (float)doubleRelativePosition.z;

and then that's the position you pass into the shader for rendering.

This is really cumbersome for a ton of objects because you have to recompute this translation every time you move your camera. There is an extension of this method to keep you from creating relative coordinates every frame. You have to create a relative anchor point that moves with your camera. To do this you have to:

1. Create a double-vector anchor point that moves with your camera periodically. You move this anchor point when float-precision starts to become insufficient to represent points inside the float-anchor-area.
2. You build relative float-vector positions for everything relative to the anchor point, as we did before with the camera but with the anchor point.

3. When you move far enough away from the anchor, you re-locate it.

4. When the anchor moves you re-translate everything relative to the new anchor point. This means everything has a double-vector world position and a float-vector relative anchor position.

5. You use a regular camera view matrix to move around inside this anchor float space.
6. Draw everything normally as if the anchor-relative position is the position, and the anchor relative camera position is the camera location.

I hope this helps!

Edits: Typo-city

Edited by DementedCarrot

#### Share this post

##### Share on other sites

You should probably consider whether or not lack of precision is really the issue you are facing. Modern GPUs may support DP floating point because of SM5, but it is a feature which is almost never used by anyone (for games anyway) so consumer GPUs tend to be really bad at it. Take my GPU for example, a GTX 760 which is probably pretty typical. Switching from SP floats to DP floats is the difference between 2.25 teraflops and 94 gigaflops. That's a huge performance decrease.

#### Share this post

##### Share on other sites
Thank you for reply

Ok i should use relative to the eye

So i have one vertexbuffer for each childnode and rootnode.
Only the worldmatrix is changing.

My problem is i use cube2sphere mapping which require that the cubecenter is 0,0,0

With relative to the eye the camera position is at 0,0,0?
So whats my line? When i substract the camera position from the patch position the cube is out of the origin in worldspace

#### Share this post

##### Share on other sites
My problem is i use cube2sphere mapping which require that the cubecenter is 0,0,0

Can you be more specific about what cube2sphere mapping is, and what it's used for?

#### Share this post

##### Share on other sites

Oh Sorry, so :

Im working on a Procedural Planet with ChunkedLOD in earth Size.

To get a Sphere out of 6 Planes, i normalize each Vertex.

But the requirement is, the center of the cube (out of 6 planes) must be 0,0,0 (world-origin) like:

http://britonia.wordpress.com/2010/05/20/planet-geometry/

But here do the Vector3.normalize on the CPU, but i do it on the GPU:

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;

float3 worldPosition = mul(input.Position, World).xyz;

float3 normalized = normalize(worldPosition);
float4 scaled = float4(normalized * SeaLevel, 1);

output.Position = mul(mul(scaled, View), Projection);

output.UV = input.UV;

return output;
}


So, when i subtract the Camera Position from the QuadTree-Patch Position the Center of my Sphere/Cube is not 0,0,0 .

Edited by montify

#### Share this post

##### Share on other sites

That's a tough one. I'm not totally sure how to accomplish this when the world meshes are created that way.

I'll think on it.

#### Share this post

##### Share on other sites

nono the worldmesh created like:

I have one VertexBuffer 33x33 vertices. ( a flat Plane )

Now i made 6 of this Planet (Rotatet, Translate) to get a Cube.

Now i normalize the Input.Position in the Shader = A perfect Sphere.

---------------------

Is it possible and have it the same effect to translate the Position ( Position - cameraPosition) NOT in the WorldSpace but rather in ViewSpace?

#### Share this post

##### Share on other sites

So i have it .

I Set the Camera Posititon to Vector3.Zero and "hack" the worldMatrix

  //new View Matrix
var View = Matrix.CreateLookAt(Vector3.Zero, cam.Forward, cam.Up);

Vector3 cameraSpacePosition = (position - cam.Position);

//Relative to the Camera
world.M41 = cameraSpacePosition.X;
world.M42 = cameraSpacePosition.Y;
world.M43 = cameraSpacePosition.Z;


But i scale/normalize each vertex (the entire Planet) in the Shader like ( with *6000):

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;

float3 worldPosition = mul(input.Position, World).xyz;

float3 normalized = normalize(worldPosition);
float4 scaled = float4(worldPosition * 6000, 1);

output.Position = mul(scaled, ViewProj);

output.Position.z = log(C*output.Position.z + 1) / log(C*Far + 1) * output.Position.w; //Logarithmic Depth Buffer

return output;
}


The Scale and Normalize don't work anymore...

anybody out there who have a Solution for this Problem?

Edited by montify

#### Share this post

##### Share on other sites

• Advertisement
• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• Advertisement

• ### Popular Now

• 18
• 13
• 9
• 9
• 25
• 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!